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 26 namespace OHOS { 27 namespace Rosen { 28 29 class RoundCornerDisplayManager { 30 public: 31 enum class RCDLayerType : uint32_t { 32 INVALID = 0, 33 TOP = 1, 34 BOTTOM = 2 35 }; 36 37 public: 38 using RoundCornerDisplayMap = std::unordered_map<NodeId, std::shared_ptr<RoundCornerDisplay>>; 39 using RCDLayerMap = std::unordered_map<std::string, std::pair<NodeId, RCDLayerType>>; 40 using RCDLayerInfoVec = std::vector<std::pair<NodeId, RCDLayerType>>; 41 RoundCornerDisplayManager(); 42 virtual ~RoundCornerDisplayManager(); 43 44 // add rendertarget nodeId info to map by layername, if layername exist update info 45 void AddLayer(const std::string& name, NodeId id, RCDLayerType type); 46 47 // Get rendertarget nodeId info via layername 48 std::pair<NodeId, RCDLayerType> GetLayerPair(const std::string& layerName); 49 50 // Check the layer is RCD layer via layername 51 bool CheckLayerIsRCD(const std::string& layerName); 52 53 // the soft draw api: draw all rendertarget node input and canvas. 54 void DrawRoundCorner(const RCDLayerInfoVec& layerInfos, RSPaintFilterCanvas* canvas); 55 56 // only add once rcd module for screen via nodeId 57 void AddRoundCornerDisplay(NodeId id); 58 59 // remove rcd resuorce for screen via nodeId 60 void RemoveRCDResource(NodeId id); 61 62 // update displayWidth_ and displayHeight_ 63 void UpdateDisplayParameter(NodeId id, uint32_t width, uint32_t height); 64 65 // update notchStatus_ 66 void UpdateNotchStatus(NodeId id, int status); 67 68 // update curOrientation_ and lastOrientation_ 69 void UpdateOrientationStatus(NodeId id, ScreenRotation orientation); 70 71 // update hardwareInfo_.resourceChanged and resourcePreparing 72 void UpdateHardwareResourcePrepared(NodeId id, bool prepared); 73 74 // run rcd hardwareComposer buffer prepare task via rendertarget ID 75 void RunHardwareTask(NodeId id, const std::function<void()>& task); 76 77 // get the hardware info via rendertarget ID which rcd hardwareComposer buffer prepare task needed 78 rs_rcd::RoundCornerHardware GetHardwareInfo(NodeId id, bool preparing = false); 79 80 // get the rcd enable tag 81 bool GetRcdEnable() const; 82 83 // get is notch need update tag for the rendertarget id 84 bool IsNotchNeedUpdate(NodeId id, bool notchStatus); 85 86 private: 87 bool CheckExist(NodeId id); 88 89 // the soft draw top rcd api: draw rendertarget node input and canvas. 90 void DrawTopRoundCorner(NodeId id, RSPaintFilterCanvas* canvas); 91 92 // the soft draw bottom rcd api: draw rendertarget node input and canvas. 93 void DrawBottomRoundCorner(NodeId id, RSPaintFilterCanvas* canvas); 94 95 // remove rcd module for screen via nodeId 96 void RemoveRoundCornerDisplay(NodeId id); 97 98 // remove rcd layer info for screen via nodeId 99 void RemoveRCDLayerInfo(NodeId id); 100 101 std::mutex rcdMapMut_; 102 RoundCornerDisplayMap rcdMap_; // key, value : rendertargetNodeId, rcd module 103 std::mutex rcdLayerMapMut_; 104 RCDLayerMap rcdlayerMap_; // key, value : rcdLayerName, rendertargetNodeId 105 }; 106 } // namespace Rosen 107 } // namespace OHOS 108 #endif