Flutter Engine
The Flutter Engine
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 324 of file SkCanvas.cpp.

324 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
325 this->init(nullptr);
326}

◆ 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 328 of file SkCanvas.cpp.

329 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
330 , fProps(SkSurfacePropsCopyOrDefault(props)) {
331 this->init(sk_make_sp<SkNoPixelsDevice>(
332 SkIRect::MakeWH(std::max(width, 0), std::max(height, 0)), fProps));
333}
static SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps *props)
Definition: SkSurfacePriv.h:15
static float max(float r, float g, float b)
Definition: hsl.cpp:49
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 341 of file SkCanvas.cpp.

342 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
343 , fProps(device->surfaceProps()) {
344 this->init(std::move(device));
345}
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) {}
Definition: bitmap.py:1

◆ 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 347 of file SkCanvas.cpp.

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

◆ SkCanvas() [6/6]

SkCanvas::SkCanvas ( const SkIRect bounds)
protected

Definition at line 335 of file SkCanvas.cpp.

336 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
337 SkIRect r = bounds.isEmpty() ? SkIRect::MakeEmpty() : bounds;
338 this->init(sk_make_sp<SkNoPixelsDevice>(r, fProps));
339}
Optional< SkRect > bounds
Definition: SkRecords.h:189
Definition: SkRect.h:32
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 1245 of file SkCanvas.cpp.

1245 {
1246 SkPixmap pmap;
1247 if (!this->onAccessTopLayerPixels(&pmap)) {
1248 return nullptr;
1249 }
1250 if (info) {
1251 *info = pmap.info();
1252 }
1253 if (rowBytes) {
1254 *rowBytes = pmap.rowBytes();
1255 }
1256 if (origin) {
1257 // If the caller requested the origin, they presumably are expecting the returned pixels to
1258 // be axis-aligned with the root canvas. If the top level device isn't axis aligned, that's
1259 // not the case. Until we update accessTopLayerPixels() to accept a coord space matrix
1260 // instead of an origin, just don't expose the pixels in that case. Note that this means
1261 // that layers with complex coordinate spaces can still report their pixels if the caller
1262 // does not ask for the origin (e.g. just to dump its output to a file, etc).
1263 if (this->topDevice()->isPixelAlignedToGlobal()) {
1264 *origin = this->topDevice()->getOrigin();
1265 } else {
1266 return nullptr;
1267 }
1268 }
1269 return pmap.writable_addr();
1270}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
virtual bool onAccessTopLayerPixels(SkPixmap *pixmap)
Definition: SkCanvas.cpp:1272
SkIPoint getOrigin() const
Definition: SkDevice.cpp:91
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 2841 of file SkCanvas.cpp.

2841 {
2842 const SkDevice* dev = this->topDevice();
2843 if (fAllocator) {
2845 SkIRect clip = dev->devClipBounds();
2846 if (!clip.intersect({0, 0, dev->width(), dev->height()})) {
2847 clip.setEmpty();
2848 }
2849
2850 fAllocator->updateHandle(handle, dev->localToDevice(), clip);
2851 return handle;
2852 }
2853 return nullptr;
2854}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
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 1378 of file SkCanvas.cpp.

1378 {
1379 // The device clip restriction is a surface-space rectangular intersection that cannot be
1380 // drawn outside of. The rectangle is remembered so that subsequent resetClip calls still
1381 // respect the restriction. Other than clip resetting, all clip operations restrict the set
1382 // of renderable pixels, so once set, the restriction will be respected until the canvas
1383 // save stack is restored past the point this function was invoked. Unfortunately, the current
1384 // implementation relies on the clip stack of the underyling SkDevices, which leads to some
1385 // awkward behavioral interactions (see skbug.com/12252).
1386 //
1387 // Namely, a canvas restore() could undo the clip restriction's rect, and if
1388 // setDeviceClipRestriction were called at a nested save level, there's no way to undo just the
1389 // prior restriction and re-apply the new one. It also only makes sense to apply to the base
1390 // device; any other device for a saved layer will be clipped back to the base device during its
1391 // matched restore. As such, we:
1392 // - Remember the save count that added the clip restriction and reset the rect to empty when
1393 // we've restored past that point to keep our state in sync with the device's clip stack.
1394 // - We assert that we're on the base device when this is invoked.
1395 // - We assert that setDeviceClipRestriction() is only called when there was no prior
1396 // restriction (cannot re-restrict, and prior state must have been reset by restoring the
1397 // canvas state).
1398 // - Historically, the empty rect would reset the clip restriction but it only could do so
1399 // partially since the device's clips wasn't adjusted. Resetting is now handled
1400 // automatically via SkCanvas::restore(), so empty input rects are skipped.
1401 SkASSERT(this->topDevice() == this->rootDevice()); // shouldn't be in a nested layer
1402 // and shouldn't already have a restriction
1403 SkASSERT(fClipRestrictionSaveCount < 0 && fClipRestrictionRect.isEmpty());
1404
1405 if (fClipRestrictionSaveCount < 0 && !rect.isEmpty()) {
1406 fClipRestrictionRect = rect;
1407 fClipRestrictionSaveCount = this->getSaveCount();
1408
1409 // A non-empty clip restriction immediately applies an intersection op (ignoring the ctm).
1410 // so we have to resolve the save.
1411 this->checkForDeferredSave();
1412 AutoUpdateQRBounds aqr(this);
1413 // Use clipRegion() since that operates in canvas-space, whereas clipRect() would apply the
1414 // device's current transform first.
1415 this->topDevice()->clipRegion(SkRegion(rect), SkClipOp::kIntersect);
1416 }
1417}
#define SkASSERT(cond)
Definition: SkAssert.h:116
int getSaveCount() const
Definition: SkCanvas.cpp:431
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 {
1200 this->clear(SkColor4f::FromColor(color));
1201 }
void clear(SkColor color)
Definition: SkCanvas.h:1199
DlColor 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)
Definition: SkCanvas.cpp:1361
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)
Definition: SkCanvas.cpp:1456

◆ 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 1456 of file SkCanvas.cpp.

1456 {
1457 this->checkForDeferredSave();
1459
1460 if (!path.isInverseFillType() && fMCRec->fMatrix.asM33().rectStaysRect()) {
1461 SkRect r;
1462 if (path.isRect(&r)) {
1463 this->onClipRect(r, op, edgeStyle);
1464 return;
1465 }
1466 SkRRect rrect;
1467 if (path.isOval(&r)) {
1468 rrect.setOval(r);
1469 this->onClipRRect(rrect, op, edgeStyle);
1470 return;
1471 }
1472 if (path.isRRect(&rrect)) {
1473 this->onClipRRect(rrect, op, edgeStyle);
1474 return;
1475 }
1476 }
1477
1478 this->onClipPath(path, op, edgeStyle);
1479}
virtual void onClipRect(const SkRect &rect, SkClipOp op, ClipEdgeStyle edgeStyle)
Definition: SkCanvas.cpp:1370
virtual void onClipRRect(const SkRRect &rrect, SkClipOp op, ClipEdgeStyle edgeStyle)
Definition: SkCanvas.cpp:1449
virtual void onClipPath(const SkPath &path, SkClipOp op, ClipEdgeStyle edgeStyle)
Definition: SkCanvas.cpp:1481
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 1361 of file SkCanvas.cpp.

1361 {
1362 if (!rect.isFinite()) {
1363 return;
1364 }
1365 this->checkForDeferredSave();
1367 this->onClipRect(rect.makeSorted(), op, edgeStyle);
1368}
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 1510 of file SkCanvas.cpp.

1510 {
1511 this->checkForDeferredSave();
1512 this->onClipRegion(rgn, op);
1513}
virtual void onClipRegion(const SkRegion &deviceRgn, SkClipOp op)
Definition: SkCanvas.cpp:1515

◆ 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)
Definition: SkCanvas.cpp:1439

◆ 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 1439 of file SkCanvas.cpp.

1439 {
1440 this->checkForDeferredSave();
1442 if (rrect.isRect()) {
1443 this->onClipRect(rrect.getBounds(), op, edgeStyle);
1444 } else {
1445 this->onClipRRect(rrect, op, edgeStyle);
1446 }
1447}
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 1488 of file SkCanvas.cpp.

