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

Commit 76f52cc2 authored by Jim Shargo's avatar Jim Shargo
Browse files

nativedisplay: ConsumerBase-based classes now create their own BufferQueues

Using ConsumerBase-based classes is now the recommended way to create
BufferQueues.

This is an important step for go/warren-buffers, because it consolidates
usages of BufferQueues to supported APIs and reduces the libgui API
surface that exposes IGBP/IGBC.

BYPASS_IGBP_IGBC_API_REASON: this CL is part of the migration.

Bug: 340933754
Flag: com.android.graphics.libgui.flags.wb_consumer_base_owns_bq
Test: atest, presubmit, compiles
Change-Id: I7592bec02a7fd7b1712dfd3bf47a61852136438f
parent 81ba7fb7
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -98,11 +98,25 @@ public:
     * is created in a detached state, and attachToContext must be called before
     * calls to updateTexImage.
     */
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    SurfaceTexture(uint32_t tex, uint32_t textureTarget, bool useFenceSync, bool isControlledByApp);

    SurfaceTexture(uint32_t textureTarget, bool useFenceSync, bool isControlledByApp);

    SurfaceTexture(const sp<IGraphicBufferConsumer>& bq, uint32_t tex, uint32_t textureTarget,
                   bool useFenceSync, bool isControlledByApp)
            __attribute((deprecated("Prefer ctors that create their own surface and consumer.")));

    SurfaceTexture(const sp<IGraphicBufferConsumer>& bq, uint32_t textureTarget, bool useFenceSync,
                   bool isControlledByApp)
            __attribute((deprecated("Prefer ctors that create their own surface and consumer.")));
#else
    SurfaceTexture(const sp<IGraphicBufferConsumer>& bq, uint32_t tex, uint32_t textureTarget,
                   bool useFenceSync, bool isControlledByApp);

    SurfaceTexture(const sp<IGraphicBufferConsumer>& bq, uint32_t textureTarget, bool useFenceSync,
                   bool isControlledByApp);
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)

    /**
     * updateTexImage acquires the most recently queued buffer, and sets the
@@ -499,6 +513,8 @@ protected:
    friend class EGLConsumer;

private:
    void initialize();

    // Proxy listener to avoid having SurfaceTexture directly implement FrameAvailableListener as it
    // is extending ConsumerBase which also implements FrameAvailableListener.
    class FrameAvailableListenerProxy : public ConsumerBase::FrameAvailableListener {
+53 −10
Original line number Diff line number Diff line
@@ -35,6 +35,49 @@ namespace android {

static const mat4 mtxIdentity;

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
SurfaceTexture::SurfaceTexture(uint32_t tex, uint32_t texTarget, bool useFenceSync,
                               bool isControlledByApp)
      : ConsumerBase(isControlledByApp),
        mCurrentCrop(Rect::EMPTY_RECT),
        mCurrentTransform(0),
        mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
        mCurrentFence(Fence::NO_FENCE),
        mCurrentTimestamp(0),
        mCurrentDataSpace(HAL_DATASPACE_UNKNOWN),
        mCurrentFrameNumber(0),
        mDefaultWidth(1),
        mDefaultHeight(1),
        mFilteringEnabled(true),
        mTexName(tex),
        mUseFenceSync(useFenceSync),
        mTexTarget(texTarget),
        mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
        mOpMode(OpMode::attachedToGL) {
    initialize();
}

SurfaceTexture::SurfaceTexture(uint32_t texTarget, bool useFenceSync, bool isControlledByApp)
      : ConsumerBase(isControlledByApp),
        mCurrentCrop(Rect::EMPTY_RECT),
        mCurrentTransform(0),
        mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
        mCurrentFence(Fence::NO_FENCE),
        mCurrentTimestamp(0),
        mCurrentDataSpace(HAL_DATASPACE_UNKNOWN),
        mCurrentFrameNumber(0),
        mDefaultWidth(1),
        mDefaultHeight(1),
        mFilteringEnabled(true),
        mTexName(0),
        mUseFenceSync(useFenceSync),
        mTexTarget(texTarget),
        mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
        mOpMode(OpMode::detached) {
    initialize();
}
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)

SurfaceTexture::SurfaceTexture(const sp<IGraphicBufferConsumer>& bq, uint32_t tex,
                               uint32_t texTarget, bool useFenceSync, bool isControlledByApp)
      : ConsumerBase(bq, isControlledByApp),
@@ -53,11 +96,7 @@ SurfaceTexture::SurfaceTexture(const sp<IGraphicBufferConsumer>& bq, uint32_t te
        mTexTarget(texTarget),
        mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
        mOpMode(OpMode::attachedToGL) {
    SFT_LOGV("SurfaceTexture");

    memcpy(mCurrentTransformMatrix, mtxIdentity.asArray(), sizeof(mCurrentTransformMatrix));

    mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
    initialize();
}

SurfaceTexture::SurfaceTexture(const sp<IGraphicBufferConsumer>& bq, uint32_t texTarget,
@@ -78,11 +117,7 @@ SurfaceTexture::SurfaceTexture(const sp<IGraphicBufferConsumer>& bq, uint32_t te
        mTexTarget(texTarget),
        mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
        mOpMode(OpMode::detached) {
    SFT_LOGV("SurfaceTexture");

    memcpy(mCurrentTransformMatrix, mtxIdentity.asArray(), sizeof(mCurrentTransformMatrix));

    mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
    initialize();
}

status_t SurfaceTexture::setDefaultBufferSize(uint32_t w, uint32_t h) {
@@ -531,4 +566,12 @@ void SurfaceTexture::onSetFrameRate(float frameRate, int8_t compatibility,
}
#endif

void SurfaceTexture::initialize() {
    SFT_LOGV("SurfaceTexture");

    memcpy(mCurrentTransformMatrix, mtxIdentity.asArray(), sizeof(mCurrentTransformMatrix));

    mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
}

} // namespace android