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