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 2011 Google Inc. |
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 | #include "SkCubicInterval.h" |
michael@0 | 9 | |
michael@0 | 10 | static SkScalar eval_cubic(SkScalar c1, SkScalar c2, SkScalar c3, |
michael@0 | 11 | SkScalar t) { |
michael@0 | 12 | return SkScalarMul(SkScalarMul(SkScalarMul(c3, t) + c2, t) + c1, t); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | static SkScalar find_cubic_t(SkScalar c1, SkScalar c2, SkScalar c3, |
michael@0 | 16 | SkScalar targetX) { |
michael@0 | 17 | SkScalar minT = 0; |
michael@0 | 18 | SkScalar maxT = SK_Scalar1; |
michael@0 | 19 | SkScalar t; |
michael@0 | 20 | |
michael@0 | 21 | for (;;) { |
michael@0 | 22 | t = SkScalarAve(minT, maxT); |
michael@0 | 23 | SkScalar x = eval_cubic(c1, c2, c3, t); |
michael@0 | 24 | if (SkScalarNearlyZero(x - targetX)) { |
michael@0 | 25 | break; |
michael@0 | 26 | } |
michael@0 | 27 | // subdivide the range and try again |
michael@0 | 28 | if (x < targetX) { |
michael@0 | 29 | minT = t; |
michael@0 | 30 | } else { |
michael@0 | 31 | maxT = t; |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | return t; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | /* |
michael@0 | 38 | a(1-t)^3 + 3bt(1-t)^2 + 3ct^2(1-t) + dt^3 |
michael@0 | 39 | a: [0, 0] |
michael@0 | 40 | d: [1, 1] |
michael@0 | 41 | |
michael@0 | 42 | 3bt - 6bt^2 + 3bt^3 + 3ct^2 - 3ct^3 + t^3 |
michael@0 | 43 | C1 = t^1: 3b |
michael@0 | 44 | C2 = t^2: 3c - 6b |
michael@0 | 45 | C3 = t^3: 3b - 3c + 1 |
michael@0 | 46 | |
michael@0 | 47 | ((C3*t + C2)*t + C1)*t |
michael@0 | 48 | */ |
michael@0 | 49 | SkScalar SkEvalCubicInterval(SkScalar x1, SkScalar y1, |
michael@0 | 50 | SkScalar x2, SkScalar y2, |
michael@0 | 51 | SkScalar unitX) { |
michael@0 | 52 | x1 = SkScalarPin(x1, 0, SK_Scalar1); |
michael@0 | 53 | x2 = SkScalarPin(x2, 0, SK_Scalar1); |
michael@0 | 54 | unitX = SkScalarPin(unitX, 0, SK_Scalar1); |
michael@0 | 55 | |
michael@0 | 56 | // First compute our coefficients in X |
michael@0 | 57 | x1 *= 3; |
michael@0 | 58 | x2 *= 3; |
michael@0 | 59 | |
michael@0 | 60 | // now search for t given unitX |
michael@0 | 61 | SkScalar t = find_cubic_t(x1, x2 - 2*x1, x1 - x2 + SK_Scalar1, unitX); |
michael@0 | 62 | |
michael@0 | 63 | // now evaluate the cubic in Y |
michael@0 | 64 | y1 *= 3; |
michael@0 | 65 | y2 *= 3; |
michael@0 | 66 | return eval_cubic(y1, y2 - 2*y1, y1 - y2 + SK_Scalar1, t); |
michael@0 | 67 | } |