• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_PIPELINE_RCD_RENDER_RS_RCD_MANAGER_H
17 #define RENDER_SERVICE_CORE_PIPELINE_RCD_RENDER_RS_RCD_MANAGER_H
18 
19 #include <mutex>
20 #include <thread>
21 #include <unordered_map>
22 
23 #include "common/rs_common_def.h"
24 #include "rs_round_corner_display.h"
25 #include "screen_manager/rs_screen_manager.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 
30 // round corner display message declaration
31 constexpr char TOPIC_RCD_DISPLAY_SIZE[] = "RCD_UPDATE_DISPLAY_SIZE";
32 constexpr char TOPIC_RCD_DISPLAY_ROTATION[] = "RCD_UPDATE_DISPLAY_ROTATION";
33 constexpr char TOPIC_RCD_DISPLAY_NOTCH[] = "RCD_UPDATE_DISPLAY_NOTCH";
34 constexpr char TOPIC_RCD_RESOURCE_CHANGE[] = "TOPIC_RCD_RESOURCE_CHANGE";
35 constexpr char TOPIC_RCD_DISPLAY_HWRESOURCE[] = "RCD_UPDATE_DISPLAY_HWRESOURCE";
36 
37 class RoundCornerDisplayManager {
38 public:
39 enum class RCDLayerType : uint32_t {
40     INVALID = 0,
41     TOP = 1,
42     BOTTOM = 2
43 };
44 
CheckRcdRenderEnable(const ScreenInfo & screenInfo)45 static bool CheckRcdRenderEnable(const ScreenInfo& screenInfo)
46 {
47     return screenInfo.state == ScreenState::HDI_OUTPUT_ENABLE;
48 }
49 
50 public:
51     using RoundCornerDisplayMap = std::unordered_map<NodeId, std::shared_ptr<RoundCornerDisplay>>;
52     using RCDLayerMap = std::unordered_map<std::string, std::pair<NodeId, RCDLayerType>>;
53     using RCDLayerInfoVec = std::vector<std::pair<NodeId, RCDLayerType>>;
54     RoundCornerDisplayManager();
55     virtual ~RoundCornerDisplayManager();
56 
57     // regist rcd message for multiple callback
58     void RegisterRcdMsg();
59 
60     // add rendertarget nodeId info to map by layername, if layername exist update info
61     void AddLayer(const std::string& name, NodeId id, RCDLayerType type);
62 
63     // Get rendertarget nodeId info via layername
64     std::pair<NodeId, RCDLayerType> GetLayerPair(const std::string& layerName);
65 
66     // Check the layer is RCD layer via layername
67     bool CheckLayerIsRCD(const std::string& layerName);
68 
69     // the soft draw api: draw all rendertarget node input and canvas.
70     void DrawRoundCorner(const RCDLayerInfoVec& layerInfos, RSPaintFilterCanvas* canvas);
71 
72     // only add once rcd module for screen via nodeId
73     void AddRoundCornerDisplay(NodeId id);
74 
75     // remove rcd resuorce for screen via nodeId
76     void RemoveRCDResource(NodeId id);
77 
78     // update displayWidth_ and displayHeight_
79     void UpdateDisplayParameter(NodeId id, uint32_t left, uint32_t top, uint32_t width, uint32_t height);
80 
81     // update notchStatus_
82     void UpdateNotchStatus(NodeId id, int status);
83 
84     // update curOrientation_ and lastOrientation_
85     void UpdateOrientationStatus(NodeId id, ScreenRotation orientation);
86 
87     // update hardwareInfo_.resourceChanged and resourcePreparing
88     void UpdateHardwareResourcePrepared(NodeId id, bool prepared);
89 
90     // update rcd status and create resource
91     void RefreshFlagAndUpdateResource(NodeId id);
92 
93     // handle rcdDirtyType_ and assign dirty rect
94     bool HandleRoundCornerDirtyRect(NodeId id, RectI &dirtyRect, const RCDLayerType type);
95 
96     // run rcd hardwareComposer buffer prepare task via rendertarget ID
97     void RunHardwareTask(NodeId id, const std::function<void()>& task);
98 
99     // get the hardware info via rendertarget ID
100     rs_rcd::RoundCornerHardware GetHardwareInfo(NodeId id);
101 
102     // update and get the hardware info via rendertarget ID which rcd hardwareComposer buffer prepare task needed
103     rs_rcd::RoundCornerHardware PrepareHardwareInfo(NodeId id);
104 
105     // get the rcd enable tag, only set to false by system properties durning debug
106     bool GetRcdEnable() const;
107 
108     // get is notch need update tag for the rendertarget id
109     bool IsNotchNeedUpdate(NodeId id, bool notchStatus);
110 
111 private:
112     bool CheckExist(NodeId id);
113 
114     // the soft draw top rcd api: draw rendertarget node input and canvas.
115     void DrawTopRoundCorner(NodeId id, RSPaintFilterCanvas* canvas);
116 
117     // the soft draw bottom rcd api: draw rendertarget node input and canvas.
118     void DrawBottomRoundCorner(NodeId id, RSPaintFilterCanvas* canvas);
119 
120     // remove rcd module for screen via nodeId
121     void RemoveRoundCornerDisplay(NodeId id);
122 
123     // remove rcd layer info for screen via nodeId
124     void RemoveRCDLayerInfo(NodeId id);
125 
126     std::mutex rcdMapMut_;
127     RoundCornerDisplayMap rcdMap_; // key, value : rendertargetNodeId, rcd module
128     std::mutex rcdLayerMapMut_;
129     RCDLayerMap rcdlayerMap_;  // key, value : rcdLayerName, rendertargetNodeId
130 
131     bool isRcdMessageRegisted_ = false;
132 };
133 } // namespace Rosen
134 } // namespace OHOS
135 #endif