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, public SkCanvas { 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 // SkCanvas override called only during creation. 39 void onDrawPath(const SkPath& path, const SkPaint& paint) override; 40 41 struct FoundPath { 42 SkPath fPath; 43 SkPaint fPaint; 44 SkMatrix fViewMatrix; 45 }; 46 47 SkString fFilePath; 48 SkIRect fDrawBounds = SkIRect::MakeEmpty(); 49 SkTArray<FoundPath> fFoundPaths; 50 SkTArray<FoundPath> fTossedPaths; 51 SkTArray<char> fTrail; 52 std::stack<std::pair<SkTArray<FoundPath>, SkTArray<FoundPath>>> fPathHistory; 53 }; 54 55 #endif 56