1488 {
1489 if (sh) {
1490 if (sh->isOpaque()) {
1491 if (op == SkClipOp::kIntersect) {
1492 // we don't occlude anything, so skip this call
1493 } else {
1495 // we occlude everything, so set the clip to empty
1496 this->clipRect({0,0,0,0});
1497 }
1498 } else {
1499 this->checkForDeferredSave();
1500 this->onClipShader(std::move(sh), op);
1501 }
1502 }
1503}
virtual void onClipShader(sk_sp< SkShader >, SkClipOp)
Definition: SkCanvas.cpp:1505
sh
Definition: run_sh.py:10

◆ concat() [1/2]

void SkCanvas::concat ( const SkM44 m)

Definition at line 1333 of file SkCanvas.cpp.

1333 {
1334 this->internalConcat44(m);
1335 // notify subclasses
1336 this->didConcat44(m);
1337}
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 1318 of file SkCanvas.cpp.

1318 {
1319 if (matrix.isIdentity()) {
1320 return;
1321 }
1322 this->concat(SkM44(matrix));
1323}
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
Definition: SkM44.h:150
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ didConcat44()

virtual void SkCanvas::didConcat44 ( const SkM44 )
inlineprotectedvirtual

Reimplemented in 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 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 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()
Definition: SkCanvas.cpp:1888

◆ 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)
Definition: SkCanvas.cpp:1824
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 1824 of file SkCanvas.cpp.

1824 {
1825 TRACE_EVENT0("skia", TRACE_FUNC);
1826 if (key) {
1827 this->onDrawAnnotation(rect, key, value);
1828 }
1829}
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
virtual void onDrawAnnotation(const SkRect &rect, const char key[], SkData *value)
Definition: SkCanvas.cpp:2615
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ 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 arc-vs-wedge
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.isWedge(), paint);
1491 }
void drawArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
Definition: SkCanvas.cpp:2728
const Paint & paint
Definition: color_source.cc:38
SkScalar fSweepAngle
Definition: SkArc.h:60
SkScalar fStartAngle
Definition: SkArc.h:58
SkRect fOval
Definition: SkArc.h:55
bool isWedge() const
Definition: SkArc.h:28

◆ 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 2728 of file SkCanvas.cpp.

2730 {
2731 TRACE_EVENT0("skia", TRACE_FUNC);
2732 if (oval.isEmpty() || !sweepAngle) {
2733 return;
2734 }
2735 this->onDrawArc(oval, startAngle, sweepAngle, useCenter, paint);
2736}
virtual void onDrawArc(const SkRect &rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
Definition: SkCanvas.cpp:2090
SkRect oval
Definition: SkRecords.h:249
SkScalar startAngle
Definition: SkRecords.h:250
SkScalar sweepAngle
Definition: SkRecords.h:251
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 1810 of file SkCanvas.cpp.

1813 {
1814 TRACE_EVENT0("skia", TRACE_FUNC);
1816 if (count <= 0) {
1817 return;
1818 }
1819 SkASSERT(atlas);
1820 SkASSERT(tex);
1821 this->onDrawAtlas2(atlas, xform, tex, colors, count, mode, sampling, cull, paint);
1822}
int count
Definition: FontMgrTest.cpp:50
#define RETURN_ON_NULL(ptr)
Definition: SkCanvas.cpp:74
virtual void onDrawAtlas2(const SkImage *, const SkRSXform[], const SkRect src[], const SkColor[], int count, SkBlendMode, const SkSamplingOptions &, const SkRect *cull, const SkPaint *)
Definition: SkCanvas.cpp:2593
sk_sp< const SkImage > atlas
Definition: SkRecords.h:331
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkSamplingOptions sampling
Definition: SkRecords.h:337
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228

◆ 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)
Definition: SkCanvas.cpp:2707
constexpr float x() const
Definition: SkPoint_impl.h:181

◆ 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 2707 of file SkCanvas.cpp.

2707 {
2708 if (radius < 0) {
2709 radius = 0;
2710 }
2711
2712 SkRect r;
2713 r.setLTRB(cx - radius, cy - radius, cx + radius, cy + radius);
2714 this->drawOval(r, paint);
2715}
void drawOval(const SkRect &oval, const SkPaint &paint)
Definition: SkCanvas.cpp:1698
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 2688 of file SkCanvas.cpp.

2688 {
2689 SkPaint paint;
2690 paint.setColor(c);
2691 paint.setBlendMode(mode);
2692 this->drawPaint(paint);
2693}
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668

◆ 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 2574 of file SkCanvas.cpp.

2574 {
2575#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
2576 TRACE_EVENT0("skia", TRACE_FUNC);
2577#endif
2579 if (matrix && matrix->isIdentity()) {
2580 matrix = nullptr;
2581 }
2582 this->onDrawDrawable(dr, matrix);
2583}
virtual void onDrawDrawable(SkDrawable *drawable, const SkMatrix *matrix)
Definition: SkCanvas.cpp:2585

◆ 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 2561 of file SkCanvas.cpp.

2561 {
2562#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
2563 TRACE_EVENT0("skia", TRACE_FUNC);
2564#endif
2566 if (x || y) {
2568 this->onDrawDrawable(dr, &matrix);
2569 } else {
2570 this->onDrawDrawable(dr, nullptr);
2571 }
2572}
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 1645 of file SkCanvas.cpp.

1646 {
1647 TRACE_EVENT0("skia", TRACE_FUNC);
1648 if (outer.isEmpty()) {
1649 return;
1650 }
1651 if (inner.isEmpty()) {
1652 this->drawRRect(outer, paint);
1653 return;
1654 }
1655
1656 // We don't have this method (yet), but technically this is what we should
1657 // be able to return ...
1658 // if (!outer.contains(inner))) {
1659 //
1660 // For now at least check for containment of bounds
1661 if (!outer.getBounds().contains(inner.getBounds())) {
1662 return;
1663 }
1664
1665 this->onDrawDRRect(outer, inner, paint);
1666}
virtual void onDrawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &paint)
Definition: SkCanvas.cpp:2132
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:1705
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 2446 of file SkCanvas.cpp.

2447 {
2448 if (count <= 0) { return; }
2449
2450 sktext::GlyphRun glyphRun {
2451 font,
2452 SkSpan(positions, count),
2457 };
2458
2459 sktext::GlyphRunList glyphRunList = fScratchGlyphRunBuilder->makeGlyphRunList(
2460 glyphRun, paint, origin);
2461 this->onDrawGlyphRunList(glyphRunList, paint);
2462}
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
virtual void onDrawGlyphRunList(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition: SkCanvas.cpp:2356
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 2464 of file SkCanvas.cpp.

2465 {
2466 if (count <= 0) { return; }
2467
2468 auto [positions, rotateScales] =
2469 fScratchGlyphRunBuilder->convertRSXForm(SkSpan(xforms, count));
2470
2471 sktext::GlyphRun glyphRun {
2472 font,
2473 positions,
2477 rotateScales
2478 };
2479 sktext::GlyphRunList glyphRunList = fScratchGlyphRunBuilder->makeGlyphRunList(
2480 glyphRun, paint, origin);
2481 this->onDrawGlyphRunList(glyphRunList, paint);
2482}
PODArray< SkRSXform > xforms
Definition: SkRecords.h:332

◆ 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 2320 of file SkCanvas.cpp.

2321 {
2322 TRACE_EVENT0("skia", TRACE_FUNC);
2324
2325 this->drawImageRect(image,
2326 /*src=*/SkRect::MakeWH(image->width(), image->height()),
2327 /*dst=*/SkRect::MakeXYWH(x, y, image->width(), image->height()),
2328 sampling,
2329 paint,
2331}
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
sk_sp< const SkImage > image
Definition: SkRecords.h:269
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 }
SkSamplingOptions(SkFilterMode::kLinear))

◆ 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)
Definition: SkCanvas.cpp:1786
dst
Definition: cp.py:12

◆ 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 1786 of file SkCanvas.cpp.

1787 {
1788 TRACE_EVENT0("skia", TRACE_FUNC);
1790 if (dst.isEmpty()) {
1791 return;
1792 }
1793
1795 Lattice latticePlusBounds = lattice;
1796 if (!latticePlusBounds.fBounds) {
1798 latticePlusBounds.fBounds = &bounds;
1799 }
1800
1801 SkPaint latticePaint = clean_paint_for_lattice(paint);
1802 if (SkLatticeIter::Valid(image->width(), image->height(), latticePlusBounds)) {
1803 this->onDrawImageLattice2(image, latticePlusBounds, dst, filter, &latticePaint);
1804 } else {
1805 this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst,
1806 SkSamplingOptions(filter), &latticePaint, kStrict_SrcRectConstraint);
1807 }
1808}
static SkPaint clean_paint_for_lattice(const SkPaint *paint)
Definition: SkCanvas.cpp:1759
virtual void onDrawImageLattice2(const SkImage *, const Lattice &, const SkRect &dst, SkFilterMode, const SkPaint *)
Definition: SkCanvas.cpp:2306
static bool Valid(int imageWidth, int imageHeight, const SkCanvas::Lattice &lattice)
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 1769 of file SkCanvas.cpp.

