Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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));
28 ToolUtils::ExtractPathsFromSKP(filepath, [&](const SkMatrix& matrix,
29 const SkPath& path,
30 const SkPaint& paint) {
31 SkRect bounds;
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
static sk_sp< BisectSlide > Create(const char filepath[])
void translate(SkScalar dx, SkScalar dy)
void drawPath(const SkPath &path, const SkPaint &paint)
void concat(const SkMatrix &matrix)
static constexpr char SEPARATOR
Definition SkOSPath.h:21
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:194
void resize_back(int newCount)
Definition SkTArray.h:338
void reset(int n)
Definition SkTArray.h:139
int size() const
Definition SkTArray.h:416
const Paint & paint
void ExtractPathsFromSKP(const char filepath[], std::function< PathSniffCallback > callback)
constexpr int32_t top() const
Definition SkRect.h:120
constexpr int32_t left() const
Definition SkRect.h:113