vl/video_buffer: use template style create params
authorChristian König <deathsimple@vodafone.de>
Mon, 2 Jan 2012 13:22:33 +0000 (14:22 +0100)
committerChristian König <deathsimple@vodafone.de>
Sun, 15 Jan 2012 11:40:44 +0000 (12:40 +0100)
Just like in the rest of gallium, this reduces the
number of parameters significantly.

Signed-off-by: Christian König <deathsimple@vodafone.de>
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/drivers/nouveau/nouveau_video.c
src/gallium/include/pipe/p_context.h
src/gallium/state_trackers/vdpau/surface.c
src/gallium/state_trackers/xorg/xvmc/surface.c

index cb55fa6f61122e4fa30e7671d9a6f5972ff2f529..6341cc1b21809caaab4043e49e7994c195f6821f 100644 (file)
@@ -909,6 +909,7 @@ init_idct(struct vl_mpeg12_decoder *dec, const struct format_config* format_conf
 {
    unsigned nr_of_idct_render_targets, max_inst;
    enum pipe_format formats[3];
+   struct pipe_video_buffer templat;
 
    struct pipe_sampler_view *matrix = NULL;
 
@@ -930,21 +931,28 @@ init_idct(struct vl_mpeg12_decoder *dec, const struct format_config* format_conf
       nr_of_idct_render_targets = 1;
 
    formats[0] = formats[1] = formats[2] = format_config->idct_source_format;
+   memset(&templat, 0, sizeof(templat));
+   templat.width = dec->base.width / 4;
+   templat.height = dec->base.height;
+   templat.chroma_format = dec->base.chroma_format;
    dec->idct_source = vl_video_buffer_create_ex
    (
-      dec->base.context, dec->base.width / 4, dec->base.height, 1,
-      dec->base.chroma_format, formats, PIPE_USAGE_STATIC
+      dec->base.context, &templat,
+      formats, 1, PIPE_USAGE_STATIC
    );
 
    if (!dec->idct_source)
       goto error_idct_source;
 
    formats[0] = formats[1] = formats[2] = format_config->mc_source_format;
+   memset(&templat, 0, sizeof(templat));
+   templat.width = dec->base.width / nr_of_idct_render_targets;
+   templat.height = dec->base.height / 4;
+   templat.chroma_format = dec->base.chroma_format;
    dec->mc_source = vl_video_buffer_create_ex
    (
-      dec->base.context, dec->base.width / nr_of_idct_render_targets,
-      dec->base.height / 4, nr_of_idct_render_targets,
-      dec->base.chroma_format, formats, PIPE_USAGE_STATIC
+      dec->base.context, &templat,
+      formats, nr_of_idct_render_targets, PIPE_USAGE_STATIC
    );
 
    if (!dec->mc_source)
@@ -985,12 +993,17 @@ static bool
 init_mc_source_widthout_idct(struct vl_mpeg12_decoder *dec, const struct format_config* format_config)
 {
    enum pipe_format formats[3];
+   struct pipe_video_buffer templat;
 
    formats[0] = formats[1] = formats[2] = format_config->mc_source_format;
+   memset(&templat, 0, sizeof(templat));
+   templat.width = dec->base.width;
+   templat.height = dec->base.height;
+   templat.chroma_format = dec->base.chroma_format;
    dec->mc_source = vl_video_buffer_create_ex
    (
-      dec->base.context, dec->base.width, dec->base.height, 1,
-      dec->base.chroma_format, formats, PIPE_USAGE_STATIC
+      dec->base.context, &templat,
+      formats, 1, PIPE_USAGE_STATIC
    );
       
    return dec->mc_source != NULL;
index 8ceb71384796a6d8021a05a033c5a66c0e1a20e1..29d910e69e5e0357f92813bb17fad0583b7b12d0 100644 (file)
@@ -253,17 +253,14 @@ error:
 
 struct pipe_video_buffer *
 vl_video_buffer_create(struct pipe_context *pipe,
-                       enum pipe_format buffer_format,
-                       enum pipe_video_chroma_format chroma_format,
-                       unsigned width, unsigned height)
+                       const struct pipe_video_buffer *tmpl)
 {
    const enum pipe_format *resource_formats;
-   struct pipe_video_buffer *result;
-   unsigned buffer_width, buffer_height;
+   struct pipe_video_buffer templat;
    bool pot_buffers;
 
    assert(pipe);
-   assert(width > 0 && height > 0);
+   assert(tmpl->width > 0 && tmpl->height > 0);
 
    pot_buffers = !pipe->screen->get_video_param
    (
@@ -272,30 +269,28 @@ vl_video_buffer_create(struct pipe_context *pipe,
       PIPE_VIDEO_CAP_NPOT_TEXTURES
    );
 
-   resource_formats = vl_video_buffer_formats(pipe->screen, buffer_format);
+   resource_formats = vl_video_buffer_formats(pipe->screen, tmpl->buffer_format);
    if (!resource_formats)
       return NULL;
 
-   buffer_width = pot_buffers ? util_next_power_of_two(width) : align(width, MACROBLOCK_WIDTH);
-   buffer_height = pot_buffers ? util_next_power_of_two(height) : align(height, MACROBLOCK_HEIGHT);
+   templat = *tmpl;
+   templat.width = pot_buffers ? util_next_power_of_two(tmpl->width)
+                 : align(tmpl->width, MACROBLOCK_WIDTH);
+   templat.height = pot_buffers ? util_next_power_of_two(tmpl->height)
+                  : align(tmpl->height, MACROBLOCK_HEIGHT);
 
-   result = vl_video_buffer_create_ex
+   return vl_video_buffer_create_ex
    (
-      pipe, buffer_width, buffer_height, 1,
-      chroma_format, resource_formats, PIPE_USAGE_STATIC
+      pipe, &templat, resource_formats,
+      1, PIPE_USAGE_STATIC
    );
-   if (result)
-      result->buffer_format = buffer_format;
-
-   return result;
 }
 
 struct pipe_video_buffer *
 vl_video_buffer_create_ex(struct pipe_context *pipe,
-                          unsigned width, unsigned height, unsigned depth,
-                          enum pipe_video_chroma_format chroma_format,
+                          const struct pipe_video_buffer *tmpl,
                           const enum pipe_format resource_formats[VL_MAX_PLANES],
-                          unsigned usage)
+                          unsigned depth, unsigned usage)
 {
    struct vl_video_buffer *buffer;
    struct pipe_resource templ;
@@ -305,21 +300,19 @@ vl_video_buffer_create_ex(struct pipe_context *pipe,
 
    buffer = CALLOC_STRUCT(vl_video_buffer);
 
+   buffer->base = *tmpl;
    buffer->base.context = pipe;
    buffer->base.destroy = vl_video_buffer_destroy;
    buffer->base.get_sampler_view_planes = vl_video_buffer_sampler_view_planes;
    buffer->base.get_sampler_view_components = vl_video_buffer_sampler_view_components;
    buffer->base.get_surfaces = vl_video_buffer_surfaces;
-   buffer->base.chroma_format = chroma_format;
-   buffer->base.width = width;
-   buffer->base.height = height;
    buffer->num_planes = 1;
 
    memset(&templ, 0, sizeof(templ));
    templ.target = depth > 1 ? PIPE_TEXTURE_3D : PIPE_TEXTURE_2D;
    templ.format = resource_formats[0];
-   templ.width0 = width;
-   templ.height0 = height;
+   templ.width0 = tmpl->width;
+   templ.height0 = tmpl->height;
    templ.depth0 = depth;
    templ.array_size = 1;
    templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
@@ -330,17 +323,17 @@ vl_video_buffer_create_ex(struct pipe_context *pipe,
       goto error;
 
    if (resource_formats[1] == PIPE_FORMAT_NONE) {
-      assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444);
+      assert(tmpl->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) {
+   if (tmpl->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
       templ.width0 /= 2;
       templ.height0 /= 2;
-   } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {
+   } else if (tmpl->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {
       templ.height0 /= 2;
    }
 
index e096ccdaac23dfe3898e30382dcf2239b5def5d2..e0e29b20f318f49b6593168faf57c50f47ae41c9 100644 (file)
@@ -90,18 +90,15 @@ vl_video_buffer_get_associated_data(struct pipe_video_buffer *vbuf,
  */
 struct pipe_video_buffer *
 vl_video_buffer_create(struct pipe_context *pipe,
-                       enum pipe_format buffer_format,
-                       enum pipe_video_chroma_format chroma_format,
-                       unsigned width, unsigned height);
+                       const struct pipe_video_buffer *templat);
 
 /**
  * extended create function, gets depth, usage and formats for each plane seperately
  */
 struct pipe_video_buffer *
 vl_video_buffer_create_ex(struct pipe_context *pipe,
-                          unsigned width, unsigned height, unsigned depth,
-                          enum pipe_video_chroma_format chroma_format,
+                          const struct pipe_video_buffer *templat,
                           const enum pipe_format resource_formats[VL_MAX_PLANES],
-                          unsigned usage);
+                          unsigned depth, unsigned usage);
 
 #endif /* vl_video_buffer_h */
index 24a63644b5d341ebba089aca51d22d9df906a16a..055f9253fa580b2bde517cefdba517c25ccb11d4 100644 (file)
@@ -780,24 +780,23 @@ nouveau_video_buffer_destroy(struct pipe_video_buffer *buffer)
 static struct pipe_video_buffer *
 nouveau_video_buffer_create(struct pipe_context *pipe,
                             struct nouveau_screen *screen,
-                            enum pipe_format buffer_format,
-                            enum pipe_video_chroma_format chroma_format,
-                            unsigned width, unsigned height)
+                            const struct pipe_video_buffer *templat)
 {
    struct nouveau_video_buffer *buffer;
    struct pipe_resource templ;
+   unsigned width, height;
 
    /* Only do a linear surface when a hardware decoder is used
     * hardware decoder is only supported on some chipsets
     * and it only supports the NV12 format
     */
-   if (buffer_format != PIPE_FORMAT_NV12 || getenv("XVMC_VL") ||
+   if (templat->buffer_format != PIPE_FORMAT_NV12 || getenv("XVMC_VL") ||
        (screen->device->chipset >= 0x98 && screen->device->chipset != 0xa0))
-      return vl_video_buffer_create(pipe, buffer_format, chroma_format, width, height);
+      return vl_video_buffer_create(pipe, templat);
 
-   assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
-   width = align(width, 64);
-   height = align(height, 64);
+   assert(templat->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
+   width = align(templat->width, 64);
+   height = align(templat->height, 64);
 
    buffer = CALLOC_STRUCT(nouveau_video_buffer);
    if (!buffer)
@@ -808,7 +807,7 @@ nouveau_video_buffer_create(struct pipe_context *pipe,
    buffer->base.get_sampler_view_planes = nouveau_video_buffer_sampler_view_planes;
    buffer->base.get_sampler_view_components = nouveau_video_buffer_sampler_view_components;
    buffer->base.get_surfaces = nouveau_video_buffer_surfaces;
-   buffer->base.chroma_format = chroma_format;
+   buffer->base.chroma_format = templat->chroma_format;
    buffer->base.width = width;
    buffer->base.height = height;
    buffer->num_planes = 2;
@@ -882,12 +881,10 @@ nvfx_context_create_decoder(struct pipe_context *context,
 
 static struct pipe_video_buffer *
 nvfx_context_video_buffer_create(struct pipe_context *pipe,
-                                 enum pipe_format buffer_format,
-                                 enum pipe_video_chroma_format chroma_format,
-                                 unsigned width, unsigned height)
+                                 const struct pipe_video_buffer *templat)
 {
    struct nouveau_screen *screen = &nvfx_context(pipe)->screen->base;
-   return nouveau_video_buffer_create(pipe, screen, buffer_format, chroma_format, width, height);
+   return nouveau_video_buffer_create(pipe, screen, templat);
 }
 
 void
@@ -913,12 +910,10 @@ nouveau_context_create_decoder(struct pipe_context *context,
 
 static struct pipe_video_buffer *
 nouveau_context_video_buffer_create(struct pipe_context *pipe,
-                                    enum pipe_format buffer_format,
-                                    enum pipe_video_chroma_format chroma_format,
-                                    unsigned width, unsigned height)
+                                    const struct pipe_video_buffer *templat)
 {
    struct nouveau_screen *screen = nouveau_context(pipe)->screen;
-   return nouveau_video_buffer_create(pipe, screen, buffer_format, chroma_format, width, height);
+   return nouveau_video_buffer_create(pipe, screen, templat);
 }
 
 void
index f7ee52298a829576b2da44d792344eb395d43ab0..4c58ed049e937b81380ad82b1af1eef5978da8a6 100644 (file)
@@ -417,9 +417,7 @@ struct pipe_context {
     * Creates a video buffer as decoding target
     */
    struct pipe_video_buffer *(*create_video_buffer)( struct pipe_context *context,
-                                                     enum pipe_format buffer_format,
-                                                     enum pipe_video_chroma_format chroma_format,
-                                                     unsigned width, unsigned height );
+                                                     const struct pipe_video_buffer *templat );
 };
 
 
index 77503cfff49eaa4890fd0c0f232bd70289acda47..206a8397e9f35b0ce3b84e594cbf179df0b8bfb9 100644 (file)
@@ -44,6 +44,7 @@ vlVdpVideoSurfaceCreate(VdpDevice device, VdpChromaType chroma_type,
                         uint32_t width, uint32_t height,
                         VdpVideoSurface *surface)
 {
+   struct pipe_video_buffer tmpl;
    vlVdpSurface *p_surf;
    VdpStatus ret;
 
@@ -72,12 +73,15 @@ vlVdpVideoSurfaceCreate(VdpDevice device, VdpChromaType chroma_type,
    }
 
    p_surf->device = dev;
+   memset(&tmpl, 0, sizeof(tmpl));
+   tmpl.buffer_format = PIPE_FORMAT_YV12;
+   tmpl.chroma_format = ChromaToPipe(chroma_type);
+   tmpl.width = width;
+   tmpl.height = height;
    p_surf->video_buffer = dev->context->pipe->create_video_buffer
    (
       dev->context->pipe,
-      PIPE_FORMAT_YV12, // most common used
-      ChromaToPipe(chroma_type),
-      width, height
+      &tmpl
    );
 
    *surface = vlAddDataHTAB(p_surf);
index b4447c4460977cfb0ee1a4ad250411593dec5a90..ddc937c64c1d23e158964e23c3e2194b4c78d498 100644 (file)
@@ -167,6 +167,7 @@ Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surfac
    XvMCContextPrivate *context_priv;
    struct pipe_context *pipe;
    XvMCSurfacePrivate *surface_priv;
+   struct pipe_video_buffer tmpl;
 
    XVMC_MSG(XVMC_TRACE, "[XvMC] Creating surface %p.\n", surface);
 
@@ -184,12 +185,13 @@ Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surfac
    if (!surface_priv)
       return BadAlloc;
 
-   surface_priv->video_buffer = pipe->create_video_buffer
-   (
-      pipe, PIPE_FORMAT_NV12, context_priv->decoder->chroma_format,
-      context_priv->decoder->width, context_priv->decoder->height
-   );
-   
+   memset(&tmpl, 0, sizeof(tmpl));
+   tmpl.buffer_format = PIPE_FORMAT_NV12;
+   tmpl.chroma_format = context_priv->decoder->chroma_format;
+   tmpl.width = context_priv->decoder->width;
+   tmpl.height = context_priv->decoder->height;
+
+   surface_priv->video_buffer = pipe->create_video_buffer(pipe, &tmpl);
    surface_priv->context = context;
 
    surface->surface_id = XAllocID(dpy);