Canvas provides an interface for drawing, and how the drawing is clipped and transformed. Canvas contains a stack of Matrix and Clip values.
Canvas and Paint together provide the state to draw into Surface or Device. Each Canvas draw call transforms the geometry of the object by the concatenation of all Matrix values in the stack. The transformed geometry is clipped by the intersection of all of Clip values in the stack. The Canvas draw calls use Paint to supply drawing state such as Color, Typeface, text size, stroke width, Shader and so on.
To draw to a pixel-based destination, create Raster Surface or GPU Surface. Request Canvas from Surface to obtain the interface to draw. Canvas generated by Raster Surface draws to memory visible to the CPU. Canvas generated by GPU Surface uses Vulkan or OpenGL to draw to the GPU.
To draw to a document, obtain Canvas from SVG Canvas, Document PDF, or Picture Recorder. Document based Canvas and other Canvas Subclasses reference Device describing the destination.
Canvas can be constructed to draw to Bitmap without first creating Raster Surface. This approach may be deprecated in the future.
topics | description |
---|
constants | description |
---|---|
Lattice::Flags | Controls Lattice transparency. |
PointMode | Sets drawPoints options. |
SaveLayerFlags | Sets SaveLayerRec options. |
SrcRectConstraint | Sets drawImageRect options. |
struct | description |
---|---|
Lattice | Divides Bitmap, Image into a rectangular grid. |
SaveLayerRec | Contains state to create Layer. |
Create the desired type of Surface to obtain its Canvas when possible. Constructors are useful when no Surface is required, and some helpers implicitly create Raster Surface.
description | |
---|---|
SkCanvas() | No Surface, no dimensions. |
SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr) | No Surface, set dimensions, Surface Properties. |
SkCanvas(SkBaseDevice* device) | Existing Device. (SkBaseDevice is private.) |
SkCanvas(const SkBitmap& bitmap) | Uses existing Bitmap. |
SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) | Uses existing Bitmap and Surface Properties. |
MakeRasterDirect | Creates from SkImageInfo and Pixel Storage. |
MakeRasterDirectN32 | Creates from image data and Pixel Storage. |
function | description |
---|---|
accessTopLayerPixels | Returns writable pixel access if available. |
accessTopRasterHandle | Returns context that tracks Clip and Matrix. |
clear | Fills Clip with Color. |
clipPath | Combines Clip with Path. |
clipRRect | Combines Clip with Round Rect. |
clipRect | Combines Clip with Rect. |
clipRegion | Combines Clip with Region. |
concat | Multiplies Matrix by Matrix. |
discard | Makes Canvas contents undefined. |
drawAnnotation | Associates a Rect with a key-value pair. |
drawArc | Draws Arc using Clip, Matrix, and Paint. |
drawAtlas | Draws sprites using Clip, Matrix, and Paint. |
drawBitmap | Draws Bitmap at (x, y) position. |
drawBitmapLattice | Draws proportionally stretched Bitmap. |
drawBitmapNine | Draws Nine Patch Bitmap. |
drawBitmapRect | Draws Bitmap, source Rect to destination Rect. |
drawCircle | Draws Circle using Clip, Matrix, and Paint. |
drawColor | Fills Clip with Color and Blend Mode. |
drawDRRect | Draws double Round Rect stroked or filled. |
drawDrawable | Draws Drawable, encapsulated drawing commands. |
drawIRect | Draws IRect using Clip, Matrix, and Paint. |
drawImage | Draws Image at (x, y) position. |
drawImageLattice | Draws proportionally stretched Image. |
drawImageNine | Draws Nine Patch Image. |
drawImageRect | Draws Image, source Rect to destination Rect. |
drawLine | Draws line segment between two points. |
drawOval | Draws Oval using Clip, Matrix, and Paint. |
drawPaint | Fills Clip with Paint. |
drawPatch | Draws Coons patch. |
drawPath | Draws Path using Clip, Matrix, and Paint. |
drawPicture | Draws Picture using Clip and Matrix. |
drawPoint | Draws point at (x, y) position. |
drawPoints | Draws array as points, lines, polygon. |
drawPosText | Draws text at array of (x, y) positions. |
drawPosTextH | Draws text at x positions with common baseline. |
drawRRect | Draws Round Rect using Clip, Matrix, and Paint. |
drawRect | Draws Rect using Clip, Matrix, and Paint. |
drawRegion | Draws Region using Clip, Matrix, and Paint. |
drawRoundRect | Draws Round Rect using Clip, Matrix, and Paint. |
drawText | Draws text at (x, y), using font advance. |
drawTextBlob | Draws text with arrays of positions and Paint. |
drawTextOnPath | Draws text following Path contour. |
drawTextOnPathHV | Draws text following Path with offsets. |
drawTextRSXform | Draws text with array of RSXform. |
drawString | Draws null terminated string at (x, y) using font advance. |
drawVertices | Draws Vertices, a triangle mesh. |
flush | Triggers execution of all pending draw operations. |
getBaseLayerSize | Gets size of base Layer in global coordinates. |
getDeviceClipBounds | Returns IRect bounds of Clip. |
getDrawFilter | Legacy; to be deprecated. |
getGrContext | Returns GPU Context of the GPU Surface. |
getLocalClipBounds | Returns Clip bounds in source coordinates. |
getMetaData | Associates additional data with the canvas. |
getProps | Copies Surface Properties if available. |
getSaveCount | Returns depth of stack containing Clip and Matrix. |
getTotalMatrix | Returns Matrix. |
imageInfo | Returns Image Info for Canvas. |
isClipEmpty | Returns if Clip is empty. |
isClipRect | Returns if Clip is Rect and not empty. |
MakeRasterDirect | Creates Canvas from SkImageInfo and pixel data. |
MakeRasterDirectN32 | Creates Canvas from image specifications and pixel data. |
makeSurface | Creates Surface matching SkImageInfo and SkSurfaceProps. |
peekPixels | Returns if Canvas has direct access to its pixels. |
quickReject | Returns if Rect is outside Clip. |
readPixels | Copies and converts rectangle of pixels from Canvas. |
resetMatrix | Resets Matrix to identity. |
restore | Restores changes to Clip and Matrix, pops save stack. |
restoreToCount | Restores changes to Clip and Matrix to given depth. |
rotate | Rotates Matrix. |
save | Saves Clip and Matrix on stack. |
saveLayer | Saves Clip and Matrix on stack; creates Layer. |
saveLayerAlpha | Saves Clip and Matrix on stack; creates Layer; sets opacity. |
saveLayerPreserveLCDTextRequests | Saves Clip and Matrix on stack; creates Layer for LCD text. |
scale | Scales Matrix. |
setAllowSimplifyClip | Experimental. |
setDrawFilter | Legacy; to be deprecated. |
setMatrix | Sets Matrix. |
skew | Skews Matrix. |
writePixels | Copies and converts rectangle of pixels to Canvas. |
Allocates raster Canvas that will draw directly into pixels. To access pixels after drawing, call flush or peekPixels.
Canvas is returned if all parameters are valid. Valid parameters include: info dimensions are zero or positive; info contains Image Color Type and Image Alpha Type supported by Raster Surface; pixels is not nullptr; rowBytes is zero or large enough to contain info width pixels of Image Color Type.
Pass zero for rowBytes to compute rowBytes from info width and size of pixel. If rowBytes is greater than zero, it must be equal to or greater than info width times bytes required for Image Color Type.
Pixel buffer size should be info height times computed rowBytes.
Canvas if all parameters are valid; otherwise, nullptr
--- -x- ---
MakeRasterDirectN32 SkSurface::MakeRasterDirect
Allocates raster Canvas specified by inline image specification. Subsequent Canvas calls draw into pixels. Image Color Type is set to kN32 SkColorType. Image Alpha Type is set to kPremul SkAlphaType. To access pixels after drawing, call flush or peekPixels.
Canvas is returned if all parameters are valid. Valid parameters include: width and height are zero or positive; pixels is not nullptr; rowBytes is zero or large enough to contain width pixels of kN32 SkColorType.
Pass zero for rowBytes to compute rowBytes from width and size of pixel. If rowBytes is greater than zero, it must be equal to or greater than width times bytes required for Image Color Type.
Pixel buffer size should be height times rowBytes.
Canvas if all parameters are valid; otherwise, nullptr
--- -x- ---
Creates an empty Canvas with no backing device or pixels, with a width and height of zero.
empty Canvas
paint draws text left to right paint draws text top to bottom paint draws text top to bottom
Creates Canvas of the specified dimensions without a Surface. Used by Subclasses with custom implementations for draw methods.
If props equals nullptr, Surface Properties are created with Surface Properties Legacy Font Host settings, which choose the pixel striping direction and order. Since a platform may dynamically change its direction when the device is rotated, and since a platform may have multiple monitors with different characteristics, it is best not to rely on this legacy behavior.
Canvas placeholder with dimensions
canvas is empty
SkSurfaceProps SkPixelGeometry
Construct a canvas that draws into device. Used by child classes of SkCanvas.
Canvas that can be used to draw into device
Construct a canvas that draws into bitmap. Sets SkSurfaceProps::kLegacyFontHost InitType in constructed Surface.
Bitmap is copied so that subsequently editing bitmap will not affect constructed Canvas.
May be deprecated in the future.
Canvas that can be used to draw into bitmap
----- ---x- ---x- ---x- ---x- ---x- ---x- ----- ---x- ---x- -----
Canvas that can be used to draw into bitmap
Construct a canvas that draws into bitmap. Use props to match the device characteristics, like LCD striping.
bitmap is copied so that subsequently editing bitmap will not affect constructed Canvas.
Canvas that can be used to draw into bitmap
----- ---x- ---x- ---x- ---x- ---x- ---x- ----- ---x- ---x- -----
Draw saved Layers, if any. Free up resources used by Canvas.
State Stack
Returns storage to associate additional data with the canvas. The storage is freed when Canvas is deleted.
storage that can be read from and written to
before: (null) during: Hello! after: (null)
Returns Image Info for Canvas. If Canvas is not associated with Raster Surface or GPU Surface, returned Image Color Type is set to kUnknown SkColorType.
dimensions and Image Color Type of Canvas
emptyInfo == canvasInfo
If Canvas is associated with Raster Surface or GPU Surface, copies Surface Properties and returns true. Otherwise, return false and leave props unchanged.
true if Surface Properties was copied
isRGB:0 isRGB:1
Triggers the immediate execution of all pending draw operations. If Canvas is associated with GPU Surface, resolves all pending GPU operations.
Gets the size of the base or root Layer in global canvas coordinates. The origin of the base Layer is always (0,0). The area available for drawing may be smaller (due to clipping or saveLayer).
integral width and height of base Layer
clip=10,30 size=20,30
Creates Surface matching info and props, and associates it with Canvas. Returns nullptr if no match found.
If props is nullptr, matches Surface Properties in Canvas. If props is nullptr and Canvas does not have Surface Properties, creates Surface with default Surface Properties.
Surface matching info and props, or nullptr if no match is available
compatible != nullptr size = 3, 4
Returns GPU Context of the GPU Surface associated with Canvas.
GPU Context, if available; nullptr otherwise
Returns the pixel base address, Image Info, rowBytes, and origin if the pixels can be read directly. The returned address is only valid while Canvas is in scope and unchanged. Any Canvas call or Surface call may invalidate the returned address and other returned values.
If pixels are inaccessible, info, rowBytes, and origin are unchanged.
address of pixels, or nullptr if inaccessible
The Layer and blended result appear on the CPU and GPU but the large dotted "" appear only on the CPU.
Returns custom context that tracks the Matrix and Clip.
Use Raster Handle Allocator to blend Skia drawing with custom drawing, typically performed by the host platform's user interface. The custom context returned is generated by SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for the drawing destination.
context of custom allocation
context = skia
SkRasterHandleAllocator
Returns true if Canvas has direct access to its pixels.
Pixels are readable when Device is raster. Pixels are not readable when Canvas is returned from GPU Surface, returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility class like SkDumpCanvas.
pixmap is valid only while Canvas is in scope and unchanged. Any Canvas or Surface call may invalidate the pixmap values.
true if Canvas has direct access to pixels
width=256 height=256
Copies rectangle of pixels from Canvas into dstPixels. Matrix and Clip are ignored. Source rectangle corners are (srcX, srcY) and(this->imageInfo.width(), this->imageInfo.height()).
Destination rectangle corners are (0, 0) and (bitmap.width(), bitmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to dstInfo.colorType() and dstInfo.alphaType() if required.
Pixels are readable when Device is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility class like SkDumpCanvas.
The destination pixel storage must be allocated by the caller.
Pixel values are converted only if Image Color Type and Image Alpha Type do not match. Only pixels within both source and destination rectangles are copied. dstPixels contents outside the rectangle intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down destination.
Does not copy, and returns false if:
true if pixels were copied
pixel = 802b5580 pixel = 8056a9ff
peekPixels writePixels drawBitmap drawImage
Copies rectangle of pixels from Canvas into pixmap. Matrix and Clip are ignored. Source rectangle corners are (srcX, srcY) and(this->imageInfo.width(), this->imageInfo.height()).
Destination rectangle corners are (0, 0) and (bitmap.width(), bitmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to pixmap.colorType() and pixmap.alphaType() if required.
Pixels are readable when Device is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility class like SkDumpCanvas.
Caller must allocate pixel storage in pixmap if needed.
Pixel values are converted only if Image Color Type and Image Alpha Type do not match. Only pixels within both source and destination rectangles are copied. pixmap pixels contents outside the rectangle intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down pixmap.
Does not copy, and returns false if:
true if pixels were copied
pixel = 802b5580
peekPixels writePixels drawBitmap drawImage
Copies rectangle of pixels from Canvas into bitmap. Matrix and Clip are ignored. Source rectangle corners are (srcX, srcY) and(this->imageInfo.width(), this->imageInfo.height()).
Destination rectangle corners are (0, 0) and (bitmap.width(), bitmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to bitmap.colorType() and bitmap.alphaType() if required.
Pixels are readable when Device is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility class like SkDumpCanvas.
Caller must allocate pixel storage in bitmap if needed.
Bitmap values are converted only if Image Color Type and Image Alpha Type do not match. Only pixels within both source and destination rectangles are copied. Bitmap pixels outside the rectangle intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down bitmap.
Does not copy, and returns false if:
true if pixels were copied
pixel = 802b5580
peekPixels writePixels drawBitmap drawImage
Copies rectangle from pixels to Canvas. Matrix and Clip are ignored. Source rectangle corners are (0, 0) and (info.width(), info.height()). Destination rectangle corners are (x, y) and(this->imageInfo.width(), this->imageInfo.height()).
Copies each readable pixel intersecting both rectangles, without scaling, converting tothis->imageInfo.colorType()andthis->imageInfo.alphaType()if required.
Pixels are writable when Device is raster, or backed by a GPU. Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility class like SkDumpCanvas.
Pixel values are converted only if Image Color Type and Image Alpha Type do not match. Only pixels within both source and destination rectangles are copied. Canvas pixels outside the rectangle intersection are unchanged.
Pass negative values for x or y to offset pixels to the left or above Canvas pixels.
Does not copy, and returns false if:
true if pixels were written to Canvas
readPixels drawBitmap drawImage
Copies rectangle from pixels to Canvas. Matrix and Clip are ignored. Source rectangle corners are (0, 0) and (bitmap.width(), bitmap.height()).
Destination rectangle corners are (x, y) and(this->imageInfo.width(), this->imageInfo.height()).
Copies each readable pixel intersecting both rectangles, without scaling, converting tothis->imageInfo.colorType()andthis->imageInfo.alphaType()if required.
Pixels are writable when Device is raster, or backed by a GPU. Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility class like SkDumpCanvas.
Pixel values are converted only if Image Color Type and Image Alpha Type do not match. Only pixels within both source and destination rectangles are copied. Canvas pixels outside the rectangle intersection are unchanged.
Pass negative values for x or y to offset pixels to the left or above Canvas pixels.
Does not copy, and returns false if:
true if pixels were written to Canvas
readPixels drawBitmap drawImage
Canvas maintains a stack of state that allows hierarchical drawing, commonly used to implement windows and views. The initial state has an identity matrix and and an infinite clip. Even with a wide-open clip, drawing is constrained by the bounds of the Canvas Surface or Device.
Canvas savable state consists of Clip, Matrix, and Draw Filter. Clip describes the area that may be drawn to. Matrix transforms the geometry. Draw Filter (deprecated on most platforms) modifies the paint before drawing.
save, saveLayer, saveLayerPreserveLCDTextRequests, and saveLayerAlpha save state and return the depth of the stack.
restore, restoreToCount, and
Each Clip uses the current Matrix for its coordinates.
save saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore restoreToCount
Saves Matrix, Clip, and Draw Filter (Draw Filter deprecated on most platforms). Calling restore discards changes to Matrix, Clip, and Draw Filter, restoring the Matrix, Clip, and Draw Filter to their state when save was called.
Matrix may be changed by translate, scale, rotate, skew, concat, setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion.
Saved Canvas state is put on a stack; multiple calls to save should be balance by an equal number of calls to restore.
Call restoreToCount with result to restore this and subsequent saves.
depth of saved stack
Removes changes to Matrix, Clip, and Draw Filter since Canvas state was last saved. The state is removed from the stack.
Does nothing if the stack is empty.
Returns the number of saved states, each containing: Matrix, Clip, and Draw Filter. Equals the number of save calls less the number of restore calls plus one. The save count of a new canvas is one.
depth of save state stack
depth = 1 depth = 2 depth = 1
Restores state to Matrix, Clip, and Draw Filter values when save, saveLayer, saveLayerPreserveLCDTextRequests, or saveLayerAlpha returned saveCount.
Does nothing if saveCount is greater than state stack count. Restores state to initial values if saveCount is less than or equal to one.
depth = 1 depth = 3 depth = 1
Layer allocates a temporary Bitmap to draw into. When the drawing is complete, the Bitmap is drawn into the Canvas.
Layer is saved in a stack along with other saved state. When state with a Layer is restored, the Bitmap is drawn into the previous Layer.
Layer may be initialized with the contents of the previous Layer. When Layer is restored, its Bitmap can be modified by Paint passed to Layer to apply Color Alpha, Color Filter, Image Filter, and Blend Mode.
Saves Matrix, Clip, and Draw Filter (Draw Filter deprecated on most platforms), and allocates a Bitmap for subsequent drawing. Calling restore discards changes to Matrix, Clip, and Draw Filter, and draws the Bitmap.
Matrix may be changed by translate, scale, rotate, skew, concat, setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion.
Rect bounds suggests but does not define the Bitmap size. To clip drawing to a specific rectangle, use clipRect.
Optional Paint paint applies Color Alpha, Color Filter, Image Filter, and Blend Mode when restore is called.
Call restoreToCount with returned value to restore this and subsequent saves.
depth of saved stack
Saves Matrix, Clip, and Draw Filter (Draw Filter deprecated on most platforms), and allocates a Bitmap for subsequent drawing. Calling restore discards changes to Matrix, Clip, and Draw Filter, and draws the Bitmap.
Matrix may be changed by translate, scale, rotate, skew, concat, setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion.
Rect bounds suggests but does not define the Layer size. To clip drawing to a specific rectangle, use clipRect.
Optional Paint paint applies Color Alpha, Color Filter, Image Filter, and Blend Mode when restore is called.
Call restoreToCount with returned value to restore this and subsequent saves.
depth of saved stack
Saves Matrix, Clip, and Draw Filter (Draw Filter deprecated on most platforms), and allocates a Bitmap for subsequent drawing. LCD Text is preserved when the Layer is drawn to the prior Layer.
Calling restore discards changes to Matrix, Clip, and Draw Filter, and draws Layer.
Matrix may be changed by translate, scale, rotate, skew, concat, setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion. Rect bounds suggests but does not define the Layer size. To clip drawing to a specific rectangle, use clipRect.
Optional Paint paint applies Color Alpha, Color Filter, Image Filter, and Blend Mode when restore is called.
Call restoreToCount with returned value to restore this and subsequent saves.
Draw text on an opaque background so that LCD Text blends correctly with the prior Layer. LCD Text drawn on a background with transparency may result in incorrect blending.
depth of saved stack
Saves Matrix, Clip, and Draw Filter (Draw Filter deprecated on most platforms), and allocates Bitmap for subsequent drawing.
Calling restore discards changes to Matrix, Clip, and Draw Filter, and blends Layer with alpha opacity onto prior Layer.
Matrix may be changed by translate, scale, rotate, skew, concat, setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion.
Rect bounds suggests but does not define Layer size. To clip drawing to a specific rectangle, use clipRect.
alpha of zero is fully transparent, 255 is fully opaque.
Call restoreToCount with returned value to restore this and subsequent saves.
depth of saved stack
SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, defining how Layer allocated by saveLayer operates.
SaveLayerRec contains the state used to create the Layer.
const SkRect* fBounds
fBounds is used as a hint to limit the size of Layer; may be nullptr. fBounds suggests but does not define Layer size. To clip drawing to a specific rectangle, use clipRect.
const SkPaint* fPaint
fPaint modifies how Layer overlays the prior Layer; may be nullptr. Color Alpha, Blend Mode, Color Filter, Draw Looper, Image Filter, and Mask Filter affect Layer draw.
const SkImageFilter* fBackdrop
fBackdrop applies Image Filter to the prior Layer when copying to the Layer; may be nullptr. Use kInitWithPrevious SaveLayerFlag to copy the prior Layer without an Image Filter.
const SkImage* fClipMask
restore clips Layer by the Color Alpha channel of fClipMask when Layer is copied to Device. fClipMask may be nullptr. .
const SkMatrix* fClipMatrix
fClipMatrix transforms fClipMask before it clips Layer. If fClipMask describes a translucent gradient, it may be scaled and rotated without introducing artifacts. fClipMatrix may be nullptr.
SaveLayerFlags fSaveLayerFlags
fSaveLayerFlags are used to create Layer without transparency, create Layer for LCD text, and to create Layer with the contents of the previous Layer.
Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags.
empty SaveLayerRec
rec1 == rec2
Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr.
SaveLayerRec with empty backdrop
rec1 == rec2
Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags.
SaveLayerRec fully specified
rec1 == rec2
Not ready for general use.Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags. clipMatrix uses Color Alpha channel of image, transformed by clipMatrix, to clip Layer when drawn to Canvas.
Implementation is incomplete; has no effect if Device is GPU-backed.
SaveLayerRec fully specified
Saves Matrix, Clip, and Draw Filter (Draw Filter deprecated on most platforms), and allocates Bitmap for subsequent drawing.
Calling restore discards changes to Matrix, Clip, and Draw Filter, and blends Bitmap with Color Alpha opacity onto the prior Layer.
Matrix may be changed by translate, scale, rotate, skew, concat, setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion.
SaveLayerRec contains the state used to create the Layer.
Call restoreToCount with returned value to restore this and subsequent saves.
depth of save state stack
Translate Matrix by dx along the x-axis and dy along the y-axis.
Mathematically, replace Matrix with a translation matrix Premultiplied with Matrix.
This has the effect of moving the drawing by (dx, dy) before transforming the result with Matrix.
The blue stroke follows translate of (50, 50); a black fill follows scale of (2, 1/2.f). After restoring the clip, which resets Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill follows translate of (50, 50).
Scale Matrix by sx on the x-axis and sy on the y-axis.
Mathematically, replace Matrix with a scale matrix Premultiplied with Matrix.
This has the effect of scaling the drawing by (sx, sy) before transforming the result with Matrix.
Rotate Matrix by degrees. Positive degrees rotates clockwise.
Mathematically, replace Matrix with a rotation matrix Premultiplied with Matrix.
This has the effect of rotating the drawing by degrees before transforming the result with Matrix.
Rotate Matrix by degrees about a point at (px, py). Positive degrees rotates clockwise.
Mathematically, construct a rotation matrix. Premultiply the rotation matrix by a translation matrix, then replace Matrix with the resulting matrix Premultiplied with Matrix.
This has the effect of rotating the drawing about a given point before transforming the result with Matrix.
Skew Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx skews the drawing right as y increases; a positive value of sy skews the drawing down as x increases.
Mathematically, replace Matrix with a skew matrix Premultiplied with Matrix.
This has the effect of skewing the drawing by (sx, sy) before transforming the result with Matrix.
Replace Matrix with matrix Premultiplied with existing Matrix.
This has the effect of transforming the drawn geometry by matrix, before transforming the result with existing Matrix.
Replace Matrix with matrix. Unlike concat, any prior matrix state is overwritten.
Sets Matrix to the identity matrix. Any prior matrix state is overwritten.
Returns Matrix. This does not account for translation by Device or Surface.
Matrix in Canvas
isIdentity true
Clip is built from a stack of clipping paths. Each Path in the stack can be constructed from one or more Path Contour elements. The Path Contour may be composed of any number of Path Verb segments. Each Path Contour forms a closed area; Path Fill Type defines the area enclosed by Path Contour.
Clip stack of Path elements successfully restrict the Path area. Each Path is transformed by Matrix, then intersected with or subtracted from the prior Clip to form the replacement Clip. Use SkClipOp::kDifference to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path with Clip.
A clipping Path may be Anti-aliased; if Path, after transformation, is composed of horizontal and vertical lines, clearing Anti-alias allows whole pixels to either be inside or outside the clip. The fastest drawing has a Aliased, rectangular clip.
If clipping Path has Anti-alias set, clip may partially clip a pixel, requiring that drawing blend partially with the destination along the edge. A rotated rectangular Anti-aliased clip looks smoother but draws slower.
Clip can combine with Rect and Round Rect primitives; like Path, these are transformed by Matrix before they are combined with Clip.
Clip can combine with Region. Region is assumed to be in Device coordinates and is unaffected by Matrix.
Replace Clip with the intersection or difference of Clip and rect, with an Aliased or Anti-aliased clip edge. rect is transformed by Matrix before it is combined with Clip.
Replace Clip with the intersection or difference of Clip and rect. Resulting Clip is Aliased; pixels are fully contained by the clip. rect is transformed by Matrix before it is combined with Clip.
Replace Clip with the intersection of Clip and rect. Resulting Clip is Aliased; pixels are fully contained by the clip. rect is transformed by Matrix before it is combined with Clip.
Sets the maximum clip rectangle, which can be set by clipRect, clipRRect and clipPath and intersect the current clip with the specified rect. The maximum clip affects only future clipping operations; it is not retroactive. The clip restriction is not recorded in pictures.
Pass an empty rect to disable maximum clip.
Replace Clip with the intersection or difference of Clip and rrect, with an Aliased or Anti-aliased clip edge. rrect is transformed by Matrix before it is combined with Clip.
Replace Clip with the intersection or difference of Clip and rrect. Resulting Clip is Aliased; pixels are fully contained by the clip. rrect is transformed by Matrix before it is combined with Clip.
Replace Clip with the intersection of Clip and rrect, with an Aliased or Anti-aliased clip edge. rrect is transformed by Matrix before it is combined with Clip.
Replace Clip with the intersection or difference of Clip and path, with an Aliased or Anti-aliased clip edge. Path Fill Type determines if path describes the area inside or outside its contours; and if Path Contour overlaps itself or another Path Contour, whether the overlaps form part of the area. path is transformed by Matrix before it is combined with Clip.
Bottom figure uses SkPath::kWinding FillType and SkClipOp::kIntersect; area inside clip is intersected with circle.
Replace Clip with the intersection or difference of Clip and path. Resulting Clip is Aliased; pixels are fully contained by the clip. Path Fill Type determines if path describes the area inside or outside its contours; and if Path Contour overlaps itself or another Path Contour, whether the overlaps form part of the area. path is transformed by Matrix before it is combined with Clip.
Replace Clip with the intersection of Clip and path. Resulting Clip is Aliased; pixels are fully contained by the clip. Path Fill Type determines if path describes the area inside or outside its contours; and if Path Contour overlaps itself or another Path Contour, whether the overlaps form part of the area. path is transformed by Matrix before it is combined with Clip.
Only used for testing.Set to simplify clip stack using PathOps.
Replace Clip with the intersection or difference of Clip and Region deviceRgn. Resulting Clip is Aliased; pixels are fully contained by the clip. deviceRgn is unaffected by Matrix.
Return true if Rect rect, transformed by Matrix, can be quickly determined to be outside of Clip. May return false even though rect is outside of Clip.
Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
true if rect, transformed by Matrix, does not intersect Clip
quickReject true quickReject false
Return true if path, transformed by Matrix, can be quickly determined to be outside of Clip. May return false even though path is outside of Clip.
Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
true if path, transformed by Matrix, does not intersect Clip
quickReject true quickReject false
Return bounds of Clip, transformed by inverse of Matrix. If Clip is empty, return SkRect::MakeEmpty, where all Rect sides equal zero.
Rect returned is outset by one to account for partial pixel coverage if Clip is Anti-aliased.
bounds of Clip in local coordinates
left:-1 top:-1 right:257 bottom:257 left:29 top:129 right:121 bottom:231 left:14.5 top:64.5 right:60.5 bottom:115.5
Return bounds of Clip, transformed by inverse of Matrix. If Clip is empty, return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero.
bounds is outset by one to account for partial pixel coverage if Clip is Anti-aliased.
true if Clip bounds is not empty
local bounds empty = false local bounds empty = true
Return IRect bounds of Clip, unaffected by Matrix. If Clip is empty, return SkRect::MakeEmpty, where all Rect sides equal zero.
Unlike getLocalClipBounds, returned IRect is not outset.
bounds of Clip in Device coordinates
left:0 top:0 right:256 bottom:256 left:30 top:130 right:120 bottom:230 left:15 top:65 right:60 bottom:115
Return IRect bounds of Clip, unaffected by Matrix. If Clip is empty, return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero.
Unlike getLocalClipBounds, bounds is not outset.
true if Clip bounds is not empty
device bounds empty = false device bounds empty = true
Fill Clip with Color color. mode determines how Color ARGB is combined with destination.
Fill Clip with Color color using SkBlendMode::kSrc. This has the effect of replacing all pixels contained by Clip with color.
Make Canvas contents undefined. Subsequent calls that read Canvas pixels, such as drawing with SkBlendMode, return undefined results. discard does not change Clip or Matrix.
discard may do nothing, depending on the implementation of Surface or Device that created Canvas.
discard allows optimized performance on subsequent draws by removing cached data associated with Surface or Device. It is not necessary to call discard once done with Canvas; any cached data is deleted when owning Surface or Device is deleted.
Fill Clip with Paint paint. Paint components Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Blend Mode affect drawing; Path Effect in paint is ignored.
Selects if an array of points are drawn as discrete points, as lines, or as an open polygon.
Draw pts using Clip, Matrix and Paint paint. count is the number of points; if count is less than one, has no effect. mode may be one of: kPoints PointMode, kLines PointMode, or kPolygon PointMode.
If mode is kPoints PointMode, the shape of point drawn depends on paint Paint Stroke Cap. If paint is set to SkPaint::kRound Cap, each point draws a circle of diameter Paint Stroke Width. If paint is set to SkPaint::kSquare Cap or SkPaint::kButt Cap, each point draws a square of width and height Paint Stroke Width.
If mode is kLines PointMode, each pair of points draws a line segment. One line is drawn for every two points; each point is used once. If count is odd, the final point is ignored.
If mode is kPolygon PointMode, each adjacent pair of points draws a line segment. count minus one lines are drawn; the first and last point are used once.
Each line segment respects paint Paint Stroke Cap and Paint Stroke Width. Paint Style is ignored, as if were set to SkPaint::kStroke Style.
Always draws each element one at a time; is not affected by Paint Stroke Join, and unlike drawPath, does not create a mask from all points and lines before drawing.
The transparent color makes multiple line draws visible; the path is drawn all at once.
Draw point at (x, y) using Clip, Matrix and Paint paint.
The shape of point drawn depends on paint Paint Stroke Cap. If paint is set to SkPaint::kRound Cap, draw a circle of diameter Paint Stroke Width. If paint is set to SkPaint::kSquare Cap or SkPaint::kButt Cap, draw a square of width and height Paint Stroke Width. Paint Style is ignored, as if were set to SkPaint::kStroke Style.
Draw point p using Clip, Matrix and Paint paint.
The shape of point drawn depends on paint Paint Stroke Cap. If paint is set to SkPaint::kRound Cap, draw a circle of diameter Paint Stroke Width. If paint is set to SkPaint::kSquare Cap or SkPaint::kButt Cap, draw a square of width and height Paint Stroke Width. Paint Style is ignored, as if were set to SkPaint::kStroke Style.
drawPoints drawCircle drawRect
Draws line segment from (x0, y0) to (x1, y1) using Clip, Matrix, and Paint paint. In paint: Paint Stroke Width describes the line thickness; Paint Stroke Cap draws the end rounded or square; Paint Style is ignored, as if were set to SkPaint::kStroke Style.
Draws line segment from p0 to p1 using Clip, Matrix, and Paint paint. In paint: Paint Stroke Width describes the line thickness; Paint Stroke Cap draws the end rounded or square; Paint Style is ignored, as if were set to SkPaint::kStroke Style.
Draw Rect rect using Clip, Matrix, and Paint paint. In paint: Paint Style determines if rectangle is stroked or filled; if stroked, Paint Stroke Width describes the line thickness, and Paint Stroke Join draws the corners rounded or square.
Draw IRect rect using Clip, Matrix, and Paint paint. In paint: Paint Style determines if rectangle is stroked or filled; if stroked, Paint Stroke Width describes the line thickness, and Paint Stroke Join draws the corners rounded or square.
Draw Region region using Clip, Matrix, and Paint paint. In paint: Paint Style determines if rectangle is stroked or filled; if stroked, Paint Stroke Width describes the line thickness, and Paint Stroke Join draws the corners rounded or square.
Draw Oval oval using Clip, Matrix, and Paint. In paint: Paint Style determines if Oval is stroked or filled; if stroked, Paint Stroke Width describes the line thickness.
Draw Round Rect rrect using Clip, Matrix, and Paint paint. In paint: Paint Style determines if rrect is stroked or filled; if stroked, Paint Stroke Width describes the line thickness.
rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or may have any combination of positive non-square radii for the four corners.
Draw Round Rect outer and inner using Clip, Matrix, and Paint paint. outer must contain inner or the drawing is undefined. In paint: Paint Style determines if Round Rect is stroked or filled; if stroked, Paint Stroke Width describes the line thickness. If stroked and Round Rect corner has zero length radii, Paint Stroke Join can draw corners rounded or square.
GPU-backed platforms optimize drawing when both outer and inner are concave and outer contains inner. These platforms may not be able to draw Path built with identical data as fast.
Draw Circle at (cx, cy) with radius using Clip, Matrix, and Paint paint. If radius is zero or less, nothing is drawn. In paint: Paint Style determines if Circle is stroked or filled; if stroked, Paint Stroke Width describes the line thickness.
Draw Circle at center with radius using Clip, Matrix, and Paint paint. If radius is zero or less, nothing is drawn. In paint: Paint Style determines if Circle is stroked or filled; if stroked, Paint Stroke Width describes the line thickness.
Draw Arc using Clip, Matrix, and Paint paint.
Arc is part of Oval bounded by oval, sweeping from startAngle to startAngle plus sweepAngle. startAngle and sweepAngle are in degrees.
startAngle of zero places start point at the right middle edge of oval. A positive sweepAngle places Arc end point clockwise from start point; a negative sweepAngle places Arc end point counterclockwise from start point. sweepAngle may exceed 360 degrees, a full circle. If useCenter is true, draw a wedge that includes lines from oval center to Arc end points. If useCenter is false, draw Arc between end points.
If Rect oval is empty or sweepAngle is zero, nothing is drawn.
Draw Round Rect bounded by Rect rect, with corner radii (rx, ry) using Clip, Matrix, and Paint paint.
In paint: Paint Style determines if Round Rect is stroked or filled; if stroked, Paint Stroke Width describes the line thickness. If rx or ry are less than zero, they are treated as if they are zero. If rx plus ry exceeds rect width or rect height, radii are scaled down to fit. If rx and ry are zero, Round Rect is drawn as Rect and if stroked is affected by Paint Stroke Join.
Draw Path path using Clip, Matrix, and Paint paint. Path contains an array of Path Contour, each of which may be open or closed.
In paint: Paint Style determines if Round Rect is stroked or filled: if filled, Path Fill Type determines whether Path Contour describes inside or outside of fill; if stroked, Paint Stroke Width describes the line thickness, Paint Stroke Cap describes line ends, and Paint Stroke Join describes how corners are drawn.
drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or a smart pointer as a convenience. The pairs of calls are otherwise identical.
Draw Image image, with its top-left corner at (left, top), using Clip, Matrix, and optional Paint paint.
If paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds. If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
Draw Image image, with its top-left corner at (left, top), using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds. If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
SrcRectConstraint controls the behavior at the edge of source Rect, provided to drawImageRect, trading off speed for precision.
Image Filter in Paint may sample multiple pixels in the image. Source Rect restricts the bounds of pixels that may be read. Image Filter may slow down if it cannot read outside the bounds, when sampling near the edge of source Rect. SrcRectConstraint specifies whether an Image Filter is allowed to read pixels outside source Rect.
Draw Rect src of Image image, scaled and translated to fill Rect dst. Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within src; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw IRect isrc of Image image, scaled and translated to fill Rect dst. Note that isrc is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within isrc; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw Image image, scaled and translated to fill Rect dst, using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within image; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw Rect src of Image image, scaled and translated to fill Rect dst. Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within src; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw IRect isrc of Image image, scaled and translated to fill Rect dst. isrc is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within image; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw Image image, scaled and translated to fill Rect dst, using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within image; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw Image image stretched proportionally to fit into Rect dst. IRect center divides the image into nine sections: four sides, four corners, and the center. Corners are unmodified or scaled down proportionately if their sides are larger than dst; center and four sides are scaled to fit remaining space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
Draw Image image stretched proportionally to fit into Rect dst. IRect center divides the image into nine sections: four sides, four corners, and the center. Corners are not scaled, or scaled down proportionately if their sides are larger than dst; center and four sides are scaled to fit remaining space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If image is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just as Shader made from SkImage::makeShader with SkShader::kClamp TileMode set replicates the image's edge color when it samples outside of its bounds.
Draw Bitmap bitmap, with its top-left corner at (left, top), using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If bitmap is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as Shader made from SkShader::MakeBitmapShader with SkShader::kClamp TileMode set replicates the bitmap's edge color when it samples outside of its bounds.
Draw Rect src of Bitmap bitmap, scaled and translated to fill Rect dst. Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If bitmap is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as Shader made from SkShader::MakeBitmapShader with SkShader::kClamp TileMode set replicates the bitmap's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within src; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw IRect isrc of Bitmap bitmap, scaled and translated to fill Rect dst. isrc is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If bitmap is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as Shader made from SkShader::MakeBitmapShader with SkShader::kClamp TileMode set replicates the bitmap's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within isrc; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw Bitmap bitmap, scaled and translated to fill Rect dst. bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If bitmap is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as Shader made from SkShader::MakeBitmapShader with SkShader::kClamp TileMode set replicates the bitmap's edge color when it samples outside of its bounds.
constraint set to kStrict SrcRectConstraint limits Paint Filter Quality to sample within bitmap; set to kFast SrcRectConstraint allows sampling outside to improve performance.
Draw Bitmap bitmap stretched proportionally to fit into Rect dst. IRect center divides the bitmap into nine sections: four sides, four corners, and the center. Corners are not scaled, or scaled down proportionately if their sides are larger than dst; center and four sides are scaled to fit remaining space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If bitmap is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as Shader made from SkShader::MakeBitmapShader with SkShader::kClamp TileMode set replicates the bitmap's edge color when it samples outside of its bounds.
Lattice divides Bitmap or Image into a rectangular grid. Grid entries on even columns and even rows are fixed; these entries are always drawn at their original size if the destination is large enough. If the destination side is too small to hold the fixed entries, all fixed entries are proportionately scaled down to fit. The grid entries not on even columns and rows are scaled to fit the remaining space, if any.
Optional setting per rectangular grid entry to make it transparent.
const int* fXDivs
Array of x-coordinates that divide the bitmap vertically. Array entries must be unique, increasing, greater than or equal to fBounds left edge, and less than fBounds right edge. Set the first element to fBounds left to collapse the left column of fixed grid entries.
const int* fYDivs
Array of y-coordinates that divide the bitmap horizontally. Array entries must be unique, increasing, greater than or equal to fBounds top edge, and less than fBounds bottom edge. Set the first element to fBounds top to collapse the top row of fixed grid entries.
const Flags* fFlags
Optional array of Flags, one per rectangular grid entry: array length must be( fXCount + 1) * (fYCount + 1).
Array entries correspond to the rectangular grid entries, ascending left to right and then top to bottom.
int fXCount
Number of entries in fXDivs array; one less than the number of horizontal divisions.
int fYCount
Number of entries in fYDivs array; one less than the number of vertical divisions.
const SkIRect* fBounds
Optional subset IRect source to draw from. If nullptr, source bounds is dimensions of Bitmap or Image.
Draw Bitmap bitmap stretched proportionally to fit into Rect dst.
Lattice lattice divides bitmap into a rectangular grid. Each intersection of an even-numbered row and column is fixed; like the corners of drawBitmapNine, fixed lattice elements never scale larger than their initial size and shrink proportionately when all fixed elements exceed the bitmap's dimension. All other grid elements scale to fill the available space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If bitmap is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as Shader made from SkShader::MakeBitmapShader with SkShader::kClamp TileMode set replicates the bitmap's edge color when it samples outside of its bounds.
Draw Image image stretched proportionally to fit into Rect dst.
Lattice lattice divides image into a rectangular grid. Each intersection of an even-numbered row and column is fixed; like the corners of drawBitmapNine, fixed lattice elements never scale larger than their initial size and shrink proportionately when all fixed elements exceed the bitmap's dimension. All other grid elements scale to fill the available space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper. If bitmap is kAlpha 8 SkColorType, apply Shader. If paint contains Mask Filter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as Shader made from SkShader::MakeBitmapShader with SkShader::kClamp TileMode set replicates the bitmap's edge color when it samples outside of its bounds.
Draw text, with origin at (x, y), using Clip, Matrix, and Paint paint.
text's meaning depends on Paint Text Encoding; by default, text encoding is UTF-8.
x and y meaning depends on Paint Text Align and Paint Vertical Text; by default text draws left to right, positioning the first glyph's left side bearing at x and its baseline at y. Text size is affected by Matrix and Paint Text Size.
All elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to text. By default, draws filled 12 point black Glyphs.
Draw null terminated string, with origin at (x, y), using Clip, Matrix, and Paint paint.
string's meaning depends on Paint Text Encoding; by default, string encoding is UTF-8. Other values of Paint Text Encoding are unlikely to produce the desired results, since zero bytes may be embedded in the string.
x and y meaning depends on Paint Text Align and Paint Vertical Text; by default string draws left to right, positioning the first glyph's left side bearing at x and its baseline at y. Text size is affected by Matrix and Paint Text Size.
All elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to text. By default, draws filled 12 point black Glyphs.
drawText
Draw null terminated string, with origin at (x, y), using Clip, Matrix, and Paint paint.
string's meaning depends on Paint Text Encoding; by default, string encoding is UTF-8. Other values of Paint Text Encoding are unlikely to produce the desired results, since zero bytes may be embedded in the string.
x and y meaning depends on Paint Text Align and Paint Vertical Text; by default string draws left to right, positioning the first glyph's left side bearing at x and its baseline at y. Text size is affected by Matrix and Paint Text Size.
All elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to text. By default, draws filled 12 point black Glyphs.
drawText
Draw each glyph in text with the origin in pos array, using Clip, Matrix, and Paint paint. The number of entries in pos array must match the number of Glyphs described by byteLength of text.
text's meaning depends on Paint Text Encoding; by default, text encoding is UTF-8. pos elements' meaning depends on Paint Text Align and Paint Vertical Text; by default each glyph's left side bearing is positioned at x and its baseline is positioned at y. Text size is affected by Matrix and Paint Text Size.
All elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to text. By default, draws filled 12 point black Glyphs.
Layout engines such as Harfbuzz typically position each glyph rather than using the font's advance widths.
Draw each glyph in text with its (x, y) origin composed from xpos array and constY, using Clip, Matrix, and Paint paint. The number of entries in xpos array must match the number of Glyphs described by byteLength of text.
text's meaning depends on Paint Text Encoding; by default, text encoding is UTF-8. xpos elements' meaning depends on Paint Text Align and Paint Vertical Text; by default each glyph's left side bearing is positioned at an xpos element and its baseline is positioned at constY. Text size is affected by Matrix and Paint Text Size.
All elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to text. By default, draws filled 12 point black Glyphs.
Layout engines such as Harfbuzz typically position each glyph rather than using the font's advance widths if all Glyphs share the same baseline.
Draw text on Path path, using Clip, Matrix, and Paint paint.
Origin of text is at distance hOffset along the path, offset by a perpendicular vector of length vOffset. If the path section corresponding the glyph advance is curved, the glyph is drawn curved to match; control points in the glyph are mapped to projected points parallel to the path. If the text's advance is larger than the path length, the excess text is clipped.
text's meaning depends on Paint Text Encoding; by default, text encoding is UTF-8. Origin meaning depends on Paint Text Align and Paint Vertical Text; by default text positions the first glyph's left side bearing at origin x and its baseline at origin y. Text size is affected by Matrix and Paint Text Size.
All elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to text. By default, draws filled 12 point black Glyphs.
Draw text on Path path, using Clip, Matrix, and Paint paint.
Origin of text is at beginning of path offset by matrix, if provided, before it is mapped to path. If the path section corresponding the glyph advance is curved, the glyph is drawn curved to match; control points in the glyph are mapped to projected points parallel to the path. If the text's advance is larger than the path length, the excess text is clipped.
text's meaning depends on Paint Text Encoding; by default, text encoding is UTF-8. Origin meaning depends on Paint Text Align and Paint Vertical Text; by default text positions the first glyph's left side bearing at origin x and its baseline at origin y. Text size is affected by Matrix and Paint Text Size.
All elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to text. By default, draws filled 12 point black Glyphs.
Draw text, transforming each glyph by the corresponding SkRSXform, using Clip, Matrix, and Paint paint.
RSXform array specifies a separate square scale, rotation, and translation for each glyph.
Optional Rect cullRect is a conservative bounds of text, taking into account RSXform and paint. If cullRect is outside of Clip, canvas can skip drawing.
All elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to text. By default, draws filled 12 point black Glyphs.
Draw Text Blob blob at (x, y), using Clip, Matrix, and Paint paint.
blob contains Glyphs, their positions, and paint attributes specific to text: Typeface, Paint Text Size, Paint Text Scale X, Paint Text Skew X, Paint Text Align, Paint Hinting, Anti-alias, Paint Fake Bold, Font Embedded Bitmaps, Full Hinting Spacing, LCD Text, Linear Text, Subpixel Text, and Paint Vertical Text.
Elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to blob.
Draw Text Blob blob at (x, y), using Clip, Matrix, and Paint paint.
blob contains Glyphs, their positions, and paint attributes specific to text: Typeface, Paint Text Size, Paint Text Scale X, Paint Text Skew X, Paint Text Align, Paint Hinting, Anti-alias, Paint Fake Bold, Font Embedded Bitmaps, Full Hinting Spacing, LCD Text, Linear Text, Subpixel Text, and Paint Vertical Text.
Elements of paint: Path Effect, Rasterizer, Mask Filter, Shader, Color Filter, Image Filter, and Draw Looper; apply to blob.
Draw Picture picture, using Clip and Matrix. Clip and Matrix are unchanged by picture contents, as if save was called before and restore was called after drawPicture.
Picture records a series of draw commands for later playback.
Draw Picture picture, using Clip and Matrix. Clip and Matrix are unchanged by picture contents, as if save was called before and restore was called after drawPicture.
Picture records a series of draw commands for later playback.
Draw Picture picture, using Clip and Matrix; transforming picture with Matrix matrix, if provided; and use Paint paint Color Alpha, Color Filter, Image Filter, and Blend Mode, if provided.
matrix transformation is equivalent to: save, concat, drawPicture, restore. paint use is equivalent to: saveLayer, drawPicture, restore.
Draw Picture picture, using Clip and Matrix; transforming picture with Matrix matrix, if provided; and use Paint paint Color Alpha, Color Filter, Image Filter, and Blend Mode, if provided.
matrix transformation is equivalent to: save, concat, drawPicture, restore. paint use is equivalent to: saveLayer, drawPicture, restore.
Draw Vertices vertices, a triangle mesh, using Clip and Matrix. If Vertices Texs and Vertices Colors are defined in vertices, and Paint paint contains Shader, Blend Mode mode combines Vertices Colors with Shader.
Draw Vertices vertices, a triangle mesh, using Clip and Matrix. If Vertices Texs and Vertices Colors are defined in vertices, and Paint paint contains Shader, Blend Mode mode combines Vertices Colors with Shader.
Draws a Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture coordinate, with each corner.
The Coons patch uses Clip and Matrix, Paint paint's Shader, Color Filter, Color Alpha, Image Filter, and Blend Mode. If Shader is provided it is treated as the Coons patch texture; Blend Mode mode combines Color colors and Shader if both are provided.
Point array cubics specifies four Cubics starting at the top left corner, in clockwise order, sharing every fourth point. The last Cubic ends at the first point.
Color array color associates colors with corners in top left, top right, bottom right, bottom left order.
If paint contains Shader, Point array texCoords maps Shader as texture to corners in top left, top right, bottom right, bottom left order.
Draws Cubic Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture coordinate, with each corner.
The Coons patch uses Clip and Matrix, Paint paint's Shader, Color Filter, Color Alpha, Image Filter, and Blend Mode. If Shader is provided it is treated as the Coons patch texture; Blend Mode mode combines Color colors and Shader if both are provided.
Point array cubics specifies four Cubics starting at the top left corner, in clockwise order, sharing every fourth point. The last Cubic ends at the first point.
Color array color associates colors with corners in top left, top right, bottom right, bottom left order.
If paint contains Shader, Point array texCoords maps Shader as texture to corners in top left, top right, bottom right, bottom left order.
Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. paint uses Anti-alias, Color Alpha, Color Filter, Image Filter, and Blend Mode to draw, if present. For each entry in the array, Rect tex locates sprite in atlas, and RSXform xform transforms it into destination space.
xform, text, and colors if present, must contain count entries. Optional colors are applied for each sprite using Blend Mode. Optional cullRect is a conservative bounds of all transformed sprites. If cullRect is outside of Clip, canvas can skip drawing.
Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. paint uses Anti-alias, Color Alpha, Color Filter, Image Filter, and Blend Mode to draw, if present. For each entry in the array, Rect tex locates sprite in atlas, and RSXform xform transforms it into destination space.
xform, text, and colors if present, must contain count entries. Optional colors is applied for each sprite using Blend Mode. Optional cullRect is a conservative bounds of all transformed sprites. If cullRect is outside of Clip, canvas can skip drawing.
Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. paint uses Anti-alias, Color Alpha, Color Filter, Image Filter, and Blend Mode to draw, if present. For each entry in the array, Rect tex locates sprite in atlas, and RSXform xform transforms it into destination space.
xform and text must contain count entries. Optional cullRect is a conservative bounds of all transformed sprites. If cullRect is outside of Clip, canvas can skip drawing.
Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. paint uses Anti-alias, Color Alpha, Color Filter, Image Filter, and Blend Mode to draw, if present. For each entry in the array, Rect tex locates sprite in atlas, and RSXform xform transforms it into destination space.
xform and text must contain count entries. Optional cullRect is a conservative bounds of all transformed sprites. If cullRect is outside of Clip, canvas can skip drawing.
Draw Drawable drawable using Clip and Matrix, concatenated with optional matrix.
If Canvas has an asynchronous implementation, as is the case when it is recording into Picture, then drawable will be referenced, so that SkDrawable::draw() can be called when the operation is finalized. To force immediate drawing, call SkDrawable::draw() instead.
Draw Drawable drawable using Clip and Matrix, offset by (x, y).
If Canvas has an asynchronous implementation, as is the case when it is recording into Picture, then drawable will be referenced, so that SkDrawable::draw() can be called when the operation is finalized. To force immediate drawing, call SkDrawable::draw() instead.
Associate Rect on Canvas when an annotation; a key-value pair, where the key is a null-terminated utf8 string, and optional value is stored as Data.
Only some canvas implementations, such as recording to Picture, or drawing to Document PDF, use annotations.
Associate Rect on Canvas when an annotation; a key-value pair, where the key is a null-terminated utf8 string, and optional value is stored as Data.
Only some canvas implementations, such as recording to Picture, or drawing to Document PDF, use annotations.
Legacy call to be deprecated.
Legacy call to be deprecated.
Returns true if Clip is empty; that is, nothing will draw.
May do work when called; it should not be called more often than needed. However, once called, subsequent calls perform no work until Clip changes.
true if Clip is empty
clip is not empty clip is empty
Returns true if Clip is Rect and not empty. Returns false if the clip is empty, or if it is not Rect.
true if Clip is Rect and not empty
clip is rect clip is not rect