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 #include "utils/matrix.h" 22 #include "utils/matrix44.h" 23 #include "utils/point.h" 24 25 #include "common/rs_macros.h" 26 #include "common/rs_matrix3.h" 27 #include "common/rs_obj_geometry.h" 28 #include "common/rs_rect.h" 29 #include "common/rs_vector2.h" 30 31 namespace OHOS { 32 namespace Rosen { 33 class RSB_EXPORT RSObjAbsGeometry : public RSObjGeometry { 34 public: 35 RSObjAbsGeometry(); 36 ~RSObjAbsGeometry() override; 37 void ConcatMatrix(const Drawing::Matrix& matrix); 38 void UpdateMatrix(const Drawing::Matrix* parentMatrix, const std::optional<Drawing::Point>& offset); 39 40 // Using by RenderService 41 void UpdateByMatrixFromSelf(); 42 GetAbsRect()43 const RectI& GetAbsRect() const 44 { 45 return absRect_; 46 } 47 RectI MapAbsRectWithMatrix(const RectF& rect, const Drawing::Matrix& matrix) const; 48 RectI MapAbsRect(const RectF& rect) const; 49 50 // Converts RectF to RectI by inward rounding (ceil for left/top, floor for right/bottom) 51 // to ensure the resulting integer rect is fully contained within the original floating-point rect. 52 // attention: used in render node's opaque area calculations 53 static RectI DeflateToRectI(const RectF& rect); 54 55 // Converts a RectF to RectI by outward rounding (floor for left/top, ceil for right/bottom) 56 // to ensure the original floating-point rect is fully contained within the resulting integer rect. 57 // attention: used in render node's draw area calculations 58 static RectI InflateToRectI(const RectF& rect); 59 60 static RectF MapRectWithoutRounding(const RectF& rect, const Drawing::Matrix& matrix); 61 static RectI MapRect(const RectF& rect, const Drawing::Matrix& matrix); 62 63 // return transform matrix (context + self) 64 // warning: If the parent node does not have the SandBox attribute, this interface does 65 // NOT cause problems. Otherwise, you need to use the GetAbsMatrix interface to multiply 66 // the AbsMatrix of the parent node by the left to obtain the matrix of the parent node. 67 const Drawing::Matrix& GetMatrix() const; 68 // return transform matrix (parent + context + self) 69 const Drawing::Matrix& GetAbsMatrix() const; 70 71 bool IsNeedClientCompose() const; 72 73 void SetContextMatrix(const std::optional<Drawing::Matrix>& matrix); 74 75 private: 76 void UpdateAbsMatrix2D(); 77 void UpdateAbsMatrix3D(); 78 void SetAbsRect(); 79 80 static Vector2f GetDataRange(float d0, float d1, float d2, float d3); 81 82 RectI absRect_; 83 Drawing::Matrix matrix_; 84 std::optional<Drawing::Matrix> absMatrix_; 85 std::optional<Drawing::Matrix> contextMatrix_; 86 }; 87 } // namespace Rosen 88 } // namespace OHOS 89 #endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_ABS_GEOMETRY_H 90