X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fimage-loader%2Fimage-load-thread.cpp;h=9b68176b61c0e231437777bf69357d6f2ae3fa15;hp=a27db1450e458aaa9a83012d37abcaeaa2c9c4c8;hb=b05a852e155e887cb0e9e1018205c57bfbbfa334;hpb=bd75dc4cad4ce62cc9206abf19280b40825b9726 diff --git a/dali-toolkit/internal/image-loader/image-load-thread.cpp b/dali-toolkit/internal/image-loader/image-load-thread.cpp index a27db14..9b68176 100644 --- a/dali-toolkit/internal/image-loader/image-load-thread.cpp +++ b/dali-toolkit/internal/image-loader/image-load-thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -18,6 +18,12 @@ // CLASS HEADER #include "image-load-thread.h" +// EXTERNAL INCLUDES +#include +#include +#include +#include + namespace Dali { @@ -27,14 +33,102 @@ namespace Toolkit namespace Internal { -LoadingTask::LoadingTask(uint32_t id, BitmapLoader loader ) -: loader( loader ), - id( id ) +LoadingTask::LoadingTask( uint32_t id, Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex ) +: pixelBuffer(), + url(), + id( id ), + dimensions(), + fittingMode(), + samplingMode(), + orientationCorrection(), + preMultiplyOnLoad( DevelAsyncImageLoader::PreMultiplyOnLoad::OFF ), + isMaskTask( false ), + maskPixelBuffer(), + contentScale( 1.0f ), + cropToMask( false ), + animatedImageLoading( animatedImageLoading ), + frameIndex( frameIndex ) +{ +} + +LoadingTask::LoadingTask( uint32_t id, const VisualUrl& url, ImageDimensions dimensions, + FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad ) +: pixelBuffer(), + url( url ), + id( id ), + dimensions( dimensions ), + fittingMode( fittingMode ), + samplingMode( samplingMode ), + orientationCorrection( orientationCorrection ), + preMultiplyOnLoad( preMultiplyOnLoad ), + isMaskTask( false ), + maskPixelBuffer(), + contentScale( 1.0f ), + cropToMask( false ), + animatedImageLoading(), + frameIndex( 0u ) +{ +} + +LoadingTask::LoadingTask( uint32_t id, Devel::PixelBuffer pixelBuffer, Devel::PixelBuffer maskPixelBuffer, float contentScale, bool cropToMask, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad ) +: pixelBuffer( pixelBuffer ), + url( "" ), + id( id ), + dimensions(), + fittingMode(), + samplingMode(), + orientationCorrection(), + preMultiplyOnLoad( preMultiplyOnLoad ), + isMaskTask( true ), + maskPixelBuffer( maskPixelBuffer ), + contentScale( contentScale ), + cropToMask( cropToMask ), + animatedImageLoading(), + frameIndex( 0u ) { } +void LoadingTask::Load() +{ + if( animatedImageLoading ) + { + pixelBuffer = animatedImageLoading.LoadFrame( frameIndex ); + } + else if( url.IsLocalResource() ) + { + pixelBuffer = Dali::LoadImageFromFile( url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection ); + } + else + { + pixelBuffer = Dali::DownloadImageSynchronously ( url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection ); + } + + if( !pixelBuffer ) + { + DALI_LOG_ERROR( "LoadingTask::Load: Loading is failed: %s\n", url.GetUrl().c_str() ); + } +} + +void LoadingTask::ApplyMask() +{ + pixelBuffer.ApplyMask( maskPixelBuffer, contentScale, cropToMask ); +} + +void LoadingTask::MultiplyAlpha() +{ + if( pixelBuffer && Pixel::HasAlpha( pixelBuffer.GetPixelFormat() ) ) + { + if( preMultiplyOnLoad == DevelAsyncImageLoader::PreMultiplyOnLoad::ON ) + { + pixelBuffer.MultiplyColorByAlpha(); + } + } +} + ImageLoadThread::ImageLoadThread( EventThreadCallback* trigger ) -: mTrigger( trigger ) +: mTrigger( trigger ), + mLogFactory( Dali::Adaptor::Get().GetLogFactory() ) { } @@ -46,13 +140,37 @@ ImageLoadThread::~ImageLoadThread() Join(); delete mTrigger; + + for( auto&& iter : mLoadQueue ) + { + delete iter; + } + mLoadQueue.Clear(); + + for( auto&& iter : mCompleteQueue ) + { + delete iter; + } + mCompleteQueue.Clear(); } void ImageLoadThread::Run() { - while( LoadingTask* task = NextTaskToProcess()) + SetThreadName( "ImageLoadThread" ); + mLogFactory.InstallLogFunction(); + + while( LoadingTask* task = NextTaskToProcess() ) { - task->loader.Load(); + if( !task->isMaskTask ) + { + task->Load(); + } + else + { + task->ApplyMask(); + } + task->MultiplyAlpha(); + AddCompletedTask( task ); } } @@ -60,7 +178,6 @@ void ImageLoadThread::Run() void ImageLoadThread::AddTask( LoadingTask* task ) { bool wasEmpty = false; - { // Lock while adding task to the queue ConditionalWait::ScopedLock lock( mConditionalWait ); @@ -68,7 +185,7 @@ void ImageLoadThread::AddTask( LoadingTask* task ) mLoadQueue.PushBack( task ); } - if( wasEmpty) + if( wasEmpty ) { // wake up the image loading thread mConditionalWait.Notify(); @@ -97,7 +214,7 @@ bool ImageLoadThread::CancelTask( uint32_t loadingTaskId ) // Lock while remove task from the queue ConditionalWait::ScopedLock lock( mConditionalWait ); - for( Vector< LoadingTask* >::Iterator iter = mLoadQueue.Begin(); iter != mLoadQueue.End(); iter++ ) + for( Vector< LoadingTask* >::Iterator iter = mLoadQueue.Begin(); iter != mLoadQueue.End(); ++iter ) { if( (*iter)->id == loadingTaskId ) { @@ -116,9 +233,9 @@ void ImageLoadThread::CancelAll() // Lock while remove task from the queue ConditionalWait::ScopedLock lock( mConditionalWait ); - for( Vector< LoadingTask* >::Iterator iter = mLoadQueue.Begin(); iter != mLoadQueue.End(); iter++ ) + for( Vector< LoadingTask* >::Iterator iter = mLoadQueue.Begin(); iter != mLoadQueue.End(); ++iter ) { - delete (*iter); + delete ( *iter ); } mLoadQueue.Clear(); } @@ -150,8 +267,6 @@ void ImageLoadThread::AddCompletedTask( LoadingTask* task ) mTrigger->Trigger(); } - - } // namespace Internal } // namespace Toolkit