Surface
public final class Surface
Surface is responsible for managing the pixels that a canvas draws into. The pixels can be
allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface).
Surface takes care of allocating a Canvas that will draw into the surface. Call
surface->getCanvas() to use that canvas (but don’t delete it, it is owned by the surface).
Surface always has non-zero dimensions. If there is a request for a new surface, and either
of the requested dimensions are zero, then nil will be returned.
Use one of the static make methods to create instances of Surface
-
Allocates raster
Surface.Canvasreturned bySurfacedraws directly into pixels.Surfaceis returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorTypeandAlphaTypesupported by raster surface; pixels is notnil; rowBytes is large enough to contain info width pixels ofColorType. Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, call flush() or peekPixels().Declaration
Swift
public static func make(_ info: ImageInfo, _ pixels: UnsafeMutableRawPointer, _ rowBytes: Int, _ surfaceProps: SurfaceProperties? = nil) -> Surface?Parameters
imageInfowidth, height,
ColorType,AlphaType,ColorSpace, of raster surface; width and height must be greater than zeropixelspointer to destination pixels buffer
rowBytesinterval from one
Surfacerow to the nextsurfacePropsLCD striping orientation and setting for device independent fonts; may be
nilReturn Value
Surfaceif all parameters are valid; otherwise,nil -
Allocates raster
Surface.Canvasreturned bySurfacedraws directly into pixels.Surfaceis returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorTypeandAlphaTypesupported by raster surface; pixels is notnil; rowBytes is large enough to contain info width pixels ofColorType. To access pixels after drawing, call flush() or peekPixels().Declaration
Swift
public static func make(_ info: ImageInfo, _ rowBytes: Int? = nil, _ surfaceProps: SurfaceProperties? = nil) -> Surface?Return Value
Surfaceif all parameters are valid; otherwise,nil -
Allocates raster
Surface.Canvasreturned bySurfacedraws directly into the pixmap’s pixels.Surfaceis returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorTypeandAlphaTypesupported by raster surface; pixels is notnil;Declaration
Swift
public static func make(pixmap: Pixmap, surfaceProps: SurfaceProperties? = nil) -> Surface?Parameters
pixmapThe pixmap to use as the backing store for this surface
surfacePropsLCD striping orientation and setting for device independent fonts; may be
nilReturn Value
Surfaceif all parameters are valid; otherwise,nil -
Returns
Surfacewithout backing pixels. Drawing to theCanvasreturned from this surface has no effect. CallingmakeImageSnapshot' on returned SkSurface returnsnil`.Declaration
Swift
public static func makeNull(width: Int32, height: Int32) -> Surface?Parameters
widthone or greater
heightone or greater
Return Value
Surface if width and height are positive; otherwise,
nil -
Returns SurfaceProps for the surface which contains the LCD striping orientation and setting for device independent fonts
Declaration
Swift
public var surfaceProperties: SurfaceProperties { get } -
Draws
Surfacecontents to canvas, with its top-left corner at (x, y). IfPaintpaint is notnil, applyColorFilter, alpha,ImageFilter,BlendMode, andDrawLooper.Parameters
canvasCanvasdrawn intoxhorizontal offset in
Canvasyvertical offset in
CanvaspaintPaintcontainingBlendMode,ColorFilter,ImageFilter, and so on; ornil -
Copies
Surfacepixel address, row bytes, andImageInfoto a pixmap and returns it, if address is available, and returns true. If pixel address is not available, returns nil.pixmap contents become invalid on any future change to
Surface.Declaration
Swift
public func peekPixels() -> Pixmap?Return Value
The pixmap with the contents, or nil.
-
Copies
Rectof pixels fromCanvasinto dstPixels. SourceRectcorners are (srcX, srcY) andSurface(width, height). DestinationRectcorners are (0, 0) and (dstInfo.width, dstInfo.height). Copies each readable pixel intersecting both rectangles, without scaling, converting to dstInfo.colorType() and dstInfo.alphaType() if required.Pixels are readable when
Surfaceis raster, or backed by a GPU.The destination pixel storage must be allocated by the caller.
Pixel values are converted only if
ColorTypeandAlphaTypedo not match. Only pixels within both source and destination rectangles are copied. dstPixels contents outsideRectintersection are unchanged.Pass negative values for srcX or srcY to offset pixels across or down destination.
Does not copy, and returns nil if:
- Source and destination rectangles do not intersect.
Surfacepixels could not be converted to dstInfo.colorType() or dstInfo.alphaType().- dstRowBytes is too small to contain one row of pixels.
Declaration
Parameters
dstInfodstPixelsstorage for pixels; dstInfo.height() times dstRowBytes, or larger
dstRowBytessize of one destination row; dstInfo.width() times pixel size, or larger
srcXoffset into readable pixels on x-axis; may be negative
srcYoffset into readable pixels on y-axis; may be negative
Return Value
the updated ImageInfo, or nil on error
View on GitHub
Install in Dash
Surface Class Reference