From 14f9e9bbf83a460236f25bc77f69cba357269828 Mon Sep 17 00:00:00 2001
From: Paul Wisbey
Date: Sat, 3 May 2014 12:27:56 +0100
Subject: [PATCH] Fix regression with BitmapImage (width/height variety)
[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
---
dali/integration-api/bitmap.cpp | 6 +++---
dali/integration-api/bitmap.h | 12 ++++++------
dali/internal/event/images/bitmap-external.cpp | 3 ++-
dali/internal/event/images/bitmap-external.h | 13 +++++++++++++
dali/internal/event/resources/resource-client.cpp | 16 ++++++++--------
5 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/dali/integration-api/bitmap.cpp b/dali/integration-api/bitmap.cpp
index 93dc10e..836c3be 100644
--- a/dali/integration-api/bitmap.cpp
+++ b/dali/integration-api/bitmap.cpp
@@ -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();
}
/**
diff --git a/dali/integration-api/bitmap.h b/dali/integration-api/bitmap.h
index d196f2d..870f54d 100644
--- a/dali/integration-api/bitmap.h
+++ b/dali/integration-api/bitmap.h
@@ -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
diff --git a/dali/internal/event/images/bitmap-external.cpp b/dali/internal/event/images/bitmap-external.cpp
index f2f30d4..89fdc4a 100644
--- a/dali/internal/event/images/bitmap-external.cpp
+++ b/dali/internal/event/images/bitmap-external.cpp
@@ -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;
diff --git a/dali/internal/event/images/bitmap-external.h b/dali/internal/event/images/bitmap-external.h
index 6121c86..53479cd 100644
--- a/dali/internal/event/images/bitmap-external.h
+++ b/dali/internal/event/images/bitmap-external.h
@@ -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
diff --git a/dali/internal/event/resources/resource-client.cpp b/dali/internal/event/resources/resource-client.cpp
index 98c898c..06105eb 100644
--- a/dali/internal/event/resources/resource-client.cpp
+++ b/dali/internal/event/resources/resource-client.cpp
@@ -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);
--
2.7.4