1770 {
1772
1773 const int xdivs[] = {center.fLeft, center.fRight};
1774 const int ydivs[] = {center.fTop, center.fBottom};
1775
1776 Lattice lat;
1777 lat.fXDivs = xdivs;
1778 lat.fYDivs = ydivs;
1779 lat.fRectTypes = nullptr;
1780 lat.fXCount = lat.fYCount = 2;
1781 lat.fBounds = nullptr;
1782 lat.fColors = nullptr;
1783 this->drawImageLattice(image, lat, dst, filter, paint);
1784}

◆ 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 2343 of file SkCanvas.cpp.

◆ 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 2333 of file SkCanvas.cpp.

2335 {
2337 if (!fillable(dst) || !fillable(src)) {
2338 return;
2339 }
2340 this->onDrawImageRect2(image, src, dst, sampling, paint, constraint);
2341}
static bool fillable(const SkRect &r)
Definition: SkCanvas.cpp:1753
virtual void onDrawImageRect2(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2204

◆ 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)
Definition: SkCanvas.cpp:1673
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)
Definition: SkCanvas.cpp:2700
constexpr float y() const
Definition: SkPoint_impl.h:187

◆ 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 2700 of file SkCanvas.cpp.

2700 {
2701 SkPoint pts[2];
2702 pts[0].set(x0, y0);
2703 pts[1].set(x1, y1);
2704 this->drawPoints(kLines_PointMode, 2, pts, paint);
2705}
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
void set(float x, float y)
Definition: SkPoint_impl.h:200

◆ 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 1739 of file SkCanvas.cpp.

1739 {
1740 TRACE_EVENT0("skia", TRACE_FUNC);
1741 if (!blender) {
1743 }
1744 this->onDrawMesh(mesh, std::move(blender), paint);
1745}
@ kModulate
r = s*d
static sk_sp< SkBlender > Mode(SkBlendMode mode)
virtual void onDrawMesh(const SkMesh &, sk_sp< SkBlender >, const SkPaint &)
Definition: SkCanvas.cpp:2521

◆ 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 1698 of file SkCanvas.cpp.

1698 {
1699 TRACE_EVENT0("skia", TRACE_FUNC);
1700 // To avoid redundant logic in our culling code and various backends, we always sort rects
1701 // before passing them along.
1702 this->onDrawOval(r.makeSorted(), paint);
1703}
virtual void onDrawOval(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:2075

◆ 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 1668 of file SkCanvas.cpp.

1668 {
1669 TRACE_EVENT0("skia", TRACE_FUNC);
1670 this->onDrawPaint(paint);
1671}
virtual void onDrawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1894

◆ 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 2529 of file SkCanvas.cpp.

2531 {
2532 TRACE_EVENT0("skia", TRACE_FUNC);
2533 if (nullptr == cubics) {
2534 return;
2535 }
2536
2537 this->onDrawPatch(cubics, colors, texCoords, bmode, paint);
2538}
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode mode, const SkPaint &paint)
Definition: SkCanvas.cpp:2540

◆ 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 1747 of file SkCanvas.cpp.

1747 {
1748 TRACE_EVENT0("skia", TRACE_FUNC);
1749 this->onDrawPath(path, paint);
1750}
virtual void onDrawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:2144

◆ 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 2747 of file SkCanvas.cpp.

2747 {
2748 TRACE_EVENT0("skia", TRACE_FUNC);
2750
2751 if (matrix && matrix->isIdentity()) {
2752 matrix = nullptr;
2753 }
2756 picture->playback(this);
2757 } else {
2758 this->onDrawPicture(picture, matrix, paint);
2759 }
2760}
constexpr int kMaxPictureOpsToUnrollInsteadOfRef
Definition: SkCanvasPriv.h:108
virtual void onDrawPicture(const SkPicture *picture, const SkMatrix *matrix, const SkPaint *paint)
Definition: SkCanvas.cpp:2762
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)
Definition: SkCanvas.cpp:2695

◆ 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 2695 of file SkCanvas.cpp.

2695 {
2696 const SkPoint pt = { x, y };
2697 this->drawPoints(kPoints_PointMode, 1, &pt, paint);
2698}

◆ 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 1710 of file SkCanvas.cpp.

1710 {
1711 TRACE_EVENT0("skia", TRACE_FUNC);
1712 this->onDrawPoints(mode, count, pts, paint);
1713}
virtual void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1911

◆ 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 1673 of file SkCanvas.cpp.

1673 {
1674 TRACE_EVENT0("skia", TRACE_FUNC);
1675 // To avoid redundant logic in our culling code and various backends, we always sort rects
1676 // before passing them along.
1677 this->onDrawRect(r.makeSorted(), paint);
1678}
virtual void onDrawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:2004

◆ 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 1685 of file SkCanvas.cpp.

1685 {
1686 TRACE_EVENT0("skia", TRACE_FUNC);
1687 if (region.isEmpty()) {
1688 return;
1689 }
1690
1691 if (region.isRect()) {
1692 return this->drawIRect(region.getBounds(), paint);
1693 }
1694
1695 this->onDrawRegion(region, paint);
1696}
virtual void onDrawRegion(const SkRegion &region, const SkPaint &paint)
Definition: SkCanvas.cpp:2019
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 2717 of file SkCanvas.cpp.

2718 {
2719 if (rx > 0 && ry > 0) {
2720 SkRRect rrect;
2721 rrect.setRectXY(r, rx, ry);
2722 this->drawRRect(rrect, paint);
2723 } else {
2724 this->drawRect(r, paint);
2725 }
2726}
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 1705 of file SkCanvas.cpp.

1705 {
1706 TRACE_EVENT0("skia", TRACE_FUNC);
1707 this->onDrawRRect(rrect, paint);
1708}
virtual void onDrawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:2105

◆ 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 2413 of file SkCanvas.cpp.

2414 {
2415 TRACE_EVENT0("skia", TRACE_FUNC);
2416 if (byteLength) {
2417 sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength));
2418 const sktext::GlyphRunList& glyphRunList =
2419 fScratchGlyphRunBuilder->textToGlyphRunList(
2420 font, paint, text, byteLength, {x, y}, encoding);
2421 if (!glyphRunList.empty()) {
2422 this->onDrawGlyphRunList(glyphRunList, paint);
2423 }
2424 }
2425}
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)
Definition: SkCanvas.cpp:2413

◆ 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)
Definition: SkCanvas.cpp:2484

◆ 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 2484 of file SkCanvas.cpp.

2485 {
2486 TRACE_EVENT0("skia", TRACE_FUNC);
2487 RETURN_ON_NULL(blob);
2489
2490 // Overflow if more than 2^21 glyphs stopping a buffer overflow latter in the stack.
2491 // See chromium:1080481
2492 // TODO: can consider unrolling a few at a time if this limit becomes a problem.
2493 int totalGlyphCount = 0;
2494 constexpr int kMaxGlyphCount = 1 << 21;
2495 SkTextBlob::Iter i(*blob);
2497 while (i.next(&r)) {
2498 int glyphsLeft = kMaxGlyphCount - totalGlyphCount;
2499 RETURN_ON_FALSE(r.fGlyphCount <= glyphsLeft);
2500 totalGlyphCount += r.fGlyphCount;
2501 }
2502
2503 this->onDrawTextBlob(blob, x, y, paint);
2504}
constexpr int kMaxGlyphCount
Definition: FuzzCanvas.cpp:865
#define RETURN_ON_FALSE(pred)
Definition: SkCanvas.cpp:75
virtual void onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2350
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 1715 of file SkCanvas.cpp.

