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

Commit 673134ed authored by Robert Carr's avatar Robert Carr
Browse files

Add ScreenshotClient functionality for returning GraphicBuffer.

WM and SysUI are interested in screenshotting to GraphicBuffer, for
zero copy initialization of Starting Windows and usage in SysUI. Both
codepaths are co-existing in the WM now, so existing screenshot APIs
are not cleaned up, though perhaps they could be soon.

Test: Manual in combination with other branches.
Bug: 31339431
Change-Id: I11151f44eddbba53559befebf5ee2bde1dee9b40
parent ff0a399e
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -214,7 +214,13 @@ public:
            Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
            uint32_t minLayerZ, uint32_t maxLayerZ,
            bool useIdentityTransform);

    static status_t captureToBuffer(
            const sp<IBinder>& display,
            Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
            uint32_t minLayerZ, uint32_t maxLayerZ,
            bool useIdentityTransform,
            uint32_t rotation,
            sp<GraphicBuffer>* outbuffer);
private:
    mutable sp<CpuConsumer> mCpuConsumer;
    mutable sp<IGraphicBufferProducer> mProducer;
+28 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@

#include <ui/DisplayInfo.h>

#include <gui/BufferItemConsumer.h>
#include <gui/CpuConsumer.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/ISurfaceComposer.h>
@@ -859,6 +860,33 @@ status_t ScreenshotClient::capture(
            reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
}

status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
        Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
        uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform,
        uint32_t rotation,
        sp<GraphicBuffer>* outBuffer) {
    sp<ISurfaceComposer> s(ComposerService::getComposerService());
    if (s == NULL) return NO_INIT;

    sp<IGraphicBufferConsumer> gbpConsumer;
    sp<IGraphicBufferProducer> producer;
    BufferQueue::createBufferQueue(&producer, &gbpConsumer);
    sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
           GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
           1, true));

    status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
            minLayerZ, maxLayerZ, useIdentityTransform,
            static_cast<ISurfaceComposer::Rotation>(rotation));
    if (ret != NO_ERROR) {
        return ret;
    }
    BufferItem b;
    consumer->acquireBuffer(&b, 0, true);
    *outBuffer = b.mGraphicBuffer;
    return ret;
}

ScreenshotClient::ScreenshotClient()
    : mHaveBuffer(false) {
    memset(&mBuffer, 0, sizeof(mBuffer));