1 /* 2 * Copyright (c) 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 MATRIX44_H 17 #define MATRIX44_H 18 19 #include "impl_interface/matrix44_impl.h" 20 #include "utils/scalar.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 namespace Drawing { 25 class Matrix44 { 26 public: 27 // Matrix44 is a 4x4 float type matrix. 28 constexpr static int MATRIX44_SIZE = 16; 29 30 Matrix44(); ~Matrix44()31 virtual ~Matrix44() {} 32 33 /* 34 * @brief Sets Matrix44 to translate by (dx, dy, dz). 35 * @param dx horizontal translation. 36 * @param dy vertical translation. 37 * @param dz z-axis translation. 38 */ 39 void Translate(scalar dx, scalar dy, scalar dz); 40 41 /* 42 * @brief Sets Matrix44 to scale by sx, sy and sz about pivot point at (0, 0, 0). 43 * @param sx horizontal scale factor. 44 * @param sy vertical scale factor. 45 * @param sz z-axis scale factor. 46 */ 47 void Scale(scalar sx, scalar sy, scalar sz); 48 49 /* 50 * @brief Gets new Matrix44 to Matrix44 multiplied by Matrix44 other. 51 * @param other on right side of multiply expression. 52 * @return A new calculated Matrix44. 53 */ 54 Matrix44 operator*(const Matrix44& other); 55 56 /* 57 * @brief Converts the Matrix44 to Matrix. 58 * @return A Matrix which converts by Matrix44. 59 */ 60 explicit operator Matrix() const; 61 62 /* 63 * @brief Sets Matrix44 to sixteen values in buffer. 64 * @param buffer a [col][row] array. eg. buffer[0] maps to m00, buffer[1] maps to m10 65 */ 66 using Buffer = std::array<scalar, MATRIX44_SIZE>; 67 void SetMatrix44(const Buffer& buffer); 68 69 /* 70 * @brief Get the adaptation layer instance, called in the adaptation layer. 71 * @return Adaptation Layer instance. 72 */ 73 template<typename T> GetImpl()74 const std::shared_ptr<T> GetImpl() const 75 { 76 return impl_->DowncastingTo<T>(); 77 } 78 private: 79 std::shared_ptr<Matrix44Impl> impl_; 80 }; 81 } // namespace Drawing 82 } // namespace Rosen 83 } // namespace OHOS 84 #endif