Skip to content

all: draw with FillRectangle when the display has it - #23

Open
hervenicol wants to merge 1 commit into
tinygo-org:devfrom
hervenicol:fast-fill
Open

hervenicol wants to merge 1 commit into
tinygo-org:devfrom
hervenicol:fast-fill

Conversation

@hervenicol

@hervenicol hervenicol commented Oct 18, 2026 •

Copy link
Copy Markdown

This PR improves performance of a few drawing primitives with drivers that support "FillRectangle".

Most display drivers have a FillRectangle method that fills a rectangle in one operation. tinydraw used only SetPixel, so it drew all shapes one pixel at a time. For example, on an st7735, each SetPixel call sets a 1x1 window and sends one pixel over SPI.

This change uses FillRectangle when the display has it:

  • Line draws horizontal and vertical lines with one FillRectangle call.
  • FilledRectangle uses one FillRectangle call.
  • Rectangle, FilledTriangle and FilledCircle use these lines, so they also get faster.

The drivers reject rectangles that are partly outside the display, so tinydraw clips the rectangle to the display first. Displays without FillRectangle keep the SetPixel path.

The output is the same, pixel for pixel. The tests now run each filled shape on a display with and without FillRectangle. New tests cover filled rectangles, filled circles, rectangles, and shapes partly outside the display. I made the new reference images with the code before this change.

I tested it on a PyBadge (st7735) with gobadge. The menu triangles and the badge's rounded corners draw correctly, and faster.

Known driver bug: ssd1306 and uc8151 clear the whole display when FillRectangle gets a black rectangle that ends at the bottom-right corner. tinydraw now calls FillRectangle much more often, so this bug is more likely to show. tinygo-org/drivers#920 fixes it.

Most display drivers have a FillRectangle method. tinydraw used only
SetPixel, so it drew all shapes one pixel at a time.

Line now draws horizontal and vertical lines with one FillRectangle
call when the display has it. FilledRectangle uses one FillRectangle
call. The shapes that use these lines also get faster. tinydraw clips
the rectangle to the display, because the drivers reject rectangles
that are partly outside it.

Run the tests of filled shapes on a display with and without
FillRectangle. Add tests for filled rectangles, filled circles,
rectangles and shapes partly outside the display.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant