[MPlayer-dev-eng] [PATCH] directx -wid support

Joey Parrish joey at nicewarrior.org
Thu Dec 16 13:50:59 CET 2004


Hello,

This patch adds support for -wid to vo_directx.

Important notes:
  * -wid for directx is a window handle as returned by a call to
    FindWindow in the win32 api.  VOCTRL_{ONTOP, ROOTWIN} have no
    effect when an external window is being used.  fullscreen still
    works.

  * -geometry, when used with -wid, will specify a location relative
    to the window rather than the screen.  this is useful for embedding
    MPlayer into a frontend or browser.

  * when using -wid, MPlayer doesn't receive window system events to
    tell it when the window has moved.  so, Directx_ManageDisplay() is
    called to calculate the position of the window.  this has not
    impacted performance in my tests.  also note that calculating the
    new values for the RECT structure takes the same exact calls as you
    would use to simply detect the movement of the window.  so no, it
    would not be better to check for movement and only call ManageDisplay()
    when it's moved.

This patch depends on the last two I've sent, (colorkey and monitoraspect)
but only because I diff'd the tree in that order.  I've attached them for
convenience in testing.

Comments?  I'd like to commit this soon.

--Joey

-- 
"I eat donuts for dying children." --Andrew
-------------- next part --------------
diff -ur main.sofar/libvo/vo_directx.c main.dev/libvo/vo_directx.c
--- main.sofar/libvo/vo_directx.c	2004-12-08 20:02:42.667761600 -0600
+++ main.dev/libvo/vo_directx.c	2004-12-08 19:45:09.846665600 -0600
@@ -79,6 +79,7 @@
 extern int vo_ontop;
 extern int vo_rootwin;
 extern int vidmode;
