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