{
Texture texture = Texture::New(type, format, width, height);
- int bufferSize = width * height * 2;
+ int bufferSize = width * height * GetBytesPerPixel(format);
uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, format, PixelData::FREE);
texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
/*
- * Copyright (c) 2021 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.
{
if(mCreateInfo.nativeImagePtr)
{
- /***********************************************************************************
- * If the native image source changes, we need to re-create the texture. *
- * In EGL, this is done in native image implementation in PrepareTexture below. *
- * *
- * In Vulkan impl, this was done in dali-core side. I think we should make this *
- * work in the graphics implementation instead. *
- ***********************************************************************************/
- if(mCreateInfo.nativeImagePtr->SourceChanged())
- {
- uint32_t width = mCreateInfo.nativeImagePtr->GetWidth();
- uint32_t height = mCreateInfo.nativeImagePtr->GetHeight();
- mCreateInfo.SetSize({width, height}); // Size may change
-
- // @todo Re-initialize this texture from the new create info.
- }
-
// Ensure the native image is up-to-date
mCreateInfo.nativeImagePtr->PrepareTexture();
}
#define DALI_TEST_GRAPHICS_TEXTURE_H
/*
- * Copyright (c) 2021 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.
void Bind(uint32_t textureUnit);
/**
- * Prepare ensures that the native texture is updated if necessary (SourceChanged)
+ * Prepare ensures that the native texture is updated if necessary
*/
void Prepare();
#define TEST_NATIVE_IMAGE_H
/*
- * Copyright (c) 2021 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.
};
inline bool SourceChanged() const override
{
- return false;
+ return true;
};
+ inline Rect<uint32_t> GetUpdatedArea() override
+ {
+ return mUpdatedArea;
+ }
+
inline virtual Dali::NativeImageInterface::Extension* GetExtension()
{
return nullptr;
}
+ inline void SetUpdatedArea(const Rect<uint32_t>& updatedArea)
+ {
+ mUpdatedArea = updatedArea;
+ }
+
private:
TestNativeImage(uint32_t width, uint32_t height);
virtual ~TestNativeImage();
- uint32_t mWidth;
- uint32_t mHeight;
+ uint32_t mWidth;
+ uint32_t mHeight;
+ Rect<uint32_t> mUpdatedArea{};
public:
int32_t mExtensionCreateCalls;
/*\r
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.\r
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).EncodeToFile(filename, quality);\r
}\r
\r
-uint8_t* AcquireBuffer(NativeImageSource& image, uint16_t& width, uint16_t& height, uint16_t& stride)\r
+uint8_t* AcquireBuffer(NativeImageSource& image, uint32_t& width, uint32_t& height, uint32_t& stride)\r
{\r
return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).AcquireBuffer(width, height, stride);\r
}\r
\r
-bool ReleaseBuffer(NativeImageSource& image)\r
+bool ReleaseBuffer(NativeImageSource& image, const Rect<uint32_t>& updatedArea)\r
{\r
- return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).ReleaseBuffer();\r
+ return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).ReleaseBuffer(updatedArea);\r
}\r
\r
void SetResourceDestructionCallback(NativeImageSource& image, EventThreadCallback* callback)\r
return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).SetResourceDestructionCallback(callback);\r
}\r
\r
+void EnableBackBuffer(NativeImageSource& image, bool enable)\r
+{\r
+ Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).EnableBackBuffer(enable);\r
+}\r
+\r
} // namespace DevelNativeImageSource\r
\r
} // namespace Dali\r
#ifndef DALI_NATIVE_IMAGE_SOURCE_DEVEL_H\r
#define DALI_NATIVE_IMAGE_SOURCE_DEVEL_H\r
/*\r
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.\r
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
*/\r
\r
// EXTERNAL INCLUDES\r
-#include <dali/public-api/adaptor-framework/native-image-source.h>\r
-#include <dali/devel-api/adaptor-framework/event-thread-callback.h>\r
+#include <dali/public-api/math/rect.h>\r
\r
+// INTERNAL INCLUDES\r
+#include <dali/devel-api/adaptor-framework/event-thread-callback.h>\r
+#include <dali/public-api/adaptor-framework/native-image-source.h>\r
\r
namespace Dali\r
{\r
* @brief Acquire buffer and information of an internal native image.\r
*\r
* AcquireBuffer() and ReleaseBuffer() are a pair.\r
- * It should be call ReleaseBuffer() after AcquireBuffer().\r
+ * ReleaseBuffer() MUST be called after AcquireBuffer().\r
* @param[in] image The instance of NativeImageSource.\r
* @param[out] width The width of image\r
* @param[out] height The height of image\r
* @param[out] stride The stride of image\r
* @return The buffer of an internal native image\r
+ * @note This locks a mutex until ReleaseBuffer is called.\r
*/\r
-DALI_ADAPTOR_API uint8_t* AcquireBuffer(NativeImageSource& image, uint16_t& width, uint16_t& height, uint16_t& stride);\r
+DALI_ADAPTOR_API uint8_t* AcquireBuffer(NativeImageSource& image, uint32_t& width, uint32_t& height, uint32_t& stride);\r
\r
/**\r
* @brief Release information of an internal native image.\r
*\r
* AcquireBuffer() and ReleaseBuffer() are a pair.\r
- * It should be call ReleaseBuffer() after AcquireBuffer().\r
+ * ReleaseBuffer() MUST be called after AcquireBuffer().\r
* @param[in] image The instance of NativeImageSource.\r
- * @return @c true If the buffer is released successfully, and @c false otherwise\r
+ * @param[in] updatedArea The updated area of the buffer.\r
+ * @return @c true If the buffer is released successfully, and @c false otherwise\r
+ * @note The empty updatedArea means that the entire area has been changed.\r
+ * @note This unlocks the mutex locked by AcquireBuffer.\r
*/\r
-DALI_ADAPTOR_API bool ReleaseBuffer(NativeImageSource& image);\r
+DALI_ADAPTOR_API bool ReleaseBuffer(NativeImageSource& image, const Rect<uint32_t>& updatedArea);\r
\r
/**\r
* @brief Set the Resource Destruction Callback object\r
*\r
- * @param image The instance of NativeImageSource.\r
- * @param callback The Resource Destruction callback\r
+ * @param[in] image The instance of NativeImageSource.\r
+ * @param[in] callback The Resource Destruction callback\r
* @note Ownership of the callback is passed onto this class.\r
*/\r
DALI_ADAPTOR_API void SetResourceDestructionCallback(NativeImageSource& image, EventThreadCallback* callback);\r
\r
+/**\r
+ * @brief Enable a back buffer.\r
+ * @param[in] image The instance of NativeImageSource.\r
+ * @param[in] enable Whether a back buffer is enabled.\r
+ * @note The front buffer will be copied to the back buffer before rendering if the front buffer is updated by AcquireBuffer and ReleaseBuffer.\r
+ */\r
+DALI_ADAPTOR_API void EnableBackBuffer(NativeImageSource& image, bool enable);\r
+\r
} // namespace DevelNativeImageSource\r
\r
} // namespace Dali\r
/*
- * 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.
return mImpl->SourceChanged();
}
+Rect<uint32_t> NativeImageSourceQueue::GetUpdatedArea()
+{
+ return mImpl->GetUpdatedArea();
+}
+
NativeImageInterface::Extension* NativeImageSourceQueue::GetExtension()
{
return mImpl->GetNativeImageInterfaceExtension();
#define DALI_NATIVE_IMAGE_SOURCE_QUEUE_H
/*
- * 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetExtension() override;
NativeImageInterfacePtr nativeImage = mCreateInfo.nativeImagePtr;
if(nativeImage)
{
- if(nativeImage->SourceChanged())
- {
- // Update size
- uint32_t width = mCreateInfo.nativeImagePtr->GetWidth();
- uint32_t height = mCreateInfo.nativeImagePtr->GetHeight();
- mCreateInfo.SetSize({width, height}); // Size may change
- }
-
nativeImage->PrepareTexture();
}
}
/*
- * 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.
}
}
-uint8_t* NativeImageSourceAndroid::AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride)
+uint8_t* NativeImageSourceAndroid::AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride)
{
if(mPixmap)
{
return NULL;
}
-bool NativeImageSourceAndroid::ReleaseBuffer()
+bool NativeImageSourceAndroid::ReleaseBuffer(const Rect<uint32_t>& updatedArea)
{
if(mPixmap)
{
mResourceDestructionCallback = std::unique_ptr<EventThreadCallback>(callback);
}
+void NativeImageSourceAndroid::EnableBackBuffer(bool enable)
+{
+}
+
} // namespace Adaptor
} // namespace Internal
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
/*
- * 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.
*/
bool SourceChanged() const override
{
- return false;
+ return true;
+ }
+
+ /**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
}
/**
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
*/
- uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
+ uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
*/
- bool ReleaseBuffer() override;
+ bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
/**
* @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
*/
void SetResourceDestructionCallback(EventThreadCallback* callback) override;
+ /**
+ * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
+ */
+ void EnableBackBuffer(bool enable) override;
+
private:
/**
* Private constructor; @see NativeImageSource::New()
/*
- * 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.
bool NativeImageSourceQueueAndroid::SourceChanged() const
{
- return false;
+ return true;
}
} // namespace Adaptor
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_ANDROID_H
/*
- * 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.
*/
bool SourceChanged() const override;
+ /**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
+ }
+
private:
/**
* Private constructor; @see NativeImageSourceQueue::New()
bool NativeBitmapBuffer::SourceChanged() const
{
- return false;
+ return true;
}
} // namespace Adaptor
#define DALI_NATIVE_BITMAP_BUFFER_H
/*
- * Copyright (c) 2021 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.
*/
bool SourceChanged() const override;
+ /**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
+ }
+
private:
NativeBitmapBuffer(const NativeBitmapBuffer&); ///< not defined
NativeBitmapBuffer& operator=(const NativeBitmapBuffer&); ///< not defined
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
/*
- * Copyright (c) 2021 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.
// INTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
-#include <dali/public-api/adaptor-framework/native-image-source.h>
#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
-
+#include <dali/public-api/adaptor-framework/native-image-source.h>
namespace Dali
{
virtual bool SourceChanged() const = 0;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ virtual Rect<uint32_t> GetUpdatedArea() = 0;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension() = 0;
/**
- * @brief Dali::DevelNativeImageSource::AcquireBuffer()
+ * @copydoc Dali::DevelNativeImageSource::AcquireBuffer()
*/
- virtual uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) = 0;
+ virtual uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) = 0;
/**
- * @brief Dali::DevelNativeImageSource::ReleaseBuffer()
+ * @copydoc Dali::DevelNativeImageSource::ReleaseBuffer()
*/
- virtual bool ReleaseBuffer() = 0;
+ virtual bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) = 0;
/**
- * @brief Dali::DevelNativeImageSource::SetResourceDestructionCallback()
+ * @copydoc Dali::DevelNativeImageSource::SetResourceDestructionCallback()
*/
virtual void SetResourceDestructionCallback(EventThreadCallback* callback) = 0;
/**
+ * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
+ */
+ virtual void EnableBackBuffer(bool enable) = 0;
+
+ /**
* @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
*/
inline bool EncodeToFile(const std::string& filename) const
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_H
/*
- * 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.
virtual bool SourceChanged() const = 0;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ virtual Rect<uint32_t> GetUpdatedArea() = 0;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension() = 0;
/*
- * Copyright (c) 2021 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.
bool NativeImageSourceCocoa::SourceChanged() const
{
- return false;
+ return true;
}
-uint8_t* NativeImageSourceCocoa::AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride)
+uint8_t* NativeImageSourceCocoa::AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride)
{
return nullptr;
}
-bool NativeImageSourceCocoa::ReleaseBuffer()
+bool NativeImageSourceCocoa::ReleaseBuffer(const Rect<uint32_t>& updatedArea)
{
return false;
}
mResourceDestructionCallback = std::unique_ptr<EventThreadCallback>(callback);
}
+void NativeImageSourceCocoa::EnableBackBuffer(bool enable)
+{
+}
+
} // namespace Dali::Internal::Adaptor
#pragma once
/*
- * Copyright (c) 2021 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, static_cast<uint32_t>(CGImageGetWidth(mImage.get())), static_cast<uint32_t>(CGImageGetHeight(mImage.get()))};
+ }
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
*/
- uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
+ uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
*/
- bool ReleaseBuffer() override;
+ bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
/**
* @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
*/
void SetResourceDestructionCallback(EventThreadCallback* callback) override;
+ /**
+ * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
+ */
+ void EnableBackBuffer(bool enable) override;
+
private:
/**
* Private constructor; @see NativeImageSource::New()
Any nativeImageSource);
private:
- CFRef<CGImageRef> mImage;
- std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
+ CFRef<CGImageRef> mImage;
+ std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
};
} // namespace Dali::Internal::Adaptor
/*
- * 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.
NativeImageSourceTizen::NativeImageSourceTizen(uint32_t width, uint32_t height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource)
: mWidth(width),
mHeight(height),
- mOwnTbmSurface(false),
mTbmSurface(NULL),
+ mTbmBackSurface(NULL),
mTbmFormat(0),
- mBlendingRequired(false),
mColorDepth(depth),
+ mMutex(),
mEglImageKHR(NULL),
mEglGraphics(NULL),
mEglImageExtensions(NULL),
+ mResourceDestructionCallback(),
+ mOwnTbmSurface(false),
+ mBlendingRequired(false),
mSetSource(false),
- mMutex(),
mIsBufferAcquired(false),
- mResourceDestructionCallback()
-
+ mBackBufferEnabled(false)
{
DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
{
if(mIsBufferAcquired)
{
- ReleaseBuffer();
+ Rect<uint32_t> emptyRect{};
+ ReleaseBuffer(emptyRect);
}
if(mOwnTbmSurface)
{
{
tbm_surface_internal_unref(mTbmSurface);
}
+ mTbmSurface = NULL;
+
+ DestroyBackBuffer();
}
}
bool NativeImageSourceTizen::GetPixels(std::vector<unsigned char>& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const
{
- Dali::Mutex::ScopedLock lock(mMutex);
+ std::scoped_lock lock(mMutex);
if(mTbmSurface != NULL)
{
tbm_surface_info_s surface_info;
void NativeImageSourceTizen::SetSource(Any source)
{
- Dali::Mutex::ScopedLock lock(mMutex);
+ std::scoped_lock lock(mMutex);
DestroySurface();
mBlendingRequired = CheckBlending(tbm_surface_get_format(mTbmSurface));
mWidth = tbm_surface_get_width(mTbmSurface);
mHeight = tbm_surface_get_height(mTbmSurface);
+
+ if(mBackBufferEnabled)
+ {
+ DestroyBackBuffer();
+ CreateBackBuffer();
+ }
}
}
// casting from an unsigned int to a void *, which should then be cast back
// to an unsigned int in the driver.
- EGLClientBuffer eglBuffer = reinterpret_cast<EGLClientBuffer>(mTbmSurface);
+ EGLClientBuffer eglBuffer = mTbmBackSurface ? reinterpret_cast<EGLClientBuffer>(mTbmBackSurface) : reinterpret_cast<EGLClientBuffer>(mTbmSurface);
if(!eglBuffer || !tbm_surface_internal_is_valid(mTbmSurface))
{
+ DALI_LOG_ERROR("Invalid surface\n");
return false;
}
DALI_ASSERT_DEBUG(mEglImageExtensions);
mEglImageKHR = mEglImageExtensions->CreateImageKHR(eglBuffer);
+ if(!mEglImageKHR)
+ {
+ DALI_LOG_ERROR("Fail to CreateImageKHR\n");
+ }
return mEglImageKHR != NULL;
}
void NativeImageSourceTizen::DestroyResource()
{
- Dali::Mutex::ScopedLock lock(mMutex);
+ std::scoped_lock lock(mMutex);
if(mEglImageKHR)
{
mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
void NativeImageSourceTizen::PrepareTexture()
{
- Dali::Mutex::ScopedLock lock(mMutex);
+ std::scoped_lock lock(mMutex);
if(mSetSource)
{
// Destroy previous eglImage because use for new one.
bool NativeImageSourceTizen::SourceChanged() const
{
- return false;
+ if(mTbmBackSurface)
+ {
+ return mUpdatedArea.IsEmpty() ? false : true;
+ }
+ return true;
+}
+
+Rect<uint32_t> NativeImageSourceTizen::GetUpdatedArea()
+{
+ std::scoped_lock lock(mMutex);
+ Rect<uint32_t> updatedArea{0, 0, mWidth, mHeight};
+ if(!mUpdatedArea.IsEmpty() && mTbmSurface != NULL && mTbmBackSurface != NULL)
+ {
+ updatedArea = mUpdatedArea;
+
+ tbm_surface_info_s info;
+ if(tbm_surface_map(mTbmSurface, TBM_SURF_OPTION_READ | TBM_SURF_OPTION_WRITE, &info) != TBM_SURFACE_ERROR_NONE)
+ {
+ DALI_LOG_ERROR("Fail to map tbm_surface\n");
+ return updatedArea;
+ }
+
+ tbm_surface_info_s backBufferInfo;
+ if(tbm_surface_map(mTbmBackSurface, TBM_SURF_OPTION_READ | TBM_SURF_OPTION_WRITE, &backBufferInfo) != TBM_SURFACE_ERROR_NONE)
+ {
+ DALI_LOG_ERROR("Fail to map tbm_surface - backbuffer\n");
+ tbm_surface_unmap(mTbmSurface);
+ return updatedArea;
+ }
+
+ unsigned char* srcBuffer = info.planes[0].ptr;
+ unsigned char* dstBuffer = backBufferInfo.planes[0].ptr;
+
+ uint32_t stride = info.planes[0].stride;
+ uint32_t bytesPerPixel = info.bpp >> 3;
+
+ srcBuffer += updatedArea.y * stride + updatedArea.x * bytesPerPixel;
+ dstBuffer += updatedArea.y * stride + updatedArea.x * bytesPerPixel;
+
+ // Copy to back buffer
+ for(uint32_t y = 0; y < updatedArea.height; y++)
+ {
+ memcpy(dstBuffer, srcBuffer, updatedArea.width * bytesPerPixel);
+ srcBuffer += stride;
+ dstBuffer += stride;
+ }
+
+ tbm_surface_unmap(mTbmSurface);
+ tbm_surface_unmap(mTbmBackSurface);
+
+ // Reset the updated area
+ mUpdatedArea.Set(0u, 0u, 0u, 0u);
+ }
+ return updatedArea;
}
bool NativeImageSourceTizen::CheckBlending(tbm_format format)
return mBlendingRequired;
}
-uint8_t* NativeImageSourceTizen::AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride)
+uint8_t* NativeImageSourceTizen::AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride)
{
- Dali::Mutex::ScopedLock lock(mMutex);
+ mMutex.lock(); // We don't use std::scoped_lock here
if(mTbmSurface != NULL)
{
tbm_surface_info_s info;
width = 0;
height = 0;
+ mMutex.unlock();
return NULL;
}
tbm_surface_internal_ref(mTbmSurface);
width = mWidth;
height = mHeight;
+ // The lock is held until ReleaseBuffer is called
return info.planes[0].ptr;
}
+ mMutex.unlock();
return NULL;
}
-bool NativeImageSourceTizen::ReleaseBuffer()
+bool NativeImageSourceTizen::ReleaseBuffer(const Rect<uint32_t>& updatedArea)
{
- Dali::Mutex::ScopedLock lock(mMutex);
- bool ret = false;
+ bool ret = false;
if(mTbmSurface != NULL)
{
+ if(mTbmBackSurface)
+ {
+ if(updatedArea.IsEmpty())
+ {
+ mUpdatedArea.Set(0, 0, mWidth, mHeight);
+ }
+ else
+ {
+ if(mUpdatedArea.IsEmpty())
+ {
+ mUpdatedArea = updatedArea;
+ }
+ else
+ {
+ mUpdatedArea.Merge(updatedArea);
+ }
+ }
+ }
+
ret = (tbm_surface_unmap(mTbmSurface) == TBM_SURFACE_ERROR_NONE);
if(!ret)
{
tbm_surface_internal_unref(mTbmSurface);
mIsBufferAcquired = false;
}
+ // Unlock the mutex locked by AcquireBuffer.
+ mMutex.unlock();
return ret;
}
void NativeImageSourceTizen::SetResourceDestructionCallback(EventThreadCallback* callback)
{
- Dali::Mutex::ScopedLock lock(mMutex);
+ std::scoped_lock lock(mMutex);
mResourceDestructionCallback = std::unique_ptr<EventThreadCallback>(callback);
}
+void NativeImageSourceTizen::EnableBackBuffer(bool enable)
+{
+ if(enable != mBackBufferEnabled)
+ {
+ mBackBufferEnabled = enable;
+
+ if(mBackBufferEnabled)
+ {
+ CreateBackBuffer();
+ }
+ else
+ {
+ DestroyBackBuffer();
+ }
+ }
+}
+
+void NativeImageSourceTizen::CreateBackBuffer()
+{
+ if(!mTbmBackSurface && mTbmSurface)
+ {
+ mTbmBackSurface = tbm_surface_create(mWidth, mHeight, tbm_surface_get_format(mTbmSurface));
+ }
+}
+
+void NativeImageSourceTizen::DestroyBackBuffer()
+{
+ if(mTbmBackSurface)
+ {
+ if(tbm_surface_destroy(mTbmBackSurface) != TBM_SURFACE_ERROR_NONE)
+ {
+ DALI_LOG_ERROR("Failed to destroy tbm_surface\n");
+ }
+ mTbmBackSurface = NULL;
+ }
+}
+
} // namespace Adaptor
} // namespace Internal
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H
/*
- * Copyright (c) 2021 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.
*/
// EXTERNAL INCLUDES
-#include <dali/devel-api/threading/mutex.h>
#include <dali/public-api/common/dali-vector.h>
#include <tbm_surface.h>
#include <memory>
+#include <mutex>
// INTERNAL INCLUDES
#include <dali/internal/imaging/common/native-image-source-impl.h>
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
*/
- uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
+ uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
*/
- bool ReleaseBuffer() override;
+ bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
/**
* @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
*/
void SetResourceDestructionCallback(EventThreadCallback* callback) override;
+ /**
+ * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
+ */
+ void EnableBackBuffer(bool enable) override;
+
private:
/**
* Private constructor; @see NativeImageSource::New()
void DestroySurface();
+ /**
+ * @brief Create back buffer
+ */
+ void CreateBackBuffer();
+
+ /**
+ * @brief Destroy back buffer
+ */
+ void DestroyBackBuffer();
+
private:
- uint32_t mWidth; ///< image width
- uint32_t mHeight; ///< image height
- bool mOwnTbmSurface; ///< Whether we created pixmap or not
- tbm_surface_h mTbmSurface;
+ uint32_t mWidth; ///< image width
+ uint32_t mHeight; ///< image height
+ tbm_surface_h mTbmSurface; ///< Tbm surface
+ tbm_surface_h mTbmBackSurface; ///< Back buffer
tbm_format mTbmFormat;
- bool mBlendingRequired; ///< Whether blending is required
- Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image
- void* mEglImageKHR; ///< From EGL extension
- EglGraphics* mEglGraphics; ///< EGL Graphics
- EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
- bool mSetSource;
- mutable Dali::Mutex mMutex;
- bool mIsBufferAcquired; ///< Whether AcquireBuffer is called
- std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
+ Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image
+ Rect<uint32_t> mUpdatedArea{}; ///< Updated area
+ mutable std::mutex mMutex;
+ void* mEglImageKHR; ///< From EGL extension
+ EglGraphics* mEglGraphics; ///< EGL Graphics
+ EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
+ std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
+ bool mOwnTbmSurface : 1; ///< Whether we created pixmap or not
+ bool mBlendingRequired : 1; ///< Whether blending is required
+ bool mSetSource : 1;
+ bool mIsBufferAcquired : 1; ///< Whether AcquireBuffer is called
+ bool mBackBufferEnabled : 1; ///< Whether the back buffer is enabled
};
} // namespace Adaptor
/*
- * 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.
bool NativeImageSourceQueueTizen::SourceChanged() const
{
- return false;
+ return true;
}
void NativeImageSourceQueueTizen::ResetEglImageList(bool releaseConsumeSurface)
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
/*
- * 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
+ }
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
/*
- * 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.
bool NativeImageSourceX::SourceChanged() const
{
- return false;
+ return true;
}
Ecore_X_Pixmap NativeImageSourceX::GetPixmapFromAny(Any pixmap) const
mBlendingRequired = (depth == 32 || depth == 8);
}
-uint8_t* NativeImageSourceX::AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride)
+uint8_t* NativeImageSourceX::AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride)
{
return NULL;
}
-bool NativeImageSourceX::ReleaseBuffer()
+bool NativeImageSourceX::ReleaseBuffer(const Rect<uint32_t>& updatedArea)
{
return false;
}
mResourceDestructionCallback = std::unique_ptr<EventThreadCallback>(callback);
}
+void NativeImageSourceX::EnableBackBuffer(bool enable)
+{
+}
+
} // namespace Adaptor
} // namespace Internal
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
/*
- * 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
+ }
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
*/
- uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
+ uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
*/
- bool ReleaseBuffer() override;
+ bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
/**
* @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
*/
void SetResourceDestructionCallback(EventThreadCallback* callback) override;
+ /**
+ * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
+ */
+ void EnableBackBuffer(bool enable) override;
+
private:
/**
* Private constructor; @see NativeImageSource::New()
/*
- * 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.
bool NativeImageSourceQueueX::SourceChanged() const
{
- return false;
+ return true;
}
} // namespace Adaptor
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_X_H
/*
- * 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
+ }
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
/*
- * 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.
bool NativeImageSourceWin::SourceChanged() const
{
- return false;
+ return true;
}
-uint8_t* NativeImageSourceWin::AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride)
+uint8_t* NativeImageSourceWin::AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride)
{
return NULL;
}
-bool NativeImageSourceWin::ReleaseBuffer()
+bool NativeImageSourceWin::ReleaseBuffer(const Rect<uint32_t>& updatedArea)
{
return false;
}
mResourceDestructionCallback = std::unique_ptr<EventThreadCallback>(callback);
}
+void NativeImageSourceWin::EnableBackBuffer(bool enable)
+{
+}
+
} // namespace Adaptor
} // namespace Internal
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
/*
- * 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
+ }
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
*/
- uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
+ uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
*/
- bool ReleaseBuffer() override;
+ bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
/**
* @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
*/
void SetResourceDestructionCallback(EventThreadCallback* callback) override;
+ /**
+ * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
+ */
+ void EnableBackBuffer(bool enable) override;
+
private:
/**
* Private constructor; @see NativeImageSource::New()
/*
- * 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.
bool NativeImageSourceX::SourceChanged() const
{
- return false;
+ return true;
}
::Pixmap NativeImageSourceX::GetPixmapFromAny(Any pixmap) const
}
}
-uint8_t* NativeImageSourceX::AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride)
+uint8_t* NativeImageSourceX::AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride)
{
return NULL;
}
-bool NativeImageSourceX::ReleaseBuffer()
+bool NativeImageSourceX::ReleaseBuffer(const Rect<uint32_t>& updatedArea)
{
return false;
}
mResourceDestructionCallback = std::unique_ptr<EventThreadCallback>(callback);
}
+void NativeImageSourceX::EnableBackBuffer(bool enable)
+{
+}
+
} // namespace Adaptor
} // namespace Internal
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
/*
- * 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
+ }
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
*/
- uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
+ uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
/**
* @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
*/
- bool ReleaseBuffer() override;
+ bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
/**
* @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
*/
void SetResourceDestructionCallback(EventThreadCallback* callback) override;
+ /**
+ * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
+ */
+ void EnableBackBuffer(bool enable) override;
+
private:
/**
* Private constructor; @see NativeImageSource::New()
/*
- * 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.
bool NativeImageSourceQueueX::SourceChanged() const
{
- return false;
+ return true;
}
} // namespace Adaptor
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_X_H
/*
- * 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override
+ {
+ return Rect<uint32_t>{0, 0, mWidth, mHeight};
+ }
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
/*
- * Copyright (c) 2020 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.
return mImpl->SourceChanged();
}
+Rect<uint32_t> NativeImageSource::GetUpdatedArea()
+{
+ return mImpl->GetUpdatedArea();
+}
+
NativeImageInterface::Extension* NativeImageSource::GetExtension()
{
return mImpl->GetNativeImageInterfaceExtension();
#define DALI_NATIVE_IMAGE_SOURCE_H
/*
- * Copyright (c) 2020 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.
bool SourceChanged() const override;
/**
+ * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
+ */
+ Rect<uint32_t> GetUpdatedArea() override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
NativeImageInterface::Extension* GetExtension() override;