• 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 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 SetSinCos(scalar sinValue, scalar cosValue, scalar px, scalar py) override;
47     void SetSkew(scalar kx, scalar ky) override;
48     void SetSkew(scalar kx, scalar ky, scalar px, scalar py) override;
49     const SkMatrix& ExportSkiaMatrix() const;
50 
51     void PreRotate(scalar degree) override;
52     void PostRotate(scalar degree) override;
53     void PostRotate(scalar degree, scalar px, scalar py) override;
54     void PreTranslate(scalar dx, scalar dy) override;
55     void PostTranslate(scalar dx, scalar dy) override;
56     void PreScale(scalar sx, scalar sy) override;
57     void PostScale(scalar sx, scalar sy) override;
58     void PostScale(scalar sx, scalar sy, scalar px, scalar py) override;
59     void PreSkew(scalar kx, scalar ky) override;
60     void PostSkew(scalar kx, scalar ky) override;
61     void PreSkew(scalar kx, scalar ky, scalar px, scalar py) override;
62     void PostSkew(scalar kx, scalar ky, scalar px, scalar py) override;
63     void PreConcat(const Matrix& other) override;
64     void PreConcat(const Matrix44& other) override;
65     void PostConcat(const Matrix& other) override;
66     void PostConcat(const Matrix44& other) override;
67 
68     bool Invert(Matrix& inverse) const override;
69     void Multiply(const Matrix& a, const Matrix& b) override;
70     bool Equals(const Matrix& a, const Matrix& b) const override;
71     void SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY,
72         scalar persp0, scalar persp1, scalar persp2) override;
73     bool SetRectToRect(const Rect& src, const Rect& dst, ScaleToFit stf) override;
74     void MapPoints(std::vector<Point>& dst, const std::vector<Point>& src, uint32_t count) const override;
75     scalar MapRadius(scalar radius) const override;
76     bool MapRect(Rect& dst, const Rect& src) const override;
77     bool SetPolyToPoly(const Point src[], const Point dst[], uint32_t count) override;
78     void Set(int index, scalar value) override;
79     scalar Get(int index) const override;
80     void GetAll(std::array<scalar, MatrixImpl::MATRIX_SIZE>& buffer) const override;
81     void SetAll(std::array<scalar, MatrixImpl::MATRIX_SIZE>& buffer) override;
82     bool IsAffine() const override;
83     bool IsIdentity() const override;
84 
85     void ImportMatrix(const SkMatrix& skMatrix);
86     SkMatrix& ExportMatrix();
87 
88     void Clone(const Matrix& other) override;
89     void PreRotate(scalar degree, scalar px, scalar py) override;
90     void PreScale(scalar sx, scalar sy, scalar px, scalar py) override;
91     bool RectStaysRect() const override;
92     void Reset() override;
93 
94     bool GetMinMaxScales(scalar scaleFactors[2]) override;
95     bool HasPerspective() const override;
96 
97 private:
98     SkMatrix skMatrix_;
99 };
100 } // namespace Drawing
101 } // namespace Rosen
102 } // namespace OHOS
103 #endif
104