currentTexture = mCurrentTexture; pendingRelease->graphicBuffer = mCurrentTextureBuffer"> currentTexture = mCurrentTexture; pendingRelease->graphicBuffer = mCurrentTextureBuffer"> currentTexture = mCurrentTexture; pendingRelease->graphicBuffer = mCurrentTextureBuffer">
status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
                                                     PendingRelease* pendingRelease) {
    ...
    int slot = item.mSlot;
    std::shared_ptr<Image> nextTextureBuffer;
    {
        std::lock_guard<std::mutex> lock(mImagesMutex);
        nextTextureBuffer = mImages[slot];
    }

    if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
        if (pendingRelease == nullptr) {
            status_t status =
                    releaseBufferLocked(mCurrentTexture, mCurrentTextureBuffer->graphicBuffer());
            if (status < NO_ERROR) {
                BLC_LOGE("updateAndRelease: failed to release buffer: %s (%d)", strerror(-status),
                         status);
                err = status;
                // keep going, with error raised [?]
            }
        } else {
            pendingRelease->currentTexture = mCurrentTexture;
            pendingRelease->graphicBuffer = mCurrentTextureBuffer->graphicBuffer();
            pendingRelease->isPending = true;
        }
    }

    // Update the BufferLayerConsumer state.
    mCurrentTexture = slot;
    mCurrentTextureBuffer = nextTextureBuffer;
    mCurrentCrop = item.mCrop;
    mCurrentTransform = item.mTransform;
    mCurrentScalingMode = item.mScalingMode;
    mCurrentTimestamp = item.mTimestamp;
    mCurrentDataSpace = static_cast<ui::Dataspace>(item.mDataSpace);
    mCurrentHdrMetadata = item.mHdrMetadata;
    mCurrentFence = item.mFence;
    mCurrentFenceTime = item.mFenceTime;
    mCurrentFrameNumber = item.mFrameNumber;
    mCurrentTransformToDisplayInverse = item.mTransformToDisplayInverse;
    mCurrentSurfaceDamage = item.mSurfaceDamage;
    mCurrentApi = item.mApi;

    computeCurrentTransformMatrixLocked();

    return err;
}

先更新 nextTextureBuffer。如果 mCurrentTexture 不等于 INVALID_BUFFER_SLOT,说明需要释放 buffer。如果 pendingRelease 是空指针,则调用 ConsumerBase::releaseBufferLocked() 释放 buffer,否则给 pendingRelease 成员赋值。

最后更新 mCurrentX 成员。其中 mCurrentTextureBuffer 中引用 GraphicBuffer,该成员在 BufferLayerConsumer::bindTextureImageLocked() 中使用。