gfx/src/nsPoint.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: 2; 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 NSPOINT_H
     7 #define NSPOINT_H
     9 #include "nsCoord.h"
    10 #include "mozilla/gfx/BaseSize.h"
    11 #include "mozilla/gfx/BasePoint.h"
    12 #include "nsSize.h"
    14 struct nsIntPoint;
    16 // nsPoint represents a point in app units.
    18 struct nsPoint : public mozilla::gfx::BasePoint<nscoord, nsPoint> {
    19   typedef mozilla::gfx::BasePoint<nscoord, nsPoint> Super;
    21   nsPoint() : Super() {}
    22   nsPoint(const nsPoint& aPoint) : Super(aPoint) {}
    23   nsPoint(nscoord aX, nscoord aY) : Super(aX, aY) {}
    25   inline nsIntPoint ScaleToNearestPixels(float aXScale, float aYScale,
    26                                          nscoord aAppUnitsPerPixel) const;
    27   inline nsIntPoint ToNearestPixels(nscoord aAppUnitsPerPixel) const;
    29   // Converts this point from aFromAPP, an appunits per pixel ratio, to aToAPP.
    30   inline nsPoint ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const;
    31 };
    33 // nsIntPoint represents a point in one of the types of pixels.
    34 // Uses of nsIntPoint should eventually be converted to CSSIntPoint,
    35 // LayoutDeviceIntPoint, etc. (see layout/base/Units.h).
    37 struct nsIntPoint : public mozilla::gfx::BasePoint<int32_t, nsIntPoint> {
    38   typedef mozilla::gfx::BasePoint<int32_t, nsIntPoint> Super;
    40   nsIntPoint() : Super() {}
    41   nsIntPoint(const nsIntPoint& aPoint) : Super(aPoint) {}
    42   nsIntPoint(int32_t aX, int32_t aY) : Super(aX, aY) {}
    44   inline nsPoint ToAppUnits(nscoord aAppUnitsPerPixel) const;
    45 };
    47 inline nsIntPoint
    48 nsPoint::ScaleToNearestPixels(float aXScale, float aYScale,
    49                               nscoord aAppUnitsPerPixel) const
    50 {
    51   return nsIntPoint(
    52       NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel) * aXScale),
    53       NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel) * aYScale));
    54 }
    56 inline nsIntPoint
    57 nsPoint::ToNearestPixels(nscoord aAppUnitsPerPixel) const
    58 {
    59   return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel);
    60 }
    62 inline nsPoint
    63 nsPoint::ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const
    64 {
    65   if (aFromAPP != aToAPP) {
    66     nsPoint point;
    67     point.x = NSToCoordRound(NSCoordScale(x, aFromAPP, aToAPP));
    68     point.y = NSToCoordRound(NSCoordScale(y, aFromAPP, aToAPP));
    69     return point;
    70   }
    71   return *this;
    72 }
    74 // app units are integer multiples of pixels, so no rounding needed
    75 inline nsPoint
    76 nsIntPoint::ToAppUnits(nscoord aAppUnitsPerPixel) const
    77 {
    78   return nsPoint(NSIntPixelsToAppUnits(x, aAppUnitsPerPixel),
    79                  NSIntPixelsToAppUnits(y, aAppUnitsPerPixel));
    80 }
    82 #endif /* NSPOINT_H */

mercurial