Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkDrawBase.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkDrawBase_DEFINED
9#define SkDrawBase_DEFINED
10
17#include "src/base/SkZip.h"
19#include "src/core/SkMask.h"
20#include <cstddef>
21
22class SkArenaAlloc;
23class SkBitmap;
24class SkBlitter;
25class SkDevice;
26class SkGlyph;
27class SkMaskFilter;
28class SkMatrix;
29class SkPath;
30class SkRRect;
31class SkRasterClip;
32class SkShader;
33class SkSurfaceProps;
34struct SkIRect;
35struct SkPoint;
36struct SkRect;
37
39public:
40 SkDrawBase();
41
42 void drawPaint(const SkPaint&) const;
43 void drawRect(const SkRect& prePaintRect, const SkPaint&, const SkMatrix* paintMatrix,
44 const SkRect* postPaintRect) const;
45 void drawRect(const SkRect& rect, const SkPaint& paint) const {
46 this->drawRect(rect, paint, nullptr, nullptr);
47 }
48 void drawRRect(const SkRRect&, const SkPaint&) const;
49 /**
50 * To save on mallocs, we allow a flag that tells us that srcPath is
51 * mutable, so that we don't have to make copies of it as we transform it.
52 *
53 * If prePathMatrix is not null, it should logically be applied before any
54 * stroking or other effects. If there are no effects on the paint that
55 * affect the geometry/rasterization, then the pre matrix can just be
56 * pre-concated with the current matrix.
57 */
58 void drawPath(const SkPath& path, const SkPaint& paint,
59 const SkMatrix* prePathMatrix = nullptr, bool pathIsMutable = false) const {
60 this->drawPath(path, paint, prePathMatrix, pathIsMutable, false);
61 }
62
63 /**
64 * Overwrite the target with the path's coverage (i.e. its mask).
65 * Will overwrite the entire device, so it need not be zero'd first.
66 *
67 * Only device A8 is supported right now.
68 */
69 void drawPathCoverage(const SkPath& src, const SkPaint& paint,
70 SkBlitter* customBlitter = nullptr) const {
71 bool isHairline = paint.getStyle() == SkPaint::kStroke_Style &&
72 paint.getStrokeWidth() == 0;
73 this->drawPath(src, paint, nullptr, false, !isHairline, customBlitter);
74 }
75
76 void drawDevicePoints(SkCanvas::PointMode, size_t count, const SkPoint[], const SkPaint&,
77 SkDevice*) const;
78
79 static bool ComputeMaskBounds(const SkRect& devPathBounds, const SkIRect& clipBounds,
80 const SkMaskFilter* filter, const SkMatrix* filterMatrix,
81 SkIRect* bounds);
82
83 /** Helper function that creates a mask from a path and an optional maskfilter.
84 Note however, that the resulting mask will not have been actually filtered,
85 that must be done afterwards (by calling filterMask). The maskfilter is provided
86 solely to assist in computing the mask's bounds (if the mode requests that).
87 */
88 static bool DrawToMask(const SkPath& devPath, const SkIRect& clipBounds,
89 const SkMaskFilter*, const SkMatrix* filterMatrix,
92
99
100 /**
101 * Based on the paint's style, strokeWidth, and the matrix, classify how
102 * to draw the rect. If no special-case is available, returns
103 * kPath_RectType.
104 *
105 * Iff RectType == kStroke_RectType, then strokeSize is set to the device
106 * width and height of the stroke.
107 */
108 static RectType ComputeRectType(const SkRect&, const SkPaint&, const SkMatrix&,
109 SkPoint* strokeSize);
110
111 using BlitterChooser = SkBlitter* (const SkPixmap& dst,
112 const SkMatrix& ctm,
113 const SkPaint&,
115 bool drawCoverage,
116 sk_sp<SkShader> clipShader,
117 const SkSurfaceProps&);
118
119
120private:
121 // not supported
122 void paintMasks(SkZip<const SkGlyph*, SkPoint> accepted, const SkPaint& paint) const override;
123 void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull,
124 const SkSamplingOptions&, const SkPaint&) const override;
125
126 void drawPath(const SkPath&,
127 const SkPaint&,
128 const SkMatrix* preMatrix,
129 bool pathIsMutable,
130 bool drawCoverage,
131 SkBlitter* customBlitter = nullptr) const;
132
133 void drawLine(const SkPoint[2], const SkPaint&) const;
134
135 void drawDevPath(const SkPath& devPath,
136 const SkPaint& paint,
137 bool drawCoverage,
138 SkBlitter* customBlitter,
139 bool doFill) const;
140 /**
141 * Return the current clip bounds, in local coordinates, with slop to account
142 * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then
143 * run through the inverse of the matrix).
144 *
145 * If the matrix cannot be inverted, or the current clip is empty, return
146 * false and ignore bounds parameter.
147 */
148 [[nodiscard]] bool computeConservativeLocalClipBounds(SkRect* bounds) const;
149
150public:
152 BlitterChooser* fBlitterChooser{nullptr}; // required
153 const SkMatrix* fCTM{nullptr}; // required
154 const SkRasterClip* fRC{nullptr}; // required
155 const SkSurfaceProps* fProps{nullptr}; // optional
156
157#ifdef SK_DEBUG
158 void validate() const;
159#else
160 void validate() const {}
161#endif
162};
163
164#endif // SkDrawBase_DEFINED
int count
@ kStroke_RectType
Definition SkDrawBase.h:96
void drawRect(const SkRect &rect, const SkPaint &paint) const
Definition SkDrawBase.h:45
void drawRRect(const SkRRect &, const SkPaint &) const
BlitterChooser * fBlitterChooser
Definition SkDrawBase.h:152
void drawPath(const SkPath &path, const SkPaint &paint, const SkMatrix *prePathMatrix=nullptr, bool pathIsMutable=false) const
Definition SkDrawBase.h:58
static bool DrawToMask(const SkPath &devPath, const SkIRect &clipBounds, const SkMaskFilter *, const SkMatrix *filterMatrix, SkMaskBuilder *dst, SkMaskBuilder::CreateMode mode, SkStrokeRec::InitStyle style)
static bool ComputeMaskBounds(const SkRect &devPathBounds, const SkIRect &clipBounds, const SkMaskFilter *filter, const SkMatrix *filterMatrix, SkIRect *bounds)
void drawPaint(const SkPaint &) const
const SkSurfaceProps * fProps
Definition SkDrawBase.h:155
const SkRasterClip * fRC
Definition SkDrawBase.h:154
void drawPathCoverage(const SkPath &src, const SkPaint &paint, SkBlitter *customBlitter=nullptr) const
Definition SkDrawBase.h:69
void drawRect(const SkRect &prePaintRect, const SkPaint &, const SkMatrix *paintMatrix, const SkRect *postPaintRect) const
SkPixmap fDst
Definition SkDrawBase.h:151
void validate() const
Definition SkDrawBase.h:160
void drawBitmap(const SkBitmap &, const SkMatrix &, const SkRect *dstOrNull, const SkSamplingOptions &, const SkPaint &) const override
static RectType ComputeRectType(const SkRect &, const SkPaint &, const SkMatrix &, SkPoint *strokeSize)
SkBlitter *(const SkPixmap &dst, const SkMatrix &ctm, const SkPaint &, SkArenaAlloc *, bool drawCoverage, sk_sp< SkShader > clipShader, const SkSurfaceProps &) BlitterChooser
Definition SkDrawBase.h:117
const SkMatrix * fCTM
Definition SkDrawBase.h:153
void paintMasks(SkZip< const SkGlyph *, SkPoint > accepted, const SkPaint &paint) const override
void drawDevicePoints(SkCanvas::PointMode, size_t count, const SkPoint[], const SkPaint &, SkDevice *) const
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
Definition SkZip.h:25
const Paint & paint