+extern int vo_colorkey;
 
 /*****************************************************************************
  * DirectDraw GUIDs.
@@ -978,6 +987,7 @@
     monitor_rect.right=GetSystemMetrics(SM_CXSCREEN);
     monitor_rect.bottom=GetSystemMetrics(SM_CYSCREEN);
 	
+    windowcolor = vo_colorkey;
     wc.style         =  CS_HREDRAW | CS_VREDRAW;
     wc.lpfnWndProc   =  WndProc;
     wc.cbClsExtra    =  0;
-------------- next part --------------
diff -ur main.sofar/libvo/vo_directx.c main.dev/libvo/vo_directx.c
--- main.sofar/libvo/vo_directx.c	2004-12-08 20:02:42.667761600 -0600
+++ main.dev/libvo/vo_directx.c	2004-12-08 19:45:09.846665600 -0600
@@ -80,6 +80,7 @@
 extern int vo_rootwin;
 extern int vidmode;
 extern int vo_colorkey;
+extern float monitor_aspect;
 
 /*****************************************************************************
  * DirectDraw GUIDs.
@@ -1196,6 +1210,7 @@
     RECT rd;
     vo_screenwidth = monitor_rect.right - monitor_rect.left;
     vo_screenheight = monitor_rect.bottom - monitor_rect.top;
+    monitor_aspect = (float)vo_screenwidth / (float)vo_screenheight;
     vo_fs = options & 0x01;
 	image_format =  format;
 	image_width = width;
-------------- next part --------------
diff -ur main.sofar/DOCS/man/en/mplayer.1 main.dev/DOCS/man/en/mplayer.1
--- main.sofar/DOCS/man/en/mplayer.1	2004-11-18 14:01:34.000000000 -0600
+++ main.dev/DOCS/man/en/mplayer.1	2004-12-14 16:18:35.679088000 -0600
@@ -2134,6 +2134,9 @@
 sign is given after the argument it turns the value into a percentage of the
 screen size in that direction.
 It also supports the standard X11 \-geometry option format.
+If an external window is specified using the \-wid option, then the x and
+y coordinates are relative to the top-left corner of the window rather
+than the screen.
 .br
 .I NOTE:
 This option is only supported by the x11, xmga, xv, xvmc, xvidix,
@@ -2269,8 +2272,8 @@
 Enables VBI for the vesa, dfbmga and svga video output drivers.
 .
 .TP
-.B \-wid <window\ ID> (also see \-guiwid) (X11 only)
-This tells MPlayer to attach to an existing X11 window.
+.B \-wid <window\ ID> (also see \-guiwid) (X11 and DirectX only)
+This tells MPlayer to attach to an existing window.
 Useful to embed MPlayer in a browser (e.g.\& the plugger extension).
 .
 .TP
diff -ur main.sofar/cfg-mplayer.h main.dev/cfg-mplayer.h
--- main.sofar/cfg-mplayer.h	2004-12-14 16:06:09.045481600 -0600
+++ main.dev/cfg-mplayer.h	2004-12-14 16:06:44.366270400 -0600
@@ -75,8 +75,8 @@
 extern int stop_xscreensaver;
 extern char **vo_fstype_list;
 extern int vo_nomouse_input;
-extern int WinID;
 #endif
+extern int WinID;
 
 #ifdef HAVE_MENU
 extern int menu_startup;
@@ -272,9 +272,9 @@
 	
     {"adapter", &vo_adapter_num, CONF_TYPE_INT, CONF_RANGE, 0, 5, NULL},
     {"refreshrate",&vo_refresh_rate,CONF_TYPE_INT,CONF_RANGE, 0,100, NULL},
+	{"wid", &WinID, CONF_TYPE_INT, 0, 0, 0, NULL},
 #ifdef HAVE_X11
 	// x11,xv,xmga,xvidix
-	{"wid", &WinID, CONF_TYPE_INT, 0, 0, 0, NULL},
 	{"icelayer", "-icelayer is obsolete. Use -fstype layer:<number> instead.\n", CONF_TYPE_PRINT, 0, 0, 0, NULL},
 	{"stop-xscreensaver", &stop_xscreensaver, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"nostop-xscreensaver", &stop_xscreensaver, CONF_TYPE_FLAG, 0, 1, 0, NULL},
diff -ur main.sofar/libvo/video_out.c main.dev/libvo/video_out.c
--- main.sofar/libvo/video_out.c	2004-12-14 16:06:10.717886400 -0600
+++ main.dev/libvo/video_out.c	2004-12-14 16:06:44.476428800 -0600
@@ -45,6 +45,7 @@
 int vo_refresh_rate=0;
 int vo_keepaspect=1;
 int vo_rootwin=0;
+int WinID = -1;
 
 int vo_pts=0; // for hw decoding
 float vo_fps=0; // for mp1e rte
diff -ur main.sofar/libvo/vo_directx.c main.dev/libvo/vo_directx.c
--- main.sofar/libvo/vo_directx.c	2004-12-14 16:06:37.937025600 -0600
+++ main.dev/libvo/vo_directx.c	2004-12-14 16:09:25.768355200 -0600
@@ -81,6 +81,7 @@
 extern int vidmode;
 extern int vo_colorkey;
 extern float monitor_aspect;
+extern int WinID;
 
 /*****************************************************************************
  * DirectDraw GUIDs.
@@ -510,6 +511,17 @@
       rd.top=(vo_screenheight-height)/2;
       if(ShowCursor(FALSE)>=0)while(ShowCursor(FALSE)>=0){}
     }
+    else if (WinID != -1 && vo_geometry) {
+      POINT pt;
+      pt.x = vo_dx;
+      pt.y = vo_dy;
+      ClientToScreen(hWnd,&pt);  
+      width=d_image_width;
+      height=d_image_height;
+      rd.left = pt.x;
+      rd.top = pt.y;
+      while(ShowCursor(TRUE)<=0){}
+    }
     else {
       POINT pt;
       pt.x = 0;  //overlayposition relative to the window
@@ -628,6 +640,7 @@
     }       
 	
     if(!vidmode && !vo_fs){
+      if(WinID == -1) {
           RECT rdw=rd;
           AdjustWindowRect(&rdw,WS_OVERLAPPEDWINDOW|WS_SIZEBOX,FALSE);
 //          printf("window: %i %i %ix%i\n",rdw.left,rdw.top,rdw.right - rdw.left,rdw.bottom - rdw.top);      
@@ -636,18 +649,18 @@
 		  rdw.right += monitor_rect.left;
 		  rdw.bottom += monitor_rect.top;
           SetWindowPos(hWnd,(vo_ontop)?HWND_TOPMOST:(vo_rootwin?HWND_BOTTOM:HWND_NOTOPMOST),rdw.left,rdw.top,rdw.right-rdw.left,rdw.bottom-rdw.top,SWP_NOOWNERZORDER); 
+      }
     }
     else SetWindowPos(vidmode?hWnd:hWndFS,vo_rootwin?HWND_BOTTOM:HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOOWNERZORDER);
 
-  	/*for nonoverlay mode we are finished, for overlay mode we have to display the overlay first*/
-	if(nooverlay)return 0;
-
     /*make sure the overlay is inside the screen*/
     if(rd.left<0)rd.left=0;
     if(rd.right>vo_screenwidth)rd.right=vo_screenwidth;
     if(rd.top<0)rd.top=0;
     if(rd.bottom>vo_screenheight)rd.bottom=vo_screenheight;
     
