PeachDrawing.Core

PeachDrawing.Core

RetainedLayer Class

A group of drawing recorded once and drawn any number of times, each time with its own opacity and under whatever transform the target canvas has at that moment. It is what lets an animation that only moves or fades a subtree (a CSS transform or opacity animation) cost a composite per frame instead of a repaint: a canvas backed by a GPU keeps the recorded group as a texture, and drawing it again is a single textured quad.

public abstract class RetainedLayer : System.IDisposable

Inheritance System.Object → RetainedLayer

Implements System.IDisposable

Remarks

Begin one with CreateRetainedLayer(Rect), draw its content onto Recorder in the coordinates of the canvas that created it, call Seal(), and then Draw(Canvas, double) it. The content is recorded once, so it must not depend on anything that changes between draws: opacity is the one thing a draw supplies, and the transform is the target’s.

A layer belongs to the surface that created it. CanDraw(Canvas) says whether a particular canvas can still draw it (a lost graphics device or a different document makes the answer no); when it cannot, discard the layer and record a new one.

Properties  
Bounds The region the layer covers, in the coordinates of the canvas that created it. Content outside it is not kept.
IsSealed Whether Seal() has been called, so the layer can be drawn and no longer recorded onto.
Recorder The canvas to record the layer’s content onto, in the coordinates of the canvas that created the layer. Valid from creation until Seal().
Methods  
CanDraw(Canvas) Whether target can draw this layer.
Dispose() Releases what the layer holds.
Draw(Canvas, double) Draws the sealed layer onto target under its current transform, at Bounds.
Seal() Finishes recording. After this the layer can be drawn, and Recorder is no longer valid.