libgui: Remove custom allocator from tests
The StreamSplitter test used a custom allocator to ensure that only one
GraphicBuffer was ever allocated during the test run. Now we can ensure
that by disabling allocation on the relevant BufferQueues after
allocating that one buffer, so the custom allocator is unnecessary.
Change-Id: I98289bda669c50a93ba9b70ceca1781203ad83b2
diff --git a/libs/gui/tests/StreamSplitter_test.cpp b/libs/gui/tests/StreamSplitter_test.cpp
index c7ce263..498492e 100644
--- a/libs/gui/tests/StreamSplitter_test.cpp
+++ b/libs/gui/tests/StreamSplitter_test.cpp
@@ -52,42 +52,16 @@
virtual void onSidebandStreamChanged() {}
};
-class CountedAllocator : public BnGraphicBufferAlloc {
-public:
- CountedAllocator() : mAllocCount(0) {
- sp<ISurfaceComposer> composer(ComposerService::getComposerService());
- mAllocator = composer->createGraphicBufferAlloc();
- }
-
- virtual ~CountedAllocator() {}
-
- virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
- PixelFormat format, uint32_t usage, status_t* error) {
- ++mAllocCount;
- sp<GraphicBuffer> buffer = mAllocator->createGraphicBuffer(w, h, format,
- usage, error);
- return buffer;
- }
-
- int getAllocCount() const { return mAllocCount; }
-
-private:
- sp<IGraphicBufferAlloc> mAllocator;
- int mAllocCount;
-};
-
static const uint32_t TEST_DATA = 0x12345678u;
TEST_F(StreamSplitterTest, OneInputOneOutput) {
- sp<CountedAllocator> allocator(new CountedAllocator);
-
sp<IGraphicBufferProducer> inputProducer;
sp<IGraphicBufferConsumer> inputConsumer;
- BufferQueue::createBufferQueue(&inputProducer, &inputConsumer, allocator);
+ BufferQueue::createBufferQueue(&inputProducer, &inputConsumer);
sp<IGraphicBufferProducer> outputProducer;
sp<IGraphicBufferConsumer> outputConsumer;
- BufferQueue::createBufferQueue(&outputProducer, &outputConsumer, allocator);
+ BufferQueue::createBufferQueue(&outputProducer, &outputConsumer);
ASSERT_EQ(OK, outputConsumer->consumerConnect(new DummyListener, false));
sp<StreamSplitter> splitter;
@@ -95,6 +69,9 @@
ASSERT_EQ(OK, status);
ASSERT_EQ(OK, splitter->addOutput(outputProducer));
+ // Never allow the output BufferQueue to allocate a buffer
+ ASSERT_EQ(OK, outputProducer->allowAllocation(false));
+
IGraphicBufferProducer::QueueBufferOutput qbOutput;
ASSERT_EQ(OK, inputProducer->connect(new DummyProducerListener,
NATIVE_WINDOW_API_CPU, false, &qbOutput));
@@ -118,6 +95,10 @@
NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, Fence::NO_FENCE);
ASSERT_EQ(OK, inputProducer->queueBuffer(slot, qbInput, &qbOutput));
+ // Now that we have dequeued/allocated one buffer, prevent any further
+ // allocations
+ ASSERT_EQ(OK, inputProducer->allowAllocation(false));
+
BufferItem item;
ASSERT_EQ(OK, outputConsumer->acquireBuffer(&item, 0));
@@ -130,26 +111,25 @@
ASSERT_EQ(OK, outputConsumer->releaseBuffer(item.mSlot, item.mFrameNumber,
EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, Fence::NO_FENCE));
+ // This should succeed even with allocation disabled since it will have
+ // received the buffer back from the output BufferQueue
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
inputProducer->dequeueBuffer(&slot, &fence, 0, 0, 0,
GRALLOC_USAGE_SW_WRITE_OFTEN));
-
- ASSERT_EQ(1, allocator->getAllocCount());
}
TEST_F(StreamSplitterTest, OneInputMultipleOutputs) {
const int NUM_OUTPUTS = 4;
- sp<CountedAllocator> allocator(new CountedAllocator);
sp<IGraphicBufferProducer> inputProducer;
sp<IGraphicBufferConsumer> inputConsumer;
- BufferQueue::createBufferQueue(&inputProducer, &inputConsumer, allocator);
+ BufferQueue::createBufferQueue(&inputProducer, &inputConsumer);
sp<IGraphicBufferProducer> outputProducers[NUM_OUTPUTS] = {};
sp<IGraphicBufferConsumer> outputConsumers[NUM_OUTPUTS] = {};
for (int output = 0; output < NUM_OUTPUTS; ++output) {
BufferQueue::createBufferQueue(&outputProducers[output],
- &outputConsumers[output], allocator);
+ &outputConsumers[output]);
ASSERT_EQ(OK, outputConsumers[output]->consumerConnect(
new DummyListener, false));
}
@@ -159,6 +139,9 @@
ASSERT_EQ(OK, status);
for (int output = 0; output < NUM_OUTPUTS; ++output) {
ASSERT_EQ(OK, splitter->addOutput(outputProducers[output]));
+
+ // Never allow the output BufferQueues to allocate a buffer
+ ASSERT_EQ(OK, outputProducers[output]->allowAllocation(false));
}
IGraphicBufferProducer::QueueBufferOutput qbOutput;
@@ -184,6 +167,10 @@
NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, Fence::NO_FENCE);
ASSERT_EQ(OK, inputProducer->queueBuffer(slot, qbInput, &qbOutput));
+ // Now that we have dequeued/allocated one buffer, prevent any further
+ // allocations
+ ASSERT_EQ(OK, inputProducer->allowAllocation(false));
+
for (int output = 0; output < NUM_OUTPUTS; ++output) {
BufferItem item;
ASSERT_EQ(OK, outputConsumers[output]->acquireBuffer(&item, 0));
@@ -199,11 +186,11 @@
Fence::NO_FENCE));
}
+ // This should succeed even with allocation disabled since it will have
+ // received the buffer back from the output BufferQueues
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
inputProducer->dequeueBuffer(&slot, &fence, 0, 0, 0,
GRALLOC_USAGE_SW_WRITE_OFTEN));
-
- ASSERT_EQ(1, allocator->getAllocCount());
}
TEST_F(StreamSplitterTest, OutputAbandonment) {