gfx/skia/trunk/src/core/SkFloat.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 2008 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 #ifndef SkFloat_DEFINED
michael@0 11 #define SkFloat_DEFINED
michael@0 12
michael@0 13 #include "SkFixed.h"
michael@0 14
michael@0 15 class SkFloat {
michael@0 16 public:
michael@0 17 SkFloat() {}
michael@0 18
michael@0 19 void setZero() { fPacked = 0; }
michael@0 20 // void setShift(int value, int shift) { fPacked = SetShift(value, shift); }
michael@0 21 void setInt(int value) { fPacked = SetShift(value, 0); }
michael@0 22 void setFixed(SkFixed value) { fPacked = SetShift(value, -16); }
michael@0 23
michael@0 24 // int getShift(int shift) const { return GetShift(fPacked, shift); }
michael@0 25 int getInt() const { return GetShift(fPacked, 0); }
michael@0 26 SkFixed getFixed() const { return GetShift(fPacked, -16); }
michael@0 27
michael@0 28 void abs() { fPacked = Abs(fPacked); }
michael@0 29 void negate() { fPacked = Neg(fPacked); }
michael@0 30
michael@0 31 void shiftLeft(int bits) { fPacked = Shift(fPacked, bits); }
michael@0 32 void setShiftLeft(const SkFloat& a, int bits) { fPacked = Shift(a.fPacked, bits); }
michael@0 33
michael@0 34 void shiftRight(int bits) { fPacked = Shift(fPacked, -bits); }
michael@0 35 void setShiftRight(const SkFloat& a, int bits) { fPacked = Shift(a.fPacked, -bits); }
michael@0 36
michael@0 37 void add(const SkFloat& a) { fPacked = Add(fPacked, a.fPacked); }
michael@0 38 void setAdd(const SkFloat& a, const SkFloat& b) { fPacked = Add(a.fPacked, b.fPacked); }
michael@0 39
michael@0 40 void sub(const SkFloat& a) { fPacked = Add(fPacked, Neg(a.fPacked)); }
michael@0 41 void setSub(const SkFloat& a, const SkFloat& b) { fPacked = Add(a.fPacked, Neg(b.fPacked)); }
michael@0 42
michael@0 43 void mul(const SkFloat& a) { fPacked = Mul(fPacked, a.fPacked); }
michael@0 44 void setMul(const SkFloat& a, const SkFloat& b) { fPacked = Mul(a.fPacked, b.fPacked); }
michael@0 45
michael@0 46 void div(const SkFloat& a) { fPacked = Div(fPacked, a.fPacked); }
michael@0 47 void setDiv(const SkFloat& a, const SkFloat& b) { fPacked = Div(a.fPacked, b.fPacked); }
michael@0 48
michael@0 49 void sqrt() { fPacked = Sqrt(fPacked); }
michael@0 50 void setSqrt(const SkFloat& a) { fPacked = Sqrt(a.fPacked); }
michael@0 51 void cubeRoot() { fPacked = CubeRoot(fPacked); }
michael@0 52 void setCubeRoot(const SkFloat& a) { fPacked = CubeRoot(a.fPacked); }
michael@0 53
michael@0 54 friend bool operator==(const SkFloat& a, const SkFloat& b) { return a.fPacked == b.fPacked; }
michael@0 55 friend bool operator!=(const SkFloat& a, const SkFloat& b) { return a.fPacked != b.fPacked; }
michael@0 56 friend bool operator<(const SkFloat& a, const SkFloat& b) { return Cmp(a.fPacked, b.fPacked) < 0; }
michael@0 57 friend bool operator<=(const SkFloat& a, const SkFloat& b) { return Cmp(a.fPacked, b.fPacked) <= 0; }
michael@0 58 friend bool operator>(const SkFloat& a, const SkFloat& b) { return Cmp(a.fPacked, b.fPacked) > 0; }
michael@0 59 friend bool operator>=(const SkFloat& a, const SkFloat& b) { return Cmp(a.fPacked, b.fPacked) >= 0; }
michael@0 60
michael@0 61 #ifdef SK_DEBUG
michael@0 62 static void UnitTest();
michael@0 63
michael@0 64 void assertEquals(float f, int tolerance = 0)
michael@0 65 {
michael@0 66 union {
michael@0 67 float fFloat;
michael@0 68 int32_t fPacked;
michael@0 69 } tmp;
michael@0 70
michael@0 71 tmp.fFloat = f;
michael@0 72 int d = tmp.fPacked - fPacked;
michael@0 73 SkASSERT(SkAbs32(d) <= tolerance);
michael@0 74 }
michael@0 75 float getFloat() const
michael@0 76 {
michael@0 77 union {
michael@0 78 float fFloat;
michael@0 79 int32_t fPacked;
michael@0 80 } tmp;
michael@0 81
michael@0 82 tmp.fPacked = fPacked;
michael@0 83 return tmp.fFloat;
michael@0 84 }
michael@0 85 #endif
michael@0 86
michael@0 87 private:
michael@0 88 int32_t fPacked;
michael@0 89
michael@0 90 public:
michael@0 91 static int GetShift(int32_t packed, int shift);
michael@0 92 static int32_t SetShift(int value, int shift);
michael@0 93 static int32_t Neg(int32_t);
michael@0 94 static int32_t Abs(int32_t packed) { return (uint32_t)(packed << 1) >> 1; }
michael@0 95 static int32_t Shift(int32_t, int bits);
michael@0 96 static int32_t Add(int32_t, int32_t);
michael@0 97 static int32_t Mul(int32_t, int32_t);
michael@0 98 static int32_t MulInt(int32_t, int);
michael@0 99 static int32_t Div(int32_t, int32_t);
michael@0 100 static int32_t DivInt(int32_t, int);
michael@0 101 static int32_t Invert(int32_t);
michael@0 102 static int32_t Sqrt(int32_t);
michael@0 103 static int32_t CubeRoot(int32_t);
michael@0 104 static int Cmp(int32_t, int32_t);
michael@0 105 };
michael@0 106
michael@0 107 #endif

mercurial