Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Private Member Functions | Friends | List of all members
SkCanvas Class Reference

#include <SkCanvas.h>

Inheritance diagram for SkCanvas:
SkCanvasVirtualEnforcer< SkCanvas > ClipCountingCanvas SaveCountingCanvas SkTestCanvas< SkRemoteSlugTestKey > SkTestCanvas< SkSerializeSlugTestKey > SkTestCanvas< SkSlugTestKey > TestAnnotationCanvas DebugCanvas MSKPPlayer::CmdRecordCanvas SkNoDrawCanvas SkPictureRecord SkCanvasVirtualEnforcer< SkNoDrawCanvas > SkNWayCanvas SkRecorder flutter::DidDrawCanvas SkCanvasVirtualEnforcer< SkNWayCanvas > SkCanvasStack SkOverdrawCanvas SkPaintFilterCanvas DebugPaintFilterCanvas OveridePaintFilterCanvas

Classes

class  AutoUpdateQRBounds
 
struct  ImageSetEntry
 
struct  Lattice
 
struct  SaveLayerRec
 

Public Types

enum  SaveLayerFlagsSet { kPreserveLCDText_SaveLayerFlag = 1 << 1 , kInitWithPrevious_SaveLayerFlag = 1 << 2 , 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
}
 
using SaveLayerFlags = uint32_t
 
using FilterSpan = SkSpan< sk_sp< SkImageFilter > >
 

Public Member Functions

 SkCanvas ()
 
 SkCanvas (int width, int height, const SkSurfaceProps *props=nullptr)
 
 SkCanvas (sk_sp< SkDevice > device)
 
 SkCanvas (const SkBitmap &bitmap)
 
 SkCanvas (const SkBitmap &bitmap, const SkSurfaceProps &props)
 
virtual ~SkCanvas ()
 
SkImageInfo imageInfo () const
 
bool getProps (SkSurfaceProps *props) const
 
SkSurfaceProps getBaseProps () const
 
SkSurfaceProps getTopProps () const
 
virtual SkISize getBaseLayerSize () const
 
sk_sp< SkSurfacemakeSurface (const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
 
virtual GrRecordingContextrecordingContext () const
 
virtual skgpu::graphite::Recorderrecorder () const
 
SkSurfacegetSurface () const
 
void * accessTopLayerPixels (SkImageInfo *info, size_t *rowBytes, SkIPoint *origin=nullptr)
 
SkRasterHandleAllocator::Handle accessTopRasterHandle () const
 
bool peekPixels (SkPixmap *pixmap)
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY)
 
bool readPixels (const SkPixmap &pixmap, int srcX, int srcY)
 
bool readPixels (const SkBitmap &bitmap, int srcX, int srcY)
 
bool writePixels (const SkImageInfo &info, const void *pixels, size_t rowBytes, int x, int y)
 
bool writePixels (const SkBitmap &bitmap, int x, int y)
 
int save ()
 
int saveLayer (const SkRect *bounds, const SkPaint *paint)
 
int saveLayer (const SkRect &bounds, const SkPaint *paint)
 
int saveLayerAlphaf (const SkRect *bounds, float alpha)
 
int saveLayerAlpha (const SkRect *bounds, U8CPU alpha)
 
int saveLayer (const SaveLayerRec &layerRec)
 
void restore ()
 
int getSaveCount () const
 
void restoreToCount (int saveCount)
 
void translate (SkScalar dx, SkScalar dy)
 
void scale (SkScalar sx, SkScalar sy)
 
void rotate (SkScalar degrees)
 
void rotate (SkScalar degrees, SkScalar px, SkScalar py)
 
void skew (SkScalar sx, SkScalar sy)
 
void concat (const SkMatrix &matrix)
 
void concat (const SkM44 &)
 
void setMatrix (const SkM44 &matrix)
 
void setMatrix (const SkMatrix &matrix)
 
void resetMatrix ()
 
void clipRect (const SkRect &rect, SkClipOp op, bool doAntiAlias)
 
void clipRect (const SkRect &rect, SkClipOp op)
 
void clipRect (const SkRect &rect, bool doAntiAlias=false)
 
void clipIRect (const SkIRect &irect, SkClipOp op=SkClipOp::kIntersect)
 
void androidFramework_setDeviceClipRestriction (const SkIRect &rect)
 
