Allow to create EncodedImageBuffer by moved data 52/300852/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 3 Nov 2023 01:36:54 +0000 (10:36 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 3 Nov 2023 01:36:54 +0000 (10:36 +0900)
Change-Id: I9fa23b959bf8cd2c3c8c0ad5904dcb6c71dd83b4
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp
dali/internal/imaging/common/encoded-image-buffer-impl.cpp
dali/internal/imaging/common/encoded-image-buffer-impl.h
dali/public-api/adaptor-framework/encoded-image-buffer.cpp
dali/public-api/adaptor-framework/encoded-image-buffer.h

index 82bbfac..0b6351f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -74,6 +74,20 @@ int UtcDaliEncodedImageBufferNew02(void)
   END_TEST;
 }
 
+int UtcDaliEncodedImageBufferNew03(void)
+{
+  // invoke default handle constructor
+  EncodedImageBuffer buffer;
+
+  DALI_TEST_CHECK(!buffer);
+
+  // initialise handle by move operator
+  buffer = EncodedImageBuffer::New(std::move(tinybuffer()), Dali::EncodedImageBuffer::ImageType::ANIMATED_VECTOR_IMAGE);
+
+  DALI_TEST_CHECK(buffer);
+  END_TEST;
+}
+
 int UtcDaliEncodedImageBufferCopyConstructor(void)
 {
   EncodedImageBuffer buffer = EncodedImageBuffer::New(tinybuffer());
@@ -159,7 +173,6 @@ int UtcDaliEncodedImageBufferGetHash(void)
   END_TEST;
 }
 
-
 int UtcDaliEncodedImageBufferSetGetType(void)
 {
   EncodedImageBuffer buffer1 = EncodedImageBuffer::New(tinybuffer());
index 33c93d3..b579ccf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -32,6 +32,13 @@ EncodedImageBuffer::EncodedImageBuffer(const RawBufferType& buffer, ImageType ty
   mBufferHash = CalculateHash(mBuffer);
 }
 
+EncodedImageBuffer::EncodedImageBuffer(RawBufferType&& buffer, ImageType type)
+: mBuffer(std::move(buffer)),
+  mType(type)
+{
+  mBufferHash = CalculateHash(mBuffer);
+}
+
 EncodedImageBuffer::~EncodedImageBuffer()
 {
 }
@@ -43,6 +50,13 @@ IntrusivePtr<EncodedImageBuffer> EncodedImageBuffer::New(const RawBufferType& bu
   return internal;
 }
 
+IntrusivePtr<EncodedImageBuffer> EncodedImageBuffer::New(RawBufferType&& buffer, ImageType type)
+{
+  IntrusivePtr<EncodedImageBuffer> internal = new EncodedImageBuffer(std::move(buffer), type);
+
+  return internal;
+}
+
 const EncodedImageBuffer::RawBufferType& EncodedImageBuffer::GetRawBuffer() const
 {
   return mBuffer;
index f482325..671a495 100644 (file)
@@ -37,16 +37,14 @@ public:
   using ImageType     = Dali::EncodedImageBuffer::ImageType;
 
   /**
-   * Constructor
-   * @param[in] buffer The raw buffer of image.
-   * @param[in] type The type of image.
+   * @copydoc Dali::EncodedImageBuffer::New
    */
-  EncodedImageBuffer(const RawBufferType& buffer, ImageType type);
+  static IntrusivePtr<EncodedImageBuffer> New(const RawBufferType& buffer, ImageType type);
 
   /**
    * @copydoc Dali::EncodedImageBuffer::New
    */
-  static IntrusivePtr<EncodedImageBuffer> New(const RawBufferType& buffer, ImageType type);
+  static IntrusivePtr<EncodedImageBuffer> New(RawBufferType&& buffer, ImageType type);
 
   /**
    * @copydoc Dali::EncodedImageBuffer::GetRawBuffer
@@ -70,6 +68,20 @@ public:
 
 protected:
   /**
+   * Constructor
+   * @param[in] buffer The raw buffer of image.
+   * @param[in] type The type of image.
+   */
+  EncodedImageBuffer(const RawBufferType& buffer, ImageType type);
+
+  /**
+   * Constructor as moved buffer
+   * @param[in] buffer The raw buffer of image as moved.
+   * @param[in] type The type of image.
+   */
+  EncodedImageBuffer(RawBufferType&& buffer, ImageType type);
+
+  /**
    * Destructor
    */
   ~EncodedImageBuffer();
index 7710ce1..75695c9 100644 (file)
@@ -69,10 +69,21 @@ EncodedImageBuffer EncodedImageBuffer::New(const RawBufferType& buffer)
   return EncodedImageBuffer::New(buffer, ImageType::DEFAULT);
 }
 
+EncodedImageBuffer EncodedImageBuffer::New(RawBufferType&& buffer)
+{
+  return EncodedImageBuffer::New(std::move(buffer), ImageType::DEFAULT);
+}
+
 EncodedImageBuffer EncodedImageBuffer::New(const RawBufferType& buffer, ImageType type)
 {
   IntrusivePtr<Internal::EncodedImageBuffer> internal = Internal::EncodedImageBuffer::New(buffer, type);
   return EncodedImageBuffer(internal.Get());
 }
 
+EncodedImageBuffer EncodedImageBuffer::New(RawBufferType&& buffer, ImageType type)
+{
+  IntrusivePtr<Internal::EncodedImageBuffer> internal = Internal::EncodedImageBuffer::New(std::move(buffer), type);
+  return EncodedImageBuffer(internal.Get());
+}
+
 } // namespace Dali
index 31bec44..f972116 100644 (file)
@@ -50,7 +50,7 @@ public:
   enum class ImageType
   {
     REGULAR_IMAGE,
-    VECTOR_IMAGE, ///< svg format.
+    VECTOR_IMAGE,          ///< svg format.
     ANIMATED_VECTOR_IMAGE, ///< lottie format.
 
     DEFAULT = REGULAR_IMAGE,
@@ -67,6 +67,15 @@ public:
   static EncodedImageBuffer New(const RawBufferType& buffer);
 
   /**
+   * @brief Create a new EncodedImageBuffer. ImageType will be setted as DEFAULT.
+   *
+   * @SINCE_2_0.34
+   * @param [in] buffer The encoded raw buffer as moved
+   * @return A handle to a new EncodedImageBuffer.
+   */
+  static EncodedImageBuffer New(RawBufferType&& buffer);
+
+  /**
    * @brief Create a new EncodedImageBuffer with ImageType.
    *
    * @SINCE_2_2.51
@@ -77,6 +86,16 @@ public:
   static EncodedImageBuffer New(const RawBufferType& buffer, ImageType type);
 
   /**
+   * @brief Create a new EncodedImageBuffer with ImageType.
+   *
+   * @SINCE_2_2.51
+   * @param [in] buffer The encoded raw buffer as moved
+   * @param [in] type The type hint of encoded raw buffer
+   * @return A handle to a new EncodedImageBuffer.
+   */
+  static EncodedImageBuffer New(RawBufferType&& buffer, ImageType type);
+
+  /**
    * @brief Create an empty handle.
    *
    * @SINCE_2_0.34