From d0978117392878f7e82bf6601be1cd2c5c24dc83 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Fri, 3 Nov 2023 10:36:54 +0900 Subject: [PATCH] Allow to create EncodedImageBuffer by moved data Change-Id: I9fa23b959bf8cd2c3c8c0ad5904dcb6c71dd83b4 Signed-off-by: Eunki, Hong --- .../dali-adaptor/utc-Dali-EncodedImageBuffer.cpp | 17 +++++++++++++++-- .../imaging/common/encoded-image-buffer-impl.cpp | 16 +++++++++++++++- .../imaging/common/encoded-image-buffer-impl.h | 22 +++++++++++++++++----- .../adaptor-framework/encoded-image-buffer.cpp | 11 +++++++++++ .../adaptor-framework/encoded-image-buffer.h | 21 ++++++++++++++++++++- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp b/automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp index 82bbfac..0b6351f 100644 --- a/automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp +++ b/automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp @@ -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()); diff --git a/dali/internal/imaging/common/encoded-image-buffer-impl.cpp b/dali/internal/imaging/common/encoded-image-buffer-impl.cpp index 33c93d3..b579ccf 100644 --- a/dali/internal/imaging/common/encoded-image-buffer-impl.cpp +++ b/dali/internal/imaging/common/encoded-image-buffer-impl.cpp @@ -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::New(const RawBufferType& bu return internal; } +IntrusivePtr EncodedImageBuffer::New(RawBufferType&& buffer, ImageType type) +{ + IntrusivePtr internal = new EncodedImageBuffer(std::move(buffer), type); + + return internal; +} + const EncodedImageBuffer::RawBufferType& EncodedImageBuffer::GetRawBuffer() const { return mBuffer; diff --git a/dali/internal/imaging/common/encoded-image-buffer-impl.h b/dali/internal/imaging/common/encoded-image-buffer-impl.h index f482325..671a495 100644 --- a/dali/internal/imaging/common/encoded-image-buffer-impl.h +++ b/dali/internal/imaging/common/encoded-image-buffer-impl.h @@ -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 New(const RawBufferType& buffer, ImageType type); /** * @copydoc Dali::EncodedImageBuffer::New */ - static IntrusivePtr New(const RawBufferType& buffer, ImageType type); + static IntrusivePtr 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(); diff --git a/dali/public-api/adaptor-framework/encoded-image-buffer.cpp b/dali/public-api/adaptor-framework/encoded-image-buffer.cpp index 7710ce1..75695c9 100644 --- a/dali/public-api/adaptor-framework/encoded-image-buffer.cpp +++ b/dali/public-api/adaptor-framework/encoded-image-buffer.cpp @@ -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 = Internal::EncodedImageBuffer::New(buffer, type); return EncodedImageBuffer(internal.Get()); } +EncodedImageBuffer EncodedImageBuffer::New(RawBufferType&& buffer, ImageType type) +{ + IntrusivePtr internal = Internal::EncodedImageBuffer::New(std::move(buffer), type); + return EncodedImageBuffer(internal.Get()); +} + } // namespace Dali diff --git a/dali/public-api/adaptor-framework/encoded-image-buffer.h b/dali/public-api/adaptor-framework/encoded-image-buffer.h index 31bec44..f972116 100644 --- a/dali/public-api/adaptor-framework/encoded-image-buffer.h +++ b/dali/public-api/adaptor-framework/encoded-image-buffer.h @@ -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 -- 2.7.4