[MPlayer-dev-eng] [PATCH] factor common code to handle -wid, vo_gc creation etc. out into x11_common.c

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Nov 16 15:11:15 CET 2008


Hello,
attached patch gets rid of a large part of massive code duplication.
The reason I am sending this as a patch first is that I can't test most
-vos, though I do not think anything will break besides where the
behaviour was previously inconsistent between vos.
Since I am almost the only one working on libvo stuff I will only give a
few days to test/object though.
In a next step I will probably move the CONFIG_XF86VM stuff, too, though
that will have the side effect that for vos that do not support it, when
-vm is specified on the command line it will no longer be ignored but
instead break things completely - IMO this is acceptable.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: vo_xmga.c
===================================================================
--- vo_xmga.c	(revision 27937)
+++ vo_xmga.c	(working copy)
@@ -55,7 +55,6 @@
 };
 
 const LIBVO_EXTERN(xmga)
-static XGCValues wGCV;
 
 static uint32_t mDepth;
 static XWindowAttributes attribs;
@@ -142,7 +141,6 @@
     vo_dy += xinerama_y;
     vo_dwidth = d_width;
     vo_dheight = d_height;
-    vo_mouse_autohide = 1;
 
     r = (vo_colorkey & 0x00ff0000) >> 16;
     g = (vo_colorkey & 0x0000ff00) >> 8;
@@ -189,45 +187,12 @@
             XCreateColormap(mDisplay, mRootWin, vinfo.visual, AllocNone);
         xWAttribs.background_pixel = 0;
         xWAttribs.border_pixel = 0;
-        xWAttribs.event_mask =
-            StructureNotifyMask | ExposureMask | KeyPressMask |
-            ((WinID ==
-              0) ? 0 : (ButtonPressMask | ButtonReleaseMask |
-                        PointerMotionMask | PropertyChangeMask));
-        xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+        xswamask = CWBackPixel | CWBorderPixel | CWColormap;
 
-        if (WinID >= 0)
-        {
-
-            vo_window = WinID ? ((Window) WinID) : mRootWin;
-            if (WinID)
-            {
-                XUnmapWindow(mDisplay, vo_window);
-                XChangeWindowAttributes(mDisplay, vo_window, xswamask,
-                                        &xWAttribs);
-                vo_x11_selectinput_witherr(mDisplay, vo_window,
-                                           StructureNotifyMask |
-                                           KeyPressMask |
-                                           PropertyChangeMask |
-                                           PointerMotionMask |
-                                           ButtonPressMask |
-                                           ButtonReleaseMask |
-                                           ExposureMask);
-                XMapWindow(mDisplay, vo_window);
-            } else
-                XSelectInput(mDisplay, vo_window, ExposureMask);
-
-        } else
-        {
             vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
                     flags, xWAttribs.colormap, "xmga", title);
             XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xWAttribs);
-        }
 
-        if (vo_gc != None)
-            XFreeGC(mDisplay, vo_gc);
-        vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &wGCV);
-
     }                           // !GUI
 
     if ((flags & VOFLAG_FULLSCREEN) && (!WinID))
