From 393b6c4423de71d8fb28644c4c836bd6700df428 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= <krh@bitplanet.net>
Date: Thu, 26 Jul 2012 12:13:19 -0400
Subject: [PATCH] gallium/dri: Support __DRIimage version 5

---
 src/gallium/state_trackers/dri/drm/dri2.c |   52 +++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 3 deletions(-)

diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index d0be710..9e02240 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -545,8 +545,6 @@ dri2_create_image(__DRIscreen *_screen,
       pf = PIPE_FORMAT_NONE;
       break;
    }
-   if (pf == PIPE_FORMAT_NONE)
-      return NULL;
 
    img = CALLOC_STRUCT(__DRIimageRec);
    if (!img)
@@ -633,14 +631,62 @@ dri2_destroy_image(__DRIimage *img)
    FREE(img);
 }
 
+static GLboolean
+dri2_validate_usage(__DRIimage *image, unsigned int use)
+{
+   if (use & __DRI_IMAGE_USE_CURSOR) {
+      if (image->texture->width0 != 64 || image->texture->height0 != 64)
+	 return GL_FALSE;
+   }
+
+   /* We only support write for cursor drm images */
+   if ((use & __DRI_IMAGE_USE_WRITE) &&
+       use != (__DRI_IMAGE_USE_WRITE | __DRI_IMAGE_USE_CURSOR))
+      return GL_FALSE;
+
+   return GL_TRUE;
+}
+
+static int
+dri2_image_write(__DRIimage *image, const void *buf, size_t count)
+{
+   return 0;
+}
+
+static __DRIimage *
+dri2_create_sub_image(__DRIimage *parent,
+                      int width, int height, int dri_format,
+                      int offset, int pitch, void *loaderPrivate)
+{
+   __DRIimage *img;
+
+   if (offset != 0)
+      return NULL;
+
+   img = CALLOC_STRUCT(__DRIimageRec);
+   if (!img)
+      return NULL;
+
+   img->texture = NULL;
+   pipe_resource_reference(&img->texture, parent->texture);
+   img->level = parent->level;
+   img->layer = parent->layer;
+   img->loader_private = loaderPrivate;
+
+   return img;
+}
+
 static struct __DRIimageExtensionRec dri2ImageExtension = {
-    { __DRI_IMAGE, 1 },
+    { __DRI_IMAGE, 5 },
     dri2_create_image_from_name,
     dri2_create_image_from_renderbuffer,
     dri2_destroy_image,
     dri2_create_image,
     dri2_query_image,
     dri2_dup_image,
+    dri2_validate_usage,
+    dri2_image_write,
+    dri2_create_sub_image
 };
 
 /*
-- 
1.7.10.2

