Sat, 03 Jan 2015 20:18:00 +0100
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 2012 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 SkIntersections_DEFINE |
michael@0 | 8 | #define SkIntersections_DEFINE |
michael@0 | 9 | |
michael@0 | 10 | #include "SkPathOpsCubic.h" |
michael@0 | 11 | #include "SkPathOpsLine.h" |
michael@0 | 12 | #include "SkPathOpsPoint.h" |
michael@0 | 13 | #include "SkPathOpsQuad.h" |
michael@0 | 14 | |
michael@0 | 15 | class SkIntersections { |
michael@0 | 16 | public: |
michael@0 | 17 | SkIntersections() |
michael@0 | 18 | : fSwap(0) |
michael@0 | 19 | #ifdef SK_DEBUG |
michael@0 | 20 | , fDepth(0) |
michael@0 | 21 | #endif |
michael@0 | 22 | { |
michael@0 | 23 | sk_bzero(fPt, sizeof(fPt)); |
michael@0 | 24 | sk_bzero(fT, sizeof(fT)); |
michael@0 | 25 | sk_bzero(fIsCoincident, sizeof(fIsCoincident)); |
michael@0 | 26 | reset(); |
michael@0 | 27 | fMax = 0; // require that the caller set the max |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | class TArray { |
michael@0 | 31 | public: |
michael@0 | 32 | explicit TArray(const double ts[9]) : fTArray(ts) {} |
michael@0 | 33 | double operator[](int n) const { |
michael@0 | 34 | return fTArray[n]; |
michael@0 | 35 | } |
michael@0 | 36 | const double* fTArray; |
michael@0 | 37 | }; |
michael@0 | 38 | TArray operator[](int n) const { return TArray(fT[n]); } |
michael@0 | 39 | |
michael@0 | 40 | void set(const SkIntersections& i) { |
michael@0 | 41 | memcpy(fPt, i.fPt, sizeof(fPt)); |
michael@0 | 42 | memcpy(fT, i.fT, sizeof(fT)); |
michael@0 | 43 | memcpy(fIsCoincident, i.fIsCoincident, sizeof(fIsCoincident)); |
michael@0 | 44 | fUsed = i.fUsed; |
michael@0 | 45 | fMax = i.fMax; |
michael@0 | 46 | fSwap = i.fSwap; |
michael@0 | 47 | SkDEBUGCODE(fDepth = i.fDepth); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | void allowNear(bool nearAllowed) { |
michael@0 | 51 | fAllowNear = nearAllowed; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | int cubic(const SkPoint a[4]) { |
michael@0 | 55 | SkDCubic cubic; |
michael@0 | 56 | cubic.set(a); |
michael@0 | 57 | fMax = 1; // self intersect |
michael@0 | 58 | return intersect(cubic); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | int cubicCubic(const SkPoint a[4], const SkPoint b[4]) { |
michael@0 | 62 | SkDCubic aCubic; |
michael@0 | 63 | aCubic.set(a); |
michael@0 | 64 | SkDCubic bCubic; |
michael@0 | 65 | bCubic.set(b); |
michael@0 | 66 | fMax = 9; |
michael@0 | 67 | return intersect(aCubic, bCubic); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | int cubicHorizontal(const SkPoint a[4], SkScalar left, SkScalar right, SkScalar y, |
michael@0 | 71 | bool flipped) { |
michael@0 | 72 | SkDCubic cubic; |
michael@0 | 73 | cubic.set(a); |
michael@0 | 74 | fMax = 3; |
michael@0 | 75 | return horizontal(cubic, left, right, y, flipped); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | int cubicVertical(const SkPoint a[4], SkScalar top, SkScalar bottom, SkScalar x, bool flipped) { |
michael@0 | 79 | SkDCubic cubic; |
michael@0 | 80 | cubic.set(a); |
michael@0 | 81 | fMax = 3; |
michael@0 | 82 | return vertical(cubic, top, bottom, x, flipped); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | int cubicLine(const SkPoint a[4], const SkPoint b[2]) { |
michael@0 | 86 | SkDCubic cubic; |
michael@0 | 87 | cubic.set(a); |
michael@0 | 88 | SkDLine line; |
michael@0 | 89 | line.set(b); |
michael@0 | 90 | fMax = 3; |
michael@0 | 91 | return intersect(cubic, line); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | int cubicQuad(const SkPoint a[4], const SkPoint b[3]) { |
michael@0 | 95 | SkDCubic cubic; |
michael@0 | 96 | cubic.set(a); |
michael@0 | 97 | SkDQuad quad; |
michael@0 | 98 | quad.set(b); |
michael@0 | 99 | fMax = 6; |
michael@0 | 100 | return intersect(cubic, quad); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | bool hasT(double t) const { |
michael@0 | 104 | SkASSERT(t == 0 || t == 1); |
michael@0 | 105 | return fUsed > 0 && (t == 0 ? fT[0][0] == 0 : fT[0][fUsed - 1] == 1); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | int insertSwap(double one, double two, const SkDPoint& pt) { |
michael@0 | 109 | if (fSwap) { |
michael@0 | 110 | return insert(two, one, pt); |
michael@0 | 111 | } else { |
michael@0 | 112 | return insert(one, two, pt); |
michael@0 | 113 | } |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | bool isCoincident(int index) { |
michael@0 | 117 | return (fIsCoincident[0] & 1 << index) != 0; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | int lineHorizontal(const SkPoint a[2], SkScalar left, SkScalar right, SkScalar y, |
michael@0 | 121 | bool flipped) { |
michael@0 | 122 | SkDLine line; |
michael@0 | 123 | line.set(a); |
michael@0 | 124 | fMax = 2; |
michael@0 | 125 | return horizontal(line, left, right, y, flipped); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | int lineVertical(const SkPoint a[2], SkScalar top, SkScalar bottom, SkScalar x, bool flipped) { |
michael@0 | 129 | SkDLine line; |
michael@0 | 130 | line.set(a); |
michael@0 | 131 | fMax = 2; |
michael@0 | 132 | return vertical(line, top, bottom, x, flipped); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | int lineLine(const SkPoint a[2], const SkPoint b[2]) { |
michael@0 | 136 | SkDLine aLine, bLine; |
michael@0 | 137 | aLine.set(a); |
michael@0 | 138 | bLine.set(b); |
michael@0 | 139 | fMax = 2; |
michael@0 | 140 | return intersect(aLine, bLine); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | const SkDPoint& pt(int index) const { |
michael@0 | 144 | return fPt[index]; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | int quadHorizontal(const SkPoint a[3], SkScalar left, SkScalar right, SkScalar y, |
michael@0 | 148 | bool flipped) { |
michael@0 | 149 | SkDQuad quad; |
michael@0 | 150 | quad.set(a); |
michael@0 | 151 | fMax = 2; |
michael@0 | 152 | return horizontal(quad, left, right, y, flipped); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | int quadVertical(const SkPoint a[3], SkScalar top, SkScalar bottom, SkScalar x, bool flipped) { |
michael@0 | 156 | SkDQuad quad; |
michael@0 | 157 | quad.set(a); |
michael@0 | 158 | fMax = 2; |
michael@0 | 159 | return vertical(quad, top, bottom, x, flipped); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | int quadLine(const SkPoint a[3], const SkPoint b[2]) { |
michael@0 | 163 | SkDQuad quad; |
michael@0 | 164 | quad.set(a); |
michael@0 | 165 | SkDLine line; |
michael@0 | 166 | line.set(b); |
michael@0 | 167 | fMax = 2; |
michael@0 | 168 | return intersect(quad, line); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | int quadQuad(const SkPoint a[3], const SkPoint b[3]) { |
michael@0 | 172 | SkDQuad aQuad; |
michael@0 | 173 | aQuad.set(a); |
michael@0 | 174 | SkDQuad bQuad; |
michael@0 | 175 | bQuad.set(b); |
michael@0 | 176 | fMax = 4; |
michael@0 | 177 | return intersect(aQuad, bQuad); |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | // leaves flip, swap, max alone |
michael@0 | 181 | void reset() { |
michael@0 | 182 | fAllowNear = true; |
michael@0 | 183 | fUsed = 0; |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | void setMax(int max) { |
michael@0 | 187 | fMax = max; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | void swap() { |
michael@0 | 191 | fSwap ^= true; |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | void swapPts(); |
michael@0 | 195 | |
michael@0 | 196 | bool swapped() const { |
michael@0 | 197 | return fSwap; |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | int used() const { |
michael@0 | 201 | return fUsed; |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | void downDepth() { |
michael@0 | 205 | SkASSERT(--fDepth >= 0); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | void upDepth() { |
michael@0 | 209 | SkASSERT(++fDepth < 16); |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | void append(const SkIntersections& ); |
michael@0 | 213 | static double Axial(const SkDQuad& , const SkDPoint& , bool vertical); |
michael@0 | 214 | void cleanUpCoincidence(); |
michael@0 | 215 | int coincidentUsed() const; |
michael@0 | 216 | int cubicRay(const SkPoint pts[4], const SkDLine& line); |
michael@0 | 217 | void flip(); |
michael@0 | 218 | int horizontal(const SkDLine&, double y); |
michael@0 | 219 | int horizontal(const SkDLine&, double left, double right, double y, bool flipped); |
michael@0 | 220 | int horizontal(const SkDQuad&, double left, double right, double y, bool flipped); |
michael@0 | 221 | int horizontal(const SkDQuad&, double left, double right, double y, double tRange[2]); |
michael@0 | 222 | int horizontal(const SkDCubic&, double y, double tRange[3]); |
michael@0 | 223 | int horizontal(const SkDCubic&, double left, double right, double y, bool flipped); |
michael@0 | 224 | int horizontal(const SkDCubic&, double left, double right, double y, double tRange[3]); |
michael@0 | 225 | // FIXME : does not respect swap |
michael@0 | 226 | int insert(double one, double two, const SkDPoint& pt); |
michael@0 | 227 | void insertNear(double one, double two, const SkDPoint& pt); |
michael@0 | 228 | // start if index == 0 : end if index == 1 |
michael@0 | 229 | void insertCoincident(double one, double two, const SkDPoint& pt); |
michael@0 | 230 | int intersect(const SkDLine&, const SkDLine&); |
michael@0 | 231 | int intersect(const SkDQuad&, const SkDLine&); |
michael@0 | 232 | int intersect(const SkDQuad&, const SkDQuad&); |
michael@0 | 233 | int intersect(const SkDCubic&); // return true if cubic self-intersects |
michael@0 | 234 | int intersect(const SkDCubic&, const SkDLine&); |
michael@0 | 235 | int intersect(const SkDCubic&, const SkDQuad&); |
michael@0 | 236 | int intersect(const SkDCubic&, const SkDCubic&); |
michael@0 | 237 | int intersectRay(const SkDLine&, const SkDLine&); |
michael@0 | 238 | int intersectRay(const SkDQuad&, const SkDLine&); |
michael@0 | 239 | int intersectRay(const SkDCubic&, const SkDLine&); |
michael@0 | 240 | static SkDPoint Line(const SkDLine&, const SkDLine&); |
michael@0 | 241 | int lineRay(const SkPoint pts[2], const SkDLine& line); |
michael@0 | 242 | void offset(int base, double start, double end); |
michael@0 | 243 | void quickRemoveOne(int index, int replace); |
michael@0 | 244 | int quadRay(const SkPoint pts[3], const SkDLine& line); |
michael@0 | 245 | void removeOne(int index); |
michael@0 | 246 | static bool Test(const SkDLine& , const SkDLine&); |
michael@0 | 247 | int vertical(const SkDLine&, double x); |
michael@0 | 248 | int vertical(const SkDLine&, double top, double bottom, double x, bool flipped); |
michael@0 | 249 | int vertical(const SkDQuad&, double top, double bottom, double x, bool flipped); |
michael@0 | 250 | int vertical(const SkDCubic&, double top, double bottom, double x, bool flipped); |
michael@0 | 251 | int verticalCubic(const SkPoint a[4], SkScalar top, SkScalar bottom, SkScalar x, bool flipped); |
michael@0 | 252 | int verticalLine(const SkPoint a[2], SkScalar top, SkScalar bottom, SkScalar x, bool flipped); |
michael@0 | 253 | int verticalQuad(const SkPoint a[3], SkScalar top, SkScalar bottom, SkScalar x, bool flipped); |
michael@0 | 254 | |
michael@0 | 255 | int depth() const { |
michael@0 | 256 | #ifdef SK_DEBUG |
michael@0 | 257 | return fDepth; |
michael@0 | 258 | #else |
michael@0 | 259 | return 0; |
michael@0 | 260 | #endif |
michael@0 | 261 | } |
michael@0 | 262 | |
michael@0 | 263 | private: |
michael@0 | 264 | bool cubicCheckCoincidence(const SkDCubic& c1, const SkDCubic& c2); |
michael@0 | 265 | bool cubicExactEnd(const SkDCubic& cubic1, bool start, const SkDCubic& cubic2); |
michael@0 | 266 | void cubicNearEnd(const SkDCubic& cubic1, bool start, const SkDCubic& cubic2, const SkDRect& ); |
michael@0 | 267 | void cleanUpParallelLines(bool parallel); |
michael@0 | 268 | void computePoints(const SkDLine& line, int used); |
michael@0 | 269 | // used by addCoincident to remove ordinary intersections in range |
michael@0 | 270 | // void remove(double one, double two, const SkDPoint& startPt, const SkDPoint& endPt); |
michael@0 | 271 | |
michael@0 | 272 | SkDPoint fPt[9]; // FIXME: since scans store points as SkPoint, this should also |
michael@0 | 273 | double fT[2][9]; |
michael@0 | 274 | uint16_t fIsCoincident[2]; // bit set for each curve's coincident T |
michael@0 | 275 | unsigned char fUsed; |
michael@0 | 276 | unsigned char fMax; |
michael@0 | 277 | bool fAllowNear; |
michael@0 | 278 | bool fSwap; |
michael@0 | 279 | #ifdef SK_DEBUG |
michael@0 | 280 | int fDepth; |
michael@0 | 281 | #endif |
michael@0 | 282 | }; |
michael@0 | 283 | |
michael@0 | 284 | extern int (SkIntersections::*CurveRay[])(const SkPoint[], const SkDLine& ); |
michael@0 | 285 | extern int (SkIntersections::*CurveVertical[])(const SkPoint[], SkScalar top, SkScalar bottom, |
michael@0 | 286 | SkScalar x, bool flipped); |
michael@0 | 287 | |
michael@0 | 288 | #endif |