How to synchronize /dev/fb0 in HDMI video output

I am developing an image processor using a Verdin iMX8M Plus SoM.
When I switch the output-image from white to black, as shown in the attached image, the output is a mixture of white and black images in the process of switching.

The output image is a 1280x720 RGBA image.
The code for the output part was implemented as follows.

void show_image(int width, int height, uint32_t color)
{
    int fd;
    fd = open("/dev/fb0", O_RDWR);
    uint32_t *frameBuffer = (uint32_t *)mmap(NULL, width * height * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    memset(frameBuffer, color, width * height * 4); 
    msync(frameBuffer, width * height * 4, 0);
    munmap(frameBuffer, width * height * 4);
    close(fd);
}

How do I synchronize /dev/fb0 and frameBuffer?

Anyone have any ideas?

Hi @p-uchi , sorry for the late reply.

Writing directly to the /dev/fb0 is basically the most basic way to render things in a screen. What you are looking for is an “atomic update” of the image.

I think of 3 options:

  1. DRM/KMS: Are you familiar with DRM/KMS? This presentation is very good:
    https://events.static.linuxfound.org/sites/events/files/slides/brezillon-drm-kms.pdf
    You can write your own application that uses the DRM device (/dev/dri/cardX).

  2. You can also use a framework like Qt to hide all the complexity of the image subsystem and simply show the image. Is likely that Qt handles

  3. You can also use Gstreamer or OpenCV and display the image (You probably need to format it to a known format like JPG)

Kind regards,
Alvaro.