From 9eed8b79466caf1505ea0ea49b04e3b54db04383 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Fri, 18 Jun 2021 13:41:11 +0900 Subject: [PATCH] Add class for encoded image buffer Add class for encoded image buffer We can use it for - AnimatedImageLoading - VectorImageRendererPlugin - VectorAnimationRendererPlugin These things may need to fix and sync a lot of codes. So we only make new class Change-Id: I148730de6cbddaabb2bb889520e8643bf3ee5599 Signed-off-by: Eunki, Hong --- automated-tests/src/dali-adaptor/CMakeLists.txt | 1 + .../dali-adaptor/utc-Dali-EncodedImageBuffer.cpp | 104 +++++++++++++++++++++ .../imaging/common/encoded-image-buffer-impl.cpp | 49 ++++++++++ .../imaging/common/encoded-image-buffer-impl.h | 93 ++++++++++++++++++ dali/internal/imaging/file.list | 1 + .../adaptor-framework/encoded-image-buffer.cpp | 61 ++++++++++++ .../adaptor-framework/encoded-image-buffer.h | 96 +++++++++++++++++++ dali/public-api/file.list | 2 + 8 files changed, 407 insertions(+) create mode 100644 automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp create mode 100644 dali/internal/imaging/common/encoded-image-buffer-impl.cpp create mode 100644 dali/internal/imaging/common/encoded-image-buffer-impl.h create mode 100644 dali/public-api/adaptor-framework/encoded-image-buffer.cpp create mode 100644 dali/public-api/adaptor-framework/encoded-image-buffer.h diff --git a/automated-tests/src/dali-adaptor/CMakeLists.txt b/automated-tests/src/dali-adaptor/CMakeLists.txt index 4b3f4b4..dc7415b 100644 --- a/automated-tests/src/dali-adaptor/CMakeLists.txt +++ b/automated-tests/src/dali-adaptor/CMakeLists.txt @@ -6,6 +6,7 @@ SET(RPM_NAME "core-${PKG_NAME}-tests") SET(CAPI_LIB "dali-adaptor") SET(TC_SOURCES utc-Dali-Application.cpp + utc-Dali-EncodedImageBuffer.cpp utc-Dali-FileLoader.cpp utc-Dali-GifLoading.cpp utc-Dali-ImageLoading.cpp diff --git a/automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp b/automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp new file mode 100644 index 0000000..8bb9086 --- /dev/null +++ b/automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include + +using namespace Dali; + +namespace +{ +EncodedImageBuffer::RawBufferType tinybuffer() +{ + EncodedImageBuffer::RawBufferType buffer; + buffer.PushBack(0x11); + buffer.PushBack(0x22); + buffer.PushBack(0x33); + return buffer; +} + +} // anonymous namespace + +void dali_encoded_image_buffer_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void dali_encoded_image_buffer_cleanup(void) +{ + test_return_value = TET_PASS; +} + +int UtcDaliEncodedImageBufferNew(void) +{ + // invoke default handle constructor + EncodedImageBuffer buffer; + + DALI_TEST_CHECK(!buffer); + + // initialise handle + buffer = EncodedImageBuffer::New(tinybuffer()); + + DALI_TEST_CHECK(buffer); + END_TEST; +} + +int UtcDaliEncodedImageBufferCopyConstructor(void) +{ + EncodedImageBuffer buffer = EncodedImageBuffer::New(tinybuffer()); + EncodedImageBuffer bufferCopy(buffer); + + DALI_TEST_EQUALS( (bool)bufferCopy, true, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliEncodedImageBufferAssignmentOperator(void) +{ + EncodedImageBuffer buffer = EncodedImageBuffer::New(tinybuffer()); + + EncodedImageBuffer buffer2; + DALI_TEST_EQUALS( (bool)buffer2, false, TEST_LOCATION ); + + buffer2 = buffer; + DALI_TEST_EQUALS( (bool)buffer2, true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliEncodedImageBufferGetRawBuffer(void) +{ + EncodedImageBuffer::RawBufferType originBuffer = tinybuffer(); + + EncodedImageBuffer buffer = EncodedImageBuffer::New(originBuffer); + + EncodedImageBuffer::RawBufferType getBuffer = buffer.GetRawBuffer(); + + // compare value between originBuffer and getBuffer + DALI_TEST_EQUALS(originBuffer.Count(), getBuffer.Count(), TEST_LOCATION); + + EncodedImageBuffer::RawBufferType::Iterator iter = originBuffer.Begin(); + EncodedImageBuffer::RawBufferType::Iterator jter = getBuffer.Begin(); + for(; iter != originBuffer.End(); ++iter, ++jter) + { + DALI_TEST_EQUALS(*iter, *jter, TEST_LOCATION ); + } + + END_TEST; +} diff --git a/dali/internal/imaging/common/encoded-image-buffer-impl.cpp b/dali/internal/imaging/common/encoded-image-buffer-impl.cpp new file mode 100644 index 0000000..1967bcb --- /dev/null +++ b/dali/internal/imaging/common/encoded-image-buffer-impl.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include "encoded-image-buffer-impl.h" + +namespace Dali +{ +namespace Internal +{ + +EncodedImageBuffer::EncodedImageBuffer(const RawBufferType& buffer) +: mBuffer(buffer) +{ +} + +EncodedImageBuffer::~EncodedImageBuffer() +{ +} + +IntrusivePtr EncodedImageBuffer::New(const RawBufferType& buffer) +{ + IntrusivePtr internal = new EncodedImageBuffer(buffer); + + return internal; +} + +const EncodedImageBuffer::RawBufferType& EncodedImageBuffer::GetRawBuffer() const +{ + return mBuffer; +} + +} // namespace Internal + +} // namespace Dali diff --git a/dali/internal/imaging/common/encoded-image-buffer-impl.h b/dali/internal/imaging/common/encoded-image-buffer-impl.h new file mode 100644 index 0000000..2ea471f --- /dev/null +++ b/dali/internal/imaging/common/encoded-image-buffer-impl.h @@ -0,0 +1,93 @@ +#ifndef DALI_ENCODED_IMAGE_BUFFER_IMPL_H +#define DALI_ENCODED_IMAGE_BUFFER_IMPL_H + +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// EXTERNAL INCLUDES +#include +#include +#include + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ +namespace Internal +{ +class EncodedImageBuffer : public BaseObject +{ +public: + using RawBufferType = Dali::EncodedImageBuffer::RawBufferType; + + /** + * Constructor + * @param [in] buffer The raw buffer of image. + */ + EncodedImageBuffer(const RawBufferType& buffer); + + /** + * @copydoc Dali::EncodedImageBuffer::New + */ + static IntrusivePtr New(const RawBufferType& buffer); + + /** + * @copydoc Dali::EncodedImageBuffer::GetRawBuffer + */ + const RawBufferType& GetRawBuffer() const; + +protected: + /** + * Destructor + */ + ~EncodedImageBuffer(); + +private: + // Undefined + EncodedImageBuffer(const EncodedImageBuffer& imageBuffer); + + // Undefined + EncodedImageBuffer& operator=(const EncodedImageBuffer& imageBuffer); + +private: + Dali::Vector mBuffer; +}; + +} // namespace Internal + +inline const Internal::EncodedImageBuffer& GetImplementation(const Dali::EncodedImageBuffer& encodedImageBuffer) +{ + DALI_ASSERT_ALWAYS(encodedImageBuffer && "EncodedImageBuffer handle is empty"); + + const BaseObject& handle = encodedImageBuffer.GetBaseObject(); + + return static_cast(handle); +} + +inline Internal::EncodedImageBuffer& GetImplementation(Dali::EncodedImageBuffer& encodedImageBuffer) +{ + DALI_ASSERT_ALWAYS(encodedImageBuffer && "EncodedImageBuffer handle is empty"); + + BaseObject& handle = encodedImageBuffer.GetBaseObject(); + + return static_cast(handle); +} + +} // namespace Dali + +#endif // DALI_ENCODED_IMAGE_BUFFER_IMPL_H diff --git a/dali/internal/imaging/file.list b/dali/internal/imaging/file.list index 4dcda76..137fa5c 100644 --- a/dali/internal/imaging/file.list +++ b/dali/internal/imaging/file.list @@ -4,6 +4,7 @@ SET( adaptor_imaging_common_src_files ${adaptor_imaging_dir}/common/native-bitmap-buffer-impl.cpp ${adaptor_imaging_dir}/common/pixel-buffer-impl.cpp ${adaptor_imaging_dir}/common/alpha-mask.cpp + ${adaptor_imaging_dir}/common/encoded-image-buffer-impl.cpp ${adaptor_imaging_dir}/common/gaussian-blur.cpp ${adaptor_imaging_dir}/common/http-utils.cpp ${adaptor_imaging_dir}/common/image-loader.cpp diff --git a/dali/public-api/adaptor-framework/encoded-image-buffer.cpp b/dali/public-api/adaptor-framework/encoded-image-buffer.cpp new file mode 100644 index 0000000..ddad181 --- /dev/null +++ b/dali/public-api/adaptor-framework/encoded-image-buffer.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include "encoded-image-buffer.h" + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +EncodedImageBuffer::EncodedImageBuffer() +{ +} + +EncodedImageBuffer::~EncodedImageBuffer() +{ +} + +EncodedImageBuffer::EncodedImageBuffer(Internal::EncodedImageBuffer* internal) +: BaseHandle(internal) +{ +} + +EncodedImageBuffer::EncodedImageBuffer(const EncodedImageBuffer& handle) +: BaseHandle(handle) +{ +} + +const EncodedImageBuffer::RawBufferType& EncodedImageBuffer::GetRawBuffer() const +{ + return GetImplementation(*this).GetRawBuffer(); +} + +EncodedImageBuffer& EncodedImageBuffer::operator=(const EncodedImageBuffer& handle) +{ + BaseHandle::operator=(handle); + return *this; +} + +EncodedImageBuffer EncodedImageBuffer::New(const RawBufferType& buffer) +{ + IntrusivePtr internal = Internal::EncodedImageBuffer::New(buffer); + 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 new file mode 100644 index 0000000..2a0da34 --- /dev/null +++ b/dali/public-api/adaptor-framework/encoded-image-buffer.h @@ -0,0 +1,96 @@ +#ifndef DALI_ENCODED_IMAGE_BUFFER_H +#define DALI_ENCODED_IMAGE_BUFFER_H +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal DALI_INTERNAL +{ +class EncodedImageBuffer; +} + +/** + * @brief EncodedImageBuffer contains the large encoded raw buffer informations. + * + * We can upload this buffer by generated url. + * The images are loaded by a worker thread to avoid blocking the main event thread. + * @note cannot change raw buffer after make handle. + * @note only regular image upload support now. + */ +class DALI_ADAPTOR_API EncodedImageBuffer : public BaseHandle +{ +public: + using RawBufferType = Dali::Vector; + +public: + /** + * @brief Create a new EncodedImageBuffer. + * + * @param [in] buffer The encoded raw buffer + * @return A handle to a new EncodedImageBuffer. + */ + static EncodedImageBuffer New(const RawBufferType& buffer); + + /** + * @brief Create an empty handle. + * + * Calling member functions of an empty handle is not allowed. + */ + EncodedImageBuffer(); + + /** + * @brief Destructor. + */ + ~EncodedImageBuffer(); + + /** + * @brief This copy constructor is required for (smart) pointer semantics. + * + * @param [in] handle A reference to the copied handle + */ + EncodedImageBuffer(const EncodedImageBuffer& handle); + + /** + * @brief This assignment operator is required for (smart) pointer semantics. + * + * @param [in] handle A reference to the copied handle + * @return A reference to this + */ + EncodedImageBuffer& operator=(const EncodedImageBuffer& handle); + + /** + * @brief Get raw buffer data + * @note this method return const value. Mean, you cannot change raw buffer + * @return A RawBufferType this buffer have + */ + const RawBufferType& GetRawBuffer() const; + +public: // Not intended for developer use + explicit DALI_INTERNAL EncodedImageBuffer(Internal::EncodedImageBuffer* impl); +}; + +} // namespace Dali + +#endif // DALI_ENCODED_IMAGE_BUFFER_H diff --git a/dali/public-api/file.list b/dali/public-api/file.list index 4453a21..cd52e1f 100644 --- a/dali/public-api/file.list +++ b/dali/public-api/file.list @@ -2,6 +2,7 @@ SET( adaptor_public_api_src_files ${adaptor_public_api_dir}/adaptor-framework/application.cpp + ${adaptor_public_api_dir}/adaptor-framework/encoded-image-buffer.cpp ${adaptor_public_api_dir}/adaptor-framework/key.cpp ${adaptor_public_api_dir}/adaptor-framework/window.cpp ${adaptor_public_api_dir}/adaptor-framework/timer.cpp @@ -24,6 +25,7 @@ SET( public_api_header_files SET( public_api_adaptor_framework_header_files ${adaptor_public_api_dir}/adaptor-framework/application.h ${adaptor_public_api_dir}/adaptor-framework/device-status.h + ${adaptor_public_api_dir}/adaptor-framework/encoded-image-buffer.h ${adaptor_public_api_dir}/adaptor-framework/input-method.h ${adaptor_public_api_dir}/adaptor-framework/key.h ${adaptor_public_api_dir}/adaptor-framework/key-grab.h -- 2.7.4