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: 4 -*- |
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 "gfxMatrix.h" |
michael@0 | 7 | #include "cairo.h" |
michael@0 | 8 | #include "mozilla/gfx/Tools.h" |
michael@0 | 9 | |
michael@0 | 10 | #define CAIRO_MATRIX(x) reinterpret_cast<cairo_matrix_t*>((x)) |
michael@0 | 11 | #define CONST_CAIRO_MATRIX(x) reinterpret_cast<const cairo_matrix_t*>((x)) |
michael@0 | 12 | |
michael@0 | 13 | const gfxMatrix& |
michael@0 | 14 | gfxMatrix::Reset() |
michael@0 | 15 | { |
michael@0 | 16 | cairo_matrix_init_identity(CAIRO_MATRIX(this)); |
michael@0 | 17 | return *this; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | const gfxMatrix& |
michael@0 | 21 | gfxMatrix::Invert() |
michael@0 | 22 | { |
michael@0 | 23 | cairo_matrix_invert(CAIRO_MATRIX(this)); |
michael@0 | 24 | return *this; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | const gfxMatrix& |
michael@0 | 28 | gfxMatrix::Scale(gfxFloat x, gfxFloat y) |
michael@0 | 29 | { |
michael@0 | 30 | cairo_matrix_scale(CAIRO_MATRIX(this), x, y); |
michael@0 | 31 | return *this; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | const gfxMatrix& |
michael@0 | 35 | gfxMatrix::Translate(const gfxPoint& pt) |
michael@0 | 36 | { |
michael@0 | 37 | cairo_matrix_translate(CAIRO_MATRIX(this), pt.x, pt.y); |
michael@0 | 38 | return *this; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | const gfxMatrix& |
michael@0 | 42 | gfxMatrix::Rotate(gfxFloat radians) |
michael@0 | 43 | { |
michael@0 | 44 | cairo_matrix_rotate(CAIRO_MATRIX(this), radians); |
michael@0 | 45 | return *this; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | const gfxMatrix& |
michael@0 | 49 | gfxMatrix::Multiply(const gfxMatrix& m) |
michael@0 | 50 | { |
michael@0 | 51 | cairo_matrix_multiply(CAIRO_MATRIX(this), CAIRO_MATRIX(this), CONST_CAIRO_MATRIX(&m)); |
michael@0 | 52 | return *this; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | const gfxMatrix& |
michael@0 | 56 | gfxMatrix::PreMultiply(const gfxMatrix& m) |
michael@0 | 57 | { |
michael@0 | 58 | cairo_matrix_multiply(CAIRO_MATRIX(this), CONST_CAIRO_MATRIX(&m), CAIRO_MATRIX(this)); |
michael@0 | 59 | return *this; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | gfxPoint |
michael@0 | 63 | gfxMatrix::Transform(const gfxPoint& point) const |
michael@0 | 64 | { |
michael@0 | 65 | gfxPoint ret = point; |
michael@0 | 66 | cairo_matrix_transform_point(CONST_CAIRO_MATRIX(this), &ret.x, &ret.y); |
michael@0 | 67 | return ret; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | gfxSize |
michael@0 | 71 | gfxMatrix::Transform(const gfxSize& size) const |
michael@0 | 72 | { |
michael@0 | 73 | gfxSize ret = size; |
michael@0 | 74 | cairo_matrix_transform_distance(CONST_CAIRO_MATRIX(this), &ret.width, &ret.height); |
michael@0 | 75 | return ret; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | gfxRect |
michael@0 | 79 | gfxMatrix::Transform(const gfxRect& rect) const |
michael@0 | 80 | { |
michael@0 | 81 | return gfxRect(Transform(rect.TopLeft()), Transform(rect.Size())); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | gfxRect |
michael@0 | 85 | gfxMatrix::TransformBounds(const gfxRect& rect) const |
michael@0 | 86 | { |
michael@0 | 87 | /* Code taken from cairo-matrix.c, _cairo_matrix_transform_bounding_box isn't public */ |
michael@0 | 88 | int i; |
michael@0 | 89 | double quad_x[4], quad_y[4]; |
michael@0 | 90 | double min_x, max_x; |
michael@0 | 91 | double min_y, max_y; |
michael@0 | 92 | |
michael@0 | 93 | quad_x[0] = rect.X(); |
michael@0 | 94 | quad_y[0] = rect.Y(); |
michael@0 | 95 | cairo_matrix_transform_point (CONST_CAIRO_MATRIX(this), &quad_x[0], &quad_y[0]); |
michael@0 | 96 | |
michael@0 | 97 | quad_x[1] = rect.XMost(); |
michael@0 | 98 | quad_y[1] = rect.Y(); |
michael@0 | 99 | cairo_matrix_transform_point (CONST_CAIRO_MATRIX(this), &quad_x[1], &quad_y[1]); |
michael@0 | 100 | |
michael@0 | 101 | quad_x[2] = rect.X(); |
michael@0 | 102 | quad_y[2] = rect.YMost(); |
michael@0 | 103 | cairo_matrix_transform_point (CONST_CAIRO_MATRIX(this), &quad_x[2], &quad_y[2]); |
michael@0 | 104 | |
michael@0 | 105 | quad_x[3] = rect.XMost(); |
michael@0 | 106 | quad_y[3] = rect.YMost(); |
michael@0 | 107 | cairo_matrix_transform_point (CONST_CAIRO_MATRIX(this), &quad_x[3], &quad_y[3]); |
michael@0 | 108 | |
michael@0 | 109 | min_x = max_x = quad_x[0]; |
michael@0 | 110 | min_y = max_y = quad_y[0]; |
michael@0 | 111 | |
michael@0 | 112 | for (i = 1; i < 4; i++) { |
michael@0 | 113 | if (quad_x[i] < min_x) |
michael@0 | 114 | min_x = quad_x[i]; |
michael@0 | 115 | if (quad_x[i] > max_x) |
michael@0 | 116 | max_x = quad_x[i]; |
michael@0 | 117 | |
michael@0 | 118 | if (quad_y[i] < min_y) |
michael@0 | 119 | min_y = quad_y[i]; |
michael@0 | 120 | if (quad_y[i] > max_y) |
michael@0 | 121 | max_y = quad_y[i]; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | return gfxRect(min_x, min_y, max_x - min_x, max_y - min_y); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | |
michael@0 | 128 | static void NudgeToInteger(double *aVal) |
michael@0 | 129 | { |
michael@0 | 130 | float f = float(*aVal); |
michael@0 | 131 | mozilla::gfx::NudgeToInteger(&f); |
michael@0 | 132 | *aVal = f; |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | void |
michael@0 | 136 | gfxMatrix::NudgeToIntegers(void) |
michael@0 | 137 | { |
michael@0 | 138 | NudgeToInteger(&xx); |
michael@0 | 139 | NudgeToInteger(&xy); |
michael@0 | 140 | NudgeToInteger(&yx); |
michael@0 | 141 | NudgeToInteger(&yy); |
michael@0 | 142 | NudgeToInteger(&x0); |
michael@0 | 143 | NudgeToInteger(&y0); |
michael@0 | 144 | } |