Add class for encoded image buffer 26/260026/7
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 18 Jun 2021 04:41:11 +0000 (13:41 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 7 Jul 2021 04:59:36 +0000 (13:59 +0900)
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 <eunkiki.hong@samsung.com>
automated-tests/src/dali-adaptor/CMakeLists.txt
automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp [new file with mode: 0644]
dali/internal/imaging/common/encoded-image-buffer-impl.cpp [new file with mode: 0644]
dali/internal/imaging/common/encoded-image-buffer-impl.h [new file with mode: 0644]
dali/internal/imaging/file.list
dali/public-api/adaptor-framework/encoded-image-buffer.cpp [new file with mode: 0644]
dali/public-api/adaptor-framework/encoded-image-buffer.h [new file with mode: 0644]
dali/public-api/file.list

index 4b3f4b4..dc7415b 100644 (file)
@@ -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 (file)
index 0000000..8bb9086
--- /dev/null
@@ -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 <stdlib.h>
+#include <unistd.h>
+#include <dali/dali.h>
+#include <dali-test-suite-utils.h>
+#include <dali/public-api/adaptor-framework/encoded-image-buffer.h>
+
+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 (file)
index 0000000..1967bcb
--- /dev/null
@@ -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> EncodedImageBuffer::New(const RawBufferType& buffer)
+{
+  IntrusivePtr<EncodedImageBuffer> 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 (file)
index 0000000..2ea471f
--- /dev/null
@@ -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 <dali/public-api/common/intrusive-ptr.h>
+#include <dali/public-api/object/base-object.h>
+#include <dali/public-api/common/dali-vector.h>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/dali-adaptor-common.h>
+#include <dali/public-api/adaptor-framework/encoded-image-buffer.h>
+
+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<EncodedImageBuffer> 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<uint8_t> 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<const Internal::EncodedImageBuffer&>(handle);
+}
+
+inline Internal::EncodedImageBuffer& GetImplementation(Dali::EncodedImageBuffer& encodedImageBuffer)
+{
+  DALI_ASSERT_ALWAYS(encodedImageBuffer && "EncodedImageBuffer handle is empty");
+
+  BaseObject& handle = encodedImageBuffer.GetBaseObject();
+
+  return static_cast<Internal::EncodedImageBuffer&>(handle);
+}
+
+} // namespace Dali
+
+#endif // DALI_ENCODED_IMAGE_BUFFER_IMPL_H
index 4dcda76..137fa5c 100644 (file)
@@ -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 (file)
index 0000000..ddad181
--- /dev/null
@@ -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 <dali/internal/imaging/common/encoded-image-buffer-impl.h>
+
+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::EncodedImageBuffer> 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 (file)
index 0000000..2a0da34
--- /dev/null
@@ -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 <dali/public-api/object/base-handle.h>
+#include <dali/public-api/common/dali-vector.h>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/dali-adaptor-common.h>
+
+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<uint8_t>;
+
+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
index 4453a21..cd52e1f 100644 (file)
@@ -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