1716 {
1717 this->drawVertices(vertices.get(), mode, paint);
1718}
void drawVertices(const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
Definition: SkCanvas.cpp:1720

◆ 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 1720 of file SkCanvas.cpp.

1720 {
1721 TRACE_EVENT0("skia", TRACE_FUNC);
1722 RETURN_ON_NULL(vertices);
1723
1724 // We expect fans to be converted to triangles when building or deserializing SkVertices.
1726
1727#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
1728 // Preserve legacy behavior for Android: ignore the SkShader if there are no texCoords present
1729 if (paint.getShader() && !vertices->priv().hasTexCoords()) {
1730 SkPaint noShaderPaint(paint);
1731 noShaderPaint.setShader(nullptr);
1732 this->onDrawVerticesObject(vertices, mode, noShaderPaint);
1733 return;
1734 }
1735#endif
1736 this->onDrawVerticesObject(vertices, mode, paint);
1737}
virtual void onDrawVerticesObject(const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
Definition: SkCanvas.cpp:2506
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 1853 of file SkCanvas.cpp.

1858 {
1859 TRACE_EVENT0("skia", TRACE_FUNC);
1860 // Route single, rectangular quads to drawImageRect() to take advantage of image filter
1861 // optimizations that avoid a layer.
1862 if (paint && paint->getImageFilter() && cnt == 1) {
1863 const auto& entry = imageSet[0];
1864 // If the preViewMatrix is skipped or a positive-scale + translate matrix, we can apply it
1865 // to the entry's dstRect w/o changing output behavior.
1866 const bool canMapDstRect = entry.fMatrixIndex < 0 ||
1867 (preViewMatrices[entry.fMatrixIndex].isScaleTranslate() &&
1868 preViewMatrices[entry.fMatrixIndex].getScaleX() > 0.f &&
1869 preViewMatrices[entry.fMatrixIndex].getScaleY() > 0.f);
1870 if (!entry.fHasClip && canMapDstRect) {
1871 SkRect dst = entry.fDstRect;
1872 if (entry.fMatrixIndex >= 0) {
1873 preViewMatrices[entry.fMatrixIndex].mapRect(&dst);
1874 }
1875 this->drawImageRect(entry.fImage.get(), entry.fSrcRect, dst,
1876 sampling, paint, constraint);
1877 return;
1878 } // Else the entry is doing more than can be represented by drawImageRect
1879 } // Else no filter, or many entries that should be filtered together
1881 constraint);
1882}
virtual void onDrawEdgeAAImageSet2(const ImageSetEntry imageSet[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2638
PODArray< SkPoint > dstClips
Definition: SkRecords.h:364
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 1845 of file SkCanvas.cpp.

1847 {
1848 TRACE_EVENT0("skia", TRACE_FUNC);
1849 // Make sure the rect is sorted before passing it along
1850 this->onDrawEdgeAAQuad(rect.makeSorted(), clip, aaFlags, color, mode);
1851}
virtual void onDrawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
Definition: SkCanvas.cpp:2623

◆ 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)
Definition: SkCanvas.cpp:1845

◆ 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 369 of file SkCanvas.cpp.

369 {
370 return this->rootDevice()->imageInfo().dimensions();
371}
const SkImageInfo & imageInfo() const
Definition: SkDevice.h:117
SkISize dimensions() const
Definition: SkImageInfo.h:421

◆ 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 1218 of file SkCanvas.cpp.

1218 {
1219 SkSurfaceProps props;
1220 this->onGetProps(&props, /*top=*/false);
1221 return props;
1222}
virtual bool onGetProps(SkSurfaceProps *props, bool top) const
Definition: SkCanvas.cpp:1230

◆ 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 1607 of file SkCanvas.cpp.

1607 {
1608 return this->computeDeviceClipBounds(/*outsetForAA=*/false).roundOut();
1609}
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
Definition: SkCanvas.cpp:1607

◆ 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 1586 of file SkCanvas.cpp.

1586 {
1587 SkIRect ibounds = this->getDeviceClipBounds();
1588 if (ibounds.isEmpty()) {
1589 return SkRect::MakeEmpty();
1590 }
1591
1592 SkMatrix inverse;
1593 // if we can't invert the CTM, we can't return local clip bounds
1594 if (!fMCRec->fMatrix.asM33().invert(&inverse)) {
1595 return SkRect::MakeEmpty();
1596 }
1597
1598 SkRect bounds;
1599 // adjust it outwards in case we are antialiasing
1600 const int margin = 1;
1601
1602 SkRect r = SkRect::Make(ibounds.makeOutset(margin, margin));
1603 inverse.mapRect(&bounds, r);
1604 return bounds;
1605}
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
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
Definition: SkCanvas.cpp:1586

◆ 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 1633 of file SkCanvas.cpp.

1633 {
1634 return fMCRec->fMatrix;
1635}

◆ 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
Definition: SkCanvas.cpp:1633
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 1214 of file SkCanvas.cpp.

1214 {
1215 return this->onGetProps(props, /*top=*/false);
1216}

◆ 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 431 of file SkCanvas.cpp.

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

◆ getSaveLayerStrategy()

virtual SaveLayerStrategy SkCanvas::getSaveLayerStrategy ( const SaveLayerRec )
inlineprotectedvirtual

Reimplemented in SkNWayCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkNoDrawCanvas, and SaveCountingCanvas.

Definition at line 2270 of file SkCanvas.h.

2270 {
2272 }

◆ 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 365 of file SkCanvas.cpp.

365 {
366 return fSurfaceBase;
367}

◆ 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 1224 of file SkCanvas.cpp.

1224 {
1225 SkSurfaceProps props;
1226 this->onGetProps(&props, /*top=*/true);
1227 return props;
1228}

◆ 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 1629 of file SkCanvas.cpp.

1629 {
1630 return fMCRec->fMatrix.asM33();
1631}

◆ 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 1206 of file SkCanvas.cpp.

1206 {
1207 return this->onImageInfo();
1208}
virtual SkImageInfo onImageInfo() const
Definition: SkCanvas.cpp:1210

◆ internal_private_asPaintFilterCanvas()

virtual SkPaintFilterCanvas * SkCanvas::internal_private_asPaintFilterCanvas ( ) const
inlineprivatevirtual

Definition at line 2610 of file SkCanvas.h.

2610{ 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 1549 of file SkCanvas.cpp.

1549 {
1550 return this->topDevice()->isClipEmpty();
1551}
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 1553 of file SkCanvas.cpp.

1553 {
1554 return this->topDevice()->isClipRect();
1555}
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 2801 of file SkCanvas.cpp.

2802 {
2803 if (!SkSurfaceValidateRasterInfo(info, rowBytes)) {
2804 return nullptr;
2805 }
2806
2808 if (!bitmap.installPixels(info, pixels, rowBytes)) {
2809 return nullptr;
2810 }
2811
2812 return props ?
2813 std::make_unique<SkCanvas>(bitmap, *props) :
2814 std::make_unique<SkCanvas>(bitmap);
2815}
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)
Definition: SkCanvas.cpp:2801
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 1195 of file SkCanvas.cpp.

1195 {
1196 if (nullptr == props) {
1197 props = &fProps;
1198 }
1199 return this->onNewSurface(info, *props);
1200}
virtual sk_sp< SkSurface > onNewSurface(const SkImageInfo &info, const SkSurfaceProps &props)
Definition: SkCanvas.cpp:1202

◆ onAccessTopLayerPixels()

bool SkCanvas::onAccessTopLayerPixels ( SkPixmap pixmap)
protectedvirtual

Reimplemented in SkPaintFilterCanvas.

Definition at line 1272 of file SkCanvas.cpp.

1272 {
1273 return this->topDevice()->accessPixels(pmap);
1274}
bool accessPixels(SkPixmap *pmap)
Definition: SkDevice.cpp:383

◆ onClipPath()

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

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

Definition at line 1481 of file SkCanvas.cpp.

1481 {
1482 bool isAA = kSoft_ClipEdgeStyle == edgeStyle;
1483
1484 AutoUpdateQRBounds aqr(this);
1485 this->topDevice()->clipPath(path, op, isAA);
1486}
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 SkNWayCanvas, SkPictureRecord, SkCanvasStack, DebugCanvas, ClipCountingCanvas, and SkRecorder.

Definition at line 1370 of file SkCanvas.cpp.

1370 {
1371 SkASSERT(rect.isSorted());
1372 const bool isAA = kSoft_ClipEdgeStyle == edgeStyle;
1373
1374 AutoUpdateQRBounds aqr(this);
1375 this->topDevice()->clipRect(rect, op, isAA);
1376}
virtual void clipRect(const SkRect &rect, SkClipOp op, bool aa)=0

◆ onClipRegion()

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

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

Definition at line 1515 of file SkCanvas.cpp.

1515 {
1516 AutoUpdateQRBounds aqr(this);
1517 this->topDevice()->clipRegion(rgn, op);
1518}

◆ onClipRRect()

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

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

Definition at line 1449 of file SkCanvas.cpp.

1449 {
1450 bool isAA = kSoft_ClipEdgeStyle == edgeStyle;
1451
1452 AutoUpdateQRBounds aqr(this);
1453 this->topDevice()->clipRRect(rrect, op, isAA);
1454}
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 1505 of file SkCanvas.cpp.

1505 {
1506 AutoUpdateQRBounds aqr(this);
1507 this->topDevice()->clipShader(sh, op);
1508}
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 2379 of file SkCanvas.cpp.

2380 {
2381 SkRect bounds = glyphRunList.sourceBoundsWithOrigin();
2382 if (bounds.isEmpty() || !bounds.isFinite() || paint.nothingToDraw()) {
2383 return nullptr;
2384 }
2385 // See comment in onDrawGlyphRunList()
2386 auto layer = this->aboutToDraw(paint, &bounds, PredrawFlags::kSkipMaskFilterAutoLayer);
2387 if (layer) {
2388 return this->topDevice()->convertGlyphRunListToSlug(glyphRunList, layer->paint());
2389 }
2390 return nullptr;
2391}
virtual sk_sp< sktext::gpu::Slug > convertGlyphRunListToSlug(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition: SkDevice.cpp:483
SkRect sourceBoundsWithOrigin() const
Definition: GlyphRun.h:116

◆ onDiscard()

void SkCanvas::onDiscard ( )
protectedvirtual

Definition at line 1888 of file SkCanvas.cpp.

1888 {
1889 if (fSurfaceBase) {
1891 }
1892}
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 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, SkNoDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkPaintFilterCanvas, TestAnnotationCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2615 of file SkCanvas.cpp.

2615 {
2616 SkASSERT(key);
2617
2618 if (this->predrawNotify()) {
2619 this->topDevice()->drawAnnotation(rect, key, value);
2620 }
2621}
virtual void drawAnnotation(const SkRect &, const char[], SkData *)
Definition: SkDevice.h:399

◆ onDrawArc()

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

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

Definition at line 2090 of file SkCanvas.cpp.

2092 {
2094 if (this->internalQuickReject(oval, paint)) {
2095 return;
2096 }
2097
2098 auto layer = this->aboutToDraw(paint, &oval);
2099 if (layer) {
2100 this->topDevice()->drawArc(SkArc::Make(oval, startAngle, sweepAngle, useCenter),
2101 layer->paint());
2102 }
2103}
virtual void drawArc(const SkArc &arc, const SkPaint &paint)
Definition: SkDevice.cpp:134
static SkArc Make(const SkRect &oval, SkScalar startAngleDegrees, SkScalar sweepAngleDegrees, Type type)
Definition: SkArc.h:38
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 SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, and MSKPPlayer::CmdRecordCanvas.

Definition at line 2593 of file SkCanvas.cpp.

2596 {
2597 // drawAtlas is a combination of drawVertices and drawImage...
2599 realPaint.setShader(atlas->makeShader(sampling));
2600
2601 if (cull && this->internalQuickReject(*cull, realPaint)) {
2602 return;
2603 }
2604
2605 // drawAtlas should not have mask filters on its paint, so we don't need to worry about
2606 // converting its "drawImage" behavior into the paint to work with the auto-mask-filter system.
2607 SkASSERT(!realPaint.getMaskFilter());
2608 auto layer = this->aboutToDraw(realPaint);
2609 if (layer) {
2610 this->topDevice()->drawAtlas(xform, tex, colors, count, SkBlender::Mode(bmode),
2611 layer->paint());
2612 }
2613}
static SkPaint clean_paint_for_drawImage(const SkPaint *paint)
Definition: SkCanvas.cpp:2165
static SkPaint clean_paint_for_drawVertices(SkPaint paint)
Definition: SkCanvas.cpp:2177
virtual void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &)
Definition: SkDevice.cpp:203
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)

◆ onDrawBehind()

void SkCanvas::onDrawBehind ( const SkPaint paint)
protectedvirtual

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

Definition at line 2031 of file SkCanvas.cpp.

2031 {
2032 SkDevice* dev = this->topDevice();
2033 if (!dev) {
2034 return;
2035 }
2036
2039 for (;;) {
2040 const MCRec* rec = (const MCRec*)iter.prev();
2041 if (!rec) {
2042 return; // no backimages, so nothing to draw
2043 }
2044 if (rec->fBackImage) {
2045 // drawBehind should only have been called when the saveBehind record is active;
2046 // if this fails, it means a real saveLayer was made w/o being restored first.
2047 SkASSERT(dev == rec->fDevice);
2048 bounds = SkIRect::MakeXYWH(rec->fBackImage->fLoc.fX, rec->fBackImage->fLoc.fY,
2049 rec->fBackImage->fImage->width(),
2050 rec->fBackImage->fImage->height());
2051 break;
2052 }
2053 }
2054
2055 // The backimage location (and thus bounds) were defined in the device's space, so mark it
2056 // as a clip. We use a clip instead of just drawing a rect in case the paint has an image
2057 // filter on it (which is applied before any auto-layer so the filter is clipped).
2058 dev->pushClipStack();
2059 {
2060 // We also have to temporarily whack the device matrix since clipRegion is affected by the
2061 // global-to-device matrix and clipRect is affected by the local-to-device.
2063 dev->clipRect(SkRect::Make(bounds), SkClipOp::kIntersect, /* aa */ false);
2064 // ~adtr will reset the local-to-device matrix so that drawPaint() shades correctly.
2065 }
2066
2067 auto layer = this->aboutToDraw(paint);
2068 if (layer) {
2069 this->topDevice()->drawPaint(layer->paint());
2070 }
2071
2072 dev->popClipStack();
2073}
@ 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()
Definition: SkMatrix.cpp:1544
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 SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2585 of file SkCanvas.cpp.

2585 {
2586 // drawable bounds are no longer reliable (e.g. android displaylist)
2587 // so don't use them for quick-reject
2588 if (this->predrawNotify()) {
2589 this->topDevice()->drawDrawable(this, dr, matrix);
2590 }
2591}
virtual void drawDrawable(SkCanvas *, SkDrawable *, const SkMatrix *)
Definition: SkDevice.cpp:298

◆ onDrawDRRect()

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

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

Definition at line 2132 of file SkCanvas.cpp.

2132 {
2133 const SkRect& bounds = outer.getBounds();
2134 if (this->internalQuickReject(bounds, paint)) {
2135 return;
2136 }
2137
2138 auto layer = this->aboutToDraw(paint, &bounds);
2139 if (layer) {
2140 this->topDevice()->drawDRRect(outer, inner, layer->paint());
2141 }
2142}
virtual void drawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &)
Definition: SkDevice.cpp:141

