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

Commit a1d24b45 authored by Dan Stoza's avatar Dan Stoza
Browse files

Add requestor name to GraphicBuffer alloc metadata

Adds a requestor name (usually the BufferQueue consumer's name) to the
metadata that GraphicBufferAllocator stores on allocation so that
`dumpsys SurfaceFlinger` can attempt to attribute buffer usage to the
correct client.

Bug: 30776557
Change-Id: I6e0f346584c871bb3b9d5481f82b697b0475a916
parent b10cd895
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ public:
    virtual ~GraphicBufferAlloc();
    virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width,
            uint32_t height, PixelFormat format, uint32_t usage,
            status_t* error);
            std::string requestorName, status_t* error) override;
};


+10 −3
Original line number Diff line number Diff line
@@ -21,14 +21,15 @@
#include <sys/types.h>

#include <binder/IInterface.h>
#include <ui/GraphicBuffer.h>
#include <ui/PixelFormat.h>
#include <utils/RefBase.h>

#include <string>

namespace android {
// ----------------------------------------------------------------------------

class GraphicBuffer;

class IGraphicBufferAlloc : public IInterface
{
public:
@@ -37,7 +38,13 @@ public:
    /* Create a new GraphicBuffer for the client to use.
     */
    virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
            PixelFormat format, uint32_t usage, status_t* error) = 0;
            PixelFormat format, uint32_t usage, std::string requestorName,
            status_t* error) = 0;

    sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
            PixelFormat format, uint32_t usage, status_t* error) {
        return createGraphicBuffer(w, h, format, usage, "<Unknown>", error);
    }
};

// ----------------------------------------------------------------------------
+3 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <utils/Flattenable.h>
#include <utils/RefBase.h>

#include <string>

struct ANativeWindowBuffer;

@@ -73,7 +74,7 @@ public:

    // creates w * h buffer
    GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
            uint32_t inUsage);
            uint32_t inUsage, std::string requestorName = "<Unknown>");

    // create a buffer from an existing handle
    GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
@@ -159,7 +160,7 @@ private:
    const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;

    status_t initSize(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
            uint32_t inUsage);
            uint32_t inUsage, std::string requestorName);

    void free_handle();

+2 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ public:

    status_t allocate(uint32_t w, uint32_t h, PixelFormat format,
            uint32_t usage, buffer_handle_t* handle, uint32_t* stride,
            uint64_t graphicBufferId);
            uint64_t graphicBufferId, std::string requestorName);

    status_t free(buffer_handle_t handle);

@@ -76,6 +76,7 @@ private:
        PixelFormat format;
        uint32_t usage;
        size_t size;
        std::string requestorName;
    };

    static Mutex sLock;
+4 −2
Original line number Diff line number Diff line
@@ -496,7 +496,8 @@ status_t BufferQueueProducer::dequeueBuffer(int *outSlot,
        status_t error;
        BQ_LOGV("dequeueBuffer: allocating a new buffer for slot %d", *outSlot);
        sp<GraphicBuffer> graphicBuffer(mCore->mAllocator->createGraphicBuffer(
                width, height, format, usage, &error));
                width, height, format, usage,
                {mConsumerName.string(), mConsumerName.size()}, &error));
        { // Autolock scope
            Mutex::Autolock lock(mCore->mMutex);

@@ -1262,7 +1263,8 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height,
        for (size_t i = 0; i <  newBufferCount; ++i) {
            status_t result = NO_ERROR;
            sp<GraphicBuffer> graphicBuffer(mCore->mAllocator->createGraphicBuffer(
                    allocWidth, allocHeight, allocFormat, allocUsage, &result));
                    allocWidth, allocHeight, allocFormat, allocUsage,
                    {mConsumerName.string(), mConsumerName.size()}, &result));
            if (result != NO_ERROR) {
                BQ_LOGE("allocateBuffers: failed to allocate buffer (%u x %u, format"
                        " %u, usage %u)", width, height, format, usage);
Loading