Enable -Wnon-virtual-dtor to avoid incorrect C++ code sneaking in
[platform/core/uifw/dali-core.git] / dali / integration-api / bitmap.h
index 977fb1e..1e1b9bc 100644 (file)
@@ -48,8 +48,6 @@ typedef unsigned char                 PixelBuffer;  ///< Pixel data buffers are
 /**
  * Bitmap class.
  * An abstract container for image data.
- * \sa{BitmapPackedPixel BitmapCompressed BitmapExternal} for concrete
- * subclasses.
  */
 class DALI_IMPORT_API Bitmap : public Dali::RefObject
 {
@@ -61,7 +59,7 @@ protected:
    * @param[in] discardable Flag to tell the bitmap if it can delete the buffer with the pixel data.
    * @param[in] pixBuf External buffer of pixel data or null.
    */
-  Bitmap( ResourcePolicy::Discardable discardable = ResourcePolicy::RETAIN, Dali::Integration::PixelBuffer* pixBuf = 0 );
+  Bitmap( ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_RETAIN, Dali::Integration::PixelBuffer* pixBuf = 0 );
 
   /**
    * Initializes internal class members
@@ -88,18 +86,23 @@ public:
     BITMAP_COMPRESSED
   };
 
+  enum ReleaseFunction
+  {
+    FREE,          ///< Use free function to release the buffer
+    DELETE_ARRAY,  ///< Use delete[] operator to release the buffer
+  };
+
   /**
    * Create a new instance of a Bitmap with the required profile.
    * @return Pointer to created Bitmap subclass. Clients should immediately
    * wrap this in a reference-counting smart pointer or store it in a similarly
    * automatic owning collection.
    * @param[in] profile Defines required features of the bitmap (\sa Profile).
-   * @param[in] discardable If this is set to DISCARD, the bitmap
-   * object owns it's own buffer of pixel data and can delete it. If
-   * it's set to RETAIN, then the lifetime of the pixel buffer is
-   * managed by an external component and is guaranteed to remain
-   * dereferenceable at least as long as the Bitmap remains alive.
-   **/
+   * @param[in] discardable OWNED_DISCARD means that the data is owned by bitmap,
+   * and may released away after uploading to GPU.
+   * OWNED_RETAIN means that the data is owned and must be kept in CPU memory
+   * e.g. for an image that cannot be reloaded from disk.
+   */
   static Bitmap* New( Profile profile, ResourcePolicy::Discardable discardable );
 
   /** \name GeneralFeatures
@@ -145,6 +148,13 @@ public:
   }
 
   /**
+   * Get the pixel buffer if it's present and take over the ownership.
+   * @note With this function called, the bitmap loses the ownership and is no longer responsible for the release of pixel buffer.
+   * @return The raw pointer pointing to the pixel buffer
+   */
+  PixelBuffer* GetBufferOwnership();
+
+  /**
    * Get the pixel buffer size in bytes
    * @return The buffer size in bytes.
    * @sa ReserveBuffer GetBuffer
@@ -170,6 +180,12 @@ public:
     return !(HasAlphaChannel() && mAlphaChannelUsed);
   }
 
+  /**
+   * Returns which release function has to be called to release the data in the bitmap
+   * @return FREE if memory has been allocated with malloc DELETE_ARRAY if memory has been allocated with new
+   */
+  virtual ReleaseFunction GetReleaseFunction() = 0;
+
   /**@}*/ ///< End of generic features
 
 
@@ -251,6 +267,13 @@ public:
      * This property can then be tested for with IsFullyOpaque().
      */
     virtual void TestForTransparency() = 0;
+
+  protected:
+
+    /**
+     * Virtual destructor, no deletion through this interface
+     */
+    virtual ~PackedPixelsProfile() {}
   };
 
   /**
@@ -288,6 +311,12 @@ public:
                                        const unsigned width,
                                        const unsigned height,
                                        const size_t numBytes ) = 0;
+  protected:
+
+    /**
+     * Virtual destructor, no deletion through this interface
+     */
+    virtual ~CompressedProfile() {}
   };
 
   virtual const CompressedProfile* GetCompressedProfile() const { return 0; }
@@ -307,20 +336,16 @@ public:
    */
   bool IsDiscardable() const
   {
-    return mDiscardable == ResourcePolicy::DISCARD;
+    return mDiscardable == ResourcePolicy::OWNED_DISCARD;
   }
 
- /**
-   * Transfer ownership of the pixel buffer to the calling function.
-   * @post bitmaps pixel data is set to NULL
-   * @return the bitmaps pixel buffer
-   */
-  PixelBuffer* ReleaseBuffer();
   /**
    * Delete the pixel buffer data
    */
   void DeletePixelBuffer();
 
+protected:
+
   /**
    * A reference counted object may only be deleted by calling Unreference()
    */