• 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 <ui/rs_surface_node.h>
21 #include "../../../common/include/device_observer.h"
22 #include "i_pointer_drawing_manager.h"
23 #include "struct_multimodal.h"
24 #include "pixel_map.h"
25 #include "window.h"
26 #include "draw/canvas.h"
27 
28 namespace OHOS {
29 namespace MMI {
30 class PointerDrawingManager : public IPointerDrawingManager,
31                               public DeviceObserver,
32                               public std::enable_shared_from_this<PointerDrawingManager> {
33 public:
34     PointerDrawingManager() = default;
35     virtual ~PointerDrawingManager() = default;
36     void DrawPointer(int32_t displayId, int32_t globalX, int32_t globalY);
37     void TellDisplayInfo(int32_t displayId, int32_t width, int32_t height);
38     void UpdatePointerDevice(bool hasPointerDevice);
39     bool Init();
40 
41 public:
42     static const int32_t IMAGE_WIDTH = 64;
43     static const int32_t IMAGE_HEIGHT = 64;
44 
45 private:
46     void CreatePointerWindow(int32_t displayId, int32_t globalX, int32_t globalY);
47     sptr<OHOS::Surface> GetLayer();
48     sptr<OHOS::SurfaceBuffer> GetSurfaceBuffer(sptr<OHOS::Surface> layer);
49     void DoDraw(uint8_t *addr, uint32_t width, uint32_t height);
50     void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas);
51     void DrawManager();
52     void FixCursorPosition(int32_t &globalX, int32_t &globalY);
53     std::unique_ptr<OHOS::Media::PixelMap> DecodeImageToPixelMap(const std::string &imagePath);
54 
55 private:
56     sptr<OHOS::Rosen::Window> pointerWindow_ = nullptr;
57     bool hasDisplay_ = false;
58     int32_t displayId_ = -1;
59     int32_t displayWidth_ = 0;
60     int32_t displayHeight_ = 0;
61     bool hasPointerDevice_ = false;
62     int32_t lastGlobalX_ = -1;
63     int32_t lastGlobalY_ = -1;
64 };
65 } // namespace MMI
66 } // namespace OHOS
67 #endif // POINTER_DRAWING_MANAGER_H