mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 23:21:05 +00:00
!38148 修复拖拽截图缩放耗时的问题
Merge pull request !38148 from Zenix/fixPixelMapScale
This commit is contained in:
commit
c22e723101
@ -669,12 +669,14 @@ void DragEventActuator::OnCollectTouchTarget(const OffsetF& coordinateOffset, co
|
||||
auto previewPixelMap = GetPreviewPixelMap(dragPreviewInfo.inspectorId, frameNode);
|
||||
gestureHub->SetPixelMap(previewPixelMap);
|
||||
gestureHub->SetDragPreviewPixelMap(previewPixelMap);
|
||||
actuator->PrepareFinalPixelMapForDragThroughTouch(previewPixelMap, false);
|
||||
} else if (dragPreviewInfo.pixelMap != nullptr) {
|
||||
gestureHub->SetPixelMap(dragPreviewInfo.pixelMap);
|
||||
gestureHub->SetDragPreviewPixelMap(dragPreviewInfo.pixelMap);
|
||||
actuator->PrepareFinalPixelMapForDragThroughTouch(dragPreviewInfo.pixelMap, false);
|
||||
} else if (dragPreviewInfo.customNode != nullptr) {
|
||||
#if defined(PIXEL_MAP_SUPPORTED)
|
||||
auto callback = [id = Container::CurrentId(), pipeline, gestureHub]
|
||||
auto callback = [id = Container::CurrentId(), pipeline, gestureHub, weak]
|
||||
(std::shared_ptr<Media::PixelMap> pixelMap, int32_t arg, std::function<void()>) {
|
||||
ContainerScope scope(id);
|
||||
if (pixelMap != nullptr) {
|
||||
@ -682,10 +684,13 @@ void DragEventActuator::OnCollectTouchTarget(const OffsetF& coordinateOffset, co
|
||||
auto taskScheduler = pipeline->GetTaskExecutor();
|
||||
CHECK_NULL_VOID(taskScheduler);
|
||||
taskScheduler->PostTask(
|
||||
[gestureHub, customPixelMap]() {
|
||||
[gestureHub, customPixelMap, weak]() {
|
||||
CHECK_NULL_VOID(gestureHub);
|
||||
gestureHub->SetPixelMap(customPixelMap);
|
||||
gestureHub->SetDragPreviewPixelMap(customPixelMap);
|
||||
auto actuator = weak.Upgrade();
|
||||
CHECK_NULL_VOID(actuator);
|
||||
actuator->PrepareFinalPixelMapForDragThroughTouch(customPixelMap, true);
|
||||
},
|
||||
TaskExecutor::TaskType::UI, "ArkUIDragSetCustomPixelMap");
|
||||
}
|
||||
@ -2390,4 +2395,55 @@ void DragEventActuator::ResetResponseRegion()
|
||||
isResponseRegionFull = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DragEventActuator::PrepareFinalPixelMapForDragThroughTouch(RefPtr<PixelMap> pixelMap, bool immediately)
|
||||
{
|
||||
ResetPreScaledPixelMapForDragThroughTouch();
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto dragDropManager = pipeline->GetDragDropManager();
|
||||
CHECK_NULL_VOID(dragDropManager);
|
||||
auto windowScale = dragDropManager->GetWindowScale();
|
||||
float scale = windowScale * PIXELMAP_DRAG_SCALE_MULTIPLE;
|
||||
|
||||
auto task = [weak = WeakClaim(this), pixelMap, scale] () {
|
||||
auto actuator = weak.Upgrade();
|
||||
CHECK_NULL_VOID(actuator);
|
||||
actuator->DoPixelMapScaleForDragThroughTouch(pixelMap, scale);
|
||||
};
|
||||
|
||||
if (immediately) {
|
||||
task();
|
||||
return;
|
||||
}
|
||||
|
||||
auto taskScheduler = pipeline->GetTaskExecutor();
|
||||
CHECK_NULL_VOID(taskScheduler);
|
||||
taskScheduler->PostTask(task, TaskExecutor::TaskType::UI, "ArkUIPrepareScaledPixel", PriorityType::VIP);
|
||||
}
|
||||
|
||||
void DragEventActuator::DoPixelMapScaleForDragThroughTouch(RefPtr<PixelMap> pixelMap, float targetScale)
|
||||
{
|
||||
#if defined(PIXEL_MAP_SUPPORTED)
|
||||
preScaledPixelMap_ = PixelMap::CopyPixelMap(pixelMap);
|
||||
if (!preScaledPixelMap_) {
|
||||
TAG_LOGW(AceLogTag::ACE_DRAG, "Copy preScaledPixelMap_ is failure!");
|
||||
return;
|
||||
}
|
||||
preScaledPixelMap_->Scale(targetScale, targetScale, AceAntiAliasingOption::HIGH);
|
||||
preScaleValue_ = targetScale;
|
||||
#endif
|
||||
}
|
||||
|
||||
RefPtr<PixelMap> DragEventActuator::GetPreScaledPixelMapForDragThroughTouch(float& preScale)
|
||||
{
|
||||
preScale = preScaleValue_;
|
||||
return preScaledPixelMap_;
|
||||
}
|
||||
|
||||
void DragEventActuator::ResetPreScaledPixelMapForDragThroughTouch()
|
||||
{
|
||||
preScaledPixelMap_ = nullptr;
|
||||
preScaleValue_ = 1.0f;
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -274,6 +274,10 @@ public:
|
||||
void SetResponseRegionFull();
|
||||
void ResetResponseRegion();
|
||||
static void ResetDragStatus();
|
||||
void PrepareFinalPixelMapForDragThroughTouch(RefPtr<PixelMap> pixelMap, bool immediately);
|
||||
void DoPixelMapScaleForDragThroughTouch(RefPtr<PixelMap> pixelMap, float targetScale);
|
||||
RefPtr<PixelMap> GetPreScaledPixelMapForDragThroughTouch(float& preScale);
|
||||
void ResetPreScaledPixelMapForDragThroughTouch();
|
||||
|
||||
private:
|
||||
void UpdatePreviewOptionFromModifier(const RefPtr<FrameNode>& frameNode);
|
||||
@ -303,6 +307,7 @@ private:
|
||||
RefPtr<TouchEventImpl> touchListener_;
|
||||
|
||||
RefPtr<PixelMap> textPixelMap_;
|
||||
RefPtr<PixelMap> preScaledPixelMap_;
|
||||
std::function<void(GestureEvent&)> actionStart_;
|
||||
std::function<void(GestureEvent&)> longPressUpdate_;
|
||||
std::function<void()> actionCancel_;
|
||||
@ -323,6 +328,7 @@ private:
|
||||
PanDirection direction_;
|
||||
int32_t fingers_ = 1;
|
||||
float distance_ = 0.0f;
|
||||
float preScaleValue_ = 1.0f;
|
||||
bool isRedragStart_ = false;
|
||||
};
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "drag_event.h"
|
||||
|
||||
#include "base/log/log_wrapper.h"
|
||||
#include "base/memory/ace_type.h"
|
||||
@ -614,6 +615,24 @@ OffsetF GestureEventHub::GetPixelMapOffset(
|
||||
return result;
|
||||
}
|
||||
|
||||
RefPtr<PixelMap> GestureEventHub::GetPreScaledPixelMapIfExist(float targetScale, RefPtr<PixelMap> defaultPixelMap)
|
||||
{
|
||||
float preScale = 1.0f;
|
||||
RefPtr<PixelMap> preScaledPixelMap = dragEventActuator_->GetPreScaledPixelMapForDragThroughTouch(preScale);
|
||||
if (preScale == targetScale && preScaledPixelMap != nullptr) {
|
||||
return preScaledPixelMap;
|
||||
}
|
||||
#if defined(PIXEL_MAP_SUPPORTED)
|
||||
preScaledPixelMap = PixelMap::CopyPixelMap(defaultPixelMap);
|
||||
if (!preScaledPixelMap) {
|
||||
TAG_LOGW(AceLogTag::ACE_DRAG, "duplicate PixelMap failed!");
|
||||
preScaledPixelMap = defaultPixelMap;
|
||||
}
|
||||
preScaledPixelMap->Scale(targetScale, targetScale, AceAntiAliasingOption::HIGH);
|
||||
#endif
|
||||
return preScaledPixelMap;
|
||||
}
|
||||
|
||||
float GestureEventHub::GetPixelMapScale(const int32_t height, const int32_t width) const
|
||||
{
|
||||
float scale = 1.0f;
|
||||
@ -977,15 +996,7 @@ void GestureEventHub::OnDragStart(const GestureEvent& info, const RefPtr<Pipelin
|
||||
dragEventActuator_->SetIsNotInPreviewState(true);
|
||||
}
|
||||
}
|
||||
RefPtr<PixelMap> pixelMapDuplicated = pixelMap;
|
||||
#if defined(PIXEL_MAP_SUPPORTED)
|
||||
pixelMapDuplicated = PixelMap::CopyPixelMap(pixelMap);
|
||||
if (!pixelMapDuplicated) {
|
||||
TAG_LOGW(AceLogTag::ACE_DRAG, "Copy PixelMap is failure!");
|
||||
pixelMapDuplicated = pixelMap;
|
||||
}
|
||||
#endif
|
||||
pixelMapDuplicated->Scale(scale, scale, AceAntiAliasingOption::HIGH);
|
||||
RefPtr<PixelMap> pixelMapDuplicated = GetPreScaledPixelMapIfExist(scale, pixelMap);
|
||||
auto width = pixelMapDuplicated->GetWidth();
|
||||
auto height = pixelMapDuplicated->GetHeight();
|
||||
auto pixelMapOffset = GetPixelMapOffset(info, SizeF(width, height), scale, IsPixelMapNeedScale());
|
||||
|
@ -608,6 +608,7 @@ public:
|
||||
void GenerateMousePixelMap(const GestureEvent& info);
|
||||
OffsetF GetPixelMapOffset(
|
||||
const GestureEvent& info, const SizeF& size, const float scale = 1.0f, const bool needScale = false) const;
|
||||
RefPtr<PixelMap> GetPreScaledPixelMapIfExist(float targetScale, RefPtr<PixelMap> defaultPixelMap);
|
||||
float GetPixelMapScale(const int32_t height, const int32_t width) const;
|
||||
bool IsPixelMapNeedScale() const;
|
||||
void InitDragDropEvent();
|
||||
|
Loading…
Reference in New Issue
Block a user