◆ 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, SkOverdrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, and SkNoDrawCanvas.

Definition at line 2638 of file SkCanvas.cpp.

2641 {
2642 if (count <= 0) {
2643 // Nothing to draw
2644 return;
2645 }
2646
2648 SkSamplingOptions realSampling = clean_sampling_for_constraint(sampling, constraint);
2649
2650 // We could calculate the set's dstRect union to always check quickReject(), but we can't reject
2651 // individual entries and Chromium's occlusion culling already makes it likely that at least one
2652 // entry will be visible. So, we only calculate the draw bounds when it's trivial (count == 1),
2653 // or we need it for the autolooper (since it greatly improves image filter perf).
2654 bool needsAutoLayer = SkToBool(realPaint.getImageFilter());
2655 bool setBoundsValid = count == 1 || needsAutoLayer;
2656 SkRect setBounds = imageSet[0].fDstRect;
2657 if (imageSet[0].fMatrixIndex >= 0) {
2658 // Account for the per-entry transform that is applied prior to the CTM when drawing
2659 preViewMatrices[imageSet[0].fMatrixIndex].mapRect(&setBounds);
2660 }
2661 if (needsAutoLayer) {
2662 for (int i = 1; i < count; ++i) {
2663 SkRect entryBounds = imageSet[i].fDstRect;
2664 if (imageSet[i].fMatrixIndex >= 0) {
2665 preViewMatrices[imageSet[i].fMatrixIndex].mapRect(&entryBounds);
2666 }
2667 setBounds.joinPossiblyEmptyRect(entryBounds);
2668 }
2669 }
2670
2671 // If we happen to have the draw bounds, though, might as well check quickReject().
2672 if (setBoundsValid && this->internalQuickReject(setBounds, realPaint)) {
2673 return;
2674 }
2675
2676 auto layer = this->aboutToDraw(realPaint, setBoundsValid ? &setBounds : nullptr);
2677 if (layer) {
2678 this->topDevice()->drawEdgeAAImageSet(imageSet, count, dstClips, preViewMatrices,
2679 realSampling, layer->paint(), constraint);
2680 }
2681}
static SkSamplingOptions clean_sampling_for_constraint(const SkSamplingOptions &sampling, SkCanvas::SrcRectConstraint constraint)
Definition: SkCanvas.cpp:2190
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:253
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, SkOverdrawCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2623 of file SkCanvas.cpp.

