Revert OSD flicker fixes done better in another branch
[mplayer.git] / libvo / video_out.c
blobc65f3a571079e0aeb9b097af0ba514be07a72a0c
2 /* this file contains libvo's common functions, variables used by
3 many/all drivers. */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
9 #include <unistd.h>
10 //#include <sys/mman.h>
12 #include "config.h"
13 #include "video_out.h"
14 #include "aspect.h"
15 #include "geometry.h"
17 #include "mp_msg.h"
18 #include "help_mp.h"
20 #include "osdep/shmem.h"
22 //int vo_flags=0;
24 int xinerama_screen = -1;
25 int xinerama_x;
26 int xinerama_y;
28 // currect resolution/bpp on screen: (should be autodetected by vo_init())
29 int vo_depthonscreen=0;
30 int vo_screenwidth=0;
31 int vo_screenheight=0;
33 int vo_config_count=0;
35 // requested resolution/bpp: (-x -y -bpp options)
36 int vo_dx=0;
37 int vo_dy=0;
38 int vo_dwidth=0;
39 int vo_dheight=0;
40 int vo_dbpp=0;
42 int vo_nomouse_input = 0;
43 int vo_grabpointer = 1;
44 int vo_doublebuffering = 1;
45 int vo_vsync = 0;
46 int vo_fs = 0;
47 int vo_fsmode = 0;
48 float vo_panscan = 0.0f;
49 int vo_ontop = 0;
50 int vo_adapter_num=0;
51 int vo_refresh_rate=0;
52 int vo_keepaspect=1;
53 int vo_rootwin=0;
54 int vo_border=1;
55 int WinID = -1;
57 int vo_pts=0; // for hw decoding
58 float vo_fps=0;
60 char *vo_subdevice = NULL;
61 int vo_directrendering=0;
63 int vo_colorkey = 0x0000ff00; // default colorkey is green
64 // (0xff000000 means that colorkey has been disabled)
67 // Externally visible list of all vo drivers
69 extern vo_functions_t video_out_mga;
70 extern vo_functions_t video_out_xmga;
71 extern vo_functions_t video_out_x11;
72 extern vo_functions_t video_out_xover;
73 extern vo_functions_t video_out_xvmc;
74 extern vo_functions_t video_out_xv;
75 extern vo_functions_t video_out_gl;
76 extern vo_functions_t video_out_gl2;
77 extern vo_functions_t video_out_dga;
78 extern vo_functions_t video_out_sdl;
79 extern vo_functions_t video_out_3dfx;
80 extern vo_functions_t video_out_tdfxfb;
81 extern vo_functions_t video_out_s3fb;
82 extern vo_functions_t video_out_wii;
83 extern vo_functions_t video_out_null;
84 extern vo_functions_t video_out_zr;
85 extern vo_functions_t video_out_zr2;
86 extern vo_functions_t video_out_bl;
87 extern vo_functions_t video_out_fbdev;
88 extern vo_functions_t video_out_fbdev2;
89 extern vo_functions_t video_out_svga;
90 extern vo_functions_t video_out_png;
91 extern vo_functions_t video_out_ggi;
92 extern vo_functions_t video_out_aa;
93 extern vo_functions_t video_out_caca;
94 extern vo_functions_t video_out_mpegpes;
95 extern vo_functions_t video_out_yuv4mpeg;
96 extern vo_functions_t video_out_direct3d;
97 extern vo_functions_t video_out_directx;
98 extern vo_functions_t video_out_dxr2;
99 extern vo_functions_t video_out_dxr3;
100 extern vo_functions_t video_out_ivtv;
101 extern vo_functions_t video_out_v4l2;
102 extern vo_functions_t video_out_jpeg;
103 extern vo_functions_t video_out_gif89a;
104 extern vo_functions_t video_out_vesa;
105 extern vo_functions_t video_out_directfb;
106 extern vo_functions_t video_out_dfbmga;
107 extern vo_functions_t video_out_xvidix;
108 extern vo_functions_t video_out_winvidix;
109 extern vo_functions_t video_out_cvidix;
110 extern vo_functions_t video_out_tdfx_vid;
111 extern vo_functions_t video_out_xvr100;
112 extern vo_functions_t video_out_tga;
113 extern vo_functions_t video_out_macosx;
114 extern vo_functions_t video_out_quartz;
115 extern vo_functions_t video_out_pnm;
116 extern vo_functions_t video_out_md5sum;
118 const vo_functions_t* const video_out_drivers[] =
120 #ifdef CONFIG_XVR100
121 &video_out_xvr100,
122 #endif
123 #ifdef CONFIG_TDFX_VID
124 &video_out_tdfx_vid,
125 #endif
126 #ifdef CONFIG_DIRECTX
127 &video_out_directx,
128 #endif
129 #ifdef CONFIG_DIRECT3D
130 &video_out_direct3d,
131 #endif
132 #ifdef CONFIG_COREVIDEO
133 &video_out_macosx,
134 #endif
135 #ifdef CONFIG_QUARTZ
136 &video_out_quartz,
137 #endif
138 #ifdef CONFIG_XMGA
139 &video_out_xmga,
140 #endif
141 #ifdef CONFIG_MGA
142 &video_out_mga,
143 #endif
144 #ifdef CONFIG_TDFXFB
145 &video_out_tdfxfb,
146 #endif
147 #ifdef CONFIG_S3FB
148 &video_out_s3fb,
149 #endif
150 #ifdef CONFIG_WII
151 &video_out_wii,
152 #endif
153 #ifdef CONFIG_3DFX
154 &video_out_3dfx,
155 #endif
156 #ifdef CONFIG_XV
157 &video_out_xv,
158 #endif
159 #ifdef CONFIG_X11
160 &video_out_x11,
161 &video_out_xover,
162 #endif
163 #ifdef CONFIG_GL
164 &video_out_gl,
165 &video_out_gl2,
166 #endif
167 #ifdef CONFIG_DGA
168 &video_out_dga,
169 #endif
170 #ifdef CONFIG_SDL
171 &video_out_sdl,
172 #endif
173 #ifdef CONFIG_GGI
174 &video_out_ggi,
175 #endif
176 #ifdef CONFIG_FBDEV
177 &video_out_fbdev,
178 &video_out_fbdev2,
179 #endif
180 #ifdef CONFIG_SVGALIB
181 &video_out_svga,
182 #endif
183 #ifdef CONFIG_AA
184 &video_out_aa,
185 #endif
186 #ifdef CONFIG_CACA
187 &video_out_caca,
188 #endif
189 #ifdef CONFIG_DXR2
190 &video_out_dxr2,
191 #endif
192 #ifdef CONFIG_DXR3
193 &video_out_dxr3,
194 #endif
195 #ifdef CONFIG_IVTV
196 &video_out_ivtv,
197 #endif
198 #ifdef CONFIG_V4L2_DECODER
199 &video_out_v4l2,
200 #endif
201 #ifdef CONFIG_ZR
202 &video_out_zr,
203 &video_out_zr2,
204 #endif
205 #ifdef CONFIG_BL
206 &video_out_bl,
207 #endif
208 #ifdef CONFIG_VESA
209 &video_out_vesa,
210 #endif
211 #ifdef CONFIG_DIRECTFB
212 &video_out_directfb,
213 #endif
214 #ifdef CONFIG_DFBMGA
215 &video_out_dfbmga,
216 #endif
217 #ifdef CONFIG_VIDIX
218 #ifdef CONFIG_X11
219 &video_out_xvidix,
220 #endif
221 #if defined(__MINGW32__) || defined(__CYGWIN__)
222 &video_out_winvidix,
223 #endif
224 &video_out_cvidix,
225 #endif
226 &video_out_null,
227 // should not be auto-selected
228 #ifdef CONFIG_XVMC
229 &video_out_xvmc,
230 #endif
231 &video_out_mpegpes,
232 #ifdef CONFIG_YUV4MPEG
233 &video_out_yuv4mpeg,
234 #endif
235 #ifdef CONFIG_PNG
236 &video_out_png,
237 #endif
238 #ifdef CONFIG_JPEG
239 &video_out_jpeg,
240 #endif
241 #ifdef CONFIG_GIF
242 &video_out_gif89a,
243 #endif
244 #ifdef CONFIG_TGA
245 &video_out_tga,
246 #endif
247 #ifdef CONFIG_PNM
248 &video_out_pnm,
249 #endif
250 #ifdef CONFIG_MD5SUM
251 &video_out_md5sum,
252 #endif
253 NULL
256 void list_video_out(void){
257 int i=0;
258 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoOutputDrivers);
259 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_OUTPUTS\n");
260 while (video_out_drivers[i]) {
261 const vo_info_t *info = video_out_drivers[i++]->info;
262 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\t%s\t%s\n", info->short_name, info->name);
264 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
267 const vo_functions_t* init_best_video_out(char** vo_list){
268 int i;
269 // first try the preferred drivers, with their optional subdevice param:
270 if(vo_list && vo_list[0])
271 while(vo_list[0][0]){
272 char* vo=strdup(vo_list[0]);
273 vo_subdevice=strchr(vo,':');
274 if (!strcmp(vo, "pgm"))
275 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_VO_PGM_HasBeenReplaced);
276 if (!strcmp(vo, "md5"))
277 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_VO_MD5_HasBeenReplaced);
278 if(vo_subdevice){
279 vo_subdevice[0]=0;
280 ++vo_subdevice;
282 for(i=0;video_out_drivers[i];i++){
283 const vo_functions_t* video_driver=video_out_drivers[i];
284 const vo_info_t *info = video_driver->info;
285 if(!strcmp(info->short_name,vo)){
286 // name matches, try it
287 if(!video_driver->preinit(vo_subdevice))
289 free(vo);
290 return video_driver; // success!
294 // continue...
295 free(vo);
296 ++vo_list;
297 if(!(vo_list[0])) return NULL; // do NOT fallback to others
299 // now try the rest...
300 vo_subdevice=NULL;
301 for(i=0;video_out_drivers[i];i++){
302 const vo_functions_t* video_driver=video_out_drivers[i];
303 if(!video_driver->preinit(vo_subdevice))
304 return video_driver; // success!
306 return NULL;
309 int config_video_out(const vo_functions_t *vo, uint32_t width, uint32_t height,
310 uint32_t d_width, uint32_t d_height, uint32_t flags,
311 char *title, uint32_t format) {
312 panscan_init();
313 aspect_save_orig(width,height);
314 aspect_save_prescale(d_width,d_height);
316 if (vo->control(VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) {
317 aspect(&d_width,&d_height,A_NOZOOM);
318 vo_dx = (int)(vo_screenwidth - d_width) / 2;
319 vo_dy = (int)(vo_screenheight - d_height) / 2;
320 geometry(&vo_dx, &vo_dy, &d_width, &d_height,
321 vo_screenwidth, vo_screenheight);
322 vo_dx += xinerama_x;
323 vo_dy += xinerama_y;
324 vo_dwidth = d_width;
325 vo_dheight = d_height;
328 return vo->config(width, height, d_width, d_height, flags, title, format);
332 * \brief lookup an integer in a table, table must have 0 as the last key
333 * \param key key to search for
334 * \result translation corresponding to key or "to" value of last mapping
335 * if not found.
337 int lookup_keymap_table(const struct keymap *map, int key) {
338 while (map->from && map->from != key) map++;
339 return map->to;
342 #if defined(CONFIG_FBDEV) || defined(CONFIG_VESA)
343 /* Borrowed from vo_fbdev.c
344 Monitor ranges related functions*/
346 char *monitor_hfreq_str = NULL;
347 char *monitor_vfreq_str = NULL;
348 char *monitor_dotclock_str = NULL;
350 float range_max(range_t *r)
352 float max = 0;
354 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++)
355 if (max < r->max) max = r->max;
356 return max;
360 int in_range(range_t *r, float f)
362 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++)
363 if (f >= r->min && f <= r->max)
364 return 1;
365 return 0;
368 range_t *str2range(char *s)
370 float tmp_min, tmp_max;
371 char *endptr = s; // to start the loop
372 range_t *r = NULL;
373 int i;
375 if (!s)
376 return NULL;
377 for (i = 0; *endptr; i++) {
378 if (*s == ',')
379 goto out_err;
380 if (!(r = (range_t *) realloc(r, sizeof(*r) * (i + 2)))) {
381 mp_msg(MSGT_GLOBAL, MSGL_WARN,"can't realloc 'r'\n");
382 return NULL;
384 tmp_min = strtod(s, &endptr);
385 if (*endptr == 'k' || *endptr == 'K') {
386 tmp_min *= 1000.0;
387 endptr++;
388 } else if (*endptr == 'm' || *endptr == 'M') {
389 tmp_min *= 1000000.0;
390 endptr++;
392 if (*endptr == '-') {
393 tmp_max = strtod(endptr + 1, &endptr);
394 if (*endptr == 'k' || *endptr == 'K') {
395 tmp_max *= 1000.0;
396 endptr++;
397 } else if (*endptr == 'm' || *endptr == 'M') {
398 tmp_max *= 1000000.0;
399 endptr++;
401 if (*endptr != ',' && *endptr)
402 goto out_err;
403 } else if (*endptr == ',' || !*endptr) {
404 tmp_max = tmp_min;
405 } else
406 goto out_err;
407 r[i].min = tmp_min;
408 r[i].max = tmp_max;
409 if (r[i].min < 0 || r[i].max < 0)
410 goto out_err;
411 s = endptr + 1;
413 r[i].min = r[i].max = -1;
414 return r;
415 out_err:
416 if (r)
417 free(r);
418 return NULL;
421 /* Borrowed from vo_fbdev.c END */
422 #endif