diff options
| author | 2023-03-13 18:41:23 +0000 | |
|---|---|---|
| committer | 2023-03-13 18:41:23 +0000 | |
| commit | 1427779de67824e59ee83963e9c19e29489ca347 (patch) | |
| tree | e91c82e8a58b00e19d0e7faaa519c4b9b4cac7d3 /libs/gui/BLASTBufferQueue.cpp | |
| parent | 008cdaf9b1623dc2573138d9b3ee880e45352a42 (diff) | |
| parent | 3c38ba37e600adcbe05a874426a08237fd737363 (diff) | |
Merge "Increase frame history size when SF buffer queue size changes"
Diffstat (limited to 'libs/gui/BLASTBufferQueue.cpp')
| -rw-r--r-- | libs/gui/BLASTBufferQueue.cpp | 45 | 
1 files changed, 42 insertions, 3 deletions
| diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index 1242ac83e3..0e3fd4f452 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -132,6 +132,11 @@ void BLASTBufferItemConsumer::onSidebandStreamChanged() {      }  } +void BLASTBufferItemConsumer::resizeFrameEventHistory(size_t newSize) { +    Mutex::Autolock lock(mMutex); +    mFrameEventHistory.resize(newSize); +} +  BLASTBufferQueue::BLASTBufferQueue(const std::string& name, bool updateDestinationFrame)        : mSurfaceControl(nullptr),          mSize(1, 1), @@ -1031,8 +1036,9 @@ public:  // can be non-blocking when the producer is in the client process.  class BBQBufferQueueProducer : public BufferQueueProducer {  public: -    BBQBufferQueueProducer(const sp<BufferQueueCore>& core) -          : BufferQueueProducer(core, false /* consumerIsSurfaceFlinger*/) {} +    BBQBufferQueueProducer(const sp<BufferQueueCore>& core, wp<BLASTBufferQueue> bbq) +          : BufferQueueProducer(core, false /* consumerIsSurfaceFlinger*/), +            mBLASTBufferQueue(std::move(bbq)) {}      status_t connect(const sp<IProducerListener>& listener, int api, bool producerControlledByApp,                       QueueBufferOutput* output) override { @@ -1044,6 +1050,26 @@ public:                                              producerControlledByApp, output);      } +    // We want to resize the frame history when changing the size of the buffer queue +    status_t setMaxDequeuedBufferCount(int maxDequeuedBufferCount) override { +        int maxBufferCount; +        status_t status = BufferQueueProducer::setMaxDequeuedBufferCount(maxDequeuedBufferCount, +                                                                         &maxBufferCount); +        // if we can't determine the max buffer count, then just skip growing the history size +        if (status == OK) { +            size_t newFrameHistorySize = maxBufferCount + 2; // +2 because triple buffer rendering +            // optimize away resizing the frame history unless it will grow +            if (newFrameHistorySize > FrameEventHistory::INITIAL_MAX_FRAME_HISTORY) { +                sp<BLASTBufferQueue> bbq = mBLASTBufferQueue.promote(); +                if (bbq != nullptr) { +                    ALOGV("increasing frame history size to %zu", newFrameHistorySize); +                    bbq->resizeFrameEventHistory(newFrameHistorySize); +                } +            } +        } +        return status; +    } +      int query(int what, int* value) override {          if (what == NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER) {              *value = 1; @@ -1051,6 +1077,9 @@ public:          }          return BufferQueueProducer::query(what, value);      } + +private: +    const wp<BLASTBufferQueue> mBLASTBufferQueue;  };  // Similar to BufferQueue::createBufferQueue but creates an adapter specific bufferqueue producer. @@ -1065,7 +1094,7 @@ void BLASTBufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer      sp<BufferQueueCore> core(new BufferQueueCore());      LOG_ALWAYS_FATAL_IF(core == nullptr, "BLASTBufferQueue: failed to create BufferQueueCore"); -    sp<IGraphicBufferProducer> producer(new BBQBufferQueueProducer(core)); +    sp<IGraphicBufferProducer> producer(new BBQBufferQueueProducer(core, this));      LOG_ALWAYS_FATAL_IF(producer == nullptr,                          "BLASTBufferQueue: failed to create BBQBufferQueueProducer"); @@ -1078,6 +1107,16 @@ void BLASTBufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer      *outConsumer = consumer;  } +void BLASTBufferQueue::resizeFrameEventHistory(size_t newSize) { +    // This can be null during creation of the buffer queue, but resizing won't do anything at that +    // point in time, so just ignore. This can go away once the class relationships and lifetimes of +    // objects are cleaned up with a major refactor of BufferQueue as a whole. +    if (mBufferItemConsumer != nullptr) { +        std::unique_lock _lock{mMutex}; +        mBufferItemConsumer->resizeFrameEventHistory(newSize); +    } +} +  PixelFormat BLASTBufferQueue::convertBufferFormat(PixelFormat& format) {      PixelFormat convertedFormat = format;      switch (format) { |