blob: 9e10537ca2bc19bc98fdeb3c8cd995406d72043b [file] [log] [blame]
Chris Dalton2d18f412018-02-20 13:23:32 -07001/*
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"
Hal Canary8a001442018-09-19 11:31:27 -040014
Chris Dalton2d18f412018-02-20 13:23:32 -070015#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 */
26class BisectSlide : public Slide, public SkCanvas {
27public:
28 static sk_sp<BisectSlide> Create(const char filepath[]);
29
30 // Slide overrides.
31 SkISize getDimensions() const override { return fDrawBounds.size(); }
32 bool onChar(SkUnichar c) override;
33 void draw(SkCanvas* canvas) override;
34
35private:
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