gfx/thebes/gfxRect.cpp

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: 4 -*-
     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 #include "gfxRect.h"
     8 #include "nsMathUtils.h"
    10 static bool
    11 WithinEpsilonOfInteger(gfxFloat aX, gfxFloat aEpsilon)
    12 {
    13     return fabs(NS_round(aX) - aX) <= fabs(aEpsilon);
    14 }
    16 bool
    17 gfxRect::WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const
    18 {
    19     NS_ASSERTION(-0.5 < aEpsilon && aEpsilon < 0.5, "Nonsense epsilon value");
    20     return (WithinEpsilonOfInteger(x, aEpsilon) &&
    21             WithinEpsilonOfInteger(y, aEpsilon) &&
    22             WithinEpsilonOfInteger(width, aEpsilon) &&
    23             WithinEpsilonOfInteger(height, aEpsilon));
    24 }
    26 /* Clamp r to CAIRO_COORD_MIN .. CAIRO_COORD_MAX
    27  * these are to be device coordinates.
    28  *
    29  * Cairo is currently using 24.8 fixed point,
    30  * so -2^24 .. 2^24-1 is our valid
    31  */
    33 #define CAIRO_COORD_MAX (16777215.0)
    34 #define CAIRO_COORD_MIN (-16777216.0)
    36 void
    37 gfxRect::Condition()
    38 {
    39     // if either x or y is way out of bounds;
    40     // note that we don't handle negative w/h here
    41     if (x > CAIRO_COORD_MAX) {
    42         x = CAIRO_COORD_MAX;
    43         width = 0.0;
    44     } 
    46     if (y > CAIRO_COORD_MAX) {
    47         y = CAIRO_COORD_MAX;
    48         height = 0.0;
    49     }
    51     if (x < CAIRO_COORD_MIN) {
    52         width += x - CAIRO_COORD_MIN;
    53         if (width < 0.0)
    54             width = 0.0;
    55         x = CAIRO_COORD_MIN;
    56     }
    58     if (y < CAIRO_COORD_MIN) {
    59         height += y - CAIRO_COORD_MIN;
    60         if (height < 0.0)
    61             height = 0.0;
    62         y = CAIRO_COORD_MIN;
    63     }
    65     if (x + width > CAIRO_COORD_MAX) {
    66         width = CAIRO_COORD_MAX - x;
    67     }
    69     if (y + height > CAIRO_COORD_MAX) {
    70         height = CAIRO_COORD_MAX - y;
    71     }
    72 }

mercurial