comparison libvo/x11_common.c @ 1732:086e8d0c4639

Handle X11 displays with multiple depths. On such an X11 display with multiple depths, the root window might use something like 8-bit pseudocolor, but there may be other 15/16/24/32 bit truecolor visuals available for MPlayer's video display.
author jkeil
date Tue, 28 Aug 2001 17:52:20 +0000
parents 5e4214a7540e
children 6e7da6f362ab
comparison
equal deleted inserted replaced
1731:07e2dfca67a3 1732:086e8d0c4639
18 #include <X11/Xatom.h> 18 #include <X11/Xatom.h>
19 19
20 #ifdef HAVE_XDPMS 20 #ifdef HAVE_XDPMS
21 #include <X11/extensions/dpms.h> 21 #include <X11/extensions/dpms.h>
22 #endif 22 #endif
23
24
25 /*
26 * If SCAN_VISUALS is defined, vo_init() scans all available TrueColor
27 * visuals for the 'best' visual for MPlayer video display. Note that
28 * the 'best' visual might be different from the default visual that
29 * is in use on the root window of the display/screen.
30 */
31 #define SCAN_VISUALS
32
23 33
24 extern verbose; 34 extern verbose;
25 35
26 static int dpms_disabled=0; 36 static int dpms_disabled=0;
27 static int timeout_save=0; 37 static int timeout_save=0;
47 no_ptr=XCreatePixmapCursor(disp, bm_no, bm_no,&black, &black,0, 0); 57 no_ptr=XCreatePixmapCursor(disp, bm_no, bm_no,&black, &black,0, 0);
48 XDefineCursor(disp,win,no_ptr); 58 XDefineCursor(disp,win,no_ptr);
49 } 59 }
50 60
51 61
62 #ifdef SCAN_VISUALS
63 /*
64 * Scan the available visuals on this Display/Screen. Try to find
65 * the 'best' available TrueColor visual that has a decent color
66 * depth (at least 15bit). If there are multiple visuals with depth
67 * >= 15bit, we prefer visuals with a smaller color depth.
68 */
69 int vo_find_depth_from_visuals(Display *dpy, int screen, Visual **visual_return)
70 {
71 XVisualInfo visual_tmpl;
72 XVisualInfo *visuals;
73 int nvisuals, i;
74 int bestvisual = -1;
75 int bestvisual_depth = -1;
76
77 visual_tmpl.screen = screen;
78 visual_tmpl.class = TrueColor;
79 visuals = XGetVisualInfo(dpy,
80 VisualScreenMask | VisualClassMask, &visual_tmpl,
81 &nvisuals);
82 if (visuals != NULL) {
83 for (i = 0; i < nvisuals; i++) {
84 if (verbose)
85 printf("vo: X11 truecolor visual %#x, depth %d, R:%lX G:%lX B:%lX\n",
86 visuals[i].visualid, visuals[i].depth,
87 visuals[i].red_mask, visuals[i].green_mask,
88 visuals[i].blue_mask);
89 /*
90 * save the visual index and it's depth, if this is the first
91 * truecolor visul, or a visual that is 'preferred' over the
92 * previous 'best' visual
93 */
94 if (bestvisual_depth == -1
95 || (visuals[i].depth >= 15
96 && ( visuals[i].depth < bestvisual_depth
97 || bestvisual_depth < 15))) {
98 bestvisual = i;
99 bestvisual_depth = visuals[i].depth;
100 }
101 }
102
103 if (bestvisual != -1 && visual_return != NULL)
104 *visual_return = visuals[bestvisual].visual;
105
106 XFree(visuals);
107 }
108 return bestvisual_depth;
109 }
110 #endif
111
112
52 int vo_init( void ) 113 int vo_init( void )
53 { 114 {
54 // int mScreen; 115 // int mScreen;
55 int bpp; 116 int depth, bpp;
56 unsigned int mask; 117 unsigned int mask;
57 // char * DisplayName = ":0.0"; 118 // char * DisplayName = ":0.0";
58 // Display * mDisplay; 119 // Display * mDisplay;
59 XImage * mXImage; 120 XImage * mXImage = NULL;
60 // Window mRootWin; 121 // Window mRootWin;
61 static XWindowAttributes attribs; 122 XWindowAttributes attribs;
62 123
63 if(vo_depthonscreen) return 1; // already called 124 if(vo_depthonscreen) return 1; // already called
64 125
65 if (!mDisplayName) 126 if (!mDisplayName)
66 if (!(mDisplayName=getenv("DISPLAY"))) 127 if (!(mDisplayName=getenv("DISPLAY")))
74 } 135 }
75 mScreen=DefaultScreen( mDisplay ); // Screen ID. 136 mScreen=DefaultScreen( mDisplay ); // Screen ID.
76 mRootWin=RootWindow( mDisplay,mScreen );// Root window ID. 137 mRootWin=RootWindow( mDisplay,mScreen );// Root window ID.
77 vo_screenwidth=DisplayWidth( mDisplay,mScreen ); 138 vo_screenwidth=DisplayWidth( mDisplay,mScreen );
78 vo_screenheight=DisplayHeight( mDisplay,mScreen ); 139 vo_screenheight=DisplayHeight( mDisplay,mScreen );
79 // get color depth: 140
80 // XGetWindowAttributes(mydisplay, DefaultRootWindow(mDisplay), &attribs); 141 // get color depth (from root window, or the best visual):
81 XGetWindowAttributes(mDisplay, mRootWin, &attribs); 142 XGetWindowAttributes(mDisplay, mRootWin, &attribs);
82 vo_depthonscreen=attribs.depth; 143 depth=attribs.depth;
83 // get bits/pixel: 144
84 mXImage=XGetImage( mDisplay,mRootWin,0,0,1,1,AllPlanes,ZPixmap ); 145 #ifdef SCAN_VISUALS
146 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) {
147 Visual *visual;
148
149 depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual);
150 if (depth != -1)
151 mXImage=XCreateImage(mDisplay, visual, depth, ZPixmap,
152 0, NULL, 1, 1, 8, 1);
153 } else
154 #endif
155 mXImage=XGetImage( mDisplay,mRootWin,0,0,1,1,AllPlanes,ZPixmap );
156
157 vo_depthonscreen = depth; // display depth on screen
158
159 // get bits/pixel from XImage structure:
160 if (mXImage == NULL) {
161 mask = 0;
162 } else {
163 /*
164 * for the depth==24 case, the XImage structures might use
165 * 24 or 32 bits of data per pixel. The global variable
166 * vo_depthonscreen stores the amount of data per pixel in the
167 * XImage structure!
168 *
169 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
170 */
85 bpp=mXImage->bits_per_pixel; 171 bpp=mXImage->bits_per_pixel;
86 if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi 172 if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi
87 mask=mXImage->red_mask|mXImage->green_mask|mXImage->blue_mask; 173 mask=mXImage->red_mask|mXImage->green_mask|mXImage->blue_mask;
174 XDestroyImage( mXImage );
88 if(verbose) 175 if(verbose)
89 printf("vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", 176 printf("vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n",
90 mask,mXImage->red_mask,mXImage->green_mask,mXImage->blue_mask); 177 mask,mXImage->red_mask,mXImage->green_mask,mXImage->blue_mask);
91 if(((vo_depthonscreen+7)/8)==2){ 178 }
92 if(mask==0x7FFF) vo_depthonscreen=15; else 179 if(((vo_depthonscreen+7)/8)==2){
93 if(mask==0xFFFF) vo_depthonscreen=16; 180 if(mask==0x7FFF) vo_depthonscreen=15; else
94 } 181 if(mask==0xFFFF) vo_depthonscreen=16;
95 XDestroyImage( mXImage ); 182 }
96 // XCloseDisplay( mDisplay ); 183 // XCloseDisplay( mDisplay );
97 /* slightly improved local display detection AST */ 184 /* slightly improved local display detection AST */
98 if ( strncmp(mDisplayName, "unix:", 5) == 0) 185 if ( strncmp(mDisplayName, "unix:", 5) == 0)
99 mDisplayName += 4; 186 mDisplayName += 4;
100 else if ( strncmp(mDisplayName, "localhost:", 10) == 0) 187 else if ( strncmp(mDisplayName, "localhost:", 10) == 0)
101 mDisplayName += 9; 188 mDisplayName += 9;
102 if (*mDisplayName==':') mLocalDisplay=1; else mLocalDisplay=0; 189 if (*mDisplayName==':') mLocalDisplay=1; else mLocalDisplay=0;
103 printf("vo: X11 running at %dx%d depth: %d (\"%s\" => %s display)\n",vo_screenwidth,vo_screenheight,vo_depthonscreen,mDisplayName,mLocalDisplay?"local":"remote"); 190 printf("vo: X11 running at %dx%d with depth %d and %d bits/pixel (\"%s\" => %s display)\n",
191 vo_screenwidth,vo_screenheight,
192 depth, vo_depthonscreen,
193 mDisplayName,mLocalDisplay?"local":"remote");
104 return 1; 194 return 1;
105 } 195 }
106 196
107 #include "../linux/keycodes.h" 197 #include "../linux/keycodes.h"
108 #include "wskeys.h" 198 #include "wskeys.h"