Tue, 06 Jan 2015 21:39:09 +0100
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 | #include "Matrix.h" |
michael@0 | 7 | #include "Tools.h" |
michael@0 | 8 | #include <math.h> |
michael@0 | 9 | |
michael@0 | 10 | namespace mozilla { |
michael@0 | 11 | namespace gfx { |
michael@0 | 12 | |
michael@0 | 13 | Matrix |
michael@0 | 14 | Matrix::Rotation(Float aAngle) |
michael@0 | 15 | { |
michael@0 | 16 | Matrix newMatrix; |
michael@0 | 17 | |
michael@0 | 18 | Float s = sin(aAngle); |
michael@0 | 19 | Float c = cos(aAngle); |
michael@0 | 20 | |
michael@0 | 21 | newMatrix._11 = c; |
michael@0 | 22 | newMatrix._12 = s; |
michael@0 | 23 | newMatrix._21 = -s; |
michael@0 | 24 | newMatrix._22 = c; |
michael@0 | 25 | |
michael@0 | 26 | return newMatrix; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | Rect |
michael@0 | 30 | Matrix::TransformBounds(const Rect &aRect) const |
michael@0 | 31 | { |
michael@0 | 32 | int i; |
michael@0 | 33 | Point quad[4]; |
michael@0 | 34 | Float min_x, max_x; |
michael@0 | 35 | Float min_y, max_y; |
michael@0 | 36 | |
michael@0 | 37 | quad[0] = *this * aRect.TopLeft(); |
michael@0 | 38 | quad[1] = *this * aRect.TopRight(); |
michael@0 | 39 | quad[2] = *this * aRect.BottomLeft(); |
michael@0 | 40 | quad[3] = *this * aRect.BottomRight(); |
michael@0 | 41 | |
michael@0 | 42 | min_x = max_x = quad[0].x; |
michael@0 | 43 | min_y = max_y = quad[0].y; |
michael@0 | 44 | |
michael@0 | 45 | for (i = 1; i < 4; i++) { |
michael@0 | 46 | if (quad[i].x < min_x) |
michael@0 | 47 | min_x = quad[i].x; |
michael@0 | 48 | if (quad[i].x > max_x) |
michael@0 | 49 | max_x = quad[i].x; |
michael@0 | 50 | |
michael@0 | 51 | if (quad[i].y < min_y) |
michael@0 | 52 | min_y = quad[i].y; |
michael@0 | 53 | if (quad[i].y > max_y) |
michael@0 | 54 | max_y = quad[i].y; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | return Rect(min_x, min_y, max_x - min_x, max_y - min_y); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | void |
michael@0 | 61 | Matrix::NudgeToIntegers() |
michael@0 | 62 | { |
michael@0 | 63 | NudgeToInteger(&_11); |
michael@0 | 64 | NudgeToInteger(&_12); |
michael@0 | 65 | NudgeToInteger(&_21); |
michael@0 | 66 | NudgeToInteger(&_22); |
michael@0 | 67 | NudgeToInteger(&_31); |
michael@0 | 68 | NudgeToInteger(&_32); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | Rect |
michael@0 | 72 | Matrix4x4::TransformBounds(const Rect& aRect) const |
michael@0 | 73 | { |
michael@0 | 74 | Point quad[4]; |
michael@0 | 75 | Float min_x, max_x; |
michael@0 | 76 | Float min_y, max_y; |
michael@0 | 77 | |
michael@0 | 78 | quad[0] = *this * aRect.TopLeft(); |
michael@0 | 79 | quad[1] = *this * aRect.TopRight(); |
michael@0 | 80 | quad[2] = *this * aRect.BottomLeft(); |
michael@0 | 81 | quad[3] = *this * aRect.BottomRight(); |
michael@0 | 82 | |
michael@0 | 83 | min_x = max_x = quad[0].x; |
michael@0 | 84 | min_y = max_y = quad[0].y; |
michael@0 | 85 | |
michael@0 | 86 | for (int i = 1; i < 4; i++) { |
michael@0 | 87 | if (quad[i].x < min_x) { |
michael@0 | 88 | min_x = quad[i].x; |
michael@0 | 89 | } |
michael@0 | 90 | if (quad[i].x > max_x) { |
michael@0 | 91 | max_x = quad[i].x; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | if (quad[i].y < min_y) { |
michael@0 | 95 | min_y = quad[i].y; |
michael@0 | 96 | } |
michael@0 | 97 | if (quad[i].y > max_y) { |
michael@0 | 98 | max_y = quad[i].y; |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | return Rect(min_x, min_y, max_x - min_x, max_y - min_y); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | } |
michael@0 | 106 | } |