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
diff --git a/include/gui/GraphicBufferAlloc.h b/include/gui/GraphicBufferAlloc.h
index 69fe51e..62e3877 100644
--- a/include/gui/GraphicBufferAlloc.h
+++ b/include/gui/GraphicBufferAlloc.h
@@ -35,7 +35,7 @@
     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;
 };
 
 
diff --git a/include/gui/IGraphicBufferAlloc.h b/include/gui/IGraphicBufferAlloc.h
index f3c46ec..600cf27 100644
--- a/include/gui/IGraphicBufferAlloc.h
+++ b/include/gui/IGraphicBufferAlloc.h
@@ -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 @@
     /* 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);
+    }
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/ui/GraphicBuffer.h b/include/ui/GraphicBuffer.h
index 3da720f..3e127a1 100644
--- a/include/ui/GraphicBuffer.h
+++ b/include/ui/GraphicBuffer.h
@@ -26,6 +26,7 @@
 #include <utils/Flattenable.h>
 #include <utils/RefBase.h>
 
+#include <string>
 
 struct ANativeWindowBuffer;
 
@@ -73,7 +74,7 @@
 
     // 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 @@
     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();
 
diff --git a/include/ui/GraphicBufferAllocator.h b/include/ui/GraphicBufferAllocator.h
index 62ebbd5..28d0238 100644
--- a/include/ui/GraphicBufferAllocator.h
+++ b/include/ui/GraphicBufferAllocator.h
@@ -61,7 +61,7 @@
 
     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 @@
         PixelFormat format;
         uint32_t usage;
         size_t size;
+        std::string requestorName;
     };
 
     static Mutex sLock;