minigbm: refactor cros_gralloc_driver to be a singleton
Only a single cros_gralloc_driver instance is allowed to exist in a
process. However, currently when Gralloc3.0 or Gralloc4.0 is used, it's
possible for 2 independent driver instances to be created. This change
refactors cros_gralloc_driver to be a singleton and ensures the driver
initialization only happens once per process.
BUG=b:191895066
TEST=No regression of gralloc0 in ARCVM
Change-Id: I3cb8b7c3d13717cfe531b557b9d69b72efdbf3da
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3002266
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Tested-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Jason Macnak <natsu@google.com>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
diff --git a/cros_gralloc/gralloc0/gralloc0.cc b/cros_gralloc/gralloc0/gralloc0.cc
index 386a90a..8570150 100644
--- a/cros_gralloc/gralloc0/gralloc0.cc
+++ b/cros_gralloc/gralloc0/gralloc0.cc
@@ -15,7 +15,7 @@
struct gralloc0_module {
gralloc_module_t base;
std::unique_ptr<alloc_device_t> alloc;
- std::unique_ptr<cros_gralloc_driver> driver;
+ cros_gralloc_driver *driver;
bool initialized;
std::mutex initialization_mutex;
};
@@ -224,11 +224,9 @@
if (mod->initialized)
return 0;
- mod->driver = std::make_unique<cros_gralloc_driver>();
- if (mod->driver->init()) {
- drv_log("Failed to initialize driver.\n");
+ mod->driver = cros_gralloc_driver::get_instance();
+ if (!mod->driver)
return -ENODEV;
- }
if (initialize_alloc) {
mod->alloc = std::make_unique<alloc_device_t>();