[Tizen] Add stride to PixelData 70/270470/2
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 3 Feb 2022 05:18:10 +0000 (14:18 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Mon, 14 Feb 2022 09:14:39 +0000 (18:14 +0900)
Change-Id: Ida564386962e1afed91d3f6805b5a14f446a6937

automated-tests/src/dali/utc-Dali-PixelData.cpp
dali/graphics-api/graphics-types.h
dali/internal/event/images/pixel-data-impl.cpp
dali/internal/event/images/pixel-data-impl.h
dali/internal/render/renderers/render-texture.cpp
dali/public-api/images/pixel-data.cpp
dali/public-api/images/pixel-data.h

index 419a4d5..bf80314 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 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.
@@ -58,6 +58,50 @@ int UtcDaliPixelData02(void)
   DALI_TEST_CHECK(pixelData);
   DALI_TEST_CHECK(pixelData.GetWidth() == width);
   DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetStride() == 0);
+  DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
+
+  END_TEST;
+}
+
+int UtcDaliPixelData03(void)
+{
+  TestApplication application;
+
+  uint32_t width      = 10u;
+  uint32_t height     = 10u;
+  uint32_t stride     = 12u;
+  uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
+
+  uint8_t*  buffer    = reinterpret_cast<uint8_t*>(malloc(bufferSize));
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::RGB888, PixelData::FREE);
+
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_CHECK(pixelData.GetWidth() == width);
+  DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetStride() == stride);
+  DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
+
+  END_TEST;
+}
+
+int UtcDaliPixelData04(void)
+{
+  TestApplication application;
+
+  uint32_t width      = 10u;
+  uint32_t height     = 10u;
+  uint32_t stride     = 12u;
+  uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  uint8_t* buffer     = new uint8_t[bufferSize];
+  buffer[0]           = 'a';
+
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
+
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_CHECK(pixelData.GetWidth() == width);
+  DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetStride() == stride);
   DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
 
   END_TEST;
index 55816f5..84f0fd3 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_API_TYPES
 
 /*
- * Copyright (c) 2021 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.
@@ -943,6 +943,7 @@ struct TextureUpdateInfo
   Extent2D srcExtent2D{};
   uint32_t srcOffset{};
   uint32_t srcSize{};
+  uint32_t srcStride{};
   Format   srcFormat{}; ///< Should match dstTexture's format, otherwise conversion may occur
 };
 
index 23a1e1c..622f867 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 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.
@@ -26,12 +26,14 @@ 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)
 {
@@ -56,10 +58,11 @@ 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);
 }
 
 uint32_t PixelData::GetWidth() const
@@ -94,6 +97,11 @@ DevelPixelData::PixelDataBuffer PixelData::ReleaseBuffer()
   return pixelDataBuffer;
 }
 
+uint32_t PixelData::GetStride() const
+{
+  return mStride;
+}
+
 } // namespace Internal
 
 } // namespace Dali
index bac08db..5667496 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_PIXEL_DATA_H
 
 /*
- * Copyright (c) 2021 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.
@@ -40,6 +40,7 @@ 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.
    */
@@ -47,6 +48,7 @@ public:
                           uint32_t                         bufferSize,
                           uint32_t                         width,
                           uint32_t                         height,
+                          uint32_t                         stride,
                           Pixel::Format                    pixelFormat,
                           Dali::PixelData::ReleaseFunction releaseFunction);
 
@@ -57,6 +59,7 @@ 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.
    */
@@ -64,6 +67,7 @@ public:
             uint32_t                         bufferSize,
             uint32_t                         width,
             uint32_t                         height,
+            uint32_t                         stride,
             Pixel::Format                    pixelFormat,
             Dali::PixelData::ReleaseFunction releaseFunction);
 
@@ -112,6 +116,11 @@ public:
    */
   DevelPixelData::PixelDataBuffer ReleaseBuffer();
 
+  /**
+   * @copydoc PixelData::GetStride()
+   */
+  uint32_t GetStride() const;
+
 private:
   /*
    * Undefined copy constructor.
@@ -125,9 +134,10 @@ private:
 
 private:
   uint8_t*                         mBuffer;          ///< The raw pixel data
-  uint32_t                         mBufferSize;      ///< Buffer sized in bytes
+  uint32_t                         mBufferSize;      ///< Buffer size in bytes
   uint32_t                         mWidth;           ///< Buffer width in pixels
   uint32_t                         mHeight;          ///< Buffer height in pixels
+  uint32_t                         mStride;          ///< Buffer stride in pixels, 0 means the buffer is tightly packed
   Pixel::Format                    mPixelFormat;     ///< Pixel format
   Dali::PixelData::ReleaseFunction mReleaseFunction; ///< Function for releasing memory
 };
index e0f2c1b..13bffdd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 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.
@@ -289,6 +289,7 @@ void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadPara
   info.srcExtent2D  = {params.width, params.height};
   info.srcOffset    = 0;
   info.srcSize      = pixelData->GetBufferSize();
+  info.srcStride    = pixelData->GetStride();
   info.srcFormat    = ConvertPixelFormat(pixelData->GetPixelFormat());
 
   Graphics::TextureUpdateSourceInfo updateSourceInfo{};
index 7086e7d..2356c4b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 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.
@@ -30,7 +30,19 @@ PixelData PixelData::New(uint8_t*        buffer,
                          Pixel::Format   pixelFormat,
                          ReleaseFunction releaseFunction)
 {
-  IntrusivePtr<Internal::PixelData> internal = Internal::PixelData::New(buffer, bufferSize, width, height, pixelFormat, releaseFunction);
+  IntrusivePtr<Internal::PixelData> internal = Internal::PixelData::New(buffer, bufferSize, width, height, 0, pixelFormat, releaseFunction);
+  return PixelData(internal.Get());
+}
+
+PixelData PixelData::New(uint8_t*        buffer,
+                         uint32_t        bufferSize,
+                         uint32_t        width,
+                         uint32_t        height,
+                         uint32_t        stride,
+                         Pixel::Format   pixelFormat,
+                         ReleaseFunction releaseFunction)
+{
+  IntrusivePtr<Internal::PixelData> internal = Internal::PixelData::New(buffer, bufferSize, width, height, stride, pixelFormat, releaseFunction);
   return PixelData(internal.Get());
 }
 
@@ -66,4 +78,9 @@ Pixel::Format PixelData::GetPixelFormat() const
   return GetImplementation(*this).GetPixelFormat();
 }
 
+uint32_t PixelData::GetStride() const
+{
+  return GetImplementation(*this).GetStride();
+}
+
 } // namespace Dali
index 03fefc6..af3a7c2 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_PIXEL_DATA_H
 
 /*
- * Copyright (c) 2020 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.
@@ -77,6 +77,25 @@ public:
                        ReleaseFunction releaseFunction);
 
   /**
+   * @brief Creates a PixelData object.
+   *
+   * @param[in] buffer          The raw pixel data
+   * @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
+   * @return A handle to the PixelData
+   */
+  static PixelData New(uint8_t*        buffer,
+                       uint32_t        bufferSize,
+                       uint32_t        width,
+                       uint32_t        height,
+                       uint32_t        stride,
+                       Pixel::Format   pixelFormat,
+                       ReleaseFunction releaseFunction);
+  /**
    * @brief Creates an empty handle.
    * Use PixelData::New() to create an initialized object.
    *
@@ -149,6 +168,13 @@ public:
    */
   Pixel::Format GetPixelFormat() 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;
+
 public:
   /**
    * @brief The constructor.