st/egl: Hookup gbm for drm backend
authorBenjamin Franzke <benjaminfranzke@googlemail.com>
Mon, 30 May 2011 09:40:52 +0000 (11:40 +0200)
committerBenjamin Franzke <benjaminfranzke@googlemail.com>
Thu, 23 Jun 2011 19:07:17 +0000 (21:07 +0200)
src/gallium/state_trackers/egl/Makefile
src/gallium/state_trackers/egl/common/egl_g3d.c
src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/drm/modeset.c
src/gallium/state_trackers/egl/drm/native_drm.c
src/gallium/state_trackers/egl/drm/native_drm.h
src/gallium/targets/egl/Makefile

index 763e7b58a492cf7a14c2c14e3ce0e49c683bf7bf..1c970222c1f97a54059c8491995e819f518553ba 100644 (file)
@@ -33,7 +33,8 @@ wayland_INCLUDES = \
 wayland_SOURCES = $(wildcard wayland/*.c)
 wayland_OBJECTS = $(wayland_SOURCES:.c=.o)
 
-drm_INCLUDES = -I$(TOP)/src/gallium/winsys $(shell pkg-config --cflags-only-I libdrm)
+drm_INCLUDES = -I$(TOP)/src/gallium/winsys $(shell pkg-config --cflags-only-I libdrm) \
+              -I$(TOP)/src/gbm/main -I$(TOP)/src/gallium/state_trackers/gbm
 drm_SOURCES = $(wildcard drm/*.c)
 drm_OBJECTS = $(drm_SOURCES:.c=.o)
 
index 29dbbefbf481c74f866c9ad64a1bc017cf965317..6a40f4d2a4bd248440d6ce2e46d4bb2d5e5c3ce6 100644 (file)
@@ -72,10 +72,26 @@ egl_g3d_new_sw_screen(struct native_display *ndpy, struct sw_winsys *ws)
    return gdpy->loader->create_sw_screen(ws);
 }
 
+static struct pipe_resource *
+egl_g3d_lookup_egl_image(struct native_display *ndpy, void *egl_image)
+{
+   _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data;
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct st_egl_image img;
+   struct pipe_resource *resource = NULL;
+
+   memset(&img, 0, sizeof(img));
+   if (gdpy->smapi->get_egl_image(gdpy->smapi, egl_image, &img))
+      resource = img.texture;
+
+   return resource;
+}
+
 static struct native_event_handler egl_g3d_native_event_handler = {
    egl_g3d_invalid_surface,
    egl_g3d_new_drm_screen,
-   egl_g3d_new_sw_screen
+   egl_g3d_new_sw_screen,
+   egl_g3d_lookup_egl_image
 };
 
 /**
index 8646e52ed7c96bcfb18e304e7389d22c4fdc3232..cb261964864d381d7f880c32a1acda735f6d5c40 100644 (file)
@@ -219,6 +219,9 @@ struct native_event_handler {
                                          const char *name, int fd);
    struct pipe_screen *(*new_sw_screen)(struct native_display *ndpy,
                                         struct sw_winsys *ws);
+
+   struct pipe_resource *(*lookup_egl_image)(struct native_display *ndpy,
+                                             void *egl_image);
 };
 
 /**
index 3fff9540905d479e430d0773797a8b83928e333f..73968d1343bb3994610382c0c7839da065e6fd9d 100644 (file)
@@ -290,6 +290,42 @@ drm_display_create_surface(struct native_display *ndpy,
    return drmsurf;
 }
 
+struct native_surface *
+drm_display_create_surface_from_resource(struct native_display *ndpy,
+                                         struct pipe_resource *resource)
+{
+   struct drm_display *drmdpy = drm_display(ndpy);
+   struct drm_surface *drmsurf;
+   enum native_attachment natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+
+   drmsurf = CALLOC_STRUCT(drm_surface);
+   if (!drmsurf)
+      return NULL;
+
+   drmsurf->drmdpy = drmdpy;
+   drmsurf->color_format = resource->format;
+   drmsurf->width = resource->width0;
+   drmsurf->height = resource->height0;
+   drmsurf->have_pageflip = FALSE;
+
+   drmsurf->rsurf = resource_surface_create(drmdpy->base.screen,
+         drmsurf->color_format,
+         PIPE_BIND_RENDER_TARGET |
+         PIPE_BIND_SAMPLER_VIEW |
+         PIPE_BIND_DISPLAY_TARGET |
+         PIPE_BIND_SCANOUT);
+   
+   resource_surface_import_resource(drmsurf->rsurf, natt, resource);
+
+   drmsurf->base.destroy = drm_surface_destroy;
+   drmsurf->base.present = drm_surface_present;
+   drmsurf->base.validate = drm_surface_validate;
+   drmsurf->base.wait = drm_surface_wait;
+
+   return &drmsurf->base;
+}
+        
+
 /**
  * Choose a CRTC that supports all given connectors.
  */
index 725fe28e4e23147926bd65fe42ed28a4fdc88e92..4814e8f888fb976ab7851b4f8e04ce86a2fe59f1 100644 (file)
@@ -33,6 +33,8 @@
 
 #include "native_drm.h"
 
+#include "gbm_gallium_drmint.h"
+
 #ifdef HAVE_LIBUDEV
 #include <libudev.h>
 #endif
@@ -136,33 +138,6 @@ drm_display_destroy(struct native_display *ndpy)
    FREE(drmdpy);
 }
 
