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 SKIA_MATRIX_H
17 #define SKIA_MATRIX_H
18 
19 #include <memory>
20 
21 #include "include/core/SkMatrix.h"
22 
23 #include "impl_interface/matrix_impl.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 class SkiaMatrix : public MatrixImpl {
29 public:
30     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
31 
32     SkiaMatrix();
33     explicit SkiaMatrix(const Matrix& other);
~SkiaMatrix()34     ~SkiaMatrix() override {}
35 
GetType()36     AdapterType GetType() const override
37     {
38         return AdapterType::SKIA_ADAPTER;
39     }
40 
41     void Rotate(scalar degree, scalar px, scalar py) override;
42     void Translate(scalar dx, scalar dy) override;
43     void Scale(scalar sx, scalar sy, scalar px, scalar py) override;
44     void SetScale(scalar sx, scalar sy) override;
45     void SetScaleTranslate(scalar sx, scalar sy, scalar dx, scalar dy) override;
46     void SetSkew(scalar kx, scalar ky) override;
47     void SetSkew(scalar kx, scalar ky, scalar px, scalar py) override;
48     const SkMatrix& ExportSkiaMatrix() const;
49 
50     void PreRotate(scalar degree) override;
51     void PostRotate(scalar degree) override;
52     void PostRotate(scalar degree, scalar px, scalar py) override;
53     void PreTranslate(scalar dx, scalar dy) override;
54     void PostTranslate(scalar dx, scalar dy) override;
55     void PreScale(scalar sx, scalar sy) override;
56     void PostScale(scalar sx, scalar sy) override;
57     void PostScale(scalar sx, scalar sy, scalar px, scalar py) override;
58     void PreSkew(scalar kx, scalar ky) override;
59     void PostSkew(scalar kx, scalar ky) override;
60     void PreSkew(scalar kx, scalar ky, scalar px, scalar py) override;
61     void PostSkew(scalar kx, scalar ky, scalar px, scalar py) override;
62     void PreConcat(const Matrix& other) override;
63     void PreConcat(const Matrix44& other) override;
64     void PostConcat(const Matrix& other) override;
65     void PostConcat(const Matrix44& other) override;
66 
67     bool Invert(Matrix& inverse) const override;
68     void Multiply(const Matrix& a, const Matrix& b) override;
69     bool Equals(const Matrix& a, const Matrix& b) const override;
70     void SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY,
71         scalar persp0, scalar persp1, scalar persp2) override;
72     bool SetRectToRect(const Rect& src, const Rect& dst, ScaleToFit stf) override;
73     void MapPoints(std::vector<Point>& dst, const std::vector<Point>& src, uint32_t count) const override;
74     bool MapRect(Rect& dst, const Rect& src) const override;
75     bool SetPolyToPoly(const Point src[], const Point dst[], uint32_t count) override;
76     void Set(int index, scalar value) override;
77     scalar Get(int index) const override;
78     void GetAll(std::array<scalar, MatrixImpl::MATRIX_SIZE>& buffer) const override;
79     void SetAll(std::array<scalar, MatrixImpl::MATRIX_SIZE>& buffer) override;
80     bool IsIdentity() const override;
81 
82     void ImportMatrix(const SkMatrix& skMatrix);
83     SkMatrix& ExportMatrix();
84 
85     void Clone(const Matrix& other) override;
86     void PreRotate(scalar degree, scalar px, scalar py) override;
87     void PreScale(scalar sx, scalar sy, scalar px, scalar py) override;
88     void Reset() override;
89 
90     bool GetMinMaxScales(scalar scaleFactors[2]) override;
91     bool HasPerspective() const override;
92 
93 private:
94     SkMatrix skMatrix_;
95 };
96 } // namespace Drawing
97 } // namespace Rosen
98 } // namespace OHOS
99 #endif
100