gbm: Validate usage flags in gbm_bo_create_from_egl_image()
authorKristian Høgsberg <krh@bitplanet.net>
Wed, 18 Jan 2012 20:32:35 +0000 (15:32 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 18 Jan 2012 20:32:51 +0000 (15:32 -0500)
The entry point is supposed to validate that the EGLImage is suitable for
the passed in usage flags, but that was never implemented.

include/GL/internal/dri_interface.h
src/gallium/state_trackers/dri/drm/dri2.c
src/gbm/backends/dri/gbm_dri.c
src/mesa/drivers/dri/intel/intel_screen.c
src/mesa/drivers/dri/radeon/radeon_screen.c

index b21445f104642f16c9e8dbb1b5913596b440fe63..701e83e7831091b75ad62daa5c23767ae436a6cb 100644 (file)
@@ -894,7 +894,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 1
+#define __DRI_IMAGE_VERSION 2
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -946,6 +946,13 @@ struct __DRIimageExtensionRec {
     * The new __DRIimage will share the content with the old one, see dup(2).
     */
    __DRIimage *(*dupImage)(__DRIimage *image, void *loaderPrivate);
+
+   /**
+    * Validate that a __DRIimage can be used a certain way.
+    *
+    * \since 2
+    */
+   GLboolean (*validateUsage)(__DRIimage *image, unsigned int use);
 };
 
 
index 2f7f1cba7e6b9c5ed0024ed8c49ff539801f893c..afd91ee27a18ffd4245789898a0426f8bea0a7d5 100644 (file)
@@ -626,7 +626,7 @@ dri2_destroy_image(__DRIimage *img)
 }
 
 static struct __DRIimageExtensionRec dri2ImageExtension = {
-    { __DRI_IMAGE, __DRI_IMAGE_VERSION },
+    { __DRI_IMAGE, 1 },
     dri2_create_image_from_name,
     dri2_create_image_from_renderbuffer,
     dri2_destroy_image,
index 9de8cb61162c13ec1095c677559b19ce78fdc4dc..ddd153a7db44056f3d21174a617d8bd6e06c243b 100644 (file)
@@ -255,6 +255,7 @@ gbm_dri_bo_create_from_egl_image(struct gbm_device *gbm,
 {
    struct gbm_dri_device *dri = gbm_dri_device(gbm);
    struct gbm_dri_bo *bo;
+   unsigned dri_use = 0;
 
    (void) egl_dpy;
 
@@ -276,6 +277,16 @@ gbm_dri_bo_create_from_egl_image(struct gbm_device *gbm,
    if (bo->image == NULL)
       return NULL;
    
+   if (usage & GBM_BO_USE_SCANOUT)
+      dri_use |= __DRI_IMAGE_USE_SCANOUT;
+   if (usage & GBM_BO_USE_CURSOR_64X64)
+      dri_use |= __DRI_IMAGE_USE_CURSOR;
+   if (dri->image->base.version >= 2 &&
+       !dri->image->validateUsage(bo->image, dri_use)) {
+      free(bo);
+      return NULL;
+   }
+
    dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
                           &bo->base.base.handle.s32);
    dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE,
index 0566907fb3d9e726336be29b672f621c6ec64b66..094ff568c44763e875f2cc8067f9968c44a6b928 100644 (file)
@@ -324,14 +324,26 @@ intel_dup_image(__DRIimage *orig_image, void *loaderPrivate)
    return image;
 }
 
+static GLboolean
+intel_validate_usage(__DRIimage *image, unsigned int use)
+{
+   if (use & __DRI_IMAGE_USE_CURSOR) {
+      if (image->region->width != 64 || image->region->height != 64)
+        return GL_FALSE;
+   }
+
+   return GL_TRUE;
+}
+
 static struct __DRIimageExtensionRec intelImageExtension = {
-    { __DRI_IMAGE, __DRI_IMAGE_VERSION },
+    { __DRI_IMAGE, 2 },
     intel_create_image_from_name,
     intel_create_image_from_renderbuffer,
     intel_destroy_image,
     intel_create_image,
     intel_query_image,
-    intel_dup_image
+    intel_dup_image,
+    intel_validate_usage
 };
 
 static const __DRIextension *intelScreenExtensions[] = {
index 2e364d028075d4ae1542a7d8be3570965484a27e..a5dff983aa9f9618a7a5945b0e4d3250605a4217 100644 (file)
@@ -375,7 +375,7 @@ radeon_query_image(__DRIimage *image, int attrib, int *value)
 }
 
 static struct __DRIimageExtensionRec radeonImageExtension = {
-    { __DRI_IMAGE, __DRI_IMAGE_VERSION },
+    { __DRI_IMAGE, 1 },
    radeon_create_image_from_name,
    radeon_create_image_from_renderbuffer,
    radeon_destroy_image,