Switch Sync- and AsynchImageLoaders to use new (object less) image loading adaptor API 64/99364/3
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 22 Nov 2016 12:58:39 +0000 (12:58 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 22 Nov 2016 16:50:05 +0000 (16:50 +0000)
Change-Id: I6d541f41ab0145f20f849c81a69c8c6369047b76

automated-tests/src/dali-toolkit-styling/CMakeLists.txt
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/internal/image-loader/async-image-loader-impl.cpp
dali-toolkit/internal/image-loader/image-load-thread.cpp
dali-toolkit/internal/image-loader/image-load-thread.h
dali-toolkit/public-api/image-loader/sync-image-loader.cpp

index d8d55f8..caa901e 100644 (file)
@@ -54,6 +54,7 @@ LIST(APPEND TC_SOURCES
 PKG_CHECK_MODULES(${CAPI_LIB} REQUIRED
   dali-core
   dali-toolkit
 PKG_CHECK_MODULES(${CAPI_LIB} REQUIRED
   dali-core
   dali-toolkit
+  dali-adaptor
 )
 
 PKG_CHECK_MODULES(DALI_ADAPTOR REQUIRED
 )
 
 PKG_CHECK_MODULES(DALI_ADAPTOR REQUIRED
index 420578b..2ff700b 100644 (file)
@@ -384,7 +384,7 @@ int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
   END_TEST;
 }
 
   END_TEST;
 }
 
-int UtcDaliImageViewAsyncLoadingWithAltasing(void)
+int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
 {
   ToolkitTestApplication application;
 
 {
   ToolkitTestApplication application;
 
@@ -393,14 +393,10 @@ int UtcDaliImageViewAsyncLoadingWithAltasing(void)
   callStack.Reset();
   callStack.Enable(true);
 
   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
   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();
 
   Stage::GetCurrent().Add( imageView );
   application.SendNotification();
@@ -408,13 +404,7 @@ int UtcDaliImageViewAsyncLoadingWithAltasing(void)
   application.Render(16);
   application.SendNotification();
 
   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();
   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
 
   application.SendNotification();
index 06065b7..1fbef38 100644 (file)
@@ -19,7 +19,6 @@
 #include "async-image-loader-impl.h"
 
 // EXTERNAL INCLUDES
 #include "async-image-loader-impl.h"
 
 // EXTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/bitmap-loader.h>
 #include <dali/integration-api/adaptors/adaptor.h>
 
 namespace Dali
 #include <dali/integration-api/adaptors/adaptor.h>
 
 namespace Dali
@@ -62,9 +61,7 @@ uint32_t AsyncImageLoader::Load( const std::string& url,
     mIsLoadThreadStarted = true;
   }
 
     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;
 }
 
   return mLoadTaskId;
 }
@@ -88,7 +85,7 @@ void AsyncImageLoader::ProcessLoadedImage()
 {
   while( LoadingTask *next =  mLoadThread.NextCompletedTask() )
   {
 {
   while( LoadingTask *next =  mLoadThread.NextCompletedTask() )
   {
-    mLoadedSignal.Emit( next->id, next->loader.GetPixelData() );
+    mLoadedSignal.Emit( next->id, next->pixelData );
     delete next;
   }
 }
     delete next;
   }
 }
index 11e251a..d0b504d 100644 (file)
@@ -18,6 +18,9 @@
 // CLASS HEADER
 #include "image-load-thread.h"
 
 // CLASS HEADER
 #include "image-load-thread.h"
 
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/image-loading.h>
+
 namespace Dali
 {
 
 namespace Dali
 {
 
@@ -27,12 +30,24 @@ namespace Toolkit
 namespace Internal
 {
 
 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 )
 {
 ImageLoadThread::ImageLoadThread( EventThreadCallback* trigger )
 : mTrigger( trigger )
 {
@@ -52,7 +67,7 @@ void ImageLoadThread::Run()
 {
   while( LoadingTask* task = NextTaskToProcess() )
   {
 {
   while( LoadingTask* task = NextTaskToProcess() )
   {
-    task->loader.Load();
+    task->Load();
     AddCompletedTask( task );
   }
 }
     AddCompletedTask( task );
   }
 }
@@ -150,8 +165,6 @@ void ImageLoadThread::AddCompletedTask( LoadingTask* task )
   mTrigger->Trigger();
 }
 
   mTrigger->Trigger();
 }
 
-
-
 } // namespace Internal
 
 } // namespace Toolkit
 } // namespace Internal
 
 } // namespace Toolkit
index 85ea419..f46d435 100644 (file)
 // EXTERNAL INCLUDES
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/object/ref-object.h>
 // EXTERNAL INCLUDES
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/object/ref-object.h>
+#include <dali/public-api/images/image-operations.h>
+#include <dali/public-api/images/pixel-data.h>
 #include <dali/devel-api/threading/conditional-wait.h>
 #include <dali/devel-api/threading/mutex.h>
 #include <dali/devel-api/threading/thread.h>
 #include <dali/devel-api/threading/conditional-wait.h>
 #include <dali/devel-api/threading/mutex.h>
 #include <dali/devel-api/threading/thread.h>
-#include <dali/devel-api/adaptor-framework/bitmap-loader.h>
 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
 
 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
 
+
 namespace Dali
 {
 
 namespace Dali
 {
 
@@ -42,8 +44,20 @@ struct LoadingTask
 {
   /**
    * Constructor.
 {
   /**
    * 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:
 
 
 private:
 
@@ -55,8 +69,14 @@ private:
 
 public:
 
 
 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
+
 };
 
 
 };
 
 
index de489dc..7a8ab3c 100644 (file)
@@ -16,7 +16,7 @@
 
 // CLASS HEADER
 #include "sync-image-loader.h"
 
 // CLASS HEADER
 #include "sync-image-loader.h"
-#include <dali/devel-api/adaptor-framework/bitmap-loader.h>
+#include <dali/devel-api/adaptor-framework/image-loading.h>
 
 
 namespace Dali
 
 
 namespace Dali
@@ -45,12 +45,8 @@ PixelData Load( const std::string& url,
                 SamplingMode::Type samplingMode,
                 bool orientationCorrection )
 {
                 SamplingMode::Type samplingMode,
                 bool orientationCorrection )
 {
-  BitmapLoader loader = BitmapLoader::New( url, dimensions, fittingMode, samplingMode, orientationCorrection );
-
   // Load the image synchronously (block the thread here).
   // Load the image synchronously (block the thread here).
-  loader.Load();
-
-  return loader.GetPixelData();
+  return Dali::LoadImageFromFile( url, dimensions, fittingMode, samplingMode, orientationCorrection );
 }
 
 
 }