implement dequeue, enqueue, aquire and release.
Change-Id: I7e90cf7acbb1b36c528c17586a97b266fa440d03
#include "DSBufferQueueTBMImpl.h"
#include "DSBufferTBMImpl.h"
#include "DSDebugLog.h"
+#include <algorithm>
namespace display_server
{
DSBufferQueueTBMImpl::~DSBufferQueueTBMImpl()
{
+ __bufferVector.erase(__bufferVector.begin(), __bufferVector.end());
tbm_surface_queue_destroy(__tqueue);
}
return (void *)__tqueue;
}
-IDSBuffer *DSBufferQueueTBMImpl::dequeueBuffer()
+std::shared_ptr<IDSBuffer> DSBufferQueueTBMImpl::dequeueBuffer()
{
- // TODO:
- return nullptr;
+ tbm_surface_queue_error_e terror = TBM_SURFACE_QUEUE_ERROR_NONE;
+ tbm_surface_h tsurface;
+
+ terror = tbm_surface_queue_dequeue(__tqueue, &tsurface);
+ if (terror != TBM_SURFACE_QUEUE_ERROR_NONE) {
+ DSLOG_ERR("BuffeQueueTBM", "tbm_surface_queue_dequeue fails.\n");
+ return nullptr;
+ }
+
+ auto isMatchFunc = [tsurface](std::shared_ptr<IDSBuffer> buffer) -> bool {
+ return ((tbm_surface_h)buffer->getNativeBuffer() == tsurface);
+ };
+
+ auto iter= std::find_if(__bufferVector.begin(), __bufferVector.end(), isMatchFunc);
+ if (iter == __bufferVector.end()) {
+ // create a IDSBuffer with tsurface.
+ __bufferVector.push_back(std::make_shared<DSBufferTBMImpl>(__bufferWidth, __bufferWidth, __format, tsurface));
+
+ return __bufferVector.back();
+ }
+
+ return *iter;
}
-bool DSBufferQueueTBMImpl::enqueueBuffer(IDSBuffer *buffer)
+bool DSBufferQueueTBMImpl::enqueueBuffer(std::shared_ptr<IDSBuffer> buffer)
{
- // TODO:
- return false;
+ tbm_surface_queue_error_e terror = TBM_SURFACE_QUEUE_ERROR_NONE;
+ tbm_surface_h tsurface = (tbm_surface_h)buffer->getNativeBuffer();
+
+ terror = tbm_surface_queue_enqueue(__tqueue, tsurface);
+ if (terror != TBM_SURFACE_QUEUE_ERROR_NONE) {
+ DSLOG_ERR("BuffeQueueTBM", "tbm_surface_queue_enqueue fails.");
+ return false;
+ }
+
+ return true;
}
-IDSBuffer *DSBufferQueueTBMImpl::acquireBuffer()
+std::shared_ptr<IDSBuffer> DSBufferQueueTBMImpl::acquireBuffer()
{
- // TODO:
- return nullptr;
+ tbm_surface_queue_error_e terror = TBM_SURFACE_QUEUE_ERROR_NONE;
+ tbm_surface_h tsurface;
+
+ terror = tbm_surface_queue_acquire(__tqueue, &tsurface);
+ if (terror != TBM_SURFACE_QUEUE_ERROR_NONE) {
+ DSLOG_ERR("BuffeQueueTBM", "tbm_surface_queue_enqueue fails.");
+ return nullptr;
+ }
+
+ auto isMatchFunc = [tsurface](std::shared_ptr<IDSBuffer> buffer) -> bool {
+ return ((tbm_surface_h)buffer->getNativeBuffer() == tsurface);
+ };
+
+ auto iter= std::find_if(__bufferVector.begin(), __bufferVector.end(), isMatchFunc);
+ if (iter == __bufferVector.end()) {
+ DSLOG_ERR("BuffeQueueTBM", "No Buffer in this BufferQueue.");
+ return nullptr;
+ }
+
+ return *iter;
}
-bool DSBufferQueueTBMImpl::releaseBuffer(IDSBuffer *buffer)
+bool DSBufferQueueTBMImpl::releaseBuffer(std::shared_ptr<IDSBuffer> buffer)
{
- // TODO:
- return false;
+ tbm_surface_queue_error_e terror = TBM_SURFACE_QUEUE_ERROR_NONE;
+
+ terror = tbm_surface_queue_release(__tqueue, (tbm_surface_h)buffer->getNativeBuffer());
+ if (terror != TBM_SURFACE_QUEUE_ERROR_NONE) {
+ DSLOG_ERR("BuffeQueueTBM", "tbm_surface_queue_release fails.");
+ return false;
+ }
+
+ return true;
}
}
#include "IDSBufferQueue.h"
#include <tbm_surface_queue.h>
+#include <vector>
namespace display_server
{
int getBufferHeight() override;
void *getNativeBufferQueue() override;
- IDSBuffer *dequeueBuffer() override;
- bool enqueueBuffer(IDSBuffer *buffer) override;
- IDSBuffer *acquireBuffer() override;
- bool releaseBuffer(IDSBuffer *buffer) override;
+ std::shared_ptr<IDSBuffer> dequeueBuffer() override;
+ bool enqueueBuffer(std::shared_ptr<IDSBuffer> buffer) override;
+ std::shared_ptr<IDSBuffer> acquireBuffer() override;
+ bool releaseBuffer(std::shared_ptr<IDSBuffer> buffer) override;
private:
int __slotSize;
int __bufferHeight;
IDSBuffer::Format __format;
tbm_surface_queue_h __tqueue;
+ std::vector<std::shared_ptr<IDSBuffer>> __bufferVector;
};
}
#define __I_DS_BUFFER_QUEUE_H_
#include "IDSBuffer.h"
+#include <memory>
namespace display_server
{
virtual int getBufferWidth() = 0;
virtual int getBufferHeight() = 0;
virtual void *getNativeBufferQueue() = 0;
- virtual IDSBuffer *dequeueBuffer() = 0;
- virtual bool enqueueBuffer(IDSBuffer *buffer) = 0;
- virtual IDSBuffer *acquireBuffer() = 0;
- virtual bool releaseBuffer(IDSBuffer *buffer) = 0;
+ virtual std::shared_ptr<IDSBuffer> dequeueBuffer() = 0;
+ virtual bool enqueueBuffer(std::shared_ptr<IDSBuffer> ) = 0;
+ virtual std::shared_ptr<IDSBuffer> acquireBuffer() = 0;
+ virtual bool releaseBuffer(std::shared_ptr<IDSBuffer> ) = 0;
};
}
+@startuml
class Client
{
}
interface IDSBufferQueue
{
- + virtual bool enqueueBuffer(IDSBuffer *buffer) = 0;
- + virtual IDSBuffer *dequeueBuffer() = 0;
- + virtual IDSBuffer *acquireBuffer() = 0;
- + virtual bool releaseBuffer(IDSBuffer *buffer) = 0;
+ + virtual bool enqueueBuffer(std::shared_ptr<IDSBuffer> buffer) = 0;
+ + virtual std::shared_ptr<IDSBuffer> dequeueBuffer() = 0;
+ + virtual std::shared_ptr<IDSBuffer> acquireBuffer() = 0;
+ + virtual bool releaseBuffer(std::shared_ptr<IDSBuffer> buffer) = 0;
}
IDSBuffer "0..*" *-up- "1" DSBufferQueueTBMImpl
+ DSBufferQueueTBMImpl(int slotSize, int bufferWidth, int bufferHeight, IDSBuffer::Format format);
+ ~DSBufferQueueTBMImpl();
- + bool enqueueBuffer(IDSBuffer *buffer) override;
+ + bool enqueueBuffer(std::shared_ptr<IDSBuffer> buffer) override;
+ IDSBuffer *dequeueBuffer() override;
+ IDSBuffer *acquireBuffer() override;
- + bool releaseBuffer(IDSBuffer *buffer) override;
+ + bool releaseBuffer(std::shared_ptr<IDSBuffer> buffer) override;
- int __slotSize;
- int __bufferWidth;
IDSBuffer <|-down-- DSBufferTBMImpl
IDSBuffer <|-down-- DSBufferSHMImpl
-
+@enduml
std::unique_ptr<IDSBufferQueue> bufferQueue = std::make_unique<DSBufferQueueTBMImpl>(3, 100, 100, IDSBuffer::FORMAT_ARGB8888);
EXPECT_TRUE(bufferQueue.get() != nullptr);
- IDSBuffer *buffer = bufferQueue->dequeueBuffer();
+ std::shared_ptr<IDSBuffer> buffer = bufferQueue->dequeueBuffer();
EXPECT_TRUE(buffer != nullptr);
}
std::unique_ptr<IDSBufferQueue> bufferQueue = std::make_unique<DSBufferQueueTBMImpl>(3, 100, 100, IDSBuffer::FORMAT_ARGB8888);
EXPECT_TRUE(bufferQueue.get() != nullptr);
- IDSBuffer *buffer = bufferQueue->dequeueBuffer();
+ std::shared_ptr<IDSBuffer> buffer = bufferQueue->dequeueBuffer();
EXPECT_TRUE(buffer != nullptr);
- bool ret = bufferQueue->enqueueBuffer(buffer);
- EXPECT_TRUE(ret);
+ EXPECT_TRUE(bufferQueue->enqueueBuffer(buffer));
}
TEST_F(DSBufferTBMImplTest, AcquireBuffer)
std::unique_ptr<IDSBufferQueue> bufferQueue = std::make_unique<DSBufferQueueTBMImpl>(3, 100, 100, IDSBuffer::FORMAT_ARGB8888);
EXPECT_TRUE(bufferQueue.get() != nullptr);
- IDSBuffer *buffer1 = bufferQueue->dequeueBuffer();
+ std::shared_ptr<IDSBuffer> buffer1 = bufferQueue->dequeueBuffer();
EXPECT_TRUE(buffer1 != nullptr);
- bool ret1 = bufferQueue->enqueueBuffer(buffer1);
- EXPECT_TRUE(ret1);
- IDSBuffer *buffer2 = bufferQueue->acquireBuffer();
+ EXPECT_TRUE(bufferQueue->enqueueBuffer(buffer1));
+ std::shared_ptr<IDSBuffer> buffer2 = bufferQueue->acquireBuffer();
EXPECT_TRUE(buffer2 != nullptr);
}
std::unique_ptr<IDSBufferQueue> bufferQueue = std::make_unique<DSBufferQueueTBMImpl>(3, 100, 100, IDSBuffer::FORMAT_ARGB8888);
EXPECT_TRUE(bufferQueue.get() != nullptr);
- IDSBuffer *buffer1 = bufferQueue->dequeueBuffer();
+ std::shared_ptr<IDSBuffer> buffer1 = bufferQueue->dequeueBuffer();
EXPECT_TRUE(buffer1 != nullptr);
- bool ret1 = bufferQueue->enqueueBuffer(buffer1);
- EXPECT_TRUE(ret1);
- IDSBuffer *buffer2 = bufferQueue->acquireBuffer();
+ EXPECT_TRUE(bufferQueue->enqueueBuffer(buffer1));
+ std::shared_ptr<IDSBuffer> buffer2 = bufferQueue->acquireBuffer();
EXPECT_TRUE(buffer2 != nullptr);
- bool ret2 = bufferQueue->releaseBuffer(buffer2);
- EXPECT_TRUE(ret2);
+ EXPECT_TRUE(bufferQueue->releaseBuffer(buffer2));
+}
+
+TEST_F(DSBufferTBMImplTest, DequeueBuffer_4Times)
+{
+ std::unique_ptr<IDSBufferQueue> bufferQueue = std::make_unique<DSBufferQueueTBMImpl>(3, 100, 100, IDSBuffer::FORMAT_ARGB8888);
+ EXPECT_TRUE(bufferQueue.get() != nullptr);
+
+ std::shared_ptr<IDSBuffer> buffer1 = bufferQueue->dequeueBuffer();
+ EXPECT_TRUE(buffer1 != nullptr);
+ std::shared_ptr<IDSBuffer> buffer2 = bufferQueue->dequeueBuffer();
+ EXPECT_TRUE(buffer2 != nullptr);
+ std::shared_ptr<IDSBuffer> buffer3 = bufferQueue->dequeueBuffer();
+ EXPECT_TRUE(buffer3 != nullptr);
+ EXPECT_TRUE(bufferQueue->releaseBuffer(buffer1));
+ EXPECT_TRUE(bufferQueue->releaseBuffer(buffer2));
+ EXPECT_TRUE(bufferQueue->releaseBuffer(buffer3));
+
+ std::shared_ptr<IDSBuffer> buffer4 = bufferQueue->dequeueBuffer();
+ EXPECT_TRUE(buffer1.get() == buffer4.get());
+ std::shared_ptr<IDSBuffer> buffer5 = bufferQueue->dequeueBuffer();
+ EXPECT_TRUE(buffer2.get() == buffer5.get());
+ std::shared_ptr<IDSBuffer> buffer6 = bufferQueue->dequeueBuffer();
+ EXPECT_TRUE(buffer3.get() == buffer6.get());
+ EXPECT_TRUE(bufferQueue->releaseBuffer(buffer4));
+ EXPECT_TRUE(bufferQueue->releaseBuffer(buffer5));
+ EXPECT_TRUE(bufferQueue->releaseBuffer(buffer6));
}
\ No newline at end of file