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