Home | History | Annotate | Download | only in pathops
      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"
     12 #include "SkPathOpsTypes.h"
     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;
     23     SkDEBUGCODE(int fID);
     24 
     25     int debugID() const {
     26         return SkDEBUGRELEASE(fID, -1);
     27     }
     28 
     29     void dump() const;
     30 };
     31 
     32 class SkOpCoincidence {
     33 public:
     34     SkOpCoincidence()
     35         : fHead(nullptr)
     36         , fTop(nullptr)
     37         SkDEBUGPARAMS(fDebugState(nullptr))
     38         {
     39     }
     40 
     41     void add(SkOpPtT* coinPtTStart, SkOpPtT* coinPtTEnd, SkOpPtT* oppPtTStart,
     42              SkOpPtT* oppPtTEnd, SkChunkAlloc* allocator);
     43     bool addExpanded(SkChunkAlloc* allocator  PATH_OPS_DEBUG_VALIDATE_PARAMS(SkOpGlobalState* ));
     44     bool addMissing(SkChunkAlloc* allocator);
     45     bool apply();
     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;
     51 
     52     const SkOpAngle* debugAngle(int id) const {
     53         return SkDEBUGRELEASE(fDebugState->debugAngle(id), nullptr);
     54     }
     55 
     56     SkOpContour* debugContour(int id) {
     57         return SkDEBUGRELEASE(fDebugState->debugContour(id), nullptr);
     58     }
     59 
     60     bool debugExpand(const char* id, SkPathOpsDebug::GlitchLog* ) const;
     61     void debugMark(const char* id, SkPathOpsDebug::GlitchLog* ) const;
     62 
     63     const SkOpPtT* debugPtT(int id) const {
     64         return SkDEBUGRELEASE(fDebugState->debugPtT(id), nullptr);
     65     }
     66 
     67     const SkOpSegment* debugSegment(int id) const {
     68         return SkDEBUGRELEASE(fDebugState->debugSegment(id), nullptr);
     69     }
     70 
     71     void debugSetGlobalState(SkOpGlobalState* debugState) {
     72         SkDEBUGCODE(fDebugState = debugState);
     73     }
     74 
     75     void debugFixAligned(const char* id, SkPathOpsDebug::GlitchLog* ) const;
     76     void debugShowCoincidence() const;
     77 
     78     const SkOpSpanBase* debugSpan(int id) const {
     79         return SkDEBUGRELEASE(fDebugState->debugSpan(id), nullptr);
     80     }
     81 
     82     void detach(SkCoincidentSpans* );
     83     void dump() const;
     84     bool expand();
     85     bool extend(SkOpPtT* coinPtTStart, SkOpPtT* coinPtTEnd, SkOpPtT* oppPtTStart,
     86         SkOpPtT* oppPtTEnd);
     87     void findOverlaps(SkOpCoincidence* , SkChunkAlloc* allocator) const;
     88     void fixAligned();
     89     void fixUp(SkOpPtT* deleted, SkOpPtT* kept);
     90 
     91     bool isEmpty() const {
     92         return !fHead;
     93     }
     94 
     95     bool mark();
     96 
     97 private:
     98     bool addIfMissing(const SkCoincidentSpans* outer, SkOpPtT* over1s, SkOpPtT* over1e,
     99                       SkChunkAlloc* );
    100     bool addIfMissing(const SkOpPtT* over1s, const SkOpPtT* over1e,
    101                       const SkOpPtT* over2s, const SkOpPtT* over2e,
    102                       double tStart, double tEnd,
    103                       SkOpPtT* coinPtTStart, const SkOpPtT* coinPtTEnd,
    104                       SkOpPtT* oppPtTStart, const SkOpPtT* oppPtTEnd,
    105                       SkChunkAlloc* );
    106     void addOverlap(SkOpSegment* seg1, SkOpSegment* seg1o, SkOpSegment* seg2, SkOpSegment* seg2o,
    107                     SkOpPtT* overS, SkOpPtT* overE, SkChunkAlloc* );
    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;
    115     bool overlap(const SkOpPtT* coinStart1, const SkOpPtT* coinEnd1,
    116                  const SkOpPtT* coinStart2, const SkOpPtT* coinEnd2,
    117                  double* overS, double* overE) const;
    118 
    119     bool testForCoincidence(const SkCoincidentSpans* outer, const SkOpPtT* testS,
    120                             const SkOpPtT* testE) const;
    121     SkCoincidentSpans* fHead;
    122     SkCoincidentSpans* fTop;
    123     SkDEBUGCODE_(SkOpGlobalState* fDebugState);
    124 };
    125 
    126 #endif
    127