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 
48     RectI MapAbsRect(const RectF& rect) const;
49     static RectI MapRect(const RectF& rect, const Drawing::Matrix& matrix);
50 
51     // return transform matrix (context + self)
52     // warning: If the parent node does not have the SandBox attribute, this interface does
53     // NOT cause problems. Otherwise, you need to use the GetAbsMatrix interface to multiply
54     // the AbsMatrix of the parent node by the left to obtain the matrix of the parent node.
55     const Drawing::Matrix& GetMatrix() const;
56     // return transform matrix (parent + context + self)
57     const Drawing::Matrix& GetAbsMatrix() const;
58 
59     bool IsNeedClientCompose() const;
60 
61     void SetContextMatrix(const std::optional<Drawing::Matrix>& matrix);
62 
63 private:
64     void UpdateAbsMatrix2D();
65     void UpdateAbsMatrix3D();
66     void SetAbsRect();
67 
68     static Vector2f GetDataRange(float d0, float d1, float d2, float d3);
69 
70     RectI absRect_;
71     Drawing::Matrix matrix_;
72     std::optional<Drawing::Matrix> absMatrix_;
73     std::optional<Drawing::Matrix> contextMatrix_;
74 };
75 } // namespace Rosen
76 } // namespace OHOS
77 #endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_ABS_GEOMETRY_H
78