st/egl: Use native_display_buffer for EGL_MESA_drm_image.
authorChia-I Wu <olv@lunarg.com>
Sun, 10 Oct 2010 12:47:02 +0000 (20:47 +0800)
committerChia-I Wu <olv@lunarg.com>
Wed, 3 Nov 2010 09:50:25 +0000 (17:50 +0800)
native_display_buffer is just a wrapper to resource_{from,get}_handle
for drm backend.

src/gallium/state_trackers/egl/common/egl_g3d.c
src/gallium/state_trackers/egl/common/egl_g3d_image.c
src/gallium/state_trackers/egl/drm/native_drm.c

index 3d0d13cfb13375372c019966f662d0cb29d0c049..a3750ac56fb88035cc9512094a96c2c110b04a8b 100644 (file)
@@ -553,7 +553,8 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
 
    if (dpy->Platform == _EGL_PLATFORM_DRM) {
       dpy->Extensions.MESA_drm_display = EGL_TRUE;
-      dpy->Extensions.MESA_drm_image = EGL_TRUE;
+      if (gdpy->native->buffer)
+         dpy->Extensions.MESA_drm_image = EGL_TRUE;
    }
 
    if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
index 0c8ad339cc28da8076c0af9a7cf5cb37ab679154..6a1f8cc697b5144bbe39138672639f73fbb30972 100644 (file)
@@ -38,7 +38,7 @@
 #include "egl_g3d_api.h"
 #include "egl_g3d_image.h"
 
-/* move this to native display? */
+/* for struct winsys_handle */
 #include "state_tracker/drm_driver.h"
 
 /**
@@ -137,13 +137,11 @@ egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name,
                              _EGLImage *img, const EGLint *attribs)
 {
    struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct pipe_screen *screen = gdpy->native->screen;
    struct pipe_resource templ;
    struct winsys_handle wsh;
    _EGLImageAttribs attrs;
    EGLint format;
 
-   /* winsys_handle is in theory platform-specific */
    if (dpy->Platform != _EGL_PLATFORM_DRM)
       return NULL;
 
@@ -181,7 +179,7 @@ egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name,
    wsh.stride =
       attrs.DRMBufferStrideMESA * util_format_get_blocksize(templ.format);
 
-   return screen->resource_from_handle(screen, &templ, &wsh);
+   return gdpy->native->buffer->import_buffer(gdpy->native, &templ, &wsh);
 }
 
 #endif /* EGL_MESA_drm_image */
@@ -303,10 +301,8 @@ egl_g3d_export_drm_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img,
 {
    struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
    struct egl_g3d_image *gimg = egl_g3d_image(img);
-   struct pipe_screen *screen = gdpy->native->screen;
    struct winsys_handle wsh;
 
-   /* winsys_handle is in theory platform-specific */
    if (dpy->Platform != _EGL_PLATFORM_DRM)
       return EGL_FALSE;
 
@@ -314,9 +310,9 @@ egl_g3d_export_drm_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img,
    if (name) {
       memset(&handle, 0, sizeof(handle));
       wsh.type = DRM_API_HANDLE_TYPE_SHARED;
-      if (!screen->resource_get_handle(screen, gimg->texture, &wsh)) {
+      if (!gdpy->native->buffer->export_buffer(gdpy->native,
+                                               gimg->texture, &wsh))
          return EGL_FALSE;
-      }
 
       *name = wsh.handle;
    }
@@ -325,7 +321,8 @@ egl_g3d_export_drm_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img,
    if (handle || stride) {
       memset(&wsh, 0, sizeof(wsh));
       wsh.type = DRM_API_HANDLE_TYPE_KMS;
-      if (!screen->resource_get_handle(screen, gimg->texture, &wsh))
+      if (!gdpy->native->buffer->export_buffer(gdpy->native,
+                                               gimg->texture, &wsh))
          return EGL_FALSE;
 
       if (handle)
index 21555dcd0ed262f0bdbe94a9cfd964ef2027311d..3759c2a26dd113cf501113be2e2acc0b676c05b0 100644 (file)
@@ -185,6 +185,29 @@ drm_display_init_screen(struct native_display *ndpy)
    return TRUE;
 }
 
+static struct pipe_resource *
+drm_display_import_buffer(struct native_display *ndpy,
+                          const struct pipe_resource *templ,
+                          void *buf)
+{
+   return ndpy->screen->resource_from_handle(ndpy->screen,
+         templ, (struct winsys_handle *) buf);
+}
+
+static boolean
+drm_display_export_buffer(struct native_display *ndpy,
+                          struct pipe_resource *res,
+                          void *buf)
+{
+   return ndpy->screen->resource_get_handle(ndpy->screen,
+         res, (struct winsys_handle *) buf);
+}
+
+static struct native_display_buffer drm_display_buffer = {
+   drm_display_import_buffer,
+   drm_display_export_buffer
+};
+
 static struct native_display *
 drm_create_display(int fd, struct native_event_handler *event_handler,
                    void *user_data)
@@ -208,6 +231,7 @@ drm_create_display(int fd, struct native_event_handler *event_handler,
    drmdpy->base.get_param = drm_display_get_param;
    drmdpy->base.get_configs = drm_display_get_configs;
 
+   drmdpy->base.buffer = &drm_display_buffer;
    drm_display_init_modeset(&drmdpy->base);
 
    return &drmdpy->base;