Merge branch 'gallium-polygon-stipple'
[mesa.git] / src / gallium / auxiliary / vl / vl_video_buffer.c
index 93bc096b7332aaa1b590bbc2d5c76fc2fff0bf83..4d8b6649dd25704d39d8d0e3163e86cd409e9349 100644 (file)
@@ -51,7 +51,7 @@ const enum pipe_format const_resource_formats_NV12[3] = {
 };
 
 const enum pipe_format *
-vl_video_buffer_formats(struct pipe_context *pipe, enum pipe_format format)
+vl_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format)
 {
    switch(format) {
    case PIPE_FORMAT_YV12:
@@ -65,6 +65,39 @@ vl_video_buffer_formats(struct pipe_context *pipe, enum pipe_format format)
    }
 }
 
+boolean
+vl_video_buffer_is_format_supported(struct pipe_screen *screen,
+                                    enum pipe_format format,
+                                    enum pipe_video_profile profile)
+{
+   const enum pipe_format *resource_formats;
+   unsigned i;
+
+   resource_formats = vl_video_buffer_formats(screen, format);
+   if (!resource_formats)
+      return false;
+
+   for(i = 0; i < VL_MAX_PLANES; ++i) {
+      if (!resource_formats[i])
+         continue;
+
+      if (!screen->is_format_supported(screen, resource_formats[i], PIPE_TEXTURE_2D, 0, PIPE_USAGE_STATIC))
+         return false;
+   }
+
+   return true;
+}
+
+unsigned
+vl_video_buffer_max_size(struct pipe_screen *screen)
+{
+   uint32_t max_2d_texture_level;
+
+   max_2d_texture_level = screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS);
+
+   return 1 << (max_2d_texture_level-1);
+}
+
 static void
 vl_video_buffer_destroy(struct pipe_video_buffer *buffer)
 {
@@ -79,6 +112,8 @@ vl_video_buffer_destroy(struct pipe_video_buffer *buffer)
       pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL);
       pipe_resource_reference(&buf->resources[i], NULL);
    }
+
+   FREE(buffer);
 }
 
 static struct pipe_sampler_view **
@@ -91,7 +126,7 @@ vl_video_buffer_sampler_view_planes(struct pipe_video_buffer *buffer)
 
    assert(buf);
 
-   pipe = buf->pipe;
+   pipe = buf->base.context;
 
    for (i = 0; i < buf->num_planes; ++i ) {
       if (!buf->sampler_view_planes[i]) {
@@ -126,7 +161,7 @@ vl_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer)
 
    assert(buf);
 
-   pipe = buf->pipe;
+   pipe = buf->base.context;
 
    for (component = 0, i = 0; i < buf->num_planes; ++i ) {
       unsigned nr_components = util_format_get_nr_components(buf->resources[i]->format);
@@ -165,7 +200,7 @@ vl_video_buffer_surfaces(struct pipe_video_buffer *buffer)
 
    assert(buf);
 
-   pipe = buf->pipe;
+   pipe = buf->base.context;
 
    for (i = 0; i < buf->num_planes; ++i ) {
       if (!buf->surfaces[i]) {
@@ -188,21 +223,60 @@ error:
 }
 
 struct pipe_video_buffer *
-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,
-                     const enum pipe_format resource_formats[VL_MAX_PLANES],
-                     unsigned usage)
+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 enum pipe_format *resource_formats;
+   struct pipe_video_buffer *result;
+   unsigned buffer_width, buffer_height;
+   bool pot_buffers;
+
+   assert(pipe);
+   assert(width > 0 && height > 0);
+
+   pot_buffers = !pipe->screen->get_video_param
+   (
+      pipe->screen,
+      PIPE_VIDEO_PROFILE_UNKNOWN,
+      PIPE_VIDEO_CAP_NPOT_TEXTURES
+   );
+
+   resource_formats = vl_video_buffer_formats(pipe->screen, 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);
+
+   result = vl_video_buffer_create_ex
+   (
+      pipe, buffer_width, buffer_height, 1,
+      chroma_format, resource_formats, 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 enum pipe_format resource_formats[VL_MAX_PLANES],
+                          unsigned usage)
 {
    struct vl_video_buffer *buffer;
    struct pipe_resource templ;
    unsigned i;
 
-   assert(context && pipe);
+   assert(pipe);
 
    buffer = CALLOC_STRUCT(vl_video_buffer);
 
+   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;
@@ -210,7 +284,6 @@ vl_video_buffer_init(struct pipe_video_context *context,
    buffer->base.chroma_format = chroma_format;
    buffer->base.width = width;
    buffer->base.height = height;
-   buffer->pipe = pipe;
    buffer->num_planes = 1;
 
    memset(&templ, 0, sizeof(templ));