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_PIPELINE_RS_ROOT_RENDER_NODE_H
16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_ROOT_RENDER_NODE_H
17 
18 #include "common/rs_macros.h"
19 #include "memory/rs_memory_track.h"
20 #include "pipeline/rs_canvas_render_node.h"
21 #ifdef NEW_RENDER_CONTEXT
22 #include "rs_render_surface.h"
23 #endif
24 
25 namespace OHOS {
26 namespace Rosen {
27 class RSSurface;
28 class RSDirtyRegionManager;
29 class RSB_EXPORT RSRootRenderNode : public RSCanvasRenderNode {
30 public:
31     static inline constexpr RSRenderNodeType Type = RSRenderNodeType::ROOT_NODE;
GetType()32     RSRenderNodeType GetType() const override
33     {
34         return Type;
35     }
36 
37     ~RSRootRenderNode() override;
38 
39     virtual void QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
40     virtual void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
41     virtual void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override;
42 
43     void AttachRSSurfaceNode(NodeId SurfaceNodeId);
44 
45     std::shared_ptr<RSDirtyRegionManager> GetDirtyManager() const;
46 #ifdef NEW_RENDER_CONTEXT
47     std::shared_ptr<RSRenderSurface> GetSurface();
48 #else
49     std::shared_ptr<RSSurface> GetSurface();
50 #endif
51     NodeId GetRSSurfaceNodeId();
52     float GetSuggestedBufferWidth() const;
53     float GetSuggestedBufferHeight() const;
54     void UpdateSuggestedBufferSize(float width, float height);
SetEnableRender(bool enableRender)55     void SetEnableRender(bool enableRender)
56     {
57         if (enableRender_ != enableRender) {
58             enableRender_ = enableRender;
59             SetContentDirty();
60         }
61     }
62 
GetEnableRender()63     bool GetEnableRender() const
64     {
65         return enableRender_;
66     }
67 
68 private:
69     explicit RSRootRenderNode(NodeId id, const std::weak_ptr<RSContext>& context = {},
70         bool isTextureExportNode = false);
71     std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr;
72 #ifdef NEW_RENDER_CONTEXT
73     std::shared_ptr<RSRenderSurface> rsSurface_ = nullptr;
74 #else
75     std::shared_ptr<RSSurface> rsSurface_ = nullptr;
76 #endif
77     NodeId surfaceNodeId_ = 0;
78     bool enableRender_ = true;
79     float suggestedBufferWidth_ = 0.f;
80     float suggestedBufferHeight_ = 0.f;
81 
82     std::vector<NodeId> childSurfaceNodeIds_;
83     friend class RootNodeCommandHelper;
84     friend class RSRenderThreadVisitor;
85 };
86 } // namespace Rosen
87 } // namespace OHOS
88 
89 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_ROOT_RENDER_NODE_H
90