PaintingContext class

A place to paint.

Rather than holding a canvas directly, RenderObjects paint using a painting context. The painting context has a Canvas, which receives the individual draw operations, and also has functions for painting child render objects.

When painting a child render object, the canvas held by the painting context can change because the draw operations issued before and after painting the child might be recorded in separate compositing layers. For this reason, do not hold a reference to the canvas across operations that might paint child render objects.

New PaintingContext objects are created automatically when using PaintingContext.repaintCompositedChild and pushLayer.

Inheritance

Constructors

PaintingContext(ContainerLayer _containerLayer, Rect estimatedBounds)
Creates a painting context. [...]

Properties

canvas Canvas
The canvas on which to paint. [...]
read-only, override
estimatedBounds Rect
An estimate of the bounds within which the painting context's canvas will record painting commands. This can be useful for debugging. [...]
final
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

addLayer(Layer layer) → void
Adds a composited leaf layer to the recording. [...]
appendLayer(Layer layer) → void
Adds a layer to the recording requiring that the recording is already stopped. [...]
@protected
createChildContext(ContainerLayer childLayer, Rect bounds) PaintingContext
Creates a compatible painting context to paint onto childLayer.
@protected
paintChild(RenderObject child, Offset offset) → void
Paint a child RenderObject. [...]
pushClipPath(bool needsCompositing, Offset offset, Rect bounds, Path clipPath, PaintingContextCallback painter, { Clip clipBehavior: Clip.antiAlias }) → void
Clip further painting using a path. [...]
pushClipRect(bool needsCompositing, Offset offset, Rect clipRect, PaintingContextCallback painter, { Clip clipBehavior: Clip.hardEdge }) → void
Clip further painting using a rectangle. [...]
pushClipRRect(bool needsCompositing, Offset offset, Rect bounds, RRect clipRRect, PaintingContextCallback painter, { Clip clipBehavior: Clip.antiAlias }) → void
Clip further painting using a rounded rectangle. [...]
pushLayer(ContainerLayer childLayer, PaintingContextCallback painter, Offset offset, { Rect childPaintBounds }) → void
Appends the given layer to the recording, and calls the painter callback with that layer, providing the childPaintBounds as the estimated paint bounds of the child. The childPaintBounds can be used for debugging but have no effect on painting. [...]
pushOpacity(Offset offset, int alpha, PaintingContextCallback painter) → void
Blend further painting with an alpha value. [...]
pushTransform(bool needsCompositing, Offset offset, Matrix4 transform, PaintingContextCallback painter) → void
Transform further painting using a matrix. [...]
setIsComplexHint() → void
Hints that the painting in the current layer is complex and would benefit from caching. [...]
setWillChangeHint() → void
Hints that the painting in the current layer is likely to change next frame. [...]
stopRecordingIfNeeded() → void
Stop recording to a canvas if recording has started. [...]
@mustCallSuper, @protected
toString() String
Returns a string representation of this object.
override
clipPathAndPaint(Path path, Clip clipBehavior, Rect bounds, void painter()) → void
Clip canvas with Path according to Clip and then paint. canvas is restored to the pre-clip status afterwards. [...]
inherited
clipRectAndPaint(Rect rect, Clip clipBehavior, Rect bounds, void painter()) → void
Clip canvas with Path according to Rect and then paint. canvas is restored to the pre-clip status afterwards. [...]
inherited
clipRRectAndPaint(RRect rrect, Clip clipBehavior, Rect bounds, void painter()) → void
Clip canvas with Path according to RRect and then paint. canvas is restored to the pre-clip status afterwards. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited

Static Methods

debugInstrumentRepaintCompositedChild(RenderObject child, { bool debugAlsoPaintedParent: false, PaintingContext customContext }) → void
In debug mode, repaint the given render object using a custom painting context that can record the results of the painting operation in addition to performing the regular paint of the child. [...]
repaintCompositedChild(RenderObject child, { bool debugAlsoPaintedParent: false }) → void
Repaint the given render object. [...]