1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "utils/matrix.h"
17
18 #include "impl_factory.h"
19
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
Matrix()23 Matrix::Matrix() : matrixImplPtr(ImplFactory::CreateMatrixImpl()) {}
24
Matrix(const Matrix & other)25 Matrix::Matrix(const Matrix& other) : matrixImplPtr(ImplFactory::CreateMatrixImpl(other)) {}
26
operator =(const Matrix & matrix)27 Matrix& Matrix::operator=(const Matrix& matrix)
28 {
29 matrixImplPtr->Clone(matrix);
30 return *this;
31 }
32
Rotate(scalar degree,scalar px,scalar py)33 void Matrix::Rotate(scalar degree, scalar px, scalar py)
34 {
35 matrixImplPtr->Rotate(degree, px, py);
36 }
37
Translate(scalar dx,scalar dy)38 void Matrix::Translate(scalar dx, scalar dy)
39 {
40 matrixImplPtr->Translate(dx, dy);
41 }
42
Scale(scalar sx,scalar sy,scalar px,scalar py)43 void Matrix::Scale(scalar sx, scalar sy, scalar px, scalar py)
44 {
45 matrixImplPtr->Scale(sx, sy, px, py);
46 }
47
SetSkew(scalar kx,scalar ky)48 void Matrix::SetSkew(scalar kx, scalar ky)
49 {
50 matrixImplPtr->SetSkew(kx, ky);
51 }
52
SetSkew(scalar kx,scalar ky,scalar px,scalar py)53 void Matrix::SetSkew(scalar kx, scalar ky, scalar px, scalar py)
54 {
55 matrixImplPtr->SetSkew(kx, ky, px, py);
56 }
57
SetConcat(const Matrix & a,const Matrix & b)58 void Matrix::SetConcat(const Matrix& a, const Matrix& b)
59 {
60 matrixImplPtr->Multiply(a, b);
61 }
62
SetScale(scalar sx,scalar sy)63 void Matrix::SetScale(scalar sx, scalar sy)
64 {
65 matrixImplPtr->SetScale(sx, sy);
66 }
67
SetScaleTranslate(scalar sx,scalar sy,scalar dx,scalar dy)68 void Matrix::SetScaleTranslate(scalar sx, scalar sy, scalar dx, scalar dy)
69 {
70 matrixImplPtr->SetScaleTranslate(sx, sy, dx, dy);
71 }
72
SetSinCos(scalar sinValue,scalar cosValue,scalar px,scalar py)73 void Matrix::SetSinCos(scalar sinValue, scalar cosValue, scalar px, scalar py)
74 {
75 return matrixImplPtr->SetSinCos(sinValue, cosValue, px, py);
76 }
77
PreRotate(scalar degree)78 void Matrix::PreRotate(scalar degree)
79 {
80 matrixImplPtr->PreRotate(degree);
81 }
82
PostRotate(scalar degree)83 void Matrix::PostRotate(scalar degree)
84 {
85 matrixImplPtr->PostRotate(degree);
86 }
87
PostRotate(scalar degree,scalar px,scalar py)88 void Matrix::PostRotate(scalar degree, scalar px, scalar py)
89 {
90 matrixImplPtr->PostRotate(degree, px, py);
91 }
92
PreTranslate(scalar dx,scalar dy)93 void Matrix::PreTranslate(scalar dx, scalar dy)
94 {
95 matrixImplPtr->PreTranslate(dx, dy);
96 }
97
PostTranslate(scalar dx,scalar dy)98 void Matrix::PostTranslate(scalar dx, scalar dy)
99 {
100 matrixImplPtr->PostTranslate(dx, dy);
101 }
102
PreScale(scalar sx,scalar sy)103 void Matrix::PreScale(scalar sx, scalar sy)
104 {
105 matrixImplPtr->PreScale(sx, sy);
106 }
107
PostScale(scalar sx,scalar sy)108 void Matrix::PostScale(scalar sx, scalar sy)
109 {
110 matrixImplPtr->PostScale(sx, sy);
111 }
112
PostScale(scalar sx,scalar sy,scalar px,scalar py)113 void Matrix::PostScale(scalar sx, scalar sy, scalar px, scalar py)
114 {
115 matrixImplPtr->PostScale(sx, sy, px, py);
116 }
117
PreSkew(scalar kx,scalar ky)118 void Matrix::PreSkew(scalar kx, scalar ky)
119 {
120 matrixImplPtr->PreSkew(kx, ky);
121 }
122
PreSkew(scalar kx,scalar ky,scalar px,scalar py)123 void Matrix::PreSkew(scalar kx, scalar ky, scalar px, scalar py)
124 {
125 matrixImplPtr->PreSkew(kx, ky, px, py);
126 }
127
PostSkew(scalar kx,scalar ky)128 void Matrix::PostSkew(scalar kx, scalar ky)
129 {
130 matrixImplPtr->PostSkew(kx, ky);
131 }
132
PostSkew(scalar kx,scalar ky,scalar px,scalar py)133 void Matrix::PostSkew(scalar kx, scalar ky, scalar px, scalar py)
134 {
135 matrixImplPtr->PostSkew(kx, ky, px, py);
136 }
137
PreConcat(const Matrix & other)138 void Matrix::PreConcat(const Matrix& other)
139 {
140 matrixImplPtr->PreConcat(other);
141 }
142
PreConcat(const Matrix44 & matrix44)143 void Matrix::PreConcat(const Matrix44& matrix44)
144 {
145 matrixImplPtr->PreConcat(matrix44);
146 }
147
PostConcat(const Matrix & other)148 void Matrix::PostConcat(const Matrix& other)
149 {
150 matrixImplPtr->PostConcat(other);
151 }
152
PostConcat(const Matrix44 & matrix44)153 void Matrix::PostConcat(const Matrix44& matrix44)
154 {
155 matrixImplPtr->PostConcat(matrix44);
156 }
157
Invert(Matrix & inverse) const158 bool Matrix::Invert(Matrix& inverse) const
159 {
160 return matrixImplPtr->Invert(inverse);
161 }
162
operator *(const Matrix & m)163 Matrix Matrix::operator*(const Matrix& m)
164 {
165 matrixImplPtr->Multiply(*this, m);
166 return *this;
167 }
168
operator ==(const Matrix & m) const169 bool Matrix::operator==(const Matrix& m) const
170 {
171 return matrixImplPtr->Equals(*this, m);
172 }
173
SetMatrix(scalar scaleX,scalar skewX,scalar transX,scalar skewY,scalar scaleY,scalar transY,scalar persp0,scalar persp1,scalar persp2)174 void Matrix::SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY,
175 scalar persp0, scalar persp1, scalar persp2)
176 {
177 matrixImplPtr->SetMatrix(scaleX, skewX, transX, skewY, scaleY, transY, persp0, persp1, persp2);
178 }
179
SetRectToRect(const Rect & src,const Rect & dst,ScaleToFit stf)180 bool Matrix::SetRectToRect(const Rect& src, const Rect& dst, ScaleToFit stf)
181 {
182 return matrixImplPtr->SetRectToRect(src, dst, stf);
183 }
184
MapPoints(std::vector<Point> & dst,const std::vector<Point> & src,uint32_t count) const185 void Matrix::MapPoints(std::vector<Point>& dst, const std::vector<Point>& src, uint32_t count) const
186 {
187 matrixImplPtr->MapPoints(dst, src, count);
188 }
189
MapRadius(scalar radius) const190 scalar Matrix::MapRadius(scalar radius) const
191 {
192 return matrixImplPtr->MapRadius(radius);
193 }
194
MapRect(Rect & dst,const Rect & src) const195 bool Matrix::MapRect(Rect& dst, const Rect& src) const
196 {
197 return matrixImplPtr->MapRect(dst, src);
198 }
199
SetPolyToPoly(const Point src[],const Point dst[],uint32_t count)200 bool Matrix::SetPolyToPoly(const Point src[], const Point dst[], uint32_t count)
201 {
202 return matrixImplPtr->SetPolyToPoly(src, dst, count);
203 }
204
Set(Index index,scalar value)205 void Matrix::Set(Index index, scalar value)
206 {
207 matrixImplPtr->Set(index, value);
208 }
209
Get(int index) const210 scalar Matrix::Get(int index) const
211 {
212 return matrixImplPtr->Get(index);
213 }
214
GetAll(Buffer & buffer) const215 void Matrix::GetAll(Buffer& buffer) const
216 {
217 matrixImplPtr->GetAll(buffer);
218 }
219
SetAll(Buffer & buffer)220 void Matrix::SetAll(Buffer& buffer)
221 {
222 matrixImplPtr->SetAll(buffer);
223 }
224
IsIdentity() const225 bool Matrix::IsIdentity() const
226 {
227 return matrixImplPtr->IsIdentity();
228 }
229
IsAffine() const230 bool Matrix::IsAffine() const
231 {
232 return matrixImplPtr->IsAffine();
233 }
234
PreRotate(scalar degree,scalar px,scalar py)235 void Matrix::PreRotate(scalar degree, scalar px, scalar py)
236 {
237 matrixImplPtr->PreRotate(degree, px, py);
238 }
239
PreScale(scalar sx,scalar sy,scalar px,scalar py)240 void Matrix::PreScale(scalar sx, scalar sy, scalar px, scalar py)
241 {
242 matrixImplPtr->PreScale(sx, sy, px, py);
243 }
244
RectStaysRect() const245 bool Matrix::RectStaysRect() const
246 {
247 return matrixImplPtr->RectStaysRect();
248 }
249
Reset()250 void Matrix::Reset()
251 {
252 matrixImplPtr->Reset();
253 }
254
GetMinMaxScales(scalar scaleFactors[2])255 bool Matrix::GetMinMaxScales(scalar scaleFactors[2])
256 {
257 return matrixImplPtr->GetMinMaxScales(scaleFactors);
258 }
259
HasPerspective() const260 bool Matrix::HasPerspective() const
261 {
262 return matrixImplPtr->HasPerspective();
263 }
264
Swap(Matrix & target)265 void Matrix::Swap(Matrix& target)
266 {
267 std::swap(matrixImplPtr, target.matrixImplPtr);
268 }
269 } // namespace Drawing
270 } // namespace Rosen
271 } // namespace OHOS
272