xref: /third_party/skia/tests/SubsetPath.h (revision cb93a386)
1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2015 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci#ifndef SubsetPath_DEFINED
8cb93a386Sopenharmony_ci#define SubsetPath_DEFINED
9cb93a386Sopenharmony_ci
10cb93a386Sopenharmony_ci#include "include/core/SkPath.h"
11cb93a386Sopenharmony_ci#include "include/private/SkTDArray.h"
12cb93a386Sopenharmony_ci
13cb93a386Sopenharmony_ci/* Given a path, generate a the desired minimal subset of the original.
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ci   This does a binary divide-and-conquer on the path, first splitting by
16cb93a386Sopenharmony_ci   contours, and then by verbs. The caller passes whether the previous subset
17cb93a386Sopenharmony_ci   behaved the same as the original. If not, the subset() call restores the
18cb93a386Sopenharmony_ci   prior state before returning a new subset.
19cb93a386Sopenharmony_ci
20cb93a386Sopenharmony_ci   If a path fails a local test, this reduces the data to the
21cb93a386Sopenharmony_ci   minimal set that fails using a pattern like:
22cb93a386Sopenharmony_ci
23cb93a386Sopenharmony_ci   bool testFailed = true;
24cb93a386Sopenharmony_ci   SkPath minimal;
25cb93a386Sopenharmony_ci   SubsetContours subsetContours(testPath);
26cb93a386Sopenharmony_ci   while (subsetContours.subset(testFailed, &minimal)) {
27cb93a386Sopenharmony_ci       testFailed = myPathTest(minimal);
28cb93a386Sopenharmony_ci   }
29cb93a386Sopenharmony_ci   testFailed = true;
30cb93a386Sopenharmony_ci   SubsetVerbs subsetVerbs(testPath);
31cb93a386Sopenharmony_ci   while (subsetVerbs.subset(testFailed, &minimal)) {
32cb93a386Sopenharmony_ci       testFailed = myPathTest(minimal);
33cb93a386Sopenharmony_ci   }
34cb93a386Sopenharmony_ci*/
35cb93a386Sopenharmony_ci
36cb93a386Sopenharmony_ciclass SubsetPath {
37cb93a386Sopenharmony_cipublic:
38cb93a386Sopenharmony_ci    SubsetPath(const SkPath& path);
39cb93a386Sopenharmony_ci    virtual ~SubsetPath() {}
40cb93a386Sopenharmony_ci    bool subset(bool testFailed, SkPath* sub);
41cb93a386Sopenharmony_ciprotected:
42cb93a386Sopenharmony_ci    int range(int* end) const;
43cb93a386Sopenharmony_ci    virtual SkPath getSubsetPath() const = 0;
44cb93a386Sopenharmony_ci
45cb93a386Sopenharmony_ci    const SkPath& fPath;
46cb93a386Sopenharmony_ci    SkTDArray<bool> fSelected;
47cb93a386Sopenharmony_ci    int fSubset;
48cb93a386Sopenharmony_ci    int fTries;
49cb93a386Sopenharmony_ci
50cb93a386Sopenharmony_ci};
51cb93a386Sopenharmony_ci
52cb93a386Sopenharmony_ciclass SubsetContours : public SubsetPath {
53cb93a386Sopenharmony_cipublic:
54cb93a386Sopenharmony_ci    SubsetContours(const SkPath& path);
55cb93a386Sopenharmony_ciprotected:
56cb93a386Sopenharmony_ci    SkPath getSubsetPath() const override;
57cb93a386Sopenharmony_ci};
58cb93a386Sopenharmony_ci
59cb93a386Sopenharmony_ciclass SubsetVerbs : public SubsetPath {
60cb93a386Sopenharmony_cipublic:
61cb93a386Sopenharmony_ci    SubsetVerbs(const SkPath& path);
62cb93a386Sopenharmony_ciprotected:
63cb93a386Sopenharmony_ci    SkPath getSubsetPath() const override;
64cb93a386Sopenharmony_ci};
65cb93a386Sopenharmony_ci
66cb93a386Sopenharmony_ci#endif
67