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
.Canvas
returned bySurface
draws directly into pixels.Surface
is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorType
andAlphaType
supported 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
imageInfo
width, height,
ColorType
,AlphaType
,ColorSpace
, of raster surface; width and height must be greater than zeropixels
pointer to destination pixels buffer
rowBytes
interval from one
Surface
row to the nextsurfaceProps
LCD striping orientation and setting for device independent fonts; may be
nil
Return Value
Surface
if all parameters are valid; otherwise,nil
-
Allocates raster
Surface
.Canvas
returned bySurface
draws directly into pixels.Surface
is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorType
andAlphaType
supported 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
Surface
if all parameters are valid; otherwise,nil
-
Allocates raster
Surface
.Canvas
returned bySurface
draws directly into the pixmap’s pixels.Surface
is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorType
andAlphaType
supported by raster surface; pixels is notnil
;Declaration
Swift
public static func make(pixmap: Pixmap, surfaceProps: SurfaceProperties? = nil) -> Surface?
Parameters
pixmap
The pixmap to use as the backing store for this surface
surfaceProps
LCD striping orientation and setting for device independent fonts; may be
nil
Return Value
Surface
if all parameters are valid; otherwise,nil
-
Returns
Surface
without backing pixels. Drawing to theCanvas
returned from this surface has no effect. CallingmakeImageSnapshot' on returned SkSurface returns
nil`.Declaration
Swift
public static func makeNull(width: Int32, height: Int32) -> Surface?
Parameters
width
one or greater
height
one 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
Surface
contents to canvas, with its top-left corner at (x, y). IfPaint
paint is notnil
, applyColorFilter
, alpha,ImageFilter
,BlendMode
, andDrawLooper
.Parameters
canvas
Canvas
drawn intox
horizontal offset in
Canvas
y
vertical offset in
Canvas
paint
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; ornil
-
Copies
Surface
pixel address, row bytes, andImageInfo
to 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
Rect
of pixels fromCanvas
into dstPixels. SourceRect
corners are (srcX, srcY) andSurface
(width, height). DestinationRect
corners 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
Surface
is raster, or backed by a GPU.The destination pixel storage must be allocated by the caller.
Pixel values are converted only if
ColorType
andAlphaType
do not match. Only pixels within both source and destination rectangles are copied. dstPixels contents outsideRect
intersection 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.
Surface
pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType().- dstRowBytes is too small to contain one row of pixels.
Declaration
Parameters
dstInfo
dstPixels
storage for pixels; dstInfo.height() times dstRowBytes, or larger
dstRowBytes
size of one destination row; dstInfo.width() times pixel size, or larger
srcX
offset into readable pixels on x-axis; may be negative
srcY
offset into readable pixels on y-axis; may be negative
Return Value
the updated ImageInfo, or nil on error