Ensure synchronous buffer decode when using encoded buffer image. 92/46092/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 14 Aug 2015 13:49:02 +0000 (14:49 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 14 Aug 2015 15:57:18 +0000 (16:57 +0100)
Change-Id: Iaff725f9ee05c2c35d902849949389807689995f

automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp
automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h
dali/integration-api/platform-abstraction.h
dali/internal/event/images/encoded-buffer-image-impl.cpp

index f0ea225..0a89ecb 100644 (file)
@@ -122,6 +122,12 @@ Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously(
   return mResources.loadedResource;
 }
 
+Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
+{
+  mTrace.PushCall("DecodeBuffer", "");
+  return Integration::BitmapPtr();
+}
+
 /**
  * @copydoc PlatformAbstraction::CancelLoad()
  */
index 5428d97..e52e112 100644 (file)
@@ -105,9 +105,17 @@ public:
    */
   virtual void LoadResource(const Integration::ResourceRequest& request);
 
+  /**
+   * @copydoc PlatformAbstraction::LoadResourceSynchronously()
+   */
   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
 
   /**
+   * @copydoc PlatformAbstraction::DecodeBuffer()
+   */
+  virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
+
+  /**
    * @copydoc PlatformAbstraction::CancelLoad()
    */
   virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
index 3caac53..d86fc3c 100644 (file)
@@ -142,6 +142,16 @@ public:
   virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
 
   /**
+   * Decode a buffer of data synchronously.
+   * @param[in] resourceType The type of resource to load
+   * @param[in] buffer The decoded data
+   * @param[in] bufferSize The size of the buffer used by the decoded data.
+   *
+   * @return A pointer to the decoded buffer.
+   */
+  virtual BitmapPtr DecodeBuffer( const ResourceType& resourceType, uint8_t * buffer, size_t bufferSize ) = 0;
+
+  /**
    * Cancel an ongoing LoadResource() request.
    * Multi-threading note: this method will be called from the main thread only i.e. not
    * from within the Core::Render() method.
index b52f838..01f379f 100644 (file)
@@ -63,19 +63,19 @@ EncodedBufferImagePtr EncodedBufferImage::New( const uint8_t * const encodedImag
   memcpy( &(buffer->GetVector()[0]), encodedImage, encodedImageByteCount );
 
   // Get image size from buffer
-  const ImageDimensions expectedSize = Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( buffer, size, fittingMode, samplingMode, orientationCorrection );
+  Dali::Integration::PlatformAbstraction& platformAbstraction = Internal::ThreadLocalStorage::Get().GetPlatformAbstraction();
+  const ImageDimensions expectedSize = platformAbstraction.GetClosestImageSize( buffer, size, fittingMode, samplingMode, orientationCorrection );
   image->mWidth = (unsigned int) expectedSize.GetWidth();
   image->mHeight = (unsigned int) expectedSize.GetHeight();
 
-  ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
-  ResourceTicketPtr ticket = resourceClient.DecodeResource( resourceType, buffer );
-  if( ticket )
-  {
-    DALI_ASSERT_DEBUG( dynamic_cast<ImageTicket*>( ticket.Get() ) && "Resource ticket returned for image resource has to be an ImageTicket subclass.\n" );
-    ImageTicket * const imageTicket = static_cast<ImageTicket*>( ticket.Get() );
+  // Load the image synchronously
+  Integration::BitmapPtr bitmap = platformAbstraction.DecodeBuffer( resourceType, &(buffer->GetVector()[0]), encodedImageByteCount );
 
-    image->mTicket = imageTicket;
-    imageTicket->AddObserver( *image );
+  if( bitmap )
+  {
+    ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
+    image->mTicket = resourceClient.AddBitmapImage( bitmap.Get() );
+    image->mTicket->AddObserver( *image );
   }
 
   return image;