From 6a661895e946f38b21775bf9cb45ef6b22fab85a Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 12 May 2011 15:12:16 +0100 Subject: egl: Fix int <-> ptr casts. Based on zhigang gong 's patch. --- src/egl/drivers/dri2/egl_dri2.c | 4 ++-- src/egl/drivers/dri2/platform_drm.c | 2 +- src/egl/drivers/dri2/platform_x11.c | 2 +- src/egl/main/eglapi.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/egl') diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index afab679bff6..1acec51a433 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -835,7 +835,7 @@ dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); struct dri2_egl_image *dri2_img; - GLuint renderbuffer = (GLuint) buffer; + GLuint renderbuffer = (GLuint) (uintptr_t) buffer; if (renderbuffer == 0) { _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); @@ -870,7 +870,7 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, (void) ctx; - name = (EGLint) buffer; + name = (EGLint) (uintptr_t) buffer; err = _eglParseImageAttribList(&attrs, disp, attr_list); if (err != EGL_SUCCESS) diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c index 68912e36732..261cbfed675 100644 --- a/src/egl/drivers/dri2/platform_drm.c +++ b/src/egl/drivers/dri2/platform_drm.c @@ -690,7 +690,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) memset(dri2_dpy, 0, sizeof *dri2_dpy); disp->DriverData = (void *) dri2_dpy; - dri2_dpy->fd = (int) disp->PlatformDisplay; + dri2_dpy->fd = (int) (intptr_t) disp->PlatformDisplay; dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd); if (dri2_dpy->driver_name == NULL) diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 5d4ac6ae948..2e26ff00b67 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -784,7 +784,7 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, (void) ctx; - drawable = (xcb_drawable_t) buffer; + drawable = (xcb_drawable_t) (uintptr_t) buffer; xcb_dri2_create_drawable (dri2_dpy->conn, drawable); attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT; buffers_cookie = diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 336ec23da5a..bdfdcb3817d 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -1168,7 +1168,7 @@ eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode) EGLDisplay EGLAPIENTRY eglGetDRMDisplayMESA(int fd) { - _EGLDisplay *dpy = _eglFindDisplay(_EGL_PLATFORM_DRM, (void *) fd); + _EGLDisplay *dpy = _eglFindDisplay(_EGL_PLATFORM_DRM, (void *) (intptr_t) fd); return _eglGetDisplayHandle(dpy); } -- cgit v1.2.3 From 6c26072bd151ee7abc897aad63cd55ec5f15762e Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 12 May 2011 15:23:02 +0100 Subject: egl/dri2: Fix const pointer duplication, prevent unitialized variable dereference. Based on zhigang gong 's patch. --- src/egl/drivers/dri2/platform_drm.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/egl') diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c index 261cbfed675..9811b280299 100644 --- a/src/egl/drivers/dri2/platform_drm.c +++ b/src/egl/drivers/dri2/platform_drm.c @@ -581,7 +581,8 @@ dri2_get_device_name(int fd) struct udev *udev; struct udev_device *device; struct stat buf; - char *device_name; + const char *const_device_name; + char *device_name = NULL; udev = udev_new(); if (fstat(fd, &buf) < 0) { @@ -596,10 +597,11 @@ dri2_get_device_name(int fd) goto out; } - device_name = udev_device_get_devnode(device); - if (!device_name) - goto out; - device_name = strdup(device_name); + const_device_name = udev_device_get_devnode(device); + if (!const_device_name) { + goto out; + } + device_name = strdup(const_device_name); out: udev_device_unref(device); -- cgit v1.2.3 From 4a47d6d46b397bf31a1fd22d35bd40ef03bd9357 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 12 May 2011 15:23:48 +0100 Subject: egl/dri2: Prevent uninitialized variable dereference. --- src/egl/drivers/dri2/egl_dri2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/egl') diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 1acec51a433..0e1a1b52a4c 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -205,8 +205,7 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, */ num_configs = 0; } - - if (num_configs == 0) { + else if (num_configs == 0) { conf = malloc(sizeof *conf); if (conf == NULL) return NULL; @@ -224,6 +223,10 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, _eglLinkConfig(&conf->base); } + else { + assert(0); + return NULL; + } conf->base.SurfaceType |= surface_type & (!double_buffer ? EGL_PIXMAP_BIT: (EGL_WINDOW_BIT | EGL_PBUFFER_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT)); -- cgit v1.2.3 From 5de2c67ba7d62882fe2c5e2a307e58f4f637fadd Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 12 May 2011 15:24:26 +0100 Subject: egl/dri2: Avoid unused static functions. --- src/egl/drivers/dri2/egl_dri2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/egl') diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 0e1a1b52a4c..d77f0ed67d1 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -925,6 +925,7 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, return &dri2_img->base; } +#ifdef HAVE_WAYLAND_PLATFORM static _EGLImage * dri2_reference_drm_image(_EGLDisplay *disp, _EGLContext *ctx, __DRIimage *dri_image, EGLint width, EGLint height) @@ -951,7 +952,6 @@ dri2_reference_drm_image(_EGLDisplay *disp, _EGLContext *ctx, attr_list); } -#ifdef HAVE_WAYLAND_PLATFORM static _EGLImage * dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, EGLClientBuffer _buffer, -- cgit v1.2.3 From 93aea63a33c575bbce80acad391e810acc2f3e94 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Wed, 11 May 2011 13:58:37 -0400 Subject: egl_dri2: Make it possible to not compile in the X11 platform --- src/egl/drivers/dri2/Makefile | 11 ++++++++--- src/egl/drivers/dri2/egl_dri2.c | 4 ++++ src/egl/drivers/dri2/egl_dri2.h | 14 +++++++++++--- src/egl/main/Makefile | 6 +++++- 4 files changed, 28 insertions(+), 7 deletions(-) (limited to 'src/egl') diff --git a/src/egl/drivers/dri2/Makefile b/src/egl/drivers/dri2/Makefile index 4783975852a..447babd6747 100644 --- a/src/egl/drivers/dri2/Makefile +++ b/src/egl/drivers/dri2/Makefile @@ -4,18 +4,17 @@ TOP = ../../../.. include $(TOP)/configs/current EGL_DRIVER = egl_dri2 -EGL_SOURCES = egl_dri2.c platform_x11.c platform_drm.c +EGL_SOURCES = egl_dri2.c platform_drm.c EGL_INCLUDES = \ -I$(TOP)/include \ -I$(TOP)/src/egl/main \ -I$(TOP)/src/mapi \ -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\" \ - $(XCB_DRI2_CFLAGS) \ $(LIBUDEV_CFLAGS) \ $(LIBDRM_CFLAGS) -EGL_LIBS = $(XCB_DRI2_LIBS) $(LIBUDEV_LIBS) $(DLOPEN_LIBS) $(LIBDRM_LIB) +EGL_LIBS = $(LIBUDEV_LIBS) $(DLOPEN_LIBS) $(LIBDRM_LIB) EGL_CFLAGS = -D_EGL_MAIN=_eglBuiltInDriverDRI2 EGL_BUILTIN = true @@ -24,6 +23,12 @@ ifeq ($(SHARED_GLAPI),1) EGL_CFLAGS += -DHAVE_SHARED_GLAPI endif +ifneq ($(findstring x11, $(EGL_PLATFORMS)),) +EGL_SOURCES += platform_x11.c +EGL_INCLUDES += -DHAVE_X11_PLATFORM $(XCB_DRI2_CFLAGS) +EGL_LIBS += $(XCB_DRI2_LIBS) +endif + ifneq ($(findstring wayland, $(EGL_PLATFORMS)),) EGL_SOURCES += platform_wayland.c EGL_INCLUDES += -DHAVE_WAYLAND_PLATFORM $(WAYLAND_CFLAGS) \ diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index d77f0ed67d1..10309e6eeaf 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -490,10 +490,12 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp) return EGL_FALSE; switch (disp->Platform) { +#ifdef HAVE_X11_PLATFORM case _EGL_PLATFORM_X11: if (disp->Options.TestOnly) return EGL_TRUE; return dri2_initialize_x11(drv, disp); +#endif #ifdef HAVE_LIBUDEV case _EGL_PLATFORM_DRM: @@ -528,8 +530,10 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) if (dri2_dpy->fd) close(dri2_dpy->fd); dlclose(dri2_dpy->driver); +#ifdef HAVE_X11_PLATFORM if (disp->PlatformDisplay == NULL) xcb_disconnect(dri2_dpy->conn); +#endif free(dri2_dpy); disp->DriverData = NULL; diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 99f990ac688..efcb366568e 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -28,10 +28,12 @@ #ifndef EGL_DRI2_INCLUDED #define EGL_DRI2_INCLUDED +#ifdef HAVE_X11_PLATFORM #include #include #include #include +#endif #ifdef HAVE_WAYLAND_PLATFORM #include @@ -64,7 +66,6 @@ struct dri2_egl_driver struct dri2_egl_display { - xcb_connection_t *conn; int dri2_major; int dri2_minor; __DRIscreen *dri_screen; @@ -84,6 +85,11 @@ struct dri2_egl_display __DRIdri2LoaderExtension dri2_loader_extension; __DRIswrastLoaderExtension swrast_loader_extension; const __DRIextension *extensions[3]; + +#ifdef HAVE_X11_PLATFORM + xcb_connection_t *conn; +#endif + #ifdef HAVE_WAYLAND_PLATFORM struct wl_display *wl_dpy; struct wl_drm *wl_server_drm; @@ -120,17 +126,19 @@ struct dri2_egl_surface { _EGLSurface base; __DRIdrawable *dri_drawable; - xcb_drawable_t drawable; __DRIbuffer buffers[5]; int buffer_count; - xcb_xfixes_region_t region; int have_fake_front; int swap_interval; +#ifdef HAVE_X11_PLATFORM + xcb_drawable_t drawable; + xcb_xfixes_region_t region; int depth; int bytes_per_pixel; xcb_gcontext_t gc; xcb_gcontext_t swapgc; +#endif enum dri2_surface_type type; #ifdef HAVE_WAYLAND_PLATFORM diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile index 820788d696b..cb8f0551293 100644 --- a/src/egl/main/Makefile +++ b/src/egl/main/Makefile @@ -58,11 +58,15 @@ LOCAL_LIBS = ifeq ($(filter dri2, $(EGL_DRIVERS_DIRS)),dri2) LOCAL_CFLAGS += -D_EGL_BUILT_IN_DRIVER_DRI2 LOCAL_LIBS += $(TOP)/src/egl/drivers/dri2/libegl_dri2.a +ifneq ($(findstring x11, $(EGL_PLATFORMS)),) +EGL_LIB_DEPS += $(XCB_DRI2_LIBS) +endif ifneq ($(findstring wayland, $(EGL_PLATFORMS)),) LOCAL_LIBS += $(TOP)/src/egl/wayland/wayland-drm/libwayland-drm.a endif -EGL_LIB_DEPS += $(XCB_DRI2_LIBS) $(LIBUDEV_LIBS) $(DLOPEN_LIBS) $(LIBDRM_LIB) $(WAYLAND_LIBS) +EGL_LIB_DEPS += $(LIBUDEV_LIBS) $(DLOPEN_LIBS) $(LIBDRM_LIB) $(WAYLAND_LIBS) endif + ifeq ($(filter glx, $(EGL_DRIVERS_DIRS)),glx) LOCAL_CFLAGS += -D_EGL_BUILT_IN_DRIVER_GLX LOCAL_LIBS += $(TOP)/src/egl/drivers/glx/libegl_glx.a -- cgit v1.2.3 From 83c68758be3589edeab4d20346388241dc2ebaac Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 12 May 2011 19:30:05 +0200 Subject: egl_dri2: Discard similar configs --- src/egl/drivers/dri2/egl_dri2.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/egl') diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 10309e6eeaf..ea8c8fba8c0 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -200,10 +200,8 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, else if (!double_buffer && !conf->dri_single_config) conf->dri_single_config = dri_config; else - /* a similar config type is already added - * => attach it as new config - */ - num_configs = 0; + /* a similar config type is already added (unlikely) => discard */ + return NULL; } else if (num_configs == 0) { conf = malloc(sizeof *conf); -- cgit v1.2.3