Bug 1732219 - Add API for fetching the preview image. r=geckoview-reviewers,agi,mconley
[gecko.git] / gfx / src / nsTransform2D.h
blobfb04f16a12e417b8b472fbe55bf6635363754027
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsTransform2D_h___
8 #define nsTransform2D_h___
10 #include "nsCoord.h"
12 class nsTransform2D {
13 private:
14 /**
15 * This represents the following matrix (note that the order of row/column
16 * indices is opposite to usual notation)
18 * / m00 0 m20 \
19 * M = | 0 m11 m21 |
20 * \ 0 0 1 /
22 * Transformation of a coordinate (x, y) is obtained by setting
23 * v = (x, y, 1)^T and evaluating M . v
24 **/
26 float m00, m11, m20, m21;
28 public:
29 nsTransform2D(void) {
30 m20 = m21 = 0.0f;
31 m00 = m11 = 1.0f;
34 ~nsTransform2D(void) = default;
36 /**
37 * set this transform to a translation
39 * @param tx, x translation
40 * @param ty, y translation
41 **/
43 void SetToTranslate(float tx, float ty) {
44 m00 = m11 = 1.0f;
45 m20 = tx;
46 m21 = ty;
49 /**
50 * get the translation portion of this transform
52 * @param pt, Point to return translation values in
53 **/
55 void GetTranslationCoord(nscoord* ptX, nscoord* ptY) const {
56 *ptX = NSToCoordRound(m20);
57 *ptY = NSToCoordRound(m21);
60 /**
61 * apply matrix to vector
63 * @param pt Point to transform
64 **/
66 void TransformCoord(nscoord* ptX, nscoord* ptY) const;
68 /**
69 * apply matrix to rect
71 * @param rect Rect to transform
72 **/
74 void TransformCoord(nscoord* aX, nscoord* aY, nscoord* aWidth,
75 nscoord* aHeight) const;
77 /**
78 * add a scale to a Transform via x, y pair
80 * @param ptX x value to add as x scale
81 * @param ptY y value to add as y scale
82 **/
84 void AddScale(float ptX, float ptY) {
85 m00 *= ptX;
86 m11 *= ptY;
89 /**
90 * Set the scale (overriding any previous calls to AddScale, but leaving
91 * any existing translation).
93 * @param ptX x value to add as x scale
94 * @param ptY y value to add as y scale
95 **/
97 void SetScale(float ptX, float ptY) {
98 m00 = ptX;
99 m11 = ptY;
103 #endif