Flutter Engine
The Flutter Engine
Classes | Functions | Variables
ImageFilterDAGSlide.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkDashPathEffect.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkImageFilters.h"
#include "src/core/SkImageFilter_Base.h"
#include "src/core/SkSpecialImage.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/viewer/Slide.h"

Go to the source code of this file.

Classes

class  ImageFilterDAGSlide
 

Functions

static FilterNode build_dag (const SkMatrix &ctm, const SkRect &rect, const SkImageFilter *rootFilter)
 
static void draw_node (SkCanvas *canvas, const FilterNode &node)
 
static float print_matrix (SkCanvas *canvas, const char *prefix, const SkMatrix &matrix, float x, float y, const SkFont &font, const SkPaint &paint)
 
static float print_size (SkCanvas *canvas, const char *prefix, const SkIRect &rect, float x, float y, const SkFont &font, const SkPaint &paint)
 
static float print_info (SkCanvas *canvas, const FilterNode &node)
 
static float draw_dag (SkCanvas *canvas, SkSurface *nodeSurface, const FilterNode &node)
 
static void draw_dag (SkCanvas *canvas, SkImageFilter *filter, const SkRect &rect, const SkISize &surfaceSize)
 

Variables

static constexpr float kLineHeight = 16.f
 
static constexpr float kLineInset = 8.f
 

Function Documentation

◆ build_dag()

static FilterNode build_dag ( const SkMatrix ctm,
const SkRect rect,
const SkImageFilter rootFilter 
)
static

Definition at line 123 of file ImageFilterDAGSlide.cpp.

124 {
125 // Emulate SkCanvas::internalSaveLayer's decomposition of the CTM.
127 skif::ParameterSpace<SkPoint> center({rect.centerX(), rect.centerY()});
128 skif::Mapping mapping;
129 SkAssertResult(mapping.decomposeCTM(ctm, rootFilter, center));
130 return FilterNode(rootFilter, mapping, content, 0);
131}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
static SkScalar center(float pos0, float pos1)
union flutter::testing::@2836::KeyboardChange::@76 content
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ draw_dag() [1/2]

static void draw_dag ( SkCanvas canvas,
SkImageFilter filter,
const SkRect rect,
const SkISize surfaceSize 
)
static

Definition at line 293 of file ImageFilterDAGSlide.cpp.

294 {
295 // Get the current CTM, which includes all the viewer's UI modifications, which we want to
296 // pass into our mock canvases for each DAG node.
297 SkMatrix ctm = canvas->getTotalMatrix();
298
299 canvas->save();
300 // Reset the matrix so that the DAG layout and instructional text is fixed to the window.
301 canvas->resetMatrix();
302
303 // Process the image filter DAG to display intermediate results later on, which will apply the
304 // provided CTM during draw_node calls.
305 FilterNode dag = build_dag(ctm, rect, filter);
306
307 sk_sp<SkSurface> nodeSurface =
308 canvas->makeSurface(canvas->imageInfo().makeDimensions(surfaceSize));
309 draw_dag(canvas, nodeSurface.get(), dag);
310
311 canvas->restore();
312}
static FilterNode build_dag(const SkMatrix &ctm, const SkRect &rect, const SkImageFilter *rootFilter)
static float draw_dag(SkCanvas *canvas, SkSurface *nodeSurface, const FilterNode &node)
void restore()
Definition: SkCanvas.cpp:461
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
void resetMatrix()
Definition: SkCanvas.cpp:1355
int save()
Definition: SkCanvas.cpp:447
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
T * get() const
Definition: SkRefCnt.h:303
SkImageInfo makeDimensions(SkISize newSize) const
Definition: SkImageInfo.h:454

◆ draw_dag() [2/2]

static float draw_dag ( SkCanvas canvas,
SkSurface nodeSurface,
const FilterNode &  node 
)
static

Definition at line 249 of file ImageFilterDAGSlide.cpp.

