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.
2 /*
3 * Copyright 2008 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
10 #ifndef SkFloat_DEFINED
11 #define SkFloat_DEFINED
13 #include "SkFixed.h"
15 class SkFloat {
16 public:
17 SkFloat() {}
19 void setZero() { fPacked = 0; }
20 // void setShift(int value, int shift) { fPacked = SetShift(value, shift); }
21 void setInt(int value) { fPacked = SetShift(value, 0); }
22 void setFixed(SkFixed value) { fPacked = SetShift(value, -16); }
24 // int getShift(int shift) const { return GetShift(fPacked, shift); }
25 int getInt() const { return GetShift(fPacked, 0); }
26 SkFixed getFixed() const { return GetShift(fPacked, -16); }
28 void abs() { fPacked = Abs(fPacked); }
29 void negate() { fPacked = Neg(fPacked); }
31 void shiftLeft(int bits) { fPacked = Shift(fPacked, bits); }
32 void setShiftLeft(const SkFloat& a, int bits) { fPacked = Shift(a.fPacked, bits); }
34 void shiftRight(int bits) { fPacked = Shift(fPacked, -bits); }
35 void setShiftRight(const SkFloat& a, int bits) { fPacked = Shift(a.fPacked, -bits); }
37 void add(const SkFloat& a) { fPacked = Add(fPacked, a.fPacked); }
38 void setAdd(const SkFloat& a, const SkFloat& b) { fPacked = Add(a.fPacked, b.fPacked); }
40 void sub(const SkFloat& a) { fPacked = Add(fPacked, Neg(a.fPacked)); }
41 void setSub(const SkFloat& a, const SkFloat& b) { fPacked = Add(a.fPacked, Neg(b.fPacked)); }
43 void mul(const SkFloat& a) { fPacked = Mul(fPacked, a.fPacked); }
44 void setMul(const SkFloat& a, const SkFloat& b) { fPacked = Mul(a.fPacked, b.fPacked); }
46 void div(const SkFloat& a) { fPacked = Div(fPacked, a.fPacked); }
47 void setDiv(const SkFloat& a, const SkFloat& b) { fPacked = Div(a.fPacked, b.fPacked); }
49 void sqrt() { fPacked = Sqrt(fPacked); }
50 void setSqrt(const SkFloat& a) { fPacked = Sqrt(a.fPacked); }
51 void cubeRoot() { fPacked = CubeRoot(fPacked); }
52 void setCubeRoot(const SkFloat& a) { fPacked = CubeRoot(a.fPacked); }
54 friend bool operator==(const SkFloat& a, const SkFloat& b) { return a.fPacked == b.fPacked; }
55 friend bool operator!=(const SkFloat& a, const SkFloat& b) { return a.fPacked != b.fPacked; }
56 friend bool operator<(const SkFloat& a, const SkFloat& b) { return Cmp(a.fPacked, b.fPacked) < 0; }
57 friend bool operator<=(const SkFloat& a, const SkFloat& b) { return Cmp(a.fPacked, b.fPacked) <= 0; }
58 friend bool operator>(const SkFloat& a, const SkFloat& b) { return Cmp(a.fPacked, b.fPacked) > 0; }
59 friend bool operator>=(const SkFloat& a, const SkFloat& b) { return Cmp(a.fPacked, b.fPacked) >= 0; }
61 #ifdef SK_DEBUG
62 static void UnitTest();
64 void assertEquals(float f, int tolerance = 0)
65 {
66 union {
67 float fFloat;
68 int32_t fPacked;
69 } tmp;
71 tmp.fFloat = f;
72 int d = tmp.fPacked - fPacked;
73 SkASSERT(SkAbs32(d) <= tolerance);
74 }
75 float getFloat() const
76 {
77 union {
78 float fFloat;
79 int32_t fPacked;
80 } tmp;
82 tmp.fPacked = fPacked;
83 return tmp.fFloat;
84 }
85 #endif
87 private:
88 int32_t fPacked;
90 public:
91 static int GetShift(int32_t packed, int shift);
92 static int32_t SetShift(int value, int shift);
93 static int32_t Neg(int32_t);
94 static int32_t Abs(int32_t packed) { return (uint32_t)(packed << 1) >> 1; }
95 static int32_t Shift(int32_t, int bits);
96 static int32_t Add(int32_t, int32_t);
97 static int32_t Mul(int32_t, int32_t);
98 static int32_t MulInt(int32_t, int);
99 static int32_t Div(int32_t, int32_t);
100 static int32_t DivInt(int32_t, int);
101 static int32_t Invert(int32_t);
102 static int32_t Sqrt(int32_t);
103 static int32_t CubeRoot(int32_t);
104 static int Cmp(int32_t, int32_t);
105 };
107 #endif