Mesa (pipe-video): [g3dvl] rework video buffer format handling

Christian König deathsimple at kemper.freedesktop.org
Tue Jun 7 15:35:53 PDT 2011


Module: Mesa
Branch: pipe-video
Commit: 00b4e48560f4d576b7b1924257322f5167e58c8d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=00b4e48560f4d576b7b1924257322f5167e58c8d

Author: Christian König <deathsimple at vodafone.de>
Date:   Tue Jun  7 22:01:30 2011 +0200

[g3dvl] rework video buffer format handling

---

 src/gallium/auxiliary/vl/vl_context.c      |   50 +++++++++++----------------
 src/gallium/auxiliary/vl/vl_video_buffer.c |   27 +++++++++++++++
 src/gallium/auxiliary/vl/vl_video_buffer.h |    6 +++
 src/gallium/include/pipe/p_video_context.h |    5 +--
 4 files changed, 55 insertions(+), 33 deletions(-)

diff --git a/src/gallium/auxiliary/vl/vl_context.c b/src/gallium/auxiliary/vl/vl_context.c
index e4805ea..e3aa49d 100644
--- a/src/gallium/auxiliary/vl/vl_context.c
+++ b/src/gallium/auxiliary/vl/vl_context.c
@@ -35,18 +35,6 @@
 #include "vl_compositor.h"
 #include "vl_mpeg12_decoder.h"
 
-const enum pipe_format const_resource_formats_YV12[3] = {
-   PIPE_FORMAT_R8_UNORM,
-   PIPE_FORMAT_R8_UNORM,
-   PIPE_FORMAT_R8_UNORM
-};
-
-const enum pipe_format const_resource_formats_NV12[3] = {
-   PIPE_FORMAT_R8_UNORM,
-   PIPE_FORMAT_R8G8_UNORM,
-   PIPE_FORMAT_NONE
-};
-
 static void
 vl_context_destroy(struct pipe_video_context *context)
 {
@@ -76,15 +64,28 @@ vl_context_get_param(struct pipe_video_context *context, int param)
 static boolean
 vl_context_is_format_supported(struct pipe_video_context *context,
                                enum pipe_format format,
-                               unsigned usage)
+                               enum pipe_video_profile profile)
 {
    struct vl_context *ctx = (struct vl_context*)context;
+   const enum pipe_format *resource_formats;
+   unsigned i;
 
    assert(context);
 
-   return ctx->pipe->screen->is_format_supported(ctx->pipe->screen, format,
-                                                 PIPE_TEXTURE_2D,
-                                                 0, usage);
+   resource_formats = vl_video_buffer_formats(ctx->pipe, format);
+   if (!resource_formats)
+      return false;
+
+   for(i = 0; i < VL_MAX_PLANES; ++i) {
+      if (!resource_formats[i])
+         continue;
+
+      if (!ctx->pipe->screen->is_format_supported(ctx->pipe->screen, resource_formats[i],
+                                                  PIPE_TEXTURE_2D, 0, PIPE_USAGE_STATIC))
+         return false;
+   }
+
+   return true;
 }
 
 static struct pipe_surface *
@@ -215,27 +216,16 @@ vl_context_create_buffer(struct pipe_video_context *context,
                          unsigned width, unsigned height)
 {
    struct vl_context *ctx = (struct vl_context*)context;
+   const enum pipe_format *resource_formats;
    struct pipe_video_buffer *result;
    unsigned buffer_width, buffer_height;
 
-   const enum pipe_format *resource_formats;
-
    assert(context);
    assert(width > 0 && height > 0);
 
-   switch(buffer_format) {
-   case PIPE_FORMAT_YV12:
-      resource_formats = const_resource_formats_YV12;
-      break;
-
-   case PIPE_FORMAT_NV12:
-      resource_formats = const_resource_formats_NV12;
-      break;
-
-   default:
-      assert(0);
+   resource_formats = vl_video_buffer_formats(ctx->pipe, buffer_format);
+   if (!resource_formats)
       return NULL;
-   }
 
    buffer_width = ctx->pot_buffers ? util_next_power_of_two(width) : align(width, MACROBLOCK_WIDTH);
    buffer_height = ctx->pot_buffers ? util_next_power_of_two(height) : align(height, MACROBLOCK_HEIGHT);
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c
index 976d228..93bc096 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.c
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.c
@@ -38,6 +38,33 @@
 
 #include "vl_video_buffer.h"
 
+const enum pipe_format const_resource_formats_YV12[3] = {
+   PIPE_FORMAT_R8_UNORM,
+   PIPE_FORMAT_R8_UNORM,
+   PIPE_FORMAT_R8_UNORM
+};
+
+const enum pipe_format const_resource_formats_NV12[3] = {
+   PIPE_FORMAT_R8_UNORM,
+   PIPE_FORMAT_R8G8_UNORM,
+   PIPE_FORMAT_NONE
+};
+
+const enum pipe_format *
+vl_video_buffer_formats(struct pipe_context *pipe, enum pipe_format format)
+{
+   switch(format) {
+   case PIPE_FORMAT_YV12:
+      return const_resource_formats_YV12;
+
+   case PIPE_FORMAT_NV12:
+      return const_resource_formats_NV12;
+
+   default:
+      return NULL;
+   }
+}
+
 static void
 vl_video_buffer_destroy(struct pipe_video_buffer *buffer)
 {
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.h b/src/gallium/auxiliary/vl/vl_video_buffer.h
index 2dca74f..728c6f5 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.h
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.h
@@ -50,6 +50,12 @@ struct vl_video_buffer
 };
 
 /**
+ * get subformats for each plane
+ */
+const enum pipe_format *
+vl_video_buffer_formats(struct pipe_context *pipe, enum pipe_format format);
+
+/**
  * initialize a buffer, creating its resources
  */
 struct pipe_video_buffer *
diff --git a/src/gallium/include/pipe/p_video_context.h b/src/gallium/include/pipe/p_video_context.h
index 2a30099..c9e618b 100644
--- a/src/gallium/include/pipe/p_video_context.h
+++ b/src/gallium/include/pipe/p_video_context.h
@@ -62,12 +62,11 @@ struct pipe_video_context
    int (*get_param)(struct pipe_video_context *context, int param);
 
    /**
-    * Check if the given pipe_format is supported as a texture or
-    * drawing surface.
+    * Check if the given pipe_format is supported as a video buffer
     */
    boolean (*is_format_supported)(struct pipe_video_context *context,
                                   enum pipe_format format,
-                                  unsigned usage);
+                                  enum pipe_video_profile profile);
 
    /**
     * create a surface of a texture



More information about the mesa-commit mailing list