X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Fimage-loader%2Fasync-image-loader-impl.cpp;h=11801fccddb13230bcc8a9fc4d1b899b9c00303e;hb=refs%2Fchanges%2F70%2F285870%2F2;hp=912a4413623f655a308f8f44eb76bde84ac5ad0f;hpb=c13965db82ba91ac307c063c931c6a3cd8bc739e;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 912a441..11801fc 100644 --- a/dali-toolkit/internal/image-loader/async-image-loader-impl.cpp +++ b/dali-toolkit/internal/image-loader/async-image-loader-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -20,27 +20,23 @@ // EXTERNAL INCLUDES #include +#include namespace Dali { - namespace Toolkit { - namespace Internal { - AsyncImageLoader::AsyncImageLoader() : mLoadedSignal(), - mLoadThread( new EventThreadCallback( MakeCallback( this, &AsyncImageLoader::ProcessLoadedImage ) ) ), - mLoadTaskId( 0u ), - mIsLoadThreadStarted( false ) + mLoadTaskId(0u) { } AsyncImageLoader::~AsyncImageLoader() { - mLoadThread.CancelAll(); + CancelAll(); } IntrusivePtr AsyncImageLoader::New() @@ -49,49 +45,63 @@ IntrusivePtr AsyncImageLoader::New() return internal; } -uint32_t AsyncImageLoader::LoadAnimatedImage( Dali::AnimatedImageLoading animatedImageLoading, - uint32_t frameIndex ) +uint32_t AsyncImageLoader::LoadAnimatedImage(Dali::AnimatedImageLoading animatedImageLoading, + uint32_t frameIndex, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad) { - if( !mIsLoadThreadStarted ) - { - mLoadThread.Start(); - mIsLoadThreadStarted = true; - } - mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, animatedImageLoading, frameIndex ) ); - + LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex, preMultiplyOnLoad, MakeCallback(this, &AsyncImageLoader::ProcessLoadedImage)); + Dali::AsyncTaskManager::Get().AddTask(loadingTask); return mLoadTaskId; } -uint32_t AsyncImageLoader::Load( const VisualUrl& url, - ImageDimensions dimensions, - FittingMode::Type fittingMode, - SamplingMode::Type samplingMode, - bool orientationCorrection, - DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad) +uint32_t AsyncImageLoader::LoadAnimatedImage(Dali::AnimatedImageLoading animatedImageLoading, + uint32_t frameIndex, + Dali::ImageDimensions desiredSize, + Dali::FittingMode::Type fittingMode, + Dali::SamplingMode::Type samplingMode, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad) { - if( !mIsLoadThreadStarted ) - { - mLoadThread.Start(); - mIsLoadThreadStarted = true; - } - mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad ) ); + LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex, desiredSize, fittingMode, samplingMode, preMultiplyOnLoad, MakeCallback(this, &AsyncImageLoader::ProcessLoadedImage)); + Dali::AsyncTaskManager::Get().AddTask(loadingTask); + return mLoadTaskId; +} +uint32_t AsyncImageLoader::Load(const VisualUrl& url, + ImageDimensions dimensions, + FittingMode::Type fittingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad, + bool loadPlanes) +{ + LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, loadPlanes, MakeCallback(this, &AsyncImageLoader::ProcessLoadedImage)); + AsyncTaskManager::Get().AddTask(loadingTask); + mLoadingTasks.push_back(AsyncImageLoadingInfo(loadingTask, mLoadTaskId)); return mLoadTaskId; } -uint32_t AsyncImageLoader::ApplyMask( Devel::PixelBuffer pixelBuffer, - Devel::PixelBuffer maskPixelBuffer, - float contentScale, - bool cropToMask, - DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad) +uint32_t AsyncImageLoader::LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer, + ImageDimensions dimensions, + FittingMode::Type fittingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad) { - if( !mIsLoadThreadStarted ) - { - mLoadThread.Start(); - mIsLoadThreadStarted = true; - } - mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad ) ); + LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, encodedImageBuffer, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, MakeCallback(this, &AsyncImageLoader::ProcessLoadedImage)); + Dali::AsyncTaskManager::Get().AddTask(loadingTask); + mLoadingTasks.push_back(AsyncImageLoadingInfo(loadingTask, mLoadTaskId)); + return mLoadTaskId; +} +uint32_t AsyncImageLoader::ApplyMask(Devel::PixelBuffer pixelBuffer, + Devel::PixelBuffer maskPixelBuffer, + float contentScale, + bool cropToMask, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad) +{ + LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad, MakeCallback(this, &AsyncImageLoader::ProcessLoadedImage)); + Dali::AsyncTaskManager::Get().AddTask(loadingTask); + mLoadingTasks.push_back(AsyncImageLoadingInfo(loadingTask, mLoadTaskId)); return mLoadTaskId; } @@ -105,36 +115,81 @@ Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& AsyncImageLoader::P return mPixelBufferLoadedSignal; } -bool AsyncImageLoader::Cancel( uint32_t loadingTaskId ) +bool AsyncImageLoader::Cancel(uint32_t loadingTaskId) { - return mLoadThread.CancelTask( loadingTaskId ); + // Remove already completed tasks + RemoveCompletedTask(); + + auto end = mLoadingTasks.end(); + for(std::vector::iterator iter = mLoadingTasks.begin(); iter != end; ++iter) + { + if((*iter).loadId == loadingTaskId) + { + Dali::AsyncTaskManager::Get().RemoveTask((*iter).loadingTask); + mLoadingTasks.erase(iter); + return true; + } + } + + return false; } void AsyncImageLoader::CancelAll() { - mLoadThread.CancelAll(); + // Remove already completed tasks + RemoveCompletedTask(); + + auto end = mLoadingTasks.end(); + for(std::vector::iterator iter = mLoadingTasks.begin(); iter != end; ++iter) + { + if((*iter).loadingTask && Dali::AsyncTaskManager::Get()) + { + Dali::AsyncTaskManager::Get().RemoveTask(((*iter).loadingTask)); + } + } + mLoadingTasks.clear(); } -void AsyncImageLoader::ProcessLoadedImage() +void AsyncImageLoader::ProcessLoadedImage(LoadingTaskPtr task) { - while( LoadingTask *next = mLoadThread.NextCompletedTask() ) + if(mPixelBufferLoadedSignal.GetConnectionCount() > 0) + { + mPixelBufferLoadedSignal.Emit(task->id, task->pixelBuffers); + } + else if(mLoadedSignal.GetConnectionCount() > 0) { - if( mPixelBufferLoadedSignal.GetConnectionCount() > 0 ) + PixelData pixelData; + if(!task->pixelBuffers.empty()) { - mPixelBufferLoadedSignal.Emit( next->id, next->pixelBuffer ); + pixelData = Devel::PixelBuffer::Convert(task->pixelBuffers[0]); } - else if( mLoadedSignal.GetConnectionCount() > 0 ) + mLoadedSignal.Emit(task->id, pixelData); + } + + mCompletedTaskIds.push_back(task->id); +} + +void AsyncImageLoader::RemoveCompletedTask() +{ + std::uint32_t loadingTaskId; + auto end = mLoadingTasks.end(); + auto endCompletedIter = mCompletedTaskIds.end(); + for(auto iterCompleted = mCompletedTaskIds.begin(); iterCompleted != endCompletedIter; ++iterCompleted) + { + loadingTaskId = (*iterCompleted); + for(std::vector::iterator iter = mLoadingTasks.begin(); iter != end; ++iter) { - PixelData pixelData; - if( next->pixelBuffer ) + if((*iter).loadId == loadingTaskId) { - pixelData = Devel::PixelBuffer::Convert( next->pixelBuffer ); + mLoadingTasks.erase(iter); + end = mLoadingTasks.end(); + break; } - mLoadedSignal.Emit( next->id, pixelData ); } - - delete next; } + + // Remove cached completed tasks + mCompletedTaskIds.clear(); } } // namespace Internal