caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 12 | |
| 13 | class SkOpEdgeBuilder { |
| 14 | public: |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 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) |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 21 | , fAllowOpenContours(true) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 22 | init(); |
| 23 | } |
| 24 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 25 | SkOpEdgeBuilder(const SkPath& path, SkOpContour* contours2, SkChunkAlloc* allocator, |
| 26 | SkOpGlobalState* globalState) |
| 27 | : fAllocator(allocator) |
| 28 | , fGlobalState(globalState) |
| 29 | , fPath(&path) |
| 30 | , fContoursHead(contours2) |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 31 | , fAllowOpenContours(false) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 32 | init(); |
| 33 | } |
| 34 | |
caryclark | d751ac0 | 2014-10-03 05:36:27 -0700 | [diff] [blame] | 35 | void addOperand(const SkPath& path); |
| 36 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 37 | void complete() { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 38 | if (fCurrentContour && fCurrentContour->count()) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 39 | fCurrentContour->complete(); |
Tom Hudson | 2880df2 | 2015-10-29 09:55:42 -0400 | [diff] [blame] | 40 | fCurrentContour = nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 44 | int count() const; |
| 45 | bool finish(SkChunkAlloc* ); |
| 46 | |
| 47 | const SkOpContour* head() const { |
| 48 | return fContoursHead; |
| 49 | } |
| 50 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 51 | void init(); |
caryclark | d751ac0 | 2014-10-03 05:36:27 -0700 | [diff] [blame] | 52 | bool unparseable() const { return fUnparseable; } |
| 53 | SkPathOpsMask xorMask() const { return fXorMask[fOperand]; } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 54 | |
| 55 | private: |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 56 | void closeContour(const SkPoint& curveEnd, const SkPoint& curveStart); |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 57 | bool close(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 58 | int preFetch(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 59 | bool walk(SkChunkAlloc* ); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 60 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 61 | SkChunkAlloc* fAllocator; |
| 62 | SkOpGlobalState* fGlobalState; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 63 | const SkPath* fPath; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 64 | SkTDArray<SkPoint> fPathPts; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 65 | SkTDArray<SkScalar> fWeights; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 66 | SkTDArray<uint8_t> fPathVerbs; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 67 | SkOpContour* fCurrentContour; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 68 | SkOpContour* fContoursHead; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 69 | SkPathOpsMask fXorMask[2]; |
| 70 | int fSecondHalf; |
| 71 | bool fOperand; |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 72 | bool fAllowOpenContours; |
| 73 | bool fUnparseable; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | #endif |