/work/obj-fuzz/dist/include/mozilla/dom/DOMMatrix.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef MOZILLA_DOM_DOMMATRIX_H_ |
8 | | #define MOZILLA_DOM_DOMMATRIX_H_ |
9 | | |
10 | | #include "nsWrapperCache.h" |
11 | | #include "nsISupports.h" |
12 | | #include "nsCycleCollectionParticipant.h" |
13 | | #include "mozilla/Attributes.h" |
14 | | #include "mozilla/ErrorResult.h" |
15 | | #include "nsCOMPtr.h" |
16 | | #include "mozilla/dom/BindingDeclarations.h" |
17 | | #include "mozilla/dom/TypedArray.h" |
18 | | #include "mozilla/gfx/Matrix.h" // for Matrix4x4 |
19 | | |
20 | | namespace mozilla { |
21 | | namespace dom { |
22 | | |
23 | | class GlobalObject; |
24 | | class DOMMatrix; |
25 | | class DOMPoint; |
26 | | class StringOrUnrestrictedDoubleSequence; |
27 | | struct DOMPointInit; |
28 | | |
29 | | class DOMMatrixReadOnly : public nsWrapperCache |
30 | | { |
31 | | public: |
32 | | explicit DOMMatrixReadOnly(nsISupports* aParent) |
33 | | : mParent(aParent) |
34 | | , mMatrix2D(new gfx::Matrix()) |
35 | 0 | { |
36 | 0 | } |
37 | | |
38 | | DOMMatrixReadOnly(nsISupports* aParent, const DOMMatrixReadOnly& other) |
39 | | : mParent(aParent) |
40 | 0 | { |
41 | 0 | if (other.mMatrix2D) { |
42 | 0 | mMatrix2D = new gfx::Matrix(*other.mMatrix2D); |
43 | 0 | } else { |
44 | 0 | mMatrix3D = new gfx::Matrix4x4(*other.mMatrix3D); |
45 | 0 | } |
46 | 0 | } |
47 | | |
48 | | DOMMatrixReadOnly(nsISupports* aParent, const gfx::Matrix4x4& aMatrix) |
49 | | : mParent(aParent) |
50 | | { |
51 | | mMatrix3D = new gfx::Matrix4x4(aMatrix); |
52 | | } |
53 | | |
54 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMMatrixReadOnly) |
55 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMMatrixReadOnly) |
56 | | |
57 | 0 | nsISupports* GetParentObject() const { return mParent; } |
58 | | virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override; |
59 | | |
60 | | static already_AddRefed<DOMMatrixReadOnly> Constructor( |
61 | | const GlobalObject& aGlobal, |
62 | | const Optional<StringOrUnrestrictedDoubleSequence>& aArg, |
63 | | ErrorResult& aRv); |
64 | | |
65 | 0 | #define GetMatrixMember(entry2D, entry3D, default) \ |
66 | 0 | { \ |
67 | 0 | if (mMatrix3D) { \ |
68 | 0 | return mMatrix3D->entry3D; \ |
69 | 0 | } \ |
70 | 0 | return mMatrix2D->entry2D; \ |
71 | 0 | } Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M11() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M12() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M21() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M22() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M41() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M42() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::A() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::B() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::C() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::D() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::E() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::F() const |
72 | | |
73 | 0 | #define Get3DMatrixMember(entry3D, default) \ |
74 | 0 | { \ |
75 | 0 | if (mMatrix3D) { \ |
76 | 0 | return mMatrix3D->entry3D; \ |
77 | 0 | } \ |
78 | 0 | return default; \ |
79 | 0 | } Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M13() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M14() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M23() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M24() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M31() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M32() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M33() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M34() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M43() const Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::M44() const |
80 | | |
81 | | double A() const GetMatrixMember(_11, _11, 1.0) |
82 | | double B() const GetMatrixMember(_12, _12, 0) |
83 | | double C() const GetMatrixMember(_21, _21, 0) |
84 | | double D() const GetMatrixMember(_22, _22, 1.0) |
85 | | double E() const GetMatrixMember(_31, _41, 0) |
86 | | double F() const GetMatrixMember(_32, _42, 0) |
87 | | |
88 | | double M11() const GetMatrixMember(_11, _11, 1.0) |
89 | | double M12() const GetMatrixMember(_12, _12, 0) |
90 | | double M13() const Get3DMatrixMember(_13, 0) |
91 | | double M14() const Get3DMatrixMember(_14, 0) |
92 | | double M21() const GetMatrixMember(_21, _21, 0) |
93 | | double M22() const GetMatrixMember(_22, _22, 1.0) |
94 | | double M23() const Get3DMatrixMember(_23, 0) |
95 | | double M24() const Get3DMatrixMember(_24, 0) |
96 | | double M31() const Get3DMatrixMember(_31, 0) |
97 | | double M32() const Get3DMatrixMember(_32, 0) |
98 | | double M33() const Get3DMatrixMember(_33, 1.0) |
99 | | double M34() const Get3DMatrixMember(_34, 0) |
100 | | double M41() const GetMatrixMember(_31, _41, 0) |
101 | | double M42() const GetMatrixMember(_32, _42, 0) |
102 | | double M43() const Get3DMatrixMember(_43, 0) |
103 | | double M44() const Get3DMatrixMember(_44, 1.0) |
104 | | |
105 | | #undef GetMatrixMember |
106 | | #undef Get3DMatrixMember |
107 | | |
108 | | // Defined here so we can construct DOMMatrixReadOnly objects. |
109 | 0 | #define Set2DMatrixMember(entry2D, entry3D) \ |
110 | 0 | { \ |
111 | 0 | if (mMatrix3D) { \ |
112 | 0 | mMatrix3D->entry3D = v; \ |
113 | 0 | } else { \ |
114 | 0 | mMatrix2D->entry2D = v; \ |
115 | 0 | } \ |
116 | 0 | } Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetA(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetB(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetC(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetD(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetE(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetF(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM11(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM12(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM21(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM22(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM41(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM42(double) |
117 | | |
118 | 0 | #define Set3DMatrixMember(entry3D, default) \ |
119 | 0 | { \ |
120 | 0 | if (mMatrix3D || (v != default)) { \ |
121 | 0 | Ensure3DMatrix(); \ |
122 | 0 | mMatrix3D->entry3D = v; \ |
123 | 0 | } \ |
124 | 0 | } Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM13(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM14(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM23(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM24(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM31(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM32(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM33(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM34(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM43(double) Unexecuted instantiation: mozilla::dom::DOMMatrixReadOnly::SetM44(double) |
125 | | |
126 | | void SetA(double v) Set2DMatrixMember(_11, _11) |
127 | | void SetB(double v) Set2DMatrixMember(_12, _12) |
128 | | void SetC(double v) Set2DMatrixMember(_21, _21) |
129 | | void SetD(double v) Set2DMatrixMember(_22, _22) |
130 | | void SetE(double v) Set2DMatrixMember(_31, _41) |
131 | | void SetF(double v) Set2DMatrixMember(_32, _42) |
132 | | |
133 | | void SetM11(double v) Set2DMatrixMember(_11, _11) |
134 | | void SetM12(double v) Set2DMatrixMember(_12, _12) |
135 | | void SetM13(double v) Set3DMatrixMember(_13, 0) |
136 | | void SetM14(double v) Set3DMatrixMember(_14, 0) |
137 | | void SetM21(double v) Set2DMatrixMember(_21, _21) |
138 | | void SetM22(double v) Set2DMatrixMember(_22, _22) |
139 | | void SetM23(double v) Set3DMatrixMember(_23, 0) |
140 | | void SetM24(double v) Set3DMatrixMember(_24, 0) |
141 | | void SetM31(double v) Set3DMatrixMember(_31, 0) |
142 | | void SetM32(double v) Set3DMatrixMember(_32, 0) |
143 | | void SetM33(double v) Set3DMatrixMember(_33, 1.0) |
144 | | void SetM34(double v) Set3DMatrixMember(_34, 0) |
145 | | void SetM41(double v) Set2DMatrixMember(_31, _41) |
146 | | void SetM42(double v) Set2DMatrixMember(_32, _42) |
147 | | void SetM43(double v) Set3DMatrixMember(_43, 0) |
148 | | void SetM44(double v) Set3DMatrixMember(_44, 1.0) |
149 | | |
150 | | #undef Set2DMatrixMember |
151 | | #undef Set3DMatrixMember |
152 | | |
153 | | |
154 | | already_AddRefed<DOMMatrix> Translate(double aTx, |
155 | | double aTy, |
156 | | double aTz = 0) const; |
157 | | already_AddRefed<DOMMatrix> Scale(double aScale, |
158 | | double aOriginX = 0, |
159 | | double aOriginY = 0) const; |
160 | | already_AddRefed<DOMMatrix> Scale3d(double aScale, |
161 | | double aOriginX = 0, |
162 | | double aOriginY = 0, |
163 | | double aOriginZ = 0) const; |
164 | | already_AddRefed<DOMMatrix> ScaleNonUniform(double aScaleX, |
165 | | double aScaleY = 1.0, |
166 | | double aScaleZ = 1.0, |
167 | | double aOriginX = 0, |
168 | | double aOriginY = 0, |
169 | | double aOriginZ = 0) const; |
170 | | already_AddRefed<DOMMatrix> Rotate(double aAngle, |
171 | | double aOriginX = 0, |
172 | | double aOriginY = 0) const; |
173 | | already_AddRefed<DOMMatrix> RotateFromVector(double aX, |
174 | | double aY) const; |
175 | | already_AddRefed<DOMMatrix> RotateAxisAngle(double aX, |
176 | | double aY, |
177 | | double aZ, |
178 | | double aAngle) const; |
179 | | already_AddRefed<DOMMatrix> SkewX(double aSx) const; |
180 | | already_AddRefed<DOMMatrix> SkewY(double aSy) const; |
181 | | already_AddRefed<DOMMatrix> Multiply(const DOMMatrix& aOther) const; |
182 | | already_AddRefed<DOMMatrix> FlipX() const; |
183 | | already_AddRefed<DOMMatrix> FlipY() const; |
184 | | already_AddRefed<DOMMatrix> Inverse() const; |
185 | | |
186 | | bool Is2D() const; |
187 | | bool IsIdentity() const; |
188 | | already_AddRefed<DOMPoint> TransformPoint(const DOMPointInit& aPoint) const; |
189 | | void ToFloat32Array(JSContext* aCx, |
190 | | JS::MutableHandle<JSObject*> aResult, |
191 | | ErrorResult& aRv) const; |
192 | | void ToFloat64Array(JSContext* aCx, |
193 | | JS::MutableHandle<JSObject*> aResult, |
194 | | ErrorResult& aRv) const; |
195 | | void Stringify(nsAString& aResult); |
196 | | protected: |
197 | | nsCOMPtr<nsISupports> mParent; |
198 | | nsAutoPtr<gfx::Matrix> mMatrix2D; |
199 | | nsAutoPtr<gfx::Matrix4x4> mMatrix3D; |
200 | | |
201 | 0 | virtual ~DOMMatrixReadOnly() {} |
202 | | |
203 | | DOMMatrixReadOnly* SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv); |
204 | | void Ensure3DMatrix(); |
205 | | |
206 | | private: |
207 | | DOMMatrixReadOnly() = delete; |
208 | | DOMMatrixReadOnly(const DOMMatrixReadOnly&) = delete; |
209 | | DOMMatrixReadOnly& operator=(const DOMMatrixReadOnly&) = delete; |
210 | | }; |
211 | | |
212 | | class DOMMatrix : public DOMMatrixReadOnly |
213 | | { |
214 | | public: |
215 | | explicit DOMMatrix(nsISupports* aParent) |
216 | | : DOMMatrixReadOnly(aParent) |
217 | 0 | {} |
218 | | |
219 | | DOMMatrix(nsISupports* aParent, const DOMMatrixReadOnly& other) |
220 | | : DOMMatrixReadOnly(aParent, other) |
221 | 0 | {} |
222 | | |
223 | | DOMMatrix(nsISupports* aParent, const gfx::Matrix4x4& aMatrix) |
224 | | : DOMMatrixReadOnly(aParent, aMatrix) |
225 | | {} |
226 | | |
227 | | static already_AddRefed<DOMMatrix> |
228 | | Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); |
229 | | static already_AddRefed<DOMMatrix> |
230 | | Constructor(const GlobalObject& aGlobal, const nsAString& aTransformList, ErrorResult& aRv); |
231 | | static already_AddRefed<DOMMatrix> |
232 | | Constructor(const GlobalObject& aGlobal, const DOMMatrixReadOnly& aOther, ErrorResult& aRv); |
233 | | static already_AddRefed<DOMMatrix> |
234 | | Constructor(const GlobalObject& aGlobal, const Float32Array& aArray32, ErrorResult& aRv); |
235 | | static already_AddRefed<DOMMatrix> |
236 | | Constructor(const GlobalObject& aGlobal, const Float64Array& aArray64, ErrorResult& aRv); |
237 | | static already_AddRefed<DOMMatrix> |
238 | | Constructor(const GlobalObject& aGlobal, const Sequence<double>& aNumberSequence, ErrorResult& aRv); |
239 | | |
240 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
241 | | |
242 | | DOMMatrix* MultiplySelf(const DOMMatrix& aOther); |
243 | | DOMMatrix* PreMultiplySelf(const DOMMatrix& aOther); |
244 | | DOMMatrix* TranslateSelf(double aTx, |
245 | | double aTy, |
246 | | double aTz = 0); |
247 | | DOMMatrix* ScaleSelf(double aScale, |
248 | | double aOriginX = 0, |
249 | | double aOriginY = 0); |
250 | | DOMMatrix* Scale3dSelf(double aScale, |
251 | | double aOriginX = 0, |
252 | | double aOriginY = 0, |
253 | | double aOriginZ = 0); |
254 | | DOMMatrix* ScaleNonUniformSelf(double aScaleX, |
255 | | double aScaleY = 1, |
256 | | double aScaleZ = 1, |
257 | | double aOriginX = 0, |
258 | | double aOriginY = 0, |
259 | | double aOriginZ = 0); |
260 | | DOMMatrix* RotateSelf(double aAngle, |
261 | | double aOriginX = 0, |
262 | | double aOriginY = 0); |
263 | | DOMMatrix* RotateFromVectorSelf(double aX, |
264 | | double aY); |
265 | | DOMMatrix* RotateAxisAngleSelf(double aX, |
266 | | double aY, |
267 | | double aZ, |
268 | | double aAngle); |
269 | | DOMMatrix* SkewXSelf(double aSx); |
270 | | DOMMatrix* SkewYSelf(double aSy); |
271 | | DOMMatrix* InvertSelf(); |
272 | | DOMMatrix* SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv); |
273 | | |
274 | 0 | virtual ~DOMMatrix() {} |
275 | | }; |
276 | | |
277 | | } // namespace dom |
278 | | } // namespace mozilla |
279 | | |
280 | | #endif /*MOZILLA_DOM_DOMMATRIX_H_*/ |