+  	/*for nonoverlay mode we are finished, for overlay mode we have to display the overlay first*/
+	if(nooverlay)return 0;
 	
 //    printf("overlay: %i %i %ix%i\n",rd.left,rd.top,rd.right - rd.left,rd.bottom - rd.top);
 	ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
@@ -992,6 +1005,8 @@
     wc.lpszClassName =  "MPlayer - The Movie Player";
     wc.lpszMenuName  =  NULL;
     RegisterClass(&wc);
+    if (WinID != -1) hWnd = WinID;
+    else
     hWnd = CreateWindowEx(vidmode?WS_EX_TOPMOST:0,
         "MPlayer - The Movie Player","",(vidmode)?WS_POPUP:WS_OVERLAPPEDWINDOW| WS_SIZEBOX,
         CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,NULL,NULL,hInstance,NULL);
@@ -1144,6 +1159,8 @@
 	uint32_t y = mpi->y;
 	uint32_t w = mpi->w;
 	uint32_t h = mpi->h;
+
+    if (WinID != -1) Directx_ManageDisplay();
    
     if((mpi->flags&MP_IMGFLAG_DIRECT)||(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) 
 	{
@@ -1232,12 +1249,15 @@
         rd.top = vo_dy;
         rd.right = rd.left + d_image_width;
         rd.bottom = rd.top + d_image_height;
+        if (WinID == -1) {
         AdjustWindowRect(&rd,WS_OVERLAPPEDWINDOW|WS_SIZEBOX,FALSE);  
         SetWindowPos(hWnd,NULL, vo_dx, vo_dy,rd.right-rd.left,rd.bottom-rd.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER); 
+        }
     }
     else ShowWindow(hWnd,SW_SHOW); 
      
     if(vo_fs && !vidmode)ShowWindow(hWndFS,SW_SHOW);   
+	if (WinID == -1)
 	SetWindowText(hWnd,title);
     
     
@@ -1380,6 +1400,7 @@
 	case VOCTRL_DRAW_IMAGE:
         return put_image(data);
     case VOCTRL_ONTOP:
+			if(WinID != -1) return VO_TRUE;
 	        if(vidmode)
 			{
 				mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>ontop has no meaning in exclusive mode\n");
@@ -1392,6 +1413,7 @@
 			}
 		return VO_TRUE;
     case VOCTRL_ROOTWIN:
+			if(WinID != -1) return VO_TRUE;
 	        if(vidmode)
 			{
 				mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>rootwin has no meaning in exclusive mode\n");
diff -ur main.sofar/libvo/x11_common.c main.dev/libvo/x11_common.c
--- main.sofar/libvo/x11_common.c	2004-11-18 14:01:49.000000000 -0600
+++ main.dev/libvo/x11_common.c	2004-12-14 16:06:44.726788800 -0600
@@ -75,7 +75,7 @@
 int mLocalDisplay;
 
 /* output window id */
-int WinID = -1;
+extern int WinID;
 int vo_mouse_autohide = 0;
 int vo_wm_type = 0;
 int vo_fs_type = 0; // needs to be accessible for GUI X11 code


More information about the MPlayer-dev-eng mailing list