• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #ifndef BisectSlide_DEFINED
9 #define BisectSlide_DEFINED
10 
11 #include "include/core/SkCanvas.h"
12 #include "include/core/SkPath.h"
13 #include "tools/viewer/Slide.h"
14 
15 #include <stack>
16 
17 /**
18  * This is a simple utility designed to extract the paths from an SKP file and then isolate a single
19  * one of them via bisect. Use the 'x' and 'X' keys to guide a binary search:
20  *
21  *   'x': Throw out half the paths.
22  *   'X': Toggle which half gets tossed and which half is kept.
23  *   'Z': Back up one level.
24  *   'D': Dump the path.
25  */
26 class BisectSlide : public Slide {
27 public:
28     static sk_sp<BisectSlide> Create(const char filepath[]);
29 
30     // Slide overrides.
getDimensions()31     SkISize getDimensions() const override { return fDrawBounds.size(); }
32     bool onChar(SkUnichar c) override;
33     void draw(SkCanvas* canvas) override;
34 
35 private:
36     BisectSlide(const char filepath[]);
37 
38     struct FoundPath {
39         SkPath fPath;
40         SkPaint fPaint;
41         SkMatrix fViewMatrix;
42     };
43 
44     SkString fFilePath;
45     SkIRect fDrawBounds = SkIRect::MakeEmpty();
46     SkTArray<FoundPath> fFoundPaths;
47     SkTArray<FoundPath> fTossedPaths;
48     SkTArray<char> fTrail;
49     std::stack<std::pair<SkTArray<FoundPath>, SkTArray<FoundPath>>> fPathHistory;
50 };
51 
52 #endif
53