8 #ifndef SkCanvas_DEFINED
9 #define SkCanvas_DEFINED
18 #include "SkSurfaceProps.h"
19 #include "SkXfermode.h"
59 enum PrivateSaveLayerFlags {
60 kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31,
81 static SkCanvas* NewRasterDirectN32(
int width,
int height,
SkPMColor* pixels,
size_t rowBytes) {
148 virtual SkISize getBaseLayerSize()
const;
161 #ifndef SK_SUPPORT_LEGACY_GETDEVICE
166 SkBaseDevice* getDevice_just_for_deprecated_compatibility_testing()
const {
167 return this->getDevice();
183 #ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
186 SkBaseDevice* getTopDevice(
bool updateMatrixClip =
false)
const;
199 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
237 #ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS
238 const void* peekPixels(
SkImageInfo* info,
size_t* rowBytes);
260 bool readPixels(
const SkImageInfo& dstInfo,
void* dstPixels,
size_t dstRowBytes,
268 bool readPixels(
SkBitmap* bitmap,
int srcX,
int srcY);
296 bool writePixels(
const SkImageInfo&,
const void* pixels,
size_t rowBytes,
int x,
int y);
302 bool writePixels(
const SkBitmap& bitmap,
int x,
int y);
331 return this->saveLayer(&bounds, paint);
339 int saveLayerPreserveLCDTextRequests(
const SkRect* bounds,
const SkPaint* paint);
352 int saveLayerAlpha(
const SkRect* bounds,
U8CPU alpha);
355 kIsOpaque_SaveLayerFlag = 1 << 0,
356 kPreserveLCDText_SaveLayerFlag = 1 << 1,
358 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
359 kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
362 typedef uint32_t SaveLayerFlags;
366 : fBounds(
nullptr), fPaint(
nullptr), fBackdrop(
nullptr), fSaveLayerFlags(0)
372 , fSaveLayerFlags(saveLayerFlags)
375 SaveLayerFlags saveLayerFlags)
378 , fBackdrop(backdrop)
379 , fSaveLayerFlags(saveLayerFlags)
385 SaveLayerFlags fSaveLayerFlags;
401 int getSaveCount()
const;
409 void restoreToCount(
int saveCount);
415 void translate(SkScalar dx, SkScalar dy);
421 void scale(SkScalar sx, SkScalar sy);
426 void rotate(SkScalar degrees);
433 void rotate(SkScalar degrees, SkScalar px, SkScalar py);
439 void skew(SkScalar sx, SkScalar sy);
444 void concat(
const SkMatrix& matrix);
449 void setMatrix(
const SkMatrix& matrix);
455 #ifdef SK_EXPERIMENTAL_SHADOWING
461 void translateZ(SkScalar z);
479 void clipRect(
const SkRect& rect,
481 bool doAntiAlias =
false);
489 void clipRRect(
const SkRRect& rrect,
491 bool doAntiAlias =
false);
499 void clipPath(
const SkPath& path,
501 bool doAntiAlias =
false);
508 fAllowSoftClip = allow;
515 fAllowSimplifyClip = allow;
525 void clipRegion(
const SkRegion& deviceRgn,
545 bool quickReject(
const SkRect& rect)
const;
557 bool quickReject(
const SkPath& path)
const;
564 virtual bool getClipBounds(
SkRect* bounds)
const;
570 virtual bool getClipDeviceBounds(
SkIRect* bounds)
const;
618 void drawPaint(
const SkPaint& paint);
650 void drawPoints(PointMode mode,
size_t count,
const SkPoint pts[],
const SkPaint& paint);
655 void drawPoint(SkScalar x, SkScalar y,
const SkPaint& paint);
662 void drawPoint(SkScalar x, SkScalar y,
SkColor color);
673 void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
691 this->drawRect(r, paint);
702 void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
703 SkScalar bottom,
const SkPaint& paint);
735 void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
749 void drawArc(
const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
750 bool useCenter,
const SkPaint& paint);
759 void drawRoundRect(
const SkRect& rect, SkScalar rx, SkScalar ry,
777 void drawImage(
const SkImage* image, SkScalar left, SkScalar top,
const SkPaint* paint = NULL);
778 void drawImage(
const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
780 this->drawImage(image.get(), left, top, paint);
825 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
828 const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
831 SrcRectConstraint = kStrict_SrcRectConstraint);
835 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
836 this->drawImageRect(image.get(), src, dst, paint, constraint);
839 const SkPaint* paint, SrcRectConstraint cons = kStrict_SrcRectConstraint) {
840 this->drawImageRect(image.get(), isrc, dst, paint, cons);
843 SrcRectConstraint cons = kStrict_SrcRectConstraint) {
844 this->drawImageRect(image.get(), dst, paint, cons);
862 const SkPaint* paint =
nullptr);
864 const SkPaint* paint =
nullptr) {
865 this->drawImageNine(image.get(), center, dst, paint);
884 void drawBitmap(
const SkBitmap& bitmap, SkScalar left, SkScalar top,
899 const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
902 const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
904 SrcRectConstraint = kStrict_SrcRectConstraint);
960 const SkPaint* paint =
nullptr);
962 const SkPaint* paint =
nullptr);
972 void drawText(
const void* text,
size_t byteLength, SkScalar x, SkScalar y,
982 void drawPosText(
const void* text,
size_t byteLength,
const SkPoint pos[],
994 void drawPosTextH(
const void* text,
size_t byteLength,
const SkScalar xpos[], SkScalar constY,
1009 void drawTextOnPathHV(
const void* text,
size_t byteLength,
const SkPath& path, SkScalar hOffset,
1010 SkScalar vOffset,
const SkPaint& paint);
1022 void drawTextOnPath(
const void* text,
size_t byteLength,
const SkPath& path,
1030 void drawTextRSXform(
const void* text,
size_t byteLength,
const SkRSXform[],
1039 void drawTextBlob(
const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint);
1041 this->drawTextBlob(blob.get(), x, y, paint);
1051 this->drawPicture(picture, NULL, NULL);
1054 this->drawPicture(picture.get());
1071 this->drawPicture(picture.get(), matrix, paint);
1074 #ifdef SK_EXPERIMENTAL_SHADOWING
1092 void drawShadowedPicture(
const SkPicture*,
1098 this->drawShadowedPicture(picture.get(), matrix, paint);
1103 kTriangles_VertexMode,
1104 kTriangleStrip_VertexMode,
1105 kTriangleFan_VertexMode
1131 void drawVertices(VertexMode vmode,
int vertexCount,
1134 const uint16_t indices[],
int indexCount,
1136 void drawVertices(VertexMode vmode,
int vertexCount,
1139 const uint16_t indices[],
int indexCount,
1141 this->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode.get(),
1142 indices, indexCount, paint);
1158 void drawPatch(
const SkPoint cubics[12],
const SkColor colors[4],
1162 this->drawPatch(cubics, colors, texCoords, xmode.get(), paint);
1194 this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cull, paint);
1211 void drawDrawable(
SkDrawable*, SkScalar x, SkScalar y);
1223 void drawAnnotation(
const SkRect&,
const char key[],
SkData* value);
1225 this->drawAnnotation(rect, key, value.get());
1230 #ifndef SK_SUPPORT_LEGACY_DRAWFILTER
1231 #define SK_SUPPORT_LEGACY_DRAWFILTER
1235 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER
1240 SK_ATTR_EXTERNALLY_DEPRECATED(
"getDrawFilter use is deprecated")
1251 SK_ATTR_EXTERNALLY_DEPRECATED("setDrawFilter use is deprecated")
1263 virtual bool isClipEmpty()
const;
1269 virtual bool isClipRect()
const;
1275 const SkMatrix& getTotalMatrix()
const;
1292 void replayClips(ClipVisitor*)
const;
1297 GrDrawContext* internal_private_accessTopLayerDrawContext();
1300 static void Internal_Private_SetIgnoreSaveLayerBounds(
bool);
1301 static bool Internal_Private_GetIgnoreSaveLayerBounds();
1302 static void Internal_Private_SetTreatSpriteAsBitmap(
bool);
1303 static bool Internal_Private_GetTreatSpriteAsBitmap();
1308 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
1311 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
1317 void temporary_internal_describeTopLayer(
SkMatrix* matrix,
SkIRect* clip_bounds);
1320 #ifdef SK_EXPERIMENTAL_SHADOWING
1323 SkScalar getZ()
const;
1332 virtual bool onPeekPixels(
SkPixmap*);
1333 virtual bool onAccessTopLayerPixels(
SkPixmap*);
1336 virtual void onFlush();
1341 enum SaveLayerStrategy {
1342 kFullLayer_SaveLayerStrategy,
1343 kNoLayer_SaveLayerStrategy,
1346 virtual void willSave() {}
1348 virtual SaveLayerStrategy getSaveLayerStrategy(
const SaveLayerRec&) {
1349 return kFullLayer_SaveLayerStrategy;
1351 virtual void willRestore() {}
1352 virtual void didRestore() {}
1353 virtual void didConcat(
const SkMatrix&) {}
1354 virtual void didSetMatrix(
const SkMatrix&) {}
1355 virtual void didTranslate(SkScalar dx, SkScalar dy) {
1356 this->didConcat(SkMatrix::MakeTrans(dx, dy));
1359 #ifdef SK_EXPERIMENTAL_SHADOWING
1360 virtual void didTranslateZ(SkScalar) {}
1363 virtual void onDrawAnnotation(
const SkRect&,
const char key[],
SkData* value);
1366 virtual void onDrawText(
const void* text,
size_t byteLength, SkScalar x,
1367 SkScalar y,
const SkPaint& paint);
1369 virtual void onDrawPosText(
const void* text,
size_t byteLength,
1372 virtual void onDrawPosTextH(
const void* text,
size_t byteLength,
1373 const SkScalar xpos[], SkScalar constY,
1376 virtual void onDrawTextOnPath(
const void* text,
size_t byteLength,
1379 virtual void onDrawTextRSXform(
const void* text,
size_t byteLength,
const SkRSXform[],
1382 virtual void onDrawTextBlob(
const SkTextBlob* blob, SkScalar x, SkScalar y,
1385 virtual void onDrawPatch(
const SkPoint cubics[12],
const SkColor colors[4],
1390 virtual void onDrawPaint(
const SkPaint&);
1393 virtual void onDrawArc(
const SkRect&, SkScalar startAngle, SkScalar sweepAngle,
bool useCenter,
1396 virtual void onDrawPoints(PointMode,
size_t count,
const SkPoint pts[],
const SkPaint&);
1397 virtual void onDrawVertices(VertexMode,
int vertexCount,
const SkPoint vertices[],
1399 const uint16_t indices[],
int indexCount,
const SkPaint&);
1404 virtual void onDrawImage(
const SkImage*, SkScalar dx, SkScalar dy,
const SkPaint*);
1409 virtual void onDrawImageLattice(
const SkImage*,
const Lattice& lattice,
const SkRect& dst,
1412 virtual void onDrawBitmap(
const SkBitmap&, SkScalar dx, SkScalar dy,
const SkPaint*);
1417 virtual void onDrawBitmapLattice(
const SkBitmap&,
const Lattice& lattice,
const SkRect& dst,
1420 enum ClipEdgeStyle {
1421 kHard_ClipEdgeStyle,
1425 virtual void onClipRect(
const SkRect& rect,
SkRegion::Op op, ClipEdgeStyle edgeStyle);
1427 virtual void onClipPath(
const SkPath& path,
SkRegion::Op op, ClipEdgeStyle edgeStyle);
1430 virtual void onDiscard();
1434 #ifdef SK_EXPERIMENTAL_SHADOWING
1435 virtual void onDrawShadowedPicture(
const SkPicture*,
1444 virtual SkCanvas* canvasForDrawIter();
1450 bool clipRectBounds(
const SkRect* bounds, SaveLayerFlags,
SkIRect* intersection,
1467 bool done()
const {
return fDone; }
1475 const SkRasterClip& clip()
const;
1486 intptr_t fStorage[32];
1487 class SkDrawIter* fImpl;
1492 static bool BoundsAffectsClip(SaveLayerFlags);
1493 static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
1507 void predrawNotify(
bool willOverwritesEntireSurface =
false);
1508 void predrawNotify(
const SkRect* rect,
const SkPaint* paint, ShaderOverrideOpacity);
1509 void predrawNotify(
const SkRect* rect,
const SkPaint* paint,
bool shaderOverrideIsOpaque) {
1510 this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
1511 : kNotOpaque_ShaderOverrideOpacity);
1524 kDeviceCMSize = 176,
1526 intptr_t fMCRecStorage[kMCRecSize * kMCRecCount /
sizeof(intptr_t)];
1527 intptr_t fDeviceCMStorage[kDeviceCMSize /
sizeof(intptr_t)];
1535 SkSurface_Base* fSurfaceBase;
1536 SkSurface_Base* getSurfaceBase()
const {
return fSurfaceBase; }
1537 void setSurfaceBase(SkSurface_Base* sb) {
1540 friend class SkSurface_Base;
1541 friend class SkSurface_Gpu;
1543 bool fDeviceCMDirty;
1544 void updateDeviceCMCache();
1547 void checkForDeferredSave();
1548 void internalSetMatrix(
const SkMatrix&);
1550 friend class SkDrawIter;
1551 friend class AutoDrawLooper;
1553 friend class SkDebugCanvas;
1554 friend class SkSurface_Raster;
1555 friend class SkRecorder;
1556 friend class SkLiteRecorder;
1557 friend class SkNoSaveLayerCanvas;
1559 friend class SkPictureRecord;
1560 friend class SkPicturePlayback;
1563 kDefault_InitFlags = 0,
1564 kConservativeRasterClip_InitFlag = 1 << 0,
1569 void resetForNextPicture(
const SkIRect& bounds);
1572 friend class SkCanvasStateUtils;
1585 SkIRect getTopLayerBounds()
const;
1587 void internalDrawBitmapRect(
const SkBitmap& bitmap,
const SkRect* src,
1590 void internalDrawPaint(
const SkPaint& paint);
1591 void internalSaveLayer(
const SaveLayerRec&, SaveLayerStrategy);
1595 void internalSave();
1596 void internalRestore();
1597 static void DrawRect(
const SkDraw& draw,
const SkPaint& paint,
1598 const SkRect& r, SkScalar textSize);
1599 static void DrawTextDecorations(
const SkDraw& draw,
const SkPaint& paint,
1600 const char text[],
size_t byteLength,
1601 SkScalar x, SkScalar y);
1604 const SkRegion& internal_private_getTotalClip()
const;
1611 bool wouldOverwriteEntireSurface(
const SkRect*,
const SkPaint*, ShaderOverrideOpacity)
const;
1616 bool canDrawBitmapAsSprite(SkScalar x, SkScalar y,
int w,
int h,
const SkPaint&);
1624 SkRect fDeviceClipBounds;
1626 bool fAllowSoftClip;
1627 bool fAllowSimplifyClip;
1628 const bool fConservativeRasterClip;
1633 fCanvas->validateClip();
1642 void validateClip()
const;
1644 void validateClip()
const {}
1685 #define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
void discard()
This makes the contents of the canvas undefined.
Definition: SkCanvas.h:611
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:58
[Sa, Sc]
Definition: SkXfermode.h:73
Definition: SkCanvas.h:364
Definition: SkPictureImageFilter.h:14
int getSaveCount() const
Returns the number of matrix/clip states on the SkCanvas' private stack.
The SkRRect class represents a rounded rect with a potentially different radii for each corner...
Definition: SkRRect.h:48
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:27
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
SkTextBlob combines multiple text runs into an immutable, ref-counted structure.
Definition: SkTextBlob.h:22
Mode
List of predefined xfermodes.
Definition: SkXfermode.h:71
If kFast is specified, the implementation may sample outside of the src-rect (if specified) by half t...
Definition: SkCanvas.h:809
After calling saveLayer(), there can be any number of devices that make up the top-most drawing area...
Definition: SkCanvas.h:1460
[Sa + Da * (1 - Sa), Sc + Dc * (1 - Sa)]
Definition: SkXfermode.h:75
bool fIsScaleTranslate
Keep track of the device clip bounds and if the matrix is scale-translate.
Definition: SkCanvas.h:1623
PointMode
Definition: SkCanvas.h:620
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:51
Pairs SkImageInfo with actual pixels and rowbytes.
Definition: SkPixmap.h:23
Definition: SkPoint.h:156
void setAllowSimplifyClip(bool allow)
EXPERIMENTAL – only used for testing Set to simplify clip stack using path ops.
Definition: SkCanvas.h:514
there is no overriding shader (bitmap or image)
Definition: SkCanvas.h:1500
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
SkSurface represents the backend/results of drawing to a canvas.
Definition: SkSurface.h:31
Definition: SkRefCnt.h:135
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:46
void drawPicture(const SkPicture *picture)
Draw the picture into this canvas.
Definition: SkCanvas.h:1050
ShaderOverrideOpacity
Definition: SkCanvas.h:1499
An SkPicture records drawing commands made to a canvas to be played back at a later time...
Definition: SkPicture.h:38
Definition: SkCanvas.h:1630
SkXfermode is the base class for objects that are called to implement custom "transfer-modes" in the ...
Definition: SkXfermode.h:34
SkData holds an immutable data buffer.
Definition: SkData.h:22
static SkImageInfo MakeN32Premul(int width, int height, sk_sp< SkColorSpace > cs=nullptr)
Sets colortype to the native ARGB32 type, and the alphatype to premul.
Definition: SkImageInfo.h:212
bool done() const
Return true if the iterator is done.
Definition: SkCanvas.h:1467
void setClipRegion(const SkRegion &deviceRgn)
Helper for clipRegion(rgn, kReplace_Op).
Definition: SkCanvas.h:533
the overriding shader may not be opaque
Definition: SkCanvas.h:1502
Specifies coordinates to divide a bitmap into (xCount*yCount) rects.
Definition: SkCanvas.h:926
void clear(SkColor color)
Helper method for drawing a color in SRC mode, completely replacing all the pixels in the current cli...
Definition: SkCanvas.h:595
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:41
Base class for image filters.
Definition: SkImageFilter.h:35
const SkClipStack * getClipStack() const
Return the clip stack.
Definition: SkCanvas.h:1282
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:258
drawPoints draws each pair of points as a line segment
Definition: SkCanvas.h:624
Definition: GrDrawContext.h:51
DEPRECATED - use SkPaintFilterCanvas instead.
Definition: SkDrawFilter.h:26
Definition: GrContext.h:48
SkISize getDeviceSize() const
DEPRECATED: call getBaseLayerSize.
Definition: SkCanvas.h:153
SrcRectConstraint
Controls the behavior at the edge of the src-rect, when specified in drawImageRect, trading off speed for exactness.
Definition: SkCanvas.h:796
The SkRegion class encapsulates the geometric region used to specify clipping areas for drawing...
Definition: SkRegion.h:30
replace the dst region with the op region
Definition: SkRegion.h:246
uint32_t SkPMColor
32 bit ARGB color value, premultiplied.
Definition: SkColor.h:147
the overriding shader is opaque
Definition: SkCanvas.h:1501
Base-class for objects that draw into SkCanvas.
Definition: SkDrawable.h:25
void drawIRect(const SkIRect &rect, const SkPaint &paint)
Draw the specified rectangle using the specified paint.
Definition: SkCanvas.h:688
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
Definition: SkDevice.h:28
drawPoints draws each point separately
Definition: SkCanvas.h:622
If kStrict is specified, the implementation must respect the src-rect (if specified) strictly...
Definition: SkCanvas.h:802
void restoreToCount(int saveCount)
Efficient way to pop any calls to save() that happened after the save count reached saveCount...
Stack helper class to automatically call restoreToCount() on the canvas when this object goes out of ...
Definition: SkCanvas.h:1654
intersect the two regions
Definition: SkRegion.h:241
void setAllowSoftClip(bool allow)
EXPERIMENTAL – only used for testing Set to false to force clips to be hard, even if doAntiAlias=true...
Definition: SkCanvas.h:507
void restore()
Perform the restore now, instead of waiting for the destructor.
Definition: SkCanvas.h:1674
int save()
This call saves the current matrix, clip, and drawFilter, and pushes a copy onto a private stack...
[Da, Dc]
Definition: SkXfermode.h:74
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
unsigned U8CPU
Fast type for unsigned 8 bits.
Definition: SkTypes.h:251
Definition: SkClipStack.h:26
SkImage is an abstraction for drawing a rectagle of pixels, though the particular type of image could...
Definition: SkImage.h:45
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
Op
The logical operations that can be performed when combining two regions.
Definition: SkRegion.h:239
Definition: SkCanvas.h:1687