gfx/region.h
A set of rectangles, and the reason it exists: partial repaint.
#include <sonore/gfx/region.h>- 1type
- Guides: The native editor
On this page
Design notes
What was wrong
Component damage was ONE rectangle, united. Two knobs at opposite corners of an editor moving at once produced a damaged area covering everything between them -- which for a wide editor is the whole thing. window_win32.h has said so in a comment since it was written: "the damaged rectangle is currently the whole window rather than the union the tree reports -- correct, and wasteful. The damage IS tracked; using it is the optimisation, and it is not free."
It matters more here than in an application. A plugin editor repaints at 30 Hz for as long as it is open, inside a process that is also running an audio callback every few milliseconds, on the same CPU. Time spent rasterising pixels nobody asked for is time the audio thread might have wanted.
Why a list rather than a proper region
A real region algebra -- subtract, xor, canonical decomposition -- is a substantial piece of computational geometry, and a plugin editor's damage is a handful of rectangles that are usually disjoint already. So: a list, with merging of anything that overlaps or touches, and a cap after which it gives up and unions everything. The cap is the honest part: past a certain count, testing each rectangle costs more than redrawing the lot.
Types 1
A small set of float rectangles that grows by union: what a component tree's damage is kept in. Named after the reference's RectangleList, but deliberately less -- add, intersect-tests and a bounding box, no subtraction -- for the reasons the file comment gives.
Rectangles that overlap, or come within a unit of each other, are merged as they are added, so the list never holds two that do; past kMaxRectangles it becomes one bounding box. The units are whatever the caller adds -- logical units for a component's damage. A plain value, used on the message thread with the tree.