From 3ebf119539595388580b8ed5ea23b2e043f5c000 Mon Sep 17 00:00:00 2001 From: xing-jiangpan Date: Sat, 18 Nov 2023 10:56:19 +0000 Subject: [PATCH 1/2] Add optional trailing effect code Signed-off-by: xing-jiangpan Change-Id: I5a1b31030330ec10b7d42407c0022c0c4473e161 --- .../src/interaction_drag_drawing_test.cpp | 2 +- .../interaction/drag/include/drag_drawing.h | 5 +- .../interaction/drag/src/drag_drawing.cpp | 104 ++++++++++-------- 3 files changed, 64 insertions(+), 47 deletions(-) diff --git a/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp b/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp index 1fbfb924e..d7a827989 100644 --- a/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp +++ b/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp @@ -237,7 +237,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Drag std::promise promiseFlag; std::future futureFlag = promiseFlag.get_future(); auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) { - FI_HILOGD("displayX:%{public}d, displayY:%{public}d, arget:%{public}d, result:%{public}d", + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, target:%{public}d, result:%{public}d", notifyMessage.displayX, notifyMessage.displayY, notifyMessage.targetPid, notifyMessage.result); promiseFlag.set_value(true); }; diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index f58deef26..603c90dd4 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -170,6 +170,8 @@ private: static float RadiusVp2Sigma(float radiusVp, float dipScale); void DoDrawMouse(); int32_t UpdateDefaultDragStyle(DragCursorStyle style); + int32_t UpdateValidDragStyle(DragCursorStyle style); + private: int64_t startNum_ { -1 }; std::shared_ptr canvasNode_ { nullptr }; @@ -180,7 +182,8 @@ private: std::shared_ptr rsUiDirector_ { nullptr }; std::shared_ptr receiver_ { nullptr }; std::shared_ptr handler_ { nullptr }; - void* dragExtHandle_ = nullptr; + void* dragExtHandle_ { nullptr }; + bool needDestroyDragWindow_ { false }; }; } // namespace DeviceStatus } // namespace Msdp diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 1892243d4..8a1ea8897 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -289,42 +289,7 @@ int32_t DragDrawing::UpdateDragStyle(DragCursorStyle style) ((style == DragCursorStyle::MOVE) && (g_drawingInfo.currentDragNum == DRAG_NUM_ONE))) { return UpdateDefaultDragStyle(style); } - g_drawingInfo.currentStyle = style; - if (g_drawingInfo.isCurrentDefaultStyle) { - if (!CheckNodesValid()) { - FI_HILOGE("Check nodes valid failed"); - return RET_ERR; - } - std::shared_ptr dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; - CHKPR(dragStyleNode, RET_ERR); - CHKPR(g_drawingInfo.parentNode, RET_ERR); - g_drawingInfo.parentNode->AddChild(dragStyleNode); - } - std::string filePath; - if (GetFilePath(filePath) != RET_OK) { - FI_HILOGD("Get file path failed"); - return RET_ERR; - } - if (!IsValidSvgFile(filePath)) { - FI_HILOGE("Svg file is invalid"); - return RET_ERR; - } - std::shared_ptr pixelMap = DecodeSvgToPixelMap(filePath); - CHKPR(pixelMap, RET_ERR); - bool isPreviousDefaultStyle = g_drawingInfo.isCurrentDefaultStyle; - g_drawingInfo.isPreviousDefaultStyle = isPreviousDefaultStyle; - g_drawingInfo.isCurrentDefaultStyle = false; - g_drawingInfo.stylePixelMap = pixelMap; - if (!CheckNodesValid()) { - FI_HILOGE("Check nodes valid failed"); - return RET_ERR; - } - std::shared_ptr dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; - CHKPR(dragStyleNode, RET_ERR); - OnDragStyle(dragStyleNode, pixelMap); - CHKPR(rsUiDirector_, RET_ERR); - rsUiDirector_->SendMessages(); - return RET_OK; + return UpdateValidDragStyle(style); } int32_t DragDrawing::UpdateShadowPic(const ShadowInfo &shadowInfo) @@ -404,6 +369,7 @@ void DragDrawing::DestroyDragWindow() { CALL_INFO_TRACE; startNum_ = START_TIME; + needDestroyDragWindow_ = false; g_drawingInfo.sourceType = -1; g_drawingInfo.currentDragNum = -1; g_drawingInfo.pixelMapX = -1; @@ -557,6 +523,8 @@ void DragDrawing::OnStopDragSuccess(std::shared_ptr shadowN FI_HILOGE("Send animationExtFunc failed"); RunAnimation(END_ALPHA, END_SCALE_SUCCESS); } else { + startNum_ = START_TIME; + needDestroyDragWindow_ = true; StartVsync(); } } @@ -587,6 +555,8 @@ void DragDrawing::OnStopDragFail(std::shared_ptr surfaceNo FI_HILOGE("Send animationExtFunc failed"); RunAnimation(END_ALPHA, END_SCALE_FAIL); } else { + startNum_ = START_TIME; + needDestroyDragWindow_ = true; StartVsync(); } } @@ -658,7 +628,6 @@ int32_t DragDrawing::DrawStyle(std::shared_ptr dragStyleNod int32_t DragDrawing::InitVSync(float endAlpha, float endScale) { CALL_DEBUG_ENTER; - startNum_ = START_TIME; CHKPR(g_drawingInfo.rootNode, RET_ERR); if (drawDynamicEffectModifier_ != nullptr) { g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); @@ -675,13 +644,16 @@ int32_t DragDrawing::InitVSync(float endAlpha, float endScale) drawDynamicEffectModifier_->SetAlpha(endAlpha); drawDynamicEffectModifier_->SetScale(endScale); }); + CHKPR(g_drawingInfo.parentNode, RET_ERR); + g_drawingInfo.parentNode->SetPivot(PIVOT_X, PIVOT_Y); + Rosen::RSTransaction::FlushImplicitTransaction(); + startNum_ = START_TIME; + needDestroyDragWindow_ = true; return StartVsync(); } int32_t DragDrawing::StartVsync() { - CHKPR(g_drawingInfo.parentNode, RET_ERR); - g_drawingInfo.parentNode->SetPivot(PIVOT_X, PIVOT_Y); Rosen::RSTransaction::FlushImplicitTransaction(); if (receiver_ == nullptr) { CHKPR(handler_, RET_ERR); @@ -716,14 +688,16 @@ void DragDrawing::OnVsync() handler_->RemoveAllEvents(); handler_->RemoveAllFileDescriptorListeners(); handler_ = nullptr; - g_drawingInfo.isRunning = false; receiver_ = nullptr; - CHKPV(g_drawingInfo.rootNode); - if (drawDynamicEffectModifier_ != nullptr) { - g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); - drawDynamicEffectModifier_ = nullptr; + if (needDestroyDragWindow_) { + g_drawingInfo.isRunning = false; + CHKPV(g_drawingInfo.rootNode); + if (drawDynamicEffectModifier_ != nullptr) { + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); + drawDynamicEffectModifier_ = nullptr; + } + DestroyDragWindow(); } - DestroyDragWindow(); return; } rsUiDirector_->SendMessages(); @@ -1309,6 +1283,46 @@ int32_t DragDrawing::UpdateDefaultDragStyle(DragCursorStyle style) return RET_OK; } +int32_t DragDrawing::UpdateValidDragStyle(DragCursorStyle style) +{ + g_drawingInfo.currentStyle = style; + if (g_drawingInfo.isCurrentDefaultStyle) { + if (!CheckNodesValid()) { + FI_HILOGE("Check nodes valid failed"); + return RET_ERR; + } + std::shared_ptr dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; + CHKPR(dragStyleNode, RET_ERR); + CHKPR(g_drawingInfo.parentNode, RET_ERR); + g_drawingInfo.parentNode->AddChild(dragStyleNode); + } + std::string filePath; + if (GetFilePath(filePath) != RET_OK) { + FI_HILOGD("Get file path failed"); + return RET_ERR; + } + if (!IsValidSvgFile(filePath)) { + FI_HILOGE("Svg file is invalid"); + return RET_ERR; + } + std::shared_ptr pixelMap = DecodeSvgToPixelMap(filePath); + CHKPR(pixelMap, RET_ERR); + bool isPreviousDefaultStyle = g_drawingInfo.isCurrentDefaultStyle; + g_drawingInfo.isPreviousDefaultStyle = isPreviousDefaultStyle; + g_drawingInfo.isCurrentDefaultStyle = false; + g_drawingInfo.stylePixelMap = pixelMap; + if (!CheckNodesValid()) { + FI_HILOGE("Check nodes valid failed"); + return RET_ERR; + } + std::shared_ptr dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; + CHKPR(dragStyleNode, RET_ERR); + OnDragStyle(dragStyleNode, pixelMap); + CHKPR(rsUiDirector_, RET_ERR); + rsUiDirector_->SendMessages(); + return RET_OK; +} + DragDrawing::~DragDrawing() { if (dragExtHandle_ != nullptr) { From be5688fee297bf293adb4f2c1528f6249117ee0d Mon Sep 17 00:00:00 2001 From: xing-jiangpan Date: Mon, 20 Nov 2023 01:37:03 +0000 Subject: [PATCH 2/2] Add optional trailing effect code Signed-off-by: xing-jiangpan Change-Id: Ic1c4a702f05078e18935b3ceae4894b16e999b3e --- services/interaction/drag/src/drag_drawing.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 8a1ea8897..e01a296e3 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -654,7 +654,6 @@ int32_t DragDrawing::InitVSync(float endAlpha, float endScale) int32_t DragDrawing::StartVsync() { - Rosen::RSTransaction::FlushImplicitTransaction(); if (receiver_ == nullptr) { CHKPR(handler_, RET_ERR); receiver_ = Rosen::RSInterfaces::GetInstance().CreateVSyncReceiver("DragDrawing", handler_);