Mercurial > mplayer.hg
annotate libvo/vo_gl.c @ 2060:0048c2a8cc95
alsa9 driver
author | gabucino |
---|---|
date | Wed, 03 Oct 2001 18:26:06 +0000 |
parents | 378aed6b232d |
children | 48f0ac1e9d13 |
rev | line source |
---|---|
1 | 1 #define DISP |
2 | |
3 // this can be 3 or 4 (regarding 24bpp and 32bpp) | |
4 #define BYTES_PP 3 | |
5 | |
6 #define TEXTUREFORMAT_32BPP | |
7 | |
8 /* | |
9 * video_out_gl.c, X11/OpenGL interface | |
10 * based on video_out_x11 by Aaron Holtzman, | |
11 * and WS opengl window manager by Pontscho/Fresh! | |
12 */ | |
13 | |
14 #include <stdio.h> | |
15 #include <stdlib.h> | |
16 #include <string.h> | |
17 #include <math.h> | |
18 | |
19 #include "config.h" | |
20 #include "video_out.h" | |
21 #include "video_out_internal.h" | |
22 | |
23 | |
24 LIBVO_EXTERN(gl) | |
25 | |
26 #include <X11/Xlib.h> | |
27 #include <X11/Xutil.h> | |
28 //#include <X11/keysym.h> | |
29 #include <GL/glx.h> | |
30 #include <errno.h> | |
31 #include "yuv2rgb.h" | |
32 | |
33 #include <GL/gl.h> | |
34 | |
31 | 35 #include "x11_common.h" |
2057 | 36 #include "aspect.h" |
31 | 37 |
1 | 38 static vo_info_t vo_info = |
39 { | |
40 "X11 (OpenGL)", | |
41 "gl", | |
42 "Arpad Gereoffy <arpi@esp-team.scene.hu>", | |
43 "" | |
44 }; | |
45 | |
46 /* private prototypes */ | |
1109 | 47 // static void Display_Image (unsigned char *ImageData); |
1 | 48 |
49 /* local data */ | |
50 static unsigned char *ImageData=NULL; | |
51 | |
52 /* X11 related variables */ | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
53 //static Display *mydisplay; |
1 | 54 static Window mywindow; |
55 //static GC mygc; | |
56 //static XImage *myximage; | |
57 //static int depth,mode; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
58 //static XWindowAttributes attribs; |
1 | 59 static int X_already_started = 0; |
60 | |
1109 | 61 //static int texture_id=1; |
1 | 62 |
63 static GLXContext wsGLXContext; | |
64 //XVisualInfo * wsVisualInfo; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
65 static int wsGLXAttrib[] = { GLX_RGBA, |
1 | 66 GLX_RED_SIZE,1, |
67 GLX_GREEN_SIZE,1, | |
68 GLX_BLUE_SIZE,1, | |
69 // GLX_DEPTH_SIZE,16, | |
70 GLX_DOUBLEBUFFER, | |
71 None }; | |
72 | |
73 | |
74 static uint32_t image_width; | |
75 static uint32_t image_height; | |
76 static uint32_t image_format; | |
77 static uint32_t image_bpp; | |
78 static uint32_t image_bytes; | |
79 | |
80 static uint32_t texture_width; | |
81 static uint32_t texture_height; | |
82 | |
612 | 83 static void resize(int x,int y){ |
1290 | 84 printf("[gl] Resize: %dx%d\n",x,y); |
1 | 85 glViewport( 0, 0, x, y ); |
86 | |
87 glMatrixMode(GL_PROJECTION); | |
88 glLoadIdentity(); | |
89 glOrtho(0, image_width, image_height, 0, -1,1); | |
90 | |
91 glMatrixMode(GL_MODELVIEW); | |
92 glLoadIdentity(); | |
93 } | |
94 | |
95 /* connect to server, create and map window, | |
96 * allocate colors and (shared) memory | |
97 */ | |
98 static uint32_t | |
2057 | 99 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
1 | 100 { |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
101 // int screen; |
2040 | 102 int dwidth,dheight; |
1 | 103 unsigned int fg, bg; |
104 char *hello = (title == NULL) ? "OpenGL rulez" : title; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
105 // char *name = ":0.0"; |
1 | 106 XSizeHints hint; |
107 XVisualInfo *vinfo; | |
108 XEvent xev; | |
109 | |
1109 | 110 // XGCValues xgcv; |
1 | 111 XSetWindowAttributes xswa; |
112 unsigned long xswamask; | |
113 | |
114 image_height = height; | |
115 image_width = width; | |
116 image_format = format; | |
117 | |
118 if (X_already_started) return -1; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
119 if(!vo_init()) return -1; |
1 | 120 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
121 X_already_started++; |
1 | 122 |
2040 | 123 dwidth=d_width; dheight=d_height; |
124 #ifdef X11_FULLSCREEN | |
2057 | 125 if( flags&0x01 ){ // (-fs) |
126 aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight); | |
2040 | 127 dwidth=d_width; dheight=d_height; |
128 } | |
129 #endif | |
1 | 130 hint.x = 0; |
131 hint.y = 0; | |
132 hint.width = d_width; | |
133 hint.height = d_height; | |
134 hint.flags = PPosition | PSize; | |
135 | |
136 /* Get some colors */ | |
137 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
138 bg = WhitePixel(mDisplay, mScreen); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
139 fg = BlackPixel(mDisplay, mScreen); |
1 | 140 |
141 /* Make the window */ | |
142 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
143 // XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); |
1 | 144 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
145 // XMatchVisualInfo(mDisplay, screen, depth, TrueColor, &vinfo); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
146 vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib ); |
1290 | 147 if (vinfo == NULL) |
148 { | |
149 printf("[gl] no GLX support present\n"); | |
150 return -1; | |
151 } | |
1 | 152 |
153 xswa.background_pixel = 0; | |
154 xswa.border_pixel = 1; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
155 // xswa.colormap = XCreateColormap(mDisplay, mRootWin, vinfo.visual, AllocNone); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
156 xswa.colormap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone); |
1 | 157 xswamask = CWBackPixel | CWBorderPixel | CWColormap; |
158 // xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWCursor | CWOverrideRedirect | CWSaveUnder | CWX | CWY | CWWidth | CWHeight; | |
159 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
160 mywindow = XCreateWindow(mDisplay, RootWindow(mDisplay,mScreen), |
1 | 161 hint.x, hint.y, hint.width, hint.height, 4, vinfo->depth,CopyFromParent,vinfo->visual,xswamask,&xswa); |
1137
4c7b219e126c
patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents:
1109
diff
changeset
|
162 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
163 vo_x11_classhint( mDisplay,mywindow,"gl" ); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
164 vo_hidecursor(mDisplay,mywindow); |
1 | 165 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
166 wsGLXContext=glXCreateContext( mDisplay,vinfo,NULL,True ); |
1 | 167 // XStoreName( wsDisplay,wsMyWin,wsSysName ); |
168 | |
169 // printf("GLXcontext ok\n"); | |
170 | |
2057 | 171 if ( flags&0x01 ) vo_x11_decoration( mDisplay,mywindow,0 ); |
1 | 172 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
173 XSelectInput(mDisplay, mywindow, StructureNotifyMask); |
1 | 174 |
175 /* Tell other applications about this window */ | |
176 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
177 XSetStandardProperties(mDisplay, mywindow, hello, hello, None, NULL, 0, &hint); |
1 | 178 |
179 /* Map window. */ | |
180 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
181 XMapWindow(mDisplay, mywindow); |
1 | 182 |
183 /* Wait for map. */ | |
184 do | |
185 { | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
186 XNextEvent(mDisplay, &xev); |
1 | 187 } |
188 while (xev.type != MapNotify || xev.xmap.event != mywindow); | |
189 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
190 XSelectInput(mDisplay, mywindow, NoEventMask); |
1 | 191 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
192 glXMakeCurrent( mDisplay,mywindow,wsGLXContext ); |
1 | 193 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
194 XFlush(mDisplay); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
195 XSync(mDisplay, False); |
1 | 196 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
197 // mygc = XCreateGC(mDisplay, mywindow, 0L, &xgcv); |
1 | 198 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
199 // myximage = XGetImage(mDisplay, mywindow, 0, 0, |
1 | 200 // width, image_height, AllPlanes, ZPixmap); |
201 // ImageData = myximage->data; | |
202 // bpp = myximage->bits_per_pixel; | |
203 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
204 //XSelectInput(mDisplay, mywindow, StructureNotifyMask); // !!!! |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
205 XSelectInput(mDisplay, mywindow, StructureNotifyMask | KeyPressMask ); |
1 | 206 |
207 // printf("Window setup ok\n"); | |
208 | |
209 #if 0 | |
210 // If we have blue in the lowest bit then obviously RGB | |
211 mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_RGB : MODE_BGR; | |
212 #ifdef WORDS_BIGENDIAN | |
213 if (myximage->byte_order != MSBFirst) | |
214 #else | |
215 if (myximage->byte_order != LSBFirst) | |
216 #endif | |
217 { | |
1302 | 218 printf("[gl] no support for non-native XImage byte order!\n"); |
1 | 219 return -1; |
220 } | |
221 | |
222 printf("DEPTH=%d BPP=%d\n",depth,bpp); | |
223 #endif | |
224 | |
225 /* | |
226 * If depth is 24 then it may either be a 3 or 4 byte per pixel | |
227 * format. We can't use bpp because then we would lose the | |
228 * distinction between 15/16bit depth (2 byte formate assumed). | |
229 * | |
230 * FIXME - change yuv2rgb_init to take both depth and bpp | |
231 * parameters | |
232 */ | |
233 | |
234 texture_width=32; | |
235 while(texture_width<image_width) texture_width*=2; | |
236 while(texture_width<image_height) texture_width*=2; | |
237 texture_height=texture_width; | |
238 | |
239 if(format==IMGFMT_YV12){ | |
240 yuv2rgb_init(8*BYTES_PP, MODE_BGR); | |
1290 | 241 printf("[gl] YUV init OK!\n"); |
1 | 242 image_bpp=8*BYTES_PP; |
243 image_bytes=BYTES_PP; | |
244 } else { | |
245 image_bpp=format&0xFF; | |
246 image_bytes=(image_bpp+7)/8; | |
247 } | |
248 | |
249 ImageData=malloc(texture_width*texture_height*image_bytes); | |
250 memset(ImageData,128,texture_width*texture_height*image_bytes); | |
251 | |
252 glDisable(GL_BLEND); | |
253 glDisable(GL_DEPTH_TEST); | |
254 glDepthMask(GL_FALSE); | |
255 glDisable(GL_CULL_FACE); | |
256 | |
257 glEnable(GL_TEXTURE_2D); | |
258 | |
1290 | 259 printf("[gl] Creating %dx%d texture...\n",texture_width,texture_height); |
1 | 260 |
261 #if 1 | |
262 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
263 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
264 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
265 #ifdef TEXTUREFORMAT_32BPP | |
266 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0, | |
267 #else | |
268 glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0, | |
269 #endif | |
270 (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData); | |
271 #endif | |
272 | |
273 resize(d_width,d_height); | |
274 | |
275 glClearColor( 1.0f,0.0f,1.0f,0.0f ); | |
276 glClear( GL_COLOR_BUFFER_BIT ); | |
277 | |
278 // printf("OpenGL setup OK!\n"); | |
279 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
280 saver_off(mDisplay); // turning off screen saver |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
281 |
1 | 282 return 0; |
283 } | |
284 | |
285 static const vo_info_t* | |
286 get_info(void) | |
287 { | |
288 return &vo_info; | |
289 } | |
290 | |
291 static void | |
292 Terminate_Display_Process(void) | |
293 { | |
294 getchar(); /* wait for enter to remove window */ | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
295 XDestroyWindow(mDisplay, mywindow); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
296 XCloseDisplay(mDisplay); |
1 | 297 X_already_started = 0; |
298 } | |
299 | |
31 | 300 |
301 static void check_events(void) | |
1 | 302 { |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
303 int e=vo_x11_check_events(mDisplay); |
31 | 304 if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight); |
305 } | |
1 | 306 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
307 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
308 { |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
309 } |
31 | 310 |
311 static void | |
312 flip_page(void) | |
313 { | |
314 | |
1 | 315 // glEnable(GL_TEXTURE_2D); |
316 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
317 | |
318 glColor3f(1,1,1); | |
319 glBegin(GL_QUADS); | |
320 glTexCoord2f(0,0);glVertex2i(0,0); | |
321 glTexCoord2f(0,1);glVertex2i(0,texture_height); | |
322 glTexCoord2f(1,1);glVertex2i(texture_width,texture_height); | |
323 glTexCoord2f(1,0);glVertex2i(texture_width,0); | |
324 glEnd(); | |
325 | |
326 // glFlush(); | |
327 glFinish(); | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
328 glXSwapBuffers( mDisplay,mywindow ); |
1 | 329 |
330 } | |
331 | |
332 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num) | |
333 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
334 { | |
335 int i; | |
336 int dstride=w*BYTES_PP; | |
337 | |
338 // dstride=(dstride+15)&(~15); | |
339 | |
340 yuv2rgb(ImageData, src[0], src[1], src[2], | |
341 w,h, dstride, stride[0],stride[1]); | |
342 | |
343 // emms (); | |
344 | |
345 for(i=0;i<h;i++){ | |
346 glTexSubImage2D( GL_TEXTURE_2D, // target | |
347 0, // level | |
348 x, // x offset | |
349 y+i, // y offset | |
350 w, // width | |
351 1, // height | |
352 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format | |
353 GL_UNSIGNED_BYTE, // type | |
354 ImageData+i*dstride ); // *pixels | |
355 } | |
356 | |
357 return 0; | |
358 } | |
359 | |
360 static inline uint32_t | |
361 draw_frame_x11_yv12(uint8_t *src[]) | |
362 { | |
363 int i; | |
364 // printf("Converting YUV->RGB...\n"); | |
365 yuv2rgb(ImageData, src[0], src[1], src[2], | |
366 image_width, image_height, | |
367 image_width*BYTES_PP, image_width, image_width/2 ); | |
368 // printf("Ready!\n"); | |
369 | |
370 // emms (); | |
371 | |
372 for(i=0;i<image_height;i++){ | |
373 glTexSubImage2D( GL_TEXTURE_2D, // target | |
374 0, // level | |
375 0, // x offset | |
376 i, // y offset | |
377 image_width, // width | |
378 1, // height | |
379 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format | |
380 GL_UNSIGNED_BYTE, // type | |
381 ImageData+i*BYTES_PP*image_width ); // *pixels | |
382 } | |
383 | |
384 // Display_Image(ImageData); | |
385 return 0; | |
386 } | |
387 | |
388 | |
389 static inline uint32_t | |
390 draw_frame_x11_bgr(uint8_t *src[]) | |
391 { | |
392 int i; | |
393 uint8_t *s=src[0]; | |
394 uint8_t *de=&ImageData[3*image_width]; | |
395 | |
396 for(i=0;i<image_height;i++){ | |
397 uint8_t *d=ImageData; | |
398 while(d<de){ | |
399 d[0]=s[2]; | |
400 d[1]=s[1]; | |
401 d[2]=s[0]; | |
402 s+=3;d+=3; | |
403 } | |
404 glTexSubImage2D( GL_TEXTURE_2D, // target | |
405 0, // level | |
406 0, // x offset | |
407 // image_height-1-i, // y offset | |
408 i, // y offset | |
409 image_width, // width | |
410 1, // height | |
411 (image_bytes==4)?GL_RGBA:GL_RGB, // format | |
412 GL_UNSIGNED_BYTE, // type | |
413 ImageData); // *pixels | |
414 } | |
415 | |
416 // Display_Image(ImageData); | |
417 return 0; | |
418 } | |
419 | |
420 static inline uint32_t | |
421 draw_frame_x11_rgb(uint8_t *src[]) | |
422 { | |
423 int i; | |
424 uint8_t *ImageData=src[0]; | |
425 | |
426 for(i=0;i<image_height;i++){ | |
427 glTexSubImage2D( GL_TEXTURE_2D, // target | |
428 0, // level | |
429 0, // x offset | |
430 // image_height-1-i, // y offset | |
431 i, // y offset | |
432 image_width, // width | |
433 1, // height | |
434 (image_bytes==4)?GL_RGBA:GL_RGB, // format | |
435 GL_UNSIGNED_BYTE, // type | |
436 ImageData+i*image_bytes*image_width ); // *pixels | |
437 } | |
438 | |
439 // Display_Image(ImageData); | |
440 return 0; | |
441 } | |
442 | |
443 | |
444 static uint32_t | |
445 draw_frame(uint8_t *src[]) | |
446 { | |
447 if(image_format==IMGFMT_YV12) | |
448 return draw_frame_x11_yv12(src); | |
449 else | |
450 if((image_format&IMGFMT_RGB_MASK)==IMGFMT_RGB) | |
451 return draw_frame_x11_rgb(src); | |
452 else | |
453 return draw_frame_x11_bgr(src); | |
454 } | |
455 | |
456 static uint32_t | |
457 query_format(uint32_t format) | |
458 { | |
459 switch(format){ | |
460 case IMGFMT_YV12: | |
461 case IMGFMT_RGB|24: | |
462 case IMGFMT_BGR|24: | |
463 return 1; | |
464 } | |
465 return 0; | |
466 } | |
467 | |
468 | |
469 static void | |
470 uninit(void) | |
471 { | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
472 saver_on(mDisplay); // screen saver back on |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
473 XDestroyWindow( mDisplay,mywindow ); |
1 | 474 } |