Surface: expose allowAllocation method
This is required to make some clients of IGBP work with Surface. See
go/warren-buffers for more details.
BYPASS_IGBP_IGBC_API_REASON=warren buffers
Bug: 340933794
Flag: com.android.graphics.libgui.flags.wb_platform_api_improvements
Test: new test
Change-Id: I4a3150c9732fdeec2277457c5c476db657bb2299
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 97c0299..eb9faf5 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -163,6 +163,12 @@
mReqFormat, mReqUsage);
}
+#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
+status_t Surface::allowAllocation(bool allowAllocation) {
+ return mGraphicBufferProducer->allowAllocation(allowAllocation);
+}
+#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
+
status_t Surface::setGenerationNumber(uint32_t generation) {
status_t result = mGraphicBufferProducer->setGenerationNumber(generation);
if (result == NO_ERROR) {
diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h
index c470b2f..d07e121 100644
--- a/libs/gui/include/gui/Surface.h
+++ b/libs/gui/include/gui/Surface.h
@@ -167,6 +167,11 @@
*/
virtual void allocateBuffers();
+#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
+ // See IGraphicBufferProducer::allowAllocation
+ status_t allowAllocation(bool allowAllocation);
+#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
+
/* Sets the generation number on the IGraphicBufferProducer and updates the
* generation number on any buffers attached to the Surface after this call.
* See IGBP::setGenerationNumber for more information. */
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index 0aa5216..8d6917f 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -2286,6 +2286,32 @@
EXPECT_EQ(OK, surface->queueBuffer(heldTooLongBuffer));
EXPECT_EQ(BAD_VALUE, surface->detachBuffer(heldTooLongBuffer));
}
+
+TEST_F(SurfaceTest, AllowAllocation) {
+ sp<IGraphicBufferProducer> producer;
+ sp<IGraphicBufferConsumer> consumer;
+ BufferQueue::createBufferQueue(&producer, &consumer);
+
+ // controlledByApp must be true to disable blocking
+ sp<CpuConsumer> cpuConsumer = sp<CpuConsumer>::make(consumer, 1, /*controlledByApp*/ true);
+ sp<Surface> surface = sp<Surface>::make(producer, /*controlledByApp*/ true);
+ sp<StubSurfaceListener> listener = sp<StubSurfaceListener>::make();
+ sp<GraphicBuffer> buffer;
+ sp<Fence> fence;
+
+ EXPECT_EQ(OK,
+ surface->connect(NATIVE_WINDOW_API_CPU, listener, /* reportBufferRemoval */ false));
+ EXPECT_EQ(OK, surface->allowAllocation(false));
+
+ EXPECT_EQ(OK, surface->setDequeueTimeout(-1));
+ EXPECT_EQ(WOULD_BLOCK, surface->dequeueBuffer(&buffer, &fence));
+
+ EXPECT_EQ(OK, surface->setDequeueTimeout(10));
+ EXPECT_EQ(TIMED_OUT, surface->dequeueBuffer(&buffer, &fence));
+
+ EXPECT_EQ(OK, surface->allowAllocation(true));
+ EXPECT_EQ(OK, surface->dequeueBuffer(&buffer, &fence));
+}
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
} // namespace android