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.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef MOZILLA_GFX_POINT_H_
     7 #define MOZILLA_GFX_POINT_H_
     9 #include "mozilla/Attributes.h"
    10 #include "Types.h"
    11 #include "BasePoint.h"
    12 #include "BasePoint3D.h"
    13 #include "BasePoint4D.h"
    14 #include "BaseSize.h"
    16 #include <cmath>
    18 namespace mozilla {
    19 namespace gfx {
    21 // This should only be used by the typedefs below.
    22 struct UnknownUnits {};
    24 template<class units>
    25 struct IntPointTyped :
    26   public BasePoint< int32_t, IntPointTyped<units> >,
    27   public units {
    28   typedef BasePoint< int32_t, IntPointTyped<units> > Super;
    30   MOZ_CONSTEXPR IntPointTyped() : Super() {}
    31   MOZ_CONSTEXPR IntPointTyped(int32_t aX, int32_t aY) : Super(aX, aY) {}
    33   // XXX When all of the code is ported, the following functions to convert to and from
    34   // unknown types should be removed.
    36   static IntPointTyped<units> FromUnknownPoint(const IntPointTyped<UnknownUnits>& aPoint) {
    37     return IntPointTyped<units>(aPoint.x, aPoint.y);
    38   }
    40   IntPointTyped<UnknownUnits> ToUnknownPoint() const {
    41     return IntPointTyped<UnknownUnits>(this->x, this->y);
    42   }
    43 };
    44 typedef IntPointTyped<UnknownUnits> IntPoint;
    46 template<class units>
    47 struct PointTyped :
    48   public BasePoint< Float, PointTyped<units> >,
    49   public units {
    50   typedef BasePoint< Float, PointTyped<units> > Super;
    52   MOZ_CONSTEXPR PointTyped() : Super() {}
    53   MOZ_CONSTEXPR PointTyped(Float aX, Float aY) : Super(aX, aY) {}
    54   MOZ_CONSTEXPR PointTyped(const IntPointTyped<units>& point) : Super(float(point.x), float(point.y)) {}
    56   // XXX When all of the code is ported, the following functions to convert to and from
    57   // unknown types should be removed.
    59   static PointTyped<units> FromUnknownPoint(const PointTyped<UnknownUnits>& aPoint) {
    60     return PointTyped<units>(aPoint.x, aPoint.y);
    61   }
    63   PointTyped<UnknownUnits> ToUnknownPoint() const {
    64     return PointTyped<UnknownUnits>(this->x, this->y);
    65   }
    66 };
    67 typedef PointTyped<UnknownUnits> Point;
    69 template<class units>
    70 IntPointTyped<units> RoundedToInt(const PointTyped<units>& aPoint) {
    71   return IntPointTyped<units>(int32_t(floorf(aPoint.x + 0.5f)),
    72                               int32_t(floorf(aPoint.y + 0.5f)));
    73 }
    75 template<class units>
    76 struct Point3DTyped :
    77   public BasePoint3D< Float, Point3DTyped<units> > {
    78   typedef BasePoint3D< Float, Point3DTyped<units> > Super;
    80   Point3DTyped() : Super() {}
    81   Point3DTyped(Float aX, Float aY, Float aZ) : Super(aX, aY, aZ) {}
    83   // XXX When all of the code is ported, the following functions to convert to and from
    84   // unknown types should be removed.
    86   static Point3DTyped<units> FromUnknownPoint(const Point3DTyped<UnknownUnits>& aPoint) {
    87     return Point3DTyped<units>(aPoint.x, aPoint.y, aPoint.z);
    88   }
    90   Point3DTyped<UnknownUnits> ToUnknownPoint() const {
    91     return Point3DTyped<UnknownUnits>(this->x, this->y, this->z);
    92   }
    93 };
    94 typedef Point3DTyped<UnknownUnits> Point3D;
    96 template<class units>
    97 struct Point4DTyped :
    98   public BasePoint4D< Float, Point4DTyped<units> > {
    99   typedef BasePoint4D< Float, Point4DTyped<units> > Super;
   101   Point4DTyped() : Super() {}
   102   Point4DTyped(Float aX, Float aY, Float aZ, Float aW) : Super(aX, aY, aZ, aW) {}
   104   // XXX When all of the code is ported, the following functions to convert to and from
   105   // unknown types should be removed.
   107   static Point4DTyped<units> FromUnknownPoint(const Point4DTyped<UnknownUnits>& aPoint) {
   108     return Point4DTyped<units>(aPoint.x, aPoint.y, aPoint.z, aPoint.w);
   109   }
   111   Point4DTyped<UnknownUnits> ToUnknownPoint() const {
   112     return Point4DTyped<UnknownUnits>(this->x, this->y, this->z, this->w);
   113   }
   114 };
   115 typedef Point4DTyped<UnknownUnits> Point4D;
   117 template<class units>
   118 struct IntSizeTyped :
   119   public BaseSize< int32_t, IntSizeTyped<units> >,
   120   public units {
   121   typedef BaseSize< int32_t, IntSizeTyped<units> > Super;
   123   MOZ_CONSTEXPR IntSizeTyped() : Super() {}
   124   MOZ_CONSTEXPR IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {}
   126   // XXX When all of the code is ported, the following functions to convert to and from
   127   // unknown types should be removed.
   129   static IntSizeTyped<units> FromUnknownSize(const IntSizeTyped<UnknownUnits>& aSize) {
   130     return IntSizeTyped<units>(aSize.width, aSize.height);
   131   }
   133   IntSizeTyped<UnknownUnits> ToUnknownSize() const {
   134     return IntSizeTyped<UnknownUnits>(this->width, this->height);
   135   }
   136 };
   137 typedef IntSizeTyped<UnknownUnits> IntSize;
   139 template<class units>
   140 struct SizeTyped :
   141   public BaseSize< Float, SizeTyped<units> >,
   142   public units {
   143   typedef BaseSize< Float, SizeTyped<units> > Super;
   145   MOZ_CONSTEXPR SizeTyped() : Super() {}
   146   MOZ_CONSTEXPR SizeTyped(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
   147   explicit SizeTyped(const IntSizeTyped<units>& size) :
   148     Super(float(size.width), float(size.height)) {}
   150   // XXX When all of the code is ported, the following functions to convert to and from
   151   // unknown types should be removed.
   153   static SizeTyped<units> FromUnknownSize(const SizeTyped<UnknownUnits>& aSize) {
   154     return SizeTyped<units>(aSize.width, aSize.height);
   155   }
   157   SizeTyped<UnknownUnits> ToUnknownSize() const {
   158     return SizeTyped<UnknownUnits>(this->width, this->height);
   159   }
   160 };
   161 typedef SizeTyped<UnknownUnits> Size;
   163 template<class units>
   164 IntSizeTyped<units> RoundedToInt(const SizeTyped<units>& aSize) {
   165   return IntSizeTyped<units>(int32_t(floorf(aSize.width + 0.5f)),
   166                              int32_t(floorf(aSize.height + 0.5f)));
   167 }
   169 }
   170 }
   172 #endif /* MOZILLA_GFX_POINT_H_ */

mercurial