[Mesa-dev] Mesa (master): egl/gbm: Fix EGL_DEFAULT_DISPLAY
Benjamin Franzke
benjaminfranzke at googlemail.com
Fri Aug 5 00:30:23 PDT 2011
2011/8/5 Chad Versace <chad at chad-versace.us>:
> This commit *really* needs a more descriptive commit message.
Ok, I thought its clear what is to be done for EGL_DEFAULT_DISPLAY.
But your right, it should have more descriptive. In future I'll try to do so.
Since I cant change the commit message now, let me answer your questions.
> - What were the symptoms of the broken EGL_DEFAULT_DISPLAY?
Segfault, because the native egl display is NULL.
> - What error in the code caused the problem?
Not handling the above.
> - What the hell did you do to fix it? This is not evident due to the length
> of the commit.
Well, its really just creating a new gbm device if there is none given,
and properly destroying it, if created by ourself.
And what does this fix?
eglinfo.c in mesa/demos/src/egl/opengl/ with EGL_PLATFORM=drm
P.S. This has nothing to do with hell.
I understand that bad commit messages can upset, but lets keep patient.
> For commits of this complexity, write descriptive messages for the sake of others.
>
> --
> Chad Versace
> chad at chad-versace.us
>
> On 08/04/2011 05:18 AM, Benjamin Franzke wrote:
>> Module: Mesa
>> Branch: master
>> Commit: 32f4cf38085e4056b8e4a9fc78fea28897a1d05f
>> URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=32f4cf38085e4056b8e4a9fc78fea28897a1d05f
>>
>> Author: Benjamin Franzke <benjaminfranzke at googlemail.com>
>> Date: Wed Jun 29 08:49:39 2011 +0200
>>
>> egl/gbm: Fix EGL_DEFAULT_DISPLAY
>>
>> ---
>>
>> src/egl/drivers/dri2/egl_dri2.c | 7 ++++++
>> src/egl/drivers/dri2/egl_dri2.h | 1 +
>> src/egl/drivers/dri2/platform_drm.c | 25 +++++++++++++++++++++-
>> src/gallium/state_trackers/egl/drm/native_drm.c | 23 ++++++++++++++++----
>> src/gallium/state_trackers/egl/drm/native_drm.h | 4 +++
>> 5 files changed, 53 insertions(+), 7 deletions(-)
>>
>> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
>> index 0aca929..9a37ea4 100644
>> --- a/src/egl/drivers/dri2/egl_dri2.c
>> +++ b/src/egl/drivers/dri2/egl_dri2.c
>> @@ -592,6 +592,13 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
>> wl_display_destroy(dri2_dpy->wl_dpy);
>> break;
>> #endif
>> +#ifdef HAVE_DRM_PLATFORM
>> + case _EGL_PLATFORM_DRM:
>> + if (dri2_dpy->own_gbm_device) {
>> + gbm_device_destroy(&dri2_dpy->gbm_dri->base.base);
>> + }
>> + break;
>> +#endif
>> default:
>> break;
>> }
>> diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
>> index 3854200..a729718 100644
>> --- a/src/egl/drivers/dri2/egl_dri2.h
>> +++ b/src/egl/drivers/dri2/egl_dri2.h
>> @@ -86,6 +86,7 @@ struct dri2_egl_display
>>
>> #ifdef HAVE_DRM_PLATFORM
>> struct gbm_dri_device *gbm_dri;
>> + int own_gbm_device;
>> #endif
>>
>> char *device_name;
>> diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
>> index 579baf9..04b10e2 100644
>> --- a/src/egl/drivers/dri2/platform_drm.c
>> +++ b/src/egl/drivers/dri2/platform_drm.c
>> @@ -30,6 +30,10 @@
>> #include <string.h>
>> #include <xf86drm.h>
>> #include <dlfcn.h>
>> +#include <sys/types.h>
>> +#include <sys/stat.h>
>> +#include <fcntl.h>
>> +#include <unistd.h>
>>
>> #include "egl_dri2.h"
>>
>> @@ -90,6 +94,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
>> {
>> struct dri2_egl_display *dri2_dpy;
>> struct gbm_device *gbm;
>> + int fd = -1;
>> int i;
>>
>> dri2_dpy = malloc(sizeof *dri2_dpy);
>> @@ -100,7 +105,15 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
>>
>> disp->DriverData = (void *) dri2_dpy;
>>
>> - gbm = (struct gbm_device *) disp->PlatformDisplay;
>> + gbm = disp->PlatformDisplay;
>> + if (gbm == NULL) {
>> + fd = open("/dev/dri/card0", O_RDWR);
>> + dri2_dpy->own_gbm_device = 1;
>> + gbm = gbm_create_device(fd);
>> + if (gbm == NULL)
>> + return EGL_FALSE;
>> + }
>> +
>> if (strcmp(gbm_device_get_backend_name(gbm), "drm") != 0) {
>> free(dri2_dpy);
>> return EGL_FALSE;
>> @@ -112,7 +125,15 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
>> return EGL_FALSE;
>> }
>>
>> - dri2_dpy->fd = gbm_device_get_fd(gbm);
>> + if (fd < 0) {
>> + fd = dup(gbm_device_get_fd(gbm));
>> + if (fd < 0) {
>> + free(dri2_dpy);
>> + return EGL_FALSE;
>> + }
>> + }
>> +
>> + dri2_dpy->fd = fd;
>> dri2_dpy->device_name = dri2_get_device_name_for_fd(dri2_dpy->fd);
>> dri2_dpy->driver_name = dri2_dpy->gbm_dri->base.driver_name;
>>
>> diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c b/src/gallium/state_trackers/egl/drm/native_drm.c
>> index 47910de..c013769 100644
>> --- a/src/gallium/state_trackers/egl/drm/native_drm.c
>> +++ b/src/gallium/state_trackers/egl/drm/native_drm.c
>> @@ -134,8 +134,11 @@ drm_display_destroy(struct native_display *ndpy)
>> if (drmdpy->device_name)
>> FREE(drmdpy->device_name);
>>
>> - if (drmdpy->fd >= 0)
>> - close(drmdpy->fd);
>> + if (drmdpy->own_gbm) {
>> + gbm_device_destroy(&drmdpy->gbmdrm->base.base);
>> + if (drmdpy->fd >= 0)
>> + close(drmdpy->fd);
>> + }
>>
>> FREE(drmdpy);
>> }
>> @@ -258,7 +261,7 @@ drm_display_init_screen(struct native_display *ndpy)
>> }
>>
>> static struct native_display *
>> -drm_create_display(struct gbm_gallium_drm_device *gbmdrm,
>> +drm_create_display(struct gbm_gallium_drm_device *gbmdrm, int own_gbm,
>> const struct native_event_handler *event_handler)
>> {
>> struct drm_display *drmdpy;
>> @@ -267,6 +270,8 @@ drm_create_display(struct gbm_gallium_drm_device *gbmdrm,
>> if (!drmdpy)
>> return NULL;
>>
>> + drmdpy->gbmdrm = gbmdrm;
>> + drmdpy->own_gbm = own_gbm;
>> drmdpy->fd = gbmdrm->base.base.fd;
>> drmdpy->device_name = drm_get_device_name(drmdpy->fd);
>>
>> @@ -302,22 +307,30 @@ native_create_display(void *dpy, boolean use_sw)
>> {
>> struct gbm_gallium_drm_device *gbm;
>> int fd;
>> + int own_gbm = 0;
>>
>> gbm = dpy;
>>
>> if (gbm == NULL) {
>> fd = open("/dev/dri/card0", O_RDWR);
>> + /* FIXME: Use an internal constructor to create a gbm
>> + * device with gallium backend directly, without setenv */
>> + setenv("GBM_BACKEND", "gbm_gallium_drm.so", 1);
>> gbm = gbm_gallium_drm_device(gbm_create_device(fd));
>> + own_gbm = 1;
>> }
>>
>> if (gbm == NULL)
>> return NULL;
>>
>> if (strcmp(gbm_device_get_backend_name(&gbm->base.base), "drm") != 0 ||
>> - gbm->base.type != GBM_DRM_DRIVER_TYPE_GALLIUM)
>> + gbm->base.type != GBM_DRM_DRIVER_TYPE_GALLIUM) {
>> + if (own_gbm)
>> + gbm_device_destroy(&gbm->base.base);
>> return NULL;
>> + }
>>
>> - return drm_create_display(gbm, drm_event_handler);
>> + return drm_create_display(gbm, own_gbm, drm_event_handler);
>> }
>>
>> static const struct native_platform drm_platform = {
>> diff --git a/src/gallium/state_trackers/egl/drm/native_drm.h b/src/gallium/state_trackers/egl/drm/native_drm.h
>> index 675a58a..18cebf4 100644
>> --- a/src/gallium/state_trackers/egl/drm/native_drm.h
>> +++ b/src/gallium/state_trackers/egl/drm/native_drm.h
>> @@ -41,6 +41,8 @@
>> #include "common/native_wayland_drm_bufmgr_helper.h"
>> #endif
>>
>> +#include "gbm_gallium_drmint.h"
>> +
>> struct drm_config;
>> struct drm_crtc;
>> struct drm_connector;
>> @@ -52,6 +54,8 @@ struct drm_display {
>>
>> const struct native_event_handler *event_handler;
>>
>> + struct gbm_gallium_drm_device *gbmdrm;
>> + int own_gbm;
>> int fd;
>> char *device_name;
>> struct drm_config *config;
>
>
>
>
More information about the mesa-dev
mailing list