From ea9e99987a626d73943cf74d7b3b493bef240d68 Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Fri, 3 Nov 2023 14:02:40 +0800 Subject: [PATCH] image obscure Signed-off-by: xiexiyun Change-Id: I3463f63cadad788c5637915a67ab50da2f36f9dc --- .../image_provider/image_loading_context.cpp | 14 ++++++++++++-- .../image_provider/image_loading_context.h | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/image_provider/image_loading_context.cpp b/frameworks/core/components_ng/image_provider/image_loading_context.cpp index fa08679a322..9f9da3c86f8 100644 --- a/frameworks/core/components_ng/image_provider/image_loading_context.cpp +++ b/frameworks/core/components_ng/image_provider/image_loading_context.cpp @@ -125,6 +125,10 @@ void ImageLoadingContext::OnLoadSuccess() if (notifiers_.onLoadSuccess_) { notifiers_.onLoadSuccess_(src_); } + if (pendingMakeCanvasImageTask_) { + pendingMakeCanvasImageTask_(); + pendingMakeCanvasImageTask_ = nullptr; + } } void ImageLoadingContext::OnLoadFail() @@ -314,8 +318,14 @@ bool ImageLoadingContext::MakeCanvasImageIfNeed( } else if (dstSize_ == SizeF()) { res |= dstSize.IsPositive(); } - - if (res) { + CHECK_NULL_RETURN(res, res); + if (stateManager_->GetCurrentState() == ImageLoadingState::MAKE_CANVAS_IMAGE) { + pendingMakeCanvasImageTask_ = [weak = AceType::WeakClaim(this), dstSize, autoResize, imageFit, sourceSize]() { + auto ctx = weak.Upgrade(); + CHECK_NULL_VOID(ctx); + ctx->MakeCanvasImage(dstSize, autoResize, imageFit, sourceSize); + }; + } else { MakeCanvasImage(dstSize, autoResize, imageFit, sourceSize); } return res; diff --git a/frameworks/core/components_ng/image_provider/image_loading_context.h b/frameworks/core/components_ng/image_provider/image_loading_context.h index 11f0c247e65..93561fd7844 100644 --- a/frameworks/core/components_ng/image_provider/image_loading_context.h +++ b/frameworks/core/components_ng/image_provider/image_loading_context.h @@ -24,6 +24,7 @@ namespace OHOS::Ace::NG { +using PendingMakeCanvasImageTask = std::function; // [ImageLoadingContext] do two things: // 1. Provide interfaces for who owns it, notify it's owner when loading events come. // 2. Drive [ImageObject] to load and make [CanvasImage]. @@ -128,6 +129,11 @@ private: // to cancel MakeCanvasImage task std::string canvasKey_; + // if another makeCanvasImage task arrives and current state cannot handle makeCanvasImage command, + // save the least recent makeCanvasImage task and trigger it when the previous makeCanvasImage task end + // and state becomes MAKE_CANVAS_IMAGE_SUCCESS + PendingMakeCanvasImageTask pendingMakeCanvasImageTask_ = nullptr; + friend class ImageStateManager; ACE_DISALLOW_COPY_AND_MOVE(ImageLoadingContext); }; -- Gitee