From 732da76ab23a23386d53cf84e0e4342bc956541d Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Tue, 14 Mar 2023 13:41:37 +0000 Subject: [PATCH 01/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I7915b746f54cdca145b62df83c2bea33294aeebd --- etc/drag_icon/BUILD.gn | 51 ++ etc/drag_icon/src/Copy_Drag.svg | 18 + etc/drag_icon/src/Copy_One_Drag.svg | 15 + etc/drag_icon/src/Forbid_Drag.svg | 17 + etc/drag_icon/src/Mouse_Drag.png | Bin 0 -> 522 bytes services/BUILD.gn | 4 +- services/interaction/drag/BUILD.gn | 7 + .../interaction/drag/include/drag_drawing.h | 120 +++ .../interaction/drag/include/drag_manager.h | 5 +- .../interaction/drag/src/drag_drawing.cpp | 753 ++++++++++++++++++ .../interaction/drag/src/drag_manager.cpp | 42 +- .../native/include/devicestatus_service.h | 1 + services/native/src/devicestatus_service.cpp | 19 +- utils/common/include/util.h | 6 + utils/common/src/util.cpp | 69 ++ 15 files changed, 1122 insertions(+), 5 deletions(-) create mode 100644 etc/drag_icon/BUILD.gn create mode 100644 etc/drag_icon/src/Copy_Drag.svg create mode 100644 etc/drag_icon/src/Copy_One_Drag.svg create mode 100644 etc/drag_icon/src/Forbid_Drag.svg create mode 100644 etc/drag_icon/src/Mouse_Drag.png create mode 100644 services/interaction/drag/include/drag_drawing.h create mode 100644 services/interaction/drag/src/drag_drawing.cpp diff --git a/etc/drag_icon/BUILD.gn b/etc/drag_icon/BUILD.gn new file mode 100644 index 000000000..6f3cf80d5 --- /dev/null +++ b/etc/drag_icon/BUILD.gn @@ -0,0 +1,51 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/msdp/device_status/device_status.gni") + +ohos_prebuilt_etc("drawing_image_Copy_Drag") { + source = "src/Copy_Drag.svg" + part_name = "${device_status_part_name}" + subsystem_name = "device_status" + relative_install_dir = "device_status/drag_icon" +} + +ohos_prebuilt_etc("drawing_image_Forbid_Drag") { + source = "src/Forbid_Drag.svg" + part_name = "${device_status_part_name}" + subsystem_name = "device_status" + relative_install_dir = "device_status/drag_icon" +} + +ohos_prebuilt_etc("drawing_image_Copy_One_Drag") { + source = "src/Copy_One_Drag.svg" + part_name = "${device_status_part_name}" + subsystem_name = "device_status" + relative_install_dir = "device_status/drag_icon" +} + +ohos_prebuilt_etc("drawing_image_Mouse_Drag") { + source = "src/Mouse_Drag.png" + part_name = "${device_status_part_name}" + subsystem_name = "device_status" + relative_install_dir = "device_status/drag_icon" +} + +group("device_status_drag_icon") { + deps = [ + ":drawing_image_Copy_Drag", + ":drawing_image_Copy_One_Drag", + ":drawing_image_Forbid_Drag", + ":drawing_image_Mouse_Drag", + ] +} diff --git a/etc/drag_icon/src/Copy_Drag.svg b/etc/drag_icon/src/Copy_Drag.svg new file mode 100644 index 000000000..d35590b4b --- /dev/null +++ b/etc/drag_icon/src/Copy_Drag.svg @@ -0,0 +1,18 @@ + + + Cursor/Copy备份 + + + + + + + + + + 8 + + + + + \ No newline at end of file diff --git a/etc/drag_icon/src/Copy_One_Drag.svg b/etc/drag_icon/src/Copy_One_Drag.svg new file mode 100644 index 000000000..e8eb03eea --- /dev/null +++ b/etc/drag_icon/src/Copy_One_Drag.svg @@ -0,0 +1,15 @@ + + + Cursor/Copy备份 + + + + + + + + + + + + \ No newline at end of file diff --git a/etc/drag_icon/src/Forbid_Drag.svg b/etc/drag_icon/src/Forbid_Drag.svg new file mode 100644 index 000000000..c2d698340 --- /dev/null +++ b/etc/drag_icon/src/Forbid_Drag.svg @@ -0,0 +1,17 @@ + + + Cursor/Forbid + + + + + + + + + + + + + + \ No newline at end of file diff --git a/etc/drag_icon/src/Mouse_Drag.png b/etc/drag_icon/src/Mouse_Drag.png new file mode 100644 index 0000000000000000000000000000000000000000..6308171fe9d612050376f6a5dfdc870e51bc92db GIT binary patch literal 522 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(&7aK09DS?;h@)n>(w zU77zQXSuG~_Vy8v33K!P7bm_yUcX@Svdm|xk@w1C%MBhDGF)SI{17H`RCu}vlS{!L zCCv%ZDe@;&i#VR}{gj=c{lwoPZ^G?{7=?OfBlmYqDP4C&Pw@N{f1qB}ng3n(RpBwS z1-ZAMe3~8@dbLJIcGrY=PaKx7dp$d9(h@!2%S_RI?##T>UmN=#ueoO!5_(r*V$$sA zKd*k+ck!CYi(Prm<=TgT>F^w8Wyn_fEW&x=`(M?6?DGTV65l;mFI%YLPBzD z8Qv=8{5Pi9nO#{PC}JC=;A!Y7^hs~t1zVqfm808ojeRc{b(#21UQ%&Z#m1>zOkKJ?!T{$GzTFckq`?ald5N4T%|&a;7<7S+i;@V%NAb rDKSoL@NiI35E9_*U~yskZ`a75v-6BzVow+-o)|n`{an^LB{Ts5(G + +#include "event_handler.h" +#include "event_runner.h" +#include "libxml/tree.h" +#include "libxml/parser.h" +#include "modifier/rs_extended_modifier.h" +#include "modifier/rs_modifier.h" +#include "pixel_map.h" +#include "ui/rs_canvas_node.h" +#include "vsync_receiver.h" + +#include "drag_data.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +class DrawSVGModifier : public OHOS::Rosen::RSContentStyleModifier { +public: + DrawSVGModifier() = default; + ~DrawSVGModifier() = default; + void Draw(OHOS::Rosen::RSDrawingContext& context) const override; + +private: + int32_t UpdateSvgNodeInfo(xmlNodePtr &curNode, int32_t strSize) const; + xmlNodePtr FindRectNode(xmlNodePtr &curNode) const; + xmlNodePtr UpdateRectNode(xmlNodePtr &curNode, int32_t strSize) const; + void UpdateTspanNode(xmlNodePtr &curNode) const; + int32_t ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const; + std::shared_ptr DecodeSvgToPixelMap(const std::string &filePath) const; +}; + +class DrawPixelMapModifier : public OHOS::Rosen::RSContentStyleModifier { +public: + DrawPixelMapModifier() = default; + ~DrawPixelMapModifier() = default; + void Draw(OHOS::Rosen::RSDrawingContext &context) const override; +}; + +class DrawMouseIconModifier : public OHOS::Rosen::RSContentStyleModifier { +public: + DrawMouseIconModifier() = default; + ~DrawMouseIconModifier() = default; + void Draw(OHOS::Rosen::RSDrawingContext &context) const override; + +private: + int32_t GetIconSize() const; +}; + +class DrawDynamicEffectModifier : public OHOS::Rosen::RSContentStyleModifier { +public: + DrawDynamicEffectModifier() = default; + ~DrawDynamicEffectModifier() = default; + void Draw(OHOS::Rosen::RSDrawingContext &context) const override; + void SetAlpha(float alpha); + void SetScale(float scale); +private: + std::shared_ptr> alpha_; + std::shared_ptr> scale_; +}; + +class DragDrawing final { +public: + DragDrawing() = default; + ~DragDrawing() = default; + DISALLOW_COPY_AND_MOVE(DragDrawing); + + int32_t Init(const DragData &dragData); + void Draw(int32_t displayId, int32_t displayX, int32_t displayY); + int32_t UpdateDragStyle(int32_t style); + void OnDragSuccess(); + void OnDragFail(); + void EraseMouseIcon(); + void DestroyDragWindow(); + +private: + int32_t InitLayer(); + void InitCanvas(int32_t width, int32_t height); + void CreateWindow(int32_t displayX, int32_t displayY); + int32_t DrawShadowPic(); + int32_t DrawMouseIcon(); + int32_t DrawStyle(); + void InitAnimation(); + int32_t InitVSync(); + void OnVsync(); + +private: + int64_t startNum_ { -1 }; + std::shared_ptr canvasNode_ { nullptr }; + std::shared_ptr drawSVGModifier_ { nullptr }; + std::shared_ptr drawPixelMapModifier_ { nullptr }; + std::shared_ptr drawMouseIconModifier_ { nullptr }; + std::shared_ptr drawDynamicEffectModifier_ { nullptr }; + std::shared_ptr rsUiDirector_ { nullptr }; + std::shared_ptr receiver_ { nullptr }; + std::shared_ptr handler_ { nullptr }; + std::shared_ptr runner_ { nullptr }; +}; +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS +#endif // DRAG_DRAWING_MANAGER_H \ No newline at end of file diff --git a/services/interaction/drag/include/drag_manager.h b/services/interaction/drag/include/drag_manager.h index f6ea9c28e..430a0f452 100644 --- a/services/interaction/drag/include/drag_manager.h +++ b/services/interaction/drag/include/drag_manager.h @@ -25,6 +25,7 @@ #include "devicestatus_define.h" #include "drag_data.h" +#include "drag_drawing.h" #include "state_change_notify.h" #include "stream_session.h" @@ -43,6 +44,7 @@ public: int32_t StartDrag(const DragData &dragData, SessionPtr sess); int32_t StopDrag(int32_t result); int32_t GetDragTargetPid() const; + int32_t UpdateDragStyle(int32_t style); void DragCallback(std::shared_ptr pointerEvent); void OnDragUp(std::shared_ptr pointerEvent); void OnDragMove(std::shared_ptr pointerEvent); @@ -61,13 +63,14 @@ private: OHOS::MMI::ExtraData CreateExtraData(bool appended) const; int32_t InitDataAdapter(const DragData &dragData) const; int32_t OnStartDrag(); - int32_t OnStopDrag(); + int32_t OnStopDrag(int32_t result); private: StateChangeNotify stateNotify_; DragMessage dragState_ { DragMessage::MSG_DRAG_STATE_STOP }; int32_t monitorId_ { -1 }; int32_t dragTargetPid_ { -1 }; SessionPtr dragOutSession_ { nullptr }; + DragDrawing dragDrawing_; }; #define INPUT_MANAGER OHOS::MMI::InputManager::GetInstance() } // namespace DeviceStatus diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp new file mode 100644 index 000000000..ef17a9670 --- /dev/null +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -0,0 +1,753 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "drag_drawing.h" + +#include +#include +#include + +#include "display_manager.h" +#include "include/core/SkTextBlob.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "libxml/tree.h" +#include "libxml/parser.h" +#include "string_ex.h" +#include "pointer_event.h" +#include "transaction/rs_interfaces.h" +#include "transaction/rs_transaction.h" +#include "ui/rs_root_node.h" +#include "ui/rs_surface_extractor.h" +#include "ui/rs_surface_node.h" +#include "ui/rs_ui_director.h" +#include "../wm/window.h" + +#include "devicestatus_define.h" +#include "drag_data_adapter.h" +#include "util.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DragDrawing" }; +constexpr int32_t BASELINE_DENSITY = 160; +constexpr int32_t DEVICE_INDEPENDENT_PIXELS = 40; +constexpr int32_t EIGHT_SIZE = 8; +constexpr int32_t IMAGE_WIDTH = 400; +constexpr int32_t IMAGE_HEIGHT = 500; +constexpr int64_t START_TIME = 181154000809; +constexpr int64_t INTERVAL_TIME = 16666667; +constexpr int32_t FRAMERATE = 30; +constexpr int32_t SVG_HEIGHT = 40; +constexpr int32_t SIXTEEN = 16; +constexpr int32_t FAIL_ANIMATION_DURATION = 1000; +constexpr int32_t SUCCESS_ANIMATION_DURATION = 300; +constexpr int32_t VIEW_BOX_POS = 2; +constexpr int32_t PIXEL_MAP_INDEX = 0; +constexpr int32_t DRAG_STYLE_INDEX = 1; +constexpr int32_t MOUSE_ICON_INDEX = 2; +constexpr size_t TOUCH_NODE_MIN_COUNT = 2; +constexpr size_t MOUSE_NODE_MIN_COUNT = 3; +constexpr double ONETHOUSAND = 1000.0; +constexpr float SUCCESS_ENLARGE_SCALE = 1.2f; +constexpr float FAIL_ENLARGE_SCALE = 0.1f; +constexpr float PIVOT_X = 0.5f; +constexpr float PIVOT_Y = 0.5f; +const std::string COPY_DRAG_PATH = "/system/etc/device_status/drag_icon/Copy_Drag.svg"; +const std::string COPY_ONE_DRAG_PATH = "/system/etc/device_status/drag_icon/Copy_One_Drag.svg"; +const std::string FORBID_DRAG_PATH = "/system/etc/device_status/drag_icon/Forbid_Drag.svg"; +const std::string MOUSE_DRAG_PATH = "/system/etc/device_status/drag_icon/Mouse_Drag.png"; +struct DrawingInfo { + int32_t sourceType { -1 }; + int32_t currentStyle { -1 }; + int32_t displayId { -1 }; + int32_t pixelMapX { -1 }; + int32_t pixelMapY { -1 }; + int32_t displayX { -1 }; + int32_t displayY { -1 }; + int32_t rootNodeWidth { -1 }; + int32_t rootNodeHeight { -1 }; + sptr dragWindow { nullptr }; + std::vector> nodes; + std::shared_ptr rootNode { nullptr }; + std::shared_ptr surfaceNode { nullptr }; + std::shared_ptr pixelMap { nullptr }; +} g_drawingInfo; +} // namespace + +int32_t DragDrawing::Init(const DragData &dragData) +{ + CALL_DEBUG_ENTER; + CHKPR(dragData.pictureResourse.pixelMap, RET_ERR); + if ((dragData.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && + (dragData.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN)) { + FI_HILOGE("Invalid sourceType:%{public}d", dragData.sourceType); + return RET_ERR; + } + g_drawingInfo.sourceType = dragData.sourceType; + g_drawingInfo.displayId = dragData.displayId; + g_drawingInfo.pixelMap = dragData.pictureResourse.pixelMap; + g_drawingInfo.pixelMapX = dragData.pictureResourse.x; + g_drawingInfo.pixelMapY = dragData.pictureResourse.y; + CreateWindow(dragData.displayX, dragData.displayY); + CHKPR(g_drawingInfo.dragWindow, RET_ERR); + if (InitLayer() != RET_OK) { + FI_HILOGE("Init Layer failed"); + return RET_ERR; + } + if (DrawShadowPic() != RET_OK) { + FI_HILOGE("Draw shadow picture failed"); + return RET_ERR; + } + if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { + g_drawingInfo.dragWindow->Show(); + InitAnimation(); + return RET_OK; + } + if (DrawMouseIcon() != RET_OK) { + FI_HILOGE("Draw mouse icon failed"); + return RET_ERR; + } + g_drawingInfo.dragWindow->Show(); + InitAnimation(); + return RET_OK; +} + +void DragDrawing::Draw(int32_t displayId, int32_t displayX, int32_t displayY) +{ + CALL_DEBUG_ENTER; + if (displayId < 0) { + FI_HILOGE("Invalid display:%{public}d", displayId); + return; + } + g_drawingInfo.displayId = displayId; + g_drawingInfo.displayX = displayX; + g_drawingInfo.displayY = displayY; + if (displayX < 0) { + g_drawingInfo.displayX = 0; + } + if (displayY < 0) { + g_drawingInfo.displayY = 0; + } + + if (g_drawingInfo.dragWindow != nullptr) { + g_drawingInfo.dragWindow->MoveTo(g_drawingInfo.displayX + g_drawingInfo.pixelMapX, + g_drawingInfo.displayY + g_drawingInfo.pixelMapY); + return; + } + CreateWindow(g_drawingInfo.displayX + g_drawingInfo.pixelMapX, g_drawingInfo.displayY + g_drawingInfo.pixelMapY); + g_drawingInfo.dragWindow->Show(); +} + +int32_t DragDrawing::UpdateDragStyle(int32_t style) +{ + CALL_DEBUG_ENTER; + CHKPR(rsUiDirector_, RET_ERR); + if (style < 0) { + FI_HILOGE("Invalid style:%{public}d", style); + return RET_ERR; + } + if (g_drawingInfo.currentStyle == style) { + FI_HILOGD("No need update drag style"); + return RET_OK; + } + g_drawingInfo.currentStyle = style; + DrawStyle(); + rsUiDirector_->SendMessages(); + return RET_OK; +} + +void DragDrawing::OnDragSuccess() +{ + CALL_DEBUG_ENTER; + CHKPV(runner_); + CHKPV(rsUiDirector_); + CHKPV(g_drawingInfo.rootNode); + if (drawDynamicEffectModifier_ != nullptr){ + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); + } + drawDynamicEffectModifier_ = std::make_shared(); + g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); + drawDynamicEffectModifier_->SetAlpha(1); + drawDynamicEffectModifier_->SetScale(1); + + OHOS::Rosen::RSAnimationTimingProtocol protocol; + protocol.SetDuration(SUCCESS_ANIMATION_DURATION); + OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { + drawDynamicEffectModifier_->SetAlpha(0); + drawDynamicEffectModifier_->SetScale(SUCCESS_ENLARGE_SCALE); + }); + runner_->Run(); +} + +void DragDrawing::OnDragFail() +{ + CALL_DEBUG_ENTER; + CHKPV(runner_); + CHKPV(rsUiDirector_); + CHKPV(g_drawingInfo.rootNode); + if (drawDynamicEffectModifier_ != nullptr){ + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); + } + drawDynamicEffectModifier_ = std::make_shared(); + g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); + drawDynamicEffectModifier_->SetAlpha(1); + drawDynamicEffectModifier_->SetScale(1); + + OHOS::Rosen::RSAnimationTimingProtocol protocol; + protocol.SetDuration(FAIL_ANIMATION_DURATION); + OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { + drawDynamicEffectModifier_->SetAlpha(0); + drawDynamicEffectModifier_->SetScale(FAIL_ENLARGE_SCALE); + }); + runner_->Run(); +} + +void DragDrawing::EraseMouseIcon() +{ + CALL_DEBUG_ENTER; + CHKPV(g_drawingInfo.rootNode); + CHKPV(rsUiDirector_); + if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) { + FI_HILOGE("Canvas nodes vector size invalid, nodes.size(): %{public}d", g_drawingInfo.nodes.size()); + return; + } + if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { + FI_HILOGE("Touch type not need erase mouse icon"); + return; + } + g_drawingInfo.rootNode->RemoveChild(g_drawingInfo.nodes[MOUSE_ICON_INDEX]); + rsUiDirector_->SendMessages(); +} + +void DragDrawing::DestroyDragWindow() +{ + CALL_DEBUG_ENTER; + g_drawingInfo.sourceType = -1; + startNum_ = START_TIME; + g_drawingInfo.currentStyle = -1; + if (g_drawingInfo.pixelMap != nullptr) { + g_drawingInfo.pixelMap = nullptr; + } + if (!g_drawingInfo.nodes.empty()) { + g_drawingInfo.nodes.clear(); + } + if (g_drawingInfo.rootNode != nullptr) { + g_drawingInfo.rootNode->ClearChildren(); + g_drawingInfo.rootNode = nullptr; + } + if (g_drawingInfo.surfaceNode != nullptr) { + g_drawingInfo.surfaceNode = nullptr; + } + if (g_drawingInfo.dragWindow != nullptr) { + g_drawingInfo.dragWindow->Destroy(); + g_drawingInfo.dragWindow = nullptr; + } + if (rsUiDirector_ != nullptr) { + rsUiDirector_ = nullptr; + } +} + +void DragDrawing::InitAnimation() +{ + CALL_DEBUG_ENTER; + if (runner_ == nullptr) { + runner_ = AppExecFwk::EventRunner::Create(false); + } + if (handler_ == nullptr) { + handler_ = std::make_shared(runner_); + } + handler_->PostTask(std::bind(&DragDrawing::InitVSync, this)); +} + +int32_t DragDrawing::DrawShadowPic() +{ + CALL_DEBUG_ENTER; + if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && + (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT)) { + FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + return RET_ERR; + } + if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && + (g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) { + FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + return RET_ERR; + } + if (drawPixelMapModifier_ != nullptr) { + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->RemoveModifier(drawPixelMapModifier_); + } + drawPixelMapModifier_ = std::make_shared(); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->AddModifier(drawPixelMapModifier_); + return RET_OK; +} + +int32_t DragDrawing::DrawMouseIcon() +{ + CALL_DEBUG_ENTER; + if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) { + FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + return RET_ERR; + } + if (drawMouseIconModifier_ != nullptr) { + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->RemoveModifier(drawMouseIconModifier_); + } + drawMouseIconModifier_ = std::make_shared(); + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->AddModifier(drawMouseIconModifier_); + return RET_OK; +} + +int32_t DragDrawing::DrawStyle() +{ + CALL_DEBUG_ENTER; + if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && + (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT)) { + FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + return RET_ERR; + } + if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && + (g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) { + FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + return RET_ERR; + } + if (drawSVGModifier_ != nullptr) { + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->RemoveModifier(drawSVGModifier_); + } + auto drawSVGModifier_ = std::make_shared(); + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->AddModifier(drawSVGModifier_); + return RET_OK; +} + +int32_t DragDrawing::InitVSync() +{ + CALL_DEBUG_ENTER; + CHKPR(handler_, RET_ERR); + CHKPR(runner_, RET_ERR); + CHKPR(g_drawingInfo.surfaceNode, RET_ERR); + + startNum_ = START_TIME; + g_drawingInfo.surfaceNode->SetPivot(PIVOT_X, PIVOT_Y); + OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); + auto rsClient = std::static_pointer_cast( + OHOS::Rosen::RSIRenderClient::CreateRenderServiceClient()); + if (receiver_ == nullptr) { + receiver_ = rsClient->CreateVSyncReceiver("DragDrawing", handler_); + } + auto ret = receiver_->Init(); + if (ret) { + FI_HILOGE("Receiver init failed"); + return RET_ERR; + } + + OHOS::Rosen::VSyncReceiver::FrameCallback fcb = { + .userData_ = this, + .callback_ = std::bind(&DragDrawing::OnVsync, this), + }; + int32_t changeFreq = static_cast((ONETHOUSAND / FRAMERATE) / SIXTEEN); + ret = receiver_->SetVSyncRate(fcb, changeFreq); + if (ret) { + FI_HILOGE("Set vsync rate failed"); + return RET_ERR; + } + return RET_OK; +} + +void DragDrawing::OnVsync() +{ + CALL_DEBUG_ENTER; + CHKPV(rsUiDirector_); + CHKPV(runner_); + bool hasRunningAnimation = rsUiDirector_->RunningCustomAnimation(startNum_); + if (!hasRunningAnimation) { + FI_HILOGD("Stop runner_, hasRunningAnimation: %{public}d", hasRunningAnimation); + runner_->Stop(); + return; + } + rsUiDirector_->SendMessages(); + startNum_ += INTERVAL_TIME; +} + +int32_t DragDrawing::InitLayer() +{ + CALL_DEBUG_ENTER; + if (g_drawingInfo.dragWindow == nullptr) { + FI_HILOGE("Init layer failed, dragWindow is nullptr"); + return RET_ERR; + } + g_drawingInfo.surfaceNode = g_drawingInfo.dragWindow->GetSurfaceNode(); + if (g_drawingInfo.surfaceNode == nullptr) { + g_drawingInfo.dragWindow->Destroy(); + g_drawingInfo.dragWindow = nullptr; + FI_HILOGE("Init layer failed, surfaceNode is nullptr"); + return RET_ERR; + } + auto surface = g_drawingInfo.surfaceNode->GetSurface(); + if (surface == nullptr) { + g_drawingInfo.dragWindow->Destroy(); + g_drawingInfo.dragWindow = nullptr; + FI_HILOGE("Init layer failed, surface is nullptr"); + return RET_ERR; + } + rsUiDirector_ = OHOS::Rosen::RSUIDirector::Create(); + rsUiDirector_->Init(); + rsUiDirector_->SetRSSurfaceNode(g_drawingInfo.surfaceNode); + InitCanvas(IMAGE_WIDTH, IMAGE_HEIGHT); + OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); + return RET_OK; +} + +void DragDrawing::InitCanvas(int32_t width, int32_t height) +{ + CALL_DEBUG_ENTER; + if (g_drawingInfo.rootNode == nullptr) { + g_drawingInfo.rootNode = OHOS::Rosen::RSRootNode::Create(); + } + g_drawingInfo.rootNode->SetBounds(g_drawingInfo.displayX, g_drawingInfo.displayY, width, height); + g_drawingInfo.rootNode->SetFrame(g_drawingInfo.displayX, g_drawingInfo.displayY, width, height); + g_drawingInfo.rootNode->SetBackgroundColor(SK_ColorTRANSPARENT); + + auto pixelMapNode = OHOS::Rosen::RSCanvasNode::Create(); + pixelMapNode->SetBounds(0, SVG_HEIGHT, g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); + pixelMapNode->SetFrame(0, SVG_HEIGHT, g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); + g_drawingInfo.nodes.emplace_back(pixelMapNode); + + auto dragStyleNode = OHOS::Rosen::RSCanvasNode::Create(); + dragStyleNode->SetBounds(0, 0, SVG_HEIGHT, SVG_HEIGHT); + dragStyleNode->SetFrame(0, 0, SVG_HEIGHT, SVG_HEIGHT); + g_drawingInfo.nodes.emplace_back(dragStyleNode); + + if (g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { + auto mouseIconNode = OHOS::Rosen::RSCanvasNode::Create(); + mouseIconNode->SetBounds(0 - g_drawingInfo.pixelMapX, 0 - g_drawingInfo.pixelMapY, SVG_HEIGHT, SVG_HEIGHT); + mouseIconNode->SetFrame(0 - g_drawingInfo.pixelMapX, 0 - g_drawingInfo.pixelMapY, SVG_HEIGHT, SVG_HEIGHT); + g_drawingInfo.nodes.emplace_back(mouseIconNode); + g_drawingInfo.rootNode->AddChild(pixelMapNode, -1); + g_drawingInfo.rootNode->AddChild(dragStyleNode, -1); + g_drawingInfo.rootNode->AddChild(mouseIconNode, -1); + rsUiDirector_->SetRoot(g_drawingInfo.rootNode->GetId()); + return; + } + g_drawingInfo.rootNode->AddChild(pixelMapNode, -1); + g_drawingInfo.rootNode->AddChild(dragStyleNode, -1); + rsUiDirector_->SetRoot(g_drawingInfo.rootNode->GetId()); +} + +void DragDrawing::CreateWindow(int32_t displayX, int32_t displayY) +{ + CALL_DEBUG_ENTER; + sptr option = new (std::nothrow) OHOS::Rosen::WindowOption(); + CHKPV(option); + option->SetWindowType(OHOS::Rosen::WindowType::WINDOW_TYPE_POINTER); + option->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING); + OHOS::Rosen::Rect rect = { + .posX_ = displayX, + .posY_ = displayY, + .width_ = IMAGE_WIDTH, + .height_ = IMAGE_HEIGHT, + }; + option->SetWindowRect(rect); + option->SetFocusable(false); + option->SetTouchable(false); + std::string windowName = "drag window"; + g_drawingInfo.dragWindow = OHOS::Rosen::Window::Create(windowName, option, nullptr); +} + +void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const +{ + CALL_DEBUG_ENTER; + std::unique_ptr fs = std::make_unique(); + std::string filePath = ""; + if (g_drawingInfo.currentStyle == 0) { + filePath = FORBID_DRAG_PATH; + } else if (g_drawingInfo.currentStyle == 1) { + filePath = COPY_ONE_DRAG_PATH; + } else { + filePath = COPY_DRAG_PATH; + } + + if (!IsValidSvgFile(filePath)) { + FI_HILOGE("Svg file is invalid"); + return; + } + std::shared_ptr pixelMap = DecodeSvgToPixelMap(filePath); + CHKPV(pixelMap); + auto rosenImage = std::make_shared(); + rosenImage->SetPixelMap(pixelMap); + rosenImage->SetImageRepeat(0); + int32_t svgTouchPositionX = g_drawingInfo.pixelMap->GetWidth() + EIGHT_SIZE - pixelMap->GetWidth(); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBounds(0, EIGHT_SIZE, + g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetFrame(0, EIGHT_SIZE, + g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetBounds(svgTouchPositionX, 0, + pixelMap->GetWidth(), pixelMap->GetHeight()); + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetFrame(svgTouchPositionX, 0, + pixelMap->GetWidth(), pixelMap->GetHeight()); + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetBgImageWidth(pixelMap->GetWidth()); + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetBgImageHeight(SVG_HEIGHT); + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetBgImagePositionX(0); + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetBgImagePositionY(0); + g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetBgImage(rosenImage); + g_drawingInfo.rootNodeWidth = g_drawingInfo.pixelMap->GetWidth() + EIGHT_SIZE; + g_drawingInfo.rootNodeHeight = pixelMap->GetHeight() + g_drawingInfo.pixelMap->GetHeight() + EIGHT_SIZE; + g_drawingInfo.rootNode->SetBounds(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); + g_drawingInfo.rootNode->SetFrame(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); + g_drawingInfo.dragWindow->Resize(g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); + OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); +} + +int32_t DrawSVGModifier::UpdateSvgNodeInfo(xmlNodePtr &curNode, int32_t strSize) const +{ + CALL_DEBUG_ENTER; + if (xmlStrcmp(curNode->name, BAD_CAST "svg")) { + FI_HILOGE("Svg format invalid"); + return RET_ERR; + } + int32_t number = 0; + std::ostringstream oStrSteam; + oStrSteam << xmlGetProp(curNode, BAD_CAST "width"); + std::string srcSvgWidth = oStrSteam.str(); + number = std::stoi(srcSvgWidth) + strSize; + std::string tgtSvgWidth = std::to_string(number); + xmlSetProp(curNode, BAD_CAST "width", BAD_CAST tgtSvgWidth.c_str()); + oStrSteam.clear(); + oStrSteam << xmlGetProp(curNode, BAD_CAST "viewBox"); + std::string srcViewBox = oStrSteam.str(); + std::istringstream iStrSteam(srcViewBox); + std::string word; + std::string tgtViewBox; + int32_t i = 0; + int32_t size = srcViewBox.size(); + while ((iStrSteam >> word) && (i < size)) { + if (i == VIEW_BOX_POS) { + number = std::stoi(word) + strSize; + word = std::to_string(number); + } + tgtViewBox.append(word); + tgtViewBox += " "; + ++i; + } + + xmlSetProp(curNode, BAD_CAST "viewBox", BAD_CAST tgtViewBox.c_str()); + return RET_OK; +} + +xmlNodePtr DrawSVGModifier::FindRectNode(xmlNodePtr &curNode) const +{ + CALL_DEBUG_ENTER; + curNode = curNode->xmlChildrenNode; + while (curNode != NULL) { + if (!xmlStrcmp(curNode->name, BAD_CAST "g")) { + while (!xmlStrcmp(curNode->name, BAD_CAST "g")) { + curNode = curNode->xmlChildrenNode; + } + break; + } + curNode = curNode->next; + } + return curNode; +} + +xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr &curNode, int32_t strSize) const +{ + CALL_DEBUG_ENTER; + int32_t number = 0; + while (curNode != NULL) { + if (!xmlStrcmp(curNode->name, BAD_CAST "rect")) { + std::ostringstream oStrSteam; + oStrSteam << xmlGetProp(curNode, BAD_CAST "width"); + std::string srcRectWidth = oStrSteam.str(); + number = std::stoi(srcRectWidth) + strSize; + std::string tgtRectWidth = std::to_string(number); + xmlSetProp(curNode, BAD_CAST "width", BAD_CAST tgtRectWidth.c_str()); + } + if (!xmlStrcmp(curNode->name, BAD_CAST "text")) { + return curNode->xmlChildrenNode; + } + curNode = curNode->next; + } + return nullptr; +} + +void DrawSVGModifier::UpdateTspanNode(xmlNodePtr &curNode) const +{ + CALL_DEBUG_ENTER; + while (curNode != NULL) { + if (!xmlStrcmp(curNode->name, BAD_CAST "tspan")) { + std::string tgtTspanValue = std::to_string(g_drawingInfo.currentStyle); + xmlNodeSetContent(curNode, BAD_CAST tgtTspanValue.c_str()); + } + curNode = curNode->next; + } +} + +int32_t DrawSVGModifier::ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const +{ + CALL_DEBUG_ENTER; + std::string strStyle = std::to_string(g_drawingInfo.currentStyle); + int32_t strSize = (strStyle.size() - 1) * EIGHT_SIZE; + xmlKeepBlanksDefault(0); + int32_t ret = UpdateSvgNodeInfo(curNode, strSize); + if (ret != RET_OK) { + FI_HILOGE("Update svg node info failed"); + return RET_ERR; + } + curNode = FindRectNode(curNode); + curNode = UpdateRectNode(curNode, strSize); + UpdateTspanNode(curNode); + return RET_OK; +} + +std::shared_ptr DrawSVGModifier::DecodeSvgToPixelMap( + const std::string &filePath) const +{ + CALL_DEBUG_ENTER; + xmlDocPtr xmlDoc = xmlReadFile(filePath.c_str(), 0, XML_PARSE_NOBLANKS); + if (g_drawingInfo.currentStyle != 0) { + xmlNodePtr node = xmlDocGetRootElement(xmlDoc); + int32_t ret = ParseAndAdjustSvgInfo(node); + if (ret != RET_OK) { + FI_HILOGE("Parse and adjust svg info failed"); + return nullptr; + } + } + xmlChar *xmlbuff; + int32_t buffersize; + xmlDocDumpFormatMemory(xmlDoc, &xmlbuff, &buffersize, 1); + std::ostringstream oStrSteam; + oStrSteam << xmlbuff; + std::string content = oStrSteam.str(); + xmlFree(xmlbuff); + xmlFreeDoc(xmlDoc); + OHOS::Media::SourceOptions opts; + opts.formatHint = "image/svg+xml"; + uint32_t ret = 0; + auto imageSource = OHOS::Media::ImageSource::CreateImageSource(reinterpret_cast(content.c_str()), + content.size(), opts, ret); + CHKPP(imageSource); + OHOS::Media::DecodeOptions decodeOpts; + std::shared_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, ret); + return pixelMap; +} + +void DrawPixelMapModifier::Draw(OHOS::Rosen::RSDrawingContext &context) const +{ + CALL_DEBUG_ENTER; + auto rosenImage = std::make_shared(); + if (g_drawingInfo.pixelMap == nullptr) { + FI_HILOGE("Param pixelMap is nullptr"); + return; + } + rosenImage->SetPixelMap(g_drawingInfo.pixelMap); + rosenImage->SetImageRepeat(0); + int32_t pixelMapWidth = g_drawingInfo.pixelMap->GetWidth(); + int32_t pixelMapHeight = g_drawingInfo.pixelMap->GetHeight(); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBoundsWidth(pixelMapWidth); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBoundsHeight(pixelMapHeight); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImageWidth(pixelMapWidth); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImageHeight(pixelMapHeight); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImagePositionX(0); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImagePositionY(0); + g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImage(rosenImage); + OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); +} + +void DrawMouseIconModifier::Draw(OHOS::Rosen::RSDrawingContext &context) const +{ + CALL_DEBUG_ENTER; + std::string imagePath = MOUSE_DRAG_PATH; + OHOS::Media::SourceOptions opts; + opts.formatHint = "image/png"; + uint32_t errCode = 0; + auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, errCode); + CHKPV(imageSource); + int32_t iconSize = GetIconSize(); + if (iconSize <= 0) { + FI_HILOGE("Get icon size failed"); + return; + } + OHOS::Media::DecodeOptions decodeOpts; + decodeOpts.desiredSize = { + .width = iconSize, + .height = iconSize + }; + decodeOpts.allocatorType = OHOS::Media::AllocatorType::SHARE_MEM_ALLOC; + std::shared_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode); + auto rosenImage = std::make_shared(); + rosenImage->SetPixelMap(pixelMap); + rosenImage->SetImageRepeat(0); + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBoundsWidth(decodeOpts.desiredSize.width); + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBoundsHeight(decodeOpts.desiredSize.height); + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImageWidth(decodeOpts.desiredSize.width); + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImageHeight(decodeOpts.desiredSize.height); + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImagePositionX(0); + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImagePositionY(0); + g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImage(rosenImage); +} + +int32_t DrawMouseIconModifier::GetIconSize() const +{ + CALL_DEBUG_ENTER; + auto displayInfo = OHOS::Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); + CHKPR(displayInfo, 0); + return displayInfo->GetDpi() * DEVICE_INDEPENDENT_PIXELS / BASELINE_DENSITY; +} + +void DrawDynamicEffectModifier::Draw(OHOS::Rosen::RSDrawingContext &context) const +{ + CALL_DEBUG_ENTER; + CHKPV(alpha_); + CHKPV(scale_); + auto rsSurface = OHOS::Rosen::RSSurfaceExtractor::ExtractRSSurface(g_drawingInfo.surfaceNode); + CHKPV(rsSurface); + g_drawingInfo.rootNode->SetAlpha(alpha_->Get()); + g_drawingInfo.surfaceNode->SetScale(scale_->Get(), scale_->Get()); + auto frame = rsSurface->RequestFrame(g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); + if (frame == nullptr) { + FI_HILOGE("Failed to create frame"); + return; + } + FI_HILOGD("alpha_:%{public}f, scale_:%{public}f", alpha_->Get(), scale_->Get()); + frame->SetDamageRegion(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); + rsSurface->FlushFrame(frame); + OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); +} + +void DrawDynamicEffectModifier::SetAlpha(float alpha) +{ + CALL_DEBUG_ENTER; + if (alpha_ == nullptr) { + alpha_ = std::make_shared>(alpha); + OHOS::Rosen::RSModifier::AttachProperty(alpha_); + } else { + alpha_->Set(alpha); + } +} + +void DrawDynamicEffectModifier::SetScale(float scale) +{ + CALL_DEBUG_ENTER; + if (scale_ == nullptr) { + scale_ = std::make_shared>(scale); + OHOS::Rosen::RSModifier::AttachProperty(scale_); + } else { + scale_->Set(scale); + } +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS \ No newline at end of file diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index 29ec2dec8..a5dda6eed 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -93,7 +93,7 @@ int32_t DragManager::StopDrag(int32_t result) FI_HILOGE("No drag instance running, can not stop drag"); return RET_ERR; } - if (OnStopDrag() != RET_OK) { + if (OnStopDrag(result) != RET_OK) { FI_HILOGE("OnStopDrag failed"); return RET_ERR; } @@ -111,6 +111,21 @@ int32_t DragManager::GetDragTargetPid() const return dragTargetPid_; } +int32_t DragManager::UpdateDragStyle(int32_t style) +{ + CALL_DEBUG_ENTER; + if (style < 0) { + FI_HILOGE("Invalid style:%{public}d", style); + return RET_ERR; + } + int32_t ret = dragDrawing_.UpdateDragStyle(style); + if (ret != RET_OK) { + FI_HILOGE("Update drag style failed"); + dragDrawing_.DestroyDragWindow(); + } + return RET_OK; +} + int32_t DragManager::NotifyDragResult(int32_t result) { CALL_DEBUG_ENTER; @@ -153,6 +168,7 @@ void DragManager::OnDragMove(std::shared_ptr pointerEvent) CHKPV(pointerEvent); MMI::PointerEvent::PointerItem pointerItem; pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem); + dragDrawing_.Draw(pointerEvent->GetTargetDisplayId(), pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); } void DragManager::OnDragUp(std::shared_ptr pointerEvent) @@ -214,15 +230,37 @@ int32_t DragManager::OnStartDrag() } auto extraData = CreateExtraData(true); INPUT_MANAGER->AppendExtraData(extraData); + DragData dragData = DataAdapter.GetDragData(); + if (dragData.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { + INPUT_MANAGER->SetPointerVisible(false); + } + if (dragDrawing_.Init(dragData) != RET_OK) { + FI_HILOGE("Init Picture failed"); + dragDrawing_.DestroyDragWindow(); + return RET_ERR; + } + dragDrawing_.Draw(dragData.displayId, dragData.displayX, dragData.displayY); return RET_OK; } -int32_t DragManager::OnStopDrag() +int32_t DragManager::OnStopDrag(int32_t result) { CALL_DEBUG_ENTER; if (monitorId_ > 0) { INPUT_MANAGER->RemoveMonitor(monitorId_); monitorId_ = -1; + DragData dragData = DataAdapter.GetDragData(); + if (dragData.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { + dragDrawing_.EraseMouseIcon(); + INPUT_MANAGER->SetPointerVisible(true); + } + if (result == 0) { + dragDrawing_.OnDragSuccess(); + } + else { + dragDrawing_.OnDragFail(); + } + dragDrawing_.DestroyDragWindow(); return RET_OK; } FI_HILOGE("RemoveMonitor failed, monitorId_:%{public}d", monitorId_); diff --git a/services/native/include/devicestatus_service.h b/services/native/include/devicestatus_service.h index eb6047f00..bcd495668 100644 --- a/services/native/include/devicestatus_service.h +++ b/services/native/include/devicestatus_service.h @@ -103,6 +103,7 @@ private: int32_t OnStartDrag(const DragData &dragData, int32_t pid); int32_t OnStopDrag(int32_t result); + int32_t OnUpdateDragStyle(int32_t style); #ifdef OHOS_BUILD_ENABLE_COORDINATION int32_t OnRegisterCoordinationListener(int32_t pid); diff --git a/services/native/src/devicestatus_service.cpp b/services/native/src/devicestatus_service.cpp index 700158de3..2e5295015 100644 --- a/services/native/src/devicestatus_service.cpp +++ b/services/native/src/devicestatus_service.cpp @@ -720,7 +720,13 @@ int32_t DeviceStatusService::StopDrag(int32_t result) int32_t DeviceStatusService::UpdateDragStyle(int32_t style) { CALL_DEBUG_ENTER; - return RET_ERR; + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&DeviceStatusService::OnUpdateDragStyle, this, style)); + if (ret != RET_OK) { + FI_HILOGE("OnStartDrag failed, ret:%{public}d", ret); + return ret; + } + return RET_OK; } int32_t DeviceStatusService::UpdateDragMessage(const std::u16string &message) @@ -882,6 +888,17 @@ int32_t DeviceStatusService::OnStopDrag(int32_t result) } return RET_OK; } + +int32_t DeviceStatusService::OnUpdateDragStyle(int32_t style) +{ + CALL_DEBUG_ENTER; + int32_t ret = dragMgr_.UpdateDragStyle(style); + if (ret != RET_OK) { + FI_HILOGE("UpdateDragStyle failed, ret:%{public}d", ret); + return ret; + } + return RET_OK; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/utils/common/include/util.h b/utils/common/include/util.h index b58cd8b4f..1596da734 100644 --- a/utils/common/include/util.h +++ b/utils/common/include/util.h @@ -61,6 +61,12 @@ inline bool AddInt64(int64_t op1, int64_t op2, int64_t &res) size_t StringSplit(const std::string &str, const std::string &sep, std::vector &vecList); std::string StringPrintf(const char *format, ...); +bool CheckFileExtendName(const std::string &filePath, const std::string &checkExtension); +int32_t GetFileSize(const std::string &filePath); +bool IsValidPath(const std::string &rootDir, const std::string &filePath); +bool IsValidSvgPath(const std::string &filePath); +bool IsFileExists(const std::string &fileName); +bool IsValidSvgFile(const std::string &filePath); } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/utils/common/src/util.cpp b/utils/common/src/util.cpp index 24ae042a0..5177b1c2d 100644 --- a/utils/common/src/util.cpp +++ b/utils/common/src/util.cpp @@ -19,6 +19,7 @@ #include +#include #include #include #include "securec.h" @@ -34,6 +35,8 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "Util" constexpr size_t BUF_TID_SIZE = 10; constexpr size_t PROGRAM_NAME_SIZE = 256; constexpr size_t BUF_CMD_SIZE = 512; +constexpr int32_t FILE_SIZE_MAX = 0x5000; +const std::string SVG_PATH = "/system/etc/device_status/drag_icon/"; } // namespace int32_t GetPid() @@ -201,6 +204,72 @@ const char* GetProgramName() return programName; } +bool CheckFileExtendName(const std::string &filePath, const std::string &checkExtension) +{ + std::string::size_type pos = filePath.find_last_of('.'); + if (pos == std::string::npos) { + FI_HILOGE("File is not find extension"); + return false; + } + return (filePath.substr(pos + 1, filePath.npos) == checkExtension); +} + +int32_t GetFileSize(const std::string &filePath) +{ + struct stat statbuf = { 0 }; + if (stat(filePath.c_str(), &statbuf) != 0) { + FI_HILOGE("Get file size error"); + return RET_ERR; + } + return statbuf.st_size; +} + +bool IsValidPath(const std::string &rootDir, const std::string &filePath) +{ + return (filePath.compare(0, rootDir.size(), rootDir) == 0); +} + +bool IsValidSvgPath(const std::string &filePath) +{ + return IsValidPath(SVG_PATH, filePath); +} + +bool IsFileExists(const std::string &fileName) +{ + return (access(fileName.c_str(), F_OK) == 0); +} + +bool IsValidSvgFile(const std::string &filePath) +{ + CALL_DEBUG_ENTER; + if (filePath.empty()) { + FI_HILOGE("FilePath is empty"); + return false; + } + char realPath[PATH_MAX] = {}; + if (realpath(filePath.c_str(), realPath) == nullptr) { + FI_HILOGE("Realpath return nullptr, realPath:%{public}s", realPath); + return false; + } + if (!IsValidSvgPath(realPath)) { + FI_HILOGE("File path invalid"); + return false; + } + if (!IsFileExists(realPath)) { + FI_HILOGE("File not exist"); + return false; + } + if (!CheckFileExtendName(realPath, "svg")) { + FI_HILOGE("Unable to parse files other than svg format"); + return false; + } + int32_t fileSize = GetFileSize(realPath); + if ((fileSize <= 0) || (fileSize > FILE_SIZE_MAX)) { + FI_HILOGE("File size out of read range"); + return false; + } + return true; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file -- Gitee From c164e199df42559b2f6540374e55bd978d0b8070 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Tue, 14 Mar 2023 14:07:39 +0000 Subject: [PATCH 02/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I851e31ec3325b3d9775ff7f951e3e095d84bcb34 --- services/interaction/drag/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/interaction/drag/BUILD.gn b/services/interaction/drag/BUILD.gn index 5f208bc01..4c9312fca 100644 --- a/services/interaction/drag/BUILD.gn +++ b/services/interaction/drag/BUILD.gn @@ -38,9 +38,9 @@ ohos_shared_library("interaction_drag") { defines = device_status_default_defines deps = [ + "${device_status_root_path}/etc/drag_icon:device_status_drag_icon", "${device_status_root_path}/utils/ipc:devicestatus_ipc", "${device_status_utils_path}:devicestatus_util", - "${device_status_root_path}/etc/drag_icon:device_status_drag_icon", "//third_party/libxml2:xml2", ] -- Gitee From d5e100f780d9eb481c6368d16d18b32112c726ef Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Wed, 15 Mar 2023 09:14:05 +0000 Subject: [PATCH 03/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I6c1bb761c1bc313ed1723f9a3d1237ac23b419d3 --- .../interaction/drag/include/drag_drawing.h | 6 +- .../interaction/drag/src/drag_drawing.cpp | 87 +++++++++++-------- .../interaction/drag/src/drag_manager.cpp | 3 +- 3 files changed, 56 insertions(+), 40 deletions(-) diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index 8d1775ce7..15ba88116 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -73,8 +73,8 @@ public: void SetAlpha(float alpha); void SetScale(float scale); private: - std::shared_ptr> alpha_; - std::shared_ptr> scale_; + std::shared_ptr> alpha_ { nullptr }; + std::shared_ptr> scale_ { nullptr }; }; class DragDrawing final { @@ -95,7 +95,7 @@ private: int32_t InitLayer(); void InitCanvas(int32_t width, int32_t height); void CreateWindow(int32_t displayX, int32_t displayY); - int32_t DrawShadowPic(); + int32_t DrawShadow(); int32_t DrawMouseIcon(); int32_t DrawStyle(); void InitAnimation(); diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index ef17a9670..8ce1483f1 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -26,8 +26,8 @@ #include "image_utils.h" #include "libxml/tree.h" #include "libxml/parser.h" -#include "string_ex.h" #include "pointer_event.h" +#include "string_ex.h" #include "transaction/rs_interfaces.h" #include "transaction/rs_transaction.h" #include "ui/rs_root_node.h" @@ -107,14 +107,15 @@ int32_t DragDrawing::Init(const DragData &dragData) CreateWindow(dragData.displayX, dragData.displayY); CHKPR(g_drawingInfo.dragWindow, RET_ERR); if (InitLayer() != RET_OK) { - FI_HILOGE("Init Layer failed"); + FI_HILOGE("Init layer failed"); return RET_ERR; } - if (DrawShadowPic() != RET_OK) { - FI_HILOGE("Draw shadow picture failed"); + if (DrawShadow() != RET_OK) { + FI_HILOGE("Draw shadow failed"); return RET_ERR; } if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { + CHKPR(g_drawingInfo.dragWindow, RET_ERR); g_drawingInfo.dragWindow->Show(); InitAnimation(); return RET_OK; @@ -123,6 +124,7 @@ int32_t DragDrawing::Init(const DragData &dragData) FI_HILOGE("Draw mouse icon failed"); return RET_ERR; } + CHKPR(g_drawingInfo.dragWindow, RET_ERR); g_drawingInfo.dragWindow->Show(); InitAnimation(); return RET_OK; @@ -151,13 +153,13 @@ void DragDrawing::Draw(int32_t displayId, int32_t displayX, int32_t displayY) return; } CreateWindow(g_drawingInfo.displayX + g_drawingInfo.pixelMapX, g_drawingInfo.displayY + g_drawingInfo.pixelMapY); + CHKPV(g_drawingInfo.dragWindow); g_drawingInfo.dragWindow->Show(); } int32_t DragDrawing::UpdateDragStyle(int32_t style) { CALL_DEBUG_ENTER; - CHKPR(rsUiDirector_, RET_ERR); if (style < 0) { FI_HILOGE("Invalid style:%{public}d", style); return RET_ERR; @@ -168,6 +170,7 @@ int32_t DragDrawing::UpdateDragStyle(int32_t style) } g_drawingInfo.currentStyle = style; DrawStyle(); + CHKPR(rsUiDirector_, RET_ERR); rsUiDirector_->SendMessages(); return RET_OK; } @@ -175,70 +178,69 @@ int32_t DragDrawing::UpdateDragStyle(int32_t style) void DragDrawing::OnDragSuccess() { CALL_DEBUG_ENTER; - CHKPV(runner_); - CHKPV(rsUiDirector_); - CHKPV(g_drawingInfo.rootNode); - if (drawDynamicEffectModifier_ != nullptr){ + if (drawDynamicEffectModifier_ != nullptr) { + CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); } drawDynamicEffectModifier_ = std::make_shared(); + CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); - drawDynamicEffectModifier_->SetAlpha(1); - drawDynamicEffectModifier_->SetScale(1); + drawDynamicEffectModifier_->SetAlpha(1.0f); + drawDynamicEffectModifier_->SetScale(1.0f); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(SUCCESS_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - drawDynamicEffectModifier_->SetAlpha(0); + drawDynamicEffectModifier_->SetAlpha(0.0f); drawDynamicEffectModifier_->SetScale(SUCCESS_ENLARGE_SCALE); }); + CHKPV(runner_); runner_->Run(); } void DragDrawing::OnDragFail() { CALL_DEBUG_ENTER; - CHKPV(runner_); - CHKPV(rsUiDirector_); - CHKPV(g_drawingInfo.rootNode); - if (drawDynamicEffectModifier_ != nullptr){ + if (drawDynamicEffectModifier_ != nullptr) { + CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); } drawDynamicEffectModifier_ = std::make_shared(); + CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); - drawDynamicEffectModifier_->SetAlpha(1); - drawDynamicEffectModifier_->SetScale(1); + drawDynamicEffectModifier_->SetAlpha(1.0f); + drawDynamicEffectModifier_->SetScale(1.0f); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(FAIL_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - drawDynamicEffectModifier_->SetAlpha(0); + drawDynamicEffectModifier_->SetAlpha(0.0f); drawDynamicEffectModifier_->SetScale(FAIL_ENLARGE_SCALE); }); + CHKPV(runner_); runner_->Run(); } void DragDrawing::EraseMouseIcon() { CALL_DEBUG_ENTER; - CHKPV(g_drawingInfo.rootNode); - CHKPV(rsUiDirector_); if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) { - FI_HILOGE("Canvas nodes vector size invalid, nodes.size(): %{public}d", g_drawingInfo.nodes.size()); + FI_HILOGE("Canvas nodes vector size invalid, nodes.size(): %{public}zu", g_drawingInfo.nodes.size()); return; } if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { FI_HILOGE("Touch type not need erase mouse icon"); return; } + CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->RemoveChild(g_drawingInfo.nodes[MOUSE_ICON_INDEX]); + CHKPV(rsUiDirector_); rsUiDirector_->SendMessages(); } void DragDrawing::DestroyDragWindow() { CALL_DEBUG_ENTER; - g_drawingInfo.sourceType = -1; startNum_ = START_TIME; g_drawingInfo.currentStyle = -1; if (g_drawingInfo.pixelMap != nullptr) { @@ -275,7 +277,7 @@ void DragDrawing::InitAnimation() handler_->PostTask(std::bind(&DragDrawing::InitVSync, this)); } -int32_t DragDrawing::DrawShadowPic() +int32_t DragDrawing::DrawShadow() { CALL_DEBUG_ENTER; if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && @@ -289,9 +291,11 @@ int32_t DragDrawing::DrawShadowPic() return RET_ERR; } if (drawPixelMapModifier_ != nullptr) { + CHKPR(g_drawingInfo.nodes[PIXEL_MAP_INDEX], RET_ERR); g_drawingInfo.nodes[PIXEL_MAP_INDEX]->RemoveModifier(drawPixelMapModifier_); } drawPixelMapModifier_ = std::make_shared(); + CHKPR(g_drawingInfo.nodes[PIXEL_MAP_INDEX], RET_ERR); g_drawingInfo.nodes[PIXEL_MAP_INDEX]->AddModifier(drawPixelMapModifier_); return RET_OK; } @@ -304,9 +308,11 @@ int32_t DragDrawing::DrawMouseIcon() return RET_ERR; } if (drawMouseIconModifier_ != nullptr) { + CHKPR(g_drawingInfo.nodes[MOUSE_ICON_INDEX], RET_ERR); g_drawingInfo.nodes[MOUSE_ICON_INDEX]->RemoveModifier(drawMouseIconModifier_); } drawMouseIconModifier_ = std::make_shared(); + CHKPR(g_drawingInfo.nodes[MOUSE_ICON_INDEX], RET_ERR); g_drawingInfo.nodes[MOUSE_ICON_INDEX]->AddModifier(drawMouseIconModifier_); return RET_OK; } @@ -325,9 +331,11 @@ int32_t DragDrawing::DrawStyle() return RET_ERR; } if (drawSVGModifier_ != nullptr) { + CHKPR(g_drawingInfo.nodes[DRAG_STYLE_INDEX], RET_ERR); g_drawingInfo.nodes[DRAG_STYLE_INDEX]->RemoveModifier(drawSVGModifier_); } auto drawSVGModifier_ = std::make_shared(); + CHKPR(g_drawingInfo.nodes[DRAG_STYLE_INDEX], RET_ERR); g_drawingInfo.nodes[DRAG_STYLE_INDEX]->AddModifier(drawSVGModifier_); return RET_OK; } @@ -335,16 +343,14 @@ int32_t DragDrawing::DrawStyle() int32_t DragDrawing::InitVSync() { CALL_DEBUG_ENTER; - CHKPR(handler_, RET_ERR); - CHKPR(runner_, RET_ERR); - CHKPR(g_drawingInfo.surfaceNode, RET_ERR); - startNum_ = START_TIME; + CHKPR(g_drawingInfo.surfaceNode, RET_ERR); g_drawingInfo.surfaceNode->SetPivot(PIVOT_X, PIVOT_Y); OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); auto rsClient = std::static_pointer_cast( OHOS::Rosen::RSIRenderClient::CreateRenderServiceClient()); if (receiver_ == nullptr) { + CHKPR(handler_, RET_ERR); receiver_ = rsClient->CreateVSyncReceiver("DragDrawing", handler_); } auto ret = receiver_->Init(); @@ -370,10 +376,10 @@ void DragDrawing::OnVsync() { CALL_DEBUG_ENTER; CHKPV(rsUiDirector_); - CHKPV(runner_); bool hasRunningAnimation = rsUiDirector_->RunningCustomAnimation(startNum_); if (!hasRunningAnimation) { FI_HILOGD("Stop runner_, hasRunningAnimation: %{public}d", hasRunningAnimation); + CHKPV(runner_); runner_->Stop(); return; } @@ -403,6 +409,7 @@ int32_t DragDrawing::InitLayer() return RET_ERR; } rsUiDirector_ = OHOS::Rosen::RSUIDirector::Create(); + CHKPR(rsUiDirector_, RET_ERR); rsUiDirector_->Init(); rsUiDirector_->SetRSSurfaceNode(g_drawingInfo.surfaceNode); InitCanvas(IMAGE_WIDTH, IMAGE_HEIGHT); @@ -415,23 +422,28 @@ void DragDrawing::InitCanvas(int32_t width, int32_t height) CALL_DEBUG_ENTER; if (g_drawingInfo.rootNode == nullptr) { g_drawingInfo.rootNode = OHOS::Rosen::RSRootNode::Create(); + CHKPV(g_drawingInfo.rootNode); } g_drawingInfo.rootNode->SetBounds(g_drawingInfo.displayX, g_drawingInfo.displayY, width, height); g_drawingInfo.rootNode->SetFrame(g_drawingInfo.displayX, g_drawingInfo.displayY, width, height); g_drawingInfo.rootNode->SetBackgroundColor(SK_ColorTRANSPARENT); auto pixelMapNode = OHOS::Rosen::RSCanvasNode::Create(); + CHKPV(pixelMapNode); + CHKPV(g_drawingInfo.pixelMap); pixelMapNode->SetBounds(0, SVG_HEIGHT, g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); pixelMapNode->SetFrame(0, SVG_HEIGHT, g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); g_drawingInfo.nodes.emplace_back(pixelMapNode); auto dragStyleNode = OHOS::Rosen::RSCanvasNode::Create(); + CHKPV(dragStyleNode); dragStyleNode->SetBounds(0, 0, SVG_HEIGHT, SVG_HEIGHT); dragStyleNode->SetFrame(0, 0, SVG_HEIGHT, SVG_HEIGHT); g_drawingInfo.nodes.emplace_back(dragStyleNode); if (g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { auto mouseIconNode = OHOS::Rosen::RSCanvasNode::Create(); + CHKPV(mouseIconNode); mouseIconNode->SetBounds(0 - g_drawingInfo.pixelMapX, 0 - g_drawingInfo.pixelMapY, SVG_HEIGHT, SVG_HEIGHT); mouseIconNode->SetFrame(0 - g_drawingInfo.pixelMapX, 0 - g_drawingInfo.pixelMapY, SVG_HEIGHT, SVG_HEIGHT); g_drawingInfo.nodes.emplace_back(mouseIconNode); @@ -488,11 +500,14 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const auto rosenImage = std::make_shared(); rosenImage->SetPixelMap(pixelMap); rosenImage->SetImageRepeat(0); + CHKPV(g_drawingInfo.pixelMap); int32_t svgTouchPositionX = g_drawingInfo.pixelMap->GetWidth() + EIGHT_SIZE - pixelMap->GetWidth(); + CHKPV(g_drawingInfo.nodes[PIXEL_MAP_INDEX]); g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBounds(0, EIGHT_SIZE, g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetFrame(0, EIGHT_SIZE, g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); + CHKPV(g_drawingInfo.nodes[DRAG_STYLE_INDEX]); g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetBounds(svgTouchPositionX, 0, pixelMap->GetWidth(), pixelMap->GetHeight()); g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetFrame(svgTouchPositionX, 0, @@ -504,6 +519,7 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const g_drawingInfo.nodes[DRAG_STYLE_INDEX]->SetBgImage(rosenImage); g_drawingInfo.rootNodeWidth = g_drawingInfo.pixelMap->GetWidth() + EIGHT_SIZE; g_drawingInfo.rootNodeHeight = pixelMap->GetHeight() + g_drawingInfo.pixelMap->GetHeight() + EIGHT_SIZE; + CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->SetBounds(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); g_drawingInfo.rootNode->SetFrame(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); g_drawingInfo.dragWindow->Resize(g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); @@ -517,11 +533,10 @@ int32_t DrawSVGModifier::UpdateSvgNodeInfo(xmlNodePtr &curNode, int32_t strSize) FI_HILOGE("Svg format invalid"); return RET_ERR; } - int32_t number = 0; std::ostringstream oStrSteam; oStrSteam << xmlGetProp(curNode, BAD_CAST "width"); std::string srcSvgWidth = oStrSteam.str(); - number = std::stoi(srcSvgWidth) + strSize; + int32_t number = std::stoi(srcSvgWidth) + strSize; std::string tgtSvgWidth = std::to_string(number); xmlSetProp(curNode, BAD_CAST "width", BAD_CAST tgtSvgWidth.c_str()); oStrSteam.clear(); @@ -565,13 +580,12 @@ xmlNodePtr DrawSVGModifier::FindRectNode(xmlNodePtr &curNode) const xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr &curNode, int32_t strSize) const { CALL_DEBUG_ENTER; - int32_t number = 0; while (curNode != NULL) { if (!xmlStrcmp(curNode->name, BAD_CAST "rect")) { std::ostringstream oStrSteam; oStrSteam << xmlGetProp(curNode, BAD_CAST "width"); std::string srcRectWidth = oStrSteam.str(); - number = std::stoi(srcRectWidth) + strSize; + int32_t number = std::stoi(srcRectWidth) + strSize; std::string tgtRectWidth = std::to_string(number); xmlSetProp(curNode, BAD_CAST "width", BAD_CAST tgtRectWidth.c_str()); } @@ -647,15 +661,16 @@ std::shared_ptr DrawSVGModifier::DecodeSvgToPixelMap( void DrawPixelMapModifier::Draw(OHOS::Rosen::RSDrawingContext &context) const { CALL_DEBUG_ENTER; - auto rosenImage = std::make_shared(); if (g_drawingInfo.pixelMap == nullptr) { FI_HILOGE("Param pixelMap is nullptr"); return; } + auto rosenImage = std::make_shared(); rosenImage->SetPixelMap(g_drawingInfo.pixelMap); rosenImage->SetImageRepeat(0); int32_t pixelMapWidth = g_drawingInfo.pixelMap->GetWidth(); int32_t pixelMapHeight = g_drawingInfo.pixelMap->GetHeight(); + CHKPV(g_drawingInfo.nodes[PIXEL_MAP_INDEX]); g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBoundsWidth(pixelMapWidth); g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBoundsHeight(pixelMapHeight); g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImageWidth(pixelMapWidth); @@ -687,9 +702,11 @@ void DrawMouseIconModifier::Draw(OHOS::Rosen::RSDrawingContext &context) const }; decodeOpts.allocatorType = OHOS::Media::AllocatorType::SHARE_MEM_ALLOC; std::shared_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode); + CHKPV(pixelMap); auto rosenImage = std::make_shared(); rosenImage->SetPixelMap(pixelMap); rosenImage->SetImageRepeat(0); + CHKPV(g_drawingInfo.nodes[MOUSE_ICON_INDEX]); g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBoundsWidth(decodeOpts.desiredSize.width); g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBoundsHeight(decodeOpts.desiredSize.height); g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImageWidth(decodeOpts.desiredSize.width); @@ -703,7 +720,7 @@ int32_t DrawMouseIconModifier::GetIconSize() const { CALL_DEBUG_ENTER; auto displayInfo = OHOS::Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); - CHKPR(displayInfo, 0); + CHKPR(displayInfo, RET_ERR); return displayInfo->GetDpi() * DEVICE_INDEPENDENT_PIXELS / BASELINE_DENSITY; } diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index a5dda6eed..91f1338d2 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -256,8 +256,7 @@ int32_t DragManager::OnStopDrag(int32_t result) } if (result == 0) { dragDrawing_.OnDragSuccess(); - } - else { + } else { dragDrawing_.OnDragFail(); } dragDrawing_.DestroyDragWindow(); -- Gitee From 6ae72d4d3a7b7f22612d49931528ddc546e163bc Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Wed, 15 Mar 2023 09:40:30 +0000 Subject: [PATCH 04/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I029fc88daa794fcafc8d884fbd1b6debefcba505 --- services/interaction/drag/include/drag_drawing.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index 15ba88116..75987b23f 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -77,7 +77,7 @@ private: std::shared_ptr> scale_ { nullptr }; }; -class DragDrawing final { +class DragDrawing final { public: DragDrawing() = default; ~DragDrawing() = default; @@ -104,7 +104,7 @@ private: private: int64_t startNum_ { -1 }; - std::shared_ptr canvasNode_ { nullptr }; + std::shared_ptr canvasNode_ { nullptr }; std::shared_ptr drawSVGModifier_ { nullptr }; std::shared_ptr drawPixelMapModifier_ { nullptr }; std::shared_ptr drawMouseIconModifier_ { nullptr }; -- Gitee From 3e5ca5ffc6688175e538958d210fe85b02f043ae Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Thu, 16 Mar 2023 03:35:17 +0000 Subject: [PATCH 05/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: Ic1c7e13495a496d02518ef331a1272fcc0e698e6 --- .../interaction/drag/src/drag_drawing.cpp | 70 ++++++++++--------- .../interaction/drag/src/drag_manager.cpp | 2 + 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 8ce1483f1..c92c40b6e 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -93,7 +93,7 @@ struct DrawingInfo { int32_t DragDrawing::Init(const DragData &dragData) { CALL_DEBUG_ENTER; - CHKPR(dragData.pictureResourse.pixelMap, RET_ERR); + CHKPR(dragData.shadowInfo.pixelMap, RET_ERR); if ((dragData.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && (dragData.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN)) { FI_HILOGE("Invalid sourceType:%{public}d", dragData.sourceType); @@ -101,9 +101,9 @@ int32_t DragDrawing::Init(const DragData &dragData) } g_drawingInfo.sourceType = dragData.sourceType; g_drawingInfo.displayId = dragData.displayId; - g_drawingInfo.pixelMap = dragData.pictureResourse.pixelMap; - g_drawingInfo.pixelMapX = dragData.pictureResourse.x; - g_drawingInfo.pixelMapY = dragData.pictureResourse.y; + g_drawingInfo.pixelMap = dragData.shadowInfo.pixelMap; + g_drawingInfo.pixelMapX = dragData.shadowInfo.x; + g_drawingInfo.pixelMapY = dragData.shadowInfo.y; CreateWindow(dragData.displayX, dragData.displayY); CHKPR(g_drawingInfo.dragWindow, RET_ERR); if (InitLayer() != RET_OK) { @@ -290,13 +290,13 @@ int32_t DragDrawing::DrawShadow() FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } + auto pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; + CHKPR(pixelMapNode, RET_ERR); if (drawPixelMapModifier_ != nullptr) { - CHKPR(g_drawingInfo.nodes[PIXEL_MAP_INDEX], RET_ERR); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->RemoveModifier(drawPixelMapModifier_); + pixelMapNode->RemoveModifier(drawPixelMapModifier_); } drawPixelMapModifier_ = std::make_shared(); - CHKPR(g_drawingInfo.nodes[PIXEL_MAP_INDEX], RET_ERR); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->AddModifier(drawPixelMapModifier_); + pixelMapNode->AddModifier(drawPixelMapModifier_); return RET_OK; } @@ -307,13 +307,13 @@ int32_t DragDrawing::DrawMouseIcon() FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } + auto mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; + CHKPR(mouseIconNode, RET_ERR); if (drawMouseIconModifier_ != nullptr) { - CHKPR(g_drawingInfo.nodes[MOUSE_ICON_INDEX], RET_ERR); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->RemoveModifier(drawMouseIconModifier_); + mouseIconNode->RemoveModifier(drawMouseIconModifier_); } drawMouseIconModifier_ = std::make_shared(); - CHKPR(g_drawingInfo.nodes[MOUSE_ICON_INDEX], RET_ERR); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->AddModifier(drawMouseIconModifier_); + mouseIconNode->AddModifier(drawMouseIconModifier_); return RET_OK; } @@ -447,14 +447,14 @@ void DragDrawing::InitCanvas(int32_t width, int32_t height) mouseIconNode->SetBounds(0 - g_drawingInfo.pixelMapX, 0 - g_drawingInfo.pixelMapY, SVG_HEIGHT, SVG_HEIGHT); mouseIconNode->SetFrame(0 - g_drawingInfo.pixelMapX, 0 - g_drawingInfo.pixelMapY, SVG_HEIGHT, SVG_HEIGHT); g_drawingInfo.nodes.emplace_back(mouseIconNode); - g_drawingInfo.rootNode->AddChild(pixelMapNode, -1); - g_drawingInfo.rootNode->AddChild(dragStyleNode, -1); - g_drawingInfo.rootNode->AddChild(mouseIconNode, -1); + g_drawingInfo.rootNode->AddChild(pixelMapNode); + g_drawingInfo.rootNode->AddChild(dragStyleNode); + g_drawingInfo.rootNode->AddChild(mouseIconNode); rsUiDirector_->SetRoot(g_drawingInfo.rootNode->GetId()); return; } - g_drawingInfo.rootNode->AddChild(pixelMapNode, -1); - g_drawingInfo.rootNode->AddChild(dragStyleNode, -1); + g_drawingInfo.rootNode->AddChild(pixelMapNode); + g_drawingInfo.rootNode->AddChild(dragStyleNode); rsUiDirector_->SetRoot(g_drawingInfo.rootNode->GetId()); } @@ -662,7 +662,7 @@ void DrawPixelMapModifier::Draw(OHOS::Rosen::RSDrawingContext &context) const { CALL_DEBUG_ENTER; if (g_drawingInfo.pixelMap == nullptr) { - FI_HILOGE("Param pixelMap is nullptr"); + FI_HILOGE("pixelMap is nullptr"); return; } auto rosenImage = std::make_shared(); @@ -670,14 +670,15 @@ void DrawPixelMapModifier::Draw(OHOS::Rosen::RSDrawingContext &context) const rosenImage->SetImageRepeat(0); int32_t pixelMapWidth = g_drawingInfo.pixelMap->GetWidth(); int32_t pixelMapHeight = g_drawingInfo.pixelMap->GetHeight(); - CHKPV(g_drawingInfo.nodes[PIXEL_MAP_INDEX]); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBoundsWidth(pixelMapWidth); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBoundsHeight(pixelMapHeight); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImageWidth(pixelMapWidth); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImageHeight(pixelMapHeight); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImagePositionX(0); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImagePositionY(0); - g_drawingInfo.nodes[PIXEL_MAP_INDEX]->SetBgImage(rosenImage); + auto pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; + CHKPV(pixelMapNode); + pixelMapNode->SetBoundsWidth(pixelMapWidth); + pixelMapNode->SetBoundsHeight(pixelMapHeight); + pixelMapNode->SetBgImageWidth(pixelMapWidth); + pixelMapNode->SetBgImageHeight(pixelMapHeight); + pixelMapNode->SetBgImagePositionX(0); + pixelMapNode->SetBgImagePositionY(0); + pixelMapNode->SetBgImage(rosenImage); OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); } @@ -706,14 +707,15 @@ void DrawMouseIconModifier::Draw(OHOS::Rosen::RSDrawingContext &context) const auto rosenImage = std::make_shared(); rosenImage->SetPixelMap(pixelMap); rosenImage->SetImageRepeat(0); - CHKPV(g_drawingInfo.nodes[MOUSE_ICON_INDEX]); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBoundsWidth(decodeOpts.desiredSize.width); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBoundsHeight(decodeOpts.desiredSize.height); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImageWidth(decodeOpts.desiredSize.width); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImageHeight(decodeOpts.desiredSize.height); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImagePositionX(0); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImagePositionY(0); - g_drawingInfo.nodes[MOUSE_ICON_INDEX]->SetBgImage(rosenImage); + auto mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; + CHKPV(mouseIconNode); + mouseIconNode->SetBoundsWidth(decodeOpts.desiredSize.width); + mouseIconNode->SetBoundsHeight(decodeOpts.desiredSize.height); + mouseIconNode->SetBgImageWidth(decodeOpts.desiredSize.width); + mouseIconNode->SetBgImageHeight(decodeOpts.desiredSize.height); + mouseIconNode->SetBgImagePositionX(0); + mouseIconNode->SetBgImagePositionY(0); + mouseIconNode->SetBgImage(rosenImage); } int32_t DrawMouseIconModifier::GetIconSize() const diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index f205fc3d2..7a8243312 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -124,6 +124,8 @@ int32_t DragManager::UpdateDragStyle(int32_t style) dragDrawing_.DestroyDragWindow(); } return RET_OK; +} + void DragManager::SetDragTargetPid(int32_t dragTargetPid) { CALL_DEBUG_ENTER; -- Gitee From d7f64e66f5ac4c0ae3c6eec0bddc9039a63464ec Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Thu, 16 Mar 2023 05:44:51 +0000 Subject: [PATCH 06/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I50d0fc3a71a4e40f0c07fc98a89606d6c71d4a8d --- .../interaction/drag/include/drag_manager.h | 2 +- .../interaction/drag/src/drag_manager.cpp | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/services/interaction/drag/include/drag_manager.h b/services/interaction/drag/include/drag_manager.h index 4f01db17f..167767189 100644 --- a/services/interaction/drag/include/drag_manager.h +++ b/services/interaction/drag/include/drag_manager.h @@ -64,7 +64,7 @@ private: OHOS::MMI::ExtraData CreateExtraData(bool appended) const; int32_t InitDataAdapter(const DragData &dragData) const; int32_t OnStartDrag(); - int32_t OnStopDrag(int32_t result); + int32_t OnStopDrag(DragResult result, bool hasCustomAnimation); private: StateChangeNotify stateNotify_; DragMessage dragState_ { DragMessage::MSG_DRAG_STATE_STOP }; diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index 1784612d5..002e221ac 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -93,7 +93,7 @@ int32_t DragManager::StopDrag(DragResult result, bool hasCustomAnimation) FI_HILOGE("No drag instance running, can not stop drag"); return RET_ERR; } - if (OnStopDrag(result) != RET_OK) { + if (OnStopDrag(result, hasCustomAnimation) != RET_OK) { FI_HILOGE("OnStopDrag failed"); return RET_ERR; } @@ -258,7 +258,7 @@ int32_t DragManager::OnStartDrag() return RET_OK; } -int32_t DragManager::OnStopDrag(int32_t result) +int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation) { CALL_DEBUG_ENTER; if (monitorId_ > 0) { @@ -269,10 +269,24 @@ int32_t DragManager::OnStopDrag(int32_t result) dragDrawing_.EraseMouseIcon(); INPUT_MANAGER->SetPointerVisible(true); } - if (result == 0) { - dragDrawing_.OnDragSuccess(); - } else { - dragDrawing_.OnDragFail(); + switch (result) { + case DragResult::DRAG_SUCCESS: { + if (!hasCustomAnimation) { + dragDrawing_.OnDragSuccess(); + } + break; + } + case DragResult::DRAG_FAIL: + case DragResult::DRAG_CANCEL: { + if (!dragData.hasCanceledAnimation) { + dragDrawing_.OnDragFail(); + } + break; + } + default: { + FI_HILOGE("Unsupported DragResult type, DragResult:%{public}d", result); + break; + } } dragDrawing_.DestroyDragWindow(); return RET_OK; -- Gitee From df179376eb29adc9b3b81bd54f4a5a8b4cc0cf97 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Thu, 16 Mar 2023 12:11:12 +0000 Subject: [PATCH 07/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: Ieca2935ac9d5c0a7c854209cbfab243135180ad3 --- .../interaction/drag/include/drag_drawing.h | 2 + .../interaction/drag/src/drag_drawing.cpp | 91 +++++++++++-------- .../interaction/drag/src/drag_manager.cpp | 69 ++++++++------ utils/common/include/devicestatus_errors.h | 6 ++ 4 files changed, 102 insertions(+), 66 deletions(-) diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index 75987b23f..2631119d5 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -72,6 +72,7 @@ public: void Draw(OHOS::Rosen::RSDrawingContext &context) const override; void SetAlpha(float alpha); void SetScale(float scale); + private: std::shared_ptr> alpha_ { nullptr }; std::shared_ptr> scale_ { nullptr }; @@ -90,6 +91,7 @@ public: void OnDragFail(); void EraseMouseIcon(); void DestroyDragWindow(); + void UpdateDrawingState(); private: int32_t InitLayer(); diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 80f57ef25..7bcbda4b8 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -61,11 +61,16 @@ constexpr int32_t VIEW_BOX_POS = 2; constexpr int32_t PIXEL_MAP_INDEX = 0; constexpr int32_t DRAG_STYLE_INDEX = 1; constexpr int32_t MOUSE_ICON_INDEX = 2; +constexpr int32_t DRAG_DRAWING_BEGIN = 0; +constexpr int32_t DRAG_DRAWING_END = -1; constexpr size_t TOUCH_NODE_MIN_COUNT = 2; constexpr size_t MOUSE_NODE_MIN_COUNT = 3; constexpr double ONETHOUSAND = 1000.0; -constexpr float SUCCESS_ENLARGE_SCALE = 1.2f; -constexpr float FAIL_ENLARGE_SCALE = 0.1f; +constexpr float BEGIN_ALPHA = 1.0f; +constexpr float END_ALPHA = 0.0f; +constexpr float BEGIN_SCALE = 1.0f; +constexpr float END_SCALE_SUCCESS = 1.2f; +constexpr float END_SCALE_FAIL = 0.1f; constexpr float PIVOT_X = 0.5f; constexpr float PIVOT_Y = 0.5f; const std::string COPY_DRAG_PATH = "/system/etc/device_status/drag_icon/Copy_Drag.svg"; @@ -73,6 +78,7 @@ const std::string COPY_ONE_DRAG_PATH = "/system/etc/device_status/drag_icon/Copy const std::string FORBID_DRAG_PATH = "/system/etc/device_status/drag_icon/Forbid_Drag.svg"; const std::string MOUSE_DRAG_PATH = "/system/etc/device_status/drag_icon/Mouse_Drag.png"; struct DrawingInfo { + int32_t drawingState { -1 }; int32_t sourceType { -1 }; int32_t currentStyle { -1 }; int32_t displayId { -1 }; @@ -93,41 +99,46 @@ struct DrawingInfo { int32_t DragDrawing::Init(const DragData &dragData) { CALL_DEBUG_ENTER; - CHKPR(dragData.shadowInfo.pixelMap, RET_ERR); + if (g_drawingInfo.drawingState != DRAG_DRAWING_END) { + FI_HILOGE("Drag drawing is running, can not init again"); + return INIT_CANCEL; + } + CHKPR(dragData.shadowInfo.pixelMap, INIT_FAIL); if ((dragData.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && (dragData.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN)) { FI_HILOGE("Invalid sourceType:%{public}d", dragData.sourceType); - return RET_ERR; + return INIT_FAIL; } + g_drawingInfo.drawingState = DRAG_DRAWING_BEGIN; g_drawingInfo.sourceType = dragData.sourceType; g_drawingInfo.displayId = dragData.displayId; g_drawingInfo.pixelMap = dragData.shadowInfo.pixelMap; g_drawingInfo.pixelMapX = dragData.shadowInfo.x; g_drawingInfo.pixelMapY = dragData.shadowInfo.y; CreateWindow(dragData.displayX, dragData.displayY); - CHKPR(g_drawingInfo.dragWindow, RET_ERR); + CHKPR(g_drawingInfo.dragWindow, INIT_FAIL); if (InitLayer() != RET_OK) { FI_HILOGE("Init layer failed"); - return RET_ERR; + return INIT_FAIL; } if (DrawShadow() != RET_OK) { FI_HILOGE("Draw shadow failed"); - return RET_ERR; + return INIT_FAIL; } if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { - CHKPR(g_drawingInfo.dragWindow, RET_ERR); + CHKPR(g_drawingInfo.dragWindow, INIT_FAIL); g_drawingInfo.dragWindow->Show(); InitAnimation(); return RET_OK; } if (DrawMouseIcon() != RET_OK) { FI_HILOGE("Draw mouse icon failed"); - return RET_ERR; + return INIT_FAIL; } - CHKPR(g_drawingInfo.dragWindow, RET_ERR); + CHKPR(g_drawingInfo.dragWindow, INIT_FAIL); g_drawingInfo.dragWindow->Show(); InitAnimation(); - return RET_OK; + return INIT_SUCCESS; } void DragDrawing::Draw(int32_t displayId, int32_t displayX, int32_t displayY) @@ -185,14 +196,14 @@ void DragDrawing::OnDragSuccess() drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); - drawDynamicEffectModifier_->SetAlpha(1.0f); - drawDynamicEffectModifier_->SetScale(1.0f); + drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); + drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(SUCCESS_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - drawDynamicEffectModifier_->SetAlpha(0.0f); - drawDynamicEffectModifier_->SetScale(SUCCESS_ENLARGE_SCALE); + drawDynamicEffectModifier_->SetAlpha(END_ALPHA); + drawDynamicEffectModifier_->SetScale(END_SCALE_SUCCESS); }); CHKPV(runner_); runner_->Run(); @@ -208,14 +219,14 @@ void DragDrawing::OnDragFail() drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); - drawDynamicEffectModifier_->SetAlpha(1.0f); - drawDynamicEffectModifier_->SetScale(1.0f); + drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); + drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(FAIL_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - drawDynamicEffectModifier_->SetAlpha(0.0f); - drawDynamicEffectModifier_->SetScale(FAIL_ENLARGE_SCALE); + drawDynamicEffectModifier_->SetAlpha(END_ALPHA); + drawDynamicEffectModifier_->SetScale(END_SCALE_FAIL); }); CHKPV(runner_); runner_->Run(); @@ -225,15 +236,13 @@ void DragDrawing::EraseMouseIcon() { CALL_DEBUG_ENTER; if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) { - FI_HILOGE("Canvas nodes vector size invalid, nodes.size(): %{public}zu", g_drawingInfo.nodes.size()); - return; - } - if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { - FI_HILOGE("Touch type not need erase mouse icon"); + FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); return; } + auto mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; + CHKPV(mouseIconNode); CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveChild(g_drawingInfo.nodes[MOUSE_ICON_INDEX]); + g_drawingInfo.rootNode->RemoveChild(mouseIconNode); CHKPV(rsUiDirector_); rsUiDirector_->SendMessages(); } @@ -265,6 +274,12 @@ void DragDrawing::DestroyDragWindow() } } +void DragDrawing::UpdateDrawingState() +{ + CALL_DEBUG_ENTER; + g_drawingInfo.drawingState = DRAG_DRAWING_END; +} + void DragDrawing::InitAnimation() { CALL_DEBUG_ENTER; @@ -282,12 +297,12 @@ int32_t DragDrawing::DrawShadow() CALL_DEBUG_ENTER; if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT)) { - FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && (g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) { - FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } auto pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; @@ -304,7 +319,7 @@ int32_t DragDrawing::DrawMouseIcon() { CALL_DEBUG_ENTER; if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) { - FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } auto mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; @@ -322,12 +337,12 @@ int32_t DragDrawing::DrawStyle() CALL_DEBUG_ENTER; if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT)) { - FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && (g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) { - FI_HILOGE("Nodes size invalid, node size: %{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } auto dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; @@ -347,12 +362,12 @@ int32_t DragDrawing::InitVSync() CHKPR(g_drawingInfo.surfaceNode, RET_ERR); g_drawingInfo.surfaceNode->SetPivot(PIVOT_X, PIVOT_Y); OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); - auto rsClient = std::static_pointer_cast( - OHOS::Rosen::RSIRenderClient::CreateRenderServiceClient()); + auto& rsClient = OHOS::Rosen::RSInterfaces::GetInstance(); if (receiver_ == nullptr) { CHKPR(handler_, RET_ERR); - receiver_ = rsClient->CreateVSyncReceiver("DragDrawing", handler_); + receiver_ = rsClient.CreateVSyncReceiver("DragDrawing", handler_); } + CHKPR(receiver_, RET_ERR); auto ret = receiver_->Init(); if (ret) { FI_HILOGE("Receiver init failed"); @@ -378,9 +393,11 @@ void DragDrawing::OnVsync() CHKPV(rsUiDirector_); bool hasRunningAnimation = rsUiDirector_->RunningCustomAnimation(startNum_); if (!hasRunningAnimation) { - FI_HILOGD("Stop runner_, hasRunningAnimation: %{public}d", hasRunningAnimation); + FI_HILOGD("Stop runner_, hasRunningAnimation:%{public}d", hasRunningAnimation); CHKPV(runner_); runner_->Stop(); + DestroyDragWindow(); + g_drawingInfo.drawingState = DRAG_DRAWING_END; return; } rsUiDirector_->SendMessages(); @@ -728,11 +745,13 @@ void DrawDynamicEffectModifier::Draw(OHOS::Rosen::RSDrawingContext &context) con { CALL_DEBUG_ENTER; CHKPV(alpha_); + CHKPV(g_drawingInfo.rootNode); + g_drawingInfo.rootNode->SetAlpha(alpha_->Get()); CHKPV(scale_); + CHKPV(g_drawingInfo.surfaceNode); + g_drawingInfo.surfaceNode->SetScale(scale_->Get(), scale_->Get()); auto rsSurface = OHOS::Rosen::RSSurfaceExtractor::ExtractRSSurface(g_drawingInfo.surfaceNode); CHKPV(rsSurface); - g_drawingInfo.rootNode->SetAlpha(alpha_->Get()); - g_drawingInfo.surfaceNode->SetScale(scale_->Get(), scale_->Get()); auto frame = rsSurface->RequestFrame(g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); if (frame == nullptr) { FI_HILOGE("Failed to create frame"); diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index 002e221ac..86d83b9e9 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -249,11 +249,15 @@ int32_t DragManager::OnStartDrag() if (dragData.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { INPUT_MANAGER->SetPointerVisible(false); } - if (dragDrawing_.Init(dragData) != RET_OK) { - FI_HILOGE("Init Picture failed"); + if (dragDrawing_.Init(dragData) == INIT_FAIL) { + FI_HILOGE("Init drag drawing failed"); dragDrawing_.DestroyDragWindow(); return RET_ERR; } + if (dragDrawing_.Init(dragData) == INIT_CANCEL) { + FI_HILOGE("Init drag drawing cancel, drag animation is running"); + return RET_ERR; + } dragDrawing_.Draw(dragData.displayId, dragData.displayX, dragData.displayY); return RET_OK; } @@ -261,38 +265,43 @@ int32_t DragManager::OnStartDrag() int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation) { CALL_DEBUG_ENTER; - if (monitorId_ > 0) { - INPUT_MANAGER->RemoveMonitor(monitorId_); - monitorId_ = -1; - DragData dragData = DataAdapter.GetDragData(); - if (dragData.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { - dragDrawing_.EraseMouseIcon(); - INPUT_MANAGER->SetPointerVisible(true); - } - switch (result) { - case DragResult::DRAG_SUCCESS: { - if (!hasCustomAnimation) { - dragDrawing_.OnDragSuccess(); - } - break; - } - case DragResult::DRAG_FAIL: - case DragResult::DRAG_CANCEL: { - if (!dragData.hasCanceledAnimation) { - dragDrawing_.OnDragFail(); - } - break; + if (monitorId_ <= 0) { + FI_HILOGE("RemoveMonitor failed, monitorId_:%{public}d", monitorId_); + return RET_ERR; + } + INPUT_MANAGER->RemoveMonitor(monitorId_); + monitorId_ = -1; + DragData dragData = DataAdapter.GetDragData(); + if (dragData.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { + dragDrawing_.EraseMouseIcon(); + INPUT_MANAGER->SetPointerVisible(true); + } + switch (result) { + case DragResult::DRAG_SUCCESS: { + if (!hasCustomAnimation) { + dragDrawing_.OnDragSuccess(); + } else { + dragDrawing_.DestroyDragWindow(); + dragDrawing_.UpdateDragStyle(); } - default: { - FI_HILOGE("Unsupported DragResult type, DragResult:%{public}d", result); - break; + break; + } + case DragResult::DRAG_FAIL: + case DragResult::DRAG_CANCEL: { + if (!dragData.hasCanceledAnimation) { + dragDrawing_.OnDragFail(); + } else { + dragDrawing_.DestroyDragWindow(); + dragDrawing_.UpdateDragStyle(); } + break; + } + default: { + FI_HILOGE("Unsupported DragResult type, DragResult:%{public}d", result); + break; } - dragDrawing_.DestroyDragWindow(); - return RET_OK; } - FI_HILOGE("RemoveMonitor failed, monitorId_:%{public}d", monitorId_); - return RET_ERR; + return RET_OK; } } // namespace DeviceStatus } // namespace Msdp diff --git a/utils/common/include/devicestatus_errors.h b/utils/common/include/devicestatus_errors.h index 1d3270e49..268972f43 100644 --- a/utils/common/include/devicestatus_errors.h +++ b/utils/common/include/devicestatus_errors.h @@ -76,6 +76,12 @@ enum { DEVICESTATUS_INVALID_FD = -2, DEVICESTATUS_NOT_FIND_JSON_ITEM = -3, }; + +enum { + INIT_FAIL = -1, + INIT_SUCCESS = 0, + INIT_CANCEL = 1, +}; } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS -- Gitee From bf2eb5545dfbe9894d24ef2680b651b628853731 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Fri, 17 Mar 2023 00:51:49 +0000 Subject: [PATCH 08/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: Id187e792712fbf43d5e831a37cdbc37e2d3544cc --- services/interaction/drag/src/drag_drawing.cpp | 2 +- services/interaction/drag/src/drag_manager.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 7bcbda4b8..c86b61d6e 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -19,6 +19,7 @@ #include #include +#include "../wm/window.h" #include "display_manager.h" #include "include/core/SkTextBlob.h" #include "image_source.h" @@ -34,7 +35,6 @@ #include "ui/rs_surface_extractor.h" #include "ui/rs_surface_node.h" #include "ui/rs_ui_director.h" -#include "../wm/window.h" #include "devicestatus_define.h" #include "drag_data_adapter.h" diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index 86d83b9e9..b6953382f 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -282,7 +282,7 @@ int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation) dragDrawing_.OnDragSuccess(); } else { dragDrawing_.DestroyDragWindow(); - dragDrawing_.UpdateDragStyle(); + dragDrawing_.UpdateDrawingState(); } break; } @@ -292,7 +292,7 @@ int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation) dragDrawing_.OnDragFail(); } else { dragDrawing_.DestroyDragWindow(); - dragDrawing_.UpdateDragStyle(); + dragDrawing_.UpdateDrawingState(); } break; } -- Gitee From 32c088b66b1b32c31542bcac62fabeea4750f85f Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sat, 18 Mar 2023 03:22:36 +0000 Subject: [PATCH 09/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I9828ba48412e69091676846767d8698ee850d794 --- .../interaction/drag/include/drag_drawing.h | 8 +- .../interaction/drag/src/drag_drawing.cpp | 84 +++++++++++-------- .../interaction/drag/src/drag_manager.cpp | 5 +- utils/common/include/util.h | 1 + utils/common/src/util.cpp | 11 +++ 5 files changed, 66 insertions(+), 43 deletions(-) diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index 2631119d5..8edd6a5a9 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -107,10 +107,10 @@ private: private: int64_t startNum_ { -1 }; std::shared_ptr canvasNode_ { nullptr }; - std::shared_ptr drawSVGModifier_ { nullptr }; - std::shared_ptr drawPixelMapModifier_ { nullptr }; - std::shared_ptr drawMouseIconModifier_ { nullptr }; - std::shared_ptr drawDynamicEffectModifier_ { nullptr }; + std::weak_ptr drawSVGModifier_; + std::weak_ptr drawPixelMapModifier_; + std::weak_ptr drawMouseIconModifier_; + std::weak_ptr drawDynamicEffectModifier_; std::shared_ptr rsUiDirector_ { nullptr }; std::shared_ptr receiver_ { nullptr }; std::shared_ptr handler_ { nullptr }; diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index c86b61d6e..3e0d9affb 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -189,13 +189,13 @@ int32_t DragDrawing::UpdateDragStyle(int32_t style) void DragDrawing::OnDragSuccess() { CALL_DEBUG_ENTER; - if (drawDynamicEffectModifier_ != nullptr) { + if (drawDynamicEffectModifier_.lock() != nullptr) { CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_.lock()); } drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); + g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_.lock()); drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); @@ -212,13 +212,13 @@ void DragDrawing::OnDragSuccess() void DragDrawing::OnDragFail() { CALL_DEBUG_ENTER; - if (drawDynamicEffectModifier_ != nullptr) { + if (drawDynamicEffectModifier_.lock() != nullptr) { CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_.lock()); } drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); + g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_.lock()); drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); @@ -297,21 +297,21 @@ int32_t DragDrawing::DrawShadow() CALL_DEBUG_ENTER; if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT)) { - FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid when mouse type, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && (g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) { - FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid when touchscreen type, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } auto pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; CHKPR(pixelMapNode, RET_ERR); - if (drawPixelMapModifier_ != nullptr) { - pixelMapNode->RemoveModifier(drawPixelMapModifier_); + if (drawPixelMapModifier_.lock() != nullptr) { + pixelMapNode->RemoveModifier(drawPixelMapModifier_.lock()); } drawPixelMapModifier_ = std::make_shared(); - pixelMapNode->AddModifier(drawPixelMapModifier_); + pixelMapNode->AddModifier(drawPixelMapModifier_.lock()); return RET_OK; } @@ -324,11 +324,11 @@ int32_t DragDrawing::DrawMouseIcon() } auto mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; CHKPR(mouseIconNode, RET_ERR); - if (drawMouseIconModifier_ != nullptr) { - mouseIconNode->RemoveModifier(drawMouseIconModifier_); + if (drawMouseIconModifier_.lock() != nullptr) { + mouseIconNode->RemoveModifier(drawMouseIconModifier_.lock()); } drawMouseIconModifier_ = std::make_shared(); - mouseIconNode->AddModifier(drawMouseIconModifier_); + mouseIconNode->AddModifier(drawMouseIconModifier_.lock()); return RET_OK; } @@ -337,21 +337,21 @@ int32_t DragDrawing::DrawStyle() CALL_DEBUG_ENTER; if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) && (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT)) { - FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid when mouse type, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } if ((g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && (g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) { - FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); + FI_HILOGE("Nodes size invalid when touchscreen type, node size:%{public}zu", g_drawingInfo.nodes.size()); return RET_ERR; } auto dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; CHKPR(dragStyleNode, RET_ERR); - if (drawSVGModifier_ != nullptr) { - dragStyleNode->RemoveModifier(drawSVGModifier_); + if (drawSVGModifier_.lock() != nullptr) { + dragStyleNode->RemoveModifier(drawSVGModifier_.lock()); } - auto drawSVGModifier_ = std::make_shared(); - dragStyleNode->AddModifier(drawSVGModifier_); + drawSVGModifier_ = std::make_shared(); + dragStyleNode->AddModifier(drawSVGModifier_.lock()); return RET_OK; } @@ -461,8 +461,10 @@ void DragDrawing::InitCanvas(int32_t width, int32_t height) if (g_drawingInfo.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { auto mouseIconNode = OHOS::Rosen::RSCanvasNode::Create(); CHKPV(mouseIconNode); - mouseIconNode->SetBounds(0 - g_drawingInfo.pixelMapX, 0 - g_drawingInfo.pixelMapY, SVG_HEIGHT, SVG_HEIGHT); - mouseIconNode->SetFrame(0 - g_drawingInfo.pixelMapX, 0 - g_drawingInfo.pixelMapY, SVG_HEIGHT, SVG_HEIGHT); + mouseIconNode->SetBounds(ChangeNumber(g_drawingInfo.pixelMapX), ChangeNumber(g_drawingInfo.pixelMapY), + SVG_HEIGHT, SVG_HEIGHT); + mouseIconNode->SetFrame(ChangeNumber(g_drawingInfo.pixelMapX), ChangeNumber(g_drawingInfo.pixelMapY), + SVG_HEIGHT, SVG_HEIGHT); g_drawingInfo.nodes.emplace_back(mouseIconNode); g_drawingInfo.rootNode->AddChild(pixelMapNode); g_drawingInfo.rootNode->AddChild(dragStyleNode); @@ -512,17 +514,18 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const FI_HILOGE("Svg file is invalid"); return; } - std::shared_ptr pixelMap = DecodeSvgToPixelMap(filePath); - CHKPV(pixelMap); - auto rosenImage = std::make_shared(); - rosenImage->SetPixelMap(pixelMap); - rosenImage->SetImageRepeat(0); - CHKPV(g_drawingInfo.pixelMap); - int32_t svgTouchPositionX = g_drawingInfo.pixelMap->GetWidth() + EIGHT_SIZE - pixelMap->GetWidth(); auto pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; CHKPV(pixelMapNode); + CHKPV(g_drawingInfo.pixelMap); pixelMapNode->SetBounds(0, EIGHT_SIZE, g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); pixelMapNode->SetFrame(0, EIGHT_SIZE, g_drawingInfo.pixelMap->GetWidth(), g_drawingInfo.pixelMap->GetHeight()); + std::shared_ptr pixelMap = DecodeSvgToPixelMap(filePath); + CHKPV(pixelMap); + int32_t svgTouchPositionX = g_drawingInfo.pixelMap->GetWidth() + EIGHT_SIZE - pixelMap->GetWidth(); + if (svgTouchPositionX < 0) { + FI_HILOGD("svgTouchPositionX:%{public}d", svgTouchPositionX); + svgTouchPositionX = 0; + } auto dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; CHKPV(dragStyleNode); dragStyleNode->SetBounds(svgTouchPositionX, 0, pixelMap->GetWidth(), pixelMap->GetHeight()); @@ -531,6 +534,9 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const dragStyleNode->SetBgImageHeight(SVG_HEIGHT); dragStyleNode->SetBgImagePositionX(0); dragStyleNode->SetBgImagePositionY(0); + auto rosenImage = std::make_shared(); + rosenImage->SetPixelMap(pixelMap); + rosenImage->SetImageRepeat(0); dragStyleNode->SetBgImage(rosenImage); g_drawingInfo.rootNodeWidth = g_drawingInfo.pixelMap->GetWidth() + EIGHT_SIZE; g_drawingInfo.rootNodeHeight = pixelMap->GetHeight() + g_drawingInfo.pixelMap->GetHeight() + EIGHT_SIZE; @@ -558,16 +564,16 @@ int32_t DrawSVGModifier::UpdateSvgNodeInfo(xmlNodePtr &curNode, int32_t strSize) oStrSteam << xmlGetProp(curNode, BAD_CAST "viewBox"); std::string srcViewBox = oStrSteam.str(); std::istringstream iStrSteam(srcViewBox); - std::string word; + std::string string; std::string tgtViewBox; int32_t i = 0; int32_t size = srcViewBox.size(); - while ((iStrSteam >> word) && (i < size)) { + while ((iStrSteam >> string) && (i < size)) { if (i == VIEW_BOX_POS) { - number = std::stoi(word) + strSize; - word = std::to_string(number); + number = std::stoi(string) + strSize; + string = std::to_string(number); } - tgtViewBox.append(word); + tgtViewBox.append(string); tgtViewBox += " "; ++i; } @@ -580,7 +586,7 @@ xmlNodePtr DrawSVGModifier::FindRectNode(xmlNodePtr &curNode) const { CALL_DEBUG_ENTER; curNode = curNode->xmlChildrenNode; - while (curNode != NULL) { + while (curNode != nullptr) { if (!xmlStrcmp(curNode->name, BAD_CAST "g")) { while (!xmlStrcmp(curNode->name, BAD_CAST "g")) { curNode = curNode->xmlChildrenNode; @@ -595,7 +601,7 @@ xmlNodePtr DrawSVGModifier::FindRectNode(xmlNodePtr &curNode) const xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr &curNode, int32_t strSize) const { CALL_DEBUG_ENTER; - while (curNode != NULL) { + while (curNode != nullptr) { if (!xmlStrcmp(curNode->name, BAD_CAST "rect")) { std::ostringstream oStrSteam; oStrSteam << xmlGetProp(curNode, BAD_CAST "width"); @@ -615,7 +621,7 @@ xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr &curNode, int32_t strSize) void DrawSVGModifier::UpdateTspanNode(xmlNodePtr &curNode) const { CALL_DEBUG_ENTER; - while (curNode != NULL) { + while (curNode != nullptr) { if (!xmlStrcmp(curNode->name, BAD_CAST "tspan")) { std::string tgtTspanValue = std::to_string(g_drawingInfo.currentStyle); xmlNodeSetContent(curNode, BAD_CAST tgtTspanValue.c_str()); @@ -627,6 +633,7 @@ void DrawSVGModifier::UpdateTspanNode(xmlNodePtr &curNode) const int32_t DrawSVGModifier::ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const { CALL_DEBUG_ENTER; + CHKPR(curNode, RET_ERR); std::string strStyle = std::to_string(g_drawingInfo.currentStyle); int32_t strSize = (strStyle.size() - 1) * EIGHT_SIZE; xmlKeepBlanksDefault(0); @@ -636,7 +643,9 @@ int32_t DrawSVGModifier::ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const return RET_ERR; } curNode = FindRectNode(curNode); + CHKPR(curNode, RET_ERR); curNode = UpdateRectNode(curNode, strSize); + CHKPR(curNode, RET_ERR); UpdateTspanNode(curNode); return RET_OK; } @@ -648,6 +657,7 @@ std::shared_ptr DrawSVGModifier::DecodeSvgToPixelMap( xmlDocPtr xmlDoc = xmlReadFile(filePath.c_str(), 0, XML_PARSE_NOBLANKS); if (g_drawingInfo.currentStyle != 0) { xmlNodePtr node = xmlDocGetRootElement(xmlDoc); + CHKPP(node); int32_t ret = ParseAndAdjustSvgInfo(node); if (ret != RET_OK) { FI_HILOGE("Parse and adjust svg info failed"); diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index b6953382f..8a23658e4 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -249,12 +249,13 @@ int32_t DragManager::OnStartDrag() if (dragData.sourceType == OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { INPUT_MANAGER->SetPointerVisible(false); } - if (dragDrawing_.Init(dragData) == INIT_FAIL) { + int32_t ret = dragDrawing_.Init(dragData); + if (ret == INIT_FAIL) { FI_HILOGE("Init drag drawing failed"); dragDrawing_.DestroyDragWindow(); return RET_ERR; } - if (dragDrawing_.Init(dragData) == INIT_CANCEL) { + if (ret == INIT_CANCEL) { FI_HILOGE("Init drag drawing cancel, drag animation is running"); return RET_ERR; } diff --git a/utils/common/include/util.h b/utils/common/include/util.h index 1596da734..234127415 100644 --- a/utils/common/include/util.h +++ b/utils/common/include/util.h @@ -67,6 +67,7 @@ bool IsValidPath(const std::string &rootDir, const std::string &filePath); bool IsValidSvgPath(const std::string &filePath); bool IsFileExists(const std::string &fileName); bool IsValidSvgFile(const std::string &filePath); +int32_t ChangeNumber(int32_t num); } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/utils/common/src/util.cpp b/utils/common/src/util.cpp index 5177b1c2d..d8317f8a7 100644 --- a/utils/common/src/util.cpp +++ b/utils/common/src/util.cpp @@ -270,6 +270,17 @@ bool IsValidSvgFile(const std::string &filePath) } return true; } + +int32_t ChangeNumber(int32_t num) +{ + if (num < 0) { + num = ~(num - 1); + } else if (num > 0) { + num = ~num + 1; + } + FI_HILOGD("Change number succeed, num:%{public}d", num); + return num; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file -- Gitee From 62dfe8c332765ab269e4c2bf40ce4cb2b32d62ec Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sat, 18 Mar 2023 07:10:24 +0000 Subject: [PATCH 10/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: Ica961c08d7a54640a573f306702b48b193df5b98 --- .../interaction/drag/include/drag_drawing.h | 4 +- .../interaction/drag/include/drag_manager.h | 1 - .../interaction/drag/src/drag_drawing.cpp | 158 +++++++++++------- .../interaction/drag/src/drag_manager.cpp | 15 -- .../native/include/devicestatus_service.h | 1 - services/native/src/devicestatus_service.cpp | 19 +-- utils/common/include/util.h | 1 + utils/common/src/util.cpp | 11 +- 8 files changed, 106 insertions(+), 104 deletions(-) diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index 8edd6a5a9..986892bfa 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -40,9 +40,9 @@ public: void Draw(OHOS::Rosen::RSDrawingContext& context) const override; private: - int32_t UpdateSvgNodeInfo(xmlNodePtr &curNode, int32_t strSize) const; + int32_t UpdateSvgNodeInfo(const xmlNodePtr &curNode, int32_t extendSvgWidth) const; xmlNodePtr FindRectNode(xmlNodePtr &curNode) const; - xmlNodePtr UpdateRectNode(xmlNodePtr &curNode, int32_t strSize) const; + xmlNodePtr UpdateRectNode(xmlNodePtr &curNode, int32_t extendSvgWidth) const; void UpdateTspanNode(xmlNodePtr &curNode) const; int32_t ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const; std::shared_ptr DecodeSvgToPixelMap(const std::string &filePath) const; diff --git a/services/interaction/drag/include/drag_manager.h b/services/interaction/drag/include/drag_manager.h index 167767189..cb6ff1a97 100644 --- a/services/interaction/drag/include/drag_manager.h +++ b/services/interaction/drag/include/drag_manager.h @@ -44,7 +44,6 @@ public: int32_t StartDrag(const DragData &dragData, SessionPtr sess); int32_t StopDrag(DragResult result, bool hasCustomAnimation); int32_t GetDragTargetPid() const; - int32_t UpdateDragStyle(int32_t style); void SetDragTargetPid(int32_t dragTargetPid); void DragCallback(std::shared_ptr pointerEvent); void OnDragUp(std::shared_ptr pointerEvent); diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 3e0d9affb..5fcf43f5b 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -15,6 +15,7 @@ #include "drag_drawing.h" +#include #include #include #include @@ -58,11 +59,11 @@ constexpr int32_t SIXTEEN = 16; constexpr int32_t FAIL_ANIMATION_DURATION = 1000; constexpr int32_t SUCCESS_ANIMATION_DURATION = 300; constexpr int32_t VIEW_BOX_POS = 2; +constexpr int32_t FORBID_DRAG_STYLE = 0; +constexpr int32_t ONE_FILE_DRAG_STYLE = 1; constexpr int32_t PIXEL_MAP_INDEX = 0; constexpr int32_t DRAG_STYLE_INDEX = 1; constexpr int32_t MOUSE_ICON_INDEX = 2; -constexpr int32_t DRAG_DRAWING_BEGIN = 0; -constexpr int32_t DRAG_DRAWING_END = -1; constexpr size_t TOUCH_NODE_MIN_COUNT = 2; constexpr size_t MOUSE_NODE_MIN_COUNT = 3; constexpr double ONETHOUSAND = 1000.0; @@ -78,7 +79,7 @@ const std::string COPY_ONE_DRAG_PATH = "/system/etc/device_status/drag_icon/Copy const std::string FORBID_DRAG_PATH = "/system/etc/device_status/drag_icon/Forbid_Drag.svg"; const std::string MOUSE_DRAG_PATH = "/system/etc/device_status/drag_icon/Mouse_Drag.png"; struct DrawingInfo { - int32_t drawingState { -1 }; + std::atomic isRunning { false }; int32_t sourceType { -1 }; int32_t currentStyle { -1 }; int32_t displayId { -1 }; @@ -99,7 +100,7 @@ struct DrawingInfo { int32_t DragDrawing::Init(const DragData &dragData) { CALL_DEBUG_ENTER; - if (g_drawingInfo.drawingState != DRAG_DRAWING_END) { + if (g_drawingInfo.isRunning) { FI_HILOGE("Drag drawing is running, can not init again"); return INIT_CANCEL; } @@ -109,7 +110,7 @@ int32_t DragDrawing::Init(const DragData &dragData) FI_HILOGE("Invalid sourceType:%{public}d", dragData.sourceType); return INIT_FAIL; } - g_drawingInfo.drawingState = DRAG_DRAWING_BEGIN; + g_drawingInfo.isRunning = true; g_drawingInfo.sourceType = dragData.sourceType; g_drawingInfo.displayId = dragData.displayId; g_drawingInfo.pixelMap = dragData.shadowInfo.pixelMap; @@ -189,21 +190,23 @@ int32_t DragDrawing::UpdateDragStyle(int32_t style) void DragDrawing::OnDragSuccess() { CALL_DEBUG_ENTER; - if (drawDynamicEffectModifier_.lock() != nullptr) { + auto spDrawDynamicEffectModifier = drawDynamicEffectModifier_.lock(); + if (spDrawDynamicEffectModifier != nullptr) { CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_.lock()); + g_drawingInfo.rootNode->RemoveModifier(spDrawDynamicEffectModifier); } drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_.lock()); - drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); - drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); + spDrawDynamicEffectModifier = drawDynamicEffectModifier_.lock(); + g_drawingInfo.rootNode->AddModifier(spDrawDynamicEffectModifier); + spDrawDynamicEffectModifier->SetAlpha(BEGIN_ALPHA); + spDrawDynamicEffectModifier->SetScale(BEGIN_SCALE); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(SUCCESS_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - drawDynamicEffectModifier_->SetAlpha(END_ALPHA); - drawDynamicEffectModifier_->SetScale(END_SCALE_SUCCESS); + spDrawDynamicEffectModifier->SetAlpha(END_ALPHA); + spDrawDynamicEffectModifier->SetScale(END_SCALE_SUCCESS); }); CHKPV(runner_); runner_->Run(); @@ -212,21 +215,23 @@ void DragDrawing::OnDragSuccess() void DragDrawing::OnDragFail() { CALL_DEBUG_ENTER; - if (drawDynamicEffectModifier_.lock() != nullptr) { + auto spDrawDynamicEffectModifier = drawDynamicEffectModifier_.lock(); + if (spDrawDynamicEffectModifier != nullptr) { CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_.lock()); + g_drawingInfo.rootNode->RemoveModifier(spDrawDynamicEffectModifier); } drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_.lock()); - drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); - drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); + spDrawDynamicEffectModifier = drawDynamicEffectModifier_.lock(); + g_drawingInfo.rootNode->AddModifier(spDrawDynamicEffectModifier); + spDrawDynamicEffectModifier->SetAlpha(BEGIN_ALPHA); + spDrawDynamicEffectModifier->SetScale(BEGIN_SCALE); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(FAIL_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - drawDynamicEffectModifier_->SetAlpha(END_ALPHA); - drawDynamicEffectModifier_->SetScale(END_SCALE_FAIL); + spDrawDynamicEffectModifier->SetAlpha(END_ALPHA); + spDrawDynamicEffectModifier->SetScale(END_SCALE_FAIL); }); CHKPV(runner_); runner_->Run(); @@ -277,7 +282,7 @@ void DragDrawing::DestroyDragWindow() void DragDrawing::UpdateDrawingState() { CALL_DEBUG_ENTER; - g_drawingInfo.drawingState = DRAG_DRAWING_END; + g_drawingInfo.isRunning = false; } void DragDrawing::InitAnimation() @@ -307,11 +312,13 @@ int32_t DragDrawing::DrawShadow() } auto pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; CHKPR(pixelMapNode, RET_ERR); - if (drawPixelMapModifier_.lock() != nullptr) { - pixelMapNode->RemoveModifier(drawPixelMapModifier_.lock()); + auto spDrawPixelMapModifier = drawPixelMapModifier_.lock(); + if (spDrawPixelMapModifier != nullptr) { + pixelMapNode->RemoveModifier(spDrawPixelMapModifier); } drawPixelMapModifier_ = std::make_shared(); - pixelMapNode->AddModifier(drawPixelMapModifier_.lock()); + spDrawPixelMapModifier = drawPixelMapModifier_.lock(); + pixelMapNode->AddModifier(spDrawPixelMapModifier); return RET_OK; } @@ -324,11 +331,13 @@ int32_t DragDrawing::DrawMouseIcon() } auto mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; CHKPR(mouseIconNode, RET_ERR); - if (drawMouseIconModifier_.lock() != nullptr) { - mouseIconNode->RemoveModifier(drawMouseIconModifier_.lock()); + auto spDrawMouseIconModifier = drawMouseIconModifier_.lock(); + if (spDrawMouseIconModifier != nullptr) { + mouseIconNode->RemoveModifier(spDrawMouseIconModifier); } drawMouseIconModifier_ = std::make_shared(); - mouseIconNode->AddModifier(drawMouseIconModifier_.lock()); + spDrawMouseIconModifier = drawMouseIconModifier_.lock(); + mouseIconNode->AddModifier(spDrawMouseIconModifier); return RET_OK; } @@ -347,11 +356,13 @@ int32_t DragDrawing::DrawStyle() } auto dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; CHKPR(dragStyleNode, RET_ERR); - if (drawSVGModifier_.lock() != nullptr) { - dragStyleNode->RemoveModifier(drawSVGModifier_.lock()); + auto spDrawSVGModifier = drawSVGModifier_.lock(); + if (spDrawSVGModifier != nullptr) { + dragStyleNode->RemoveModifier(spDrawSVGModifier); } drawSVGModifier_ = std::make_shared(); - dragStyleNode->AddModifier(drawSVGModifier_.lock()); + spDrawSVGModifier = drawSVGModifier_.lock(); + dragStyleNode->AddModifier(spDrawSVGModifier); return RET_OK; } @@ -393,11 +404,11 @@ void DragDrawing::OnVsync() CHKPV(rsUiDirector_); bool hasRunningAnimation = rsUiDirector_->RunningCustomAnimation(startNum_); if (!hasRunningAnimation) { - FI_HILOGD("Stop runner_, hasRunningAnimation:%{public}d", hasRunningAnimation); + FI_HILOGD("Stop runner, hasRunningAnimation:%{public}d", hasRunningAnimation); CHKPV(runner_); runner_->Stop(); DestroyDragWindow(); - g_drawingInfo.drawingState = DRAG_DRAWING_END; + g_drawingInfo.isRunning = false; return; } rsUiDirector_->SendMessages(); @@ -502,9 +513,9 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const CALL_DEBUG_ENTER; std::unique_ptr fs = std::make_unique(); std::string filePath = ""; - if (g_drawingInfo.currentStyle == 0) { + if (g_drawingInfo.currentStyle == FORBID_DRAG_STYLE) { filePath = FORBID_DRAG_PATH; - } else if (g_drawingInfo.currentStyle == 1) { + } else if (g_drawingInfo.currentStyle == ONE_FILE_DRAG_STYLE) { filePath = COPY_ONE_DRAG_PATH; } else { filePath = COPY_DRAG_PATH; @@ -547,33 +558,40 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); } -int32_t DrawSVGModifier::UpdateSvgNodeInfo(xmlNodePtr &curNode, int32_t strSize) const +int32_t DrawSVGModifier::UpdateSvgNodeInfo(const xmlNodePtr &curNode, int32_t extendSvgWidth) const { CALL_DEBUG_ENTER; if (xmlStrcmp(curNode->name, BAD_CAST "svg")) { FI_HILOGE("Svg format invalid"); return RET_ERR; } - std::ostringstream oStrSteam; - oStrSteam << xmlGetProp(curNode, BAD_CAST "width"); - std::string srcSvgWidth = oStrSteam.str(); - int32_t number = std::stoi(srcSvgWidth) + strSize; + std::ostringstream oStrStream; + oStrStream << xmlGetProp(curNode, BAD_CAST "width"); + std::string srcSvgWidth = oStrStream.str(); + if (!IsNum(srcSvgWidth)) { + FI_HILOGE("srcSvgWidth invalid, srcSvgWidth:%{public}s", srcSvgWidth.c_str()); + return RET_ERR; + } + int32_t number = std::stoi(srcSvgWidth) + extendSvgWidth; std::string tgtSvgWidth = std::to_string(number); xmlSetProp(curNode, BAD_CAST "width", BAD_CAST tgtSvgWidth.c_str()); - oStrSteam.clear(); - oStrSteam << xmlGetProp(curNode, BAD_CAST "viewBox"); - std::string srcViewBox = oStrSteam.str(); - std::istringstream iStrSteam(srcViewBox); - std::string string; + oStrStream.clear(); + oStrStream << xmlGetProp(curNode, BAD_CAST "viewBox"); + std::string srcViewBox = oStrStream.str(); + std::istringstream iStrStream(srcViewBox); + std::string tmpString; std::string tgtViewBox; int32_t i = 0; - int32_t size = srcViewBox.size(); - while ((iStrSteam >> string) && (i < size)) { + while (iStrStream >> tmpString) { if (i == VIEW_BOX_POS) { - number = std::stoi(string) + strSize; - string = std::to_string(number); + if (!IsNum(tmpString)) { + FI_HILOGE("tmpString invalid, tmpString:%{public}s", tmpString.c_str()); + return RET_ERR; + } + number = std::stoi(tmpString) + extendSvgWidth; + tmpString = std::to_string(number); } - tgtViewBox.append(string); + tgtViewBox.append(tmpString); tgtViewBox += " "; ++i; } @@ -598,17 +616,20 @@ xmlNodePtr DrawSVGModifier::FindRectNode(xmlNodePtr &curNode) const return curNode; } -xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr &curNode, int32_t strSize) const +xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr &curNode, int32_t extendSvgWidth) const { CALL_DEBUG_ENTER; while (curNode != nullptr) { if (!xmlStrcmp(curNode->name, BAD_CAST "rect")) { - std::ostringstream oStrSteam; - oStrSteam << xmlGetProp(curNode, BAD_CAST "width"); - std::string srcRectWidth = oStrSteam.str(); - int32_t number = std::stoi(srcRectWidth) + strSize; - std::string tgtRectWidth = std::to_string(number); - xmlSetProp(curNode, BAD_CAST "width", BAD_CAST tgtRectWidth.c_str()); + std::ostringstream oStrStream; + oStrStream << xmlGetProp(curNode, BAD_CAST "width"); + std::string srcRectWidth = oStrStream.str(); + if (!IsNum(srcRectWidth)) { + FI_HILOGE("srcRectWidth invalid, srcRectWidth:%{public}s", srcRectWidth.c_str()); + return nullptr; + } + int32_t number = std::stoi(srcRectWidth) + extendSvgWidth; + xmlSetProp(curNode, BAD_CAST "width", BAD_CAST std::to_string(number).c_str()); } if (!xmlStrcmp(curNode->name, BAD_CAST "text")) { return curNode->xmlChildrenNode; @@ -623,8 +644,7 @@ void DrawSVGModifier::UpdateTspanNode(xmlNodePtr &curNode) const CALL_DEBUG_ENTER; while (curNode != nullptr) { if (!xmlStrcmp(curNode->name, BAD_CAST "tspan")) { - std::string tgtTspanValue = std::to_string(g_drawingInfo.currentStyle); - xmlNodeSetContent(curNode, BAD_CAST tgtTspanValue.c_str()); + xmlNodeSetContent(curNode, BAD_CAST std::to_string(g_drawingInfo.currentStyle).c_str()); } curNode = curNode->next; } @@ -635,16 +655,24 @@ int32_t DrawSVGModifier::ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const CALL_DEBUG_ENTER; CHKPR(curNode, RET_ERR); std::string strStyle = std::to_string(g_drawingInfo.currentStyle); - int32_t strSize = (strStyle.size() - 1) * EIGHT_SIZE; + if (strStyle.size() == 1) { + FI_HILOGE("NO need adjust svg"); + return RET_OK; + } + if (strStyle.size() < 1) { + FI_HILOGE("strStyle size:%{public}zu invalid", strStyle.size()); + return RET_ERR; + } + int32_t extendSvgWidth = (strStyle.size() - 1) * EIGHT_SIZE; xmlKeepBlanksDefault(0); - int32_t ret = UpdateSvgNodeInfo(curNode, strSize); + int32_t ret = UpdateSvgNodeInfo(curNode, extendSvgWidth); if (ret != RET_OK) { - FI_HILOGE("Update svg node info failed"); + FI_HILOGE("Update svg node info failed, ret:%{public}d", ret); return RET_ERR; } curNode = FindRectNode(curNode); CHKPR(curNode, RET_ERR); - curNode = UpdateRectNode(curNode, strSize); + curNode = UpdateRectNode(curNode, extendSvgWidth); CHKPR(curNode, RET_ERR); UpdateTspanNode(curNode); return RET_OK; @@ -660,16 +688,16 @@ std::shared_ptr DrawSVGModifier::DecodeSvgToPixelMap( CHKPP(node); int32_t ret = ParseAndAdjustSvgInfo(node); if (ret != RET_OK) { - FI_HILOGE("Parse and adjust svg info failed"); + FI_HILOGE("Parse and adjust svg info failed, ret:%{public}d", ret); return nullptr; } } xmlChar *xmlbuff; int32_t buffersize; xmlDocDumpFormatMemory(xmlDoc, &xmlbuff, &buffersize, 1); - std::ostringstream oStrSteam; - oStrSteam << xmlbuff; - std::string content = oStrSteam.str(); + std::ostringstream oStrStream; + oStrStream << xmlbuff; + std::string content = oStrStream.str(); xmlFree(xmlbuff); xmlFreeDoc(xmlDoc); OHOS::Media::SourceOptions opts; diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index 8a23658e4..58f8ac603 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -111,21 +111,6 @@ int32_t DragManager::GetDragTargetPid() const return dragTargetPid_; } -int32_t DragManager::UpdateDragStyle(int32_t style) -{ - CALL_DEBUG_ENTER; - if (style < 0) { - FI_HILOGE("Invalid style:%{public}d", style); - return RET_ERR; - } - int32_t ret = dragDrawing_.UpdateDragStyle(style); - if (ret != RET_OK) { - FI_HILOGE("Update drag style failed"); - dragDrawing_.DestroyDragWindow(); - } - return RET_OK; -} - void DragManager::SetDragTargetPid(int32_t dragTargetPid) { CALL_DEBUG_ENTER; diff --git a/services/native/include/devicestatus_service.h b/services/native/include/devicestatus_service.h index 5291c021d..345cc52f5 100644 --- a/services/native/include/devicestatus_service.h +++ b/services/native/include/devicestatus_service.h @@ -103,7 +103,6 @@ private: int32_t OnStartDrag(const DragData &dragData, int32_t pid); int32_t OnStopDrag(DragResult result, bool hasCustomAnimation); - int32_t OnUpdateDragStyle(int32_t style); #ifdef OHOS_BUILD_ENABLE_COORDINATION int32_t OnRegisterCoordinationListener(int32_t pid); diff --git a/services/native/src/devicestatus_service.cpp b/services/native/src/devicestatus_service.cpp index a7217fd94..7fb3876cb 100644 --- a/services/native/src/devicestatus_service.cpp +++ b/services/native/src/devicestatus_service.cpp @@ -720,13 +720,7 @@ int32_t DeviceStatusService::StopDrag(DragResult result, bool hasCustomAnimation int32_t DeviceStatusService::UpdateDragStyle(int32_t style) { CALL_DEBUG_ENTER; - int32_t ret = delegateTasks_.PostSyncTask( - std::bind(&DeviceStatusService::OnUpdateDragStyle, this, style)); - if (ret != RET_OK) { - FI_HILOGE("OnStartDrag failed, ret:%{public}d", ret); - return ret; - } - return RET_OK; + return RET_ERR; } int32_t DeviceStatusService::UpdateDragMessage(const std::u16string &message) @@ -888,17 +882,6 @@ int32_t DeviceStatusService::OnStopDrag(DragResult result, bool hasCustomAnimati } return RET_OK; } - -int32_t DeviceStatusService::OnUpdateDragStyle(int32_t style) -{ - CALL_DEBUG_ENTER; - int32_t ret = dragMgr_.UpdateDragStyle(style); - if (ret != RET_OK) { - FI_HILOGE("UpdateDragStyle failed, ret:%{public}d", ret); - return ret; - } - return RET_OK; -} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/utils/common/include/util.h b/utils/common/include/util.h index 234127415..ee14c0430 100644 --- a/utils/common/include/util.h +++ b/utils/common/include/util.h @@ -67,6 +67,7 @@ bool IsValidPath(const std::string &rootDir, const std::string &filePath); bool IsValidSvgPath(const std::string &filePath); bool IsFileExists(const std::string &fileName); bool IsValidSvgFile(const std::string &filePath); +bool IsNum(const std::string &str); int32_t ChangeNumber(int32_t num); } // namespace DeviceStatus } // namespace Msdp diff --git a/utils/common/src/util.cpp b/utils/common/src/util.cpp index d8317f8a7..309faf933 100644 --- a/utils/common/src/util.cpp +++ b/utils/common/src/util.cpp @@ -19,10 +19,10 @@ #include +#include "securec.h" +#include #include #include -#include -#include "securec.h" #include "devicestatus_hilog_wrapper.h" #include "fi_log.h" @@ -271,6 +271,13 @@ bool IsValidSvgFile(const std::string &filePath) return true; } +bool IsNum(const std::string &str) +{ + std::istringstream sin(str); + double num; + return (sin >> num) && sin.eof(); +} + int32_t ChangeNumber(int32_t num) { if (num < 0) { -- Gitee From 5cd1f43629e7b7f81b53324dbe14c79db0bafe79 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sat, 18 Mar 2023 09:56:21 +0000 Subject: [PATCH 11/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: Ib9d477e09987a19025fef8f9d72afa6c8e1b47d1 --- .../native/interaction/test/unittest/BUILD.gn | 24 + .../src/interaction_manager_mouse_test.cpp | 168 +++++ .../unittest/src/interaction_manager_test.cpp | 615 ++++++++++++++++++ .../interaction/drag/include/drag_drawing.h | 3 +- .../interaction/drag/src/drag_drawing.cpp | 122 ++-- .../interaction/drag/src/drag_manager.cpp | 1 + 6 files changed, 873 insertions(+), 60 deletions(-) create mode 100644 frameworks/native/interaction/test/unittest/src/interaction_manager_mouse_test.cpp create mode 100644 frameworks/native/interaction/test/unittest/src/interaction_manager_test.cpp diff --git a/frameworks/native/interaction/test/unittest/BUILD.gn b/frameworks/native/interaction/test/unittest/BUILD.gn index fd3e01f56..af9163987 100644 --- a/frameworks/native/interaction/test/unittest/BUILD.gn +++ b/frameworks/native/interaction/test/unittest/BUILD.gn @@ -44,3 +44,27 @@ group("unittest") { deps = [] deps += [ ":InteractionManagerTest" ] } + +ohos_unittest("InteractionManagerMouseTest") { + module_out_path = module_output_path + include_dirs = [ + "${device_status_interfaces_path}/innerkits/interaction/include", + "${device_status_utils_path}/include", + ] + + defines = [] + + sources = [ + "src/interaction_manager_mouse_test.cpp", + ] + + configs = [] + + deps = [ "${device_status_interfaces_path}/innerkits:devicestatus_client" ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", + "multimedia_image_framework:image_native", + ] +} diff --git a/frameworks/native/interaction/test/unittest/src/interaction_manager_mouse_test.cpp b/frameworks/native/interaction/test/unittest/src/interaction_manager_mouse_test.cpp new file mode 100644 index 000000000..7308a8eab --- /dev/null +++ b/frameworks/native/interaction/test/unittest/src/interaction_manager_mouse_test.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "pointer_event.h" + +#include "image_source.h" + +#include "coordination_message.h" +#include "devicestatus_define.h" +#include "devicestatus_errors.h" +#include "interaction_manager.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +using namespace testing::ext; +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "InteractionManagerMouseTest" }; +constexpr int32_t TIME_WAIT_FOR_OP = 100; +static bool stopCallbackFlag { false }; +const std::string CURSOR_DRAG_PATH = "/system/etc/device_status/drag_icon/File_Drag.png"; +} // namespace +class InteractionManagerMouseTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + static void SetUpTestCase(); +}; + +void InteractionManagerMouseTest::SetUpTestCase() +{ +} + +void InteractionManagerMouseTest::SetUp() +{ +} + +void InteractionManagerMouseTest::TearDown() +{ + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); +} + +std::shared_ptr CreatePixelMap(int32_t pixelMapWidth, int32_t pixelMapHeight) +{ + std::string imagePath = CURSOR_DRAG_PATH; + OHOS::Media::SourceOptions opts; + opts.formatHint = "image/png"; + uint32_t errCode = 0; + auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, errCode); + if (imageSource == nullptr) { + return nullptr; + } + std::set formats; + imageSource->GetSupportedFormats(formats); + OHOS::Media::DecodeOptions decodeOpts; + decodeOpts.desiredSize = { + .width = pixelMapWidth, + .height = pixelMapHeight + }; + decodeOpts.allocatorType = OHOS::Media::AllocatorType::SHARE_MEM_ALLOC; + std::shared_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode); + return pixelMap; +} + +int32_t SetParam(int32_t width, int32_t height, DragData& dragData, int32_t sourceType, int32_t pointerId) +{ + auto pixelMap = CreatePixelMap(width, height); + dragData.shadowInfo.pixelMap = pixelMap; + dragData.shadowInfo.x = -50; + dragData.shadowInfo.y = -50; + dragData.buffer = std::vector(MAX_BUFFER_SIZE, 0); + dragData.sourceType = sourceType; + dragData.pointerId = pointerId; + dragData.dragNum = 100; + dragData.displayX = 0; + dragData.displayY = 0; + dragData.displayId = 0; + dragData.hasCanceledAnimation = false; + return RET_OK; +} + +/** + * @tc.name: InteractionManagerMouseTest_Drag + * @tc.desc: Start Drag + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerMouseTest, InteractionManagerMouseTest_Drag, TestSize.Level1) +{ + CALL_TEST_DEBUG; + DragData dragData; + int32_t ret = SetParam(90, 90, dragData, MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0); + ASSERT_EQ(ret, RET_OK); + stopCallbackFlag = false; + std::function callback = [](const DragNotifyMsg& dragNotifyMsg) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, targetPid%{public}d", + dragNotifyMsg.displayX, dragNotifyMsg.displayY, dragNotifyMsg.result, dragNotifyMsg.targetPid); + stopCallbackFlag = true; + }; + ret = InteractionManager::GetInstance()->StartDrag(dragData, callback); + ASSERT_EQ(ret, RET_OK); + std::cout << "please move the mouse" << std::endl; + std::cout << "start Drag" << std::endl; + sleep(10); + ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::FORBIDDEN); + ASSERT_EQ(ret, RET_OK); + std::cout << "update drag style 0" << std::endl; + sleep(10); + ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY); + std::cout << "change drag style" << std::endl; + sleep(10); + ret = InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, false); + std::cout << "stop drag" << std::endl; + ASSERT_EQ(ret, RET_OK); +} + +/** + * @tc.name: InteractionManagerMouseTest_Drag_002 + * @tc.desc: Start Drag + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerMouseTest, InteractionManagerMouseTest_Drag_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + DragData dragData; + int32_t ret = SetParam(200, 200, dragData, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, 0); + ASSERT_EQ(ret, RET_OK); + stopCallbackFlag = false; + std::function callback = [](const DragNotifyMsg& dragNotifyMsg) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, targetPid%{public}d", + dragNotifyMsg.displayX, dragNotifyMsg.displayY, dragNotifyMsg.result, dragNotifyMsg.targetPid); + stopCallbackFlag = true; + }; + ret = InteractionManager::GetInstance()->StartDrag(dragData, callback); + ASSERT_EQ(ret, RET_OK); + std::cout << "please move the mouse" << std::endl; + std::cout << "start Drag" << std::endl; + sleep(10); + ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::FORBIDDEN); + ASSERT_EQ(ret, RET_OK); + std::cout << "update drag style 0" << std::endl; + sleep(10); + ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY); + std::cout << "change drag style" << std::endl; + sleep(10); + ret = InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_FAIL, false); + std::cout << "stop drag" << std::endl; + ASSERT_EQ(ret, RET_OK); +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS diff --git a/frameworks/native/interaction/test/unittest/src/interaction_manager_test.cpp b/frameworks/native/interaction/test/unittest/src/interaction_manager_test.cpp new file mode 100644 index 000000000..b76bf6749 --- /dev/null +++ b/frameworks/native/interaction/test/unittest/src/interaction_manager_test.cpp @@ -0,0 +1,615 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +#include +#include "input_manager.h" +#include "pointer_event.h" + +#include "coordination_message.h" +#include "devicestatus_define.h" +#include "devicestatus_errors.h" +#include "interaction_manager.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +using namespace testing::ext; +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "InteractionManagerTest" }; +constexpr int32_t TIME_WAIT_FOR_OP { 100 }; +constexpr int32_t TIME_WAIT_FOR_INJECT_MS { 20000 }; +constexpr int32_t TIME_WAIT_FOR_PROCESS_CALLBACK { 20000 }; +constexpr int32_t TIME_WAIT_FOR_TOUCH_DOWN { 1 }; +constexpr int32_t DEFAULT_DEVICE_ID { 0 }; +constexpr int32_t MOUSE_POINTER_ID { 0 }; +constexpr int32_t TOUCH_POINTER_ID { 1 }; +constexpr int32_t DISPLAY_ID { 0 }; +constexpr int32_t DRAG_SRC_X { 0 }; +constexpr int32_t DRAG_SRC_Y { 0 }; +constexpr int32_t DRAG_DST_X { 200 }; +constexpr int32_t DRAG_DST_Y { 200 }; +constexpr int32_t DRAG_NUM { 1 }; +constexpr bool HAS_CANCELED_ANIMATION { false }; +constexpr bool HAS_CUSTOM_ANIMATION { false }; +constexpr int32_t MOVE_STEP { 100 }; +#define INPUT_MANAGER MMI::InputManager::GetInstance() +} // namespace + +class InteractionManagerTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + static void SetUpTestCase(); + std::shared_ptr CreatePixelMap(int32_t width, int32_t height); + std::optional CreateDragData(std::pair pixelMapSize, int32_t sourceType, + int32_t pointerId, int32_t displayId, std::pair location); + MMI::PointerEvent::PointerItem CreatePointerItem(int32_t pointerId, + int32_t deviceId, std::pair displayLocation, bool isPressed); + std::shared_ptr SetupPointerEvent(std::pair displayLocation, int32_t action, + int32_t sourceType, int32_t pointerId, bool isPressed); + void SimulateDownEvent(std::pair location, int32_t sourceType, int32_t pointerId); + void SimulateMoveEvent(std::pair srcLocation, std::pair dstLocation, + int32_t sourceType, int32_t pointerId, bool isPressed); + void SimulateUpEvent(std::pair location, int32_t sourceType, int32_t pointerId); + int32_t TestAddMonitor(std::shared_ptr consumer); + void TestRemoveMonitor(int32_t monitorId); +}; + +void InteractionManagerTest::SetUpTestCase() +{ +} + +void InteractionManagerTest::SetUp() +{ +} + +void InteractionManagerTest::TearDown() +{ + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); +} + +std::shared_ptr InteractionManagerTest::CreatePixelMap(int32_t width, int32_t height) +{ + CALL_DEBUG_ENTER; + if (width <= 0 || width > MAX_PIXEL_MAP_WIDTH || + height <= 0 || height > MAX_PIXEL_MAP_HEIGHT) { + FI_HILOGE("Invalid size,width:%{public}d,height:%{public}d", width, height); + return nullptr; + } + OHOS::Media::InitializationOptions opts; + opts.size.width = width; + opts.size.height = height; + std::unique_ptr uniquePixelMap = Media::PixelMap::Create(opts); + std::shared_ptr pixelMap = std::move(uniquePixelMap); + return pixelMap; +} + +std::optional InteractionManagerTest::CreateDragData(std::pair pixelMapSize, + int32_t sourceType, int32_t pointerId, int32_t displayId, std::pair location) +{ + CALL_DEBUG_ENTER; + std::shared_ptr pixelMap = CreatePixelMap(pixelMapSize.first, pixelMapSize.second); + if (pixelMap == nullptr) { + FI_HILOGE("CreatePixelMap failed"); + return std::nullopt; + } + DragData dragData; + dragData.shadowInfo.pixelMap = pixelMap; + dragData.shadowInfo.x = 0; + dragData.shadowInfo.y = 0; + dragData.buffer = std::vector(MAX_BUFFER_SIZE, 0); + dragData.sourceType = sourceType; + dragData.pointerId = pointerId; + dragData.dragNum = DRAG_NUM; + dragData.displayX = location.first; + dragData.displayY = location.second; + dragData.displayId = displayId; + dragData.hasCanceledAnimation = HAS_CANCELED_ANIMATION; + return dragData; +} + +MMI::PointerEvent::PointerItem InteractionManagerTest::CreatePointerItem(int32_t pointerId, + int32_t deviceId, std::pair displayLocation, bool isPressed) +{ + MMI::PointerEvent::PointerItem item; + item.SetPointerId(pointerId); + item.SetDeviceId(deviceId); + item.SetDisplayX(displayLocation.first); + item.SetDisplayY(displayLocation.second); + item.SetPressed(isPressed); + return item; +} + +std::shared_ptr InteractionManagerTest::SetupPointerEvent(std::pair displayLocation, + int32_t action, int32_t sourceType, int32_t pointerId, bool isPressed) +{ + CALL_DEBUG_ENTER; + auto pointerEvent = MMI::PointerEvent::Create(); + CHKPP(pointerEvent); + pointerEvent->SetPointerAction(action); + pointerEvent->SetSourceType(sourceType); + pointerEvent->SetPointerId(pointerId); + auto curPointerItem = CreatePointerItem(pointerId, DEFAULT_DEVICE_ID, displayLocation, isPressed); + pointerEvent->AddPointerItem(curPointerItem); + return pointerEvent; +} + +void InteractionManagerTest::SimulateDownEvent(std::pair location, int32_t sourceType, int32_t pointerId) +{ + CALL_DEBUG_ENTER; + std::shared_ptr pointerEvent = + SetupPointerEvent(location, MMI::PointerEvent::POINTER_ACTION_DOWN, sourceType, pointerId, true); + FI_HILOGD("TEST:sourceType:%{public}d, pointerId:%{public}d, pointerAction:%{public}d", + pointerEvent->GetSourceType(), pointerEvent->GetPointerId(), pointerEvent->GetPointerAction()); + INPUT_MANAGER->SimulateInputEvent(pointerEvent); +} + +void InteractionManagerTest::SimulateMoveEvent(std::pair srcLocation, std::pair dstLocation, + int32_t sourceType, int32_t pointerId, bool isPressed) +{ + CALL_DEBUG_ENTER; + int32_t srcX = srcLocation.first; + int32_t srcY = srcLocation.second; + int32_t dstX = dstLocation.first; + int32_t dstY = dstLocation.second; + std::vector> coordinates; + if (dstX == srcX) { + for (int32_t y = srcY; y <= dstY; y += MOVE_STEP) { + coordinates.push_back({srcX, y}); + } + } else { + double ratio = (dstY - srcY) * 1.0 / (dstX - srcX); + for (int32_t x = srcX; x < dstX; x += MOVE_STEP) { + coordinates.push_back({x, srcY + static_cast(ratio * (x - srcX))}); + } + coordinates.push_back({dstX, dstY}); + } + for (const auto& pointer : coordinates) { + std::shared_ptr pointerEvent = + SetupPointerEvent(pointer, MMI::PointerEvent::POINTER_ACTION_MOVE, sourceType, pointerId, isPressed); + FI_HILOGD("TEST:sourceType:%{public}d, pointerId:%{public}d, pointerAction:%{public}d", + pointerEvent->GetSourceType(), pointerEvent->GetPointerId(), pointerEvent->GetPointerAction()); + INPUT_MANAGER->SimulateInputEvent(pointerEvent); + usleep(TIME_WAIT_FOR_INJECT_MS); + } +} + +void InteractionManagerTest::SimulateUpEvent(std::pair location, int32_t sourceType, int32_t pointerId) +{ + CALL_DEBUG_ENTER; + std::shared_ptr pointerEvent = + SetupPointerEvent(location, MMI::PointerEvent::POINTER_ACTION_UP, sourceType, pointerId, false); + FI_HILOGD("TEST:sourceType:%{public}d, pointerId:%{public}d, pointerAction:%{public}d", + pointerEvent->GetSourceType(), pointerEvent->GetPointerId(), pointerEvent->GetPointerAction()); + INPUT_MANAGER->SimulateInputEvent(pointerEvent); +} + +int32_t InteractionManagerTest::TestAddMonitor(std::shared_ptr consumer) +{ + return MMI::InputManager::GetInstance()->AddMonitor(consumer); +} + +void InteractionManagerTest::TestRemoveMonitor(int32_t monitorId) +{ + MMI::InputManager::GetInstance()->RemoveMonitor(monitorId); +} + +class InputEventCallbackTest : public MMI::IInputEventConsumer { +public: + virtual void OnInputEvent(std::shared_ptr keyEvent) const override {}; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const override; + virtual void OnInputEvent(std::shared_ptr axisEvent) const override {}; +}; + +void InputEventCallbackTest::OnInputEvent(std::shared_ptr pointerEvent) const +{ + CALL_DEBUG_ENTER; + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_TRUE(!pointerEvent->GetBuffer().empty()); + ASSERT_TRUE(pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_MOVE); +} +/** + * @tc.name: InteractionManagerTest_RegisterCoordinationListener_001 + * @tc.desc: Register coordination listener + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_RegisterCoordinationListener_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr consumer = nullptr; + int32_t ret = InteractionManager::GetInstance()->RegisterCoordinationListener(consumer); +#ifdef OHOS_BUILD_ENABLE_COORDINATION + ASSERT_EQ(ret, RET_ERR); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COORDINATION +} + +/** + * @tc.name: InteractionManagerTest_RegisterCoordinationListener_002 + * @tc.desc: Register coordination listener + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_RegisterCoordinationListener_002, TestSize.Level1) +{ + CALL_DEBUG_ENTER; + class CoordinationListenerTest : public ICoordinationListener { + public: + CoordinationListenerTest() : ICoordinationListener() {} + void OnCoordinationMessage(const std::string &deviceId, CoordinationMessage msg) override + { + FI_HILOGD("RegisterCoordinationListenerTest"); + }; + }; + std::shared_ptr consumer = + std::make_shared(); + int32_t ret = InteractionManager::GetInstance()->RegisterCoordinationListener(consumer); +#ifdef OHOS_BUILD_ENABLE_COORDINATION + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COORDINATION + ret = InteractionManager::GetInstance()->UnregisterCoordinationListener(consumer); +#ifdef OHOS_BUILD_ENABLE_COORDINATION + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COORDINATION +} + +/** + * @tc.name: InteractionManagerTest_UnregisterCoordinationListener + * @tc.desc: Unregister coordination listener + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_UnregisterCoordinationListener, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr consumer = nullptr; + int32_t ret = InteractionManager::GetInstance()->UnregisterCoordinationListener(consumer); +#ifdef OHOS_BUILD_ENABLE_COORDINATION + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COORDINATION +} + +/** + * @tc.name: InteractionManagerTest_EnableCoordination + * @tc.desc: Enable coordination + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_EnableCoordination, TestSize.Level1) +{ + CALL_TEST_DEBUG; + bool enabled = false; + auto fun = [](std::string listener, CoordinationMessage coordinationMessages) { + FI_HILOGD("Enable coordination success"); + }; + int32_t ret = InteractionManager::GetInstance()->EnableCoordination(enabled, fun); +#ifdef OHOS_BUILD_ENABLE_COORDINATION + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COORDINATION +} + +/** + * @tc.name: InteractionManagerTest_StartCoordination + * @tc.desc: Start coordination + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartCoordination, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::string sinkDeviceId(""); + int32_t srcDeviceId = -1; + auto fun = [](std::string listener, CoordinationMessage coordinationMessages) { + FI_HILOGD("Start coordination success"); + }; + int32_t ret = InteractionManager::GetInstance()->StartCoordination(sinkDeviceId, srcDeviceId, fun); +#ifdef OHOS_BUILD_ENABLE_COORDINATION + ASSERT_NE(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COORDINATION +} + +/** + * @tc.name: InteractionManagerTest_StopCoordination + * @tc.desc: Stop coordination + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopCoordination, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto fun = [](std::string listener, CoordinationMessage coordinationMessages) { + FI_HILOGD("Stop coordination success"); + }; + int32_t ret = InteractionManager::GetInstance()->StopCoordination(fun); +#ifdef OHOS_BUILD_ENABLE_COORDINATION + ASSERT_NE(ret, ERROR_UNSUPPORT); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COORDINATION +} + +/** + * @tc.name: InteractionManagerTest_GetCoordinationState + * @tc.desc: Get coordination state + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetCoordinationState, TestSize.Level1) +{ + CALL_TEST_DEBUG; + const std::string deviceId(""); + auto fun = [](bool state) { + FI_HILOGD("Get coordination state success"); + }; + int32_t ret = InteractionManager::GetInstance()->GetCoordinationState(deviceId, fun); +#ifdef OHOS_BUILD_ENABLE_COORDINATION + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COORDINATION +} + +/** + * @tc.name: InteractionManagerTest_StartDrag_Mouse + * @tc.desc: Start Drag + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Mouse, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto callback = [](const DragNotifyMsg& notifyMessage) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); + }; + SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID); + std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, + MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ASSERT_EQ(ret, RET_OK); + SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y }, + MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true); + SimulateUpEvent({ DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID); + InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION); +} + +/** + * @tc.name: InteractionManagerTest_StopDrag_Mouse + * @tc.desc: Stop drag + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag_Mouse, TestSize.Level1) +{ + CALL_TEST_DEBUG; + bool stopCallbackFlag = false; + auto callback = [&stopCallbackFlag](const DragNotifyMsg& notifyMessage) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); + stopCallbackFlag = true; + FI_HILOGD("set stopCallbackFlag to true"); + }; + SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID); + std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, + MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); + ASSERT_TRUE(dragData); + InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + SimulateUpEvent({ DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID); + int32_t ret = InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION); + ASSERT_EQ(ret, RET_OK); + usleep(TIME_WAIT_FOR_PROCESS_CALLBACK); + ASSERT_TRUE(stopCallbackFlag); +} + +/** + * @tc.name: InteractionManagerTest_StartDrag_Touch + * @tc.desc: Start Drag + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Touch, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto callback = [](const DragNotifyMsg& notifyMessage) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); + }; + SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID); + sleep(TIME_WAIT_FOR_TOUCH_DOWN); + std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ASSERT_EQ(ret, RET_OK); + SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y }, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true); + SimulateUpEvent({ DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID); + InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION); +} + +/** + * @tc.name: InteractionManagerTest_StopDrag_Touch + * @tc.desc: Stop drag + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag_Touch, TestSize.Level1) +{ + CALL_TEST_DEBUG; + bool stopCallbackFlag = false; + auto callback = [&stopCallbackFlag](const DragNotifyMsg& notifyMessage) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); + stopCallbackFlag = true; + FI_HILOGD("set stopCallbackFlag to true"); + }; + SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID); + sleep(TIME_WAIT_FOR_TOUCH_DOWN); + std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); + ASSERT_TRUE(dragData); + InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + SimulateUpEvent({ DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID); + int32_t ret = InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION); + ASSERT_EQ(ret, RET_OK); + usleep(TIME_WAIT_FOR_PROCESS_CALLBACK); + ASSERT_TRUE(stopCallbackFlag); +} + +/** + * @tc.name: InteractionManagerTest_GetDragTargetPid + * @tc.desc: Get the target pid dragged by the mouse + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, GetDragTargetPid_Mouse, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto callback = [](const DragNotifyMsg& notifyMessage) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); + }; + SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID); + std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, + MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ASSERT_EQ(ret, RET_OK); + SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y }, + MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true); + SimulateUpEvent({ DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID); + + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + int32_t pid = InteractionManager::GetInstance()->GetDragTargetPid(); + FI_HILOGI("Target pid:%{public}d", pid); + ASSERT_TRUE(pid > 0); + InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION); +} + +/** + * @tc.name: InteractionManagerTest_GetDragTargetPid + * @tc.desc: Get the target pid dragged by the touchscreen + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, GetDragTargetPid_Touch, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto callback = [](const DragNotifyMsg& notifyMessage) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); + }; + SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID); + sleep(TIME_WAIT_FOR_TOUCH_DOWN); + std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ASSERT_EQ(ret, RET_OK); + SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y }, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true); + SimulateUpEvent({ DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID); + + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + int32_t pid = InteractionManager::GetInstance()->GetDragTargetPid(); + FI_HILOGI("Target pid:%{public}d", pid); + ASSERT_TRUE(pid > 0); + InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION); +} + +/** +* @tc.name: InteractionManagerTest_TouchEventDispatch +* @tc.desc: Get Drag Target Pid +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(InteractionManagerTest, TouchEventDispatch, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto callback = [](const DragNotifyMsg& notifyMessage) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); + }; + SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID); + sleep(TIME_WAIT_FOR_TOUCH_DOWN); + std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ASSERT_EQ(ret, RET_OK); + + auto callbackPtr = std::make_shared(); + ASSERT_TRUE(callbackPtr != nullptr); + int32_t monitorId = TestAddMonitor(callbackPtr); + SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_SRC_X, DRAG_SRC_Y }, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true); + + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + TestRemoveMonitor(monitorId); + InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION); +} + +/** +* @tc.name: InteractionManagerTest_MouseEventDispatch +* @tc.desc: Get Drag Target Pid +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(InteractionManagerTest, MouseEventDispatch, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto callback = [](const DragNotifyMsg& notifyMessage) { + FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); + }; + SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0); + std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, + MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ASSERT_EQ(ret, RET_OK); + + auto callbackPtr = std::make_shared(); + ASSERT_TRUE(callbackPtr != nullptr); + int32_t monitorId = TestAddMonitor(callbackPtr); + SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_SRC_X, DRAG_SRC_Y }, + MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0, true); + + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + TestRemoveMonitor(monitorId); + InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION); +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index 986892bfa..a52a49c0d 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -86,7 +86,7 @@ public: int32_t Init(const DragData &dragData); void Draw(int32_t displayId, int32_t displayX, int32_t displayY); - int32_t UpdateDragStyle(int32_t style); + int32_t UpdateDragStyle(DragCursorStyle style); void OnDragSuccess(); void OnDragFail(); void EraseMouseIcon(); @@ -103,6 +103,7 @@ private: void InitAnimation(); int32_t InitVSync(); void OnVsync(); + void InitDrawingInfo(const DragData &dragData); private: int64_t startNum_ { -1 }; diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 5fcf43f5b..e0371fffb 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -59,8 +59,6 @@ constexpr int32_t SIXTEEN = 16; constexpr int32_t FAIL_ANIMATION_DURATION = 1000; constexpr int32_t SUCCESS_ANIMATION_DURATION = 300; constexpr int32_t VIEW_BOX_POS = 2; -constexpr int32_t FORBID_DRAG_STYLE = 0; -constexpr int32_t ONE_FILE_DRAG_STYLE = 1; constexpr int32_t PIXEL_MAP_INDEX = 0; constexpr int32_t DRAG_STYLE_INDEX = 1; constexpr int32_t MOUSE_ICON_INDEX = 2; @@ -81,7 +79,8 @@ const std::string MOUSE_DRAG_PATH = "/system/etc/device_status/drag_icon/Mouse_D struct DrawingInfo { std::atomic isRunning { false }; int32_t sourceType { -1 }; - int32_t currentStyle { -1 }; + int32_t currentDragNum { -1 }; + DragCursorStyle currentStyle { DragCursorStyle::DEFAULT }; int32_t displayId { -1 }; int32_t pixelMapX { -1 }; int32_t pixelMapY { -1 }; @@ -110,14 +109,14 @@ int32_t DragDrawing::Init(const DragData &dragData) FI_HILOGE("Invalid sourceType:%{public}d", dragData.sourceType); return INIT_FAIL; } - g_drawingInfo.isRunning = true; - g_drawingInfo.sourceType = dragData.sourceType; - g_drawingInfo.displayId = dragData.displayId; - g_drawingInfo.pixelMap = dragData.shadowInfo.pixelMap; - g_drawingInfo.pixelMapX = dragData.shadowInfo.x; - g_drawingInfo.pixelMapY = dragData.shadowInfo.y; + if (dragData.dragNum < 0) { + FI_HILOGE("Invalid dragNum:%{public}d", dragData.dragNum); + return INIT_FAIL; + } + InitDrawingInfo(dragData); CreateWindow(dragData.displayX, dragData.displayY); CHKPR(g_drawingInfo.dragWindow, INIT_FAIL); + g_drawingInfo.dragWindow->Show(); if (InitLayer() != RET_OK) { FI_HILOGE("Init layer failed"); return INIT_FAIL; @@ -126,19 +125,22 @@ int32_t DragDrawing::Init(const DragData &dragData) FI_HILOGE("Draw shadow failed"); return INIT_FAIL; } + if (DrawStyle() != RET_OK) { + FI_HILOGE("Draw style failed"); + return INIT_FAIL; + } + InitAnimation(); if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { - CHKPR(g_drawingInfo.dragWindow, INIT_FAIL); - g_drawingInfo.dragWindow->Show(); - InitAnimation(); + CHKPR(rsUiDirector_, RET_ERR); + rsUiDirector_->SendMessages(); return RET_OK; } if (DrawMouseIcon() != RET_OK) { FI_HILOGE("Draw mouse icon failed"); return INIT_FAIL; } - CHKPR(g_drawingInfo.dragWindow, INIT_FAIL); - g_drawingInfo.dragWindow->Show(); - InitAnimation(); + CHKPR(rsUiDirector_, RET_ERR); + rsUiDirector_->SendMessages(); return INIT_SUCCESS; } @@ -169,15 +171,15 @@ void DragDrawing::Draw(int32_t displayId, int32_t displayX, int32_t displayY) g_drawingInfo.dragWindow->Show(); } -int32_t DragDrawing::UpdateDragStyle(int32_t style) +int32_t DragDrawing::UpdateDragStyle(DragCursorStyle style) { CALL_DEBUG_ENTER; - if (style < 0) { + if (style < DragCursorStyle::DEFAULT || style > DragCursorStyle::MOVE) { FI_HILOGE("Invalid style:%{public}d", style); return RET_ERR; } if (g_drawingInfo.currentStyle == style) { - FI_HILOGD("No need update drag style"); + FI_HILOGD("Not need update drag style"); return RET_OK; } g_drawingInfo.currentStyle = style; @@ -190,23 +192,21 @@ int32_t DragDrawing::UpdateDragStyle(int32_t style) void DragDrawing::OnDragSuccess() { CALL_DEBUG_ENTER; - auto spDrawDynamicEffectModifier = drawDynamicEffectModifier_.lock(); - if (spDrawDynamicEffectModifier != nullptr) { + if (drawDynamicEffectModifier_.lock() != nullptr) { CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveModifier(spDrawDynamicEffectModifier); + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_.lock()); } drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); - spDrawDynamicEffectModifier = drawDynamicEffectModifier_.lock(); - g_drawingInfo.rootNode->AddModifier(spDrawDynamicEffectModifier); - spDrawDynamicEffectModifier->SetAlpha(BEGIN_ALPHA); - spDrawDynamicEffectModifier->SetScale(BEGIN_SCALE); + g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_.lock()); + drawDynamicEffectModifier_.lock()->SetAlpha(BEGIN_ALPHA); + drawDynamicEffectModifier_.lock()->SetScale(BEGIN_SCALE); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(SUCCESS_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - spDrawDynamicEffectModifier->SetAlpha(END_ALPHA); - spDrawDynamicEffectModifier->SetScale(END_SCALE_SUCCESS); + drawDynamicEffectModifier_.lock()->SetAlpha(END_ALPHA); + drawDynamicEffectModifier_.lock()->SetScale(END_SCALE_SUCCESS); }); CHKPV(runner_); runner_->Run(); @@ -215,23 +215,21 @@ void DragDrawing::OnDragSuccess() void DragDrawing::OnDragFail() { CALL_DEBUG_ENTER; - auto spDrawDynamicEffectModifier = drawDynamicEffectModifier_.lock(); - if (spDrawDynamicEffectModifier != nullptr) { + if (drawDynamicEffectModifier_.lock() != nullptr) { CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveModifier(spDrawDynamicEffectModifier); + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_.lock()); } drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); - spDrawDynamicEffectModifier = drawDynamicEffectModifier_.lock(); - g_drawingInfo.rootNode->AddModifier(spDrawDynamicEffectModifier); - spDrawDynamicEffectModifier->SetAlpha(BEGIN_ALPHA); - spDrawDynamicEffectModifier->SetScale(BEGIN_SCALE); + g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_.lock()); + drawDynamicEffectModifier_.lock()->SetAlpha(BEGIN_ALPHA); + drawDynamicEffectModifier_.lock()->SetScale(BEGIN_SCALE); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(FAIL_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - spDrawDynamicEffectModifier->SetAlpha(END_ALPHA); - spDrawDynamicEffectModifier->SetScale(END_SCALE_FAIL); + drawDynamicEffectModifier_.lock()->SetAlpha(END_ALPHA); + drawDynamicEffectModifier_.lock()->SetScale(END_SCALE_FAIL); }); CHKPV(runner_); runner_->Run(); @@ -256,7 +254,7 @@ void DragDrawing::DestroyDragWindow() { CALL_DEBUG_ENTER; startNum_ = START_TIME; - g_drawingInfo.currentStyle = -1; + g_drawingInfo.currentStyle = DragCursorStyle::DEFAULT; if (g_drawingInfo.pixelMap != nullptr) { g_drawingInfo.pixelMap = nullptr; } @@ -312,13 +310,11 @@ int32_t DragDrawing::DrawShadow() } auto pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; CHKPR(pixelMapNode, RET_ERR); - auto spDrawPixelMapModifier = drawPixelMapModifier_.lock(); - if (spDrawPixelMapModifier != nullptr) { - pixelMapNode->RemoveModifier(spDrawPixelMapModifier); + if (drawPixelMapModifier_.lock() != nullptr) { + pixelMapNode->RemoveModifier(drawPixelMapModifier_.lock()); } drawPixelMapModifier_ = std::make_shared(); - spDrawPixelMapModifier = drawPixelMapModifier_.lock(); - pixelMapNode->AddModifier(spDrawPixelMapModifier); + pixelMapNode->AddModifier(drawPixelMapModifier_.lock()); return RET_OK; } @@ -331,13 +327,11 @@ int32_t DragDrawing::DrawMouseIcon() } auto mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; CHKPR(mouseIconNode, RET_ERR); - auto spDrawMouseIconModifier = drawMouseIconModifier_.lock(); - if (spDrawMouseIconModifier != nullptr) { - mouseIconNode->RemoveModifier(spDrawMouseIconModifier); + if (drawMouseIconModifier_.lock() != nullptr) { + mouseIconNode->RemoveModifier(drawMouseIconModifier_.lock()); } drawMouseIconModifier_ = std::make_shared(); - spDrawMouseIconModifier = drawMouseIconModifier_.lock(); - mouseIconNode->AddModifier(spDrawMouseIconModifier); + mouseIconNode->AddModifier(drawMouseIconModifier_.lock()); return RET_OK; } @@ -356,13 +350,11 @@ int32_t DragDrawing::DrawStyle() } auto dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; CHKPR(dragStyleNode, RET_ERR); - auto spDrawSVGModifier = drawSVGModifier_.lock(); - if (spDrawSVGModifier != nullptr) { - dragStyleNode->RemoveModifier(spDrawSVGModifier); + if (drawSVGModifier_.lock() != nullptr) { + dragStyleNode->RemoveModifier(drawSVGModifier_.lock()); } drawSVGModifier_ = std::make_shared(); - spDrawSVGModifier = drawSVGModifier_.lock(); - dragStyleNode->AddModifier(spDrawSVGModifier); + dragStyleNode->AddModifier(drawSVGModifier_.lock()); return RET_OK; } @@ -415,6 +407,18 @@ void DragDrawing::OnVsync() startNum_ += INTERVAL_TIME; } +void DragDrawing::InitDrawingInfo(const DragData &dragData) +{ + CALL_DEBUG_ENTER; + g_drawingInfo.isRunning = true; + g_drawingInfo.currentDragNum = dragData.dragNum; + g_drawingInfo.sourceType = dragData.sourceType; + g_drawingInfo.displayId = dragData.displayId; + g_drawingInfo.pixelMap = dragData.shadowInfo.pixelMap; + g_drawingInfo.pixelMapX = dragData.shadowInfo.x; + g_drawingInfo.pixelMapY = dragData.shadowInfo.y; +} + int32_t DragDrawing::InitLayer() { CALL_DEBUG_ENTER; @@ -513,12 +517,12 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const CALL_DEBUG_ENTER; std::unique_ptr fs = std::make_unique(); std::string filePath = ""; - if (g_drawingInfo.currentStyle == FORBID_DRAG_STYLE) { + if (g_drawingInfo.currentStyle == DragCursorStyle::FORBIDDEN) { filePath = FORBID_DRAG_PATH; - } else if (g_drawingInfo.currentStyle == ONE_FILE_DRAG_STYLE) { - filePath = COPY_ONE_DRAG_PATH; - } else { + } else if (g_drawingInfo.currentStyle == DragCursorStyle::COPY) { filePath = COPY_DRAG_PATH; + } else { + filePath = COPY_ONE_DRAG_PATH; } if (!IsValidSvgFile(filePath)) { @@ -644,7 +648,7 @@ void DrawSVGModifier::UpdateTspanNode(xmlNodePtr &curNode) const CALL_DEBUG_ENTER; while (curNode != nullptr) { if (!xmlStrcmp(curNode->name, BAD_CAST "tspan")) { - xmlNodeSetContent(curNode, BAD_CAST std::to_string(g_drawingInfo.currentStyle).c_str()); + xmlNodeSetContent(curNode, BAD_CAST std::to_string(g_drawingInfo.currentDragNum).c_str()); } curNode = curNode->next; } @@ -654,7 +658,7 @@ int32_t DrawSVGModifier::ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const { CALL_DEBUG_ENTER; CHKPR(curNode, RET_ERR); - std::string strStyle = std::to_string(g_drawingInfo.currentStyle); + std::string strStyle = std::to_string(g_drawingInfo.currentDragNum); if (strStyle.size() == 1) { FI_HILOGE("NO need adjust svg"); return RET_OK; @@ -683,7 +687,7 @@ std::shared_ptr DrawSVGModifier::DecodeSvgToPixelMap( { CALL_DEBUG_ENTER; xmlDocPtr xmlDoc = xmlReadFile(filePath.c_str(), 0, XML_PARSE_NOBLANKS); - if (g_drawingInfo.currentStyle != 0) { + if (g_drawingInfo.currentStyle != DragCursorStyle::FORBIDDEN) { xmlNodePtr node = xmlDocGetRootElement(xmlDoc); CHKPP(node); int32_t ret = ParseAndAdjustSvgInfo(node); diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index 2331e16b1..f144ec5d4 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -125,6 +125,7 @@ int32_t DragManager::UpdateDragStyle(DragCursorStyle style) return RET_ERR; } DataAdapter.SetDragStyle(style); + dragDrawing_.UpdateDragStyle(style); return RET_OK; } -- Gitee From 820d48fa9fafd18de6df9bb6d22ea0c4b587a9be Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sat, 18 Mar 2023 10:35:51 +0000 Subject: [PATCH 12/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I2cecf9dc5cc5e98ace03721ff1082da3379da6b8 --- .../interaction/drag/include/drag_drawing.h | 18 ++--- .../interaction/drag/src/drag_drawing.cpp | 65 ++++++++++--------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index a52a49c0d..0b4f87254 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -40,11 +40,11 @@ public: void Draw(OHOS::Rosen::RSDrawingContext& context) const override; private: - int32_t UpdateSvgNodeInfo(const xmlNodePtr &curNode, int32_t extendSvgWidth) const; - xmlNodePtr FindRectNode(xmlNodePtr &curNode) const; - xmlNodePtr UpdateRectNode(xmlNodePtr &curNode, int32_t extendSvgWidth) const; - void UpdateTspanNode(xmlNodePtr &curNode) const; - int32_t ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const; + int32_t UpdateSvgNodeInfo(const xmlNodePtr curNode, int32_t extendSvgWidth) const; + xmlNodePtr GetRectNode(xmlNodePtr curNode) const; + xmlNodePtr UpdateRectNode(xmlNodePtr curNode, int32_t extendSvgWidth) const; + void UpdateTspanNode(xmlNodePtr curNode) const; + int32_t ParseAndAdjustSvgInfo(xmlNodePtr curNode) const; std::shared_ptr DecodeSvgToPixelMap(const std::string &filePath) const; }; @@ -108,10 +108,10 @@ private: private: int64_t startNum_ { -1 }; std::shared_ptr canvasNode_ { nullptr }; - std::weak_ptr drawSVGModifier_; - std::weak_ptr drawPixelMapModifier_; - std::weak_ptr drawMouseIconModifier_; - std::weak_ptr drawDynamicEffectModifier_; + std::shared_ptr drawSVGModifier_; + std::shared_ptr drawPixelMapModifier_; + std::shared_ptr drawMouseIconModifier_; + std::shared_ptr drawDynamicEffectModifier_; std::shared_ptr rsUiDirector_ { nullptr }; std::shared_ptr receiver_ { nullptr }; std::shared_ptr handler_ { nullptr }; diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index e0371fffb..73721be9c 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -192,21 +192,21 @@ int32_t DragDrawing::UpdateDragStyle(DragCursorStyle style) void DragDrawing::OnDragSuccess() { CALL_DEBUG_ENTER; - if (drawDynamicEffectModifier_.lock() != nullptr) { + if (drawDynamicEffectModifier_ != nullptr) { CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_.lock()); + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); } drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_.lock()); - drawDynamicEffectModifier_.lock()->SetAlpha(BEGIN_ALPHA); - drawDynamicEffectModifier_.lock()->SetScale(BEGIN_SCALE); + g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); + drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); + drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(SUCCESS_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - drawDynamicEffectModifier_.lock()->SetAlpha(END_ALPHA); - drawDynamicEffectModifier_.lock()->SetScale(END_SCALE_SUCCESS); + drawDynamicEffectModifier_->SetAlpha(END_ALPHA); + drawDynamicEffectModifier_->SetScale(END_SCALE_SUCCESS); }); CHKPV(runner_); runner_->Run(); @@ -215,21 +215,21 @@ void DragDrawing::OnDragSuccess() void DragDrawing::OnDragFail() { CALL_DEBUG_ENTER; - if (drawDynamicEffectModifier_.lock() != nullptr) { + if (drawDynamicEffectModifier_ != nullptr) { CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_.lock()); + g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); } drawDynamicEffectModifier_ = std::make_shared(); CHKPV(g_drawingInfo.rootNode); - g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_.lock()); - drawDynamicEffectModifier_.lock()->SetAlpha(BEGIN_ALPHA); - drawDynamicEffectModifier_.lock()->SetScale(BEGIN_SCALE); + g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); + drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); + drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); OHOS::Rosen::RSAnimationTimingProtocol protocol; protocol.SetDuration(FAIL_ANIMATION_DURATION); OHOS::Rosen::RSNode::Animate(protocol, OHOS::Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { - drawDynamicEffectModifier_.lock()->SetAlpha(END_ALPHA); - drawDynamicEffectModifier_.lock()->SetScale(END_SCALE_FAIL); + drawDynamicEffectModifier_->SetAlpha(END_ALPHA); + drawDynamicEffectModifier_->SetScale(END_SCALE_FAIL); }); CHKPV(runner_); runner_->Run(); @@ -310,11 +310,11 @@ int32_t DragDrawing::DrawShadow() } auto pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; CHKPR(pixelMapNode, RET_ERR); - if (drawPixelMapModifier_.lock() != nullptr) { - pixelMapNode->RemoveModifier(drawPixelMapModifier_.lock()); + if (drawPixelMapModifier_ != nullptr) { + pixelMapNode->RemoveModifier(drawPixelMapModifier_); } drawPixelMapModifier_ = std::make_shared(); - pixelMapNode->AddModifier(drawPixelMapModifier_.lock()); + pixelMapNode->AddModifier(drawPixelMapModifier_); return RET_OK; } @@ -327,11 +327,11 @@ int32_t DragDrawing::DrawMouseIcon() } auto mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; CHKPR(mouseIconNode, RET_ERR); - if (drawMouseIconModifier_.lock() != nullptr) { - mouseIconNode->RemoveModifier(drawMouseIconModifier_.lock()); + if (drawMouseIconModifier_ != nullptr) { + mouseIconNode->RemoveModifier(drawMouseIconModifier_); } drawMouseIconModifier_ = std::make_shared(); - mouseIconNode->AddModifier(drawMouseIconModifier_.lock()); + mouseIconNode->AddModifier(drawMouseIconModifier_); return RET_OK; } @@ -350,11 +350,12 @@ int32_t DragDrawing::DrawStyle() } auto dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; CHKPR(dragStyleNode, RET_ERR); - if (drawSVGModifier_.lock() != nullptr) { - dragStyleNode->RemoveModifier(drawSVGModifier_.lock()); + if (drawSVGModifier_ != nullptr) { + FI_HILOGE("XJP111"); + dragStyleNode->RemoveModifier(drawSVGModifier_); } drawSVGModifier_ = std::make_shared(); - dragStyleNode->AddModifier(drawSVGModifier_.lock()); + dragStyleNode->AddModifier(drawSVGModifier_); return RET_OK; } @@ -562,7 +563,7 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); } -int32_t DrawSVGModifier::UpdateSvgNodeInfo(const xmlNodePtr &curNode, int32_t extendSvgWidth) const +int32_t DrawSVGModifier::UpdateSvgNodeInfo(const xmlNodePtr curNode, int32_t extendSvgWidth) const { CALL_DEBUG_ENTER; if (xmlStrcmp(curNode->name, BAD_CAST "svg")) { @@ -604,7 +605,7 @@ int32_t DrawSVGModifier::UpdateSvgNodeInfo(const xmlNodePtr &curNode, int32_t ex return RET_OK; } -xmlNodePtr DrawSVGModifier::FindRectNode(xmlNodePtr &curNode) const +xmlNodePtr DrawSVGModifier::GetRectNode(xmlNodePtr curNode) const { CALL_DEBUG_ENTER; curNode = curNode->xmlChildrenNode; @@ -620,7 +621,7 @@ xmlNodePtr DrawSVGModifier::FindRectNode(xmlNodePtr &curNode) const return curNode; } -xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr &curNode, int32_t extendSvgWidth) const +xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr curNode, int32_t extendSvgWidth) const { CALL_DEBUG_ENTER; while (curNode != nullptr) { @@ -643,7 +644,7 @@ xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr &curNode, int32_t extendSv return nullptr; } -void DrawSVGModifier::UpdateTspanNode(xmlNodePtr &curNode) const +void DrawSVGModifier::UpdateTspanNode(xmlNodePtr curNode) const { CALL_DEBUG_ENTER; while (curNode != nullptr) { @@ -654,7 +655,7 @@ void DrawSVGModifier::UpdateTspanNode(xmlNodePtr &curNode) const } } -int32_t DrawSVGModifier::ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const +int32_t DrawSVGModifier::ParseAndAdjustSvgInfo(xmlNodePtr curNode) const { CALL_DEBUG_ENTER; CHKPR(curNode, RET_ERR); @@ -674,7 +675,7 @@ int32_t DrawSVGModifier::ParseAndAdjustSvgInfo(xmlNodePtr &curNode) const FI_HILOGE("Update svg node info failed, ret:%{public}d", ret); return RET_ERR; } - curNode = FindRectNode(curNode); + curNode = GetRectNode(curNode); CHKPR(curNode, RET_ERR); curNode = UpdateRectNode(curNode, extendSvgWidth); CHKPR(curNode, RET_ERR); @@ -706,12 +707,12 @@ std::shared_ptr DrawSVGModifier::DecodeSvgToPixelMap( xmlFreeDoc(xmlDoc); OHOS::Media::SourceOptions opts; opts.formatHint = "image/svg+xml"; - uint32_t ret = 0; + uint32_t errCode = 0; auto imageSource = OHOS::Media::ImageSource::CreateImageSource(reinterpret_cast(content.c_str()), - content.size(), opts, ret); + content.size(), opts, errCode); CHKPP(imageSource); OHOS::Media::DecodeOptions decodeOpts; - std::shared_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, ret); + std::shared_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode); return pixelMap; } -- Gitee From bd9b897d7a096defc38598d6bc4fddd1462e08f2 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sat, 18 Mar 2023 16:03:22 +0000 Subject: [PATCH 13/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I6ec406630c24bede717e1ece472ddaec8b3602b8 --- services/interaction/drag/include/drag_drawing.h | 2 +- services/interaction/drag/src/drag_drawing.cpp | 9 +++++---- utils/common/src/util.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index 0b4f87254..90ed586c9 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -40,7 +40,7 @@ public: void Draw(OHOS::Rosen::RSDrawingContext& context) const override; private: - int32_t UpdateSvgNodeInfo(const xmlNodePtr curNode, int32_t extendSvgWidth) const; + int32_t UpdateSvgNodeInfo(xmlNodePtr curNode, int32_t extendSvgWidth) const; xmlNodePtr GetRectNode(xmlNodePtr curNode) const; xmlNodePtr UpdateRectNode(xmlNodePtr curNode, int32_t extendSvgWidth) const; void UpdateTspanNode(xmlNodePtr curNode) const; diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 73721be9c..db5ef8cbb 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -559,11 +559,12 @@ void DrawSVGModifier::Draw(OHOS::Rosen::RSDrawingContext& context) const CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->SetBounds(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); g_drawingInfo.rootNode->SetFrame(0, 0, g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); + CHKPV(g_drawingInfo.dragWindow); g_drawingInfo.dragWindow->Resize(g_drawingInfo.rootNodeWidth, g_drawingInfo.rootNodeHeight); OHOS::Rosen::RSTransaction::FlushImplicitTransaction(); } -int32_t DrawSVGModifier::UpdateSvgNodeInfo(const xmlNodePtr curNode, int32_t extendSvgWidth) const +int32_t DrawSVGModifier::UpdateSvgNodeInfo(xmlNodePtr curNode, int32_t extendSvgWidth) const { CALL_DEBUG_ENTER; if (xmlStrcmp(curNode->name, BAD_CAST "svg")) { @@ -574,7 +575,7 @@ int32_t DrawSVGModifier::UpdateSvgNodeInfo(const xmlNodePtr curNode, int32_t ext oStrStream << xmlGetProp(curNode, BAD_CAST "width"); std::string srcSvgWidth = oStrStream.str(); if (!IsNum(srcSvgWidth)) { - FI_HILOGE("srcSvgWidth invalid, srcSvgWidth:%{public}s", srcSvgWidth.c_str()); + FI_HILOGE("srcSvgWidth is not digital, srcSvgWidth:%{public}s", srcSvgWidth.c_str()); return RET_ERR; } int32_t number = std::stoi(srcSvgWidth) + extendSvgWidth; @@ -590,7 +591,7 @@ int32_t DrawSVGModifier::UpdateSvgNodeInfo(const xmlNodePtr curNode, int32_t ext while (iStrStream >> tmpString) { if (i == VIEW_BOX_POS) { if (!IsNum(tmpString)) { - FI_HILOGE("tmpString invalid, tmpString:%{public}s", tmpString.c_str()); + FI_HILOGE("tmpString is not digital, tmpString:%{public}s", tmpString.c_str()); return RET_ERR; } number = std::stoi(tmpString) + extendSvgWidth; @@ -630,7 +631,7 @@ xmlNodePtr DrawSVGModifier::UpdateRectNode(xmlNodePtr curNode, int32_t extendSvg oStrStream << xmlGetProp(curNode, BAD_CAST "width"); std::string srcRectWidth = oStrStream.str(); if (!IsNum(srcRectWidth)) { - FI_HILOGE("srcRectWidth invalid, srcRectWidth:%{public}s", srcRectWidth.c_str()); + FI_HILOGE("srcRectWidth is not digital, srcRectWidth:%{public}s", srcRectWidth.c_str()); return nullptr; } int32_t number = std::stoi(srcRectWidth) + extendSvgWidth; diff --git a/utils/common/src/util.cpp b/utils/common/src/util.cpp index 309faf933..d850311c5 100644 --- a/utils/common/src/util.cpp +++ b/utils/common/src/util.cpp @@ -218,7 +218,7 @@ int32_t GetFileSize(const std::string &filePath) { struct stat statbuf = { 0 }; if (stat(filePath.c_str(), &statbuf) != 0) { - FI_HILOGE("Get file size error"); + FI_HILOGE("Get file size error, errno:%{public}d", errno); return RET_ERR; } return statbuf.st_size; -- Gitee From 85a3bdc8ba330b06a94be4c2126f00ee623d8a90 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sat, 18 Mar 2023 16:09:23 +0000 Subject: [PATCH 14/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: Id1570ebc88557c3a1d55eae246cca98a4ffbec69 --- .../src/interaction_manager_mouse_test.cpp | 168 ------------------ 1 file changed, 168 deletions(-) delete mode 100644 frameworks/native/interaction/test/unittest/src/interaction_manager_mouse_test.cpp diff --git a/frameworks/native/interaction/test/unittest/src/interaction_manager_mouse_test.cpp b/frameworks/native/interaction/test/unittest/src/interaction_manager_mouse_test.cpp deleted file mode 100644 index 7308a8eab..000000000 --- a/frameworks/native/interaction/test/unittest/src/interaction_manager_mouse_test.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include "pointer_event.h" - -#include "image_source.h" - -#include "coordination_message.h" -#include "devicestatus_define.h" -#include "devicestatus_errors.h" -#include "interaction_manager.h" - -namespace OHOS { -namespace Msdp { -namespace DeviceStatus { -using namespace testing::ext; -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "InteractionManagerMouseTest" }; -constexpr int32_t TIME_WAIT_FOR_OP = 100; -static bool stopCallbackFlag { false }; -const std::string CURSOR_DRAG_PATH = "/system/etc/device_status/drag_icon/File_Drag.png"; -} // namespace -class InteractionManagerMouseTest : public testing::Test { -public: - void SetUp(); - void TearDown(); - static void SetUpTestCase(); -}; - -void InteractionManagerMouseTest::SetUpTestCase() -{ -} - -void InteractionManagerMouseTest::SetUp() -{ -} - -void InteractionManagerMouseTest::TearDown() -{ - std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); -} - -std::shared_ptr CreatePixelMap(int32_t pixelMapWidth, int32_t pixelMapHeight) -{ - std::string imagePath = CURSOR_DRAG_PATH; - OHOS::Media::SourceOptions opts; - opts.formatHint = "image/png"; - uint32_t errCode = 0; - auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, errCode); - if (imageSource == nullptr) { - return nullptr; - } - std::set formats; - imageSource->GetSupportedFormats(formats); - OHOS::Media::DecodeOptions decodeOpts; - decodeOpts.desiredSize = { - .width = pixelMapWidth, - .height = pixelMapHeight - }; - decodeOpts.allocatorType = OHOS::Media::AllocatorType::SHARE_MEM_ALLOC; - std::shared_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode); - return pixelMap; -} - -int32_t SetParam(int32_t width, int32_t height, DragData& dragData, int32_t sourceType, int32_t pointerId) -{ - auto pixelMap = CreatePixelMap(width, height); - dragData.shadowInfo.pixelMap = pixelMap; - dragData.shadowInfo.x = -50; - dragData.shadowInfo.y = -50; - dragData.buffer = std::vector(MAX_BUFFER_SIZE, 0); - dragData.sourceType = sourceType; - dragData.pointerId = pointerId; - dragData.dragNum = 100; - dragData.displayX = 0; - dragData.displayY = 0; - dragData.displayId = 0; - dragData.hasCanceledAnimation = false; - return RET_OK; -} - -/** - * @tc.name: InteractionManagerMouseTest_Drag - * @tc.desc: Start Drag - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(InteractionManagerMouseTest, InteractionManagerMouseTest_Drag, TestSize.Level1) -{ - CALL_TEST_DEBUG; - DragData dragData; - int32_t ret = SetParam(90, 90, dragData, MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0); - ASSERT_EQ(ret, RET_OK); - stopCallbackFlag = false; - std::function callback = [](const DragNotifyMsg& dragNotifyMsg) { - FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, targetPid%{public}d", - dragNotifyMsg.displayX, dragNotifyMsg.displayY, dragNotifyMsg.result, dragNotifyMsg.targetPid); - stopCallbackFlag = true; - }; - ret = InteractionManager::GetInstance()->StartDrag(dragData, callback); - ASSERT_EQ(ret, RET_OK); - std::cout << "please move the mouse" << std::endl; - std::cout << "start Drag" << std::endl; - sleep(10); - ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::FORBIDDEN); - ASSERT_EQ(ret, RET_OK); - std::cout << "update drag style 0" << std::endl; - sleep(10); - ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY); - std::cout << "change drag style" << std::endl; - sleep(10); - ret = InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_SUCCESS, false); - std::cout << "stop drag" << std::endl; - ASSERT_EQ(ret, RET_OK); -} - -/** - * @tc.name: InteractionManagerMouseTest_Drag_002 - * @tc.desc: Start Drag - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(InteractionManagerMouseTest, InteractionManagerMouseTest_Drag_002, TestSize.Level1) -{ - CALL_TEST_DEBUG; - DragData dragData; - int32_t ret = SetParam(200, 200, dragData, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, 0); - ASSERT_EQ(ret, RET_OK); - stopCallbackFlag = false; - std::function callback = [](const DragNotifyMsg& dragNotifyMsg) { - FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, targetPid%{public}d", - dragNotifyMsg.displayX, dragNotifyMsg.displayY, dragNotifyMsg.result, dragNotifyMsg.targetPid); - stopCallbackFlag = true; - }; - ret = InteractionManager::GetInstance()->StartDrag(dragData, callback); - ASSERT_EQ(ret, RET_OK); - std::cout << "please move the mouse" << std::endl; - std::cout << "start Drag" << std::endl; - sleep(10); - ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::FORBIDDEN); - ASSERT_EQ(ret, RET_OK); - std::cout << "update drag style 0" << std::endl; - sleep(10); - ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY); - std::cout << "change drag style" << std::endl; - sleep(10); - ret = InteractionManager::GetInstance()->StopDrag(DragResult::DRAG_FAIL, false); - std::cout << "stop drag" << std::endl; - ASSERT_EQ(ret, RET_OK); -} -} // namespace DeviceStatus -} // namespace Msdp -} // namespace OHOS -- Gitee From df337ec4cd37ba9b53d9f7571bade4a21dc5bb26 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sun, 19 Mar 2023 03:31:00 +0000 Subject: [PATCH 15/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I78dabb375532495d6dd6f432ec364ecae1edf91f --- .../interaction/drag/include/drag_drawing.h | 8 +++---- .../interaction/drag/src/drag_drawing.cpp | 21 +++++++------------ .../interaction/drag/src/drag_manager.cpp | 2 +- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/services/interaction/drag/include/drag_drawing.h b/services/interaction/drag/include/drag_drawing.h index 90ed586c9..bdd5b943f 100644 --- a/services/interaction/drag/include/drag_drawing.h +++ b/services/interaction/drag/include/drag_drawing.h @@ -108,10 +108,10 @@ private: private: int64_t startNum_ { -1 }; std::shared_ptr canvasNode_ { nullptr }; - std::shared_ptr drawSVGModifier_; - std::shared_ptr drawPixelMapModifier_; - std::shared_ptr drawMouseIconModifier_; - std::shared_ptr drawDynamicEffectModifier_; + std::shared_ptr drawSVGModifier_ { nullptr }; + std::shared_ptr drawPixelMapModifier_ { nullptr }; + std::shared_ptr drawMouseIconModifier_ { nullptr }; + std::shared_ptr drawDynamicEffectModifier_ { nullptr }; std::shared_ptr rsUiDirector_ { nullptr }; std::shared_ptr receiver_ { nullptr }; std::shared_ptr handler_ { nullptr }; diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index e99fe3a7b..adb05260d 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -130,8 +130,8 @@ int32_t DragDrawing::Init(const DragData &dragData) return INIT_FAIL; } InitAnimation(); - if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { - CHKPR(rsUiDirector_, RET_ERR); + CHKPR(rsUiDirector_, RET_ERR); + if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { rsUiDirector_->SendMessages(); return RET_OK; } @@ -139,7 +139,6 @@ int32_t DragDrawing::Init(const DragData &dragData) FI_HILOGE("Draw mouse icon failed"); return INIT_FAIL; } - CHKPR(rsUiDirector_, RET_ERR); rsUiDirector_->SendMessages(); return INIT_SUCCESS; } @@ -254,10 +253,10 @@ void DragDrawing::DestroyDragWindow() { CALL_DEBUG_ENTER; startNum_ = START_TIME; + rsUiDirector_ = nullptr; g_drawingInfo.currentStyle = DragCursorStyle::DEFAULT; - if (g_drawingInfo.pixelMap != nullptr) { - g_drawingInfo.pixelMap = nullptr; - } + g_drawingInfo.pixelMap = nullptr; + g_drawingInfo.surfaceNode = nullptr; if (!g_drawingInfo.nodes.empty()) { g_drawingInfo.nodes.clear(); } @@ -265,16 +264,10 @@ void DragDrawing::DestroyDragWindow() g_drawingInfo.rootNode->ClearChildren(); g_drawingInfo.rootNode = nullptr; } - if (g_drawingInfo.surfaceNode != nullptr) { - g_drawingInfo.surfaceNode = nullptr; - } if (g_drawingInfo.dragWindow != nullptr) { g_drawingInfo.dragWindow->Destroy(); g_drawingInfo.dragWindow = nullptr; } - if (rsUiDirector_ != nullptr) { - rsUiDirector_ = nullptr; - } } void DragDrawing::UpdateDrawingState() @@ -371,8 +364,8 @@ int32_t DragDrawing::InitVSync() receiver_ = rsClient.CreateVSyncReceiver("DragDrawing", handler_); } CHKPR(receiver_, RET_ERR); - auto ret = receiver_->Init(); - if (ret) { + int32_t ret = receiver_->Init(); + if (ret != RET_OK) { FI_HILOGE("Receiver init failed"); return RET_ERR; } diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index f144ec5d4..89aeba9df 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -295,7 +295,7 @@ int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation) break; } default: { - FI_HILOGE("Unsupported DragResult type, DragResult:%{public}d", result); + FI_HILOGW("Unsupported DragResult type, DragResult:%{public}d", result); break; } } -- Gitee From 758616e8208f3253ba284df18b4939f0752bcdea Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sun, 19 Mar 2023 03:42:20 +0000 Subject: [PATCH 16/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I9c0deb6b5b3243c391c06eac4151f74e7573d1be --- services/interaction/drag/src/drag_drawing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index adb05260d..3f34736a5 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -131,7 +131,7 @@ int32_t DragDrawing::Init(const DragData &dragData) } InitAnimation(); CHKPR(rsUiDirector_, RET_ERR); - if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { + if (g_drawingInfo.sourceType != OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE) { rsUiDirector_->SendMessages(); return RET_OK; } -- Gitee From 54a17249c1ae171495dd1e61ee7525513516f75d Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Sun, 19 Mar 2023 06:17:54 +0000 Subject: [PATCH 17/17] drag drawing Signed-off-by: mayunteng_1 Change-Id: I105ea3e83ad7ffd59681a4b5fdac880a3a6f8bd1 --- services/interaction/drag/src/drag_drawing.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 3f34736a5..57df30ff8 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -191,12 +191,11 @@ int32_t DragDrawing::UpdateDragStyle(DragCursorStyle style) void DragDrawing::OnDragSuccess() { CALL_DEBUG_ENTER; + CHKPV(g_drawingInfo.rootNode); if (drawDynamicEffectModifier_ != nullptr) { - CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); } drawDynamicEffectModifier_ = std::make_shared(); - CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); @@ -214,12 +213,11 @@ void DragDrawing::OnDragSuccess() void DragDrawing::OnDragFail() { CALL_DEBUG_ENTER; + CHKPV(g_drawingInfo.rootNode); if (drawDynamicEffectModifier_ != nullptr) { - CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); } drawDynamicEffectModifier_ = std::make_shared(); - CHKPV(g_drawingInfo.rootNode); g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); -- Gitee