diff libvo/vo_xv.c @ 28511:db19e31a2c7c

Add a calc_src_dst_rects that calculates from window size, panscan etc. which part of the video source must be scaled onto which part of the window. Direct3D and (future) VDPAU need this, for XvMC it makes it easier to add cropping support and Xv is changed to keep the diff to XvMC small.
author reimar
date Thu, 12 Feb 2009 17:40:53 +0000
parents 7681eab10aea
children 4172d83194f2
line wrap: on
line diff
--- a/libvo/vo_xv.c	Thu Feb 12 16:58:47 2009 +0000
+++ b/libvo/vo_xv.c	Thu Feb 12 17:40:53 2009 +0000
@@ -106,7 +106,8 @@
 
 static int int_pause;
 
-static uint32_t drwX, drwY;
+static struct vo_rect src_rect;
+static struct vo_rect dst_rect;
 static uint32_t max_width = 0, max_height = 0; // zero means: not set
 
 static void (*draw_alpha_fnc) (int x0, int y0, int w, int h,
@@ -158,6 +159,13 @@
 
 static void deallocate_xvimage(int foo);
 
+static void resize(void)
+{
+    calc_src_dst_rects(image_width, image_height, &src_rect, &dst_rect, NULL);
+    vo_x11_clearwindow_part(mDisplay, vo_window, dst_rect.width, dst_rect.height, 1);
+    vo_xv_draw_colorkey(dst_rect.left, dst_rect.top, dst_rect.width, dst_rect.height);
+}
+
 /*
  * connect to server, create and map window,
  * allocate colors and (shared) memory
@@ -288,17 +296,8 @@
     current_ip_buf = 0;
 
     if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0) vo_fs = 1;
-    vo_calc_drwXY(&drwX, &drwY);
-
-    panscan_calc();
     
-    vo_xv_draw_colorkey(drwX - (vo_panscan_x >> 1),
-                        drwY - (vo_panscan_y >> 1),
-                        vo_dwidth + vo_panscan_x - 1,
-                        vo_dheight + vo_panscan_y - 1);
-
-    mp_msg(MSGT_VO, MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n", drwX,
-           drwY, vo_dwidth, vo_dheight);
+    resize();
 
     return 0;
 }
@@ -371,19 +370,17 @@
     if (Shmem_Flag)
     {
         XvShmPutImage(mDisplay, xv_port, vo_window, vo_gc,
-                      xvi, 0, 0, image_width,
-                      image_height, drwX - (vo_panscan_x >> 1),
-                      drwY - (vo_panscan_y >> 1), vo_dwidth + vo_panscan_x,
-                      vo_dheight + vo_panscan_y,
+                      xvi,
+                      src_rect.left, src_rect.top, src_rect.width, src_rect.height,
+                      dst_rect.left, dst_rect.top, dst_rect.width, dst_rect.height,
                       False);
     } else
 #endif
     {
         XvPutImage(mDisplay, xv_port, vo_window, vo_gc,
-                   xvi, 0, 0, image_width, image_height,
-                   drwX - (vo_panscan_x >> 1), drwY - (vo_panscan_y >> 1),
-                   vo_dwidth + vo_panscan_x,
-                   vo_dheight + vo_panscan_y);
+                   xvi,
+                   src_rect.left, src_rect.top, src_rect.width, src_rect.height,
+                   dst_rect.left, dst_rect.top, dst_rect.width, dst_rect.height);
     }
 }
 
@@ -391,17 +388,9 @@
 {
     int e = vo_x11_check_events(mDisplay);
 
-    if (e & VO_EVENT_RESIZE)
-    {
-        vo_calc_drwXY(&drwX, &drwY);
-    }
-
     if (e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE)
     {
-	vo_xv_draw_colorkey(drwX - (vo_panscan_x >> 1),
-			    drwY - (vo_panscan_y >> 1),
-			    vo_dwidth + vo_panscan_x - 1,
-			    vo_dheight + vo_panscan_y - 1);
+        resize();
     }
 
     if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause)
@@ -777,14 +766,7 @@
 
                 if (old_y != vo_panscan_y)
                 {
-                    vo_x11_clearwindow_part(mDisplay, vo_window,
-                                            vo_dwidth + vo_panscan_x - 1,
-                                            vo_dheight + vo_panscan_y - 1,
-                                            1);
-		    vo_xv_draw_colorkey(drwX - (vo_panscan_x >> 1),
-					drwY - (vo_panscan_y >> 1),
-					vo_dwidth + vo_panscan_x - 1,
-					vo_dheight + vo_panscan_y - 1);
+                    resize();
                     flip_page();
                 }
             }