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 2006 The Android Open Source Project |
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 | #ifndef SkFixed_DEFINED |
michael@0 | 9 | #define SkFixed_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkTypes.h" |
michael@0 | 12 | |
michael@0 | 13 | /** \file SkFixed.h |
michael@0 | 14 | |
michael@0 | 15 | Types and macros for 16.16 fixed point |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | /** 32 bit signed integer used to represent fractions values with 16 bits to the right of the decimal point |
michael@0 | 19 | */ |
michael@0 | 20 | typedef int32_t SkFixed; |
michael@0 | 21 | #define SK_Fixed1 (1 << 16) |
michael@0 | 22 | #define SK_FixedHalf (1 << 15) |
michael@0 | 23 | #define SK_FixedMax (0x7FFFFFFF) |
michael@0 | 24 | #define SK_FixedMin (-SK_FixedMax) |
michael@0 | 25 | #define SK_FixedNaN ((int) 0x80000000) |
michael@0 | 26 | #define SK_FixedPI (0x3243F) |
michael@0 | 27 | #define SK_FixedSqrt2 (92682) |
michael@0 | 28 | #define SK_FixedTanPIOver8 (0x6A0A) |
michael@0 | 29 | #define SK_FixedRoot2Over2 (0xB505) |
michael@0 | 30 | |
michael@0 | 31 | #define SkFixedToFloat(x) ((x) * 1.5258789e-5f) |
michael@0 | 32 | #if 1 |
michael@0 | 33 | #define SkFloatToFixed(x) ((SkFixed)((x) * SK_Fixed1)) |
michael@0 | 34 | #else |
michael@0 | 35 | // pins over/under flows to max/min int32 (slower than just a cast) |
michael@0 | 36 | static inline SkFixed SkFloatToFixed(float x) { |
michael@0 | 37 | int64_t n = x * SK_Fixed1; |
michael@0 | 38 | return (SkFixed)n; |
michael@0 | 39 | } |
michael@0 | 40 | #endif |
michael@0 | 41 | |
michael@0 | 42 | #ifdef SK_DEBUG |
michael@0 | 43 | static inline SkFixed SkFloatToFixed_Check(float x) { |
michael@0 | 44 | int64_t n64 = (int64_t)(x * SK_Fixed1); |
michael@0 | 45 | SkFixed n32 = (SkFixed)n64; |
michael@0 | 46 | SkASSERT(n64 == n32); |
michael@0 | 47 | return n32; |
michael@0 | 48 | } |
michael@0 | 49 | #else |
michael@0 | 50 | #define SkFloatToFixed_Check(x) SkFloatToFixed(x) |
michael@0 | 51 | #endif |
michael@0 | 52 | |
michael@0 | 53 | #define SkFixedToDouble(x) ((x) * 1.5258789e-5) |
michael@0 | 54 | #define SkDoubleToFixed(x) ((SkFixed)((x) * SK_Fixed1)) |
michael@0 | 55 | |
michael@0 | 56 | /** Converts an integer to a SkFixed, asserting that the result does not overflow |
michael@0 | 57 | a 32 bit signed integer |
michael@0 | 58 | */ |
michael@0 | 59 | #ifdef SK_DEBUG |
michael@0 | 60 | inline SkFixed SkIntToFixed(int n) |
michael@0 | 61 | { |
michael@0 | 62 | SkASSERT(n >= -32768 && n <= 32767); |
michael@0 | 63 | return n << 16; |
michael@0 | 64 | } |
michael@0 | 65 | #else |
michael@0 | 66 | // force the cast to SkFixed to ensure that the answer is signed (like the debug version) |
michael@0 | 67 | #define SkIntToFixed(n) (SkFixed)((n) << 16) |
michael@0 | 68 | #endif |
michael@0 | 69 | |
michael@0 | 70 | #define SkFixedRoundToInt(x) (((x) + SK_FixedHalf) >> 16) |
michael@0 | 71 | #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16) |
michael@0 | 72 | #define SkFixedFloorToInt(x) ((x) >> 16) |
michael@0 | 73 | |
michael@0 | 74 | #define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000) |
michael@0 | 75 | #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000) |
michael@0 | 76 | #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000) |
michael@0 | 77 | |
michael@0 | 78 | #define SkFixedAbs(x) SkAbs32(x) |
michael@0 | 79 | #define SkFixedAve(a, b) (((a) + (b)) >> 1) |
michael@0 | 80 | |
michael@0 | 81 | SkFixed SkFixedMul_portable(SkFixed, SkFixed); |
michael@0 | 82 | |
michael@0 | 83 | #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) |
michael@0 | 84 | |
michael@0 | 85 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 86 | // TODO: move fixed sin/cos into SkCosineMapper, as that is the only caller |
michael@0 | 87 | // or rewrite SkCosineMapper to not use it at all |
michael@0 | 88 | |
michael@0 | 89 | SkFixed SkFixedSinCos(SkFixed radians, SkFixed* cosValueOrNull); |
michael@0 | 90 | #define SkFixedSin(radians) SkFixedSinCos(radians, NULL) |
michael@0 | 91 | static inline SkFixed SkFixedCos(SkFixed radians) { |
michael@0 | 92 | SkFixed cosValue; |
michael@0 | 93 | (void)SkFixedSinCos(radians, &cosValue); |
michael@0 | 94 | return cosValue; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | ////////////////////////////////////////////////////////////////////////////////////////////////////// |
michael@0 | 98 | // Now look for ASM overrides for our portable versions (should consider putting this in its own file) |
michael@0 | 99 | |
michael@0 | 100 | #ifdef SkLONGLONG |
michael@0 | 101 | inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) |
michael@0 | 102 | { |
michael@0 | 103 | return (SkFixed)((int64_t)a * b >> 16); |
michael@0 | 104 | } |
michael@0 | 105 | #define SkFixedMul(a,b) SkFixedMul_longlong(a,b) |
michael@0 | 106 | #endif |
michael@0 | 107 | |
michael@0 | 108 | #if defined(SK_CPU_ARM) |
michael@0 | 109 | /* This guy does not handle NaN or other obscurities, but is faster than |
michael@0 | 110 | than (int)(x*65536) |
michael@0 | 111 | */ |
michael@0 | 112 | inline SkFixed SkFloatToFixed_arm(float x) |
michael@0 | 113 | { |
michael@0 | 114 | int32_t y, z; |
michael@0 | 115 | asm("movs %1, %3, lsl #1 \n" |
michael@0 | 116 | "mov %2, #0x8E \n" |
michael@0 | 117 | "sub %1, %2, %1, lsr #24 \n" |
michael@0 | 118 | "mov %2, %3, lsl #8 \n" |
michael@0 | 119 | "orr %2, %2, #0x80000000 \n" |
michael@0 | 120 | "mov %1, %2, lsr %1 \n" |
michael@0 | 121 | "it cs \n" |
michael@0 | 122 | "rsbcs %1, %1, #0 \n" |
michael@0 | 123 | : "=r"(x), "=&r"(y), "=&r"(z) |
michael@0 | 124 | : "r"(x) |
michael@0 | 125 | : "cc" |
michael@0 | 126 | ); |
michael@0 | 127 | return y; |
michael@0 | 128 | } |
michael@0 | 129 | inline SkFixed SkFixedMul_arm(SkFixed x, SkFixed y) |
michael@0 | 130 | { |
michael@0 | 131 | int32_t t; |
michael@0 | 132 | asm("smull %0, %2, %1, %3 \n" |
michael@0 | 133 | "mov %0, %0, lsr #16 \n" |
michael@0 | 134 | "orr %0, %0, %2, lsl #16 \n" |
michael@0 | 135 | : "=r"(x), "=&r"(y), "=r"(t) |
michael@0 | 136 | : "r"(x), "1"(y) |
michael@0 | 137 | : |
michael@0 | 138 | ); |
michael@0 | 139 | return x; |
michael@0 | 140 | } |
michael@0 | 141 | #undef SkFixedMul |
michael@0 | 142 | #define SkFixedMul(x, y) SkFixedMul_arm(x, y) |
michael@0 | 143 | |
michael@0 | 144 | #undef SkFloatToFixed |
michael@0 | 145 | #define SkFloatToFixed(x) SkFloatToFixed_arm(x) |
michael@0 | 146 | #endif |
michael@0 | 147 | |
michael@0 | 148 | #ifndef SkFixedMul |
michael@0 | 149 | #define SkFixedMul(x, y) SkFixedMul_portable(x, y) |
michael@0 | 150 | #endif |
michael@0 | 151 | |
michael@0 | 152 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 153 | |
michael@0 | 154 | typedef int64_t SkFixed48; |
michael@0 | 155 | |
michael@0 | 156 | #define SkIntToFixed48(x) ((SkFixed48)(x) << 48) |
michael@0 | 157 | #define SkFixed48ToInt(x) ((int)((x) >> 48)) |
michael@0 | 158 | #define SkFixedToFixed48(x) ((SkFixed48)(x) << 32) |
michael@0 | 159 | #define SkFixed48ToFixed(x) ((SkFixed)((x) >> 32)) |
michael@0 | 160 | #define SkFloatToFixed48(x) ((SkFixed48)((x) * (65536.0f * 65536.0f * 65536.0f))) |
michael@0 | 161 | |
michael@0 | 162 | #define SkScalarToFixed48(x) SkFloatToFixed48(x) |
michael@0 | 163 | |
michael@0 | 164 | #endif |