SkCanvas Reference
===
---
class SkCanvas {
public:
static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels,
size_t rowBytes,
const SkSurfaceProps* props = nullptr);
static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
size_t rowBytes);
SkCanvas();
SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr);
explicit SkCanvas(sk_sp<SkBaseDevice> device);
explicit SkCanvas(const SkBitmap& bitmap);
enum class ColorBehavior {
kLegacy,
};
SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior);
SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
virtual ~SkCanvas();
SkMetaData& getMetaData();
SkImageInfo imageInfo() const;
bool getProps(SkSurfaceProps* props) const;
void flush();
virtual SkISize getBaseLayerSize() const;
sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr);
virtual GrContext* getGrContext();
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 saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
enum SaveLayerFlagsSet {
kPreserveLCDText_SaveLayerFlag = 1 << 1,
kInitWithPrevious_SaveLayerFlag = 1 << 2,
kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag =
1 << 3,
kDontClipToLayer_Legacy_SaveLayerFlag =
kDontClipToLayer_PrivateSaveLayerFlag,
};
typedef uint32_t SaveLayerFlags;
struct SaveLayerRec {
SaveLayerRec();
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0);
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
SaveLayerFlags saveLayerFlags);
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
const SkImage* clipMask, const SkMatrix* clipMatrix,
SaveLayerFlags saveLayerFlags);
const SkRect* fBounds = nullptr;
const SkPaint* fPaint = nullptr;
const SkImageFilter* fBackdrop = nullptr;
const SkImage* fClipMask = nullptr;
const SkMatrix* fClipMatrix = nullptr;
SaveLayerFlags fSaveLayerFlags = 0;
};
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 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 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 setAllowSimplifyClip(bool allow);
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 clear(SkColor color);
void discard();
void drawPaint(const SkPaint& paint);
enum PointMode {
kPoints_PointMode,
kLines_PointMode,
kPolygon_PointMode,
};
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 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,
const SkPaint* paint = nullptr);
void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
const SkPaint* paint = nullptr);
enum SrcRectConstraint {
kStrict_SrcRectConstraint,
kFast_SrcRectConstraint,
};
void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint);
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint);
void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint = nullptr);
void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint = nullptr);
void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint = nullptr);
void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
const SkPaint* paint = nullptr);
struct Lattice {
enum RectType : uint8_t {
kDefault = 0,
kTransparent,
kFixedColor,
};
const int* fXDivs;
const int* fYDivs;
const RectType* fRectTypes;
int fXCount;
int fYCount;
const SkIRect* fBounds;
const SkColor* fColors;
};
void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
const SkPaint* paint = nullptr);
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
const SkPaint* paint = nullptr);
enum QuadAAFlags : unsigned {
kLeft_QuadAAFlag = 0b0001,
kTop_QuadAAFlag = 0b0010,
kRight_QuadAAFlag = 0b0100,
kBottom_QuadAAFlag = 0b1000,
kNone_QuadAAFlags = 0b0000,
kAll_QuadAAFlags = 0b1111,
};
struct ImageSetEntry {
sk_spSkImage> fImage;
SkRect fSrcRect;
SkRect fDstRect;
unsigned fAAFlags;
};
void experimental_DrawImageSetV0(const ImageSetEntry imageSet[], int cnt, float alpha,
SkFilterQuality quality, SkBlendMode mode);
void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint& paint);
void drawString(const char* string, SkScalar x, SkScalar y, const SkPaint& paint);
void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint);
void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
const SkPaint& paint);
void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
const SkPaint& paint);
void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
const SkRect* cullRect, 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 drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[], int boneCount,
SkBlendMode mode, const SkPaint& paint);
void drawVertices(const sk_sp<SkVertices>& vertices, const SkVertices::Bone bones[],
int boneCount, SkBlendMode mode, const SkPaint& paint);
void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], const SkPaint& paint);
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
const SkPaint* paint);
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
const SkPaint* paint);
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
const SkRect* cullRect, const SkPaint* paint);
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
int count, 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;
const SkMatrix& getTotalMatrix() const;
};
Canvas provides an interface for drawing, and how the drawing is clipped and transformed.
Canvas contains a stack of Matrix and Clip values.
Canvas and Paint together provide the state to draw into Surface or Device.
Each Canvas draw call transforms the geometry of the object by the concatenation of all
Matrix values in the stack. The transformed geometry is clipped by the intersection
of all of Clip values in the stack. The Canvas draw calls use Paint to supply drawing
state such as Color, Typeface, text size, stroke width, Shader and so on.
To draw to a pixel-based destination, create Raster_Surface or GPU_Surface.
Request Canvas from Surface to obtain the interface to draw.
Canvas generated by Raster_Surface draws to memory visible to the CPU.
Canvas generated by GPU_Surface uses Vulkan or OpenGL to draw to the GPU.
To draw to a document, obtain Canvas from SVG_Canvas, Document_PDF, or Picture_Recorder.
Document based Canvas and other Canvas subclasses reference Device describing the
destination.
Canvas can be constructed to draw to Bitmap without first creating Raster_Surface.
This approach may be deprecated in the future.
Canvas may be created directly when no Surface is required; some Canvas methods
implicitly create Raster_Surface.
---
static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels,
size_t rowBytes,
const SkSurfaceProps* props = nullptr)
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
width, or height, or both, may be zero
### Parameters
may be nullptr
### Return Value
SkCanvas if all parameters are valid; otherwise, nullptr
### Example
Allocates a three by three
bitmap, clears it to white, and draws a black
pixel
in the center.
#### Example Output
~~~~
---
-x-
---
~~~~
### See Also
MakeRasterDirectN32 SkSurface::MakeRasterDirect
---
static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
size_t rowBytes)
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
times rowBytes
### Parameters
### Return Value
SkCanvas if all parameters are valid; otherwise, nullptr
### Example
Allocates a three by three
bitmap, clears it to white, and draws a black
pixel
in the center.
#### Example Output
~~~~
---
-x-
---
~~~~
### See Also
MakeRasterDirect SkSurface::MakeRasterDirect SkImageInfo::MakeN32Premul
---
SkCanvas()
Creates an empty SkCanvas with no backing device or pixels, with
a width and height of zero.
### Return Value
empty SkCanvas
### Example
Passes a placeholder to a function that requires one.
#### Example Output
~~~~
rect stays rect is true
rect stays rect is false
rect stays rect is true
~~~~
### See Also
MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas
---
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
width |
zero or greater |
height |
zero or greater |
props |
LCD striping orientation and setting for device independent fonts; |
may be nullptr
### Return Value
SkCanvas placeholder with dimensions
### Example
#### Example Output
~~~~
canvas is empty
~~~~
### See Also
MakeRasterDirect SkSurfaceProps SkPixelGeometry SkCreateColorSpaceXformCanvas
---
explicit SkCanvas(sk_sp<SkBaseDevice> device)
To be deprecated soon.
---
explicit SkCanvas(const SkBitmap& bitmap)
Constructs a canvas that draws into bitmap.
Sets SkSurfaceProps::kLegacyFontHost_InitType in constructed SkSurface.
SkBitmap is copied so that subsequently editing bitmap will not affect
constructed SkCanvas.
May be deprecated in the future.
### Parameters
storage of raster surface
### Return Value
SkCanvas that can be used to draw into bitmap
### Example
The actual output depends on the installed fonts.
#### Example Output
~~~~
-----
---x-
---x-
---x-
---x-
---x-
---x-
-----
---x-
---x-
-----
~~~~
### See Also
MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas
---
Private: Android framework only.
enum class ColorBehavior {
kLegacy,
};
### Constants
---
SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior)
For use by Android framework only.
### Parameters
### Return Value
SkCanvas that can be used to draw into bitmap
---
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
and pixel storage of raster surface
### Parameters
props |
order and orientation of RGB striping; and whether to use |
device independent fonts
### Return Value
SkCanvas that can be used to draw into bitmap
### Example
The actual output depends on the installed fonts.
#### Example Output
~~~~
-----
---x-
---x-
---x-
---x-
---x-
---x-
-----
---x-
---x-
-----
~~~~
### See Also
MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas
---
virtual ~SkCanvas()
Draws saved layers, if any.
Frees up resources used by SkCanvas.
### Example
### See Also
State_Stack
---
SkMetaData& getMetaData()
Returns storage to associate additional data with the canvas.
The storage is freed when SkCanvas is deleted.
### Return Value
storage that can be read from and written to
### Example
#### Example Output
~~~~
before: (null)
during: Hello!
after: (null)
~~~~
### See Also
SkMetaData
---
SkImageInfo imageInfo() const
Returns SkImageInfo for SkCanvas. If SkCanvas is not associated with raster surface or
GPU surface, returned SkColorType is set to kUnknown_SkColorType.
### Return Value
dimensions and SkColorType of SkCanvas
### Example
#### Example Output
~~~~
emptyInfo == canvasInfo
~~~~
### See Also
SkImageInfo MakeRasterDirect makeSurface
---
bool 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
### Return Value
true if SkSurfaceProps was copied
### Example
#### Example Output
~~~~
isRGB:0
isRGB:1
~~~~
### See Also
SkSurfaceProps makeSurface
---
void flush()
Triggers the immediate execution of all pending draw operations.
If SkCanvas is associated with GPU surface, resolves all pending GPU operations.
If SkCanvas is associated with raster surface, has no effect; raster draw
operations are never deferred.
### See Also
peekPixels SkSurface::flush GrContext::flush SkSurface::prepareForExternalIO GrContext::abandonContext
---
virtual SkISize getBaseLayerSize() const
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).
### Return Value
integral width and height of base layer
### Example
#### Example Output
~~~~
clip=10,30
size=20,30
~~~~
### See Also
getDeviceClipBounds
---
sk_sp<SkSurface> 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
### Return Value
SkSurface matching info and props, or nullptr if no match is available
### Example
#### Example Output
~~~~
compatible != nullptr
size = 3, 4
~~~~
### See Also
SkSurface SkSurface::makeSurface SkImageInfo SkSurfaceProps
---
virtual GrContext* getGrContext()
Returns GPU context of the GPU surface associated with SkCanvas.
### Return Value
GPU context, if available; nullptr otherwise
### Example
### See Also
GrContext
---
void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr)
Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels
can be read directly. 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
may be nullptr
### Return Value
address of pixels, or nullptr if inaccessible
### Example
### Example
Draws "ABC" on the
device. Then draws "DEF" in
Layer, and reads
Layer to add a large dotted "DEF". Finally blends
Layer with the
device.
The
Layer and blended result appear on the CPU and GPU but the large dotted
"DEF" appear only on the CPU.
### See Also
SkImageInfo SkPixmap
---
SkRasterHandleAllocator::Handle 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.
### Return Value
context of custom allocation
### Example
#### Example Output
~~~~
context = skia
~~~~
### See Also
SkRasterHandleAllocator
---
bool peekPixels(SkPixmap* pixmap)
Returns true if SkCanvas has direct access to its pixels.
Pixels are readable when SkBaseDevice is raster. Pixels are not readable when SkCanvas
is returned from GPU surface, returned by SkDocument::beginPage, returned by
SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class
like SkDebugCanvas.
pixmap is valid only while SkCanvas is in scope and unchanged. Any
SkCanvas or SkSurface call may invalidate the pixmap values.
### Parameters
pixmap |
storage for pixel state if pixels are readable; otherwise, ignored |
### Return Value
true if SkCanvas has direct access to pixels
### Example
#### Example Output
~~~~
width=256 height=256
~~~~
### See Also
readPixels SkBitmap::peekPixels SkImage::peekPixels SkSurface::peekPixels
---
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY)
Copies Rect of pixels from Canvas into dstPixels. Matrix and Clip are
ignored.
Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
Destination Rect 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 Device is raster, or backed by a GPU.
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
class like SkDebugCanvas.
The destination pixel storage must be allocated by the caller.
Pixel values are converted only if Color_Type and Alpha_Type
do not match. Only pixels within both source and destination rectangles
are copied. dstPixels contents outside Rect intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down destination.
Does not copy, and returns false if:
### Parameters
### Return Value
true if pixels were copied
### Example
A black
circle drawn on a blue background provides an
image to copy.
readPixels copies one quarter of the
canvas into each of the four corners.
The copied quarter
circles overdraw the original
circle.
### Example
#### Example Output
~~~~
pixel = 802b5580
pixel = 8056a9ff
~~~~
### See Also
peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels
---
bool readPixels(const SkPixmap& pixmap, int srcX, int srcY)
Copies Rect of pixels from Canvas into pixmap. Matrix and Clip are
ignored.
Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
Destination Rect 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 Device is raster, or backed by a GPU.
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
class like SkDebugCanvas.
Caller must allocate pixel storage in pixmap if needed.
Pixel values are converted only if Color_Type and Alpha_Type
do not match. Only pixels within both source and destination Rects
are copied. pixmap pixels contents outside Rect intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down pixmap.
Does not copy, and returns false if:
### Parameters
pixmap |
storage for pixels copied from Canvas |
srcX |
offset into readable pixels on x-axis; may be negative |
srcY |
offset into readable pixels on y-axis; may be negative |
### Return Value
true if pixels were copied
### Example
#### Example Output
~~~~
pixel = 802b5580
~~~~
### See Also
peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels
---
bool readPixels(const SkBitmap& bitmap, int srcX, int srcY)
Copies Rect of pixels from Canvas into bitmap. Matrix and Clip are
ignored.
Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()).
Copies each readable pixel intersecting both rectangles, without scaling,
converting to bitmap.colorType() and bitmap.alphaType() if required.
Pixels are readable when Device is raster, or backed by a GPU.
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
class like SkDebugCanvas.
Caller must allocate pixel storage in bitmap if needed.
Bitmap values are converted only if Color_Type and Alpha_Type
do not match. Only pixels within both source and destination rectangles
are copied. Bitmap pixels outside Rect intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down bitmap.
Does not copy, and returns false if:
### Parameters
bitmap |
storage for pixels copied from Canvas |
srcX |
offset into readable pixels on x-axis; may be negative |
srcY |
offset into readable pixels on y-axis; may be negative |
### Return Value
true if pixels were copied
### Example
#### Example Output
~~~~
pixel = 802b5580
~~~~
### See Also
peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels
---
bool writePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, int x, int y)
Copies Rect from pixels to Canvas. Matrix and Clip are ignored.
Source Rect corners are (0, 0) and (info.width(), info.height()).
Destination Rect 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 Device is raster, or backed by a GPU.
Pixels are not writable when SkCanvas is returned by SkDocument::beginPage,
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
class like SkDebugCanvas.
Pixel values are converted only if Color_Type and Alpha_Type
do not match. Only pixels within both source and destination rectangles
are copied. Canvas pixels outside Rect intersection are unchanged.
Pass negative values for x or y to offset pixels to the left or
above Canvas pixels.
Does not copy, and returns false if:
### Parameters
### Return Value
true if pixels were written to Canvas
### Example
### See Also
readPixels drawBitmap drawImage SkBitmap::writePixels
---
bool writePixels(const SkBitmap& bitmap, int x, int y)
Copies Rect from pixels to Canvas. Matrix and Clip are ignored.
Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()).
Destination Rect 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 Device is raster, or backed by a GPU.
Pixels are not writable when SkCanvas is returned by SkDocument::beginPage,
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
class like SkDebugCanvas.
Pixel values are converted only if Color_Type and Alpha_Type
do not match. Only pixels within both source and destination rectangles
are copied. Canvas pixels outside Rect intersection are unchanged.
Pass negative values for x or y to offset pixels to the left or
above Canvas pixels.
Does not copy, and returns false if:
### Parameters
bitmap |
contains pixels copied to Canvas |
x |
offset into Canvas writable pixels in x; may be negative |
y |
offset into Canvas writable pixels in y; may be negative |
### Return Value
true if pixels were written to Canvas
### Example
### See Also
readPixels drawBitmap drawImage SkBitmap::writePixels
---
Canvas maintains a stack of state that allows hierarchical drawing, commonly used
to implement windows and views. The initial state has an identity matrix and and
an infinite clip. Even with a wide-open clip, drawing is constrained by the
bounds of the Canvas Surface or Device.
Canvas savable state consists of Clip and Matrix.
Clip describes the area that may be drawn to.
Matrix transforms the geometry.
save(), saveLayer, saveLayerPreserveLCDTextRequests, and saveLayerAlpha
save state and return the depth of the stack.
restore(), restoreToCount, and ~SkCanvas() revert state to its value when saved.
Each state on the stack intersects Clip with the previous Clip,
and concatenates Matrix with the previous Matrix.
The intersected Clip makes the drawing area the same or smaller;
the concatenated Matrix may move the origin and potentially scale or rotate
the coordinate space.
Canvas does not require balancing the state stack but it is a good idea
to do so. Calling save() without restore() will eventually cause Skia to fail;
mismatched save() and restore() create hard to find bugs.
It is not possible to use state to draw outside of the clip defined by the
previous state.
### Example
Draw to ever smaller clips; then restore drawing to full
canvas.
Note that the second
clipRect is not permitted to enlarge Clip.
Each Clip uses the current Matrix for its coordinates.
### Example
### See Also
save saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount
---
int 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.
### Return Value
depth of saved stack
### Example
The black square is translated 50 pixels down and to the right.
Restoring
Canvas state removes
translate() from
Canvas stack;
the red square is not translated, and is drawn at the origin.
### See Also
saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore restoreToCount
---
void 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
### See Also
save saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restoreToCount
---
int 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.
### Return Value
depth of save state stack
### Example
#### Example Output
~~~~
depth = 1
depth = 2
depth = 1
~~~~
### See Also
save restore restoreToCount
---
void 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
### Example
#### Example Output
~~~~
depth = 1
depth = 3
depth = 1
~~~~
### See Also
restore getSaveCount save
Layer allocates a temporary Bitmap to draw into. When the drawing is
complete, the Bitmap is drawn into the Canvas.
Layer is saved in a stack along with other saved state. When state with a Layer
is restored, the Bitmap is drawn into the previous Layer.
Layer may be initialized with the contents of the previous Layer. When Layer is
restored, its Bitmap can be modified by Paint passed to Layer to apply
Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode.
---
int saveLayer(const SkRect* bounds, const SkPaint* paint)
Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing.
Calling restore() discards changes to SkMatrix and clip, and draws the SkBitmap.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
clipPath(), clipRegion().
SkRect bounds suggests but does not define the SkBitmap size. To clip drawing to
a specific rectangle, use clipRect().
Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and
SkBlendMode when restore() is called.
Call restoreToCount() with returned value to restore this and subsequent saves.
### Parameters
### Return Value
depth of saved stack
### Example
### See Also
save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec
---
int saveLayer(const SkRect& bounds, const SkPaint* paint)
Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing.
Calling restore() discards changes to SkMatrix and clip, and draws the SkBitmap.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
clipPath(), clipRegion().
SkRect bounds suggests but does not define the 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
### Return Value
depth of saved stack
### Example
### See Also
save restore saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec
---
int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint)
Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing.
LCD text is preserved when the layer is drawn to the prior layer.
Calling restore() discards changes to SkMatrix and clip, and draws 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 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.
Draw text on an opaque background so that LCD text blends correctly with the
prior layer. LCD text drawn on a background with transparency may result in
incorrect blending.
### Parameters
### Return Value
depth of saved stack
### Example
### See Also
save restore saveLayer saveLayerAlpha SaveLayerRec
---
int saveLayerAlpha(const SkRect* bounds, U8CPU alpha)
Saves SkMatrix and clip, and allocates SkBitmap for subsequent drawing.
Calling restore() discards changes to SkMatrix and clip,
and blends layer with alpha opacity onto prior layer.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
clipPath(), clipRegion().
SkRect bounds suggests but does not define layer size. To clip drawing to
a specific rectangle, use clipRect().
alpha of zero is fully transparent, 255 is fully opaque.
Call restoreToCount() with returned value to restore this and subsequent saves.
### Parameters
### Return Value
depth of saved stack
### Example
### See Also
save restore saveLayer saveLayerPreserveLCDTextRequests SaveLayerRec
---
enum SaveLayerFlagsSet {
kPreserveLCDText_SaveLayerFlag = 1 << 1,
kInitWithPrevious_SaveLayerFlag = 1 << 2,
kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag =
1 << 3,
kDontClipToLayer_Legacy_SaveLayerFlag =
kDontClipToLayer_PrivateSaveLayerFlag,
};
---
SaveLayerFlags provides options that may be used in any combination in SaveLayerRec,
defining how Layer allocated by saveLayer operates. It may be set to zero,
kPreserveLCDText_SaveLayerFlag, kInitWithPrevious_SaveLayerFlag, or both flags.
### Constants
### Example
### See Also
save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec
---
struct SaveLayerRec {
SaveLayerRec();
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0);
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
SaveLayerFlags saveLayerFlags);
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
const SkImage* clipMask, const SkMatrix* clipMatrix,
SaveLayerFlags saveLayerFlags);
const SkRect* fBounds = nullptr;
const SkPaint* fPaint = nullptr;
const SkImageFilter* fBackdrop = nullptr;
const SkImage* fClipMask = nullptr;
const SkMatrix* fClipMatrix = nullptr;
SaveLayerFlags fSaveLayerFlags = 0;
};
SaveLayerRec contains the state used to create the Layer.
### Example
---
SaveLayerRec()
Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags.
### Return Value
empty SaveLayerRec
### Example
#### Example Output
~~~~
rec1 == rec2
~~~~
### See Also
save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
---
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr.
### Parameters
### Return Value
SaveLayerRec with empty fBackdrop
### Example
#### Example Output
~~~~
rec1 == rec2
~~~~
### See Also
save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
---
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
SaveLayerFlags saveLayerFlags)
Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags.
### Parameters
may be nullptr
### Parameters
### Return Value
SaveLayerRec fully specified
### Example
#### Example Output
~~~~
rec1 == rec2
~~~~
### See Also
save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
---
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
const SkImage* clipMask, const SkMatrix* clipMatrix, SaveLayerFlags saveLayerFlags)
Experimental. Not ready for general use.
Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags.
clipMatrix uses Color_Alpha channel of image, transformed by clipMatrix, to clip
Layer when drawn to Canvas.
Implementation is not complete; has no effect if Device is GPU-backed.
### Parameters
### Return Value
SaveLayerRec fully specified
### See Also
save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
---
int saveLayer(const SaveLayerRec& layerRec)
Saves SkMatrix and clip, and allocates SkBitmap for subsequent drawing.
Calling restore() discards changes to SkMatrix and clip,
and blends SkBitmap with alpha opacity onto the prior layer.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
clipPath(), clipRegion().
SaveLayerRec contains the state used to create the layer.
Call restoreToCount() with returned value to restore this and subsequent saves.
### Parameters
### Return Value
depth of save state stack
### Example
### See Also
save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
---
void 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
dx |
distance to translate on x-axis |
dy |
distance to translate on y-axis |
### Example
scale() followed by
translate() produces different results from
translate() followed
by
scale().
The blue stroke follows translate of (50, 50); a black
fill follows scale of (2, 1/2.f). After restoring the clip, which resets
Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill
follows translate of (50, 50).
### See Also
concat() scale() skew() rotate() setMatrix
---
void 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
sx |
amount to scale on x-axis |
sy |
amount to scale on y-axis |
### Example
### See Also
concat() translate() skew() rotate() setMatrix
---
void 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
### Example
Draw clock hands at time 5:10. The hour hand and minute hand
point up and
are rotated clockwise.
### See Also
concat() translate() skew() scale() setMatrix
---
void 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
### Example
### See Also
concat() translate() skew() scale() setMatrix
---
void 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
sx |
amount to skew on x-axis |
sy |
amount to skew on y-axis |
### Example
Black
text mimics an oblique
text style by using a negative skew on x-axis
that shifts the geometry to the right as the y-axis values decrease.
Red
text uses a positive skew on y-axis to shift the geometry down
as the x-axis values increase.
Blue
text combines
sx and
sy skew to rotate and scale.
### See Also
concat() translate() rotate() scale() setMatrix
---
void 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
### Example
### See Also
translate() rotate() scale() skew() setMatrix
---
void setMatrix(const SkMatrix& matrix)
Replaces SkMatrix with matrix.
Unlike concat(), any prior matrix state is overwritten.
### Parameters
### Example
### See Also
resetMatrix concat() translate() rotate() scale() skew()
---
void resetMatrix()
Sets SkMatrix to the identity matrix.
Any prior matrix state is overwritten.
### Example
### See Also
setMatrix concat() translate() rotate() scale() skew()
---
const SkMatrix& getTotalMatrix() const
Returns SkMatrix.
This does not account for translation by SkBaseDevice or SkSurface.
### Return Value
SkMatrix in SkCanvas
### Example
#### Example Output
~~~~
isIdentity true
~~~~
### See Also
setMatrix resetMatrix concat()
---
Clip is built from a stack of clipping paths. Each Path in the
stack can be constructed from one or more Path_Contour elements. The
Path_Contour may be composed of any number of Path_Verb segments. Each
Path_Contour forms a closed area; Path_Fill_Type defines the area enclosed
by Path_Contour.
Clip stack of Path elements successfully restrict the Path area. Each
Path is transformed by Matrix, then intersected with or subtracted from the
prior Clip to form the replacement Clip. Use SkClipOp::kDifference
to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path
with Clip.
A clipping Path may be Anti_Aliased; if Path, after transformation, is
composed of horizontal and vertical lines, clearing Anti_Alias allows whole pixels
to either be inside or outside the clip. The fastest drawing has a Aliased,
rectangular clip.
If clipping Path has Anti_Alias set, clip may partially clip a pixel, requiring
that drawing blend partially with the destination along the edge. A rotated
rectangular Anti_Aliased clip looks smoother but draws slower.
Clip can combine with Rect and Round_Rect primitives; like
Path, these are transformed by Matrix before they are combined with Clip.
Clip can combine with Region. Region is assumed to be in Device coordinates
and is unaffected by Matrix.
### Example
---
void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias)
Replaces clip with the intersection or difference of clip and rect,
with an aliased or anti-aliased clip edge. rect is transformed by SkMatrix
before it is combined with clip.
### Parameters
### Example
### See Also
clipRRect clipPath clipRegion
---
void clipRect(const SkRect& rect, SkClipOp op)
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
### Example
### See Also
clipRRect clipPath clipRegion
---
void clipRect(const SkRect& rect, bool doAntiAlias = false)
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
### Example
### See Also
clipRRect clipPath clipRegion
---
void androidFramework_setDeviceClipRestriction(const SkIRect& rect)
Sets the maximum clip rectangle, which can be set by clipRect, clipRRect and
clipPath and intersect the current clip with the specified rect.
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.
Private: This private API is for use by Android framework only.
### Parameters
rect |
maximum allowed clip in device coordinates |
#
---
void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias)
Replaces clip with the intersection or difference of clip and rrect,
with an aliased or anti-aliased clip edge.
rrect is transformed by SkMatrix
before it is combined with clip.
### Parameters
### Example
### See Also
clipRect clipPath clipRegion
---
void clipRRect(const SkRRect& rrect, SkClipOp op)
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
### Example
### See Also
clipRect clipPath clipRegion
---
void clipRRect(const SkRRect& rrect, bool doAntiAlias = false)
Replaces clip with the intersection of clip and rrect,
with an aliased or anti-aliased clip edge.
rrect is transformed by SkMatrix before it is combined with clip.
### Parameters
### Example
### See Also
clipRect clipPath clipRegion
---
void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias)
Replaces clip with the intersection or difference of clip and path,
with an aliased or anti-aliased clip edge. 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
### Example
### See Also
clipRect clipRRect clipRegion
---
void clipPath(const SkPath& path, SkClipOp op)
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
### Example
### See Also
clipRect clipRRect clipRegion
---
void clipPath(const SkPath& path, bool doAntiAlias = false)
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
### Example
### See Also
clipRect clipRRect clipRegion
---
void setAllowSimplifyClip(bool allow)
Experimental. For testing only.
Set to simplify clip stack using PathOps.
---
void 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
### Example
### See Also
clipRect clipRRect clipPath
---
bool 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
### Return Value
true if rect, transformed by SkMatrix, does not intersect clip
### Example
#### Example Output
~~~~
quickReject true
quickReject false
~~~~
### See Also
getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing
---
bool 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
### Return Value
true if path, transformed by SkMatrix, does not intersect clip
### Example
#### Example Output
~~~~
quickReject true
quickReject false
~~~~
### See Also
getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing
---
SkRect 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.
### Return Value
bounds of clip in local coordinates
### Example
Initial bounds is
device bounds outset by 1 on all sides.
Clipped bounds is
clipPath bounds outset by 1 on all sides.
Scaling the
canvas by two on both axes scales the local bounds by 1/2
on both axes.
#### Example Output
~~~~
left:-1 top:-1 right:257 bottom:257
left:29 top:129 right:121 bottom:231
left:14.5 top:64.5 right:60.5 bottom:115.5
~~~~
### See Also
getDeviceClipBounds getBaseLayerSize quickReject
---
bool getLocalClipBounds(SkRect* bounds) const
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
### Return Value
true if clip bounds is not empty
### Example
#### Example Output
~~~~
local bounds empty = false
local bounds empty = true
~~~~
### See Also
getDeviceClipBounds getBaseLayerSize quickReject
---
SkIRect 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.
### Return Value
bounds of clip in SkBaseDevice coordinates
### Example
Initial bounds is
device bounds, not outset.
Clipped bounds is
clipPath bounds, not outset.
Scaling the
canvas by 1/2 on both axes scales the
device bounds by 1/2
on both axes.
#### Example Output
~~~~
left:0 top:0 right:256 bottom:256
left:30 top:130 right:120 bottom:230
left:15 top:65 right:60 bottom:115
~~~~
### See Also
getLocalClipBounds getBaseLayerSize quickReject
---
bool getDeviceClipBounds(SkIRect* bounds) const
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
### Return Value
true if clip bounds is not empty
### Example
#### Example Output
~~~~
device bounds empty = false
device bounds empty = true
~~~~
### See Also
getLocalClipBounds getBaseLayerSize quickReject
---
void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver)
Fills clip with color color.
mode determines how ARGB is combined with destination.
### Parameters
### Example
### See Also
clear SkBitmap::erase drawPaint
---
void clear(SkColor color)
Fills clip with color color using SkBlendMode::kSrc.
This has the effect of replacing all pixels contained by clip with color.
### Parameters
### Example
### See Also
drawColor SkBitmap::erase drawPaint
---
void discard()
Makes SkCanvas contents undefined. Subsequent calls that read SkCanvas pixels,
such as drawing with SkBlendMode, return undefined results. discard() does
not change clip or SkMatrix.
discard() may do nothing, depending on the implementation of SkSurface or SkBaseDevice
that created SkCanvas.
discard() allows optimized performance on subsequent draws by removing
cached data associated with SkSurface or SkBaseDevice.
It is not necessary to call discard() once done with SkCanvas;
any cached data is deleted when owning SkSurface or SkBaseDevice is deleted.
### See Also
flush() SkSurface::prepareForExternalIO GrContext::abandonContext
---
void drawPaint(const SkPaint& paint)
Fills clip with SkPaint paint. SkPaint components SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;
SkPathEffect in paint is ignored.
### Parameters
### Example
### See Also
clear drawColor SkBitmap::erase
---
enum PointMode {
kPoints_PointMode,
kLines_PointMode,
kPolygon_PointMode,
};
Selects if an array of points are drawn as discrete points, as lines, or as
an open polygon.
### Constants
### Example
The upper left corner shows three squares when drawn as
points.
The upper right corner shows one
line; when drawn as
lines, two
points are required per
line.
The lower right corner shows two
lines; when draw as polygon, no miter is drawn at the corner.
The lower left corner shows two
lines with a miter when
path contains polygon.
### See Also
drawLine drawPoint drawPath
---
void 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
### Example
The first column draws points. |
The second column draws points as lines. |
The third column draws points as a polygon. |
The fourth column draws points as a polygonal path. |
The first row uses a round cap and round join. |
The second row uses a square cap and a miter join. |
The third row uses a butt cap and a bevel join. |
The transparent
color makes multiple
line draws visible;
the
path is drawn all at once.
### See Also
drawLine drawPoint drawPath
---
void 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
### Example
### See Also
drawPoints drawCircle drawRect drawLine drawPath
---
void drawPoint(SkPoint p, const SkPaint& paint)
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
p |
top-left edge of circle or square |
paint |
stroke, blend, color, and so on, used to draw |
### Example
### See Also
drawPoints drawCircle drawRect drawLine drawPath
---
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint)
Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.
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
x0 |
start of line segment on x-axis |
y0 |
start of line segment on y-axis |
x1 |
end of line segment on x-axis |
y1 |
end of line segment on y-axis |
paint |
stroke, blend, color, and so on, used to draw |
### Example
### See Also
drawPoint drawCircle drawRect drawPath
---
void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint)
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
### Example
### See Also
drawPoint drawCircle drawRect drawPath
---
void 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
rect |
rectangle to draw |
paint |
stroke or fill, blend, color, and so on, used to draw |
### Example
### See Also
drawIRect drawRRect drawRoundRect drawRegion drawPath drawLine
---
void drawIRect(const SkIRect& rect, const SkPaint& paint)
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
rect |
rectangle to draw |
paint |
stroke or fill, blend, color, and so on, used to draw |
### Example
### See Also
drawRect drawRRect drawRoundRect drawRegion drawPath drawLine
---
void 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
### Example
### See Also
drawRect drawIRect drawPath
---
void 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
### Example
### See Also
drawCircle drawPoint drawPath drawRRect drawRoundRect
---
void 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
### Example
### See Also
drawRect drawRoundRect drawDRRect drawCircle drawOval drawPath
---
void 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
### Example
### Example
Outer
Rect has no corner radii, but stroke join is rounded.
Inner
Round_Rect has corner radii; outset stroke increases radii of corners.
Stroke join does not affect
inner Round_Rect since it has no sharp corners.
### See Also
drawRect drawRoundRect drawRRect drawCircle drawOval drawPath
---
void 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
### Example
### See Also
drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine
---
void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint)
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
### Example
### See Also
drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine
---
void 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
### Example
### Example
### See Also
SkPath::arcTo drawCircle drawOval drawPath
---
void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint)
Draws SkRRect bounded by SkRect rect, with corner radii (rx, ry) using clip,
SkMatrix, and SkPaint paint.
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
rect |
SkRect bounds of SkRRect to draw |
rx |
axis length on x-axis of oval describing rounded corners |
ry |
axis length on y-axis of oval describing rounded corners |
paint |
stroke, blend, color, and so on, used to draw |
### Example
Top row has a zero radius a generates a rectangle.
Second row radii sum to less than sides.
Third row radii sum equals sides.
Fourth row radii sum exceeds sides; radii are scaled to fit.
### See Also
drawRRect drawRect drawDRRect drawPath drawCircle drawOval drawPoint
---
void 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
### Example
Top rows draw stroked
path with combinations of joins and caps. The open
contour
is affected by caps; the closed
contour is affected by joins.
Bottom row draws fill the same for open and closed
contour.
First bottom column shows winding fills overlap.
Second bottom column shows even odd fills exclude overlap.
Third bottom column shows inverse winding fills area outside both
contours.
### See Also
SkPath drawLine drawArc drawRect drawPoints
drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or
a smart pointer as a convenience. The pairs of calls are otherwise identical.
---
void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = nullptr)
Draws SkImage image, with its top-left corner at (left, top),
using clip, SkMatrix, and optional SkPaint paint.
If paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode,
and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from image bounds. If generated
mask extends beyond image bounds, replicate image edge colors, just as SkShader
made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the
image edge color when it samples outside of its bounds.
### Parameters
and so on; or nullptr
### Example
### See Also
drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter
---
void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
const SkPaint* paint = nullptr)
Draws SkImage image, with its top-left corner at (left, top),
using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from image bounds. If generated
mask extends beyond image bounds, replicate image edge colors, just as SkShader
made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the
image edge color when it samples outside of its bounds.
### Parameters
and so on; or nullptr
### Example
### See Also
drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter
---
enum SrcRectConstraint {
kStrict_SrcRectConstraint,
kFast_SrcRectConstraint,
};
SrcRectConstraint controls the behavior at the edge of source Rect,
provided to drawImageRect, trading off speed for precision.
Image_Filter in Paint may sample multiple pixels in the image. Source Rect
restricts the bounds of pixels that may be read. Image_Filter may slow down if
it cannot read outside the bounds, when sampling near the edge of source Rect.
SrcRectConstraint specifies whether an Image_Filter is allowed to read pixels
outside source Rect.
### Constants
### Example
redBorder contains a black and white checkerboard bordered by red.
redBorder is drawn scaled by 16 on the left.
The middle and right
bitmaps are filtered checkerboards.
Drawing the checkerboard with
kStrict_SrcRectConstraint shows only a blur of black and white.
Drawing the checkerboard with
kFast_SrcRectConstraint allows red to bleed in the corners.
### See Also
drawImageRect drawImage SkPaint::setImageFilter
---
void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint)
Draws SkRect src of SkImage image, scaled and translated to fill SkRect dst.
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just
as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
replicates the image edge color when it samples outside of its bounds.
constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
sample within src; set to kFast_SrcRectConstraint allows sampling outside to
improve performance.
### Parameters
and so on; or nullptr
### Parameters
### Example
### See Also
SrcRectConstraint drawImage drawImageLattice drawImageNine
---
void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint)
Draws SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst.
Note that isrc is on integer pixel boundaries; dst may include fractional
boundaries. Additionally transform draw using clip, SkMatrix, and optional SkPaint
paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just
as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
replicates the image edge color when it samples outside of its bounds.
constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to
improve performance.
### Parameters
and so on; or nullptr
### Parameters
### Example
### See Also
SrcRectConstraint drawImage drawImageLattice drawImageNine
---
void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint)
Draws SkImage image, scaled and translated to fill SkRect dst, using clip, SkMatrix,
and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just
as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
replicates the image edge color when it samples outside of its bounds.
### Parameters
and so on; or nullptr
### Example
### See Also
SrcRectConstraint drawImage drawImageLattice drawImageNine
---
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint)
Draws SkRect src of SkImage image, scaled and translated to fill SkRect dst.
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just
as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
replicates the image edge color when it samples outside of its bounds.
### Parameters
and so on; or nullptr
### Parameters
### Example
Canvas scales and translates; transformation from
src to
dst also scales.
The two
matrices are concatenated to create the final transformation.
### See Also
SrcRectConstraint drawImage drawImageLattice drawImageNine
---
void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint)
Draws SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst.
isrc is on integer pixel boundaries; dst may include fractional boundaries.
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just
as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
replicates the image edge color when it samples outside of its bounds.
constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
sample within image; set to kFast_SrcRectConstraint allows sampling outside to
improve performance.
### Parameters
and so on; or nullptr
### Parameters
### Example
### See Also
SrcRectConstraint drawImage drawImageLattice drawImageNine
---
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint)
Draws SkImage image, scaled and translated to fill SkRect dst,
using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from image bounds.
If generated mask extends beyond image bounds, replicate image edge colors, just
as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
replicates the image edge color when it samples outside of its bounds.
constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
sample within image; set to kFast_SrcRectConstraint allows sampling outside to
improve performance.
### Parameters
and so on; or nullptr
### Example
### See Also
SrcRectConstraint drawImage drawImageLattice drawImageNine
---
void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint = nullptr)
Draws Image image stretched proportionally to fit into Rect dst.
IRect center divides the image into nine sections: four sides, four corners, and
the center. Corners are unmodified or scaled down proportionately if their sides
are larger than dst; center and four sides are scaled to fit remaining space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
If paint contains Mask_Filter, generate mask from image bounds. If paint
Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all
other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels.
Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state.
If generated mask extends beyond image bounds, replicate image edge colors, just
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
replicates the image edge color when it samples outside of its bounds.
### Parameters
### Example
The leftmost
image is smaller than
center; only corners are drawn, all scaled to fit.
The second
image equals the
size of
center; only corners are drawn without scaling.
The remaining images are larger than
center. All corners draw without scaling.
The sides and
center are scaled if needed to take up the remaining space.
### See Also
drawImage drawBitmapNine drawImageLattice drawImageRect
---
void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint = nullptr)
Draws Image image stretched proportionally to fit into Rect dst.
IRect center divides the image into nine sections: four sides, four corners, and
the center. Corners are not scaled, or scaled down proportionately if their sides
are larger than dst; center and four sides are scaled to fit remaining space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
If paint contains Mask_Filter, generate mask from image bounds. If paint
Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all
other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels.
Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state.
If generated mask extends beyond image bounds, replicate image edge colors, just
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
replicates the image edge color when it samples outside of its bounds.
### Parameters
### Example
The two leftmost images has four corners and sides to the left and right of
center.
The leftmost
image scales the width of corners proportionately to fit.
The third and fourth
image corners are not scaled; the sides and
center are scaled to
fill the remaining space.
The rightmost
image has four corners scaled vertically to fit, and uses sides above
and below
center to fill the remaining space.
### See Also
drawImage drawBitmapNine drawImageLattice drawImageRect
---
void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, const SkPaint* paint = nullptr)
Draws SkBitmap bitmap, with its top-left corner at (left, top),
using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
just as SkShader made from SkShader::MakeBitmapShader with
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
outside of its bounds.
### Parameters
and so on; or nullptr
### Example
### See Also
drawImage drawBitmapLattice drawBitmapNine drawBitmapRect SkBitmap::readPixels SkBitmap::writePixels
---
void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint)
Draws SkRect src of SkBitmap bitmap, scaled and translated to fill SkRect dst.
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
just as SkShader made from SkShader::MakeBitmapShader with
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
outside of its bounds.
constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
sample within src; set to kFast_SrcRectConstraint allows sampling outside to
improve performance.
### Parameters
and so on; or nullptr
### Parameters
### Example
### See Also
drawImageRect drawBitmap drawBitmapLattice drawBitmapNine
---
void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint)
Draws SkIRect isrc of SkBitmap bitmap, scaled and translated to fill SkRect dst.
isrc is on integer pixel boundaries; dst may include fractional boundaries.
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
just as SkShader made from SkShader::MakeBitmapShader with
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
outside of its bounds.
constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to
improve performance.
### Parameters
and so on; or nullptr
### Parameters
### Example
### See Also
drawImageRect drawBitmap drawBitmapLattice drawBitmapNine
---
void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint)
Draws SkBitmap bitmap, scaled and translated to fill SkRect dst.
bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries.
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
If paint contains SkMaskFilter, generate mask from bitmap bounds.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
just as SkShader made from SkShader::MakeBitmapShader with
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
outside of its bounds.
constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to
improve performance.
### Parameters
and so on; or nullptr
### Parameters
### Example
### See Also
drawImageRect drawBitmap drawBitmapLattice drawBitmapNine
---
void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
const SkPaint* paint = nullptr)
Draws Bitmap bitmap stretched proportionally to fit into Rect dst.
IRect center divides the bitmap into nine sections: four sides, four corners,
and the center. Corners are not scaled, or scaled down proportionately if their
sides are larger than dst; center and four sides are scaled to fit remaining
space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
If paint contains Mask_Filter, generate mask from bitmap bounds. If paint
Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all
other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels.
Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
just as Shader made from SkShader::MakeBitmapShader with
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
outside of its bounds.
### Parameters
### Example
The two leftmost
bitmap draws has four corners and sides to the left and right of
center.
The leftmost
bitmap draw scales the width of corners proportionately to fit.
The third and fourth draw corners are not scaled; the sides and
center are scaled to
fill the remaining space.
The rightmost
bitmap draw has four corners scaled vertically to fit, and uses sides above
and below
center to fill the remaining space.
### See Also
drawImageNine drawBitmap drawBitmapLattice drawBitmapRect
---
struct Lattice {
enum RectType : uint8_t {
kDefault = 0,
kTransparent,
kFixedColor,
};
const int* fXDivs;
const int* fYDivs;
const RectType* fRectTypes;
int fXCount;
int fYCount;
const SkIRect* fBounds;
const SkColor* fColors;
};
Lattice divides Bitmap or Image into a rectangular grid.
Grid entries on even columns and even rows are fixed; these entries are
always drawn at their original size if the destination is large enough.
If the destination side is too small to hold the fixed entries, all fixed
entries are proportionately scaled down to fit.
The grid entries not on even columns and rows are scaled to fit the
remaining space, if any.
---
enum RectType : uint8_t {
kDefault = 0,
kTransparent,
kFixedColor,
};
Optional setting per rectangular grid entry to make it transparent,
or to fill the grid entry with a color.
### Constants
Type |
Member |
Description |
const int* |
fXDivs |
Array of x-axis values that divide the bitmap vertically.
Array entries must be unique, increasing, greater than or equal to
fBounds left edge, and less than fBounds right edge.
Set the first element to fBounds left to collapse the left column of
fixed grid entries.
|
const int* |
fYDivs |
Array of y-axis values that divide the bitmap horizontally.
Array entries must be unique, increasing, greater than or equal to
fBounds top edge, and less than fBounds bottom edge.
Set the first element to fBounds top to collapse the top row of fixed
grid entries.
|
const RectType* |
fRectTypes |
Optional array of fill types, one per rectangular grid entry:
array length must be (fXCount + 1) * (fYCount + 1) .
Each RectType is one of: kDefault, kTransparent, kFixedColor.
Array entries correspond to the rectangular grid entries, ascending
left to right and then top to bottom.
|
int |
fXCount |
Number of entries in fXDivs array; one less than the number of
horizontal divisions.
|
int |
fYCount |
Number of entries in fYDivs array; one less than the number of vertical
divisions.
|
const SkIRect* |
fBounds |
Optional subset IRect source to draw from.
If nullptr, source bounds is dimensions of Bitmap or Image.
|
const SkColor* |
fColors |
Optional array of colors, one per rectangular grid entry.
Array length must be (fXCount + 1) * (fYCount + 1) .
Array entries correspond to the rectangular grid entries, ascending
left to right, then top to bottom.
|
---
void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
const SkPaint* paint = nullptr)
Draws Bitmap bitmap stretched proportionally to fit into Rect dst.
Lattice lattice divides bitmap into a rectangular grid.
Each intersection of an even-numbered row and column is fixed; like the corners
of drawBitmapNine, fixed lattice elements never scale larger than their initial
size and shrink proportionately when all fixed elements exceed the bitmap
dimension. All other grid elements scale to fill the available space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
If paint contains Mask_Filter, generate mask from bitmap bounds. If paint
Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all
other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels.
Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
just as Shader made from SkShader::MakeBitmapShader with
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
outside of its bounds.
### Parameters
### Example
The two leftmost
bitmap draws has four corners and sides to the left and right of center.
The leftmost
bitmap draw scales the width of corners proportionately to fit.
The third and fourth draw corners are not scaled; the sides are scaled to
fill the remaining space; the center is transparent.
The rightmost
bitmap draw has four corners scaled vertically to fit, and uses sides above
and below center to fill the remaining space.
### See Also
drawImageLattice drawBitmap drawBitmapNine Lattice
---
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
const SkPaint* paint = nullptr)
Draws Image image stretched proportionally to fit into Rect dst.
Lattice lattice divides image into a rectangular grid.
Each intersection of an even-numbered row and column is fixed; like the corners
of drawBitmapNine, fixed lattice elements never scale larger than their initial
size and shrink proportionately when all fixed elements exceed the bitmap
dimension. All other grid elements scale to fill the available space, if any.
Additionally transform draw using Clip, Matrix, and optional Paint paint.
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
If paint contains Mask_Filter, generate mask from image bounds. If paint
Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all
other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels.
Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
just as Shader made from SkShader::MakeBitmapShader with
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
outside of its bounds.
### Parameters
### Example
The leftmost
image is smaller than center; only corners are drawn, all scaled to fit.
The second
image equals the
size of center; only corners are drawn without scaling.
The remaining images are larger than center. All corners draw without scaling. The sides
are scaled if needed to take up the remaining space; the center is transparent.
### See Also
drawBitmapLattice drawImage drawImageNine Lattice
---
enum QuadAAFlags : unsigned {
kLeft_QuadAAFlag = 0b0001,
kTop_QuadAAFlag = 0b0010,
kRight_QuadAAFlag = 0b0100,
kBottom_QuadAAFlag = 0b1000,
kNone_QuadAAFlags = 0b0000,
kAll_QuadAAFlags = 0b1111,
};
Private: Do not use.
### Constants
---
struct ImageSetEntry {
sk_spSkImage> fImage;
SkRect fSrcRect;
SkRect fDstRect;
unsigned fAAFlags;
};
Private: Do not use.
Type |
Member |
Description |
SkImage* |
fImage |
image to draw |
SkRect |
fSrcRect |
image src rectangle |
SkRect |
fDstRect |
local space rectangle |
unsigned |
fAAFlags |
antialiasing flags |
---
void experimental_DrawImageSetV0(const ImageSetEntry imageSet[], int cnt, float alpha,
SkFilterQuality quality, SkBlendMode mode) ;
Private: Do not use.
Draws a set of images. Do not use this method.
### Parameters
---
void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint)
Draws text, with origin at (x, y), using clip, SkMatrix, and SkPaint paint.
text meaning depends on SkPaint::TextEncoding; by default, text is encoded as
UTF-8.
x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
text draws left to right, positioning the first glyph left side bearing at x
and its baseline at y. Text size is affected by SkMatrix and SkPaint text size.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
filled 12 point black glyphs.
### Parameters
### Example
### See Also
drawString drawPosText drawPosTextH drawTextBlob drawTextRSXform
---
void drawString(const char* string, SkScalar x, SkScalar y, const SkPaint& paint)
Draws null terminated string, with origin at (x, y), using clip, SkMatrix, and
SkPaint paint.
string meaning depends on SkPaint::TextEncoding; by default, strings are encoded
as UTF-8. Other values of SkPaint::TextEncoding are unlikely to produce the desired
results, since zero bytes may be embedded in the string.
x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
string draws left to right, positioning the first glyph left side bearing at x
and its baseline at y. Text size is affected by SkMatrix and SkPaint text size.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
filled 12 point black glyphs.
### Parameters
ending with a char value of zero
### Parameters
### Example
### See Also
drawText drawPosText drawPosTextH drawTextBlob drawTextRSXform
---
void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint)
Draws null terminated string, with origin at (x, y), using clip, SkMatrix, and
SkPaint paint.
string meaning depends on SkPaint::TextEncoding; by default, strings are encoded
as UTF-8. Other values of SkPaint::TextEncoding are unlikely to produce the desired
results, since zero bytes may be embedded in the string.
x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
string draws left to right, positioning the first glyph left side bearing at x
and its baseline at y. Text size is affected by SkMatrix and SkPaint text size.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
filled 12 point black glyphs.
### Parameters
ending with a char value of zero
### Parameters
### Example
### See Also
drawText drawPosText drawPosTextH drawTextBlob drawTextRSXform
---
void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkPaint& paint)
Draws each glyph in text with the origin in pos array, using clip, SkMatrix, and
SkPaint paint. The number of entries in pos array must match the number of glyphs
described by byteLength of text.
text meaning depends on SkPaint::TextEncoding; by default, text is encoded as
UTF-8. pos elements meaning depends on SkPaint vertical text; by default
glyph left side bearing and baseline are relative to SkPoint in pos array.
Text size is affected by SkMatrix and SkPaint text size.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
filled 12 point black glyphs.
Layout engines such as Harfbuzz typically position each glyph
rather than using the font advance widths.
### Parameters
### Example
### See Also
drawText drawPosTextH drawTextBlob drawTextRSXform
---
void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
const SkPaint& paint)
Draws each glyph in text with its origin composed from xpos array and
constY, using clip, SkMatrix, and SkPaint paint. The number of entries in xpos array
must match the number of glyphs described by byteLength of text.
text meaning depends on SkPaint::TextEncoding; by default, text is encoded as
UTF-8. xpos elements meaning depends on SkPaint vertical text;
by default each glyph left side bearing is positioned at an xpos element and
its baseline is positioned at constY. Text size is affected by SkMatrix and
SkPaint text size.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
filled 12 point black glyphs.
Layout engines such as Harfbuzz typically position each glyph
rather than using the font advance widths if all glyphs share the same
baseline.
### Parameters
### Example
### See Also
drawText drawPosText drawTextBlob drawTextRSXform
---
void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
const SkRect* cullRect, const SkPaint& paint)
Draws text, transforming each glyph by the corresponding SkRSXform,
using clip, SkMatrix, and SkPaint paint.
SkRSXform xform array specifies a separate square scale, rotation, and translation
for each glyph. xform does not affect paint SkShader.
Optional SkRect cullRect is a conservative bounds of text, taking into account
SkRSXform and paint. If cullRect is outside of clip, canvas can skip drawing.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
filled 12 point black glyphs.
### Parameters
### Example
### See Also
drawText drawPosText drawTextBlob
---
void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint)
Draws Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint.
blob contains Glyphs, their positions, and paint attributes specific to text: Typeface, Paint_Text_Size, Paint_Text_Scale_X,
Paint_Text_Skew_X, Paint_Hinting, Anti_Alias, Paint_Fake_Bold,
Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text,
and Subpixel_Text
.
Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding.
Elements of paint: Anti_Alias, Blend_Mode, Color including Color_Alpha,
Color_Filter, Paint_Dither, Draw_Looper, Mask_Filter, Path_Effect, Shader, and
Paint_Style; apply to blob. If Paint contains SkPaint::kStroke_Style:
Paint_Miter_Limit, Paint_Stroke_Cap, Paint_Stroke_Join, and Paint_Stroke_Width;
apply to Path created from blob.
### Parameters
### Example
### See Also
drawText drawPosText drawPosTextH
---
void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint)
Draws Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint.
blob contains Glyphs, their positions, and paint attributes specific to text: Typeface, Paint_Text_Size, Paint_Text_Scale_X,
Paint_Text_Skew_X, Paint_Hinting, Anti_Alias, Paint_Fake_Bold,
Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text,
and Subpixel_Text
.
Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding.
Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter,
Image_Filter, and Draw_Looper; apply to blob.
### Parameters
### Example
### See Also
drawText drawPosText drawPosTextH
---
void drawPicture(const SkPicture* picture)
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
picture |
recorded drawing commands to play |
### Example
### See Also
drawDrawable SkPicture SkPicture::playback
---
void drawPicture(const sk_sp<SkPicture>& picture)
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
picture |
recorded drawing commands to play |
### Example
### See Also
drawDrawable SkPicture SkPicture::playback
---
void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint)
Draws SkPicture picture, using clip and SkMatrix; transforming picture with
SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter,
SkImageFilter, and SkBlendMode, if provided.
matrix transformation is equivalent to: save(), concat(), drawPicture(), restore().
paint use is equivalent to: saveLayer(), drawPicture(), restore().
### Parameters
picture |
recorded drawing commands to play |
matrix |
SkMatrix to rotate, scale, translate, and so on; may be nullptr |
paint |
SkPaint to apply transparency, filtering, and so on; may be nullptr |
### Example
### See Also
drawDrawable SkPicture SkPicture::playback
---
void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint)
Draws SkPicture picture, using clip and SkMatrix; transforming picture with
SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter,
SkImageFilter, and SkBlendMode, if provided.
matrix transformation is equivalent to: save(), concat(), drawPicture(), restore().
paint use is equivalent to: saveLayer(), drawPicture(), restore().
### Parameters
picture |
recorded drawing commands to play |
matrix |
SkMatrix to rotate, scale, translate, and so on; may be nullptr |
paint |
SkPaint to apply transparency, filtering, and so on; may be nullptr |
### Example
### See Also
drawDrawable SkPicture SkPicture::playback
---
void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint)
Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix.
If vertices texs and vertices colors are defined in vertices, and SkPaint paint
contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
### Parameters
### Example
### See Also
drawPatch drawPicture
---
void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint)
Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix.
If vertices texs and vertices colors are defined in vertices, and SkPaint paint
contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
### Parameters
### Example
### See Also
drawPatch drawPicture
---
void drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[], int boneCount,
SkBlendMode mode, const SkPaint& paint)
Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. Bone data is used to
deform vertices with bone weights.
If vertices texs and vertices colors are defined in vertices, and SkPaint paint
contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
The first element of bones should be an object to world space transformation matrix that
will be applied before performing mesh deformations. If no such transformation is needed,
it should be the identity matrix.
boneCount must be at most 80, and thus the size of bones should be at most 80.
### Parameters
### See Also
drawPatch drawPicture
---
void drawVertices(const sk_sp<SkVertices>& vertices, const SkVertices::Bone bones[], int boneCount,
SkBlendMode mode, const SkPaint& paint)
Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. Bone data is used to
deform vertices with bone weights.
If vertices texs and vertices colors are defined in vertices, and SkPaint paint
contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
The first element of bones should be an object to world space transformation matrix that
will be applied before performing mesh deformations. If no such transformation is needed,
it should be the identity matrix.
boneCount must be at most 80, and thus the size of bones should be at most 80.
### Parameters
### See Also
drawPatch drawPicture
---
void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4],
SkBlendMode mode, const SkPaint& paint)
Draws a Coons patch: the interpolation of four cubics with shared corners,
associating a color, and optionally a texture SkPoint, with each corner.
Coons patch uses clip and SkMatrix, paint SkShader, SkColorFilter,
alpha, SkImageFilter, and SkBlendMode. If SkShader is provided it is treated
as Coons patch texture; SkBlendMode mode combines color colors and SkShader if
both are provided.
SkPoint array cubics specifies four SkPath cubic starting at the top-left corner,
in clockwise order, sharing every fourth point. The last SkPath cubic ends at the
first point.
Color array color associates colors with corners in top-left, top-right,
bottom-right, bottom-left order.
If paint contains SkShader, SkPoint array texCoords maps SkShader as texture to
corners in top-left, top-right, bottom-right, bottom-left order.
### Parameters
may be nullptr
### Parameters
### Example
### See Also
drawVertices drawPicture
---
void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4],
const SkPaint& paint)
Draws SkPath cubic Coons patch: the interpolation of four cubics with shared corners,
associating a color, and optionally a texture SkPoint, with each corner.
Coons patch uses clip and SkMatrix, paint SkShader, SkColorFilter,
alpha, SkImageFilter, and SkBlendMode. If SkShader is provided it is treated
as Coons patch texture; SkBlendMode mode combines color colors and SkShader if
both are provided.
SkPoint array cubics specifies four SkPath cubic starting at the top-left corner,
in clockwise order, sharing every fourth point. The last SkPath cubic ends at the
first point.
Color array color associates colors with corners in top-left, top-right,
bottom-right, bottom-left order.
If paint contains SkShader, SkPoint array texCoords maps SkShader as texture to
corners in top-left, top-right, bottom-right, bottom-left order.
### Parameters
may be nullptr
### Parameters
### Example
### Example
### See Also
drawVertices drawPicture
---
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
const SkPaint* paint)
Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
to draw, if present. For each entry in the array, SkRect tex locates sprite in
atlas, and SkRSXform xform transforms it into destination space.
xform, text, and colors if present, must contain count entries.
Optional colors are applied for each sprite using SkBlendMode mode, treating
sprite as source and colors as destination.
Optional cullRect is a conservative bounds of all transformed sprites.
If cullRect is outside of clip, canvas can skip drawing.
### Parameters
### Example
### See Also
drawBitmap drawImage
---
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
const SkPaint* paint)
Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
to draw, if present. For each entry in the array, SkRect tex locates sprite in
atlas, and SkRSXform xform transforms it into destination space.
xform, text, and colors if present, must contain count entries.
Optional colors is applied for each sprite using SkBlendMode.
Optional cullRect is a conservative bounds of all transformed sprites.
If cullRect is outside of clip, canvas can skip drawing.
### Parameters
### Example
### See Also
drawBitmap drawImage
---
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
const SkRect* cullRect, const SkPaint* paint)
Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
to draw, if present. For each entry in the array, SkRect tex locates sprite in
atlas, and SkRSXform xform transforms it into destination space.
xform and text must contain count entries.
Optional cullRect is a conservative bounds of all transformed sprites.
If cullRect is outside of clip, canvas can skip drawing.
### Parameters
### Example
### See Also
drawBitmap drawImage
---
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], int count,
const SkRect* cullRect, const SkPaint* paint)
Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
to draw, if present. For each entry in the array, SkRect tex locates sprite in
atlas, and SkRSXform xform transforms it into destination space.
xform and text must contain count entries.
Optional cullRect is a conservative bounds of all transformed sprites.
If cullRect is outside of clip, canvas can skip drawing.
### Parameters
### Example
### See Also
drawBitmap drawImage
---
void 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
drawable |
custom struct encapsulating drawing commands |
matrix |
transformation applied to drawing; may be nullptr |
### Example
### See Also
SkDrawable drawPicture
---
void 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
drawable |
custom struct encapsulating drawing commands |
x |
offset into SkCanvas writable pixels on x-axis |
y |
offset into SkCanvas writable pixels on y-axis |
### Example
### See Also
SkDrawable drawPicture
---
void drawAnnotation(const SkRect& rect, const char key[], SkData* value)
Associates SkRect on SkCanvas with an annotation; a key-value pair, where the key is
a null-terminated UTF-8 string, and optional value is stored as SkData.
Only some canvas implementations, such as recording to SkPicture, or drawing to
document PDF, use annotations.
### Parameters
### Example
### See Also
SkPicture SkDocument
---
void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value)
Associates SkRect on SkCanvas when an annotation; a key-value pair, where the key is
a null-terminated UTF-8 string, and optional value is stored as SkData.
Only some canvas implementations, such as recording to SkPicture, or drawing to
document PDF, use annotations.
### Parameters
### Example
### See Also
SkPicture SkDocument
---
virtual bool isClipEmpty() const
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.
### Return Value
true if clip is empty
### Example
#### Example Output
~~~~
clip is not empty
clip is empty
~~~~
### See Also
isClipRect getLocalClipBounds getDeviceClipBounds
---
virtual bool isClipRect() const
Returns true if clip is SkRect and not empty.
Returns false if the clip is empty, or if it is not SkRect.
### Return Value
true if clip is SkRect and not empty
### Example
#### Example Output
~~~~
clip is rect
clip is not rect
~~~~
### See Also
isClipEmpty getLocalClipBounds getDeviceClipBounds