Fix regression with BitmapImage (width/height variety) 20/20620/1
authorPaul Wisbey <p.wisbey@samsung.com>
Sat, 3 May 2014 11:27:56 +0000 (12:27 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Fri, 9 May 2014 13:59:45 +0000 (14:59 +0100)
[Issue#] N/A
[Problem] Pointer returned by BitmapImage::GetBuffer() is invalid. This only
affects the variety of BitmapImage where the data is allocated by ResourceClient.
[Cause] Regression from "[SRUK] Compressed Texture Support for Dali Core"
[Solution] Partial rollback  of BitmapExternal, Integration::Bitmap etc.

Change-Id: I3480e935ce908c1ced6cd57f0df87f6072292e3b
Signed-off-by: Ferran Sole <ferran.sole@samsung.com>
dali/integration-api/bitmap.cpp
dali/integration-api/bitmap.h
dali/internal/event/images/bitmap-external.cpp
dali/internal/event/images/bitmap-external.h
dali/internal/event/resources/resource-client.cpp

index 93dc10e..836c3be 100644 (file)
@@ -272,13 +272,13 @@ Bitmap::Bitmap( bool discardable, Dali::Integration::PixelBuffer* pixBuf)
   mHasAlphaChannel(true),
   mAlphaChannelUsed(true),
   mData(pixBuf),
-  mDataIsOwned(discardable)
+  mDiscardable(discardable)
 {
 }
 
 void Bitmap::DiscardBuffer()
 {
-  if ( mDataIsOwned )
+  if ( mDiscardable )
   {
     DeletePixelBuffer();
   }
@@ -297,7 +297,7 @@ PixelBuffer* Bitmap::ReleaseBuffer()
 Bitmap::~Bitmap()
 {
   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
-  DiscardBuffer();
+  DeletePixelBuffer();
 }
 
 /**
index d196f2d..870f54d 100644 (file)
@@ -298,12 +298,12 @@ public:
   void DiscardBuffer();
 
   /**
-   * @return True if the buffer of pixel data is owned by this Bitmap itself,
-   * or false if the buffer is owned by an external component.
-   **/
-  bool BufferIsOwned() const
+   * Check if the pixel buffer can be discarded
+   * @return true if the pixel buffer can be discarded
+   */
+  bool IsDiscardable() const
   {
-    return mDataIsOwned;
+    return mDiscardable;
   }
 
  /**
@@ -333,7 +333,7 @@ protected:
 
 private:
 
-  bool          mDataIsOwned;     ///< Should delete the buffer when discard buffer is called.
+  bool mDiscardable; ///< Should delete the buffer when discard buffer is called.
 
   Bitmap(const Bitmap& other);  ///< defined private to prevent use
   Bitmap& operator = (const Bitmap& other); ///< defined private to prevent use
index f2f30d4..89fdc4a 100644 (file)
@@ -33,7 +33,8 @@ BitmapExternal::BitmapExternal(Dali::Integration::PixelBuffer* pixBuf,
                Pixel::Format pixelFormat,
                unsigned int bufferWidth,
                unsigned int bufferHeight)
-: BitmapPackedPixel(false, pixBuf)
+: BitmapPackedPixel(false, NULL/*pixBuf is externally owned*/),
+  mExternalData(pixBuf)
 {
   mImageWidth   = width;
   mImageHeight  = height;
index 6121c86..53479cd 100644 (file)
@@ -70,6 +70,15 @@ public:
     return NULL;
   }
 
+  /**
+   * Get the pixel buffer
+   * @return The buffer. You can modify its contents.
+   */
+  virtual Dali::Integration::PixelBuffer* GetBuffer()
+  {
+    return mExternalData;
+  }
+
 protected:
   /**
    * A reference counted object may only be deleted by calling Unreference()
@@ -77,6 +86,10 @@ protected:
   virtual ~BitmapExternal();
 
 private:
+
+  Dali::Integration::PixelBuffer* mExternalData; ///< Externally owned pixel data
+
+private:
   BitmapExternal();  ///< defined private to prevent use
   BitmapExternal(const BitmapExternal& other);  ///< defined private to prevent use
   BitmapExternal& operator = (const BitmapExternal& other); ///< defined private to prevent use
index 98c898c..06105eb 100644 (file)
@@ -264,14 +264,14 @@ ResourceTicketPtr ResourceClient::RequestResourceTicket( ResourceId id )
   return ticket;
 }
 
-ImageTicketPtr ResourceClient::AllocateBitmapImage ( unsigned int width,
-                                                     unsigned int height,
-                                                     unsigned int bufferWidth,
-                                                     unsigned int bufferHeight,
-                                                     Pixel::Format pixelformat )
-{
-  Bitmap * const bitmap = Bitmap::New(Bitmap::BITMAP_2D_PACKED_PIXELS, true); ///< Not exception safe.
-  Bitmap::PackedPixelsProfile * const packedBitmap = bitmap->GetPackedPixelsProfile();
+ImageTicketPtr ResourceClient::AllocateBitmapImage( unsigned int width,
+                                                    unsigned int height,
+                                                    unsigned int bufferWidth,
+                                                    unsigned int bufferHeight,
+                                                    Pixel::Format pixelformat )
+{
+  Bitmap* const bitmap = Bitmap::New( Bitmap::BITMAP_2D_PACKED_PIXELS, false/*buffer is available via public-api, therefore not discardable*/ );
+  Bitmap::PackedPixelsProfile* const packedBitmap = bitmap->GetPackedPixelsProfile();
   DALI_ASSERT_DEBUG(packedBitmap);
 
   packedBitmap->ReserveBuffer(pixelformat, width, height, bufferWidth, bufferHeight);