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