2624 {
2625 SkASSERT(r.isSorted());
2626
2628 paint.setBlendMode(mode);
2629 if (this->internalQuickReject(r, paint)) {
2630 return;
2631 }
2632
2633 if (this->predrawNotify()) {
2634 this->topDevice()->drawEdgeAAQuad(r, clip, edgeAA, color, mode);
2635 }
2636}
virtual void drawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
Definition: SkDevice.cpp:236

◆ 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 2356 of file SkCanvas.cpp.

2356 {
2357 SkRect bounds = glyphRunList.sourceBoundsWithOrigin();
2358 if (this->internalQuickReject(bounds, paint)) {
2359 return;
2360 }
2361
2362 // Text attempts to apply any SkMaskFilter internally and save the blurred masks in the
2363 // strike cache; if a glyph must be drawn as a path or drawable, SkDevice routes back to
2364 // this SkCanvas to retry, which will go through a function that does *not* skip the mask
2365 // filter layer.
2366 auto layer = this->aboutToDraw(paint, &bounds, PredrawFlags::kSkipMaskFilterAutoLayer);
2367 if (layer) {
2368 this->topDevice()->drawGlyphRunList(this, glyphRunList, layer->paint());
2369 }
2370}
void drawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition: SkDevice.cpp:426

◆ onDrawImage2()

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

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

Definition at line 2185 of file SkCanvas.cpp.

2186 {
2188}
#define SkUNREACHABLE
Definition: SkAssert.h:135

◆ onDrawImageLattice2()

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

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

Definition at line 2306 of file SkCanvas.cpp.

2307 {
2309
2310 if (this->internalQuickReject(dst, realPaint)) {
2311 return;
2312 }
2313
2314 auto layer = this->aboutToDraw(realPaint, &dst);
2315 if (layer) {
2316 this->topDevice()->drawImageLattice(image, lattice, dst, filter, layer->paint());
2317 }
2318}
virtual void drawImageLattice(const SkImage *, const SkCanvas::Lattice &, const SkRect &dst, SkFilterMode, const SkPaint &)
Definition: SkDevice.cpp:163

◆ 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, and MSKPPlayer::CmdRecordCanvas.

Definition at line 2204 of file SkCanvas.cpp.

2206 {
2208 SkSamplingOptions realSampling = clean_sampling_for_constraint(sampling, constraint);
2209
2210 if (this->internalQuickReject(dst, realPaint)) {
2211 return;
2212 }
2213
2214 if (this->topDevice()->shouldDrawAsTiledImageRect()) {
2215 if (this->topDevice()->drawAsTiledImageRect(
2216 this, image, &src, dst, realSampling, realPaint, constraint)) {
2217 return;
2218 }
2219 }
2220
2221 // drawImageRect()'s behavior is modified by the presence of an image filter, a mask filter, a
2222 // color filter, the paint's alpha, the paint's blender, and--when it's an alpha-only image--
2223 // the paint's color or shader. When there's an image filter, the paint's blender is applied to
2224 // the result of the image filter function, but every other aspect would influence the source
2225 // image that's then rendered with src-over blending into a transparent temporary layer.
2226 //
2227 // However, skif::FilterResult can apply the paint alpha and any color filter often without
2228 // requiring a layer, and src-over blending onto a transparent dst is a no-op, so we can use the
2229 // input image directly as the source for filtering. When the image is alpha-only and must be
2230 // colorized, or when a mask filter would change the coverage we skip this optimization for
2231 // simplicity since *somehow* embedding colorization or mask blurring into the filter graph
2232 // would likely be equivalent to using the existing AutoLayerForImageFilter functionality.
2233 if (realPaint.getImageFilter() && !image->isAlphaOnly() && !realPaint.getMaskFilter()) {
2234 SkDevice* device = this->topDevice();
2235
2236 skif::ParameterSpace<SkRect> imageBounds{dst};
2237 skif::DeviceSpace<SkIRect> outputBounds{device->devClipBounds()};
2238 FilterToSpan filterAsSpan(realPaint.getImageFilter());
2239 auto mappingAndBounds = get_layer_mapping_and_bounds(filterAsSpan,
2240 device->localToDevice(),
2241 outputBounds,
2242 imageBounds);
2243 if (!mappingAndBounds) {
2244 return;
2245 }
2246 if (!this->predrawNotify()) {
2247 return;
2248 }
2249
2250 // Start out with an empty source image, to be replaced with the converted 'image', and a
2251 // desired output equal to the calculated initial source layer bounds, which accounts for
2252 // how the image filters will access 'image' (possibly different than just 'outputBounds').
2253 auto backend = device->createImageFilteringBackend(
2254 device->surfaceProps(),
2255 image_filter_color_type(device->imageInfo().colorInfo()));
2256 auto [mapping, srcBounds] = *mappingAndBounds;
2258 skif::Context ctx{std::move(backend),
2259 mapping,
2260 srcBounds,
2262 device->imageInfo().colorSpace(),
2263 &stats};
2264
2266 ctx, sk_ref_sp(image), src, imageBounds, sampling);
2267 // Apply effects that are normally processed on the draw *before* any layer/image filter.
2268 source = apply_alpha_and_colorfilter(ctx, source, realPaint);
2269
2270 // Evaluate the image filter, with a context pointing to the source created directly from
2271 // 'image' (which will not require intermediate renderpasses when 'src' is integer aligned).
2272 // and a desired output matching the device clip bounds.
2273 ctx = ctx.withNewDesiredOutput(mapping.deviceToLayer(outputBounds))
2274 .withNewSource(source);
2275 auto result = as_IFB(realPaint.getImageFilter())->filterImage(ctx);
2276 result.draw(ctx, device, realPaint.getBlender());
2277 stats.reportStats();
2278 return;
2279 }
2280
2281 // When there's a alpha-only image that must be colorized or a mask filter to apply, go through
2282 // the regular auto-layer-for-imagefilter process
2283 if (realPaint.getMaskFilter() && this->topDevice()->useDrawCoverageMaskForMaskFilters()) {
2284 // Route mask-filtered drawImages to drawRect() to use the auto-layer for mask filters,
2285 // which require all shading to be encoded in the paint.
2287 image, sampling, src, dst, constraint == kStrict_SrcRectConstraint, &realPaint);
2288 if (drawDst.isEmpty()) {
2289 return;
2290 } else {
2291 this->drawRect(drawDst, realPaint);
2292 return;
2293 }
2294 }
2295
2296 auto layer = this->aboutToDraw(realPaint, &dst,
2297 PredrawFlags::kCheckForOverwrite |
2298 (image->isOpaque() ? PredrawFlags::kOpaqueShaderOverride
2299 : PredrawFlags::kNonOpaqueShaderOverride));
2300 if (layer) {
2301 this->topDevice()->drawImageRect(image, &src, dst, realSampling, layer->paint(),
2302 constraint);
2303 }
2304}
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:568
static skif::FilterResult apply_alpha_and_colorfilter(const skif::Context &ctx, const skif::FilterResult &image, const SkPaint &paint)
Definition: SkCanvas.cpp:681
static SkColorType image_filter_color_type(const SkColorInfo &dstInfo)
Definition: SkCanvas.cpp:670
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
virtual void drawImageRect(const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)=0
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
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
dictionary 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 2521 of file SkCanvas.cpp.

2521 {
2523 auto layer = this->aboutToDraw(simplePaint, nullptr);
2524 if (layer) {
2525 this->topDevice()->drawMesh(mesh, std::move(blender), paint);
2526 }
2527}
virtual void drawMesh(const SkMesh &mesh, sk_sp< SkBlender >, const SkPaint &)=0
SkMesh mesh
Definition: SkRecords.h:345

◆ onDrawOval()

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

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

Definition at line 2075 of file SkCanvas.cpp.

