| 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" |
| 12 | #include "SkTArray.h" |
| 13 | #include "SkTDArray.h" |
| 14 | |
| 15 | class SkOpEdgeBuilder { |
| 16 | public: |
| 17 | SkOpEdgeBuilder(const SkPathWriter& path, SkTArray<SkOpContour>& contours) |
| 18 | : fPath(path.nativePath()) |
| caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame^] | 19 | , fContours(contours) |
| 20 | , fAllowOpenContours(true) { |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 21 | init(); |
| 22 | } |
| 23 | |
| 24 | SkOpEdgeBuilder(const SkPath& path, SkTArray<SkOpContour>& contours) |
| 25 | : fPath(&path) |
| caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame^] | 26 | , fContours(contours) |
| 27 | , fAllowOpenContours(false) { |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 28 | init(); |
| 29 | } |
| 30 | |
| 31 | void complete() { |
| 32 | if (fCurrentContour && fCurrentContour->segments().count()) { |
| 33 | fCurrentContour->complete(); |
| 34 | fCurrentContour = NULL; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | SkPathOpsMask xorMask() const { |
| 39 | return fXorMask[fOperand]; |
| 40 | } |
| 41 | |
| 42 | void addOperand(const SkPath& path); |
| caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame^] | 43 | bool finish(); |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 44 | void init(); |
| 45 | |
| 46 | private: |
| caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame^] | 47 | bool close(); |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 48 | int preFetch(); |
| caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame^] | 49 | bool walk(); |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 50 | |
| 51 | const SkPath* fPath; |
| caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame^] | 52 | SkTDArray<SkPoint> fPathPts; |
| 53 | SkTDArray<uint8_t> fPathVerbs; |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 54 | SkOpContour* fCurrentContour; |
| 55 | SkTArray<SkOpContour>& fContours; |
| 56 | SkTDArray<SkPoint> fReducePts; // segments created on the fly |
| 57 | SkTDArray<int> fExtra; // -1 marks new contour, > 0 offsets into contour |
| 58 | SkPathOpsMask fXorMask[2]; |
| caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame^] | 59 | const SkPoint* fFinalCurveStart; |
| 60 | const SkPoint* fFinalCurveEnd; |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 61 | int fSecondHalf; |
| 62 | bool fOperand; |
| caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame^] | 63 | bool fAllowOpenContours; |
| 64 | bool fUnparseable; |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif |