[g3dvl] make resource format selection a public interface
authorChristian König <deathsimple@vodafone.de>
Tue, 12 Apr 2011 17:21:07 +0000 (19:21 +0200)
committerChristian König <deathsimple@vodafone.de>
Tue, 12 Apr 2011 17:21:07 +0000 (19:21 +0200)
src/gallium/auxiliary/vl/vl_context.c
src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
src/gallium/auxiliary/vl/vl_video_buffer.c
src/gallium/auxiliary/vl/vl_video_buffer.h
src/gallium/include/pipe/p_video_context.h
src/gallium/state_trackers/vdpau/surface.c
src/gallium/state_trackers/xorg/xvmc/surface.c

index 2bc027fedc54632e11fba761d0d8eb50ea179064..ba7325487326e7d4f21d94b8daef2dd9c1973f1c 100644 (file)
@@ -199,15 +199,10 @@ vl_context_create_decoder(struct pipe_video_context *context,
 static struct pipe_video_buffer *
 vl_context_create_buffer(struct pipe_video_context *context,
                          enum pipe_format buffer_format,
+                         enum pipe_format resource_formats[3],
                          enum pipe_video_chroma_format chroma_format,
                          unsigned width, unsigned height)
 {
-   const enum pipe_format resource_formats[3] = {
-      PIPE_FORMAT_R8_SNORM,
-      PIPE_FORMAT_R8_SNORM,
-      PIPE_FORMAT_R8_SNORM
-   };
-
    struct vl_context *ctx = (struct vl_context*)context;
    struct pipe_video_buffer *result;
    unsigned buffer_width, buffer_height;
@@ -221,7 +216,7 @@ vl_context_create_buffer(struct pipe_video_context *context,
 
    result = vl_video_buffer_init(context, ctx->pipe,
                                  buffer_width, buffer_height, 1,
-                                 chroma_format, 3,
+                                 chroma_format,
                                  resource_formats,
                                  PIPE_USAGE_STATIC);
    if (result) // TODO move format handling into vl_video_buffer
index 40a1b74f654ac73e52dea46408aa86a6bd73f447..ce0393848e35196a1e35a2d7afb0b4461b2ddde4 100644 (file)
@@ -309,7 +309,7 @@ init_idct_buffer(struct vl_mpeg12_buffer *buffer)
    formats[0] = formats[1] = formats[2] = dec->idct_source_format;
    buffer->idct_source = vl_video_buffer_init(dec->base.context, dec->pipe,
                                               dec->base.width / 4, dec->base.height, 1,
-                                              dec->base.chroma_format, 3,
+                                              dec->base.chroma_format,
                                               formats, PIPE_USAGE_STREAM);
    if (!buffer->idct_source)
       goto error_source;
@@ -318,7 +318,7 @@ init_idct_buffer(struct vl_mpeg12_buffer *buffer)
    buffer->idct_intermediate = vl_video_buffer_init(dec->base.context, dec->pipe,
                                                     dec->base.width / dec->nr_of_idct_render_targets,
                                                     dec->base.height / 4, dec->nr_of_idct_render_targets,
-                                                    dec->base.chroma_format, 3,
+                                                    dec->base.chroma_format,
                                                     formats, PIPE_USAGE_STATIC);
 
    if (!buffer->idct_intermediate)
@@ -395,7 +395,7 @@ vl_mpeg12_create_buffer(struct pipe_video_decoder *decoder)
    formats[0] = formats[1] = formats[2] =dec->mc_source_format;
    buffer->mc_source = vl_video_buffer_init(dec->base.context, dec->pipe,
                                             dec->base.width, dec->base.height, 1,
-                                            dec->base.chroma_format, 3,
+                                            dec->base.chroma_format,
                                             formats, PIPE_USAGE_STATIC);
 
    if (!buffer->mc_source)
index b1d8fd85dcd08aee46000eed377e02245c5e16c6..dad8dd2c9ae9b45350957cca0d6326799b77065f 100644 (file)
@@ -133,7 +133,6 @@ vl_video_buffer_init(struct pipe_video_context *context,
                      struct pipe_context *pipe,
                      unsigned width, unsigned height, unsigned depth,
                      enum pipe_video_chroma_format chroma_format,
-                     unsigned num_planes,
                      const enum pipe_format resource_formats[VL_MAX_PLANES],
                      unsigned usage)
 {
@@ -142,7 +141,6 @@ vl_video_buffer_init(struct pipe_video_context *context,
    unsigned i;
 
    assert(context && pipe);
-   assert(num_planes > 0 && num_planes <= VL_MAX_PLANES);
 
    buffer = CALLOC_STRUCT(vl_video_buffer);
 
@@ -150,7 +148,7 @@ vl_video_buffer_init(struct pipe_video_context *context,
    buffer->base.get_sampler_views = vl_video_buffer_sampler_views;
    buffer->base.get_surfaces = vl_video_buffer_surfaces;
    buffer->pipe = pipe;
-   buffer->num_planes = num_planes;
+   buffer->num_planes = 1;
 
    memset(&templ, 0, sizeof(templ));
    templ.target = depth > 1 ? PIPE_TEXTURE_3D : PIPE_TEXTURE_2D;
@@ -166,10 +164,12 @@ vl_video_buffer_init(struct pipe_video_context *context,
    if (!buffer->resources[0])
       goto error;
 
-   if (num_planes == 1) {
+   if (resource_formats[1] == PIPE_FORMAT_NONE) {
       assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444);
+      assert(resource_formats[2] == PIPE_FORMAT_NONE);
       return &buffer->base;
-   }
+   } else
+      buffer->num_planes = 2;
 
    templ.format = resource_formats[1];
    if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
@@ -183,8 +183,10 @@ vl_video_buffer_init(struct pipe_video_context *context,
    if (!buffer->resources[1])
       goto error;
 
-   if (num_planes == 2)
+   if (resource_formats[2] == PIPE_FORMAT_NONE)
       return &buffer->base;
+   else
+      buffer->num_planes = 3;
 
    templ.format = resource_formats[2];
    buffer->resources[2] = pipe->screen->resource_create(pipe->screen, &templ);
index 3f462acc51028f06f650a6ef62a6fb9bbf7715b0..f5c424cf296f19561f65cfc32bc1d5e4199e95d0 100644 (file)
@@ -56,7 +56,6 @@ vl_video_buffer_init(struct pipe_video_context *context,
                      struct pipe_context *pipe,
                      unsigned width, unsigned height, unsigned depth,
                      enum pipe_video_chroma_format chroma_format,
-                     unsigned num_planes,
                      const enum pipe_format resource_formats[VL_MAX_PLANES],
                      unsigned usage);
 #endif /* vl_ycbcr_buffer_h */
index 21d0581226d81034a4740f26e31a8f45af14e0b8..22203b66d6f5106118ef7f6076f8bd447d635371 100644 (file)
@@ -121,6 +121,7 @@ struct pipe_video_context
     */
    struct pipe_video_buffer *(*create_buffer)(struct pipe_video_context *context,
                                               enum pipe_format buffer_format,
+                                              enum pipe_format resource_formats[3],
                                               enum pipe_video_chroma_format chroma_format,
                                               unsigned width, unsigned height);
 
index f0aafae79b5d3ca4c897a8476738959047cc0fa0..2b1eb0471418f6abade9fc1a8eb44d72faa09272 100644 (file)
@@ -41,6 +41,12 @@ vlVdpVideoSurfaceCreate(VdpDevice device, VdpChromaType chroma_type,
                         uint32_t width, uint32_t height,
                         VdpVideoSurface *surface)
 {
+   const enum pipe_format resource_formats[3] = {
+      PIPE_FORMAT_R8_UNORM,
+      PIPE_FORMAT_R8_UNORM,
+      PIPE_FORMAT_R8_UNORM
+   };
+
    vlVdpSurface *p_surf;
    VdpStatus ret;
 
@@ -71,6 +77,7 @@ vlVdpVideoSurfaceCreate(VdpDevice device, VdpChromaType chroma_type,
    p_surf->device = dev;
    p_surf->video_buffer = dev->context->vpipe->create_buffer(dev->context->vpipe,
                                                              PIPE_FORMAT_YV12, // most common used
+                                                             resource_formats,
                                                              ChromaToPipe(chroma_type),
                                                              width, height);
 
index 68d003e470a3599d029d7e3267e790f10be86728..10701856223feb9b5b2954cad4c2e8e89a095610 100644 (file)
@@ -197,6 +197,12 @@ unmap_and_flush_surface(XvMCSurfacePrivate *surface)
 PUBLIC
 Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surface)
 {
+   const enum pipe_format resource_formats[3] = {
+      PIPE_FORMAT_R8_SNORM,
+      PIPE_FORMAT_R8_SNORM,
+      PIPE_FORMAT_R8_SNORM
+   };
+
    XvMCContextPrivate *context_priv;
    struct pipe_video_context *vpipe;
    XvMCSurfacePrivate *surface_priv;
@@ -219,6 +225,7 @@ Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surfac
 
    surface_priv->decode_buffer = context_priv->decoder->create_buffer(context_priv->decoder);
    surface_priv->video_buffer = vpipe->create_buffer(vpipe, PIPE_FORMAT_YV12, //TODO
+                                                     resource_formats,
                                                      context_priv->decoder->chroma_format,
                                                      context_priv->decoder->width,
                                                      context_priv->decoder->height);