8#ifndef SkCanvas_DEFINED
9#define SkCanvas_DEFINED
41#ifndef SK_SUPPORT_LEGACY_GETTOTALMATRIX
42#define SK_SUPPORT_LEGACY_GETTOTALMATRIX
134 static std::unique_ptr<SkCanvas> MakeRasterDirect(
const SkImageInfo&
info,
void* pixels,
216#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
219 enum class ColorBehavior {
299 virtual SkISize getBaseLayerSize()
const;
417 bool readPixels(
const SkImageInfo& dstInfo,
void* dstPixels,
size_t dstRowBytes,
455 bool readPixels(
const SkPixmap& pixmap,
int srcX,
int srcY);
530 bool writePixels(
const SkImageInfo&
info,
const void* pixels,
size_t rowBytes,
int x,
int y);
634 return this->saveLayer(&bounds,
paint);
659 int saveLayerAlphaf(
const SkRect* bounds,
float alpha);
662 return this->saveLayerAlphaf(bounds, alpha * (1.0f / 255));
671 kPreserveLCDText_SaveLayerFlag = 1 << 1,
672 kInitWithPrevious_SaveLayerFlag = 1 << 2,
674 kF16ColorType = 1 << 4,
679 static constexpr int kMaxFiltersPerLayer = 16;
779 , fBackdrop(backdrop)
780 , fColorSpace(colorSpace)
781 , fSaveLayerFlags(saveLayerFlags)
782 , fExperimentalBackdropScale(backdropScale) {
791 SkScalar fExperimentalBackdropScale = 1.f;
812 int saveLayer(
const SaveLayerRec& layerRec);
833 int getSaveCount()
const;
845 void restoreToCount(
int saveCount);
934 void concat(
const SkMatrix& matrix);
935 void concat(
const SkM44&);
944 void setMatrix(
const SkM44& matrix);
947 void setMatrix(
const SkMatrix& matrix);
976 this->clipRect(rect, op,
false);
1007 void androidFramework_setDeviceClipRestriction(
const SkIRect& rect);
1030 this->clipRRect(rrect, op,
false);
1056 void clipPath(
const SkPath& path,
SkClipOp op,
bool doAntiAlias);
1070 this->clipPath(path, op,
false);
1110 bool quickReject(
const SkRect& rect)
const;
1122 bool quickReject(
const SkPath& path)
const;
1134 SkRect getLocalClipBounds()
const;
1146 *bounds = this->getLocalClipBounds();
1147 return !bounds->isEmpty();
1159 SkIRect getDeviceClipBounds()
const;
1170 *bounds = this->getDeviceClipBounds();
1171 return !bounds->isEmpty();
1307 this->drawPoint(p.x(), p.y(),
paint);
1335 this->drawLine(p0.
x(), p0.
y(), p1.
x(), p1.
y(),
paint);
1361 this->drawRect(r,
paint);
1559 this->drawImageRect(
image.
get(), src, dst, sampling,
paint, constraint);
1659 kLeft_QuadAAFlag = 0b0001,
1660 kTop_QuadAAFlag = 0b0010,
1661 kRight_QuadAAFlag = 0b0100,
1662 kBottom_QuadAAFlag = 0b1000,
1664 kNone_QuadAAFlags = 0b0000,
1665 kAll_QuadAAFlags = 0b1111,
1671 int matrixIndex,
float alpha,
unsigned aaFlags,
bool hasClip);
1674 float alpha,
unsigned aaFlags);
1684 int fMatrixIndex = -1;
1686 unsigned fAAFlags = kNone_QuadAAFlags;
1687 bool fHasClip =
false;
1744 void experimental_DrawEdgeAAImageSet(
const ImageSetEntry imageSet[],
int cnt,
1747 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
1860 const uint32_t clusters[],
int textByteCount,
const char utf8text[],
1962 this->drawPicture(picture,
nullptr,
nullptr);
1974 this->drawPicture(picture.
get());
2007 this->drawPicture(picture.
get(), matrix,
paint);
2101 void drawPatch(
const SkPoint cubics[12],
const SkColor colors[4],
2175 void drawAnnotation(
const SkRect& rect,
const char key[],
SkData* value);
2188 this->drawAnnotation(rect,
key,
value.get());
2201 virtual bool isClipEmpty()
const;
2210 virtual bool isClipRect()
const;
2217 SkM44 getLocalToDevice()
const;
2223 return this->getLocalToDevice().asM33();
2226#ifdef SK_SUPPORT_LEGACY_GETTOTALMATRIX
2245 void temporary_internal_getRgnClip(
SkRegion* region);
2255 virtual bool onPeekPixels(
SkPixmap* pixmap);
2256 virtual bool onAccessTopLayerPixels(
SkPixmap* pixmap);
2271 return kFullLayer_SaveLayerStrategy;
2303 virtual void onDrawPatch(
const SkPoint cubics[12],
const SkColor colors[4],
2305 virtual void onDrawPoints(PointMode mode,
size_t count,
const SkPoint pts[],
2312 virtual void onDrawImageLattice2(
const SkImage*,
const Lattice&,
const SkRect& dst,
2317 virtual void onDrawEdgeAAImageSet2(
const ImageSetEntry imageSet[],
int count,
2325 virtual void onDrawAnnotation(
const SkRect& rect,
const char key[],
SkData* value);
2332 virtual void onDrawEdgeAAQuad(
const SkRect& rect,
const SkPoint clip[4], QuadAAFlags aaFlags,
2340 virtual void onClipRect(
const SkRect& rect,
SkClipOp op, ClipEdgeStyle edgeStyle);
2341 virtual void onClipRRect(
const SkRRect& rrect,
SkClipOp op, ClipEdgeStyle edgeStyle);
2342 virtual void onClipPath(
const SkPath& path,
SkClipOp op, ClipEdgeStyle edgeStyle);
2345 virtual void onResetClip();
2347 virtual void onDiscard();
2359 enum class PredrawFlags :
unsigned {
2361 kOpaqueShaderOverride = 1,
2362 kNonOpaqueShaderOverride = 2,
2363 kCheckForOverwrite = 4,
2364 kSkipMaskFilterAutoLayer = 8,
2375 [[nodiscard]]
bool predrawNotify(
bool willOverwritesEntireSurface =
false);
2379 std::optional<AutoLayerForImageFilter> aboutToDraw(
2383 std::optional<AutoLayerForImageFilter> aboutToDraw(
2385 const SkRect* rawBounds =
nullptr);
2391 return fRootDevice.get();
2409 FilterSpan imageFilters,
2418 BackImage(
const BackImage&);
2419 BackImage(BackImage&&);
2420 BackImage& operator=(
const BackImage&);
2432 std::unique_ptr<Layer> fLayer;
2438 std::unique_ptr<BackImage> fBackImage;
2440 int fDeferredSaveCount = 0;
2443 MCRec(
const MCRec*
prev);
2449 bool layerIsCoverage);
2455 static constexpr int kMCRecSize = 96;
2456 static constexpr int kMCRecCount = 32;
2458 intptr_t fMCRecStorage[kMCRecSize * kMCRecCount /
sizeof(intptr_t)];
2470 std::unique_ptr<SkRasterHandleAllocator> fAllocator;
2481 int fClipRestrictionSaveCount = -1;
2484 void checkForDeferredSave();
2485 void internalSetMatrix(
const SkM44&);
2487 friend class SkAndroidFrameworkUtils;
2497 template <
typename Key>
2533 int only_axis_aligned_saveBehind(
const SkRect* subset);
2539 void drawClippedToSaveBehind(
const SkPaint&);
2541 void resetForNextPicture(
const SkIRect& bounds);
2555 void internalSaveBehind(
const SkRect*);
2557 void internalConcat44(
const SkM44&);
2560 void internalSave();
2561 void internalRestore();
2563 enum class DeviceCompatibleWithFilter :
bool {
2584 DeviceCompatibleWithFilter compat,
2587 bool srcIsCoverageLayer =
false);
2594 bool wouldOverwriteEntireSurface(
const SkRect*,
const SkPaint*,
2607 bool androidFramework_isClipAA()
const;
2614 void internal_private_resetClip();
2620 SkRect fQuickRejectBounds;
2624 SkRect computeDeviceClipBounds(
bool outsetForAA=
true)
const;
2630 std::optional<AutoLayerForImageFilter> attemptBlurredRRectDraw(
const SkRRect&,
2634 class AutoUpdateQRBounds;
2635 void validateClip()
const;
2637 std::unique_ptr<sktext::GlyphRunBuilder> fScratchGlyphRunBuilder;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static float prev(float f)
@ kSrcOver
r = s + (1-sa)*d
@ kUTF8
uses bytes to represent UTF-8 or ASCII
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
static bool rotate(const SkDCubic &cubic, int zero, int index, SkDCubic &rotPath)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
static bool left(const SkPoint &p0, const SkPoint &p1)
static SkScalar center(float pos0, float pos1)
SkAutoCanvasRestore(SkCanvas *canvas, bool doSave)
static std::unique_ptr< SkCanvas > MakeRasterDirectN32(int width, int height, SkPMColor *pixels, size_t rowBytes)
friend constexpr SkEnumBitMask< PredrawFlags > operator|(PredrawFlags, PredrawFlags)
void clipPath(const SkPath &path, bool doAntiAlias=false)
void drawImageRect(const sk_sp< SkImage > &image, const SkRect &dst, const SkSamplingOptions &sampling, const SkPaint *paint=nullptr)
void drawArc(const SkArc &arc, const SkPaint &paint)
void drawPoint(SkPoint p, const SkPaint &paint)
void clipIRect(const SkIRect &irect, SkClipOp op=SkClipOp::kIntersect)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
void drawPicture(const sk_sp< SkPicture > &picture)
void clipRect(const SkRect &rect, SkClipOp op)
void clear(const SkColor4f &color)
SkMatrix getLocalToDeviceAs3x3() const
void drawString(const SkString &str, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
virtual void didScale(SkScalar, SkScalar)
virtual void didSetM44(const SkM44 &)
bool getLocalClipBounds(SkRect *bounds) const
virtual void didRestore()
void clipRRect(const SkRRect &rrect, SkClipOp op)
friend constexpr SkEnumBitMask< PredrawFlags > operator^(PredrawFlags, PredrawFlags)
virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec &)
void clipPath(const SkPath &path, SkClipOp op)
int saveLayerAlpha(const SkRect *bounds, U8CPU alpha)
void clipRect(const SkRect &rect, bool doAntiAlias=false)
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
@ kFast_SrcRectConstraint
sample outside bounds; faster
int saveLayer(const SkRect &bounds, const SkPaint *paint)
void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[], const uint32_t clusters[], int textByteCount, const char utf8text[], SkPoint origin, const SkFont &font, const SkPaint &paint)
@ kFullLayer_SaveLayerStrategy
@ kNoLayer_SaveLayerStrategy
void drawIRect(const SkIRect &rect, const SkPaint &paint)
void clear(SkColor color)
void drawImageRect(const sk_sp< SkImage > &image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling, const SkPaint *paint, SrcRectConstraint constraint)
bool getDeviceClipBounds(SkIRect *bounds) const
virtual void willRestore()
friend constexpr SkEnumBitMask< PredrawFlags > operator~(PredrawFlags)
virtual SkPaintFilterCanvas * internal_private_asPaintFilterCanvas() const
void restoreToCount(int saveCount)
void experimental_DrawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, SkColor color, SkBlendMode mode)
virtual void didTranslate(SkScalar, SkScalar)
void drawImage(const sk_sp< SkImage > &image, SkScalar left, SkScalar top)
void drawPicture(const sk_sp< SkPicture > &picture, const SkMatrix *matrix, const SkPaint *paint)
void clipRRect(const SkRRect &rrect, bool doAntiAlias=false)
friend constexpr SkEnumBitMask< PredrawFlags > operator&(PredrawFlags, PredrawFlags)
virtual void didConcat44(const SkM44 &)
void drawImageLattice(const SkImage *image, const Lattice &lattice, const SkRect &dst)
void drawCircle(SkPoint center, SkScalar radius, const SkPaint &paint)
void drawImage(const sk_sp< SkImage > &image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling, const SkPaint *paint=nullptr)
virtual bool onDoSaveBehind(const SkRect *)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void drawPicture(const SkPicture *picture)
void drawLine(SkPoint p0, SkPoint p1, const SkPaint &paint)
void drawTextBlob(const sk_sp< SkTextBlob > &blob, SkScalar x, SkScalar y, const SkPaint &paint)
@ kLines_PointMode
draw each pair of points as a line segment
@ kPolygon_PointMode
draw the array of points as a open polygon
@ kPoints_PointMode
draw each point separately
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
void drawAnnotation(const SkRect &rect, const char key[], const sk_sp< SkData > &value)
constexpr bool empty() const
constexpr size_t size() const
const char * c_str() const
FlutterSemanticsFlag flags
static void drawPath(SkPath &path, SkCanvas *canvas, SkColor color, const SkRect &clip, SkPaint::Cap cap, SkPaint::Join join, SkPaint::Style style, SkPathFillType fill, SkScalar strokeWidth)
ImageSetEntry(const ImageSetEntry &)
ImageSetEntry & operator=(const ImageSetEntry &)
sk_sp< const SkImage > fImage
int fYCount
number of y-coordinates
const SkIRect * fBounds
source bounds to draw from
@ kFixedColor
draws one of fColors into lattice rectangle
@ kTransparent
skips lattice rectangle by making it transparent
const int * fYDivs
y-axis values dividing bitmap
int fXCount
number of x-coordinates
const RectType * fRectTypes
array of fill types
const SkColor * fColors
array of colors
const int * fXDivs
x-axis values dividing bitmap
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 SkColorSpace *colorSpace, SaveLayerFlags saveLayerFlags)
static constexpr SkIRect MakeEmpty()
static SkImageInfo MakeN32Premul(int width, int height)
constexpr float y() const
constexpr float x() const
static SkRGBA4f FromColor(SkColor color)
static SkRect Make(const SkISize &size)
void set(const SkIRect &src)