Skia
2D Graphics Library
SkCanvas Class Reference

SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed. More...

#include <SkCanvas.h>

Classes

struct  ImageSetEntry
 This is used by the experimental API below. More...
 
struct  Lattice
 SkCanvas::Lattice divides SkBitmap or SkImage into a rectangular grid. More...
 
struct  SaveLayerRec
 SaveLayerRec contains the state used to create the layer. More...
 

Public Types

enum  SaveLayerFlagsSet { kInitWithPrevious_SaveLayerFlag = 1 << 2, kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag, kF16ColorType = 1 << 4 }
 
enum  PointMode { kPoints_PointMode, kLines_PointMode, kPolygon_PointMode }
 
enum  SrcRectConstraint { kStrict_SrcRectConstraint, kFast_SrcRectConstraint }
 
enum  QuadAAFlags : unsigned {
  kLeft_QuadAAFlag = 0b0001, kTop_QuadAAFlag = 0b0010, kRight_QuadAAFlag = 0b0100, kBottom_QuadAAFlag = 0b1000,
  kNone_QuadAAFlags = 0b0000, kAll_QuadAAFlags = 0b1111
}
 Experimental. More...
 
typedef uint32_t SaveLayerFlags
 

Public Member Functions

 SkCanvas ()
 Creates an empty SkCanvas with no backing device or pixels, with a width and height of zero. More...
 
 SkCanvas (int width, int height, const SkSurfaceProps *props=nullptr)
 Creates SkCanvas of the specified dimensions without a SkSurface. More...
 
 SkCanvas (sk_sp< SkBaseDevice > device)
 Private. More...
 
 SkCanvas (const SkBitmap &bitmap)
 Constructs a canvas that draws into bitmap. More...
 
 SkCanvas (const SkBitmap &bitmap, const SkSurfaceProps &props)
 Constructs a canvas that draws into bitmap. More...
 
virtual ~SkCanvas ()
 Draws saved layers, if any. More...
 
SkImageInfo imageInfo () const
 Returns SkImageInfo for SkCanvas. More...
 
bool getProps (SkSurfaceProps *props) const
 Copies SkSurfaceProps, if SkCanvas is associated with raster surface or GPU surface, and returns true. More...
 
void flush ()
 Triggers the immediate execution of all pending draw operations. More...
 
virtual SkISize getBaseLayerSize () const
 Gets the size of the base or root layer in global canvas coordinates. More...
 
sk_sp< SkSurfacemakeSurface (const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
 Creates SkSurface matching info and props, and associates it with SkCanvas. More...
 
virtual GrContextgetGrContext ()
 Returns GPU context of the GPU surface associated with SkCanvas. More...
 
SkSurfacegetSurface () const
 Sometimes a canvas is owned by a surface. More...
 
void * accessTopLayerPixels (SkImageInfo *info, size_t *rowBytes, SkIPoint *origin=nullptr)
 Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels can be read directly. More...
 
SkRasterHandleAllocator::Handle accessTopRasterHandle () const
 Returns custom context that tracks the SkMatrix and clip. More...
 
bool peekPixels (SkPixmap *pixmap)
 Returns true if SkCanvas has direct access to its pixels. More...
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY)
 Copies SkRect of pixels from SkCanvas into dstPixels. More...
 
bool readPixels (const SkPixmap &pixmap, int srcX, int srcY)
 Copies SkRect of pixels from SkCanvas into pixmap. More...
 
bool readPixels (const SkBitmap &bitmap, int srcX, int srcY)
 Copies SkRect of pixels from SkCanvas into bitmap. More...
 
bool writePixels (const SkImageInfo &info, const void *pixels, size_t rowBytes, int x, int y)
 Copies SkRect from pixels to SkCanvas. More...
 
bool writePixels (const SkBitmap &bitmap, int x, int y)
 Copies SkRect from pixels to SkCanvas. More...
 
int save ()
 Saves SkMatrix and clip. More...
 
int saveLayer (const SkRect *bounds, const SkPaint *paint)
 Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing. More...
 
int saveLayer (const SkRect &bounds, const SkPaint *paint)
 Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing. More...
 
int saveLayerAlpha (const SkRect *bounds, U8CPU alpha)
 Saves SkMatrix and clip, and allocates SkBitmap for subsequent drawing. More...
 
int saveLayer (const SaveLayerRec &layerRec)
 Saves SkMatrix and clip, and allocates SkBitmap for subsequent drawing. More...
 
int experimental_saveCamera (const SkM44 &projection, const SkM44 &camera)
 
int experimental_saveCamera (const SkScalar projection[16], const SkScalar camera[16])
 
void restore ()
 Removes changes to SkMatrix and clip since SkCanvas state was last saved. More...
 
int getSaveCount () const
 Returns the number of saved states, each containing: SkMatrix and clip. More...
 
void restoreToCount (int saveCount)
 Restores state to SkMatrix and clip values when save(), saveLayer(), saveLayerPreserveLCDTextRequests(), or saveLayerAlpha() returned saveCount. More...
 
void translate (SkScalar dx, SkScalar dy)
 Translates SkMatrix by dx along the x-axis and dy along the y-axis. More...
 
void scale (SkScalar sx, SkScalar sy)
 Scales SkMatrix by sx on the x-axis and sy on the y-axis. More...
 
void rotate (SkScalar degrees)
 Rotates SkMatrix by degrees. More...
 
void rotate (SkScalar degrees, SkScalar px, SkScalar py)
 Rotates SkMatrix by degrees about a point at (px, py). More...
 
void skew (SkScalar sx, SkScalar sy)
 Skews SkMatrix by sx on the x-axis and sy on the y-axis. More...
 
void concat (const SkMatrix &matrix)
 Replaces SkMatrix with matrix premultiplied with existing SkMatrix. More...
 
void experimental_concat44 (const SkM44 &)
 
void experimental_concat44 (const SkScalar[])
 
void setMatrix (const SkMatrix &matrix)
 Replaces SkMatrix with matrix. More...
 
void resetMatrix ()
 Sets SkMatrix to the identity matrix. More...
 
void clipRect (const SkRect &rect, SkClipOp op, bool doAntiAlias)
 Replaces clip with the intersection or difference of clip and rect, with an aliased or anti-aliased clip edge. More...
 
void clipRect (const SkRect &rect, SkClipOp op)
 Replaces clip with the intersection or difference of clip and rect. More...
 
void clipRect (const SkRect &rect, bool doAntiAlias=false)
 Replaces clip with the intersection of clip and rect. More...
 
void androidFramework_setDeviceClipRestriction (const SkIRect &rect)
 Sets the maximum clip rectangle, which can be set by clipRect(), clipRRect() and clipPath() and intersect the current clip with the specified rect. More...
 
