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_display_render_node.h" 21 #include "pipeline/rs_surface_render_node.h" 22 #include "pipeline/rs_processor_factory.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 class RSPointerWindowManager { 27 public: 28 RSPointerWindowManager(); 29 ~RSPointerWindowManager() = default; 30 31 static RSPointerWindowManager& Instance(); 32 33 void UpdatePointerDirtyToGlobalDirty(std::shared_ptr<RSSurfaceRenderNode>& pointWindow, 34 std::shared_ptr<RSDisplayRenderNode>& curDisplayNode); 35 36 static bool GetHardCursorEnabledPass(); 37 struct BoundParam { 38 float x = 0.0f; 39 float y = 0.0f; 40 float z = 0.0f; 41 float w = 0.0f; 42 }; 43 IsNeedForceCommitByPointer()44 bool IsNeedForceCommitByPointer() const 45 { 46 return isNeedForceCommitByPointer_; 47 } 48 SetNeedForceCommitByPointer(bool isNeedForceCommitByPointer)49 void SetNeedForceCommitByPointer(bool isNeedForceCommitByPointer) 50 { 51 isNeedForceCommitByPointer_ = isNeedForceCommitByPointer; 52 } 53 CollectInfoForHardCursor(NodeId id,DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr cursorDrawable)54 void CollectInfoForHardCursor(NodeId id, 55 DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr cursorDrawable) 56 { 57 hardCursorDrawables_.id = id; 58 hardCursorDrawables_.drawablePtr = cursorDrawable; 59 } 60 GetHardCursorDrawables()61 const HardCursorInfo& GetHardCursorDrawables() const 62 { 63 return hardCursorDrawables_; 64 } 65 CollectAllHardCursor(NodeId id,DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr cursorDrawable)66 void CollectAllHardCursor(NodeId id, DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr cursorDrawable) 67 { 68 hardCursorDrawableMap_.emplace(id, cursorDrawable); 69 } 70 GetHardCursorDrawableMap()71 const std::map<NodeId, DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>& GetHardCursorDrawableMap() const 72 { 73 return hardCursorDrawableMap_; 74 } 75 ResetHardCursorDrawables()76 void ResetHardCursorDrawables() 77 { 78 hardCursorDrawableMap_.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 158 private: 159 bool isNeedForceCommitByPointer_{ false }; 160 HardCursorInfo hardCursorDrawables_; 161 std::map<NodeId, DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr> hardCursorDrawableMap_; 162 std::shared_ptr<RSSurfaceRenderNode> hardCursorNodes_; 163 std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>> hardCursorNodeMap_; 164 std::mutex mtx_; 165 std::atomic<bool> isPointerEnableHwc_ = true; 166 std::atomic<bool> isPointerCanSkipFrame_ = false; 167 std::atomic<bool> boundHasUpdate_ = false; 168 BoundParam bound_ = {0.0f, 0.0f, 0.0f, 0.0f}; 169 int64_t rsNodeId_ = -1; 170 bool isHardCursorEnable_ = false; 171 }; 172 } // namespace Rosen 173 } // namespace OHOS 174 #endif // RENDER_SERVICE_CORE_PIPELINE_RS_POINTER_WINDOW_MANAGER_H