Flutter Engine
The Flutter Engine
BisectSlide.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 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
13#include "src/utils/SkOSPath.h"
14#include "tools/ToolUtils.h"
15
16#include <string>
17#include <functional>
18#include <utility>
19
21 SkFILEStream stream(filepath);
22 if (!stream.isValid()) {
23 SkDebugf("BISECT: invalid input file at \"%s\"\n", filepath);
24 return nullptr;
25 }
26
27 sk_sp<BisectSlide> bisect(new BisectSlide(filepath));
29 const SkPath& path,
30 const SkPaint& paint) {
32 SkIRect ibounds;
33 matrix.mapRect(&bounds, path.getBounds());
34 bounds.roundOut(&ibounds);
35 bisect->fDrawBounds.join(ibounds);
36 bisect->fFoundPaths.push_back() = {path, paint, matrix};
37 });
38 return bisect;
39}
40
41BisectSlide::BisectSlide(const char filepath[])
42 : fFilePath(filepath) {
43 const char* basename = strrchr(fFilePath.c_str(), SkOSPath::SEPARATOR);
44 fName.printf("BISECT_%s", basename ? basename + 1 : fFilePath.c_str());
45}
46
48 switch (c) {
49 case 'X':
50 if (!fTossedPaths.empty()) {
51 using std::swap;
52 swap(fFoundPaths, fTossedPaths);
53 if ('X' == fTrail.back()) {
54 fTrail.pop_back();
55 } else {
56 fTrail.push_back('X');
57 }
58 }
59 return true;
60
61 case 'x':
62 if (fFoundPaths.size() > 1) {
63 int midpt = (fFoundPaths.size() + 1) / 2;
64 fPathHistory.emplace(fFoundPaths, fTossedPaths);
65 fTossedPaths.reset(fFoundPaths.begin() + midpt, fFoundPaths.size() - midpt);
66 fFoundPaths.resize_back(midpt);
67 fTrail.push_back('x');
68 }
69 return true;
70
71 case 'Z': {
72 if (!fPathHistory.empty()) {
73 fFoundPaths = fPathHistory.top().first;
74 fTossedPaths = fPathHistory.top().second;
75 fPathHistory.pop();
76 char ch;
77 do {
78 ch = fTrail.back();
79 fTrail.pop_back();
80 } while (ch != 'x');
81 }
82 return true;
83 }
84
85 case 'D':
86 SkDebugf("viewer --bisect %s", fFilePath.c_str());
87 if (!fTrail.empty()) {
88 SkDebugf(" ");
89 for (char ch : fTrail) {
90 SkDebugf("%c", ch);
91 }
92 }
93 SkDebugf("\n");
94 for (const FoundPath& foundPath : fFoundPaths) {
95 foundPath.fPath.dump();
96 }
97 return true;
98 }
99
100 return false;
101}
102
104 SkAutoCanvasRestore acr(canvas, true);
105 canvas->translate(-fDrawBounds.left(), -fDrawBounds.top());
106
107 for (const FoundPath& path : fFoundPaths) {
108 SkAutoCanvasRestore acr2(canvas, true);
109 canvas->concat(path.fViewMatrix);
110 canvas->drawPath(path.fPath, path.fPaint);
111 }
112}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
int32_t SkUnichar
Definition: SkTypes.h:175
void draw(SkCanvas *canvas) override
bool onChar(SkUnichar c) override
Definition: BisectSlide.cpp:47
static sk_sp< BisectSlide > Create(const char filepath[])
Definition: BisectSlide.cpp:20
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
static constexpr char SEPARATOR
Definition: SkOSPath.h:21
Definition: SkPath.h:59
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
SkString fName
Definition: Slide.h:54
bool empty() const
Definition: SkTArray.h:199
void resize_back(int newCount)
Definition: SkTArray.h:343
void reset(int n)
Definition: SkTArray.h:144
int size() const
Definition: SkTArray.h:421
const Paint & paint
Definition: color_source.cc:38
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Optional< SkRect > bounds
Definition: SkRecords.h:189
void ExtractPathsFromSKP(const char filepath[], std::function< PathSniffCallback > callback)
Definition: ToolUtils.cpp:757
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
basename
Definition: malisc.py:23
Definition: SkRect.h:32
constexpr int32_t top() const
Definition: SkRect.h:120
constexpr int32_t left() const
Definition: SkRect.h:113