void clipRRect (const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
 Replaces clip with the intersection or difference of clip and rrect, with an aliased or anti-aliased clip edge. More...
 
void clipRRect (const SkRRect &rrect, SkClipOp op)
 Replaces clip with the intersection or difference of clip and rrect. More...
 
void clipRRect (const SkRRect &rrect, bool doAntiAlias=false)
 Replaces clip with the intersection of clip and rrect, with an aliased or anti-aliased clip edge. More...
 
void clipPath (const SkPath &path, SkClipOp op, bool doAntiAlias)
 Replaces clip with the intersection or difference of clip and path, with an aliased or anti-aliased clip edge. More...
 
void clipPath (const SkPath &path, SkClipOp op)
 Replaces clip with the intersection or difference of clip and path. More...
 
void clipPath (const SkPath &path, bool doAntiAlias=false)
 Replaces clip with the intersection of clip and path. More...
 
void clipRegion (const SkRegion &deviceRgn, SkClipOp op=SkClipOp::kIntersect)
 Replaces clip with the intersection or difference of clip and SkRegion deviceRgn. More...
 
bool quickReject (const SkRect &rect) const
 Returns true if SkRect rect, transformed by SkMatrix, can be quickly determined to be outside of clip. More...
 
bool quickReject (const SkPath &path) const
 Returns true if path, transformed by SkMatrix, can be quickly determined to be outside of clip. More...
 
SkRect getLocalClipBounds () const
 Returns bounds of clip, transformed by inverse of SkMatrix. More...
 
bool getLocalClipBounds (SkRect *bounds) const
 Returns bounds of clip, transformed by inverse of SkMatrix. More...
 
SkIRect getDeviceClipBounds () const
 Returns SkIRect bounds of clip, unaffected by SkMatrix. More...
 
bool getDeviceClipBounds (SkIRect *bounds) const
 Returns SkIRect bounds of clip, unaffected by SkMatrix. More...
 
void drawColor (SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
 Fills clip with color color. More...
 
void clear (SkColor color)
 Fills clip with color color using SkBlendMode::kSrc. More...
 
void discard ()
 Makes SkCanvas contents undefined. More...
 
void drawPaint (const SkPaint &paint)
 Fills clip with SkPaint paint. More...
 
void drawPoints (PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
 Draws pts using clip, SkMatrix and SkPaint paint. More...
 
void drawPoint (SkScalar x, SkScalar y, const SkPaint &paint)
 Draws point at (x, y) using clip, SkMatrix and SkPaint paint. More...
 
void drawPoint (SkPoint p, const SkPaint &paint)
 Draws point p using clip, SkMatrix and SkPaint paint. More...
 
void drawLine (SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
 Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint. More...
 
void drawLine (SkPoint p0, SkPoint p1, const SkPaint &paint)
 Draws line segment from p0 to p1 using clip, SkMatrix, and SkPaint paint. More...
 
void drawRect (const SkRect &rect, const SkPaint &paint)
 Draws SkRect rect using clip, SkMatrix, and SkPaint paint. More...
 
void drawIRect (const SkIRect &rect, const SkPaint &paint)
 Draws SkIRect rect using clip, SkMatrix, and SkPaint paint. More...
 
void drawRegion (const SkRegion &region, const SkPaint &paint)
 Draws SkRegion region using clip, SkMatrix, and SkPaint paint. More...
 
void drawOval (const SkRect &oval, const SkPaint &paint)
 Draws oval oval using clip, SkMatrix, and SkPaint. More...
 
void drawRRect (const SkRRect &rrect, const SkPaint &paint)
 Draws SkRRect rrect using clip, SkMatrix, and SkPaint paint. More...
 
void drawDRRect (const SkRRect &outer, const SkRRect &inner, const SkPaint &paint)
 Draws SkRRect outer and inner using clip, SkMatrix, and SkPaint paint. More...
 
void drawCircle (SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
 Draws circle at (cx, cy) with radius using clip, SkMatrix, and SkPaint paint. More...
 
void drawCircle (SkPoint center, SkScalar radius, const SkPaint &paint)
 Draws circle at center with radius using clip, SkMatrix, and SkPaint paint. More...
 
void drawArc (const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
 Draws arc using clip, SkMatrix, and SkPaint paint. More...
 
void drawRoundRect (const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint)
 Draws SkRRect bounded by SkRect rect, with corner radii (rx, ry) using clip, SkMatrix, and SkPaint paint. More...
 
void drawPath (const SkPath &path, const SkPaint &paint)
 Draws SkPath path using clip, SkMatrix, and SkPaint paint. More...
 
void drawImage (const SkImage *image, SkScalar left, SkScalar top, const SkPaint *paint=nullptr)
 Draws SkImage image, with its top-left corner at (left, top), using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawImage (const sk_sp< SkImage > &image, SkScalar left, SkScalar top, const SkPaint *paint=nullptr)
 Draws SkImage image, with its top-left corner at (left, top), using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawImageRect (const SkImage *image, const SkRect &src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 Draws SkRect src of SkImage image, scaled and translated to fill SkRect dst. More...
 
void drawImageRect (const SkImage *image, const SkIRect &isrc, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 Draws SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst. More...
 
void drawImageRect (const SkImage *image, const SkRect &dst, const SkPaint *paint)
 Draws SkImage image, scaled and translated to fill SkRect dst, using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawImageRect (const sk_sp< SkImage > &image, const SkRect &src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 Draws SkRect src of SkImage image, scaled and translated to fill SkRect dst. More...
 
void drawImageRect (const sk_sp< SkImage > &image, const SkIRect &isrc, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 Draws SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst. More...
 
void drawImageRect (const sk_sp< SkImage > &image, const SkRect &dst, const SkPaint *paint)
 Draws SkImage image, scaled and translated to fill SkRect dst, using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawImageNine (const SkImage *image, const SkIRect &center, const SkRect &dst, const SkPaint *paint=nullptr)
 Draws SkImage image stretched proportionally to fit into SkRect dst. More...
 
void drawImageNine (const sk_sp< SkImage > &image, const SkIRect &center, const SkRect &dst, const SkPaint *paint=nullptr)
 Draws SkImage image stretched proportionally to fit into SkRect dst. More...
 
void drawBitmap (const SkBitmap &bitmap, SkScalar left, SkScalar top, const SkPaint *paint=nullptr)
 Draws SkBitmap bitmap, with its top-left corner at (left, top), using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawBitmapRect (const SkBitmap &bitmap, const SkRect &src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 Draws SkRect src of SkBitmap bitmap, scaled and translated to fill SkRect dst. More...
 
void drawBitmapRect (const SkBitmap &bitmap, const SkIRect &isrc, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 Draws SkIRect isrc of SkBitmap bitmap, scaled and translated to fill SkRect dst. More...
 
void drawBitmapRect (const SkBitmap &bitmap, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 Draws SkBitmap bitmap, scaled and translated to fill SkRect dst. More...
 
void drawBitmapNine (const SkBitmap &bitmap, const SkIRect &center, const SkRect &dst, const SkPaint *paint=nullptr)
 Draws SkBitmap bitmap stretched proportionally to fit into SkRect dst. More...
 
void drawBitmapLattice (const SkBitmap &bitmap, const Lattice &lattice, const SkRect &dst, const SkPaint *paint=nullptr)
 Draws SkBitmap bitmap stretched proportionally to fit into SkRect dst. More...
 
void drawImageLattice (const SkImage *image, const Lattice &lattice, const SkRect &dst, const SkPaint *paint=nullptr)
 Draws SkImage image stretched proportionally to fit into SkRect dst. More...
 
void experimental_DrawEdgeAAQuad (const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
 This is an experimental API for the SkiaRenderer Chromium project, and its API will surely evolve if it is not removed outright. More...
 
void experimental_DrawEdgeAAQuad (const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, SkColor color, SkBlendMode mode)
 
void experimental_DrawEdgeAAImageSet (const ImageSetEntry imageSet[], int cnt, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkPaint *paint=nullptr, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 This is an bulk variant of experimental_DrawEdgeAAQuad() that renders 'cnt' textured quads. More...
 
void drawSimpleText (const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
 Draws text, with origin at (x, y), using clip, SkMatrix, SkFont font, and SkPaint paint. More...
 
void drawString (const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
 Draws null terminated string, with origin at (x, y), using clip, SkMatrix, SkFont font, and SkPaint paint. More...
 
void drawString (const SkString &str, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
 Draws SkString, with origin at (x, y), using clip, SkMatrix, SkFont font, and SkPaint paint. More...
 
void drawTextBlob (const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
 Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint. More...
 
void drawTextBlob (const sk_sp< SkTextBlob > &blob, SkScalar x, SkScalar y, const SkPaint &paint)
 Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint. More...
 
void drawPicture (const SkPicture *picture)
 Draws SkPicture picture, using clip and SkMatrix. More...
 
void drawPicture (const sk_sp< SkPicture > &picture)
 Draws SkPicture picture, using clip and SkMatrix. More...
 
void drawPicture (const SkPicture *picture, const SkMatrix *matrix, const SkPaint *paint)
 Draws SkPicture picture, using clip and SkMatrix; transforming picture with SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter, SkImageFilter, and SkBlendMode, if provided. More...
 
void drawPicture (const sk_sp< SkPicture > &picture, const SkMatrix *matrix, const SkPaint *paint)
 Draws SkPicture picture, using clip and SkMatrix; transforming picture with SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter, SkImageFilter, and SkBlendMode, if provided. More...
 
void drawVertices (const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
 Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. More...
 
void drawVertices (const sk_sp< SkVertices > &vertices, SkBlendMode mode, const SkPaint &paint)
 Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. More...
 
void drawVertices (const SkVertices *vertices, const SkVertices::Bone bones[], int boneCount, SkBlendMode mode, const SkPaint &paint)
 Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. More...
 
void drawVertices (const sk_sp< SkVertices > &vertices, const SkVertices::Bone bones[], int boneCount, SkBlendMode mode, const SkPaint &paint)
 Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. More...
 
void drawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode mode, const SkPaint &paint)
 Draws a Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture SkPoint, with each corner. More...
 
void drawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], const SkPaint &paint)
 Draws SkPath cubic Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture SkPoint, with each corner. More...
 
void drawAtlas (const SkImage *atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkBlendMode mode, const SkRect *cullRect, const SkPaint *paint)
 Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawAtlas (const sk_sp< SkImage > &atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkBlendMode mode, const SkRect *cullRect, const SkPaint *paint)
 Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawAtlas (const SkImage *atlas, const SkRSXform xform[], const SkRect tex[], int count, const SkRect *cullRect, const SkPaint *paint)
 Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawAtlas (const sk_sp< SkImage > &atlas, const SkRSXform xform[], const SkRect tex[], int count, const SkRect *cullRect, const SkPaint *paint)
 Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint. More...
 
void drawDrawable (SkDrawable *drawable, const SkMatrix *matrix=nullptr)
 Draws SkDrawable drawable using clip and SkMatrix, concatenated with optional matrix. More...
 
void drawDrawable (SkDrawable *drawable, SkScalar x, SkScalar y)
 Draws SkDrawable drawable using clip and SkMatrix, offset by (x, y). More...
 
void drawAnnotation (const SkRect &rect, const char key[], SkData *value)
 Associates SkRect on SkCanvas with an annotation; a key-value pair, where the key is a null-terminated UTF-8 string, and optional value is stored as SkData. More...
 
void drawAnnotation (const SkRect &rect, const char key[], const sk_sp< SkData > &value)
 Associates SkRect on SkCanvas when an annotation; a key-value pair, where the key is a null-terminated UTF-8 string, and optional value is stored as SkData. More...
 
virtual bool isClipEmpty () const
 Returns true if clip is empty; that is, nothing will draw. More...
 
virtual bool isClipRect () const
 Returns true if clip is SkRect and not empty. More...
 
SkMatrix getTotalMatrix () const
 Returns SkMatrix. More...
 
SkM44 experimental_getLocalToDevice () const
 
SkM44 experimental_getLocalToWorld () const
 
SkM44 experimental_getLocalToCamera () const
 
void experimental_getLocalToDevice (SkScalar colMajor[16]) const
 
void experimental_getLocalToWorld (SkScalar colMajor[16]) const
 
void experimental_getLocalToCamera (SkScalar colMajor[16]) const
 
virtual GrRenderTargetContext * internal_private_accessTopLayerRenderTargetContext ()
 
SkIRect internal_private_getTopLayerBounds () const
 
void legacy_drawImageRect (const SkImage *image, const SkRect *src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 
void legacy_drawBitmapRect (const SkBitmap &bitmap, const SkRect *src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 
void temporary_internal_getRgnClip (SkRegion *region)
 Returns the global clip as a region. More...
 
void private_draw_shadow_rec (const SkPath &, const SkDrawShadowRec &)
 

Static Public Member Functions

static std::unique_ptr< SkCanvasMakeRasterDirect (const SkImageInfo &info, void *pixels, size_t rowBytes, const SkSurfaceProps *props=nullptr)
 Allocates raster SkCanvas that will draw directly into pixels. More...
 
static std::unique_ptr< SkCanvasMakeRasterDirectN32 (int width, int height, SkPMColor *pixels, size_t rowBytes)
 Allocates raster SkCanvas specified by inline image specification. More...
 

Protected Types

enum  SaveLayerStrategy { kFullLayer_SaveLayerStrategy, kNoLayer_SaveLayerStrategy }
 
enum  ClipEdgeStyle { kHard_ClipEdgeStyle, kSoft_ClipEdgeStyle }
 

Protected Member Functions

virtual sk_sp< SkSurfaceonNewSurface (const SkImageInfo &info, const SkSurfaceProps &props)
 
virtual bool onPeekPixels (SkPixmap *pixmap)
 
virtual bool onAccessTopLayerPixels (SkPixmap *pixmap)
 
virtual SkImageInfo onImageInfo () const
 
virtual bool onGetProps (SkSurfaceProps *props) const
 
virtual void onFlush ()
 
virtual void willSave ()
 
virtual SaveLayerStrategy getSaveLayerStrategy (const SaveLayerRec &)
 
virtual bool onDoSaveBehind (const SkRect *)
 
virtual void willRestore ()
 
virtual void didRestore ()
 
virtual void didConcat44 (const SkScalar[])
 
virtual void didConcat (const SkMatrix &)
 
virtual void didSetMatrix (const SkMatrix &)
 
virtual void didTranslate (SkScalar, SkScalar)
 
virtual void didScale (SkScalar, SkScalar)
 
virtual void onDrawPaint (const SkPaint &paint)
 
virtual void onDrawBehind (const SkPaint &paint)
 
virtual void onDrawRect (const SkRect &rect, const SkPaint &paint)
 
virtual void onDrawRRect (const SkRRect &rrect, const SkPaint &paint)
 
virtual void onDrawDRRect (const SkRRect &outer, const SkRRect &inner, const SkPaint &paint)
 
virtual void onDrawOval (const SkRect &rect, const SkPaint &paint)
 
virtual void onDrawArc (const SkRect &rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
 
virtual void onDrawPath (const SkPath &path, const SkPaint &paint)
 
virtual void onDrawRegion (const SkRegion &region, const SkPaint &paint)
 
virtual void onDrawTextBlob (const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
 
virtual void onDrawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode mode, const SkPaint &paint)
 
virtual void onDrawPoints (PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
 
virtual void onDrawVerticesObject (const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
 
virtual void onDrawVerticesObject (const SkVertices *vertices, const SkVertices::Bone bones[], int boneCount, SkBlendMode mode, const SkPaint &paint)
 
virtual void onDrawImage (const SkImage *image, SkScalar dx, SkScalar dy, const SkPaint *paint)
 
virtual void onDrawImageRect (const SkImage *image, const SkRect *src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint)
 
virtual void onDrawImageNine (const SkImage *image, const SkIRect &center, const SkRect &dst, const SkPaint *paint)
 
virtual void onDrawImageLattice (const SkImage *image, const Lattice &lattice, const SkRect &dst, const SkPaint *paint)
 
virtual void onDrawBitmap (const SkBitmap &bitmap, SkScalar dx, SkScalar dy, const SkPaint *paint)
 
virtual void onDrawBitmapRect (const SkBitmap &bitmap, const SkRect *src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint)
 
virtual void onDrawBitmapNine (const SkBitmap &bitmap, const SkIRect &center, const SkRect &dst, const SkPaint *paint)
 
virtual void onDrawBitmapLattice (const SkBitmap &bitmap, const Lattice &lattice, const SkRect &dst, const SkPaint *paint)
 
virtual void onDrawAtlas (const SkImage *atlas, const SkRSXform xform[], const SkRect rect[], const SkColor colors[], int count, SkBlendMode mode, const SkRect *cull, const SkPaint *paint)
 
virtual void onDrawAnnotation (const SkRect &rect, const char key[], SkData *value)
 
virtual void onDrawShadowRec (const SkPath &, const SkDrawShadowRec &)
 
virtual void onDrawDrawable (SkDrawable *drawable, const SkMatrix *matrix)
 
virtual void onDrawPicture (const SkPicture *picture, const SkMatrix *matrix, const SkPaint *paint)
 
virtual void onDrawEdgeAAQuad (const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
 
virtual void onDrawEdgeAAImageSet (const ImageSetEntry imageSet[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkPaint *paint, SrcRectConstraint constraint)
 
virtual void onClipRect (const SkRect &rect, SkClipOp op, ClipEdgeStyle edgeStyle)
 
virtual void onClipRRect (const SkRRect &rrect, SkClipOp op, ClipEdgeStyle edgeStyle)
 
virtual void onClipPath (const SkPath &path, SkClipOp op, ClipEdgeStyle edgeStyle)
 
virtual void onClipRegion (const SkRegion &deviceRgn, SkClipOp op)
 
virtual void onDiscard ()
 
bool clipRectBounds (const SkRect *bounds, SaveLayerFlags flags, SkIRect *intersection, const SkImageFilter *imageFilter=nullptr)
 
SkBaseDevice * getTopDevice () const
 
 SkCanvas (const SkIRect &bounds)
 

Friends

class SkSurface_Base
 
class SkSurface_Gpu
 
class SkAndroidFrameworkUtils
 
class SkCanvasPriv
 
class SkDrawIter
 
class AutoLayerForImageFilter
 
class SkSurface_Raster
 
class SkNoDrawCanvas
 
class SkPictureRecord
 
class SkOverdrawCanvas
 
class SkRasterHandleAllocator
 
class SkCanvasStateUtils
 

Detailed Description

SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.

SkCanvas contains a stack of SkMatrix and clip values.

SkCanvas and SkPaint together provide the state to draw into SkSurface or SkBaseDevice. Each SkCanvas draw call transforms the geometry of the object by the concatenation of all SkMatrix values in the stack. The transformed geometry is clipped by the intersection of all of clip values in the stack. The SkCanvas draw calls use SkPaint to supply drawing state such as color, SkTypeface, text size, stroke width, SkShader and so on.

To draw to a pixel-based destination, create raster surface or GPU surface. Request SkCanvas from SkSurface to obtain the interface to draw. SkCanvas generated by raster surface draws to memory visible to the CPU. SkCanvas generated by GPU surface uses Vulkan or OpenGL to draw to the GPU.

To draw to a document, obtain SkCanvas from SVG canvas, document PDF, or SkPictureRecorder. SkDocument based SkCanvas and other SkCanvas subclasses reference SkBaseDevice describing the destination.

SkCanvas can be constructed to draw to SkBitmap without first creating raster surface. This approach may be deprecated in the future.

Member Typedef Documentation

◆ SaveLayerFlags

typedef uint32_t SkCanvas::SaveLayerFlags

Member Enumeration Documentation

◆ ClipEdgeStyle

enum SkCanvas::ClipEdgeStyle
protected
Enumerator
kHard_ClipEdgeStyle 
kSoft_ClipEdgeStyle 

◆ PointMode

Enumerator
kPoints_PointMode 

draw each point separately

kLines_PointMode 

draw each pair of points as a line segment

kPolygon_PointMode 

draw the array of points as a open polygon

◆ QuadAAFlags

enum SkCanvas::QuadAAFlags : unsigned

Experimental.

Controls anti-aliasing of each edge of images in an image-set.

Enumerator
kLeft_QuadAAFlag 
kTop_QuadAAFlag 
kRight_QuadAAFlag 
kBottom_QuadAAFlag 
kNone_QuadAAFlags 
kAll_QuadAAFlags 

◆ SaveLayerFlagsSet

Enumerator
kInitWithPrevious_SaveLayerFlag 

initializes with previous contents

kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag 

experimental: do not use

kF16ColorType 

◆ SaveLayerStrategy

Enumerator
kFullLayer_SaveLayerStrategy 
kNoLayer_SaveLayerStrategy 

◆ SrcRectConstraint

Enumerator
kStrict_SrcRectConstraint 

sample only inside bounds; slower

kFast_SrcRectConstraint 

sample outside bounds; faster

Constructor & Destructor Documentation

◆ SkCanvas() [1/6]

SkCanvas::SkCanvas ( )

Creates an empty SkCanvas with no backing device or pixels, with a width and height of zero.

Returns
empty SkCanvas

example: https://fiddle.skia.org/c/@Canvas_empty_constructor

◆ SkCanvas() [2/6]

SkCanvas::SkCanvas ( int  width,
int  height,
const SkSurfaceProps props = nullptr 
)

Creates SkCanvas of the specified dimensions without a SkSurface.

Used by subclasses with custom implementations for draw member functions.

If props equals nullptr, SkSurfaceProps are created with SkSurfaceProps::InitType 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.

Parameters
widthzero or greater
heightzero or greater
propsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkCanvas placeholder with dimensions

example: https://fiddle.skia.org/c/@Canvas_int_int_const_SkSurfaceProps_star

◆ SkCanvas() [3/6]

SkCanvas::SkCanvas ( sk_sp< SkBaseDevice >  device)
explicit

Private.

For internal use only.

◆ SkCanvas() [4/6]

SkCanvas::SkCanvas ( const SkBitmap bitmap)
explicit

Constructs a canvas that draws into bitmap.

Sets SkSurfaceProps::kLegacyFontHost_InitType in constructed SkSurface.

SkBitmap is copied so that subsequently editing bitmap will not affect constructed SkCanvas.

May be deprecated in the future.

Parameters
bitmapwidth, height, SkColorType, SkAlphaType, and pixel storage of raster surface
Returns
SkCanvas that can be used to draw into bitmap

example: https://fiddle.skia.org/c/@Canvas_copy_const_SkBitmap

◆ SkCanvas() [5/6]

SkCanvas::SkCanvas ( const SkBitmap bitmap,
const SkSurfaceProps props 
)

Constructs 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 SkCanvas.

Parameters
bitmapwidth, height, SkColorType, SkAlphaType, and pixel storage of raster surface
propsorder and orientation of RGB striping; and whether to use device independent fonts
Returns
SkCanvas that can be used to draw into bitmap

example: https://fiddle.skia.org/c/@Canvas_const_SkBitmap_const_SkSurfaceProps

◆ ~SkCanvas()

virtual SkCanvas::~SkCanvas ( )
virtual

Draws saved layers, if any.

Frees up resources used by SkCanvas.

example: https://fiddle.skia.org/c/@Canvas_destructor

◆ SkCanvas() [6/6]

SkCanvas::SkCanvas ( const SkIRect bounds)
protected

Member Function Documentation

◆ accessTopLayerPixels()

void* SkCanvas::accessTopLayerPixels ( SkImageInfo info,
size_t *  rowBytes,
SkIPoint origin = nullptr 
)

Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels can be read directly.

The returned address is only valid while SkCanvas is in scope and unchanged. Any SkCanvas call or SkSurface call may invalidate the returned address and other returned values.

If pixels are inaccessible, info, rowBytes, and origin are unchanged.

Parameters
infostorage for writable pixels' SkImageInfo; may be nullptr
rowBytesstorage for writable pixels' row bytes; may be nullptr
originstorage for SkCanvas top layer origin, its top-left corner; may be nullptr
Returns
address of pixels, or nullptr if inaccessible

example: https://fiddle.skia.org/c/@Canvas_accessTopLayerPixels_a example: https://fiddle.skia.org/c/@Canvas_accessTopLayerPixels_b

◆ accessTopRasterHandle()

SkRasterHandleAllocator::Handle SkCanvas::accessTopRasterHandle ( ) const

Returns custom context that tracks the SkMatrix and clip.

Use SkRasterHandleAllocator to blend Skia drawing with custom drawing, typically performed by the host platform user interface. The custom context returned is generated by SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for the drawing destination.

Returns
context of custom allocation

example: https://fiddle.skia.org/c/@Canvas_accessTopRasterHandle

◆ androidFramework_setDeviceClipRestriction()

void SkCanvas::androidFramework_setDeviceClipRestriction ( const SkIRect rect)

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. This private API is for use by Android framework only.

Parameters
rectmaximum allowed clip in device coordinates

◆ clear()

void SkCanvas::clear ( SkColor  color)
inline

Fills clip with color color using SkBlendMode::kSrc.

This has the effect of replacing all pixels contained by clip with color.

Parameters
colorunpremultiplied ARGB

◆ clipPath() [1/3]

void SkCanvas::clipPath ( const SkPath path,
SkClipOp  op,
bool  doAntiAlias 
)

Replaces clip with the intersection or difference of clip and path, with an aliased or anti-aliased clip edge.

SkPath::FillType 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 SkMatrix before it is combined with clip.

Parameters
pathSkPath to combine with clip
opSkClipOp to apply to clip
doAntiAliastrue if clip is to be anti-aliased

example: https://fiddle.skia.org/c/@Canvas_clipPath

◆ clipPath() [2/3]

void SkCanvas::clipPath ( const SkPath path,
SkClipOp  op 
)
inline

Replaces clip with the intersection or difference of clip and path.

Resulting clip is aliased; pixels are fully contained by the clip. SkPath::FillType 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 SkMatrix before it is combined with clip.

Parameters
pathSkPath to combine with clip
opSkClipOp to apply to clip

◆ clipPath() [3/3]

void SkCanvas::clipPath ( const SkPath path,
bool  doAntiAlias = false 
)
inline

Replaces clip with the intersection of clip and path.

Resulting clip is aliased; pixels are fully contained by the clip. SkPath::FillType 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 SkMatrix before it is combined with clip.

Parameters
pathSkPath to combine with clip
doAntiAliastrue if clip is to be anti-aliased

◆ clipRect() [1/3]

void SkCanvas::clipRect ( const SkRect rect,
SkClipOp  op,
bool  doAntiAlias 
)

Replaces clip with the intersection or difference of clip and rect, with an aliased or anti-aliased clip edge.

rect is transformed by SkMatrix before it is combined with clip.

Parameters
rectSkRect to combine with clip
opSkClipOp to apply to clip
doAntiAliastrue if clip is to be anti-aliased

example: https://fiddle.skia.org/c/@Canvas_clipRect

◆ clipRect() [2/3]

void SkCanvas::clipRect ( const SkRect rect,
SkClipOp  op 
)
inline

Replaces 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 SkMatrix before it is combined with clip.

Parameters
rectSkRect to combine with clip
opSkClipOp to apply to clip

◆ clipRect() [3/3]

void SkCanvas::clipRect ( const SkRect rect,
bool  doAntiAlias = false 
)
inline

Replaces clip with the intersection of clip and rect.

Resulting clip is aliased; pixels are fully contained by the clip. rect is transformed by SkMatrix before it is combined with clip.

Parameters
rectSkRect to combine with clip
doAntiAliastrue if clip is to be anti-aliased

◆ clipRectBounds()

bool SkCanvas::clipRectBounds ( const SkRect bounds,
SaveLayerFlags  flags,
SkIRect intersection,
const SkImageFilter imageFilter = nullptr 
)
protected

◆ clipRegion()

void SkCanvas::clipRegion ( const SkRegion deviceRgn,
SkClipOp  op = SkClipOp::kIntersect 
)

Replaces clip with the intersection or difference of clip and SkRegion deviceRgn.

Resulting clip is aliased; pixels are fully contained by the clip. deviceRgn is unaffected by SkMatrix.

Parameters
deviceRgnSkRegion to combine with clip
opSkClipOp to apply to clip

example: https://fiddle.skia.org/c/@Canvas_clipRegion

◆ clipRRect() [1/3]

void SkCanvas::clipRRect ( const SkRRect rrect,
SkClipOp  op,
bool  doAntiAlias 
)

Replaces clip with the intersection or difference of clip and rrect, with an aliased or anti-aliased clip edge.

rrect is transformed by SkMatrix before it is combined with clip.

Parameters
rrectSkRRect to combine with clip
opSkClipOp to apply to clip
doAntiAliastrue if clip is to be anti-aliased

example: https://fiddle.skia.org/c/@Canvas_clipRRect

◆ clipRRect() [2/3]

void SkCanvas::clipRRect ( const SkRRect rrect,
SkClipOp  op 
)
inline

Replaces 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 SkMatrix before it is combined with clip.

Parameters
rrectSkRRect to combine with clip
opSkClipOp to apply to clip

◆ clipRRect() [3/3]

void SkCanvas::clipRRect ( const SkRRect rrect,
bool  doAntiAlias = false 
)
inline

Replaces clip with the intersection of clip and rrect, with an aliased or anti-aliased clip edge.

rrect is transformed by SkMatrix before it is combined with clip.

Parameters
rrectSkRRect to combine with clip
doAntiAliastrue if clip is to be anti-aliased

◆ concat()

void SkCanvas::concat ( const SkMatrix matrix)

Replaces SkMatrix with matrix premultiplied with existing SkMatrix.

This has the effect of transforming the drawn geometry by matrix, before transforming the result with existing SkMatrix.

Parameters
matrixmatrix to premultiply with existing SkMatrix

example: https://fiddle.skia.org/c/@Canvas_concat

◆ didConcat()

virtual void SkCanvas::didConcat ( const SkMatrix )
inlineprotectedvirtual

◆ didConcat44()

virtual void SkCanvas::didConcat44 ( const SkScalar  [])
inlineprotectedvirtual

◆ didRestore()

virtual void SkCanvas::didRestore ( )
inlineprotectedvirtual

◆ didScale()

virtual void SkCanvas::didScale ( SkScalar  ,
SkScalar   
)
inlineprotectedvirtual

◆ didSetMatrix()

virtual void SkCanvas::didSetMatrix ( const SkMatrix )
inlineprotectedvirtual

◆ didTranslate()

virtual void SkCanvas::didTranslate ( SkScalar  ,
SkScalar   
)
inlineprotectedvirtual

◆ discard()

void SkCanvas::discard ( )
inline

Makes SkCanvas contents undefined.

Subsequent calls that read SkCanvas pixels, such as drawing with SkBlendMode, return undefined results. discard() does not change clip or SkMatrix.

discard() may do nothing, depending on the implementation of SkSurface or SkBaseDevice that created SkCanvas.

discard() allows optimized performance on subsequent draws by removing cached data associated with SkSurface or SkBaseDevice. It is not necessary to call discard() once done with SkCanvas; any cached data is deleted when owning SkSurface or SkBaseDevice is deleted.

◆ drawAnnotation() [1/2]

void SkCanvas::drawAnnotation ( const SkRect rect,
const char  key[],
SkData value 
)

Associates SkRect on SkCanvas with an annotation; a key-value pair, where the key is a null-terminated UTF-8 string, and optional value is stored as SkData.

Only some canvas implementations, such as recording to SkPicture, or drawing to document PDF, use annotations.

Parameters
rectSkRect extent of canvas to annotate
keystring used for lookup
valuedata holding value stored in annotation

example: https://fiddle.skia.org/c/@Canvas_drawAnnotation_2

◆ drawAnnotation() [2/2]

void SkCanvas::drawAnnotation ( const SkRect rect,
const char  key[],
const sk_sp< SkData > &  value 
)
inline

Associates SkRect on SkCanvas when an annotation; a key-value pair, where the key is a null-terminated UTF-8 string, and optional value is stored as SkData.

Only some canvas implementations, such as recording to SkPicture, or drawing to document PDF, use annotations.

Parameters
rectSkRect extent of canvas to annotate
keystring used for lookup
valuedata holding value stored in annotation

◆ drawArc()

void SkCanvas::drawArc ( const SkRect oval,
SkScalar  startAngle,
SkScalar  sweepAngle,
bool  useCenter,
const SkPaint paint 
)

Draws arc using clip, SkMatrix, and SkPaint 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 SkRect oval is empty or sweepAngle is zero, nothing is drawn.

Parameters
ovalSkRect bounds of oval containing arc to draw
startAngleangle in degrees where arc begins
sweepAnglesweep angle in degrees; positive is clockwise
useCenterif true, include the center of the oval
paintSkPaint stroke or fill, blend, color, and so on, used to draw

◆ drawAtlas() [1/4]

void SkCanvas::drawAtlas ( const SkImage atlas,
const SkRSXform  xform[],
const SkRect  tex[],
const SkColor  colors[],
int  count,
SkBlendMode  mode,
const SkRect cullRect,
const SkPaint paint 
)

Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.

paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode to draw, if present. For each entry in the array, SkRect tex locates sprite in atlas, and SkRSXform xform transforms it into destination space.

xform, text, and colors if present, must contain count entries. Optional colors are applied for each sprite using SkBlendMode mode, treating sprite as source and colors as destination. Optional cullRect is a conservative bounds of all transformed sprites. If cullRect is outside of clip, canvas can skip drawing.

If atlas is nullptr, this draws nothing.

Parameters
atlasSkImage containing sprites
xformSkRSXform mappings for sprites in atlas
texSkRect locations of sprites in atlas
colorsone per sprite, blended with sprite using SkBlendMode; may be nullptr
countnumber of sprites to draw
modeSkBlendMode combining colors and sprites
cullRectbounds of transformed sprites for efficient clipping; may be nullptr
paintSkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr

◆ drawAtlas() [2/4]

void SkCanvas::drawAtlas ( const sk_sp< SkImage > &  atlas,
const SkRSXform  xform[],
const SkRect  tex[],
const SkColor  colors[],
int  count,
SkBlendMode  mode,
const SkRect cullRect,
const SkPaint paint 
)
inline

Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.

paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode to draw, if present. For each entry in the array, SkRect tex locates sprite in atlas, and SkRSXform xform transforms it into destination space.

xform, text, and colors if present, must contain count entries. Optional colors is applied for each sprite using SkBlendMode. Optional cullRect is a conservative bounds of all transformed sprites. If cullRect is outside of clip, canvas can skip drawing.

Parameters
atlasSkImage containing sprites
xformSkRSXform mappings for sprites in atlas
texSkRect locations of sprites in atlas
colorsone per sprite, blended with sprite using SkBlendMode; may be nullptr
countnumber of sprites to draw
modeSkBlendMode combining colors and sprites
cullRectbounds of transformed sprites for efficient clipping; may be nullptr
paintSkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr

◆ drawAtlas() [3/4]

void SkCanvas::drawAtlas ( const SkImage atlas,
const SkRSXform  xform[],
const SkRect  tex[],
int  count,
const SkRect cullRect,
const SkPaint paint 
)
inline

Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.

paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode to draw, if present. For each entry in the array, SkRect tex locates sprite in atlas, and SkRSXform 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.

Parameters
atlasSkImage containing sprites
xformSkRSXform mappings for sprites in atlas
texSkRect locations of sprites in atlas
countnumber of sprites to draw
cullRectbounds of transformed sprites for efficient clipping; may be nullptr
paintSkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr

◆ drawAtlas() [4/4]

void SkCanvas::drawAtlas ( const sk_sp< SkImage > &  atlas,
const SkRSXform  xform[],
const SkRect  tex[],
int  count,
const SkRect cullRect,
const SkPaint paint 
)
inline

Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.

paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode to draw, if present. For each entry in the array, SkRect tex locates sprite in atlas, and SkRSXform 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.

Parameters
atlasSkImage containing sprites
xformSkRSXform mappings for sprites in atlas
texSkRect locations of sprites in atlas
countnumber of sprites to draw
cullRectbounds of transformed sprites for efficient clipping; may be nullptr
paintSkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr

◆ drawBitmap()

void SkCanvas::drawBitmap ( const SkBitmap bitmap,
SkScalar  left,
SkScalar  top,
const SkPaint paint = nullptr 
)

Draws SkBitmap bitmap, with its top-left corner at (left, top), using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from bitmap bounds.

If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as SkShader made from SkShader::MakeBitmapShader with SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples outside of its bounds.

Parameters
bitmapSkBitmap containing pixels, dimensions, and format
leftleft side of bitmap
toptop side of bitmap
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawBitmapLattice()

void SkCanvas::drawBitmapLattice ( const SkBitmap bitmap,
const Lattice lattice,
const SkRect dst,
const SkPaint paint = nullptr 
)

Draws SkBitmap bitmap stretched proportionally to fit into SkRect dst.

SkCanvas::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 dimension. All other grid elements scale to fill the available space, if any.

Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from bitmap bounds. If paint SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels. Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.

If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as SkShader made from SkShader::MakeBitmapShader with SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples outside of its bounds.

Parameters
bitmapSkBitmap containing pixels, dimensions, and format
latticedivision of bitmap into fixed and variable rectangles
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawBitmapNine()

void SkCanvas::drawBitmapNine ( const SkBitmap bitmap,
const SkIRect center,
const SkRect dst,
const SkPaint paint = nullptr 
)

Draws SkBitmap bitmap stretched proportionally to fit into SkRect dst.

SkIRect 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, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from bitmap bounds. If paint SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels. Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.

If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as SkShader made from SkShader::MakeBitmapShader with SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples outside of its bounds.

Parameters
bitmapSkBitmap containing pixels, dimensions, and format
centerSkIRect edge of image corners and sides
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawBitmapRect() [1/3]

void SkCanvas::drawBitmapRect ( const SkBitmap bitmap,
const SkRect src,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)

Draws SkRect src of SkBitmap bitmap, scaled and translated to fill SkRect dst.

Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from bitmap bounds.

If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as SkShader made from SkShader::MakeBitmapShader with SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples outside of its bounds.

constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to sample within src; set to kFast_SrcRectConstraint allows sampling outside to improve performance.

Parameters
bitmapSkBitmap containing pixels, dimensions, and format
srcsource SkRect of image to draw from
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr
constraintfilter strictly within src or draw faster

◆ drawBitmapRect() [2/3]

void SkCanvas::drawBitmapRect ( const SkBitmap bitmap,
const SkIRect isrc,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)

Draws SkIRect isrc of SkBitmap bitmap, scaled and translated to fill SkRect dst.

isrc is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from bitmap bounds.

If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as SkShader made from SkShader::MakeBitmapShader with SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples outside of its bounds.

constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to improve performance.

Parameters
bitmapSkBitmap containing pixels, dimensions, and format
isrcsource SkIRect of image to draw from
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr
constraintsample strictly within isrc, or draw faster

◆ drawBitmapRect() [3/3]

void SkCanvas::drawBitmapRect ( const SkBitmap bitmap,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)

Draws SkBitmap bitmap, scaled and translated to fill SkRect dst.

bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from bitmap bounds.

If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as SkShader made from SkShader::MakeBitmapShader with SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples outside of its bounds.

constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to improve performance.

Parameters
bitmapSkBitmap containing pixels, dimensions, and format
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr
constraintfilter strictly within bitmap or draw faster

◆ drawCircle() [1/2]

void SkCanvas::drawCircle ( SkScalar  cx,
SkScalar  cy,
SkScalar  radius,
const SkPaint paint 
)

Draws circle at (cx, cy) with radius using clip, SkMatrix, and SkPaint paint.

If radius is zero or less, nothing is drawn. In paint: SkPaint::Style determines if circle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness.

Parameters
cxcircle center on the x-axis
cycircle center on the y-axis
radiushalf the diameter of circle
paintSkPaint stroke or fill, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawCircle

◆ drawCircle() [2/2]

void SkCanvas::drawCircle ( SkPoint  center,
SkScalar  radius,
const SkPaint paint 
)
inline

Draws circle at center with radius using clip, SkMatrix, and SkPaint paint.

If radius is zero or less, nothing is drawn. In paint: SkPaint::Style determines if circle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness.

Parameters
centercircle center
radiushalf the diameter of circle
paintSkPaint stroke or fill, blend, color, and so on, used to draw

◆ drawColor()

void SkCanvas::drawColor ( SkColor  color,
SkBlendMode  mode = SkBlendMode::kSrcOver 
)

Fills clip with color color.

mode determines how ARGB is combined with destination.

Parameters
colorunpremultiplied ARGB
modeSkBlendMode used to combine source color and destination

example: https://fiddle.skia.org/c/@Canvas_drawColor

◆ drawDrawable() [1/2]

void SkCanvas::drawDrawable ( SkDrawable drawable,
const SkMatrix matrix = nullptr 
)

Draws SkDrawable drawable using clip and SkMatrix, concatenated with optional matrix.

If SkCanvas has an asynchronous implementation, as is the case when it is recording into SkPicture, 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.

Parameters
drawablecustom struct encapsulating drawing commands
matrixtransformation applied to drawing; may be nullptr

example: https://fiddle.skia.org/c/@Canvas_drawDrawable

◆ drawDrawable() [2/2]

void SkCanvas::drawDrawable ( SkDrawable drawable,
SkScalar  x,
SkScalar  y 
)

Draws SkDrawable drawable using clip and SkMatrix, offset by (x, y).

If SkCanvas has an asynchronous implementation, as is the case when it is recording into SkPicture, 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.

Parameters
drawablecustom struct encapsulating drawing commands
xoffset into SkCanvas writable pixels on x-axis
yoffset into SkCanvas writable pixels on y-axis

example: https://fiddle.skia.org/c/@Canvas_drawDrawable_2

◆ drawDRRect()

void SkCanvas::drawDRRect ( const SkRRect outer,
const SkRRect inner,
const SkPaint paint 
)

Draws SkRRect outer and inner using clip, SkMatrix, and SkPaint paint.

outer must contain inner or the drawing is undefined. In paint: SkPaint::Style determines if SkRRect is stroked or filled; if stroked, SkPaint stroke width describes the line thickness. If stroked and SkRRect corner has zero length radii, SkPaint::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 SkPath built with identical data as fast.

Parameters
outerSkRRect outer bounds to draw
innerSkRRect inner bounds to draw
paintSkPaint stroke or fill, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawDRRect_a example: https://fiddle.skia.org/c/@Canvas_drawDRRect_b

◆ drawImage() [1/2]

void SkCanvas::drawImage ( const SkImage image,
SkScalar  left,
SkScalar  top,
const SkPaint paint = nullptr 
)

Draws SkImage image, with its top-left corner at (left, top), using clip, SkMatrix, and optional SkPaint paint.

This is equivalent to drawImageRect() using a dst rect at (x,y) with the same width and height of the image.

Parameters
imageuncompressed rectangular map of pixels
leftleft side of image
toptop side of image
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawImage() [2/2]

void SkCanvas::drawImage ( const sk_sp< SkImage > &  image,
SkScalar  left,
SkScalar  top,
const SkPaint paint = nullptr 
)
inline

Draws SkImage image, with its top-left corner at (left, top), using clip, SkMatrix, and optional SkPaint paint.

This is equivalent to drawImageRect() using a dst rect at (x,y) with the same width and height of the image.

Parameters
imageuncompressed rectangular map of pixels
leftleft side of image
toppop side of image
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawImageLattice()

void SkCanvas::drawImageLattice ( const SkImage image,
const Lattice lattice,
const SkRect dst,
const SkPaint paint = nullptr 
)

Draws SkImage image stretched proportionally to fit into SkRect dst.

SkCanvas::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 dimension. All other grid elements scale to fill the available space, if any.

Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds. If paint SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels. Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.

If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as SkShader made from SkShader::MakeBitmapShader with SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples outside of its bounds.

Parameters
imageSkImage containing pixels, dimensions, and format
latticedivision of bitmap into fixed and variable rectangles
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawImageNine() [1/2]

void SkCanvas::drawImageNine ( const SkImage image,
const SkIRect center,
const SkRect dst,
const SkPaint paint = nullptr 
)

Draws SkImage image stretched proportionally to fit into SkRect dst.

SkIRect 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, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds. If paint SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels. Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.

If generated mask extends beyond image bounds, replicate image edge colors, just as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the image edge color when it samples outside of its bounds.

Parameters
imageSkImage containing pixels, dimensions, and format
centerSkIRect edge of image corners and sides
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawImageNine() [2/2]

void SkCanvas::drawImageNine ( const sk_sp< SkImage > &  image,
const SkIRect center,
const SkRect dst,
const SkPaint paint = nullptr 
)
inline

Draws SkImage image stretched proportionally to fit into SkRect dst.

SkIRect 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, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds. If paint SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels. Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.

If generated mask extends beyond image bounds, replicate image edge colors, just as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the image edge color when it samples outside of its bounds.

Parameters
imageSkImage containing pixels, dimensions, and format
centerSkIRect edge of image corners and sides
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawImageRect() [1/6]

void SkCanvas::drawImageRect ( const SkImage image,
const SkRect src,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)

Draws SkRect src of SkImage image, scaled and translated to fill SkRect dst.

Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds.

If generated mask extends beyond image bounds, replicate image edge colors, just as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the image edge color when it samples outside of its bounds.

When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst). The src rect is only used to access the provided image.

constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to sample within src; set to kFast_SrcRectConstraint allows sampling outside to improve performance.

Parameters
imageSkImage containing pixels, dimensions, and format
srcsource SkRect of image to draw from
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr
constraintfilter strictly within src or draw faster

◆ drawImageRect() [2/6]

void SkCanvas::drawImageRect ( const SkImage image,
const SkIRect isrc,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)

Draws SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst.

Note that isrc is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds.

If generated mask extends beyond image bounds, replicate image edge colors, just as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the image edge color when it samples outside of its bounds.

When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst). The src rect is only used to access the provided image.

constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to improve performance.

Parameters
imageSkImage containing pixels, dimensions, and format
isrcsource SkIRect of image to draw from
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr
constraintfilter strictly within isrc or draw faster

◆ drawImageRect() [3/6]

void SkCanvas::drawImageRect ( const SkImage image,
const SkRect dst,
const SkPaint paint 
)

Draws SkImage image, scaled and translated to fill SkRect dst, using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds.

If generated mask extends beyond image bounds, replicate image edge colors, just as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the image edge color when it samples outside of its bounds.

When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst).

Parameters
imageSkImage containing pixels, dimensions, and format
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

example: https://fiddle.skia.org/c/@Canvas_drawImageRect_3

◆ drawImageRect() [4/6]

void SkCanvas::drawImageRect ( const sk_sp< SkImage > &  image,
const SkRect src,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)
inline

Draws SkRect src of SkImage image, scaled and translated to fill SkRect dst.

Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds.

If generated mask extends beyond image bounds, replicate image edge colors, just as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the image edge color when it samples outside of its bounds.

When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst). The src rect is only used to access the provided image.

Parameters
imageSkImage containing pixels, dimensions, and format
srcsource SkRect of image to draw from
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr
constraintfilter strictly within src or draw faster

◆ drawImageRect() [5/6]

void SkCanvas::drawImageRect ( const sk_sp< SkImage > &  image,
const SkIRect isrc,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)
inline

Draws SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst.

isrc is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds.

If generated mask extends beyond image bounds, replicate image edge colors, just as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the image edge color when it samples outside of its bounds.

When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst). The src rect is only used to access the provided image.

constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to sample within image; set to kFast_SrcRectConstraint allows sampling outside to improve performance.

Parameters
imageSkImage containing pixels, dimensions, and format
isrcsource SkIRect of image to draw from
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr
constraintfilter strictly within image or draw faster

◆ drawImageRect() [6/6]

void SkCanvas::drawImageRect ( const sk_sp< SkImage > &  image,
const SkRect dst,
const SkPaint paint 
)
inline

Draws SkImage image, scaled and translated to fill SkRect dst, using clip, SkMatrix, and optional SkPaint paint.

If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds.

If generated mask extends beyond image bounds, replicate image edge colors, just as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the image edge color when it samples outside of its bounds.

When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst).

constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to sample within image; set to kFast_SrcRectConstraint allows sampling outside to improve performance.

Parameters
imageSkImage containing pixels, dimensions, and format
dstdestination SkRect of image to draw to
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

◆ drawIRect()

void SkCanvas::drawIRect ( const SkIRect rect,
const SkPaint paint 
)
inline

Draws SkIRect rect using clip, SkMatrix, and SkPaint paint.

In paint: SkPaint::Style determines if rectangle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness, and SkPaint::Join draws the corners rounded or square.

Parameters
rectrectangle to draw
paintstroke or fill, blend, color, and so on, used to draw

◆ drawLine() [1/2]

void SkCanvas::drawLine ( SkScalar  x0,
SkScalar  y0,
SkScalar  x1,
SkScalar  y1,
const SkPaint paint 
)

Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.

In paint: SkPaint stroke width describes the line thickness; SkPaint::Cap draws the end rounded or square; SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.

Parameters
x0start of line segment on x-axis
y0start of line segment on y-axis
x1end of line segment on x-axis
y1end of line segment on y-axis
paintstroke, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawLine

◆ drawLine() [2/2]

void SkCanvas::drawLine ( SkPoint  p0,
SkPoint  p1,
const SkPaint paint 
)
inline

Draws line segment from p0 to p1 using clip, SkMatrix, and SkPaint paint.

In paint: SkPaint stroke width describes the line thickness; SkPaint::Cap draws the end rounded or square; SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.

Parameters
p0start of line segment
p1end of line segment
paintstroke, blend, color, and so on, used to draw

◆ drawOval()

void SkCanvas::drawOval ( const SkRect oval,
const SkPaint paint 
)

Draws oval oval using clip, SkMatrix, and SkPaint.

In paint: SkPaint::Style determines if oval is stroked or filled; if stroked, SkPaint stroke width describes the line thickness.

Parameters
ovalSkRect bounds of oval
paintSkPaint stroke or fill, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawOval

◆ drawPaint()

void SkCanvas::drawPaint ( const SkPaint paint)

Fills clip with SkPaint paint.

SkPaint components SkMaskFilter, SkShader, SkColorFilter, SkImageFilter, and SkBlendMode affect drawing; SkPathEffect in paint is ignored.

Parameters
paintgraphics state used to fill SkCanvas

example: https://fiddle.skia.org/c/@Canvas_drawPaint

◆ drawPatch() [1/2]

void SkCanvas::drawPatch ( const SkPoint  cubics[12],
const SkColor  colors[4],
const SkPoint  texCoords[4],
SkBlendMode  mode,
const SkPaint paint 
)

Draws a Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture SkPoint, with each corner.

Coons patch uses clip and SkMatrix, paint SkShader, SkColorFilter, alpha, SkImageFilter, and SkBlendMode. If SkShader is provided it is treated as Coons patch texture; SkBlendMode mode combines color colors and SkShader if both are provided.

SkPoint array cubics specifies four SkPath cubic starting at the top-left corner, in clockwise order, sharing every fourth point. The last SkPath 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 SkShader, SkPoint array texCoords maps SkShader as texture to corners in top-left, top-right, bottom-right, bottom-left order.

Parameters
cubicsSkPath cubic array, sharing common points
colorscolor array, one for each corner
texCoordsSkPoint array of texture coordinates, mapping SkShader to corners; may be nullptr
modeSkBlendMode for colors, and for SkShader if paint has one
paintSkShader, SkColorFilter, SkBlendMode, used to draw

◆ drawPatch() [2/2]

void SkCanvas::drawPatch ( const SkPoint  cubics[12],
const SkColor  colors[4],
const SkPoint  texCoords[4],
const SkPaint paint 
)
inline

Draws SkPath cubic Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture SkPoint, with each corner.

Coons patch uses clip and SkMatrix, paint SkShader, SkColorFilter, alpha, SkImageFilter, and SkBlendMode. If SkShader is provided it is treated as Coons patch texture; SkBlendMode mode combines color colors and SkShader if both are provided.

SkPoint array cubics specifies four SkPath cubic starting at the top-left corner, in clockwise order, sharing every fourth point. The last SkPath 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 SkShader, SkPoint array texCoords maps SkShader as texture to corners in top-left, top-right, bottom-right, bottom-left order.

Parameters
cubicsSkPath cubic array, sharing common points
colorscolor array, one for each corner
texCoordsSkPoint array of texture coordinates, mapping SkShader to corners; may be nullptr
paintSkShader, SkColorFilter, SkBlendMode, used to draw

◆ drawPath()

void SkCanvas::drawPath ( const SkPath path,
const SkPaint paint 
)

Draws SkPath path using clip, SkMatrix, and SkPaint paint.

SkPath contains an array of path contour, each of which may be open or closed.

In paint: SkPaint::Style determines if SkRRect is stroked or filled: if filled, SkPath::FillType determines whether path contour describes inside or outside of fill; if stroked, SkPaint stroke width describes the line thickness, SkPaint::Cap describes line ends, and SkPaint::Join describes how corners are drawn.

Parameters
pathSkPath to draw
paintstroke, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawPath

◆ drawPicture() [1/4]

void SkCanvas::drawPicture ( const SkPicture picture)
inline

Draws SkPicture picture, using clip and SkMatrix.

Clip and SkMatrix are unchanged by picture contents, as if save() was called before and restore() was called after drawPicture().

SkPicture records a series of draw commands for later playback.

Parameters
picturerecorded drawing commands to play

◆ drawPicture() [2/4]

void SkCanvas::drawPicture ( const sk_sp< SkPicture > &  picture)
inline

Draws SkPicture picture, using clip and SkMatrix.

Clip and SkMatrix are unchanged by picture contents, as if save() was called before and restore() was called after drawPicture().

SkPicture records a series of draw commands for later playback.

Parameters
picturerecorded drawing commands to play

◆ drawPicture() [3/4]

void SkCanvas::drawPicture ( const SkPicture picture,
const SkMatrix matrix,
const SkPaint paint 
)

Draws SkPicture picture, using clip and SkMatrix; transforming picture with SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter, SkImageFilter, and SkBlendMode, if provided.

matrix transformation is equivalent to: save(), concat(), drawPicture(), restore(). paint use is equivalent to: saveLayer(), drawPicture(), restore().

Parameters
picturerecorded drawing commands to play
matrixSkMatrix to rotate, scale, translate, and so on; may be nullptr
paintSkPaint to apply transparency, filtering, and so on; may be nullptr

example: https://fiddle.skia.org/c/@Canvas_drawPicture_3

◆ drawPicture() [4/4]

void SkCanvas::drawPicture ( const sk_sp< SkPicture > &  picture,
const SkMatrix matrix,
const SkPaint paint 
)
inline

Draws SkPicture picture, using clip and SkMatrix; transforming picture with SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter, SkImageFilter, and SkBlendMode, if provided.

matrix transformation is equivalent to: save(), concat(), drawPicture(), restore(). paint use is equivalent to: saveLayer(), drawPicture(), restore().

Parameters
picturerecorded drawing commands to play
matrixSkMatrix to rotate, scale, translate, and so on; may be nullptr
paintSkPaint to apply transparency, filtering, and so on; may be nullptr

◆ drawPoint() [1/2]

void SkCanvas::drawPoint ( SkScalar  x,
SkScalar  y,
const SkPaint paint 
)

Draws point at (x, y) using clip, SkMatrix and SkPaint paint.

The shape of point drawn depends on paint SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, draw a circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, draw a square of width and height SkPaint stroke width. SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.

Parameters
xleft edge of circle or square
ytop edge of circle or square
paintstroke, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawPoint

◆ drawPoint() [2/2]

void SkCanvas::drawPoint ( SkPoint  p,
const SkPaint paint 
)
inline

Draws point p using clip, SkMatrix and SkPaint paint.

The shape of point drawn depends on paint SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, draw a circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, draw a square of width and height SkPaint stroke width. SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.

Parameters
ptop-left edge of circle or square
paintstroke, blend, color, and so on, used to draw

◆ drawPoints()

void SkCanvas::drawPoints ( PointMode  mode,
size_t  count,
const SkPoint  pts[],
const SkPaint paint 
)

Draws pts using clip, SkMatrix and SkPaint 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 SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, each point draws a circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, each point draws a square of width and height SkPaint 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 SkPaint::Cap and SkPaint stroke width. SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.

Always draws each element one at a time; is not affected by SkPaint::Join, and unlike drawPath(), does not create a mask from all points and lines before drawing.

Parameters
modewhether pts draws points or lines
countnumber of points in the array
ptsarray of points to draw
paintstroke, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawPoints

◆ drawRect()

void SkCanvas::drawRect ( const SkRect rect,
const SkPaint paint 
)

Draws SkRect rect using clip, SkMatrix, and SkPaint paint.

In paint: SkPaint::Style determines if rectangle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness, and SkPaint::Join draws the corners rounded or square.

Parameters
rectrectangle to draw
paintstroke or fill, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawRect

◆ drawRegion()

void SkCanvas::drawRegion ( const SkRegion region,
const SkPaint paint 
)

Draws SkRegion region using clip, SkMatrix, and SkPaint paint.

In paint: SkPaint::Style determines if rectangle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness, and SkPaint::Join draws the corners rounded or square.

Parameters
regionregion to draw
paintSkPaint stroke or fill, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawRegion

◆ drawRoundRect()

void SkCanvas::drawRoundRect ( const SkRect rect,
SkScalar  rx,
SkScalar  ry,
const SkPaint paint 
)

Draws SkRRect bounded by SkRect rect, with corner radii (rx, ry) using clip, SkMatrix, and SkPaint paint.

In paint: SkPaint::Style determines if SkRRect is stroked or filled; if stroked, SkPaint 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, SkRRect is drawn as SkRect and if stroked is affected by SkPaint::Join.

Parameters
rectSkRect bounds of SkRRect to draw
rxaxis length on x-axis of oval describing rounded corners
ryaxis length on y-axis of oval describing rounded corners
paintstroke, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawRoundRect

◆ drawRRect()

void SkCanvas::drawRRect ( const SkRRect rrect,
const SkPaint paint 
)

Draws SkRRect rrect using clip, SkMatrix, and SkPaint paint.

In paint: SkPaint::Style determines if rrect is stroked or filled; if stroked, SkPaint 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.

Parameters
rrectSkRRect with up to eight corner radii to draw
paintSkPaint stroke or fill, blend, color, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawRRect

◆ drawSimpleText()

void SkCanvas::drawSimpleText ( const void *  text,
size_t  byteLength,
SkTextEncoding  encoding,
SkScalar  x,
SkScalar  y,
const SkFont font,
const SkPaint paint 
)

Draws text, with origin at (x, y), using clip, SkMatrix, SkFont font, and SkPaint paint.

When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or SkTextEncoding::kUTF32, this function uses the default character-to-glyph mapping from the SkTypeface in font. It does not perform typeface fallback for characters not found in the SkTypeface. It does not perform kerning or other complex shaping; glyphs are positioned based on their default advances.

Text meaning depends on SkTextEncoding.

Text size is affected by SkMatrix and SkFont text size. Default text size is 12 point.

All elements of paint: SkPathEffect, SkMaskFilter, SkShader, SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws filled black glyphs.

Parameters
textcharacter code points or glyphs drawn
byteLengthbyte length of text array
encodingtext encoding used in the text array
xstart of text on x-axis
ystart of text on y-axis
fonttypeface, text size and so, used to describe the text
paintblend, color, and so on, used to draw

◆ drawString() [1/2]

void SkCanvas::drawString ( const char  str[],
SkScalar  x,
SkScalar  y,
const SkFont font,
const SkPaint paint 
)
inline

Draws null terminated string, with origin at (x, y), using clip, SkMatrix, SkFont font, and SkPaint paint.

This function uses the default character-to-glyph mapping from the SkTypeface in font. It does not perform typeface fallback for characters not found in the SkTypeface. It does not perform kerning; glyphs are positioned based on their default advances.

String str is encoded as UTF-8.

Text size is affected by SkMatrix and font text size. Default text size is 12 point.

All elements of paint: SkPathEffect, SkMaskFilter, SkShader, SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws filled black glyphs.

Parameters
strcharacter code points drawn, ending with a char value of zero
xstart of string on x-axis
ystart of string on y-axis
fonttypeface, text size and so, used to describe the text
paintblend, color, and so on, used to draw

◆ drawString() [2/2]

void SkCanvas::drawString ( const SkString str,
SkScalar  x,
SkScalar  y,
const SkFont font,
const SkPaint paint 
)
inline

Draws SkString, with origin at (x, y), using clip, SkMatrix, SkFont font, and SkPaint paint.

This function uses the default character-to-glyph mapping from the SkTypeface in font. It does not perform typeface fallback for characters not found in the SkTypeface. It does not perform kerning; glyphs are positioned based on their default advances.

SkString str is encoded as UTF-8.

Text size is affected by SkMatrix and SkFont text size. Default text size is 12 point.

All elements of paint: SkPathEffect, SkMaskFilter, SkShader, SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws filled black glyphs.

Parameters
strcharacter code points drawn, ending with a char value of zero
xstart of string on x-axis
ystart of string on y-axis
fonttypeface, text size and so, used to describe the text
paintblend, color, and so on, used to draw

◆ drawTextBlob() [1/2]

void SkCanvas::drawTextBlob ( const SkTextBlob blob,
SkScalar  x,
SkScalar  y,
const SkPaint paint 
)

Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.

blob contains glyphs, their positions, and paint attributes specific to text: SkTypeface, SkPaint text size, SkPaint text scale x, SkPaint text skew x, SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold, SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text, and SkPaint subpixel text.

SkTextEncoding must be set to SkTextEncoding::kGlyphID.

Elements of paint: anti-alias, SkBlendMode, color including alpha, SkColorFilter, SkPaint dither, SkDrawLooper, SkMaskFilter, SkPathEffect, SkShader, and SkPaint::Style; apply to blob. If SkPaint contains SkPaint::kStroke_Style: SkPaint miter limit, SkPaint::Cap, SkPaint::Join, and SkPaint stroke width; apply to SkPath created from blob.

Parameters
blobglyphs, positions, and their paints' text size, typeface, and so on
xhorizontal offset applied to blob
yvertical offset applied to blob
paintblend, color, stroking, and so on, used to draw

example: https://fiddle.skia.org/c/@Canvas_drawTextBlob

◆ drawTextBlob() [2/2]

void SkCanvas::drawTextBlob ( const sk_sp< SkTextBlob > &  blob,
SkScalar  x,
SkScalar  y,
const SkPaint paint 
)
inline

Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.

blob contains glyphs, their positions, and paint attributes specific to text: SkTypeface, SkPaint text size, SkPaint text scale x, SkPaint text skew x, SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold, SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text, and SkPaint subpixel text.

SkTextEncoding must be set to SkTextEncoding::kGlyphID.

Elements of paint: SkPathEffect, SkMaskFilter, SkShader, SkColorFilter, SkImageFilter, and SkDrawLooper; apply to blob.

Parameters
blobglyphs, positions, and their paints' text size, typeface, and so on
xhorizontal offset applied to blob
yvertical offset applied to blob
paintblend, color, stroking, and so on, used to draw

◆ drawVertices() [1/4]

void SkCanvas::drawVertices ( const SkVertices vertices,
SkBlendMode  mode,
const SkPaint paint 
)

Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix.

If vertices texs and vertices colors are defined in vertices, and SkPaint paint contains SkShader, SkBlendMode mode combines vertices colors with SkShader.

Parameters
verticestriangle mesh to draw
modecombines vertices colors with SkShader, if both are present
paintspecifies the SkShader, used as SkVertices texture; may be nullptr

example: https://fiddle.skia.org/c/@Canvas_drawVertices

◆ drawVertices() [2/4]

void SkCanvas::drawVertices ( const sk_sp< SkVertices > &  vertices,
SkBlendMode  mode,
const SkPaint paint 
)

Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix.

If vertices texs and vertices colors are defined in vertices, and SkPaint paint contains SkShader, SkBlendMode mode combines vertices colors with SkShader.

Parameters
verticestriangle mesh to draw
modecombines vertices colors with SkShader, if both are present
paintspecifies the SkShader, used as SkVertices texture, may be nullptr

example: https://fiddle.skia.org/c/@Canvas_drawVertices_2

◆ drawVertices() [3/4]

void SkCanvas::drawVertices ( const SkVertices vertices,
const SkVertices::Bone  bones[],
int  boneCount,
SkBlendMode  mode,
const SkPaint paint 
)

Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix.

Bone data is used to deform vertices with bone weights. If vertices texs and vertices colors are defined in vertices, and SkPaint paint contains SkShader, SkBlendMode mode combines vertices colors with SkShader. The first element of bones should be an object to world space transformation matrix that will be applied before performing mesh deformations. If no such transformation is needed, it should be the identity matrix. boneCount must be at most 80, and thus the size of bones should be at most 80.

Parameters
verticestriangle mesh to draw
bonesbone matrix data
boneCountnumber of bone matrices
modecombines vertices colors with SkShader, if both are present
paintspecifies the SkShader, used as SkVertices texture, may be nullptr

◆ drawVertices() [4/4]

void SkCanvas::drawVertices ( const sk_sp< SkVertices > &  vertices,
const SkVertices::Bone  bones[],
int  boneCount,
SkBlendMode  mode,
const SkPaint paint 
)

Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix.

Bone data is used to deform vertices with bone weights. If vertices texs and vertices colors are defined in vertices, and SkPaint paint contains SkShader, SkBlendMode mode combines vertices colors with SkShader. The first element of bones should be an object to world space transformation matrix that will be applied before performing mesh deformations. If no such transformation is needed, it should be the identity matrix. boneCount must be at most 80, and thus the size of bones should be at most 80.

Parameters
verticestriangle mesh to draw
bonesbone matrix data
boneCountnumber of bone matrices
modecombines vertices colors with SkShader, if both are present
paintspecifies the SkShader, used as SkVertices texture, may be nullptr

◆ experimental_concat44() [1/2]

void SkCanvas::experimental_concat44 ( const SkM44 &  )

◆ experimental_concat44() [2/2]

void SkCanvas::experimental_concat44 ( const SkScalar  [])

◆ experimental_DrawEdgeAAImageSet()

void SkCanvas::experimental_DrawEdgeAAImageSet ( const ImageSetEntry  imageSet[],
int  cnt,
const SkPoint  dstClips[],
const SkMatrix  preViewMatrices[],
const SkPaint paint = nullptr,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)

This is an bulk variant of experimental_DrawEdgeAAQuad() that renders 'cnt' textured quads.

For each entry, 'fDstRect' is rendered with its clip (determined by entry's 'fHasClip' and the current index in 'dstClip'). The entry's fImage is applied to the destination rectangle by sampling from 'fSrcRect' sub-image. The corners of 'fSrcRect' map to the corners of 'fDstRect', just like in drawImageRect(), and they will be properly interpolated when applying a clip.

Like experimental_DrawEdgeAAQuad(), each entry can specify edge AA flags that apply to both the destination rect and its clip.

If provided, the 'dstClips' array must have length equal 4 * the number of entries with fHasClip true. If 'dstClips' is null, every entry must have 'fHasClip' set to false. The destination clip coordinates will be read consecutively with the image set entries, advancing by 4 points every time an entry with fHasClip is passed.

This entry point supports per-entry manipulations to the canvas's current matrix. If an entry provides 'fMatrixIndex' >= 0, it will be drawn as if the canvas's CTM was canvas->getTotalMatrix() * preViewMatrices[fMatrixIndex]. If 'fMatrixIndex' is less than 0, the pre-view matrix transform is implicitly the identity, so it will be drawn using just the current canvas matrix. The pre-view matrix modifies the canvas's view matrix, it does not affect the local coordinates of each entry.

An optional paint may be provided, which supports the same subset of features usable with drawImageRect (i.e. assumed to be filled and no path effects). When a paint is provided, the image set is drawn as if each image used the applied paint independently, so each is affected by the image, color, and/or mask filter.

◆ experimental_DrawEdgeAAQuad() [1/2]

void SkCanvas::experimental_DrawEdgeAAQuad ( const SkRect rect,
const SkPoint  clip[4],
QuadAAFlags  aaFlags,
const SkColor4f color,
SkBlendMode  mode 
)

This is an experimental API for the SkiaRenderer Chromium project, and its API will surely evolve if it is not removed outright.

This behaves very similarly to drawRect() combined with a clipPath() formed by clip quadrilateral. 'rect' and 'clip' are in the same coordinate space. If 'clip' is null, then it is as if the rectangle was not clipped (or, alternatively, clipped to itself). If not null, then it must provide 4 points.

In addition to combining the draw and clipping into one operation, this function adds the additional capability of controlling each of the rectangle's edges anti-aliasing independently. The edges of the clip will respect the per-edge AA flags. It is required that 'clip' be contained inside 'rect'. In terms of mapping to edge labels, the 'clip' points should be ordered top-left, top-right, bottom-right, bottom-left so that the edge between [0] and [1] is "top", [1] and [2] is "right", [2] and [3] is "bottom", and [3] and [0] is "left". This ordering matches SkRect::toQuad().

This API only draws solid color, filled rectangles so it does not accept a full SkPaint.

◆ experimental_DrawEdgeAAQuad() [2/2]

void SkCanvas::experimental_DrawEdgeAAQuad ( const SkRect rect,
const SkPoint  clip[4],
QuadAAFlags  aaFlags,
SkColor  color,
SkBlendMode  mode 
)
inline

◆ experimental_getLocalToCamera() [1/2]

SkM44 SkCanvas::experimental_getLocalToCamera ( ) const

◆ experimental_getLocalToCamera() [2/2]

void SkCanvas::experimental_getLocalToCamera ( SkScalar  colMajor[16]) const

◆ experimental_getLocalToDevice() [1/2]

SkM44 SkCanvas::experimental_getLocalToDevice ( ) const

◆ experimental_getLocalToDevice() [2/2]

void SkCanvas::experimental_getLocalToDevice ( SkScalar  colMajor[16]) const

◆ experimental_getLocalToWorld() [1/2]

SkM44 SkCanvas::experimental_getLocalToWorld ( ) const

◆ experimental_getLocalToWorld() [2/2]

void SkCanvas::experimental_getLocalToWorld ( SkScalar  colMajor[16]) const

◆ experimental_saveCamera() [1/2]

int SkCanvas::experimental_saveCamera ( const SkM44 &  projection,
const SkM44 &  camera 
)

◆ experimental_saveCamera() [2/2]

int SkCanvas::experimental_saveCamera ( const SkScalar  projection[16],
const SkScalar  camera[16] 
)

◆ flush()

void SkCanvas::flush ( )

Triggers the immediate execution of all pending draw operations.

If SkCanvas is associated with GPU surface, resolves all pending GPU operations. If SkCanvas is associated with raster surface, has no effect; raster draw operations are never deferred.

◆ getBaseLayerSize()

virtual SkISize SkCanvas::getBaseLayerSize ( ) const
virtual

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).

Returns
integral width and height of base layer

example: https://fiddle.skia.org/c/@Canvas_getBaseLayerSize

◆ getDeviceClipBounds() [1/2]

SkIRect SkCanvas::getDeviceClipBounds ( ) const

Returns SkIRect bounds of clip, unaffected by SkMatrix.

If clip is empty, return SkRect::MakeEmpty, where all SkRect sides equal zero.

Unlike getLocalClipBounds(), returned SkIRect is not outset.

Returns
bounds of clip in SkBaseDevice coordinates

example: https://fiddle.skia.org/c/@Canvas_getDeviceClipBounds

◆ getDeviceClipBounds() [2/2]

bool SkCanvas::getDeviceClipBounds ( SkIRect bounds) const
inline

Returns SkIRect bounds of clip, unaffected by SkMatrix.

If clip is empty, return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero.

Unlike getLocalClipBounds(), bounds is not outset.

Parameters
boundsSkRect of clip in device coordinates
Returns
true if clip bounds is not empty

◆ getGrContext()

virtual GrContext* SkCanvas::getGrContext ( )
virtual

Returns GPU context of the GPU surface associated with SkCanvas.

Returns
GPU context, if available; nullptr otherwise

example: https://fiddle.skia.org/c/@Canvas_getGrContext

◆ getLocalClipBounds() [1/2]

SkRect SkCanvas::getLocalClipBounds ( ) const

Returns bounds of clip, transformed by inverse of SkMatrix.

If clip is empty, return SkRect::MakeEmpty, where all SkRect sides equal zero.

SkRect returned is outset by one to account for partial pixel coverage if clip is anti-aliased.

Returns
bounds of clip in local coordinates

example: https://fiddle.skia.org/c/@Canvas_getLocalClipBounds

◆ getLocalClipBounds() [2/2]

bool SkCanvas::getLocalClipBounds ( SkRect bounds) const
inline

Returns bounds of clip, transformed by inverse of SkMatrix.

If clip is empty, return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero.

bounds is outset by one to account for partial pixel coverage if clip is anti-aliased.

Parameters
boundsSkRect of clip in local coordinates
Returns
true if clip bounds is not empty

◆ getProps()

bool SkCanvas::getProps ( SkSurfaceProps props) const

Copies SkSurfaceProps, if SkCanvas is associated with raster surface or GPU surface, and returns true.

Otherwise, returns false and leave props unchanged.

Parameters
propsstorage for writable SkSurfaceProps
Returns
true if SkSurfaceProps was copied

example: https://fiddle.skia.org/c/@Canvas_getProps

◆ getSaveCount()

int SkCanvas::getSaveCount ( ) const

Returns the number of saved states, each containing: SkMatrix and clip.

Equals the number of save() calls less the number of restore() calls plus one. The save count of a new canvas is one.

Returns
depth of save state stack

example: https://fiddle.skia.org/c/@Canvas_getSaveCount

◆ getSaveLayerStrategy()

virtual SaveLayerStrategy SkCanvas::getSaveLayerStrategy ( const SaveLayerRec )
inlineprotectedvirtual

◆ getSurface()

SkSurface* SkCanvas::getSurface ( ) const

Sometimes a canvas is owned by a surface.

If it is, getSurface() will return a bare pointer to that surface, else this will return nullptr.

◆ getTopDevice()

SkBaseDevice* SkCanvas::getTopDevice ( ) const
protected

◆ getTotalMatrix()

SkMatrix SkCanvas::getTotalMatrix ( ) const

Returns SkMatrix.

This does not account for translation by SkBaseDevice or SkSurface.

Returns
SkMatrix in SkCanvas

example: https://fiddle.skia.org/c/@Canvas_getTotalMatrix example: https://fiddle.skia.org/c/@Clip

◆ imageInfo()

SkImageInfo SkCanvas::imageInfo ( ) const

Returns SkImageInfo for SkCanvas.

If SkCanvas is not associated with raster surface or GPU surface, returned SkColorType is set to kUnknown_SkColorType.

Returns
dimensions and SkColorType of SkCanvas

example: https://fiddle.skia.org/c/@Canvas_imageInfo

◆ internal_private_accessTopLayerRenderTargetContext()

virtual GrRenderTargetContext* SkCanvas::internal_private_accessTopLayerRenderTargetContext ( )
virtual

◆ internal_private_getTopLayerBounds()

SkIRect SkCanvas::internal_private_getTopLayerBounds ( ) const
inline

◆ isClipEmpty()

virtual bool SkCanvas::isClipEmpty ( ) const
virtual

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.

Returns
true if clip is empty

example: https://fiddle.skia.org/c/@Canvas_isClipEmpty

◆ isClipRect()

virtual bool SkCanvas::isClipRect ( ) const
virtual

Returns true if clip is SkRect and not empty.

Returns false if the clip is empty, or if it is not SkRect.

Returns
true if clip is SkRect and not empty

example: https://fiddle.skia.org/c/@Canvas_isClipRect

◆ legacy_drawBitmapRect()

void SkCanvas::legacy_drawBitmapRect ( const SkBitmap bitmap,
const SkRect src,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)

◆ legacy_drawImageRect()

void SkCanvas::legacy_drawImageRect ( const SkImage image,
const SkRect src,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint = kStrict_SrcRectConstraint 
)

◆ MakeRasterDirect()

static std::unique_ptr<SkCanvas> SkCanvas::MakeRasterDirect ( const SkImageInfo info,
void *  pixels,
size_t  rowBytes,
const SkSurfaceProps props = nullptr 
)
static

Allocates raster SkCanvas that will draw directly into pixels.

SkCanvas is returned if all parameters are valid. Valid parameters include: info dimensions are zero or positive; info contains SkColorType and SkAlphaType supported by raster surface; pixels is not nullptr; rowBytes is zero or large enough to contain info width pixels of SkColorType.

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 SkColorType.

Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, call flush() or peekPixels().

Parameters
infowidth, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; width, or height, or both, may be zero
pixelspointer to destination pixels buffer
rowBytesinterval from one SkSurface row to the next, or zero
propsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkCanvas if all parameters are valid; otherwise, nullptr

◆ MakeRasterDirectN32()

static std::unique_ptr<SkCanvas> SkCanvas::MakeRasterDirectN32 ( int  width,
int  height,
SkPMColor pixels,
size_t  rowBytes 
)
inlinestatic

Allocates raster SkCanvas specified by inline image specification.

Subsequent SkCanvas calls draw into pixels. SkColorType is set to kN32_SkColorType. SkAlphaType is set to kPremul_SkAlphaType. To access pixels after drawing, call flush() or peekPixels().

SkCanvas 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 SkColorType.

Pixel buffer size should be height times rowBytes.

Parameters
widthpixel column count on raster surface created; must be zero or greater
heightpixel row count on raster surface created; must be zero or greater
pixelspointer to destination pixels buffer; buffer size should be height times rowBytes
rowBytesinterval from one SkSurface row to the next, or zero
Returns
SkCanvas if all parameters are valid; otherwise, nullptr

◆ makeSurface()

sk_sp<SkSurface> SkCanvas::makeSurface ( const SkImageInfo info,
const SkSurfaceProps props = nullptr 
)

Creates SkSurface matching info and props, and associates it with SkCanvas.

Returns nullptr if no match found.

If props is nullptr, matches SkSurfaceProps in SkCanvas. If props is nullptr and SkCanvas does not have SkSurfaceProps, creates SkSurface with default SkSurfaceProps.

Parameters
infowidth, height, SkColorType, SkAlphaType, and SkColorSpace
propsSkSurfaceProps to match; may be nullptr to match SkCanvas
Returns
SkSurface matching info and props, or nullptr if no match is available

example: https://fiddle.skia.org/c/@Canvas_makeSurface

◆ onAccessTopLayerPixels()

virtual bool SkCanvas::onAccessTopLayerPixels ( SkPixmap pixmap)
protectedvirtual

◆ onClipPath()

virtual void SkCanvas::onClipPath ( const SkPath path,
SkClipOp  op,
ClipEdgeStyle  edgeStyle 
)
protectedvirtual

◆ onClipRect()

virtual void SkCanvas::onClipRect ( const SkRect rect,
SkClipOp  op,
ClipEdgeStyle  edgeStyle 
)
protectedvirtual

◆ onClipRegion()

virtual void SkCanvas::onClipRegion ( const SkRegion deviceRgn,
SkClipOp  op 
)
protectedvirtual

◆ onClipRRect()

virtual void SkCanvas::onClipRRect ( const SkRRect rrect,
SkClipOp  op,
ClipEdgeStyle  edgeStyle 
)
protectedvirtual

◆ onDiscard()

virtual void SkCanvas::onDiscard ( )
protectedvirtual

◆ onDoSaveBehind()

virtual bool SkCanvas::onDoSaveBehind ( const SkRect )
inlineprotectedvirtual

◆ onDrawAnnotation()

virtual void SkCanvas::onDrawAnnotation ( const SkRect rect,
const char  key[],
SkData value 
)
protectedvirtual

◆ onDrawArc()

virtual void SkCanvas::onDrawArc ( const SkRect rect,
SkScalar  startAngle,
SkScalar  sweepAngle,
bool  useCenter,
const SkPaint paint 
)
protectedvirtual

◆ onDrawAtlas()

virtual void SkCanvas::onDrawAtlas ( const SkImage atlas,
const SkRSXform  xform[],
const SkRect  rect[],
const SkColor  colors[],
int  count,
SkBlendMode  mode,
const SkRect cull,
const SkPaint paint 
)
protectedvirtual

◆ onDrawBehind()

virtual void SkCanvas::onDrawBehind ( const SkPaint paint)
protectedvirtual

◆ onDrawBitmap()

virtual void SkCanvas::onDrawBitmap ( const SkBitmap bitmap,
SkScalar  dx,
SkScalar  dy,
const SkPaint paint 
)
protectedvirtual

◆ onDrawBitmapLattice()

virtual void SkCanvas::onDrawBitmapLattice ( const SkBitmap bitmap,
const Lattice lattice,
const SkRect dst,
const SkPaint paint 
)
protectedvirtual

◆ onDrawBitmapNine()

virtual void SkCanvas::onDrawBitmapNine ( const SkBitmap bitmap,
const SkIRect center,
const SkRect dst,
const SkPaint paint 
)
protectedvirtual

◆ onDrawBitmapRect()

virtual void SkCanvas::onDrawBitmapRect ( const SkBitmap bitmap,
const SkRect src,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint 
)
protectedvirtual

◆ onDrawDrawable()

virtual void SkCanvas::onDrawDrawable ( SkDrawable drawable,
const SkMatrix matrix 
)
protectedvirtual

◆ onDrawDRRect()

virtual void SkCanvas::onDrawDRRect ( const SkRRect outer,
const SkRRect inner,
const SkPaint paint 
)
protectedvirtual

◆ onDrawEdgeAAImageSet()

virtual void SkCanvas::onDrawEdgeAAImageSet ( const ImageSetEntry  imageSet[],
int  count,
const SkPoint  dstClips[],
const SkMatrix  preViewMatrices[],
const SkPaint paint,
SrcRectConstraint  constraint 
)
protectedvirtual

◆ onDrawEdgeAAQuad()

virtual void SkCanvas::onDrawEdgeAAQuad ( const SkRect rect,
const SkPoint  clip[4],
QuadAAFlags  aaFlags,
const SkColor4f color,
SkBlendMode  mode 
)
protectedvirtual

◆ onDrawImage()

virtual void SkCanvas::onDrawImage ( const SkImage image,
SkScalar  dx,
SkScalar  dy,
const SkPaint paint 
)
protectedvirtual

◆ onDrawImageLattice()

virtual void SkCanvas::onDrawImageLattice ( const SkImage image,
const Lattice lattice,
const SkRect dst,
const SkPaint paint 
)
protectedvirtual

◆ onDrawImageNine()

virtual void SkCanvas::onDrawImageNine ( const SkImage image,
const SkIRect center,
const SkRect dst,
const SkPaint paint 
)
protectedvirtual

◆ onDrawImageRect()

virtual void SkCanvas::onDrawImageRect ( const SkImage image,
const SkRect src,
const SkRect dst,
const SkPaint paint,
SrcRectConstraint  constraint 
)
protectedvirtual

◆ onDrawOval()

virtual void SkCanvas::onDrawOval ( const SkRect rect,
const SkPaint paint 
)
protectedvirtual

◆ onDrawPaint()

virtual void SkCanvas::onDrawPaint ( const SkPaint paint)
protectedvirtual

◆ onDrawPatch()

virtual void SkCanvas::onDrawPatch ( const SkPoint  cubics[12],
const SkColor  colors[4],
const SkPoint  texCoords[4],
SkBlendMode  mode,
const SkPaint paint 
)
protectedvirtual

◆ onDrawPath()

virtual void SkCanvas::onDrawPath ( const SkPath path,
const SkPaint paint 
)
protectedvirtual

◆ onDrawPicture()

virtual void SkCanvas::onDrawPicture ( const SkPicture picture,
const SkMatrix matrix,
const SkPaint paint 
)
protectedvirtual

◆ onDrawPoints()

virtual void SkCanvas::onDrawPoints ( PointMode  mode,
size_t  count,
const SkPoint  pts[],
const SkPaint paint 
)
protectedvirtual

◆ onDrawRect()

virtual void SkCanvas::onDrawRect ( const SkRect rect,
const SkPaint paint 
)
protectedvirtual

◆ onDrawRegion()

virtual void SkCanvas::onDrawRegion ( const SkRegion region,
const SkPaint paint 
)
protectedvirtual

◆ onDrawRRect()

virtual void SkCanvas::onDrawRRect ( const SkRRect rrect,
const SkPaint paint 
)
protectedvirtual

◆ onDrawShadowRec()

virtual void SkCanvas::onDrawShadowRec ( const SkPath ,
const SkDrawShadowRec &   
)
protectedvirtual

◆ onDrawTextBlob()

virtual void SkCanvas::onDrawTextBlob ( const SkTextBlob blob,
SkScalar  x,
SkScalar  y,
const SkPaint paint 
)
protectedvirtual

◆ onDrawVerticesObject() [1/2]

virtual void SkCanvas::onDrawVerticesObject ( const SkVertices vertices,
SkBlendMode  mode,
const SkPaint paint 
)
inlineprotectedvirtual

◆ onDrawVerticesObject() [2/2]

virtual void SkCanvas::onDrawVerticesObject ( const SkVertices vertices,
const SkVertices::Bone  bones[],
int  boneCount,
SkBlendMode  mode,
const SkPaint paint 
)
protectedvirtual

◆ onFlush()

virtual void SkCanvas::onFlush ( )
protectedvirtual

◆ onGetProps()

virtual bool SkCanvas::onGetProps ( SkSurfaceProps props) const
protectedvirtual

◆ onImageInfo()

virtual SkImageInfo SkCanvas::onImageInfo ( ) const
protectedvirtual

◆ onNewSurface()

virtual sk_sp<SkSurface> SkCanvas::onNewSurface ( const SkImageInfo info,
const SkSurfaceProps props 
)
protectedvirtual

◆ onPeekPixels()

virtual bool SkCanvas::onPeekPixels ( SkPixmap pixmap)
protectedvirtual

◆ peekPixels()

bool SkCanvas::peekPixels ( SkPixmap pixmap)

Returns true if SkCanvas has direct access to its pixels.

Pixels are readable when SkBaseDevice is raster. Pixels are not readable when SkCanvas is returned from GPU surface, returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.

pixmap is valid only while SkCanvas is in scope and unchanged. Any SkCanvas or SkSurface call may invalidate the pixmap values.

Parameters
pixmapstorage for pixel state if pixels are readable; otherwise, ignored
Returns
true if SkCanvas has direct access to pixels

example: https://fiddle.skia.org/c/@Canvas_peekPixels

◆ private_draw_shadow_rec()

void SkCanvas::private_draw_shadow_rec ( const SkPath ,
const SkDrawShadowRec &   
)

◆ quickReject() [1/2]

bool SkCanvas::quickReject ( const SkRect rect) const

Returns true if SkRect rect, transformed by SkMatrix, 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.

Parameters
rectSkRect to compare with clip
Returns
true if rect, transformed by SkMatrix, does not intersect clip

example: https://fiddle.skia.org/c/@Canvas_quickReject

◆ quickReject() [2/2]

bool SkCanvas::quickReject ( const SkPath path) const

Returns true if path, transformed by SkMatrix, 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.

Parameters
pathSkPath to compare with clip
Returns
true if path, transformed by SkMatrix, does not intersect clip

example: https://fiddle.skia.org/c/@Canvas_quickReject_2

◆ readPixels() [1/3]

bool SkCanvas::readPixels ( const SkImageInfo dstInfo,
void *  dstPixels,
size_t  dstRowBytes,
int  srcX,
int  srcY 
)

Copies SkRect of pixels from SkCanvas into dstPixels.

SkMatrix and clip are ignored.

Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). Destination SkRect 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 SkBaseDevice is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.

The destination pixel storage must be allocated by the caller.

Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. dstPixels contents outside SkRect intersection are unchanged.

Pass negative values for srcX or srcY to offset pixels across or down destination.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.
  • SkCanvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType().
  • SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
  • dstRowBytes is too small to contain one row of pixels.
Parameters
dstInfowidth, height, SkColorType, and SkAlphaType of dstPixels
dstPixelsstorage 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
Returns
true if pixels were copied

◆ readPixels() [2/3]

bool SkCanvas::readPixels ( const SkPixmap pixmap,
int  srcX,
int  srcY 
)

Copies SkRect of pixels from SkCanvas into pixmap.

SkMatrix and clip are ignored.

Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). Destination SkRect corners are (0, 0) and (pixmap.width(), pixmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to pixmap.colorType() and pixmap.alphaType() if required.

Pixels are readable when SkBaseDevice is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.

Caller must allocate pixel storage in pixmap if needed.

Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination SkRect are copied. pixmap pixels contents outside SkRect intersection are unchanged.

Pass negative values for srcX or srcY to offset pixels across or down pixmap.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.
  • SkCanvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType().
  • SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
  • SkPixmap pixels could not be allocated.
  • pixmap.rowBytes() is too small to contain one row of pixels.
Parameters
pixmapstorage for pixels copied from SkCanvas
srcXoffset into readable pixels on x-axis; may be negative
srcYoffset into readable pixels on y-axis; may be negative
Returns
true if pixels were copied

example: https://fiddle.skia.org/c/@Canvas_readPixels_2

◆ readPixels() [3/3]

bool SkCanvas::readPixels ( const SkBitmap bitmap,
int  srcX,
int  srcY 
)

Copies SkRect of pixels from SkCanvas into bitmap.

SkMatrix and clip are ignored.

Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). Destination SkRect 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 SkBaseDevice is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.

Caller must allocate pixel storage in bitmap if needed.

SkBitmap values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. SkBitmap pixels outside SkRect intersection are unchanged.

Pass negative values for srcX or srcY to offset pixels across or down bitmap.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.
  • SkCanvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType().
  • SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
  • bitmap pixels could not be allocated.
  • bitmap.rowBytes() is too small to contain one row of pixels.
Parameters
bitmapstorage for pixels copied from SkCanvas
srcXoffset into readable pixels on x-axis; may be negative
srcYoffset into readable pixels on y-axis; may be negative
Returns
true if pixels were copied

example: https://fiddle.skia.org/c/@Canvas_readPixels_3

◆ resetMatrix()

void SkCanvas::resetMatrix ( )

Sets SkMatrix to the identity matrix.

Any prior matrix state is overwritten.

example: https://fiddle.skia.org/c/@Canvas_resetMatrix

◆ restore()

void SkCanvas::restore ( )

Removes changes to SkMatrix and clip since SkCanvas state was last saved.

The state is removed from the stack.

Does nothing if the stack is empty.

example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore

example: https://fiddle.skia.org/c/@Canvas_restore

◆ restoreToCount()

void SkCanvas::restoreToCount ( int  saveCount)

Restores state to SkMatrix and clip 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.

Parameters
saveCountdepth of state stack to restore

example: https://fiddle.skia.org/c/@Canvas_restoreToCount

◆ rotate() [1/2]

void SkCanvas::rotate ( SkScalar  degrees)

Rotates SkMatrix by degrees.

Positive degrees rotates clockwise.

Mathematically, replaces SkMatrix with a rotation matrix premultiplied with SkMatrix.

This has the effect of rotating the drawing by degrees before transforming the result with SkMatrix.

Parameters
degreesamount to rotate, in degrees

example: https://fiddle.skia.org/c/@Canvas_rotate

◆ rotate() [2/2]

void SkCanvas::rotate ( SkScalar  degrees,
SkScalar  px,
SkScalar  py 
)

Rotates SkMatrix by degrees about a point at (px, py).

Positive degrees rotates clockwise.

Mathematically, constructs a rotation matrix; premultiplies the rotation matrix by a translation matrix; then replaces SkMatrix with the resulting matrix premultiplied with SkMatrix.

This has the effect of rotating the drawing about a given point before transforming the result with SkMatrix.

Parameters
degreesamount to rotate, in degrees
pxx-axis value of the point to rotate about
pyy-axis value of the point to rotate about

example: https://fiddle.skia.org/c/@Canvas_rotate_2

◆ save()

int SkCanvas::save ( )

Saves SkMatrix and clip.

Calling restore() discards changes to SkMatrix and clip, restoring the SkMatrix and clip to their state when save() was called.

SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().

Saved SkCanvas 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.

Returns
depth of saved stack

example: https://fiddle.skia.org/c/@Canvas_save

◆ saveLayer() [1/3]

int SkCanvas::saveLayer ( const SkRect bounds,
const SkPaint paint 
)

Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing.

Calling restore() discards changes to SkMatrix and clip, and draws the SkBitmap.

SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().

SkRect bounds suggests but does not define the SkBitmap size. To clip drawing to a specific rectangle, use clipRect().

Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and SkBlendMode when restore() is called.

Call restoreToCount() with returned value to restore this and subsequent saves.

Parameters
boundshint to limit the size of the layer; may be nullptr
paintgraphics state for layer; may be nullptr
Returns
depth of saved stack

example: https://fiddle.skia.org/c/@Canvas_saveLayer

◆ saveLayer() [2/3]

int SkCanvas::saveLayer ( const SkRect bounds,
const SkPaint paint 
)
inline

Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing.

Calling restore() discards changes to SkMatrix and clip, and draws the SkBitmap.

SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().

SkRect bounds suggests but does not define the layer size. To clip drawing to a specific rectangle, use clipRect().

Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and SkBlendMode when restore() is called.

Call restoreToCount() with returned value to restore this and subsequent saves.

Parameters
boundshint to limit the size of layer; may be nullptr
paintgraphics state for layer; may be nullptr
Returns
depth of saved stack

◆ saveLayer() [3/3]

int SkCanvas::saveLayer ( const SaveLayerRec layerRec)

Saves SkMatrix and clip, and allocates SkBitmap for subsequent drawing.

Calling restore() discards changes to SkMatrix and clip, and blends SkBitmap with alpha opacity onto the prior layer.

SkMatrix 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.

Parameters
layerReclayer state
Returns
depth of save state stack before this call was made.

example: https://fiddle.skia.org/c/@Canvas_saveLayer_3

◆ saveLayerAlpha()

int SkCanvas::saveLayerAlpha ( const SkRect bounds,
U8CPU  alpha 
)

Saves SkMatrix and clip, and allocates SkBitmap for subsequent drawing.

Calling restore() discards changes to SkMatrix and clip, and blends layer with alpha opacity onto prior layer.

SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().

SkRect 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.

Parameters
boundshint to limit the size of layer; may be nullptr
alphaopacity of layer
Returns
depth of saved stack

example: https://fiddle.skia.org/c/@Canvas_saveLayerAlpha

◆ scale()

void SkCanvas::scale ( SkScalar  sx,
SkScalar  sy 
)

Scales SkMatrix by sx on the x-axis and sy on the y-axis.

Mathematically, replaces SkMatrix with a scale matrix premultiplied with SkMatrix.

This has the effect of scaling the drawing by (sx, sy) before transforming the result with SkMatrix.

Parameters
sxamount to scale on x-axis
syamount to scale on y-axis

example: https://fiddle.skia.org/c/@Canvas_scale

◆ setMatrix()

void SkCanvas::setMatrix ( const SkMatrix matrix)

Replaces SkMatrix with matrix.

Unlike concat(), any prior matrix state is overwritten.

Parameters
matrixmatrix to copy, replacing existing SkMatrix

example: https://fiddle.skia.org/c/@Canvas_setMatrix

◆ skew()

void SkCanvas::skew ( SkScalar  sx,
SkScalar  sy 
)

Skews SkMatrix by sx on the x-axis and sy on the y-axis.

A positive value of sx skews the drawing right as y-axis values increase; a positive value of sy skews the drawing down as x-axis values increase.

Mathematically, replaces SkMatrix with a skew matrix premultiplied with SkMatrix.

This has the effect of skewing the drawing by (sx, sy) before transforming the result with SkMatrix.

Parameters
sxamount to skew on x-axis
syamount to skew on y-axis

example: https://fiddle.skia.org/c/@Canvas_skew

◆ temporary_internal_getRgnClip()

void SkCanvas::temporary_internal_getRgnClip ( SkRegion region)

Returns the global clip as a region.

If the clip contains AA, then only the bounds of the clip may be returned.

◆ translate()

void SkCanvas::translate ( SkScalar  dx,
SkScalar  dy 
)

Translates SkMatrix by dx along the x-axis and dy along the y-axis.

Mathematically, replaces SkMatrix with a translation matrix premultiplied with SkMatrix.

This has the effect of moving the drawing by (dx, dy) before transforming the result with SkMatrix.

Parameters
dxdistance to translate on x-axis
dydistance to translate on y-axis

example: https://fiddle.skia.org/c/@Canvas_translate

◆ willRestore()

virtual void SkCanvas::willRestore ( )
inlineprotectedvirtual

◆ willSave()

virtual void SkCanvas::willSave ( )
inlineprotectedvirtual

◆ writePixels() [1/2]

bool SkCanvas::writePixels ( const SkImageInfo info,
const void *  pixels,
size_t  rowBytes,
int  x,
int  y 
)

Copies SkRect from pixels to SkCanvas.

SkMatrix and clip are ignored. Source SkRect corners are (0, 0) and (info.width(), info.height()). Destination SkRect corners are (x, y) and (imageInfo().width(), imageInfo().height()).

Copies each readable pixel intersecting both rectangles, without scaling, converting to imageInfo().colorType() and imageInfo().alphaType() if required.

Pixels are writable when SkBaseDevice is raster, or backed by a GPU. Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.

Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. SkCanvas pixels outside SkRect intersection are unchanged.

Pass negative values for x or y to offset pixels to the left or above SkCanvas pixels.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.
  • pixels could not be converted to SkCanvas imageInfo().colorType() or imageInfo().alphaType().
  • SkCanvas pixels are not writable; for instance, SkCanvas is document-based.
  • rowBytes is too small to contain one row of pixels.
Parameters
infowidth, height, SkColorType, and SkAlphaType of pixels
pixelspixels to copy, of size info.height() times rowBytes, or larger
rowBytessize of one row of pixels; info.width() times pixel size, or larger
xoffset into SkCanvas writable pixels on x-axis; may be negative
yoffset into SkCanvas writable pixels on y-axis; may be negative
Returns
true if pixels were written to SkCanvas

example: https://fiddle.skia.org/c/@Canvas_writePixels

◆ writePixels() [2/2]

bool SkCanvas::writePixels ( const SkBitmap bitmap,
int  x,
int  y 
)

Copies SkRect from pixels to SkCanvas.

SkMatrix and clip are ignored. Source SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()).

Destination SkRect corners are (x, y) and (imageInfo().width(), imageInfo().height()).

Copies each readable pixel intersecting both rectangles, without scaling, converting to imageInfo().colorType() and imageInfo().alphaType() if required.

Pixels are writable when SkBaseDevice is raster, or backed by a GPU. Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.

Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. SkCanvas pixels outside SkRect intersection are unchanged.

Pass negative values for x or y to offset pixels to the left or above SkCanvas pixels.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.
  • bitmap does not have allocated pixels.
  • bitmap pixels could not be converted to SkCanvas imageInfo().colorType() or imageInfo().alphaType().
  • SkCanvas pixels are not writable; for instance, SkCanvas is document based.
  • bitmap pixels are inaccessible; for instance, bitmap wraps a texture.
Parameters
bitmapcontains pixels copied to SkCanvas
xoffset into SkCanvas writable pixels on x-axis; may be negative
yoffset into SkCanvas writable pixels on y-axis; may be negative
Returns
true if pixels were written to SkCanvas

example: https://fiddle.skia.org/c/@Canvas_writePixels_2 example: https://fiddle.skia.org/c/@State_Stack_a example: https://fiddle.skia.org/c/@State_Stack_b

Friends And Related Function Documentation

◆ AutoLayerForImageFilter

friend class AutoLayerForImageFilter
friend

◆ SkAndroidFrameworkUtils

friend class SkAndroidFrameworkUtils
friend

◆ SkCanvasPriv

friend class SkCanvasPriv
friend

◆ SkCanvasStateUtils

friend class SkCanvasStateUtils
friend

◆ SkDrawIter

friend class SkDrawIter
friend

◆ SkNoDrawCanvas

friend class SkNoDrawCanvas
friend

◆ SkOverdrawCanvas

friend class SkOverdrawCanvas
friend

◆ SkPictureRecord

friend class SkPictureRecord
friend

◆ SkRasterHandleAllocator

friend class SkRasterHandleAllocator
friend

◆ SkSurface_Base

friend class SkSurface_Base
friend

◆ SkSurface_Gpu

friend class SkSurface_Gpu
friend

◆ SkSurface_Raster

friend class SkSurface_Raster
friend

The documentation for this class was generated from the following file: