g3dvl: Basic subpicture support.

RGB subpictures only at the moment.
This commit is contained in:
Younes Manton 2009-11-22 16:40:15 -05:00
parent 334676ed9a
commit 5f730690f8
10 changed files with 541 additions and 182 deletions

View file

@ -1,8 +1,8 @@
/**************************************************************************
*
*
* Copyright 2009 Younes Manton.
* All Rights Reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@ -10,11 +10,11 @@
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
@ -22,7 +22,7 @@
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
**************************************************************************/
#include "vl_compositor.h"
@ -33,16 +33,6 @@
#include <util/u_memory.h>
#include "vl_csc.h"
struct vertex2f
{
float x, y;
};
struct vertex4f
{
float x, y, z, w;
};
struct vertex_shader_consts
{
struct vertex4f dst_scale;
@ -56,51 +46,45 @@ struct fragment_shader_consts
float matrix[16];
};
/*
* Represents 2 triangles in a strip in normalized coords.
* Used to render the surface onto the frame buffer.
*/
static const struct vertex2f surface_verts[4] =
static bool
u_video_rects_equal(struct pipe_video_rect *a, struct pipe_video_rect *b)
{
{0.0f, 0.0f},
{0.0f, 1.0f},
{1.0f, 0.0f},
{1.0f, 1.0f}
};
assert(a && b);
/*
* Represents texcoords for the above. We can use the position values directly.
* TODO: Duplicate these in the shader, no need to create a buffer.
*/
static const struct vertex2f *surface_texcoords = surface_verts;
if (a->x != b->x)
return false;
if (a->y != b->y)
return false;
if (a->w != b->w)
return false;
if (a->h != b->h)
return false;
return true;
}
static bool
create_vert_shader(struct vl_compositor *c)
{
struct ureg_program *shader;
struct ureg_src vpos, vtex;
struct ureg_src vpos_scale, vpos_trans, vtex_scale, vtex_trans;
struct ureg_dst o_vpos, o_vtex;
shader = ureg_create(TGSI_PROCESSOR_VERTEX);
if (!shader)
return false;
vpos = ureg_DECL_vs_input(shader, 0);
vtex = ureg_DECL_vs_input(shader, 1);
vpos_scale = ureg_DECL_constant(shader, 0);
vpos_trans = ureg_DECL_constant(shader, 1);
vtex_scale = ureg_DECL_constant(shader, 2);
vtex_trans = ureg_DECL_constant(shader, 3);
o_vpos = ureg_DECL_output(shader, TGSI_SEMANTIC_POSITION, 0);
o_vtex = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, 1);
/*
* o_vpos = vpos * vpos_scale + vpos_trans
* o_vtex = vtex * vtex_scale + vtex_trans
* o_vpos = vpos
* o_vtex = vtex
*/
ureg_MAD(shader, o_vpos, vpos, vpos_scale, vpos_trans);
ureg_MAD(shader, o_vtex, vtex, vtex_scale, vtex_trans);
ureg_MOV(shader, o_vpos, vpos);
ureg_MOV(shader, o_vtex, vtex);
ureg_END(shader);
@ -121,7 +105,7 @@ create_frag_shader(struct vl_compositor *c)
struct ureg_dst texel;
struct ureg_dst fragment;
unsigned i;
shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
if (!shader)
return false;
@ -177,14 +161,14 @@ init_pipe_state(struct vl_compositor *c)
/*sampler.border_color[i] = ;*/
/*sampler.max_anisotropy = ;*/
c->sampler = c->pipe->create_sampler_state(c->pipe, &sampler);
return true;
}
static void cleanup_pipe_state(struct vl_compositor *c)
{
assert(c);
c->pipe->delete_sampler_state(c->pipe, c->sampler);
}
@ -202,7 +186,7 @@ init_shaders(struct vl_compositor *c)
static void cleanup_shaders(struct vl_compositor *c)
{
assert(c);
c->pipe->delete_vs_state(c->pipe, c->vertex_shader);
c->pipe->delete_fs_state(c->pipe, c->fragment_shader);
}
@ -213,79 +197,30 @@ init_buffers(struct vl_compositor *c)
struct fragment_shader_consts fsc;
assert(c);
/*
* Create our vertex buffer and vertex buffer element
* VB contains 4 vertices that render a quad covering the entire window
* to display a rendered surface
* Quad is rendered as a tri strip
* Create our vertex buffer and vertex buffer elements
*/
c->vertex_bufs[0].stride = sizeof(struct vertex2f);
c->vertex_bufs[0].max_index = 3;
c->vertex_bufs[0].buffer_offset = 0;
c->vertex_bufs[0].buffer = pipe_buffer_create
c->vertex_buf.stride = sizeof(struct vertex4f);
c->vertex_buf.max_index = (VL_COMPOSITOR_MAX_LAYERS + 2) * 6 - 1;
c->vertex_buf.buffer_offset = 0;
c->vertex_buf.buffer = pipe_buffer_create
(
c->pipe->screen,
1,
PIPE_BUFFER_USAGE_VERTEX,
sizeof(struct vertex2f) * 4
sizeof(struct vertex4f) * (VL_COMPOSITOR_MAX_LAYERS + 2) * 6
);
memcpy
(
pipe_buffer_map(c->pipe->screen, c->vertex_bufs[0].buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
surface_verts,
sizeof(struct vertex2f) * 4
);
pipe_buffer_unmap(c->pipe->screen, c->vertex_bufs[0].buffer);
c->vertex_elems[0].src_offset = 0;
c->vertex_elems[0].vertex_buffer_index = 0;
c->vertex_elems[0].nr_components = 2;
c->vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT;
/*
* Create our texcoord buffer and texcoord buffer element
* Texcoord buffer contains the TCs for mapping the rendered surface to the 4 vertices
*/
c->vertex_bufs[1].stride = sizeof(struct vertex2f);
c->vertex_bufs[1].max_index = 3;
c->vertex_bufs[1].buffer_offset = 0;
c->vertex_bufs[1].buffer = pipe_buffer_create
(
c->pipe->screen,
1,
PIPE_BUFFER_USAGE_VERTEX,
sizeof(struct vertex2f) * 4
);
memcpy
(
pipe_buffer_map(c->pipe->screen, c->vertex_bufs[1].buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
surface_texcoords,
sizeof(struct vertex2f) * 4
);
pipe_buffer_unmap(c->pipe->screen, c->vertex_bufs[1].buffer);
c->vertex_elems[1].src_offset = 0;
c->vertex_elems[1].vertex_buffer_index = 1;
c->vertex_elems[1].src_offset = sizeof(struct vertex2f);
c->vertex_elems[1].vertex_buffer_index = 0;
c->vertex_elems[1].nr_components = 2;
c->vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
/*
* Create our vertex shader's constant buffer
* Const buffer contains scaling and translation vectors
*/
c->vs_const_buf.buffer = pipe_buffer_create
(
c->pipe->screen,
1,
PIPE_BUFFER_USAGE_CONSTANT | PIPE_BUFFER_USAGE_DISCARD,
sizeof(struct vertex_shader_consts)
);
/*
* Create our fragment shader's constant buffer
* Const buffer contains the color conversion matrix and bias vectors
@ -308,19 +243,16 @@ init_buffers(struct vl_compositor *c)
static void
cleanup_buffers(struct vl_compositor *c)
{
unsigned i;
assert(c);
for (i = 0; i < 2; ++i)
pipe_buffer_reference(&c->vertex_bufs[i].buffer, NULL);
pipe_buffer_reference(&c->vs_const_buf.buffer, NULL);
pipe_buffer_reference(&c->vertex_buf.buffer, NULL);
pipe_buffer_reference(&c->fs_const_buf.buffer, NULL);
}
bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe)
{
unsigned i;
assert(compositor);
memset(compositor, 0, sizeof(struct vl_compositor));
@ -339,21 +271,161 @@ bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *p
return false;
}
compositor->fb_state.width = 0;
compositor->fb_state.height = 0;
compositor->bg = NULL;
compositor->dirty_bg = false;
for (i = 0; i < VL_COMPOSITOR_MAX_LAYERS; ++i)
compositor->layers[i] = NULL;
compositor->dirty_layers = 0;
return true;
}
void vl_compositor_cleanup(struct vl_compositor *compositor)
{
assert(compositor);
cleanup_buffers(compositor);
cleanup_shaders(compositor);
cleanup_pipe_state(compositor);
}
void vl_compositor_set_background(struct vl_compositor *compositor,
struct pipe_texture *bg, struct pipe_video_rect *bg_src_rect)
{
assert(compositor);
assert((bg && bg_src_rect) || (!bg && !bg_src_rect));
if (compositor->bg != bg ||
!u_video_rects_equal(&compositor->bg_src_rect, bg_src_rect)) {
pipe_texture_reference(&compositor->bg, bg);
/*if (!u_video_rects_equal(&compositor->bg_src_rect, bg_src_rect))*/
compositor->bg_src_rect = *bg_src_rect;
compositor->dirty_bg = true;
}
}
void vl_compositor_set_layers(struct vl_compositor *compositor,
struct pipe_texture *layers[],
struct pipe_video_rect *src_rects[],
struct pipe_video_rect *dst_rects[],
unsigned num_layers)
{
unsigned i;
assert(compositor);
assert(num_layers <= VL_COMPOSITOR_MAX_LAYERS);
for (i = 0; i < num_layers; ++i)
{
assert((layers[i] && src_rects[i] && dst_rects[i]) ||
(!layers[i] && !src_rects[i] && !dst_rects[i]));
if (compositor->layers[i] != layers[i] ||
!u_video_rects_equal(&compositor->layer_src_rects[i], src_rects[i]) ||
!u_video_rects_equal(&compositor->layer_dst_rects[i], dst_rects[i]))
{
pipe_texture_reference(&compositor->layers[i], layers[i]);
/*if (!u_video_rects_equal(&compositor->layer_src_rects[i], src_rects[i]))*/
compositor->layer_src_rects[i] = *src_rects[i];
/*if (!u_video_rects_equal(&compositor->layer_dst_rects[i], dst_rects[i]))*/
compositor->layer_dst_rects[i] = *dst_rects[i];
compositor->dirty_layers |= 1 << i;
}
}
for (; i < VL_COMPOSITOR_MAX_LAYERS; ++i)
pipe_texture_reference(&compositor->layers[i], NULL);
}
static void gen_rect_verts(unsigned pos,
struct pipe_video_rect *src_rect,
struct vertex2f *src_inv_size,
struct pipe_video_rect *dst_rect,
struct vertex2f *dst_inv_size,
struct vertex4f *vb)
{
assert(pos < VL_COMPOSITOR_MAX_LAYERS + 2);
assert(src_rect);
assert(src_inv_size);
assert((dst_rect && dst_inv_size) || (!dst_rect && !dst_inv_size));
assert(vb);
vb[pos * 6 + 0].x = dst_rect->x * dst_inv_size->x;
vb[pos * 6 + 0].y = dst_rect->y * dst_inv_size->y;
vb[pos * 6 + 0].z = src_rect->x * src_inv_size->x;
vb[pos * 6 + 0].w = src_rect->y * src_inv_size->y;
vb[pos * 6 + 1].x = dst_rect->x * dst_inv_size->x;
vb[pos * 6 + 1].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
vb[pos * 6 + 1].z = src_rect->x * src_inv_size->x;
vb[pos * 6 + 1].w = (src_rect->y + src_rect->h) * src_inv_size->y;
vb[pos * 6 + 2].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
vb[pos * 6 + 2].y = dst_rect->y * dst_inv_size->y;
vb[pos * 6 + 2].z = (src_rect->x + src_rect->w) * src_inv_size->x;
vb[pos * 6 + 2].w = src_rect->y * src_inv_size->y;
vb[pos * 6 + 3].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
vb[pos * 6 + 3].y = dst_rect->y * dst_inv_size->y;
vb[pos * 6 + 3].z = (src_rect->x + src_rect->w) * src_inv_size->x;
vb[pos * 6 + 3].w = src_rect->y * src_inv_size->y;
vb[pos * 6 + 4].x = dst_rect->x * dst_inv_size->x;
vb[pos * 6 + 4].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
vb[pos * 6 + 4].z = src_rect->x * src_inv_size->x;
vb[pos * 6 + 4].w = (src_rect->y + src_rect->h) * src_inv_size->y;
vb[pos * 6 + 5].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
vb[pos * 6 + 5].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
vb[pos * 6 + 5].z = (src_rect->x + src_rect->w) * src_inv_size->x;
vb[pos * 6 + 5].w = (src_rect->y + src_rect->h) * src_inv_size->y;
}
static unsigned gen_verts(struct vl_compositor *c,
struct pipe_video_rect *src_rect,
struct vertex2f *src_inv_size,
struct pipe_video_rect *dst_rect)
{
void *vb;
unsigned num_rects = 0;
unsigned i;
assert(c);
assert(src_rect);
assert(src_inv_size);
assert(dst_rect);
vb = pipe_buffer_map(c->pipe->screen, c->vertex_buf.buffer,
PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD);
if (c->dirty_bg) {
struct vertex2f bg_inv_size = {1.0f / c->bg->width[0], 1.0f / c->bg->height[0]};
gen_rect_verts(num_rects++, &c->bg_src_rect, &bg_inv_size, NULL, NULL, vb);
c->dirty_bg = false;
}
gen_rect_verts(num_rects++, src_rect, src_inv_size, dst_rect, &c->fb_inv_size, vb);
for (i = 0; c->dirty_layers > 0; i++)
{
assert(i < VL_COMPOSITOR_MAX_LAYERS);
if (c->dirty_layers & (1 << i)) {
struct vertex2f layer_inv_size = {1.0f / c->layers[i]->width[0], 1.0f / c->layers[i]->height[0]};
gen_rect_verts(num_rects++, &c->layer_src_rects[i], &layer_inv_size,
&c->layer_dst_rects[i], &c->fb_inv_size, vb);
c->dirty_layers &= ~(1 << i);
}
}
pipe_buffer_unmap(c->pipe->screen, c->vertex_buf.buffer);
return num_rects;
}
void vl_compositor_render(struct vl_compositor *compositor,
/*struct pipe_texture *backround,
struct pipe_video_rect *backround_area,*/
struct pipe_texture *src_surface,
enum pipe_mpeg12_picture_type picture_type,
/*unsigned num_past_surfaces,
@ -363,13 +435,9 @@ void vl_compositor_render(struct vl_compositor *compositor,
struct pipe_video_rect *src_area,
struct pipe_texture *dst_surface,
struct pipe_video_rect *dst_area,
/*unsigned num_layers,
struct pipe_texture *layers,
struct pipe_video_rect *layer_src_areas,
struct pipe_video_rect *layer_dst_areas*/
struct pipe_fence_handle **fence)
{
struct vertex_shader_consts *vs_consts;
unsigned num_rects;
assert(compositor);
assert(src_surface);
@ -378,8 +446,15 @@ void vl_compositor_render(struct vl_compositor *compositor,
assert(dst_area);
assert(picture_type == PIPE_MPEG12_PICTURE_TYPE_FRAME);
compositor->fb_state.width = dst_surface->width[0];
compositor->fb_state.height = dst_surface->height[0];
if (compositor->fb_state.width != dst_surface->width[0]) {
compositor->fb_inv_size.x = 1.0f / dst_surface->width[0];
compositor->fb_state.width = dst_surface->width[0];
}
if (compositor->fb_state.height != dst_surface->height[0]) {
compositor->fb_inv_size.y = 1.0f / dst_surface->height[0];
compositor->fb_state.height = dst_surface->height[0];
}
compositor->fb_state.cbufs[0] = compositor->pipe->screen->get_tex_surface
(
compositor->pipe->screen,
@ -402,39 +477,19 @@ void vl_compositor_render(struct vl_compositor *compositor,
compositor->pipe->set_sampler_textures(compositor->pipe, 1, &src_surface);
compositor->pipe->bind_vs_state(compositor->pipe, compositor->vertex_shader);
compositor->pipe->bind_fs_state(compositor->pipe, compositor->fragment_shader);
compositor->pipe->set_vertex_buffers(compositor->pipe, 2, compositor->vertex_bufs);
compositor->pipe->set_vertex_buffers(compositor->pipe, 1, &compositor->vertex_buf);
compositor->pipe->set_vertex_elements(compositor->pipe, 2, compositor->vertex_elems);
compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_VERTEX, 0, &compositor->vs_const_buf);
compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_FRAGMENT, 0, &compositor->fs_const_buf);
vs_consts = pipe_buffer_map
(
compositor->pipe->screen,
compositor->vs_const_buf.buffer,
PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
);
{
struct vertex2f src_inv_size = {1.0f / src_surface->width[0], 1.0f / src_surface->height[0]};
num_rects = gen_verts(compositor, src_area, &src_inv_size, dst_area);
}
vs_consts->dst_scale.x = dst_area->w / (float)compositor->fb_state.cbufs[0]->width;
vs_consts->dst_scale.y = dst_area->h / (float)compositor->fb_state.cbufs[0]->height;
vs_consts->dst_scale.z = 1;
vs_consts->dst_scale.w = 1;
vs_consts->dst_trans.x = dst_area->x / (float)compositor->fb_state.cbufs[0]->width;
vs_consts->dst_trans.y = dst_area->y / (float)compositor->fb_state.cbufs[0]->height;
vs_consts->dst_trans.z = 0;
vs_consts->dst_trans.w = 0;
assert(!compositor->dirty_bg && !compositor->dirty_layers);
assert(num_rects > 0);
vs_consts->src_scale.x = src_area->w / (float)src_surface->width[0];
vs_consts->src_scale.y = src_area->h / (float)src_surface->height[0];
vs_consts->src_scale.z = 1;
vs_consts->src_scale.w = 1;
vs_consts->src_trans.x = src_area->x / (float)src_surface->width[0];
vs_consts->src_trans.y = src_area->y / (float)src_surface->height[0];
vs_consts->src_trans.z = 0;
vs_consts->src_trans.w = 0;
pipe_buffer_unmap(compositor->pipe->screen, compositor->vs_const_buf.buffer);
compositor->pipe->draw_arrays(compositor->pipe, PIPE_PRIM_TRIANGLE_STRIP, 0, 4);
compositor->pipe->draw_arrays(compositor->pipe, PIPE_PRIM_TRIANGLES, 0, num_rects * 6);
compositor->pipe->flush(compositor->pipe, PIPE_FLUSH_RENDER_CACHE, fence);
pipe_surface_reference(&compositor->fb_state.cbufs[0], NULL);

View file

@ -1,8 +1,8 @@
/**************************************************************************
*
*
* Copyright 2009 Younes Manton.
* All Rights Reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@ -10,11 +10,11 @@
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
@ -22,7 +22,7 @@
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
**************************************************************************/
#ifndef vl_compositor_h
@ -31,31 +31,50 @@
#include <pipe/p_compiler.h>
#include <pipe/p_state.h>
#include <pipe/p_video_state.h>
#include "vl_types.h"
struct pipe_context;
struct pipe_texture;
#define VL_COMPOSITOR_MAX_LAYERS 16
struct vl_compositor
{
struct pipe_context *pipe;
struct pipe_framebuffer_state fb_state;
struct vertex2f fb_inv_size;
void *sampler;
void *vertex_shader;
void *fragment_shader;
struct pipe_viewport_state viewport;
struct pipe_vertex_buffer vertex_bufs[2];
struct pipe_vertex_buffer vertex_buf;
struct pipe_vertex_element vertex_elems[2];
struct pipe_constant_buffer vs_const_buf, fs_const_buf;
struct pipe_constant_buffer fs_const_buf;
struct pipe_texture *bg;
struct pipe_video_rect bg_src_rect;
bool dirty_bg;
struct pipe_texture *layers[VL_COMPOSITOR_MAX_LAYERS];
struct pipe_video_rect layer_src_rects[VL_COMPOSITOR_MAX_LAYERS];
struct pipe_video_rect layer_dst_rects[VL_COMPOSITOR_MAX_LAYERS];
unsigned dirty_layers;
};
bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe);
void vl_compositor_cleanup(struct vl_compositor *compositor);
void vl_compositor_set_background(struct vl_compositor *compositor,
struct pipe_texture *bg, struct pipe_video_rect *bg_src_rect);
void vl_compositor_set_layers(struct vl_compositor *compositor,
struct pipe_texture *layers[],
struct pipe_video_rect *src_rects[],
struct pipe_video_rect *dst_rects[],
unsigned num_layers);
void vl_compositor_render(struct vl_compositor *compositor,
/*struct pipe_texture *backround,
struct pipe_video_rect *backround_area,*/
struct pipe_texture *src_surface,
enum pipe_mpeg12_picture_type picture_type,
/*unsigned num_past_surfaces,
@ -65,10 +84,6 @@ void vl_compositor_render(struct vl_compositor *compositor,
struct pipe_video_rect *src_area,
struct pipe_texture *dst_surface,
struct pipe_video_rect *dst_area,
/*unsigned num_layers,
struct pipe_texture *layers,
struct pipe_video_rect *layer_src_areas,
struct pipe_video_rect *layer_dst_areas,*/
struct pipe_fence_handle **fence);
void vl_compositor_set_csc_matrix(struct vl_compositor *compositor, const float *mat);

View file

@ -42,11 +42,6 @@
#define ZERO_BLOCK_IS_NIL(zb) ((zb).x < 0.0f)
#define SCALE_FACTOR_16_TO_9 (32767.0f / 255.0f)
struct vertex4f
{
float x, y, z, w;
};
struct vertex_shader_consts
{
struct vertex4f denorm;

View file

@ -31,6 +31,7 @@
#include <pipe/p_compiler.h>
#include <pipe/p_state.h>
#include <pipe/p_video_state.h>
#include "vl_types.h"
struct pipe_context;
struct pipe_video_surface;
@ -50,11 +51,6 @@ enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK
VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_NONE /* Needs conditional texel fetch! */
};
struct vertex2f
{
float x, y;
};
struct vl_mpeg12_mc_renderer
{
struct pipe_context *pipe;

View file

@ -0,0 +1,41 @@
/**************************************************************************
*
* Copyright 2009 Younes Manton.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifndef vl_types_h
#define vl_types_h
struct vertex2f
{
float x, y;
};
struct vertex4f
{
float x, y, z, w;
};
#endif /* vl_types_h */

View file

@ -1,8 +1,8 @@
/**************************************************************************
*
*
* Copyright 2009 Younes Manton.
* All Rights Reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@ -10,7 +10,7 @@
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
@ -22,28 +22,78 @@
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
**************************************************************************/
#include <assert.h>
#include <X11/Xlibint.h>
#include <X11/extensions/XvMClib.h>
#include <vl_winsys.h>
#include <pipe/p_screen.h>
#include <pipe/p_video_context.h>
#include <pipe/p_state.h>
#include <util/u_memory.h>
#include <util/u_math.h>
#include "xvmc_private.h"
#define FOURCC_RGB 0x0000003
Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture,
unsigned short width, unsigned short height, int xvimage_id)
{
XvMCContextPrivate *context_priv;
XvMCSubPicturePrivate *subpicture_priv;
struct pipe_video_context *vpipe;
struct pipe_texture template;
struct pipe_texture *tex;
assert(dpy);
if (!context)
return XvMCBadContext;
assert(subpicture);
context_priv = context->privData;
vpipe = context_priv->vctx->vpipe;
/*if (width > || height > )
return BadValue;*/
if (!subpicture)
return XvMCBadSubpicture;
/*if (xvimage_id != )
return BadMatch;*/
if (width > 2048 || height > 2048)
return BadValue;
if (xvimage_id != FOURCC_RGB)
return BadMatch;
subpicture_priv = CALLOC(1, sizeof(XvMCSubPicturePrivate));
if (!subpicture_priv)
return BadAlloc;
memset(&template, 0, sizeof(struct pipe_texture));
template.target = PIPE_TEXTURE_2D;
template.format = PIPE_FORMAT_X8R8G8B8_UNORM;
template.last_level = 0;
if (vpipe->screen->get_param(vpipe->screen, PIPE_CAP_NPOT_TEXTURES)) {
template.width[0] = width;
template.height[0] = height;
}
else {
template.width[0] = util_next_power_of_two(width);
template.height[0] = util_next_power_of_two(height);
}
template.depth[0] = 1;
pf_get_block(template.format, &template.block);
template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;
subpicture_priv->context = context;
tex = vpipe->screen->texture_create(vpipe->screen, &template);
subpicture_priv->sfc = vpipe->screen->get_tex_surface(vpipe->screen, tex, 0, 0, 0,
PIPE_BUFFER_USAGE_GPU_READ_WRITE);
pipe_texture_reference(&tex, NULL);
if (!subpicture_priv->sfc)
{
FREE(subpicture_priv);
return BadAlloc;
}
subpicture->subpicture_id = XAllocID(dpy);
subpicture->context_id = context->context_id;
@ -56,7 +106,7 @@ Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *
subpicture->component_order[1] = 0;
subpicture->component_order[2] = 0;
subpicture->component_order[3] = 0;
/* TODO: subpicture->privData = ;*/
subpicture->privData = subpicture_priv;
SyncHandle();
@ -66,12 +116,19 @@ Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *
Status XvMCClearSubpicture(Display *dpy, XvMCSubpicture *subpicture, short x, short y,
unsigned short width, unsigned short height, unsigned int color)
{
XvMCSubPicturePrivate *subpicture_priv;
XvMCContextPrivate *context_priv;
assert(dpy);
if (!subpicture)
return XvMCBadSubpicture;
subpicture_priv = subpicture->privData;
context_priv = subpicture_priv->context->privData;
/* TODO: Assert clear rect is within bounds? Or clip? */
context_priv->vctx->vpipe->surface_fill(context_priv->vctx->vpipe,
subpicture_priv->sfc, x, y,
width, height, color);
return Success;
}
@ -97,12 +154,18 @@ Status XvMCCompositeSubpicture(Display *dpy, XvMCSubpicture *subpicture, XvImage
Status XvMCDestroySubpicture(Display *dpy, XvMCSubpicture *subpicture)
{
XvMCSubPicturePrivate *subpicture_priv;
assert(dpy);
if (!subpicture)
return XvMCBadSubpicture;
return BadImplementation;
subpicture_priv = subpicture->privData;
pipe_surface_reference(&subpicture_priv->sfc, NULL);
FREE(subpicture_priv);
return Success;
}
Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsigned char *palette)

View file

@ -1,5 +1,6 @@
test_context
test_surface
test_subpicture
test_blocks
test_rendering
xvmc_bench

View file

@ -7,7 +7,7 @@ LIBS = -lXvMCW -lXvMC -lXv -lX11
.PHONY: default clean
default: test_context test_surface test_blocks test_rendering xvmc_bench
default: test_context test_surface test_subpicture test_blocks test_rendering xvmc_bench
test_context: test_context.o testlib.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
@ -15,6 +15,9 @@ test_context: test_context.o testlib.o
test_surface: test_surface.o testlib.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
test_subpicture: test_subpicture.o testlib.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
test_blocks: test_blocks.o testlib.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
@ -25,4 +28,4 @@ xvmc_bench: xvmc_bench.o testlib.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
clean:
$(RM) -rf *.o test_context test_surface test_blocks test_rendering xvmc_bench
$(RM) -rf *.o test_context test_surface test_subpicture test_blocks test_rendering xvmc_bench

View file

@ -0,0 +1,182 @@
/**************************************************************************
*
* Copyright 2009 Younes Manton.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include <assert.h>
#include <error.h>
#include <stdio.h>
#include "testlib.h"
static void PrintGUID(const char *guid)
{
int i;
printf("\tguid: ");
for (i = 0; i < 4; ++i)
printf("%C,", guid[i] == 0 ? '0' : guid[i]);
for (; i < 15; ++i)
printf("%x,", (unsigned char)guid[i]);
printf("%x\n", (unsigned int)guid[15]);
}
static void PrintComponentOrder(const char *co)
{
int i;
printf("\tcomponent_order:\n\t ");
for (i = 0; i < 4; ++i)
printf("%C,", co[i] == 0 ? '0' : co[i]);
for (; i < 31; ++i)
printf("%x,", (unsigned int)co[i]);
printf("%x\n", (unsigned int)co[31]);
}
int main(int argc, char **argv)
{
const unsigned int width = 16, height = 16;
const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
const unsigned int subpic_width = 16, subpic_height = 16;
Display *display;
XvPortID port_num;
int surface_type_id;
unsigned int is_overlay, intra_unsigned;
int colorkey;
XvMCContext context;
XvImageFormatValues *subpics;
int num_subpics;
XvMCSubpicture subpicture = {0};
int i;
display = XOpenDisplay(NULL);
if (!GetPort
(
display,
width,
height,
XVMC_CHROMA_FORMAT_420,
mc_types,
2,
&port_num,
&surface_type_id,
&is_overlay,
&intra_unsigned
))
{
XCloseDisplay(display);
error(1, 0, "Error, unable to find a good port.\n");
}
if (is_overlay)
{
Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
}
assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics);
assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0));
for (i = 0; i < num_subpics; ++i)
{
printf("Subpicture %d:\n", i);
printf("\tid: 0x%08x\n", subpics[i].id);
printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown"));
printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown"));
PrintGUID(subpics[i].guid);
printf("\tbpp: %u\n", subpics[i].bits_per_pixel);
printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown"));
printf("\tnum_planes: %u\n", subpics[i].num_planes);
if (subpics[i].type == XvRGB)
{
printf("\tdepth: %u\n", subpics[i].depth);
printf("\tred_mask: 0x%08x\n", subpics[i].red_mask);
printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask);
printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask);
}
else if (subpics[i].type == XvYUV)
{
printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits);
printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits);
printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits);
printf("\thorz_y_period: %u\n", subpics[i].horz_y_period);
printf("\thorz_u_period: %u\n", subpics[i].horz_u_period);
printf("\thorz_v_period: %u\n", subpics[i].horz_v_period);
printf("\tvert_y_period: %u\n", subpics[i].vert_y_period);
printf("\tvert_u_period: %u\n", subpics[i].vert_u_period);
printf("\tvert_v_period: %u\n", subpics[i].vert_v_period);
}
PrintComponentOrder(subpics[i].component_order);
printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown"));
}
if (num_subpics == 0)
{
printf("Subpictures not supported, nothing to test.\n");
return 0;
}
/* Test NULL context */
assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext);
/* Test NULL subpicture */
assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture);
/* Test invalid subpicture */
assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch);
/* Test huge width */
assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue);
/* Test huge height */
assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue);
/* Test huge width & height */
assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue);
for (i = 0; i < num_subpics; ++i)
{
/* Test valid params */
assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success);
/* Test subpicture id assigned */
assert(subpicture.subpicture_id != 0);
/* Test context id assigned and correct */
assert(subpicture.context_id == context.context_id);
/* Test subpicture type id assigned and correct */
assert(subpicture.xvimage_id == subpics[i].id);
/* Test width & height assigned and correct */
assert(subpicture.width == width && subpicture.height == height);
/* Test no palette support */
assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0);
/* Test valid params */
assert(XvMCDestroySubpicture(display, &subpicture) == Success);
}
/* Test NULL surface */
assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture);
assert(XvMCDestroyContext(display, &context) == Success);
XFree(subpics);
XvUngrabPort(display, port_num, CurrentTime);
XCloseDisplay(display);
return 0;
}

View file

@ -55,4 +55,12 @@ typedef struct
XvMCContext *context;
} XvMCSurfacePrivate;
typedef struct
{
struct pipe_surface *sfc;
/* Some XvMC functions take a subpicture but not a context,
so we keep track of which context each subpicture belongs to. */
XvMCContext *context;
} XvMCSubPicturePrivate;
#endif /* xvmc_private_h */