st/xorg: fix scaling ov xv data, plus some cleanups
authorZack Rusin <zackr@vmware.com>
Mon, 26 Oct 2009 11:43:49 +0000 (07:43 -0400)
committerZack Rusin <zackr@vmware.com>
Thu, 29 Oct 2009 19:13:17 +0000 (15:13 -0400)
src/gallium/state_trackers/xorg/xorg_renderer.c
src/gallium/state_trackers/xorg/xorg_renderer.h
src/gallium/state_trackers/xorg/xorg_xv.c

index a740e862b758245486cdd292e195cafc5c6d3ce8..ac2c4935a519760e17e8d4288b43ee9db5a4f72f 100644 (file)
@@ -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);
+   }
+}
index f86ef670beefcb042c3f59201777bbc64137e746..34c9ee4541d26bada5e86302bd7f39744512ef78 100644 (file)
@@ -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
index c3d9454245b052bf176b5f65091568f3bf8278b0..2b935c0f73762b4f07e5c4e033d05cb0ffffef8e 100644 (file)
@@ -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++;
    }