Updates following the PixelData change
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-bitmap-loader.cpp
index 00c1204..1315e53 100644 (file)
  * limitations under the License.
  */
 
+// CLASS HEADER
+#include "toolkit-bitmap-loader.h"
+
+// EXTERNAL INCLUDES
 #include <dali/public-api/object/base-object.h>
-#include <dali/devel-api/adaptor-framework/bitmap-loader.h>
 #include <cstring>
+#include <semaphore.h>
 
 using namespace Dali;
 
 namespace Dali
 {
-class Adaptor;
+namespace
+{
+Dali::BitmapLoader gBitmapLoader;
+}
+
 
 namespace Internal
 {
@@ -49,6 +57,7 @@ public:
     mPixelData(),
     mUrl(url)
   {
+    sem_init( &mySemaphore, 0, 0 );
   }
 
   ~BitmapLoader(){}
@@ -59,10 +68,12 @@ public:
     unsigned char* buffer = static_cast<unsigned char*>(malloc(bufferSize));
     memset(buffer, 0, bufferSize);
 
-    mPixelData = PixelData::New( buffer, mSize.GetWidth(), mSize.GetHeight(), Pixel::RGBA8888, PixelData::FREE);
+    mPixelData = Dali::PixelData::New( buffer, mSize.GetWidth(), mSize.GetHeight(), Pixel::RGBA8888, Dali::PixelData::FREE);
+
+    sem_post( &mySemaphore );
   }
 
-  PixelDataPtr GetPixelData() const
+  Dali::PixelData GetPixelData() const
   {
     return mPixelData;
   }
@@ -77,9 +88,19 @@ public:
     return mPixelData ? true : false;
   }
 
+  void WaitForLoading()
+  {
+    if( mPixelData )
+    {
+      return;
+    }
+    sem_wait( &mySemaphore );
+  }
+
   ImageDimensions mSize;
-  PixelDataPtr mPixelData;
+  Dali::PixelData mPixelData;
   const std::string mUrl;
+  sem_t mySemaphore;
 };
 
 } // internal
@@ -101,7 +122,12 @@ inline const Internal::BitmapLoader& GetImplementation(const Dali::BitmapLoader&
 Dali::BitmapLoader Dali::BitmapLoader::New(std::string const&url, Dali::Uint16Pair size, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode, bool orientationCorrection)
 {
   IntrusivePtr<Internal::BitmapLoader> internal = Internal::BitmapLoader::New(url, size, fittingMode, samplingMode, orientationCorrection);
-  return BitmapLoader( internal.Get() );
+  gBitmapLoader = BitmapLoader(internal.Get());
+  return gBitmapLoader;
+}
+
+BitmapLoader::BitmapLoader()
+{
 }
 
 Dali::BitmapLoader::BitmapLoader(Dali::BitmapLoader const& handle)
@@ -115,11 +141,16 @@ Dali::BitmapLoader::BitmapLoader(Internal::BitmapLoader* internal)
 Dali::BitmapLoader::~BitmapLoader()
 {
 }
+BitmapLoader& BitmapLoader::operator=(const BitmapLoader& rhs)
+{
+  BaseHandle::operator=(rhs);
+  return *this;
+}
 void Dali::BitmapLoader::Load()
 {
   GetImplementation(*this).Load();
 }
-PixelDataPtr Dali::BitmapLoader::GetPixelData() const
+PixelData Dali::BitmapLoader::GetPixelData() const
 {
   return GetImplementation(*this).GetPixelData();
 }
@@ -131,5 +162,19 @@ bool Dali::BitmapLoader::IsLoaded()
 {
   return GetImplementation(*this).IsLoaded();
 }
+void Dali::BitmapLoader::WaitForLoading()
+{
+  GetImplementation(*this).WaitForLoading();
+}
+
+BitmapLoader Dali::BitmapLoader::GetLatestCreated()
+{
+  return gBitmapLoader;
+}
+
+void Dali::BitmapLoader::ResetLatestCreated()
+{
+  gBitmapLoader.Reset();
+}
 
 } // Dali