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

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

BufferItemConsumer: Make creation calls flag-agnostic

It's really annoying to work with these right now since clients have to
juggle two flag-guarded constructors. Instead, add a static create
function that returns a BIC and a Surface.

Also removes flag guards around ConsumerBase::setConsumerIsProtected,
which was never necessary and makes it possible to migrate clients away
from this flag in their code.

BYPASS_IGBP_IGBC_API_REASON=warren buffers

Bug: 398822412
Flag: EXEMPT refactor
Test: compiles, presubmit
Change-Id: I045a8ba804928623fcf7c430be245fd6f2e70bb1
parent f4fb3287
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <com_android_graphics_libgui_flags.h>
#include <gui/BufferItem.h>
#include <gui/BufferItemConsumer.h>
#include <gui/Surface.h>
#include <ui/BufferQueueDefs.h>
#include <ui/GraphicBuffer.h>

@@ -35,6 +36,30 @@

namespace android {

std::tuple<sp<BufferItemConsumer>, sp<Surface>> BufferItemConsumer::create(
        uint64_t consumerUsage, int bufferCount, bool controlledByApp,
        bool isConsumerSurfaceFlinger) {
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    sp<BufferItemConsumer> bufferItemConsumer =
            sp<BufferItemConsumer>::make(consumerUsage, bufferCount, controlledByApp,
                                         isConsumerSurfaceFlinger);
    return {bufferItemConsumer, bufferItemConsumer->getSurface()};
#else
    sp<IGraphicBufferProducer> igbp;
    sp<IGraphicBufferConsumer> igbc;
    BufferQueue::createBufferQueue(&igbp, &igbc, isConsumerSurfaceFlinger);
    sp<BufferItemConsumer> bufferItemConsumer =
            sp<BufferItemConsumer>::make(igbc, consumerUsage, bufferCount, controlledByApp);
    return {bufferItemConsumer, sp<Surface>::make(igbp, controlledByApp)};
#endif
}

sp<BufferItemConsumer> BufferItemConsumer::create(const sp<IGraphicBufferConsumer>& consumer,
                                                  uint64_t consumerUsage, int bufferCount,
                                                  bool controlledByApp) {
    return sp<BufferItemConsumer>::make(consumer, consumerUsage, bufferCount, controlledByApp);
}

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
BufferItemConsumer::BufferItemConsumer(uint64_t consumerUsage, int bufferCount,
                                       bool controlledByApp, bool isConsumerSurfaceFlinger)
+0 −2
Original line number Diff line number Diff line
@@ -480,7 +480,6 @@ status_t ConsumerBase::setMaxAcquiredBufferCount(int maxAcquiredBuffers) {
    return mConsumer->setMaxAcquiredBufferCount(maxAcquiredBuffers);
}

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
status_t ConsumerBase::setConsumerIsProtected(bool isProtected) {
    Mutex::Autolock lock(mMutex);
    if (mAbandoned) {
@@ -489,7 +488,6 @@ status_t ConsumerBase::setConsumerIsProtected(bool isProtected) {
    }
    return mConsumer->setConsumerIsProtected(isProtected);
}
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)

sp<NativeHandle> ConsumerBase::getSidebandStream() const {
    Mutex::Autolock _l(mMutex);
+10 −0
Original line number Diff line number Diff line
@@ -47,6 +47,16 @@ class BufferItemConsumer: public ConsumerBase
    enum { INVALID_BUFFER_SLOT = BufferQueue::INVALID_BUFFER_SLOT };
    enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE };

    static std::tuple<sp<BufferItemConsumer>, sp<Surface>> create(
            uint64_t consumerUsage, int bufferCount = DEFAULT_MAX_BUFFERS,
            bool controlledByApp = false, bool isConsumerSurfaceFlinger = false);

    static sp<BufferItemConsumer> create(const sp<IGraphicBufferConsumer>& consumer,
                                         uint64_t consumerUsage,
                                         int bufferCount = DEFAULT_MAX_BUFFERS,
                                         bool controlledByApp = false)
            __attribute((deprecated("Prefer ctors that create their own surface and consumer.")));

    // Create a new buffer item consumer. The consumerUsage parameter determines
    // the consumer usage flags passed to the graphics allocator. The
    // bufferCount parameter specifies how many buffers can be locked for user
+0 −2
Original line number Diff line number Diff line
@@ -123,9 +123,7 @@ public:
    // See IGraphicBufferConsumer::setMaxAcquiredBufferCount
    status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers);

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    status_t setConsumerIsProtected(bool isProtected);
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)

    // See IGraphicBufferConsumer::getSidebandStream
    sp<NativeHandle> getSidebandStream() const;
+3 −2
Original line number Diff line number Diff line
@@ -62,14 +62,15 @@ class BufferItemConsumerTest : public ::testing::Test {
    void SetUp() override {
        mBuffers.resize(BufferQueueDefs::NUM_BUFFER_SLOTS);

        mBIC = new BufferItemConsumer(kUsage, kMaxLockedBuffers, true);
        sp<Surface> surface;
        std::tie(mBIC, surface) = BufferItemConsumer::create(kUsage, kMaxLockedBuffers, true);
        String8 name("BufferItemConsumer_Under_Test");
        mBIC->setName(name);
        mBFL = new BufferFreedListener(this);
        mBIC->setBufferFreedListener(mBFL);

        sp<IProducerListener> producerListener = new TrackingProducerListener(this);
        mProducer = mBIC->getSurface()->getIGraphicBufferProducer();
        mProducer = surface->getIGraphicBufferProducer();
        IGraphicBufferProducer::QueueBufferOutput bufferOutput;
        ASSERT_EQ(NO_ERROR,
                  mProducer->connect(producerListener, NATIVE_WINDOW_API_CPU,
Loading