+static int gralloc0_open_fb0(struct gralloc0_module *mod, struct hw_device_t **dev)
+{
+ int ret;
+
+ if (!mod->initialized) {
+ ret = gralloc0_init(mod, true, true);
+ if (ret)
+ return ret;
+ }
+
+ if (!mod->fb) {
+ /*
+ * On Pie and above the FB HAL is opened before the Gralloc HAL.
+ * This has the advantage that we can open the DRM card node in this case,
+ * and open the render node in all other cases.
+ *
+ * On earlier Android versions this is not the case, so we need to make
+ * sure the FB HAL was actually initialized.
+ *
+ * TODO: Currently it does not attempt to set master on the opened render
+ * node. That means it will only work with DRM authentication disabled.
+ */
+ std::lock_guard<std::mutex> lock(mod->initialization_mutex);
+ drv_log("FB HAL opened after Gralloc HAL, we might not be DRM master!\n");
+
+ ret = drm_framebuffer_init(mod->driver->get_fd(), &mod->fb);
+ if (ret)
+ return ret;
+ }
+
+ *dev = (struct hw_device_t *) mod->fb;
+ return 0;
+}
+