1 /* 2 * Copyright (c) 2021-2022 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 POINTER_DRAWING_MANAGER_H 17 #define POINTER_DRAWING_MANAGER_H 18 19 #include <iostream> 20 #include <list> 21 22 #include <ui/rs_canvas_node.h> 23 #include <ui/rs_surface_node.h> 24 #include <transaction/rs_transaction.h> 25 26 #include "draw/canvas.h" 27 #include "nocopyable.h" 28 #include "pixel_map.h" 29 #include "window.h" 30 31 #include "device_observer.h" 32 #include "i_pointer_drawing_manager.h" 33 #include "mouse_event_normalize.h" 34 #include "struct_multimodal.h" 35 36 namespace OHOS { 37 namespace MMI { 38 class PointerDrawingManager final : public IPointerDrawingManager, 39 public IDeviceObserver, 40 public std::enable_shared_from_this<PointerDrawingManager> { 41 public: 42 int32_t IMAGE_WIDTH = 64; 43 int32_t IMAGE_HEIGHT = 64; 44 45 public: 46 PointerDrawingManager(); 47 DISALLOW_COPY_AND_MOVE(PointerDrawingManager); 48 ~PointerDrawingManager() override = default; 49 void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, 50 const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT) override; 51 void UpdateDisplayInfo(const DisplayInfo& displayInfo) override; 52 void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) override; 53 void OnWindowInfo(const WinInfo &info) override; 54 void UpdatePointerDevice(bool hasPointerDevice, bool isPointerVisible) override; 55 bool Init() override; 56 int32_t SetPointerColor(int32_t color) override; 57 int32_t GetPointerColor() override; 58 void DeletePointerVisible(int32_t pid) override; 59 int32_t SetPointerVisible(int32_t pid, bool visible) override; 60 int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle) override; 61 int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle) override; 62 int32_t SetPointerSize(int32_t size) override; 63 int32_t GetPointerSize() override; 64 void DrawPointerStyle() override; 65 bool IsPointerVisible() override; 66 void SetPointerLocation(int32_t pid, int32_t x, int32_t y) override; 67 void AdjustMouseFocus(ICON_TYPE iconType, int32_t &physicalX, int32_t &physicalY); 68 void SetMouseDisplayState(bool state) override; 69 bool GetMouseDisplayState() const override; 70 int32_t SetMouseIcon(int32_t windowId, void* pixelMap) override; 71 int32_t SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY) override; 72 private: 73 void DrawLoadingPointerStyle(const MOUSE_ICON mouseStyle); 74 void DrawRunningPointerAnimate(const MOUSE_ICON mouseStyle); 75 void CreatePointerWindow(int32_t displayId, int32_t physicalX, int32_t physicalY); 76 sptr<OHOS::Surface> GetLayer(); 77 sptr<OHOS::SurfaceBuffer> GetSurfaceBuffer(sptr<OHOS::Surface> layer) const; 78 void DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT); 79 void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const MOUSE_ICON mouseStyle); 80 void DrawManager(); 81 void FixCursorPosition(int32_t &physicalX, int32_t &physicalY); 82 std::shared_ptr<OHOS::Media::PixelMap> DecodeImageToPixelMap(const std::string &imagePath); 83 void UpdatePointerVisible(); 84 int32_t UpdateDefaultPointerStyle(int32_t pid, int32_t windowId, PointerStyle style); 85 void CheckMouseIconPath(); 86 void InitStyle(); 87 int32_t InitLayer(const MOUSE_ICON mouseStyle); 88 89 private: 90 struct PidInfo { 91 int32_t pid { 0 }; 92 bool visible { false }; 93 }; 94 bool hasDisplay_ { false }; 95 DisplayInfo displayInfo_ {}; 96 bool hasPointerDevice_ { false }; 97 int32_t lastPhysicalX_ { -1 }; 98 int32_t lastPhysicalY_ { -1 }; 99 PointerStyle lastMouseStyle_ {}; 100 int32_t pid_ { 0 }; 101 int32_t windowId_ { 0 }; 102 int32_t imageWidth_ { 0 }; 103 int32_t imageHeight_ { 0 }; 104 std::map<MOUSE_ICON, IconStyle> mouseIcons_; 105 std::list<PidInfo> pidInfos_; 106 bool mouseDisplayState_ { false }; 107 std::unique_ptr<OHOS::Media::PixelMap> userIcon_ { nullptr }; 108 uint64_t screenId_ { 0 }; 109 std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode_; 110 std::shared_ptr<Rosen::RSCanvasNode> canvasNode_; 111 int32_t userIconHotSpotX_ { 0 }; 112 int32_t userIconHotSpotY_ { 0 }; 113 int32_t tempPointerColor_ { -1 }; 114 }; 115 } // namespace MMI 116 } // namespace OHOS 117 #endif // POINTER_DRAWING_MANAGER_H 118