• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MATRIX_IMPL_H
17 #define MATRIX_IMPL_H
18 
19 #include <vector>
20 
21 #include "base_impl.h"
22 
23 #include "utils/point.h"
24 #include "utils/rect.h"
25 #include "utils/scalar.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 enum class ScaleToFit;
31 class DRAWING_API Matrix;
32 class DRAWING_API Matrix44;
33 class MatrixImpl : public BaseImpl {
34 public:
35     // Matrix is a 3x3 float type matrix.
36     static constexpr int MATRIX_SIZE = 9;
37 
MatrixImpl()38     MatrixImpl() {}
~MatrixImpl()39     ~MatrixImpl() override {}
40 
41     virtual void Rotate(scalar degree, scalar px, scalar py) = 0;
42     virtual void Translate(scalar dx, scalar dy) = 0;
43     virtual void Scale(scalar sx, scalar sy, scalar px, scalar py) = 0;
44     virtual void SetScale(scalar sx, scalar sy) = 0;
45     virtual void SetScaleTranslate(scalar sx, scalar sy, scalar dx, scalar dy) = 0;
46     virtual void SetSinCos(scalar sinValue, scalar cosValue, scalar px, scalar py);
47     virtual void SetSkew(scalar kx, scalar ky) = 0;
48     virtual void SetSkew(scalar kx, scalar ky, scalar px, scalar py) = 0;
49 
50     virtual void PreRotate(scalar degree) = 0;
51     virtual void PostRotate(scalar degree) = 0;
52     virtual void PostRotate(scalar degree, scalar px, scalar py) = 0;
53     virtual void PreTranslate(scalar dx, scalar dy) = 0;
54     virtual void PostTranslate(scalar dx, scalar dy) = 0;
55     virtual void PreScale(scalar sx, scalar sy) = 0;
56     virtual void PostScale(scalar sx, scalar sy) = 0;
57     virtual void PostScale(scalar sx, scalar sy, scalar px, scalar py) = 0;
58     virtual void PreSkew(scalar kx, scalar ky) = 0;
59     virtual void PostSkew(scalar kx, scalar ky) = 0;
60     virtual void PreSkew(scalar kx, scalar ky, scalar px, scalar py) = 0;
61     virtual void PostSkew(scalar kx, scalar ky, scalar px, scalar py) = 0;
62     virtual void PreConcat(const Matrix& other) = 0;
63     virtual void PreConcat(const Matrix44& other) = 0;
64     virtual void PostConcat(const Matrix& other) = 0;
65     virtual void PostConcat(const Matrix44& other) = 0;
66 
67     virtual bool Invert(Matrix& inverse) const = 0;
68     virtual void Multiply(const Matrix& a, const Matrix& b) = 0;
69     virtual bool Equals(const Matrix& a, const Matrix& b) const = 0;
70     virtual void SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY,
71         scalar persp0, scalar persp1, scalar persp2) = 0;
72     virtual bool SetRectToRect(const Rect& src, const Rect& dst, ScaleToFit stf);
73     virtual void MapPoints(std::vector<Point>& dst, const std::vector<Point>& src, uint32_t count) const;
74     virtual scalar MapRadius(scalar radius) const;
75     virtual bool MapRect(Rect& dst, const Rect& src) const;
76     virtual bool SetPolyToPoly(const Point src[], const Point dst[], uint32_t count);
77     virtual void Set(int index, scalar value);
78     virtual scalar Get(int index) const = 0;
79     virtual void GetAll(std::array<scalar, MATRIX_SIZE>& buffer) const = 0;
80     virtual void SetAll(std::array<scalar, MATRIX_SIZE>& buffer) = 0;
81     virtual bool IsAffine() const = 0;
82     virtual bool IsIdentity() const = 0;
83     virtual void Clone(const Matrix&) = 0;
84     virtual void PreRotate(scalar degree, scalar px, scalar py) = 0;
85     virtual void PreScale(scalar sx, scalar sy, scalar px, scalar py) = 0;
86     virtual bool RectStaysRect() const = 0;
87     virtual void Reset() = 0;
88 
89     virtual bool GetMinMaxScales(scalar scaleFactors[2]) = 0;
90     virtual bool HasPerspective() const = 0;
91 };
92 } // namespace Drawing
93 } // namespace Rosen
94 } // namespace OHOS
95 #endif
96