Merge "Added memory pool logging" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / images / pixel-data-impl.cpp
index 44a7e1d..745896a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
 // CLASS HEADER
 #include <dali/internal/event/images/pixel-data-impl.h>
 
-// EXTERNAL INCLUDES
-#include <stdlib.h>
+#include <dali/integration-api/debug.h>
+
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gPixelDataLogFilter = Debug::Filter::New(Debug::NoLogging, false, "DALI_LOG_PIXEL_DATA_SIZE");
+#endif
 
 namespace Dali
 {
-
 namespace Internal
 {
+#if defined(DEBUG_ENABLED)
+// Only track data allocation if debug is enabled
+uint32_t PixelData::gPixelDataAllocationTotal{0};
+#endif
 
-PixelData::PixelData( unsigned char* buffer,
-                      unsigned int bufferSize,
-                      unsigned int width,
-                      unsigned int height,
-                      Pixel::Format pixelFormat,
-                      Dali::PixelData::ReleaseFunction releaseFunction )
-: mBuffer( buffer ),
-  mBufferSize( bufferSize ),
-  mWidth( width ),
-  mHeight( height ),
-  mPixelFormat( pixelFormat ),
-  mReleaseFunction( releaseFunction )
+PixelData::PixelData(uint8_t*                         buffer,
+                     uint32_t                         bufferSize,
+                     uint32_t                         width,
+                     uint32_t                         height,
+                     uint32_t                         stride,
+                     Pixel::Format                    pixelFormat,
+                     Dali::PixelData::ReleaseFunction releaseFunction)
+: mBuffer(buffer),
+  mBufferSize(bufferSize),
+  mWidth(width),
+  mHeight(height),
+  mStride(stride),
+  mPixelFormat(pixelFormat),
+  mReleaseFunction(releaseFunction)
 {
+  DALI_LOG_INFO(gPixelDataLogFilter, Debug::Concise, "Allocated PixelData of size %u\n", bufferSize);
+#if defined(DEBUG_ENABLED)
+  gPixelDataAllocationTotal += mBufferSize;
+#endif
 }
 
 PixelData::~PixelData()
 {
-  if( mBuffer )
+  if(mBuffer)
   {
-    if( mReleaseFunction == Dali::PixelData::FREE)
+    if(mReleaseFunction == Dali::PixelData::FREE)
     {
-      free( mBuffer );
+      free(mBuffer);
     }
     else
     {
       delete[] mBuffer;
     }
+#if defined(DEBUG_ENABLED)
+    gPixelDataAllocationTotal -= mBufferSize;
+#endif
   }
- }
+}
 
-PixelDataPtr PixelData::New(unsigned char* buffer,
-                            unsigned int bufferSize,
-                            unsigned int width,
-                            unsigned int height,
-                            Pixel::Format pixelFormat,
+PixelDataPtr PixelData::New(uint8_t*                         buffer,
+                            uint32_t                         bufferSize,
+                            uint32_t                         width,
+                            uint32_t                         height,
+                            uint32_t                         stride,
+                            Pixel::Format                    pixelFormat,
                             Dali::PixelData::ReleaseFunction releaseFunction)
 {
-  return new PixelData( buffer, bufferSize, width, height, pixelFormat, releaseFunction );
+  return new PixelData(buffer, bufferSize, width, height, stride, pixelFormat, releaseFunction);
 }
 
-unsigned int PixelData::GetWidth() const
+uint32_t PixelData::GetWidth() const
 {
   return mWidth;
 }
 
-unsigned int PixelData::GetHeight() const
+uint32_t PixelData::GetHeight() const
 {
   return mHeight;
 }
@@ -82,16 +98,28 @@ Pixel::Format PixelData::GetPixelFormat() const
   return mPixelFormat;
 }
 
-unsigned char* PixelData::GetBuffer() const
+uint8_t* PixelData::GetBuffer() const
 {
   return mBuffer;
 }
 
-unsigned int PixelData::GetBufferSize() const
+uint32_t PixelData::GetBufferSize() const
 {
   return mBufferSize;
 }
 
-}// namespace Internal
+DevelPixelData::PixelDataBuffer PixelData::ReleaseBuffer()
+{
+  DevelPixelData::PixelDataBuffer pixelDataBuffer(mBuffer, mBufferSize, mReleaseFunction);
+  mBuffer = nullptr;
+  return pixelDataBuffer;
+}
+
+uint32_t PixelData::GetStride() const
+{
+  return mStride;
+}
+
+} // namespace Internal
 
-}// namespace Dali
+} // namespace Dali