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

John Kåre Alsaker john.kare.alsaker at gmail.com
Sat Sep 29 09:21:08 PDT 2012


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

diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h
index 3a11cd4..bcdc342 100644
--- a/src/gallium/include/state_tracker/st_api.h
+++ b/src/gallium/include/state_tracker/st_api.h
@@ -202,6 +202,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 b76cb9a..81e61f3 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.c
+++ b/src/gallium/state_trackers/dri/common/dri_screen.c
@@ -328,6 +328,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 ff48b02..e2aab55 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.h
+++ b/src/gallium/state_trackers/dri/common/dri_screen.h
@@ -83,6 +83,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 78852fb..8f61c37 100755
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -636,6 +636,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;
@@ -727,6 +728,34 @@ 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) {
+      if(!image->texture)
+         return NULL;
+
+      format = util_format_srgb(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)
 {
@@ -735,7 +764,7 @@ dri2_destroy_image(__DRIimage *img)
 }
 
 static struct __DRIimageExtensionRec dri2ImageExtension = {
-    { __DRI_IMAGE, 5 },
+    { __DRI_IMAGE, 6 },
     dri2_create_image_from_name,
     dri2_create_image_from_renderbuffer,
     dri2_destroy_image,
@@ -745,6 +774,7 @@ static struct __DRIimageExtensionRec dri2ImageExtension = {
     dri2_validate_usage,
     dri2_from_names,
     dri2_from_planar,
+    dri2_duplicate_image,
 };
 
 /*
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index 88b886d..d3de42e 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -807,6 +807,10 @@ st_manager_get_egl_image_surface(struct st_context *st,
       return NULL;
 
    u_surface_default_template(&surf_tmpl, stimg.texture, usage);
+
+   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.7.12.1



More information about the mesa-dev mailing list