changeset 7256:ec6dd0a29d93

Add the code that chooses a good X11 truecolor visual to the vo_x11 config() function. This is useful for framebuffers on Sun hardware, where we have multiple truecolor visuals of different depths available, and the root window typically runs at depth 8, yet there are 24 bit true color visuals available as well.
author jkeil
date Tue, 03 Sep 2002 18:10:42 +0000
parents 34b5a0b12558
children 9f8ea4d17cb5
files libvo/vo_x11.c libvo/x11_common.c libvo/x11_common.h
diffstat 3 files changed, 57 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_x11.c	Tue Sep 03 17:15:08 2002 +0000
+++ b/libvo/vo_x11.c	Tue Sep 03 18:10:42 2002 +0000
@@ -272,7 +272,10 @@
  XGetWindowAttributes( mDisplay,mRootWin,&attribs );
  depth=attribs.depth;
 
- if ( depth != 8 && depth != 15 && depth != 16 && depth != 24 && depth != 32 ) depth=24;
+ if ( depth != 15 && depth != 16 && depth != 24 && depth != 32 ) {
+   Visual *visual;
+   depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual);
+ }
  XMatchVisualInfo( mDisplay,mScreen,depth,TrueColor,&vinfo );
 
  /* set image size (which is indeed neither the input nor output size), 
--- a/libvo/x11_common.c	Tue Sep 03 17:15:08 2002 +0000
+++ b/libvo/x11_common.c	Tue Sep 03 18:10:42 2002 +0000
@@ -40,14 +40,6 @@
 #include "../mplayer.h"
 #endif
 
-/*
- * If SCAN_VISUALS is defined, vo_init() scans all available TrueColor
- * visuals for the 'best' visual for MPlayer video display.  Note that
- * the 'best' visual might be different from the default visual that
- * is in use on the root window of the display/screen.
- */
-#define	SCAN_VISUALS
-
 #define vo_wm_Unknown     0
 #define vo_wm_NetWM       1
 #define vo_wm_KDE         2
@@ -108,55 +100,6 @@
  XDefineCursor( disp,win,0 ); 
 }
 
-#ifdef	SCAN_VISUALS
-/*
- * Scan the available visuals on this Display/Screen.  Try to find
- * the 'best' available TrueColor visual that has a decent color
- * depth (at least 15bit).  If there are multiple visuals with depth
- * >= 15bit, we prefer visuals with a smaller color depth.
- */
-int vo_find_depth_from_visuals(Display *dpy, int screen, Visual **visual_return)
-{
-  XVisualInfo visual_tmpl;
-  XVisualInfo *visuals;
-  int nvisuals, i;
-  int bestvisual = -1;
-  int bestvisual_depth = -1;
-
-  visual_tmpl.screen = screen;
-  visual_tmpl.class = TrueColor;
-  visuals = XGetVisualInfo(dpy,
-			   VisualScreenMask | VisualClassMask, &visual_tmpl,
-			   &nvisuals);
-  if (visuals != NULL) {
-    for (i = 0; i < nvisuals; i++) {
-      mp_msg(MSGT_VO,MSGL_V,"vo: X11 truecolor visual %#x, depth %d, R:%lX G:%lX B:%lX\n",
-	       visuals[i].visualid, visuals[i].depth,
-	       visuals[i].red_mask, visuals[i].green_mask,
-	       visuals[i].blue_mask);
-      /*
-       * save the visual index and it's depth, if this is the first
-       * truecolor visul, or a visual that is 'preferred' over the
-       * previous 'best' visual
-       */
-      if (bestvisual_depth == -1
-	  || (visuals[i].depth >= 15 
-	      && (   visuals[i].depth < bestvisual_depth
-		  || bestvisual_depth < 15))) {
-	bestvisual = i;
-	bestvisual_depth = visuals[i].depth;
-      }
-    }
-
-    if (bestvisual != -1 && visual_return != NULL)
-      *visual_return = visuals[bestvisual].visual;
-
-    XFree(visuals);
-  }
-  return bestvisual_depth;
-}
-#endif
-
 static int x11_errorhandler(Display *display, XErrorEvent *event)
 {
 #define MSGLEN 60
@@ -313,7 +256,6 @@
  XGetWindowAttributes(mDisplay, mRootWin, &attribs);
  depth=attribs.depth;
 
-#ifdef	SCAN_VISUALS
  if (depth != 15 && depth != 16 && depth != 24 && depth != 32) {
    Visual *visual;
 
@@ -322,8 +264,7 @@
      mXImage=XCreateImage(mDisplay, visual, depth, ZPixmap,
 			  0, NULL, 1, 1, 8, 1);
  } else
-#endif
- mXImage=XGetImage( mDisplay,mRootWin,0,0,1,1,AllPlanes,ZPixmap );
+   mXImage=XGetImage( mDisplay,mRootWin,0,0,1,1,AllPlanes,ZPixmap );
 
  vo_depthonscreen = depth;	// display depth on screen
 
@@ -953,4 +894,53 @@
 }
 #endif
 
-#endif
+#endif	/* X11_FULLSCREEN */
+
+
+/*
+ * Scan the available visuals on this Display/Screen.  Try to find
+ * the 'best' available TrueColor visual that has a decent color
+ * depth (at least 15bit).  If there are multiple visuals with depth
+ * >= 15bit, we prefer visuals with a smaller color depth.
+ */
+int vo_find_depth_from_visuals(Display *dpy, int screen, Visual **visual_return)
+{
+  XVisualInfo visual_tmpl;
+  XVisualInfo *visuals;
+  int nvisuals, i;
+  int bestvisual = -1;
+  int bestvisual_depth = -1;
+
+  visual_tmpl.screen = screen;
+  visual_tmpl.class = TrueColor;
+  visuals = XGetVisualInfo(dpy,
+			   VisualScreenMask | VisualClassMask, &visual_tmpl,
+			   &nvisuals);
+  if (visuals != NULL) {
+    for (i = 0; i < nvisuals; i++) {
+      mp_msg(MSGT_VO,MSGL_V,"vo: X11 truecolor visual %#x, depth %d, R:%lX G:%lX B:%lX\n",
+	       visuals[i].visualid, visuals[i].depth,
+	       visuals[i].red_mask, visuals[i].green_mask,
+	       visuals[i].blue_mask);
+      /*
+       * save the visual index and it's depth, if this is the first
+       * truecolor visul, or a visual that is 'preferred' over the
+       * previous 'best' visual
+       */
+      if (bestvisual_depth == -1
+	  || (visuals[i].depth >= 15 
+	      && (   visuals[i].depth < bestvisual_depth
+		  || bestvisual_depth < 15))) {
+	bestvisual = i;
+	bestvisual_depth = visuals[i].depth;
+      }
+    }
+
+    if (bestvisual != -1 && visual_return != NULL)
+      *visual_return = visuals[bestvisual].visual;
+
+    XFree(visuals);
+  }
+  return bestvisual_depth;
+}
+
--- a/libvo/x11_common.h	Tue Sep 03 17:15:08 2002 +0000
+++ b/libvo/x11_common.h	Tue Sep 03 18:10:42 2002 +0000
@@ -61,3 +61,5 @@
 #endif
 
 #endif
+
+int vo_find_depth_from_visuals(Display *dpy, int screen, Visual **visual_return);