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 | |
michael@0 | 8 | #include "SkIntersections.h" |
michael@0 | 9 | |
michael@0 | 10 | void SkIntersections::append(const SkIntersections& i) { |
michael@0 | 11 | for (int index = 0; index < i.fUsed; ++index) { |
michael@0 | 12 | insert(i[0][index], i[1][index], i.pt(index)); |
michael@0 | 13 | } |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | int (SkIntersections::*CurveVertical[])(const SkPoint[], SkScalar, SkScalar, SkScalar, bool) = { |
michael@0 | 17 | NULL, |
michael@0 | 18 | &SkIntersections::verticalLine, |
michael@0 | 19 | &SkIntersections::verticalQuad, |
michael@0 | 20 | &SkIntersections::verticalCubic |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | int (SkIntersections::*CurveRay[])(const SkPoint[], const SkDLine&) = { |
michael@0 | 24 | NULL, |
michael@0 | 25 | &SkIntersections::lineRay, |
michael@0 | 26 | &SkIntersections::quadRay, |
michael@0 | 27 | &SkIntersections::cubicRay |
michael@0 | 28 | }; |
michael@0 | 29 | |
michael@0 | 30 | int SkIntersections::coincidentUsed() const { |
michael@0 | 31 | if (!fIsCoincident[0]) { |
michael@0 | 32 | SkASSERT(!fIsCoincident[1]); |
michael@0 | 33 | return 0; |
michael@0 | 34 | } |
michael@0 | 35 | int count = 0; |
michael@0 | 36 | SkDEBUGCODE(int count2 = 0;) |
michael@0 | 37 | for (int index = 0; index < fUsed; ++index) { |
michael@0 | 38 | if (fIsCoincident[0] & (1 << index)) { |
michael@0 | 39 | ++count; |
michael@0 | 40 | } |
michael@0 | 41 | #ifdef SK_DEBUG |
michael@0 | 42 | if (fIsCoincident[1] & (1 << index)) { |
michael@0 | 43 | ++count2; |
michael@0 | 44 | } |
michael@0 | 45 | #endif |
michael@0 | 46 | } |
michael@0 | 47 | SkASSERT(count == count2); |
michael@0 | 48 | return count; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | int SkIntersections::cubicRay(const SkPoint pts[4], const SkDLine& line) { |
michael@0 | 52 | SkDCubic cubic; |
michael@0 | 53 | cubic.set(pts); |
michael@0 | 54 | fMax = 3; |
michael@0 | 55 | return intersectRay(cubic, line); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | void SkIntersections::flip() { |
michael@0 | 59 | for (int index = 0; index < fUsed; ++index) { |
michael@0 | 60 | fT[1][index] = 1 - fT[1][index]; |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | int SkIntersections::insert(double one, double two, const SkDPoint& pt) { |
michael@0 | 65 | if (fIsCoincident[0] == 3 && between(fT[0][0], one, fT[0][1])) { |
michael@0 | 66 | // For now, don't allow a mix of coincident and non-coincident intersections |
michael@0 | 67 | return -1; |
michael@0 | 68 | } |
michael@0 | 69 | SkASSERT(fUsed <= 1 || fT[0][0] <= fT[0][1]); |
michael@0 | 70 | int index; |
michael@0 | 71 | for (index = 0; index < fUsed; ++index) { |
michael@0 | 72 | double oldOne = fT[0][index]; |
michael@0 | 73 | double oldTwo = fT[1][index]; |
michael@0 | 74 | if (one == oldOne && two == oldTwo) { |
michael@0 | 75 | return -1; |
michael@0 | 76 | } |
michael@0 | 77 | if (more_roughly_equal(oldOne, one) && more_roughly_equal(oldTwo, two)) { |
michael@0 | 78 | if ((precisely_zero(one) && !precisely_zero(oldOne)) |
michael@0 | 79 | || (precisely_equal(one, 1) && !precisely_equal(oldOne, 1)) |
michael@0 | 80 | || (precisely_zero(two) && !precisely_zero(oldTwo)) |
michael@0 | 81 | || (precisely_equal(two, 1) && !precisely_equal(oldTwo, 1))) { |
michael@0 | 82 | fT[0][index] = one; |
michael@0 | 83 | fT[1][index] = two; |
michael@0 | 84 | fPt[index] = pt; |
michael@0 | 85 | } |
michael@0 | 86 | return -1; |
michael@0 | 87 | } |
michael@0 | 88 | #if ONE_OFF_DEBUG |
michael@0 | 89 | if (pt.roughlyEqual(fPt[index])) { |
michael@0 | 90 | SkDebugf("%s t=%1.9g pts roughly equal\n", __FUNCTION__, one); |
michael@0 | 91 | } |
michael@0 | 92 | #endif |
michael@0 | 93 | if (fT[0][index] > one) { |
michael@0 | 94 | break; |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | if (fUsed >= fMax) { |
michael@0 | 98 | SkASSERT(0); // FIXME : this error, if it is to be handled at runtime in release, must |
michael@0 | 99 | // be propagated all the way back down to the caller, and return failure. |
michael@0 | 100 | fUsed = 0; |
michael@0 | 101 | return 0; |
michael@0 | 102 | } |
michael@0 | 103 | int remaining = fUsed - index; |
michael@0 | 104 | if (remaining > 0) { |
michael@0 | 105 | memmove(&fPt[index + 1], &fPt[index], sizeof(fPt[0]) * remaining); |
michael@0 | 106 | memmove(&fT[0][index + 1], &fT[0][index], sizeof(fT[0][0]) * remaining); |
michael@0 | 107 | memmove(&fT[1][index + 1], &fT[1][index], sizeof(fT[1][0]) * remaining); |
michael@0 | 108 | int clearMask = ~((1 << index) - 1); |
michael@0 | 109 | fIsCoincident[0] += fIsCoincident[0] & clearMask; |
michael@0 | 110 | fIsCoincident[1] += fIsCoincident[1] & clearMask; |
michael@0 | 111 | } |
michael@0 | 112 | fPt[index] = pt; |
michael@0 | 113 | fT[0][index] = one; |
michael@0 | 114 | fT[1][index] = two; |
michael@0 | 115 | ++fUsed; |
michael@0 | 116 | return index; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | void SkIntersections::insertCoincident(double one, double two, const SkDPoint& pt) { |
michael@0 | 120 | int index = insertSwap(one, two, pt); |
michael@0 | 121 | int bit = 1 << index; |
michael@0 | 122 | fIsCoincident[0] |= bit; |
michael@0 | 123 | fIsCoincident[1] |= bit; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | int SkIntersections::lineRay(const SkPoint pts[2], const SkDLine& line) { |
michael@0 | 127 | SkDLine l; |
michael@0 | 128 | l.set(pts); |
michael@0 | 129 | fMax = 2; |
michael@0 | 130 | return intersectRay(l, line); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | void SkIntersections::offset(int base, double start, double end) { |
michael@0 | 134 | for (int index = base; index < fUsed; ++index) { |
michael@0 | 135 | double val = fT[fSwap][index]; |
michael@0 | 136 | val *= end - start; |
michael@0 | 137 | val += start; |
michael@0 | 138 | fT[fSwap][index] = val; |
michael@0 | 139 | } |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | int SkIntersections::quadRay(const SkPoint pts[3], const SkDLine& line) { |
michael@0 | 143 | SkDQuad quad; |
michael@0 | 144 | quad.set(pts); |
michael@0 | 145 | fMax = 2; |
michael@0 | 146 | return intersectRay(quad, line); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | void SkIntersections::quickRemoveOne(int index, int replace) { |
michael@0 | 150 | if (index < replace) { |
michael@0 | 151 | fT[0][index] = fT[0][replace]; |
michael@0 | 152 | } |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | #if 0 |
michael@0 | 156 | void SkIntersections::remove(double one, double two, const SkDPoint& startPt, |
michael@0 | 157 | const SkDPoint& endPt) { |
michael@0 | 158 | for (int index = fUsed - 1; index >= 0; --index) { |
michael@0 | 159 | if (!(fIsCoincident[0] & (1 << index)) && (between(one, fT[fSwap][index], two) |
michael@0 | 160 | || startPt.approximatelyEqual(fPt[index]) |
michael@0 | 161 | || endPt.approximatelyEqual(fPt[index]))) { |
michael@0 | 162 | SkASSERT(fUsed > 0); |
michael@0 | 163 | removeOne(index); |
michael@0 | 164 | } |
michael@0 | 165 | } |
michael@0 | 166 | } |
michael@0 | 167 | #endif |
michael@0 | 168 | |
michael@0 | 169 | void SkIntersections::removeOne(int index) { |
michael@0 | 170 | int remaining = --fUsed - index; |
michael@0 | 171 | if (remaining <= 0) { |
michael@0 | 172 | return; |
michael@0 | 173 | } |
michael@0 | 174 | memmove(&fPt[index], &fPt[index + 1], sizeof(fPt[0]) * remaining); |
michael@0 | 175 | memmove(&fT[0][index], &fT[0][index + 1], sizeof(fT[0][0]) * remaining); |
michael@0 | 176 | memmove(&fT[1][index], &fT[1][index + 1], sizeof(fT[1][0]) * remaining); |
michael@0 | 177 | SkASSERT(fIsCoincident[0] == 0); |
michael@0 | 178 | int coBit = fIsCoincident[0] & (1 << index); |
michael@0 | 179 | fIsCoincident[0] -= ((fIsCoincident[0] >> 1) & ~((1 << index) - 1)) + coBit; |
michael@0 | 180 | SkASSERT(!(coBit ^ (fIsCoincident[1] & (1 << index)))); |
michael@0 | 181 | fIsCoincident[1] -= ((fIsCoincident[1] >> 1) & ~((1 << index) - 1)) + coBit; |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | void SkIntersections::swapPts() { |
michael@0 | 185 | int index; |
michael@0 | 186 | for (index = 0; index < fUsed; ++index) { |
michael@0 | 187 | SkTSwap(fT[0][index], fT[1][index]); |
michael@0 | 188 | } |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | int SkIntersections::verticalLine(const SkPoint a[2], SkScalar top, SkScalar bottom, |
michael@0 | 192 | SkScalar x, bool flipped) { |
michael@0 | 193 | SkDLine line; |
michael@0 | 194 | line.set(a); |
michael@0 | 195 | return vertical(line, top, bottom, x, flipped); |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | int SkIntersections::verticalQuad(const SkPoint a[3], SkScalar top, SkScalar bottom, |
michael@0 | 199 | SkScalar x, bool flipped) { |
michael@0 | 200 | SkDQuad quad; |
michael@0 | 201 | quad.set(a); |
michael@0 | 202 | return vertical(quad, top, bottom, x, flipped); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | int SkIntersections::verticalCubic(const SkPoint a[4], SkScalar top, SkScalar bottom, |
michael@0 | 206 | SkScalar x, bool flipped) { |
michael@0 | 207 | SkDCubic cubic; |
michael@0 | 208 | cubic.set(a); |
michael@0 | 209 | return vertical(cubic, top, bottom, x, flipped); |
michael@0 | 210 | } |