/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// CLASS HEADER
-#include "texture-async-loading-helper.h"
+#include <dali-toolkit/internal/texture-manager/texture-async-loading-helper.h>
// EXTERNAL HEADERS
#include <dali/integration-api/debug.h>
#endif
TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(TextureManager& textureManager)
-: TextureAsyncLoadingHelper(Toolkit::AsyncImageLoader::New(), textureManager, AsyncLoadingInfoContainerType())
+: mTextureManager(textureManager),
+ mLoadTaskId(0u)
{
}
-void TextureAsyncLoadingHelper::LoadAnimatedImage(const TextureManager::TextureId& textureId,
- Dali::AnimatedImageLoading animatedImageLoading,
- const std::uint32_t& frameIndex)
+void TextureAsyncLoadingHelper::LoadAnimatedImage(const TextureManager::TextureId textureId,
+ Dali::AnimatedImageLoading animatedImageLoading,
+ const uint32_t frameIndex,
+ const Dali::ImageDimensions& desiredSize,
+ const Dali::FittingMode::Type fittingMode,
+ const Dali::SamplingMode::Type samplingMode,
+ const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
{
- mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
- auto id = GetImplementation(mLoader).LoadAnimatedImage(animatedImageLoading, frameIndex);
- mLoadingInfoContainer.back().loadId = id;
+ LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex, desiredSize, fittingMode, samplingMode, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
+ loadingTask->SetTextureId(textureId);
+ Dali::AsyncTaskManager::Get().AddTask(loadingTask);
}
-void TextureAsyncLoadingHelper::Load(const TextureManager::TextureId& textureId,
- const VisualUrl& url,
- const Dali::ImageDimensions& desiredSize,
- const Dali::FittingMode::Type& fittingMode,
- const Dali::SamplingMode::Type& samplingMode,
- const bool& orientationCorrection,
- const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
+void TextureAsyncLoadingHelper::Load(const TextureManager::TextureId textureId,
+ const VisualUrl& url,
+ const Dali::ImageDimensions& desiredSize,
+ const Dali::FittingMode::Type fittingMode,
+ const Dali::SamplingMode::Type samplingMode,
+ const bool orientationCorrection,
+ const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
+ const bool loadYuvPlanes)
{
- mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
+ LoadingTaskPtr loadingTask;
if(DALI_UNLIKELY(url.IsBufferResource()))
{
- auto id = GetImplementation(mLoader).LoadEncodedImageBuffer(mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
- mLoadingInfoContainer.back().loadId = id;
+ loadingTask = new LoadingTask(++mLoadTaskId, mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
}
else
{
- auto id = GetImplementation(mLoader).Load(url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
- mLoadingInfoContainer.back().loadId = id;
+ loadingTask = new LoadingTask(++mLoadTaskId, url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, loadYuvPlanes, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
}
-}
-void TextureAsyncLoadingHelper::ApplyMask(const TextureManager::TextureId& textureId,
- Devel::PixelBuffer pixelBuffer,
- Devel::PixelBuffer maskPixelBuffer,
- const float& contentScale,
- const bool& cropToMask,
- const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
-{
- mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
- auto id = GetImplementation(mLoader).ApplyMask(pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad);
- mLoadingInfoContainer.back().loadId = id;
+ loadingTask->SetTextureId(textureId);
+ Dali::AsyncTaskManager::Get().AddTask(loadingTask);
}
-TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(TextureAsyncLoadingHelper&& rhs)
-: TextureAsyncLoadingHelper(rhs.mLoader, rhs.mTextureManager, std::move(rhs.mLoadingInfoContainer))
+void TextureAsyncLoadingHelper::ApplyMask(const TextureManager::TextureId textureId,
+ Devel::PixelBuffer pixelBuffer,
+ Devel::PixelBuffer maskPixelBuffer,
+ const float contentScale,
+ const bool cropToMask,
+ const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
{
+ LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
+ loadingTask->SetTextureId(textureId);
+ Dali::AsyncTaskManager::Get().AddTask(loadingTask);
}
-TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(
- Toolkit::AsyncImageLoader loader,
- TextureManager& textureManager,
- AsyncLoadingInfoContainerType&& loadingInfoContainer)
-: mLoader(loader),
- mTextureManager(textureManager),
- mLoadingInfoContainer(std::move(loadingInfoContainer))
+void TextureAsyncLoadingHelper::AsyncLoadComplete(LoadingTaskPtr task)
{
- DevelAsyncImageLoader::PixelBufferLoadedSignal(mLoader).Connect(
- this, &TextureAsyncLoadingHelper::AsyncLoadComplete);
-}
-
-void TextureAsyncLoadingHelper::AsyncLoadComplete(uint32_t id,
- Devel::PixelBuffer pixelBuffer)
-{
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureAsyncLoadingHelper::AsyncLoadComplete( loadId :%d )\n", id);
- if(mLoadingInfoContainer.size() >= 1u)
+ // Call TextureManager::AsyncLoadComplete
+ if(task->textureId != TextureManager::INVALID_TEXTURE_ID)
{
- AsyncLoadingInfo loadingInfo = mLoadingInfoContainer.front();
-
- // We can assume that First Loading task comes First.
- if(loadingInfo.loadId == id)
- {
- // Call TextureManager::AsyncLoadComplete
- mTextureManager.AsyncLoadComplete(loadingInfo.textureId, pixelBuffer);
- }
-
- mLoadingInfoContainer.pop_front();
+ mTextureManager.AsyncLoadComplete(task->textureId, task->pixelBuffers);
}
}