Repository navigation
FrameBuffer: areas=False draws without making an Area per call - #105
Merged
Merged
Conversation
FrameBuffer(buf, w, h, fmt, areas=False) makes every drawing call on that framebuffer return None instead of a new Area: its own methods, a Draw on it, and the module functions given it. On MicroPython with the compiled module that drawing allocates nothing, where each call made a 32-byte Area before. The default is unchanged, because callers keep areas past later draws (lists of dirty rectangles, areas added together), so a shared, reused Area would have changed their results. tests/test_areas_off.py checks every drawing call both ways, that both draw the same pixels, subclasses, clips, and on unix MicroPython that nine kinds of call allocate 0 bytes. Pure Python and the CPython extension pass the suite; tools/compare_graphics_run.py passes 423 checks. Fixes #104
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.
A program that draws every frame and never reads the returned areas can now make its framebuffer with
areas=False. Every drawing call on it returnsNone, whether through the framebuffer's own methods, aDrawon it, or a module function such aspygraphics.text8(fb, ...). On MicroPython with the compiled module, that drawing allocates nothing; before, each call made a 32-byteArea, and a few hundred calls a frame made kilobytes of garbage.fb.areasreads the setting. Fixes #104. Refs PyDevices/apps#189.The default is unchanged, and the switch is opt-in on purpose. Code in the wild holds areas across later draws on the same framebuffer: pdwidgets' Console keeps a list of them and adds them up, and the gallery's blackjack holds one for a whole hand. A single reused
Areawould have changed their results without an error. It is a constructor keyword rather than a settable attribute because on MicroPython a Python subclass's attribute store never reaches the native object, so setting it there would silently do nothing. Subclasses pass the keyword throughsuper().__init__.On unix MicroPython the issue's reproduction gives 32.0 bytes a call by default and 0.0 with
areas=False. The newtests/test_areas_off.pychecks every drawing call both ways, that both draw the same pixels, subclasses and clips, and on MicroPython that nine kinds of call (fill_rect, text, text16, blit_alpha, blit, circle,Draw.circle,Draw.text,text8) allocate 0 bytes. The suite passes on pure Python (160) and the CPython extension (147), andtools/compare_graphics_run.pypasses all 423 checks. Speed with the default is unchanged within the noise of a shared machine: best of five, in ns per call on unix MicroPython, fill_rect went from 401 to 388, pixel from 266 to 289, text from 1013 to 890,Draw.circlefrom 639 to 576, and withareas=Falsefill_rect takes 304. I haven't built it for CircuitPython.