Proper way to update canvas

Description

I’m using canvas to stream the camera frame with FreeRTOS.

Right now I create the canvas in my setup code, then every time I take a snapshot with the camera, this is executed before lv_timer_handler in a while(1)


    lv_canvas_set_buffer(p_canvas, camera_buffer, CAMERA_CANVAS_WIDTH, CAMERA_CANVAS_HEIGHT, LV_COLOR_FORMAT_RGB565);

    memcpy(camera_buffer, pbuff, LV_CANVAS_BUF_SIZE(width, height, 16, LV_DRAW_BUF_STRIDE_ALIGN));

where camera buffer is the buffer for the canvas:
static uint8_t camera_buffer[LV_CANVAS_BUF_SIZE(CAMERA_CANVAS_WIDTH, CAMERA_CANVAS_HEIGHT, 16, LV_DRAW_BUF_STRIDE_ALIGN)] ;

p_canvas is the pointer to the canvas

pbuff is the pointer to the snapshot.

It works, but is it mandatory to call lv_canvas_set_buffer every time ?
If i just call the memcpy, the canvas is not updated.

What MCU/Processor/Board and compiler are you using?

Alif Ensamble E7

What LVGL version are you using?

9.1

What do you want to achieve?

What have you tried so far?

This is a tricky thing… How many buffers does the camera render to? I would imagine it is using 2 buffers one that it is rendering to and the other has been rendered to and is able to be displayed. If that is the case then all you would need to do is flip flop the pointers to the 2 buffers to the canvas widget and call lv_refr_now to redraw.

The mechanics behind the scenes in LVGL is it is copying the data that from the canvas buffer to the frame buffer so it can be rendered to the display. It would be far more efficient for you to update that area by calling the flush callback providing the coordinates where you want to rendered to. This would eliminate the need to copy the camera buffer data which would speed thing up a large amount. That can be done depending on the type of display that is being used.

To provide you with the best advise I really need to know the bus the display is using and also the MCU being used.

I’m working with this board https://alifsemi.com/support/kits/ai-ml-appkit-gen-2/
Using this repo as template: GitHub - alifsemi/alif_m55-lvgl: LVGL example for Alif Semiconductor Ensemble device based DevKit. For bug reports or questions, please use ticket system in alifsemi.com web page.

I’m using just one buffer for the camera, right now I’m just memcpy the camera buffer to the already created canvas buffer (which is , then calling lv_obj_invalidate(pcanvas); and it’s working; i call lv_canvas_set_buffer just at init.