Mercurial > mplayer.hg
comparison libvo/vo_gl.c @ 2041:ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
author | arpi |
---|---|
date | Mon, 01 Oct 2001 22:38:16 +0000 |
parents | bf7764f429c9 |
children | 378aed6b232d |
comparison
equal
deleted
inserted
replaced
2040:bf7764f429c9 | 2041:ba8a225d1a18 |
---|---|
47 | 47 |
48 /* local data */ | 48 /* local data */ |
49 static unsigned char *ImageData=NULL; | 49 static unsigned char *ImageData=NULL; |
50 | 50 |
51 /* X11 related variables */ | 51 /* X11 related variables */ |
52 static Display *mydisplay; | 52 //static Display *mydisplay; |
53 static Window mywindow; | 53 static Window mywindow; |
54 //static GC mygc; | 54 //static GC mygc; |
55 //static XImage *myximage; | 55 //static XImage *myximage; |
56 //static int depth,mode; | 56 //static int depth,mode; |
57 static XWindowAttributes attribs; | 57 //static XWindowAttributes attribs; |
58 static int X_already_started = 0; | 58 static int X_already_started = 0; |
59 | 59 |
60 //static int texture_id=1; | 60 //static int texture_id=1; |
61 | 61 |
62 static GLXContext wsGLXContext; | 62 static GLXContext wsGLXContext; |
63 //XVisualInfo * wsVisualInfo; | 63 //XVisualInfo * wsVisualInfo; |
64 int wsGLXAttrib[] = { GLX_RGBA, | 64 static int wsGLXAttrib[] = { GLX_RGBA, |
65 GLX_RED_SIZE,1, | 65 GLX_RED_SIZE,1, |
66 GLX_GREEN_SIZE,1, | 66 GLX_GREEN_SIZE,1, |
67 GLX_BLUE_SIZE,1, | 67 GLX_BLUE_SIZE,1, |
68 // GLX_DEPTH_SIZE,16, | 68 // GLX_DEPTH_SIZE,16, |
69 GLX_DOUBLEBUFFER, | 69 GLX_DOUBLEBUFFER, |
95 * allocate colors and (shared) memory | 95 * allocate colors and (shared) memory |
96 */ | 96 */ |
97 static uint32_t | 97 static uint32_t |
98 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) | 98 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
99 { | 99 { |
100 int screen; | 100 // int screen; |
101 int dwidth,dheight; | 101 int dwidth,dheight; |
102 unsigned int fg, bg; | 102 unsigned int fg, bg; |
103 char *hello = (title == NULL) ? "OpenGL rulez" : title; | 103 char *hello = (title == NULL) ? "OpenGL rulez" : title; |
104 char *name = ":0.0"; | 104 // char *name = ":0.0"; |
105 XSizeHints hint; | 105 XSizeHints hint; |
106 XVisualInfo *vinfo; | 106 XVisualInfo *vinfo; |
107 XEvent xev; | 107 XEvent xev; |
108 | 108 |
109 // XGCValues xgcv; | 109 // XGCValues xgcv; |
113 image_height = height; | 113 image_height = height; |
114 image_width = width; | 114 image_width = width; |
115 image_format = format; | 115 image_format = format; |
116 | 116 |
117 if (X_already_started) return -1; | 117 if (X_already_started) return -1; |
118 | 118 if(!vo_init()) return -1; |
119 if(getenv("DISPLAY")) name = getenv("DISPLAY"); | 119 |
120 | 120 X_already_started++; |
121 mydisplay = XOpenDisplay(name); | |
122 | |
123 if (mydisplay == NULL) | |
124 { | |
125 printf("[gl] Can not open display\n"); | |
126 return -1; | |
127 } | |
128 | |
129 screen = DefaultScreen(mydisplay); | |
130 vo_screenwidth = DisplayWidth(mydisplay, myscreen); | |
131 vo_screenheight = DisplayHeight(mydisplay, myscreen); | |
132 | 121 |
133 dwidth=d_width; dheight=d_height; | 122 dwidth=d_width; dheight=d_height; |
134 #ifdef X11_FULLSCREEN | 123 #ifdef X11_FULLSCREEN |
135 if(fullscreen){ // handle flags correct | 124 if(fullscreen){ // handle flags correct |
136 d_height=(int)((float)vo_screenwidth/(float)dwidth*(float)dheight); | 125 d_height=(int)((float)vo_screenwidth/(float)dwidth*(float)dheight); |
150 hint.height = d_height; | 139 hint.height = d_height; |
151 hint.flags = PPosition | PSize; | 140 hint.flags = PPosition | PSize; |
152 | 141 |
153 /* Get some colors */ | 142 /* Get some colors */ |
154 | 143 |
155 bg = WhitePixel(mydisplay, screen); | 144 bg = WhitePixel(mDisplay, mScreen); |
156 fg = BlackPixel(mydisplay, screen); | 145 fg = BlackPixel(mDisplay, mScreen); |
157 | 146 |
158 /* Make the window */ | 147 /* Make the window */ |
159 | 148 |
160 XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs); | 149 // XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); |
161 | 150 |
162 #if 0 | 151 // XMatchVisualInfo(mDisplay, screen, depth, TrueColor, &vinfo); |
163 /* | 152 vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib ); |
164 * | |
165 * depth in X11 terminology land is the number of bits used to | |
166 * actually represent the colour. | |
167 * | |
168 * bpp in X11 land means how many bits in the frame buffer per | |
169 * pixel. | |
170 * | |
171 * ex. 15 bit color is 15 bit depth and 16 bpp. Also 24 bit | |
172 * color is 24 bit depth, but can be 24 bpp or 32 bpp. | |
173 */ | |
174 | |
175 depth = attribs.depth; | |
176 | |
177 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) | |
178 { | |
179 /* The root window may be 8bit but there might still be | |
180 * visuals with other bit depths. For example this is the | |
181 * case on Sun/Solaris machines. | |
182 */ | |
183 depth = 24; | |
184 } | |
185 //BEGIN HACK | |
186 //mywindow = XCreateSimpleWindow(mydisplay, DefaultRootWindow(mydisplay), | |
187 //hint.x, hint.y, hint.width, hint.height, 4, fg, bg); | |
188 // | |
189 #endif | |
190 | |
191 // XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo); | |
192 vinfo=glXChooseVisual( mydisplay,screen,wsGLXAttrib ); | |
193 if (vinfo == NULL) | 153 if (vinfo == NULL) |
194 { | 154 { |
195 printf("[gl] no GLX support present\n"); | 155 printf("[gl] no GLX support present\n"); |
196 return -1; | 156 return -1; |
197 } | 157 } |
198 | 158 |
199 xswa.background_pixel = 0; | 159 xswa.background_pixel = 0; |
200 xswa.border_pixel = 1; | 160 xswa.border_pixel = 1; |
201 // xswa.colormap = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), vinfo.visual, AllocNone); | 161 // xswa.colormap = XCreateColormap(mDisplay, mRootWin, vinfo.visual, AllocNone); |
202 xswa.colormap = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), vinfo->visual, AllocNone); | 162 xswa.colormap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone); |
203 xswamask = CWBackPixel | CWBorderPixel | CWColormap; | 163 xswamask = CWBackPixel | CWBorderPixel | CWColormap; |
204 // xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWCursor | CWOverrideRedirect | CWSaveUnder | CWX | CWY | CWWidth | CWHeight; | 164 // xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWCursor | CWOverrideRedirect | CWSaveUnder | CWX | CWY | CWWidth | CWHeight; |
205 | 165 |
206 mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen), | 166 mywindow = XCreateWindow(mDisplay, RootWindow(mDisplay,mScreen), |
207 hint.x, hint.y, hint.width, hint.height, 4, vinfo->depth,CopyFromParent,vinfo->visual,xswamask,&xswa); | 167 hint.x, hint.y, hint.width, hint.height, 4, vinfo->depth,CopyFromParent,vinfo->visual,xswamask,&xswa); |
208 | 168 |
209 vo_x11_classhint( mydisplay,mywindow,"gl" ); | 169 vo_x11_classhint( mDisplay,mywindow,"gl" ); |
210 vo_hidecursor(mydisplay,mywindow); | 170 vo_hidecursor(mDisplay,mywindow); |
211 | 171 |
212 wsGLXContext=glXCreateContext( mydisplay,vinfo,NULL,True ); | 172 wsGLXContext=glXCreateContext( mDisplay,vinfo,NULL,True ); |
213 // XStoreName( wsDisplay,wsMyWin,wsSysName ); | 173 // XStoreName( wsDisplay,wsMyWin,wsSysName ); |
214 | 174 |
215 // printf("GLXcontext ok\n"); | 175 // printf("GLXcontext ok\n"); |
216 | 176 |
217 if ( fullscreen ) vo_x11_decoration( mydisplay,mywindow,0 ); | 177 if ( fullscreen ) vo_x11_decoration( mDisplay,mywindow,0 ); |
218 | 178 |
219 XSelectInput(mydisplay, mywindow, StructureNotifyMask); | 179 XSelectInput(mDisplay, mywindow, StructureNotifyMask); |
220 | 180 |
221 /* Tell other applications about this window */ | 181 /* Tell other applications about this window */ |
222 | 182 |
223 XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint); | 183 XSetStandardProperties(mDisplay, mywindow, hello, hello, None, NULL, 0, &hint); |
224 | 184 |
225 /* Map window. */ | 185 /* Map window. */ |
226 | 186 |
227 XMapWindow(mydisplay, mywindow); | 187 XMapWindow(mDisplay, mywindow); |
228 | 188 |
229 /* Wait for map. */ | 189 /* Wait for map. */ |
230 do | 190 do |
231 { | 191 { |
232 XNextEvent(mydisplay, &xev); | 192 XNextEvent(mDisplay, &xev); |
233 } | 193 } |
234 while (xev.type != MapNotify || xev.xmap.event != mywindow); | 194 while (xev.type != MapNotify || xev.xmap.event != mywindow); |
235 | 195 |
236 XSelectInput(mydisplay, mywindow, NoEventMask); | 196 XSelectInput(mDisplay, mywindow, NoEventMask); |
237 | 197 |
238 glXMakeCurrent( mydisplay,mywindow,wsGLXContext ); | 198 glXMakeCurrent( mDisplay,mywindow,wsGLXContext ); |
239 | 199 |
240 XFlush(mydisplay); | 200 XFlush(mDisplay); |
241 XSync(mydisplay, False); | 201 XSync(mDisplay, False); |
242 | 202 |
243 // mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv); | 203 // mygc = XCreateGC(mDisplay, mywindow, 0L, &xgcv); |
244 | 204 |
245 // myximage = XGetImage(mydisplay, mywindow, 0, 0, | 205 // myximage = XGetImage(mDisplay, mywindow, 0, 0, |
246 // width, image_height, AllPlanes, ZPixmap); | 206 // width, image_height, AllPlanes, ZPixmap); |
247 // ImageData = myximage->data; | 207 // ImageData = myximage->data; |
248 // bpp = myximage->bits_per_pixel; | 208 // bpp = myximage->bits_per_pixel; |
249 | 209 |
250 //XSelectInput(mydisplay, mywindow, StructureNotifyMask); // !!!! | 210 //XSelectInput(mDisplay, mywindow, StructureNotifyMask); // !!!! |
251 XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask ); | 211 XSelectInput(mDisplay, mywindow, StructureNotifyMask | KeyPressMask ); |
252 | 212 |
253 // printf("Window setup ok\n"); | 213 // printf("Window setup ok\n"); |
254 | 214 |
255 #if 0 | 215 #if 0 |
256 // If we have blue in the lowest bit then obviously RGB | 216 // If we have blue in the lowest bit then obviously RGB |
321 glClearColor( 1.0f,0.0f,1.0f,0.0f ); | 281 glClearColor( 1.0f,0.0f,1.0f,0.0f ); |
322 glClear( GL_COLOR_BUFFER_BIT ); | 282 glClear( GL_COLOR_BUFFER_BIT ); |
323 | 283 |
324 // printf("OpenGL setup OK!\n"); | 284 // printf("OpenGL setup OK!\n"); |
325 | 285 |
326 X_already_started++; | 286 saver_off(mDisplay); // turning off screen saver |
287 | |
327 return 0; | 288 return 0; |
328 } | 289 } |
329 | 290 |
330 static const vo_info_t* | 291 static const vo_info_t* |
331 get_info(void) | 292 get_info(void) |
335 | 296 |
336 static void | 297 static void |
337 Terminate_Display_Process(void) | 298 Terminate_Display_Process(void) |
338 { | 299 { |
339 getchar(); /* wait for enter to remove window */ | 300 getchar(); /* wait for enter to remove window */ |
340 XDestroyWindow(mydisplay, mywindow); | 301 XDestroyWindow(mDisplay, mywindow); |
341 XCloseDisplay(mydisplay); | 302 XCloseDisplay(mDisplay); |
342 X_already_started = 0; | 303 X_already_started = 0; |
343 } | 304 } |
344 | 305 |
345 | 306 |
346 static void check_events(void) | 307 static void check_events(void) |
347 { | 308 { |
348 int e=vo_x11_check_events(mydisplay); | 309 int e=vo_x11_check_events(mDisplay); |
349 if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight); | 310 if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight); |
350 } | 311 } |
351 | 312 |
352 static void draw_osd(void) | 313 static void draw_osd(void) |
353 { | 314 { |
368 glTexCoord2f(1,0);glVertex2i(texture_width,0); | 329 glTexCoord2f(1,0);glVertex2i(texture_width,0); |
369 glEnd(); | 330 glEnd(); |
370 | 331 |
371 // glFlush(); | 332 // glFlush(); |
372 glFinish(); | 333 glFinish(); |
373 glXSwapBuffers( mydisplay,mywindow ); | 334 glXSwapBuffers( mDisplay,mywindow ); |
374 | 335 |
375 } | 336 } |
376 | 337 |
377 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num) | 338 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num) |
378 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | 339 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) |
512 | 473 |
513 | 474 |
514 static void | 475 static void |
515 uninit(void) | 476 uninit(void) |
516 { | 477 { |
517 } | 478 saver_on(mDisplay); // screen saver back on |
479 XDestroyWindow( mDisplay,mywindow ); | |
480 } |