249 {
250 // First capture the results of the node, into nodeSurface
251 draw_node(nodeSurface->getCanvas(), node);
252 sk_sp<SkImage> nodeResults = nodeSurface->makeImageSnapshot();
253
254 // Fill in background of the filter node with a checkerboard
255 canvas->save();
256 canvas->clipRect(SkRect::MakeWH(nodeResults->width(), nodeResults->height()));
258 canvas->restore();
259
260 // Display filtered results in current canvas' location (assumed CTM is set for this node)
261 canvas->drawImage(nodeResults, 0, 0);
262
264 line.setAntiAlias(true);
266 line.setStrokeWidth(3.f);
267
268 // Text info
269 canvas->save();
270 canvas->translate(0, nodeResults->height());
271 float textHeight = print_info(canvas, node);
272 canvas->restore();
273
274 // Border around filtered results + text info
275 canvas->drawRect(SkRect::MakeWH(nodeResults->width(), nodeResults->height() + textHeight),
276 line);
277
278 static const float kPad = 20.f;
279 float x = nodeResults->width() + kPad;
280 float y = 0;
281 for (size_t i = 0; i < node.fInputNodes.size(); ++i) {
282 // Line connecting this node to its child
283 canvas->drawLine(nodeResults->width(), 0.5f * nodeResults->height(), // right of node
284 x, y + 0.5f * nodeResults->height(), line); // left of child
285 canvas->save();
286 canvas->translate(x, y);
287 y += draw_dag(canvas, nodeSurface, node.fInputNodes[i]);
288 canvas->restore();
289 }
290 return std::max(y, nodeResults->height() + textHeight + kPad);
291}
static float print_info(SkCanvas *canvas, const FilterNode &node)
static void draw_node(SkCanvas *canvas, const FilterNode &node)
constexpr SkColor SK_ColorLTGRAY
Definition: SkColor.h:118
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr int kPad
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
sk_sp< SkImage > makeImageSnapshot()
Definition: SkSurface.cpp:90
static float max(float r, float g, float b)
Definition: hsl.cpp:49
double y
double x
void draw_checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: ToolUtils.cpp:174
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ draw_node()

static void draw_node ( SkCanvas canvas,
const FilterNode &  node 
)
static

Definition at line 133 of file ImageFilterDAGSlide.cpp.

133 {
134 canvas->clear(SK_ColorTRANSPARENT);
135
136 SkPaint filterPaint;
137 filterPaint.setImageFilter(node.fFilter);
138
139 SkRect content = SkRect(node.fContent);
141 static const SkColor kColors[2] = {SK_ColorGREEN, SK_ColorWHITE};
142 SkPoint points[2] = { {content.fLeft + 15.f, content.fTop + 15.f},
143 {content.fRight - 15.f, content.fBottom - 15.f} };
146
148 line.setStrokeWidth(0.f);
150
151 canvas->save();
152 canvas->concat(node.fMapping.layerToDevice());
153 canvas->save();
154 canvas->concat(node.fMapping.layerMatrix());
155
156 canvas->saveLayer(&content, &filterPaint);
157 canvas->drawRect(content, paint);
158 canvas->restore(); // Completes the image filter
159
160 // Draw content-rect bounds
161 line.setColor(SK_ColorBLACK);
162 canvas->drawRect(content, line);
163
164 // Bounding boxes have all been mapped by the layer matrix from local to layer space, so undo
165 // the layer matrix, leaving just the device matrix.
166 canvas->restore();
167
168 // The hinted bounds of the layer saved for the filtering
169 line.setColor(SK_ColorRED);
170 canvas->drawRect(SkRect::Make(SkIRect(node.fHintedLayerBounds)).makeOutset(3.f, 3.f), line);
171 // The bounds of the layer if there was no local content hint
172 line.setColor(SK_ColorGREEN);
173 canvas->drawRect(SkRect::Make(SkIRect(node.fUnhintedLayerBounds)).makeOutset(2.f, 2.f), line);
174
175 // The output bounds in layer space
176 line.setColor(SK_ColorBLUE);
177 canvas->drawRect(SkRect::Make(SkIRect(node.fOutputBounds)).makeOutset(1.f, 1.f), line);
178 // Device-space bounding box of the output bounds (e.g. what legacy DAG manipulation via
179 // MatrixTransform would produce).
180 static const SkScalar kDashParams[] = {6.f, 12.f};
181 line.setPathEffect(SkDashPathEffect::Make(kDashParams, 2, 0.f));
182 SkRect devOutputBounds = SkRect::Make(SkIRect(node.fMapping.layerToDevice(node.fOutputBounds)));
183 canvas->restore(); // undoes device matrix
184 canvas->drawRect(devOutputBounds, line);
185}
static const int points[]
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void clear(SkColor color)
Definition: SkCanvas.h:1199
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
const DlColor kColors[]
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: SkRect.h:32
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
SkRect makeOutset(float dx, float dy) const
Definition: SkRect.h:1002

