OSDN Git Service

libgui: Fix attaching buffers without allocation
authorDan Stoza <stoza@google.com>
Tue, 5 Jan 2016 01:01:02 +0000 (17:01 -0800)
committerDan Stoza <stoza@google.com>
Tue, 5 Jan 2016 23:03:04 +0000 (15:03 -0800)
commit5ecfb68ffd63d352df0392dca6e95ef67a66c679
tree2eac3e11bdf561ba7b41079747ba340dfed2e3e2
parent127fc63e8a15366b4395f1363e8e18eb058d1709
libgui: Fix attaching buffers without allocation

This changes the way that BufferQueue selects slots in
waitForFreeSlotThenRelock. This method is called from both
dequeueBuffer and attachBuffer, but those two methods actually have
different preferences:

dequeueBuffer wants a slot with a buffer if possible (to avoid
unnecessary allocations), but will settle for a slot without a buffer
if no free buffers are available.

attachBuffer wants a slot without a buffer if possible (to avoid
clobbering an existing buffer), but will settle with clobbering a free
buffer if no empty slots are available.

These preferences are now respected, which has the side-effect of
fixing a bug where it was not possible to attach a buffer if allocation
is disabled (since the previous implementation assumed finding a slot
without a buffer meant that the caller intended to allocate a buffer,
which would accordingly be blocked since allocation is disabled).

Bug: 26387372
Change-Id: Iefd550fd01925d8c51d6f062d5708d1f6d517edd
include/gui/BufferQueueProducer.h
libs/gui/BufferQueueProducer.cpp
libs/gui/tests/BufferQueue_test.cpp