Repository navigation
Conversation
acd3dd2 to
3c26aeb
Compare
|
@TimJTi I think it is fine. Just let @patacongo say if he thinks this approach is fine (don't know if it is compatible with FLAT, PROTECTED and KERNEL modes). @TimJTi please also remember to update SAMA5D2 Documentation/ to include this information that they need to enable CONFIG_FB_UPDATE to avoid tearing/flickering as you was facing. |
|
Drivers really should not write directly into hardware frame buffers. For the case of a single graphics user thread, that would work but it will not work in a multithreaded environment. The result could be a disaster. Mutexes might be used to enforce single user access, but that would also result in terrible performance in multithreaded case: One or most thread would be blocked waiting for display access and trashing real-time performance. [I am not sure if the existing framebuffer driver has these same issues. It was a pretty low level of effort to create so that wouldn't surprise me.] AFAIK LVGL itself knows nothing about mulithreaded display usage. At the application level, that is fine. But within the OS we really need to be cognizant and responsible for multithreaded use in all cases. When the NX windowing system is used, for example, numerous threads may be accessing the display concurrently. Display requests are serialized in a message queue. LVGL will not work in that configuration, but other graphics do. NX will serialize all accesses across multiple threads and all will work well. This is not a good solution and I ask that you do not commit it. Instead, please consider using the pre-window framebuffer logic. I think this does whay you want to do, but might require that you think a little differently: The RAM-backed, per-window framebuffers were created to support grabbing and dragging windows without tearing or degraded performance. The is a superior, bug-free alternative. |
In the case of LVGL, you would not use all windows but only the background window (which is not movable or resizeable). You might have to enable the NX subsystem which would provide the multithreaded support. I am not sure how entangled those are. Perhaps other work would be required to do this without NX. It is always best to reuse and extend the currently architecture rather than redesign some parallel, overlapping, bugger redudant solution. |
|
Thank you @patacongo !!! @XuNeo since you are working on LVGL V9 could you please take a look and help Tim on that? |
A truly great solution would be to implement a LGVL compatible framebuffer driver for the NX windows. That would allow to solve BOTH the tearing problem to to support multithreaded concurrent windows with LVGL. How cool would that be? |
Thank you for your comments. Having slept on it I have realised my solution is right...but in completely the wrong place. It belongs in LVCGL not NuttX which is what I had thought until convincing myself otherwise. I am right that LVGL was "messing" with the framebuffer and homed in on a SAMA5D2 driver issue; but the LVGL NuttX framebuffer is rendering DIRECT to the framebuffer, not to it's own draw buffer. This is contrary to the basic principles of LVGL - set up a buffer or buffers for LVGL to render to; flush it to the display; notify that the flush is complete; repeat. I will reopen my issue on LVGL as this needs to be addressed there. I will keep this PR open for a short while as it is a useful place for a discussion and NuttX issues get more attention than LVGL ones do, sadly. But I like the idea of NX and RAM backed windows but I am not sure what "a LGVL compatible framebuffer driver for the NX windows" would be like? Since LVGL simply renders to a buffer that is setup in user-land, can an app not simply use LVGL to render to an NX RAM-backed window without any change to the NX/NuttX ecosystem? Very interested to discuss this further - when I asked a question that was 100% related to this issus @gregory-nutt essentially said the same: LVGL on multiple NX windows would be super cool; and my nascent App could easily use multiple NX windows, many of which have independent LVGL graphics rendered to them. Bring it on!! |
The RAM backed windows are an option and it sounds like you don't need the option since the buffering will occur in user space.
An window framebuffer would be a minor extension to the existing full display framebuffer. If the framebuffer is not RAM backed then this driver Window framebuffer driver would just replace the direct writes into the framebuffer with calls to NX APIs to write the image. NX would write to the correct position on the display, clip, and handle intersections. Other than the initialization of the window and selection of the driver, I don't think that the change would affect the application. The driver would also have to handle a few callbacks like redraw (just redraw the window if it a new part of the window is exposed) and other events (like moving the window or keyboard or mouse input). Keyboard / mouse input is another topic. These events go to the window that has focus. I would need to think about that more. Imagine a normal LVGL display. And error occurs and and error window pops up. The error window gets focus so the error window would then get the mouse input. Clicking OK should dismiss the error window and return focus to the LVGL window. To integrate, LVGL would have to use this NX framebuffer with the so-called "background" window: https://cwiki.apache.org/confluence/display/NUTTX/NX+Graphics+Subsystem#nxrequestbkgd I am interested in this topic. I am very retired now, but still willing to help out. |
I am on the cusp of being too deep into my current LVGL path to invite NX to the party, but I will if I have to, short term - and will certainly look into it mid-term if there is a miraculous lvgl fix for now. Bear with me. |
|
Hi @TimJTi , There are two issues with your current setup. I have explained a bit in lvgl/lvgl#6389. IssueFrom the video, it looks like the arc head is flicking. This happens because LVGL's intermediate drawing result is sent to display by hardware LCD controller directly without waiting. SolutionLVGL has a special refreshing mode called PARTIAL mode. It allows LVGL to draw on a temporal buffer and memcpy to FB when it's really finished(thus no flicking). It can still suffer from screen tearing with single FB. Current LVGL NuttX porting( Instead of hacking into FB driver, we should upgrading Multiple instanceLVGL V9 introduces support for multiple instances, allowing multiple windows to run simultaneously. The server allocates virtual framebuffers to clients, which can be easily composed using the LVGL Image widget. Clients draw on the virtual FB and send update events to the server. The NX Graphic system sounds like a good candidate for managing the window framebuffers, and input events. The recent LVGL QNX porting PR has something similar that using QNX Screen window as a display. |
|
@XuNeo I have tried partial mode but, to be fair, not before I did the linux-style framebuffer driver. If the declaration of the buffer as PARTIAL rather than DIRECT is a trigger for lvgl to only call the flush after rendering is definitely complete, it would be useful to know, and I will try it when I get a moment. But, for now, LVGL V9 is broken when it comes to using a framebuffer rather than arch or board-specfic device driver. |
|
Perhaps the answer is flush_cb a callback function to copy a buffer's content to a specific area of the display. lv_disp_flush_ready(&disp_drv) needs to be called when flushing is ready. LVGL might render the screen in multiple chunks and therefore call flush_cb multiple times. To see if the current one is the last chunk of rendering use lv_disp_flush_is_last(&disp_drv). |
|
This is 100% LVGL, so I will close this and work on a fix and PR at the LVGL repo. Once I get time to look at an NX+LVGL combo I will open a new discussion and/or PR. Thanks for everyone's help here. |
The SAMA5D2 LCDC driver has memory mapped framebuffers that LVGL (for example) can write to directly causing issues. LVGL - and presumably other applications - need a buffer that they can render to and only when done should that be copied to the "real" framebuffers of the LCDC.
I have added a function
CONFIG_FB_UPDATEthat can be called via the relevant IOCTL that does the copy and it has fixed the issue I was seeing in relation to screen artefacts I noted as an issue in the nuttx-apps repo here.I am not 100% sure what the correct way to address this is, so for now I have added a new Kconfig entry to allow an "EXT" memory buffer to be declared, and that is what is reported as the
pinfo->fbmemmemory location but it doesn't really feel right - and it seems there are no other architectures that address this so it is perhaps unique to the SAMA5D2?There must be a better/neater/proper way to be doing this?
Impact
It allows LVGL V9 to behave as expected, on this processor. I have tried to ensure that the driver reverts to the previous methodology if the new Kconfig entry is not present.
Testing
Custom board with SAMA5D27-D1G and 800x480 LCDC. Manually deleted new Kconfig entry to check the driver reverts to as before and, similarly, deleted the newly enforced
CONFIG FB_UPDATEentry to check.