• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "drag_drawing.h"
17 
18 #include <atomic>
19 #include <cstdint>
20 #include <fstream>
21 #include <limits>
22 #include <string>
23 
24 #include <dlfcn.h>
25 
26 #include "include/core/SkTextBlob.h"
27 #include "image_source.h"
28 #include "image_type.h"
29 #include "image_utils.h"
30 #include "input_manager.h"
31 #include "parameters.h"
32 #include "pointer_event.h"
33 #include "pointer_style.h"
34 #include "render/rs_filter.h"
35 #include "string_ex.h"
36 #include "transaction/rs_interfaces.h"
37 #include "ui/rs_surface_extractor.h"
38 #include "ui/rs_surface_node.h"
39 #include "ui/rs_ui_director.h"
40 
41 #include "animation_curve.h"
42 #include "devicestatus_define.h"
43 #include "drag_data_manager.h"
44 #include "drag_hisysevent.h"
45 #include "json_parser.h"
46 #include "include/util.h"
47 
48 namespace OHOS {
49 namespace Msdp {
50 namespace DeviceStatus {
51 namespace {
52 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragDrawing" };
53 constexpr int32_t BASELINE_DENSITY { 160 };
54 constexpr int32_t DEVICE_INDEPENDENT_PIXEL { 40 };
55 constexpr int32_t DRAG_NUM_ONE { 1 };
56 constexpr int32_t STRING_PX_LENGTH { 2 };
57 constexpr int32_t EIGHT_SIZE { 8 };
58 constexpr int32_t TWELVE_SIZE { 12 };
59 constexpr int64_t START_TIME { 181154000809 };
60 constexpr int64_t INTERVAL_TIME { 16666667 };
61 constexpr int32_t SVG_WIDTH { 40 };
62 constexpr float SCALE_THRESHOLD_EIGHT { 1.0F * INT32_MAX / (SVG_WIDTH + EIGHT_SIZE) };
63 constexpr float SCALE_THRESHOLD_TWELVE { 1.0F * INT32_MAX / (SVG_WIDTH + TWELVE_SIZE) };
64 constexpr int32_t SUCCESS_ANIMATION_DURATION { 300 };
65 constexpr int32_t VIEW_BOX_POS { 2 };
66 constexpr int32_t BACKGROUND_FILTER_INDEX { 0 };
67 constexpr int32_t PIXEL_MAP_INDEX { 1 };
68 constexpr int32_t DRAG_STYLE_INDEX { 2 };
69 constexpr int32_t MOUSE_ICON_INDEX { 3 };
70 constexpr int32_t SHORT_DURATION { 55 };
71 constexpr int32_t LONG_DURATION { 90 };
72 constexpr int32_t FIRST_PIXELMAP_INDEX { 0 };
73 constexpr int32_t SECOND_PIXELMAP_INDEX { 1 };
74 constexpr size_t TOUCH_NODE_MIN_COUNT { 3 };
75 constexpr size_t MOUSE_NODE_MIN_COUNT { 4 };
76 constexpr float DEFAULT_SCALING { 1.0f };
77 constexpr float BEGIN_ALPHA { 1.0f };
78 constexpr float END_ALPHA { 0.0f };
79 constexpr float START_STYLE_ALPHA { 1.0f };
80 constexpr float END_STYLE_ALPHA { 0.0f };
81 constexpr float BEGIN_SCALE { 1.0f };
82 constexpr float END_SCALE_FAIL { 1.2f };
83 constexpr float END_SCALE_SUCCESS { 0.0f };
84 constexpr float START_STYLE_SCALE { 1.0f };
85 constexpr float STYLE_CHANGE_SCALE { 1.1f };
86 constexpr float STYLE_MAX_SCALE { 1.2f };
87 constexpr float STYLE_END_SCALE { 1.0f };
88 constexpr float DEFAULT_PIVOT { 0.0f };
89 constexpr float SVG_ORIGINAL_SIZE { 40.0f };
90 constexpr float DEFAULT_POSITION_X { 0.0f };
91 constexpr float BLUR_SIGMA_SCALE { 0.57735f };
92 constexpr float RADIUS_VP { 23.0f };
93 constexpr float DEFAULT_SATURATION { 1.05f };
94 constexpr float DEFAULT_BRIGHTNESS { 1.05f };
95 constexpr float INCREASE_RATIO { 1.22f };
96 constexpr float DRAG_WINDOW_POSITION_Z { 6999.0f };
97 constexpr float DEFAULT_ANGLE { 0.0f };
98 constexpr float POSITIVE_ANGLE { 8.0f };
99 constexpr float NEGATIVE_ANGLE { -8.0f };
100 constexpr float DEFAULT_ALPHA { 1.0f };
101 constexpr float FIRST_PIXELMAP_ALPHA { 0.6f };
102 constexpr float SECOND_PIXELMAP_ALPHA { 0.3f };
103 constexpr float HALF_RATIO { 0.5f };
104 constexpr float ROTATION_DEFAULT { 0.0f };
105 constexpr float ROTATION_FIRST_ORDER { -90.0f };
106 constexpr float ROTATION_SECOND_ORDER { -180.0f };
107 constexpr float ROTATION_THIRD_ORDER { -270.0f };
108 constexpr uint32_t TRANSPARENT_COLOR_ARGB { 0x00000000 };
109 constexpr int32_t DEFAULT_MOUSE_SIZE { 1 };
110 constexpr int32_t DEFAULT_COLOR_VALUE { 0 };
111 constexpr int32_t INVALID_COLOR_VALUE { -1 };
112 constexpr int32_t GLOBAL_WINDOW_ID { -1 };
113 constexpr int32_t MOUSE_DRAG_CURSOR_CIRCLE_STYLE { 41 };
114 constexpr int32_t CURSOR_CIRCLE_MIDDLE { 2 };
115 constexpr int32_t TWICE_SIZE { 2 };
116 constexpr size_t EXTRA_INFO_MAX_SIZE { 200 };
117 constexpr int32_t HEX_FF { 0xFF };
118 const Rosen::RSAnimationTimingCurve SPRING = Rosen::RSAnimationTimingCurve::CreateSpring(0.347f, 0.99f, 0.0f);
119 const std::string DEVICE_TYPE_DEFAULT { "default" };
120 const std::string DEVICE_TYPE_PHONE { "phone" };
121 constexpr float BEZIER_000 { 0.00f };
122 constexpr float BEZIER_020 { 0.20f };
123 constexpr float BEZIER_030 { 0.30f };
124 constexpr float BEZIER_033 { 0.33f };
125 constexpr float BEZIER_040 { 0.40f };
126 constexpr float BEZIER_060 { 0.60f };
127 constexpr float BEZIER_067 { 0.67f };
128 constexpr float BEZIER_100 { 1.00f };
129 constexpr int32_t TIME_DRAG_CHANGE_STYLE { 50 };
130 constexpr int32_t TIME_DRAG_STYLE { 100 };
131 constexpr int32_t TIME_STOP_FAIL_WINDOW { 125 };
132 constexpr int32_t TIME_STOP_SUCCESS_WINDOW { 250 };
133 constexpr int32_t TIME_STOP_SUCCESS_STYLE { 150 };
134 constexpr int32_t TIME_STOP { 0 };
135 constexpr int64_t TIME_SLEEP { 30000 };
136 constexpr int32_t INTERRUPT_SCALE { 15 };
137 const std::string THREAD_NAME { "os_AnimationEventRunner" };
138 const std::string COPY_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy_Drag.svg" };
139 const std::string COPY_ONE_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy_One_Drag.svg" };
140 const std::string FORBID_DRAG_PATH { "/system/etc/device_status/drag_icon/Forbid_Drag.svg" };
141 const std::string FORBID_ONE_DRAG_PATH { "/system/etc/device_status/drag_icon/Forbid_One_Drag.svg" };
142 const std::string MOUSE_DRAG_DEFAULT_PATH { "/system/etc/device_status/drag_icon/Mouse_Drag_Default.svg" };
143 const std::string MOUSE_DRAG_CURSOR_CIRCLE_PATH { "/system/etc/device_status/drag_icon/Mouse_Drag_Cursor_Circle.png" };
144 const std::string MOVE_DRAG_PATH { "/system/etc/device_status/drag_icon/Move_Drag.svg" };
145 #ifdef __aarch64__
146 const std::string DRAG_ANIMATION_EXTENSION_SO_PATH { "/system/lib64/drag_drop_ext/libdrag_drop_ext.z.so" };
147 #else
148 const std::string DRAG_ANIMATION_EXTENSION_SO_PATH { "/system/lib/drag_drop_ext/libdrag_drop_ext.z.so" };
149 #endif
150 const std::string BIG_FOLDER_LABEL { "scb_folder" };
151 struct DrawingInfo g_drawingInfo;
152 
CheckNodesValid()153 bool CheckNodesValid()
154 {
155     CALL_DEBUG_ENTER;
156     if (g_drawingInfo.nodes.empty() || g_drawingInfo.nodes[DRAG_STYLE_INDEX] == nullptr) {
157         FI_HILOGE("Nodes invalid");
158         return false;
159     }
160     if ((g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
161         (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT)) {
162         FI_HILOGE("Nodes size invalid when mouse type, node size:%{public}zu", g_drawingInfo.nodes.size());
163         return false;
164     }
165     if ((g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) &&
166         (g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) {
167         FI_HILOGE("Nodes size invalid when touchscreen type, node size:%{public}zu", g_drawingInfo.nodes.size());
168         return false;
169     }
170     return true;
171 }
172 
GetScaling()173 float GetScaling()
174 {
175     if (g_drawingInfo.isExistScalingValue) {
176         return g_drawingInfo.scalingValue;
177     }
178     sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId);
179     if (display == nullptr) {
180         FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId);
181         display = Rosen::DisplayManager::GetInstance().GetDisplayById(0);
182         if (display == nullptr) {
183             FI_HILOGE("Get display info failed, display is nullptr");
184             return DEFAULT_SCALING;
185         }
186     }
187 
188     int32_t deviceDpi = display->GetDpi();
189     FI_HILOGD("displayId:%{public}d, deviceDpi:%{public}d", g_drawingInfo.displayId, deviceDpi);
190     if (deviceDpi < -std::numeric_limits<float>::epsilon()) {
191         FI_HILOGE("Invalid deviceDpi:%{public}d", deviceDpi);
192         return DEFAULT_SCALING;
193     }
194     g_drawingInfo.scalingValue = (1.0 * deviceDpi * DEVICE_INDEPENDENT_PIXEL / BASELINE_DENSITY) / SVG_ORIGINAL_SIZE;
195     g_drawingInfo.isExistScalingValue = true;
196     return g_drawingInfo.scalingValue;
197 }
198 } // namespace
199 
Init(const DragData & dragData)200 int32_t DragDrawing::Init(const DragData &dragData)
201 {
202     CALL_DEBUG_ENTER;
203     int32_t checkDragDataResult = CheckDragData(dragData);
204     if (INIT_SUCCESS != checkDragDataResult) {
205         return checkDragDataResult;
206     }
207     InitDrawingInfo(dragData);
208     CreateWindow();
209     CHKPR(g_drawingInfo.surfaceNode, INIT_FAIL);
210     if (InitLayer() != RET_OK) {
211         FI_HILOGE("Init layer failed");
212         return INIT_FAIL;
213     }
214     DragAnimationData dragAnimationData;
215     if (InitDragAnimationData(dragAnimationData) != RET_OK) {
216         FI_HILOGE("Init drag animation data failed");
217         return INIT_FAIL;
218     }
219     if (!CheckNodesValid()) {
220         FI_HILOGE("Check nodes valid failed");
221         return INIT_FAIL;
222     }
223     std::shared_ptr<Rosen::RSCanvasNode> shadowNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX];
224     CHKPR(shadowNode, INIT_FAIL);
225     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
226     CHKPR(dragStyleNode, INIT_FAIL);
227     OnStartDrag(dragAnimationData, shadowNode, dragStyleNode);
228     if (!g_drawingInfo.multiSelectedNodes.empty()) {
229         g_drawingInfo.isCurrentDefaultStyle = true;
230         UpdateDragStyle(DragCursorStyle::MOVE);
231     }
232     CHKPR(rsUiDirector_, INIT_FAIL);
233     if (g_drawingInfo.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
234         rsUiDirector_->SendMessages();
235         return INIT_SUCCESS;
236     }
237     if (DrawMouseIcon() != RET_OK) {
238         FI_HILOGE("Draw mouse icon failed");
239         return INIT_FAIL;
240     }
241     rsUiDirector_->SendMessages();
242     return INIT_SUCCESS;
243 }
244 
CheckDragData(const DragData & dragData)245 int32_t DragDrawing::CheckDragData(const DragData &dragData)
246 {
247     if (g_drawingInfo.isRunning) {
248         FI_HILOGE("Drag drawing is running, can not init again");
249         return INIT_CANCEL;
250     }
251     if (dragData.shadowInfos.empty()) {
252         FI_HILOGE("ShadowInfos is empty");
253         return INIT_FAIL;
254     }
255     CHKPR(dragData.shadowInfos.front().pixelMap, INIT_FAIL);
256     if ((dragData.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
257         (dragData.sourceType != MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN)) {
258         FI_HILOGE("Invalid sourceType:%{public}d", dragData.sourceType);
259         return INIT_FAIL;
260     }
261     if (dragData.dragNum < 0) {
262         FI_HILOGE("Invalid dragNum:%{public}d", dragData.dragNum);
263         return INIT_FAIL;
264     }
265     return INIT_SUCCESS;
266 }
267 
Draw(int32_t displayId,int32_t displayX,int32_t displayY,bool isNeedAdjustDisplayXY)268 void DragDrawing::Draw(int32_t displayId, int32_t displayX, int32_t displayY, bool isNeedAdjustDisplayXY)
269 {
270     if (displayId < 0) {
271         FI_HILOGE("Invalid displayId:%{public}d", displayId);
272         return;
273     }
274     if (isNeedAdjustDisplayXY) {
275         RotateDisplayXY(displayX, displayY);
276     }
277     g_drawingInfo.displayId = displayId;
278     g_drawingInfo.displayX = displayX;
279     g_drawingInfo.displayY = displayY;
280     if (displayX < 0) {
281         g_drawingInfo.displayX = 0;
282     }
283     if (displayY < 0) {
284         g_drawingInfo.displayY = 0;
285     }
286     int32_t adjustSize = TWELVE_SIZE * GetScaling();
287     int32_t positionX = g_drawingInfo.displayX + g_drawingInfo.pixelMapX;
288     int32_t positionY = g_drawingInfo.displayY + g_drawingInfo.pixelMapY - adjustSize;
289     CHKPV(g_drawingInfo.parentNode);
290     CHKPV(g_drawingInfo.pixelMap);
291     g_drawingInfo.parentNode->SetBounds(positionX, positionY, g_drawingInfo.pixelMap->GetWidth(),
292         g_drawingInfo.pixelMap->GetHeight());
293     g_drawingInfo.parentNode->SetFrame(positionX, positionY, g_drawingInfo.pixelMap->GetWidth(),
294         g_drawingInfo.pixelMap->GetHeight());
295     if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
296         DoDrawMouse();
297     }
298     if (!g_drawingInfo.multiSelectedNodes.empty() && !g_drawingInfo.multiSelectedPixelMaps.empty()) {
299         MultiSelectedAnimation(positionX, positionY, adjustSize);
300     }
301     Rosen::RSTransaction::FlushImplicitTransaction();
302 }
303 
UpdateDragStyle(DragCursorStyle style)304 int32_t DragDrawing::UpdateDragStyle(DragCursorStyle style)
305 {
306     FI_HILOGD("style:%{public}d", style);
307     if ((style < DragCursorStyle::DEFAULT) || (style > DragCursorStyle::MOVE)) {
308         DragDFX::WriteUpdateDragStyle(style, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
309         FI_HILOGE("Invalid style:%{public}d", style);
310         return RET_ERR;
311     }
312     if ((style == DragCursorStyle::DEFAULT) ||
313         ((style == DragCursorStyle::MOVE) && (g_drawingInfo.currentDragNum == DRAG_NUM_ONE))) {
314         return UpdateDefaultDragStyle(style);
315     }
316     return UpdateValidDragStyle(style);
317 }
318 
UpdateShadowPic(const ShadowInfo & shadowInfo)319 int32_t DragDrawing::UpdateShadowPic(const ShadowInfo &shadowInfo)
320 {
321     CALL_DEBUG_ENTER;
322     CHKPR(shadowInfo.pixelMap, RET_ERR);
323     g_drawingInfo.pixelMap = shadowInfo.pixelMap;
324     g_drawingInfo.pixelMapX = shadowInfo.x;
325     g_drawingInfo.pixelMapY = shadowInfo.y;
326     g_drawingInfo.lastPixelMapX = g_drawingInfo.pixelMapX;
327     g_drawingInfo.lastPixelMapY = g_drawingInfo.pixelMapY;
328     if (!CheckNodesValid()) {
329         FI_HILOGE("Check nodes valid failed");
330         return RET_ERR;
331     }
332     std::shared_ptr<Rosen::RSCanvasNode> shadowNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX];
333     CHKPR(shadowNode, RET_ERR);
334     DrawShadow(shadowNode);
335     float scalingValue = GetScaling();
336     if (SCALE_THRESHOLD_TWELVE < scalingValue || fabsf(SCALE_THRESHOLD_TWELVE - scalingValue) < EPSILON) {
337         FI_HILOGE("Invalid scalingValue:%{public}f", scalingValue);
338         return RET_ERR;
339     }
340     if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
341         DrawMouseIcon();
342     }
343     ProcessFilter();
344     Draw(g_drawingInfo.displayId, g_drawingInfo.displayX, g_drawingInfo.displayY, false);
345     RotateDragWindow(rotation_);
346     Rosen::RSTransaction::FlushImplicitTransaction();
347     CHKPR(rsUiDirector_, RET_ERR);
348     rsUiDirector_->SendMessages();
349     return RET_OK;
350 }
351 
OnDragSuccess()352 void DragDrawing::OnDragSuccess()
353 {
354     CALL_INFO_TRACE;
355     if (!CheckNodesValid()) {
356         FI_HILOGE("Check nodes valid failed");
357         return;
358     }
359     std::shared_ptr<Rosen::RSCanvasNode> shadowNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX];
360     CHKPV(shadowNode);
361     std::shared_ptr<Rosen::RSCanvasNode> styleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
362     CHKPV(styleNode);
363     OnStopDragSuccess(shadowNode, styleNode);
364 }
365 
OnDragFail()366 void DragDrawing::OnDragFail()
367 {
368     CALL_INFO_TRACE;
369     std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode = g_drawingInfo.surfaceNode;
370     CHKPV(surfaceNode);
371     std::shared_ptr<Rosen::RSNode> rootNode = g_drawingInfo.rootNode;
372     CHKPV(rootNode);
373     OnStopDragFail(surfaceNode, rootNode);
374 }
375 
EraseMouseIcon()376 void DragDrawing::EraseMouseIcon()
377 {
378     CALL_INFO_TRACE;
379     if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) {
380         FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size());
381         return;
382     }
383     std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX];
384     CHKPV(mouseIconNode);
385     if (drawMouseIconModifier_ != nullptr) {
386         mouseIconNode->RemoveModifier(drawMouseIconModifier_);
387         drawMouseIconModifier_ = nullptr;
388     }
389     CHKPV(g_drawingInfo.rootNode);
390     g_drawingInfo.rootNode->RemoveChild(mouseIconNode);
391     CHKPV(rsUiDirector_);
392     rsUiDirector_->SendMessages();
393 }
394 
DestroyDragWindow()395 void DragDrawing::DestroyDragWindow()
396 {
397     CALL_DEBUG_ENTER;
398     ResetParameter();
399     RemoveModifier();
400     ClearMultiSelectedData();
401     if (!g_drawingInfo.nodes.empty()) {
402         g_drawingInfo.nodes.clear();
403         g_drawingInfo.nodes.shrink_to_fit();
404     }
405     if (g_drawingInfo.parentNode != nullptr) {
406         g_drawingInfo.parentNode->ClearChildren();
407         g_drawingInfo.parentNode.reset();
408         g_drawingInfo.parentNode = nullptr;
409     }
410     if (g_drawingInfo.rootNode != nullptr) {
411         g_drawingInfo.rootNode->ClearChildren();
412         g_drawingInfo.rootNode.reset();
413         g_drawingInfo.rootNode = nullptr;
414     }
415     if (g_drawingInfo.surfaceNode != nullptr) {
416         g_drawingInfo.surfaceNode->DetachToDisplay(screenId_);
417         screenId_ = 0;
418         g_drawingInfo.displayId = -1;
419         g_drawingInfo.surfaceNode = nullptr;
420         Rosen::RSTransaction::FlushImplicitTransaction();
421     }
422     CHKPV(rsUiDirector_);
423     rsUiDirector_->SetRoot(-1);
424     rsUiDirector_->SendMessages();
425 }
426 
UpdateDrawingState()427 void DragDrawing::UpdateDrawingState()
428 {
429     CALL_DEBUG_ENTER;
430     g_drawingInfo.isRunning = false;
431 }
432 
UpdateDragWindowState(bool visible)433 void DragDrawing::UpdateDragWindowState(bool visible)
434 {
435     CHKPV(g_drawingInfo.surfaceNode);
436     if (visible) {
437         g_drawingInfo.surfaceNode->SetVisible(true);
438         FI_HILOGI("Drag surfaceNode show success");
439     } else {
440         g_drawingInfo.surfaceNode->SetVisible(false);
441         FI_HILOGI("Drag surfaceNode hide success");
442     }
443     Rosen::RSTransaction::FlushImplicitTransaction();
444 }
445 
OnStartStyleAnimation()446 void DragDrawing::OnStartStyleAnimation()
447 {
448     CALL_DEBUG_ENTER;
449     hasRunningStopAnimation_ = false;
450 }
451 
OnStartDrag(const DragAnimationData & dragAnimationData,std::shared_ptr<Rosen::RSCanvasNode> shadowNode,std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode)452 void DragDrawing::OnStartDrag(const DragAnimationData &dragAnimationData,
453     std::shared_ptr<Rosen::RSCanvasNode> shadowNode, std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode)
454 {
455     CALL_DEBUG_ENTER;
456     CHKPV(shadowNode);
457     if (DrawShadow(shadowNode) != RET_OK) {
458         FI_HILOGE("Draw shadow failed");
459         return;
460     }
461     g_drawingInfo.isCurrentDefaultStyle = true;
462 #ifdef OHOS_DRAG_ENABLE_ANIMATION
463     if (handler_ == nullptr) {
464         auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
465         CHKPV(runner);
466         handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
467     }
468     if (!handler_->PostTask(std::bind(&DragDrawing::OnStartStyleAnimation, this))) {
469         FI_HILOGE("Start style animation failed");
470     }
471 #endif // OHOS_DRAG_ENABLE_ANIMATION
472 }
473 
CheckStyleNodeModifier(std::shared_ptr<Rosen::RSCanvasNode> styleNode)474 void DragDrawing::CheckStyleNodeModifier(std::shared_ptr<Rosen::RSCanvasNode> styleNode)
475 {
476     CALL_DEBUG_ENTER;
477     CHKPV(styleNode);
478     if (drawStyleChangeModifier_ != nullptr) {
479         styleNode->RemoveModifier(drawStyleChangeModifier_);
480         drawStyleChangeModifier_ = nullptr;
481     }
482     if (drawStyleScaleModifier_ != nullptr && hasRunningScaleAnimation_) {
483         needBreakStyleScaleAnimation_ = true;
484     }
485     styleNode->RemoveAllAnimations();
486 }
487 
RemoveStyleNodeModifier(std::shared_ptr<Rosen::RSCanvasNode> styleNode)488 void DragDrawing::RemoveStyleNodeModifier(std::shared_ptr<Rosen::RSCanvasNode> styleNode)
489 {
490     CALL_DEBUG_ENTER;
491     CHKPV(styleNode);
492     if (drawStyleChangeModifier_ != nullptr) {
493         styleNode->RemoveModifier(drawStyleChangeModifier_);
494         drawStyleChangeModifier_ = nullptr;
495     }
496     if (drawStyleScaleModifier_ != nullptr) {
497         styleNode->RemoveModifier(drawStyleScaleModifier_);
498         drawStyleScaleModifier_ = nullptr;
499     }
500 }
501 
UpdateAnimationProtocol(Rosen::RSAnimationTimingProtocol protocol)502 void DragDrawing::UpdateAnimationProtocol(Rosen::RSAnimationTimingProtocol protocol)
503 {
504     CALL_DEBUG_ENTER;
505     startNum_ = START_TIME;
506     interruptNum_ = START_TIME * INTERRUPT_SCALE;
507     hasRunningAnimation_ = true;
508     bool stopSignal = true;
509     CHKPV(rsUiDirector_);
510     while (hasRunningAnimation_) {
511         hasRunningAnimation_ = rsUiDirector_->FlushAnimation(startNum_);
512         rsUiDirector_->FlushModifier();
513         rsUiDirector_->SendMessages();
514         if ((startNum_ >= interruptNum_) && stopSignal) {
515             protocol.SetDuration(TIME_STOP);
516             stopSignal = false;
517         }
518         startNum_ += INTERVAL_TIME;
519         usleep(TIME_SLEEP);
520     }
521 }
522 
StartStyleAnimation(float startScale,float endScale,int32_t duration)523 void DragDrawing::StartStyleAnimation(float startScale, float endScale, int32_t duration)
524 {
525     FI_HILOGI("StartStyleAnimation, startScale is %{public}lf", startScale);
526     if (!CheckNodesValid() || needBreakStyleScaleAnimation_ || hasRunningStopAnimation_) {
527         FI_HILOGE("needBreakStyleScaleAnimation_ or hasRunningStopAnimation_, return");
528         return;
529     }
530     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
531     CHKPV(dragStyleNode);
532     RemoveStyleNodeModifier(dragStyleNode);
533     drawStyleScaleModifier_ = std::make_shared<DrawStyleScaleModifier>();
534     dragStyleNode->AddModifier(drawStyleScaleModifier_);
535     CHKPV(drawStyleScaleModifier_);
536     drawStyleScaleModifier_->SetScale(startScale);
537     Rosen::RSAnimationTimingProtocol protocol;
538     protocol.SetDuration(duration);
539     auto springCurveStyle = endScale == STYLE_END_SCALE
540         ? Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_030, BEZIER_000, BEZIER_040, BEZIER_100)
541         : Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_020, BEZIER_000, BEZIER_060, BEZIER_100);
542     CHKPV(drawStyleScaleModifier_);
543     Rosen::RSNode::Animate(protocol, springCurveStyle, [&]() {
544         drawStyleScaleModifier_->SetScale(endScale);
545     });
546     UpdateAnimationProtocol(protocol);
547     if (endScale == STYLE_CHANGE_SCALE) {
548         if (drawStyleChangeModifier_ != nullptr) {
549             dragStyleNode->RemoveModifier(drawStyleChangeModifier_);
550             drawStyleChangeModifier_ = nullptr;
551         }
552         if (drawStyleScaleModifier_ != nullptr) {
553             dragStyleNode->RemoveModifier(drawStyleScaleModifier_);
554             drawStyleScaleModifier_ = nullptr;
555         }
556         drawStyleChangeModifier_ = std::make_shared<DrawStyleChangeModifier>(g_drawingInfo.stylePixelMap);
557         dragStyleNode->AddModifier(drawStyleChangeModifier_);
558     }
559     if (endScale == STYLE_END_SCALE && drawStyleScaleModifier_ != nullptr) {
560         dragStyleNode->RemoveModifier(drawStyleScaleModifier_);
561         drawStyleScaleModifier_ = nullptr;
562     }
563 }
564 
ChangeStyleAnimation()565 void DragDrawing::ChangeStyleAnimation()
566 {
567     CALL_DEBUG_ENTER;
568     hasRunningScaleAnimation_ = true;
569     StartStyleAnimation(START_STYLE_SCALE, STYLE_CHANGE_SCALE, TIME_DRAG_CHANGE_STYLE);
570     StartStyleAnimation(STYLE_CHANGE_SCALE, STYLE_MAX_SCALE, TIME_DRAG_CHANGE_STYLE);
571     StartStyleAnimation(STYLE_MAX_SCALE, STYLE_END_SCALE, TIME_DRAG_STYLE);
572     needBreakStyleScaleAnimation_ = false;
573     hasRunningScaleAnimation_ = false;
574 }
575 
OnDragStyleAnimation()576 void DragDrawing::OnDragStyleAnimation()
577 {
578     CALL_DEBUG_ENTER;
579     if (!CheckNodesValid()) {
580         FI_HILOGE("Check nodes valid failed");
581         return;
582     }
583     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
584     CHKPV(dragStyleNode);
585     needBreakStyleScaleAnimation_ = false;
586     if (g_drawingInfo.isPreviousDefaultStyle == true || g_drawingInfo.isCurrentDefaultStyle == true) {
587         FI_HILOGE("Has DefaultStyle, change style and return");
588         CheckStyleNodeModifier(dragStyleNode);
589         drawStyleChangeModifier_ = std::make_shared<DrawStyleChangeModifier>(g_drawingInfo.stylePixelMap);
590         dragStyleNode->AddModifier(drawStyleChangeModifier_);
591         return;
592     }
593     rsUiDirector_ = Rosen::RSUIDirector::Create();
594     CHKPV(rsUiDirector_);
595     rsUiDirector_->Init();
596     rsUiDirector_->SetRSSurfaceNode(g_drawingInfo.surfaceNode);
597     if (handler_ == nullptr) {
598         auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
599         handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
600     }
601     CheckStyleNodeModifier(dragStyleNode);
602     handler_->PostTask(std::bind(&DragDrawing::ChangeStyleAnimation, this));
603 }
604 
OnDragStyle(std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode,std::shared_ptr<Media::PixelMap> stylePixelMap)605 void DragDrawing::OnDragStyle(std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode,
606     std::shared_ptr<Media::PixelMap> stylePixelMap)
607 {
608     CALL_DEBUG_ENTER;
609     CHKPV(dragStyleNode);
610     CHKPV(stylePixelMap);
611 #ifdef OHOS_DRAG_ENABLE_ANIMATION
612     if (handler_ == nullptr) {
613         auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
614         CHKPV(runner);
615         handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
616     }
617     if (drawSVGModifier_ != nullptr) {
618         dragStyleNode->RemoveModifier(drawSVGModifier_);
619         drawSVGModifier_ = nullptr;
620     }
621     if (!handler_->PostTask(std::bind(&DragDrawing::OnDragStyleAnimation, this))) {
622         FI_HILOGE("Drag style animation failed");
623         DrawStyle(dragStyleNode, stylePixelMap);
624     }
625 #else // OHOS_DRAG_ENABLE_ANIMATION
626     DrawStyle(dragStyleNode, stylePixelMap);
627 #endif // OHOS_DRAG_ENABLE_ANIMATION
628 }
629 
OnStopAnimationSuccess()630 void DragDrawing::OnStopAnimationSuccess()
631 {
632     CALL_DEBUG_ENTER;
633     if (!CheckNodesValid()) {
634         FI_HILOGE("Check nodes valid failed");
635         return;
636     }
637     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
638     if (dragStyleNode != nullptr && drawStyleScaleModifier_ != nullptr) {
639         dragStyleNode->RemoveModifier(drawStyleScaleModifier_);
640         dragStyleNode->RemoveAllAnimations();
641         drawStyleScaleModifier_ = nullptr;
642         needBreakStyleScaleAnimation_ = true;
643     }
644     CHKPV(g_drawingInfo.rootNode);
645     hasRunningStopAnimation_ = true;
646     if (drawDragStopModifier_ != nullptr) {
647         g_drawingInfo.rootNode->RemoveModifier(drawDragStopModifier_);
648         drawDragStopModifier_ = nullptr;
649     }
650     drawDragStopModifier_ = std::make_shared<DrawDragStopModifier>();
651     g_drawingInfo.rootNode->AddModifier(drawDragStopModifier_);
652     drawDragStopModifier_->SetAlpha(BEGIN_ALPHA);
653     drawDragStopModifier_->SetScale(BEGIN_SCALE);
654     drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE);
655     drawDragStopModifier_->SetStyleAlpha(START_STYLE_ALPHA);
656     Rosen::RSAnimationTimingProtocol windowProtocol;
657     Rosen::RSAnimationTimingProtocol styleProtocol;
658     windowProtocol.SetDuration(TIME_STOP_SUCCESS_WINDOW);
659     styleProtocol.SetDuration(TIME_STOP_SUCCESS_STYLE);
660     auto springCurveSuccessWindow = Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_040, BEZIER_000,
661         BEZIER_100, BEZIER_100);
662     auto springCurveSuccessStyle = Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_000, BEZIER_000,
663         BEZIER_100, BEZIER_100);
664     Rosen::RSNode::Animate(windowProtocol, springCurveSuccessWindow, [&]() {
665         drawDragStopModifier_->SetAlpha(BEGIN_ALPHA);
666         drawDragStopModifier_->SetScale(END_SCALE_SUCCESS);
667         Rosen::RSNode::Animate(styleProtocol, springCurveSuccessStyle, [&]() {
668             drawDragStopModifier_->SetStyleAlpha(END_STYLE_ALPHA);
669             drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE);
670         });
671     });
672 }
673 
OnStopDragSuccess(std::shared_ptr<Rosen::RSCanvasNode> shadowNode,std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode)674 void DragDrawing::OnStopDragSuccess(std::shared_ptr<Rosen::RSCanvasNode> shadowNode,
675     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode)
676 {
677     CALL_DEBUG_ENTER;
678     auto animateCb = std::bind(&DragDrawing::InitVSync, this, END_ALPHA, END_SCALE_SUCCESS);
679 #ifdef OHOS_DRAG_ENABLE_ANIMATION
680     if (handler_ == nullptr) {
681         auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
682         CHKPV(runner);
683         handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
684     }
685     if (!handler_->PostTask(std::bind(&DragDrawing::OnStopAnimationSuccess, this))) {
686         FI_HILOGE("Failed to stop style animation");
687         RunAnimation(animateCb);
688     } else {
689         startNum_ = START_TIME;
690         needDestroyDragWindow_ = true;
691         StartVsync();
692     }
693 #else // OHOS_DRAG_ENABLE_ANIMATION
694     RunAnimation(animateCb);
695 #endif // OHOS_DRAG_ENABLE_ANIMATION
696 }
697 
OnStopAnimationFail()698 void DragDrawing::OnStopAnimationFail()
699 {
700     CALL_DEBUG_ENTER;
701     if (!CheckNodesValid()) {
702         FI_HILOGE("Check nodes valid failed");
703         return;
704     }
705     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
706     if (dragStyleNode != nullptr && drawStyleScaleModifier_ != nullptr) {
707         dragStyleNode->RemoveModifier(drawStyleScaleModifier_);
708         dragStyleNode->RemoveAllAnimations();
709         drawStyleScaleModifier_ = nullptr;
710         needBreakStyleScaleAnimation_ = true;
711     }
712     CHKPV(g_drawingInfo.rootNode);
713     if (drawDragStopModifier_ != nullptr) {
714         g_drawingInfo.rootNode->RemoveModifier(drawDragStopModifier_);
715         drawDragStopModifier_ = nullptr;
716     }
717     drawDragStopModifier_ = std::make_shared<DrawDragStopModifier>();
718     hasRunningStopAnimation_ = true;
719     g_drawingInfo.rootNode->AddModifier(drawDragStopModifier_);
720     drawDragStopModifier_->SetAlpha(BEGIN_ALPHA);
721     drawDragStopModifier_->SetScale(BEGIN_SCALE);
722     drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE);
723     drawDragStopModifier_->SetStyleAlpha(START_STYLE_ALPHA);
724     Rosen::RSAnimationTimingProtocol protocol;
725     protocol.SetDuration(TIME_STOP_FAIL_WINDOW);
726     auto springCurveFail = Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_033, BEZIER_000,
727         BEZIER_067, BEZIER_100);
728     Rosen::RSNode::Animate(protocol, springCurveFail, [&]() {
729         drawDragStopModifier_->SetAlpha(END_ALPHA);
730         drawDragStopModifier_->SetScale(END_SCALE_FAIL);
731         drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE);
732         drawDragStopModifier_->SetStyleAlpha(END_STYLE_ALPHA);
733     });
734 }
735 
OnStopDragFail(std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode,std::shared_ptr<Rosen::RSNode> rootNode)736 void DragDrawing::OnStopDragFail(std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode,
737     std::shared_ptr<Rosen::RSNode> rootNode)
738 {
739     CALL_DEBUG_ENTER;
740     auto animateCb = std::bind(&DragDrawing::InitVSync, this, END_ALPHA, END_SCALE_FAIL);
741 #ifdef OHOS_DRAG_ENABLE_ANIMATION
742     if (handler_ == nullptr) {
743         auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
744         CHKPV(runner);
745         handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
746     }
747     if (!handler_->PostTask(std::bind(&DragDrawing::OnStopAnimationFail, this))) {
748         FI_HILOGE("Failed to stop style animation");
749         RunAnimation(animateCb);
750     } else {
751         startNum_ = START_TIME;
752         needDestroyDragWindow_ = true;
753         StartVsync();
754     }
755 #else // OHOS_DRAG_ENABLE_ANIMATION
756     RunAnimation(animateCb);
757 #endif // OHOS_DRAG_ENABLE_ANIMATION
758 }
759 
OnStopAnimation()760 void DragDrawing::OnStopAnimation()
761 {
762     CALL_DEBUG_ENTER;
763 }
764 
RunAnimation(std::function<int32_t ()> cb)765 int32_t DragDrawing::RunAnimation(std::function<int32_t()> cb)
766 {
767     CALL_DEBUG_ENTER;
768     if (handler_ == nullptr) {
769         auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
770         CHKPR(runner, RET_ERR);
771         handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
772     }
773     if (!handler_->PostTask(cb)) {
774         FI_HILOGE("Send vsync event failed");
775         return RET_ERR;
776     }
777     return RET_OK;
778 }
779 
DrawShadow(std::shared_ptr<Rosen::RSCanvasNode> shadowNode)780 int32_t DragDrawing::DrawShadow(std::shared_ptr<Rosen::RSCanvasNode> shadowNode)
781 {
782     CALL_DEBUG_ENTER;
783     CHKPR(shadowNode, RET_ERR);
784     if (drawPixelMapModifier_ != nullptr) {
785         shadowNode->RemoveModifier(drawPixelMapModifier_);
786         drawPixelMapModifier_ = nullptr;
787     }
788     drawPixelMapModifier_ = std::make_shared<DrawPixelMapModifier>();
789     shadowNode->AddModifier(drawPixelMapModifier_);
790     return RET_OK;
791 }
792 
DrawMouseIcon()793 int32_t DragDrawing::DrawMouseIcon()
794 {
795     CALL_DEBUG_ENTER;
796     if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) {
797         FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size());
798         return RET_ERR;
799     }
800     std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX];
801     CHKPR(mouseIconNode, RET_ERR);
802     if (drawMouseIconModifier_ != nullptr) {
803         mouseIconNode->RemoveModifier(drawMouseIconModifier_);
804         drawMouseIconModifier_ = nullptr;
805     }
806     drawMouseIconModifier_ = std::make_shared<DrawMouseIconModifier>();
807     mouseIconNode->AddModifier(drawMouseIconModifier_);
808     return RET_OK;
809 }
810 
DrawStyle(std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode,std::shared_ptr<Media::PixelMap> stylePixelMap)811 int32_t DragDrawing::DrawStyle(std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode,
812     std::shared_ptr<Media::PixelMap> stylePixelMap)
813 {
814     CALL_DEBUG_ENTER;
815     CHKPR(dragStyleNode, RET_ERR);
816     CHKPR(stylePixelMap, RET_ERR);
817     if (drawSVGModifier_ != nullptr) {
818         dragStyleNode->RemoveModifier(drawSVGModifier_);
819         drawSVGModifier_ = nullptr;
820     }
821     drawSVGModifier_ = std::make_shared<DrawSVGModifier>(stylePixelMap);
822     dragStyleNode->AddModifier(drawSVGModifier_);
823     return RET_OK;
824 }
825 
InitVSync(float endAlpha,float endScale)826 int32_t DragDrawing::InitVSync(float endAlpha, float endScale)
827 {
828     CALL_DEBUG_ENTER;
829     CHKPR(g_drawingInfo.rootNode, RET_ERR);
830     if (drawDynamicEffectModifier_ != nullptr) {
831         g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_);
832         drawDynamicEffectModifier_ = nullptr;
833     }
834     drawDynamicEffectModifier_ = std::make_shared<DrawDynamicEffectModifier>();
835     g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_);
836     drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA);
837     drawDynamicEffectModifier_->SetScale(BEGIN_SCALE);
838 
839     Rosen::RSAnimationTimingProtocol protocol;
840     protocol.SetDuration(SUCCESS_ANIMATION_DURATION);
841     Rosen::RSNode::Animate(protocol, Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() {
842         drawDynamicEffectModifier_->SetAlpha(endAlpha);
843         drawDynamicEffectModifier_->SetScale(endScale);
844     });
845     CHKPR(g_drawingInfo.parentNode, RET_ERR);
846     Rosen::RSTransaction::FlushImplicitTransaction();
847     startNum_ = START_TIME;
848     needDestroyDragWindow_ = true;
849     return StartVsync();
850 }
851 
StartVsync()852 int32_t DragDrawing::StartVsync()
853 {
854     if (receiver_ == nullptr) {
855         CHKPR(handler_, RET_ERR);
856         receiver_ = Rosen::RSInterfaces::GetInstance().CreateVSyncReceiver("DragDrawing", handler_);
857         CHKPR(receiver_, RET_ERR);
858     }
859     int32_t ret = receiver_->Init();
860     if (ret != RET_OK) {
861         FI_HILOGE("Receiver init failed");
862         return RET_ERR;
863     }
864     Rosen::VSyncReceiver::FrameCallback fcb = {
865         .userData_ = this,
866         .callback_ = std::bind(&DragDrawing::OnVsync, this)
867     };
868     ret = receiver_->RequestNextVSync(fcb);
869     if (ret != RET_OK) {
870         FI_HILOGE("Request next vsync failed");
871     }
872     return ret;
873 }
874 
OnVsync()875 void DragDrawing::OnVsync()
876 {
877     CALL_DEBUG_ENTER;
878     CHKPV(rsUiDirector_);
879     bool hasRunningAnimation = rsUiDirector_->FlushAnimation(startNum_);
880     rsUiDirector_->FlushModifier();
881     if (!hasRunningAnimation) {
882         FI_HILOGD("Stop runner, hasRunningAnimation:%{public}d", hasRunningAnimation);
883         CHKPV(handler_);
884         handler_->RemoveAllEvents();
885         handler_->RemoveAllFileDescriptorListeners();
886         handler_ = nullptr;
887         receiver_ = nullptr;
888         if (needDestroyDragWindow_) {
889             CHKPV(g_drawingInfo.rootNode);
890             if (drawDynamicEffectModifier_ != nullptr) {
891                 g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_);
892                 drawDynamicEffectModifier_ = nullptr;
893             }
894             DestroyDragWindow();
895             g_drawingInfo.isRunning = false;
896         }
897         return;
898     }
899     Rosen::VSyncReceiver::FrameCallback fcb = {
900         .userData_ = this,
901         .callback_ = std::bind(&DragDrawing::OnVsync, this)
902     };
903     int32_t ret = receiver_->RequestNextVSync(fcb);
904     if (ret != RET_OK) {
905         FI_HILOGE("Request next vsync failed");
906     }
907     rsUiDirector_->SendMessages();
908     startNum_ += INTERVAL_TIME;
909 }
910 
InitDrawingInfo(const DragData & dragData)911 void DragDrawing::InitDrawingInfo(const DragData &dragData)
912 {
913     g_drawingInfo.isRunning = true;
914     if (dragData.shadowInfos.empty()) {
915         FI_HILOGE("ShadowInfos is empty");
916         return;
917     }
918     size_t shadowInfosSize = dragData.shadowInfos.size();
919     for (size_t i = 1; i < shadowInfosSize; ++i) {
920         g_drawingInfo.multiSelectedPixelMaps.emplace_back(dragData.shadowInfos[i].pixelMap);
921     }
922     g_drawingInfo.pixelMap = dragData.shadowInfos.front().pixelMap;
923     g_drawingInfo.pixelMapX = dragData.shadowInfos.front().x;
924     g_drawingInfo.pixelMapY = dragData.shadowInfos.front().y;
925     g_drawingInfo.lastPixelMapX = g_drawingInfo.pixelMapX;
926     g_drawingInfo.lastPixelMapY = g_drawingInfo.pixelMapY;
927     g_drawingInfo.currentDragNum = dragData.dragNum;
928     g_drawingInfo.sourceType = dragData.sourceType;
929     g_drawingInfo.displayId = dragData.displayId;
930     g_drawingInfo.displayX = dragData.displayX;
931     g_drawingInfo.displayY = dragData.displayY;
932     RotateDisplayXY(g_drawingInfo.displayX, g_drawingInfo.displayY);
933     g_drawingInfo.extraInfo = dragData.extraInfo;
934     g_drawingInfo.filterInfo = dragData.filterInfo;
935 }
936 
InitDragAnimationData(DragAnimationData & dragAnimationData)937 int32_t DragDrawing::InitDragAnimationData(DragAnimationData &dragAnimationData)
938 {
939     CHKPR(g_drawingInfo.pixelMap, RET_ERR);
940     dragAnimationData.pixelMap = g_drawingInfo.pixelMap;
941     dragAnimationData.displayX = g_drawingInfo.displayX;
942     dragAnimationData.displayY = g_drawingInfo.displayY;
943     dragAnimationData.offsetX = g_drawingInfo.pixelMapX;
944     dragAnimationData.offsetY = g_drawingInfo.pixelMapY;
945     return RET_OK;
946 }
947 
InitLayer()948 int32_t DragDrawing::InitLayer()
949 {
950     CALL_DEBUG_ENTER;
951     if (g_drawingInfo.surfaceNode == nullptr) {
952         FI_HILOGE("Init layer failed, surfaceNode is nullptr");
953         return RET_ERR;
954     }
955     auto surface = g_drawingInfo.surfaceNode->GetSurface();
956     if (surface == nullptr) {
957         g_drawingInfo.surfaceNode->DetachToDisplay(g_drawingInfo.displayId);
958         g_drawingInfo.surfaceNode = nullptr;
959         FI_HILOGE("Init layer failed, surface is nullptr");
960         Rosen::RSTransaction::FlushImplicitTransaction();
961         return RET_ERR;
962     }
963     if (g_drawingInfo.isInitUiDirector) {
964         g_drawingInfo.isInitUiDirector = false;
965         rsUiDirector_ = Rosen::RSUIDirector::Create();
966         CHKPR(rsUiDirector_, RET_ERR);
967         rsUiDirector_->Init();
968     }
969     rsUiDirector_->SetRSSurfaceNode(g_drawingInfo.surfaceNode);
970     sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId);
971     if (display == nullptr) {
972         FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId);
973         display = Rosen::DisplayManager::GetInstance().GetDisplayById(0);
974         if (display == nullptr) {
975             FI_HILOGE("Get display info failed, display is nullptr");
976             return RET_ERR;
977         }
978     }
979     int32_t rootNodeSize = std::max(display->GetWidth(), display->GetHeight());
980     InitCanvas(rootNodeSize, rootNodeSize);
981     if (rotation_ != Rosen::Rotation::ROTATION_0) {
982         RotateDragWindow(rotation_);
983     }
984     Rosen::RSTransaction::FlushImplicitTransaction();
985     return RET_OK;
986 }
987 
InitCanvas(int32_t width,int32_t height)988 void DragDrawing::InitCanvas(int32_t width, int32_t height)
989 {
990     CALL_DEBUG_ENTER;
991     if (g_drawingInfo.rootNode == nullptr) {
992         g_drawingInfo.rootNode = Rosen::RSRootNode::Create();
993         CHKPV(g_drawingInfo.rootNode);
994     }
995     g_drawingInfo.rootNode->SetBounds(0, 0, width, height);
996     g_drawingInfo.rootNode->SetFrame(0, 0, width, height);
997     g_drawingInfo.rootNode->SetBackgroundColor(SK_ColorTRANSPARENT);
998     std::shared_ptr<Rosen::RSCanvasNode> filterNode = Rosen::RSCanvasNode::Create();
999     CHKPV(filterNode);
1000     g_drawingInfo.nodes.emplace_back(filterNode);
1001     if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
1002         ProcessFilter();
1003     }
1004     std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = Rosen::RSCanvasNode::Create();
1005     CHKPV(pixelMapNode);
1006     pixelMapNode->SetForegroundColor(TRANSPARENT_COLOR_ARGB);
1007     g_drawingInfo.nodes.emplace_back(pixelMapNode);
1008     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = Rosen::RSCanvasNode::Create();
1009     CHKPV(dragStyleNode);
1010     g_drawingInfo.nodes.emplace_back(dragStyleNode);
1011     if (g_drawingInfo.parentNode == nullptr) {
1012         g_drawingInfo.parentNode = Rosen::RSCanvasNode::Create();
1013         CHKPV(g_drawingInfo.parentNode);
1014     }
1015     g_drawingInfo.parentNode->AddChild(filterNode);
1016     g_drawingInfo.parentNode->AddChild(pixelMapNode);
1017     if (!g_drawingInfo.multiSelectedPixelMaps.empty()) {
1018         InitMultiSelectedNodes();
1019         if (!g_drawingInfo.multiSelectedNodes.empty()) {
1020             size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size();
1021             for (size_t i = 0; i < multiSelectedNodesSize; ++i) {
1022                 g_drawingInfo.rootNode->AddChild(g_drawingInfo.multiSelectedNodes[i]);
1023             }
1024         }
1025     }
1026     g_drawingInfo.rootNode->AddChild(g_drawingInfo.parentNode);
1027     CHKPV(rsUiDirector_);
1028     if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
1029         std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = Rosen::RSCanvasNode::Create();
1030         CHKPV(mouseIconNode);
1031         g_drawingInfo.nodes.emplace_back(mouseIconNode);
1032         g_drawingInfo.rootNode->AddChild(mouseIconNode);
1033         rsUiDirector_->SetRoot(g_drawingInfo.rootNode->GetId());
1034         return;
1035     }
1036     rsUiDirector_->SetRoot(g_drawingInfo.rootNode->GetId());
1037 }
1038 
CreateWindow()1039 void DragDrawing::CreateWindow()
1040 {
1041     FI_HILOGD("Parameter screen number:%{public}llu", static_cast<unsigned long long>(screenId_));
1042     Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1043     surfaceNodeConfig.SurfaceNodeName = "drag window";
1044     Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1045     g_drawingInfo.surfaceNode = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1046     CHKPV(g_drawingInfo.surfaceNode);
1047     sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId);
1048     if (display == nullptr) {
1049         FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId);
1050         display = Rosen::DisplayManager::GetInstance().GetDisplayById(0);
1051         if (display == nullptr) {
1052             FI_HILOGE("Get display info failed, display is nullptr");
1053             return;
1054         }
1055     }
1056     int32_t surfaceNodeSize = std::max(display->GetWidth(), display->GetHeight());
1057     g_drawingInfo.surfaceNode->SetBounds(0, 0, surfaceNodeSize, surfaceNodeSize);
1058     g_drawingInfo.surfaceNode->SetFrameGravity(Rosen::Gravity::RESIZE_ASPECT_FILL);
1059     g_drawingInfo.surfaceNode->SetPositionZ(DRAG_WINDOW_POSITION_Z);
1060     g_drawingInfo.surfaceNode->SetBackgroundColor(SK_ColorTRANSPARENT);
1061     g_drawingInfo.surfaceNode->AttachToDisplay(screenId_);
1062     g_drawingInfo.surfaceNode->SetVisible(false);
1063     Rosen::RSTransaction::FlushImplicitTransaction();
1064 }
1065 
RemoveModifier()1066 void DragDrawing::RemoveModifier()
1067 {
1068     CALL_DEBUG_ENTER;
1069     if ((g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) {
1070         FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size());
1071         return;
1072     }
1073 
1074     std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX];
1075     CHKPV(pixelMapNode);
1076     if (drawPixelMapModifier_ != nullptr) {
1077         pixelMapNode->RemoveModifier(drawPixelMapModifier_);
1078         drawPixelMapModifier_ = nullptr;
1079     }
1080     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
1081     CHKPV(dragStyleNode);
1082     if (drawSVGModifier_ != nullptr) {
1083         dragStyleNode->RemoveModifier(drawSVGModifier_);
1084         drawSVGModifier_ = nullptr;
1085     }
1086 }
1087 
UpdateSvgNodeInfo(xmlNodePtr curNode,int32_t extendSvgWidth)1088 int32_t DragDrawing::UpdateSvgNodeInfo(xmlNodePtr curNode, int32_t extendSvgWidth)
1089 {
1090     CALL_DEBUG_ENTER;
1091     if (xmlStrcmp(curNode->name, BAD_CAST "svg")) {
1092         FI_HILOGE("Svg format invalid");
1093         return RET_ERR;
1094     }
1095     std::ostringstream oStrStream;
1096     oStrStream << xmlGetProp(curNode, BAD_CAST "width");
1097     std::string srcSvgWidth = oStrStream.str();
1098     if (srcSvgWidth.length() < STRING_PX_LENGTH) {
1099         FI_HILOGE("Svg width invalid, srcSvgWidth:%{public}s", srcSvgWidth.c_str());
1100         return RET_ERR;
1101     }
1102     srcSvgWidth = srcSvgWidth.substr(0, srcSvgWidth.length() - STRING_PX_LENGTH);
1103     if (!IsNum(srcSvgWidth)) {
1104         FI_HILOGE("srcSvgWidth is not digital, srcSvgWidth:%{public}s", srcSvgWidth.c_str());
1105         return RET_ERR;
1106     }
1107     int32_t number = std::stoi(srcSvgWidth) + extendSvgWidth;
1108     std::string tgtSvgWidth = std::to_string(number);
1109     tgtSvgWidth.append("px");
1110     xmlSetProp(curNode, BAD_CAST "width", BAD_CAST tgtSvgWidth.c_str());
1111     oStrStream.str("");
1112     oStrStream << xmlGetProp(curNode, BAD_CAST "viewBox");
1113     std::string srcViewBox = oStrStream.str();
1114     std::istringstream iStrStream(srcViewBox);
1115     std::string tmpString;
1116     std::string tgtViewBox;
1117     int32_t i = 0;
1118     while (iStrStream >> tmpString) {
1119         if (i == VIEW_BOX_POS) {
1120             if (!IsNum(tmpString)) {
1121                 FI_HILOGE("tmpString is not digital, tmpString:%{public}s", tmpString.c_str());
1122                 return RET_ERR;
1123             }
1124             number = std::stoi(tmpString) + extendSvgWidth;
1125             tmpString = std::to_string(number);
1126         }
1127         tgtViewBox.append(tmpString);
1128         tgtViewBox += " ";
1129         ++i;
1130     }
1131 
1132     xmlSetProp(curNode, BAD_CAST "viewBox", BAD_CAST tgtViewBox.c_str());
1133     return RET_OK;
1134 }
1135 
GetRectNode(xmlNodePtr curNode)1136 xmlNodePtr DragDrawing::GetRectNode(xmlNodePtr curNode)
1137 {
1138     CALL_DEBUG_ENTER;
1139     curNode = curNode->xmlChildrenNode;
1140     while (curNode != nullptr) {
1141         if (!xmlStrcmp(curNode->name, BAD_CAST "g")) {
1142             while (!xmlStrcmp(curNode->name, BAD_CAST "g")) {
1143                 curNode = curNode->xmlChildrenNode;
1144             }
1145             break;
1146         }
1147         curNode = curNode->next;
1148     }
1149     return curNode;
1150 }
1151 
UpdateRectNode(int32_t extendSvgWidth,xmlNodePtr curNode)1152 xmlNodePtr DragDrawing::UpdateRectNode(int32_t extendSvgWidth, xmlNodePtr curNode)
1153 {
1154     CALL_DEBUG_ENTER;
1155     while (curNode != nullptr) {
1156         if (!xmlStrcmp(curNode->name, BAD_CAST "rect")) {
1157             std::ostringstream oStrStream;
1158             oStrStream << xmlGetProp(curNode, BAD_CAST "width");
1159             std::string srcRectWidth = oStrStream.str();
1160             if (!IsNum(srcRectWidth)) {
1161                 FI_HILOGE("srcRectWidth is not digital, srcRectWidth:%{public}s", srcRectWidth.c_str());
1162                 return nullptr;
1163             }
1164             int32_t number = std::stoi(srcRectWidth) + extendSvgWidth;
1165             xmlSetProp(curNode, BAD_CAST "width", BAD_CAST std::to_string(number).c_str());
1166         }
1167         if (!xmlStrcmp(curNode->name, BAD_CAST "text")) {
1168             return curNode->xmlChildrenNode;
1169         }
1170         curNode = curNode->next;
1171     }
1172     FI_HILOGE("Empty node of XML");
1173     return nullptr;
1174 }
1175 
UpdateTspanNode(xmlNodePtr curNode)1176 void DragDrawing::UpdateTspanNode(xmlNodePtr curNode)
1177 {
1178     CALL_DEBUG_ENTER;
1179     while (curNode != nullptr) {
1180         if (!xmlStrcmp(curNode->name, BAD_CAST "tspan")) {
1181             xmlNodeSetContent(curNode, BAD_CAST std::to_string(g_drawingInfo.currentDragNum).c_str());
1182         }
1183         curNode = curNode->next;
1184     }
1185 }
1186 
ParseAndAdjustSvgInfo(xmlNodePtr curNode)1187 int32_t DragDrawing::ParseAndAdjustSvgInfo(xmlNodePtr curNode)
1188 {
1189     CALL_DEBUG_ENTER;
1190     CHKPR(curNode, RET_ERR);
1191     std::string strStyle = std::to_string(g_drawingInfo.currentDragNum);
1192     if (strStyle.empty()) {
1193         FI_HILOGE("strStyle size:%{public}zu invalid", strStyle.size());
1194         return RET_ERR;
1195     }
1196     int32_t extendSvgWidth = (static_cast<int32_t>(strStyle.size()) - 1) * EIGHT_SIZE;
1197     xmlKeepBlanksDefault(0);
1198     int32_t ret = UpdateSvgNodeInfo(curNode, extendSvgWidth);
1199     if (ret != RET_OK) {
1200         FI_HILOGE("Update svg node info failed, ret:%{public}d", ret);
1201         return RET_ERR;
1202     }
1203     curNode = GetRectNode(curNode);
1204     CHKPR(curNode, RET_ERR);
1205     curNode = UpdateRectNode(extendSvgWidth, curNode);
1206     CHKPR(curNode, RET_ERR);
1207     UpdateTspanNode(curNode);
1208     return RET_OK;
1209 }
1210 
DecodeSvgToPixelMap(const std::string & filePath)1211 std::shared_ptr<Media::PixelMap> DragDrawing::DecodeSvgToPixelMap(
1212     const std::string &filePath)
1213 {
1214     CALL_DEBUG_ENTER;
1215     xmlDocPtr xmlDoc = xmlReadFile(filePath.c_str(), 0, XML_PARSE_NOBLANKS);
1216     if (NeedAdjustSvgInfo()) {
1217         xmlNodePtr node = xmlDocGetRootElement(xmlDoc);
1218         CHKPP(node);
1219         int32_t ret = ParseAndAdjustSvgInfo(node);
1220         if (ret != RET_OK) {
1221             FI_HILOGE("Parse and adjust svg info failed, ret:%{public}d", ret);
1222             return nullptr;
1223         }
1224     }
1225     xmlChar *xmlbuff = nullptr;
1226     int32_t buffersize = 0;
1227     xmlDocDumpFormatMemory(xmlDoc, &xmlbuff, &buffersize, 1);
1228     std::ostringstream oStrStream;
1229     oStrStream << xmlbuff;
1230     std::string content = oStrStream.str();
1231     xmlFree(xmlbuff);
1232     xmlFreeDoc(xmlDoc);
1233     Media::SourceOptions opts;
1234     opts.formatHint = "image/svg+xml";
1235     uint32_t errCode = 0;
1236     auto imageSource = Media::ImageSource::CreateImageSource(reinterpret_cast<const uint8_t*>(content.c_str()),
1237         content.size(), opts, errCode);
1238     CHKPP(imageSource);
1239     Media::DecodeOptions decodeOpts;
1240     SetDecodeOptions(decodeOpts);
1241     std::shared_ptr<Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode);
1242     return pixelMap;
1243 }
1244 
NeedAdjustSvgInfo()1245 bool DragDrawing::NeedAdjustSvgInfo()
1246 {
1247     CALL_DEBUG_ENTER;
1248     if (g_drawingInfo.currentStyle == DragCursorStyle::DEFAULT) {
1249         return false;
1250     }
1251     if ((g_drawingInfo.currentStyle == DragCursorStyle::COPY) &&
1252         (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) {
1253         return false;
1254     }
1255     if ((g_drawingInfo.currentStyle == DragCursorStyle::MOVE) &&
1256         (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) {
1257         return false;
1258     }
1259     if ((g_drawingInfo.currentStyle == DragCursorStyle::FORBIDDEN) &&
1260         (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) {
1261         return false;
1262     }
1263     return true;
1264 }
1265 
GetFilePath(std::string & filePath)1266 int32_t DragDrawing::GetFilePath(std::string &filePath)
1267 {
1268     CALL_DEBUG_ENTER;
1269     switch (g_drawingInfo.currentStyle) {
1270         case DragCursorStyle::COPY: {
1271             if (g_drawingInfo.currentDragNum == DRAG_NUM_ONE) {
1272                 filePath = COPY_ONE_DRAG_PATH;
1273             } else {
1274                 filePath = COPY_DRAG_PATH;
1275             }
1276             break;
1277         }
1278         case DragCursorStyle::MOVE: {
1279             filePath = MOVE_DRAG_PATH;
1280             break;
1281         }
1282         case DragCursorStyle::FORBIDDEN: {
1283             if (g_drawingInfo.currentDragNum == DRAG_NUM_ONE) {
1284                 filePath = FORBID_ONE_DRAG_PATH;
1285             } else {
1286                 filePath = FORBID_DRAG_PATH;
1287             }
1288             break;
1289         }
1290         case DragCursorStyle::DEFAULT:
1291         default: {
1292             FI_HILOGW("Not need draw svg style, DragCursorStyle:%{public}d", g_drawingInfo.currentStyle);
1293             break;
1294         }
1295     }
1296     return RET_OK;
1297 }
1298 
SetDecodeOptions(Media::DecodeOptions & decodeOpts)1299 void DragDrawing::SetDecodeOptions(Media::DecodeOptions &decodeOpts)
1300 {
1301     CALL_DEBUG_ENTER;
1302     std::string strStyle = std::to_string(g_drawingInfo.currentDragNum);
1303     if (strStyle.empty()) {
1304         FI_HILOGE("strStyle size:%{public}zu invalid", strStyle.size());
1305         return;
1306     }
1307     int32_t extendSvgWidth = (static_cast<int32_t>(strStyle.size()) - 1) * EIGHT_SIZE;
1308     std::string deviceType = system::GetDeviceType();
1309     if ((g_drawingInfo.currentStyle == DragCursorStyle::COPY) && (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) {
1310         decodeOpts.desiredSize = {
1311             .width = DEVICE_INDEPENDENT_PIXEL * GetScaling(),
1312             .height = DEVICE_INDEPENDENT_PIXEL * GetScaling()
1313         };
1314     } else if (((deviceType.compare(0, DEVICE_TYPE_DEFAULT.size(), DEVICE_TYPE_DEFAULT) == 0) ||
1315         (deviceType.compare(0, DEVICE_TYPE_PHONE.size(), DEVICE_TYPE_PHONE) == 0)) &&
1316         (g_drawingInfo.currentStyle == DragCursorStyle::MOVE) && (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) {
1317         decodeOpts.desiredSize = {
1318             .width = DEVICE_INDEPENDENT_PIXEL * GetScaling(),
1319             .height = DEVICE_INDEPENDENT_PIXEL * GetScaling()
1320         };
1321     } else {
1322         decodeOpts.desiredSize = {
1323             .width = (DEVICE_INDEPENDENT_PIXEL + extendSvgWidth) * GetScaling(),
1324             .height = DEVICE_INDEPENDENT_PIXEL * GetScaling()
1325         };
1326     }
1327 }
1328 
ParserFilterInfo(FilterInfo & filterInfo)1329 bool DragDrawing::ParserFilterInfo(FilterInfo &filterInfo)
1330 {
1331     FI_HILOGD("ExtraInfo size:%{public}zu, extraInfo:%{public}s, filterInfo size:%{public}zu, filterInfo:%{public}s",
1332         g_drawingInfo.extraInfo.size(), g_drawingInfo.extraInfo.c_str(), g_drawingInfo.filterInfo.size(),
1333         g_drawingInfo.filterInfo.c_str());
1334     if (g_drawingInfo.extraInfo.empty() || g_drawingInfo.filterInfo.empty()) {
1335         FI_HILOGD("ExtraInfo or filterInfo is empty");
1336         return false;
1337     }
1338     JsonParser extraInfoParser;
1339     extraInfoParser.json = cJSON_Parse(g_drawingInfo.extraInfo.c_str());
1340     if (!cJSON_IsObject(extraInfoParser.json)) {
1341         FI_HILOGE("ExtraInfo is not json object");
1342         return false;
1343     }
1344     cJSON *componentType = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "drag_data_type");
1345     if (!cJSON_IsString(componentType)) {
1346         FI_HILOGE("Parser componentType failed");
1347         return false;
1348     }
1349     cJSON *blurStyle = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "drag_blur_style");
1350     if (!cJSON_IsNumber(blurStyle)) {
1351         FI_HILOGE("Parser blurStyle failed");
1352         return false;
1353     }
1354     cJSON *cornerRadius = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "drag_corner_radius");
1355     if (!cJSON_IsNumber(cornerRadius)) {
1356         FI_HILOGE("Parser cornerRadius failed");
1357         return false;
1358     }
1359 
1360     JsonParser filterInfoParser;
1361     filterInfoParser.json = cJSON_Parse(g_drawingInfo.filterInfo.c_str());
1362     if (!cJSON_IsObject(filterInfoParser.json)) {
1363         FI_HILOGE("FilterInfo is not json object");
1364         return false;
1365     }
1366     cJSON *dipScale = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "dip_scale");
1367     if (!cJSON_IsNumber(dipScale)) {
1368         FI_HILOGE("Parser dipScale failed");
1369         return false;
1370     }
1371     filterInfo = { componentType->valuestring, blurStyle->valueint, cornerRadius->valuedouble, dipScale->valuedouble };
1372     return true;
1373 }
1374 
GetAllowDragState()1375 bool DragDrawing::GetAllowDragState()
1376 {
1377     if (g_drawingInfo.extraInfo.empty()) {
1378         FI_HILOGE("The extraInfo is empty");
1379         return true;
1380     }
1381     if (g_drawingInfo.extraInfo.size() > EXTRA_INFO_MAX_SIZE) {
1382         FI_HILOGE("The extraInfo is greater than the length limit");
1383         return true;
1384     }
1385     JsonParser extraInfoParser;
1386     extraInfoParser.json = cJSON_Parse(g_drawingInfo.extraInfo.c_str());
1387     if (!cJSON_IsObject(extraInfoParser.json)) {
1388         FI_HILOGE("The extraInfo is not a json object");
1389         return true;
1390     }
1391     bool ret = static_cast<bool>(cJSON_HasObjectItem(extraInfoParser.json, "drag_allow_distributed"));
1392     if (!ret) {
1393         FI_HILOGE("Can't found \'drag_allow_distributed\' in extraInfo");
1394         return true;
1395     }
1396     cJSON *json = cJSON_GetObjectItem(extraInfoParser.json, "drag_allow_distributed");
1397     if (json == nullptr || !cJSON_IsBool(json)) {
1398         FI_HILOGE("Can't parse \'drag_allow_distributed\' in extraInfo");
1399         return true;
1400     }
1401     bool isAllowDrag = cJSON_IsTrue(json) ? true : false;
1402     FI_HILOGD("Parse extraInfo, the \'drag_allow_distributed\' is %{public}s", isAllowDrag ? "true" : "false");
1403 
1404     return isAllowDrag;
1405 }
1406 
SetScreenId(uint64_t screenId)1407 void DragDrawing::SetScreenId(uint64_t screenId)
1408 {
1409     CALL_DEBUG_ENTER;
1410     screenId_ = screenId;
1411 }
1412 
RotateDragWindow(Rosen::Rotation rotation)1413 int32_t DragDrawing::RotateDragWindow(Rosen::Rotation rotation)
1414 {
1415     if (needRotatePixelMapXY_) {
1416         CHKPR(g_drawingInfo.pixelMap, RET_ERR);
1417         g_drawingInfo.pixelMapX = -(HALF_RATIO * g_drawingInfo.pixelMap->GetWidth());
1418         g_drawingInfo.pixelMapY = -(EIGHT_SIZE * GetScaling());
1419     }
1420     switch (rotation) {
1421         case Rosen::Rotation::ROTATION_0: {
1422             return DoRotateDragWindow(ROTATION_DEFAULT);
1423         }
1424         case Rosen::Rotation::ROTATION_90: {
1425             return DoRotateDragWindow(ROTATION_FIRST_ORDER);
1426         }
1427         case Rosen::Rotation::ROTATION_180: {
1428             return DoRotateDragWindow(ROTATION_SECOND_ORDER);
1429         }
1430         case Rosen::Rotation::ROTATION_270: {
1431             return DoRotateDragWindow(ROTATION_THIRD_ORDER);
1432         }
1433         default: {
1434             FI_HILOGE("Invalid parameter, rotation:%{public}d", static_cast<int32_t>(rotation));
1435             return RET_ERR;
1436         }
1437     }
1438     return RET_OK;
1439 }
1440 
SetRotation(Rosen::Rotation rotation)1441 void DragDrawing::SetRotation(Rosen::Rotation rotation)
1442 {
1443     rotation_ = rotation;
1444 }
1445 
ProcessFilter()1446 void DragDrawing::ProcessFilter()
1447 {
1448     CALL_DEBUG_ENTER;
1449     std::shared_ptr<Rosen::RSCanvasNode> filterNode = g_drawingInfo.nodes[BACKGROUND_FILTER_INDEX];
1450     CHKPV(filterNode);
1451     CHKPV(g_drawingInfo.pixelMap);
1452     int32_t adjustSize = TWELVE_SIZE * GetScaling();
1453     if (FilterInfo filterInfo; ParserFilterInfo(filterInfo) && filterInfo.componentType == BIG_FOLDER_LABEL) {
1454         std::shared_ptr<Rosen::RSFilter> backFilter = Rosen::RSFilter::CreateMaterialFilter(
1455             RadiusVp2Sigma(RADIUS_VP, filterInfo.dipScale),
1456             DEFAULT_SATURATION, DEFAULT_BRIGHTNESS, DEFAULT_COLOR_VALUE);
1457         if (backFilter == nullptr) {
1458             FI_HILOGE("Create backgroundFilter failed");
1459             return;
1460         }
1461         filterNode->SetBackgroundFilter(backFilter);
1462         filterNode->SetBounds(DEFAULT_POSITION_X, adjustSize, g_drawingInfo.pixelMap->GetWidth(),
1463             g_drawingInfo.pixelMap->GetHeight());
1464         filterNode->SetFrame(DEFAULT_POSITION_X, adjustSize, g_drawingInfo.pixelMap->GetWidth(),
1465             g_drawingInfo.pixelMap->GetHeight());
1466         if (filterInfo.cornerRadius < 0 || filterInfo.dipScale < 0 || fabs(filterInfo.dipScale) < EPSILON ||
1467             std::numeric_limits<float>::max() / filterInfo.dipScale < filterInfo.cornerRadius) {
1468             FI_HILOGE("Invalid parameters, cornerRadius:%{public}f, dipScale:%{public}f",
1469                 filterInfo.cornerRadius, filterInfo.dipScale);
1470             return;
1471         }
1472         filterNode->SetCornerRadius(filterInfo.cornerRadius * filterInfo.dipScale);
1473         FI_HILOGD("Add filter successfully");
1474     }
1475 }
1476 
SetNodesLocation(int32_t positionX,int32_t positionY)1477 int32_t DragDrawing::SetNodesLocation(int32_t positionX, int32_t positionY)
1478 {
1479     CALL_DEBUG_ENTER;
1480     Rosen::RSAnimationTimingProtocol protocol;
1481     int32_t adjustSize = TWELVE_SIZE * GetScaling();
1482     CHKPR(g_drawingInfo.parentNode, RET_ERR);
1483     CHKPR(g_drawingInfo.pixelMap, RET_ERR);
1484     Rosen::RSNode::Animate(protocol, SPRING, [&]() {
1485         g_drawingInfo.parentNode->SetBounds(positionX, positionY, g_drawingInfo.pixelMap->GetWidth() + adjustSize,
1486             g_drawingInfo.pixelMap->GetHeight() + adjustSize);
1487         g_drawingInfo.parentNode->SetFrame(positionX, positionY, g_drawingInfo.pixelMap->GetWidth() + adjustSize,
1488             g_drawingInfo.pixelMap->GetHeight() + adjustSize);
1489     });
1490     startNum_ = START_TIME;
1491     needDestroyDragWindow_ = false;
1492     StartVsync();
1493     return RET_OK;
1494 }
1495 
1496 
EnterTextEditorArea(bool enable)1497 int32_t DragDrawing::EnterTextEditorArea(bool enable)
1498 {
1499     CALL_DEBUG_ENTER;
1500     if (enable) {
1501         DRAG_DATA_MGR.SetInitialPixelMapLocation({ g_drawingInfo.pixelMapX, g_drawingInfo.pixelMapY });
1502         needRotatePixelMapXY_ = true;
1503         RotatePixelMapXY(g_drawingInfo.pixelMapX, g_drawingInfo.pixelMapY);
1504     } else {
1505         needRotatePixelMapXY_ = false;
1506         auto initialPixelMapLocation = DRAG_DATA_MGR.GetInitialPixelMapLocation();
1507         g_drawingInfo.pixelMapX = initialPixelMapLocation.first;
1508         g_drawingInfo.pixelMapY = initialPixelMapLocation.second;
1509     }
1510     DRAG_DATA_MGR.SetPixelMapLocation({ g_drawingInfo.pixelMapX, g_drawingInfo.pixelMapY });
1511     int32_t positionX = g_drawingInfo.displayX + g_drawingInfo.pixelMapX;
1512     int32_t positionY = g_drawingInfo.displayY + g_drawingInfo.pixelMapY - TWELVE_SIZE * GetScaling();
1513     if (RunAnimation(std::bind(&DragDrawing::SetNodesLocation, this, positionX, positionY)) != RET_OK) {
1514         FI_HILOGE("RunAnimation to SetNodesLocation failed");
1515         return RET_ERR;
1516     }
1517     DRAG_DATA_MGR.SetTextEditorAreaFlag(enable);
1518     FI_HILOGI("EnterTextEditorArea %{public}s successfully", (enable ? "true" : "false"));
1519     return RET_OK;
1520 }
1521 
RadiusVp2Sigma(float radiusVp,float dipScale)1522 float DragDrawing::RadiusVp2Sigma(float radiusVp, float dipScale)
1523 {
1524     float radiusPx = radiusVp * dipScale;
1525     return radiusPx > 0.0f ? BLUR_SIGMA_SCALE * radiusPx + 0.5f : 0.0f;
1526 }
1527 
UpdatePreviewStyle(const PreviewStyle & previewStyle)1528 int32_t DragDrawing::UpdatePreviewStyle(const PreviewStyle &previewStyle)
1529 {
1530     CALL_DEBUG_ENTER;
1531     if (ModifyPreviewStyle(g_drawingInfo.nodes[PIXEL_MAP_INDEX], previewStyle) != RET_OK) {
1532         FI_HILOGE("ModifyPreviewStyle failed");
1533         return RET_ERR;
1534     }
1535     if (ModifyMultiPreviewStyle(std::vector<PreviewStyle>(g_drawingInfo.multiSelectedNodes.size(), previewStyle)) !=
1536         RET_OK) {
1537         FI_HILOGE("ModifyPreviewStyle failed");
1538         return RET_ERR;
1539     }
1540     Rosen::RSTransaction::FlushImplicitTransaction();
1541     return RET_OK;
1542 }
1543 
UpdatePreviewStyleWithAnimation(const PreviewStyle & previewStyle,const PreviewAnimation & animation)1544 int32_t DragDrawing::UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle,
1545     const PreviewAnimation &animation)
1546 {
1547     CALL_DEBUG_ENTER;
1548     std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX];
1549     CHKPR(pixelMapNode, RET_ERR);
1550     PreviewStyle originStyle;
1551     originStyle.types = previewStyle.types;
1552     if (auto color = pixelMapNode->GetShowingProperties().GetForegroundColor(); color.has_value()) {
1553         originStyle.foregroundColor = color->AsArgbInt();
1554         originStyle.radius = previewStyle.radius;
1555     }
1556     size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size();
1557     std::vector<PreviewStyle> multiOriginStyles;
1558     for (size_t i = 0; i < multiSelectedNodesSize; ++i) {
1559         if (auto color = g_drawingInfo.multiSelectedNodes[i]->GetShowingProperties().GetForegroundColor();
1560             color.has_value()) {
1561             PreviewStyle currentStyle;
1562             currentStyle.types = { PreviewType::FOREGROUND_COLOR, PreviewType::RADIUS };
1563             currentStyle.foregroundColor = color->AsArgbInt();
1564             currentStyle.radius = previewStyle.radius;
1565             multiOriginStyles.push_back(currentStyle);
1566         }
1567     }
1568     if (ModifyPreviewStyle(pixelMapNode, originStyle) != RET_OK) {
1569         FI_HILOGE("ModifyPreviewStyle failed");
1570         return RET_ERR;
1571     }
1572     if (ModifyMultiPreviewStyle(multiOriginStyles) != RET_OK) {
1573         FI_HILOGE("ModifyMultiPreviewStyle failed");
1574         return RET_ERR;
1575     }
1576     Rosen::RSAnimationTimingProtocol protocol;
1577     protocol.SetDuration(animation.duration);
1578     auto curve = AnimationCurve::CreateCurve(animation.curveName, animation.curve);
1579     Rosen::RSNode::Animate(protocol, curve, [&]() {
1580         if (ModifyPreviewStyle(pixelMapNode, previewStyle) != RET_OK) {
1581             FI_HILOGE("ModifyPreviewStyle failed");
1582         }
1583         if (ModifyMultiPreviewStyle(std::vector<PreviewStyle>(multiSelectedNodesSize, previewStyle)) != RET_OK) {
1584             FI_HILOGE("ModifyMultiPreviewStyle failed");
1585         }
1586     });
1587     return RET_OK;
1588 }
1589 
DoDrawMouse()1590 void DragDrawing::DoDrawMouse()
1591 {
1592     if (!CheckNodesValid()) {
1593         FI_HILOGE("Check nodes valid failed");
1594         return;
1595     }
1596     MMI::PointerStyle pointerStyle;
1597     int32_t ret = MMI::InputManager::GetInstance()->GetPointerStyle(GLOBAL_WINDOW_ID, pointerStyle);
1598     if (ret != RET_OK) {
1599         FI_HILOGE("Get pointer style failed, ret:%{public}d", ret);
1600         return;
1601     }
1602     std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX];
1603     CHKPV(mouseIconNode);
1604     int32_t pointerStyleId = pointerStyle.id;
1605     if (pointerStyleId == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) {
1606         int32_t positionX = g_drawingInfo.displayX - (g_drawingInfo.mouseWidth / CURSOR_CIRCLE_MIDDLE);
1607         int32_t positionY = g_drawingInfo.displayY - (g_drawingInfo.mouseHeight / CURSOR_CIRCLE_MIDDLE);
1608         mouseIconNode->SetBounds(positionX, positionY, g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight);
1609         mouseIconNode->SetFrame(positionX, positionY, g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight);
1610     } else {
1611         mouseIconNode->SetBounds(g_drawingInfo.displayX, g_drawingInfo.displayY,
1612             g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight);
1613         mouseIconNode->SetFrame(g_drawingInfo.displayX, g_drawingInfo.displayY,
1614             g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight);
1615     }
1616 }
1617 
UpdateDefaultDragStyle(DragCursorStyle style)1618 int32_t DragDrawing::UpdateDefaultDragStyle(DragCursorStyle style)
1619 {
1620     if (!CheckNodesValid()) {
1621         FI_HILOGE("Check nodes valid failed");
1622         return RET_ERR;
1623     }
1624     if (!g_drawingInfo.isCurrentDefaultStyle) {
1625         std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
1626         CHKPR(dragStyleNode, RET_ERR);
1627         CHKPR(g_drawingInfo.parentNode, RET_ERR);
1628         g_drawingInfo.parentNode->RemoveChild(dragStyleNode);
1629         CHKPR(rsUiDirector_, RET_ERR);
1630         rsUiDirector_->SendMessages();
1631     }
1632     g_drawingInfo.currentStyle = style;
1633     bool isPreviousDefaultStyle = g_drawingInfo.isCurrentDefaultStyle;
1634     g_drawingInfo.isPreviousDefaultStyle = isPreviousDefaultStyle;
1635     g_drawingInfo.isCurrentDefaultStyle = true;
1636     return RET_OK;
1637 }
1638 
UpdateValidDragStyle(DragCursorStyle style)1639 int32_t DragDrawing::UpdateValidDragStyle(DragCursorStyle style)
1640 {
1641     g_drawingInfo.currentStyle = style;
1642     if (g_drawingInfo.isCurrentDefaultStyle) {
1643         if (!CheckNodesValid()) {
1644             FI_HILOGE("Check nodes valid failed");
1645             return RET_ERR;
1646         }
1647         std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
1648         CHKPR(dragStyleNode, RET_ERR);
1649         CHKPR(g_drawingInfo.parentNode, RET_ERR);
1650         g_drawingInfo.parentNode->AddChild(dragStyleNode);
1651     }
1652     std::string filePath;
1653     if (GetFilePath(filePath) != RET_OK) {
1654         FI_HILOGD("Get file path failed");
1655         return RET_ERR;
1656     }
1657     if (!IsValidSvgFile(filePath)) {
1658         FI_HILOGE("Svg file is invalid");
1659         return RET_ERR;
1660     }
1661     std::shared_ptr<Media::PixelMap> pixelMap = DecodeSvgToPixelMap(filePath);
1662     CHKPR(pixelMap, RET_ERR);
1663     bool isPreviousDefaultStyle = g_drawingInfo.isCurrentDefaultStyle;
1664     g_drawingInfo.isPreviousDefaultStyle = isPreviousDefaultStyle;
1665     g_drawingInfo.isCurrentDefaultStyle = false;
1666     g_drawingInfo.stylePixelMap = pixelMap;
1667     if (!CheckNodesValid()) {
1668         FI_HILOGE("Check nodes valid failed");
1669         return RET_ERR;
1670     }
1671     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
1672     CHKPR(dragStyleNode, RET_ERR);
1673     OnDragStyle(dragStyleNode, pixelMap);
1674     CHKPR(rsUiDirector_, RET_ERR);
1675     rsUiDirector_->SendMessages();
1676     DragDFX::WriteUpdateDragStyle(style, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
1677     return RET_OK;
1678 }
1679 
ModifyPreviewStyle(std::shared_ptr<Rosen::RSCanvasNode> node,const PreviewStyle & previewStyle)1680 int32_t DragDrawing::ModifyPreviewStyle(std::shared_ptr<Rosen::RSCanvasNode> node, const PreviewStyle &previewStyle)
1681 {
1682     CALL_DEBUG_ENTER;
1683     CHKPR(node, RET_ERR);
1684     if (float radius = 0.0F; ParserRadius(radius)) {
1685         node->SetCornerRadius(radius);
1686         FI_HILOGD("SetCornerRadius by radius:%{public}f", radius);
1687     }
1688     for (const auto &type : previewStyle.types) {
1689         switch (type) {
1690             case PreviewType::FOREGROUND_COLOR: {
1691                 node->SetForegroundColor(previewStyle.foregroundColor);
1692                 break;
1693             }
1694             case PreviewType::OPACITY: {
1695                 node->SetAlpha(previewStyle.opacity / static_cast<float>(HEX_FF));
1696                 break;
1697             }
1698             case PreviewType::RADIUS: {
1699                 node->SetCornerRadius(previewStyle.radius);
1700                 break;
1701             }
1702             case PreviewType::SCALE: {
1703                 node->SetScale(previewStyle.scale);
1704                 break;
1705             }
1706             default: {
1707                 FI_HILOGE("Unsupported type");
1708                 break;
1709             }
1710         }
1711     }
1712     return RET_OK;
1713 }
1714 
ModifyMultiPreviewStyle(const std::vector<PreviewStyle> & previewStyles)1715 int32_t DragDrawing::ModifyMultiPreviewStyle(const std::vector<PreviewStyle> &previewStyles)
1716 {
1717     size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size();
1718     if (previewStyles.size() != multiSelectedNodesSize) {
1719         FI_HILOGE("Size of previewStyles:%{public}zu does not match multiSelectedNodesSize:%{public}zu",
1720             previewStyles.size(), multiSelectedNodesSize);
1721         return RET_ERR;
1722     }
1723     for (size_t i = 0; i < multiSelectedNodesSize; ++i) {
1724         if (ModifyPreviewStyle(g_drawingInfo.multiSelectedNodes[i], previewStyles[i]) != RET_OK) {
1725             FI_HILOGW("ModifyPreviewStyle No.%{public}zu failed", i);
1726         }
1727     }
1728     return RET_OK;
1729 }
1730 
MultiSelectedAnimation(int32_t positionX,int32_t positionY,int32_t adjustSize)1731 void DragDrawing::MultiSelectedAnimation(int32_t positionX, int32_t positionY, int32_t adjustSize)
1732 {
1733     size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size();
1734     size_t multiSelectedPixelMapsSize = g_drawingInfo.multiSelectedPixelMaps.size();
1735     for (size_t i = 0; (i < multiSelectedNodesSize) && (i < multiSelectedPixelMapsSize); ++i) {
1736         std::shared_ptr<Rosen::RSCanvasNode> multiSelectedNode = g_drawingInfo.multiSelectedNodes[i];
1737         std::shared_ptr<Media::PixelMap> multiSelectedPixelMap = g_drawingInfo.multiSelectedPixelMaps[i];
1738         Rosen::RSAnimationTimingProtocol protocol;
1739         if (i == FIRST_PIXELMAP_INDEX) {
1740             protocol.SetDuration(SHORT_DURATION);
1741         } else {
1742             protocol.SetDuration(LONG_DURATION);
1743         }
1744         Rosen::RSNode::Animate(protocol, Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() {
1745             multiSelectedNode->SetBounds(positionX, positionY + adjustSize, multiSelectedPixelMap->GetWidth(),
1746                 multiSelectedPixelMap->GetHeight());
1747             multiSelectedNode->SetFrame(positionX, positionY + adjustSize, multiSelectedPixelMap->GetWidth(),
1748                 multiSelectedPixelMap->GetHeight());
1749         });
1750     }
1751 }
1752 
InitMultiSelectedNodes()1753 void DragDrawing::InitMultiSelectedNodes()
1754 {
1755     CALL_DEBUG_ENTER;
1756     size_t multiSelectedPixelMapsSize = g_drawingInfo.multiSelectedPixelMaps.size();
1757     for (size_t i = 0; i < multiSelectedPixelMapsSize; ++i) {
1758         std::shared_ptr<Media::PixelMap> multiSelectedPixelMap = g_drawingInfo.multiSelectedPixelMaps[i];
1759         std::shared_ptr<Rosen::RSCanvasNode> multiSelectedNode = Rosen::RSCanvasNode::Create();
1760         multiSelectedNode->SetBgImageWidth(multiSelectedPixelMap->GetWidth());
1761         multiSelectedNode->SetBgImageHeight(multiSelectedPixelMap->GetHeight());
1762         multiSelectedNode->SetBgImagePositionX(0);
1763         multiSelectedNode->SetBgImagePositionY(0);
1764         multiSelectedNode->SetForegroundColor(TRANSPARENT_COLOR_ARGB);
1765         auto rosenImage = std::make_shared<Rosen::RSImage>();
1766         rosenImage->SetPixelMap(multiSelectedPixelMap);
1767         rosenImage->SetImageRepeat(0);
1768         multiSelectedNode->SetBgImage(rosenImage);
1769         float alpha = DEFAULT_ALPHA;
1770         float degrees = DEFAULT_ANGLE;
1771         if (i == FIRST_PIXELMAP_INDEX) {
1772             alpha = FIRST_PIXELMAP_ALPHA;
1773             degrees = POSITIVE_ANGLE;
1774         } else if (i == SECOND_PIXELMAP_INDEX) {
1775             alpha = SECOND_PIXELMAP_ALPHA;
1776             degrees = NEGATIVE_ANGLE;
1777         }
1778         multiSelectedNode->SetRotation(degrees);
1779         multiSelectedNode->SetAlpha(alpha);
1780         g_drawingInfo.multiSelectedNodes.emplace_back(multiSelectedNode);
1781     }
1782 }
1783 
ClearMultiSelectedData()1784 void DragDrawing::ClearMultiSelectedData()
1785 {
1786     CALL_DEBUG_ENTER;
1787     if (!g_drawingInfo.multiSelectedNodes.empty()) {
1788         g_drawingInfo.multiSelectedNodes.clear();
1789         g_drawingInfo.multiSelectedNodes.shrink_to_fit();
1790     }
1791     if (!g_drawingInfo.multiSelectedPixelMaps.empty()) {
1792         g_drawingInfo.multiSelectedPixelMaps.clear();
1793         g_drawingInfo.multiSelectedPixelMaps.shrink_to_fit();
1794     }
1795 }
1796 
RotateDisplayXY(int32_t & displayX,int32_t & displayY)1797 void DragDrawing::RotateDisplayXY(int32_t &displayX, int32_t &displayY)
1798 {
1799     sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId);
1800     if (display == nullptr) {
1801         FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId);
1802         display = Rosen::DisplayManager::GetInstance().GetDisplayById(0);
1803         CHKPV(display);
1804     }
1805     switch (rotation_) {
1806         case Rosen::Rotation::ROTATION_0: {
1807             break;
1808         }
1809         case Rosen::Rotation::ROTATION_90: {
1810             int32_t temp = displayY;
1811             displayY = display->GetWidth() - displayX;
1812             displayX = temp;
1813             break;
1814         }
1815         case Rosen::Rotation::ROTATION_180: {
1816             displayX = display->GetWidth() - displayX;
1817             displayY = display->GetHeight() - displayY;
1818             break;
1819         }
1820         case Rosen::Rotation::ROTATION_270: {
1821             int32_t temp = displayX;
1822             displayX = display->GetHeight() - displayY;
1823             displayY = temp;
1824             break;
1825         }
1826         default: {
1827             FI_HILOGE("Invalid parameter, rotation:%{public}d", static_cast<int32_t>(rotation_));
1828             break;
1829         }
1830     }
1831 }
1832 
RotatePixelMapXY(int32_t & pixelMapX,int32_t & pixelMapY)1833 void DragDrawing::RotatePixelMapXY(int32_t &pixelMapX, int32_t &pixelMapY)
1834 {
1835     FI_HILOGI("rotation:%{public}d", static_cast<int32_t>(rotation_));
1836     CHKPV(g_drawingInfo.pixelMap);
1837     switch (rotation_) {
1838         case Rosen::Rotation::ROTATION_0: {
1839             g_drawingInfo.pixelMapX = -(HALF_RATIO * g_drawingInfo.pixelMap->GetWidth());
1840             g_drawingInfo.pixelMapY = -(EIGHT_SIZE * GetScaling());
1841             break;
1842         }
1843         case Rosen::Rotation::ROTATION_90: {
1844             g_drawingInfo.pixelMapX = EIGHT_SIZE * GetScaling() + g_drawingInfo.lastPixelMapX;
1845             g_drawingInfo.pixelMapY = HALF_RATIO * g_drawingInfo.pixelMap->GetWidth() + g_drawingInfo.lastPixelMapX;
1846             break;
1847         }
1848         case Rosen::Rotation::ROTATION_180: {
1849             g_drawingInfo.pixelMapX = HALF_RATIO * g_drawingInfo.pixelMap->GetWidth() +
1850                 TWICE_SIZE * g_drawingInfo.lastPixelMapX;
1851             g_drawingInfo.pixelMapY = -(EIGHT_SIZE * GetScaling());
1852             break;
1853         }
1854         case Rosen::Rotation::ROTATION_270: {
1855             g_drawingInfo.pixelMapX = -EIGHT_SIZE * GetScaling() + g_drawingInfo.lastPixelMapX;
1856             g_drawingInfo.pixelMapY = -HALF_RATIO * g_drawingInfo.pixelMap->GetWidth() - g_drawingInfo.lastPixelMapX;
1857             break;
1858         }
1859         default: {
1860             FI_HILOGE("Invalid parameter, rotation:%{public}d", static_cast<int32_t>(rotation_));
1861             break;
1862         }
1863     }
1864 }
1865 
ResetParameter()1866 void  DragDrawing::ResetParameter()
1867 {
1868     CALL_INFO_TRACE;
1869     startNum_ = START_TIME;
1870     needDestroyDragWindow_ = false;
1871     needRotatePixelMapXY_ = false;
1872     g_drawingInfo.sourceType = -1;
1873     g_drawingInfo.currentDragNum = -1;
1874     g_drawingInfo.pixelMapX = -1;
1875     g_drawingInfo.pixelMapY = -1;
1876     g_drawingInfo.lastPixelMapX = -1;
1877     g_drawingInfo.lastPixelMapY = -1;
1878     g_drawingInfo.displayX = -1;
1879     g_drawingInfo.displayY = -1;
1880     g_drawingInfo.mouseWidth = 0;
1881     g_drawingInfo.mouseHeight = 0;
1882     g_drawingInfo.rootNodeWidth = -1;
1883     g_drawingInfo.rootNodeHeight = -1;
1884     g_drawingInfo.pixelMap = nullptr;
1885     g_drawingInfo.stylePixelMap = nullptr;
1886     g_drawingInfo.isPreviousDefaultStyle = false;
1887     g_drawingInfo.isCurrentDefaultStyle = false;
1888     g_drawingInfo.currentStyle = DragCursorStyle::DEFAULT;
1889     g_drawingInfo.filterInfo.clear();
1890     g_drawingInfo.extraInfo.clear();
1891 }
1892 
DoRotateDragWindow(float rotation)1893 int32_t DragDrawing::DoRotateDragWindow(float rotation)
1894 {
1895     FI_HILOGD("rotation:%{public}f", rotation);
1896     CHKPR(g_drawingInfo.parentNode, RET_ERR);
1897     CHKPR(g_drawingInfo.pixelMap, RET_ERR);
1898     if ((g_drawingInfo.pixelMap->GetWidth() <= 0) || (g_drawingInfo.pixelMap->GetHeight() <= 0)) {
1899         FI_HILOGE("Invalid parameter pixelmap");
1900         return RET_ERR;
1901     }
1902     float pivotX = 0.0f;
1903     float pivotY = 0.0f;
1904     int32_t adjustSize = TWELVE_SIZE * GetScaling();
1905     if ((g_drawingInfo.currentStyle == DragCursorStyle::DEFAULT) ||
1906         ((g_drawingInfo.currentStyle == DragCursorStyle::MOVE) && (g_drawingInfo.currentDragNum == DRAG_NUM_ONE))) {
1907         pivotX = -g_drawingInfo.pixelMapX * 1.0 / g_drawingInfo.pixelMap->GetWidth();
1908         pivotY = (-g_drawingInfo.pixelMapY + adjustSize) * 1.0 / g_drawingInfo.pixelMap->GetHeight();
1909     } else {
1910         pivotX = -g_drawingInfo.pixelMapX * 1.0 / (g_drawingInfo.pixelMap->GetWidth() + adjustSize);
1911         pivotY = (-g_drawingInfo.pixelMapY + adjustSize) * 1.0 / (g_drawingInfo.pixelMap->GetHeight() + adjustSize);
1912     }
1913     g_drawingInfo.parentNode->SetPivot(pivotX, pivotY);
1914     g_drawingInfo.parentNode->SetRotation(rotation);
1915     if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
1916         if (!CheckNodesValid()) {
1917             FI_HILOGE("Check nodes valid failed");
1918             return RET_ERR;
1919         }
1920         std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX];
1921         CHKPR(mouseIconNode, RET_ERR);
1922         mouseIconNode->SetPivot(DEFAULT_PIVOT, DEFAULT_PIVOT);
1923         mouseIconNode->SetRotation(rotation);
1924     }
1925     Rosen::RSTransaction::FlushImplicitTransaction();
1926     return RET_OK;
1927 }
1928 
ParserRadius(float & radius)1929 bool DragDrawing::ParserRadius(float &radius)
1930 {
1931     FI_HILOGD("ExtraInfo size:%{public}zu, extraInfo:%{public}s, filterInfo size:%{public}zu, filterInfo:%{public}s",
1932         g_drawingInfo.extraInfo.size(), g_drawingInfo.extraInfo.c_str(), g_drawingInfo.filterInfo.size(),
1933         g_drawingInfo.filterInfo.c_str());
1934     if (g_drawingInfo.extraInfo.empty() || g_drawingInfo.filterInfo.empty()) {
1935         FI_HILOGD("ExtraInfo or filterInfo is empty");
1936         return false;
1937     }
1938     JsonParser extraInfoParser;
1939     extraInfoParser.json = cJSON_Parse(g_drawingInfo.extraInfo.c_str());
1940     if (!cJSON_IsObject(extraInfoParser.json)) {
1941         FI_HILOGE("ExtraInfo is not json object");
1942         return false;
1943     }
1944     cJSON *cornerRadius = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "drag_corner_radius");
1945     if (!cJSON_IsNumber(cornerRadius)) {
1946         FI_HILOGE("Parser cornerRadius failed");
1947         return false;
1948     }
1949 
1950     JsonParser filterInfoParser;
1951     filterInfoParser.json = cJSON_Parse(g_drawingInfo.filterInfo.c_str());
1952     if (!cJSON_IsObject(filterInfoParser.json)) {
1953         FI_HILOGE("FilterInfo is not json object");
1954         return false;
1955     }
1956     cJSON *dipScale = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "dip_scale");
1957     if (!cJSON_IsNumber(dipScale)) {
1958         FI_HILOGE("Parser dipScale failed");
1959         return false;
1960     }
1961     if (cornerRadius->valuedouble < 0 || dipScale->valuedouble < 0 || fabs(dipScale->valuedouble) < EPSILON ||
1962         std::numeric_limits<float>::max() / dipScale->valuedouble < cornerRadius->valuedouble) {
1963         FI_HILOGE("Invalid parameters, cornerRadius:%{public}f, dipScale:%{public}f",
1964             cornerRadius->valuedouble, dipScale->valuedouble);
1965         return false;
1966     }
1967     radius = cornerRadius->valuedouble * dipScale->valuedouble;
1968     return true;
1969 }
1970 
Draw(Rosen::RSDrawingContext & context) const1971 void DrawSVGModifier::Draw(Rosen::RSDrawingContext& context) const
1972 {
1973     CALL_DEBUG_ENTER;
1974     CHKPV(stylePixelMap_);
1975     CHKPV(g_drawingInfo.pixelMap);
1976     float scalingValue = GetScaling();
1977     if (SCALE_THRESHOLD_EIGHT < scalingValue || fabsf(SCALE_THRESHOLD_EIGHT - scalingValue) < EPSILON) {
1978         FI_HILOGE("Invalid scalingValue:%{public}f", scalingValue);
1979         return;
1980     }
1981     int32_t adjustSize = EIGHT_SIZE * scalingValue;
1982     int32_t svgTouchPositionX = g_drawingInfo.pixelMap->GetWidth() + adjustSize - stylePixelMap_->GetWidth();
1983     if (!CheckNodesValid()) {
1984         FI_HILOGE("Check nodes valid failed");
1985         return;
1986     }
1987     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
1988     CHKPV(dragStyleNode);
1989     adjustSize = (TWELVE_SIZE - EIGHT_SIZE) * scalingValue;
1990     dragStyleNode->SetBounds(svgTouchPositionX, adjustSize, stylePixelMap_->GetWidth() + adjustSize,
1991         stylePixelMap_->GetHeight());
1992     dragStyleNode->SetFrame(svgTouchPositionX, adjustSize, stylePixelMap_->GetWidth() + adjustSize,
1993         stylePixelMap_->GetHeight());
1994     dragStyleNode->SetBgImageWidth(stylePixelMap_->GetWidth());
1995     dragStyleNode->SetBgImageHeight(stylePixelMap_->GetHeight());
1996     dragStyleNode->SetBgImagePositionX(0);
1997     dragStyleNode->SetBgImagePositionY(0);
1998     auto rosenImage = std::make_shared<Rosen::RSImage>();
1999     rosenImage->SetPixelMap(stylePixelMap_);
2000     rosenImage->SetImageRepeat(0);
2001     dragStyleNode->SetBgImage(rosenImage);
2002     Rosen::RSTransaction::FlushImplicitTransaction();
2003 }
2004 
Draw(Rosen::RSDrawingContext & context) const2005 void DrawPixelMapModifier::Draw(Rosen::RSDrawingContext &context) const
2006 {
2007     CALL_DEBUG_ENTER;
2008     CHKPV(g_drawingInfo.pixelMap);
2009     auto rosenImage = std::make_shared<Rosen::RSImage>();
2010     rosenImage->SetPixelMap(g_drawingInfo.pixelMap);
2011     rosenImage->SetImageRepeat(0);
2012     int32_t pixelMapWidth = g_drawingInfo.pixelMap->GetWidth();
2013     int32_t pixelMapHeight = g_drawingInfo.pixelMap->GetHeight();
2014     if (!CheckNodesValid()) {
2015         FI_HILOGE("Check nodes valid failed");
2016         return;
2017     }
2018     std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX];
2019     CHKPV(pixelMapNode);
2020     int32_t adjustSize = TWELVE_SIZE * GetScaling();
2021     pixelMapNode->SetBounds(DEFAULT_POSITION_X, adjustSize, pixelMapWidth, pixelMapHeight);
2022     pixelMapNode->SetFrame(DEFAULT_POSITION_X, adjustSize, pixelMapWidth, pixelMapHeight);
2023     pixelMapNode->SetBgImageWidth(pixelMapWidth);
2024     pixelMapNode->SetBgImageHeight(pixelMapHeight);
2025     pixelMapNode->SetBgImagePositionX(0);
2026     pixelMapNode->SetBgImagePositionY(0);
2027     pixelMapNode->SetBgImage(rosenImage);
2028     Rosen::RSTransaction::FlushImplicitTransaction();
2029 }
2030 
Draw(Rosen::RSDrawingContext & context) const2031 void DrawMouseIconModifier::Draw(Rosen::RSDrawingContext &context) const
2032 {
2033     CALL_DEBUG_ENTER;
2034     std::string imagePath;
2035     MMI::PointerStyle pointerStyle;
2036     int32_t ret = MMI::InputManager::GetInstance()->GetPointerStyle(GLOBAL_WINDOW_ID, pointerStyle);
2037     if (ret != RET_OK) {
2038         FI_HILOGE("Get pointer style failed, ret:%{public}d", ret);
2039         return;
2040     }
2041     int32_t pointerStyleId = pointerStyle.id;
2042     if (pointerStyleId == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) {
2043         imagePath = MOUSE_DRAG_CURSOR_CIRCLE_PATH;
2044     } else {
2045         imagePath = MOUSE_DRAG_DEFAULT_PATH;
2046     }
2047     Media::SourceOptions opts;
2048     opts.formatHint = "image/svg+xml";
2049     uint32_t errCode = 0;
2050     auto imageSource = Media::ImageSource::CreateImageSource(imagePath, opts, errCode);
2051     CHKPV(imageSource);
2052     int32_t pointerSize = pointerStyle.size;
2053     if (pointerSize < DEFAULT_MOUSE_SIZE) {
2054         FI_HILOGD("Invalid pointerSize:%{public}d", pointerSize);
2055         pointerSize = DEFAULT_MOUSE_SIZE;
2056     }
2057     Media::DecodeOptions decodeOpts;
2058     decodeOpts.desiredSize = {
2059         .width = pow(INCREASE_RATIO, pointerSize - 1) * DEVICE_INDEPENDENT_PIXEL * GetScaling(),
2060         .height = pow(INCREASE_RATIO, pointerSize - 1) * DEVICE_INDEPENDENT_PIXEL * GetScaling()
2061     };
2062     int32_t pointerColor = pointerStyle.color;
2063     if (pointerColor != INVALID_COLOR_VALUE) {
2064         decodeOpts.SVGOpts.fillColor = {.isValidColor = true, .color = pointerColor};
2065     }
2066     std::shared_ptr<Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode);
2067     CHKPV(pixelMap);
2068     OnDraw(pixelMap, pointerStyleId);
2069 }
2070 
OnDraw(std::shared_ptr<Media::PixelMap> pixelMap,int32_t pointerStyleId) const2071 void DrawMouseIconModifier::OnDraw(std::shared_ptr<Media::PixelMap> pixelMap, int32_t pointerStyleId) const
2072 {
2073     CALL_DEBUG_ENTER;
2074     CHKPV(pixelMap);
2075     if (!CheckNodesValid()) {
2076         FI_HILOGE("Check nodes valid failed");
2077         return;
2078     }
2079     g_drawingInfo.mouseWidth = pixelMap->GetWidth();
2080     g_drawingInfo.mouseHeight = pixelMap->GetHeight();
2081     std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX];
2082     CHKPV(mouseIconNode);
2083     mouseIconNode->SetBgImageWidth(pixelMap->GetWidth());
2084     mouseIconNode->SetBgImageHeight(pixelMap->GetHeight());
2085     mouseIconNode->SetBgImagePositionX(0);
2086     mouseIconNode->SetBgImagePositionY(0);
2087     auto rosenImage = std::make_shared<Rosen::RSImage>();
2088     rosenImage->SetPixelMap(pixelMap);
2089     rosenImage->SetImageRepeat(0);
2090     mouseIconNode->SetBgImage(rosenImage);
2091     Rosen::RSTransaction::FlushImplicitTransaction();
2092 }
2093 
Draw(Rosen::RSDrawingContext & context) const2094 void DrawDynamicEffectModifier::Draw(Rosen::RSDrawingContext &context) const
2095 {
2096     CALL_DEBUG_ENTER;
2097     CHKPV(alpha_);
2098     CHKPV(g_drawingInfo.parentNode);
2099     g_drawingInfo.parentNode->SetAlpha(alpha_->Get());
2100     CHKPV(scale_);
2101     g_drawingInfo.parentNode->SetScale(scale_->Get(), scale_->Get());
2102     Rosen::RSTransaction::FlushImplicitTransaction();
2103 }
2104 
SetAlpha(float alpha)2105 void DrawDynamicEffectModifier::SetAlpha(float alpha)
2106 {
2107     CALL_DEBUG_ENTER;
2108     if (alpha_ == nullptr) {
2109         alpha_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(alpha);
2110         Rosen::RSModifier::AttachProperty(alpha_);
2111         return;
2112     }
2113     alpha_->Set(alpha);
2114 }
2115 
SetScale(float scale)2116 void DrawDynamicEffectModifier::SetScale(float scale)
2117 {
2118     CALL_DEBUG_ENTER;
2119     if (scale_ == nullptr) {
2120         scale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale);
2121         Rosen::RSModifier::AttachProperty(scale_);
2122         return;
2123     }
2124     scale_->Set(scale);
2125 }
2126 
Draw(Rosen::RSDrawingContext & context) const2127 void DrawStyleChangeModifier::Draw(Rosen::RSDrawingContext &context) const
2128 {
2129     CALL_DEBUG_ENTER;
2130     if (!CheckNodesValid()) {
2131         FI_HILOGE("Check nodes valid failed");
2132         return;
2133     }
2134     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
2135     CHKPV(dragStyleNode);
2136     CHKPV(g_drawingInfo.pixelMap);
2137     float pixelMapWidth = g_drawingInfo.pixelMap->GetWidth();
2138     if (stylePixelMap_ == nullptr) {
2139         if (scale_ == nullptr) {
2140             return;
2141         }
2142         dragStyleNode->SetScale(scale_->Get());
2143         return;
2144     }
2145     float scalingValue = GetScaling();
2146     if ((1.0 * INT_MAX / EIGHT_SIZE) <= scalingValue) {
2147         return;
2148     }
2149     int32_t adjustSize = EIGHT_SIZE * scalingValue;
2150     int32_t svgTouchPositionX = pixelMapWidth + adjustSize - stylePixelMap_->GetWidth();
2151     dragStyleNode->SetBounds(svgTouchPositionX, (TWELVE_SIZE-EIGHT_SIZE)*scalingValue, stylePixelMap_->GetWidth(),
2152         stylePixelMap_->GetHeight());
2153     dragStyleNode->SetFrame(svgTouchPositionX, (TWELVE_SIZE-EIGHT_SIZE)*scalingValue, stylePixelMap_->GetWidth(),
2154         stylePixelMap_->GetHeight());
2155     dragStyleNode->SetBgImageWidth(stylePixelMap_->GetWidth());
2156     dragStyleNode->SetBgImageHeight(stylePixelMap_->GetHeight());
2157     dragStyleNode->SetBgImagePositionX(0);
2158     dragStyleNode->SetBgImagePositionY(0);
2159     auto rosenImage = std::make_shared<Rosen::RSImage>();
2160     rosenImage->SetPixelMap(stylePixelMap_);
2161     rosenImage->SetImageRepeat(0);
2162     dragStyleNode->SetBgImage(rosenImage);
2163     Rosen::RSTransaction::FlushImplicitTransaction();
2164 }
2165 
SetScale(float scale)2166 void DrawStyleChangeModifier::SetScale(float scale)
2167 {
2168     CALL_DEBUG_ENTER;
2169     if (scale_ == nullptr) {
2170         scale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale);
2171         Rosen::RSModifier::AttachProperty(scale_);
2172     } else {
2173         scale_->Set(scale);
2174     }
2175 }
2176 
Draw(Rosen::RSDrawingContext & context) const2177 void DrawStyleScaleModifier::Draw(Rosen::RSDrawingContext &context) const
2178 {
2179     CALL_DEBUG_ENTER;
2180     if (!CheckNodesValid()) {
2181         FI_HILOGE("Check nodes valid failed");
2182         return;
2183     }
2184     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
2185     CHKPV(dragStyleNode);
2186     CHKPV(scale_);
2187     dragStyleNode->SetScale(scale_->Get());
2188 }
2189 
SetScale(float scale)2190 void DrawStyleScaleModifier::SetScale(float scale)
2191 {
2192     CALL_DEBUG_ENTER;
2193     if (scale_ == nullptr) {
2194         scale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale);
2195         Rosen::RSModifier::AttachProperty(scale_);
2196     } else {
2197         scale_->Set(scale);
2198     }
2199 }
2200 
Draw(Rosen::RSDrawingContext & context) const2201 void DrawDragStopModifier::Draw(Rosen::RSDrawingContext &context) const
2202 {
2203     CALL_DEBUG_ENTER;
2204     CHKPV(alpha_);
2205     CHKPV(scale_);
2206     if (!CheckNodesValid()) {
2207         FI_HILOGE("Check nodes valid failed");
2208         return;
2209     }
2210     CHKPV(g_drawingInfo.parentNode);
2211     g_drawingInfo.parentNode->SetAlpha(alpha_->Get());
2212     g_drawingInfo.parentNode->SetScale(scale_->Get(), scale_->Get());
2213     std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
2214     CHKPV(dragStyleNode);
2215     dragStyleNode->SetScale(styleScale_->Get());
2216     dragStyleNode->SetAlpha(styleAlpha_->Get());
2217 }
2218 
SetAlpha(float alpha)2219 void DrawDragStopModifier::SetAlpha(float alpha)
2220 {
2221     CALL_DEBUG_ENTER;
2222     if (alpha_ == nullptr) {
2223         alpha_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(alpha);
2224         Rosen::RSModifier::AttachProperty(alpha_);
2225     } else {
2226         alpha_->Set(alpha);
2227     }
2228 }
2229 
SetScale(float scale)2230 void DrawDragStopModifier::SetScale(float scale)
2231 {
2232     CALL_DEBUG_ENTER;
2233     if (scale_ == nullptr) {
2234         scale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale);
2235         Rosen::RSModifier::AttachProperty(scale_);
2236     } else {
2237         scale_->Set(scale);
2238     }
2239 }
2240 
SetStyleScale(float scale)2241 void DrawDragStopModifier::SetStyleScale(float scale)
2242 {
2243     CALL_DEBUG_ENTER;
2244     if (styleScale_ == nullptr) {
2245         styleScale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale);
2246         Rosen::RSModifier::AttachProperty(styleScale_);
2247     } else {
2248         styleScale_->Set(scale);
2249     }
2250 }
2251 
SetStyleAlpha(float alpha)2252 void DrawDragStopModifier::SetStyleAlpha(float alpha)
2253 {
2254     CALL_DEBUG_ENTER;
2255     if (styleAlpha_ == nullptr) {
2256         styleAlpha_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(alpha);
2257         Rosen::RSModifier::AttachProperty(styleAlpha_);
2258     } else {
2259         styleAlpha_->Set(alpha);
2260     }
2261 }
2262 } // namespace DeviceStatus
2263 } // namespace Msdp
2264 } // namespace OHOS
2265