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_surface_node.h> 23 24 #include "draw/canvas.h" 25 #include "nocopyable.h" 26 #include "pixel_map.h" 27 #include "window.h" 28 29 #include "device_observer.h" 30 #include "i_pointer_drawing_manager.h" 31 #include "mouse_event_normalize.h" 32 #include "struct_multimodal.h" 33 34 namespace OHOS { 35 namespace MMI { 36 class PointerDrawingManager : public IPointerDrawingManager, 37 public IDeviceObserver, 38 public std::enable_shared_from_this<PointerDrawingManager> { 39 public: 40 static const int32_t IMAGE_WIDTH = 64; 41 static const int32_t IMAGE_HEIGHT = 64; 42 43 public: 44 PointerDrawingManager(); 45 DISALLOW_COPY_AND_MOVE(PointerDrawingManager); 46 ~PointerDrawingManager() = default; 47 void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, 48 const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT) override; 49 void UpdateDisplayInfo(const DisplayInfo& displayInfo) override; 50 void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) override; 51 void OnWindowInfo(const WinInfo &info) override; 52 void UpdatePointerDevice(bool hasPointerDevicee, bool isPointerVisible) override; 53 bool Init() override; 54 void DeletePointerVisible(int32_t pid) override; 55 int32_t SetPointerVisible(int32_t pid, bool visible) override; 56 int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) override; 57 int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) override; 58 void DrawPointerStyle() override; 59 bool IsPointerVisible() override; 60 void SetPointerLocation(int32_t pid, int32_t x, int32_t y) override; 61 void SetMouseDisplayState(bool state) override; 62 bool GetMouseDisplayState() const override; 63 void AdjustMouseFocus(ICON_TYPE iconType, int32_t &physicalX, int32_t &physicalY); 64 65 private: 66 void CreatePointerWindow(int32_t displayId, int32_t physicalX, int32_t physicalY); 67 sptr<OHOS::Surface> GetLayer(); 68 sptr<OHOS::SurfaceBuffer> GetSurfaceBuffer(sptr<OHOS::Surface> layer) const; 69 void DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT); 70 void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& iconPath); 71 void DrawManager(); 72 void FixCursorPosition(int32_t &physicalX, int32_t &physicalY); 73 std::unique_ptr<OHOS::Media::PixelMap> DecodeImageToPixelMap(const std::string &imagePath); 74 void UpdatePointerVisible(); 75 void InitStyle(); 76 int32_t InitLayer(const MOUSE_ICON mouseStyle); 77 78 private: 79 struct PidInfo { 80 int32_t pid { 0 }; 81 bool visible { false }; 82 }; 83 sptr<OHOS::Rosen::Window> pointerWindow_ { nullptr }; 84 bool hasDisplay_ { false }; 85 DisplayInfo displayInfo_ {}; 86 bool hasPointerDevice_ { false }; 87 int32_t lastPhysicalX_ { -1 }; 88 int32_t lastPhysicalY_ { -1 }; 89 int32_t lastMouseStyle_ { -1 }; 90 int32_t pid_ { 0 }; 91 int32_t windowId_ { 0 }; 92 int32_t imageWidth_ { 0 }; 93 int32_t imageHeight_ { 0 }; 94 std::map<MOUSE_ICON, IconStyle> mouseIcons_; 95 std::list<PidInfo> pidInfos_; 96 bool mouseDisplayState_ { false }; 97 }; 98 } // namespace MMI 99 } // namespace OHOS 100 #endif // POINTER_DRAWING_MANAGER_H