• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 KNUCKLE_DRAWING_MANAGER_H
17 #define KNUCKLE_DRAWING_MANAGER_H
18 
19 #include "transaction/rs_transaction.h"
20 #include "ui/rs_canvas_drawing_node.h"
21 #include "ui/rs_surface_node.h"
22 
23 #include "pointer_event.h"
24 #include "old_display_info.h"
25 #include "setting_datashare.h"
26 
27 namespace OHOS {
28 namespace MMI {
29 using AddTimerCallbackFunc = std::function<int32_t(int, int, std::function<void()>, const std::string&)>;
30 struct PointerInfo {
31     float x { 0.0F };
32     float y { 0.0F };
33 };
34 
35 struct ScreenReadState {
36     std::string switchName;
37     std::string state;
38 };
39 
40 class KnuckleDrawingManager {
41 public:
42     void KnuckleDrawHandler(std::shared_ptr<PointerEvent> touchEvent, int32_t rsId = -1);
43     void UpdateDisplayInfo(const OLD::DisplayInfo& displayInfo);
44     KnuckleDrawingManager();
45     ~KnuckleDrawingManager();
46     void RotationCanvasNode(std::shared_ptr<Rosen::RSCanvasNode> canvasNode, const OLD::DisplayInfo& displayInfo);
47     std::string GetScreenReadState();
48     void SetMultiWindowScreenId(uint64_t screenId, uint64_t displayNodeScreenId);
49     void RegisterAddTimer(AddTimerCallbackFunc addTimerFunc);
50 private:
51     bool IsValidAction(int32_t action);
52     void CreateTouchWindow(int32_t rsId);
53     void StartTouchDraw(std::shared_ptr<PointerEvent> touchEvent);
54     int32_t DrawGraphic(std::shared_ptr<PointerEvent> touchEvent);
55     int32_t GetPointerPos(std::shared_ptr<PointerEvent> touchEvent);
56     bool IsSingleKnuckle(std::shared_ptr<PointerEvent> touchEvent);
57     bool IsSingleKnuckleDoubleClick(std::shared_ptr<PointerEvent> touchEvent);
58     int32_t DestoryWindow();
59     void CreateObserver();
60     template <class T>
61     void CreateScreenReadObserver(T& item);
62 #ifdef OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
63     void CreateBrushWorkCanvasNode();
64     void CreateTrackCanvasNode();
65     void InitParticleEmitter();
66     void UpdateEmitter();
67     void DrawTrackCanvas();
68     void DrawBrushCanvas();
69     int32_t ClearTrackCanvas();
70     int32_t ClearBrushCanvas();
71     void ActionUpAnimation();
72     uint32_t GetDeltaColor(uint32_t deltaSource, uint32_t deltaTarget);
73     uint32_t DrawTrackColorBlue(int32_t pathValue);
74     uint32_t DrawTrackColorPink(int32_t pathValue);
75     uint32_t DrawTrackColorOrangeRed(int32_t pathValue);
76     uint32_t DrawTrackColorYellow(int32_t pathValue);
77     int32_t ProcessUpEvent(bool isNeedUpAnimation);
78 #else
79     void CreateCanvasNode();
80 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
81 
82 private:
83     std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode_ { nullptr };
84 #ifdef OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
85     std::shared_ptr<Rosen::RSCanvasDrawingNode> brushCanvasNode_ { nullptr };
86     std::shared_ptr<Rosen::RSCanvasDrawingNode> trackCanvasNode_ { nullptr };
87 #else
88     std::shared_ptr<Rosen::RSCanvasDrawingNode> canvasNode_ { nullptr };
89 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
90     std::vector<PointerInfo> pointerInfos_;
91     Rosen::Drawing::Paint paint_;
92     Rosen::Drawing::Path path_;
93     OLD::DisplayInfo displayInfo_ {};
94     uint64_t screenId_ { 0 };
95     bool isActionUp_ { false };
96     bool isNeedInitParticleEmitter_ { true };
97     PointerInfo lastDownPointer_ {};
98     int64_t lastUpTime_ { 0 };
99     bool isRotate_ { false };
100     int32_t scaleW_ { 0 };
101     int32_t scaleH_ { 0 };
102     int64_t firstDownTime_ { 0 };
103     sptr<SettingObserver> screenReadObserver_ { nullptr };
104     ScreenReadState screenReadState_ { };
105     int32_t pointerNum_ { 0 };
106 #ifdef OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
107     std::vector<Rosen::Drawing::Path> pathInfos_;
108     float pathLength_ { 0.0f };
109     float brushPathLength_ { 0.0f };
110     uint32_t trackColorR_ { 0x00 };
111     uint32_t trackColorG_ { 0x00 };
112     uint32_t trackColorB_ { 0x00 };
113 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
114     AddTimerCallbackFunc addTimerFunc_;
115     int32_t destroyTimerId_ { -1 };
116 };
117 } // namespace MMI
118 } // namespace OHOS
119 #endif // KNUCKLE_DRAWING_MANAGER_H
120