Index: x11_common.c
===================================================================
--- x11_common.c	(revision 27937)
+++ x11_common.c	(working copy)
@@ -1269,6 +1269,23 @@
                              Colormap col_map,
                              const char *classname, const char *title)
 {
+  XGCValues xgcv;
+  if (WinID >= 0) {
+    vo_window = WinID ? (Window)WinID : mRootWin;
+    if (col_map != CopyFromParent) {
+      unsigned long xswamask = CWColormap;
+      XSetWindowAttributes xswa;
+      xswa.colormap = col_map;
+      XUnmapWindow(mDisplay, vo_window);
+      XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
+      XMapWindow(mDisplay, vo_window);
+    }
+    if (WinID) vo_x11_update_geometry();
+    vo_x11_selectinput_witherr(mDisplay, vo_window,
+          StructureNotifyMask | KeyPressMask | PointerMotionMask |
+          ButtonPressMask | ButtonReleaseMask | ExposureMask);
+    goto final;
+  }
   if (vo_window == None) {
     XSizeHints hint;
     XEvent xev;
@@ -1304,6 +1321,12 @@
   vo_x11_nofs_sizepos(vo_dx, vo_dy, width, height);
   if (!!vo_fs != !!(flags & VOFLAG_FULLSCREEN))
     vo_x11_fullscreen();
+final:
+  if (vo_gc != None)
+    XFreeGC(mDisplay, vo_gc);
+  vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &xgcv);
+  XSync(mDisplay, False);
+  vo_mouse_autohide = 1;
 }
 
 void vo_x11_clearwindow_part(Display * mDisplay, Window vo_window,
Index: vo_xvmc.c
===================================================================
--- vo_xvmc.c	(revision 27937)
+++ vo_xvmc.c	(working copy)
@@ -456,7 +456,6 @@
 //from vo_xv
 XSizeHints hint;
 XVisualInfo vinfo;
-XGCValues xgcv;
 XSetWindowAttributes xswa;
 XWindowAttributes attribs;
 unsigned long xswamask;
@@ -634,8 +633,6 @@
 
 skip_surface_allocation:
 
-   vo_mouse_autohide = 1;
-
 #ifdef CONFIG_XF86VM
    if( flags&VOFLAG_MODESWITCHING ) vm = 1;
 #endif
@@ -670,29 +667,10 @@
    xswa.border_pixel     = 0;
    xswamask = CWBackPixel | CWBorderPixel;
 
-   if ( WinID>=0 ){
-      vo_window = WinID ? ((Window)WinID) : mRootWin;
-      if ( WinID ) 
-      {
-         Window mRoot;
-         uint32_t drwBorderWidth, drwDepth;
-         XUnmapWindow( mDisplay,vo_window );
-         XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xswa );
-	 vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
-         XMapWindow( mDisplay,vo_window );
-         XGetGeometry(mDisplay, vo_window, &mRoot,
-                      &drwX, &drwY, &vo_dwidth, &vo_dheight,
-                      &drwBorderWidth, &drwDepth);
-         aspect_save_prescale(vo_dwidth, vo_dheight);
-      }
-   } else 
       vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags,
               CopyFromParent, "xvmc", title);
       XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
 
-      if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc );
-      vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &xgcv);
-      XSync(mDisplay, False);
 #ifdef CONFIG_XF86VM
       if ( vm )
       {
Index: vo_xv.c
===================================================================
--- vo_xv.c	(revision 27937)
+++ vo_xv.c	(working copy)
@@ -166,7 +166,6 @@
                        uint32_t format)
 {
     XVisualInfo vinfo;
-    XGCValues xgcv;
     XSetWindowAttributes xswa;
     XWindowAttributes attribs;
     unsigned long xswamask;
@@ -188,8 +187,6 @@
         return -1;
     }
 
-    vo_mouse_autohide = 1;
-
     int_pause = 0;
     visible_buf = -1;
 
@@ -246,38 +243,10 @@
         xswa.border_pixel = 0;
         xswamask = CWBackPixel | CWBorderPixel;
 
-        if (WinID >= 0)
-        {
-            vo_window = WinID ? ((Window) WinID) : mRootWin;
-            if (WinID)
-            {
-                XUnmapWindow(mDisplay, vo_window);
-                XChangeWindowAttributes(mDisplay, vo_window, xswamask,
-                                        &xswa);
-                vo_x11_selectinput_witherr(mDisplay, vo_window,
-                                           StructureNotifyMask |
-                                           KeyPressMask |
-                                           PropertyChangeMask |
-                                           PointerMotionMask |
-                                           ButtonPressMask |
-                                           ButtonReleaseMask |
-                                           ExposureMask);
-                XMapWindow(mDisplay, vo_window);
-                vo_x11_update_geometry();
-                aspect_save_prescale(vo_dwidth, vo_dheight);
-            } else
-                XSelectInput(mDisplay, vo_window, ExposureMask);
-        } else
-        {
             vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, vo_dwidth, vo_dheight,
                    flags, CopyFromParent, "xv", title);
             XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
