amenui
en·中 github ↗ v0.0.1
01文档 02组件 03实验室 04作品
en·中github ↗
×

文档 / 概念 / 设计 / 1.36 Drawn once: cached subtrees and round clips 文档 / 概念 / 设计 /

1.36 Drawn once: cached subtrees and round clips

03.52

本页只有英文。

A page of thousands of small glyphs (the Lab's Loupe: a source file at 2.75 px, about 20,000 glyphs) costs as many instances every frame it is drawn. El::cached() draws such a subtree once and keeps it.

  • A cached element is a plate (§1.33, fade_s 0, with its limits and its rules: a picture, not content; it clips its children). When the page is painted, its subtree's instances are hashed. Equal to what the plate holds, and the plate not emptied this frame, they are dropped from the scene: the plate's span is empty and the plate lays on what it kept, so the frame costs no instances for it. Different, the plate is emptied and they are drawn onto it, once. A restage that copies the subtree from the last paint with nothing in it leaves it as it was.
  • A paint in which nothing the subtree draws from changed passes it by: it is neither drawn nor hashed (Counters::kept), the plate's span is empty, and what it drew besides its instances (its identities' and texts' births, its texts' recomposition records and laid glyphs) is what it last drew. What it draws from is its nodes (key, box, clip, text and its type, fill, border, looseness, opacity, material) and what its ancestors give it (scale, a press held, the modal layer, the look's timing). Something it reads that its nodes cannot tell the same is never passed by and is compared as above: a morph or flow on the page, faces changing, and in it a drawing, a picture, a 3D view, a stage, posed, selected or composing text, a caret, a see-through group, something hidden, turned, at its own size, under a view scale, that stirs, sheds, traces or wipes, or that is pressed, focused, recomposing or decoding (tests/cached.rs).
  • So it is drawn again whenever what it draws changes: it scrolls or moves, it loosens (a front passing, its birth), its words change, the window changes size (which empties every plate). A stage, a 3D view or a see-through group inside it is drawn with the rest, each time the rest is.
  • Text in a pixel face asked for under its native size inside a cached element (Departure Mono at 2.75 px) is set and drawn at the size asked, as its outline's coverage at that size (a box filter of the native raster), not at its native size as anywhere else (§1.6), so the small page is laid out as asked and does not overlap itself: its faces carry text::FINE. At its native size and above it is a pixel face as anywhere.
  • A plate is the renderer's. A renderer that meets a cached element drawing nothing into a plate it has not inked (one made after the page was painted, offscreen) has it drawn again (Ui::plates_lost), and sends the whole glyph atlas on its first frame. Each paint's ink goes into a plate once (Scene::paint), so the scene drawn again (no paint between) lays on what the plate holds.
  • el::cached_view(over, from, ink) shows the part from (logical px on the page: x, y, w, h) of what the cached element over drew, scaled to its own box. Each pixel of the plate's ink is read as its coverage (alpha), nearest, and drawn as a glyph's coverage in ink: at a whole zoom each source pixel is a square of whole pixels, and the material draws it as text. It is one instance (Instance::cached_slot: its coordinates are packed below −1 with the slot; its batch, scene::CACHED_BATCH + slot, binds the plate's ink where a glyph's atlas would be). It draws nothing before the cached element has drawn once in this window, or inside the cached element itself.
  • El::clip_round(radius) clips the subtree to the box inside the border with round corners (half the side: a circle). The radius rides in each instance's look[3] above its in-place flag (twice the radius in quarter device px); the ink stage discards past half a pixel outside and antialiases the edge. A square clip inside it that cuts it is square; a clip around it that cuts it keeps its own straight edge. Presses are still taken anywhere in the box.

Acceptance: tests/cached.rs (a cached page drawn the first frame as without caching, then laid on with no instances of its own while something else changes and the same as uncached; a frame with nothing new identical; drawn again when its words change, with no old ink; after a new window size as uncached; a cached view at ×4 inside a round clip of radius 40: every source pixel a 4 × 4 square of one colour, with ink, and the box's corners outside the circle as the page without it).