Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / state_trackers / egl / common / egl_g3d_image.c
index be9c88e5e478654f309791be002914d0db11cfa4..e6ff100de04fc985d5d3d5f19d1b1d416edd83f6 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"
 
 /**
@@ -48,17 +48,11 @@ static struct pipe_resource *
 egl_g3d_reference_native_pixmap(_EGLDisplay *dpy, EGLNativePixmapType pix)
 {
    struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_config *gconf;
    struct native_surface *nsurf;
    struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
    enum native_attachment natt;
 
-   gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, pix));
-   if (!gconf)
-      return NULL;
-
-   nsurf = gdpy->native->create_pixmap_surface(gdpy->native,
-         pix, gconf->native);
+   nsurf = gdpy->native->create_pixmap_surface(gdpy->native, pix, NULL);
    if (!nsurf)
       return NULL;
 
@@ -137,13 +131,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;
 
@@ -175,12 +167,14 @@ egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name,
    templ.width0 = attrs.Width;
    templ.height0 = attrs.Height;
    templ.depth0 = 1;
+   templ.array_size = 1;
 
    memset(&wsh, 0, sizeof(wsh));
    wsh.handle = (unsigned) name;
-   wsh.stride = attrs.DRMBufferStrideMESA;
+   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 */
@@ -192,7 +186,7 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
 {
    struct pipe_resource *ptex;
    struct egl_g3d_image *gimg;
-   unsigned face = 0, level = 0, zslice = 0;
+   unsigned level = 0, layer = 0;
 
    gimg = CALLOC_STRUCT(egl_g3d_image);
    if (!gimg) {
@@ -232,7 +226,7 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
       FREE(gimg);
       return NULL;
    }
-   if (zslice > ptex->depth0) {
+   if (layer >= (u_minify(ptex->depth0, level) + ptex->array_size - 1)) {
       _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
       pipe_resource_reference(&gimg->texture, NULL);
       FREE(gimg);
@@ -241,9 +235,8 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
 
    /* transfer the ownership to the image */
    gimg->texture = ptex;
-   gimg->face = face;
    gimg->level = level;
-   gimg->zslice = zslice;
+   gimg->layer = layer;
 
    return &gimg->base;
 }
@@ -289,9 +282,8 @@ egl_g3d_create_drm_image(_EGLDriver *drv, _EGLDisplay *dpy,
 
    /* transfer the ownership to the image */
    gimg->texture = ptex;
-   gimg->face = 0;
    gimg->level = 0;
-   gimg->zslice = 0;
+   gimg->layer = 0;
 
    return &gimg->base;
 }
@@ -302,10 +294,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;
 
@@ -313,9 +303,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;
    }
@@ -324,7 +314,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)