Skia
2DGraphicsLibrary
|
A Canvas encapsulates all of the state about drawing into a device (bitmap). More...
#include <SkCanvas.h>
Classes | |
class | AutoValidateClip |
struct | Lattice |
Specifies coordinates to divide a bitmap into (xCount*yCount) rects. More... | |
class | LayerIter |
After calling saveLayer(), there can be any number of devices that make up the top-most drawing area. More... | |
struct | SaveLayerRec |
Public Types | |
enum | { kIsOpaque_SaveLayerFlag = 1 << 0, kPreserveLCDText_SaveLayerFlag = 1 << 1 } |
enum | PointMode { kPoints_PointMode, kLines_PointMode, kPolygon_PointMode } |
enum | SrcRectConstraint { kStrict_SrcRectConstraint, kFast_SrcRectConstraint } |
Controls the behavior at the edge of the src-rect, when specified in drawImageRect, trading off speed for exactness. More... | |
enum | VertexMode { kTriangles_VertexMode, kTriangleStrip_VertexMode, kTriangleFan_VertexMode } |
typedef uint32_t | SaveLayerFlags |
typedef SkCanvasClipVisitor | ClipVisitor |
Public Member Functions | |
SkCanvas () | |
Creates an empty canvas with no backing device/pixels, and zero dimensions. | |
SkCanvas (int width, int height, const SkSurfaceProps *=NULL) | |
Creates a canvas of the specified dimensions, but explicitly not backed by any device/pixels. More... | |
SkCanvas (SkBaseDevice *device) | |
Construct a canvas with the specified device to draw into. More... | |
SkCanvas (const SkBitmap &bitmap) | |
Construct a canvas with the specified bitmap to draw into. More... | |
SkCanvas (const SkBitmap &bitmap, const SkSurfaceProps &props) | |
Construct a canvas with the specified bitmap to draw into. More... | |
SkMetaData & | getMetaData () |
SkImageInfo | imageInfo () const |
Return ImageInfo for this canvas. More... | |
bool | getProps (SkSurfaceProps *) const |
If the canvas is backed by pixels (cpu or gpu), this writes a copy of the SurfaceProps for the canvas to the location supplied by the caller, and returns true. More... | |
void | flush () |
Trigger the immediate execution of all pending draw operations. More... | |
virtual SkISize | getBaseLayerSize () const |
Gets the size of the base or root layer in global canvas coordinates. More... | |
SkISize | getDeviceSize () const |
DEPRECATED: call getBaseLayerSize. | |
SkBaseDevice * | getDevice_just_for_deprecated_compatibility_testing () const |
sk_sp< SkSurface > | makeSurface (const SkImageInfo &, const SkSurfaceProps *=nullptr) |
Create a new surface matching the specified info, one that attempts to be maximally compatible when used with this canvas. More... | |
GrContext * | getGrContext () |
Return the GPU context of the device that is associated with the canvas. More... | |
void * | accessTopLayerPixels (SkImageInfo *info, size_t *rowBytes, SkIPoint *origin=NULL) |
If the canvas has writable pixels in its top layer (and is not recording to a picture or other non-raster target) and has direct access to its pixels (i.e. More... | |
bool | peekPixels (SkPixmap *) |
If the canvas has readable pixels in its base layer (and is not recording to a picture or other non-raster target) and has direct access to its pixels (i.e. More... | |
bool | readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) |
Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes), converting them into the requested format (SkImageInfo). More... | |
bool | readPixels (SkBitmap *bitmap, int srcX, int srcY) |
Helper for calling readPixels(info, ...). More... | |
bool | readPixels (const SkIRect &srcRect, SkBitmap *bitmap) |
Helper for allocating pixels and then calling readPixels(info, ...). More... | |
bool | writePixels (const SkImageInfo &, const void *pixels, size_t rowBytes, int x, int y) |
This method affects the pixels in the base-layer, and operates in pixel coordinates, ignoring the matrix and clip. More... | |
bool | writePixels (const SkBitmap &bitmap, int x, int y) |
Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. More... | |
int | save () |
This call saves the current matrix, clip, and drawFilter, and pushes a copy onto a private stack. More... | |
int | saveLayer (const SkRect *bounds, const SkPaint *paint) |
This behaves the same as save(), but in addition it allocates an offscreen bitmap. More... | |
int | saveLayer (const SkRect &bounds, const SkPaint *paint) |
int | saveLayerPreserveLCDTextRequests (const SkRect *bounds, const SkPaint *paint) |
Temporary name. More... | |
int | saveLayerAlpha (const SkRect *bounds, U8CPU alpha) |
This behaves the same as save(), but in addition it allocates an offscreen bitmap. More... | |
int | saveLayer (const SaveLayerRec &) |
void | restore () |
This call balances a previous call to save(), and is used to remove all modifications to the matrix/clip/drawFilter state since the last save call. More... | |
int | getSaveCount () const |
Returns the number of matrix/clip states on the SkCanvas' private stack. More... | |
void | restoreToCount (int saveCount) |
Efficient way to pop any calls to save() that happened after the save count reached saveCount. More... | |
void | translate (SkScalar dx, SkScalar dy) |
Preconcat the current matrix with the specified translation. More... | |
void | scale (SkScalar sx, SkScalar sy) |
Preconcat the current matrix with the specified scale. More... | |
void | rotate (SkScalar degrees) |
Preconcat the current matrix with the specified rotation about the origin. More... | |
void | rotate (SkScalar degrees, SkScalar px, SkScalar py) |
Preconcat the current matrix with the specified rotation about a given point. More... | |
void | skew (SkScalar sx, SkScalar sy) |
Preconcat the current matrix with the specified skew. More... | |
void | concat (const SkMatrix &matrix) |
Preconcat the current matrix with the specified matrix. More... | |
void | setMatrix (const SkMatrix &matrix) |
Replace the current matrix with a copy of the specified matrix. More... | |
void | resetMatrix () |
Helper for setMatrix(identity). More... | |
void | clipRect (const SkRect &rect, SkRegion::Op op=SkRegion::kIntersect_Op, bool doAntiAlias=false) |
Modify the current clip with the specified rectangle. More... | |
void | clipRRect (const SkRRect &rrect, SkRegion::Op op=SkRegion::kIntersect_Op, bool doAntiAlias=false) |
Modify the current clip with the specified SkRRect. More... | |
void | clipPath (const SkPath &path, SkRegion::Op op=SkRegion::kIntersect_Op, bool doAntiAlias=false) |
Modify the current clip with the specified path. More... | |
void | setAllowSoftClip (bool allow) |
EXPERIMENTAL – only used for testing Set to false to force clips to be hard, even if doAntiAlias=true is passed to clipRect or clipPath. | |
void | setAllowSimplifyClip (bool allow) |
EXPERIMENTAL – only used for testing Set to simplify clip stack using path ops. | |
void | clipRegion (const SkRegion &deviceRgn, SkRegion::Op op=SkRegion::kIntersect_Op) |
Modify the current clip with the specified region. More... | |
void | setClipRegion (const SkRegion &deviceRgn) |
Helper for clipRegion(rgn, kReplace_Op). More... | |
bool | quickReject (const SkRect &rect) const |
Return true if the specified rectangle, after being transformed by the current matrix, would lie completely outside of the current clip. More... | |
bool | quickReject (const SkPath &path) const |
Return true if the specified path, after being transformed by the current matrix, would lie completely outside of the current clip. More... | |
virtual bool | getClipBounds (SkRect *bounds) const |
Return the bounds of the current clip (in local coordinates) in the bounds parameter, and return true if it is non-empty. More... | |
virtual bool | getClipDeviceBounds (SkIRect *bounds) const |
Return the bounds of the current clip, in device coordinates; returns true if non-empty. More... | |
void | drawARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b, SkXfermode::Mode mode=SkXfermode::kSrcOver_Mode) |
Fill the entire canvas' bitmap (restricted to the current clip) with the specified ARGB color, using the specified mode. More... | |
void | drawColor (SkColor color, SkXfermode::Mode mode=SkXfermode::kSrcOver_Mode) |
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and mode. More... | |
void | clear (SkColor color) |
Helper method for drawing a color in SRC mode, completely replacing all the pixels in the current clip with this color. | |
void | discard () |
This makes the contents of the canvas undefined. More... | |
void | drawPaint (const SkPaint &paint) |
Fill the entire canvas (restricted to the current clip) with the specified paint. More... | |
void | drawPoints (PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint) |
Draw a series of points, interpreted based on the PointMode mode. More... | |
void | drawPoint (SkScalar x, SkScalar y, const SkPaint &paint) |
Helper method for drawing a single point. More... | |
void | drawPoint (SkScalar x, SkScalar y, SkColor color) |
Draws a single pixel in the specified color. More... | |
void | drawLine (SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint) |
Draw a line segment with the specified start and stop x,y coordinates, using the specified paint. More... | |
void | drawRect (const SkRect &rect, const SkPaint &paint) |
Draw the specified rectangle using the specified paint. More... | |
void | drawIRect (const SkIRect &rect, const SkPaint &paint) |
Draw the specified rectangle using the specified paint. More... | |
void | drawRectCoords (SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, const SkPaint &paint) |
Draw the specified rectangle using the specified paint. More... | |
void | drawOval (const SkRect &oval, const SkPaint &) |
Draw the specified oval using the specified paint. More... | |
void | drawRRect (const SkRRect &rrect, const SkPaint &paint) |
Draw the specified RRect using the specified paint The rrect will be filled or stroked based on the Style in the paint. More... | |
void | drawDRRect (const SkRRect &outer, const SkRRect &inner, const SkPaint &) |
Draw the annulus formed by the outer and inner rrects. More... | |
void | drawCircle (SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint) |
Draw the specified circle using the specified paint. More... | |
void | drawArc (const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint) |
Draw the specified arc, which will be scaled to fit inside the specified oval. More... | |
void | drawRoundRect (const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint) |
Draw the specified round-rect using the specified paint. More... | |
void | drawPath (const SkPath &path, const SkPaint &paint) |
Draw the specified path using the specified paint. More... | |
void | drawImage (const SkImage *image, SkScalar left, SkScalar top, const SkPaint *paint=NULL) |
Draw the specified image, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix. More... | |
void | drawImage (const sk_sp< SkImage > &image, SkScalar left, SkScalar top, const SkPaint *paint=NULL) |
void | drawImageRect (const SkImage *image, const SkRect &src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint) |
Draw the specified image, scaling and translating so that it fills the specified dst rect. More... | |
void | drawImageRect (const SkImage *image, const SkIRect &isrc, const SkRect &dst, const SkPaint *paint, SrcRectConstraint=kStrict_SrcRectConstraint) |
void | drawImageRect (const SkImage *image, const SkRect &dst, const SkPaint *paint, SrcRectConstraint=kStrict_SrcRectConstraint) |
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 cons=kStrict_SrcRectConstraint) |
void | drawImageRect (const sk_sp< SkImage > &image, const SkRect &dst, const SkPaint *paint, SrcRectConstraint cons=kStrict_SrcRectConstraint) |
void | drawImageNine (const SkImage *, const SkIRect ¢er, const SkRect &dst, const SkPaint *paint=nullptr) |
Draw the image stretched differentially to fit into dst. More... | |
void | drawImageNine (const sk_sp< SkImage > &image, const SkIRect ¢er, const SkRect &dst, const SkPaint *paint=nullptr) |
void | drawBitmap (const SkBitmap &bitmap, SkScalar left, SkScalar top, const SkPaint *paint=NULL) |
Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix. More... | |
void | drawBitmapRect (const SkBitmap &bitmap, const SkRect &src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint=kStrict_SrcRectConstraint) |
Draw the specified bitmap, scaling and translating so that it fills the specified dst rect. More... | |
void | drawBitmapRect (const SkBitmap &bitmap, const SkIRect &isrc, const SkRect &dst, const SkPaint *paint, SrcRectConstraint=kStrict_SrcRectConstraint) |
void | drawBitmapRect (const SkBitmap &bitmap, const SkRect &dst, const SkPaint *paint, SrcRectConstraint=kStrict_SrcRectConstraint) |
void | drawBitmapNine (const SkBitmap &bitmap, const SkIRect ¢er, const SkRect &dst, const SkPaint *paint=NULL) |
Draw the bitmap stretched or shrunk differentially to fit into dst. More... | |
void | drawBitmapLattice (const SkBitmap &bitmap, const Lattice &lattice, const SkRect &dst, const SkPaint *paint=nullptr) |
Draw the bitmap stretched or shrunk differentially to fit into dst. More... | |
void | drawImageLattice (const SkImage *image, const Lattice &lattice, const SkRect &dst, const SkPaint *paint=nullptr) |
void | drawText (const void *text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint &paint) |
Draw the text, with origin at (x,y), using the specified paint. More... | |
void | drawPosText (const void *text, size_t byteLength, const SkPoint pos[], const SkPaint &paint) |
Draw the text, with each character/glyph origin specified by the pos[] array. More... | |
void | drawPosTextH (const void *text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkPaint &paint) |
Draw the text, with each character/glyph origin specified by the x coordinate taken from the xpos[] array, and the y from the constY param. More... | |
void | drawTextOnPathHV (const void *text, size_t byteLength, const SkPath &path, SkScalar hOffset, SkScalar vOffset, const SkPaint &paint) |
Draw the text, with origin at (x,y), using the specified paint, along the specified path. More... | |
void | drawTextOnPath (const void *text, size_t byteLength, const SkPath &path, const SkMatrix *matrix, const SkPaint &paint) |
Draw the text, with origin at (x,y), using the specified paint, along the specified path. More... | |
void | drawTextRSXform (const void *text, size_t byteLength, const SkRSXform[], const SkRect *cullRect, const SkPaint &paint) |
Draw the text with each character/glyph individually transformed by its xform. More... | |
void | drawTextBlob (const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint) |
Draw the text blob, offset by (x,y), using the specified paint. More... | |
void | drawTextBlob (const sk_sp< SkTextBlob > &blob, SkScalar x, SkScalar y, const SkPaint &paint) |
void | drawPicture (const SkPicture *picture) |
Draw the picture into this canvas. More... | |
void | drawPicture (const sk_sp< SkPicture > &picture) |
void | drawPicture (const SkPicture *, const SkMatrix *matrix, const SkPaint *paint) |
Draw the picture into this canvas. More... | |
void | drawPicture (const sk_sp< SkPicture > &picture, const SkMatrix *matrix, const SkPaint *paint) |
void | drawVertices (VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], SkXfermode *xmode, const uint16_t indices[], int indexCount, const SkPaint &paint) |
Draw the array of vertices, interpreted as triangles (based on mode). More... | |
void | drawVertices (VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], const sk_sp< SkXfermode > &xmode, const uint16_t indices[], int indexCount, const SkPaint &paint) |
void | drawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkXfermode *xmode, const SkPaint &paint) |
Draw a cubic coons patch. More... | |
void | drawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], const sk_sp< SkXfermode > &xmode, const SkPaint &paint) |
void | drawAtlas (const SkImage *atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkXfermode::Mode, const SkRect *cullRect, const SkPaint *paint) |
Draw a set of sprites from the atlas. More... | |
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[], const SkColor colors[], int count, SkXfermode::Mode mode, const SkRect *cull, 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 *=NULL) |
Draw the contents of this drawable into the canvas. More... | |
void | drawDrawable (SkDrawable *, SkScalar x, SkScalar y) |
void | drawAnnotation (const SkRect &, const char key[], SkData *value) |
Send an "annotation" to the canvas. More... | |
void | drawAnnotation (const SkRect &rect, const char key[], const sk_sp< SkData > &value) |
virtual bool | isClipEmpty () const |
Return true if the current clip is empty (i.e. More... | |
virtual bool | isClipRect () const |
Returns true if the current clip is just a (non-empty) rectangle. More... | |
const SkMatrix & | getTotalMatrix () const |
Return the current matrix on the canvas. More... | |
const SkClipStack * | getClipStack () const |
Return the clip stack. More... | |
void | replayClips (ClipVisitor *) const |
Replays the clip operations, back to front, that have been applied to the canvas, calling the appropriate method on the visitor for each clip. More... | |
GrDrawContext * | internal_private_accessTopLayerDrawContext () |
void | legacy_drawImageRect (const SkImage *image, const SkRect *src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint) |
void | legacy_drawBitmapRect (const SkBitmap &bitmap, const SkRect *src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint constraint=kStrict_SrcRectConstraint) |
void | temporary_internal_describeTopLayer (SkMatrix *matrix, SkIRect *clip_bounds) |
Returns CTM and clip bounds, translated from canvas coordinates to top layer coordinates. | |
Public Member Functions inherited from SkRefCntBase | |
SkRefCntBase () | |
Default construct, initializing the reference count to 1. | |
virtual | ~SkRefCntBase () |
Destruct, asserting that the reference count is 1. | |
int32_t | getRefCnt () const |
Return the reference count. More... | |
void | validate () const |
bool | unique () const |
May return true if the caller is the only owner. More... | |
void | ref () const |
Increment the reference count. More... | |
void | unref () const |
Decrement the reference count. More... | |
Static Public Member Functions | |
static SkCanvas * | NewRasterDirect (const SkImageInfo &, void *, size_t) |
Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the specified pixels. More... | |
static SkCanvas * | NewRasterDirectN32 (int width, int height, SkPMColor *pixels, size_t rowBytes) |
static void | Internal_Private_SetIgnoreSaveLayerBounds (bool) |
static bool | Internal_Private_GetIgnoreSaveLayerBounds () |
static void | Internal_Private_SetTreatSpriteAsBitmap (bool) |
static bool | Internal_Private_GetTreatSpriteAsBitmap () |
Protected Types | |
enum | SaveLayerStrategy { kFullLayer_SaveLayerStrategy, kNoLayer_SaveLayerStrategy } |
enum | ClipEdgeStyle { kHard_ClipEdgeStyle, kSoft_ClipEdgeStyle } |
Protected Member Functions | |
SkBaseDevice * | getDevice () const |
DEPRECATED. More... | |
virtual sk_sp< SkSurface > | onNewSurface (const SkImageInfo &, const SkSurfaceProps &) |
virtual bool | onPeekPixels (SkPixmap *) |
virtual bool | onAccessTopLayerPixels (SkPixmap *) |
virtual SkImageInfo | onImageInfo () const |
virtual bool | onGetProps (SkSurfaceProps *) const |
virtual void | onFlush () |
virtual void | willSave () |
virtual SaveLayerStrategy | getSaveLayerStrategy (const SaveLayerRec &) |
virtual void | willRestore () |
virtual void | didRestore () |
virtual void | didConcat (const SkMatrix &) |
virtual void | didSetMatrix (const SkMatrix &) |
virtual void | didTranslate (SkScalar dx, SkScalar dy) |
virtual void | onDrawAnnotation (const SkRect &, const char key[], SkData *value) |
virtual void | onDrawDRRect (const SkRRect &, const SkRRect &, const SkPaint &) |
virtual void | onDrawText (const void *text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint &paint) |
virtual void | onDrawPosText (const void *text, size_t byteLength, const SkPoint pos[], const SkPaint &paint) |
virtual void | onDrawPosTextH (const void *text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkPaint &paint) |
virtual void | onDrawTextOnPath (const void *text, size_t byteLength, const SkPath &path, const SkMatrix *matrix, const SkPaint &paint) |
virtual void | onDrawTextRSXform (const void *text, size_t byteLength, const SkRSXform[], const SkRect *cullRect, const SkPaint &paint) |
virtual void | onDrawTextBlob (const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint) |
virtual void | onDrawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkXfermode *xmode, const SkPaint &paint) |
virtual void | onDrawDrawable (SkDrawable *, const SkMatrix *) |
virtual void | onDrawPaint (const SkPaint &) |
virtual void | onDrawRect (const SkRect &, const SkPaint &) |
virtual void | onDrawOval (const SkRect &, const SkPaint &) |
virtual void | onDrawArc (const SkRect &, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &) |
virtual void | onDrawRRect (const SkRRect &, const SkPaint &) |
virtual void | onDrawPoints (PointMode, size_t count, const SkPoint pts[], const SkPaint &) |
virtual void | onDrawVertices (VertexMode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], SkXfermode *, const uint16_t indices[], int indexCount, const SkPaint &) |
virtual void | onDrawAtlas (const SkImage *, const SkRSXform[], const SkRect[], const SkColor[], int count, SkXfermode::Mode, const SkRect *cull, const SkPaint *) |
virtual void | onDrawPath (const SkPath &, const SkPaint &) |
virtual void | onDrawImage (const SkImage *, SkScalar dx, SkScalar dy, const SkPaint *) |
virtual void | onDrawImageRect (const SkImage *, const SkRect *, const SkRect &, const SkPaint *, SrcRectConstraint) |
virtual void | onDrawImageNine (const SkImage *, const SkIRect ¢er, const SkRect &dst, const SkPaint *) |
virtual void | onDrawImageLattice (const SkImage *, const Lattice &lattice, const SkRect &dst, const SkPaint *) |
virtual void | onDrawBitmap (const SkBitmap &, SkScalar dx, SkScalar dy, const SkPaint *) |
virtual void | onDrawBitmapRect (const SkBitmap &, const SkRect *, const SkRect &, const SkPaint *, SrcRectConstraint) |
virtual void | onDrawBitmapNine (const SkBitmap &, const SkIRect ¢er, const SkRect &dst, const SkPaint *) |
virtual void | onDrawBitmapLattice (const SkBitmap &, const Lattice &lattice, const SkRect &dst, const SkPaint *) |
virtual void | onClipRect (const SkRect &rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) |
virtual void | onClipRRect (const SkRRect &rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) |
virtual void | onClipPath (const SkPath &path, SkRegion::Op op, ClipEdgeStyle edgeStyle) |
virtual void | onClipRegion (const SkRegion &deviceRgn, SkRegion::Op op) |
virtual void | onDiscard () |
virtual void | onDrawPicture (const SkPicture *, const SkMatrix *, const SkPaint *) |
virtual SkCanvas * | canvasForDrawIter () |
bool | clipRectBounds (const SkRect *bounds, SaveLayerFlags, SkIRect *intersection, const SkImageFilter *imageFilter=NULL) |
Protected Member Functions inherited from SkRefCntBase | |
void | internal_dispose_restore_refcnt_to_1 () const |
Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g. More... | |
Private Types | |
enum | PrivateSaveLayerFlags { kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31 } |
enum | ShaderOverrideOpacity { kNone_ShaderOverrideOpacity, kOpaque_ShaderOverrideOpacity, kNotOpaque_ShaderOverrideOpacity } |
enum | { kMCRecSize = 128, kMCRecCount = 32, kDeviceCMSize = 176 } |
enum | InitFlags { kDefault_InitFlags = 0, kConservativeRasterClip_InitFlag = 1 << 0 } |
typedef SkRefCnt | INHERITED |
Private Member Functions | |
SkBaseDevice * | getTopDevice (bool updateMatrixClip=false) const |
saveLayer() can create another device (which is later drawn onto the previous device). More... | |
void | predrawNotify (bool willOverwritesEntireSurface=false) |
void | predrawNotify (const SkRect *rect, const SkPaint *paint, ShaderOverrideOpacity) |
void | predrawNotify (const SkRect *rect, const SkPaint *paint, bool shaderOverrideIsOpaque) |
SkSurface_Base * | getSurfaceBase () const |
void | setSurfaceBase (SkSurface_Base *sb) |
void | updateDeviceCMCache () |
void | doSave () |
void | checkForDeferredSave () |
void | internalSetMatrix (const SkMatrix &) |
SkCanvas (const SkIRect &bounds, InitFlags) | |
SkCanvas (SkBaseDevice *device, InitFlags) | |
void | resetForNextPicture (const SkIRect &bounds) |
void | setupDevice (SkBaseDevice *) |
SkBaseDevice * | init (SkBaseDevice *, InitFlags) |
SkIRect | getTopLayerBounds () const |
Gets the bounds of the top level layer in global canvas coordinates. More... | |
void | internalDrawBitmapRect (const SkBitmap &bitmap, const SkRect *src, const SkRect &dst, const SkPaint *paint, SrcRectConstraint) |
void | internalDrawPaint (const SkPaint &paint) |
void | internalSaveLayer (const SaveLayerRec &, SaveLayerStrategy) |
void | internalDrawDevice (SkBaseDevice *, int x, int y, const SkPaint *) |
void | internalSave () |
void | internalRestore () |
const SkRegion & | internal_private_getTotalClip () const |
bool | wouldOverwriteEntireSurface (const SkRect *, const SkPaint *, ShaderOverrideOpacity) const |
bool | canDrawBitmapAsSprite (SkScalar x, SkScalar y, int w, int h, const SkPaint &) |
Returns true if the paint's imagefilter can be invoked directly, without needed a layer. | |
void | validateClip () const |
Static Private Member Functions | |
static bool | BoundsAffectsClip (SaveLayerFlags) |
static SaveLayerFlags | LegacySaveFlagsToSaveLayerFlags (uint32_t legacySaveFlags) |
static void | DrawDeviceWithFilter (SkBaseDevice *src, const SkImageFilter *filter, SkBaseDevice *dst, const SkMatrix &ctm, const SkClipStack *clipStack) |
static void | DrawRect (const SkDraw &draw, const SkPaint &paint, const SkRect &r, SkScalar textSize) |
static void | DrawTextDecorations (const SkDraw &draw, const SkPaint &paint, const char text[], size_t byteLength, SkScalar x, SkScalar y) |
Private Attributes | |
SkAutoTUnref< SkClipStack > | fClipStack |
SkDeque | fMCStack |
MCRec * | fMCRec |
intptr_t | fMCRecStorage [kMCRecSize *kMCRecCount/sizeof(intptr_t)] |
intptr_t | fDeviceCMStorage [kDeviceCMSize/sizeof(intptr_t)] |
const SkSurfaceProps | fProps |
int | fSaveCount |
SkMetaData * | fMetaData |
SkSurface_Base * | fSurfaceBase |
bool | fDeviceCMDirty |
bool | fIsScaleTranslate |
Keep track of the device clip bounds and if the matrix is scale-translate. More... | |
SkRect | fDeviceClipBounds |
bool | fAllowSoftClip |
bool | fAllowSimplifyClip |
const bool | fConservativeRasterClip |
A Canvas encapsulates all of the state about drawing into a device (bitmap).
This includes a reference to the device itself, and a stack of matrix/clip values. For any given draw call (e.g. drawRect), the geometry of the object being drawn is transformed by the concatenation of all the matrices in the stack. The transformed geometry is clipped by the intersection of all of the clips in the stack.
While the Canvas holds the state of the drawing device, the state (style) of the object being drawn is held by the Paint, which is provided as a parameter to each of the draw() methods. The Paint holds attributes such as color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), etc.
enum SkCanvas::PointMode |
|
private |
Controls the behavior at the edge of the src-rect, when specified in drawImageRect, trading off speed for exactness.
When filtering is enabled (in the Paint), skia may need to sample in a neighborhood around the pixels in the image. If there is a src-rect specified, it is intended to restrict the pixels that will be read. However, for performance reasons, some implementations may slow down if they cannot read 1-pixel past the src-rect boundary at times.
This enum allows the caller to specify if such a 1-pixel "slop" will be visually acceptable. If it is, the caller should pass kFast, and it may result in a faster draw. If the src-rect must be strictly respected, the caller should pass kStrict.
SkCanvas::SkCanvas | ( | int | width, |
int | height, | ||
const SkSurfaceProps * | = NULL |
||
) |
Creates a canvas of the specified dimensions, but explicitly not backed by any device/pixels.
Typically this use used by subclasses who handle the draw calls in some other way.
|
explicit |
Construct a canvas with the specified device to draw into.
device | Specifies a device for the canvas to draw into. |
|
explicit |
Construct a canvas with the specified bitmap to draw into.
bitmap | Specifies a bitmap for the canvas to draw into. Its structure are copied to the canvas. |
SkCanvas::SkCanvas | ( | const SkBitmap & | bitmap, |
const SkSurfaceProps & | props | ||
) |
Construct a canvas with the specified bitmap to draw into.
bitmap | Specifies a bitmap for the canvas to draw into. Its structure are copied to the canvas. |
props | New canvas surface properties. |
void* SkCanvas::accessTopLayerPixels | ( | SkImageInfo * | info, |
size_t * | rowBytes, | ||
SkIPoint * | origin = NULL |
||
) |
If the canvas has writable pixels in its top layer (and is not recording to a picture or other non-raster target) and has direct access to its pixels (i.e.
they are in local RAM) return the address of those pixels, and if not null, return the ImageInfo, rowBytes and origin. The returned address is only valid while the canvas object is in scope and unchanged. Any API calls made on canvas (or its parent surface if any) will invalidate the returned address (and associated information).
On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
void SkCanvas::clipPath | ( | const SkPath & | path, |
SkRegion::Op | op = SkRegion::kIntersect_Op , |
||
bool | doAntiAlias = false |
||
) |
Modify the current clip with the specified path.
path | The path to combine with the current clip |
op | The region op to apply to the current clip |
doAntiAlias | true if the clip should be antialiased |
void SkCanvas::clipRect | ( | const SkRect & | rect, |
SkRegion::Op | op = SkRegion::kIntersect_Op , |
||
bool | doAntiAlias = false |
||
) |
Modify the current clip with the specified rectangle.
rect | The rect to combine with the current clip |
op | The region op to apply to the current clip |
doAntiAlias | true if the clip should be antialiased |
void SkCanvas::clipRegion | ( | const SkRegion & | deviceRgn, |
SkRegion::Op | op = SkRegion::kIntersect_Op |
||
) |
Modify the current clip with the specified region.
Note that unlike clipRect() and clipPath() which transform their arguments by the current matrix, clipRegion() assumes its argument is already in device coordinates, and so no transformation is performed.
deviceRgn | The region to apply to the current clip |
op | The region op to apply to the current clip |
void SkCanvas::clipRRect | ( | const SkRRect & | rrect, |
SkRegion::Op | op = SkRegion::kIntersect_Op , |
||
bool | doAntiAlias = false |
||
) |
Modify the current clip with the specified SkRRect.
rrect | The rrect to combine with the current clip |
op | The region op to apply to the current clip |
doAntiAlias | true if the clip should be antialiased |
void SkCanvas::concat | ( | const SkMatrix & | matrix | ) |
Preconcat the current matrix with the specified matrix.
matrix | The matrix to preconcatenate with the current matrix |
|
inline |
This makes the contents of the canvas undefined.
Subsequent calls that require reading the canvas contents will produce undefined results. Examples include blending and readPixels. The actual implementation is backend- dependent and one legal implementation is to do nothing. This method ignores the current clip.
This function should only be called if the caller intends to subsequently draw to the canvas. The canvas may do real work at discard() time in order to optimize performance on subsequent draws. Thus, if you call this and then never draw to the canvas subsequently you may pay a perfomance penalty.
Send an "annotation" to the canvas.
The annotation is a key/value pair, where the key is a null-terminated utf8 string, and the value is a blob of data stored in an SkData (which may be null). The annotation is associated with the specified rectangle.
The caller still retains its ownership of the data (if any).
Note: on may canvas types, this information is ignored, but some canvases (e.g. recording a picture or drawing to a PDF document) will pass on this information.
void SkCanvas::drawArc | ( | const SkRect & | oval, |
SkScalar | startAngle, | ||
SkScalar | sweepAngle, | ||
bool | useCenter, | ||
const SkPaint & | paint | ||
) |
Draw the specified arc, which will be scaled to fit inside the specified oval.
If the sweep angle is >= 360, then the oval is drawn completely. Note that this differs slightly from SkPath::arcTo, which treats the sweep angle mod 360.
oval | The bounds of oval used to define the shape of the arc. |
startAngle | Starting angle (in degrees) where the arc begins |
sweepAngle | Sweep angle (in degrees) measured clockwise. |
useCenter | true means include the center of the oval. For filling this will draw a wedge. False means just use the arc. |
paint | The paint used to draw the arc |
void SkCanvas::drawARGB | ( | U8CPU | a, |
U8CPU | r, | ||
U8CPU | g, | ||
U8CPU | b, | ||
SkXfermode::Mode | mode = SkXfermode::kSrcOver_Mode |
||
) |
Fill the entire canvas' bitmap (restricted to the current clip) with the specified ARGB color, using the specified mode.
a | the alpha component (0..255) of the color to fill the canvas |
r | the red component (0..255) of the color to fill the canvas |
g | the green component (0..255) of the color to fill the canvas |
b | the blue component (0..255) of the color to fill the canvas |
mode | the mode to apply the color in (defaults to SrcOver) |
void SkCanvas::drawAtlas | ( | const SkImage * | atlas, |
const SkRSXform | xform[], | ||
const SkRect | tex[], | ||
const SkColor | colors[], | ||
int | count, | ||
SkXfermode::Mode | , | ||
const SkRect * | cullRect, | ||
const SkPaint * | paint | ||
) |
Draw a set of sprites from the atlas.
Each is specified by a tex rectangle in the coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle into a quad.
xform maps [0, 0, tex.width, tex.height] -> quad
The color array is optional. When specified, each color modulates the pixels in its corresponding quad (via the specified SkXfermode::Mode).
The cullRect is optional. When specified, it must be a conservative bounds of all of the resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not intersect the current clip.
The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter and xfermode are used to affect each of the quads.
void SkCanvas::drawBitmap | ( | const SkBitmap & | bitmap, |
SkScalar | left, | ||
SkScalar | top, | ||
const SkPaint * | paint = NULL |
||
) |
Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.
Note: if the paint contains a maskfilter that generates a mask which extends beyond the bitmap's original width/height, then the bitmap will be drawn as if it were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be the edge color replicated.
If a shader is present on the paint it will be ignored, except in the case where the bitmap is kAlpha_8_SkColorType. In that case, the color is generated by the shader.
bitmap | The bitmap to be drawn |
left | The position of the left side of the bitmap being drawn |
top | The position of the top side of the bitmap being drawn |
paint | The paint used to draw the bitmap, or NULL |
void SkCanvas::drawBitmapLattice | ( | const SkBitmap & | bitmap, |
const Lattice & | lattice, | ||
const SkRect & | dst, | ||
const SkPaint * | paint = nullptr |
||
) |
Draw the bitmap stretched or shrunk differentially to fit into dst.
Moving horizontally across the bitmap, alternating rects will be "scalable" (in the x-dimension) to fit into dst or must be left "fixed". The first rect is treated as "fixed", but it's possible to specify an empty first rect by making lattice.fXDivs[0] = 0.
The scale factor for all "scalable" rects will be the same, and may be greater than or less than 1 (meaning we can stretch or shrink). If the number of "fixed" pixels is greater than the width of the dst, we will collapse all of the "scalable" regions and appropriately downscale the "fixed" regions.
The same interpretation also applies to the y-dimension.
void SkCanvas::drawBitmapNine | ( | const SkBitmap & | bitmap, |
const SkIRect & | center, | ||
const SkRect & | dst, | ||
const SkPaint * | paint = NULL |
||
) |
Draw the bitmap stretched or shrunk differentially to fit into dst.
center is a rect within the bitmap, and logically divides the bitmap into 9 sections (3x3). For example, if the middle pixel of a [5x5] bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
If the dst is >= the bitmap size, then...
void SkCanvas::drawBitmapRect | ( | const SkBitmap & | bitmap, |
const SkRect & | src, | ||
const SkRect & | dst, | ||
const SkPaint * | paint, | ||
SrcRectConstraint | = kStrict_SrcRectConstraint |
||
) |
Draw the specified bitmap, scaling and translating so that it fills the specified dst rect.
If the src rect is non-null, only that subset of the bitmap is transformed and drawn.
bitmap | The bitmap to be drawn |
src | Optional: specify the subset of the bitmap to be drawn |
dst | The destination rectangle where the scaled/translated bitmap will be drawn |
paint | The paint used to draw the bitmap, or NULL |
constraint | Control the tradeoff between speed and exactness w.r.t. the src-rect. |
void SkCanvas::drawCircle | ( | SkScalar | cx, |
SkScalar | cy, | ||
SkScalar | radius, | ||
const SkPaint & | paint | ||
) |
Draw the specified circle using the specified paint.
If radius is <= 0, then nothing will be drawn. The circle will be filled or framed based on the Style in the paint.
cx | The x-coordinate of the center of the cirle to be drawn |
cy | The y-coordinate of the center of the cirle to be drawn |
radius | The radius of the cirle to be drawn |
paint | The paint used to draw the circle |
void SkCanvas::drawColor | ( | SkColor | color, |
SkXfermode::Mode | mode = SkXfermode::kSrcOver_Mode |
||
) |
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and mode.
color | the color to draw with |
mode | the mode to apply the color in (defaults to SrcOver) |
void SkCanvas::drawDrawable | ( | SkDrawable * | drawable, |
const SkMatrix * | = NULL |
||
) |
Draw the contents of this drawable into the canvas.
If the canvas is async (e.g. it is recording into a picture) then the drawable will be referenced instead, to have its draw() method called when the picture is finalized.
If the intent is to force the contents of the drawable into this canvas immediately, then drawable->draw(canvas) may be called.
Draw the annulus formed by the outer and inner rrects.
The results are undefined if the outer does not contain the inner.
void SkCanvas::drawImage | ( | const SkImage * | image, |
SkScalar | left, | ||
SkScalar | top, | ||
const SkPaint * | paint = NULL |
||
) |
Draw the specified image, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.
image | The image to be drawn |
left | The position of the left side of the image being drawn |
top | The position of the top side of the image being drawn |
paint | The paint used to draw the image, or NULL |
void SkCanvas::drawImageNine | ( | const SkImage * | , |
const SkIRect & | center, | ||
const SkRect & | dst, | ||
const SkPaint * | paint = nullptr |
||
) |
Draw the image stretched differentially to fit into dst.
center is a rect within the image, and logically divides the image into 9 sections (3x3). For example, if the middle pixel of a [5x5] image is the "center", then the center-rect should be [2, 2, 3, 3].
If the dst is >= the image size, then...
void SkCanvas::drawImageRect | ( | const SkImage * | image, |
const SkRect & | src, | ||
const SkRect & | dst, | ||
const SkPaint * | paint, | ||
SrcRectConstraint | constraint = kStrict_SrcRectConstraint |
||
) |
Draw the specified image, scaling and translating so that it fills the specified dst rect.
If the src rect is non-null, only that subset of the image is transformed and drawn.
image | The image to be drawn |
src | Optional: specify the subset of the image to be drawn |
dst | The destination rectangle where the scaled/translated image will be drawn |
paint | The paint used to draw the image, or NULL |
constraint | Control the tradeoff between speed and exactness w.r.t. the src-rect. |
Draw the specified rectangle using the specified paint.
The rectangle will be filled or framed based on the Style in the paint.
rect | The rect to be drawn |
paint | The paint used to draw the rect |
void SkCanvas::drawLine | ( | SkScalar | x0, |
SkScalar | y0, | ||
SkScalar | x1, | ||
SkScalar | y1, | ||
const SkPaint & | paint | ||
) |
Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.
NOTE: since a line is always "framed", the paint's Style is ignored.
x0 | The x-coordinate of the start point of the line |
y0 | The y-coordinate of the start point of the line |
x1 | The x-coordinate of the end point of the line |
y1 | The y-coordinate of the end point of the line |
paint | The paint used to draw the line |
Draw the specified oval using the specified paint.
The oval will be filled or framed based on the Style in the paint.
oval | The rectangle bounds of the oval to be drawn |
paint | The paint used to draw the oval |
void SkCanvas::drawPaint | ( | const SkPaint & | paint | ) |
Fill the entire canvas (restricted to the current clip) with the specified paint.
paint | The paint used to fill the canvas |
void SkCanvas::drawPatch | ( | const SkPoint | cubics[12], |
const SkColor | colors[4], | ||
const SkPoint | texCoords[4], | ||
SkXfermode * | xmode, | ||
const SkPaint & | paint | ||
) |
Draw a cubic coons patch.
cubic | specifies the 4 bounding cubic bezier curves of a patch with clockwise order starting at the top left corner. |
colors | specifies the colors for the corners which will be bilerp across the patch, their order is clockwise starting at the top left corner. |
texCoords | specifies the texture coordinates that will be bilerp across the patch, their order is the same as the colors. |
xmode | specifies how are the colors and the textures combined if both of them are present. |
paint | Specifies the shader/texture if present. |
Draw the specified path using the specified paint.
The path will be filled or framed based on the Style in the paint.
path | The path to be drawn |
paint | The paint used to draw the path |
|
inline |
Draw the picture into this canvas.
This method effective brackets the playback of the picture's draw calls with save/restore, so the state of this canvas will be unchanged after this call.
picture | The recorded drawing commands to playback into this canvas. |
Draw the picture into this canvas.
If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is logically equivalent to save/concat/drawPicture/restore
If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. This is logically equivalent to saveLayer(paint)/drawPicture/restore
void SkCanvas::drawPoint | ( | SkScalar | x, |
SkScalar | y, | ||
const SkPaint & | paint | ||
) |
Helper method for drawing a single point.
See drawPoints() for a more details.
void SkCanvas::drawPoint | ( | SkScalar | x, |
SkScalar | y, | ||
SkColor | color | ||
) |
Draws a single pixel in the specified color.
x | The X coordinate of which pixel to draw |
y | The Y coordiante of which pixel to draw |
color | The color to draw |
void SkCanvas::drawPoints | ( | PointMode | mode, |
size_t | count, | ||
const SkPoint | pts[], | ||
const SkPaint & | paint | ||
) |
Draw a series of points, interpreted based on the PointMode mode.
For all modes, the count parameter is interpreted as the total number of points. For kLine mode, count/2 line segments are drawn. For kPoint mode, each point is drawn centered at its coordinate, and its size is specified by the paint's stroke-width. It draws as a square, unless the paint's cap-type is round, in which the points are drawn as circles. For kLine mode, each pair of points is drawn as a line segment, respecting the paint's settings for cap/join/width. For kPolygon mode, the entire array is drawn as a series of connected line segments. Note that, while similar, kLine and kPolygon modes draw slightly differently than the equivalent path built with a series of moveto, lineto calls, in that the path will draw all of its contours at once, with no interactions if contours intersect each other (think XOR xfermode). drawPoints always draws each element one at a time.
mode | PointMode specifying how to draw the array of points. |
count | The number of points in the array |
pts | Array of points to draw |
paint | The paint used to draw the points |
void SkCanvas::drawPosText | ( | const void * | text, |
size_t | byteLength, | ||
const SkPoint | pos[], | ||
const SkPaint & | paint | ||
) |
Draw the text, with each character/glyph origin specified by the pos[] array.
The origin is interpreted by the Align setting in the paint.
text | The text to be drawn |
byteLength | The number of bytes to read from the text parameter |
pos | Array of positions, used to position each character |
paint | The paint used for the text (e.g. color, size, style) |
void SkCanvas::drawPosTextH | ( | const void * | text, |
size_t | byteLength, | ||
const SkScalar | xpos[], | ||
SkScalar | constY, | ||
const SkPaint & | paint | ||
) |
Draw the text, with each character/glyph origin specified by the x coordinate taken from the xpos[] array, and the y from the constY param.
The origin is interpreted by the Align setting in the paint.
text | The text to be drawn |
byteLength | The number of bytes to read from the text parameter |
xpos | Array of x-positions, used to position each character |
constY | The shared Y coordinate for all of the positions |
paint | The paint used for the text (e.g. color, size, style) |
Draw the specified rectangle using the specified paint.
The rectangle will be filled or stroked based on the Style in the paint.
rect | The rect to be drawn |
paint | The paint used to draw the rect |
void SkCanvas::drawRectCoords | ( | SkScalar | left, |
SkScalar | top, | ||
SkScalar | right, | ||
SkScalar | bottom, | ||
const SkPaint & | paint | ||
) |
Draw the specified rectangle using the specified paint.
The rectangle will be filled or framed based on the Style in the paint.
left | The left side of the rectangle to be drawn |
top | The top side of the rectangle to be drawn |
right | The right side of the rectangle to be drawn |
bottom | The bottom side of the rectangle to be drawn |
paint | The paint used to draw the rect |
void SkCanvas::drawRoundRect | ( | const SkRect & | rect, |
SkScalar | rx, | ||
SkScalar | ry, | ||
const SkPaint & | paint | ||
) |
Draw the specified round-rect using the specified paint.
The round-rect will be filled or framed based on the Style in the paint.
rect | The rectangular bounds of the roundRect to be drawn |
rx | The x-radius of the oval used to round the corners |
ry | The y-radius of the oval used to round the corners |
paint | The paint used to draw the roundRect |
Draw the specified RRect using the specified paint The rrect will be filled or stroked based on the Style in the paint.
rrect | The round-rect to draw |
paint | The paint used to draw the round-rect |
void SkCanvas::drawText | ( | const void * | text, |
size_t | byteLength, | ||
SkScalar | x, | ||
SkScalar | y, | ||
const SkPaint & | paint | ||
) |
Draw the text, with origin at (x,y), using the specified paint.
The origin is interpreted based on the Align setting in the paint.
text | The text to be drawn |
byteLength | The number of bytes to read from the text parameter |
x | The x-coordinate of the origin of the text being drawn |
y | The y-coordinate of the origin of the text being drawn |
paint | The paint used for the text (e.g. color, size, style) |
void SkCanvas::drawTextBlob | ( | const SkTextBlob * | blob, |
SkScalar | x, | ||
SkScalar | y, | ||
const SkPaint & | paint | ||
) |
Draw the text blob, offset by (x,y), using the specified paint.
blob | The text blob to be drawn |
x | The x-offset of the text being drawn |
y | The y-offset of the text being drawn |
paint | The paint used for the text (e.g. color, size, style) |
void SkCanvas::drawTextOnPath | ( | const void * | text, |
size_t | byteLength, | ||
const SkPath & | path, | ||
const SkMatrix * | matrix, | ||
const SkPaint & | paint | ||
) |
Draw the text, with origin at (x,y), using the specified paint, along the specified path.
The paint's Align setting determins where along the path to start the text.
text | The text to be drawn |
byteLength | The number of bytes to read from the text parameter |
path | The path the text should follow for its baseline |
matrix | (may be null) Applied to the text before it is mapped onto the path |
paint | The paint used for the text |
void SkCanvas::drawTextOnPathHV | ( | const void * | text, |
size_t | byteLength, | ||
const SkPath & | path, | ||
SkScalar | hOffset, | ||
SkScalar | vOffset, | ||
const SkPaint & | paint | ||
) |
Draw the text, with origin at (x,y), using the specified paint, along the specified path.
The paint's Align setting determins where along the path to start the text.
text | The text to be drawn |
byteLength | The number of bytes to read from the text parameter |
path | The path the text should follow for its baseline |
hOffset | The distance along the path to add to the text's starting position |
vOffset | The distance above(-) or below(+) the path to position the text |
paint | The paint used for the text |
void SkCanvas::drawTextRSXform | ( | const void * | text, |
size_t | byteLength, | ||
const SkRSXform | [], | ||
const SkRect * | cullRect, | ||
const SkPaint & | paint | ||
) |
Draw the text with each character/glyph individually transformed by its xform.
If cullRect is not null, it is a conservative bounds of what will be drawn taking into account the xforms and the paint, and will be used to accelerate culling.
void SkCanvas::drawVertices | ( | VertexMode | vmode, |
int | vertexCount, | ||
const SkPoint | vertices[], | ||
const SkPoint | texs[], | ||
const SkColor | colors[], | ||
SkXfermode * | xmode, | ||
const uint16_t | indices[], | ||
int | indexCount, | ||
const SkPaint & | paint | ||
) |
Draw the array of vertices, interpreted as triangles (based on mode).
If both textures and vertex-colors are NULL, it strokes hairlines with the paint's color. This behavior is a useful debugging mode to visualize the mesh.
vmode | How to interpret the array of vertices |
vertexCount | The number of points in the vertices array (and corresponding texs and colors arrays if non-null) |
vertices | Array of vertices for the mesh |
texs | May be null. If not null, specifies the coordinate in texture space (not uv space) for each vertex. |
colors | May be null. If not null, specifies a color for each vertex, to be interpolated across the triangle. |
xmode | Used if both texs and colors are present. In this case the colors are combined with the texture using mode, before being drawn using the paint. If mode is null, then kModulate_Mode is used. |
indices | If not null, array of indices to reference into the vertex (texs, colors) array. |
indexCount | number of entries in the indices array (if not null) |
paint | Specifies the shader/texture if present. |
void SkCanvas::flush | ( | ) |
Trigger the immediate execution of all pending draw operations.
For the GPU backend this will resolve all rendering to the GPU surface backing the SkSurface that owns this canvas.
|
virtual |
Gets the size of the base or root layer in global canvas coordinates.
The origin of the base layer is always (0,0). The current drawable area may be smaller (due to clipping or saveLayer).
|
virtual |
Return the bounds of the current clip (in local coordinates) in the bounds parameter, and return true if it is non-empty.
This can be useful in a way similar to quickReject, in that it tells you that drawing outside of these bounds will be clipped out.
|
virtual |
Return the bounds of the current clip, in device coordinates; returns true if non-empty.
Maybe faster than getting the clip explicitly and then taking its bounds.
|
inline |
Return the clip stack.
The clip stack stores all the individual clips organized by the save/restore frame in which they were added.
|
protected |
DEPRECATED.
Return the canvas' device object, which may be null. The device holds the bitmap of the pixels that the canvas draws into. The reference count of the returned device is not changed by this call.
GrContext* SkCanvas::getGrContext | ( | ) |
Return the GPU context of the device that is associated with the canvas.
For a canvas with non-GPU device, NULL is returned.
bool SkCanvas::getProps | ( | SkSurfaceProps * | ) | const |
If the canvas is backed by pixels (cpu or gpu), this writes a copy of the SurfaceProps for the canvas to the location supplied by the caller, and returns true.
Otherwise, return false and leave the supplied props unchanged.
int SkCanvas::getSaveCount | ( | ) | const |
|
private |
saveLayer() can create another device (which is later drawn onto the previous device).
getTopDevice() returns the top-most device current installed. Note that this can change on other calls like save/restore, so do not access this device after subsequent canvas calls. The reference count of the device is not changed.
updateMatrixClip | If this is true, then before the device is returned, we ensure that its has been notified about the current matrix and clip. Note: this happens automatically when the device is drawn to, but is optional here, as there is a small perf hit sometimes. |
|
private |
Gets the bounds of the top level layer in global canvas coordinates.
We don't want this to be public because it exposes decisions about layer sizes that are internal to the canvas.
const SkMatrix& SkCanvas::getTotalMatrix | ( | ) | const |
Return the current matrix on the canvas.
This does not account for the translate in any of the devices.
SkImageInfo SkCanvas::imageInfo | ( | ) | const |
Return ImageInfo for this canvas.
If the canvas is not backed by pixels (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
|
virtual |
Return true if the current clip is empty (i.e.
nothing will draw). Note: this is not always a free call, so it should not be used more often than necessary. However, once the canvas has computed this result, subsequent calls will be cheap (until the clip state changes, which can happen on any clip..() or restore() call.
|
virtual |
Returns true if the current clip is just a (non-empty) rectangle.
Returns false if the clip is empty, or if it is complex.
sk_sp<SkSurface> SkCanvas::makeSurface | ( | const SkImageInfo & | , |
const SkSurfaceProps * | = nullptr |
||
) |
Create a new surface matching the specified info, one that attempts to be maximally compatible when used with this canvas.
If there is no matching Surface type, NULL is returned.
If surfaceprops is specified, those are passed to the new surface, otherwise the new surface inherits the properties of the surface that owns this canvas. If this canvas has no parent surface, then the new surface is created with default properties.
|
static |
Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the specified pixels.
To access the pixels after drawing to them, the caller should call flush() or call peekPixels(...).
On failure, return NULL. This can fail for several reasons:
Note: it is valid to request a supported ImageInfo, but with zero dimensions.
bool SkCanvas::peekPixels | ( | SkPixmap * | ) |
If the canvas has readable pixels in its base layer (and is not recording to a picture or other non-raster target) and has direct access to its pixels (i.e.
they are in local RAM) return true, and if not null, return in the pixmap parameter information about the pixels. The pixmap's pixel address is only valid while the canvas object is in scope and unchanged. Any API calls made on canvas (or its parent surface if any) will invalidate the pixel address (and associated information).
On failure, returns false and the pixmap parameter will be ignored.
bool SkCanvas::quickReject | ( | const SkRect & | rect | ) | const |
Return true if the specified rectangle, after being transformed by the current matrix, would lie completely outside of the current clip.
Call this to check if an area you intend to draw into is clipped out (and therefore you can skip making the draw calls).
rect | the rect to compare with the current clip |
bool SkCanvas::quickReject | ( | const SkPath & | path | ) | const |
Return true if the specified path, after being transformed by the current matrix, would lie completely outside of the current clip.
Call this to check if an area you intend to draw into is clipped out (and therefore you can skip making the draw calls). Note, for speed it may return false even if the path itself might not intersect the clip (i.e. the bounds of the path intersects, but the path does not).
path | The path to compare with the current clip |
bool SkCanvas::readPixels | ( | const SkImageInfo & | dstInfo, |
void * | dstPixels, | ||
size_t | dstRowBytes, | ||
int | srcX, | ||
int | srcY | ||
) |
Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes), converting them into the requested format (SkImageInfo).
The base-layer pixels are read starting at the specified (srcX,srcY) location in the coordinate system of the base-layer.
The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
srcR is intersected with the bounds of the base-layer. If this intersection is not empty, then we have two sets of pixels (of equal size). Replace the dst pixels with the corresponding src pixels, performing any colortype/alphatype transformations needed (in the case where the src and dst have different colortypes or alphatypes).
This call can fail, returning false, for several reasons:
bool SkCanvas::readPixels | ( | SkBitmap * | bitmap, |
int | srcX, | ||
int | srcY | ||
) |
Helper for calling readPixels(info, ...).
This call will check if bitmap has been allocated. If not, it will attempt to call allocPixels(). If this fails, it will return false. If not, it calls through to readPixels(info, ...) and returns its result.
Helper for allocating pixels and then calling readPixels(info, ...).
The bitmap is resized to the intersection of srcRect and the base-layer bounds. On success, pixels will be allocated in bitmap and true returned. On failure, false is returned and bitmap will be set to empty.
void SkCanvas::replayClips | ( | ClipVisitor * | ) | const |
Replays the clip operations, back to front, that have been applied to the canvas, calling the appropriate method on the visitor for each clip.
All clips have already been transformed into device space.
void SkCanvas::resetMatrix | ( | ) |
Helper for setMatrix(identity).
Sets the current matrix to identity.
void SkCanvas::restore | ( | ) |
void SkCanvas::restoreToCount | ( | int | saveCount | ) |
Efficient way to pop any calls to save() that happened after the save count reached saveCount.
It is an error for saveCount to be greater than getSaveCount(). To pop all the way back to the initial matrix/clip context pass saveCount == 1.
saveCount | The number of save() levels to restore from |
void SkCanvas::rotate | ( | SkScalar | degrees | ) |
Preconcat the current matrix with the specified rotation about the origin.
degrees | The amount to rotate, in degrees |
void SkCanvas::rotate | ( | SkScalar | degrees, |
SkScalar | px, | ||
SkScalar | py | ||
) |
Preconcat the current matrix with the specified rotation about a given point.
degrees | The amount to rotate, in degrees |
px | The x coordinate of the point to rotate about. |
py | The y coordinate of the point to rotate about. |
int SkCanvas::save | ( | ) |
This call saves the current matrix, clip, and drawFilter, and pushes a copy onto a private stack.
Subsequent calls to translate, scale, rotate, skew, concat or clipRect, clipPath, and setDrawFilter all operate on this copy. When the balancing call to restore() is made, the previous matrix, clip, and drawFilter are restored.
This behaves the same as save(), but in addition it allocates an offscreen bitmap.
All drawing calls are directed there, and only when the balancing call to restore() is made is that offscreen transfered to the canvas (or the previous layer).
bounds | (may be null) This rect, if non-null, is used as a hint to limit the size of the offscreen, and thus drawing may be clipped to it, though that clipping is not guaranteed to happen. If exact clipping is desired, use clipRect(). |
paint | (may be null) This is copied, and is applied to the offscreen when restore() is called |
This behaves the same as save(), but in addition it allocates an offscreen bitmap.
All drawing calls are directed there, and only when the balancing call to restore() is made is that offscreen transfered to the canvas (or the previous layer).
bounds | (may be null) This rect, if non-null, is used as a hint to limit the size of the offscreen, and thus drawing may be clipped to it, though that clipping is not guaranteed to happen. If exact clipping is desired, use clipRect(). |
alpha | This is applied to the offscreen when restore() is called. |
Temporary name.
Will allow any requests for LCD text to be respected, so the caller must be careful to only draw on top of opaque sections of the layer to get good results.
void SkCanvas::scale | ( | SkScalar | sx, |
SkScalar | sy | ||
) |
Preconcat the current matrix with the specified scale.
sx | The amount to scale in X |
sy | The amount to scale in Y |
|
inline |
Helper for clipRegion(rgn, kReplace_Op).
Sets the current clip to the specified region. This does not intersect or in any other way account for the existing clip region.
deviceRgn | The region to copy into the current clip. |
void SkCanvas::setMatrix | ( | const SkMatrix & | matrix | ) |
Replace the current matrix with a copy of the specified matrix.
matrix | The matrix that will be copied into the current matrix. |
void SkCanvas::skew | ( | SkScalar | sx, |
SkScalar | sy | ||
) |
Preconcat the current matrix with the specified skew.
sx | The amount to skew in X |
sy | The amount to skew in Y |
void SkCanvas::translate | ( | SkScalar | dx, |
SkScalar | dy | ||
) |
Preconcat the current matrix with the specified translation.
dx | The distance to translate in X |
dy | The distance to translate in Y |
bool SkCanvas::writePixels | ( | const SkImageInfo & | , |
const void * | pixels, | ||
size_t | rowBytes, | ||
int | x, | ||
int | y | ||
) |
This method affects the pixels in the base-layer, and operates in pixel coordinates, ignoring the matrix and clip.
The specified ImageInfo and (x,y) offset specifies a rectangle: target.
target.setXYWH(x, y, info.width(), info.height());
Target is intersected with the bounds of the base-layer. If this intersection is not empty, then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src pixels, performing any colortype/alphatype transformations needed (in the case where the src and dst have different colortypes or alphatypes).
This call can fail, returning false, for several reasons:
bool SkCanvas::writePixels | ( | const SkBitmap & | bitmap, |
int | x, | ||
int | y | ||
) |
Helper for calling writePixels(info, ...) by passing its pixels and rowbytes.
If the bitmap is just wrapping a texture, returns false and does nothing.
|
private |
Keep track of the device clip bounds and if the matrix is scale-translate.
This allows us to do a fast quick reject in the common case.