Merge svn changes up to r30055
[mplayer/kovensky.git] / libvo / vo_gl.c
blobe3c4571b320f12a7039c388d271a8c5faf5e25a3
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <math.h>
24 #include "config.h"
25 #include "mp_msg.h"
26 #include "subopt-helper.h"
27 #include "video_out.h"
28 #include "video_out_internal.h"
29 #include "font_load.h"
30 #include "sub.h"
32 #include "gl_common.h"
33 #include "aspect.h"
34 #include "fastmemcpy.h"
35 #include "ass_mp.h"
37 static const vo_info_t info =
39 "X11 (OpenGL)",
40 "gl",
41 "Arpad Gereoffy <arpi@esp-team.scene.hu>",
45 const LIBVO_EXTERN(gl)
47 #ifdef CONFIG_X11
48 static int wsGLXAttrib[] = { GLX_RGBA,
49 GLX_RED_SIZE,1,
50 GLX_GREEN_SIZE,1,
51 GLX_BLUE_SIZE,1,
52 GLX_DOUBLEBUFFER,
53 None };
54 #endif
55 static MPGLContext glctx;
57 static int use_osd;
58 static int scaled_osd;
59 //! How many parts the OSD may consist of at most
60 #define MAX_OSD_PARTS 20
61 //! Textures for OSD
62 static GLuint osdtex[MAX_OSD_PARTS];
63 #ifndef FAST_OSD
64 //! Alpha textures for OSD
65 static GLuint osdatex[MAX_OSD_PARTS];
66 #endif
67 static GLuint *eosdtex;
68 #define LARGE_EOSD_TEX_SIZE 512
69 #define TINYTEX_SIZE 16
70 #define TINYTEX_COLS (LARGE_EOSD_TEX_SIZE/TINYTEX_SIZE)
71 #define TINYTEX_MAX (TINYTEX_COLS*TINYTEX_COLS)
72 #define SMALLTEX_SIZE 32
73 #define SMALLTEX_COLS (LARGE_EOSD_TEX_SIZE/SMALLTEX_SIZE)
74 #define SMALLTEX_MAX (SMALLTEX_COLS*SMALLTEX_COLS)
75 static GLuint largeeosdtex[2];
76 //! Display lists that draw the OSD parts
77 static GLuint osdDispList[MAX_OSD_PARTS];
78 #ifndef FAST_OSD
79 static GLuint osdaDispList[MAX_OSD_PARTS];
80 #endif
81 static GLuint eosdDispList;
82 //! How many parts the OSD currently consists of
83 static int osdtexCnt;
84 static int eosdtexCnt;
85 static int osd_color;
87 static int use_aspect;
88 static int use_ycbcr;
89 static int use_yuv;
90 static int lscale;
91 static int cscale;
92 static float filter_strength;
93 static int yuvconvtype;
94 static int use_rectangle;
95 static int err_shown;
96 static uint32_t image_width;
97 static uint32_t image_height;
98 static uint32_t image_format;
99 static int many_fmts;
100 static int ati_hack;
101 static int force_pbo;
102 static int mesa_buffer;
103 static int use_glFinish;
104 static int swap_interval;
105 static GLenum gl_target;
106 static GLint gl_texfmt;
107 static GLenum gl_format;
108 static GLenum gl_type;
109 static GLuint gl_buffer;
110 static GLuint gl_buffer_uv[2];
111 static int gl_buffersize;
112 static int gl_buffersize_uv;
113 static void *gl_bufferptr;
114 static void *gl_bufferptr_uv[2];
115 static int mesa_buffersize;
116 static void *mesa_bufferptr;
117 static GLuint fragprog;
118 static GLuint default_texs[22];
119 static char *custom_prog;
120 static char *custom_tex;
121 static int custom_tlin;
122 static int custom_trect;
124 static int int_pause;
125 static int eq_bri = 0;
126 static int eq_cont = 0;
127 static int eq_sat = 0;
128 static int eq_hue = 0;
129 static int eq_rgamma = 0;
130 static int eq_ggamma = 0;
131 static int eq_bgamma = 0;
133 static int texture_width;
134 static int texture_height;
135 static int mpi_flipped;
136 static int vo_flipped;
137 static int ass_border_x, ass_border_y;
139 static unsigned int slice_height = 1;
141 static void redraw(void);
143 static void resize(int x,int y){
144 mp_msg(MSGT_VO, MSGL_V, "[gl] Resize: %dx%d\n",x,y);
145 if (WinID >= 0) {
146 int top = 0, left = 0, w = x, h = y;
147 geometry(&top, &left, &w, &h, vo_screenwidth, vo_screenheight);
148 Viewport(top, left, w, h);
149 } else
150 Viewport( 0, 0, x, y );
152 MatrixMode(GL_PROJECTION);
153 LoadIdentity();
154 ass_border_x = ass_border_y = 0;
155 if (aspect_scaling() && use_aspect) {
156 int new_w, new_h;
157 GLdouble scale_x, scale_y;
158 aspect(&new_w, &new_h, A_WINZOOM);
159 panscan_calc_windowed();
160 new_w += vo_panscan_x;
161 new_h += vo_panscan_y;
162 scale_x = (GLdouble)new_w / (GLdouble)x;
163 scale_y = (GLdouble)new_h / (GLdouble)y;
164 Scaled(scale_x, scale_y, 1);
165 ass_border_x = (vo_dwidth - new_w) / 2;
166 ass_border_y = (vo_dheight - new_h) / 2;
168 Ortho(0, image_width, image_height, 0, -1,1);
170 MatrixMode(GL_MODELVIEW);
171 LoadIdentity();
173 if (!scaled_osd) {
174 #ifdef CONFIG_FREETYPE
175 // adjust font size to display size
176 force_load_font = 1;
177 #endif
178 vo_osd_changed(OSDTYPE_OSD);
180 Clear(GL_COLOR_BUFFER_BIT);
181 redraw();
184 static void texSize(int w, int h, int *texw, int *texh) {
185 if (use_rectangle) {
186 *texw = w; *texh = h;
187 } else {
188 *texw = 32;
189 while (*texw < w)
190 *texw *= 2;
191 *texh = 32;
192 while (*texh < h)
193 *texh *= 2;
195 if (mesa_buffer) *texw = (*texw + 63) & ~63;
196 else if (ati_hack) *texw = (*texw + 511) & ~511;
199 //! maximum size of custom fragment program
200 #define MAX_CUSTOM_PROG_SIZE (1024 * 1024)
201 static void update_yuvconv(void) {
202 float bri = eq_bri / 100.0;
203 float cont = (eq_cont + 100) / 100.0;
204 float hue = eq_hue / 100.0 * 3.1415927;
205 float sat = (eq_sat + 100) / 100.0;
206 float rgamma = exp(log(8.0) * eq_rgamma / 100.0);
207 float ggamma = exp(log(8.0) * eq_ggamma / 100.0);
208 float bgamma = exp(log(8.0) * eq_bgamma / 100.0);
209 gl_conversion_params_t params = {gl_target, yuvconvtype,
210 bri, cont, hue, sat, rgamma, ggamma, bgamma,
211 texture_width, texture_height, filter_strength};
212 glSetupYUVConversion(&params);
213 if (custom_prog) {
214 FILE *f = fopen(custom_prog, "r");
215 if (!f)
216 mp_msg(MSGT_VO, MSGL_WARN,
217 "[gl] Could not read customprog %s\n", custom_prog);
218 else {
219 char *prog = calloc(1, MAX_CUSTOM_PROG_SIZE + 1);
220 fread(prog, 1, MAX_CUSTOM_PROG_SIZE, f);
221 fclose(f);
222 loadGPUProgram(GL_FRAGMENT_PROGRAM, prog);
223 free(prog);
225 ProgramEnvParameter4f(GL_FRAGMENT_PROGRAM, 0,
226 1.0 / texture_width, 1.0 / texture_height,
227 texture_width, texture_height);
229 if (custom_tex) {
230 FILE *f = fopen(custom_tex, "r");
231 if (!f)
232 mp_msg(MSGT_VO, MSGL_WARN,
233 "[gl] Could not read customtex %s\n", custom_tex);
234 else {
235 int width, height, maxval;
236 ActiveTexture(GL_TEXTURE3);
237 if (glCreatePPMTex(custom_trect?GL_TEXTURE_RECTANGLE:GL_TEXTURE_2D, 0,
238 custom_tlin?GL_LINEAR:GL_NEAREST,
239 f, &width, &height, &maxval))
240 ProgramEnvParameter4f(GL_FRAGMENT_PROGRAM, 1,
241 1.0 / width, 1.0 / height, width, height);
242 else
243 mp_msg(MSGT_VO, MSGL_WARN,
244 "[gl] Error parsing customtex %s\n", custom_tex);
245 fclose(f);
246 ActiveTexture(GL_TEXTURE0);
252 * \brief remove all OSD textures and display-lists, thus clearing it.
254 static void clearOSD(void) {
255 int i;
256 if (!osdtexCnt)
257 return;
258 DeleteTextures(osdtexCnt, osdtex);
259 #ifndef FAST_OSD
260 DeleteTextures(osdtexCnt, osdatex);
261 for (i = 0; i < osdtexCnt; i++)
262 DeleteLists(osdaDispList[i], 1);
263 #endif
264 for (i = 0; i < osdtexCnt; i++)
265 DeleteLists(osdDispList[i], 1);
266 osdtexCnt = 0;
270 * \brief remove textures, display list and free memory used by EOSD
272 static void clearEOSD(void) {
273 if (eosdDispList)
274 DeleteLists(eosdDispList, 1);
275 eosdDispList = 0;
276 if (eosdtexCnt)
277 DeleteTextures(eosdtexCnt, eosdtex);
278 eosdtexCnt = 0;
279 free(eosdtex);
280 eosdtex = NULL;
283 static void do_render_osd(int);
285 static inline int is_tinytex(ASS_Image *i, int tinytexcur) {
286 return i->w < TINYTEX_SIZE && i->h < TINYTEX_SIZE && tinytexcur < TINYTEX_MAX;
289 static inline int is_smalltex(ASS_Image *i, int smalltexcur) {
290 return i->w < SMALLTEX_SIZE && i->h < SMALLTEX_SIZE && smalltexcur < SMALLTEX_MAX;
293 static inline void tinytex_pos(int tinytexcur, int *x, int *y) {
294 *x = (tinytexcur % TINYTEX_COLS) * TINYTEX_SIZE;
295 *y = (tinytexcur / TINYTEX_COLS) * TINYTEX_SIZE;
298 static inline void smalltex_pos(int smalltexcur, int *x, int *y) {
299 *x = (smalltexcur % SMALLTEX_COLS) * SMALLTEX_SIZE;
300 *y = (smalltexcur / SMALLTEX_COLS) * SMALLTEX_SIZE;
304 * \brief construct display list from ass image list
305 * \param img image list to create OSD from.
306 * A value of NULL has the same effect as clearEOSD()
308 static void genEOSD(mp_eosd_images_t *imgs) {
309 int sx, sy;
310 int tinytexcur = 0;
311 int smalltexcur = 0;
312 GLuint *curtex;
313 GLint scale_type = scaled_osd ? GL_LINEAR : GL_NEAREST;
314 ASS_Image *img = imgs->imgs;
315 ASS_Image *i;
317 if (imgs->changed == 0) // there are elements, but they are unchanged
318 return;
319 if (img && imgs->changed == 1) // there are elements, but they just moved
320 goto skip_upload;
322 clearEOSD();
323 if (!img)
324 return;
325 if (!largeeosdtex[0]) {
326 glGenTextures(2, largeeosdtex);
327 BindTexture(gl_target, largeeosdtex[0]);
328 glCreateClearTex(gl_target, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, scale_type, LARGE_EOSD_TEX_SIZE, LARGE_EOSD_TEX_SIZE, 0);
329 BindTexture(gl_target, largeeosdtex[1]);
330 glCreateClearTex(gl_target, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, scale_type, LARGE_EOSD_TEX_SIZE, LARGE_EOSD_TEX_SIZE, 0);
332 for (i = img; i; i = i->next)
334 if (i->w <= 0 || i->h <= 0 || i->stride < i->w)
335 continue;
336 if (is_tinytex(i, tinytexcur))
337 tinytexcur++;
338 else if (is_smalltex(i, smalltexcur))
339 smalltexcur++;
340 else
341 eosdtexCnt++;
343 mp_msg(MSGT_VO, MSGL_DBG2, "EOSD counts (tiny, small, all): %i, %i, %i\n",
344 tinytexcur, smalltexcur, eosdtexCnt);
345 if (eosdtexCnt) {
346 eosdtex = calloc(eosdtexCnt, sizeof(GLuint));
347 glGenTextures(eosdtexCnt, eosdtex);
349 tinytexcur = smalltexcur = 0;
350 for (i = img, curtex = eosdtex; i; i = i->next) {
351 int x = 0, y = 0;
352 if (i->w <= 0 || i->h <= 0 || i->stride < i->w) {
353 mp_msg(MSGT_VO, MSGL_V, "Invalid dimensions OSD for part!\n");
354 continue;
356 if (is_tinytex(i, tinytexcur)) {
357 tinytex_pos(tinytexcur, &x, &y);
358 BindTexture(gl_target, largeeosdtex[0]);
359 tinytexcur++;
360 } else if (is_smalltex(i, smalltexcur)) {
361 smalltex_pos(smalltexcur, &x, &y);
362 BindTexture(gl_target, largeeosdtex[1]);
363 smalltexcur++;
364 } else {
365 texSize(i->w, i->h, &sx, &sy);
366 BindTexture(gl_target, *curtex++);
367 glCreateClearTex(gl_target, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, scale_type, sx, sy, 0);
369 glUploadTex(gl_target, GL_ALPHA, GL_UNSIGNED_BYTE, i->bitmap, i->stride,
370 x, y, i->w, i->h, 0);
372 eosdDispList = GenLists(1);
373 skip_upload:
374 NewList(eosdDispList, GL_COMPILE);
375 tinytexcur = smalltexcur = 0;
376 for (i = img, curtex = eosdtex; i; i = i->next) {
377 int x = 0, y = 0;
378 if (i->w <= 0 || i->h <= 0 || i->stride < i->w)
379 continue;
380 Color4ub(i->color >> 24, (i->color >> 16) & 0xff, (i->color >> 8) & 0xff, 255 - (i->color & 0xff));
381 if (is_tinytex(i, tinytexcur)) {
382 tinytex_pos(tinytexcur, &x, &y);
383 sx = sy = LARGE_EOSD_TEX_SIZE;
384 BindTexture(gl_target, largeeosdtex[0]);
385 tinytexcur++;
386 } else if (is_smalltex(i, smalltexcur)) {
387 smalltex_pos(smalltexcur, &x, &y);
388 sx = sy = LARGE_EOSD_TEX_SIZE;
389 BindTexture(gl_target, largeeosdtex[1]);
390 smalltexcur++;
391 } else {
392 texSize(i->w, i->h, &sx, &sy);
393 BindTexture(gl_target, *curtex++);
395 glDrawTex(i->dst_x, i->dst_y, i->w, i->h, x, y, i->w, i->h, sx, sy, use_rectangle == 1, 0, 0);
397 EndList();
398 BindTexture(gl_target, 0);
402 * \brief uninitialize OpenGL context, freeing textures, buffers etc.
404 static void uninitGl(void) {
405 int i = 0;
406 if (DeletePrograms && fragprog)
407 DeletePrograms(1, &fragprog);
408 fragprog = 0;
409 while (default_texs[i] != 0)
410 i++;
411 if (i)
412 DeleteTextures(i, default_texs);
413 default_texs[0] = 0;
414 clearOSD();
415 clearEOSD();
416 if (largeeosdtex[0])
417 DeleteTextures(2, largeeosdtex);
418 largeeosdtex[0] = 0;
419 if (DeleteBuffers && gl_buffer)
420 DeleteBuffers(1, &gl_buffer);
421 gl_buffer = 0; gl_buffersize = 0;
422 gl_bufferptr = NULL;
423 if (DeleteBuffers && gl_buffer_uv[0])
424 DeleteBuffers(2, gl_buffer_uv);
425 gl_buffer_uv[0] = gl_buffer_uv[1] = 0; gl_buffersize_uv = 0;
426 gl_bufferptr_uv[0] = gl_bufferptr_uv[1] = 0;
427 #ifdef CONFIG_X11
428 if (mesa_bufferptr)
429 FreeMemoryMESA(mDisplay, mScreen, mesa_bufferptr);
430 #endif
431 mesa_bufferptr = NULL;
432 err_shown = 0;
435 static void autodetectGlExtensions(void) {
436 const char *extensions = GetString(GL_EXTENSIONS);
437 const char *vendor = GetString(GL_VENDOR);
438 const char *version = GetString(GL_VERSION);
439 int is_ati = strstr(vendor, "ATI") != NULL;
440 int ati_broken_pbo = 0;
441 if (is_ati && strncmp(version, "2.1.", 4) == 0) {
442 int ver = atoi(version + 4);
443 mp_msg(MSGT_VO, MSGL_V, "[gl] Detected ATI driver version: %i\n", ver);
444 ati_broken_pbo = ver && ver < 8395;
446 if (ati_hack == -1) ati_hack = ati_broken_pbo;
447 if (force_pbo == -1) force_pbo = strstr(extensions, "_pixel_buffer_object") ? is_ati : 0;
448 if (use_rectangle == -1) use_rectangle = strstr(extensions, "_texture_non_power_of_two") ? 0 : 0;
449 if (is_ati && (lscale == 1 || lscale == 2 || cscale == 1 || cscale == 2))
450 mp_msg(MSGT_VO, MSGL_WARN, "[gl] Selected scaling mode may be broken on ATI cards.\n"
451 "Tell _them_ to fix GL_REPEAT if you have issues.\n");
452 mp_msg(MSGT_VO, MSGL_V, "[gl] Settings after autodetection: ati-hack = %i, force-pbo = %i, rectangle = %i\n",
453 ati_hack, force_pbo, use_rectangle);
457 * \brief Initialize a (new or reused) OpenGL context.
458 * set global gl-related variables to their default values
460 static int initGl(uint32_t d_width, uint32_t d_height) {
461 autodetectGlExtensions();
462 texSize(image_width, image_height, &texture_width, &texture_height);
464 Disable(GL_BLEND);
465 Disable(GL_DEPTH_TEST);
466 DepthMask(GL_FALSE);
467 Disable(GL_CULL_FACE);
468 Enable(gl_target);
469 DrawBuffer(vo_doublebuffering?GL_BACK:GL_FRONT);
470 TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
472 mp_msg(MSGT_VO, MSGL_V, "[gl] Creating %dx%d texture...\n",
473 texture_width, texture_height);
475 if (image_format == IMGFMT_YV12) {
476 int i;
477 GenTextures(21, default_texs);
478 default_texs[21] = 0;
479 for (i = 0; i < 7; i++) {
480 ActiveTexture(GL_TEXTURE1 + i);
481 BindTexture(GL_TEXTURE_2D, default_texs[i]);
482 BindTexture(GL_TEXTURE_RECTANGLE, default_texs[i + 7]);
483 BindTexture(GL_TEXTURE_3D, default_texs[i + 14]);
485 ActiveTexture(GL_TEXTURE1);
486 glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, GL_LINEAR,
487 texture_width / 2, texture_height / 2, 128);
488 ActiveTexture(GL_TEXTURE2);
489 glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, GL_LINEAR,
490 texture_width / 2, texture_height / 2, 128);
491 switch (use_yuv) {
492 case YUV_CONVERSION_FRAGMENT_LOOKUP:
493 case YUV_CONVERSION_FRAGMENT_POW:
494 case YUV_CONVERSION_FRAGMENT:
495 if (!GenPrograms || !BindProgram) {
496 mp_msg(MSGT_VO, MSGL_ERR, "[gl] fragment program functions missing!\n");
497 break;
499 GenPrograms(1, &fragprog);
500 BindProgram(GL_FRAGMENT_PROGRAM, fragprog);
501 break;
503 ActiveTexture(GL_TEXTURE0);
504 BindTexture(gl_target, 0);
505 update_yuvconv();
507 glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, GL_LINEAR,
508 texture_width, texture_height, 0);
510 resize(d_width, d_height);
512 ClearColor( 0.0f,0.0f,0.0f,0.0f );
513 Clear( GL_COLOR_BUFFER_BIT );
514 if (SwapInterval && swap_interval >= 0)
515 SwapInterval(swap_interval);
516 return 1;
519 /* connect to server, create and map window,
520 * allocate colors and (shared) memory
522 static int
523 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
525 image_height = height;
526 image_width = width;
527 image_format = format;
528 glFindFormat(format, NULL, &gl_texfmt, &gl_format, &gl_type);
530 vo_flipped = !!(flags & VOFLAG_FLIPPING);
532 #ifdef GL_WIN32
533 if (glctx.type == GLTYPE_W32 && !vo_w32_config(d_width, d_height, flags))
534 return -1;
535 #endif
536 #ifdef CONFIG_X11
537 if (glctx.type == GLTYPE_X11) {
538 XVisualInfo *vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib );
539 if (vinfo == NULL)
541 mp_msg(MSGT_VO, MSGL_ERR, "[gl] no GLX support present\n");
542 return -1;
544 mp_msg(MSGT_VO, MSGL_V, "[gl] GLX chose visual with ID 0x%x\n", (int)vinfo->visualid);
546 vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height, flags,
547 XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone),
548 "gl", title);
550 #endif
552 glconfig:
553 if (vo_config_count)
554 uninitGl();
555 if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED)
556 return -1;
557 if (mesa_buffer && !AllocateMemoryMESA) {
558 mp_msg(MSGT_VO, MSGL_ERR, "Can not enable mesa-buffer because AllocateMemoryMESA was not found\n");
559 mesa_buffer = 0;
561 initGl(vo_dwidth, vo_dheight);
563 return 0;
566 static void check_events(void)
568 int e=glctx.check_events();
569 if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight);
570 if(e&VO_EVENT_EXPOSE && int_pause) redraw();
574 * Creates the textures and the display list needed for displaying
575 * an OSD part.
576 * Callback function for vo_draw_text().
578 static void create_osd_texture(int x0, int y0, int w, int h,
579 unsigned char *src, unsigned char *srca,
580 int stride)
582 // initialize to 8 to avoid special-casing on alignment
583 int sx = 8, sy = 8;
584 GLint scale_type = scaled_osd ? GL_LINEAR : GL_NEAREST;
586 if (w <= 0 || h <= 0 || stride < w) {
587 mp_msg(MSGT_VO, MSGL_V, "Invalid dimensions OSD for part!\n");
588 return;
590 texSize(w, h, &sx, &sy);
592 if (osdtexCnt >= MAX_OSD_PARTS) {
593 mp_msg(MSGT_VO, MSGL_ERR, "Too many OSD parts, contact the developers!\n");
594 return;
597 // create Textures for OSD part
598 GenTextures(1, &osdtex[osdtexCnt]);
599 BindTexture(gl_target, osdtex[osdtexCnt]);
600 glCreateClearTex(gl_target, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, scale_type, sx, sy, 0);
601 glUploadTex(gl_target, GL_LUMINANCE, GL_UNSIGNED_BYTE, src, stride,
602 0, 0, w, h, 0);
604 #ifndef FAST_OSD
605 GenTextures(1, &osdatex[osdtexCnt]);
606 BindTexture(gl_target, osdatex[osdtexCnt]);
607 glCreateClearTex(gl_target, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, scale_type, sx, sy, 0);
609 int i;
610 char *tmp = malloc(stride * h);
611 // convert alpha from weird MPlayer scale.
612 // in-place is not possible since it is reused for future OSDs
613 for (i = h * stride - 1; i >= 0; i--)
614 tmp[i] = -srca[i];
615 glUploadTex(gl_target, GL_ALPHA, GL_UNSIGNED_BYTE, tmp, stride,
616 0, 0, w, h, 0);
617 free(tmp);
619 #endif
621 BindTexture(gl_target, 0);
623 // Create a list for rendering this OSD part
624 #ifndef FAST_OSD
625 osdaDispList[osdtexCnt] = GenLists(1);
626 NewList(osdaDispList[osdtexCnt], GL_COMPILE);
627 // render alpha
628 BindTexture(gl_target, osdatex[osdtexCnt]);
629 glDrawTex(x0, y0, w, h, 0, 0, w, h, sx, sy, use_rectangle == 1, 0, 0);
630 EndList();
631 #endif
632 osdDispList[osdtexCnt] = GenLists(1);
633 NewList(osdDispList[osdtexCnt], GL_COMPILE);
634 // render OSD
635 BindTexture(gl_target, osdtex[osdtexCnt]);
636 glDrawTex(x0, y0, w, h, 0, 0, w, h, sx, sy, use_rectangle == 1, 0, 0);
637 EndList();
639 osdtexCnt++;
642 static void draw_osd(void)
644 if (!use_osd) return;
645 if (vo_osd_changed(0)) {
646 int osd_h, osd_w;
647 clearOSD();
648 osd_w = scaled_osd ? image_width : vo_dwidth;
649 osd_h = scaled_osd ? image_height : vo_dheight;
650 vo_draw_text_ext(osd_w, osd_h, ass_border_x, ass_border_y, ass_border_x, ass_border_y,
651 image_width, image_height, create_osd_texture);
653 if (vo_doublebuffering) do_render_osd(1);
656 static void do_render(void) {
657 // Enable(GL_TEXTURE_2D);
658 // BindTexture(GL_TEXTURE_2D, texture_id);
660 Color3f(1,1,1);
661 if (image_format == IMGFMT_YV12)
662 glEnableYUVConversion(gl_target, yuvconvtype);
663 glDrawTex(0, 0, image_width, image_height,
664 0, 0, image_width, image_height,
665 texture_width, texture_height,
666 use_rectangle == 1, image_format == IMGFMT_YV12,
667 mpi_flipped ^ vo_flipped);
668 if (image_format == IMGFMT_YV12)
669 glDisableYUVConversion(gl_target, yuvconvtype);
673 * \param type bit 0: render OSD, bit 1: render EOSD
675 static void do_render_osd(int type) {
676 if (((type & 1) && osdtexCnt > 0) || ((type & 2) && eosdDispList)) {
677 // set special rendering parameters
678 if (!scaled_osd) {
679 MatrixMode(GL_PROJECTION);
680 PushMatrix();
681 LoadIdentity();
682 Ortho(0, vo_dwidth, vo_dheight, 0, -1, 1);
684 Enable(GL_BLEND);
685 if ((type & 2) && eosdDispList) {
686 BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
687 CallList(eosdDispList);
689 if ((type & 1) && osdtexCnt > 0) {
690 Color4ub((osd_color >> 16) & 0xff, (osd_color >> 8) & 0xff, osd_color & 0xff, 0xff - (osd_color >> 24));
691 // draw OSD
692 #ifndef FAST_OSD
693 BlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
694 CallLists(osdtexCnt, GL_UNSIGNED_INT, osdaDispList);
695 #endif
696 BlendFunc(GL_SRC_ALPHA, GL_ONE);
697 CallLists(osdtexCnt, GL_UNSIGNED_INT, osdDispList);
699 // set rendering parameters back to defaults
700 Disable(GL_BLEND);
701 if (!scaled_osd)
702 PopMatrix();
703 BindTexture(gl_target, 0);
707 static void flip_page(void) {
708 if (vo_doublebuffering) {
709 if (use_glFinish) Finish();
710 glctx.swapGlBuffers(&glctx);
711 if (aspect_scaling() && use_aspect)
712 Clear(GL_COLOR_BUFFER_BIT);
713 } else {
714 do_render();
715 do_render_osd(3);
716 if (use_glFinish) Finish();
717 else Flush();
721 static void redraw(void) {
722 if (vo_doublebuffering) { do_render(); do_render_osd(3); }
723 flip_page();
726 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num)
727 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
729 mpi_flipped = stride[0] < 0;
730 glUploadTex(gl_target, gl_format, gl_type, src[0], stride[0],
731 x, y, w, h, slice_height);
732 if (image_format == IMGFMT_YV12) {
733 ActiveTexture(GL_TEXTURE1);
734 glUploadTex(gl_target, gl_format, gl_type, src[1], stride[1],
735 x / 2, y / 2, w / 2, h / 2, slice_height);
736 ActiveTexture(GL_TEXTURE2);
737 glUploadTex(gl_target, gl_format, gl_type, src[2], stride[2],
738 x / 2, y / 2, w / 2, h / 2, slice_height);
739 ActiveTexture(GL_TEXTURE0);
741 return 0;
744 static uint32_t get_image(mp_image_t *mpi) {
745 int needed_size;
746 if (!GenBuffers || !BindBuffer || !BufferData || !MapBuffer) {
747 if (!err_shown)
748 mp_msg(MSGT_VO, MSGL_ERR, "[gl] extensions missing for dr\n"
749 "Expect a _major_ speed penalty\n");
750 err_shown = 1;
751 return VO_FALSE;
753 if (mpi->flags & MP_IMGFLAG_READABLE) return VO_FALSE;
754 if (mpi->type != MP_IMGTYPE_STATIC && mpi->type != MP_IMGTYPE_TEMP &&
755 (mpi->type != MP_IMGTYPE_NUMBERED || mpi->number))
756 return VO_FALSE;
757 if (mesa_buffer) mpi->width = texture_width;
758 else if (ati_hack) {
759 mpi->width = texture_width;
760 mpi->height = texture_height;
762 mpi->stride[0] = mpi->width * mpi->bpp / 8;
763 needed_size = mpi->stride[0] * mpi->height;
764 if (mesa_buffer) {
765 #ifdef CONFIG_X11
766 if (mesa_bufferptr && needed_size > mesa_buffersize) {
767 FreeMemoryMESA(mDisplay, mScreen, mesa_bufferptr);
768 mesa_bufferptr = NULL;
770 if (!mesa_bufferptr)
771 mesa_bufferptr = AllocateMemoryMESA(mDisplay, mScreen, needed_size, 0, 1.0, 1.0);
772 mesa_buffersize = needed_size;
773 #endif
774 mpi->planes[0] = mesa_bufferptr;
775 } else {
776 if (!gl_buffer)
777 GenBuffers(1, &gl_buffer);
778 BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer);
779 if (needed_size > gl_buffersize) {
780 gl_buffersize = needed_size;
781 BufferData(GL_PIXEL_UNPACK_BUFFER, gl_buffersize,
782 NULL, GL_DYNAMIC_DRAW);
784 if (!gl_bufferptr)
785 gl_bufferptr = MapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
786 mpi->planes[0] = gl_bufferptr;
787 BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
789 if (!mpi->planes[0]) {
790 if (!err_shown)
791 mp_msg(MSGT_VO, MSGL_ERR, "[gl] could not acquire buffer for dr\n"
792 "Expect a _major_ speed penalty\n");
793 err_shown = 1;
794 return VO_FALSE;
796 if (mpi->imgfmt == IMGFMT_YV12) {
797 // YV12
798 mpi->flags |= MP_IMGFLAG_COMMON_STRIDE | MP_IMGFLAG_COMMON_PLANE;
799 mpi->stride[0] = mpi->width;
800 mpi->planes[1] = mpi->planes[0] + mpi->stride[0] * mpi->height;
801 mpi->stride[1] = mpi->width >> 1;
802 mpi->planes[2] = mpi->planes[1] + mpi->stride[1] * (mpi->height >> 1);
803 mpi->stride[2] = mpi->width >> 1;
804 if (ati_hack && !mesa_buffer) {
805 mpi->flags &= ~MP_IMGFLAG_COMMON_PLANE;
806 if (!gl_buffer_uv[0]) GenBuffers(2, gl_buffer_uv);
807 if (mpi->stride[1] * mpi->height > gl_buffersize_uv) {
808 BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer_uv[0]);
809 BufferData(GL_PIXEL_UNPACK_BUFFER, mpi->stride[1] * mpi->height,
810 NULL, GL_DYNAMIC_DRAW);
811 BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer_uv[1]);
812 BufferData(GL_PIXEL_UNPACK_BUFFER, mpi->stride[1] * mpi->height,
813 NULL, GL_DYNAMIC_DRAW);
814 gl_buffersize_uv = mpi->stride[1] * mpi->height;
816 if (!gl_bufferptr_uv[0]) {
817 BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer_uv[0]);
818 gl_bufferptr_uv[0] = MapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
819 BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer_uv[1]);
820 gl_bufferptr_uv[1] = MapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
822 mpi->planes[1] = gl_bufferptr_uv[0];
823 mpi->planes[2] = gl_bufferptr_uv[1];
826 mpi->flags |= MP_IMGFLAG_DIRECT;
827 return VO_TRUE;
830 static void clear_border(uint8_t *dst, int start, int stride, int height, int full_height, int value) {
831 int right_border = stride - start;
832 int bottom_border = full_height - height;
833 while (height > 0) {
834 memset(dst + start, value, right_border);
835 dst += stride;
836 height--;
838 if (bottom_border > 0)
839 memset(dst, value, stride * bottom_border);
842 static uint32_t draw_image(mp_image_t *mpi) {
843 int slice = slice_height;
844 int stride[3];
845 unsigned char *planes[3];
846 mp_image_t mpi2 = *mpi;
847 int w = mpi->w, h = mpi->h;
848 if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
849 goto skip_upload;
850 mpi2.flags = 0; mpi2.type = MP_IMGTYPE_TEMP;
851 mpi2.width = mpi2.w; mpi2.height = mpi2.h;
852 if (force_pbo && !(mpi->flags & MP_IMGFLAG_DIRECT) && !gl_bufferptr && get_image(&mpi2) == VO_TRUE) {
853 int bpp = mpi->imgfmt == IMGFMT_YV12 ? 8 : mpi->bpp;
854 memcpy_pic(mpi2.planes[0], mpi->planes[0], mpi->w * bpp / 8, mpi->h, mpi2.stride[0], mpi->stride[0]);
855 if (mpi->imgfmt == IMGFMT_YV12) {
856 memcpy_pic(mpi2.planes[1], mpi->planes[1], mpi->w >> 1, mpi->h >> 1, mpi2.stride[1], mpi->stride[1]);
857 memcpy_pic(mpi2.planes[2], mpi->planes[2], mpi->w >> 1, mpi->h >> 1, mpi2.stride[2], mpi->stride[2]);
859 if (ati_hack) { // since we have to do a full upload we need to clear the borders
860 clear_border(mpi2.planes[0], mpi->w * bpp / 8, mpi2.stride[0], mpi->h, mpi2.height, 0);
861 if (mpi->imgfmt == IMGFMT_YV12) {
862 clear_border(mpi2.planes[1], mpi->w >> 1, mpi2.stride[1], mpi->h >> 1, mpi2.height >> 1, 128);
863 clear_border(mpi2.planes[2], mpi->w >> 1, mpi2.stride[2], mpi->h >> 1, mpi2.height >> 1, 128);
866 mpi = &mpi2;
868 stride[0] = mpi->stride[0]; stride[1] = mpi->stride[1]; stride[2] = mpi->stride[2];
869 planes[0] = mpi->planes[0]; planes[1] = mpi->planes[1]; planes[2] = mpi->planes[2];
870 mpi_flipped = stride[0] < 0;
871 if (mpi->flags & MP_IMGFLAG_DIRECT) {
872 if (mesa_buffer) {
873 PixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
874 w = texture_width;
875 } else {
876 intptr_t base = (intptr_t)planes[0];
877 if (ati_hack) { w = texture_width; h = texture_height; }
878 if (mpi_flipped)
879 base += (mpi->h - 1) * stride[0];
880 planes[0] -= base;
881 planes[1] -= base;
882 planes[2] -= base;
883 BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer);
884 UnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
885 gl_bufferptr = NULL;
886 if (!(mpi->flags & MP_IMGFLAG_COMMON_PLANE))
887 planes[0] = planes[1] = planes[2] = NULL;
889 slice = 0; // always "upload" full texture
891 glUploadTex(gl_target, gl_format, gl_type, planes[0], stride[0],
892 mpi->x, mpi->y, w, h, slice);
893 if (mpi->imgfmt == IMGFMT_YV12) {
894 if ((mpi->flags & MP_IMGFLAG_DIRECT) && !(mpi->flags & MP_IMGFLAG_COMMON_PLANE)) {
895 BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer_uv[0]);
896 UnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
897 gl_bufferptr_uv[0] = NULL;
899 ActiveTexture(GL_TEXTURE1);
900 glUploadTex(gl_target, gl_format, gl_type, planes[1], stride[1],
901 mpi->x / 2, mpi->y / 2, w / 2, h / 2, slice);
902 if ((mpi->flags & MP_IMGFLAG_DIRECT) && !(mpi->flags & MP_IMGFLAG_COMMON_PLANE)) {
903 BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer_uv[1]);
904 UnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
905 gl_bufferptr_uv[1] = NULL;
907 ActiveTexture(GL_TEXTURE2);
908 glUploadTex(gl_target, gl_format, gl_type, planes[2], stride[2],
909 mpi->x / 2, mpi->y / 2, w / 2, h / 2, slice);
910 ActiveTexture(GL_TEXTURE0);
912 if (mpi->flags & MP_IMGFLAG_DIRECT) {
913 if (mesa_buffer) PixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 0);
914 else BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
916 skip_upload:
917 if (vo_doublebuffering) do_render();
918 return VO_TRUE;
921 static int
922 draw_frame(uint8_t *src[])
924 return VO_ERROR;
927 static int
928 query_format(uint32_t format)
930 int caps = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW |
931 VFCAP_FLIP |
932 VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE;
933 if (use_osd)
934 caps |= VFCAP_OSD | VFCAP_EOSD | (scaled_osd ? 0 : VFCAP_EOSD_UNSCALED);
935 if (format == IMGFMT_RGB24 || format == IMGFMT_RGBA)
936 return caps;
937 if (use_yuv && format == IMGFMT_YV12)
938 return caps;
939 // HACK, otherwise we get only b&w with some filters (e.g. -vf eq)
940 // ideally MPlayer should be fixed instead not to use Y800 when it has the choice
941 if (!use_yuv && (format == IMGFMT_Y8 || format == IMGFMT_Y800))
942 return 0;
943 if (!use_ycbcr && (format == IMGFMT_UYVY || format == IMGFMT_YUY2))
944 return 0;
945 if (many_fmts &&
946 glFindFormat(format, NULL, NULL, NULL, NULL))
947 return caps;
948 return 0;
952 static void
953 uninit(void)
955 if (!vo_config_count) return;
956 uninitGl();
957 if (custom_prog) free(custom_prog);
958 custom_prog = NULL;
959 if (custom_tex) free(custom_tex);
960 custom_tex = NULL;
961 uninit_mpglcontext(&glctx);
964 static const opt_t subopts[] = {
965 {"manyfmts", OPT_ARG_BOOL, &many_fmts, NULL},
966 {"osd", OPT_ARG_BOOL, &use_osd, NULL},
967 {"scaled-osd", OPT_ARG_BOOL, &scaled_osd, NULL},
968 {"aspect", OPT_ARG_BOOL, &use_aspect, NULL},
969 {"ycbcr", OPT_ARG_BOOL, &use_ycbcr, NULL},
970 {"slice-height", OPT_ARG_INT, &slice_height, (opt_test_f)int_non_neg},
971 {"rectangle", OPT_ARG_INT, &use_rectangle,(opt_test_f)int_non_neg},
972 {"yuv", OPT_ARG_INT, &use_yuv, (opt_test_f)int_non_neg},
973 {"lscale", OPT_ARG_INT, &lscale, (opt_test_f)int_non_neg},
974 {"cscale", OPT_ARG_INT, &cscale, (opt_test_f)int_non_neg},
975 {"filter-strength", OPT_ARG_FLOAT, &filter_strength, NULL},
976 {"ati-hack", OPT_ARG_BOOL, &ati_hack, NULL},
977 {"force-pbo", OPT_ARG_BOOL, &force_pbo, NULL},
978 {"mesa-buffer", OPT_ARG_BOOL, &mesa_buffer, NULL},
979 {"glfinish", OPT_ARG_BOOL, &use_glFinish, NULL},
980 {"swapinterval", OPT_ARG_INT, &swap_interval,NULL},
981 {"customprog", OPT_ARG_MSTRZ,&custom_prog, NULL},
982 {"customtex", OPT_ARG_MSTRZ,&custom_tex, NULL},
983 {"customtlin", OPT_ARG_BOOL, &custom_tlin, NULL},
984 {"customtrect", OPT_ARG_BOOL, &custom_trect, NULL},
985 {"osdcolor", OPT_ARG_INT, &osd_color, NULL},
986 {NULL}
989 static int preinit(const char *arg)
991 enum MPGLType gltype = GLTYPE_X11;
992 // set defaults
993 #ifdef GL_WIN32
994 gltype = GLTYPE_W32;
995 #endif
996 many_fmts = 1;
997 use_osd = 1;
998 scaled_osd = 0;
999 use_aspect = 1;
1000 use_ycbcr = 0;
1001 use_yuv = 0;
1002 lscale = 0;
1003 cscale = 0;
1004 filter_strength = 0.5;
1005 use_rectangle = -1;
1006 use_glFinish = 0;
1007 ati_hack = -1;
1008 force_pbo = -1;
1009 mesa_buffer = 0;
1010 swap_interval = 1;
1011 slice_height = 0;
1012 custom_prog = NULL;
1013 custom_tex = NULL;
1014 custom_tlin = 1;
1015 custom_trect = 0;
1016 osd_color = 0xffffff;
1017 if (subopt_parse(arg, subopts) != 0) {
1018 mp_msg(MSGT_VO, MSGL_FATAL,
1019 "\n-vo gl command line help:\n"
1020 "Example: mplayer -vo gl:slice-height=4\n"
1021 "\nOptions:\n"
1022 " nomanyfmts\n"
1023 " Disable extended color formats for OpenGL 1.2 and later\n"
1024 " slice-height=<0-...>\n"
1025 " Slice size for texture transfer, 0 for whole image\n"
1026 " noosd\n"
1027 " Do not use OpenGL OSD code\n"
1028 " scaled-osd\n"
1029 " Render OSD at movie resolution and scale it\n"
1030 " noaspect\n"
1031 " Do not do aspect scaling\n"
1032 " rectangle=<0,1,2>\n"
1033 " 0: use power-of-two textures\n"
1034 " 1: use texture_rectangle\n"
1035 " 2: use texture_non_power_of_two\n"
1036 " ati-hack\n"
1037 " Workaround ATI bug with PBOs\n"
1038 " force-pbo\n"
1039 " Force use of PBO even if this involves an extra memcpy\n"
1040 " glfinish\n"
1041 " Call glFinish() before swapping buffers\n"
1042 " swapinterval=<n>\n"
1043 " Interval in displayed frames between to buffer swaps.\n"
1044 " 1 is equivalent to enable VSYNC, 0 to disable VSYNC.\n"
1045 " Requires GLX_SGI_swap_control support to work.\n"
1046 " yuv=<n>\n"
1047 " 0: use software YUV to RGB conversion.\n"
1048 " 1: use register combiners (nVidia only, for older cards).\n"
1049 " 2: use fragment program.\n"
1050 " 3: use fragment program with gamma correction.\n"
1051 " 4: use fragment program with gamma correction via lookup.\n"
1052 " 5: use ATI-specific method (for older cards).\n"
1053 " 6: use lookup via 3D texture.\n"
1054 " lscale=<n>\n"
1055 " 0: use standard bilinear scaling for luma.\n"
1056 " 1: use improved bicubic scaling for luma.\n"
1057 " 2: use cubic in X, linear in Y direction scaling for luma.\n"
1058 " 3: as 1 but without using a lookup texture.\n"
1059 " 4: experimental unsharp masking (sharpening).\n"
1060 " 5: experimental unsharp masking (sharpening) with larger radius.\n"
1061 " cscale=<n>\n"
1062 " as lscale but for chroma (2x slower with little visible effect).\n"
1063 " filter-strength=<value>\n"
1064 " set the effect strength for some lscale/cscale filters\n"
1065 " customprog=<filename>\n"
1066 " use a custom YUV conversion program\n"
1067 " customtex=<filename>\n"
1068 " use a custom YUV conversion lookup texture\n"
1069 " nocustomtlin\n"
1070 " use GL_NEAREST scaling for customtex texture\n"
1071 " customtrect\n"
1072 " use texture_rectangle for customtex texture\n"
1073 " osdcolor=<0xAARRGGBB>\n"
1074 " use the given color for the OSD\n"
1075 " ycbcr\n"
1076 " also try to use the GL_MESA_ycbcr_texture extension\n"
1077 "\n" );
1078 return -1;
1080 if (use_rectangle == 1)
1081 gl_target = GL_TEXTURE_RECTANGLE;
1082 else
1083 gl_target = GL_TEXTURE_2D;
1084 yuvconvtype = use_yuv | lscale << YUV_LUM_SCALER_SHIFT | cscale << YUV_CHROM_SCALER_SHIFT;
1085 if (many_fmts)
1086 mp_msg(MSGT_VO, MSGL_INFO, "[gl] using extended formats. "
1087 "Use -vo gl:nomanyfmts if playback fails.\n");
1088 mp_msg(MSGT_VO, MSGL_V, "[gl] Using %d as slice height "
1089 "(0 means image height).\n", slice_height);
1090 if (!init_mpglcontext(&glctx, gltype)) return -1;
1092 return 0;
1095 #define MASK_ALL_YUV (~(1 << YUV_CONVERSION_NONE))
1096 #define MASK_NOT_COMBINERS (~((1 << YUV_CONVERSION_NONE) | (1 << YUV_CONVERSION_COMBINERS) | (1 << YUV_CONVERSION_COMBINERS_ATI)))
1097 #define MASK_GAMMA_SUPPORT (MASK_NOT_COMBINERS & ~(1 << YUV_CONVERSION_FRAGMENT))
1099 static const struct {
1100 const char *name;
1101 int *value;
1102 int supportmask;
1103 } eq_map[] = {
1104 {"brightness", &eq_bri, MASK_NOT_COMBINERS},
1105 {"contrast", &eq_cont, MASK_NOT_COMBINERS},
1106 {"saturation", &eq_sat, MASK_ALL_YUV },
1107 {"hue", &eq_hue, MASK_ALL_YUV },
1108 {"gamma", &eq_rgamma, MASK_GAMMA_SUPPORT},
1109 {"red_gamma", &eq_rgamma, MASK_GAMMA_SUPPORT},
1110 {"green_gamma", &eq_ggamma, MASK_GAMMA_SUPPORT},
1111 {"blue_gamma", &eq_bgamma, MASK_GAMMA_SUPPORT},
1112 {NULL, NULL, 0 }
1115 static int control(uint32_t request, void *data)
1117 switch (request) {
1118 case VOCTRL_PAUSE:
1119 case VOCTRL_RESUME:
1120 int_pause = (request == VOCTRL_PAUSE);
1121 return VO_TRUE;
1122 case VOCTRL_QUERY_FORMAT:
1123 return query_format(*(uint32_t*)data);
1124 case VOCTRL_GET_IMAGE:
1125 return get_image(data);
1126 case VOCTRL_DRAW_IMAGE:
1127 return draw_image(data);
1128 case VOCTRL_DRAW_EOSD:
1129 if (!data)
1130 return VO_FALSE;
1131 genEOSD(data);
1132 if (vo_doublebuffering) do_render_osd(2);
1133 return VO_TRUE;
1134 case VOCTRL_GET_EOSD_RES:
1136 mp_eosd_res_t *r = data;
1137 r->w = vo_dwidth; r->h = vo_dheight;
1138 r->mt = r->mb = r->ml = r->mr = 0;
1139 if (scaled_osd) {r->w = image_width; r->h = image_height;}
1140 else if (aspect_scaling()) {
1141 r->ml = r->mr = ass_border_x;
1142 r->mt = r->mb = ass_border_y;
1145 return VO_TRUE;
1146 case VOCTRL_ONTOP:
1147 glctx.ontop();
1148 return VO_TRUE;
1149 case VOCTRL_FULLSCREEN:
1150 glctx.fullscreen();
1151 resize(vo_dwidth, vo_dheight);
1152 return VO_TRUE;
1153 case VOCTRL_BORDER:
1154 glctx.border();
1155 resize(vo_dwidth, vo_dheight);
1156 return VO_TRUE;
1157 case VOCTRL_GET_PANSCAN:
1158 if (!use_aspect) return VO_NOTIMPL;
1159 return VO_TRUE;
1160 case VOCTRL_SET_PANSCAN:
1161 if (!use_aspect) return VO_NOTIMPL;
1162 resize(vo_dwidth, vo_dheight);
1163 return VO_TRUE;
1164 case VOCTRL_GET_EQUALIZER:
1165 if (image_format == IMGFMT_YV12) {
1166 struct voctrl_get_equalizer_args *args = data;
1167 int i;
1168 for (i = 0; eq_map[i].name; i++)
1169 if (strcmp(args->name, eq_map[i].name) == 0) break;
1170 if (!(eq_map[i].supportmask & (1 << use_yuv)))
1171 break;
1172 *args->valueptr = *eq_map[i].value;
1173 return VO_TRUE;
1175 break;
1176 case VOCTRL_SET_EQUALIZER:
1177 if (image_format == IMGFMT_YV12) {
1178 struct voctrl_set_equalizer_args *args = data;
1179 int i;
1180 for (i = 0; eq_map[i].name; i++)
1181 if (strcmp(args->name, eq_map[i].name) == 0) break;
1182 if (!(eq_map[i].supportmask & (1 << use_yuv)))
1183 break;
1184 *eq_map[i].value = args->value;
1185 update_yuvconv();
1186 return VO_TRUE;
1188 break;
1189 case VOCTRL_UPDATE_SCREENINFO:
1190 glctx.update_xinerama_info();
1191 return VO_TRUE;
1192 case VOCTRL_REDRAW_OSD:
1193 if (vo_doublebuffering)
1194 do_render();
1195 draw_osd();
1196 if (vo_doublebuffering)
1197 do_render_osd(2);
1198 flip_page();
1199 return VO_TRUE;
1201 return VO_NOTIMPL;