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

Commit f6f61aa4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "C2HIDL: handle consumer side attach from Surface" into main

parents 2ba5979a c33a058f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ private:
    uint64_t mBqId;
    int32_t mMaxDequeueBufferCount;
    std::shared_ptr<int> mOwner;
    std::shared_ptr<int> mConsumerAttachCount;
    // To migrate existing buffers
    sp<GraphicBuffer> mBuffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; // find a better way
    std::weak_ptr<_C2BlockPoolData> mPoolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS];
+33 −3
Original line number Diff line number Diff line
@@ -261,6 +261,7 @@ bool OutputBufferQueue::configure(const sp<IGraphicBufferProducer>& igbp,
        mGeneration = generation;
        mBqId = bqId;
        mOwner = std::make_shared<int>(0);
        mConsumerAttachCount = std::make_shared<int>(0);
        mMaxDequeueBufferCount = maxDequeueBufferCount;
        if (igbp == nullptr) {
            return false;
@@ -522,6 +523,7 @@ void OutputBufferQueue::onBufferReleased(uint32_t generation) {
    std::shared_ptr<C2SurfaceSyncMemory> syncMem;
    sp<IGraphicBufferProducer> outputIgbp;
    uint32_t outputGeneration = 0;
    std::shared_ptr<int> consumerAttachCount;
    {
        std::unique_lock<std::mutex> l(mMutex);
        if (mStopped) {
@@ -529,6 +531,7 @@ void OutputBufferQueue::onBufferReleased(uint32_t generation) {
        }
        outputIgbp = mIgbp;
        outputGeneration = mGeneration;
        consumerAttachCount = mConsumerAttachCount;
        syncMem = mSyncMem;
    }

@@ -536,15 +539,42 @@ void OutputBufferQueue::onBufferReleased(uint32_t generation) {
        auto syncVar = syncMem ? syncMem->mem() : nullptr;
        if (syncVar) {
            syncVar->lock();
            if (consumerAttachCount && *consumerAttachCount > 0) {
                (*consumerAttachCount)--;
            } else {
                syncVar->notifyQueuedLocked();
            }
            syncVar->unlock();
        }
    }
}

void OutputBufferQueue::onBufferAttached(uint32_t generation) {
    // TODO
    (void) generation;
    std::shared_ptr<C2SurfaceSyncMemory> syncMem;
    sp<IGraphicBufferProducer> outputIgbp;
    uint32_t outputGeneration = 0;
    std::shared_ptr<int> consumerAttachCount;
    {
        std::unique_lock<std::mutex> l(mMutex);
        if (mStopped) {
            return;
        }
        outputIgbp = mIgbp;
        outputGeneration = mGeneration;
        consumerAttachCount = mConsumerAttachCount;
        syncMem = mSyncMem;
    }

    if (outputIgbp && generation == outputGeneration) {
        auto syncVar = syncMem ? syncMem->mem() : nullptr;
        if (syncVar) {
            syncVar->lock();
            if (consumerAttachCount) {
                (*consumerAttachCount)++;
            }
            syncVar->unlock();
        }
    }
}

void OutputBufferQueue::pollForRenderedFrames(FrameEventHistoryDelta* delta) {