Make PixelData flag that we release buffer after texture upload
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / pixel-buffer-impl.h
index 47c478c..d9898bf 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/integration-api/debug.h>
 #include <dali/public-api/images/image-operations.h> // For ImageDimensions
 #include <dali/public-api/images/pixel-data.h>
 #include <dali/public-api/object/base-object.h>
@@ -49,8 +50,8 @@ public:
    * @param [in] height           Buffer height in pixels
    * @param [in] pixelFormat      The pixel format
    */
-  static PixelBufferPtr New(unsigned int  width,
-                            unsigned int  height,
+  static PixelBufferPtr New(uint32_t      width,
+                            uint32_t      height,
                             Pixel::Format pixelFormat);
 
   /**
@@ -60,23 +61,25 @@ public:
    * @param [in] bufferSize       The size of the buffer in bytes
    * @param [in] width            Buffer width in pixels
    * @param [in] height           Buffer height in pixels
+   * @param [in] stride           Buffer stride in pixels, 0 means the buffer is tightly packed
    * @param [in] pixelFormat      The pixel format
-   * @param [in] releaseFunction  The function used to release the memory.
    */
-  static PixelBufferPtr New(unsigned char* buffer,
-                            unsigned int   bufferSize,
-                            unsigned int   width,
-                            unsigned int   height,
-                            Pixel::Format  pixelFormat);
+  static PixelBufferPtr New(uint8_t*      buffer,
+                            uint32_t      bufferSize,
+                            uint32_t      width,
+                            uint32_t      height,
+                            uint32_t      stride,
+                            Pixel::Format pixelFormat);
 
   /**
    * Convert a pixelBuffer object into a PixelData object.
    * The new object takes ownership of the buffer data, and the
    * mBuffer pointer is reset to NULL.
    * @param[in] pixelBuffer The buffer to convert
+   * @param[in] releaseAfterUpload Whether converted PixelData released after upload or not.
    * @return the pixelData
    */
-  static Dali::PixelData Convert(PixelBuffer& pixelBuffer);
+  static Dali::PixelData Convert(PixelBuffer& pixelBuffer, bool releaseAfterUpload);
 
   /**
    * @brief Constructor.
@@ -85,13 +88,15 @@ public:
    * @param [in] bufferSize       The size of the buffer in bytes
    * @param [in] width            Buffer width in pixels
    * @param [in] height           Buffer height in pixels
+   * @param [in] stride           Buffer stride in pixels, 0 means the buffer is tightly packed
    * @param [in] pixelFormat      The pixel format
    */
-  PixelBuffer(unsigned char* buffer,
-              unsigned int   bufferSize,
-              unsigned int   width,
-              unsigned int   height,
-              Pixel::Format  pixelFormat);
+  PixelBuffer(uint8_t*      buffer,
+              uint32_t      bufferSize,
+              uint32_t      width,
+              uint32_t      height,
+              uint32_t      stride,
+              Pixel::Format pixelFormat);
 
 protected:
   /**
@@ -103,16 +108,34 @@ protected:
 
 public:
   /**
+   * Get the total allocated size of current pixel buffers
+   */
+  static uint32_t GetTotalAllocatedSize()
+  {
+#if defined(DEBUG_ENABLED)
+    return gPixelBufferAllocationTotal;
+#else
+    return 0;
+#endif
+  }
+
+  /**
    * Get the width of the buffer in pixels.
    * @return The width of the buffer in pixels
    */
-  unsigned int GetWidth() const;
+  uint32_t GetWidth() const;
 
   /**
    * Get the height of the buffer in pixels
    * @return The height of the buffer in pixels
    */
-  unsigned int GetHeight() const;
+  uint32_t GetHeight() const;
+
+  /**
+   * @brief Gets the stride of the buffer in pixels.
+   * @return The stride of the buffer in pixels. 0 means the buffer is tightly packed.
+   */
+  uint32_t GetStride() const;
 
   /**
    * Get the pixel format
@@ -124,18 +147,18 @@ public:
    * Get the pixel buffer if it's present.
    * @return The buffer if exists, or NULL if there is no pixel buffer.
    */
-  unsigned char* GetBuffer() const;
+  uint8_t* GetBuffer() const;
 
   /**
    * @copydoc Devel::PixelBuffer::GetBuffer()
    */
-  const unsigned char* const GetConstBuffer() const;
+  const uint8_t* GetConstBuffer() const;
 
   /**
    * Get the size of the buffer in bytes
    * @return The size of the buffer
    */
-  unsigned int GetBufferSize() const;
+  uint32_t GetBufferSize() const;
 
   /**
    * Copy the buffer into a new PixelData
@@ -221,6 +244,11 @@ public:
    */
   bool IsAlphaPreMultiplied() const;
 
+  /**
+   * @copydoc Devel::PixelBuffer::GetBrightness()
+   */
+  uint32_t GetBrightness() const;
+
 private:
   /*
    * Undefined copy constructor.
@@ -276,12 +304,17 @@ private:
 
 private:
   std::unique_ptr<Property::Map> mMetadata;      ///< Metadata fields
-  unsigned char*                 mBuffer;        ///< The raw pixel data
-  unsigned int                   mBufferSize;    ///< Buffer sized in bytes
-  unsigned int                   mWidth;         ///< Buffer width in pixels
-  unsigned int                   mHeight;        ///< Buffer height in pixels
+  uint8_t*                       mBuffer;        ///< The raw pixel data
+  uint32_t                       mBufferSize;    ///< Buffer sized in bytes
+  uint32_t                       mWidth;         ///< Buffer width in pixels
+  uint32_t                       mHeight;        ///< Buffer height in pixels
+  uint32_t                       mStride;        ///< Buffer stride in bytes, 0 means the buffer is tightly packed
   Pixel::Format                  mPixelFormat;   ///< Pixel format
   bool                           mPreMultiplied; ///< PreMultiplied
+
+#if defined(DEBUG_ENABLED)
+  static uint32_t gPixelBufferAllocationTotal;
+#endif
 };
 
 } // namespace Adaptor