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