From 1bad054940de89414972d96be98c4ab9bf696aaf Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Mon, 2 Aug 2021 14:29:12 +0900 Subject: [PATCH] Remove VisualFactory::Get() code at AsyncImageLoader Make to send EncodedImageBuffer from TextureManager to AsyncImageLoader directly. Now we don't need to get standalone factory at AsyncImageLoader. So we don't need fearful exception check Change-Id: I9b903c6a446fc167d11bdf7e22e6c7e19d085cc5 Signed-off-by: Eunki, Hong --- .../image-loader/async-image-loader-impl.cpp | 31 ++++++++++------------ .../image-loader/async-image-loader-impl.h | 17 ++++++++++++ .../internal/visuals/texture-manager-impl.cpp | 12 +++++++-- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/dali-toolkit/internal/image-loader/async-image-loader-impl.cpp b/dali-toolkit/internal/image-loader/async-image-loader-impl.cpp index ea10924..64639b5 100644 --- a/dali-toolkit/internal/image-loader/async-image-loader-impl.cpp +++ b/dali-toolkit/internal/image-loader/async-image-loader-impl.cpp @@ -21,9 +21,6 @@ // EXTERNAL INCLUDES #include -// INTERNAL INCLUDES -#include - namespace Dali { namespace Toolkit @@ -74,24 +71,24 @@ uint32_t AsyncImageLoader::Load(const VisualUrl& url, mLoadThread.Start(); mIsLoadThreadStarted = true; } - if(url.IsBufferResource()) - { - auto visualFactory = Toolkit::VisualFactory::Get(); - if(visualFactory) - { - // Get EncodedImageBuffer from texturemanager - // and make new LoadingTask with buffer - auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); + mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad)); - const EncodedImageBuffer& encodedBuffer = textureManager.GetEncodedImageBuffer(url.GetUrl()); + return mLoadTaskId; +} - mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, encodedBuffer, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad)); - } - } - else +uint32_t AsyncImageLoader::LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer, + ImageDimensions dimensions, + FittingMode::Type fittingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad) +{ + if(!mIsLoadThreadStarted) { - mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad)); + mLoadThread.Start(); + mIsLoadThreadStarted = true; } + mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, encodedImageBuffer, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad)); return mLoadTaskId; } diff --git a/dali-toolkit/internal/image-loader/async-image-loader-impl.h b/dali-toolkit/internal/image-loader/async-image-loader-impl.h index 2227711..39e4690 100644 --- a/dali-toolkit/internal/image-loader/async-image-loader-impl.h +++ b/dali-toolkit/internal/image-loader/async-image-loader-impl.h @@ -62,6 +62,23 @@ public: DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad); /** + * @brief Starts an image loading task by encoded image buffer. + * @param[in] encodedImageBuffer The encoded buffer of the image to load + * @param[in] dimensions The width and height to fit the loaded image to + * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter + * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size + * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header + * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha. + * @return The loading task id + */ + uint32_t LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer, + ImageDimensions dimensions, + FittingMode::Type fittingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad); + + /** * @brief Starts an mask applying task. * @param[in] pixelBuffer of the to be masked image * @param[in] maskPixelBuffer of the mask image diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.cpp b/dali-toolkit/internal/visuals/texture-manager-impl.cpp index dbb1230..c6fc0c2 100644 --- a/dali-toolkit/internal/visuals/texture-manager-impl.cpp +++ b/dali-toolkit/internal/visuals/texture-manager-impl.cpp @@ -1419,8 +1419,16 @@ void TextureManager::AsyncLoadingHelper::Load(TextureId DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad) { mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId)); - auto id = GetImplementation(mLoader).Load(url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad); - mLoadingInfoContainer.back().loadId = id; + if(DALI_UNLIKELY(url.IsBufferResource())) + { + auto id = GetImplementation(mLoader).LoadEncodedImageBuffer(mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad); + mLoadingInfoContainer.back().loadId = id; + } + else + { + auto id = GetImplementation(mLoader).Load(url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad); + mLoadingInfoContainer.back().loadId = id; + } } void TextureManager::AsyncLoadingHelper::ApplyMask(TextureId textureId, -- 2.7.4