!1143 Add optional trailing effect code

Merge pull request !1143 from 邢江盼/xing_drag_drawing_001
This commit is contained in:
openharmony_ci 2023-11-20 06:10:21 +00:00 committed by Gitee
commit b097dedc1c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 64 additions and 48 deletions

View File

@ -237,7 +237,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Drag
std::promise<bool> promiseFlag;
std::future<bool> 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);
};

View File

@ -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<Rosen::RSCanvasNode> canvasNode_ { nullptr };
@ -180,7 +182,8 @@ private:
std::shared_ptr<Rosen::RSUIDirector> rsUiDirector_ { nullptr };
std::shared_ptr<Rosen::VSyncReceiver> receiver_ { nullptr };
std::shared_ptr<AppExecFwk::EventHandler> handler_ { nullptr };
void* dragExtHandle_ = nullptr;
void* dragExtHandle_ { nullptr };
bool needDestroyDragWindow_ { false };
};
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -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<Rosen::RSCanvasNode> 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<Media::PixelMap> 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<Rosen::RSCanvasNode> 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<Rosen::RSCanvasNode> 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<Rosen::RSSurfaceNode> 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<Rosen::RSCanvasNode> 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,14 +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);
receiver_ = Rosen::RSInterfaces::GetInstance().CreateVSyncReceiver("DragDrawing", handler_);
@ -716,14 +687,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 +1282,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<Rosen::RSCanvasNode> 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<Media::PixelMap> 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<Rosen::RSCanvasNode> 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) {