Mercurial > mplayer.hg
annotate libvo/vo_gl.c @ 7862:013c255225d8
mpdemux.c|h moved to libinput, mpdemux_check_interrupt() -> mp_input_check_interrupt()
author | arpi |
---|---|
date | Wed, 23 Oct 2002 14:46:20 +0000 |
parents | ed7b05575aab |
children | 48c71b6c7389 |
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 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <math.h> | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
12 #include <errno.h> |
1 | 13 |
14 #include "config.h" | |
15 #include "video_out.h" | |
16 #include "video_out_internal.h" | |
17 | |
18 | |
19 LIBVO_EXTERN(gl) | |
20 | |
21 #include <X11/Xlib.h> | |
22 #include <X11/Xutil.h> | |
23 //#include <X11/keysym.h> | |
24 #include <GL/glx.h> | |
25 #include <errno.h> | |
2732 | 26 #include "../postproc/rgb2rgb.h" |
1 | 27 |
28 #include <GL/gl.h> | |
29 | |
31 | 30 #include "x11_common.h" |
2057 | 31 #include "aspect.h" |
31 | 32 |
1 | 33 static vo_info_t vo_info = |
34 { | |
35 "X11 (OpenGL)", | |
36 "gl", | |
37 "Arpad Gereoffy <arpi@esp-team.scene.hu>", | |
38 "" | |
39 }; | |
40 | |
41 /* local data */ | |
42 static unsigned char *ImageData=NULL; | |
43 | |
44 static GLXContext wsGLXContext; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
45 static int wsGLXAttrib[] = { GLX_RGBA, |
1 | 46 GLX_RED_SIZE,1, |
47 GLX_GREEN_SIZE,1, | |
48 GLX_BLUE_SIZE,1, | |
49 GLX_DOUBLEBUFFER, | |
50 None }; | |
51 | |
52 | |
53 static uint32_t image_width; | |
54 static uint32_t image_height; | |
55 static uint32_t image_format; | |
56 static uint32_t image_bpp; | |
57 static uint32_t image_bytes; | |
58 | |
59 static uint32_t texture_width; | |
60 static uint32_t texture_height; | |
61 | |
612 | 62 static void resize(int x,int y){ |
1290 | 63 printf("[gl] Resize: %dx%d\n",x,y); |
1 | 64 glViewport( 0, 0, x, y ); |
65 | |
66 glMatrixMode(GL_PROJECTION); | |
67 glLoadIdentity(); | |
68 glOrtho(0, image_width, image_height, 0, -1,1); | |
69 | |
70 glMatrixMode(GL_MODELVIEW); | |
71 glLoadIdentity(); | |
72 } | |
73 | |
74 /* connect to server, create and map window, | |
75 * allocate colors and (shared) memory | |
76 */ | |
77 static uint32_t | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
7111
diff
changeset
|
78 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
1 | 79 { |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
80 // int screen; |
1 | 81 unsigned int fg, bg; |
82 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
|
83 // char *name = ":0.0"; |
1 | 84 XSizeHints hint; |
85 XVisualInfo *vinfo; | |
86 XEvent xev; | |
87 | |
1109 | 88 // XGCValues xgcv; |
1 | 89 XSetWindowAttributes xswa; |
90 unsigned long xswamask; | |
91 | |
92 image_height = height; | |
93 image_width = width; | |
94 image_format = format; | |
95 | |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
96 aspect_save_orig(width,height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
97 aspect_save_prescale(d_width,d_height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
98 aspect_save_screenres(vo_screenwidth,vo_screenheight); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
99 |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
100 aspect(&d_width,&d_height,A_NOZOOM); |
2040 | 101 #ifdef X11_FULLSCREEN |
6095 | 102 // if( flags&0x01 ){ // (-fs) |
103 // aspect(&d_width,&d_height,A_ZOOM); | |
104 // } | |
2040 | 105 #endif |
1 | 106 hint.x = 0; |
107 hint.y = 0; | |
108 hint.width = d_width; | |
109 hint.height = d_height; | |
110 hint.flags = PPosition | PSize; | |
111 | |
112 /* Get some colors */ | |
113 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
114 bg = WhitePixel(mDisplay, mScreen); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
115 fg = BlackPixel(mDisplay, mScreen); |
1 | 116 |
117 /* Make the window */ | |
118 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
119 vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib ); |
1290 | 120 if (vinfo == NULL) |
121 { | |
122 printf("[gl] no GLX support present\n"); | |
123 return -1; | |
124 } | |
1 | 125 |
126 xswa.background_pixel = 0; | |
127 xswa.border_pixel = 1; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
128 xswa.colormap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone); |
1 | 129 xswamask = CWBackPixel | CWBorderPixel | CWColormap; |
1137
4c7b219e126c
patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents:
1109
diff
changeset
|
130 |
7777 | 131 if ( vo_window == None ) |
132 { | |
133 vo_window = XCreateWindow(mDisplay, mRootWin, | |
134 hint.x, hint.y, hint.width, hint.height, 4, vinfo->depth,CopyFromParent,vinfo->visual,xswamask,&xswa); | |
1 | 135 |
7777 | 136 vo_x11_classhint( mDisplay,vo_window,"gl" ); |
137 vo_hidecursor(mDisplay,vo_window); | |
1 | 138 |
7777 | 139 // if ( flags&0x01 ) vo_x11_decoration( mDisplay,vo_window,0 ); |
140 XSelectInput(mDisplay, vo_window, StructureNotifyMask); | |
141 /* Tell other applications about this window */ | |
142 XSetStandardProperties(mDisplay, vo_window, hello, hello, None, NULL, 0, &hint); | |
143 /* Map window. */ | |
144 XMapWindow(mDisplay, vo_window); | |
145 if ( flags&1 ) vo_x11_fullscreen(); | |
4017 | 146 #ifdef HAVE_XINERAMA |
7777 | 147 vo_x11_xinerama_move(mDisplay,vo_window); |
4017 | 148 #endif |
1 | 149 |
7777 | 150 /* Wait for map. */ |
151 do | |
152 { | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
153 XNextEvent(mDisplay, &xev); |
7777 | 154 } |
155 while (xev.type != MapNotify || xev.xmap.event != vo_window); | |
1 | 156 |
7777 | 157 XSelectInput(mDisplay, vo_window, NoEventMask); |
158 } | |
1 | 159 |
7777 | 160 if ( vo_config_count ) glXDestroyContext( mDisplay,wsGLXContext ); |
161 wsGLXContext=glXCreateContext( mDisplay,vinfo,NULL,True ); | |
162 glXMakeCurrent( mDisplay,vo_window,wsGLXContext ); | |
1 | 163 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
164 XFlush(mDisplay); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
165 XSync(mDisplay, False); |
1 | 166 |
6953
ce67cc1f0beb
ignore BadAccess error at XSelectInput() (grabbing mouse etc) with warning
arpi
parents:
6212
diff
changeset
|
167 vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask |
4658 | 168 | ButtonPressMask | ButtonReleaseMask |
169 ); | |
1 | 170 |
171 #if 0 | |
172 // If we have blue in the lowest bit then obviously RGB | |
173 mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_RGB : MODE_BGR; | |
174 #ifdef WORDS_BIGENDIAN | |
175 if (myximage->byte_order != MSBFirst) | |
176 #else | |
177 if (myximage->byte_order != LSBFirst) | |
178 #endif | |
179 { | |
1302 | 180 printf("[gl] no support for non-native XImage byte order!\n"); |
1 | 181 return -1; |
182 } | |
183 | |
184 printf("DEPTH=%d BPP=%d\n",depth,bpp); | |
185 #endif | |
186 | |
187 /* | |
188 * If depth is 24 then it may either be a 3 or 4 byte per pixel | |
189 * format. We can't use bpp because then we would lose the | |
190 * distinction between 15/16bit depth (2 byte formate assumed). | |
191 * | |
192 * FIXME - change yuv2rgb_init to take both depth and bpp | |
193 * parameters | |
194 */ | |
195 | |
196 texture_width=32; | |
197 while(texture_width<image_width) texture_width*=2; | |
198 while(texture_width<image_height) texture_width*=2; | |
199 texture_height=texture_width; | |
200 | |
201 if(format==IMGFMT_YV12){ | |
202 yuv2rgb_init(8*BYTES_PP, MODE_BGR); | |
1290 | 203 printf("[gl] YUV init OK!\n"); |
1 | 204 image_bpp=8*BYTES_PP; |
205 image_bytes=BYTES_PP; | |
206 } else { | |
207 image_bpp=format&0xFF; | |
208 image_bytes=(image_bpp+7)/8; | |
209 } | |
210 | |
7777 | 211 if ( ImageData ) free( ImageData ); |
1 | 212 ImageData=malloc(texture_width*texture_height*image_bytes); |
213 memset(ImageData,128,texture_width*texture_height*image_bytes); | |
214 | |
215 glDisable(GL_BLEND); | |
216 glDisable(GL_DEPTH_TEST); | |
217 glDepthMask(GL_FALSE); | |
218 glDisable(GL_CULL_FACE); | |
219 | |
220 glEnable(GL_TEXTURE_2D); | |
221 | |
1290 | 222 printf("[gl] Creating %dx%d texture...\n",texture_width,texture_height); |
1 | 223 |
224 #if 1 | |
225 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
226 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
227 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
228 #ifdef TEXTUREFORMAT_32BPP | |
229 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0, | |
230 #else | |
231 glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0, | |
232 #endif | |
233 (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData); | |
234 #endif | |
235 | |
236 resize(d_width,d_height); | |
237 | |
238 glClearColor( 1.0f,0.0f,1.0f,0.0f ); | |
239 glClear( GL_COLOR_BUFFER_BIT ); | |
240 | |
241 // printf("OpenGL setup OK!\n"); | |
242 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
243 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
|
244 |
1 | 245 return 0; |
246 } | |
247 | |
248 static const vo_info_t* | |
249 get_info(void) | |
250 { | |
251 return &vo_info; | |
252 } | |
253 | |
31 | 254 static void check_events(void) |
1 | 255 { |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
256 int e=vo_x11_check_events(mDisplay); |
31 | 257 if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight); |
258 } | |
1 | 259 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
260 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
261 { |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
262 } |
31 | 263 |
264 static void | |
265 flip_page(void) | |
266 { | |
267 | |
1 | 268 // glEnable(GL_TEXTURE_2D); |
269 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
270 | |
271 glColor3f(1,1,1); | |
272 glBegin(GL_QUADS); | |
273 glTexCoord2f(0,0);glVertex2i(0,0); | |
274 glTexCoord2f(0,1);glVertex2i(0,texture_height); | |
275 glTexCoord2f(1,1);glVertex2i(texture_width,texture_height); | |
276 glTexCoord2f(1,0);glVertex2i(texture_width,0); | |
277 glEnd(); | |
278 | |
279 // glFlush(); | |
280 glFinish(); | |
6095 | 281 glXSwapBuffers( mDisplay,vo_window ); |
282 | |
1 | 283 } |
284 | |
285 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num) | |
286 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
287 { | |
288 int i; | |
289 int dstride=w*BYTES_PP; | |
290 | |
291 // dstride=(dstride+15)&(~15); | |
292 | |
293 yuv2rgb(ImageData, src[0], src[1], src[2], | |
294 w,h, dstride, stride[0],stride[1]); | |
295 | |
296 for(i=0;i<h;i++){ | |
297 glTexSubImage2D( GL_TEXTURE_2D, // target | |
298 0, // level | |
299 x, // x offset | |
300 y+i, // y offset | |
301 w, // width | |
302 1, // height | |
303 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format | |
304 GL_UNSIGNED_BYTE, // type | |
305 ImageData+i*dstride ); // *pixels | |
306 } | |
307 | |
308 return 0; | |
309 } | |
310 | |
311 static inline uint32_t | |
312 draw_frame_x11_yv12(uint8_t *src[]) | |
313 { | |
314 int i; | |
315 // printf("Converting YUV->RGB...\n"); | |
316 yuv2rgb(ImageData, src[0], src[1], src[2], | |
317 image_width, image_height, | |
318 image_width*BYTES_PP, image_width, image_width/2 ); | |
319 | |
320 for(i=0;i<image_height;i++){ | |
321 glTexSubImage2D( GL_TEXTURE_2D, // target | |
322 0, // level | |
323 0, // x offset | |
324 i, // y offset | |
325 image_width, // width | |
326 1, // height | |
327 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format | |
328 GL_UNSIGNED_BYTE, // type | |
329 ImageData+i*BYTES_PP*image_width ); // *pixels | |
330 } | |
331 | |
332 return 0; | |
333 } | |
334 | |
335 | |
336 static inline uint32_t | |
337 draw_frame_x11_bgr(uint8_t *src[]) | |
338 { | |
339 int i; | |
340 uint8_t *s=src[0]; | |
341 uint8_t *de=&ImageData[3*image_width]; | |
342 | |
343 for(i=0;i<image_height;i++){ | |
344 uint8_t *d=ImageData; | |
345 while(d<de){ | |
346 d[0]=s[2]; | |
347 d[1]=s[1]; | |
348 d[2]=s[0]; | |
349 s+=3;d+=3; | |
350 } | |
351 glTexSubImage2D( GL_TEXTURE_2D, // target | |
352 0, // level | |
353 0, // x offset | |
354 // image_height-1-i, // y offset | |
355 i, // y offset | |
356 image_width, // width | |
357 1, // height | |
358 (image_bytes==4)?GL_RGBA:GL_RGB, // format | |
359 GL_UNSIGNED_BYTE, // type | |
360 ImageData); // *pixels | |
361 } | |
362 | |
363 return 0; | |
364 } | |
365 | |
366 static inline uint32_t | |
367 draw_frame_x11_rgb(uint8_t *src[]) | |
368 { | |
369 int i; | |
370 uint8_t *ImageData=src[0]; | |
371 | |
372 for(i=0;i<image_height;i++){ | |
373 glTexSubImage2D( GL_TEXTURE_2D, // target | |
374 0, // level | |
375 0, // x offset | |
376 // image_height-1-i, // y offset | |
377 i, // y offset | |
378 image_width, // width | |
379 1, // height | |
380 (image_bytes==4)?GL_RGBA:GL_RGB, // format | |
381 GL_UNSIGNED_BYTE, // type | |
382 ImageData+i*image_bytes*image_width ); // *pixels | |
383 } | |
384 | |
385 return 0; | |
386 } | |
387 | |
388 | |
389 static uint32_t | |
390 draw_frame(uint8_t *src[]) | |
391 { | |
392 if(image_format==IMGFMT_YV12) | |
393 return draw_frame_x11_yv12(src); | |
394 else | |
395 if((image_format&IMGFMT_RGB_MASK)==IMGFMT_RGB) | |
396 return draw_frame_x11_rgb(src); | |
397 else | |
398 return draw_frame_x11_bgr(src); | |
399 } | |
400 | |
401 static uint32_t | |
402 query_format(uint32_t format) | |
403 { | |
404 switch(format){ | |
405 case IMGFMT_YV12: | |
6212 | 406 return VFCAP_CSP_SUPPORTED; |
1 | 407 case IMGFMT_RGB|24: |
408 case IMGFMT_BGR|24: | |
6212 | 409 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; |
1 | 410 } |
411 return 0; | |
412 } | |
413 | |
414 | |
415 static void | |
416 uninit(void) | |
417 { | |
6095 | 418 if ( !vo_config_count ) return; |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
419 saver_on(mDisplay); // screen saver back on |
6095 | 420 vo_x11_uninit(); |
1 | 421 } |
4352 | 422 |
423 static uint32_t preinit(const char *arg) | |
424 { | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
425 if(arg) |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
426 { |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
427 printf("[gl] Unknown subdevice: %s\n",arg); |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
428 return ENOSYS; |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
429 } |
7777 | 430 |
431 if(!vo_init()) return 1; | |
432 | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
433 return 0; |
4352 | 434 } |
435 | |
4596 | 436 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 437 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
438 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
439 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
440 return query_format(*((uint32_t*)data)); |
6095 | 441 case VOCTRL_FULLSCREEN: |
442 vo_x11_fullscreen(); | |
443 return VO_TRUE; | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
444 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
445 return VO_NOTIMPL; |
4352 | 446 } |