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 13class SkOpEdgeBuilder { 14public: 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 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 37 void complete() { 38 if (fCurrentContour && fCurrentContour->count()) { 39 fCurrentContour->complete(); 40 fCurrentContour = nullptr; 41 } 42 } 43 44 int count() const; 45 bool finish(SkChunkAlloc* ); 46 47 const SkOpContour* head() const { 48 return fContoursHead; 49 } 50 51 void init(); 52 bool unparseable() const { return fUnparseable; } 53 SkPathOpsMask xorMask() const { return fXorMask[fOperand]; } 54 55private: 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