• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TOUCH_DRAWING_HANDLER_H
17 #define TOUCH_DRAWING_HANDLER_H
18 
19 #include <draw/canvas.h>
20 #include <nocopyable.h>
21 #include <transaction/rs_transaction.h>
22 #include <ui/rs_canvas_node.h>
23 #include <ui/rs_surface_node.h>
24 #include <utils/rect.h>
25 
26 #ifndef USE_ROSEN_DRAWING
27 #include <pipeline/rs_recording_canvas.h>
28 #else
29 #include <recording/recording_canvas.h>
30 #include <ui/rs_canvas_drawing_node.h>
31 #endif // USE_ROSEN_DRAWING
32 
33 #include "i_touch_drawing_handler.h"
34 
35 namespace OHOS {
36 namespace MMI {
37 class TouchDrawingHandler final : public ITouchDrawingHandler {
38     struct Bubble {
39         int32_t innerCircleRadius { 0 };
40         int32_t outerCircleRadius { 0 };
41         float outerCircleWidth { 0 };
42     };
43 
44     struct DevMode {
45         std::string SwitchName;
46         bool isShow { false };
47     };
48 
49 #ifndef USE_ROSEN_DRAWING
50     using RosenCanvas = Rosen::RSRecordingCanvas;
51 #else
52     using RosenCanvas = Rosen::Drawing::RecordingCanvas;
53 #endif // USE_ROSEN_DRAWING
54 
55 public:
56     TouchDrawingHandler() = default;
57     ~TouchDrawingHandler() override;
58     DISALLOW_COPY_AND_MOVE(TouchDrawingHandler);
59 
60     void UpdateDisplayInfo(const OLD::DisplayInfo &displayInfo) override;
61     void TouchDrawHandler(std::shared_ptr<PointerEvent> pointerEvent) override;
62     void RotationScreen() override;
63     void UpdateLabels(bool isOn) override;
64     void UpdateBubbleData(bool isOn) override;
65     void SetMultiWindowScreenId(uint64_t screenId, uint64_t displayNodeScreenId) override;
66     void Dump(int32_t fd, const std::vector<std::string> &args) override;
67     bool IsWindowRotation() const override;
68     bool IsValidScaleInfo() override;
69 
70 private:
71     void AddCanvasNode(std::shared_ptr<Rosen::RSCanvasNode>& canvasNode, bool isTrackerNode,
72         bool isNeedRotate = true);
73     void RotationCanvasNode(std::shared_ptr<Rosen::RSCanvasNode> canvasNode);
74     void ResetCanvasNode(std::shared_ptr<Rosen::RSCanvasNode> canvasNode);
75     void RotationCanvas(RosenCanvas *canvas, Direction direction);
76     void CreateTouchWindow();
77     void DestoryTouchWindow();
78     void DrawBubbleHandler();
79     void DrawBubble();
80     void DrawPointerPositionHandler();
81     void DrawTracker(int32_t x, int32_t y, int32_t pointerId);
82     void DrawCrosshairs(RosenCanvas *canvas, int32_t x, int32_t y);
83     void DrawLabels();
84     void DrawRectItem(RosenCanvas* canvas, const std::string &text,
85         Rosen::Drawing::Rect &rect, const Rosen::Drawing::Color &color);
86     void UpdatePointerPosition();
87     void RecordLabelsInfo();
88     void UpdateLastPointerItem(PointerEvent::PointerItem &pointerItem);
89     void RemovePointerPosition();
90     void ClearTracker();
91     void InitLabels();
92 
93     template <class T>
94     std::string FormatNumber(T number, int32_t precision);
95 
96     bool IsValidAction(const int32_t action);
97     void Snapshot();
98     std::pair<int32_t, int32_t> CalcDrawCoordinate(
99         const OLD::DisplayInfo& displayInfo, const PointerEvent::PointerItem &pointerItem);
100     std::pair<double, double> TransformDisplayXY(const OLD::DisplayInfo &info, double logicX, double logicY) const;
101     void StartTrace(int32_t pointerId);
102     void StopTrace();
103 
104 private:
105     std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode_ { nullptr };
106     std::shared_ptr<Rosen::RSCanvasNode> bubbleCanvasNode_ { nullptr };
107     std::shared_ptr<Rosen::RSCanvasNode> trackerCanvasNode_ { nullptr };
108     std::shared_ptr<Rosen::RSCanvasNode> crosshairCanvasNode_ { nullptr };
109     std::shared_ptr<Rosen::RSCanvasNode> labelsCanvasNode_ { nullptr };
110     OLD::DisplayInfo displayInfo_ {};
111     Bubble bubble_;
112     Rosen::Drawing::Point firstPt_;
113     Rosen::Drawing::Point currentPt_;
114     Rosen::Drawing::Point lastPt_;
115     DevMode bubbleMode_;
116     DevMode pointerMode_;
117     int32_t currentDeviceId_ { -1 };
118     int32_t currentPointerId_ { 0 };
119     int32_t maxPointerCount_ { 0 };
120     int32_t currentPointerCount_ { 0 };
121     int32_t rectTopPosition_ { 0 };
122     int32_t scaleW_ { 0 };
123     int32_t scaleH_ { 0 };
124     int64_t lastActionTime_ { 0 };
125     uint64_t screenId_ { -1 };
126     double xVelocity_ { 0.0 };
127     double yVelocity_ { 0.0 };
128     double pressure_ { 0.0 };
129     double itemRectW_ { 0.0 };
130     bool hasBubbleObserver_{ false };
131     bool hasPointerObserver_{ false };
132     bool isFirstDownAction_ { false };
133     bool isDownAction_ { false };
134     bool isFirstDraw_ { true };
135     bool isChangedRotation_ { false };
136     bool isChangedMode_ { false };
137     bool stopRecord_ { false };
138     std::shared_ptr<PointerEvent> pointerEvent_ { nullptr };
139     std::list<PointerEvent::PointerItem> lastPointerItem_ { };
140     std::mutex mutex_;
141     uint64_t windowScreenId_ { 0 };
142     uint64_t displayNodeScreenId_ { 0 };
143 };
144 } // namespace MMI
145 } // namespace OHOS
146 #endif // TOUCH_DRAWING_HANDLER_H
147