Merge "Temporarily disable viewport caching in GL context" into devel/master
[platform/core/uifw/dali-core.git] / dali / integration-api / bitmap.h
index 6319ae1..3058689 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTEGRATION_BITMAP_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,19 +39,17 @@ namespace Integration
  * @param[out] pixelDataType  pixel data type (eg. GL_UNSIGNED_BYTE)
  * @param[out] internalFormat pixel internal format (eg. GL_RGBA)
  */
-DALI_IMPORT_API void ConvertToGlFormat(Pixel::Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat);
+DALI_CORE_API void ConvertToGlFormat(Pixel::Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat);
 
 class Bitmap;
 typedef IntrusivePtr<Bitmap>    BitmapPtr;
-typedef unsigned char                 PixelBuffer;  ///< Pixel data buffers are composed of these
+typedef uint8_t                 PixelBuffer;  ///< Pixel data buffers are composed of these
 
 /**
  * Bitmap class.
  * An abstract container for image data.
- * \sa{BitmapPackedPixel BitmapCompressed BitmapExternal} for concrete
- * subclasses.
  */
-class DALI_IMPORT_API Bitmap : public Dali::RefObject
+class DALI_CORE_API Bitmap : public Dali::RefObject
 {
 protected:
 
@@ -70,8 +68,8 @@ protected:
    * @param[in] height        Image height in pixels
    */
   void Initialize(Pixel::Format pixelFormat,
-                           unsigned int width,
-                           unsigned int height);
+                           uint32_t width,
+                           uint32_t height);
 
 
 public:
@@ -88,6 +86,12 @@ 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
@@ -98,8 +102,6 @@ public:
    * 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.
-   * NOT_OWNED means that the data is managed by an external component and is
-   * guaranteed to remain dereferenceable at least as long as the Bitmap remains alive.
    */
   static Bitmap* New( Profile profile, ResourcePolicy::Discardable discardable );
 
@@ -111,7 +113,7 @@ public:
    * Get the width of the image
    * @return The width of the image
    */
-  unsigned int GetImageWidth() const
+  uint32_t GetImageWidth() const
   {
     return mImageWidth;
   }
@@ -120,7 +122,7 @@ public:
    * Get the height of the image
    * @return The height of the image
    */
-  unsigned int GetImageHeight() const
+  uint32_t GetImageHeight() const
   {
     return mImageHeight;
   }
@@ -146,11 +148,18 @@ 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
    */
-  virtual size_t GetBufferSize() const = 0;
+  virtual uint32_t GetBufferSize() const = 0;
 
   /**
    * Queries if the bitmap has an alpha channel
@@ -171,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
 
 
@@ -196,10 +211,10 @@ public:
      * @return pixel buffer pointer
      */
     virtual PixelBuffer* ReserveBuffer(Pixel::Format pixelFormat,
-                                       unsigned int width,
-                                       unsigned int height,
-                                       unsigned int bufferWidth = 0,
-                                       unsigned int bufferHeight = 0) = 0;
+                                       uint32_t width,
+                                       uint32_t height,
+                                       uint32_t bufferWidth = 0,
+                                       uint32_t bufferHeight = 0) = 0;
 
     /**
      * Assign a pixel buffer. Any previously allocated pixel buffer is deleted.
@@ -223,35 +238,42 @@ public:
      */
     virtual void AssignBuffer(Pixel::Format pixelFormat,
                               PixelBuffer* buffer,
-                              std::size_t bufferSize,
-                              unsigned int width,
-                              unsigned int height,
-                              unsigned int bufferWidth = 0,
-                              unsigned int bufferHeight = 0) = 0;
+                              uint32_t bufferSize,
+                              uint32_t width,
+                              uint32_t height,
+                              uint32_t bufferWidth = 0,
+                              uint32_t bufferHeight = 0) = 0;
     /**
      * Get the width of the buffer (stride)
      * @return The width of the buffer in pixels
      */
-    virtual unsigned int GetBufferWidth() const = 0;
+    virtual uint32_t GetBufferWidth() const = 0;
 
     /**
      * Get the height of the buffer
      * @return The height of the buffer in pixels
      */
-    virtual unsigned int GetBufferHeight() const = 0;
+    virtual uint32_t GetBufferHeight() const = 0;
 
     /**
      * Get the pixel buffer stride.
      * @return The buffer stride (in bytes) if this is bitmap of non-compressed
      * packed pixels for which a stride is meaningful or 0 otherwise.
      */
-    virtual unsigned int GetBufferStride() const = 0;
+    virtual uint32_t GetBufferStride() const = 0;
 
     /**
      * Check the bitmap data and test whether it has any transparent pixels.
      * This property can then be tested for with IsFullyOpaque().
      */
     virtual void TestForTransparency() = 0;
+
+  protected:
+
+    /**
+     * Virtual destructor, no deletion through this interface
+     */
+    virtual ~PackedPixelsProfile() {}
   };
 
   /**
@@ -288,7 +310,13 @@ public:
     virtual PixelBuffer* ReserveBufferOfSize( Pixel::Format pixelFormat,
                                        const unsigned width,
                                        const unsigned height,
-                                       const size_t numBytes ) = 0;
+                                       const uint32_t numBytes ) = 0;
+  protected:
+
+    /**
+     * Virtual destructor, no deletion through this interface
+     */
+    virtual ~CompressedProfile() {}
   };
 
   virtual const CompressedProfile* GetCompressedProfile() const { return 0; }
@@ -316,6 +344,8 @@ public:
    */
   void DeletePixelBuffer();
 
+protected:
+
   /**
    * A reference counted object may only be deleted by calling Unreference()
    */
@@ -323,8 +353,8 @@ public:
 
 protected:
 
-  unsigned int  mImageWidth;          ///< Image width in pixels
-  unsigned int  mImageHeight;         ///< Image height in pixels
+  uint32_t  mImageWidth;          ///< Image width in pixels
+  uint32_t  mImageHeight;         ///< Image height in pixels
   Pixel::Format mPixelFormat;         ///< Pixel format
   bool          mHasAlphaChannel;   ///< Whether the image has an alpha channel
   bool          mAlphaChannelUsed;  ///< Whether the alpha channel is used in case the image owns one.