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 "src/pathops/SkOpContour.h" 11 #include "src/pathops/SkPathWriter.h" 12 13 class SkOpEdgeBuilder { 14 public: SkOpEdgeBuilder(const SkPathWriter & path,SkOpContourHead * contours2,SkOpGlobalState * globalState)15 SkOpEdgeBuilder(const SkPathWriter& path, SkOpContourHead* contours2, 16 SkOpGlobalState* globalState) 17 : fGlobalState(globalState) 18 , fPath(path.nativePath()) 19 , fContourBuilder(contours2) 20 , fContoursHead(contours2) 21 , fAllowOpenContours(true) { 22 init(); 23 } 24 SkOpEdgeBuilder(const SkPath & path,SkOpContourHead * contours2,SkOpGlobalState * globalState)25 SkOpEdgeBuilder(const SkPath& path, SkOpContourHead* contours2, SkOpGlobalState* globalState) 26 : fGlobalState(globalState) 27 , fPath(&path) 28 , fContourBuilder(contours2) 29 , fContoursHead(contours2) 30 , fAllowOpenContours(false) { 31 init(); 32 } 33 34 void addOperand(const SkPath& path); 35 complete()36 void complete() { 37 fContourBuilder.flush(); 38 SkOpContour* contour = fContourBuilder.contour(); 39 if (contour && contour->count()) { 40 contour->complete(); 41 fContourBuilder.setContour(nullptr); 42 } 43 } 44 45 bool finish(); 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(); 60 61 SkOpGlobalState* fGlobalState; 62 const SkPath* fPath; 63 SkTDArray<SkPoint> fPathPts; 64 SkTDArray<SkScalar> fWeights; 65 SkTDArray<uint8_t> fPathVerbs; 66 SkOpContourBuilder fContourBuilder; 67 SkOpContourHead* fContoursHead; 68 SkPathOpsMask fXorMask[2]; 69 int fSecondHalf; 70 bool fOperand; 71 bool fAllowOpenContours; 72 bool fUnparseable; 73 }; 74 75 #endif 76