2075 {
2077 if (this->internalQuickReject(oval, paint)) {
2078 return;
2079 }
2080
2081 // Returns a layer if a blurred draw is not applicable or was unsuccessful.
2082 std::optional<AutoLayerForImageFilter> layer =
2083 this->attemptBlurredRRectDraw(SkRRect::MakeOval(oval), paint, PredrawFlags::kNone);
2084
2085 if (layer) {
2086 this->topDevice()->drawOval(oval, layer->paint());
2087 }
2088}
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 2540 of file SkCanvas.cpp.

2542 {
2543 // drawPatch has the same behavior restrictions as drawVertices
2545
2546 // Since a patch is always within the convex hull of the control points, we discard it when its
2547 // bounding rectangle is completely outside the current clip.
2548 SkRect bounds;
2549 bounds.setBounds(cubics, SkPatchUtils::kNumCtrlPts);
2550 if (this->internalQuickReject(bounds, simplePaint)) {
2551 return;
2552 }
2553
2554 auto layer = this->aboutToDraw(simplePaint, &bounds);
2555 if (layer) {
2556 this->topDevice()->drawPatch(cubics, colors, texCoords, SkBlender::Mode(bmode),
2557 layer->paint());
2558 }
2559}
virtual void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], sk_sp< SkBlender >, const SkPaint &paint)
Definition: SkDevice.cpp:152

◆ onDrawPath()

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

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

Definition at line 2144 of file SkCanvas.cpp.

2144 {
2145 if (!path.isFinite()) {
2146 return;
2147 }
2148
2149 const SkRect& pathBounds = path.getBounds();
2150 if (!path.isInverseFillType() && this->internalQuickReject(pathBounds, paint)) {
2151 return;
2152 }
2153 if (path.isInverseFillType() && pathBounds.width() <= 0 && pathBounds.height() <= 0) {
2154 this->internalDrawPaint(paint);
2155 return;
2156 }
2157
2158 auto layer = this->aboutToDraw(paint, path.isInverseFillType() ? nullptr : &pathBounds);
2159 if (layer) {
2160 this->topDevice()->drawPath(path, layer->paint());
2161 }
2162}
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 SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkOverdrawCanvas, SkNoDrawCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 1911 of file SkCanvas.cpp.

1912 {
1913 if ((long)count <= 0 || paint.nothingToDraw()) {
1914 return;
1915 }
1916 SkASSERT(pts != nullptr);
1917
1918 SkRect bounds;
1919 // Compute bounds from points (common for drawing a single line)
1920 if (count == 2) {
1921 bounds.set(pts[0], pts[1]);
1922 } else {
1923 bounds.setBounds(pts, SkToInt(count));
1924 }
1925
1926 // Enforce paint style matches implicit behavior of drawPoints
1927 SkPaint strokePaint = paint;
1928 strokePaint.setStyle(SkPaint::kStroke_Style);
1929 if (this->internalQuickReject(bounds, strokePaint)) {
1930 return;
1931 }
1932
1933 auto layer = this->aboutToDraw(strokePaint, &bounds);
1934 if (layer) {
1935 this->topDevice()->drawPoints(mode, count, pts, layer->paint());
1936 }
1937}
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 SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2004 of file SkCanvas.cpp.

2004 {
2005 SkASSERT(r.isSorted());
2006 if (this->internalQuickReject(r, paint)) {
2007 return;
2008 }
2009
2010 // Returns a layer if a blurred draw is not applicable or was unsuccessful.
2011 std::optional<AutoLayerForImageFilter> layer = this->attemptBlurredRRectDraw(
2012 SkRRect::MakeRect(r), paint, PredrawFlags::kCheckForOverwrite);
2013
2014 if (layer) {
2015 this->topDevice()->drawRect(r, layer->paint());
2016 }
2017}
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 SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, DebugCanvas, MSKPPlayer::CmdRecordCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, and SkCanvasVirtualEnforcer< SkNWayCanvas >.

Definition at line 2019 of file SkCanvas.cpp.

2019 {
2021 if (this->internalQuickReject(bounds, paint)) {
2022 return;
2023 }
2024
2025 auto layer = this->aboutToDraw(paint, &bounds);
2026 if (layer) {
2027 this->topDevice()->drawRegion(region, layer->paint());
2028 }
2029}
virtual void drawRegion(const SkRegion &r, const SkPaint &paint)
Definition: SkDevice.cpp:113

◆ onDrawRRect()

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

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

Definition at line 2105 of file SkCanvas.cpp.

2105 {
2106 const SkRect& bounds = rrect.getBounds();
2107
2108 // Delegating to simpler draw operations
2109 if (rrect.isRect()) {
2110 // call the non-virtual version
2111 this->SkCanvas::drawRect(bounds, paint);
2112 return;
2113 } else if (rrect.isOval()) {
2114 // call the non-virtual version
2115 this->SkCanvas::drawOval(bounds, paint);
2116 return;
2117 }
2118
2119 if (this->internalQuickReject(bounds, paint)) {
2120 return;
2121 }
2122
2123 // Returns a layer if a blurred draw is not applicable or was unsuccessful.
2124 std::optional<AutoLayerForImageFilter> layer =
2125 this->attemptBlurredRRectDraw(rrect, paint, PredrawFlags::kNone);
2126
2127 if (layer) {
2128 this->topDevice()->drawRRect(rrect, layer->paint());
2129 }
2130}
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 SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPictureRecord, SkRecorder, DebugCanvas, SkCanvasVirtualEnforcer< SkCanvas >, SkCanvasVirtualEnforcer< SkNoDrawCanvas >, SkCanvasVirtualEnforcer< SkNWayCanvas >, SkPaintFilterCanvas, and MSKPPlayer::CmdRecordCanvas.

Definition at line 1836 of file SkCanvas.cpp.

1836 {
1837 // We don't test quickReject because the shadow outsets the path's bounds.
1838 // TODO(michaelludwig): Is it worth calling SkDrawShadowMetrics::GetLocalBounds here?
1839 if (!this->predrawNotify()) {
1840 return;
1841 }
1842 this->topDevice()->drawShadow(path, rec);
1843}
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 2400 of file SkCanvas.cpp.

2400 {
2402 if (this->internalQuickReject(bounds, paint)) {
2403 return;
2404 }
2405 // See comment in onDrawGlyphRunList()
2406 auto layer = this->aboutToDraw(paint, &bounds, PredrawFlags::kSkipMaskFilterAutoLayer);
2407 if (layer) {
2408 this->topDevice()->drawSlug(this, slug, layer->paint());
2409 }
2410}
virtual void drawSlug(SkCanvas *, const sktext::gpu::Slug *slug, const SkPaint &paint)
Definition: SkDevice.cpp:488
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 SkOverdrawCanvas, SkNoDrawCanvas, SkNWayCanvas, SkPaintFilterCanvas, SkPictureRecord, SkRecorder, and DebugCanvas.

Definition at line 2506 of file SkCanvas.cpp.

2507 {
2509
2510 const SkRect& bounds = vertices->bounds();
2511 if (this->internalQuickReject(bounds, simplePaint)) {
2512 return;
2513 }
2514
2515 auto layer = this->aboutToDraw(simplePaint, &bounds);
2516 if (layer) {
2517 this->topDevice()->drawVertices(vertices, SkBlender::Mode(bmode), layer->paint());
2518 }
2519}
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 1230 of file SkCanvas.cpp.

1230 {
1231 if (props) {
1232 *props = top ? topDevice()->surfaceProps() : fProps;
1233 }
1234 return true;
1235}
const SkSurfaceProps & surfaceProps() const
Definition: SkDevice.h:131

◆ onImageInfo()

SkImageInfo SkCanvas::onImageInfo ( ) const
protectedvirtual

Reimplemented in SkPaintFilterCanvas.

Definition at line 1210 of file SkCanvas.cpp.

1210 {
1211 return this->rootDevice()->imageInfo();
1212}

◆ onNewSurface()

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

Reimplemented in SkPaintFilterCanvas, SkPictureRecord, and SkRecorder.

Definition at line 1202 of file SkCanvas.cpp.

1202 {
1203 return this->rootDevice()->makeSurface(info, props);
1204}
virtual sk_sp< SkSurface > makeSurface(const SkImageInfo &, const SkSurfaceProps &)
Definition: SkDevice.cpp:494

◆ onPeekPixels()

bool SkCanvas::onPeekPixels ( SkPixmap pixmap)
protectedvirtual

Reimplemented in SkPictureRecord, and SkPaintFilterCanvas.

Definition at line 1241 of file SkCanvas.cpp.

1241 {
1242 return this->rootDevice()->peekPixels(pmap);
1243}
bool peekPixels(SkPixmap *)
Definition: SkDevice.cpp:391

