/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
height = mHeight;
// Push the buffer
- mBuffers.push_back(BufferPair(tbmSurface, buffer));
+ mBuffers.insert({buffer, tbmSurface});
return buffer;
}
bool NativeImageSourceQueueTizen::EnqueueBuffer(uint8_t* buffer)
{
Dali::Mutex::ScopedLock lock(mMutex);
- auto bufferInstance = std::find_if(mBuffers.begin(),
- mBuffers.end(),
- [buffer](BufferPair pair) { return (pair.second == buffer); });
+ auto bufferInstance = mBuffers.find(buffer);
if(bufferInstance != mBuffers.end())
{
- tbm_surface_internal_unref((*bufferInstance).first);
- tbm_surface_unmap((*bufferInstance).first);
- tbm_surface_queue_enqueue(mTbmQueue, (*bufferInstance).first);
+ tbm_surface_internal_unref((*bufferInstance).second);
+ tbm_surface_unmap((*bufferInstance).second);
+ tbm_surface_queue_enqueue(mTbmQueue, (*bufferInstance).second);
mBuffers.erase(bufferInstance);
return true;
}
if(mConsumeSurface)
{
- bool existing = false;
- for(auto&& iter : mEglImages)
- {
- if(iter.first == mConsumeSurface)
- {
- // Find the surface in the existing list
- existing = true;
- mEglImageExtensions->TargetTextureKHR(iter.second);
- break;
- }
- }
-
- if(!existing)
+ auto iter = mEglImages.find(mConsumeSurface);
+ if(iter == mEglImages.end())
{
// Push the surface
tbm_surface_internal_ref(mConsumeSurface);
void* eglImageKHR = mEglImageExtensions->CreateImageKHR(reinterpret_cast<EGLClientBuffer>(mConsumeSurface));
mEglImageExtensions->TargetTextureKHR(eglImageKHR);
- mEglImages.push_back(EglImagePair(mConsumeSurface, eglImageKHR));
+ mEglImages.insert({mConsumeSurface, eglImageKHR});
+ }
+ else
+ {
+ mEglImageExtensions->TargetTextureKHR(iter->second);
}
}
}
if(mFreeRequest)
{
- auto iter = std::remove_if(mEglImages.begin(), mEglImages.end(), [&](EglImagePair& eglImage) {
- if(mConsumeSurface == eglImage.first) return false;
- mEglImageExtensions->DestroyImageKHR(eglImage.second);
- tbm_surface_internal_unref(eglImage.first);
- return true; });
- mEglImages.erase(iter, mEglImages.end());
+ // Destroy all egl images which is not mConsumeSurface.
+ for(auto iter = mEglImages.begin(); iter != mEglImages.end();)
+ {
+ if(iter->first == mConsumeSurface)
+ {
+ ++iter;
+ }
+ else
+ {
+ mEglImageExtensions->DestroyImageKHR(iter->second);
+ tbm_surface_internal_unref(iter->first);
+
+ iter = mEglImages.erase(iter);
+ }
+ }
tbm_surface_queue_free_flush(mTbmQueue);
mFreeRequest = false;
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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/common/map-wrapper.h>
#include <dali/devel-api/threading/mutex.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <tbm_surface.h>
#include <tbm_surface_queue.h>
+#include <unordered_map>
// INTERNAL INCLUDES
#include <dali/internal/imaging/common/native-image-source-queue-impl.h>
bool CheckBlending(int format);
private:
- typedef std::pair<tbm_surface_h, void*> EglImagePair;
- typedef std::pair<tbm_surface_h, uint8_t*> BufferPair;
-
- Dali::Mutex mMutex; ///< Mutex
- uint32_t mQueueCount; ///< queue count
- uint32_t mWidth; ///< image width
- uint32_t mHeight; ///< image height
- tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle
- tbm_surface_h mConsumeSurface; ///< The current tbm surface
- std::vector<EglImagePair> mEglImages; ///< EGL Image vector
- std::vector<BufferPair> mBuffers; ///< Buffer vector
- EglGraphics* mEglGraphics; ///< EGL Graphics
- EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
- bool mOwnTbmQueue; ///< Whether we created tbm queue
- bool mBlendingRequired; ///< Whether blending is required
- bool mIsResized; ///< Whether the size has changed
- bool mFreeRequest; ///< Whether it is requested to free the released buffers
+ using SurfaceEglContainer = std::unordered_map<tbm_surface_h, void*>;
+ using BufferSurfaceContainer = std::unordered_map<uint8_t*, tbm_surface_h>;
+
+ Dali::Mutex mMutex; ///< Mutex
+ uint32_t mQueueCount; ///< queue count
+ uint32_t mWidth; ///< image width
+ uint32_t mHeight; ///< image height
+ tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle
+ tbm_surface_h mConsumeSurface; ///< The current tbm surface
+ SurfaceEglContainer mEglImages; ///< EGL Image map
+ BufferSurfaceContainer mBuffers; ///< Buffer map
+ EglGraphics* mEglGraphics; ///< EGL Graphics
+ EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
+ bool mOwnTbmQueue; ///< Whether we created tbm queue
+ bool mBlendingRequired; ///< Whether blending is required
+ bool mIsResized; ///< Whether the size has changed
+ bool mFreeRequest; ///< Whether it is requested to free the released buffers
};
} // namespace Adaptor