Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_GFX_BASEPOINT_H_ |
michael@0 | 7 | #define MOZILLA_GFX_BASEPOINT_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include <cmath> |
michael@0 | 10 | #include "mozilla/Attributes.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | namespace gfx { |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * Do not use this class directly. Subclass it, pass that subclass as the |
michael@0 | 17 | * Sub parameter, and only use that subclass. This allows methods to safely |
michael@0 | 18 | * cast 'this' to 'Sub*'. |
michael@0 | 19 | */ |
michael@0 | 20 | template <class T, class Sub> |
michael@0 | 21 | struct BasePoint { |
michael@0 | 22 | T x, y; |
michael@0 | 23 | |
michael@0 | 24 | // Constructors |
michael@0 | 25 | MOZ_CONSTEXPR BasePoint() : x(0), y(0) {} |
michael@0 | 26 | MOZ_CONSTEXPR BasePoint(T aX, T aY) : x(aX), y(aY) {} |
michael@0 | 27 | |
michael@0 | 28 | void MoveTo(T aX, T aY) { x = aX; y = aY; } |
michael@0 | 29 | void MoveBy(T aDx, T aDy) { x += aDx; y += aDy; } |
michael@0 | 30 | |
michael@0 | 31 | // Note that '=' isn't defined so we'll get the |
michael@0 | 32 | // compiler generated default assignment operator |
michael@0 | 33 | |
michael@0 | 34 | bool operator==(const Sub& aPoint) const { |
michael@0 | 35 | return x == aPoint.x && y == aPoint.y; |
michael@0 | 36 | } |
michael@0 | 37 | bool operator!=(const Sub& aPoint) const { |
michael@0 | 38 | return x != aPoint.x || y != aPoint.y; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | Sub operator+(const Sub& aPoint) const { |
michael@0 | 42 | return Sub(x + aPoint.x, y + aPoint.y); |
michael@0 | 43 | } |
michael@0 | 44 | Sub operator-(const Sub& aPoint) const { |
michael@0 | 45 | return Sub(x - aPoint.x, y - aPoint.y); |
michael@0 | 46 | } |
michael@0 | 47 | Sub& operator+=(const Sub& aPoint) { |
michael@0 | 48 | x += aPoint.x; |
michael@0 | 49 | y += aPoint.y; |
michael@0 | 50 | return *static_cast<Sub*>(this); |
michael@0 | 51 | } |
michael@0 | 52 | Sub& operator-=(const Sub& aPoint) { |
michael@0 | 53 | x -= aPoint.x; |
michael@0 | 54 | y -= aPoint.y; |
michael@0 | 55 | return *static_cast<Sub*>(this); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | Sub operator*(T aScale) const { |
michael@0 | 59 | return Sub(x * aScale, y * aScale); |
michael@0 | 60 | } |
michael@0 | 61 | Sub operator/(T aScale) const { |
michael@0 | 62 | return Sub(x / aScale, y / aScale); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | Sub operator-() const { |
michael@0 | 66 | return Sub(-x, -y); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | // Round() is *not* rounding to nearest integer if the values are negative. |
michael@0 | 70 | // They are always rounding as floor(n + 0.5). |
michael@0 | 71 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14 |
michael@0 | 72 | Sub& Round() { |
michael@0 | 73 | x = static_cast<T>(floor(x + 0.5)); |
michael@0 | 74 | y = static_cast<T>(floor(y + 0.5)); |
michael@0 | 75 | return *static_cast<Sub*>(this); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | } |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | #endif /* MOZILLA_GFX_BASEPOINT_H_ */ |