drm_hwcomposer: Cache FB and gem in gralloc buffer
Move drm fb object creation to the importer.
In NV importer, use GRALLOC_MODULE_PERFORM_SET_IMPORTER_PRIVATE
and GRALLOC_MODULE_PERFORM_GET_IMPORTER_PRIVATE to cache the hwc_drm_bo
in the gralloc buffer. This avoids the need to recreate fb objects
again each frame, and also greatly simplifies managing the lifetime of
the gem handles.
The drm_gralloc importer does not support caching at this point. In an
attempt to keep it somewhat working, add hwc_import_bo_release function
that hwc calls when it's ok to rm fb. If hwc_import_bo_release returns
true, then hwc will clean up gem handles as it did before.
We should consider doing a follow-up patch that adds fb/gem caching to
drm_gralloc importer also. Then some of the code that is kept in this
patch for backwards compatibility can be removed.
Change-Id: I92857dcaddf8cea219ebc041e16ef76087a1b696
Reviewed-on: https://chrome-internal-review.googlesource.com/200895
Reviewed-by: Stéphane Marchesin <marcheu@google.com>
Commit-Queue: Stéphane Marchesin <marcheu@google.com>
Tested-by: Stéphane Marchesin <marcheu@google.com>
diff --git a/drm_hwcomposer.h b/drm_hwcomposer.h
index 35b3aa9..b94e5dd 100644
--- a/drm_hwcomposer.h
+++ b/drm_hwcomposer.h
@@ -17,7 +17,29 @@
struct hwc_import_context;
enum {
- GRALLOC_MODULE_PERFORM_DRM_IMPORT = 0xffeeff00
+ /* perform(const struct gralloc_module_t *mod,
+ * int op,
+ * int drm_fd,
+ * buffer_handle_t buffer,
+ * struct hwc_drm_bo *bo);
+ */
+ GRALLOC_MODULE_PERFORM_DRM_IMPORT = 0xffeeff00,
+
+ /* perform(const struct gralloc_module_t *mod,
+ * int op,
+ * buffer_handle_t buffer,
+ * void (*free_callback)(void *),
+ * void *priv);
+ */
+ GRALLOC_MODULE_PERFORM_SET_IMPORTER_PRIVATE = 0xffeeff01,
+
+ /* perform(const struct gralloc_module_t *mod,
+ * int op,
+ * buffer_handle_t buffer,
+ * void (*free_callback)(void *),
+ * void **priv);
+ */
+ GRALLOC_MODULE_PERFORM_GET_IMPORTER_PRIVATE = 0xffeeff02,
};
struct hwc_drm_bo {
@@ -29,13 +51,12 @@
uint32_t gem_handles[4];
uint32_t fb_id;
int acquire_fence_fd;
-
- /* TODO: This is bad voodoo, remove it once drm_gralloc uses dma_buf */
- int importer_fd;
};
int hwc_import_init(struct hwc_import_context **ctx);
int hwc_import_destroy(struct hwc_import_context *ctx);
-int hwc_create_bo_from_import(int fd, struct hwc_import_context *ctx,
+int hwc_import_bo_create(int fd, struct hwc_import_context *ctx,
buffer_handle_t buf, struct hwc_drm_bo *bo);
+bool hwc_import_bo_release(int fd, hwc_import_context *ctx,
+ struct hwc_drm_bo *bo);