caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 SkOpCoincidence_DEFINED |
| 8 | #define SkOpCoincidence_DEFINED |
| 9 | |
| 10 | #include "SkOpTAllocator.h" |
| 11 | #include "SkOpSpan.h" |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 12 | #include "SkPathOpsTypes.h" |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 13 | |
| 14 | class SkOpPtT; |
| 15 | |
| 16 | struct SkCoincidentSpans { |
| 17 | SkCoincidentSpans* fNext; |
| 18 | SkOpPtT* fCoinPtTStart; |
| 19 | SkOpPtT* fCoinPtTEnd; |
| 20 | SkOpPtT* fOppPtTStart; |
| 21 | SkOpPtT* fOppPtTEnd; |
| 22 | bool fFlipped; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 23 | SkDEBUGCODE(int fID); |
| 24 | |
| 25 | int debugID() const { |
| 26 | return SkDEBUGRELEASE(fID, -1); |
| 27 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 28 | |
| 29 | void dump() const; |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | class SkOpCoincidence { |
| 33 | public: |
| 34 | SkOpCoincidence() |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 35 | : fHead(nullptr) |
| 36 | , fTop(nullptr) |
| 37 | SkDEBUGPARAMS(fDebugState(nullptr)) |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 38 | { |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void add(SkOpPtT* coinPtTStart, SkOpPtT* coinPtTEnd, SkOpPtT* oppPtTStart, |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 42 | SkOpPtT* oppPtTEnd, SkChunkAlloc* allocator); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 43 | bool addExpanded(SkChunkAlloc* allocator PATH_OPS_DEBUG_VALIDATE_PARAMS(SkOpGlobalState* )); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 44 | bool addMissing(SkChunkAlloc* allocator); |
| 45 | bool apply(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 46 | bool contains(const SkOpPtT* coinPtTStart, const SkOpPtT* coinPtTEnd, |
| 47 | const SkOpPtT* oppPtTStart, const SkOpPtT* oppPtTEnd, bool flipped) const; |
| 48 | |
| 49 | void debugAddExpanded(const char* id, SkPathOpsDebug::GlitchLog* ) const; |
| 50 | void debugAddMissing(const char* id, SkPathOpsDebug::GlitchLog* ) const; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 51 | |
| 52 | const SkOpAngle* debugAngle(int id) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 53 | return SkDEBUGRELEASE(fDebugState->debugAngle(id), nullptr); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | SkOpContour* debugContour(int id) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 57 | return SkDEBUGRELEASE(fDebugState->debugContour(id), nullptr); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 58 | } |
| 59 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 60 | bool debugExpand(const char* id, SkPathOpsDebug::GlitchLog* ) const; |
| 61 | void debugMark(const char* id, SkPathOpsDebug::GlitchLog* ) const; |
| 62 | |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 63 | const SkOpPtT* debugPtT(int id) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 64 | return SkDEBUGRELEASE(fDebugState->debugPtT(id), nullptr); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | const SkOpSegment* debugSegment(int id) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 68 | return SkDEBUGRELEASE(fDebugState->debugSegment(id), nullptr); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void debugSetGlobalState(SkOpGlobalState* debugState) { |
| 72 | SkDEBUGCODE(fDebugState = debugState); |
| 73 | } |
| 74 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 75 | void debugFixAligned(const char* id, SkPathOpsDebug::GlitchLog* ) const; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 76 | void debugShowCoincidence() const; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 77 | |
| 78 | const SkOpSpanBase* debugSpan(int id) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 79 | return SkDEBUGRELEASE(fDebugState->debugSpan(id), nullptr); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 80 | } |
| 81 | |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 82 | void release(SkCoincidentSpans* ); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 83 | void dump() const; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 84 | bool expand(); |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 85 | bool extend(SkOpPtT* coinPtTStart, SkOpPtT* coinPtTEnd, SkOpPtT* oppPtTStart, |
| 86 | SkOpPtT* oppPtTEnd); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 87 | void findOverlaps(SkOpCoincidence* , SkChunkAlloc* allocator) const; |
| 88 | void fixAligned(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 89 | void fixUp(SkOpPtT* deleted, SkOpPtT* kept); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 90 | |
| 91 | bool isEmpty() const { |
| 92 | return !fHead; |
| 93 | } |
| 94 | |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 95 | void mark(); |
| 96 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 97 | private: |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 98 | bool addIfMissing(const SkCoincidentSpans* outer, SkOpPtT* over1s, SkOpPtT* over1e, |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 99 | SkChunkAlloc* ); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 100 | bool addIfMissing(const SkOpPtT* over1s, const SkOpPtT* over1e, |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 101 | const SkOpPtT* over2s, const SkOpPtT* over2e, |
| 102 | double tStart, double tEnd, |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 103 | SkOpPtT* coinPtTStart, const SkOpPtT* coinPtTEnd, |
| 104 | SkOpPtT* oppPtTStart, const SkOpPtT* oppPtTEnd, |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 105 | SkChunkAlloc* ); |
| 106 | void addOverlap(SkOpSegment* seg1, SkOpSegment* seg1o, SkOpSegment* seg2, SkOpSegment* seg2o, |
| 107 | SkOpPtT* overS, SkOpPtT* overE, SkChunkAlloc* ); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 108 | bool debugAddIfMissing(const SkCoincidentSpans* outer, const SkOpPtT* over1s, |
| 109 | const SkOpPtT* over1e) const; |
| 110 | bool debugAddIfMissing(const SkOpPtT* over1s, const SkOpPtT* over1e, |
| 111 | const SkOpPtT* over2s, const SkOpPtT* over2e, |
| 112 | double tStart, double tEnd, |
| 113 | SkOpPtT* coinPtTStart, const SkOpPtT* coinPtTEnd, |
| 114 | SkOpPtT* oppPtTStart, const SkOpPtT* oppPtTEnd) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 115 | bool overlap(const SkOpPtT* coinStart1, const SkOpPtT* coinEnd1, |
| 116 | const SkOpPtT* coinStart2, const SkOpPtT* coinEnd2, |
| 117 | double* overS, double* overE) const; |
| 118 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 119 | bool testForCoincidence(const SkCoincidentSpans* outer, const SkOpPtT* testS, |
| 120 | const SkOpPtT* testE) const; |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 121 | SkCoincidentSpans* fHead; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 122 | SkCoincidentSpans* fTop; |
| 123 | SkDEBUGCODE_(SkOpGlobalState* fDebugState); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | #endif |