gfx/2d/ScaleFactor.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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: 20; 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_SCALEFACTOR_H_
michael@0 7 #define MOZILLA_GFX_SCALEFACTOR_H_
michael@0 8
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10
michael@0 11 #include "gfxPoint.h"
michael@0 12
michael@0 13 namespace mozilla {
michael@0 14 namespace gfx {
michael@0 15
michael@0 16 /*
michael@0 17 * This class represents a scaling factor between two different pixel unit
michael@0 18 * systems. This is effectively a type-safe float, intended to be used in
michael@0 19 * combination with the known-type instances of gfx::Point, gfx::Rect, etc.
michael@0 20 *
michael@0 21 * Note that some parts of the code that pre-date this class used separate
michael@0 22 * scaling factors for the x and y axes. However, at runtime these values
michael@0 23 * were always expected to be the same, so this class uses only one scale
michael@0 24 * factor for both axes. The two constructors that take two-axis scaling
michael@0 25 * factors check to ensure that this assertion holds.
michael@0 26 */
michael@0 27 template<class src, class dst>
michael@0 28 struct ScaleFactor {
michael@0 29 float scale;
michael@0 30
michael@0 31 MOZ_CONSTEXPR ScaleFactor() : scale(1.0) {}
michael@0 32 MOZ_CONSTEXPR ScaleFactor(const ScaleFactor<src, dst>& aCopy) : scale(aCopy.scale) {}
michael@0 33 explicit MOZ_CONSTEXPR ScaleFactor(float aScale) : scale(aScale) {}
michael@0 34
michael@0 35 explicit ScaleFactor(float aX, float aY) : scale(aX) {
michael@0 36 MOZ_ASSERT(fabs(aX - aY) < 1e-6);
michael@0 37 }
michael@0 38
michael@0 39 ScaleFactor<dst, src> Inverse() {
michael@0 40 return ScaleFactor<dst, src>(1 / scale);
michael@0 41 }
michael@0 42
michael@0 43 bool operator==(const ScaleFactor<src, dst>& aOther) const {
michael@0 44 return scale == aOther.scale;
michael@0 45 }
michael@0 46
michael@0 47 bool operator!=(const ScaleFactor<src, dst>& aOther) const {
michael@0 48 return !(*this == aOther);
michael@0 49 }
michael@0 50
michael@0 51 bool operator<(const ScaleFactor<src, dst>& aOther) const {
michael@0 52 return scale < aOther.scale;
michael@0 53 }
michael@0 54
michael@0 55 bool operator<=(const ScaleFactor<src, dst>& aOther) const {
michael@0 56 return scale <= aOther.scale;
michael@0 57 }
michael@0 58
michael@0 59 bool operator>(const ScaleFactor<src, dst>& aOther) const {
michael@0 60 return scale > aOther.scale;
michael@0 61 }
michael@0 62
michael@0 63 bool operator>=(const ScaleFactor<src, dst>& aOther) const {
michael@0 64 return scale >= aOther.scale;
michael@0 65 }
michael@0 66
michael@0 67 template<class other>
michael@0 68 ScaleFactor<other, dst> operator/(const ScaleFactor<src, other>& aOther) const {
michael@0 69 return ScaleFactor<other, dst>(scale / aOther.scale);
michael@0 70 }
michael@0 71
michael@0 72 template<class other>
michael@0 73 ScaleFactor<src, other> operator/(const ScaleFactor<other, dst>& aOther) const {
michael@0 74 return ScaleFactor<src, other>(scale / aOther.scale);
michael@0 75 }
michael@0 76
michael@0 77 template<class other>
michael@0 78 ScaleFactor<src, other> operator*(const ScaleFactor<dst, other>& aOther) const {
michael@0 79 return ScaleFactor<src, other>(scale * aOther.scale);
michael@0 80 }
michael@0 81
michael@0 82 template<class other>
michael@0 83 ScaleFactor<other, dst> operator*(const ScaleFactor<other, src>& aOther) const {
michael@0 84 return ScaleFactor<other, dst>(scale * aOther.scale);
michael@0 85 }
michael@0 86 };
michael@0 87
michael@0 88 }
michael@0 89 }
michael@0 90
michael@0 91 #endif /* MOZILLA_GFX_SCALEFACTOR_H_ */

mercurial