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
SetScale(scalar sx,scalar sy)58 void Matrix::SetScale(scalar sx, scalar sy)
59 {
60 matrixImplPtr->SetScale(sx, sy);
61 }
62
SetScaleTranslate(scalar sx,scalar sy,scalar dx,scalar dy)63 void Matrix::SetScaleTranslate(scalar sx, scalar sy, scalar dx, scalar dy)
64 {
65 matrixImplPtr->SetScaleTranslate(sx, sy, dx, dy);
66 }
67
PreRotate(scalar degree)68 void Matrix::PreRotate(scalar degree)
69 {
70 matrixImplPtr->PreRotate(degree);
71 }
72
PostRotate(scalar degree)73 void Matrix::PostRotate(scalar degree)
74 {
75 matrixImplPtr->PostRotate(degree);
76 }
77
PostRotate(scalar degree,scalar px,scalar py)78 void Matrix::PostRotate(scalar degree, scalar px, scalar py)
79 {
80 matrixImplPtr->PostRotate(degree, px, py);
81 }
82
PreTranslate(scalar dx,scalar dy)83 void Matrix::PreTranslate(scalar dx, scalar dy)
84 {
85 matrixImplPtr->PreTranslate(dx, dy);
86 }
87
PostTranslate(scalar dx,scalar dy)88 void Matrix::PostTranslate(scalar dx, scalar dy)
89 {
90 matrixImplPtr->PostTranslate(dx, dy);
91 }
92
PreScale(scalar sx,scalar sy)93 void Matrix::PreScale(scalar sx, scalar sy)
94 {
95 matrixImplPtr->PreScale(sx, sy);
96 }
97
PostScale(scalar sx,scalar sy)98 void Matrix::PostScale(scalar sx, scalar sy)
99 {
100 matrixImplPtr->PostScale(sx, sy);
101 }
102
PostScale(scalar sx,scalar sy,scalar px,scalar py)103 void Matrix::PostScale(scalar sx, scalar sy, scalar px, scalar py)
104 {
105 matrixImplPtr->PostScale(sx, sy, px, py);
106 }
107
PreSkew(scalar kx,scalar ky)108 void Matrix::PreSkew(scalar kx, scalar ky)
109 {
110 matrixImplPtr->PreSkew(kx, ky);
111 }
112
PreSkew(scalar kx,scalar ky,scalar px,scalar py)113 void Matrix::PreSkew(scalar kx, scalar ky, scalar px, scalar py)
114 {
115 matrixImplPtr->PreSkew(kx, ky, px, py);
116 }
117
PostSkew(scalar kx,scalar ky)118 void Matrix::PostSkew(scalar kx, scalar ky)
119 {
120 matrixImplPtr->PostSkew(kx, ky);
121 }
122
PostSkew(scalar kx,scalar ky,scalar px,scalar py)123 void Matrix::PostSkew(scalar kx, scalar ky, scalar px, scalar py)
124 {
125 matrixImplPtr->PostSkew(kx, ky, px, py);
126 }
127
PreConcat(const Matrix & other)128 void Matrix::PreConcat(const Matrix& other)
129 {
130 matrixImplPtr->PreConcat(other);
131 }
132
PreConcat(const Matrix44 & matrix44)133 void Matrix::PreConcat(const Matrix44& matrix44)
134 {
135 matrixImplPtr->PreConcat(matrix44);
136 }
137
PostConcat(const Matrix & other)138 void Matrix::PostConcat(const Matrix& other)
139 {
140 matrixImplPtr->PostConcat(other);
141 }
142
PostConcat(const Matrix44 & matrix44)143 void Matrix::PostConcat(const Matrix44& matrix44)
144 {
145 matrixImplPtr->PostConcat(matrix44);
146 }
147
Invert(Matrix & inverse) const148 bool Matrix::Invert(Matrix& inverse) const
149 {
150 return matrixImplPtr->Invert(inverse);
151 }
152
operator *(const Matrix & m)153 Matrix Matrix::operator*(const Matrix& m)
154 {
155 matrixImplPtr->Multiply(*this, m);
156 return *this;
157 }
158
operator ==(const Matrix & m) const159 bool Matrix::operator==(const Matrix& m) const
160 {
161 return matrixImplPtr->Equals(*this, m);
162 }
163
SetMatrix(scalar scaleX,scalar skewX,scalar transX,scalar skewY,scalar scaleY,scalar transY,scalar persp0,scalar persp1,scalar persp2)164 void Matrix::SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY,
165 scalar persp0, scalar persp1, scalar persp2)
166 {
167 matrixImplPtr->SetMatrix(scaleX, skewX, transX, skewY, scaleY, transY, persp0, persp1, persp2);
168 }
169
SetRectToRect(const Rect & src,const Rect & dst,ScaleToFit stf)170 bool Matrix::SetRectToRect(const Rect& src, const Rect& dst, ScaleToFit stf)
171 {
172 return matrixImplPtr->SetRectToRect(src, dst, stf);
173 }
174
MapPoints(std::vector<Point> & dst,const std::vector<Point> & src,uint32_t count) const175 void Matrix::MapPoints(std::vector<Point>& dst, const std::vector<Point>& src, uint32_t count) const
176 {
177 matrixImplPtr->MapPoints(dst, src, count);
178 }
179
MapRect(Rect & dst,const Rect & src) const180 bool Matrix::MapRect(Rect& dst, const Rect& src) const
181 {
182 return matrixImplPtr->MapRect(dst, src);
183 }
184
SetPolyToPoly(const Point src[],const Point dst[],uint32_t count)185 bool Matrix::SetPolyToPoly(const Point src[], const Point dst[], uint32_t count)
186 {
187 return matrixImplPtr->SetPolyToPoly(src, dst, count);
188 }
189
Set(Index index,scalar value)190 void Matrix::Set(Index index, scalar value)
191 {
192 matrixImplPtr->Set(index, value);
193 }
194
Get(int index) const195 scalar Matrix::Get(int index) const
196 {
197 return matrixImplPtr->Get(index);
198 }
199
GetAll(Buffer & buffer) const200 void Matrix::GetAll(Buffer& buffer) const
201 {
202 matrixImplPtr->GetAll(buffer);
203 }
204
SetAll(Buffer & buffer)205 void Matrix::SetAll(Buffer& buffer)
206 {
207 matrixImplPtr->SetAll(buffer);
208 }
209
IsIdentity() const210 bool Matrix::IsIdentity() const
211 {
212 return matrixImplPtr->IsIdentity();
213 }
214
PreRotate(scalar degree,scalar px,scalar py)215 void Matrix::PreRotate(scalar degree, scalar px, scalar py)
216 {
217 matrixImplPtr->PreRotate(degree, px, py);
218 }
219
PreScale(scalar sx,scalar sy,scalar px,scalar py)220 void Matrix::PreScale(scalar sx, scalar sy, scalar px, scalar py)
221 {
222 matrixImplPtr->PreScale(sx, sy, px, py);
223 }
224
Reset()225 void Matrix::Reset()
226 {
227 matrixImplPtr->Reset();
228 }
229
GetMinMaxScales(scalar scaleFactors[2])230 bool Matrix::GetMinMaxScales(scalar scaleFactors[2])
231 {
232 return matrixImplPtr->GetMinMaxScales(scaleFactors);
233 }
234
HasPerspective() const235 bool Matrix::HasPerspective() const
236 {
237 return matrixImplPtr->HasPerspective();
238 }
239
Swap(Matrix & target)240 void Matrix::Swap(Matrix& target)
241 {
242 std::swap(matrixImplPtr, target.matrixImplPtr);
243 }
244 } // namespace Drawing
245 } // namespace Rosen
246 } // namespace OHOS
247