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

Commit c79b7537 authored by Rob Carr's avatar Rob Carr Committed by Android (Google) Code Review
Browse files

Merge changes from topic "bbq-surface"

* changes:
  BLASTBufferQueue: Support setFrameRate
  BLASTBufferQueue: Handler allocateBuffers on thread.
parents b05b9099 9c006e03
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <gui/BLASTBufferQueue.h>
#include <gui/BufferItemConsumer.h>
#include <gui/GLConsumer.h>
#include <gui/Surface.h>

#include <utils/Trace.h>

@@ -352,4 +353,48 @@ bool BLASTBufferQueue::maxBuffersAcquired() const {
            (!mInitialCallbackReceived && mNumAcquired == 1);
}

class BBQSurface : public Surface {
private:
    sp<BLASTBufferQueue> mBbq;
public:
  BBQSurface(const sp<IGraphicBufferProducer>& igbp, bool controlledByApp,
      const sp<BLASTBufferQueue>& bbq) :
      Surface(igbp, controlledByApp),
      mBbq(bbq) {
    }

    void allocateBuffers() override {
        uint32_t reqWidth = mReqWidth ? mReqWidth : mUserWidth;
        uint32_t reqHeight = mReqHeight ? mReqHeight : mUserHeight;
        auto gbp = getIGraphicBufferProducer();
        std::thread ([reqWidth, reqHeight, gbp=getIGraphicBufferProducer(),
                      reqFormat=mReqFormat, reqUsage=mReqUsage] () {
            gbp->allocateBuffers(reqWidth, reqHeight,
                                 reqFormat, reqUsage);

        }).detach();
    }

    status_t setFrameRate(float frameRate, int8_t compatibility) override {
        if (!ValidateFrameRate(frameRate, compatibility, "BBQSurface::setFrameRate")) {
            return BAD_VALUE;
        }
        return mBbq->setFrameRate(frameRate, compatibility);
    }
};

// TODO: Can we coalesce this with frame updates? Need to confirm
// no timing issues.
status_t BLASTBufferQueue::setFrameRate(float frameRate, int8_t compatibility) {
    std::unique_lock _lock{mMutex};
    SurfaceComposerClient::Transaction t;

    return t.setFrameRate(mSurfaceControl, frameRate, compatibility)
        .apply();
}

sp<Surface> BLASTBufferQueue::getSurface() {
    return new BBQSurface(mProducer, true, this);
}

} // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public:
    sp<IGraphicBufferProducer> getIGraphicBufferProducer() const {
        return mProducer;
    }
    sp<Surface> getSurface();

    void onBufferFreed(const wp<GraphicBuffer>&/* graphicBuffer*/) override { /* TODO */ }
    void onFrameReplaced(const BufferItem& item) override {onFrameAvailable(item);}
@@ -84,6 +85,8 @@ public:
    void update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height);
    void flushShadowQueue() { mFlushShadowQueue = true; }

    status_t setFrameRate(float frameRate, int8_t compatibility);

    virtual ~BLASTBufferQueue() = default;

private:
+2 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public:
     * delay during dequeueBuffer. If there are already the maximum number of
     * buffers allocated, this function has no effect.
     */
    void allocateBuffers();
    virtual void allocateBuffers();

    /* Sets the generation number on the IGraphicBufferProducer and updates the
     * generation number on any buffers attached to the Surface after this call.
@@ -179,7 +179,7 @@ public:
    status_t getUniqueId(uint64_t* outId) const;
    status_t getConsumerUsage(uint64_t* outUsage) const;

    status_t setFrameRate(float frameRate, int8_t compatibility);
    virtual status_t setFrameRate(float frameRate, int8_t compatibility);

protected:
    virtual ~Surface();