PeachDrawing.Skia

SkiaRenderContext Class

The RenderContext for SkiaCanvas: where fonts, images and colours come from. It owns no surface and creates no GPU context; it may be told about the one the host draws with (GpuContext) so decoded images are uploaded to it once.

public class SkiaRenderContext : PeachDrawing.Core.RenderContext, System.IDisposable

Inheritance System.Object → RenderContext → SkiaRenderContext

Implements System.IDisposable

Remarks

Lifetime. Dispose the context after every canvas and composer made from it. Disposing it releases the font faces the native text engine loaded; fonts and images it handed out stay valid objects, but a native font can no longer measure text. It is not thread-safe to draw from two threads at once; the context’s own caches are.

Constructors  
SkiaRenderContext(SkiaTextEngine, SkiaImageCodec, ISkiaTextShaper, FontSet) Makes a context.
Properties  
FallbackToPeachImage Whether an image Skia’s codecs cannot decode is handed to PeachImage instead, when ImageCodec is Native. With it off, such an image fails to load. It has no effect with PeachImage or Auto, which always hand such an image to PeachImage.
GpuContext The GPU context the host draws with, or null for a CPU surface. It is borrowed (never disposed here). When set, a decoded image is uploaded to it once and the texture reused for every draw; when the host’s canvas is not backed by it, leave it unset.
ImageCodec Which decoder turns an encoded image into pixels.
LayoutUnitsPerPoint The factor between the layout units font sizes are requested in and the points the font behind them is built at (points = size / LayoutUnitsPerPoint). It is part of a cached font’s identity: the same requested size under a different scale is a different physical font, so the font handler keys every font cache by it. 1 for an adapter whose layout unit is the point.
PixelsPerPoint Layout units per point; see LayoutUnitsPerPoint. 1 means a layout unit is a point.
TextEngine Which text engine this context’s fonts use.
TextShaper What shapes text for Native fonts.
Methods  
AddFont(Stream, string) Adds a font from stream under fontFamilyName (or the family the file names).
AddFont(Stream, string, FontFaceDescriptors, IReadOnlyList<RuneInterval>) Adds a font from stream with the weight, width and style it is declared for.
Dispose() Releases the font faces the native text engine loaded. Safe to call more than once.
GetCssMediaType(IEnumerable<string>) The CSS media type (e.g. "print", "screen") this render context evaluates media queries against, chosen from mediaTypesAvailable.
SupportsImageType(string) What Skia’s codecs read (PNG, JPEG, GIF, WebP, BMP, ICO), when ImageCodec is Native and FallbackToPeachImage is off; PeachImage’s formats otherwise.
SyncFonts() Registers with this context the font families that were added to its FontSet since it last looked. A context that was given a set shared with others has to be told when one of them added a font; one with a set of its own sees its own additions at once and never needs this.