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 "SkOpContour.h"
11 #include "SkPathWriter.h"
12 
13 class SkOpEdgeBuilder {
14 public:
SkOpEdgeBuilder(const SkPathWriter & path,SkOpContour * contours2,SkChunkAlloc * allocator,SkOpGlobalState * globalState)15     SkOpEdgeBuilder(const SkPathWriter& path, SkOpContour* contours2, SkChunkAlloc* allocator,
16             SkOpGlobalState* globalState)
17         : fAllocator(allocator)  // FIXME: replace with const, tune this
18         , fGlobalState(globalState)
19         , fPath(path.nativePath())
20         , fContoursHead(contours2)
21         , fAllowOpenContours(true) {
22         init();
23     }
24 
SkOpEdgeBuilder(const SkPath & path,SkOpContour * contours2,SkChunkAlloc * allocator,SkOpGlobalState * globalState)25     SkOpEdgeBuilder(const SkPath& path, SkOpContour* contours2, SkChunkAlloc* allocator,
26             SkOpGlobalState* globalState)
27         : fAllocator(allocator)
28         , fGlobalState(globalState)
29         , fPath(&path)
30         , fContoursHead(contours2)
31         , fAllowOpenContours(false) {
32         init();
33     }
34 
35     void addOperand(const SkPath& path);
36 
complete()37     void complete() {
38         if (fCurrentContour && fCurrentContour->count()) {
39             fCurrentContour->complete();
40             fCurrentContour = NULL;
41         }
42     }
43 
44     int count() const;
45     bool finish(SkChunkAlloc* );
46 
head()47     const SkOpContour* head() const {
48         return fContoursHead;
49     }
50 
51     void init();
unparseable()52     bool unparseable() const { return fUnparseable; }
xorMask()53     SkPathOpsMask xorMask() const { return fXorMask[fOperand]; }
54 
55 private:
56     void closeContour(const SkPoint& curveEnd, const SkPoint& curveStart);
57     bool close();
58     int preFetch();
59     bool walk(SkChunkAlloc* );
60 
61     SkChunkAlloc* fAllocator;
62     SkOpGlobalState* fGlobalState;
63     const SkPath* fPath;
64     SkTDArray<SkPoint> fPathPts;
65     SkTDArray<SkScalar> fWeights;
66     SkTDArray<uint8_t> fPathVerbs;
67     SkOpContour* fCurrentContour;
68     SkOpContour* fContoursHead;
69     SkPathOpsMask fXorMask[2];
70     int fSecondHalf;
71     bool fOperand;
72     bool fAllowOpenContours;
73     bool fUnparseable;
74 };
75 
76 #endif
77