| From b4e589dbc15b1c62a3686cc405333f457ce980f3 Mon Sep 17 00:00:00 2001 |
| From: Tomasz Figa <tfiga@chromium.org> |
| Date: Tue, 2 Aug 2016 18:19:43 +0900 |
| Subject: [PATCH 29/39] CHROMIUM: egl/android: Support opening render nodes |
| from within EGL |
| |
| This patch adds support for opening render nodes directly from within |
| display initialization, Instead of relying on private interfaces |
| provided by gralloc. |
| |
| In addition to having better separation from gralloc and being able to |
| use different render nodes for allocation and rendering, this also fixes |
| problems encountered when using the same DRI FD for gralloc and Mesa, |
| when both stepped each over another because of shared GEM handle |
| namespace. |
| |
| BUG=b:29036398 |
| TEST=No significant regressions in dEQP inside the container |
| |
| Signed-off-by: Tomasz Figa <tfiga@chromium.org> |
| Reviewed-on: https://chromium-review.googlesource.com/367215 |
| Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> |
| (cherry picked from commit 4471713aa71d83943eb195868707ebe4e6515bb6) |
| |
| BUG=b:32077712 |
| BUG=b:33533853 |
| TEST=No CTS regressions on cyan and reef. |
| |
| Change-Id: I7f901eb9dadbfc2200484666fdc6a2bc0ca42a0c |
| Signed-off-by: Tomasz Figa <tfiga@chromium.org> |
| Reviewed-on: https://chromium-review.googlesource.com/558138 |
| Reviewed-by: Chad Versace <chadversary@chromium.org> |
| --- |
| src/egl/drivers/dri2/platform_android.c | 79 ++++++++++++++++++++++----------- |
| 1 file changed, 54 insertions(+), 25 deletions(-) |
| |
| diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c |
| index 826a922..949ed2b 100644 |
| --- a/src/egl/drivers/dri2/platform_android.c |
| +++ b/src/egl/drivers/dri2/platform_android.c |
| @@ -1092,7 +1092,7 @@ droid_open_device(struct dri2_egl_display *dri2_dpy) |
| GRALLOC_MODULE_PERFORM_GET_DRM_FD, |
| &fd); |
| if (err || fd < 0) { |
| - _eglLog(_EGL_WARNING, "fail to get drm fd"); |
| + _eglLog(_EGL_DEBUG, "fail to get drm fd"); |
| fd = -1; |
| } |
| |
| @@ -1154,11 +1154,17 @@ static const __DRIextension *droid_image_loader_extensions[] = { |
| }; |
| |
| static bool |
| -droid_load_driver(_EGLDisplay *dpy, bool swrast, bool dri3) |
| +droid_probe_device(_EGLDisplay *dpy, bool swrast) |
| { |
| struct dri2_egl_display *dri2_dpy = dpy->DriverData; |
| bool loaded; |
| |
| + dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd) == DRM_NODE_RENDER; |
| + if (!dri2_dpy->is_render_node && !gralloc_supports_gem_names()) { |
| + _eglLog(_EGL_WARNING, "DRI2: control nodes not supported without GEM name suport in gralloc\n"); |
| + return false; |
| + } |
| + |
| if (swrast) |
| dri2_dpy->driver_name = strdup("kms_swrast"); |
| else |
| @@ -1169,10 +1175,15 @@ droid_load_driver(_EGLDisplay *dpy, bool swrast, bool dri3) |
| return false; |
| } |
| |
| - if (dri3) |
| - loaded = dri2_load_driver_dri3(dpy); |
| - else |
| + /* render nodes cannot use Gem names, and thus do not support |
| + * the __DRI_DRI2_LOADER extension */ |
| + if (!dri2_dpy->is_render_node) { |
| + dri2_dpy->loader_extensions = droid_dri2_loader_extensions; |
| loaded = dri2_load_driver(dpy); |
| + } else { |
| + dri2_dpy->loader_extensions = droid_image_loader_extensions; |
| + loaded = dri2_load_driver_dri3(dpy); |
| + } |
| |
| if (!loaded) { |
| _eglLog(_EGL_WARNING, "DRI2: failed to load driver"); |
| @@ -1184,6 +1195,36 @@ droid_load_driver(_EGLDisplay *dpy, bool swrast, bool dri3) |
| return true; |
| } |
| |
| +static bool |
| +droid_probe_devices(_EGLDisplay *dpy, bool swrast) |
| +{ |
| + struct dri2_egl_display *dri2_dpy = dpy->DriverData; |
| + const char *name_template = "%s/renderD%d"; |
| + const int base = 128; |
| + const int limit = 64; |
| + int minor; |
| + |
| + for (minor = base; minor < base + limit; ++minor) { |
| + char *card_path; |
| + |
| + if (asprintf(&card_path, name_template, DRM_DIR_NAME, minor) < 0) |
| + continue; |
| + |
| + dri2_dpy->fd = loader_open_device(card_path); |
| + free(card_path); |
| + if (dri2_dpy->fd < 0) |
| + continue; |
| + |
| + if (droid_probe_device(dpy, swrast)) |
| + return true; |
| + |
| + close(dri2_dpy->fd); |
| + dri2_dpy->fd = -1; |
| + } |
| + |
| + return false; |
| +} |
| + |
| EGLBoolean |
| dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy) |
| { |
| @@ -1208,27 +1249,15 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy) |
| dpy->DriverData = (void *) dri2_dpy; |
| |
| dri2_dpy->fd = droid_open_device(dri2_dpy); |
| - if (dri2_dpy->fd < 0) { |
| - err = "DRI2: failed to open device"; |
| - goto cleanup; |
| - } |
| - |
| - dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd) == DRM_NODE_RENDER; |
| - if (!dri2_dpy->is_render_node && !gralloc_supports_gem_names()) { |
| - _eglLog(_EGL_WARNING, "DRI2: control nodes not supported without GEM name suport in gralloc\n"); |
| - goto cleanup; |
| - } |
| - |
| - /* render nodes cannot use Gem names, and thus do not support |
| - * the __DRI_DRI2_LOADER extension */ |
| - if (!dri2_dpy->is_render_node) |
| - dri2_dpy->loader_extensions = droid_dri2_loader_extensions; |
| - else |
| - dri2_dpy->loader_extensions = droid_image_loader_extensions; |
| - |
| - if (!droid_load_driver(dpy, false, dri2_dpy->is_render_node)) { |
| + if (dri2_dpy->fd >= 0 && !droid_probe_device(dpy, false)) { |
| + _eglLog(_EGL_WARNING, "DRI2: Failed to load hardware driver, trying software..."); |
| + if (!droid_probe_device(dpy, true)) { |
| + err = "DRI2: failed to load driver"; |
| + goto cleanup; |
| + } |
| + } else if (!droid_probe_devices(dpy, false)) { |
| _eglLog(_EGL_WARNING, "DRI2: Failed to load hardware driver, trying software..."); |
| - if (!droid_load_driver(dpy, true, dri2_dpy->is_render_node)) { |
| + if (!droid_probe_devices(dpy, true)) { |
| err = "DRI2: failed to load driver"; |
| goto cleanup; |
| } |
| -- |
| 2.7.4 |
| |