-/**
- * Initialize KMS and pipe screen.
- */
-static boolean
-drm_display_init_screen(struct native_display *ndpy)
-{
-   struct drm_display *drmdpy = drm_display(ndpy);
-   drmVersionPtr version;
-
-   version = drmGetVersion(drmdpy->fd);
-   if (!version) {
-      _eglLog(_EGL_WARNING, "invalid fd %d", drmdpy->fd);
-      return FALSE;
-   }
-
-   drmdpy->base.screen =
-      drmdpy->event_handler->new_drm_screen(&drmdpy->base, NULL, drmdpy->fd);
-   drmFreeVersion(version);
-
-   if (!drmdpy->base.screen) {
-      _eglLog(_EGL_DEBUG, "failed to create DRM screen");
-      return FALSE;
-   }
-
-   return TRUE;
-}
-
 static struct pipe_resource *
 drm_display_import_buffer(struct native_display *ndpy,
                           const struct pipe_resource *templ,
@@ -281,9 +256,19 @@ static struct native_display_wayland_bufmgr drm_display_wayland_bufmgr = {
 
 #endif /* HAVE_WAYLAND_BACKEND */
 
+static struct native_surface *
+drm_create_pixmap_surface(struct native_display *ndpy,
+                              EGLNativePixmapType pix,
+                              const struct native_config *nconf)
+{
+   struct gbm_gallium_drm_bo *bo = (void *) pix;
+
+   return drm_display_create_surface_from_resource(ndpy, bo->resource);
+}
+
 static struct native_display *
-drm_create_display(int fd, struct native_event_handler *event_handler,
-                   void *user_data)
+drm_create_display(struct gbm_gallium_drm_device *gbmdrm,
+                   struct native_event_handler *event_handler, void *user_data)
 {
    struct drm_display *drmdpy;
 
@@ -291,20 +276,24 @@ drm_create_display(int fd, struct native_event_handler *event_handler,
    if (!drmdpy)
       return NULL;
 
-   drmdpy->fd = fd;
-   drmdpy->device_name = drm_get_device_name(fd);
+   drmdpy->fd = gbmdrm->base.base.fd;
+   drmdpy->device_name = drm_get_device_name(drmdpy->fd);
+
+   gbmdrm->lookup_egl_image = (struct pipe_resource *(*)(void *, void *))
+      event_handler->lookup_egl_image;
+   gbmdrm->lookup_egl_image_data = &drmdpy->base;
+
    drmdpy->event_handler = event_handler;
    drmdpy->base.user_data = user_data;
 
-   if (!drm_display_init_screen(&drmdpy->base)) {
-      drm_display_destroy(&drmdpy->base);
-      return NULL;
-   }
+   drmdpy->base.screen = gbmdrm->screen;
 
    drmdpy->base.destroy = drm_display_destroy;
    drmdpy->base.get_param = drm_display_get_param;
    drmdpy->base.get_configs = drm_display_get_configs;
 
+   drmdpy->base.create_pixmap_surface = drm_create_pixmap_surface;
+
    drmdpy->base.buffer = &drm_display_buffer;
 #ifdef HAVE_WAYLAND_BACKEND
    if (drmdpy->device_name)
@@ -326,18 +315,24 @@ native_set_event_handler(struct native_event_handler *event_handler)
 static struct native_display *
 native_create_display(void *dpy, boolean use_sw, void *user_data)
 {
+   struct gbm_gallium_drm_device *gbm;
    int fd;
 
-   if (dpy) {
-      fd = dup((int) pointer_to_intptr(dpy));
-   }
-   else {
+   gbm = dpy;
+
+   if (gbm == NULL) {
       fd = open("/dev/dri/card0", O_RDWR);
+      gbm = gbm_gallium_drm_device(gbm_create_device(fd));
    }
-   if (fd < 0)
+
+   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)
       return NULL;
 
-   return drm_create_display(fd, drm_event_handler, user_data);
+   return drm_create_display(gbm, drm_event_handler, user_data);
 }
 
 static const struct native_platform drm_platform = {
index 41cdc4f9d041d75118ceae94becc0ff175272ccf..f938edeada7b3a489d475a49a32cc7a833e65950 100644 (file)
@@ -154,4 +154,8 @@ drm_display_init_modeset(struct native_display *ndpy);
 void
 drm_display_fini_modeset(struct native_display *ndpy);
 
+struct native_surface *
+drm_display_create_surface_from_resource(struct native_display *ndpy,
+                                         struct pipe_resource *resource);
+
 #endif /* _NATIVE_DRM_H_ */
index dd566bd9a0627bed3a200d3816d95e284d1e1852..0cbcc8f731574d6ba5359c2fa35caa548567ee95 100644 (file)
@@ -52,7 +52,7 @@ egl_LIBS += $(TOP)/src/gallium/winsys/sw/wayland/libws_wayland.a
 egl_LIBS += $(TOP)/src/egl/wayland/wayland-drm/libwayland-drm.a
 endif
 ifneq ($(findstring drm, $(EGL_PLATFORMS)),)
-egl_SYS += $(LIBUDEV_LIBS) $(LIBDRM_LIB)
+egl_SYS += $(LIBUDEV_LIBS) $(LIBDRM_LIB) -lgbm
 endif
 ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),)
 egl_LIBS += $(TOP)/src/gallium/winsys/sw/fbdev/libfbdev.a