-        }
 
-        if (vo_gc != None)
-            XFreeGC(mDisplay, vo_gc);
-        vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv);
-        XSync(mDisplay, False);
 #ifdef CONFIG_XF86VM
         if (vm)
         {
Index: vo_gl.c
===================================================================
--- vo_gl.c	(revision 27937)
+++ vo_gl.c	(working copy)
@@ -473,14 +473,6 @@
   if (!vo_w32_config(d_width, d_height, flags))
     return -1;
 #else
-  vo_mouse_autohide = 1;
-  if (WinID >= 0) {
-    vo_window = WinID ? (Window)WinID : mRootWin;
-    vo_x11_selectinput_witherr(mDisplay, vo_window,
-             StructureNotifyMask | KeyPressMask | PointerMotionMask |
-             ButtonPressMask | ButtonReleaseMask | ExposureMask);
-    goto glconfig;
-  }
   {
     XVisualInfo *vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib );
     if (vinfo == NULL)
Index: vo_xover.c
===================================================================
--- vo_xover.c	(revision 27937)
+++ vo_xover.c	(working copy)
@@ -51,7 +51,6 @@
 
 /* X11 related variables */
 /* Colorkey handling */
-static XGCValues mGCV;
 static int colorkey;
 
 /* Image parameters */
@@ -217,7 +216,6 @@
   image_height = height;
   image_width = width;
   image_format = format;
-  vo_mouse_autohide=1;
 
   aspect_save_orig(width, height);
   aspect_save_prescale(d_width, d_height);
@@ -281,31 +279,13 @@
       xswa.border_pixel     = 0;
       xswa.colormap         = XCreateColormap(mDisplay, RootWindow(mDisplay, mScreen),
 					      vinfo.visual, AllocNone);
-      xswa.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask | PropertyChangeMask |
-	((WinID==0)?0:(ButtonPressMask | ButtonReleaseMask | PointerMotionMask));
-      xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+      xswamask = CWBackPixel | CWBorderPixel | CWColormap;
 
-      if (WinID >= 0)
-	{
-	  vo_window = WinID ? ((Window)WinID) : RootWindow(mDisplay, mScreen);
-	  if ( WinID )
-	    {
-	      XUnmapWindow(mDisplay, vo_window);
-	      XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
-	      vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
-	      XMapWindow(mDisplay, vo_window);
-	    } else XSelectInput( mDisplay,vo_window,ExposureMask );
-	}
-      else
-	{
 	    vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy,
                   window_width, window_height, flags,
 	          xswa.colormap, "xvidix", title);
 	    XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
-	}
 	 
-      if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc );
-      vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &mGCV);
 #ifdef CONFIG_GUI
     }
 #endif
Index: vo_x11.c
===================================================================
--- vo_x11.c	(revision 27937)
+++ vo_x11.c	(working copy)
@@ -317,7 +317,6 @@
     int vm = 0;
 #endif
 
-    vo_mouse_autohide = 1;
     old_vo_dwidth = -1;
     old_vo_dheight = -1;
 
@@ -395,37 +394,11 @@
         }
 #endif
 
-        if (WinID >= 0)
-        {
-            vo_window = WinID ? ((Window) WinID) : mRootWin;
-            if (WinID)
-            {
-                XUnmapWindow(mDisplay, vo_window);
-                XChangeWindowAttributes(mDisplay, vo_window, xswamask,
-                                        &xswa);
-                vo_x11_selectinput_witherr(mDisplay, vo_window,
-                                           StructureNotifyMask |
-                                           KeyPressMask |
-                                           PropertyChangeMask |
-                                           PointerMotionMask |
-                                           ButtonPressMask |
-                                           ButtonReleaseMask |
-                                           ExposureMask);
-                XMapWindow(mDisplay, vo_window);
-                depth = vo_x11_update_geometry();
-            } else
-                XSelectInput(mDisplay, vo_window, ExposureMask);
-        } else
-        {
             vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, vo_dwidth, vo_dheight,
                     flags, theCmap, "x11", title);
