diff options
author | Jiwen 'Steve' Cai <jwcai@google.com> | 2017-08-04 17:34:37 -0700 |
---|---|---|
committer | Jiwen 'Steve' Cai <jwcai@google.com> | 2017-08-07 15:34:44 -0700 |
commit | 005f45d7bb059c0ef8d69f1cac81bca4f70852af (patch) | |
tree | 3f51a233a453ea63494c8f5e8d782ed611ae2210 /libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp | |
parent | 6aa5b4e7fdaa86a76e00e2508d7122e59cbd2aa2 (diff) |
BufferHubQueueProducer reset buffers on disconnect
When Surface.cpp disconnects a IGraphicBufferProducer, it clears up all
the buffer cache it holds. Thus our implementation should do the same.
New tests:
1/ BufferHubQueueProducerTest.ConnectDisconnectReconnect: tests
IGraphicBufferProducer to behave proper after disconnect and
re-connect.
2/ BufferHubQueueTest.TestFreeAllBuffers: tests BufferHubQueue handles
FreeAllBuffers() properly under different producer/consumer state.
Bug: 64402829
Test: Pause and resume GVR video player demo and observer no more fails
around IGraphicBufferProducer::requestBuffer and Surface::dequeueBuffer.
Change-Id: Ia61e3f991248135cecf22039045f6960226bda42
Diffstat (limited to 'libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp')
-rw-r--r-- | libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp index bfb9a55e93..f9f87ff1b8 100644 --- a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp +++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp @@ -417,6 +417,28 @@ void BufferHubQueue::SetBufferRemovedCallback(BufferRemovedCallback callback) { on_buffer_removed_ = callback; } +pdx::Status<void> BufferHubQueue::FreeAllBuffers() { + // Clear all available buffers. + available_buffers_.Clear(); + + pdx::Status<void> last_error; // No error. + // Clear all buffers this producer queue is tracking. + for (size_t slot = 0; slot < BufferHubQueue::kMaxQueueCapacity; slot++) { + if (buffers_[slot] != nullptr) { + auto status = RemoveBuffer(slot); + if (!status) { + ALOGE( + "ProducerQueue::FreeAllBuffers: Failed to remove buffer at " + "slot=%d.", + slot); + last_error = status.error_status(); + } + } + } + + return last_error; +} + ProducerQueue::ProducerQueue(LocalChannelHandle handle) : BASE(std::move(handle)) { auto status = ImportQueue(); |