xref: /aosp_15_r20/external/skia/src/pathops/SkOpEdgeBuilder.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2012 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 SkOpEdgeBuilder_DEFINED
8 #define SkOpEdgeBuilder_DEFINED
9 
10 #include "include/core/SkPoint.h"
11 #include "include/core/SkScalar.h"
12 #include "include/private/base/SkTDArray.h"
13 #include "src/pathops/SkOpContour.h"
14 #include "src/pathops/SkPathOpsTypes.h"
15 #include "src/pathops/SkPathWriter.h"
16 
17 #include <cstdint>
18 
19 class SkPath;
20 
21 class SkOpEdgeBuilder {
22 public:
SkOpEdgeBuilder(const SkPathWriter & path,SkOpContourHead * contours2,SkOpGlobalState * globalState)23     SkOpEdgeBuilder(const SkPathWriter& path, SkOpContourHead* contours2,
24             SkOpGlobalState* globalState)
25         : fGlobalState(globalState)
26         , fPath(path.nativePath())
27         , fContourBuilder(contours2)
28         , fContoursHead(contours2)
29         , fAllowOpenContours(true) {
30         init();
31     }
32 
SkOpEdgeBuilder(const SkPath & path,SkOpContourHead * contours2,SkOpGlobalState * globalState)33     SkOpEdgeBuilder(const SkPath& path, SkOpContourHead* contours2, SkOpGlobalState* globalState)
34         : fGlobalState(globalState)
35         , fPath(&path)
36         , fContourBuilder(contours2)
37         , fContoursHead(contours2)
38         , fAllowOpenContours(false) {
39         init();
40     }
41 
42     void addOperand(const SkPath& path);
43 
complete()44     void complete() {
45         fContourBuilder.flush();
46         SkOpContour* contour = fContourBuilder.contour();
47         if (contour && contour->count()) {
48             contour->complete();
49             fContourBuilder.setContour(nullptr);
50         }
51     }
52 
53     bool finish();
54 
head()55     const SkOpContour* head() const {
56         return fContoursHead;
57     }
58 
59     void init();
unparseable()60     bool unparseable() const { return fUnparseable; }
xorMask()61     SkPathOpsMask xorMask() const { return fXorMask[fOperand]; }
62 
63 private:
64     void closeContour(const SkPoint& curveEnd, const SkPoint& curveStart);
65     bool close();
66     int preFetch();
67     bool walk();
68 
69     SkOpGlobalState* fGlobalState;
70     const SkPath* fPath;
71     SkTDArray<SkPoint> fPathPts;
72     SkTDArray<SkScalar> fWeights;
73     SkTDArray<uint8_t> fPathVerbs;
74     SkOpContourBuilder fContourBuilder;
75     SkOpContourHead* fContoursHead;
76     SkPathOpsMask fXorMask[2];
77     int fSecondHalf;
78     bool fOperand;
79     bool fAllowOpenContours;
80     bool fUnparseable;
81 };
82 
83 #endif
84