From: Kimmo Hoikka Date: Tue, 22 Nov 2016 12:58:39 +0000 (+0000) Subject: Switch Sync- and AsynchImageLoaders to use new (object less) image loading adaptor API X-Git-Tag: dali_1.2.16~9 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=78d26caf8723599166886a1fca571c2365f227bf Switch Sync- and AsynchImageLoaders to use new (object less) image loading adaptor API Change-Id: I6d541f41ab0145f20f849c81a69c8c6369047b76 --- diff --git a/automated-tests/src/dali-toolkit-styling/CMakeLists.txt b/automated-tests/src/dali-toolkit-styling/CMakeLists.txt index d8d55f8..caa901e 100644 --- a/automated-tests/src/dali-toolkit-styling/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-styling/CMakeLists.txt @@ -54,6 +54,7 @@ LIST(APPEND TC_SOURCES PKG_CHECK_MODULES(${CAPI_LIB} REQUIRED dali-core dali-toolkit + dali-adaptor ) PKG_CHECK_MODULES(DALI_ADAPTOR REQUIRED diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp index 420578b..2ff700b 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp @@ -384,7 +384,7 @@ int UtcDaliImageViewAsyncLoadingWithoutAltasing(void) END_TEST; } -int UtcDaliImageViewAsyncLoadingWithAltasing(void) +int UtcDaliImageViewAsyncLoadingWithAtlasing(void) { ToolkitTestApplication application; @@ -393,14 +393,10 @@ int UtcDaliImageViewAsyncLoadingWithAltasing(void) callStack.Reset(); callStack.Enable(true); - application.GetPlatform().SetClosestImageSize(Vector2(34, 34)); - BitmapLoader::ResetLatestCreated(); ImageView imageView = ImageView::New( gImage_34_RGBA, ImageDimensions( 34, 34 ) ); // By default, Aysnc loading is used // loading is not started if the actor is offStage - BitmapLoader loader = BitmapLoader::GetLatestCreated(); - DALI_TEST_CHECK( !loader ); Stage::GetCurrent().Add( imageView ); application.SendNotification(); @@ -408,13 +404,7 @@ int UtcDaliImageViewAsyncLoadingWithAltasing(void) application.Render(16); application.SendNotification(); - // loading started - loader = BitmapLoader::GetLatestCreated(); - DALI_TEST_CHECK( loader ); - - loader.WaitForLoading();// waiting until the image to be loaded - DALI_TEST_CHECK( loader.IsLoaded() ); - + // loading started, this waits for the loader thread for max 30 seconds DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); application.SendNotification(); 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 06065b7..1fbef38 100644 --- a/dali-toolkit/internal/image-loader/async-image-loader-impl.cpp +++ b/dali-toolkit/internal/image-loader/async-image-loader-impl.cpp @@ -19,7 +19,6 @@ #include "async-image-loader-impl.h" // EXTERNAL INCLUDES -#include #include namespace Dali @@ -62,9 +61,7 @@ uint32_t AsyncImageLoader::Load( const std::string& url, mIsLoadThreadStarted = true; } - BitmapLoader loader = BitmapLoader::New( url, dimensions, fittingMode, samplingMode, orientationCorrection ); - - mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, loader ) ); + mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection ) ); return mLoadTaskId; } @@ -88,7 +85,7 @@ void AsyncImageLoader::ProcessLoadedImage() { while( LoadingTask *next = mLoadThread.NextCompletedTask() ) { - mLoadedSignal.Emit( next->id, next->loader.GetPixelData() ); + mLoadedSignal.Emit( next->id, next->pixelData ); delete next; } } diff --git a/dali-toolkit/internal/image-loader/image-load-thread.cpp b/dali-toolkit/internal/image-loader/image-load-thread.cpp index 11e251a..d0b504d 100644 --- a/dali-toolkit/internal/image-loader/image-load-thread.cpp +++ b/dali-toolkit/internal/image-loader/image-load-thread.cpp @@ -18,6 +18,9 @@ // CLASS HEADER #include "image-load-thread.h" +// EXTERNAL INCLUDES +#include + namespace Dali { @@ -27,12 +30,24 @@ namespace Toolkit namespace Internal { -LoadingTask::LoadingTask(uint32_t id, BitmapLoader loader ) -: loader( loader ), - id( id ) +LoadingTask::LoadingTask( uint32_t id, const std::string& url, ImageDimensions dimensions, + FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection ) +: pixelData(), + url( url ), + id( id ), + dimensions( dimensions ), + fittingMode( fittingMode ), + samplingMode( samplingMode ), + orientationCorrection( orientationCorrection ) +{ +} + +void LoadingTask::Load() { + pixelData = Dali::LoadImageFromFile( url, dimensions, fittingMode, samplingMode, orientationCorrection ); } + ImageLoadThread::ImageLoadThread( EventThreadCallback* trigger ) : mTrigger( trigger ) { @@ -52,7 +67,7 @@ void ImageLoadThread::Run() { while( LoadingTask* task = NextTaskToProcess() ) { - task->loader.Load(); + task->Load(); AddCompletedTask( task ); } } @@ -150,8 +165,6 @@ void ImageLoadThread::AddCompletedTask( LoadingTask* task ) mTrigger->Trigger(); } - - } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/image-loader/image-load-thread.h b/dali-toolkit/internal/image-loader/image-load-thread.h index 85ea419..f46d435 100644 --- a/dali-toolkit/internal/image-loader/image-load-thread.h +++ b/dali-toolkit/internal/image-loader/image-load-thread.h @@ -20,12 +20,14 @@ // EXTERNAL INCLUDES #include #include +#include +#include #include #include #include -#include #include + namespace Dali { @@ -42,8 +44,20 @@ struct LoadingTask { /** * Constructor. + * @param [in] id of the task + * @param [in] url The URL of the image file to load. + * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image + * @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. */ - LoadingTask( uint32_t id, BitmapLoader loader ); + LoadingTask( uint32_t id, const std::string& url, ImageDimensions dimensions, + FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection ); + + /** + * Load the image + */ + void Load(); private: @@ -55,8 +69,14 @@ private: public: - BitmapLoader loader; ///< The loader used to load the bitmap from URL - uint32_t id; ///< The id associated with this task. + PixelData pixelData; ///< pixelData handle after successfull load + std::string url; ///< url of the image to load + uint32_t id; ///< The unique id associated with this task. + ImageDimensions dimensions; ///< dimensions to load + FittingMode::Type fittingMode; ///< fitting options + SamplingMode::Type samplingMode; ///< sampling options + bool orientationCorrection:1; ///< if orientation correction is needed + }; diff --git a/dali-toolkit/public-api/image-loader/sync-image-loader.cpp b/dali-toolkit/public-api/image-loader/sync-image-loader.cpp index de489dc..7a8ab3c 100644 --- a/dali-toolkit/public-api/image-loader/sync-image-loader.cpp +++ b/dali-toolkit/public-api/image-loader/sync-image-loader.cpp @@ -16,7 +16,7 @@ // CLASS HEADER #include "sync-image-loader.h" -#include +#include namespace Dali @@ -45,12 +45,8 @@ PixelData Load( const std::string& url, SamplingMode::Type samplingMode, bool orientationCorrection ) { - BitmapLoader loader = BitmapLoader::New( url, dimensions, fittingMode, samplingMode, orientationCorrection ); - // Load the image synchronously (block the thread here). - loader.Load(); - - return loader.GetPixelData(); + return Dali::LoadImageFromFile( url, dimensions, fittingMode, samplingMode, orientationCorrection ); }