Repository navigation
displaydev: one-call canvas blits, and WorkerDisplay for Python in a Web Worker - #207
Merged
Merged
Conversation
bdbarnett
force-pushed
the
ostinato/display
branch
from
October 15, 2026 07:26
51a0a7f to
8438b82
Compare
…ay for an OffscreenCanvas in a Web Worker PSDisplay.blit_rect converted RGB565 one pixel at a time through the Python-to-JavaScript bridge, four calls a pixel: about two seconds for a full 1280x720 LVGL frame. It now converts the whole buffer in one JavaScript call, byte for byte the same pixels. The drawing and the input handling move into two shared helpers (_webcanvas, _webinput) so a second canvas display can use them: WorkerDisplay draws on an OffscreenCanvas the page transfers to a Web Worker and takes its input from events the page relays. A board config, board_configs/workerdisplay, pairs them, and LVGL's display_driver runs on it unchanged.
Without a pyscript module, a Pyodide Web Worker fell through to wake sources that never fire there, so timers (LVGL's display_driver loop among them) armed and never ran.
…nerated TOML sorted
bdbarnett
force-pushed
the
ostinato/display
branch
from
October 15, 2026 07:27
8438b82 to
123e3d9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Faster PyScript drawing
PSDisplay.blit_rectconverted RGB565 to RGBA one pixel at a time through the Python-to-JavaScript bridge, four calls a pixel. A full 1280x720 LVGL frame took about two seconds. It now hands the whole buffer to JavaScript once and converts it there: about 60 ms for the same frame in Chrome, with byte-for-byte the same pixels (checked against the old lookup table on random data).Python in a Web Worker
A long redraw on the page's main thread holds up everything else the page has to do on time.
displaydev.workerdisplay.WorkerDisplaylets your Python run in a Web Worker instead: the page transfers its canvas as anOffscreenCanvasand relays pointer, wheel and key events, andget_eventshands them out exactly asPSDisplaydoes, soappdevand LVGL'sdisplay_driverwork unchanged.board_configs/workerdisplaypairs them. The module docstring has the page-side JavaScript and the event format.To share code between the two, the canvas drawing moves into
displaydev/_webcanvas.pyand the input handling intodisplaydev/_webinput.py(neither touchesdocument, so both import in a worker).PSDisplay's public behaviour is unchanged. Both new helpers are listed inpydevices-desktop.tomlandmip-split.toml.Tests
tests/test_workerdisplay.py: one JavaScript call per blit, bounds checks, mouse events in CSS pixels, touch mapped to framebuffer pixels, keys with auto-repeat dropped, wheel. The existing display tests pass.