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 | /* |
michael@0 | 3 | * Copyright 2006 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #include "Sk1DPathEffect.h" |
michael@0 | 11 | #include "SkReadBuffer.h" |
michael@0 | 12 | #include "SkWriteBuffer.h" |
michael@0 | 13 | #include "SkPathMeasure.h" |
michael@0 | 14 | |
michael@0 | 15 | bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src, |
michael@0 | 16 | SkStrokeRec*, const SkRect*) const { |
michael@0 | 17 | SkPathMeasure meas(src, false); |
michael@0 | 18 | do { |
michael@0 | 19 | SkScalar length = meas.getLength(); |
michael@0 | 20 | SkScalar distance = this->begin(length); |
michael@0 | 21 | while (distance < length) { |
michael@0 | 22 | SkScalar delta = this->next(dst, distance, meas); |
michael@0 | 23 | if (delta <= 0) { |
michael@0 | 24 | break; |
michael@0 | 25 | } |
michael@0 | 26 | distance += delta; |
michael@0 | 27 | } |
michael@0 | 28 | } while (meas.nextContour()); |
michael@0 | 29 | return true; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 33 | |
michael@0 | 34 | SkPath1DPathEffect::SkPath1DPathEffect(const SkPath& path, SkScalar advance, |
michael@0 | 35 | SkScalar phase, Style style) : fPath(path) |
michael@0 | 36 | { |
michael@0 | 37 | if (advance <= 0 || path.isEmpty()) { |
michael@0 | 38 | SkDEBUGF(("SkPath1DPathEffect can't use advance <= 0\n")); |
michael@0 | 39 | fAdvance = 0; // signals we can't draw anything |
michael@0 | 40 | fInitialOffset = 0; |
michael@0 | 41 | fStyle = kStyleCount; |
michael@0 | 42 | } else { |
michael@0 | 43 | // cleanup their phase parameter, inverting it so that it becomes an |
michael@0 | 44 | // offset along the path (to match the interpretation in PostScript) |
michael@0 | 45 | if (phase < 0) { |
michael@0 | 46 | phase = -phase; |
michael@0 | 47 | if (phase > advance) { |
michael@0 | 48 | phase = SkScalarMod(phase, advance); |
michael@0 | 49 | } |
michael@0 | 50 | } else { |
michael@0 | 51 | if (phase > advance) { |
michael@0 | 52 | phase = SkScalarMod(phase, advance); |
michael@0 | 53 | } |
michael@0 | 54 | phase = advance - phase; |
michael@0 | 55 | } |
michael@0 | 56 | // now catch the edge case where phase == advance (within epsilon) |
michael@0 | 57 | if (phase >= advance) { |
michael@0 | 58 | phase = 0; |
michael@0 | 59 | } |
michael@0 | 60 | SkASSERT(phase >= 0); |
michael@0 | 61 | |
michael@0 | 62 | fAdvance = advance; |
michael@0 | 63 | fInitialOffset = phase; |
michael@0 | 64 | |
michael@0 | 65 | if ((unsigned)style >= kStyleCount) { |
michael@0 | 66 | SkDEBUGF(("SkPath1DPathEffect style enum out of range %d\n", style)); |
michael@0 | 67 | } |
michael@0 | 68 | fStyle = style; |
michael@0 | 69 | } |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src, |
michael@0 | 73 | SkStrokeRec* rec, const SkRect* cullRect) const { |
michael@0 | 74 | if (fAdvance > 0) { |
michael@0 | 75 | rec->setFillStyle(); |
michael@0 | 76 | return this->INHERITED::filterPath(dst, src, rec, cullRect); |
michael@0 | 77 | } |
michael@0 | 78 | return false; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | static bool morphpoints(SkPoint dst[], const SkPoint src[], int count, |
michael@0 | 82 | SkPathMeasure& meas, SkScalar dist) { |
michael@0 | 83 | for (int i = 0; i < count; i++) { |
michael@0 | 84 | SkPoint pos; |
michael@0 | 85 | SkVector tangent; |
michael@0 | 86 | |
michael@0 | 87 | SkScalar sx = src[i].fX; |
michael@0 | 88 | SkScalar sy = src[i].fY; |
michael@0 | 89 | |
michael@0 | 90 | if (!meas.getPosTan(dist + sx, &pos, &tangent)) { |
michael@0 | 91 | return false; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | SkMatrix matrix; |
michael@0 | 95 | SkPoint pt; |
michael@0 | 96 | |
michael@0 | 97 | pt.set(sx, sy); |
michael@0 | 98 | matrix.setSinCos(tangent.fY, tangent.fX, 0, 0); |
michael@0 | 99 | matrix.preTranslate(-sx, 0); |
michael@0 | 100 | matrix.postTranslate(pos.fX, pos.fY); |
michael@0 | 101 | matrix.mapPoints(&dst[i], &pt, 1); |
michael@0 | 102 | } |
michael@0 | 103 | return true; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | /* TODO |
michael@0 | 107 | |
michael@0 | 108 | Need differentially more subdivisions when the follow-path is curvy. Not sure how to |
michael@0 | 109 | determine that, but we need it. I guess a cheap answer is let the caller tell us, |
michael@0 | 110 | but that seems like a cop-out. Another answer is to get Rob Johnson to figure it out. |
michael@0 | 111 | */ |
michael@0 | 112 | static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, |
michael@0 | 113 | SkScalar dist) { |
michael@0 | 114 | SkPath::Iter iter(src, false); |
michael@0 | 115 | SkPoint srcP[4], dstP[3]; |
michael@0 | 116 | SkPath::Verb verb; |
michael@0 | 117 | |
michael@0 | 118 | while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) { |
michael@0 | 119 | switch (verb) { |
michael@0 | 120 | case SkPath::kMove_Verb: |
michael@0 | 121 | if (morphpoints(dstP, srcP, 1, meas, dist)) { |
michael@0 | 122 | dst->moveTo(dstP[0]); |
michael@0 | 123 | } |
michael@0 | 124 | break; |
michael@0 | 125 | case SkPath::kLine_Verb: |
michael@0 | 126 | srcP[2] = srcP[1]; |
michael@0 | 127 | srcP[1].set(SkScalarAve(srcP[0].fX, srcP[2].fX), |
michael@0 | 128 | SkScalarAve(srcP[0].fY, srcP[2].fY)); |
michael@0 | 129 | // fall through to quad |
michael@0 | 130 | case SkPath::kQuad_Verb: |
michael@0 | 131 | if (morphpoints(dstP, &srcP[1], 2, meas, dist)) { |
michael@0 | 132 | dst->quadTo(dstP[0], dstP[1]); |
michael@0 | 133 | } |
michael@0 | 134 | break; |
michael@0 | 135 | case SkPath::kCubic_Verb: |
michael@0 | 136 | if (morphpoints(dstP, &srcP[1], 3, meas, dist)) { |
michael@0 | 137 | dst->cubicTo(dstP[0], dstP[1], dstP[2]); |
michael@0 | 138 | } |
michael@0 | 139 | break; |
michael@0 | 140 | case SkPath::kClose_Verb: |
michael@0 | 141 | dst->close(); |
michael@0 | 142 | break; |
michael@0 | 143 | default: |
michael@0 | 144 | SkDEBUGFAIL("unknown verb"); |
michael@0 | 145 | break; |
michael@0 | 146 | } |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | SkPath1DPathEffect::SkPath1DPathEffect(SkReadBuffer& buffer) { |
michael@0 | 151 | fAdvance = buffer.readScalar(); |
michael@0 | 152 | if (fAdvance > 0) { |
michael@0 | 153 | buffer.readPath(&fPath); |
michael@0 | 154 | fInitialOffset = buffer.readScalar(); |
michael@0 | 155 | fStyle = (Style) buffer.readUInt(); |
michael@0 | 156 | } else { |
michael@0 | 157 | SkDEBUGF(("SkPath1DPathEffect can't use advance <= 0\n")); |
michael@0 | 158 | // Make Coverity happy. |
michael@0 | 159 | fInitialOffset = 0; |
michael@0 | 160 | fStyle = kStyleCount; |
michael@0 | 161 | } |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | SkScalar SkPath1DPathEffect::begin(SkScalar contourLength) const { |
michael@0 | 165 | return fInitialOffset; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | void SkPath1DPathEffect::flatten(SkWriteBuffer& buffer) const { |
michael@0 | 169 | this->INHERITED::flatten(buffer); |
michael@0 | 170 | buffer.writeScalar(fAdvance); |
michael@0 | 171 | if (fAdvance > 0) { |
michael@0 | 172 | buffer.writePath(fPath); |
michael@0 | 173 | buffer.writeScalar(fInitialOffset); |
michael@0 | 174 | buffer.writeUInt(fStyle); |
michael@0 | 175 | } |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | SkScalar SkPath1DPathEffect::next(SkPath* dst, SkScalar distance, |
michael@0 | 179 | SkPathMeasure& meas) const { |
michael@0 | 180 | switch (fStyle) { |
michael@0 | 181 | case kTranslate_Style: { |
michael@0 | 182 | SkPoint pos; |
michael@0 | 183 | if (meas.getPosTan(distance, &pos, NULL)) { |
michael@0 | 184 | dst->addPath(fPath, pos.fX, pos.fY); |
michael@0 | 185 | } |
michael@0 | 186 | } break; |
michael@0 | 187 | case kRotate_Style: { |
michael@0 | 188 | SkMatrix matrix; |
michael@0 | 189 | if (meas.getMatrix(distance, &matrix)) { |
michael@0 | 190 | dst->addPath(fPath, matrix); |
michael@0 | 191 | } |
michael@0 | 192 | } break; |
michael@0 | 193 | case kMorph_Style: |
michael@0 | 194 | morphpath(dst, fPath, meas, distance); |
michael@0 | 195 | break; |
michael@0 | 196 | default: |
michael@0 | 197 | SkDEBUGFAIL("unknown Style enum"); |
michael@0 | 198 | break; |
michael@0 | 199 | } |
michael@0 | 200 | return fAdvance; |
michael@0 | 201 | } |