Flutter Engine
The Flutter Engine
SkOverdrawCanvas.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
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
9
17#include "include/core/SkPath.h"
19#include "include/core/SkRect.h"
24#include "src/base/SkZip.h"
25#include "src/core/SkDevice.h"
27#include "src/core/SkGlyph.h"
30#include "src/core/SkMask.h"
31#include "src/text/GlyphRun.h"
32
33class SkBitmap;
34class SkData;
35class SkPicture;
36class SkRRect;
37class SkRegion;
38class SkTextBlob;
39class SkVertices;
40
42 : INHERITED(canvas->onImageInfo().width(), canvas->onImageInfo().height())
43{
44 // Non-drawing calls that SkOverdrawCanvas does not override (translate, save, etc.)
45 // will pass through to the input canvas.
46 this->addCanvas(canvas);
47
48 static constexpr float kIncrementAlpha[] = {
49 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
50 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
51 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
52 0.0f, 0.0f, 0.0f, 0.0f, 1.0f/255,
53 };
54
55 fPaint.setAntiAlias(false);
57 fPaint.setColorFilter(SkColorFilters::Matrix(kIncrementAlpha));
58}
59
60namespace {
62public:
63 TextDevice(SkCanvas* overdrawCanvas, const SkSurfaceProps& props)
64 : SkNoPixelsDevice{SkIRect::MakeWH(32767, 32767), props},
65 fOverdrawCanvas{overdrawCanvas},
66 fPainter{props, kN32_SkColorType, nullptr} {}
67
68 void paintMasks(SkZip<const SkGlyph*, SkPoint> accepted, const SkPaint& paint) const override {
69 for (auto [glyph, pos] : accepted) {
70 SkMask mask = glyph->mask(pos);
71 // We need to ignore any matrix on the overdraw canvas (it's already been baked into
72 // our glyph positions). Otherwise, the CTM is double-applied. (skbug.com/13732)
73 fOverdrawCanvas->save();
74 fOverdrawCanvas->resetMatrix();
75 fOverdrawCanvas->drawRect(SkRect::Make(mask.fBounds), SkPaint());
76 fOverdrawCanvas->restore();
77 }
78 }
79
80 void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull,
81 const SkSamplingOptions&, const SkPaint&) const override {}
82
83 void onDrawGlyphRunList(SkCanvas* canvas,
84 const sktext::GlyphRunList& glyphRunList,
85 const SkPaint& paint) override {
86 SkASSERT(!glyphRunList.hasRSXForm());
87 fPainter.drawForBitmapDevice(
88 canvas, this, glyphRunList, paint, fOverdrawCanvas->getTotalMatrix());
89 }
90
91private:
92 SkCanvas* const fOverdrawCanvas;
94};
95} // namespace
96
98 const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) {
100 auto glyphRunList = b.blobToGlyphRunList(*blob, {x, y});
101 this->onDrawGlyphRunList(glyphRunList, paint);
102}
103
105 const SkPaint& paint) {
106 SkSurfaceProps props;
107 this->getProps(&props);
108 TextDevice device{this, props};
109
110 device.drawGlyphRunList(this, glyphRunList, paint);
111}
112
113void SkOverdrawCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
114 const SkPoint texCoords[4], SkBlendMode blendMode,
115 const SkPaint&) {
116 fList[0]->onDrawPatch(cubics, colors, texCoords, blendMode, fPaint);
117}
118
120 if (0 == paint.getColor() && !paint.getColorFilter() && !paint.getShader()) {
121 // This is a clear, ignore it.
122 } else {
123 fList[0]->onDrawPaint(this->overdrawPaint(paint));
124 }
125}
126
128 fList[0]->onDrawBehind(this->overdrawPaint(paint));
129}
130
132 fList[0]->onDrawRect(rect, this->overdrawPaint(paint));
133}
134
136 fList[0]->onDrawRegion(region, this->overdrawPaint(paint));
137}
138
140 fList[0]->onDrawOval(oval, this->overdrawPaint(paint));
141}
142
144 bool useCenter, const SkPaint& paint) {
145 fList[0]->onDrawArc(arc, startAngle, sweepAngle, useCenter, this->overdrawPaint(paint));
146}
147
148void SkOverdrawCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
149 const SkPaint& paint) {
150 fList[0]->onDrawDRRect(outer, inner, this->overdrawPaint(paint));
151}
152
154 fList[0]->onDrawRRect(rect, this->overdrawPaint(paint));
155}
156
158 const SkPaint& paint) {
159 fList[0]->onDrawPoints(mode, count, points, this->overdrawPaint(paint));
160}
161
163 SkBlendMode blendMode, const SkPaint& paint) {
164 fList[0]->onDrawVerticesObject(vertices, blendMode, this->overdrawPaint(paint));
165}
166
168 const SkRect texs[], const SkColor colors[], int count,
170 const SkRect* cull, const SkPaint* paint) {
171 SkPaint* paintPtr = &fPaint;
172 SkPaint storage;
173 if (paint) {
174 storage = this->overdrawPaint(*paint);
175 paintPtr = &storage;
176 }
177
178 fList[0]->onDrawAtlas2(image, xform, texs, colors, count, mode, sampling, cull, paintPtr);
179}
180
182 fList[0]->onDrawPath(path, fPaint);
183}
184
186 const SkSamplingOptions&, const SkPaint*) {
187 fList[0]->onDrawRect(SkRect::MakeXYWH(x, y, image->width(), image->height()), fPaint);
188}
189
192 fList[0]->onDrawRect(dst, fPaint);
193}
194
196 const SkRect& dst, SkFilterMode, const SkPaint*) {
198 Lattice latticePlusBounds = lattice;
199 if (!latticePlusBounds.fBounds) {
201 latticePlusBounds.fBounds = &bounds;
202 }
203
204 if (SkLatticeIter::Valid(image->width(), image->height(), latticePlusBounds)) {
205 SkLatticeIter iter(latticePlusBounds, dst);
206
207 SkRect ignored, iterDst;
208 while (iter.next(&ignored, &iterDst)) {
209 fList[0]->onDrawRect(iterDst, fPaint);
210 }
211 } else {
212 fList[0]->onDrawRect(dst, fPaint);
213 }
214}
215
217 drawable->draw(this, matrix);
218}
219
221 SkASSERT(false);
222}
223
224void SkOverdrawCanvas::onDrawAnnotation(const SkRect&, const char[], SkData*) {}
225
229 fList[0]->onDrawRect(bounds, fPaint);
230}
231
234 if (clip) {
235 fList[0]->onDrawPath(SkPath::Polygon(clip, 4, true), fPaint);
236 } else {
237 fList[0]->onDrawRect(rect, fPaint);
238 }
239}
240
242 const SkPoint dstClips[],
245 const SkPaint* paint,
246 SrcRectConstraint constraint) {
247 int clipIndex = 0;
248 for (int i = 0; i < count; ++i) {
249 if (set[i].fMatrixIndex >= 0) {
250 fList[0]->save();
251 fList[0]->concat(preViewMatrices[set[i].fMatrixIndex]);
252 }
253 if (set[i].fHasClip) {
254 fList[0]->onDrawPath(SkPath::Polygon(dstClips + clipIndex, 4, true), fPaint);
255 clipIndex += 4;
256 } else {
257 fList[0]->onDrawRect(set[i].fDstRect, fPaint);
258 }
259 if (set[i].fMatrixIndex >= 0) {
260 fList[0]->restore();
261 }
262 }
263}
264
265inline SkPaint SkOverdrawCanvas::overdrawPaint(const SkPaint& paint) {
266 SkPaint newPaint = fPaint;
267 newPaint.setStyle(paint.getStyle());
268 newPaint.setStrokeWidth(paint.getStrokeWidth());
269 return newPaint;
270}
int count
Definition: FontMgrTest.cpp:50
static const int points[]
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBlendMode
Definition: SkBlendMode.h:38
@ kPlus
r = min(s + d, 1)
uint32_t SkColor
Definition: SkColor.h:37
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
SkFilterMode
bool getProps(SkSurfaceProps *props) const
Definition: SkCanvas.cpp:1214
friend class SkOverdrawCanvas
Definition: SkCanvas.h:2494
SrcRectConstraint
Definition: SkCanvas.h:1541
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
Definition: SkData.h:25
void draw(SkCanvas *, const SkMatrix *=nullptr)
Definition: SkDrawable.cpp:43
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
bool next(SkIRect *src, SkRect *dst, bool *isFixedColor=nullptr, SkColor *fixedColor=nullptr)
static bool Valid(int imageWidth, int imageHeight, const SkCanvas::Lattice &lattice)
virtual void addCanvas(SkCanvas *)
SkTDArray< SkCanvas * > fList
Definition: SkNWayCanvas.h:60
void onDrawImage2(const SkImage *, SkScalar, SkScalar, const SkSamplingOptions &, const SkPaint *) override
void onDrawTextBlob(const SkTextBlob *, SkScalar, SkScalar, const SkPaint &) override
void onDrawAnnotation(const SkRect &, const char key[], SkData *value) override
void onDrawImageRect2(const SkImage *, const SkRect &, const SkRect &, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint) override
void onDrawImageLattice2(const SkImage *, const Lattice &, const SkRect &, SkFilterMode, const SkPaint *) override
void onDrawOval(const SkRect &, const SkPaint &) override
void onDrawPoints(PointMode, size_t, const SkPoint[], const SkPaint &) override
void onDrawPath(const SkPath &, const SkPaint &) override
void onDrawRRect(const SkRRect &, const SkPaint &) override
void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode, const SkPaint &) override
void onDrawShadowRec(const SkPath &, const SkDrawShadowRec &) override
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[], const SkSamplingOptions &, const SkPaint *, SrcRectConstraint) override
void onDrawVerticesObject(const SkVertices *, SkBlendMode, const SkPaint &) override
void onDrawGlyphRunList(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint) override
void onDrawRegion(const SkRegion &, const SkPaint &) override
void onDrawEdgeAAQuad(const SkRect &, const SkPoint[4], SkCanvas::QuadAAFlags, const SkColor4f &, SkBlendMode) override
void onDrawArc(const SkRect &, SkScalar, SkScalar, bool, const SkPaint &) override
void onDrawPaint(const SkPaint &) override
void onDrawRect(const SkRect &, const SkPaint &) override
void onDrawDrawable(SkDrawable *, const SkMatrix *) override
void onDrawPicture(const SkPicture *, const SkMatrix *, const SkPaint *) override
void onDrawDRRect(const SkRRect &, const SkRRect &, const SkPaint &) override
void onDrawBehind(const SkPaint &paint) override
void onDrawAtlas2(const SkImage *, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode, const SkSamplingOptions &, const SkRect *, const SkPaint *) override
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
void setColorFilter(sk_sp< SkColorFilter > colorFilter)
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition: SkPath.cpp:3614
Definition: SkZip.h:25
bool hasRSXForm() const
Definition: GlyphRun.h:105
const Paint & paint
Definition: color_source.cc:38
DlColor color
VkDevice device
Definition: main.cc:53
float SkScalar
Definition: extension.cpp:12
static bool b
double y
double x
void GetLocalBounds(const SkPath &path, const SkDrawShadowRec &rec, const SkMatrix &ctm, SkRect *bounds)
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Optional< SkRect > bounds
Definition: SkRecords.h:189
PODArray< SkRect > texs
Definition: SkRecords.h:333
PODArray< SkPoint > dstClips
Definition: SkRecords.h:364
sk_sp< const SkImage > image
Definition: SkRecords.h:269
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
SkRect oval
Definition: SkRecords.h:249
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkMatrix > preViewMatrices
Definition: SkRecords.h:365
SkScalar startAngle
Definition: SkRecords.h:250
SkScalar sweepAngle
Definition: SkRecords.h:251
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkSamplingOptions sampling
Definition: SkRecords.h:337
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
dst
Definition: cp.py:12
int32_t height
int32_t width
const SkIRect * fBounds
source bounds to draw from
Definition: SkCanvas.h:1618
Definition: SkRect.h:32
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
Definition: SkMask.h:25
const SkIRect fBounds
Definition: SkMask.h:42
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659