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