Update dragDrawing for fast mouse drag

Signed-off-by: xingjiangpan <xingjiangpan2@huawei.com>
Change-Id: I3956fcba801e52346d9998baa4cd7f1b03f4dc8c
This commit is contained in:
xingjiangpan 2024-08-05 14:37:27 +08:00
parent 01e3e0b6df
commit efa183755a
15 changed files with 159 additions and 34 deletions

View File

@ -232,6 +232,11 @@ int32_t InteractionManager::EraseMouseIcon()
return INTER_MGR_IMPL.EraseMouseIcon();
}
int32_t InteractionManager::SetMouseDragMonitorState(bool state)
{
return INTER_MGR_IMPL.SetMouseDragMonitorState(state);
}
int32_t InteractionManager::AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
std::function<void(bool)> callback)
{

View File

@ -65,6 +65,7 @@ public:
int32_t EraseMouseIcon(ITunnelClient &tunnel);
int32_t AddSelectedPixelMap(ITunnelClient &tunnel, std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
std::function<void(bool)> callback);
int32_t SetMouseDragMonitorState(ITunnelClient &tunnel, bool state);
int32_t OnNotifyResult(const StreamClient &client, NetPacket &pkt);
int32_t OnNotifyHideIcon(const StreamClient& client, NetPacket& pkt);

View File

@ -422,6 +422,18 @@ int32_t DragClient::EraseMouseIcon(ITunnelClient &tunnel)
return ret;
}
int32_t DragClient::SetMouseDragMonitorState(ITunnelClient &tunnel, bool state)
{
SetMouseDragMonitorStateParam param { state };
DefaultReply reply {};
int32_t ret = tunnel.Control(Intention::DRAG, DragRequestID::SET_MOUSE_DRAG_MONITOR_STATE, param, reply);
if (ret != RET_OK) {
FI_HILOGE("ITunnelClient::Control fail");
}
return ret;
}
int32_t DragClient::AddSelectedPixelMap(ITunnelClient &tunnel, std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
std::function<void(bool)> callback)
{

View File

@ -47,6 +47,7 @@ enum DragRequestID : uint32_t {
GET_DRAG_STATE,
ADD_PRIVILEGE,
ENTER_TEXT_EDITOR_AREA,
SET_MOUSE_DRAG_MONITOR_STATE,
GET_DRAG_ACTION,
GET_EXTRA_INFO,
ERASE_MOUSE_ICON,
@ -237,7 +238,7 @@ struct GetDragStateReply final : public ParamBase {
};
using EnterTextEditorAreaParam = BooleanReply;
using SetMouseDragMonitorStateParam = BooleanReply;
struct GetDragActionReply final : public ParamBase {
GetDragActionReply() = default;
explicit GetDragActionReply(DragAction dragAction);

View File

@ -64,6 +64,7 @@ private:
int32_t AddSelectedPixelMap(CallingContext &context, MessageParcel &data, MessageParcel &reply);
int32_t RemoveListener(CallingContext &context, MessageParcel &data);
int32_t AddListener(CallingContext &context, MessageParcel &data);
int32_t SetMouseDragMonitorState(CallingContext &context, MessageParcel &data, MessageParcel &reply);
IContext *env_ { nullptr };
};

View File

@ -205,6 +205,10 @@ int32_t DragServer::Control(CallingContext &context, uint32_t id, MessageParcel
FI_HILOGI("Erase mouse, from:%{public}d", context.pid);
return env_->GetDragManager().EraseMouseIcon();
}
case DragRequestID::SET_MOUSE_DRAG_MONITOR_STATE: {
FI_HILOGI("Set mouse drag monitor state, from:%{public}d", context.pid);
return SetMouseDragMonitorState(context, data, reply);
}
default: {
FI_HILOGE("Unexpected request ID (%{public}u)", id);
return RET_ERR;
@ -495,6 +499,17 @@ int32_t DragServer::EnterTextEditorArea(CallingContext &context, MessageParcel &
return env_->GetDragManager().EnterTextEditorArea(param.state);
}
int32_t DragServer::SetMouseDragMonitorState(CallingContext &context, MessageParcel &data, MessageParcel &reply)
{
SetMouseDragMonitorStateParam param {};
if (!param.Unmarshalling(data)) {
FI_HILOGE("SetMouseDragMonitorStateParam::Unmarshalling fail");
return RET_ERR;
}
return env_->GetDragManager().SetMouseDragMonitorState(param.state);
}
std::string DragServer::GetPackageName(Security::AccessToken::AccessTokenID tokenId)
{
std::string packageName = std::string();

View File

@ -82,6 +82,7 @@ public:
int32_t AddPrivilege();
int32_t EraseMouseIcon();
int32_t SetDragWindowScreenId(uint64_t displayId, uint64_t screenId);
int32_t SetMouseDragMonitorState(bool state);
int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap, std::function<void(bool)> callback);
private:

View File

@ -460,6 +460,12 @@ int32_t IntentionManager::EraseMouseIcon()
return drag_.EraseMouseIcon(*tunnel_);
}
int32_t IntentionManager::SetMouseDragMonitorState(bool state)
{
CALL_DEBUG_ENTER;
return drag_.SetMouseDragMonitorState(*tunnel_, state);
}
int32_t IntentionManager::AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
std::function<void(bool)> callback)
{

View File

@ -79,6 +79,7 @@ public:
virtual void SetAllowStartDrag(bool hasUpEvent) = 0;
virtual void SetCooperatePriv(uint32_t priv) = 0;
virtual uint32_t GetCooperatePriv() const = 0;
virtual int32_t SetMouseDragMonitorState(bool state) = 0;
};
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -347,6 +347,8 @@ public:
int32_t SetDragWindowScreenId(uint64_t displayId, uint64_t screenId);
int32_t SetMouseDragMonitorState(bool state);
/**
* @brief Add an image to the drag list.
* @param pixelMap Add Selected image information.

View File

@ -70,7 +70,8 @@
"OHOS::Msdp::DeviceStatus::InteractionManager::EraseMouseIcon()";
"OHOS::Msdp::DeviceStatus::InteractionManager::SetDragWindowScreenId(unsigned long, unsigned long)";
"OHOS::Msdp::DeviceStatus::InteractionManager::SetDragWindowScreenId(unsigned long long, unsigned long long)";
"OHOS::Msdp::DeviceStatus::InteractionManager::AddSelectedPixelMap(std::__h::shared_ptr<OHOS::Media::PixelMap>, std::__h::function<void (bool)>)";
"OHOS::Msdp::DeviceStatus::InteractionManager::SetMouseDragMonitorState(bool)";
"OHOS::Msdp::DeviceStatus::InteractionManager::AddSelectedPixelMap(std::__h::shared_ptr<OHOS::Media::PixelMap>, std::__h::function<void (bool)>)";
};
local:
*;

View File

@ -266,6 +266,7 @@ public:
float CalculateWidthScale();
float GetMaxWidthScale(int32_t width);
int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
void MouseDragMonitorPosition(int32_t displayX, int32_t displayY);
private:
int32_t CheckDragData(const DragData &dragData);
@ -349,6 +350,8 @@ private:
private:
int64_t interruptNum_ { -1 };
int64_t mouseDragMonitorDisplayX_ { -1 };
int64_t mouseDragMonitorDisplayY_ { -1 };
std::shared_ptr<Rosen::RSCanvasNode> canvasNode_ { nullptr };
std::shared_ptr<DrawSVGModifier> drawSVGModifier_ { nullptr };
std::shared_ptr<DrawPixelMapModifier> drawPixelMapModifier_ { nullptr };

View File

@ -93,6 +93,7 @@ public:
void SetAllowStartDrag(bool hasUpEvent) override;
void SetCooperatePriv(uint32_t priv) override;
uint32_t GetCooperatePriv() const override;
int32_t SetMouseDragMonitorState(bool state) override;
#ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
class InterceptorConsumer : public MMI::IInputEventConsumer {
public:
@ -123,6 +124,7 @@ private:
int32_t AddDragEventHandler(int32_t sourceType);
int32_t AddPointerEventHandler(uint32_t deviceTags);
int32_t AddKeyEventMonitor();
int32_t RemoveDragEventHandler();
int32_t RemoveKeyEventMonitor();
int32_t RemovePointerEventHandler();
int32_t NotifyDragResult(DragResult result, DragBehavior dragBehavior);
@ -147,6 +149,7 @@ private:
bool IsAllowStartDrag() const;
private:
int32_t timerId_ { -1 };
int32_t mouseDragMonitorTimerId_ { -1 };
StateChangeNotify stateNotify_;
DragState dragState_ { DragState::STOP };
DragResult dragResult_ { DragResult::DRAG_FAIL };

View File

@ -264,6 +264,9 @@ int32_t DragDrawing::Init(const DragData &dragData, IContext* context)
FI_HILOGE("Draw mouse icon failed");
return INIT_FAIL;
}
if ((mouseDragMonitorDisplayX_ != -1) && (mouseDragMonitorDisplayY_ != -1)) {
UpdateDragPosition(g_drawingInfo.displayId, mouseDragMonitorDisplayX_, mouseDragMonitorDisplayY_);
}
rsUiDirector_->SendMessages();
FI_HILOGI("leave");
return INIT_SUCCESS;
@ -553,6 +556,12 @@ int32_t DragDrawing::AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap>
return RET_OK;
}
void DragDrawing::MouseDragMonitorPosition(int32_t displayX, int32_t displayY)
{
mouseDragMonitorDisplayX_ = displayX;
mouseDragMonitorDisplayY_ = displayY;
}
void DragDrawing::OnDragSuccess(IContext* context)
{
FI_HILOGI("enter");

View File

@ -191,6 +191,11 @@ void DragManager::PrintDragData(const DragData &dragData, const std::string &pac
int32_t DragManager::StartDrag(const DragData &dragData, int32_t pid)
{
FI_HILOGI("enter");
if ((context_ != nullptr) && (mouseDragMonitorTimerId_ >= 0) &&
(dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE)) {
context_->GetTimerManager().RemoveTimer(mouseDragMonitorTimerId_);
mouseDragMonitorTimerId_ = -1;
}
if (!IsAllowStartDrag()) {
FI_HILOGE("Dragging is not allowed when there is an up event");
SetAllowStartDrag(true);
@ -216,11 +221,13 @@ int32_t DragManager::StartDrag(const DragData &dragData, int32_t pid)
PrintDragData(dragData, packageName);
if (InitDataManager(dragData) != RET_OK) {
FI_HILOGE("Failed to init data manager");
RemoveDragEventHandler();
return RET_ERR;
}
if (OnStartDrag() != RET_OK) {
DragDFX::WriteStartDrag(dragState_, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
FI_HILOGE("Failed to execute OnStartDrag");
RemoveDragEventHandler();
return RET_ERR;
}
if (notifyPUllUpCallback_ != nullptr) {
@ -427,12 +434,20 @@ void DragManager::DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)
{
CHKPV(pointerEvent);
int32_t pointerAction = pointerEvent->GetPointerAction();
if ((pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
(pointerAction == MMI::PointerEvent::POINTER_ACTION_MOVE)) {
MMI::PointerEvent::PointerItem pointerItem;
pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
dragDrawing_.MouseDragMonitorPosition(pointerItem.GetDisplayX(), pointerItem.GetDisplayY());
}
if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_MOVE) {
dragDrawing_.MouseDragMonitorPosition(-1, -1);
OnDragMove(pointerEvent);
return;
}
FI_HILOGD("DragCallback, pointerAction:%{public}d", pointerAction);
if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
dragDrawing_.MouseDragMonitorPosition(-1, -1);
CHKPV(context_);
int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, pointerEvent] {
return this->OnDragUp(pointerEvent);
@ -687,14 +702,14 @@ int32_t DragManager::AddDragEventHandler(int32_t sourceType)
return RET_ERR;
}
#endif // OHOS_DRAG_ENABLE_INTERCEPTOR
if (AddPointerEventHandler(deviceTags) != RET_OK) {
FI_HILOGE("Failed to add pointer event handler");
return RET_ERR;
}
if (AddKeyEventMonitor() != RET_OK) {
FI_HILOGE("Failed to add key event handler");
return RET_ERR;
}
if (AddPointerEventHandler(deviceTags) != RET_OK) {
FI_HILOGE("Failed to add pointer event handler");
return RET_ERR;
}
FI_HILOGI("leave");
return RET_OK;
}
@ -702,43 +717,49 @@ int32_t DragManager::AddDragEventHandler(int32_t sourceType)
int32_t DragManager::AddPointerEventHandler(uint32_t deviceTags)
{
FI_HILOGI("enter");
#ifdef OHOS_DRAG_ENABLE_MONITOR
auto monitor = std::make_shared<MonitorConsumer>([this](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
return this->DragCallback(pointerEvent);
});
pointerEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor);
if (pointerEventMonitorId_ <= 0) {
FI_HILOGE("Failed to add pointer event monitor");
return RET_ERR;
}
#ifdef OHOS_DRAG_ENABLE_MONITOR
auto monitor = std::make_shared<MonitorConsumer>([this](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
return this->DragCallback(pointerEvent);
});
pointerEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor);
if (pointerEventMonitorId_ <= 0) {
FI_HILOGE("Failed to add pointer event monitor");
return RET_ERR;
}
#else
auto callback = [this](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
return this->DragCallback(pointerEvent);
};
auto interceptor = std::make_shared<InterceptorConsumer>(callback);
pointerEventInterceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor(
interceptor, DRAG_PRIORITY, deviceTags);
if (pointerEventInterceptorId_ <= 0) {
FI_HILOGE("Failed to add pointer event interceptor");
return RET_ERR;
}
auto callback = [this](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
return this->DragCallback(pointerEvent);
};
auto interceptor = std::make_shared<InterceptorConsumer>(callback);
pointerEventInterceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor(
interceptor, DRAG_PRIORITY, deviceTags);
if (pointerEventInterceptorId_ <= 0) {
FI_HILOGE("Failed to add pointer event interceptor");
return RET_ERR;
}
#endif // OHOS_DRAG_ENABLE_MONITOR
FI_HILOGI("Add drag poniter event handle successfully");
FI_HILOGI("Add drag poniter event handle successfully");
}
FI_HILOGI("leave");
return RET_OK;
}
int32_t DragManager::AddKeyEventMonitor()
{
FI_HILOGI("enter");
keyEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(
[this](std::shared_ptr<MMI::KeyEvent> keyEvent) {
return this->DragKeyEventCallback(keyEvent);
});
if (keyEventMonitorId_ <= 0) {
FI_HILOGE("Failed to add key event monitor");
return RET_ERR;
keyEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(
[this](std::shared_ptr<MMI::KeyEvent> keyEvent) {
return this->DragKeyEventCallback(keyEvent);
});
if (keyEventMonitorId_ <= 0) {
FI_HILOGE("Failed to add key event monitor");
return RET_ERR;
}
FI_HILOGI("Add drag key event monitor successfully");
}
FI_HILOGI("Add drag key event monitor successfully");
FI_HILOGI("leave");
return RET_OK;
}
@ -763,6 +784,21 @@ int32_t DragManager::RemovePointerEventHandler()
return RET_OK;
}
int32_t DragManager::RemoveDragEventHandler()
{
FI_HILOGI("enter");
if (RemoveKeyEventMonitor() != RET_OK) {
FI_HILOGE("Failed to remove key event handler");
return RET_ERR;
}
if (RemovePointerEventHandler() != RET_OK) {
FI_HILOGE("Failed to remove pointer event handler");
return RET_ERR;
}
FI_HILOGI("leave");
return RET_OK;
}
int32_t DragManager::RemoveKeyEventMonitor()
{
FI_HILOGI("enter");
@ -811,10 +847,14 @@ int32_t DragManager::OnStartDrag()
FI_HILOGE("Init drag drawing cancel, drag animation is running");
return RET_ERR;
}
dragDrawing_.Draw(dragData.displayId, dragData.displayX, dragData.displayY);
if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
dragDrawing_.Draw(dragData.displayId, dragData.displayX, dragData.displayY);
}
FI_HILOGI("Start drag, appened extra data");
MMI::InputManager::GetInstance()->AppendExtraData(extraData);
ret = AddDragEventHandler(dragData.sourceType);
if (pointerEventMonitorId_ <= 0) {
ret = AddDragEventHandler(dragData.sourceType);
}
if (ret != RET_OK) {
FI_HILOGE("Failed to add drag event handler");
dragDrawing_.DestroyDragWindow();
@ -1373,6 +1413,30 @@ uint32_t DragManager::GetCooperatePriv() const
{
return priv_;
}
int32_t DragManager::SetMouseDragMonitorState(bool state)
{
if (state) {
if (AddDragEventHandler(MMI::PointerEvent::SOURCE_TYPE_MOUSE) != RET_OK) {
FI_HILOGE("Failed to add drag event handler");
return RET_ERR;
}
if (context_ != nullptr) {
int32_t repeatCount = 1;
mouseDragMonitorTimerId_ = context_->GetTimerManager().AddTimer(TIMEOUT_MS,
repeatCount, [this]() {
FI_HILOGW("Timeout, automatically remove monitor");
this->RemoveDragEventHandler();
});
}
} else {
if (RemoveDragEventHandler() != RET_OK) {
FI_HILOGE("Failed to remove drag event handler");
return RET_ERR;
}
}
return RET_OK;
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS