Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw line using VG-Lite #6201

Open
oleg-amp opened this issue May 8, 2024 · 6 comments
Open

Draw line using VG-Lite #6201

oleg-amp opened this issue May 8, 2024 · 6 comments

Comments

@oleg-amp
Copy link

oleg-amp commented May 8, 2024

LVGL version

v8.3.1

What happened?

I want to draw multiple lines using GPU. I use NXP MIMXRT1176 which has VG-Lite.
The final result shall be an arc, drawn using short thin lines, like ticks, with constant radius from the center. I took the inspiration from the lv_meter widget.

To draw lines, I use inner and outer circular masks and draw the lines started from the center of the circle and end up right about the outer mask. This method draws all those pixels which are in-between the two circular masks.

I draw these lines upon changes in encoder, like a volume control. So I need these lines to be drawm efficiently and fast enough. My problem is that using lvgl 8.3.1 I cannot do it at all using VG-Lite because of the following code in lv_draw_vglite.c:

static void lv_draw_vglite_line(lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1,
                                const lv_point_t * point2)
{
    ...

    bool done = false;
    bool has_mask = lv_draw_mask_is_any(&rel_clip_area);

    if(!has_mask) {
        done = (lv_gpu_nxp_vglite_draw_line(&rel_point1, &rel_point2, &rel_clip_area, dsc) == LV_RES_OK);
        if(!done)
            VG_LITE_LOG_TRACE("VG-Lite draw line failed. Fallback.");
    }

    if(!done)
        lv_draw_sw_line(draw_ctx, dsc, point1, point2);
}

Meaning, if I have any masks at all, LVGL uses software to draw the lines instead of GPU. Software method is extremelly slow.

In LVGL 9 I didn't see such condition, so, I tried to to use it. Unfortunatelly, LVGL 9.x does not support VG-Lite 3.x, which basically is supported currentnly by the latest NXP SDK.

What are my options (except maybe waiting for the NXP SDK which is planned to support VG-Lite 4.x)?

How to reproduce?

No response

@liamHowatt
Copy link
Collaborator

Hi. Are you able to draw the line segments without a mask? i.e. start the lines from where the inner mask's edge would be and end the lines where the outer mask's edge would be? If it's too difficult to align the ends of the lines nicely, could you draw something else like a LV_DRAW_TASK_TYPE_ARC where the mask would have been, on top of the lines?

@kisvegabor
Copy link
Member

What are my options (except maybe waiting for the NXP SDK which is planned to support VG-Lite 4.x)?

See this issue for comments from NXP on this topic.

I draw these lines upon changes in encoder, like a volume control. So I need these lines to be drawm efficiently and fast enough.

What about having an image with the ticks and setting it as the background of an arc. The arc will mask out parts of the image as you adjust it's angles/value. It should be much faster than drawing the ticks one by one.

@oleg-amp
Copy link
Author

oleg-amp commented May 10, 2024

What about having an image with the ticks and setting it as the background of an arc. The arc will mask out parts of the image as you adjust it's angles/value. It should be much faster than drawing the ticks one by one.

The problem is that the design should have one color for ON ticks and another for OFF tick. I solved this by drawing a line with a different color on a canvas on top of already drawn lines.

If it's too difficult to align the ends of the lines nicely, could you draw something else like a LV_DRAW_TASK_TYPE_ARC where the mask would have been, on top of the lines?

So, I will have to draw the inner and outer arcs every time I redraw the tick with the different color, correct? It is possible, as long the lines and arcs are drawn by vglite. I will try it.

@kisvegabor
Copy link
Member

Can you send an image about how the result should look like?

@oleg-amp
Copy link
Author

image

@kisvegabor
Copy link
Member

You can try this:

lv_obj_set_style_arc_image_src(arc, &img, LV_PART_MAIN);
lv_obj_set_style_arc_opa(arc, LV_OPA_50, LV_PART_MAIN);
lv_obj_set_style_arc_image_src(arc, &img, LV_PART_INDICATOR);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants