caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 SubsetPath_DEFINED |
| 8 | #define SubsetPath_DEFINED |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkPath.h" |
| 11 | #include "include/private/SkTDArray.h" |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 12 | |
| 13 | /* Given a path, generate a the desired minimal subset of the original. |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 14 | |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 15 | This does a binary divide-and-conquer on the path, first splitting by |
| 16 | contours, and then by verbs. The caller passes whether the previous subset |
| 17 | behaved the same as the original. If not, the subset() call restores the |
| 18 | prior state before returning a new subset. |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 19 | |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 20 | If a path fails a local test, this reduces the data to the |
| 21 | minimal set that fails using a pattern like: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 22 | |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 23 | bool testFailed = true; |
| 24 | SkPath minimal; |
| 25 | SubsetContours subsetContours(testPath); |
| 26 | while (subsetContours.subset(testFailed, &minimal)) { |
| 27 | testFailed = myPathTest(minimal); |
| 28 | } |
| 29 | testFailed = true; |
| 30 | SubsetVerbs subsetVerbs(testPath); |
| 31 | while (subsetVerbs.subset(testFailed, &minimal)) { |
| 32 | testFailed = myPathTest(minimal); |
| 33 | } |
| 34 | */ |
| 35 | |
| 36 | class SubsetPath { |
| 37 | public: |
| 38 | SubsetPath(const SkPath& path); |
| 39 | virtual ~SubsetPath() {} |
| 40 | bool subset(bool testFailed, SkPath* sub); |
| 41 | protected: |
| 42 | int range(int* end) const; |
| 43 | virtual SkPath getSubsetPath() const = 0; |
| 44 | |
| 45 | const SkPath& fPath; |
| 46 | SkTDArray<bool> fSelected; |
| 47 | int fSubset; |
| 48 | int fTries; |
| 49 | |
| 50 | }; |
| 51 | |
| 52 | class SubsetContours : public SubsetPath { |
| 53 | public: |
| 54 | SubsetContours(const SkPath& path); |
| 55 | protected: |
| 56 | SkPath getSubsetPath() const override; |
| 57 | }; |
| 58 | |
| 59 | class SubsetVerbs : public SubsetPath { |
| 60 | public: |
| 61 | SubsetVerbs(const SkPath& path); |
| 62 | protected: |
| 63 | SkPath getSubsetPath() const override; |
| 64 | }; |
| 65 | |
| 66 | #endif |