1 /* 2 * Copyright (c) 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 CURSOR_DRAWING_COMPONENT_H 17 #define CURSOR_DRAWING_COMPONENT_H 18 19 #include <cstdint> 20 #include <map> 21 22 #include "delegate_interface.h" 23 #include "i_pointer_drawing_manager.h" 24 #include "pointer_style.h" 25 #include "window_info.h" 26 #include "struct_multimodal.h" 27 28 namespace OHOS::MMI { 29 class CursorDrawingComponent { 30 public: 31 static CursorDrawingComponent& GetInstance(); 32 void Load(); 33 void UnLoad(); 34 35 void DrawPointer(uint64_t displayId, int32_t physicalX, int32_t physicalY, 36 const PointerStyle pointerStyle, Direction direction); 37 void UpdateDisplayInfo(const OLD::DisplayInfo &displayInfo); 38 void OnDisplayInfo(const OLD::DisplayGroupInfo &displayGroupInfo); 39 void OnWindowInfo(const WinInfo &info); 40 bool Init(); 41 void DeletePointerVisible(int32_t pid); 42 int32_t SetPointerVisible(int32_t pid, bool visible, int32_t priority, bool isHap); 43 bool GetPointerVisible(int32_t pid); 44 int32_t SetPointerColor(int32_t color); 45 int32_t GetPointerColor(); 46 int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle, bool isUiExtension); 47 int32_t ClearWindowPointerStyle(int32_t pid, int32_t windowId); 48 int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension); 49 void DrawPointerStyle(const PointerStyle &pointerStyle); 50 bool IsPointerVisible(); 51 void SetPointerLocation(int32_t x, int32_t y, uint64_t displayId); 52 void SetMouseDisplayState(bool state); 53 bool GetMouseDisplayState(); 54 int32_t SetCustomCursor(CursorPixelMap curPixelMap, int32_t pid, int32_t windowId, int32_t focusX, int32_t focusY); 55 int32_t SetCustomCursor(int32_t pid, int32_t windowId, CustomCursor cursor, CursorOptions options); 56 int32_t SetMouseIcon(int32_t pid, int32_t windowId, CursorPixelMap curPixelMap); 57 int32_t SetMouseHotSpot(int32_t pid, int32_t windowId, int32_t hotSpotX, int32_t hotSpotY); 58 int32_t SetPointerSize(int32_t size); 59 int32_t GetPointerSize(); 60 void GetPointerImageSize(int32_t &width, int32_t &height); 61 int32_t GetCursorSurfaceId(uint64_t &surfaceId); 62 PointerStyle GetLastMouseStyle(); 63 IconStyle GetIconStyle(const MOUSE_ICON mouseStyle); 64 const std::map<MOUSE_ICON, IconStyle>& GetMouseIconPath(); 65 int32_t SwitchPointerStyle(); 66 void DrawMovePointer(uint64_t displayId, int32_t physicalX, int32_t physicalY); 67 void Dump(int32_t fd, const std::vector<std::string> &args); 68 void InitPointerCallback(); 69 void InitScreenInfo(); 70 int32_t EnableHardwareCursorStats(int32_t pid, bool enable); 71 int32_t GetHardwareCursorStats(int32_t pid, uint32_t &frameCount, uint32_t &vsyncCount); 72 OLD::DisplayInfo GetCurrentDisplayInfo(); 73 void ForceClearPointerVisiableStatus(); 74 void InitPointerObserver(); 75 void OnSessionLost(int32_t pid); 76 int32_t SkipPointerLayer(bool isSkip); 77 78 void SetDelegateProxy(std::shared_ptr<DelegateInterface> proxy); 79 std::shared_ptr<DelegateInterface> GetDelegateProxy(); 80 void DestroyPointerWindow(); 81 void DrawScreenCenterPointer(const PointerStyle &pointerStyle); 82 void SubscribeScreenModeChange(); 83 void RegisterDisplayStatusReceiver(); 84 int32_t UpdateMouseLayer( 85 const PointerStyle &pointerStyle, uint64_t displayId, int32_t physicalX, int32_t physicalY); 86 int32_t DrawNewDpiPointer(); 87 bool GetHardCursorEnabled(); 88 89 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR 90 int32_t GetPointerSnapshot(void *pixelMapPtr); 91 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR 92 93 #ifndef OHOS_BUILD_ENABLE_WATCH 94 void NotifyPointerEventToRS(int32_t pointAction, int32_t pointCnt); 95 #endif // OHOS_BUILD_ENABLE_WATCH 96 private: 97 CursorDrawingComponent(); 98 ~CursorDrawingComponent(); 99 bool LoadLibrary(); 100 DISALLOW_COPY_AND_MOVE(CursorDrawingComponent); 101 using GetPointerInstanceFunc = void* (*)(); 102 GetPointerInstanceFunc getPointerInstance_; 103 104 std::mutex loadSoMutex_; 105 std::atomic<bool> exitFlag_ { false }; 106 std::atomic<bool> isLoaded_ { false }; 107 void *soHandle_ { nullptr }; 108 IPointerDrawingManager* pointerInstance_ { nullptr }; 109 int32_t timerId_ { -1 }; 110 std::chrono::time_point<std::chrono::steady_clock> lastCallTime_ { std::chrono::steady_clock::now() }; 111 }; 112 } // namespace OHOS::MMI 113 114 #endif // CURSOR_DRAWING_COMPONENT_H