gfx/cached_image.h
StandardCachedComponentImage: what Component::setBufferedToImage installs.
#include <sonore/gfx/cached_image.h>- 1type
- Guides: The native editor
On this page
Design notes
Included at the END of component.h, after Component is complete -- the cache paints the component, and the component's setBufferedToImage makes the cache, so each needs the other whole. Including this header on its own works too: it includes component.h first, whose tail include of this file is then skipped by #pragma once.
Types 1
class StandardCachedComponentImage : public CachedComponentImage
The cache setBufferedToImage installs: the component's subtree rendered once into a Bitmap at DEVICE resolution, then composited from it.
Why device pixels, and why the sub-pixel offset is part of the key
A component at x = 10.25 under a 1.5 scale lands at device x = 15.375. Its antialiased edges are decided by that .375. A cache rendered at logical resolution and scaled up would blur; one rendered at device resolution but at a whole-pixel origin would put every edge in a slightly different place from where painting directly puts it. So the cache is rendered with the very transform the direct paint would use, shifted by WHOLE pixels only -- and when the scale or the fractional part of the position changes, it is rendered again. The result is the direct paint's pixels, composited: exact for an opaque component, and within a level of rounding for a translucent one (8-bit "over" is associative only up to rounding).
What invalidates it
repaint() of the component or of anything inside it (Component::repaint walks up to every cached ancestor), a child being added, removed or moved, and a resize. NOT a move of the component itself: its picture did not change, only where it goes. Invalidation is by rectangle, and only the invalid rectangles are re-rendered, through the same damage-skipping walk the window uses.
Rotation or shear in the transform cannot be cached this way -- the device footprint would no longer be a rectangle of the same pixels -- and paints directly instead, every time.