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 #ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_ABS_GEOMETRY_H 16 #define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_ABS_GEOMETRY_H 17 18 #include <memory> 19 #include <optional> 20 21 #ifndef USE_ROSEN_DRAWING 22 #include "include/core/SkMatrix.h" 23 #include "include/core/SkPoint.h" 24 #else 25 #include "utils/matrix.h" 26 #include "utils/point.h" 27 #endif 28 29 #include "common/rs_macros.h" 30 #include "common/rs_matrix3.h" 31 #include "common/rs_obj_geometry.h" 32 #include "common/rs_rect.h" 33 #include "common/rs_vector2.h" 34 35 namespace OHOS { 36 namespace Rosen { 37 class RSB_EXPORT RSObjAbsGeometry : public RSObjGeometry { 38 public: 39 RSObjAbsGeometry(); 40 ~RSObjAbsGeometry() override; 41 #ifndef USE_ROSEN_DRAWING 42 void ConcatMatrix(const SkMatrix& matrix); 43 void UpdateMatrix(const std::shared_ptr<RSObjAbsGeometry>& parent, const std::optional<SkPoint>& offset, 44 const std::optional<SkRect>& clipRect); 45 #else 46 void ConcatMatrix(const Drawing::Matrix& matrix); 47 void UpdateMatrix(const std::shared_ptr<RSObjAbsGeometry>& parent, const std::optional<Drawing::Point>& offset, 48 const std::optional<Drawing::Rect>& clipRect); 49 #endif 50 51 // Using by RenderService 52 void UpdateByMatrixFromSelf(); 53 GetAbsRect()54 const RectI& GetAbsRect() const 55 { 56 return absRect_; 57 } 58 RectI MapAbsRect(const RectF& rect) const; 59 60 #ifndef USE_ROSEN_DRAWING 61 // return transform matrix (context + self) 62 const SkMatrix& GetMatrix() const; 63 // return transform matrix (parent + context + self) 64 const SkMatrix& GetAbsMatrix() const; 65 #else 66 // return transform matrix (context + self) 67 const Drawing::Matrix& GetMatrix() const; 68 // return transform matrix (parent + context + self) 69 const Drawing::Matrix& GetAbsMatrix() const; 70 #endif 71 72 bool IsNeedClientCompose() const; 73 74 #ifndef USE_ROSEN_DRAWING 75 void SetContextMatrix(const std::optional<SkMatrix>& matrix); 76 #else 77 void SetContextMatrix(const std::optional<Drawing::Matrix>& matrix); 78 #endif 79 Reset()80 void Reset() override 81 { 82 RSObjGeometry::Reset(); 83 absMatrix_.reset(); 84 contextMatrix_.reset(); 85 } 86 87 private: 88 void UpdateAbsMatrix2D(); 89 void UpdateAbsMatrix3D(); 90 void SetAbsRect(); 91 92 Vector2f GetDataRange(float d0, float d1, float d2, float d3) const; 93 94 RectI absRect_; 95 #ifndef USE_ROSEN_DRAWING 96 SkMatrix matrix_; 97 std::optional<SkMatrix> absMatrix_; 98 std::optional<SkMatrix> contextMatrix_; 99 #else 100 Drawing::Matrix matrix_; 101 std::optional<Drawing::Matrix> absMatrix_; 102 std::optional<Drawing::Matrix> contextMatrix_; 103 #endif 104 }; 105 } // namespace Rosen 106 } // namespace OHOS 107 #endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_ABS_GEOMETRY_H 108