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

John Kåre Alsaker john.kare.alsaker at gmail.com
Sat Feb 23 07:53:23 PST 2013


---
 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          | 39 +++++++++++++++++++++-
 src/mesa/state_tracker/st_manager.c                |  4 +++
 5 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h
index 9f3d2a1..1e63ed3 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 a908e28..92abaf9 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.c
+++ b/src/gallium/state_trackers/dri/common/dri_screen.c
@@ -315,6 +315,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 181b22f..d37c393 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.h
+++ b/src/gallium/state_trackers/dri/common/dri_screen.h
@@ -84,6 +84,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 f8d311c..54339fe 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -658,6 +658,7 @@ dri2_dup_image(__DRIimage *image, void *loaderPrivate)
    pipe_resource_reference(&img->texture, image->texture);
    img->level = image->level;
    img->layer = image->layer;
+   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;
@@ -749,6 +750,40 @@ dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate)
    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;
+}
+
 static void
 dri2_destroy_image(__DRIimage *img)
 {
@@ -757,7 +792,7 @@ dri2_destroy_image(__DRIimage *img)
 }
 
 static struct __DRIimageExtensionRec dri2ImageExtension = {
-    { __DRI_IMAGE, 5 },
+    { __DRI_IMAGE, 7 },
     dri2_create_image_from_name,
     dri2_create_image_from_renderbuffer,
     dri2_destroy_image,
@@ -767,6 +802,8 @@ static struct __DRIimageExtensionRec dri2ImageExtension = {
     dri2_validate_usage,
     dri2_from_names,
     dri2_from_planar,
+    NULL,
+    dri2_duplicate_image,
 };
 
 /*
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index a3a6771..3659499 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -810,6 +810,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.8.1.3



More information about the mesa-dev mailing list