gfx/skia/trunk/src/pathops/SkOpContour.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7 #ifndef SkOpContour_DEFINED
michael@0 8 #define SkOpContour_DEFINED
michael@0 9
michael@0 10 #include "SkOpSegment.h"
michael@0 11 #include "SkTArray.h"
michael@0 12
michael@0 13 class SkIntersections;
michael@0 14 class SkOpContour;
michael@0 15 class SkPathWriter;
michael@0 16
michael@0 17 struct SkCoincidence {
michael@0 18 SkOpContour* fOther;
michael@0 19 int fSegments[2];
michael@0 20 double fTs[2][2];
michael@0 21 SkPoint fPts[2];
michael@0 22 };
michael@0 23
michael@0 24 class SkOpContour {
michael@0 25 public:
michael@0 26 SkOpContour() {
michael@0 27 reset();
michael@0 28 #ifdef SK_DEBUG
michael@0 29 fID = ++SkPathOpsDebug::gContourID;
michael@0 30 #endif
michael@0 31 }
michael@0 32
michael@0 33 bool operator<(const SkOpContour& rh) const {
michael@0 34 return fBounds.fTop == rh.fBounds.fTop
michael@0 35 ? fBounds.fLeft < rh.fBounds.fLeft
michael@0 36 : fBounds.fTop < rh.fBounds.fTop;
michael@0 37 }
michael@0 38
michael@0 39 bool addCoincident(int index, SkOpContour* other, int otherIndex,
michael@0 40 const SkIntersections& ts, bool swap);
michael@0 41 void addCoincidentPoints();
michael@0 42
michael@0 43 void addCross(const SkOpContour* crosser) {
michael@0 44 #ifdef DEBUG_CROSS
michael@0 45 for (int index = 0; index < fCrosses.count(); ++index) {
michael@0 46 SkASSERT(fCrosses[index] != crosser);
michael@0 47 }
michael@0 48 #endif
michael@0 49 fCrosses.push_back(crosser);
michael@0 50 }
michael@0 51
michael@0 52 void addCubic(const SkPoint pts[4]) {
michael@0 53 fSegments.push_back().addCubic(pts, fOperand, fXor);
michael@0 54 fContainsCurves = fContainsCubics = true;
michael@0 55 }
michael@0 56
michael@0 57 int addLine(const SkPoint pts[2]) {
michael@0 58 fSegments.push_back().addLine(pts, fOperand, fXor);
michael@0 59 return fSegments.count();
michael@0 60 }
michael@0 61
michael@0 62 void addOtherT(int segIndex, int tIndex, double otherT, int otherIndex) {
michael@0 63 fSegments[segIndex].addOtherT(tIndex, otherT, otherIndex);
michael@0 64 }
michael@0 65
michael@0 66 bool addPartialCoincident(int index, SkOpContour* other, int otherIndex,
michael@0 67 const SkIntersections& ts, int ptIndex, bool swap);
michael@0 68
michael@0 69 int addQuad(const SkPoint pts[3]) {
michael@0 70 fSegments.push_back().addQuad(pts, fOperand, fXor);
michael@0 71 fContainsCurves = true;
michael@0 72 return fSegments.count();
michael@0 73 }
michael@0 74
michael@0 75 int addT(int segIndex, SkOpContour* other, int otherIndex, const SkPoint& pt, double newT) {
michael@0 76 setContainsIntercepts();
michael@0 77 return fSegments[segIndex].addT(&other->fSegments[otherIndex], pt, newT);
michael@0 78 }
michael@0 79
michael@0 80 int addSelfT(int segIndex, SkOpContour* other, int otherIndex, const SkPoint& pt, double newT) {
michael@0 81 setContainsIntercepts();
michael@0 82 return fSegments[segIndex].addSelfT(&other->fSegments[otherIndex], pt, newT);
michael@0 83 }
michael@0 84
michael@0 85 const SkPathOpsBounds& bounds() const {
michael@0 86 return fBounds;
michael@0 87 }
michael@0 88
michael@0 89 void calcCoincidentWinding();
michael@0 90 void calcPartialCoincidentWinding();
michael@0 91
michael@0 92 void checkEnds() {
michael@0 93 if (!fContainsCurves) {
michael@0 94 return;
michael@0 95 }
michael@0 96 int segmentCount = fSegments.count();
michael@0 97 for (int sIndex = 0; sIndex < segmentCount; ++sIndex) {
michael@0 98 SkOpSegment* segment = &fSegments[sIndex];
michael@0 99 if (segment->verb() == SkPath::kLine_Verb) {
michael@0 100 continue;
michael@0 101 }
michael@0 102 if (segment->done()) {
michael@0 103 continue; // likely coincident, nothing to do
michael@0 104 }
michael@0 105 segment->checkEnds();
michael@0 106 }
michael@0 107 }
michael@0 108
michael@0 109 // if same point has different T values, choose a common T
michael@0 110 void checkTiny() {
michael@0 111 int segmentCount = fSegments.count();
michael@0 112 if (segmentCount <= 2) {
michael@0 113 return;
michael@0 114 }
michael@0 115 for (int sIndex = 0; sIndex < segmentCount; ++sIndex) {
michael@0 116 fSegments[sIndex].checkTiny();
michael@0 117 }
michael@0 118 }
michael@0 119
michael@0 120 void complete() {
michael@0 121 setBounds();
michael@0 122 fContainsIntercepts = false;
michael@0 123 }
michael@0 124
michael@0 125 bool containsCubics() const {
michael@0 126 return fContainsCubics;
michael@0 127 }
michael@0 128
michael@0 129 bool crosses(const SkOpContour* crosser) const {
michael@0 130 for (int index = 0; index < fCrosses.count(); ++index) {
michael@0 131 if (fCrosses[index] == crosser) {
michael@0 132 return true;
michael@0 133 }
michael@0 134 }
michael@0 135 return false;
michael@0 136 }
michael@0 137
michael@0 138 bool done() const {
michael@0 139 return fDone;
michael@0 140 }
michael@0 141
michael@0 142 const SkPoint& end() const {
michael@0 143 const SkOpSegment& segment = fSegments.back();
michael@0 144 return segment.pts()[SkPathOpsVerbToPoints(segment.verb())];
michael@0 145 }
michael@0 146
michael@0 147 void fixOtherTIndex() {
michael@0 148 int segmentCount = fSegments.count();
michael@0 149 for (int sIndex = 0; sIndex < segmentCount; ++sIndex) {
michael@0 150 fSegments[sIndex].fixOtherTIndex();
michael@0 151 }
michael@0 152 }
michael@0 153
michael@0 154 void joinCoincidence() {
michael@0 155 joinCoincidence(fCoincidences, false);
michael@0 156 joinCoincidence(fPartialCoincidences, true);
michael@0 157 }
michael@0 158
michael@0 159 SkOpSegment* nonVerticalSegment(int* start, int* end);
michael@0 160
michael@0 161 bool operand() const {
michael@0 162 return fOperand;
michael@0 163 }
michael@0 164
michael@0 165 void reset() {
michael@0 166 fSegments.reset();
michael@0 167 fBounds.set(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
michael@0 168 fContainsCurves = fContainsCubics = fContainsIntercepts = fDone = false;
michael@0 169 }
michael@0 170
michael@0 171 SkTArray<SkOpSegment>& segments() {
michael@0 172 return fSegments;
michael@0 173 }
michael@0 174
michael@0 175 void setContainsIntercepts() {
michael@0 176 fContainsIntercepts = true;
michael@0 177 }
michael@0 178
michael@0 179 void setOperand(bool isOp) {
michael@0 180 fOperand = isOp;
michael@0 181 }
michael@0 182
michael@0 183 void setOppXor(bool isOppXor) {
michael@0 184 fOppXor = isOppXor;
michael@0 185 int segmentCount = fSegments.count();
michael@0 186 for (int test = 0; test < segmentCount; ++test) {
michael@0 187 fSegments[test].setOppXor(isOppXor);
michael@0 188 }
michael@0 189 }
michael@0 190
michael@0 191 void setXor(bool isXor) {
michael@0 192 fXor = isXor;
michael@0 193 }
michael@0 194
michael@0 195 void sortSegments();
michael@0 196
michael@0 197 const SkPoint& start() const {
michael@0 198 return fSegments.front().pts()[0];
michael@0 199 }
michael@0 200
michael@0 201 void toPath(SkPathWriter* path) const;
michael@0 202
michael@0 203 void toPartialBackward(SkPathWriter* path) const {
michael@0 204 int segmentCount = fSegments.count();
michael@0 205 for (int test = segmentCount - 1; test >= 0; --test) {
michael@0 206 fSegments[test].addCurveTo(1, 0, path, true);
michael@0 207 }
michael@0 208 }
michael@0 209
michael@0 210 void toPartialForward(SkPathWriter* path) const {
michael@0 211 int segmentCount = fSegments.count();
michael@0 212 for (int test = 0; test < segmentCount; ++test) {
michael@0 213 fSegments[test].addCurveTo(0, 1, path, true);
michael@0 214 }
michael@0 215 }
michael@0 216
michael@0 217 void topSortableSegment(const SkPoint& topLeft, SkPoint* bestXY, SkOpSegment** topStart);
michael@0 218 SkOpSegment* undoneSegment(int* start, int* end);
michael@0 219
michael@0 220 int updateSegment(int index, const SkPoint* pts) {
michael@0 221 SkOpSegment& segment = fSegments[index];
michael@0 222 segment.updatePts(pts);
michael@0 223 return SkPathOpsVerbToPoints(segment.verb()) + 1;
michael@0 224 }
michael@0 225
michael@0 226 #if DEBUG_TEST
michael@0 227 SkTArray<SkOpSegment>& debugSegments() {
michael@0 228 return fSegments;
michael@0 229 }
michael@0 230 #endif
michael@0 231
michael@0 232 #if DEBUG_ACTIVE_SPANS || DEBUG_ACTIVE_SPANS_FIRST_ONLY
michael@0 233 void debugShowActiveSpans() {
michael@0 234 for (int index = 0; index < fSegments.count(); ++index) {
michael@0 235 fSegments[index].debugShowActiveSpans();
michael@0 236 }
michael@0 237 }
michael@0 238 #endif
michael@0 239
michael@0 240 #if DEBUG_SHOW_WINDING
michael@0 241 int debugShowWindingValues(int totalSegments, int ofInterest);
michael@0 242 static void debugShowWindingValues(const SkTArray<SkOpContour*, true>& contourList);
michael@0 243 #endif
michael@0 244
michael@0 245 private:
michael@0 246 void calcCommonCoincidentWinding(const SkCoincidence& );
michael@0 247 void joinCoincidence(const SkTArray<SkCoincidence, true>& , bool partial);
michael@0 248 void setBounds();
michael@0 249
michael@0 250 SkTArray<SkOpSegment> fSegments;
michael@0 251 SkTArray<SkOpSegment*, true> fSortedSegments;
michael@0 252 int fFirstSorted;
michael@0 253 SkTArray<SkCoincidence, true> fCoincidences;
michael@0 254 SkTArray<SkCoincidence, true> fPartialCoincidences;
michael@0 255 SkTArray<const SkOpContour*, true> fCrosses;
michael@0 256 SkPathOpsBounds fBounds;
michael@0 257 bool fContainsIntercepts; // FIXME: is this used by anybody?
michael@0 258 bool fContainsCubics;
michael@0 259 bool fContainsCurves;
michael@0 260 bool fDone;
michael@0 261 bool fOperand; // true for the second argument to a binary operator
michael@0 262 bool fXor;
michael@0 263 bool fOppXor;
michael@0 264 #ifdef SK_DEBUG
michael@0 265 int fID;
michael@0 266 #endif
michael@0 267 };
michael@0 268
michael@0 269 #endif

mercurial