blob: 96bd21ac482ba1d764a67875c6babd52ccb3a857 [file] [log] [blame]
caryclark45fa4472015-01-16 07:04:10 -08001/*
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"
caryclark27c8eb82015-07-06 11:38:33 -070012#include "SkPathOpsTypes.h"
caryclark45fa4472015-01-16 07:04:10 -080013
14class SkOpPtT;
15
16struct SkCoincidentSpans {
17 SkCoincidentSpans* fNext;
18 SkOpPtT* fCoinPtTStart;
19 SkOpPtT* fCoinPtTEnd;
20 SkOpPtT* fOppPtTStart;
21 SkOpPtT* fOppPtTEnd;
22 bool fFlipped;
caryclark26ad22a2015-10-16 09:03:38 -070023 SkDEBUGCODE(int fID);
24
25 int debugID() const {
26 return SkDEBUGRELEASE(fID, -1);
27 }
caryclark54359292015-03-26 07:52:43 -070028
29 void dump() const;
caryclark45fa4472015-01-16 07:04:10 -080030};
31
32class SkOpCoincidence {
33public:
34 SkOpCoincidence()
halcanary96fcdcc2015-08-27 07:41:13 -070035 : fHead(nullptr)
36 , fTop(nullptr)
37 SkDEBUGPARAMS(fDebugState(nullptr))
caryclark27c8eb82015-07-06 11:38:33 -070038 {
caryclark45fa4472015-01-16 07:04:10 -080039 }
40
41 void add(SkOpPtT* coinPtTStart, SkOpPtT* coinPtTEnd, SkOpPtT* oppPtTStart,
caryclark54359292015-03-26 07:52:43 -070042 SkOpPtT* oppPtTEnd, SkChunkAlloc* allocator);
caryclark26ad22a2015-10-16 09:03:38 -070043 bool addExpanded(SkChunkAlloc* allocator PATH_OPS_DEBUG_VALIDATE_PARAMS(SkOpGlobalState* ));
caryclark54359292015-03-26 07:52:43 -070044 bool addMissing(SkChunkAlloc* allocator);
45 bool apply();
caryclark26ad22a2015-10-16 09:03:38 -070046 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;
caryclark27c8eb82015-07-06 11:38:33 -070051
52 const SkOpAngle* debugAngle(int id) const {
halcanary96fcdcc2015-08-27 07:41:13 -070053 return SkDEBUGRELEASE(fDebugState->debugAngle(id), nullptr);
caryclark27c8eb82015-07-06 11:38:33 -070054 }
55
56 SkOpContour* debugContour(int id) {
halcanary96fcdcc2015-08-27 07:41:13 -070057 return SkDEBUGRELEASE(fDebugState->debugContour(id), nullptr);
caryclark27c8eb82015-07-06 11:38:33 -070058 }
59
caryclark26ad22a2015-10-16 09:03:38 -070060 bool debugExpand(const char* id, SkPathOpsDebug::GlitchLog* ) const;
61 void debugMark(const char* id, SkPathOpsDebug::GlitchLog* ) const;
62
caryclark27c8eb82015-07-06 11:38:33 -070063 const SkOpPtT* debugPtT(int id) const {
halcanary96fcdcc2015-08-27 07:41:13 -070064 return SkDEBUGRELEASE(fDebugState->debugPtT(id), nullptr);
caryclark27c8eb82015-07-06 11:38:33 -070065 }
66
67 const SkOpSegment* debugSegment(int id) const {
halcanary96fcdcc2015-08-27 07:41:13 -070068 return SkDEBUGRELEASE(fDebugState->debugSegment(id), nullptr);
caryclark27c8eb82015-07-06 11:38:33 -070069 }
70
71 void debugSetGlobalState(SkOpGlobalState* debugState) {
72 SkDEBUGCODE(fDebugState = debugState);
73 }
74
caryclark26ad22a2015-10-16 09:03:38 -070075 void debugFixAligned(const char* id, SkPathOpsDebug::GlitchLog* ) const;
caryclark624637c2015-05-11 07:21:27 -070076 void debugShowCoincidence() const;
caryclark27c8eb82015-07-06 11:38:33 -070077
78 const SkOpSpanBase* debugSpan(int id) const {
halcanary96fcdcc2015-08-27 07:41:13 -070079 return SkDEBUGRELEASE(fDebugState->debugSpan(id), nullptr);
caryclark27c8eb82015-07-06 11:38:33 -070080 }
81
mtklein18300a32016-03-16 13:53:35 -070082 void release(SkCoincidentSpans* );
caryclark45fa4472015-01-16 07:04:10 -080083 void dump() const;
caryclark27c8eb82015-07-06 11:38:33 -070084 bool expand();
caryclarkbca19f72015-05-13 08:23:48 -070085 bool extend(SkOpPtT* coinPtTStart, SkOpPtT* coinPtTEnd, SkOpPtT* oppPtTStart,
86 SkOpPtT* oppPtTEnd);
caryclark27c8eb82015-07-06 11:38:33 -070087 void findOverlaps(SkOpCoincidence* , SkChunkAlloc* allocator) const;
88 void fixAligned();
caryclark54359292015-03-26 07:52:43 -070089 void fixUp(SkOpPtT* deleted, SkOpPtT* kept);
caryclark27c8eb82015-07-06 11:38:33 -070090
91 bool isEmpty() const {
92 return !fHead;
93 }
94
caryclark45fa4472015-01-16 07:04:10 -080095 void mark();
96
caryclark54359292015-03-26 07:52:43 -070097private:
caryclark26ad22a2015-10-16 09:03:38 -070098 bool addIfMissing(const SkCoincidentSpans* outer, SkOpPtT* over1s, SkOpPtT* over1e,
caryclark27c8eb82015-07-06 11:38:33 -070099 SkChunkAlloc* );
caryclark54359292015-03-26 07:52:43 -0700100 bool addIfMissing(const SkOpPtT* over1s, const SkOpPtT* over1e,
caryclark27c8eb82015-07-06 11:38:33 -0700101 const SkOpPtT* over2s, const SkOpPtT* over2e,
102 double tStart, double tEnd,
caryclark54359292015-03-26 07:52:43 -0700103 SkOpPtT* coinPtTStart, const SkOpPtT* coinPtTEnd,
104 SkOpPtT* oppPtTStart, const SkOpPtT* oppPtTEnd,
caryclark27c8eb82015-07-06 11:38:33 -0700105 SkChunkAlloc* );
106 void addOverlap(SkOpSegment* seg1, SkOpSegment* seg1o, SkOpSegment* seg2, SkOpSegment* seg2o,
107 SkOpPtT* overS, SkOpPtT* overE, SkChunkAlloc* );
caryclark26ad22a2015-10-16 09:03:38 -0700108 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;
caryclark54359292015-03-26 07:52:43 -0700115 bool overlap(const SkOpPtT* coinStart1, const SkOpPtT* coinEnd1,
116 const SkOpPtT* coinStart2, const SkOpPtT* coinEnd2,
117 double* overS, double* overE) const;
118
caryclark26ad22a2015-10-16 09:03:38 -0700119 bool testForCoincidence(const SkCoincidentSpans* outer, const SkOpPtT* testS,
120 const SkOpPtT* testE) const;
caryclark45fa4472015-01-16 07:04:10 -0800121 SkCoincidentSpans* fHead;
caryclark27c8eb82015-07-06 11:38:33 -0700122 SkCoincidentSpans* fTop;
123 SkDEBUGCODE_(SkOpGlobalState* fDebugState);
caryclark45fa4472015-01-16 07:04:10 -0800124};
125
126#endif