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_RS_POINTER_WINDOW_MANAGER_H 17 #define RENDER_SERVICE_CORE_PIPELINE_RS_POINTER_WINDOW_MANAGER_H 18 19 #include "params/rs_render_thread_params.h" 20 #include "pipeline/rs_screen_render_node.h" 21 #include "pipeline/rs_logical_display_render_node.h" 22 #include "pipeline/rs_surface_render_node.h" 23 #include "pipeline/rs_processor_factory.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 class RSPointerWindowManager { 28 public: 29 RSPointerWindowManager(); 30 ~RSPointerWindowManager() = default; 31 32 static RSPointerWindowManager& Instance(); 33 34 void UpdatePointerDirtyToGlobalDirty(std::shared_ptr<RSSurfaceRenderNode>& pointWindow, 35 std::shared_ptr<RSScreenRenderNode>& curScreenNode); 36 37 static bool GetHardCursorEnabledPass(); 38 struct BoundParam { 39 float x = 0.0f; 40 float y = 0.0f; 41 float z = 0.0f; 42 float w = 0.0f; 43 }; 44 IsNeedForceCommitByPointer()45 bool IsNeedForceCommitByPointer() const 46 { 47 return isNeedForceCommitByPointer_; 48 } 49 SetNeedForceCommitByPointer(bool isNeedForceCommitByPointer)50 void SetNeedForceCommitByPointer(bool isNeedForceCommitByPointer) 51 { 52 isNeedForceCommitByPointer_ = isNeedForceCommitByPointer; 53 } 54 CollectInfoForHardCursor(NodeId id,DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr cursorDrawable)55 void CollectInfoForHardCursor(NodeId id, 56 DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr cursorDrawable) 57 { 58 hardCursorDrawables_.id = id; 59 hardCursorDrawables_.drawablePtr = cursorDrawable; 60 } 61 GetHardCursorDrawables()62 const HardCursorInfo& GetHardCursorDrawables() const 63 { 64 return hardCursorDrawables_; 65 } 66 67 void CollectAllHardCursor( 68 RSSurfaceRenderNode& hardCursorNode, std::shared_ptr<RSScreenRenderNode>& curScreenNode, 69 std::shared_ptr<RSLogicalDisplayRenderNode>& curDisplayNode); 70 GetHardCursorDrawableVec()71 const auto& GetHardCursorDrawableVec() const 72 { 73 return hardCursorDrawableVec_; 74 } 75 ResetHardCursorDrawables()76 void ResetHardCursorDrawables() 77 { 78 hardCursorDrawableVec_.clear(); 79 hardCursorNodeMap_.clear(); 80 } 81 GetIsPointerEnableHwc()82 bool GetIsPointerEnableHwc() const 83 { 84 return isPointerEnableHwc_.load(); 85 } 86 SetIsPointerEnableHwc(bool flag)87 void SetIsPointerEnableHwc(bool flag) 88 { 89 isPointerEnableHwc_.store(flag); 90 } 91 GetIsPointerCanSkipFrame()92 bool GetIsPointerCanSkipFrame() const 93 { 94 return isPointerCanSkipFrame_.load(); 95 } 96 SetIsPointerCanSkipFrame(bool flag)97 void SetIsPointerCanSkipFrame(bool flag) 98 { 99 isPointerCanSkipFrame_.store(flag); 100 } 101 IsPointerCanSkipFrameCompareChange(bool flag,bool changeFlag)102 bool IsPointerCanSkipFrameCompareChange(bool flag, bool changeFlag) 103 { 104 bool expectChanged = flag; 105 return isPointerCanSkipFrame_.compare_exchange_weak(expectChanged, changeFlag); 106 } 107 GetRsNodeId()108 int64_t GetRsNodeId() const 109 { 110 return rsNodeId_; 111 } 112 SetRsNodeId(int64_t id)113 void SetRsNodeId(int64_t id) 114 { 115 rsNodeId_ = id; 116 } 117 GetBoundHasUpdate()118 bool GetBoundHasUpdate() const 119 { 120 return boundHasUpdate_.load(); 121 } 122 SetBoundHasUpdate(bool flag)123 void SetBoundHasUpdate(bool flag) 124 { 125 boundHasUpdate_.store(flag); 126 } 127 BoundHasUpdateCompareChange(bool flag,bool changeFlag)128 bool BoundHasUpdateCompareChange(bool flag, bool changeFlag) 129 { 130 bool expectChanged = flag; 131 return boundHasUpdate_.compare_exchange_weak(expectChanged, changeFlag); 132 } 133 GetBound()134 BoundParam GetBound() const 135 { 136 return bound_; 137 } 138 SetBound(BoundParam bound)139 void SetBound(BoundParam bound) 140 { 141 bound_.x = bound.x; 142 bound_.y = bound.y; 143 bound_.z = bound.z; 144 bound_.w = bound.w; 145 } 146 147 void UpdatePointerInfo(); 148 void SetHwcNodeBounds(int64_t rsNodeId, float positionX, float positionY, 149 float positionZ, float positionW); 150 void SetHardCursorNodeInfo(std::shared_ptr<RSSurfaceRenderNode> hardCursorNode); 151 const std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>>& GetHardCursorNode() const; 152 153 void HardCursorCreateLayerForDirect(std::shared_ptr<RSProcessor> processor); 154 155 bool CheckHardCursorSupport(uint32_t screenId); 156 bool HasMirrorDisplay() const; 157 std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> GetHardCursorDrawable(NodeId id); 158 static void CheckHardCursorValid(const RSSurfaceRenderNode& node); 159 private: 160 bool isNeedForceCommitByPointer_{ false }; 161 HardCursorInfo hardCursorDrawables_; 162 std::vector<std::tuple<NodeId, NodeId, DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>> hardCursorDrawableVec_; 163 std::shared_ptr<RSSurfaceRenderNode> hardCursorNodes_; 164 std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>> hardCursorNodeMap_; 165 std::mutex mtx_; 166 std::atomic<bool> isPointerEnableHwc_ = true; 167 std::atomic<bool> isPointerCanSkipFrame_ = false; 168 std::atomic<bool> boundHasUpdate_ = false; 169 BoundParam bound_ = {0.0f, 0.0f, 0.0f, 0.0f}; 170 int64_t rsNodeId_ = -1; 171 bool isHardCursorEnable_ = false; 172 }; 173 } // namespace Rosen 174 } // namespace OHOS 175 #endif // RENDER_SERVICE_CORE_PIPELINE_RS_POINTER_WINDOW_MANAGER_H