Flutter Engine
The Flutter Engine
canvas_spy.h
Go to the documentation of this file.
1
2// Copyright 2013 The Flutter Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6#include "flutter/display_list/skia/dl_sk_canvas.h"
7#include "flutter/fml/macros.h"
12
13#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_CANVAS_SPY_H_
14#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_CANVAS_SPY_H_
15
16namespace flutter {
17
18class DidDrawCanvas;
19
20//------------------------------------------------------------------------------
21/// Facilitates spying on drawing commands to an SkCanvas.
22///
23/// This is used to determine whether anything was drawn into
24/// a canvas so it is possible to implement optimizations that
25/// are specific to empty canvases.
26class CanvasSpy {
27 public:
28 explicit CanvasSpy(SkCanvas* target_canvas);
29
30 //----------------------------------------------------------------------------
31 /// @brief Returns true if any non transparent content has been drawn
32 /// into
33 /// the spying canvas. Note that this class does tries to detect
34 /// empty canvases but in some cases may return true even for
35 /// empty canvases (e.g when a transparent image is drawn into the
36 /// canvas).
37 bool DidDrawIntoCanvas();
38
39 //----------------------------------------------------------------------------
40 /// @brief The returned canvas delegate all operations to the target
41 /// canvas
42 /// while spying on them.
44
45 //----------------------------------------------------------------------------
46 /// @brief The underlying Skia canvas that implements the spying
47 /// (mainly for testing)
49
50 private:
51 std::unique_ptr<SkNWayCanvas> n_way_canvas_;
52 std::unique_ptr<DidDrawCanvas> did_draw_canvas_;
53 DlSkCanvasAdapter adapter_;
54
55 FML_DISALLOW_COPY_AND_ASSIGN(CanvasSpy);
56};
57
58class DidDrawCanvas final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> {
59 public:
60 DidDrawCanvas(int width, int height);
61 ~DidDrawCanvas() override;
62 bool DidDrawIntoCanvas();
63
64 private:
65 bool did_draw_ = false;
66
67 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
68 void willSave() override;
69
70 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
71 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
72
73 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
74 bool onDoSaveBehind(const SkRect*) override;
75
76 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
77 void willRestore() override;
78
79 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
80 void didConcat44(const SkM44&) override;
81 void didScale(SkScalar, SkScalar) override;
82 void didTranslate(SkScalar, SkScalar) override;
83
84 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
85 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
86
87 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
88 virtual void onDrawTextBlob(const SkTextBlob* blob,
89 SkScalar x,
90 SkScalar y,
91 const SkPaint& paint) override;
92 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
93 virtual void onDrawPatch(const SkPoint cubics[12],
94 const SkColor colors[4],
95 const SkPoint texCoords[4],
97 const SkPaint& paint) override;
98
99 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
100 void onDrawPaint(const SkPaint&) override;
101
102 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
103 void onDrawBehind(const SkPaint&) override;
104
105 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
106 void onDrawPoints(PointMode,
107 size_t count,
108 const SkPoint pts[],
109 const SkPaint&) override;
110
111 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
112 void onDrawRect(const SkRect&, const SkPaint&) override;
113
114 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
115 void onDrawRegion(const SkRegion&, const SkPaint&) override;
116
117 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
118 void onDrawOval(const SkRect&, const SkPaint&) override;
119
120 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
121 void onDrawArc(const SkRect&,
122 SkScalar,
123 SkScalar,
124 bool,
125 const SkPaint&) override;
126
127 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
128 void onDrawRRect(const SkRRect&, const SkPaint&) override;
129
130 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
131 void onDrawPath(const SkPath&, const SkPaint&) override;
132
133#ifdef SK_SUPPORT_LEGACY_ONDRAWIMAGERECT
134 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
135 void onDrawImage(const SkImage*,
136 SkScalar left,
137 SkScalar top,
138 const SkPaint*) override;
139
140 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
141 void onDrawImageRect(const SkImage*,
142 const SkRect* src,
143 const SkRect& dst,
144 const SkPaint*,
145 SrcRectConstraint) override;
146
147 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
148 void onDrawImageLattice(const SkImage*,
149 const Lattice&,
150 const SkRect&,
151 const SkPaint*) override;
152
153 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
154 void onDrawAtlas(const SkImage*,
155 const SkRSXform[],
156 const SkRect[],
157 const SkColor[],
158 int,
160 const SkRect*,
161 const SkPaint*) override;
162 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
163 void onDrawEdgeAAImageSet(const ImageSetEntry[],
164 int count,
165 const SkPoint[],
166 const SkMatrix[],
167 const SkPaint*,
168 SrcRectConstraint) override;
169#endif
170
171 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
172 void onDrawImage2(const SkImage*,
173 SkScalar left,
174 SkScalar top,
175 const SkSamplingOptions&,
176 const SkPaint*) override;
177
178 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
179 void onDrawImageRect2(const SkImage*,
180 const SkRect& src,
181 const SkRect& dst,
182 const SkSamplingOptions&,
183 const SkPaint*,
184 SrcRectConstraint) override;
185
186 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
187 void onDrawImageLattice2(const SkImage*,
188 const Lattice&,
189 const SkRect&,
191 const SkPaint*) override;
192
193 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
194 void onDrawVerticesObject(const SkVertices*,
196 const SkPaint&) override;
197
198 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
199 void onDrawAtlas2(const SkImage*,
200 const SkRSXform[],
201 const SkRect[],
202 const SkColor[],
203 int,
205 const SkSamplingOptions&,
206 const SkRect*,
207 const SkPaint*) override;
208
209 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
210 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
211
212 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
213 void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
214
215 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
216 void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
217
218 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
219 void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
220
221 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
222 void onClipRegion(const SkRegion&, SkClipOp) override;
223
224 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
225 void onDrawPicture(const SkPicture*,
226 const SkMatrix*,
227 const SkPaint*) override;
228
229 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
230 void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
231
232 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
233 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
234
235 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
236 void onDrawEdgeAAQuad(const SkRect&,
237 const SkPoint[4],
239 const SkColor4f&,
240 SkBlendMode) override;
241
242 // |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
243 void onDrawEdgeAAImageSet2(const ImageSetEntry[],
244 int count,
245 const SkPoint[],
246 const SkMatrix[],
247 const SkSamplingOptions&,
248 const SkPaint*,
249 SrcRectConstraint) override;
250
251 void MarkDrawIfNonTransparentPaint(const SkPaint& paint);
252
253 FML_DISALLOW_COPY_AND_ASSIGN(DidDrawCanvas);
254};
255
256} // namespace flutter
257
258#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_CANVAS_SPY_H_
int count
Definition: FontMgrTest.cpp:50
SkBlendMode
Definition: SkBlendMode.h:38
SkClipOp
Definition: SkClipOp.h:13
uint32_t SkColor
Definition: SkColor.h:37
SkFilterMode
SrcRectConstraint
Definition: SkCanvas.h:1541
SaveLayerStrategy
Definition: SkCanvas.h:2263
Definition: SkData.h:25
Definition: SkM44.h:150
Definition: SkPath.h:59
SkCanvas * GetRawSpyingCanvas()
The underlying Skia canvas that implements the spying (mainly for testing)
Definition: canvas_spy.cc:24
CanvasSpy(SkCanvas *target_canvas)
Definition: canvas_spy.cc:9
bool DidDrawIntoCanvas()
Returns true if any non transparent content has been drawn into the spying canvas....
Definition: canvas_spy.cc:38
DlCanvas * GetSpyingCanvas()
The returned canvas delegate all operations to the target canvas while spying on them.
Definition: canvas_spy.cc:20
virtual void onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint) override
Definition: canvas_spy.cc:197
DidDrawCanvas(int width, int height)
Definition: canvas_spy.cc:28
~DidDrawCanvas() override
Definition: canvas_spy.cc:31
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode, const SkPaint &paint) override
Definition: canvas_spy.cc:221
Developer-facing API for rendering anything within the engine.
Definition: dl_canvas.h:38
Backend implementation of |DlCanvas| for |SkCanvas|.
Definition: dl_sk_canvas.h:20
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
PODArray< SkColor > colors
Definition: SkRecords.h:276
dst
Definition: cp.py:12
int32_t height
int32_t width