• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 
SetScale(scalar sx,scalar sy)48 void Matrix::SetScale(scalar sx, scalar sy)
49 {
50     matrixImplPtr->SetScale(sx, sy);
51 }
52 
SetScaleTranslate(scalar sx,scalar sy,scalar dx,scalar dy)53 void Matrix::SetScaleTranslate(scalar sx, scalar sy, scalar dx, scalar dy)
54 {
55     matrixImplPtr->SetScaleTranslate(sx, sy, dx, dy);
56 }
57 
PreRotate(scalar degree)58 void Matrix::PreRotate(scalar degree)
59 {
60     matrixImplPtr->PreRotate(degree);
61 }
62 
PostRotate(scalar degree)63 void Matrix::PostRotate(scalar degree)
64 {
65     matrixImplPtr->PostRotate(degree);
66 }
67 
PostRotate(scalar degree,scalar px,scalar py)68 void Matrix::PostRotate(scalar degree, scalar px, scalar py)
69 {
70     matrixImplPtr->PostRotate(degree, px, py);
71 }
72 
PreTranslate(scalar dx,scalar dy)73 void Matrix::PreTranslate(scalar dx, scalar dy)
74 {
75     matrixImplPtr->PreTranslate(dx, dy);
76 }
77 
PostTranslate(scalar dx,scalar dy)78 void Matrix::PostTranslate(scalar dx, scalar dy)
79 {
80     matrixImplPtr->PostTranslate(dx, dy);
81 }
82 
PreScale(scalar sx,scalar sy)83 void Matrix::PreScale(scalar sx, scalar sy)
84 {
85     matrixImplPtr->PreScale(sx, sy);
86 }
87 
PostScale(scalar sx,scalar sy)88 void Matrix::PostScale(scalar sx, scalar sy)
89 {
90     matrixImplPtr->PostScale(sx, sy);
91 }
92 
PostScale(scalar sx,scalar sy,scalar px,scalar py)93 void Matrix::PostScale(scalar sx, scalar sy, scalar px, scalar py)
94 {
95     matrixImplPtr->PostScale(sx, sy, px, py);
96 }
97 
PreConcat(const Matrix & other)98 void Matrix::PreConcat(const Matrix& other)
99 {
100     matrixImplPtr->PreConcat(other);
101 }
102 
PreConcat(const Matrix44 & matrix44)103 void Matrix::PreConcat(const Matrix44& matrix44)
104 {
105     matrixImplPtr->PreConcat(matrix44);
106 }
107 
PostConcat(const Matrix & other)108 void Matrix::PostConcat(const Matrix& other)
109 {
110     matrixImplPtr->PostConcat(other);
111 }
112 
PostConcat(const Matrix44 & matrix44)113 void Matrix::PostConcat(const Matrix44& matrix44)
114 {
115     matrixImplPtr->PostConcat(matrix44);
116 }
117 
Invert(Matrix & inverse) const118 bool Matrix::Invert(Matrix& inverse) const
119 {
120     return matrixImplPtr->Invert(inverse);
121 }
122 
operator *(const Matrix & m)123 Matrix Matrix::operator*(const Matrix& m)
124 {
125     matrixImplPtr->Multiply(*this, m);
126     return *this;
127 }
128 
operator ==(const Matrix & m) const129 bool Matrix::operator==(const Matrix& m) const
130 {
131     return matrixImplPtr->Equals(*this, m);
132 }
133 
SetMatrix(scalar scaleX,scalar skewX,scalar transX,scalar skewY,scalar scaleY,scalar transY,scalar persp0,scalar persp1,scalar persp2)134 void Matrix::SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY,
135     scalar persp0, scalar persp1, scalar persp2)
136 {
137     matrixImplPtr->SetMatrix(scaleX, skewX, transX, skewY, scaleY, transY, persp0, persp1, persp2);
138 }
139 
MapPoints(std::vector<Point> & dst,const std::vector<Point> & src,uint32_t count) const140 void Matrix::MapPoints(std::vector<Point>& dst, const std::vector<Point>& src, uint32_t count) const
141 {
142     matrixImplPtr->MapPoints(dst, src, count);
143 }
144 
MapRect(Rect & dst,const Rect & src) const145 bool Matrix::MapRect(Rect& dst, const Rect& src) const
146 {
147     return matrixImplPtr->MapRect(dst, src);
148 }
149 
Set(Index index,scalar value)150 void Matrix::Set(Index index, scalar value)
151 {
152     matrixImplPtr->Set(index, value);
153 }
154 
Get(int index) const155 scalar Matrix::Get(int index) const
156 {
157     return matrixImplPtr->Get(index);
158 }
159 
GetAll(Buffer & buffer) const160 void Matrix::GetAll(Buffer& buffer) const
161 {
162     matrixImplPtr->GetAll(buffer);
163 }
164 
SetAll(Buffer & buffer)165 void Matrix::SetAll(Buffer& buffer)
166 {
167     matrixImplPtr->SetAll(buffer);
168 }
169 
IsIdentity() const170 bool Matrix::IsIdentity() const
171 {
172     return matrixImplPtr->IsIdentity();
173 }
174 
PreRotate(scalar degree,scalar px,scalar py)175 void Matrix::PreRotate(scalar degree, scalar px, scalar py)
176 {
177     matrixImplPtr->PreRotate(degree, px, py);
178 }
179 
PreScale(scalar sx,scalar sy,scalar px,scalar py)180 void Matrix::PreScale(scalar sx, scalar sy, scalar px, scalar py)
181 {
182     matrixImplPtr->PreScale(sx, sy, px, py);
183 }
184 
Reset()185 void Matrix::Reset()
186 {
187     matrixImplPtr->Reset();
188 }
189 
GetMinMaxScales(scalar scaleFactors[2])190 bool Matrix::GetMinMaxScales(scalar scaleFactors[2])
191 {
192     return matrixImplPtr->GetMinMaxScales(scaleFactors);
193 }
194 
HasPerspective() const195 bool Matrix::HasPerspective() const
196 {
197     return matrixImplPtr->HasPerspective();
198 }
199 } // namespace Drawing
200 } // namespace Rosen
201 } // namespace OHOS
202