gfx/2d/Point.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_POINT_H_
michael@0 7 #define MOZILLA_GFX_POINT_H_
michael@0 8
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10 #include "Types.h"
michael@0 11 #include "BasePoint.h"
michael@0 12 #include "BasePoint3D.h"
michael@0 13 #include "BasePoint4D.h"
michael@0 14 #include "BaseSize.h"
michael@0 15
michael@0 16 #include <cmath>
michael@0 17
michael@0 18 namespace mozilla {
michael@0 19 namespace gfx {
michael@0 20
michael@0 21 // This should only be used by the typedefs below.
michael@0 22 struct UnknownUnits {};
michael@0 23
michael@0 24 template<class units>
michael@0 25 struct IntPointTyped :
michael@0 26 public BasePoint< int32_t, IntPointTyped<units> >,
michael@0 27 public units {
michael@0 28 typedef BasePoint< int32_t, IntPointTyped<units> > Super;
michael@0 29
michael@0 30 MOZ_CONSTEXPR IntPointTyped() : Super() {}
michael@0 31 MOZ_CONSTEXPR IntPointTyped(int32_t aX, int32_t aY) : Super(aX, aY) {}
michael@0 32
michael@0 33 // XXX When all of the code is ported, the following functions to convert to and from
michael@0 34 // unknown types should be removed.
michael@0 35
michael@0 36 static IntPointTyped<units> FromUnknownPoint(const IntPointTyped<UnknownUnits>& aPoint) {
michael@0 37 return IntPointTyped<units>(aPoint.x, aPoint.y);
michael@0 38 }
michael@0 39
michael@0 40 IntPointTyped<UnknownUnits> ToUnknownPoint() const {
michael@0 41 return IntPointTyped<UnknownUnits>(this->x, this->y);
michael@0 42 }
michael@0 43 };
michael@0 44 typedef IntPointTyped<UnknownUnits> IntPoint;
michael@0 45
michael@0 46 template<class units>
michael@0 47 struct PointTyped :
michael@0 48 public BasePoint< Float, PointTyped<units> >,
michael@0 49 public units {
michael@0 50 typedef BasePoint< Float, PointTyped<units> > Super;
michael@0 51
michael@0 52 MOZ_CONSTEXPR PointTyped() : Super() {}
michael@0 53 MOZ_CONSTEXPR PointTyped(Float aX, Float aY) : Super(aX, aY) {}
michael@0 54 MOZ_CONSTEXPR PointTyped(const IntPointTyped<units>& point) : Super(float(point.x), float(point.y)) {}
michael@0 55
michael@0 56 // XXX When all of the code is ported, the following functions to convert to and from
michael@0 57 // unknown types should be removed.
michael@0 58
michael@0 59 static PointTyped<units> FromUnknownPoint(const PointTyped<UnknownUnits>& aPoint) {
michael@0 60 return PointTyped<units>(aPoint.x, aPoint.y);
michael@0 61 }
michael@0 62
michael@0 63 PointTyped<UnknownUnits> ToUnknownPoint() const {
michael@0 64 return PointTyped<UnknownUnits>(this->x, this->y);
michael@0 65 }
michael@0 66 };
michael@0 67 typedef PointTyped<UnknownUnits> Point;
michael@0 68
michael@0 69 template<class units>
michael@0 70 IntPointTyped<units> RoundedToInt(const PointTyped<units>& aPoint) {
michael@0 71 return IntPointTyped<units>(int32_t(floorf(aPoint.x + 0.5f)),
michael@0 72 int32_t(floorf(aPoint.y + 0.5f)));
michael@0 73 }
michael@0 74
michael@0 75 template<class units>
michael@0 76 struct Point3DTyped :
michael@0 77 public BasePoint3D< Float, Point3DTyped<units> > {
michael@0 78 typedef BasePoint3D< Float, Point3DTyped<units> > Super;
michael@0 79
michael@0 80 Point3DTyped() : Super() {}
michael@0 81 Point3DTyped(Float aX, Float aY, Float aZ) : Super(aX, aY, aZ) {}
michael@0 82
michael@0 83 // XXX When all of the code is ported, the following functions to convert to and from
michael@0 84 // unknown types should be removed.
michael@0 85
michael@0 86 static Point3DTyped<units> FromUnknownPoint(const Point3DTyped<UnknownUnits>& aPoint) {
michael@0 87 return Point3DTyped<units>(aPoint.x, aPoint.y, aPoint.z);
michael@0 88 }
michael@0 89
michael@0 90 Point3DTyped<UnknownUnits> ToUnknownPoint() const {
michael@0 91 return Point3DTyped<UnknownUnits>(this->x, this->y, this->z);
michael@0 92 }
michael@0 93 };
michael@0 94 typedef Point3DTyped<UnknownUnits> Point3D;
michael@0 95
michael@0 96 template<class units>
michael@0 97 struct Point4DTyped :
michael@0 98 public BasePoint4D< Float, Point4DTyped<units> > {
michael@0 99 typedef BasePoint4D< Float, Point4DTyped<units> > Super;
michael@0 100
michael@0 101 Point4DTyped() : Super() {}
michael@0 102 Point4DTyped(Float aX, Float aY, Float aZ, Float aW) : Super(aX, aY, aZ, aW) {}
michael@0 103
michael@0 104 // XXX When all of the code is ported, the following functions to convert to and from
michael@0 105 // unknown types should be removed.
michael@0 106
michael@0 107 static Point4DTyped<units> FromUnknownPoint(const Point4DTyped<UnknownUnits>& aPoint) {
michael@0 108 return Point4DTyped<units>(aPoint.x, aPoint.y, aPoint.z, aPoint.w);
michael@0 109 }
michael@0 110
michael@0 111 Point4DTyped<UnknownUnits> ToUnknownPoint() const {
michael@0 112 return Point4DTyped<UnknownUnits>(this->x, this->y, this->z, this->w);
michael@0 113 }
michael@0 114 };
michael@0 115 typedef Point4DTyped<UnknownUnits> Point4D;
michael@0 116
michael@0 117 template<class units>
michael@0 118 struct IntSizeTyped :
michael@0 119 public BaseSize< int32_t, IntSizeTyped<units> >,
michael@0 120 public units {
michael@0 121 typedef BaseSize< int32_t, IntSizeTyped<units> > Super;
michael@0 122
michael@0 123 MOZ_CONSTEXPR IntSizeTyped() : Super() {}
michael@0 124 MOZ_CONSTEXPR IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {}
michael@0 125
michael@0 126 // XXX When all of the code is ported, the following functions to convert to and from
michael@0 127 // unknown types should be removed.
michael@0 128
michael@0 129 static IntSizeTyped<units> FromUnknownSize(const IntSizeTyped<UnknownUnits>& aSize) {
michael@0 130 return IntSizeTyped<units>(aSize.width, aSize.height);
michael@0 131 }
michael@0 132
michael@0 133 IntSizeTyped<UnknownUnits> ToUnknownSize() const {
michael@0 134 return IntSizeTyped<UnknownUnits>(this->width, this->height);
michael@0 135 }
michael@0 136 };
michael@0 137 typedef IntSizeTyped<UnknownUnits> IntSize;
michael@0 138
michael@0 139 template<class units>
michael@0 140 struct SizeTyped :
michael@0 141 public BaseSize< Float, SizeTyped<units> >,
michael@0 142 public units {
michael@0 143 typedef BaseSize< Float, SizeTyped<units> > Super;
michael@0 144
michael@0 145 MOZ_CONSTEXPR SizeTyped() : Super() {}
michael@0 146 MOZ_CONSTEXPR SizeTyped(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
michael@0 147 explicit SizeTyped(const IntSizeTyped<units>& size) :
michael@0 148 Super(float(size.width), float(size.height)) {}
michael@0 149
michael@0 150 // XXX When all of the code is ported, the following functions to convert to and from
michael@0 151 // unknown types should be removed.
michael@0 152
michael@0 153 static SizeTyped<units> FromUnknownSize(const SizeTyped<UnknownUnits>& aSize) {
michael@0 154 return SizeTyped<units>(aSize.width, aSize.height);
michael@0 155 }
michael@0 156
michael@0 157 SizeTyped<UnknownUnits> ToUnknownSize() const {
michael@0 158 return SizeTyped<UnknownUnits>(this->width, this->height);
michael@0 159 }
michael@0 160 };
michael@0 161 typedef SizeTyped<UnknownUnits> Size;
michael@0 162
michael@0 163 template<class units>
michael@0 164 IntSizeTyped<units> RoundedToInt(const SizeTyped<units>& aSize) {
michael@0 165 return IntSizeTyped<units>(int32_t(floorf(aSize.width + 0.5f)),
michael@0 166 int32_t(floorf(aSize.height + 0.5f)));
michael@0 167 }
michael@0 168
michael@0 169 }
michael@0 170 }
michael@0 171
michael@0 172 #endif /* MOZILLA_GFX_POINT_H_ */

mercurial