SkiaBackend Class

Definition

The SkiaSharp backend: renders a page or a DisplayList onto an SkiaSharp.SKCanvas (an SkiaSharp.SKBitmap, a surface, or the canvas a MAUI, Avalonia or Uno view hands its paint handler).

public sealed class SkiaBackend : IDisposable

Remarks

It consumes display lists only, replaying them through its own IRenderingBackend. Paths fill with the non-zero winding or even-odd rule (ISO 32000-2 §8.5.3.3), strokes follow the line parameters of §8.4.3 and the stroking rules of §8.5.3.2 (each subpath on its own, dashes restarted per subpath and measured in user space, a degenerate subpath a dot only with round caps, the thinnest line one device pixel, stroke adjustment of §10.7.5), and clipping paths intersect the clip, which RestoreState() restores (§8.5.4). Edges are anti-aliased by Skia. Colours convert to RGB through GetColorConverter(PdfColorSpace, ColorConversion, PdfDefaultColorSpaces?), so the engine's colour management decides them (§8.6, §10). The page maps to pixels as the software rasterizer maps it (RenderOptions), so both backends' images line up.

Constant alpha (§11.6.4.4) goes into the paints' colours and the blend mode (§11.3.5) into the paints: Skia's sixteen blend modes are the functions of Tables 134 and 135. Annotations and form fields (§12.5.5) are placed as the software rasterizer places them (NoZoom and NoRotate, §12.5.3), clipped to their rectangle and, when translucent or blending, drawn in a layer composited with their opacity and blend mode.

Transparency groups (§11.4, §11.6.6) Skia can composite are layers: isolated groups, and non-isolated ones whose content does not blend, are transparent layers composited with the group's opacity, blend mode and soft mask; a non-isolated group of blending content at an opacity below 1 is a layer started from the backdrop and interpolated towards it (§11.4.8); the implicit knockout group of a fill and stroke (§11.7.4.4) is a layer its paints replace into. Other knockout groups, and groups that blend in a gray or CMYK group colour space, are drawn by SoftwareRasterizer into an image composited in their place and reported once per render (BackendKnockoutGroupRasterized, BackendGroupColorSpaceRasterized, both Information); a non-isolated group of blending content composited with a blend mode or a soft mask is drawn that way against a transparent backdrop, an approximation reported as the Warning BackendNonIsolatedGroupApproximated. Soft masks (§11.5, §11.6.5.1): their values are rendered by the software rasterizer once per mask, placement and clip, kept across renders (BackendSoftMaskRasterized), and applied to each masked paint or group result through a layer and SkiaSharp.SKBlendMode.DstIn.

GPU: the canvas may be a GPU surface's (SKSurface.Create(GRContext, ...), Metal, OpenGL, Vulkan or Direct3D); every image the backend makes (images, mask values, rasterized groups) is a raster image Skia uploads, so the same calls draw on both.

Text (§9.3.6, §9.4.3): glyphs of TrueType and OpenType programs (§9.9) are filled by Skia's font engine from a typeface loaded from the program's bytes (TryGetSfntData(out ReadOnlyMemory<Byte>, out Int32)), created once per program per backend, unhinted and positioned exactly; every other program (Type 1, bare CFF), every glyph whose Skia outline does not have the bounds of the program's, and every glyph when ForceOutlines is set are filled from their outlines (§9.2.4) with the non-zero winding rule. A program Skia cannot load, or a glyph it reads differently, adds the Information diagnostic BackendNativeGlyphsUnavailable, once per render. Strokes of text (modes 1, 2, 5, 6) follow the outlines like any stroke; Type 3 glyphs arrive as the paths their descriptions paint. Invisible text (mode 3) paints nothing.

Images (§8.9.4, §8.9.5) are converted once per interned display-list image to a Skia image (colour management as for paths; Decode, Indexed, colour key, Matte; a mask of the image's size folded into its alpha, one of another size drawn at its own resolution) and resampled to the device as the software rasterizer resamples them: a box filter where a pixel spans more than a sample, square samples or a tent (Interpolate, §8.9.5.3) where it does not, for the first four transforms each image is drawn at; further transforms, and enlargements past 256 pixels per sample, are sampled by Skia (mipmaps when reduced). Stencil masks (§8.9.6.2) are alpha-only images painted in the fill colour. Converted pixels are kept within the document's ImageCacheBudget; a budget of zero converts on every paint with the same output. Axial and radial shadings (§8.7.4.5.3, §8.7.4.5.4) are native linear and two-point conical gradients sampled from the function; function-based shadings (§8.7.4.5.2) a texture of the function over its domain; triangle and patch meshes (§8.7.4.5.5 to §8.7.4.5.8) vertices, a function's t interpolated through a colour table; shading patterns fill and stroke over their Background (§8.7.4.3). Tiling patterns (§8.7.3) record their cell once per scale into a picture repeated by a picture shader, laid out on the device as the rasterizer lays them out. What cannot be drawn is reported once per render: BackendImageTooLarge (an image too large to convert in memory), BackendShadingUnsupported (an unknown shading type) and BackendTilingPatternApproximated (cells nested more than eight deep, or overlapping their neighbours more than 256 times per tile).

Reuse one instance for many renders (one per surface): it keeps its paints and caches every Skia path it builds, keyed by the path's geometry, so replaying the same list again (a repaint, a cached display list) allocates nothing per operation. The cache holds at most 2^21 coordinates and 2^16 paths and is emptied when it would grow past them; typefaces are kept per font program (at most 256, held weakly, so a closed document's go with it) with at most 2^16 glyphs among them; images, shadings (at most 256, 64 MiB) and pattern cells are kept per display-list instance, held weakly; Dispose() releases them all. An instance renders one page at a time; use one per thread to render in parallel (a document is safe for concurrent renders while nobody changes it).

Tip: use kind:method, kind:property, kind:ctor. Press Esc to clear.

Constructors (1)

Properties (1)

Methods (6)