1 /*
2  * Copyright (c) 2022-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_PIPELINE_RS_PROXY_RENDER_NODE_H
16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_PROXY_RENDER_NODE_H
17 
18 #include "common/rs_macros.h"
19 #include "modifier/rs_modifier_type.h"
20 #include "pipeline/rs_render_node.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 class RSSurfaceRenderNode;
25 class RSB_EXPORT RSProxyRenderNode : public RSRenderNode {
26 public:
27     using WeakPtr = std::weak_ptr<RSProxyRenderNode>;
28     using SharedPtr = std::shared_ptr<RSProxyRenderNode>;
29     static inline constexpr RSRenderNodeType Type = RSRenderNodeType::PROXY_NODE;
GetType()30     RSRenderNodeType GetType() const override
31     {
32         return Type;
33     }
34 
GetUifirstSupportFlag()35     bool GetUifirstSupportFlag() override
36     {
37         return false;
38     }
39 
OpincGetNodeSupportFlag()40     bool OpincGetNodeSupportFlag() override
41     {
42         return false;
43     }
44 
45     ~RSProxyRenderNode() override;
46 
47     void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
48     void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override;
49 
50     // Transfer the rendering context variables (matrix/alpha/clip) from the proxy node to the target node, usually a
51     // surface node. Note that:
52     // 1. All three variables (alpha, matrix, and clipRegion) are RELATIVE to its parent node.
53     // 2. Alpha can be processed as an absolute value, as its parent (surface) node's alpha should always be 1.0f.
54     // 3. The matrix and clipRegion should be applied according to the parent node's matrix.
55     void SetContextMatrix(const std::optional<Drawing::Matrix>& transform);
56     void SetContextAlpha(float alpha);
57     void SetContextClipRegion(const std::optional<Drawing::Rect>& clipRegion);
58 
59     void ResetContextVariableCache();
60 protected:
61     void OnTreeStateChanged() override;
62 
63 private:
64     explicit RSProxyRenderNode(NodeId id, std::weak_ptr<RSSurfaceRenderNode> target, NodeId targetId,
65         const std::weak_ptr<RSContext>& context = {});
66     std::weak_ptr<RSSurfaceRenderNode> target_;
67     NodeId targetId_;
68 
69     std::optional<Drawing::Matrix> contextMatrix_;
70     float contextAlpha_ = 0.0f;
71     std::optional<Drawing::Rect> contextClipRect_;
72 
73     void CleanUp(bool removeModifiers);
74 
75     friend class ProxyNodeCommandHelper;
76     friend class RSUniRenderVisitor;
77 };
78 } // namespace Rosen
79 } // namespace OHOS
80 
81 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_PROXY_RENDER_NODE_H
82