egl/android: Get gralloc module in dri2_initialize_android() (v2)
authorTomasz Figa <tfiga@chromium.org>
Thu, 10 Nov 2016 07:55:52 +0000 (16:55 +0900)
committerEmil Velikov <emil.l.velikov@gmail.com>
Mon, 21 Nov 2016 13:27:41 +0000 (13:27 +0000)
Currently droid_open_device() gets a reference to the gralloc module
only for its own use and does not store it anywhere. To make it possible
to call gralloc methods from code added in further patches, let's
refactor current code to get gralloc module in dri2_initialize_android()
and store it in dri2_dpy.

v2: fixes from Emil's review:
 a) remove duplicate initialization of 'err'.

Signed-off-by: Tomasz Figa <tfiga@chromium.org>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_android.c

index c039b64cb2c5ad0e669ba1e3ff7734d8c61b8be5..fd4e87bb0780187824e6d76d4b49262bb862956f 100644 (file)
@@ -219,6 +219,10 @@ struct dri2_egl_display
    char                     *device_name;
 #endif
 
+#ifdef HAVE_ANDROID_PLATFORM
+   const gralloc_module_t *gralloc;
+#endif
+
    int                       is_render_node;
    int                       is_different_gpu;
 };
index f62a0386d9b1701cf8b38d93e79065aa7efa52e8..fc499327d63b45208b0b117be69bf21dea5c8645 100644 (file)
@@ -856,19 +856,14 @@ droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy)
 }
 
 static int
-droid_open_device(void)
+droid_open_device(struct dri2_egl_display *dri2_dpy)
 {
-   const hw_module_t *mod;
-   int fd = -1, err;
+   int fd = -1, err = -EINVAL;
 
-   err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &mod);
-   if (!err) {
-      const gralloc_module_t *gr = (gralloc_module_t *) mod;
-
-      err = -EINVAL;
-      if (gr->perform)
-         err = gr->perform(gr, GRALLOC_MODULE_PERFORM_GET_DRM_FD, &fd);
-   }
+   if (dri2_dpy->gralloc->perform)
+         err = dri2_dpy->gralloc->perform(dri2_dpy->gralloc,
+                                          GRALLOC_MODULE_PERFORM_GET_DRM_FD,
+                                          &fd);
    if (err || fd < 0) {
       _eglLog(_EGL_WARNING, "fail to get drm fd");
       fd = -1;
@@ -963,6 +958,7 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
 {
    struct dri2_egl_display *dri2_dpy;
    const char *err;
+   int ret;
 
    _eglSetLogProc(droid_log);
 
@@ -972,9 +968,16 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
    if (!dri2_dpy)
       return _eglError(EGL_BAD_ALLOC, "eglInitialize");
 
+   ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
+                       (const hw_module_t **)&dri2_dpy->gralloc);
+   if (ret) {
+      err = "DRI2: failed to get gralloc module";
+      goto cleanup_display;
+   }
+
    dpy->DriverData = (void *) dri2_dpy;
 
-   dri2_dpy->fd = droid_open_device();
+   dri2_dpy->fd = droid_open_device(dri2_dpy);
    if (dri2_dpy->fd < 0) {
       err = "DRI2: failed to open device";
       goto cleanup_display;