void clipRRect (const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
 
void clipRRect (const SkRRect &rrect, SkClipOp op)
 
void clipRRect (const SkRRect &rrect, bool doAntiAlias=false)
 
void clipPath (const SkPath &path, SkClipOp op, bool doAntiAlias)
 
void clipPath (const SkPath &path, SkClipOp op)
 
void clipPath (const SkPath &path, bool doAntiAlias=false)
 
void clipShader (sk_sp< SkShader >, SkClipOp=SkClipOp::kIntersect)
 
void clipRegion (const SkRegion &deviceRgn, SkClipOp op=SkClipOp::kIntersect)
 
bool quickReject (const SkRect &rect) const
 
bool quickReject (const SkPath &path) const
 
SkRect getLocalClipBounds () const
 
bool getLocalClipBounds (SkRect *bounds) const
 
SkIRect getDeviceClipBounds () const
 
bool getDeviceClipBounds (SkIRect *bounds) const
 
void drawColor (SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
 
void drawColor (const SkColor4f &color, SkBlendMode mode=SkBlendMode::kSrcOver)
 
void clear (SkColor color)
 
void clear (const SkColor4f &color)
 
void discard ()
 
void drawPaint (const SkPaint &paint)
 
void drawPoints (PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
 
void drawPoint (SkScalar x, SkScalar y, const SkPaint &paint)
 
void drawPoint (SkPoint p, const SkPaint &paint)
 
void drawLine (SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
 
void drawLine (SkPoint p0, SkPoint p1, const SkPaint &paint)
 
void drawRect (const SkRect &rect, const SkPaint &paint)
 
void drawIRect (const SkIRect &rect, const SkPaint &paint)
 
void drawRegion (const SkRegion &region, const SkPaint &paint)
 
void drawOval (const SkRect &oval, const SkPaint &paint)
 
void drawRRect (const SkRRect &rrect, const SkPaint &paint)
 
void drawDRRect (const SkRRect &outer, const SkRRect &inner, const SkPaint &paint)
 
void drawCircle (SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
 
void drawCircle (SkPoint center, SkScalar radius, const SkPaint &paint)
 
void drawArc (const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
 
void drawArc (const SkArc &arc, const SkPaint &paint)
 
void drawRoundRect (const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint)
 
void drawPath (const SkPath &path, const SkPaint &paint)
 
void drawImage (const SkImage *image, SkScalar left, SkScalar top)
 
void drawImage (const sk_sp< SkImage > &image, SkScalar left, SkScalar top)
 
void drawImage (const SkImage *, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *=nullptr)
 
void drawImage (const sk_sp< SkImage > &image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling, const SkPaint *paint=nullptr)
 
void drawImageRect (const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
 
void drawImageRect (const SkImage *, const SkRect &dst, const SkSamplingOptions &, const SkPaint *=nullptr)
 
void drawImageRect (const sk_sp< SkImage > &image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling, const SkPaint *paint, SrcRectConstraint constraint)
 
void drawImageRect (const sk_sp< SkImage > &image, const SkRect &dst, const SkSamplingOptions &sampling, const SkPaint *paint=nullptr)
 
void drawImageNine (const SkImage *image, const SkIRect &center, const SkRect &dst, SkFilterMode filter, const SkPaint *paint=nullptr)
 
void drawImageLattice (const SkImage *image, const Lattice &lattice, const SkRect &dst, SkFilterMode filter, const SkPaint *paint=nullptr)
 
void drawImageLattice (const SkImage *image, const Lattice &lattice, const SkRect &dst)
 
void experimental_DrawEdgeAAQuad (const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
 
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 SkSamplingOptions &, const SkPaint *paint=nullptr, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
 
void drawSimpleText (const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
 
void drawString (const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
 
void drawString (const SkString &str, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
 
void drawGlyphs (int count, const SkGlyphID glyphs[], const SkPoint positions[], const uint32_t clusters[], int textByteCount, const char utf8text[], SkPoint origin, const SkFont &font, const SkPaint &paint)
 
void drawGlyphs (int count, const SkGlyphID glyphs[], const SkPoint positions[], SkPoint origin, const SkFont &font, const SkPaint &paint)
 
void drawGlyphs (int count, const SkGlyphID glyphs[], const SkRSXform xforms[], SkPoint origin, const SkFont &font, const SkPaint &paint)
 
void drawTextBlob (const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
 
void drawTextBlob (const sk_sp< SkTextBlob > &blob, SkScalar x, SkScalar y, const SkPaint &paint)
 
void drawPicture (const SkPicture *picture)
 
void drawPicture (const sk_sp< SkPicture > &picture)
 
void drawPicture (const SkPicture *picture, const SkMatrix *matrix, const SkPaint *paint)
 
void drawPicture (const sk_sp< SkPicture > &picture, const SkMatrix *matrix, const SkPaint *paint)
 
void drawVertices (const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
 
void drawVertices (const sk_sp< SkVertices > &vertices, SkBlendMode mode, const SkPaint &paint)
 
void drawMesh (const SkMesh &mesh, sk_sp< SkBlender > blender, const SkPaint &paint)
 
void drawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode mode, const SkPaint &paint)
 
void drawAtlas (const SkImage *atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkBlendMode mode, const SkSamplingOptions &sampling, const SkRect *cullRect, const SkPaint *paint)
 
void drawDrawable (SkDrawable *drawable, const SkMatrix *matrix=nullptr)
 
void drawDrawable (SkDrawable *drawable, SkScalar x, SkScalar y)
 
void drawAnnotation (const SkRect &rect, const char key[], SkData *value)
 
void drawAnnotation (const SkRect &rect, const char key[], const sk_sp< SkData > &value)
 
virtual bool isClipEmpty () const
 
virtual bool isClipRect () const
 
SkM44 getLocalToDevice () const
 
SkMatrix getLocalToDeviceAs3x3 () const
 
SkMatrix getTotalMatrix () const
 
void temporary_internal_getRgnClip (SkRegion *region)
 
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)
 
static std::unique_ptr< SkCanvasMakeRasterDirectN32 (int width, int height, SkPMColor *pixels, size_t rowBytes)
 

Static Public Attributes

static constexpr int kMaxFiltersPerLayer = 16
 

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, bool top) const
 
virtual void willSave ()
 
virtual SaveLayerStrategy getSaveLayerStrategy (const SaveLayerRec &)
 
virtual bool onDoSaveBehind (const SkRect *)
 
virtual void willRestore ()
 
virtual void didRestore ()
 
virtual void didConcat44 (const SkM44 &)
 
virtual void didSetM44 (const SkM44 &)
 
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 onDrawGlyphRunList (const sktext::GlyphRunList &glyphRunList, 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 onDrawImage2 (const SkImage *, SkScalar dx, SkScalar dy, const SkSamplingOptions &, const SkPaint *)
 
virtual void onDrawImageRect2 (const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
 
virtual void onDrawImageLattice2 (const SkImage *, const Lattice &, const SkRect &dst, SkFilterMode, const SkPaint *)
 
virtual void onDrawAtlas2 (const SkImage *, const SkRSXform[], const SkRect src[], const SkColor[], int count, SkBlendMode, const SkSamplingOptions &, const SkRect *cull, const SkPaint *)
 
virtual void onDrawEdgeAAImageSet2 (const ImageSetEntry imageSet[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
 
virtual void onDrawVerticesObject (const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
 
virtual void onDrawMesh (const SkMesh &, sk_sp< SkBlender >, const SkPaint &)
 
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 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 onClipShader (sk_sp< SkShader >, SkClipOp)
 
virtual void onClipRegion (const SkRegion &deviceRgn, SkClipOp op)
 
virtual void onResetClip ()
 
virtual void onDiscard ()
 
virtual sk_sp< sktext::gpu::SlugonConvertGlyphRunListToSlug (const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
 
virtual void onDrawSlug (const sktext::gpu::Slug *slug, const SkPaint &paint)
 
 SkCanvas (const SkIRect &bounds)
 

Private Member Functions

virtual SkPaintFilterCanvasinternal_private_asPaintFilterCanvas () const
 

Friends

class SkSurface_Base
 
class SkSurface_Ganesh
 
class SkAndroidFrameworkUtils
 
class SkCanvasPriv
 
class AutoLayerForImageFilter
 
class SkSurface_Raster
 
class SkNoDrawCanvas
 
class SkNWayCanvas
 
class SkPictureRecord
 
class SkOverdrawCanvas
 
class SkRasterHandleAllocator
 
class SkRecords::Draw
 
template<typename Key >
class SkTestCanvas
 
class sktext::gpu::Slug
 
class SkPicturePlayback
 
class SkCanvasStateUtils
 
constexpr SkEnumBitMask< PredrawFlags > operator| (PredrawFlags, PredrawFlags)
 
constexpr SkEnumBitMask< PredrawFlags > operator& (PredrawFlags, PredrawFlags)
 
constexpr SkEnumBitMask< PredrawFlags > operator^ (PredrawFlags, PredrawFlags)
 
constexpr SkEnumBitMask< PredrawFlags > operator~ (PredrawFlags)
 

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 SkDevice. 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 SkDevice describing the destination.

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

Definition at line 106 of file SkCanvas.h.

Member Typedef Documentation

◆ FilterSpan

Definition at line 678 of file SkCanvas.h.

◆ SaveLayerFlags

using SkCanvas::SaveLayerFlags = uint32_t

Definition at line 677 of file SkCanvas.h.

Member Enumeration Documentation

◆ ClipEdgeStyle

enum SkCanvas::ClipEdgeStyle
protected
Enumerator
kHard_ClipEdgeStyle 
kSoft_ClipEdgeStyle 

Definition at line 2335 of file SkCanvas.h.

2335 {
2338 };
@ kHard_ClipEdgeStyle
Definition SkCanvas.h:2336
@ kSoft_ClipEdgeStyle
Definition SkCanvas.h:2337

◆ 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

Definition at line 1240 of file SkCanvas.h.

1240 {
1241 kPoints_PointMode, //!< draw each point separately
1242 kLines_PointMode, //!< draw each pair of points as a line segment
1243 kPolygon_PointMode, //!< draw the array of points as a open polygon
1244 };
@ kLines_PointMode
draw each pair of points as a line segment
Definition SkCanvas.h:1242
@ kPolygon_PointMode
draw the array of points as a open polygon
Definition SkCanvas.h:1243
@ kPoints_PointMode
draw each point separately
Definition SkCanvas.h:1241

◆ 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 

Definition at line 1658 of file SkCanvas.h.

1658 : unsigned {
1659 kLeft_QuadAAFlag = 0b0001,
1660 kTop_QuadAAFlag = 0b0010,
1661 kRight_QuadAAFlag = 0b0100,
1662 kBottom_QuadAAFlag = 0b1000,
1663
1664 kNone_QuadAAFlags = 0b0000,
1665 kAll_QuadAAFlags = 0b1111,
1666 };
@ kTop_QuadAAFlag
Definition SkCanvas.h:1660
@ kRight_QuadAAFlag
Definition SkCanvas.h:1661
@ kLeft_QuadAAFlag
Definition SkCanvas.h:1659
@ kBottom_QuadAAFlag
Definition SkCanvas.h:1662
@ kNone_QuadAAFlags
Definition SkCanvas.h:1664
@ kAll_QuadAAFlags
Definition SkCanvas.h:1665

◆ SaveLayerFlagsSet

Enumerator
kPreserveLCDText_SaveLayerFlag 
kInitWithPrevious_SaveLayerFlag 

initializes with previous contents

kF16ColorType 

Definition at line 670 of file SkCanvas.h.

670 {
672 kInitWithPrevious_SaveLayerFlag = 1 << 2, //!< initializes with previous contents
673 // instead of matching previous layer's colortype, use F16
674 kF16ColorType = 1 << 4,
675 };
@ kPreserveLCDText_SaveLayerFlag
Definition SkCanvas.h:671
@ kF16ColorType
Definition SkCanvas.h:674
@ kInitWithPrevious_SaveLayerFlag
initializes with previous contents
Definition SkCanvas.h:672

◆ SaveLayerStrategy

Enumerator
kFullLayer_SaveLayerStrategy 
kNoLayer_SaveLayerStrategy 

Definition at line 2263 of file SkCanvas.h.

2263 {
2266 };
@ kFullLayer_SaveLayerStrategy
Definition SkCanvas.h:2264
@ kNoLayer_SaveLayerStrategy
Definition SkCanvas.h:2265

◆ SrcRectConstraint

Enumerator
kStrict_SrcRectConstraint 

sample only inside bounds; slower

kFast_SrcRectConstraint 

sample outside bounds; faster

Definition at line 1541 of file SkCanvas.h.

1541 {
1542 kStrict_SrcRectConstraint, //!< sample only inside bounds; slower
1543 kFast_SrcRectConstraint, //!< sample outside bounds; faster
1544 };
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition SkCanvas.h:1542
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition SkCanvas.h:1543

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

Definition at line 328 of file SkCanvas.cpp.

328 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
329 this->init(nullptr);
330}

◆ 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

Definition at line 332 of file SkCanvas.cpp.

333 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
334 , fProps(SkSurfacePropsCopyOrDefault(props)) {
335 this->init(sk_make_sp<SkNoPixelsDevice>(
336 SkIRect::MakeWH(std::max(width, 0), std::max(height, 0)), fProps));
337}
static SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps *props)
int32_t height
int32_t width
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56

◆ SkCanvas() [3/6]

SkCanvas::SkCanvas ( sk_sp< SkDevice device)
explicit

Private. For internal use only.

Definition at line 345 of file SkCanvas.cpp.

346 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
347 , fProps(device->surfaceProps()) {
348 this->init(std::move(device));
349}
VkDevice device
Definition main.cc:53

◆ SkCanvas() [4/6]

SkCanvas::SkCanvas ( const SkBitmap bitmap)
explicit

Constructs a canvas that draws into bitmap. Sets kUnknown_SkPixelGeometry 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

Definition at line 44 of file SkCanvas_Raster.cpp.

44: SkCanvas(bitmap, nullptr, nullptr, nullptr) {}

◆ 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

Definition at line 29 of file SkCanvas_Raster.cpp.

30 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)), fProps(props) {
31 this->init(sk_make_sp<SkBitmapDevice>(bitmap, fProps));
32}

◆ ~SkCanvas()

SkCanvas::~SkCanvas ( )
virtual

Draws saved layers, if any. Frees up resources used by SkCanvas.

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

Definition at line 351 of file SkCanvas.cpp.

351 {
352 // Mark all pending layers to be discarded during restore (rather than drawn)
354 for (;;) {
355 MCRec* rec = (MCRec*)iter.next();
356 if (!rec) {
357 break;
358 }
359 if (rec->fLayer) {
360 rec->fLayer->fDiscard = true;
361 }
362 }
363
364 // free up the contents of our deque
365 this->restoreToCount(1); // restore everything but the last
366 this->internalRestore(); // restore the last, since we're going away
367}
void restoreToCount(int saveCount)
Definition SkCanvas.cpp:482
@ kFront_IterStart
Definition SkDeque.h:65

◆ SkCanvas() [6/6]

SkCanvas::SkCanvas ( const SkIRect bounds)
protected

Definition at line 339 of file SkCanvas.cpp.

340 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
341 SkIRect r = bounds.isEmpty() ? SkIRect::MakeEmpty() : bounds;
342 this->init(sk_make_sp<SkNoPixelsDevice>(r, fProps));
343}
Optional< SkRect > bounds
Definition SkRecords.h:189
static constexpr SkIRect MakeEmpty()
Definition SkRect.h:45

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

Definition at line 1569 of file SkCanvas.cpp.

1569 {
1570 SkPixmap pmap;
1571 if (!this->onAccessTopLayerPixels(&pmap)) {
1572 return nullptr;
1573 }
1574 if (info) {
1575 *info = pmap.info();
1576 }
1577 if (rowBytes) {
1578 *rowBytes = pmap.rowBytes();
1579 }
1580 if (origin) {
1581 // If the caller requested the origin, they presumably are expecting the returned pixels to
1582 // be axis-aligned with the root canvas. If the top level device isn't axis aligned, that's
1583 // not the case. Until we update accessTopLayerPixels() to accept a coord space matrix
1584 // instead of an origin, just don't expose the pixels in that case. Note that this means
1585 // that layers with complex coordinate spaces can still report their pixels if the caller
1586 // does not ask for the origin (e.g. just to dump its output to a file, etc).
1587 if (this->topDevice()->isPixelAlignedToGlobal()) {
1588 *origin = this->topDevice()->getOrigin();
1589 } else {
1590 return nullptr;
1591 }
1592 }
1593 return pmap.writable_addr();
1594}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
virtual bool onAccessTopLayerPixels(SkPixmap *pixmap)
SkIPoint getOrigin() const
Definition SkDevice.cpp:90
size_t rowBytes() const
Definition SkPixmap.h:145
const SkImageInfo & info() const
Definition SkPixmap.h:135
void * writable_addr() const
Definition SkPixmap.h:483

◆ 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

Definition at line 3268 of file SkCanvas.cpp.

3268 {
3269 const SkDevice* dev = this->topDevice();
3270 if (fAllocator) {
3272 SkIRect clip = dev->devClipBounds();
3273 if (!clip.intersect({0, 0, dev->width(), dev->height()})) {
3274 clip.setEmpty();
3275 }
3276
3277 fAllocator->updateHandle(handle, dev->localToDevice(), clip);
3278 return handle;
3279 }
3280 return nullptr;
3281}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
virtual void * getRasterHandle() const
Definition SkDevice.h:282
const SkMatrix & localToDevice() const
Definition SkDevice.h:179
virtual SkIRect devClipBounds() const =0

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

DEPRECATED: Replace usage with SkAndroidFrameworkUtils::replaceClip()

Parameters
rectmaximum allowed clip in device coordinates

Definition at line 1702 of file SkCanvas.cpp.

1702 {
1703 // The device clip restriction is a surface-space rectangular intersection that cannot be
1704 // drawn outside of. The rectangle is remembered so that subsequent resetClip calls still
1705 // respect the restriction. Other than clip resetting, all clip operations restrict the set
1706 // of renderable pixels, so once set, the restriction will be respected until the canvas
1707 // save stack is restored past the point this function was invoked. Unfortunately, the current
1708 // implementation relies on the clip stack of the underyling SkDevices, which leads to some
1709 // awkward behavioral interactions (see skbug.com/12252).
1710 //
1711 // Namely, a canvas restore() could undo the clip restriction's rect, and if
1712 // setDeviceClipRestriction were called at a nested save level, there's no way to undo just the
1713 // prior restriction and re-apply the new one. It also only makes sense to apply to the base
1714 // device; any other device for a saved layer will be clipped back to the base device during its
1715 // matched restore. As such, we:
1716 // - Remember the save count that added the clip restriction and reset the rect to empty when
1717 // we've restored past that point to keep our state in sync with the device's clip stack.
1718 // - We assert that we're on the base device when this is invoked.
1719 // - We assert that setDeviceClipRestriction() is only called when there was no prior
1720 // restriction (cannot re-restrict, and prior state must have been reset by restoring the
1721 // canvas state).
1722 // - Historically, the empty rect would reset the clip restriction but it only could do so
1723 // partially since the device's clips wasn't adjusted. Resetting is now handled
1724 // automatically via SkCanvas::restore(), so empty input rects are skipped.
1725 SkASSERT(this->topDevice() == this->rootDevice()); // shouldn't be in a nested layer
1726 // and shouldn't already have a restriction
1727 SkASSERT(fClipRestrictionSaveCount < 0 && fClipRestrictionRect.isEmpty());
1728
1729 if (fClipRestrictionSaveCount < 0 && !rect.isEmpty()) {
1730 fClipRestrictionRect = rect;
1731 fClipRestrictionSaveCount = this->getSaveCount();
1732
1733 // A non-empty clip restriction immediately applies an intersection op (ignoring the ctm).
1734 // so we have to resolve the save.
1735 this->checkForDeferredSave();
1736 AutoUpdateQRBounds aqr(this);
1737 // Use clipRegion() since that operates in canvas-space, whereas clipRect() would apply the
1738 // device's current transform first.
1739 this->topDevice()->clipRegion(SkRegion(rect), SkClipOp::kIntersect);
1740 }
1741}
#define SkASSERT(cond)
Definition SkAssert.h:116
int getSaveCount() const
Definition SkCanvas.cpp:435
virtual void clipRegion(const SkRegion &region, SkClipOp op)=0
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
bool isEmpty() const
Definition SkRect.h:202

◆ clear() [1/2]

void SkCanvas::clear ( const SkColor4f color)
inline

Fills clip with color color using SkBlendMode::kSrc. This has the effect of replacing all pixels contained by clip with color.

Parameters
colorSkColor4f representing unpremultiplied color.

Definition at line 1208 of file SkCanvas.h.

1208 {
1209 this->drawColor(color, SkBlendMode::kSrc);
1210 }
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182

◆ clear() [2/2]

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

Definition at line 1199 of file SkCanvas.h.

1199 {
1201 }
SkColor4f color
void clear(SkColor color)
Definition SkCanvas.h:1199
static SkRGBA4f FromColor(SkColor color)

◆ clipIRect()

void SkCanvas::clipIRect ( const SkIRect irect,
SkClipOp  op = SkClipOp::kIntersect 
)
inline

Definition at line 991 of file SkCanvas.h.

991 {
992 this->clipRect(SkRect::Make(irect), op, false);
993 }
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
static SkRect Make(const SkISize &size)
Definition SkRect.h:669

◆ clipPath() [1/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

Definition at line 1083 of file SkCanvas.h.

1083 {
1084 this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
1085 }
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)

◆ 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

Definition at line 1069 of file SkCanvas.h.

1069 {
1070 this->clipPath(path, op, false);
1071 }

◆ clipPath() [3/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

Definition at line 1780 of file SkCanvas.cpp.

1780 {
1781 this->checkForDeferredSave();
1783
1784 if (!path.isInverseFillType() && fMCRec->fMatrix.asM33().rectStaysRect()) {
1785 SkRect r;
1786 if (path.isRect(&r)) {
1787 this->onClipRect(r, op, edgeStyle);
1788 return;
1789 }
1790 SkRRect rrect;
1791 if (path.isOval(&r)) {
1792 rrect.setOval(r);
1793 this->onClipRRect(rrect, op, edgeStyle);
1794 return;
1795 }
1796 if (path.isRRect(&rrect)) {
1797 this->onClipRRect(rrect, op, edgeStyle);
1798 return;
1799 }
1800 }
1801
1802 this->onClipPath(path, op, edgeStyle);
1803}
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)
void setOval(const SkRect &oval)
Definition SkRRect.cpp:30
SkRRect rrect
Definition SkRecords.h:232
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57

◆ clipRect() [1/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

Definition at line 987 of file SkCanvas.h.

987 {
988 this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
989 }

◆ 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

Definition at line 975 of file SkCanvas.h.

975 {
976 this->clipRect(rect, op, false);
977 }

◆ clipRect() [3/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

Definition at line 1685 of file SkCanvas.cpp.

1685 {
1686 if (!rect.isFinite()) {
1687 return;
1688 }
1689 this->checkForDeferredSave();
1691 this->onClipRect(rect.makeSorted(), op, edgeStyle);
1692}
SkRect makeSorted() const
Definition SkRect.h:1330

◆ 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

Definition at line 1834 of file SkCanvas.cpp.

1834 {
1835 this->checkForDeferredSave();
1836 this->onClipRegion(rgn, op);
1837}
virtual void onClipRegion(const SkRegion &deviceRgn, SkClipOp op)

◆ clipRRect() [1/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

Definition at line 1040 of file SkCanvas.h.

1040 {
1041 this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
1042 }
void clipRRect(const SkRRect &rrect, SkClipOp op, bool doAntiAlias)

◆ 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

Definition at line 1029 of file SkCanvas.h.

1029 {
1030 this->clipRRect(rrect, op, false);
1031 }

◆ clipRRect() [3/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

Definition at line 1763 of file SkCanvas.cpp.

1763 {
1764 this->checkForDeferredSave();
1766 if (rrect.isRect()) {
1767 this->onClipRect(rrect.getBounds(), op, edgeStyle);
1768 } else {
1769 this->onClipRRect(rrect, op, edgeStyle);
1770 }
1771}
bool isRect() const
Definition SkRRect.h:84
const SkRect & getBounds() const
Definition SkRRect.h:279

◆ clipShader()

void SkCanvas::clipShader ( sk_sp< SkShader sh,
SkClipOp  op = SkClipOp::kIntersect 
)

Definition at line 1812 of file SkCanvas.cpp.

1812 {
1813 if (sh) {
1814 if (sh->isOpaque()) {
1815 if (op == SkClipOp::kIntersect) {
1816 // we don't occlude anything, so skip this call
1817 } else {
1819 // we occlude everything, so set the clip to empty
1820 this->clipRect({0,0,0,0});
1821 }
1822 } else {
1823 this->checkForDeferredSave();
1824 this->onClipShader(std::move(sh), op);
1825 }
1826 }
1827}
virtual void onClipShader(sk_sp< SkShader >, SkClipOp)

◆ concat() [1/2]

void SkCanvas::concat ( const SkM44 m)

Definition at line 1657 of file SkCanvas.cpp.

1657 {
1658 this->internalConcat44(m);
1659 // notify subclasses
1660 this->didConcat44(m);
1661}
virtual void didConcat44(const SkM44 &)
Definition SkCanvas.h:2279

◆ concat() [2/2]

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

Definition at line 1642 of file SkCanvas.cpp.

1642 {
1643 if (matrix.isIdentity()) {
1644 return;
1645 }
1646 this->concat(SkM44(matrix));
1647}
void concat(const SkMatrix &matrix)
Definition SkM44.h:150
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258

◆ didConcat44()

virtual void SkCanvas::didConcat44 ( const SkM44 )
inlineprotectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, and DebugCanvas.

Definition at line 2279 of file SkCanvas.h.

2279{}

◆ didRestore()

virtual void SkCanvas::didRestore ( )
inlineprotectedvirtual

Reimplemented in SkRecorder.

Definition at line 2277 of file SkCanvas.h.

2277{}

◆ didScale()

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

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, and DebugCanvas.

Definition at line 2282 of file SkCanvas.h.

2282{}

◆ didSetM44()

virtual void SkCanvas::didSetM44 ( const SkM44 )
inlineprotectedvirtual

Reimplemented in SkNWayCanvas, SkPictureRecord, SkRecorder, SkCanvasStack, and DebugCanvas.

Definition at line 2280 of file SkCanvas.h.

2280{}

◆ didTranslate()

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

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, and DebugCanvas.

Definition at line 2281 of file SkCanvas.h.

2281{}

◆ 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 SkDevice that created SkCanvas.

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

Definition at line 1224 of file SkCanvas.h.

1224{ this->onDiscard(); }
virtual void onDiscard()

◆ drawAnnotation() [1/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

Definition at line 2187 of file SkCanvas.h.

2187 {
2188 this->drawAnnotation(rect, key, value.get());
2189 }
void drawAnnotation(const SkRect &rect, const char key[], SkData *value)
uint8_t value

◆ drawAnnotation() [2/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

Definition at line 2148 of file SkCanvas.cpp.

2148 {
2149 TRACE_EVENT0("skia", TRACE_FUNC);
2150 if (key) {
2151 this->onDrawAnnotation(rect, key, value);
2152 }
2153}
#define TRACE_FUNC
virtual void onDrawAnnotation(const SkRect &rect, const char key[], SkData *value)
#define TRACE_EVENT0(category_group, name)

◆ drawArc() [1/2]

void SkCanvas::drawArc ( const SkArc arc,
const SkPaint paint 
)
inline

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
arcSkArc specifying oval, startAngle, sweepAngle, and useCenter
paintSkPaint stroke or fill, blend, color, and so on, used to draw

Definition at line 1489 of file SkCanvas.h.

1489 {
1490 this->drawArc(arc.fOval, arc.fStartAngle, arc.fSweepAngle, arc.fUseCenter, paint);
1491 }
void drawArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
const Paint & paint
bool fUseCenter
Definition SkArc.h:26
SkScalar fSweepAngle
Definition SkArc.h:22
SkScalar fStartAngle
Definition SkArc.h:20
SkRect fOval
Definition SkArc.h:17

◆ drawArc() [2/2]

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

Definition at line 3155 of file SkCanvas.cpp.

3157 {
3158 TRACE_EVENT0("skia", TRACE_FUNC);
3159 if (oval.isEmpty() || !sweepAngle) {
3160 return;
3161 }
3162 this->onDrawArc(oval, startAngle, sweepAngle, useCenter, paint);
3163}
virtual void onDrawArc(const SkRect &rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
SkRect oval
Definition SkRecords.h:249
bool isEmpty() const
Definition SkRect.h:693

◆ drawAtlas()

void SkCanvas::drawAtlas ( const SkImage atlas,
const SkRSXform  xform[],
const SkRect  tex[],
const SkColor  colors[],
int  count,
SkBlendMode  mode,
const SkSamplingOptions sampling,
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.

SkMaskFilter and SkPathEffect on paint are ignored.

xform, tex, 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
samplingSkSamplingOptions used when sampling from the atlas image
cullRectbounds of transformed sprites for efficient clipping; may be nullptr
paintSkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr

Definition at line 2134 of file SkCanvas.cpp.

2137 {
2138 TRACE_EVENT0("skia", TRACE_FUNC);
2139 RETURN_ON_NULL(atlas);
2140 if (count <= 0) {
2141 return;
2142 }
2143 SkASSERT(atlas);
2144 SkASSERT(tex);
2145 this->onDrawAtlas2(atlas, xform, tex, colors, count, mode, sampling, cull, paint);
2146}
int count
#define RETURN_ON_NULL(ptr)
Definition SkCanvas.cpp:78
virtual void onDrawAtlas2(const SkImage *, const SkRSXform[], const SkRect src[], const SkColor[], int count, SkBlendMode, const SkSamplingOptions &, const SkRect *cull, const SkPaint *)

◆ drawCircle() [1/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

Definition at line 1445 of file SkCanvas.h.

1445 {
1446 this->drawCircle(center.x(), center.y(), radius, paint);
1447 }
static SkScalar center(float pos0, float pos1)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
constexpr float x() const

◆ drawCircle() [2/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

Definition at line 3134 of file SkCanvas.cpp.

3134 {
3135 if (radius < 0) {
3136 radius = 0;
3137 }
3138
3139 SkRect r;
3140 r.setLTRB(cx - radius, cy - radius, cx + radius, cy + radius);
3141 this->drawOval(r, paint);
3142}
void drawOval(const SkRect &oval, const SkPaint &paint)
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865

◆ drawColor() [1/2]

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

Fills clip with color color. mode determines how ARGB is combined with destination.

Parameters
colorSkColor4f representing unpremultiplied color.
modeSkBlendMode used to combine source color and destination

Definition at line 3115 of file SkCanvas.cpp.

3115 {
3116 SkPaint paint;
3117 paint.setColor(c);
3118 paint.setBlendMode(mode);
3119 this->drawPaint(paint);
3120}
void drawPaint(const SkPaint &paint)

◆ drawColor() [2/2]

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

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

Definition at line 1182 of file SkCanvas.h.

1182 {
1183 this->drawColor(SkColor4f::FromColor(color), mode);
1184 }

◆ 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

Definition at line 3001 of file SkCanvas.cpp.

3001 {
3002#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
3003 TRACE_EVENT0("skia", TRACE_FUNC);
3004#endif
3006 if (matrix && matrix->isIdentity()) {
3007 matrix = nullptr;
3008 }
3009 this->onDrawDrawable(dr, matrix);
3010}
virtual void onDrawDrawable(SkDrawable *drawable, const SkMatrix *matrix)

◆ 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

Definition at line 2988 of file SkCanvas.cpp.

2988 {
2989#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
2990 TRACE_EVENT0("skia", TRACE_FUNC);
2991#endif
2993 if (x || y) {
2995 this->onDrawDrawable(dr, &matrix);
2996 } else {
2997 this->onDrawDrawable(dr, nullptr);
2998 }
2999}
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
double y
double x

◆ 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

Definition at line 1969 of file SkCanvas.cpp.

1970 {
1971 TRACE_EVENT0("skia", TRACE_FUNC);
1972 if (outer.isEmpty()) {
1973 return;
1974 }
1975 if (inner.isEmpty()) {
1976 this->drawRRect(outer, paint);
1977 return;
1978 }
1979
1980 // We don't have this method (yet), but technically this is what we should
1981 // be able to return ...
1982 // if (!outer.contains(inner))) {
1983 //
1984 // For now at least check for containment of bounds
1985 if (!outer.getBounds().contains(inner.getBounds())) {
1986 return;
1987 }
1988
1989 this->onDrawDRRect(outer, inner, paint);
1990}
virtual void onDrawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &paint)
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
bool isEmpty() const
Definition SkRRect.h:83
bool contains(SkScalar x, SkScalar y) const
Definition extension.cpp:19

◆ drawGlyphs() [1/3]

void SkCanvas::drawGlyphs ( int  count,
const SkGlyphID  glyphs[],
const SkPoint  positions[],
const uint32_t  clusters[],
int  textByteCount,
const char  utf8text[],
SkPoint  origin,
const SkFont font,
const SkPaint paint 
)

Draws count glyphs, at positions relative to origin styled with font and paint with supporting utf8 and cluster information.

This function draw glyphs at the given positions relative to the given origin. It does not perform typeface fallback for glyphs not found in the SkTypeface in font.

The drawing obeys the current transform matrix and clipping.

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

Parameters
countnumber of glyphs to draw
glyphsthe array of glyphIDs to draw
positionswhere to draw each glyph relative to origin
clustersarray of size count of cluster information
textByteCountsize of the utf8text
utf8textutf8text supporting information for the glyphs
originthe origin of all the positions
fonttypeface, text size and so, used to describe the text
paintblend, color, and so on, used to draw

◆ drawGlyphs() [2/3]

void SkCanvas::drawGlyphs ( int  count,
const SkGlyphID  glyphs[],
const SkPoint  positions[],
SkPoint  origin,
const SkFont font,
const SkPaint paint 
)

Draws count glyphs, at positions relative to origin styled with font and paint.

This function draw glyphs at the given positions relative to the given origin. It does not perform typeface fallback for glyphs not found in the SkTypeface in font.

The drawing obeys the current transform matrix and clipping.

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

Parameters
countnumber of glyphs to draw
glyphsthe array of glyphIDs to draw
positionswhere to draw each glyph relative to origin
originthe origin of all the positions
fonttypeface, text size and so, used to describe the text
paintblend, color, and so on, used to draw

Definition at line 2873 of file SkCanvas.cpp.

2874 {
2875 if (count <= 0) { return; }
2876
2877 sktext::GlyphRun glyphRun {
2878 font,
2879 SkSpan(positions, count),
2884 };
2885
2886 sktext::GlyphRunList glyphRunList = fScratchGlyphRunBuilder->makeGlyphRunList(
2887 glyphRun, paint, origin);
2888 this->onDrawGlyphRunList(glyphRunList, paint);
2889}
uint16_t glyphs[5]
virtual void onDrawGlyphRunList(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
font
Font Metadata and Metrics.

◆ drawGlyphs() [3/3]

void SkCanvas::drawGlyphs ( int  count,
const SkGlyphID  glyphs[],
const SkRSXform  xforms[],
SkPoint  origin,
const SkFont font,
const SkPaint paint 
)

Draws count glyphs, at positions relative to origin styled with font and paint.

This function draw glyphs using the given scaling and rotations. They are positioned relative to the given origin. It does not perform typeface fallback for glyphs not found in the SkTypeface in font.

The drawing obeys the current transform matrix and clipping.

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

Parameters
countnumber of glyphs to draw
glyphsthe array of glyphIDs to draw
xformswhere to draw and orient each glyph
originthe origin of all the positions
fonttypeface, text size and so, used to describe the text
paintblend, color, and so on, used to draw

Definition at line 2891 of file SkCanvas.cpp.

2892 {
2893 if (count <= 0) { return; }
2894
2895 auto [positions, rotateScales] =
2896 fScratchGlyphRunBuilder->convertRSXForm(SkSpan(xforms, count));
2897
2898 sktext::GlyphRun glyphRun {
2899 font,
2900 positions,
2904 rotateScales
2905 };
2906 sktext::GlyphRunList glyphRunList = fScratchGlyphRunBuilder->makeGlyphRunList(
2907 glyphRun, paint, origin);
2908 this->onDrawGlyphRunList(glyphRunList, paint);
2909}

◆ drawImage() [1/4]

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

Definition at line 1531 of file SkCanvas.h.

1531 {
1532 this->drawImage(image.get(), left, top, SkSamplingOptions(), nullptr);
1533 }
static bool left(const SkPoint &p0, const SkPoint &p1)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
T * get() const
Definition SkRefCnt.h:303

◆ drawImage() [2/4]

void SkCanvas::drawImage ( const sk_sp< SkImage > &  image,
SkScalar  x,
SkScalar  y,
const SkSamplingOptions sampling,
const SkPaint paint = nullptr 
)
inline

Definition at line 1548 of file SkCanvas.h.

1549 {
1550 this->drawImage(image.get(), x, y, sampling, paint);
1551 }

◆ drawImage() [3/4]

void SkCanvas::drawImage ( const SkImage image,
SkScalar  x,
SkScalar  y,
const SkSamplingOptions sampling,
const SkPaint paint = nullptr 
)

Definition at line 2744 of file SkCanvas.cpp.

2745 {
2746 TRACE_EVENT0("skia", TRACE_FUNC);
2748#if defined(SK_RESOLVE_FILTERS_BEFORE_RESTORE)
2749 this->onDrawImage2(image, x, y, sampling, paint);
2750#else
2751 this->drawImageRect(image,
2752 /*src=*/SkRect::MakeWH(image->width(), image->height()),
2753 /*dst=*/SkRect::MakeXYWH(x, y, image->width(), image->height()),
2754 sampling,
2755 paint,
2757#endif
2758}
virtual void onDrawImage2(const SkImage *, SkScalar dx, SkScalar dy, const SkSamplingOptions &, const SkPaint *)
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
sk_sp< SkImage > image
Definition examples.cpp:29
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ drawImage() [4/4]

void SkCanvas::drawImage ( const SkImage image,
SkScalar  left,
SkScalar  top 
)
inline

Definition at line 1528 of file SkCanvas.h.

1528 {
1529 this->drawImage(image, left, top, SkSamplingOptions(), nullptr);
1530 }

◆ drawImageLattice() [1/2]

void SkCanvas::drawImageLattice ( const SkImage image,
const Lattice lattice,
const SkRect dst 
)
inline

Definition at line 1651 of file SkCanvas.h.

1651 {
1652 this->drawImageLattice(image, lattice, dst, SkFilterMode::kNearest, nullptr);
1653 }
void drawImageLattice(const SkImage *image, const Lattice &lattice, const SkRect &dst, SkFilterMode filter, const SkPaint *paint=nullptr)

◆ drawImageLattice() [2/2]

void SkCanvas::drawImageLattice ( const SkImage image,
const Lattice lattice,
const SkRect dst,
SkFilterMode  filter,
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; 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, and SkBlendMode. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds. 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
filterwhat technique to use when sampling the image
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

Definition at line 2110 of file SkCanvas.cpp.

2111 {
2112 TRACE_EVENT0("skia", TRACE_FUNC);
2114 if (dst.isEmpty()) {
2115 return;
2116 }
2117
2119 Lattice latticePlusBounds = lattice;
2120 if (!latticePlusBounds.fBounds) {
2122 latticePlusBounds.fBounds = &bounds;
2123 }
2124
2125 SkPaint latticePaint = clean_paint_for_lattice(paint);
2126 if (SkLatticeIter::Valid(image->width(), image->height(), latticePlusBounds)) {
2127 this->onDrawImageLattice2(image, latticePlusBounds, dst, filter, &latticePaint);
2128 } else {
2129 this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst,
2130 SkSamplingOptions(filter), &latticePaint, kStrict_SrcRectConstraint);
2131 }
2132}
static SkPaint clean_paint_for_lattice(const SkPaint *paint)
virtual void onDrawImageLattice2(const SkImage *, const Lattice &, const SkRect &dst, SkFilterMode, const SkPaint *)
static bool Valid(int imageWidth, int imageHeight, const SkCanvas::Lattice &lattice)
dst
Definition cp.py:12
static SkRect MakeIWH(int w, int h)
Definition SkRect.h:623

◆ drawImageNine()

void SkCanvas::drawImageNine ( const SkImage image,
const SkIRect center,
const SkRect dst,
SkFilterMode  filter,
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, and SkBlendMode. If image is kAlpha_8_SkColorType, apply SkShader. If paint contains SkMaskFilter, generate mask from image bounds. 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
filterwhat technique to use when sampling the image
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

Definition at line 2093 of file SkCanvas.cpp.

2094 {
2096
2097 const int xdivs[] = {center.fLeft, center.fRight};
2098 const int ydivs[] = {center.fTop, center.fBottom};
2099
2100 Lattice lat;
2101 lat.fXDivs = xdivs;
2102 lat.fYDivs = ydivs;
2103 lat.fRectTypes = nullptr;
2104 lat.fXCount = lat.fYCount = 2;
2105 lat.fBounds = nullptr;
2106 lat.fColors = nullptr;
2107 this->drawImageLattice(image, lat, dst, filter, paint);
2108}

◆ drawImageRect() [1/4]

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

Definition at line 1561 of file SkCanvas.h.

1562 {
1563 this->drawImageRect(image.get(), dst, sampling, paint);
1564 }

◆ drawImageRect() [2/4]

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

Definition at line 1556 of file SkCanvas.h.

1558 {
1559 this->drawImageRect(image.get(), src, dst, sampling, paint, constraint);
1560 }

◆ drawImageRect() [3/4]

void SkCanvas::drawImageRect ( const SkImage image,
const SkRect dst,
const SkSamplingOptions sampling,
const SkPaint paint = nullptr 
)

Definition at line 2770 of file SkCanvas.cpp.

2771 {
2773 this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, sampling,
2775}

◆ drawImageRect() [4/4]

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

Definition at line 2760 of file SkCanvas.cpp.

2762 {
2764 if (!fillable(dst) || !fillable(src)) {
2765 return;
2766 }
2767 this->onDrawImageRect2(image, src, dst, sampling, paint, constraint);
2768}
static bool fillable(const SkRect &r)
virtual void onDrawImageRect2(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)

◆ 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

Definition at line 1358 of file SkCanvas.h.

1358 {
1359 SkRect r;
1360 r.set(rect); // promotes the ints to scalars
1361 this->drawRect(r, paint);
1362 }
void drawRect(const SkRect &rect, const SkPaint &paint)
void set(const SkIRect &src)
Definition SkRect.h:849

◆ drawLine() [1/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

Definition at line 1334 of file SkCanvas.h.

1334 {
1335 this->drawLine(p0.x(), p0.y(), p1.x(), p1.y(), paint);
1336 }
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
constexpr float y() const

◆ drawLine() [2/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

Definition at line 3127 of file SkCanvas.cpp.

3127 {
3128 SkPoint pts[2];
3129 pts[0].set(x0, y0);
3130 pts[1].set(x1, y1);
3131 this->drawPoints(kLines_PointMode, 2, pts, paint);
3132}
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
void set(float x, float y)

◆ drawMesh()

void SkCanvas::drawMesh ( const SkMesh mesh,
sk_sp< SkBlender blender,
const SkPaint paint 
)

Experimental, under active development, and subject to change without notice.

Draws a mesh using a user-defined specification (see SkMeshSpecification). Requires a GPU backend or SkSL to be compiled in.

SkBlender is ignored if SkMesh's specification does not output fragment shader color. Otherwise, it combines

SkMaskFilter, SkPathEffect, and antialiasing on SkPaint are ignored.

Parameters
meshthe mesh vertices and compatible specification.
blendercombines vertices colors with SkShader if present or SkPaint opaque color if not. Ignored if the custom mesh does not output color. Defaults to SkBlendMode::kModulate if nullptr.
paintspecifies the SkShader, used as SkVertices texture, may be nullptr

Definition at line 2063 of file SkCanvas.cpp.

2063 {
2064 TRACE_EVENT0("skia", TRACE_FUNC);
2065 if (!blender) {
2067 }
2068 this->onDrawMesh(mesh, std::move(blender), paint);
2069}
@ kModulate
r = s*d
static sk_sp< SkBlender > Mode(SkBlendMode mode)
virtual void onDrawMesh(const SkMesh &, sk_sp< SkBlender >, const SkPaint &)

◆ 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

Definition at line 2022 of file SkCanvas.cpp.

2022 {
2023 TRACE_EVENT0("skia", TRACE_FUNC);
2024 // To avoid redundant logic in our culling code and various backends, we always sort rects
2025 // before passing them along.
2026 this->onDrawOval(r.makeSorted(), paint);
2027}
virtual void onDrawOval(const SkRect &rect, const SkPaint &paint)

◆ drawPaint()

void SkCanvas::drawPaint ( const SkPaint paint)

Fills clip with SkPaint paint. SkPaint components, SkShader, SkColorFilter, SkImageFilter, and SkBlendMode affect drawing; SkMaskFilter and SkPathEffect in paint are ignored.

Parameters
paintgraphics state used to fill SkCanvas

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

Definition at line 1992 of file SkCanvas.cpp.

1992 {
1993 TRACE_EVENT0("skia", TRACE_FUNC);
1994 this->onDrawPaint(paint);
1995}
virtual void onDrawPaint(const SkPaint &paint)

◆ drawPatch()

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.

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. If texCoords is nullptr, SkShader is mapped using positions (derived from cubics).

SkBlendMode is ignored if colors is null. Otherwise, it combines

SkMaskFilter, SkPathEffect, and antialiasing on SkPaint are ignored.

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
modecombines patch's colors with SkShader if present or SkPaint opaque color if not. Ignored if colors is null.
paintSkShader, SkColorFilter, SkBlendMode, used to draw

Definition at line 2956 of file SkCanvas.cpp.

2958 {
2959 TRACE_EVENT0("skia", TRACE_FUNC);
2960 if (nullptr == cubics) {
2961 return;
2962 }
2963
2964 this->onDrawPatch(cubics, colors, texCoords, bmode, paint);
2965}
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode mode, const SkPaint &paint)

◆ 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

Definition at line 2071 of file SkCanvas.cpp.

2071 {
2072 TRACE_EVENT0("skia", TRACE_FUNC);
2073 this->onDrawPath(path, paint);
2074}
virtual void onDrawPath(const SkPath &path, const SkPaint &paint)

◆ drawPicture() [1/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

Definition at line 1973 of file SkCanvas.h.

1973 {
1974 this->drawPicture(picture.get());
1975 }
void drawPicture(const SkPicture *picture)
Definition SkCanvas.h:1961

◆ drawPicture() [2/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.

If paint is non-null, then the picture is always drawn into a temporary layer before actually landing on the canvas. Note that drawing into a layer can also change its appearance if there are any non-associative blendModes inside any of the pictures elements.

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

Definition at line 2005 of file SkCanvas.h.

2006 {
2007 this->drawPicture(picture.get(), matrix, paint);
2008 }

◆ drawPicture() [3/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

Definition at line 1961 of file SkCanvas.h.

1961 {
1962 this->drawPicture(picture, nullptr, nullptr);
1963 }

◆ drawPicture() [4/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.

If paint is non-null, then the picture is always drawn into a temporary layer before actually landing on the canvas. Note that drawing into a layer can also change its appearance if there are any non-associative blendModes inside any of the pictures elements.

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

Definition at line 3174 of file SkCanvas.cpp.

3174 {
3175 TRACE_EVENT0("skia", TRACE_FUNC);
3176 RETURN_ON_NULL(picture);
3177
3178 if (matrix && matrix->isIdentity()) {
3179 matrix = nullptr;
3180 }
3182 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
3183 picture->playback(this);
3184 } else {
3185 this->onDrawPicture(picture, matrix, paint);
3186 }
3187}
constexpr int kMaxPictureOpsToUnrollInsteadOfRef
virtual void onDrawPicture(const SkPicture *picture, const SkMatrix *matrix, const SkPaint *paint)
virtual SkRect cullRect() const =0
virtual void playback(SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
virtual int approximateOpCount(bool nested=false) const =0
sk_sp< const SkPicture > picture
Definition SkRecords.h:299

◆ drawPoint() [1/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

Definition at line 1306 of file SkCanvas.h.

1306 {
1307 this->drawPoint(p.x(), p.y(), paint);
1308 }
void drawPoint(SkScalar x, SkScalar y, const SkPaint &paint)

◆ drawPoint() [2/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

Definition at line 3122 of file SkCanvas.cpp.

3122 {
3123 const SkPoint pt = { x, y };
3124 this->drawPoints(kPoints_PointMode, 1, &pt, paint);
3125}

◆ 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

Definition at line 2034 of file SkCanvas.cpp.

2034 {
2035 TRACE_EVENT0("skia", TRACE_FUNC);
2036 this->onDrawPoints(mode, count, pts, paint);
2037}
virtual void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)

◆ 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

Definition at line 1997 of file SkCanvas.cpp.

1997 {
1998 TRACE_EVENT0("skia", TRACE_FUNC);
1999 // To avoid redundant logic in our culling code and various backends, we always sort rects
2000 // before passing them along.
2001 this->onDrawRect(r.makeSorted(), paint);
2002}
virtual void onDrawRect(const SkRect &rect, const SkPaint &paint)

◆ 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

Definition at line 2009 of file SkCanvas.cpp.

2009 {
2010 TRACE_EVENT0("skia", TRACE_FUNC);
2011 if (region.isEmpty()) {
2012 return;
2013 }
2014
2015 if (region.isRect()) {
2016 return this->drawIRect(region.getBounds(), paint);
2017 }
2018
2019 this->onDrawRegion(region, paint);
2020}
virtual void onDrawRegion(const SkRegion &region, const SkPaint &paint)
void drawIRect(const SkIRect &rect, const SkPaint &paint)
Definition SkCanvas.h:1358
bool isRect() const
Definition SkRegion.h:152
const SkIRect & getBounds() const
Definition SkRegion.h:165
bool isEmpty() const
Definition SkRegion.h:146
ClipOpAndAA opAA SkRegion region
Definition SkRecords.h:238

◆ 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

Definition at line 3144 of file SkCanvas.cpp.

3145 {
3146 if (rx > 0 && ry > 0) {
3147 SkRRect rrect;
3148 rrect.setRectXY(r, rx, ry);
3149 this->drawRRect(rrect, paint);
3150 } else {
3151 this->drawRect(r, paint);
3152 }
3153}
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.cpp:52

◆ 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

Definition at line 2029 of file SkCanvas.cpp.

2029 {
2030 TRACE_EVENT0("skia", TRACE_FUNC);
2031 this->onDrawRRect(rrect, paint);
2032}
virtual void onDrawRRect(const SkRRect &rrect, const SkPaint &paint)

◆ 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, and SkImageFilter; 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

Definition at line 2840 of file SkCanvas.cpp.

2841 {
2842 TRACE_EVENT0("skia", TRACE_FUNC);
2843 if (byteLength) {
2844 sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength));
2845 const sktext::GlyphRunList& glyphRunList =
2846 fScratchGlyphRunBuilder->textToGlyphRunList(
2847 font, paint, text, byteLength, {x, y}, encoding);
2848 if (!glyphRunList.empty()) {
2849 this->onDrawGlyphRunList(glyphRunList, paint);
2850 }
2851 }
2852}
static void sk_msan_assert_initialized(const void *begin, const void *end)
Definition SkMSAN.h:24
auto empty() const -> decltype(fGlyphRuns.empty())
Definition GlyphRun.h:125
std::u16string text

◆ 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, and SkImageFilter; 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

Definition at line 1803 of file SkCanvas.h.

1804 {
1805 this->drawSimpleText(str, strlen(str), SkTextEncoding::kUTF8, x, y, font, paint);
1806 }
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)

◆ 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, and SkImageFilter; 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

Definition at line 1832 of file SkCanvas.h.

1833 {
1834 this->drawSimpleText(str.c_str(), str.size(), SkTextEncoding::kUTF8, x, y, font, paint);
1835 }
size_t size() const
Definition SkString.h:131
const char * c_str() const
Definition SkString.h:133

◆ drawTextBlob() [1/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, and SkImageFilter; 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

Definition at line 1949 of file SkCanvas.h.

1949 {
1950 this->drawTextBlob(blob.get(), x, y, paint);
1951 }
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)

◆ drawTextBlob() [2/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, 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

Definition at line 2911 of file SkCanvas.cpp.

2912 {
2913 TRACE_EVENT0("skia", TRACE_FUNC);
2914 RETURN_ON_NULL(blob);
2916
2917 // Overflow if more than 2^21 glyphs stopping a buffer overflow latter in the stack.
2918 // See chromium:1080481
2919 // TODO: can consider unrolling a few at a time if this limit becomes a problem.
2920 int totalGlyphCount = 0;
2921 constexpr int kMaxGlyphCount = 1 << 21;
2922 SkTextBlob::Iter i(*blob);
2924 while (i.next(&r)) {
2925 int glyphsLeft = kMaxGlyphCount - totalGlyphCount;
2926 RETURN_ON_FALSE(r.fGlyphCount <= glyphsLeft);
2927 totalGlyphCount += r.fGlyphCount;
2928 }
2929
2930 this->onDrawTextBlob(blob, x, y, paint);
2931}
constexpr int kMaxGlyphCount
#define RETURN_ON_FALSE(pred)
Definition SkCanvas.cpp:79
virtual void onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
const SkRect & bounds() const
Definition SkTextBlob.h:53
constexpr SkRect makeOffset(float dx, float dy) const
Definition SkRect.h:965
bool isFinite() const
Definition SkRect.h:711

◆ drawVertices() [1/2]

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

Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. If paint contains an SkShader and vertices does not contain texCoords, the shader is mapped using the vertices' positions.

SkBlendMode is ignored if SkVertices does not have colors. Otherwise, it combines

SkMaskFilter, SkPathEffect, and antialiasing on SkPaint are ignored.

Parameters
verticestriangle mesh to draw
modecombines vertices' colors with SkShader if present or SkPaint opaque color if not. Ignored if the vertices do not contain color.
paintspecifies the SkShader, used as SkVertices texture, may be nullptr

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

Definition at line 2039 of file SkCanvas.cpp.

2040 {
2041 this->drawVertices(vertices.get(), mode, paint);
2042}
void drawVertices(const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)

◆ drawVertices() [2/2]

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

Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. If paint contains an SkShader and vertices does not contain texCoords, the shader is mapped using the vertices' positions.

SkBlendMode is ignored if SkVertices does not have colors. Otherwise, it combines

SkMaskFilter, SkPathEffect, and antialiasing on SkPaint are ignored.

Parameters
verticestriangle mesh to draw
modecombines vertices' colors with SkShader if present or SkPaint opaque color if not. Ignored if the vertices do not contain color.
paintspecifies the SkShader, used as SkVertices texture, and SkColorFilter.

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

Definition at line 2044 of file SkCanvas.cpp.

2044 {
2045 TRACE_EVENT0("skia", TRACE_FUNC);
2046 RETURN_ON_NULL(vertices);
2047
2048 // We expect fans to be converted to triangles when building or deserializing SkVertices.
2050
2051#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
2052 // Preserve legacy behavior for Android: ignore the SkShader if there are no texCoords present
2053 if (paint.getShader() && !vertices->priv().hasTexCoords()) {
2054 SkPaint noShaderPaint(paint);
2055 noShaderPaint.setShader(nullptr);
2056 this->onDrawVerticesObject(vertices, mode, noShaderPaint);
2057 return;
2058 }
2059#endif
2060 this->onDrawVerticesObject(vertices, mode, paint);
2061}
virtual void onDrawVerticesObject(const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
SkVertices::VertexMode mode() const
bool hasTexCoords() const
@ kTriangleFan_VertexMode
Definition SkVertices.h:33
SkVerticesPriv priv()

◆ experimental_DrawEdgeAAImageSet()

void SkCanvas::experimental_DrawEdgeAAImageSet ( const ImageSetEntry  imageSet[],
int  cnt,
const SkPoint  dstClips[],
const SkMatrix  preViewMatrices[],
const SkSamplingOptions sampling,
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.

Definition at line 2177 of file SkCanvas.cpp.

2182 {
2183 TRACE_EVENT0("skia", TRACE_FUNC);
2184#if !defined(SK_RESOLVE_FILTERS_BEFORE_RESTORE)
2185 // Route single, rectangular quads to drawImageRect() to take advantage of image filter
2186 // optimizations that avoid a layer.
2187 if (paint && paint->getImageFilter() && cnt == 1) {
2188 const auto& entry = imageSet[0];
2189 // If the preViewMatrix is skipped or a positive-scale + translate matrix, we can apply it
2190 // to the entry's dstRect w/o changing output behavior.
2191 const bool canMapDstRect = entry.fMatrixIndex < 0 ||
2192 (preViewMatrices[entry.fMatrixIndex].isScaleTranslate() &&
2193 preViewMatrices[entry.fMatrixIndex].getScaleX() > 0.f &&
2194 preViewMatrices[entry.fMatrixIndex].getScaleY() > 0.f);
2195 if (!entry.fHasClip && canMapDstRect) {
2196 SkRect dst = entry.fDstRect;
2197 if (entry.fMatrixIndex >= 0) {
2198 preViewMatrices[entry.fMatrixIndex].mapRect(&dst);
2199 }
2200 this->drawImageRect(entry.fImage.get(), entry.fSrcRect, dst,
2201 sampling, paint, constraint);
2202 return;
2203 } // Else the entry is doing more than can be represented by drawImageRect
2204 } // Else no filter, or many entries that should be filtered together
2205#endif
2206 this->onDrawEdgeAAImageSet2(imageSet, cnt, dstClips, preViewMatrices, sampling, paint,
2207 constraint);
2208}
virtual void onDrawEdgeAAImageSet2(const ImageSetEntry imageSet[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
PODArray< SkMatrix > preViewMatrices
Definition SkRecords.h:365

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

Definition at line 2169 of file SkCanvas.cpp.

2171 {
2172 TRACE_EVENT0("skia", TRACE_FUNC);
2173 // Make sure the rect is sorted before passing it along
2174 this->onDrawEdgeAAQuad(rect.makeSorted(), clip, aaFlags, color, mode);
2175}
virtual void onDrawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)

◆ experimental_DrawEdgeAAQuad() [2/2]

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

Definition at line 1711 of file SkCanvas.h.

1712 {
1713 this->experimental_DrawEdgeAAQuad(rect, clip, aaFlags, SkColor4f::FromColor(color), mode);
1714 }
void experimental_DrawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)

◆ getBaseLayerSize()

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

Reimplemented in SkPaintFilterCanvas.

Definition at line 373 of file SkCanvas.cpp.

373 {
374 return this->rootDevice()->imageInfo().dimensions();
375}
const SkImageInfo & imageInfo() const
Definition SkDevice.h:117
SkISize dimensions() const

◆ getBaseProps()

SkSurfaceProps SkCanvas::getBaseProps ( ) const

Returns the SkSurfaceProps associated with the canvas (i.e., at the base of the layer stack).

Returns
base SkSurfaceProps

Definition at line 1542 of file SkCanvas.cpp.

1542 {
1543 SkSurfaceProps props;
1544 this->onGetProps(&props, /*top=*/false);
1545 return props;
1546}
virtual bool onGetProps(SkSurfaceProps *props, bool top) const

◆ 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 base device coordinates

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

Definition at line 1931 of file SkCanvas.cpp.

1931 {
1932 return this->computeDeviceClipBounds(/*outsetForAA=*/false).roundOut();
1933}
void roundOut(SkIRect *dst) const
Definition SkRect.h:1241

◆ 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

Definition at line 1169 of file SkCanvas.h.

1169 {
1170 *bounds = this->getDeviceClipBounds();
1171 return !bounds->isEmpty();
1172 }
SkIRect getDeviceClipBounds() const

◆ 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

Definition at line 1910 of file SkCanvas.cpp.

1910 {
1911 SkIRect ibounds = this->getDeviceClipBounds();
1912 if (ibounds.isEmpty()) {
1913 return SkRect::MakeEmpty();
1914 }
1915
1916 SkMatrix inverse;
1917 // if we can't invert the CTM, we can't return local clip bounds
1918 if (!fMCRec->fMatrix.asM33().invert(&inverse)) {
1919 return SkRect::MakeEmpty();
1920 }
1921
1922 SkRect bounds;
1923 // adjust it outwards in case we are antialiasing
1924 const int margin = 1;
1925
1926 SkRect r = SkRect::Make(ibounds.makeOutset(margin, margin));
1927 inverse.mapRect(&bounds, r);
1928 return bounds;
1929}
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
SkIRect makeOutset(int32_t dx, int32_t dy) const
Definition SkRect.h:350
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595

◆ 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

Definition at line 1145 of file SkCanvas.h.

1145 {
1146 *bounds = this->getLocalClipBounds();
1147 return !bounds->isEmpty();
1148 }
SkRect getLocalClipBounds() const

◆ getLocalToDevice()

SkM44 SkCanvas::getLocalToDevice ( ) const

Returns the current transform from local coordinates to the 'device', which for most purposes means pixels.

Returns
transformation from local coordinates to device / pixels.

Definition at line 1957 of file SkCanvas.cpp.

1957 {
1958 return fMCRec->fMatrix;
1959}

◆ getLocalToDeviceAs3x3()

SkMatrix SkCanvas::getLocalToDeviceAs3x3 ( ) const
inline

Throws away the 3rd row and column in the matrix, so be warned.

Definition at line 2222 of file SkCanvas.h.

2222 {
2223 return this->getLocalToDevice().asM33();
2224 }
SkM44 getLocalToDevice() const
SkMatrix asM33() const
Definition SkM44.h:409

◆ 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

DEPRECATED: Replace usage with getBaseProps() or getTopProps()

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

Definition at line 1538 of file SkCanvas.cpp.

1538 {
1539 return this->onGetProps(props, /*top=*/false);
1540}

◆ 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

Definition at line 435 of file SkCanvas.cpp.

435 {
436#ifdef SK_DEBUG
437 int count = 0;
439 for (;;) {
440 const MCRec* rec = (const MCRec*)iter.next();
441 if (!rec) {
442 break;
443 }
444 count += 1 + rec->fDeferredSaveCount;
445 }
446 SkASSERT(count == fSaveCount);
447#endif
448 return fSaveCount;
449}

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

Definition at line 369 of file SkCanvas.cpp.

369 {
370 return fSurfaceBase;
371}

◆ getTopProps()

SkSurfaceProps SkCanvas::getTopProps ( ) const

Returns the SkSurfaceProps associated with the canvas that are currently active (i.e., at the top of the layer stack). This can differ from getBaseProps depending on the flags passed to saveLayer (see SaveLayerFlagsSet).

Returns
SkSurfaceProps active in the current/top layer

Definition at line 1548 of file SkCanvas.cpp.

1548 {
1549 SkSurfaceProps props;
1550 this->onGetProps(&props, /*top=*/true);
1551 return props;
1552}

◆ getTotalMatrix()

SkMatrix SkCanvas::getTotalMatrix ( ) const

DEPRECATED Legacy version of getLocalToDevice(), which strips away any Z information, and just returns a 3x3 version.

Returns
3x3 version of getLocalToDevice()

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

Definition at line 1953 of file SkCanvas.cpp.

1953 {
1954 return fMCRec->fMatrix.asM33();
1955}

◆ 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

Definition at line 1530 of file SkCanvas.cpp.

1530 {
1531 return this->onImageInfo();
1532}
virtual SkImageInfo onImageInfo() const

◆ internal_private_asPaintFilterCanvas()

virtual SkPaintFilterCanvas * SkCanvas::internal_private_asPaintFilterCanvas ( ) const
inlineprivatevirtual

Reimplemented in SkPaintFilterCanvas.

Definition at line 2616 of file SkCanvas.h.

2616{ return nullptr; }

◆ isClipEmpty()

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

Definition at line 1873 of file SkCanvas.cpp.

1873 {
1874 return this->topDevice()->isClipEmpty();
1875}
virtual bool isClipEmpty() const =0

◆ isClipRect()

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

Definition at line 1877 of file SkCanvas.cpp.

1877 {
1878 return this->topDevice()->isClipRect();
1879}
virtual bool isClipRect() const =0

◆ MakeRasterDirect()

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

Definition at line 3228 of file SkCanvas.cpp.

3229 {
3230 if (!SkSurfaceValidateRasterInfo(info, rowBytes)) {
3231 return nullptr;
3232 }
3233
3235 if (!bitmap.installPixels(info, pixels, rowBytes)) {
3236 return nullptr;
3237 }
3238
3239 return props ?
3240 std::make_unique<SkCanvas>(bitmap, *props) :
3241 std::make_unique<SkCanvas>(bitmap);
3242}
bool SkSurfaceValidateRasterInfo(const SkImageInfo &, size_t rb=kIgnoreRowBytesValue)
Definition ref_ptr.h:256

◆ 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

Definition at line 163 of file SkCanvas.h.

164 {
165 return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
166 }
static std::unique_ptr< SkCanvas > MakeRasterDirect(const SkImageInfo &info, void *pixels, size_t rowBytes, const SkSurfaceProps *props=nullptr)
static SkImageInfo MakeN32Premul(int width, int height)

◆ 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

Definition at line 1519 of file SkCanvas.cpp.

1519 {
1520 if (nullptr == props) {
1521 props = &fProps;
1522 }
1523 return this->onNewSurface(info, *props);
1524}
virtual sk_sp< SkSurface > onNewSurface(const SkImageInfo &info, const SkSurfaceProps &props)

◆ onAccessTopLayerPixels()

bool SkCanvas::onAccessTopLayerPixels ( SkPixmap pixmap)
protectedvirtual

Reimplemented in SkPaintFilterCanvas.

Definition at line 1596 of file SkCanvas.cpp.

1596 {
1597 return this->topDevice()->accessPixels(pmap);
1598}
bool accessPixels(SkPixmap *pmap)
Definition SkDevice.cpp:388

◆ onClipPath()

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

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkCanvasStack, DebugCanvas, ClipCountingCanvas, and SkRecorder.

Definition at line 1805 of file SkCanvas.cpp.

1805 {
1806 bool isAA = kSoft_ClipEdgeStyle == edgeStyle;
1807
1808 AutoUpdateQRBounds aqr(this);
1809 this->topDevice()->clipPath(path, op, isAA);
1810}
virtual void clipPath(const SkPath &path, SkClipOp op, bool aa)=0

◆ onClipRect()

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

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkCanvasStack, DebugCanvas, ClipCountingCanvas, and SkRecorder.

Definition at line 1694 of file SkCanvas.cpp.

1694 {
1695 SkASSERT(rect.isSorted());
1696 const bool isAA = kSoft_ClipEdgeStyle == edgeStyle;
1697
1698 AutoUpdateQRBounds aqr(this);
1699 this->topDevice()->clipRect(rect, op, isAA);
1700}
virtual void clipRect(const SkRect &rect, SkClipOp op, bool aa)=0

◆ onClipRegion()

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

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkCanvasStack, ClipCountingCanvas, SkRecorder, and DebugCanvas.

Definition at line 1839 of file SkCanvas.cpp.

1839 {
1840 AutoUpdateQRBounds aqr(this);
1841 this->topDevice()->clipRegion(rgn, op);
1842}

◆ onClipRRect()

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

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkCanvasStack, DebugCanvas, ClipCountingCanvas, and SkRecorder.

Definition at line 1773 of file SkCanvas.cpp.

1773 {
1774 bool isAA = kSoft_ClipEdgeStyle == edgeStyle;
1775
1776 AutoUpdateQRBounds aqr(this);
1777 this->topDevice()->clipRRect(rrect, op, isAA);
1778}
virtual void clipRRect(const SkRRect &rrect, SkClipOp op, bool aa)=0

◆ onClipShader()

void SkCanvas::onClipShader ( sk_sp< SkShader sh,
SkClipOp  op 
)
protectedvirtual

Reimplemented in SkNWayCanvas, SkPictureRecord, SkRecorder, SkCanvasStack, and DebugCanvas.

Definition at line 1829 of file SkCanvas.cpp.

1829 {
1830 AutoUpdateQRBounds aqr(this);
1831 this->topDevice()->clipShader(sh, op);
1832}
void clipShader(sk_sp< SkShader > sh, SkClipOp op)
Definition SkDevice.h:251

◆ onConvertGlyphRunListToSlug()

sk_sp< Slug > SkCanvas::onConvertGlyphRunListToSlug ( const sktext::GlyphRunList glyphRunList,
const SkPaint paint 
)
protectedvirtual

Definition at line 2806 of file SkCanvas.cpp.

2807 {
2808 SkRect bounds = glyphRunList.sourceBoundsWithOrigin();
2809 if (bounds.isEmpty() || !bounds.isFinite() || paint.nothingToDraw()) {
2810 return nullptr;
2811 }
2812 // See comment in onDrawGlyphRunList()
2813 auto layer = this->aboutToDraw(paint, &bounds, PredrawFlags::kSkipMaskFilterAutoLayer);
2814 if (layer) {
2815 return this->topDevice()->convertGlyphRunListToSlug(glyphRunList, layer->paint());
2816 }
2817 return nullptr;
2818}
virtual sk_sp< sktext::gpu::Slug > convertGlyphRunListToSlug(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition SkDevice.cpp:488
SkRect sourceBoundsWithOrigin() const
Definition GlyphRun.h:116

◆ onDiscard()

void SkCanvas::onDiscard ( )
protectedvirtual

Definition at line 2214 of file SkCanvas.cpp.

2214 {
2215 if (fSurfaceBase) {
2217 }
2218}
void sk_ignore_unused_variable(const T &)
Definition SkTemplates.h:37
@ kDiscard_ContentChangeMode
discards surface on change
Definition SkSurface.h:204

◆ onDoSaveBehind()

virtual bool SkCanvas::onDoSaveBehind ( const SkRect )
inlineprotectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, DebugCanvas, and SaveCountingCanvas.

Definition at line 2275 of file SkCanvas.h.

2275{ return true; }

◆ onDrawAnnotation()

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

Reimplemented in SkOverdrawCanvas, flutter::DidDrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkPaintFilterCanvas, TestAnnotationCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 3042 of file SkCanvas.cpp.

3042 {
3043 SkASSERT(key);
3044
3045 if (this->predrawNotify()) {
3046 this->topDevice()->drawAnnotation(rect, key, value);
3047 }
3048}
virtual void drawAnnotation(const SkRect &, const char[], SkData *)
Definition SkDevice.h:400

◆ onDrawArc()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2416 of file SkCanvas.cpp.

2418 {
2420 if (this->internalQuickReject(oval, paint)) {
2421 return;
2422 }
2423
2424 auto layer = this->aboutToDraw(paint, &oval);
2425 if (layer) {
2426 this->topDevice()->drawArc(oval, startAngle, sweepAngle, useCenter, layer->paint());
2427 }
2428}
virtual void drawArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
Definition SkDevice.cpp:133
bool isSorted() const
Definition SkRect.h:705

◆ onDrawAtlas2()

void SkCanvas::onDrawAtlas2 ( const SkImage atlas,
const SkRSXform  xform[],
const SkRect  src[],
const SkColor  colors[],
int  count,
SkBlendMode  bmode,
const SkSamplingOptions sampling,
const SkRect cull,
const SkPaint paint 
)
protectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, and MSKPPlayer::CmdRecordCanvas.

Definition at line 3020 of file SkCanvas.cpp.

3023 {
3024 // drawAtlas is a combination of drawVertices and drawImage...
3026 realPaint.setShader(atlas->makeShader(sampling));
3027
3028 if (cull && this->internalQuickReject(*cull, realPaint)) {
3029 return;
3030 }
3031
3032 // drawAtlas should not have mask filters on its paint, so we don't need to worry about
3033 // converting its "drawImage" behavior into the paint to work with the auto-mask-filter system.
3034 SkASSERT(!realPaint.getMaskFilter());
3035 auto layer = this->aboutToDraw(realPaint);
3036 if (layer) {
3037 this->topDevice()->drawAtlas(xform, tex, colors, count, SkBlender::Mode(bmode),
3038 layer->paint());
3039 }
3040}
static SkPaint clean_paint_for_drawImage(const SkPaint *paint)
static SkPaint clean_paint_for_drawVertices(SkPaint paint)
virtual void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &)
Definition SkDevice.cpp:204
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:179
SkMaskFilter * getMaskFilter() const
Definition SkPaint.h:534
void setShader(sk_sp< SkShader > shader)
sk_sp< const SkImage > atlas
Definition SkRecords.h:331

◆ onDrawBehind()

void SkCanvas::onDrawBehind ( const SkPaint paint)
protectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, SkCanvasVirtualEnforcer< SkNWayCanvas >, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkOverdrawCanvas, and MSKPPlayer::CmdRecordCanvas.

Definition at line 2357 of file SkCanvas.cpp.

2357 {
2358 SkDevice* dev = this->topDevice();
2359 if (!dev) {
2360 return;
2361 }
2362
2365 for (;;) {
2366 const MCRec* rec = (const MCRec*)iter.prev();
2367 if (!rec) {
2368 return; // no backimages, so nothing to draw
2369 }
2370 if (rec->fBackImage) {
2371 // drawBehind should only have been called when the saveBehind record is active;
2372 // if this fails, it means a real saveLayer was made w/o being restored first.
2373 SkASSERT(dev == rec->fDevice);
2374 bounds = SkIRect::MakeXYWH(rec->fBackImage->fLoc.fX, rec->fBackImage->fLoc.fY,
2375 rec->fBackImage->fImage->width(),
2376 rec->fBackImage->fImage->height());
2377 break;
2378 }
2379 }
2380
2381 // The backimage location (and thus bounds) were defined in the device's space, so mark it
2382 // as a clip. We use a clip instead of just drawing a rect in case the paint has an image
2383 // filter on it (which is applied before any auto-layer so the filter is clipped).
2384 dev->pushClipStack();
2385 {
2386 // We also have to temporarily whack the device matrix since clipRegion is affected by the
2387 // global-to-device matrix and clipRect is affected by the local-to-device.
2389 dev->clipRect(SkRect::Make(bounds), SkClipOp::kIntersect, /* aa */ false);
2390 // ~adtr will reset the local-to-device matrix so that drawPaint() shades correctly.
2391 }
2392
2393 auto layer = this->aboutToDraw(paint);
2394 if (layer) {
2395 this->topDevice()->drawPaint(layer->paint());
2396 }
2397
2398 dev->popClipStack();
2399}
@ kBack_IterStart
Definition SkDeque.h:66
virtual void popClipStack()=0
virtual void pushClipStack()=0
virtual void drawPaint(const SkPaint &paint)=0
static const SkMatrix & I()
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104

◆ onDrawDrawable()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 3012 of file SkCanvas.cpp.

3012 {
3013 // drawable bounds are no longer reliable (e.g. android displaylist)
3014 // so don't use them for quick-reject
3015 if (this->predrawNotify()) {
3016 this->topDevice()->drawDrawable(this, dr, matrix);
3017 }
3018}
virtual void drawDrawable(SkCanvas *, SkDrawable *, const SkMatrix *)
Definition SkDevice.cpp:299

◆ onDrawDRRect()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2457 of file SkCanvas.cpp.

2457 {
2458 const SkRect& bounds = outer.getBounds();
2459 if (this->internalQuickReject(bounds, paint)) {
2460 return;
2461 }
2462
2463 auto layer = this->aboutToDraw(paint, &bounds);
2464 if (layer) {
2465 this->topDevice()->drawDRRect(outer, inner, layer->paint());
2466 }
2467}
virtual void drawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &)
Definition SkDevice.cpp:142

◆ onDrawEdgeAAImageSet2()

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

Reimplemented in MSKPPlayer::CmdRecordCanvas, flutter::DidDrawCanvas, SkOverdrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, and SkNoDrawCanvas.

Definition at line 3065 of file SkCanvas.cpp.

3068 {
3069 if (count <= 0) {
3070 // Nothing to draw
3071 return;
3072 }
3073
3075 SkSamplingOptions realSampling = clean_sampling_for_constraint(sampling, constraint);
3076
3077 // We could calculate the set's dstRect union to always check quickReject(), but we can't reject
3078 // individual entries and Chromium's occlusion culling already makes it likely that at least one
3079 // entry will be visible. So, we only calculate the draw bounds when it's trivial (count == 1),
3080 // or we need it for the autolooper (since it greatly improves image filter perf).
3081 bool needsAutoLayer = SkToBool(realPaint.getImageFilter());
3082 bool setBoundsValid = count == 1 || needsAutoLayer;
3083 SkRect setBounds = imageSet[0].fDstRect;
3084 if (imageSet[0].fMatrixIndex >= 0) {
3085 // Account for the per-entry transform that is applied prior to the CTM when drawing
3086 preViewMatrices[imageSet[0].fMatrixIndex].mapRect(&setBounds);
3087 }
3088 if (needsAutoLayer) {
3089 for (int i = 1; i < count; ++i) {
3090 SkRect entryBounds = imageSet[i].fDstRect;
3091 if (imageSet[i].fMatrixIndex >= 0) {
3092 preViewMatrices[imageSet[i].fMatrixIndex].mapRect(&entryBounds);
3093 }
3094 setBounds.joinPossiblyEmptyRect(entryBounds);
3095 }
3096 }
3097
3098 // If we happen to have the draw bounds, though, might as well check quickReject().
3099 if (setBoundsValid && this->internalQuickReject(setBounds, realPaint)) {
3100 return;
3101 }
3102
3103 auto layer = this->aboutToDraw(realPaint, setBoundsValid ? &setBounds : nullptr);
3104 if (layer) {
3105 this->topDevice()->drawEdgeAAImageSet(imageSet, count, dstClips, preViewMatrices,
3106 realSampling, layer->paint(), constraint);
3107 }
3108}
static SkSamplingOptions clean_sampling_for_constraint(const SkSamplingOptions &sampling, SkCanvas::SrcRectConstraint constraint)
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
virtual void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
Definition SkDevice.cpp:254
SkImageFilter * getImageFilter() const
Definition SkPaint.h:564
void joinPossiblyEmptyRect(const SkRect &r)
Definition SkRect.h:1174

◆ onDrawEdgeAAQuad()

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

Reimplemented in SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, flutter::DidDrawCanvas, SkOverdrawCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 3050 of file SkCanvas.cpp.

3051 {
3052 SkASSERT(r.isSorted());
3053
3055 paint.setBlendMode(mode);
3056 if (this->internalQuickReject(r, paint)) {
3057 return;
3058 }
3059
3060 if (this->predrawNotify()) {
3061 this->topDevice()->drawEdgeAAQuad(r, clip, edgeAA, color, mode);
3062 }
3063}
virtual void drawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
Definition SkDevice.cpp:237

◆ onDrawGlyphRunList()

void SkCanvas::onDrawGlyphRunList ( const sktext::GlyphRunList glyphRunList,
const SkPaint paint 
)
protectedvirtual

Reimplemented in SkNWayCanvas, SkPaintFilterCanvas, SkOverdrawCanvas, SkRecorder, SkTestCanvas< SkSlugTestKey >, SkTestCanvas< SkSerializeSlugTestKey >, SkTestCanvas< SkRemoteSlugTestKey >, and OveridePaintFilterCanvas.

Definition at line 2783 of file SkCanvas.cpp.

2783 {
2784 SkRect bounds = glyphRunList.sourceBoundsWithOrigin();
2785 if (this->internalQuickReject(bounds, paint)) {
2786 return;
2787 }
2788
2789 // Text attempts to apply any SkMaskFilter internally and save the blurred masks in the
2790 // strike cache; if a glyph must be drawn as a path or drawable, SkDevice routes back to
2791 // this SkCanvas to retry, which will go through a function that does *not* skip the mask
2792 // filter layer.
2793 auto layer = this->aboutToDraw(paint, &bounds, PredrawFlags::kSkipMaskFilterAutoLayer);
2794 if (layer) {
2795 this->topDevice()->drawGlyphRunList(this, glyphRunList, layer->paint());
2796 }
2797}
void drawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition SkDevice.cpp:431

◆ onDrawImage2()

void SkCanvas::onDrawImage2 ( const SkImage image,
SkScalar  dx,
SkScalar  dy,
const SkSamplingOptions sampling,
const SkPaint paint 
)
protectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, and MSKPPlayer::CmdRecordCanvas.

Definition at line 2545 of file SkCanvas.cpp.

2546 {
2547#if defined(SK_RESOLVE_FILTERS_BEFORE_RESTORE)
2549
2551 if (this->internalQuickReject(dst, realPaint)) {
2552 return;
2553 }
2554
2555 if (realPaint.getImageFilter() &&
2556 this->canDrawBitmapAsSprite(x, y, image->width(), image->height(), sampling, realPaint) &&
2557 !SkCanvasPriv::ImageToColorFilter(&realPaint)) {
2558 // Evaluate the image filter directly on the input image and then draw the result, instead
2559 // of first drawing the image to a temporary layer and filtering.
2560 SkDevice* device = this->topDevice();
2561 sk_sp<SkSpecialImage> special;
2562 if ((special = device->makeSpecial(image))) {
2563 sk_sp<SkImageFilter> filter = realPaint.refImageFilter();
2564 realPaint.setImageFilter(nullptr);
2565
2566 // TODO(michaelludwig) - Many filters could probably be evaluated like this even if the
2567 // CTM is not translate-only; the post-transformation of the filtered image by the CTM
2568 // will probably look just as good and not require an extra layer.
2569 // TODO(michaelludwig) - Once image filter implementations can support source images
2570 // with non-(0,0) origins, we can just mark the origin as (x,y) instead of doing a
2571 // pre-concat here.
2572 SkMatrix layerToDevice = device->localToDevice();
2573 layerToDevice.preTranslate(x, y);
2574
2575 SkMatrix deviceToLayer;
2576 if (!layerToDevice.invert(&deviceToLayer)) {
2577 return; // bad ctm, draw nothing
2578 }
2579
2580 skif::Mapping mapping(layerToDevice, deviceToLayer, SkMatrix::Translate(-x, -y));
2581
2582 if (this->predrawNotify()) {
2583 // While we are skipping an initial layer, evaluate the rest of the image filter
2584 // pipeline in the same color format as we would have if there was a layer.
2585 const auto filterColorType =
2586 image_filter_color_type(device->imageInfo().colorInfo());
2587 device->drawFilteredImage(mapping, special.get(), filterColorType, filter.get(),
2588 sampling,realPaint);
2589 }
2590 return;
2591 } // else fall through to regular drawing path
2592 }
2593
2594 if (this->topDevice()->shouldDrawAsTiledImageRect()) {
2595 if (this->topDevice()->drawAsTiledImageRect(
2596 this, image, nullptr, dst, sampling, realPaint, kFast_SrcRectConstraint)) {
2597 return;
2598 }
2599 }
2600
2601 auto layer = this->aboutToDraw(realPaint, &dst);
2602 if (layer) {
2603 this->topDevice()->drawImageRect(image, nullptr, dst, sampling,
2604 layer->paint(), kFast_SrcRectConstraint);
2605 }
2606#else
2607 // drawImage() should call into onDrawImageRect() if SK_RESOLVE_FILTERS_BEFORE_RESTORE is off
2609#endif
2610}
#define SkUNREACHABLE
Definition SkAssert.h:135
static SkColorType image_filter_color_type(const SkColorInfo &dstInfo)
Definition SkCanvas.cpp:684
static bool ImageToColorFilter(SkPaint *)
virtual void drawImageRect(const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)=0
bool invert(SkMatrix *inverse) const
Definition SkMatrix.h:1206
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Definition SkMatrix.cpp:263
sk_sp< SkImageFilter > refImageFilter() const
void setImageFilter(sk_sp< SkImageFilter > imageFilter)

◆ onDrawImageLattice2()

void SkCanvas::onDrawImageLattice2 ( const SkImage image,
const Lattice lattice,
const SkRect dst,
SkFilterMode  filter,
const SkPaint paint 
)
protectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, and MSKPPlayer::CmdRecordCanvas.

Definition at line 2730 of file SkCanvas.cpp.

2731 {
2733
2734 if (this->internalQuickReject(dst, realPaint)) {
2735 return;
2736 }
2737
2738 auto layer = this->aboutToDraw(realPaint, &dst);
2739 if (layer) {
2740 this->topDevice()->drawImageLattice(image, lattice, dst, filter, layer->paint());
2741 }
2742}
virtual void drawImageLattice(const SkImage *, const SkCanvas::Lattice &, const SkRect &dst, SkFilterMode, const SkPaint &)
Definition SkDevice.cpp:164

◆ onDrawImageRect2()

void SkCanvas::onDrawImageRect2 ( const SkImage image,
const SkRect src,
const SkRect dst,
const SkSamplingOptions sampling,
const SkPaint paint,
SrcRectConstraint  constraint 
)
protectedvirtual

Reimplemented in SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, flutter::DidDrawCanvas, and MSKPPlayer::CmdRecordCanvas.

Definition at line 2626 of file SkCanvas.cpp.

2628 {
2630 SkSamplingOptions realSampling = clean_sampling_for_constraint(sampling, constraint);
2631
2632 if (this->internalQuickReject(dst, realPaint)) {
2633 return;
2634 }
2635
2636 if (this->topDevice()->shouldDrawAsTiledImageRect()) {
2637 if (this->topDevice()->drawAsTiledImageRect(
2638 this, image, &src, dst, realSampling, realPaint, constraint)) {
2639 return;
2640 }
2641 }
2642#if !defined(SK_RESOLVE_FILTERS_BEFORE_RESTORE)
2643 // drawImageRect()'s behavior is modified by the presence of an image filter, a mask filter, a
2644 // color filter, the paint's alpha, the paint's blender, and--when it's an alpha-only image--
2645 // the paint's color or shader. When there's an image filter, the paint's blender is applied to
2646 // the result of the image filter function, but every other aspect would influence the source
2647 // image that's then rendered with src-over blending into a transparent temporary layer.
2648 //
2649 // However, skif::FilterResult can apply the paint alpha and any color filter often without
2650 // requiring a layer, and src-over blending onto a transparent dst is a no-op, so we can use the
2651 // input image directly as the source for filtering. When the image is alpha-only and must be
2652 // colorized, or when a mask filter would change the coverage we skip this optimization for
2653 // simplicity since *somehow* embedding colorization or mask blurring into the filter graph
2654 // would likely be equivalent to using the existing AutoLayerForImageFilter functionality.
2655 if (realPaint.getImageFilter() && !image->isAlphaOnly() && !realPaint.getMaskFilter()) {
2656 SkDevice* device = this->topDevice();
2657
2658 skif::ParameterSpace<SkRect> imageBounds{dst};
2659 skif::DeviceSpace<SkIRect> outputBounds{device->devClipBounds()};
2660 FilterToSpan filterAsSpan(realPaint.getImageFilter());
2661 auto mappingAndBounds = get_layer_mapping_and_bounds(filterAsSpan,
2662 device->localToDevice(),
2663 outputBounds,
2664 imageBounds);
2665 if (!mappingAndBounds) {
2666 return;
2667 }
2668 if (!this->predrawNotify()) {
2669 return;
2670 }
2671
2672 // Start out with an empty source image, to be replaced with the converted 'image', and a
2673 // desired output equal to the calculated initial source layer bounds, which accounts for
2674 // how the image filters will access 'image' (possibly different than just 'outputBounds').
2675 auto backend = device->createImageFilteringBackend(
2676 device->surfaceProps(),
2677 image_filter_color_type(device->imageInfo().colorInfo()));
2678 auto [mapping, srcBounds] = *mappingAndBounds;
2680 skif::Context ctx{std::move(backend),
2681 mapping,
2682 srcBounds,
2684 device->imageInfo().colorSpace(),
2685 &stats};
2686
2688 ctx, sk_ref_sp(image), src, imageBounds, sampling);
2689 // Apply effects that are normally processed on the draw *before* any layer/image filter.
2690 source = apply_alpha_and_colorfilter(ctx, source, realPaint);
2691
2692 // Evaluate the image filter, with a context pointing to the source created directly from
2693 // 'image' (which will not require intermediate renderpasses when 'src' is integer aligned).
2694 // and a desired output matching the device clip bounds.
2695 ctx = ctx.withNewDesiredOutput(mapping.deviceToLayer(outputBounds))
2696 .withNewSource(source);
2697 auto result = as_IFB(realPaint.getImageFilter())->filterImage(ctx);
2698 result.draw(ctx, device, realPaint.getBlender());
2699 stats.reportStats();
2700 return;
2701 }
2702
2703 // When there's a alpha-only image that must be colorized or a mask filter to apply, go through
2704 // the regular auto-layer-for-imagefilter process
2705#endif
2706
2707 if (realPaint.getMaskFilter() && this->topDevice()->useDrawCoverageMaskForMaskFilters()) {
2708 // Route mask-filtered drawImages to drawRect() to use the auto-layer for mask filters,
2709 // which require all shading to be encoded in the paint.
2711 image, sampling, src, dst, constraint == kStrict_SrcRectConstraint, &realPaint);
2712 if (drawDst.isEmpty()) {
2713 return;
2714 } else {
2715 this->drawRect(drawDst, realPaint);
2716 return;
2717 }
2718 }
2719
2720 auto layer = this->aboutToDraw(realPaint, &dst,
2721 PredrawFlags::kCheckForOverwrite |
2722 (image->isOpaque() ? PredrawFlags::kOpaqueShaderOverride
2723 : PredrawFlags::kNonOpaqueShaderOverride));
2724 if (layer) {
2725 this->topDevice()->drawImageRect(image, &src, dst, realSampling, layer->paint(),
2726 constraint);
2727 }
2728}
const char * backend
static std::optional< std::pair< skif::Mapping, skif::LayerSpace< SkIRect > > > get_layer_mapping_and_bounds(SkCanvas::FilterSpan filters, const SkMatrix &localToDst, const skif::DeviceSpace< SkIRect > &targetOutput, std::optional< skif::ParameterSpace< SkRect > > contentBounds={}, SkScalar scaleFactor=1.0f)
Definition SkCanvas.cpp:572
static skif::FilterResult apply_alpha_and_colorfilter(const skif::Context &ctx, const skif::FilterResult &image, const SkPaint &paint)
Definition SkCanvas.cpp:697
static SkImageFilter_Base * as_IFB(SkImageFilter *filter)
SkRect SkModifyPaintAndDstForDrawImageRect(const SkImage *image, const SkSamplingOptions &, SkRect src, SkRect dst, bool strictSrcSubset, SkPaint *paint)
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
skif::FilterResult filterImage(const skif::Context &context) const
bool isAlphaOnly() const
Definition SkImage.cpp:239
bool isOpaque() const
Definition SkImage.h:375
SkBlender * getBlender() const
Definition SkPaint.h:480
void draw(const Context &ctx, SkDevice *target, const SkBlender *blender) const
static FilterResult MakeFromImage(const Context &ctx, sk_sp< SkImage > image, SkRect srcRect, ParameterSpace< SkRect > dstRect, const SkSamplingOptions &sampling)
SkBitmap source
Definition examples.cpp:28
GAsyncResult * result
dict stats
Definition malisc.py:20

◆ onDrawMesh()

void SkCanvas::onDrawMesh ( const SkMesh mesh,
sk_sp< SkBlender blender,
const SkPaint paint 
)
protectedvirtual

Reimplemented in SkRecorder.

Definition at line 2948 of file SkCanvas.cpp.

2948 {
2950 auto layer = this->aboutToDraw(simplePaint, nullptr);
2951 if (layer) {
2952 this->topDevice()->drawMesh(mesh, std::move(blender), paint);
2953 }
2954}
virtual void drawMesh(const SkMesh &mesh, sk_sp< SkBlender >, const SkPaint &)=0

◆ onDrawOval()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2401 of file SkCanvas.cpp.

2401 {
2403 if (this->internalQuickReject(oval, paint)) {
2404 return;
2405 }
2406
2407 // Returns a layer if a blurred draw is not applicable or was unsuccessful.
2408 std::optional<AutoLayerForImageFilter> layer =
2409 this->attemptBlurredRRectDraw(SkRRect::MakeOval(oval), paint, PredrawFlags::kNone);
2410
2411 if (layer) {
2412 this->topDevice()->drawOval(oval, layer->paint());
2413 }
2414}
virtual void drawOval(const SkRect &oval, const SkPaint &paint)=0
static SkRRect MakeOval(const SkRect &oval)
Definition SkRRect.h:162

◆ onDrawPaint()

void SkCanvas::onDrawPaint ( const SkPaint paint)
protectedvirtual

◆ onDrawPatch()

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

Reimplemented in MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, SkCanvasVirtualEnforcer< SkNWayCanvas >, flutter::DidDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkOverdrawCanvas, and SkNoDrawCanvas.

Definition at line 2967 of file SkCanvas.cpp.

2969 {
2970 // drawPatch has the same behavior restrictions as drawVertices
2972
2973 // Since a patch is always within the convex hull of the control points, we discard it when its
2974 // bounding rectangle is completely outside the current clip.
2975 SkRect bounds;
2976 bounds.setBounds(cubics, SkPatchUtils::kNumCtrlPts);
2977 if (this->internalQuickReject(bounds, simplePaint)) {
2978 return;
2979 }
2980
2981 auto layer = this->aboutToDraw(simplePaint, &bounds);
2982 if (layer) {
2983 this->topDevice()->drawPatch(cubics, colors, texCoords, SkBlender::Mode(bmode),
2984 layer->paint());
2985 }
2986}
virtual void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], sk_sp< SkBlender >, const SkPaint &paint)
Definition SkDevice.cpp:153

◆ onDrawPath()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2469 of file SkCanvas.cpp.

2469 {
2470 if (!path.isFinite()) {
2471 return;
2472 }
2473
2474 const SkRect& pathBounds = path.getBounds();
2475 if (!path.isInverseFillType() && this->internalQuickReject(pathBounds, paint)) {
2476 return;
2477 }
2478 if (path.isInverseFillType() && pathBounds.width() <= 0 && pathBounds.height() <= 0) {
2479 this->internalDrawPaint(paint);
2480 return;
2481 }
2482
2483 auto layer = this->aboutToDraw(paint, path.isInverseFillType() ? nullptr : &pathBounds);
2484 if (layer) {
2485 this->topDevice()->drawPath(path, layer->paint());
2486 }
2487}
virtual void drawPath(const SkPath &path, const SkPaint &paint, bool pathIsMutable=false)=0
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762

◆ onDrawPicture()

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

◆ onDrawPoints()

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

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkOverdrawCanvas, SkNoDrawCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2237 of file SkCanvas.cpp.

2238 {
2239 if ((long)count <= 0 || paint.nothingToDraw()) {
2240 return;
2241 }
2242 SkASSERT(pts != nullptr);
2243
2244 SkRect bounds;
2245 // Compute bounds from points (common for drawing a single line)
2246 if (count == 2) {
2247 bounds.set(pts[0], pts[1]);
2248 } else {
2249 bounds.setBounds(pts, SkToInt(count));
2250 }
2251
2252 // Enforce paint style matches implicit behavior of drawPoints
2253 SkPaint strokePaint = paint;
2254 strokePaint.setStyle(SkPaint::kStroke_Style);
2255 if (this->internalQuickReject(bounds, strokePaint)) {
2256 return;
2257 }
2258
2259 auto layer = this->aboutToDraw(strokePaint, &bounds);
2260 if (layer) {
2261 this->topDevice()->drawPoints(mode, count, pts, layer->paint());
2262 }
2263}
constexpr int SkToInt(S x)
Definition SkTo.h:29
virtual void drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint)=0
void setStyle(Style style)
Definition SkPaint.cpp:105
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194

◆ onDrawRect()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2330 of file SkCanvas.cpp.

2330 {
2331 SkASSERT(r.isSorted());
2332 if (this->internalQuickReject(r, paint)) {
2333 return;
2334 }
2335
2336 // Returns a layer if a blurred draw is not applicable or was unsuccessful.
2337 std::optional<AutoLayerForImageFilter> layer = this->attemptBlurredRRectDraw(
2338 SkRRect::MakeRect(r), paint, PredrawFlags::kCheckForOverwrite);
2339
2340 if (layer) {
2341 this->topDevice()->drawRect(r, layer->paint());
2342 }
2343}
virtual void drawRect(const SkRect &r, const SkPaint &paint)=0
static SkRRect MakeRect(const SkRect &r)
Definition SkRRect.h:149

◆ onDrawRegion()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2345 of file SkCanvas.cpp.

2345 {
2347 if (this->internalQuickReject(bounds, paint)) {
2348 return;
2349 }
2350
2351 auto layer = this->aboutToDraw(paint, &bounds);
2352 if (layer) {
2353 this->topDevice()->drawRegion(region, layer->paint());
2354 }
2355}
virtual void drawRegion(const SkRegion &r, const SkPaint &paint)
Definition SkDevice.cpp:112

◆ onDrawRRect()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2430 of file SkCanvas.cpp.

2430 {
2431 const SkRect& bounds = rrect.getBounds();
2432
2433 // Delegating to simpler draw operations
2434 if (rrect.isRect()) {
2435 // call the non-virtual version
2436 this->SkCanvas::drawRect(bounds, paint);
2437 return;
2438 } else if (rrect.isOval()) {
2439 // call the non-virtual version
2440 this->SkCanvas::drawOval(bounds, paint);
2441 return;
2442 }
2443
2444 if (this->internalQuickReject(bounds, paint)) {
2445 return;
2446 }
2447
2448 // Returns a layer if a blurred draw is not applicable or was unsuccessful.
2449 std::optional<AutoLayerForImageFilter> layer =
2450 this->attemptBlurredRRectDraw(rrect, paint, PredrawFlags::kNone);
2451
2452 if (layer) {
2453 this->topDevice()->drawRRect(rrect, layer->paint());
2454 }
2455}
virtual void drawRRect(const SkRRect &rr, const SkPaint &paint)=0
bool isOval() const
Definition SkRRect.h:85

◆ onDrawShadowRec()

void SkCanvas::onDrawShadowRec ( const SkPath path,
const SkDrawShadowRec rec 
)
protectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, SkCanvasVirtualEnforcer< SkNWayCanvas >, SkPaintFilterCanvas, and MSKPPlayer::CmdRecordCanvas.

Definition at line 2160 of file SkCanvas.cpp.

2160 {
2161 // We don't test quickReject because the shadow outsets the path's bounds.
2162 // TODO(michaelludwig): Is it worth calling SkDrawShadowMetrics::GetLocalBounds here?
2163 if (!this->predrawNotify()) {
2164 return;
2165 }
2166 this->topDevice()->drawShadow(path, rec);
2167}
virtual void drawShadow(const SkPath &, const SkDrawShadowRec &)

◆ onDrawSlug()

void SkCanvas::onDrawSlug ( const sktext::gpu::Slug slug,
const SkPaint paint 
)
protectedvirtual

Reimplemented in SkNWayCanvas, SkPictureRecord, and SkRecorder.

Definition at line 2827 of file SkCanvas.cpp.

2827 {
2829 if (this->internalQuickReject(bounds, paint)) {
2830 return;
2831 }
2832 // See comment in onDrawGlyphRunList()
2833 auto layer = this->aboutToDraw(paint, &bounds, PredrawFlags::kSkipMaskFilterAutoLayer);
2834 if (layer) {
2835 this->topDevice()->drawSlug(this, slug, layer->paint());
2836 }
2837}
virtual void drawSlug(SkCanvas *, const sktext::gpu::Slug *slug, const SkPaint &paint)
Definition SkDevice.cpp:493
virtual SkRect sourceBoundsWithOrigin() const =0

◆ onDrawTextBlob()

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

◆ onDrawVerticesObject()

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

Reimplemented in flutter::DidDrawCanvas, SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, and DebugCanvas.

Definition at line 2933 of file SkCanvas.cpp.

2934 {
2936
2937 const SkRect& bounds = vertices->bounds();
2938 if (this->internalQuickReject(bounds, simplePaint)) {
2939 return;
2940 }
2941
2942 auto layer = this->aboutToDraw(simplePaint, &bounds);
2943 if (layer) {
2944 this->topDevice()->drawVertices(vertices, SkBlender::Mode(bmode), layer->paint());
2945 }
2946}
virtual void drawVertices(const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool skipColorXform=false)=0
const SkRect & bounds() const
Definition SkVertices.h:98

◆ onGetProps()

bool SkCanvas::onGetProps ( SkSurfaceProps props,
bool  top 
) const
protectedvirtual

Reimplemented in SkPaintFilterCanvas.

Definition at line 1554 of file SkCanvas.cpp.

1554 {
1555 if (props) {
1556 *props = top ? topDevice()->surfaceProps() : fProps;
1557 }
1558 return true;
1559}
const SkSurfaceProps & surfaceProps() const
Definition SkDevice.h:131

◆ onImageInfo()

SkImageInfo SkCanvas::onImageInfo ( ) const
protectedvirtual

Reimplemented in SkPaintFilterCanvas.

Definition at line 1534 of file SkCanvas.cpp.

1534 {
1535 return this->rootDevice()->imageInfo();
1536}

◆ onNewSurface()

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

Reimplemented in SkPaintFilterCanvas, SkPictureRecord, and SkRecorder.

Definition at line 1526 of file SkCanvas.cpp.

1526 {
1527 return this->rootDevice()->makeSurface(info, props);
1528}
virtual sk_sp< SkSurface > makeSurface(const SkImageInfo &, const SkSurfaceProps &)
Definition SkDevice.cpp:499

◆ onPeekPixels()

bool SkCanvas::onPeekPixels ( SkPixmap pixmap)
protectedvirtual

Reimplemented in SkPictureRecord, and SkPaintFilterCanvas.

Definition at line 1565 of file SkCanvas.cpp.

1565 {
1566 return this->rootDevice()->peekPixels(pmap);
1567}
bool peekPixels(SkPixmap *)
Definition SkDevice.cpp:396

◆ onResetClip()

void SkCanvas::onResetClip ( )
protectedvirtual

Reimplemented in SkNWayCanvas, SkPictureRecord, SkRecorder, and DebugCanvas.

Definition at line 1748 of file SkCanvas.cpp.

1748 {
1749 SkIRect deviceRestriction = this->topDevice()->imageInfo().bounds();
1750 if (fClipRestrictionSaveCount >= 0 && this->topDevice() == this->rootDevice()) {
1751 // Respect the device clip restriction when resetting the clip if we're on the base device.
1752 // If we're not on the base device, then the "reset" applies to the top device's clip stack,
1753 // and the clip restriction will be respected automatically during a restore of the layer.
1754 if (!deviceRestriction.intersect(fClipRestrictionRect)) {
1755 deviceRestriction = SkIRect::MakeEmpty();
1756 }
1757 }
1758
1759 AutoUpdateQRBounds aqr(this);
1760 this->topDevice()->replaceClip(deviceRestriction);
1761}
virtual void replaceClip(const SkIRect &rect)=0
bool intersect(const SkIRect &r)
Definition SkRect.h:513
SkIRect bounds() const

◆ peekPixels()

bool SkCanvas::peekPixels ( SkPixmap pixmap)

Returns true if SkCanvas has direct access to its pixels.

Pixels are readable when SkDevice 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

Definition at line 1561 of file SkCanvas.cpp.

1561 {
1562 return this->onPeekPixels(pmap);
1563}
virtual bool onPeekPixels(SkPixmap *pixmap)

◆ private_draw_shadow_rec()

void SkCanvas::private_draw_shadow_rec ( const SkPath path,
const SkDrawShadowRec rec 
)

Definition at line 2155 of file SkCanvas.cpp.

2155 {
2156 TRACE_EVENT0("skia", TRACE_FUNC);
2157 this->onDrawShadowRec(path, rec);
2158}
virtual void onDrawShadowRec(const SkPath &, const SkDrawShadowRec &)

◆ quickReject() [1/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

Definition at line 1891 of file SkCanvas.cpp.

1891 {
1892 return path.isEmpty() || this->quickReject(path.getBounds());
1893}
bool quickReject(const SkRect &rect) const
const SkRect & getBounds() const
Definition SkPath.cpp:420

◆ quickReject() [2/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

Definition at line 1881 of file SkCanvas.cpp.

1881 {
1882#ifdef SK_DEBUG
1883 // Verify that fQuickRejectBounds are set properly.
1884 this->validateClip();
1885#endif
1886
1887 SkRect devRect = SkMatrixPriv::MapRect(fMCRec->fMatrix, src);
1888 return !devRect.isFinite() || !devRect.intersects(fQuickRejectBounds);
1889}
static SkRect MapRect(const SkM44 &m, const SkRect &r)
Definition SkM44.cpp:216
bool intersects(const SkRect &r) const
Definition SkRect.h:1121

◆ readPixels() [1/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 SkDevice 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

Definition at line 390 of file SkCanvas.cpp.

390 {
391 SkPixmap pm;
392 return bm.peekPixels(&pm) && this->readPixels(pm, x, y);
393}
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY)
Definition SkCanvas.cpp:386

◆ readPixels() [2/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 SkDevice 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

Definition at line 386 of file SkCanvas.cpp.

386 {
387 return this->readPixels({ dstInfo, dstP, rowBytes}, x, y);
388}

◆ readPixels() [3/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 SkDevice 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

Definition at line 382 of file SkCanvas.cpp.

382 {
383 return pm.addr() && this->rootDevice()->readPixels(pm, x, y);
384}
bool readPixels(const SkPixmap &dst, int x, int y)
Definition SkDevice.h:153

◆ recorder()

skgpu::graphite::Recorder * SkCanvas::recorder ( ) const
virtual

Returns Recorder for the GPU surface associated with SkCanvas.

Returns
Recorder, if available; nullptr otherwise

Definition at line 1965 of file SkCanvas.cpp.

1965 {
1966 return this->topDevice()->recorder();
1967}
virtual skgpu::graphite::Recorder * recorder() const
Definition SkDevice.h:285

◆ recordingContext()

GrRecordingContext * SkCanvas::recordingContext ( ) const
virtual

Returns Ganesh context of the GPU surface associated with SkCanvas.

Returns
GPU context, if available; nullptr otherwise

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

Reimplemented in SkPaintFilterCanvas.

Definition at line 1961 of file SkCanvas.cpp.

1961 {
1962 return this->topDevice()->recordingContext();
1963}
virtual GrRecordingContext * recordingContext() const
Definition SkDevice.h:284

◆ resetMatrix()

void SkCanvas::resetMatrix ( )

Sets SkMatrix to the identity matrix. Any prior matrix state is overwritten.

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

Definition at line 1679 of file SkCanvas.cpp.

1679 {
1680 this->setMatrix(SkM44());
1681}
void setMatrix(const SkM44 &matrix)

◆ 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

Definition at line 465 of file SkCanvas.cpp.

465 {
466 if (fMCRec->fDeferredSaveCount > 0) {
467 SkASSERT(fSaveCount > 1);
468 fSaveCount -= 1;
469 fMCRec->fDeferredSaveCount -= 1;
470 } else {
471 // check for underflow
472 if (fMCStack.count() > 1) {
473 this->willRestore();
474 SkASSERT(fSaveCount > 1);
475 fSaveCount -= 1;
476 this->internalRestore();
477 this->didRestore();
478 }
479 }
480}
virtual void didRestore()
Definition SkCanvas.h:2277
virtual void willRestore()
Definition SkCanvas.h:2276
int count() const
Definition SkDeque.h:39

◆ 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

Definition at line 482 of file SkCanvas.cpp.

482 {
483 // safety check
484 if (count < 1) {
485 count = 1;
486 }
487
488 int n = this->getSaveCount() - count;
489 for (int i = 0; i < n; ++i) {
490 this->restore();
491 }
492}
void restore()
Definition SkCanvas.cpp:465

◆ 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

Definition at line 1624 of file SkCanvas.cpp.

1624 {
1625 SkMatrix m;
1626 m.setRotate(degrees);
1627 this->concat(m);
1628}

◆ 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

Definition at line 1630 of file SkCanvas.cpp.

1630 {
1631 SkMatrix m;
1632 m.setRotate(degrees, px, py);
1633 this->concat(m);
1634}

◆ 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

Definition at line 451 of file SkCanvas.cpp.

451 {
452 fSaveCount += 1;
453 fMCRec->fDeferredSaveCount += 1;
454 return this->getSaveCount() - 1; // return our prev value
455}

◆ saveLayer() [1/3]

int SkCanvas::saveLayer ( const SaveLayerRec layerRec)

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

Calling restore() discards changes to SkMatrix and clip, and blends SkSurface 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

Definition at line 504 of file SkCanvas.cpp.

504 {
505 TRACE_EVENT0("skia", TRACE_FUNC);
506 if (rec.fPaint && rec.fPaint->nothingToDraw()) {
507 // no need for the layer (or any of the draws until the matching restore()
508 this->save();
509 this->clipRect({0,0,0,0});
510 } else {
511 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec);
512 fSaveCount += 1;
513 this->internalSaveLayer(rec, strategy);
514 }
515 return this->getSaveCount() - 1;
516}
virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec &)
Definition SkCanvas.h:2270
SaveLayerStrategy
Definition SkCanvas.h:2263
int save()
Definition SkCanvas.cpp:451

◆ saveLayer() [2/3]

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

Saves SkMatrix and clip, and allocates a SkSurface for subsequent drawing. Calling restore() discards changes to SkMatrix and clip, and draws the SkSurface.

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

Definition at line 633 of file SkCanvas.h.

633 {
634 return this->saveLayer(&bounds, paint);
635 }
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition SkCanvas.cpp:500

◆ saveLayer() [3/3]

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

Saves SkMatrix and clip, and allocates a SkSurface for subsequent drawing. Calling restore() discards changes to SkMatrix and clip, and draws the SkSurface.

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 SkSurface 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 example: https://fiddle.skia.org/c/@Canvas_saveLayer_4

Definition at line 500 of file SkCanvas.cpp.

500 {
501 return this->saveLayer(SaveLayerRec(bounds, paint, 0));
502}

◆ saveLayerAlpha()

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

Definition at line 661 of file SkCanvas.h.

661 {
662 return this->saveLayerAlphaf(bounds, alpha * (1.0f / 255));
663 }
int saveLayerAlphaf(const SkRect *bounds, float alpha)

◆ saveLayerAlphaf()

int SkCanvas::saveLayerAlphaf ( const SkRect bounds,
float  alpha 
)

Saves SkMatrix and clip, and allocates SkSurface 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, 1.0f 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

Definition at line 1401 of file SkCanvas.cpp.

1401 {
1402 if (alpha >= 1.0f) {
1403 return this->saveLayer(bounds, nullptr);
1404 } else {
1405 SkPaint tmpPaint;
1406 tmpPaint.setAlphaf(alpha);
1407 return this->saveLayer(bounds, &tmpPaint);
1408 }
1409}
void setAlphaf(float a)
Definition SkPaint.cpp:130

◆ 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

Definition at line 1613 of file SkCanvas.cpp.

1613 {
1614 if (sx != 1 || sy != 1) {
1615 this->checkForDeferredSave();
1616 fMCRec->fMatrix.preScale(sx, sy);
1617
1618 this->topDevice()->setGlobalCTM(fMCRec->fMatrix);
1619
1620 this->didScale(sx, sy);
1621 }
1622}
virtual void didScale(SkScalar, SkScalar)
Definition SkCanvas.h:2282
void setGlobalCTM(const SkM44 &ctm)
Definition SkDevice.cpp:72

◆ setMatrix() [1/2]

void SkCanvas::setMatrix ( const SkM44 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

Definition at line 1673 of file SkCanvas.cpp.

1673 {
1674 this->checkForDeferredSave();
1675 this->internalSetMatrix(m);
1676 this->didSetM44(m);
1677}
virtual void didSetM44(const SkM44 &)
Definition SkCanvas.h:2280

◆ setMatrix() [2/2]

void SkCanvas::setMatrix ( const SkMatrix matrix)

Definition at line 1669 of file SkCanvas.cpp.

1669 {
1670 this->setMatrix(SkM44(matrix));
1671}

◆ 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

Definition at line 1636 of file SkCanvas.cpp.

1636 {
1637 SkMatrix m;
1638 m.setSkew(sx, sy);
1639 this->concat(m);
1640}

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

Definition at line 1859 of file SkCanvas.cpp.

1859 {
1860 rgn->setEmpty();
1861 SkDevice* device = this->topDevice();
1862 if (device && device->isPixelAlignedToGlobal()) {
1863 device->android_utils_clipAsRgn(rgn);
1864 SkIPoint origin = device->getOrigin();
1865 if (origin.x() | origin.y()) {
1866 rgn->translate(origin.x(), origin.y());
1867 }
1868 }
1869}
constexpr int32_t y() const
constexpr int32_t x() const

◆ 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

Definition at line 1602 of file SkCanvas.cpp.

1602 {
1603 if (dx || dy) {
1604 this->checkForDeferredSave();
1605 fMCRec->fMatrix.preTranslate(dx, dy);
1606
1607 this->topDevice()->setGlobalCTM(fMCRec->fMatrix);
1608
1609 this->didTranslate(dx,dy);
1610 }
1611}
virtual void didTranslate(SkScalar, SkScalar)
Definition SkCanvas.h:2281

◆ willRestore()

virtual void SkCanvas::willRestore ( )
inlineprotectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, SaveCountingCanvas, and DebugCanvas.

Definition at line 2276 of file SkCanvas.h.

2276{}

◆ willSave()

virtual void SkCanvas::willSave ( )
inlineprotectedvirtual

Reimplemented in flutter::DidDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, SaveCountingCanvas, and DebugCanvas.

Definition at line 2268 of file SkCanvas.h.

2268{}

◆ writePixels() [1/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 SkDevice 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

Definition at line 395 of file SkCanvas.cpp.

395 {
396 SkPixmap pm;
397 if (bitmap.peekPixels(&pm)) {
398 return this->writePixels(pm.info(), pm.addr(), pm.rowBytes(), x, y);
399 }
400 return false;
401}
bool writePixels(const SkImageInfo &info, const void *pixels, size_t rowBytes, int x, int y)
Definition SkCanvas.cpp:403
const void * addr() const
Definition SkPixmap.h:153

◆ writePixels() [2/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 SkDevice 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:

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

Definition at line 403 of file SkCanvas.cpp.

404 {
405 SkDevice* device = this->rootDevice();
406
407 // This check gives us an early out and prevents generation ID churn on the surface.
408 // This is purely optional: it is a subset of the checks performed by SkWritePixelsRec.
409 SkIRect srcRect = SkIRect::MakeXYWH(x, y, srcInfo.width(), srcInfo.height());
410 if (!srcRect.intersect({0, 0, device->width(), device->height()})) {
411 return false;
412 }
413
414 // Tell our owning surface to bump its generation ID.
415 const bool completeOverwrite = srcRect.size() == device->imageInfo().dimensions();
416 if (!this->predrawNotify(completeOverwrite)) {
417 return false;
418 }
419
420 // This can still fail, most notably in the case of a invalid color type or alpha type
421 // conversion. We could pull those checks into this function and avoid the unnecessary
422 // generation ID bump. But then we would be performing those checks twice, since they
423 // are also necessary at the bitmap/pixmap entry points.
424 return device->writePixels({srcInfo, pixels, rowBytes}, x, y);
425}
constexpr SkISize size() const
Definition SkRect.h:172

Friends And Related Symbol Documentation

◆ AutoLayerForImageFilter

friend class AutoLayerForImageFilter
friend

Definition at line 2489 of file SkCanvas.h.

◆ operator&

constexpr SkEnumBitMask< PredrawFlags > operator& ( PredrawFlags  ,
PredrawFlags   
)
friend

◆ operator^

constexpr SkEnumBitMask< PredrawFlags > operator^ ( PredrawFlags  ,
PredrawFlags   
)
friend

◆ operator|

constexpr SkEnumBitMask< PredrawFlags > operator| ( PredrawFlags  ,
PredrawFlags   
)
friend

◆ operator~

constexpr SkEnumBitMask< PredrawFlags > operator~ ( PredrawFlags  )
friend

◆ SkAndroidFrameworkUtils

friend class SkAndroidFrameworkUtils
friend

Definition at line 2487 of file SkCanvas.h.

◆ SkCanvasPriv

friend class SkCanvasPriv
friend

Definition at line 2488 of file SkCanvas.h.

◆ SkCanvasStateUtils

friend class SkCanvasStateUtils
friend

Definition at line 2544 of file SkCanvas.h.

◆ SkNoDrawCanvas

friend class SkNoDrawCanvas
friend

Definition at line 2491 of file SkCanvas.h.

◆ SkNWayCanvas

friend class SkNWayCanvas
friend

Definition at line 2492 of file SkCanvas.h.

◆ SkOverdrawCanvas

friend class SkOverdrawCanvas
friend

Definition at line 2494 of file SkCanvas.h.

◆ SkPicturePlayback

friend class SkPicturePlayback
friend

Definition at line 2513 of file SkCanvas.h.

◆ SkPictureRecord

friend class SkPictureRecord
friend

Definition at line 2493 of file SkCanvas.h.

◆ SkRasterHandleAllocator

friend class SkRasterHandleAllocator
friend

Definition at line 2495 of file SkCanvas.h.

◆ SkRecords::Draw

friend class SkRecords::Draw
friend

Definition at line 2496 of file SkCanvas.h.

◆ SkSurface_Base

friend class SkSurface_Base
friend

Definition at line 2477 of file SkCanvas.h.

◆ SkSurface_Ganesh

friend class SkSurface_Ganesh
friend

Definition at line 2478 of file SkCanvas.h.

◆ SkSurface_Raster

friend class SkSurface_Raster
friend

Definition at line 2490 of file SkCanvas.h.

◆ SkTestCanvas

template<typename Key >
friend class SkTestCanvas
friend

Definition at line 2498 of file SkCanvas.h.

◆ sktext::gpu::Slug

friend class sktext::gpu::Slug
friend

Definition at line 2512 of file SkCanvas.h.

Member Data Documentation

◆ kMaxFiltersPerLayer

constexpr int SkCanvas::kMaxFiltersPerLayer = 16
staticconstexpr

Definition at line 679 of file SkCanvas.h.


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