Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e77d47e5 authored by Jim Shargo's avatar Jim Shargo
Browse files

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
parent 00886398
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -163,6 +163,12 @@ void Surface::allocateBuffers() {
            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) {
+5 −0
Original line number Diff line number Diff line
@@ -167,6 +167,11 @@ public:
     */
    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. */
+26 −0
Original line number Diff line number Diff line
@@ -2286,6 +2286,32 @@ TEST_F(SurfaceTest, PlatformBufferMethods) {
    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