-        }
+        if (WinID > 0)
+            depth = vo_x11_update_geometry();
 
-        if (vo_gc != None)
-            XFreeGC(mDisplay, vo_gc);
-        vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv);
-        XSync(mDisplay, False);
-
 #ifdef CONFIG_XF86VM
         if (vm)
         {
Index: vo_gl2.c
===================================================================
--- vo_gl2.c	(revision 27937)
+++ vo_gl2.c	(working copy)
@@ -521,14 +521,6 @@
 
 static int config_glx(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
   XVisualInfo *vinfo, vinfo_buf;
-  vo_mouse_autohide = 1;
-  if (WinID >= 0) {
-    vo_window = WinID ? (Window)WinID : mRootWin;
-    vo_x11_selectinput_witherr(mDisplay, vo_window,
-             StructureNotifyMask | KeyPressMask | PointerMotionMask |
-             ButtonPressMask | ButtonReleaseMask | ExposureMask);
-    return 0;
-  }
     vinfo = choose_glx_visual(mDisplay,mScreen,&vinfo_buf) < 0 ? NULL : &vinfo_buf;
     if (vinfo == NULL) {
       mp_msg(MSGT_VO, MSGL_FATAL, "[gl2] no GLX support present\n");
Index: vo_xvidix.c
===================================================================
--- vo_xvidix.c	(revision 27937)
+++ vo_xvidix.c	(working copy)
@@ -49,7 +49,6 @@
 #define UNUSED(x) ((void)(x))   /* Removes warning about unused arguments */
 /* X11 related variables */
 /* Colorkey handling */
-static XGCValues mGCV;
 static int colorkey;
 static vidix_grkey_t gr_key;
 
@@ -205,7 +204,6 @@
     image_height = height;
     image_width = width;
     image_format = format;
-    vo_mouse_autohide = 1;
 
     window_width = d_width;
     window_height = d_height;
@@ -268,44 +266,13 @@
         xswa.colormap =
             XCreateColormap(mDisplay, RootWindow(mDisplay, mScreen),
                             vinfo.visual, AllocNone);
-        xswa.event_mask =
-            StructureNotifyMask | ExposureMask | KeyPressMask |
-            PropertyChangeMask | ((WinID == 0) ? 0
-                                  : (ButtonPressMask | ButtonReleaseMask |
-                                     PointerMotionMask));
-        xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+        xswamask = CWBackPixel | CWBorderPixel | CWColormap;
 
-        if (WinID >= 0)
-        {
-            vo_window =
-                WinID ? ((Window) WinID) : RootWindow(mDisplay, mScreen);
-            if (WinID)
-            {
-                XUnmapWindow(mDisplay, vo_window);
-                XChangeWindowAttributes(mDisplay, vo_window, xswamask,
-                                        &xswa);
-                vo_x11_selectinput_witherr(mDisplay, vo_window,
-                                           StructureNotifyMask |
-                                           KeyPressMask |
-                                           PropertyChangeMask |
-                                           PointerMotionMask |
-                                           ButtonPressMask |
-                                           ButtonReleaseMask |
-                                           ExposureMask);
-                XMapWindow(mDisplay, vo_window);
-            } else
-                XSelectInput(mDisplay, vo_window, ExposureMask);
-        } else
-        {
             vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy,
                     window_width, window_height, flags,
                     CopyFromParent, "xvidix", title);
             XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
-        }
 
-        if (vo_gc != None)
-            XFreeGC(mDisplay, vo_gc);
-        vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &mGCV);
 #ifdef CONFIG_GUI
     }
 #endif


More information about the MPlayer-dev-eng mailing list