Squashed: gralloc1/binder/requestor
This is a combination of the following three commits:
libui: Convert Allocator and Mapper to gralloc1
Converts GraphicBufferAllocator and GraphicBufferMapper to speak
gralloc 1.0 (via the C++ shim and optionally the 1On0 adapter) instead
of gralloc 0.x.
-----
Create graphic buffer using binder interfaces
Using binder interfaces rather than directly allocating the buffer prevents
SELinux warnings.
-----
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: 28401203
Bug: 29402015
Bug: 30776557
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 5443f09..28d0238 100644
--- a/include/ui/GraphicBufferAllocator.h
+++ b/include/ui/GraphicBufferAllocator.h
@@ -27,42 +27,41 @@
#include <utils/threads.h>
#include <utils/Singleton.h>
+#include <ui/Gralloc1.h>
#include <ui/PixelFormat.h>
-#include <hardware/gralloc.h>
-
-
namespace android {
-// ---------------------------------------------------------------------------
+class Gralloc1Loader;
class String8;
class GraphicBufferAllocator : public Singleton<GraphicBufferAllocator>
{
public:
enum {
- USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER,
- USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
- USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
- USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
+ USAGE_SW_READ_NEVER = GRALLOC1_CONSUMER_USAGE_CPU_READ_NEVER,
+ USAGE_SW_READ_RARELY = GRALLOC1_CONSUMER_USAGE_CPU_READ,
+ USAGE_SW_READ_OFTEN = GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN,
+ USAGE_SW_READ_MASK = GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN,
- USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
- USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
- USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
- USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK,
+ USAGE_SW_WRITE_NEVER = GRALLOC1_PRODUCER_USAGE_CPU_WRITE_NEVER,
+ USAGE_SW_WRITE_RARELY = GRALLOC1_PRODUCER_USAGE_CPU_WRITE,
+ USAGE_SW_WRITE_OFTEN = GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN,
+ USAGE_SW_WRITE_MASK = GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN,
USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
- USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE,
- USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER,
- USAGE_HW_2D = GRALLOC_USAGE_HW_2D,
- USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK
+ USAGE_HW_TEXTURE = GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE,
+ USAGE_HW_RENDER = GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET,
+ USAGE_HW_2D = 0x00000400, // Deprecated
+ USAGE_HW_MASK = 0x00071F00, // Deprecated
};
static inline GraphicBufferAllocator& get() { return getInstance(); }
- status_t alloc(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage,
- buffer_handle_t* handle, uint32_t* stride);
+ status_t allocate(uint32_t w, uint32_t h, PixelFormat format,
+ uint32_t usage, buffer_handle_t* handle, uint32_t* stride,
+ uint64_t graphicBufferId, std::string requestorName);
status_t free(buffer_handle_t handle);
@@ -77,6 +76,7 @@
PixelFormat format;
uint32_t usage;
size_t size;
+ std::string requestorName;
};
static Mutex sLock;
@@ -86,7 +86,8 @@
GraphicBufferAllocator();
~GraphicBufferAllocator();
- alloc_device_t *mAllocDev;
+ std::unique_ptr<Gralloc1::Loader> mLoader;
+ std::unique_ptr<Gralloc1::Device> mDevice;
};
// ---------------------------------------------------------------------------
diff --git a/include/ui/GraphicBufferMapper.h b/include/ui/GraphicBufferMapper.h
index 6099548..a25809c 100644
--- a/include/ui/GraphicBufferMapper.h
+++ b/include/ui/GraphicBufferMapper.h
@@ -20,13 +20,10 @@
#include <stdint.h>
#include <sys/types.h>
+#include <ui/Gralloc1.h>
+
#include <utils/Singleton.h>
-#include <hardware/gralloc.h>
-
-
-struct gralloc_module_t;
-
namespace android {
// ---------------------------------------------------------------------------
@@ -39,6 +36,7 @@
static inline GraphicBufferMapper& get() { return getInstance(); }
status_t registerBuffer(buffer_handle_t handle);
+ status_t registerBuffer(const GraphicBuffer* buffer);
status_t unregisterBuffer(buffer_handle_t handle);
@@ -59,13 +57,13 @@
status_t unlockAsync(buffer_handle_t handle, int *fenceFd);
- // dumps information about the mapping of this handle
- void dump(buffer_handle_t handle);
-
private:
friend class Singleton<GraphicBufferMapper>;
+
GraphicBufferMapper();
- gralloc_module_t const *mAllocMod;
+
+ std::unique_ptr<Gralloc1::Loader> mLoader;
+ std::unique_ptr<Gralloc1::Device> mDevice;
};
// ---------------------------------------------------------------------------