BisectSlide.h 1.5 KB

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