1 /* 2 * Copyright (c) 2025-2025 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 SCREEN_POINTER_H 17 #define SCREEN_POINTER_H 18 19 #include "screen_info.h" 20 #include "hardware_cursor_pointer_manager.h" 21 #include "window_info.h" 22 #include "pointer_renderer.h" 23 24 namespace OHOS::MMI { 25 using hwcmgr_ptr_t = std::shared_ptr<HardwareCursorPointerManager>; 26 using handler_ptr_t = std::shared_ptr<OHOS::AppExecFwk::EventHandler>; 27 using buffer_ptr_t = sptr<OHOS::SurfaceBuffer>; 28 using screen_info_ptr_t = sptr<OHOS::Rosen::ScreenInfo>; 29 using mode_t = OHOS::Rosen::ScreenSourceMode; 30 using rotation_t = OHOS::Rosen::Rotation; 31 32 uint32_t GetScreenInfoWidth(const screen_info_ptr_t); 33 uint32_t GetScreenInfoHeight(const screen_info_ptr_t); 34 35 class ScreenPointer final { 36 public: 37 DISALLOW_COPY_AND_MOVE(ScreenPointer); 38 ScreenPointer(hwcmgr_ptr_t hwcmgr, handler_ptr_t handler, const DisplayInfo &di); 39 ScreenPointer(hwcmgr_ptr_t hwcmgr, handler_ptr_t handler, screen_info_ptr_t si); 40 ~ScreenPointer() = default; 41 42 bool Init(); 43 bool InitSurface(); 44 void UpdateScreenInfo(screen_info_ptr_t si); 45 bool UpdatePadding(uint32_t mainWidth, uint32_t mainHeight); 46 void OnDisplayInfo(const DisplayInfo &di); 47 48 buffer_ptr_t RequestBuffer(); 49 buffer_ptr_t GetCurrentBuffer(); 50 51 bool Move(int32_t x, int32_t y, ICON_TYPE align); 52 bool MoveSoft(int32_t x, int32_t y, ICON_TYPE align); 53 void CalculatePositionForMirror(int32_t x, int32_t y, int32_t* px, int32_t* py); 54 bool SetInvisible(); 55 GetScreenId()56 uint32_t GetScreenId() const 57 { 58 return screenId_; 59 } 60 GetScreenWidth()61 uint32_t GetScreenWidth() const 62 { 63 return width_; 64 } 65 GetScreenHeight()66 uint32_t GetScreenHeight() const 67 { 68 return height_; 69 } 70 GetSurfaceNode()71 std::shared_ptr<OHOS::Rosen::RSSurfaceNode> GetSurfaceNode() 72 { 73 return surfaceNode_; 74 } 75 GetDPI()76 float GetDPI() const 77 { 78 return dpi_; 79 } 80 GetScale()81 float GetScale() const 82 { 83 return scale_; 84 } 85 IsMain()86 bool IsMain() const 87 { 88 return mode_ == mode_t::SCREEN_MAIN; 89 } 90 IsMirror()91 bool IsMirror() const 92 { 93 return mode_ == mode_t::SCREEN_MIRROR; 94 } 95 IsExtend()96 bool IsExtend() const 97 { 98 return mode_ == mode_t::SCREEN_EXTEND; 99 } 100 GetIsCurrentOffScreenRendering()101 bool GetIsCurrentOffScreenRendering() const 102 { 103 return isCurrentOffScreenRendering_; 104 } 105 GetOffRenderScale()106 float GetOffRenderScale() const 107 { 108 return offRenderScale_; 109 } 110 GetScreenRealDPI()111 float GetScreenRealDPI() const 112 { 113 return screenRealDPI_; 114 } 115 116 float GetRenderDPI() const; 117 SetRotation(const rotation_t rotation)118 void SetRotation(const rotation_t rotation) 119 { 120 rotation_ = rotation; 121 } 122 GetRotation()123 rotation_t GetRotation() 124 { 125 return rotation_; 126 } 127 128 private: 129 bool InitSurfaceNode(); 130 bool FlushSerfaceBuffer(); 131 void Rotate(rotation_t rotation, int32_t& x, int32_t& y); 132 void CalculateHwcPositionForMirror(int32_t& x, int32_t& y); 133 void CalculateHwcPositionForExtend(int32_t& x, int32_t& y); 134 135 private: 136 std::mutex mtx_; 137 138 uint32_t screenId_{0}; 139 uint32_t width_{0}; 140 uint32_t height_{0}; 141 mode_t mode_{mode_t::SCREEN_MAIN}; 142 rotation_t rotation_{rotation_t::ROTATION_0}; 143 float dpi_{1.0f}; 144 145 // screen scale and padding info 146 float scale_{1.0f}; 147 int32_t paddingTop_{0}; 148 int32_t paddingLeft_{0}; 149 150 hwcmgr_ptr_t hwcMgr_{nullptr}; 151 handler_ptr_t handler_{nullptr}; 152 153 // RS Layer 154 std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceNode_{nullptr}; 155 std::shared_ptr<OHOS::Rosen::RSCanvasNode> canvasNode_{nullptr}; 156 157 std::vector<buffer_ptr_t> buffers_; 158 uint32_t bufferId_ {0}; 159 160 // isCurrentOffScreenRendering 161 bool isCurrentOffScreenRendering_ = false; 162 float offRenderScale_{1.0f}; 163 int32_t screenRealDPI_{1.0f}; 164 }; 165 166 } // namespace OHOS::MMI 167 168 #endif // SCREEN_POINTER_H