From a7fa56a64b8963e74e93f3bac8ac80813f4a9778 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 26 Oct 2009 07:43:49 -0400 Subject: [PATCH] st/xorg: fix scaling ov xv data, plus some cleanups --- src/gallium/state_trackers/xorg/xorg_renderer.c | 47 +++++++++++++++++-------- src/gallium/state_trackers/xorg/xorg_renderer.h | 5 +++ src/gallium/state_trackers/xorg/xorg_xv.c | 33 ++++++++++------- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.c b/src/gallium/state_trackers/xorg/xorg_renderer.c index a740e86..ac2c493 100644 --- a/src/gallium/state_trackers/xorg/xorg_renderer.c +++ b/src/gallium/state_trackers/xorg/xorg_renderer.c @@ -226,9 +226,8 @@ setup_vertex_data2(struct xorg_renderer *r, static struct pipe_buffer * setup_vertex_data_yuv(struct xorg_renderer *r, - float srcX, float srcY, - float dstX, float dstY, - float width, float height, + float srcX, float srcY, float srcW, float srcH, + float dstX, float dstY, float dstW, float dstH, struct pipe_texture **tex) { float s0, t0, s1, t1; @@ -236,8 +235,8 @@ setup_vertex_data_yuv(struct xorg_renderer *r, spt0[0] = srcX; spt0[1] = srcY; - spt1[0] = srcX + width; - spt1[1] = srcY + height; + spt1[0] = srcX + srcW; + spt1[1] = srcY + srcH; s0 = spt0[0] / tex[0]->width[0]; t0 = spt0[1] / tex[0]->height[0]; @@ -247,13 +246,13 @@ setup_vertex_data_yuv(struct xorg_renderer *r, /* 1st vertex */ setup_vertex1(r->vertices2[0], dstX, dstY, s0, t0); /* 2nd vertex */ - setup_vertex1(r->vertices2[1], dstX + width, dstY, + setup_vertex1(r->vertices2[1], dstX + dstW, dstY, s1, t0); /* 3rd vertex */ - setup_vertex1(r->vertices2[2], dstX + width, dstY + height, + setup_vertex1(r->vertices2[2], dstX + dstW, dstY + dstH, s1, t1); /* 4th vertex */ - setup_vertex1(r->vertices2[3], dstX, dstY + height, + setup_vertex1(r->vertices2[3], dstX, dstY + dstH, s0, t1); @@ -864,13 +863,6 @@ void renderer_draw_textures(struct xorg_renderer *r, src_matrix, mask_matrix); break; case 3: - buf = setup_vertex_data_yuv(r, - pos[0], pos[1], - pos[2], pos[3], - width, height, - textures); - num_textures = 1; - break; default: debug_assert(!"Unsupported number of textures"); break; @@ -888,3 +880,28 @@ void renderer_draw_textures(struct xorg_renderer *r, pipe_buffer_reference(&buf, NULL); } } + +void renderer_draw_yuv(struct xorg_renderer *r, + int src_x, int src_y, int src_w, int src_h, + int dst_x, int dst_y, int dst_w, int dst_h, + struct pipe_texture **textures) +{ + struct pipe_context *pipe = r->pipe; + struct pipe_buffer *buf = 0; + + buf = setup_vertex_data_yuv(r, + src_x, src_y, src_w, src_h, + dst_x, dst_y, dst_w, dst_h, + textures); + + if (buf) { + const int num_attribs = 2; /*pos + tex coord*/ + + util_draw_vertex_buffer(pipe, buf, 0, + PIPE_PRIM_TRIANGLE_FAN, + 4, /* verts */ + num_attribs); /* attribs/vert */ + + pipe_buffer_reference(&buf, NULL); + } +} diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.h b/src/gallium/state_trackers/xorg/xorg_renderer.h index f86ef67..34c9ee4 100644 --- a/src/gallium/state_trackers/xorg/xorg_renderer.h +++ b/src/gallium/state_trackers/xorg/xorg_renderer.h @@ -51,5 +51,10 @@ void renderer_draw_textures(struct xorg_renderer *r, float *src_matrix, float *mask_matrix); +void renderer_draw_yuv(struct xorg_renderer *r, + int src_x, int src_y, int src_w, int src_h, + int dst_x, int dst_y, int dst_w, int dst_h, + struct pipe_texture **textures); + #endif diff --git a/src/gallium/state_trackers/xorg/xorg_xv.c b/src/gallium/state_trackers/xorg/xorg_xv.c index c3d9454..2b935c0 100644 --- a/src/gallium/state_trackers/xorg/xorg_xv.c +++ b/src/gallium/state_trackers/xorg/xorg_xv.c @@ -343,19 +343,16 @@ setup_fs_video_constants(struct xorg_renderer *r, boolean hdtv) } static void -draw_yuv(struct xorg_xv_port_priv *port, int src_x, int src_y, - int dst_x, int dst_y, - int w, int h) +draw_yuv(struct xorg_xv_port_priv *port, + int src_x, int src_y, int src_w, int src_h, + int dst_x, int dst_y, int dst_w, int dst_h) { - int pos[4] = {src_x, src_y, - dst_x, dst_y}; struct pipe_texture **textures = port->yuv[port->current_set]; - renderer_draw_textures(port->r, - pos, w, h, - textures, - 3, /*bound samplers/textures */ - NULL, NULL /* no transformations */); + renderer_draw_yuv(port->r, + src_x, src_y, src_w, src_h, + dst_x, dst_y, dst_w, dst_h, + textures); } static void @@ -438,8 +435,7 @@ static int display_video(ScrnInfoPtr pScrn, struct xorg_xv_port_priv *pPriv, int id, RegionPtr dstRegion, int src_x, int src_y, int src_w, int src_h, - int dstX, int dstY, - short width, short height, + int dstX, int dstY, int dst_w, int dst_h, PixmapPtr pPixmap) { modesettingPtr ms = modesettingPTR(pScrn); @@ -478,13 +474,24 @@ display_video(ScrnInfoPtr pScrn, struct xorg_xv_port_priv *pPriv, int id, int box_y1 = pbox->y1; int box_x2 = pbox->x2; int box_y2 = pbox->y2; + float diff_x = (float)src_w / (float)dst_w; + float diff_y = (float)src_h / (float)dst_h; + int offset_x = box_x1 - dstX; + int offset_y = box_y1 - dstY; + int offset_w; + int offset_h; x = box_x1; y = box_y1; w = box_x2 - box_x1; h = box_y2 - box_y1; - draw_yuv(pPriv, src_x, src_y, x, y, w, h); + offset_w = dst_w - w; + offset_h = dst_h - h; + + draw_yuv(pPriv, src_x + offset_x*diff_x, src_y + offset_y*diff_y, + src_w - offset_w*diff_x, src_h - offset_h*diff_x, + x, y, w, h); pbox++; } -- 2.7.4