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