◆ print_info()

static float print_info ( SkCanvas canvas,
const FilterNode &  node 
)
static

Definition at line 214 of file ImageFilterDAGSlide.cpp.

214 {
217 text.setAntiAlias(true);
218
219 float y = kLineHeight;
220 if (node.fFilter) {
221 canvas->drawString(node.fFilter->getTypeName(), kLineInset, y, font, text);
222 y += kLineHeight;
223 if (node.fDepth == 0) {
224 // The mapping is the same for all nodes, so only print at the root
225 y = print_matrix(canvas, "Param->Layer", node.fMapping.layerMatrix(),
226 kLineInset, y, font, text);
227 y = print_matrix(canvas,
228 "Layer->Device",
229 node.fMapping.layerToDevice(),
231 y,
232 font,
233 text);
234 }
235
236 y = print_size(canvas, "Layer Size", SkIRect(node.fUnhintedLayerBounds),
237 kLineInset, y, font, text);
238 y = print_size(canvas, "Layer Size (hinted)", SkIRect(node.fHintedLayerBounds),
239 kLineInset, y, font, text);
240 } else {
241 canvas->drawString("Source Input", kLineInset, y, font, text);
242 y += kLineHeight;
243 }
244
245 return y;
246}
static float print_matrix(SkCanvas *canvas, const char *prefix, const SkMatrix &matrix, float x, float y, const SkFont &font, const SkPaint &paint)
static constexpr float kLineHeight
static float print_size(SkCanvas *canvas, const char *prefix, const SkIRect &rect, float x, float y, const SkFont &font, const SkPaint &paint)
static constexpr float kLineInset
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
std::u16string text
sk_sp< SkTypeface > DefaultTypeface()
font
Font Metadata and Metrics.

◆ print_matrix()

static float print_matrix ( SkCanvas canvas,
const char *  prefix,
const SkMatrix matrix,
float  x,
float  y,
const SkFont font,
const SkPaint paint 
)
static

Definition at line 190 of file ImageFilterDAGSlide.cpp.

191 {
192 canvas->drawString(prefix, x, y, font, paint);
193 y += kLineHeight;
194 for (int i = 0; i < 3; ++i) {
195 SkString row;
196 row.appendf("[%.2f %.2f %.2f]",
197 matrix.get(i * 3), matrix.get(i * 3 + 1), matrix.get(i * 3 + 2));
198 canvas->drawString(row, x, y, font, paint);
199 y += kLineHeight;
200 }
201 return y;
202}
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ print_size()

static float print_size ( SkCanvas canvas,
const char *  prefix,
const SkIRect rect,
float  x,
float  y,
const SkFont font,
const SkPaint paint 
)
static

Definition at line 204 of file ImageFilterDAGSlide.cpp.

205 {
206 canvas->drawString(prefix, x, y, font, paint);
207 y += kLineHeight;
208 SkString sz;
209 sz.appendf("%d x %d", rect.width(), rect.height());
210 canvas->drawString(sz, x, y, font, paint);
211 return y + kLineHeight;
212}

Variable Documentation

◆ kLineHeight

constexpr float kLineHeight = 16.f
staticconstexpr

Definition at line 187 of file ImageFilterDAGSlide.cpp.

◆ kLineInset

constexpr float kLineInset = 8.f
staticconstexpr

Definition at line 188 of file ImageFilterDAGSlide.cpp.