Move MultiplyColorByAlpha() from main thread to resource thread
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / image-load-thread.cpp
index 11e251a..320911d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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 "image-load-thread.h"
 
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/image-loading.h>
+#include <dali/integration-api/adaptors/adaptor.h>
+#include <dali/devel-api/adaptor-framework/thread-settings.h>
+
 namespace Dali
 {
 
@@ -27,14 +32,43 @@ namespace Toolkit
 namespace Internal
 {
 
-LoadingTask::LoadingTask(uint32_t id, BitmapLoader loader )
-: loader( loader ),
-  id( id )
+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 )
 {
 }
 
+void LoadingTask::Load()
+{
+  if( url.IsLocalResource() )
+  {
+    pixelBuffer = Dali::LoadImageFromFile( url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection );
+  }
+  else
+  {
+    pixelBuffer = Dali::DownloadImageSynchronously ( url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection );
+  }
+
+  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() )
 {
 }
 
@@ -50,9 +84,12 @@ ImageLoadThread::~ImageLoadThread()
 
 void ImageLoadThread::Run()
 {
+  SetThreadName( "ImageLoadThread" );
+  mLogFactory.InstallLogFunction();
+
   while( LoadingTask* task = NextTaskToProcess() )
   {
-    task->loader.Load();
+    task->Load();
     AddCompletedTask( task );
   }
 }
@@ -150,8 +187,6 @@ void ImageLoadThread::AddCompletedTask( LoadingTask* task )
   mTrigger->Trigger();
 }
 
-
-
 } // namespace Internal
 
 } // namespace Toolkit