◆ onResetClip()

void SkCanvas::onResetClip ( )
protectedvirtual

Reimplemented in SkNWayCanvas, SkPictureRecord, SkRecorder, and DebugCanvas.

Definition at line 1424 of file SkCanvas.cpp.

1424 {
1425 SkIRect deviceRestriction = this->topDevice()->imageInfo().bounds();
1426 if (fClipRestrictionSaveCount >= 0 && this->topDevice() == this->rootDevice()) {
1427 // Respect the device clip restriction when resetting the clip if we're on the base device.
1428 // If we're not on the base device, then the "reset" applies to the top device's clip stack,
1429 // and the clip restriction will be respected automatically during a restore of the layer.
1430 if (!deviceRestriction.intersect(fClipRestrictionRect)) {
1431 deviceRestriction = SkIRect::MakeEmpty();
1432 }
1433 }
1434
1435 AutoUpdateQRBounds aqr(this);
1436 this->topDevice()->replaceClip(deviceRestriction);
1437}
virtual void replaceClip(const SkIRect &rect)=0
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
SkIRect bounds() const
Definition: SkImageInfo.h:427

◆ 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 1237 of file SkCanvas.cpp.

1237 {
1238 return this->onPeekPixels(pmap);
1239}
virtual bool onPeekPixels(SkPixmap *pixmap)
Definition: SkCanvas.cpp:1241

◆ private_draw_shadow_rec()

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

Definition at line 1831 of file SkCanvas.cpp.

1831 {
1832 TRACE_EVENT0("skia", TRACE_FUNC);
1833 this->onDrawShadowRec(path, rec);
1834}
virtual void onDrawShadowRec(const SkPath &, const SkDrawShadowRec &)
Definition: SkCanvas.cpp:1836

◆ 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 1567 of file SkCanvas.cpp.

1567 {
1568 return path.isEmpty() || this->quickReject(path.getBounds());
1569}
bool quickReject(const SkRect &rect) const
Definition: SkCanvas.cpp:1557
const SkRect & getBounds() const
Definition: SkPath.cpp:430

◆ 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 1557 of file SkCanvas.cpp.

1557 {
1558#ifdef SK_DEBUG
1559 // Verify that fQuickRejectBounds are set properly.
1560 this->validateClip();
1561#endif
1562
1563 SkRect devRect = SkMatrixPriv::MapRect(fMCRec->fMatrix, src);
1564 return !devRect.isFinite() || !devRect.intersects(fQuickRejectBounds);
1565}
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 386 of file SkCanvas.cpp.

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

◆ 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 382 of file SkCanvas.cpp.

382 {
383 return this->readPixels({ dstInfo, dstP, rowBytes}, x, y);
384}

◆ 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 378 of file SkCanvas.cpp.

378 {
379 return pm.addr() && this->rootDevice()->readPixels(pm, x, y);
380}
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 1641 of file SkCanvas.cpp.

1641 {
1642 return this->topDevice()->recorder();
1643}
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 1637 of file SkCanvas.cpp.

1637 {
1638 return this->topDevice()->recordingContext();
1639}
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 1355 of file SkCanvas.cpp.

1355 {
1356 this->setMatrix(SkM44());
1357}
void setMatrix(const SkM44 &matrix)
Definition: SkCanvas.cpp:1349

◆ 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 461 of file SkCanvas.cpp.

461 {
462 if (fMCRec->fDeferredSaveCount > 0) {
463 SkASSERT(fSaveCount > 1);
464 fSaveCount -= 1;
465 fMCRec->fDeferredSaveCount -= 1;
466 } else {
467 // check for underflow
468 if (fMCStack.count() > 1) {
469 this->willRestore();
470 SkASSERT(fSaveCount > 1);
471 fSaveCount -= 1;
472 this->internalRestore();
473 this->didRestore();
474 }
475 }
476}
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 478 of file SkCanvas.cpp.

478 {
479 // safety check
480 if (count < 1) {
481 count = 1;
482 }
483
484 int n = this->getSaveCount() - count;
485 for (int i = 0; i < n; ++i) {
486 this->restore();
487 }
488}
void restore()
Definition: SkCanvas.cpp:461

◆ 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 1300 of file SkCanvas.cpp.

1300 {
1301 SkMatrix m;
1302 m.setRotate(degrees);
1303 this->concat(m);
1304}

◆ 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 1306 of file SkCanvas.cpp.

1306 {
1307 SkMatrix m;
1308 m.setRotate(degrees, px, py);
1309 this->concat(m);
1310}

◆ 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 447 of file SkCanvas.cpp.

447 {
448 fSaveCount += 1;
449 fMCRec->fDeferredSaveCount += 1;
450 return this->getSaveCount() - 1; // return our prev value
451}

◆ 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 500 of file SkCanvas.cpp.

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

◆ 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:496

◆ 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 496 of file SkCanvas.cpp.

496 {
497 return this->saveLayer(SaveLayerRec(bounds, paint, 0));
498}

◆ 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)
Definition: SkCanvas.cpp:1077

◆ 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 1077 of file SkCanvas.cpp.

1077 {
1078 if (alpha >= 1.0f) {
1079 return this->saveLayer(bounds, nullptr);
1080 } else {
1081 SkPaint tmpPaint;
1082 tmpPaint.setAlphaf(alpha);
1083 return this->saveLayer(bounds, &tmpPaint);
1084 }
1085}
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 1289 of file SkCanvas.cpp.

1289 {
1290 if (sx != 1 || sy != 1) {
1291 this->checkForDeferredSave();
1292 fMCRec->fMatrix.preScale(sx, sy);
1293
1294 this->topDevice()->setGlobalCTM(fMCRec->fMatrix);
1295
1296 this->didScale(sx, sy);
1297 }
1298}
virtual void didScale(SkScalar, SkScalar)
Definition: SkCanvas.h:2282
void setGlobalCTM(const SkM44 &ctm)
Definition: SkDevice.cpp:73

◆ 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 1349 of file SkCanvas.cpp.

1349 {
1350 this->checkForDeferredSave();
1351 this->internalSetMatrix(m);
1352 this->didSetM44(m);
1353}
virtual void didSetM44(const SkM44 &)
Definition: SkCanvas.h:2280

◆ setMatrix() [2/2]

void SkCanvas::setMatrix ( const SkMatrix matrix)

Definition at line 1345 of file SkCanvas.cpp.

1345 {
1346 this->setMatrix(SkM44(matrix));
1347}

◆ 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 1312 of file SkCanvas.cpp.

1312 {
1313 SkMatrix m;
1314 m.setSkew(sx, sy);
1315 this->concat(m);
1316}

◆ 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 1535 of file SkCanvas.cpp.

1535 {
1536 rgn->setEmpty();
1537 SkDevice* device = this->topDevice();
1538 if (device && device->isPixelAlignedToGlobal()) {
1539 device->android_utils_clipAsRgn(rgn);
1540 SkIPoint origin = device->getOrigin();
1541 if (origin.x() | origin.y()) {
1542 rgn->translate(origin.x(), origin.y());
1543 }
1544 }
1545}
constexpr int32_t y() const
Definition: SkPoint_impl.h:52
constexpr int32_t x() const
Definition: SkPoint_impl.h:46

◆ 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 1278 of file SkCanvas.cpp.

1278 {
1279 if (dx || dy) {
1280 this->checkForDeferredSave();
1281 fMCRec->fMatrix.preTranslate(dx, dy);
1282
1283 this->topDevice()->setGlobalCTM(fMCRec->fMatrix);
1284
1285 this->didTranslate(dx,dy);
1286 }
1287}
virtual void didTranslate(SkScalar, SkScalar)
Definition: SkCanvas.h:2281
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208

◆ willRestore()

virtual void SkCanvas::willRestore ( )
inlineprotectedvirtual

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

Definition at line 2276 of file SkCanvas.h.

2276{}

◆ willSave()

virtual void SkCanvas::willSave ( )
inlineprotectedvirtual

Reimplemented in 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 391 of file SkCanvas.cpp.

391 {
392 SkPixmap pm;
393 if (bitmap.peekPixels(&pm)) {
394 return this->writePixels(pm.info(), pm.addr(), pm.rowBytes(), x, y);
395 }
396 return false;
397}
bool writePixels(const SkImageInfo &info, const void *pixels, size_t rowBytes, int x, int y)
Definition: SkCanvas.cpp:399
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 399 of file SkCanvas.cpp.

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

Friends And Related Function 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: