[Mesa-dev] [PATCH v3 3/5] gallium: Implement DRIimageExtension.duplicateImage

John Kåre Alsaker john.kare.alsaker at gmail.com
Sat Apr 26 07:25:53 PDT 2014


---
 src/gallium/include/state_tracker/st_api.h         |  1 +
 src/gallium/state_trackers/dri/common/dri_screen.c |  1 +
 src/gallium/state_trackers/dri/common/dri_screen.h |  1 +
 src/gallium/state_trackers/dri/drm/dri2.c          | 42 ++++++++++++++++++++--
 src/mesa/state_tracker/st_manager.c                |  4 +++
 5 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h
index 9dcb76f..28ac9aa 100644
--- a/src/gallium/include/state_tracker/st_api.h
+++ b/src/gallium/include/state_tracker/st_api.h
@@ -203,6 +203,7 @@ struct st_egl_image
 {
    /* this is owned by the caller */
    struct pipe_resource *texture;
+   enum pipe_format format;
 
    unsigned level;
    unsigned layer;
diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c
index 7a6dcb2..996d150 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.c
+++ b/src/gallium/state_trackers/dri/common/dri_screen.c
@@ -326,6 +326,7 @@ dri_get_egl_image(struct st_manager *smapi,
 
    stimg->texture = NULL;
    pipe_resource_reference(&stimg->texture, img->texture);
+   stimg->format = img->format;
    stimg->level = img->level;
    stimg->layer = img->layer;
 
diff --git a/src/gallium/state_trackers/dri/common/dri_screen.h b/src/gallium/state_trackers/dri/common/dri_screen.h
index 7c8e582..cc09d18 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.h
+++ b/src/gallium/state_trackers/dri/common/dri_screen.h
@@ -89,6 +89,7 @@ dri_screen(__DRIscreen * sPriv)
 
 struct __DRIimageRec {
    struct pipe_resource *texture;
+   enum pipe_format format;
    unsigned level;
    unsigned layer;
    uint32_t dri_format;
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index 4f2a87e..fedeba5 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -817,6 +817,7 @@ dri2_dup_image(__DRIimage *image, void *loaderPrivate)
    img->level = image->level;
    img->layer = image->layer;
    img->dri_format = image->dri_format;
+   img->format = image->format;
    /* This should be 0 for sub images, but dup is also used for base images. */
    img->dri_components = image->dri_components;
    img->loader_private = loaderPrivate;
@@ -1025,6 +1026,41 @@ dri2_from_dma_bufs(__DRIscreen *screen,
    img->dri_components = dri_components;
 
    *error = __DRI_IMAGE_ERROR_SUCCESS;
+
+   return img;
+}
+
+static __DRIimage *
+dri2_duplicate_image(__DRIscreen *_screen, __DRIimage *image,
+                     unsigned int flags, void *loaderPrivate)
+{
+   enum pipe_format format;
+   struct dri_screen *screen = dri_screen(_screen);
+   __DRIimage *img = NULL;
+
+   if ((flags & __DRI_IMAGE_FLAG_SRGB_VIEW) && (flags & __DRI_IMAGE_FLAG_LINEAR_VIEW))
+      return NULL;
+
+   if (flags & (__DRI_IMAGE_FLAG_SRGB_VIEW | __DRI_IMAGE_FLAG_LINEAR_VIEW)) {
+      if (!image->texture)
+         return NULL;
+
+      if (flags & __DRI_IMAGE_FLAG_SRGB_VIEW)
+         format = util_format_srgb(image->texture->format);
+      else
+         format = util_format_linear(image->texture->format);
+
+      if (!screen->base.screen->is_format_supported(screen->base.screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW))
+         return NULL;
+
+      img = dri2_dup_image(image, loaderPrivate);
+
+      if (img)
+         img->format = format;
+   } else if (flags == 0) {
+      img = dri2_dup_image(image, loaderPrivate);
+   }
+
    return img;
 }
 
@@ -1036,7 +1072,7 @@ dri2_destroy_image(__DRIimage *img)
 }
 
 static struct __DRIimageExtensionRec dri2ImageExtension = {
-    { __DRI_IMAGE, 6 },
+    { __DRI_IMAGE, 9 },
     dri2_create_image_from_name,
     dri2_create_image_from_renderbuffer,
     dri2_destroy_image,
@@ -1047,6 +1083,9 @@ static struct __DRIimageExtensionRec dri2ImageExtension = {
     dri2_from_names,
     dri2_from_planar,
     dri2_create_from_texture,
+    NULL,
+    NULL,
+    dri2_duplicate_image,
 };
 
 /*
@@ -1102,7 +1141,6 @@ dri2_init_screen(__DRIscreen * sPriv)
       if (drmGetCap(sPriv->fd, DRM_CAP_PRIME, &cap) == 0 &&
           (cap & DRM_PRIME_CAP_IMPORT)) {
 
-         dri2ImageExtension.base.version = 8;
          dri2ImageExtension.createImageFromFds = dri2_from_fds;
          dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
       }
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index 314d342..5708e90 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -835,6 +835,10 @@ st_manager_get_egl_image_surface(struct st_context *st, void *eglimg)
       return NULL;
 
    u_surface_default_template(&surf_tmpl, stimg.texture);
+
+   if (stimg.format != PIPE_FORMAT_NONE)
+      surf_tmpl.format = stimg.format;
+
    surf_tmpl.u.tex.level = stimg.level;
    surf_tmpl.u.tex.first_layer = stimg.layer;
    surf_tmpl.u.tex.last_layer = stimg.layer;
-- 
1.9.2



More information about the mesa-dev mailing list