[RFC 4/9] egl_dri2: use gbm_surface as the native window type in drm platform
Ander Conselvan de Oliveira
conselvan2 at gmail.com
Wed Dec 14 02:00:03 PST 2011
From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
src/egl/drivers/dri2/egl_dri2.h | 7 +++
src/egl/drivers/dri2/platform_drm.c | 100 ++++++++++++++++++++++++++++++++++-
2 files changed, 106 insertions(+), 1 deletions(-)
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 193a866..206902b 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -175,6 +175,13 @@ struct dri2_egl_surface
int format;
#endif
+#ifdef HAVE_DRM_PLATFORM
+ struct gbm_dri_surface *gbm_surf;
+#ifndef HAVE_WAYLAND_PLATFORM
+ __DRIbuffer *dri_buffers[__DRI_BUFFER_COUNT];
+#endif
+#endif
+
#ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index bd3d1e0..6ec63c1 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -37,6 +37,101 @@
#include "egl_dri2.h"
+static _EGLSurface *
+dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
+ _EGLConfig *conf, EGLNativeWindowType window,
+ const EGLint *attrib_list)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);
+ struct dri2_egl_surface *dri2_surf;
+ struct dri2_egl_buffer *dri2_buf;
+ struct gbm_dri_surface *surf;
+ int i;
+
+ (void) drv;
+
+ dri2_surf = malloc(sizeof *dri2_surf);
+ if (!dri2_surf) {
+ _eglError(EGL_BAD_ALLOC, "dri2_create_surface");
+ return NULL;
+ }
+
+ if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list))
+ goto cleanup_surf;
+
+ for (i = 0; i < __DRI_BUFFER_COUNT; ++i)
+ dri2_surf->dri_buffers[i] = NULL;
+
+ switch (type) {
+ case EGL_WINDOW_BIT:
+ surf = gbm_dri_surface((struct gbm_surface *) window);
+ dri2_surf->gbm_surf = surf;
+
+ dri2_surf->base.Width = surf->base.width;
+ dri2_surf->base.Height = surf->base.height;
+
+ break;
+ default:
+ goto cleanup_surf;
+ }
+
+ dri2_surf->dri_drawable =
+ (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen,
+ dri2_conf->dri_double_config,
+ dri2_surf->gbm_surf);
+
+ if (dri2_surf->dri_drawable == NULL) {
+ _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable");
+ goto cleanup_surf;
+ }
+
+ return &dri2_surf->base;
+
+ cleanup_surf:
+ free(dri2_surf);
+
+ return NULL;
+}
+
+static _EGLSurface *
+dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
+ _EGLConfig *conf, EGLNativeWindowType window,
+ const EGLint *attrib_list)
+{
+ return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf,
+ window, attrib_list);
+}
+
+static EGLBoolean
+dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+ int i;
+
+ if (!_eglPutSurface(surf))
+ return EGL_TRUE;
+
+ (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable);
+
+ for (i = 0; i < __DRI_BUFFER_COUNT; i++)
+ if (dri2_surf->dri_buffers[i])
+ dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
+ dri2_surf->dri_buffers[i]);
+
+ free(surf);
+
+ return EGL_TRUE;
+}
+
+static EGLBoolean
+dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
+{
+ return EGL_FALSE;
+}
+
+
static _EGLImage *
dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
EGLClientBuffer buffer, const EGLint *attr_list)
@@ -151,8 +246,11 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
for (i = 0; dri2_dpy->driver_configs[i]; i++)
dri2_add_config(disp, dri2_dpy->driver_configs[i],
- i + 1, 0, 0, NULL, NULL);
+ i + 1, 0, EGL_WINDOW_BIT, NULL, NULL);
+ drv->API.CreateWindowSurface = dri2_create_window_surface;
+ drv->API.DestroySurface = dri2_destroy_surface;
+ drv->API.SwapBuffers = dri2_swap_buffers;
drv->API.CreateImageKHR = dri2_drm_create_image_khr;
#ifdef HAVE_WAYLAND_PLATFORM
--
1.7.4.1
More information about the wayland-devel
mailing list