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

fix(display): update the color format of the draw buffers on color format change #5973

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

kisvegabor
Copy link
Member

Description of the feature or fix

fixes #5889

@XuNeo
We reshape the draw buffer before rendering, so I think the changes are ok, but please confirm it.

Notes

@kisvegabor
Copy link
Member Author

@kdschlosser With this change the C tests are passing but the MicroPython test fails. How can we check the reason of the failure?

Copy link
Collaborator

@XuNeo XuNeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lv_display_set_color_format could be called before and after set the real buf.
So it's better to use

if(disp->buf_1) disp->buf_1 = lv_draw_buf_reshape(disp->buf_1, color_format, hor_res, ver_res, LV_STRIDE_AUTO);
if(disp->buf_2) disp->buf_2 = lv_draw_buf_reshape(disp->buf_2, color_format, hor_res, ver_res, LV_STRIDE_AUTO);

We should also mention that do not mix use below two API sets

/* Raw buffer manuplation */
lv_display_set_color_format();
lv_display_set_buffers();
lv_display_set_draw_buffers()

@kisvegabor
Copy link
Member Author

What is the problem with settings the color format after using lv_display_set_draw_buffers? Note that the color format is stored in the display anyway and buffers are always reshaped before rendering. So it doesn't really matter how the users set up the draw buffers initially because only the actual buffer (data) and its size (data_size) are used.

@XuNeo
Copy link
Collaborator

XuNeo commented Mar 27, 2024

buffers are always reshaped before rendering

True. You are correct, there's no need to call lv_draw_buf_reshape here.

@kdschlosser
Copy link
Contributor

This is the error. You just have to go and look at the CI for the micropython test and it will tell you why it is failing.

Traceback (most recent call last):
  File "lib/lv_bindings/lvgl/tests/micropy_test/__init__.py", line 298, in test_1_image_compare
ValueError: not enough image data

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "lib/lv_bindings/lvgl/tests/micropy_test/__init__.py", line 318, in test_1_image_compare
AssertionError: Traceback (most recent call last):
  File "lib/lv_bindings/lvgl/tests/micropy_test/__init__.py", line 298, in test_1_image_compare
  File "/home/runner/.local/lib/python3.8/site-packages/PIL/Image.py", line 815, in frombytes
    raise ValueError(msg)
ValueError: not enough image data

It is telling us there is not enough image data. Meaning the color depth is somehow not right. The test script is collecting raw RGB data from the frame buffer so whatever change has been made is causing the wrong amount of data to be collected or the data that is being collected is not 3 byte RGB pixel data.

@kdschlosser
Copy link
Contributor

IDK where the artifacts are stored but in there should be a file with the raw pixel data that was collected so we can see what is going on.

@kdschlosser
Copy link
Contributor

It looks like you are trying to allow dynamic changing of the color format after the display driver has been initialized. Wouldn't the easiest way to be only to allow the color format to be set once and if the user wants to change the color format they would need to create a new display in LVGL in order to do that?

I say that because of buffer sizing. the frame buffers that have been passed in would need to be resized in order for this to work. In the case of someone that has passed in a raw buffer LVGL is not going to be able to handle that resizing and it would need to be done externally.

It could be explained but then how would the user go about changing the size of the buffer that is stored in LVGL? It would be easier to restrict a display's color format to only being set a single time.

@kdschlosser
Copy link
Contributor

Let me explain further on that.

When a display gets created in LVGL the user must tell the display what the frame buffers are. So lets use an RGB display as an example because it is easier to follow what I am saying.

Lets say the display is 480 x 320 and the color format for the display is RGB888. but for whatever reason the display when it was initialized is set to RGB565. That would mean the buffers are going to have a size of 480 x 320 x 2. Now if we allow dynamic changing of the color format and the user changes it to RGB888 guess what? You now have a buffer overrun condition because the size needed is going to be 480 x 320 x 3. If we flop flop it the other way around and the starting color format is RGB888 and we are changing it to RGB565 no you have a wasted memory use scenario.

You also need to remember these are MCU's we are dealing with so creating a second set of buffers or even resizing the frame buffers might not even be possible due to memory constraints. having to add 153600 bytes to an already existing frame buffer while everything is up and running is going to be a hard thing to do because the entire frame buffer would need to occupy 460800 bytes of contiguous memory. Due to memory constraints the frame buffers are one of the things that get allocated first in order to secure that amount of contiguous memory because there might not be that must contiguous space available later on. This problem gets even more compounded when dealing with double buffering.

@kisvegabor
Copy link
Member Author

kisvegabor commented Mar 27, 2024

Artifacts are not created automatically, but require explicit steps in the CI. Like this.

I think it was crashing because the buffers were NULL in set_color_format as you set the buffers only after that. See here. I added a fix, let's see if it passes now.

In case of screen sized buffer, the user really might need to set new buffers, which is doable and a reasonable expectation from the user. It's better to keep this opportunity open than limiting to setting the color depth once.

@kisvegabor
Copy link
Member Author

And passed! Could you improve the log to indicate if there was a crash and where was it?

@kdschlosser
Copy link
Contributor

I will need to have the problem duplicated and debugging turned on in order to see why the error didn't surface like it should have.

@lvgl-bot
Copy link

We need some feedback on this pull request.

Now we mark this as "stale" because there was no activity here for 14 days.

Remove the "stale" label or comment else this will be closed in 7 days.

@lvgl-bot lvgl-bot added the stale label Apr 11, 2024
@FASTSHIFT FASTSHIFT merged commit eb62ddf into lvgl:master Apr 11, 2024
16 checks passed
@kisvegabor kisvegabor deleted the fix/display-color-formet-update branch April 12, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LVGL9: lv_display_set_color_format bug
5 participants