1 /*
2  * Copyright (c) 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 
16 #ifndef RENDER_SERVICE_CORE_RS_RCD_RENDER_MANAGER_H
17 #define RENDER_SERVICE_CORE_RS_RCD_RENDER_MANAGER_H
18 
19 #include <mutex>
20 #include <thread>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "pipeline/rs_context.h"
25 #include "pipeline/rs_processor.h"
26 #include "rs_rcd_surface_render_node.h"
27 #include "pipeline/round_corner_display/rs_round_corner_config.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 using RSRcdSurfaceRenderNodePtr = RSRcdSurfaceRenderNode::SharedPtr;
32 using RSRcdSurfaceRenderNodePtrMap = std::unordered_map<NodeId, RSRcdSurfaceRenderNode::SharedPtr>;
33 using RSRcdSurfaceRenderNodePtrVec = std::vector<RSRcdSurfaceRenderNodePtr>;
34 struct RcdPrepareInfo {
35     RSBaseRenderNode::SharedPtr bottomNode = nullptr;
36     RSBaseRenderNode::SharedPtr topNode = nullptr;
37     bool hasInvalidScene = false;
38 };
39 
40 struct RcdProcessInfo {
41     std::shared_ptr<RSProcessor> uniProcessor = nullptr;
42     std::shared_ptr<rs_rcd::RoundCornerLayer> topLayer = nullptr;
43     std::shared_ptr<rs_rcd::RoundCornerLayer> bottomLayer = nullptr;
44     bool resourceChanged = false;
45 };
46 
47 struct RcdInfo {
48     RcdPrepareInfo prepareInfo;
49     RcdProcessInfo processInfo;
50 };
51 
52 class RSRcdRenderManager {
53 public:
54     static RSRcdRenderManager& GetInstance();
55     static void InitInstance();
56     bool GetRcdRenderEnabled() const;
57 
58     void CheckRenderTargetNode(const RSContext& context);
59     RSRcdSurfaceRenderNodePtr GetTopSurfaceNode(NodeId id);
60     RSRcdSurfaceRenderNodePtr GetBottomSurfaceNode(NodeId id);
61     void DoProcessRenderTask(NodeId id, const RcdProcessInfo& info);
62 
63     void DoProcessRenderMainThreadTask(NodeId id, const RcdProcessInfo& info);
64 
65     static bool IsRcdProcessInfoValid(const RcdProcessInfo& info);
66 
67     RSRcdRenderManager() = default;
68     virtual ~RSRcdRenderManager() = default;
69 
70 private:
71     static bool CheckExist(NodeId id, const RSRenderNodeMap& map);
72     RSRcdSurfaceRenderNodePtr GetTopRenderNode(NodeId id);
73     RSRcdSurfaceRenderNodePtr GetBottomRenderNode(NodeId id);
74     void RemoveRcdResource(NodeId id);
75 
76     bool rcdRenderEnabled_ = false;
77     constexpr static NodeId TOP_RCD_NODE_ID = 1;
78     constexpr static NodeId BACKGROUND_RCD_NODE_ID = 2;
79 
80     std::mutex topNodeMapMut_;
81     std::mutex bottomNodeMapMut_;
82     // key nodeId of display screen, rcd rendernode
83     RSRcdSurfaceRenderNodePtrMap topSurfaceNodeMap_;
84     RSRcdSurfaceRenderNodePtrMap bottomSurfaceNodeMap_;
85 
86     bool isBufferCacheClear_ = false;
87 };
88 } // namespace Rosen
89 } // namespace OHOS
90 #endif // RENDER_SERVICE_CORE_RS_RCD_RENDER_MANAGER_H