gfx/src/nsTransform2D.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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; 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 #ifndef nsTransform2D_h___
michael@0 7 #define nsTransform2D_h___
michael@0 8
michael@0 9 #include "gfxCore.h"
michael@0 10 #include "nsCoord.h"
michael@0 11
michael@0 12 class NS_GFX nsTransform2D
michael@0 13 {
michael@0 14 private:
michael@0 15 /**
michael@0 16 * This represents the following matrix (note that the order of row/column
michael@0 17 * indices is opposite to usual notation)
michael@0 18 *
michael@0 19 * / m00 0 m20 \
michael@0 20 * M = | 0 m11 m21 |
michael@0 21 * \ 0 0 1 /
michael@0 22 *
michael@0 23 * Transformation of a coordinate (x, y) is obtained by setting
michael@0 24 * v = (x, y, 1)^T and evaluating M . v
michael@0 25 **/
michael@0 26
michael@0 27 float m00, m11, m20, m21;
michael@0 28
michael@0 29 public:
michael@0 30 nsTransform2D(void) { m20 = m21 = 0.0f; m00 = m11 = 1.0f; }
michael@0 31 nsTransform2D(nsTransform2D *aTransform2D) {
michael@0 32 m00 = aTransform2D->m00;
michael@0 33 m11 = aTransform2D->m11;
michael@0 34 m20 = aTransform2D->m20;
michael@0 35 m21 = aTransform2D->m21;
michael@0 36 }
michael@0 37
michael@0 38 ~nsTransform2D(void) { }
michael@0 39
michael@0 40 /**
michael@0 41 * set this transform to a translation
michael@0 42 *
michael@0 43 * @param tx, x translation
michael@0 44 * @param ty, y translation
michael@0 45 **/
michael@0 46
michael@0 47 void SetToTranslate(float tx, float ty) { m00 = m11 = 1.0f; m20 = tx; m21 = ty; }
michael@0 48
michael@0 49 /**
michael@0 50 * get the translation portion of this transform
michael@0 51 *
michael@0 52 * @param pt, Point to return translation values in
michael@0 53 **/
michael@0 54
michael@0 55 void GetTranslationCoord(nscoord *ptX, nscoord *ptY) const { *ptX = NSToCoordRound(m20); *ptY = NSToCoordRound(m21); }
michael@0 56
michael@0 57 /**
michael@0 58 * apply matrix to vector
michael@0 59 *
michael@0 60 * @param pt Point to transform
michael@0 61 **/
michael@0 62
michael@0 63 void TransformCoord(nscoord *ptX, nscoord *ptY) const;
michael@0 64
michael@0 65 /**
michael@0 66 * apply matrix to rect
michael@0 67 *
michael@0 68 * @param rect Rect to transform
michael@0 69 **/
michael@0 70
michael@0 71 void TransformCoord(nscoord *aX, nscoord *aY, nscoord *aWidth, nscoord *aHeight) const;
michael@0 72
michael@0 73 /**
michael@0 74 * add a scale to a Transform via x, y pair
michael@0 75 *
michael@0 76 * @param ptX x value to add as x scale
michael@0 77 * @param ptY y value to add as y scale
michael@0 78 **/
michael@0 79
michael@0 80 void AddScale(float ptX, float ptY) { m00 *= ptX; m11 *= ptY; }
michael@0 81
michael@0 82 /**
michael@0 83 * Set the scale (overriding any previous calls to AddScale, but leaving
michael@0 84 * any existing translation).
michael@0 85 *
michael@0 86 * @param ptX x value to add as x scale
michael@0 87 * @param ptY y value to add as y scale
michael@0 88 **/
michael@0 89
michael@0 90 void SetScale(float ptX, float ptY) { m00 = ptX; m11 = ptY; }
michael@0 91 };
michael@0 92
michael@0 93 #endif

mercurial