summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Macnak <natsu@google.com>2022-02-08 17:17:59 -0800
committerCommit Bot <commit-bot@chromium.org>2022-02-24 03:36:29 +0000
commit40d5c7d98c91a22081d98e266792a343ce0bc405 (patch)
tree3a928ca0528f43d73b8e96c9967fa21a996ab9ae
parent35fd7d23bbbcad96c4a265fa6ccd3a98bd48262a (diff)
downloadminigbm-40d5c7d98c91a22081d98e266792a343ce0bc405.tar.gz
gralloc: use dmabuf-heaps when available
... for reserved region / metadata as dmabuf heaps are the hot new thing replacing ion. Also, Android already has sepolicy in place for passing around dmabufs (see `dmabuf_system_heap_device:chr_file` references in system/sepolicy) while memfds require manual additions (see aosp/1960673). BUG=b:207388558 TEST=cvd start TEST=vts -m VtsHalGraphicsMapperV4_0Target Change-Id: I9acb30a10afb1f9f273ceb17dd44a9ac96da1a97 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3449613 Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com> Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Tested-by: Jason Macnak <natsu@google.com> Commit-Queue: Jason Macnak <natsu@google.com>
-rw-r--r--cros_gralloc/cros_gralloc_driver.cc39
-rw-r--r--cros_gralloc/cros_gralloc_driver.h12
2 files changed, 41 insertions, 10 deletions
diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc
index f719edb..42abb74 100644
--- a/cros_gralloc/cros_gralloc_driver.cc
+++ b/cros_gralloc/cros_gralloc_driver.cc
@@ -44,6 +44,22 @@ int memfd_create_wrapper(const char *name, unsigned int flags)
return fd;
}
+int memfd_create_reserved_region(const std::string &buffer_name, uint64_t reserved_region_size)
+{
+ const std::string reserved_region_name = buffer_name + " reserved region";
+
+ int reserved_region_fd = memfd_create_wrapper(reserved_region_name.c_str(), FD_CLOEXEC);
+ if (reserved_region_fd == -1)
+ return -errno;
+
+ if (ftruncate(reserved_region_fd, reserved_region_size)) {
+ drv_log("Failed to set reserved region size: %s.\n", strerror(errno));
+ return -errno;
+ }
+
+ return reserved_region_fd;
+}
+
cros_gralloc_driver *cros_gralloc_driver::get_instance()
{
static cros_gralloc_driver s_instance;
@@ -183,20 +199,23 @@ bool cros_gralloc_driver::is_supported(const struct cros_gralloc_buffer_descript
return descriptor->width <= max_texture_size && descriptor->height <= max_texture_size;
}
-int32_t create_reserved_region(const std::string &buffer_name, uint64_t reserved_region_size)
+int cros_gralloc_driver::create_reserved_region(const std::string &buffer_name,
+ uint64_t reserved_region_size)
{
- std::string reserved_region_name = buffer_name + " reserved region";
+ int ret;
- int32_t reserved_region_fd = memfd_create_wrapper(reserved_region_name.c_str(), FD_CLOEXEC);
- if (reserved_region_fd == -1)
- return -errno;
+#if ANDROID_API_LEVEL >= 31
+ ret = allocator_.Alloc(kDmabufSystemHeapName, reserved_region_size);
+ if (ret >= 0)
+ return ret;
+#endif
- if (ftruncate(reserved_region_fd, reserved_region_size)) {
- drv_log("Failed to set reserved region size: %s.\n", strerror(errno));
- return -errno;
- }
+ ret = memfd_create_reserved_region(buffer_name, reserved_region_size);
+ if (ret >= 0)
+ return ret;
- return reserved_region_fd;
+ drv_log("Failed to create_reserved_region.\n");
+ return -1;
}
int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descriptor *descriptor,
diff --git a/cros_gralloc/cros_gralloc_driver.h b/cros_gralloc/cros_gralloc_driver.h
index 6de5df9..c8dcd35 100644
--- a/cros_gralloc/cros_gralloc_driver.h
+++ b/cros_gralloc/cros_gralloc_driver.h
@@ -12,8 +12,13 @@
#include <functional>
#include <memory>
#include <mutex>
+#include <string>
#include <unordered_map>
+#if ANDROID_API_LEVEL >= 31
+#include <BufferAllocator/BufferAllocator.h>
+#endif
+
class cros_gralloc_driver
{
public:
@@ -54,6 +59,13 @@ class cros_gralloc_driver
get_resolved_format_and_use_flags(const struct cros_gralloc_buffer_descriptor *descriptor,
uint32_t *out_format, uint64_t *out_use_flags);
+ int create_reserved_region(const std::string &buffer_name, uint64_t reserved_region_size);
+
+#if ANDROID_API_LEVEL >= 31
+ /* For allocating cros_gralloc_buffer reserved regions for metadata. */
+ BufferAllocator allocator_;
+#endif
+
std::unique_ptr<struct driver, void (*)(struct driver *)> drv_;
std::mutex mutex_;