4 * (was video_out_sdl.c from OMS project/mpeg2dec -> http://linuxvideo.org)
6 * Copyright (C) Ryan C. Gordon <icculus@lokigames.com> - April 22, 2000.
8 * Copyright (C) Felix Buenemann <atmosfear@users.sourceforge.net> - 2001
10 * (for extensive code enhancements)
12 * Current maintainer for MPlayer project (report bugs to that address):
13 * Felix Buenemann <atmosfear@users.sourceforge.net>
15 * This file is a video out driver using the SDL library (http://libsdl.org/),
16 * to be used with MPlayer, further info from http://www.mplayerhq.hu
18 * -- old disclaimer --
20 * A mpeg2dec display driver that does output through the
21 * Simple DirectMedia Layer (SDL) library. This effectively gives us all
22 * sorts of output options: X11, SVGAlib, fbcon, AAlib, GGI. Win32, MacOS
23 * and BeOS support, too. Yay. SDL info, source, and binaries can be found
24 * at http://slouken.devolution.com/SDL/
26 * -- end old disclaimer --
28 * This file is part of MPlayer.
30 * MPlayer is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
35 * MPlayer is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
40 * You should have received a copy of the GNU General Public License along
41 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
42 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
45 /* define to force software-surface (video surface stored in system memory)*/
46 #undef SDL_NOHWSURFACE
48 /* define to enable surface locks, this might be needed on SMP machines */
49 #undef SDL_ENABLE_LOCKS
51 //#define BUGGY_SDL //defined by configure
53 /* MONITOR_ASPECT MUST BE FLOAT */
54 #define MONITOR_ASPECT 4.0/3.0
65 #include "video_out.h"
66 #include "video_out_internal.h"
68 #include "fastmemcpy.h"
71 #include "libmpcodecs/vfcap.h"
75 #include "x11_common.h"
78 #include "input/input.h"
79 #include "input/mouse.h"
80 #include "subopt-helper.h"
83 static const vo_info_t info
=
85 "SDL YUV/RGB/BGR renderer (SDL v1.1.7+ only!)",
87 "Ryan C. Gordon <icculus@lokigames.com>, Felix Buenemann <atmosfear@users.sourceforge.net>",
91 const LIBVO_EXTERN(sdl
)
94 //#include <SDL/SDL_syswm.h>
97 #ifdef SDL_ENABLE_LOCKS
98 #define SDL_OVR_LOCK(x) if (SDL_LockYUVOverlay (priv->overlay)) { \
99 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock YUV overlay\n"); \
102 #define SDL_OVR_UNLOCK SDL_UnlockYUVOverlay (priv->overlay);
104 #define SDL_SRF_LOCK(srf, x) if(SDL_MUSTLOCK(srf)) { \
105 if(SDL_LockSurface (srf)) { \
106 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock RGB surface\n"); \
111 #define SDL_SRF_UNLOCK(srf) if(SDL_MUSTLOCK(srf)) \
112 SDL_UnlockSurface (srf);
114 #define SDL_OVR_LOCK(x)
115 #define SDL_OVR_UNLOCK
116 #define SDL_SRF_LOCK(srf, x)
117 #define SDL_SRF_UNLOCK(srf)
120 /** Private SDL Data structure **/
122 static struct sdl_priv_s
{
124 /* output driver used by sdl */
127 /* SDL display surface */
128 SDL_Surface
*surface
;
130 /* SDL RGB surface */
131 SDL_Surface
*rgbsurface
;
133 /* SDL YUV overlay */
134 SDL_Overlay
*overlay
;
136 /* available fullscreen modes */
137 SDL_Rect
**fullmodes
;
139 /* surface attributes for fullscreen and windowed mode */
140 Uint32 sdlflags
, sdlfullflags
;
142 /* save the windowed output extents */
154 /* use direct blitting to surface */
157 /* current fullscreen mode, 0 = highest available fullscreen mode */
161 int framePlaneY
, framePlaneUV
, framePlaneYUY
;
162 int stridePlaneY
, stridePlaneUV
, stridePlaneYUY
;
171 /* fullscreen behaviour; see init */
174 /* is X running (0/1) */
180 /* original image dimensions */
183 /* destination dimensions */
184 int dstwidth
, dstheight
;
186 /* Draw image at coordinate y on the SDL surfaces */
189 /* The image is displayed between those y coordinates in priv->surface */
190 int y_screen_top
, y_screen_bottom
;
192 /* 1 if the OSD has changed otherwise 0 */
195 /* source image format (YUV/RGB/...) */
198 /* dirty_off_frame[0] contains a bounding box around the osd contents drawn above the image
199 dirty_off_frame[1] is the corresponding thing for OSD contents drawn below the image
201 SDL_Rect dirty_off_frame
[2];
204 static void erase_area_4(int x_start
, int width
, int height
, int pitch
, uint32_t color
, uint8_t* pixels
);
205 static void erase_area_1(int x_start
, int width
, int height
, int pitch
, uint8_t color
, uint8_t* pixels
);
206 static int setup_surfaces(void);
207 static void set_video_mode(int width
, int height
, int bpp
, uint32_t sdlflags
);
208 static void erase_rectangle(int x
, int y
, int w
, int h
);
210 /* Expand 'rect' to contain the rectangle specified by x, y, w and h */
211 static void expand_rect(SDL_Rect
* rect
, int x
, int y
, int w
, int h
)
213 if(rect
->x
< 0 || rect
->y
< 0) {
227 if(rect
->x
+ rect
->w
< x
+ w
)
228 rect
->w
= x
+ w
- rect
->x
;
230 if(rect
->y
+ rect
->h
< y
+ h
)
231 rect
->h
= y
+ h
- rect
->y
;
234 /** libvo Plugin functions **/
237 * draw_alpha is used for osd and subtitle display.
241 static void draw_alpha(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
242 struct sdl_priv_s
*priv
= &sdl_priv
;
244 if(priv
->osd_has_changed
) {
245 /* OSD did change. Store a bounding box of everything drawn into the OSD */
247 /* Make sure we don't mark part of the frame area dirty */
249 expand_rect(&priv
->dirty_off_frame
[0], x0
, y0
, w
, priv
->y
- y0
);
251 expand_rect(&priv
->dirty_off_frame
[0], x0
, y0
, w
, h
);
253 else if(priv
->y
+ priv
->height
<= y0
+ h
) {
254 /* Make sure we don't mark part of the frame area dirty */
255 if(y0
< priv
->y
+ priv
->height
)
256 expand_rect(&priv
->dirty_off_frame
[1], x0
,
257 priv
->y
+ priv
->height
,
258 w
, h
- ((priv
->y
+ priv
->height
) - y0
));
260 expand_rect(&priv
->dirty_off_frame
[1], x0
, y0
, w
, h
);
263 else { /* OSD contents didn't change only draw parts that was erased by the frame */
265 src
= src
+ (priv
->y
- y0
) * stride
;
266 srca
= srca
+ (priv
->y
- y0
) * stride
;
271 if(priv
->y
+ priv
->height
<= y0
+ h
)
272 h
= priv
->y
+ priv
->height
- y0
;
278 switch(priv
->format
) {
282 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
287 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
291 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
296 x0
*= priv
->surface
->format
->BytesPerPixel
;
297 switch(priv
->format
) {
300 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
304 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
308 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
312 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
317 x0
*= priv
->rgbsurface
->format
->BytesPerPixel
;
318 switch(priv
->format
) {
321 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
325 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
329 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
333 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
343 * Take a null-terminated array of pointers, and find the last element.
345 * params : array == array of which we want to find the last element.
346 * returns : index of last NON-NULL element.
349 static inline int findArrayEnd (SDL_Rect
**array
)
352 while ( array
[i
++] ); /* keep loopin' ... */
354 /* return the index of the last array element */
360 * Open and prepare SDL output.
362 * params : *plugin ==
364 * returns : 0 on success, -1 on failure
367 static int sdl_open (void *plugin
, void *name
)
369 struct sdl_priv_s
*priv
= &sdl_priv
;
370 const SDL_VideoInfo
*vidInfo
= NULL
;
371 /*static int opened = 0;
378 /* other default values */
379 #ifdef SDL_NOHWSURFACE
380 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using software-surface\n");
381 priv
->sdlflags
= SDL_SWSURFACE
|SDL_RESIZABLE
|SDL_ANYFORMAT
;
382 priv
->sdlfullflags
= SDL_SWSURFACE
|SDL_FULLSCREEN
|SDL_ANYFORMAT
;
383 // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems
385 /*if((strcmp(priv->driver, "dga") == 0) && (priv->mode)) {
386 if( mp_msg_test(MSGT_VO,MSGL_V) ) {
387 printf("SDL: using software-surface\n"); }
388 priv->sdlflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;
389 priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;
392 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using hardware-surface\n");
393 priv
->sdlflags
= SDL_HWSURFACE
|SDL_RESIZABLE
/*|SDL_ANYFORMAT*/;
394 priv
->sdlfullflags
= SDL_HWSURFACE
|SDL_FULLSCREEN
/*|SDL_ANYFORMAT*/;
395 // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems
399 #if !defined( __AMIGAOS4__ ) && !defined( __APPLE__ )
400 priv
->sdlfullflags
|= SDL_DOUBLEBUF
;
401 if (vo_doublebuffering
)
402 priv
->sdlflags
|= SDL_DOUBLEBUF
;
405 /* Setup Keyrepeats (500/30 are defaults) */
406 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/);
408 /* get information about the graphics adapter */
409 vidInfo
= SDL_GetVideoInfo ();
411 /* collect all fullscreen & hardware modes available */
412 if (!(priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
))) {
414 /* non hardware accelerated fullscreen modes */
415 priv
->sdlfullflags
&= ~SDL_HWSURFACE
;
416 priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
);
419 /* test for normal resizeable & windowed hardware accellerated surfaces */
420 if (!SDL_ListModes (vidInfo
->vfmt
, priv
->sdlflags
)) {
422 /* test for NON hardware accelerated resizeable surfaces - poor you.
423 * That's all we have. If this fails there's nothing left.
424 * Theoretically there could be Fullscreenmodes left - we ignore this for now.
426 priv
->sdlflags
&= ~SDL_HWSURFACE
;
427 if ((!SDL_ListModes (vidInfo
->vfmt
, priv
->sdlflags
)) && (!priv
->fullmodes
)) {
428 mp_msg(MSGT_VO
,MSGL_ERR
, MSGTR_LIBVO_SDL_CouldntGetAnyAcceptableSDLModeForOutput
);
434 /* YUV overlays need at least 16-bit color depth, but the
435 * display might less. The SDL AAlib target says it can only do
436 * 8-bits, for example. So, if the display is less than 16-bits,
437 * we'll force the BPP to 16, and pray that SDL can emulate for us.
439 priv
->bpp
= vidInfo
->vfmt
->BitsPerPixel
;
440 if (priv
->mode
== YUV
&& priv
->bpp
< 16) {
442 mp_msg(MSGT_VO
,MSGL_V
, "SDL: Your SDL display target wants to be at a color "
443 "depth of (%d), but we need it to be at least 16 "
444 "bits, so we need to emulate 16-bit color. This is "
445 "going to slow things down; you might want to "
446 "increase your display's color depth, if possible.\n",
452 /* We don't want those in our event queue.
453 * We use SDL_KEYUP cause SDL_KEYDOWN seems to cause problems
454 * with keys need to be pressed twice, to be recognized.
457 SDL_EventState(SDL_ACTIVEEVENT
, SDL_IGNORE
);
458 SDL_EventState(SDL_MOUSEMOTION
, SDL_IGNORE
);
459 // SDL_EventState(SDL_QUIT, SDL_IGNORE);
460 SDL_EventState(SDL_SYSWMEVENT
, SDL_IGNORE
);
461 SDL_EventState(SDL_USEREVENT
, SDL_IGNORE
);
470 * Close SDL, Cleanups, Free Memory
473 * returns : non-zero on success, zero on error.
476 static int sdl_close (void)
478 struct sdl_priv_s
*priv
= &sdl_priv
;
483 /* Cleanup YUV Overlay structure */
485 SDL_FreeYUVOverlay(priv
->overlay
);
489 /* Free RGB Surface */
490 if (priv
->rgbsurface
) {
491 SDL_FreeSurface(priv
->rgbsurface
);
492 priv
->rgbsurface
=NULL
;
495 /* Free our blitting surface */
497 SDL_FreeSurface(priv
->surface
);
501 /* DON'T attempt to free the fullscreen modes array. SDL_Quit* does this for us */
507 * Do aspect ratio calculations
509 * params : srcw == sourcewidth
510 * srch == sourceheight
511 * dstw == destinationwidth
512 * dsth == destinationheight
514 * returns : SDL_Rect structure with new x and y, w and h
518 static SDL_Rect
aspect(int srcw
, int srch
, int dstw
, int dsth
) {
520 mp_msg(MSGT_VO
,MSGL_V
, "SDL Aspect-Destinationres: %ix%i (x: %i, y: %i)\n", newres
.w
, newres
.h
, newres
.x
, newres
.y
);
521 newres
.h
= ((float)dstw
/ (float)srcw
* (float)srch
) * ((float)dsth
/((float)dstw
/(MONITOR_ASPECT
)));
522 if(newres
.h
> dsth
) {
523 newres
.w
= ((float)dsth
/ (float)newres
.h
) * dstw
;
525 newres
.x
= (dstw
- newres
.w
) / 2;
531 newres
.y
= (dsth
- newres
.h
) / 2;
534 mp_msg(MSGT_VO
,MSGL_V
, "SDL Mode: %d: %d x %d\n", i
, priv
->fullmodes
[i
]->w
, priv
->fullmodes
[i
]->h
);
541 * Sets the specified fullscreen mode.
543 * params : mode == index of the desired fullscreen mode
544 * returns : doesn't return
548 static void set_fullmode (int mode
)
550 struct sdl_priv_s
*priv
= &sdl_priv
;
551 SDL_Surface
*newsurface
= NULL
;
552 int haspect
, waspect
= 0;
554 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
556 mode
= priv
->fullmode
= findArrayEnd(priv
->fullmodes
) - 1;
558 /* Calculate proper aspect ratio for fullscreen
559 * Height smaller than expected: add horizontal black bars (haspect)*/
560 haspect
= (priv
->width
* (float) ((float) priv
->fullmodes
[mode
]->h
/ (float) priv
->fullmodes
[mode
]->w
) - priv
->height
) * (float) ((float) priv
->fullmodes
[mode
]->w
/ (float) priv
->width
);
561 /* Height bigger than expected: add vertical black bars (waspect)*/
563 haspect
= 0; /* set haspect to zero because image will be scaled horizontal instead of vertical */
564 waspect
= priv
->fullmodes
[mode
]->w
- ((float) ((float) priv
->fullmodes
[mode
]->h
/ (float) priv
->height
) * (float) priv
->width
);
566 // printf ("W-Aspect: %i H-Aspect: %i\n", waspect, haspect);
568 /* change to given fullscreen mode and hide the mouse cursor */
569 newsurface
= SDL_SetVideoMode(priv
->fullmodes
[mode
]->w
- waspect
, priv
->fullmodes
[mode
]->h
- haspect
, priv
->bpp
, priv
->sdlfullflags
);
571 /* if we were successful hide the mouse cursor and save the mode */
574 SDL_FreeSurface(priv
->surface
);
575 priv
->surface
= newsurface
;
581 /* Set video mode. Not fullscreen */
582 static void set_video_mode(int width
, int height
, int bpp
, uint32_t sdlflags
)
584 struct sdl_priv_s
*priv
= &sdl_priv
;
585 SDL_Surface
* newsurface
;
588 SDL_FreeSurface(priv
->rgbsurface
);
589 else if(priv
->overlay
)
590 SDL_FreeYUVOverlay(priv
->overlay
);
592 priv
->rgbsurface
= NULL
;
593 priv
->overlay
= NULL
;
595 newsurface
= SDL_SetVideoMode(width
, height
, bpp
, sdlflags
);
599 /* priv->surface will be NULL the first time this function is called. */
601 SDL_FreeSurface(priv
->surface
);
603 priv
->surface
= newsurface
;
604 priv
->dstwidth
= width
;
605 priv
->dstheight
= height
;
610 mp_msg(MSGT_VO
,MSGL_WARN
, "set_video_mode: SDL_SetVideoMode failed: %s\n", SDL_GetError());
613 static void set_fullmode (int mode
) {
614 struct sdl_priv_s
*priv
= &sdl_priv
;
615 SDL_Surface
*newsurface
= NULL
;
616 int screen_surface_w
, screen_surface_h
;
619 SDL_FreeSurface(priv
->rgbsurface
);
620 else if(priv
->overlay
)
621 SDL_FreeYUVOverlay(priv
->overlay
);
623 priv
->rgbsurface
= NULL
;
624 priv
->overlay
= NULL
;
626 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
627 /* But select a mode where the full video enter */
628 if(priv
->X
&& priv
->fulltype
& VOFLAG_FULLSCREEN
) {
629 screen_surface_w
= priv
->XWidth
;
630 screen_surface_h
= priv
->XHeight
;
634 mode
= 0; // Default to the biggest mode avaible
635 if ( mp_msg_test(MSGT_VO
,MSGL_V
) ) for(i
=0;priv
->fullmodes
[i
];++i
)
636 mp_msg(MSGT_VO
,MSGL_V
, "SDL Mode: %d: %d x %d\n", i
, priv
->fullmodes
[i
]->w
, priv
->fullmodes
[i
]->h
);
637 for(i
= findArrayEnd(priv
->fullmodes
) - 1; i
>=0; i
--) {
638 if( (priv
->fullmodes
[i
]->w
>= priv
->dstwidth
) &&
639 (priv
->fullmodes
[i
]->h
>= priv
->dstheight
) ) {
641 for (j
= findArrayEnd(priv
->fullmodes
) - 1; j
>=0; j
--) {
642 if (priv
->fullmodes
[j
]->w
> priv
->fullmodes
[imax
]->w
643 && priv
->fullmodes
[j
]->h
== priv
->fullmodes
[imax
]->h
)
650 mp_msg(MSGT_VO
,MSGL_V
, "SET SDL Mode: %d: %d x %d\n", mode
, priv
->fullmodes
[mode
]->w
, priv
->fullmodes
[mode
]->h
);
651 priv
->fullmode
= mode
;
652 screen_surface_h
= priv
->fullmodes
[mode
]->h
;
653 screen_surface_w
= priv
->fullmodes
[mode
]->w
;
656 screen_surface_h
= priv
->fullmodes
[mode
]->h
;
657 screen_surface_w
= priv
->fullmodes
[mode
]->w
;
660 aspect_save_screenres(screen_surface_w
, screen_surface_h
);
662 /* calculate new video size/aspect */
663 if(priv
->mode
== YUV
) {
664 if(priv
->fulltype
&VOFLAG_FULLSCREEN
)
665 aspect_save_screenres(priv
->XWidth
, priv
->XHeight
);
667 aspect(&priv
->dstwidth
, &priv
->dstheight
, A_ZOOM
);
670 /* try to change to given fullscreenmode */
671 newsurface
= SDL_SetVideoMode(priv
->dstwidth
, screen_surface_h
, priv
->bpp
,
675 * In Mac OS X (and possibly others?) SDL_SetVideoMode() appears to
676 * destroy the datastructure previously retrived, so we need to
677 * re-assign it. The comment in sdl_close() seems to imply that we
678 * should not free() anything.
682 const SDL_VideoInfo
*vidInfo
= NULL
;
683 vidInfo
= SDL_GetVideoInfo ();
685 /* collect all fullscreen & hardware modes available */
686 if (!(priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
))) {
688 /* non hardware accelerated fullscreen modes */
689 priv
->sdlfullflags
&= ~SDL_HWSURFACE
;
690 priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
);
697 /* if creation of new surface was successful, save it and hide mouse cursor */
700 SDL_FreeSurface(priv
->surface
);
701 priv
->surface
= newsurface
;
703 SDL_SRF_LOCK(priv
->surface
, -1)
704 SDL_FillRect(priv
->surface
, NULL
, 0);
705 SDL_SRF_UNLOCK(priv
->surface
)
709 mp_msg(MSGT_VO
,MSGL_INFO
, MSGTR_LIBVO_SDL_SetVideoModeFailedFull
, SDL_GetError());
714 * Initialize an SDL surface and an SDL YUV overlay.
716 * params : width == width of video we'll be displaying.
717 * height == height of video we'll be displaying.
718 * fullscreen == want to be fullscreen?
719 * title == Title for window titlebar.
720 * returns : non-zero on success, zero on error.
724 config(uint32_t width
, uint32_t height
, uint32_t d_width
, uint32_t d_height
, uint32_t flags
, char *title
, uint32_t format
)
725 //static int sdl_setup (int width, int height)
727 struct sdl_priv_s
*priv
= &sdl_priv
;
731 mp_msg(MSGT_VO
,MSGL_INFO
, MSGTR_LIBVO_SDL_MappingI420ToIYUV
);
732 format
= SDL_IYUV_OVERLAY
;
753 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_SDL_UnsupportedImageFormat
,format
);
757 if ( vo_config_count
) sdl_close();
759 mp_msg(MSGT_VO
,MSGL_V
, "SDL: Using 0x%X (%s) image format\n", format
, vo_format_name(format
));
761 if(priv
->mode
!= YUV
) {
762 priv
->sdlflags
|= SDL_ANYFORMAT
;
763 priv
->sdlfullflags
|= SDL_ANYFORMAT
;
766 /* SDL can only scale YUV data */
767 if(priv
->mode
== RGB
|| priv
->mode
== BGR
) {
772 aspect_save_orig(width
,height
);
773 aspect_save_prescale(d_width
? d_width
: width
, d_height
? d_height
: height
);
775 /* Save the original Image size */
777 priv
->height
= height
;
778 priv
->dstwidth
= d_width
? d_width
: width
;
779 priv
->dstheight
= d_height
? d_height
: height
;
781 priv
->format
= format
;
783 if (sdl_open(NULL
, NULL
) != 0)
786 /* Set output window title */
787 SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title
);
788 //SDL_WM_SetCaption (title, title);
791 aspect_save_screenres(priv
->XWidth
,priv
->XHeight
);
792 aspect(&priv
->dstwidth
,&priv
->dstheight
,A_NOZOOM
);
795 priv
->windowsize
.w
= priv
->dstwidth
;
796 priv
->windowsize
.h
= priv
->dstheight
;
798 /* bit 0 (0x01) means fullscreen (-fs)
799 * bit 1 (0x02) means mode switching (-vm)
800 * bit 2 (0x04) enables software scaling (-zoom)
801 * bit 3 (0x08) enables flipping (-flip)
803 // printf("SDL: flags are set to: %i\n", flags);
804 // printf("SDL: Width: %i Height: %i D_Width %i D_Height: %i\n", width, height, d_width, d_height);
805 if(flags
&VOFLAG_FLIPPING
) {
806 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using flipped video (only with RGB/BGR/packed YUV)\n");
809 if(flags
&VOFLAG_FULLSCREEN
) {
810 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen without modeswitching\n");
811 mp_msg(MSGT_VO
,MSGL_INFO
, MSGTR_LIBVO_SDL_InfoPleaseUseVmOrZoom
);
812 priv
->fulltype
= VOFLAG_FULLSCREEN
;
813 set_fullmode(priv
->fullmode
);
814 /*if((priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlfullflags)))
817 if(flags
&VOFLAG_MODESWITCHING
) {
818 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
819 priv
->fulltype
= VOFLAG_MODESWITCHING
;
820 set_fullmode(priv
->fullmode
);
821 /*if((priv->surface = SDL_SetVideoMode (d_width ? d_width : width, d_height ? d_height : height, priv->bpp, priv->sdlfullflags)))
824 if(flags
&VOFLAG_SWSCALE
) {
825 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
826 priv
->fulltype
= VOFLAG_SWSCALE
;
827 set_fullmode(priv
->fullmode
);
830 if((strcmp(priv
->driver
, "x11") == 0)
831 ||(strcmp(priv
->driver
, "windib") == 0)
832 ||(strcmp(priv
->driver
, "directx") == 0)
833 ||(strcmp(priv
->driver
, "Quartz") == 0)
834 ||(strcmp(priv
->driver
, "cgx") == 0)
835 ||(strcmp(priv
->driver
, "os4video") == 0)
836 ||((strcmp(priv
->driver
, "aalib") == 0) && priv
->X
)){
837 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting windowed mode\n");
838 set_video_mode(priv
->dstwidth
, priv
->dstheight
, priv
->bpp
, priv
->sdlflags
);
841 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
842 priv
->fulltype
= VOFLAG_SWSCALE
;
843 set_fullmode(priv
->fullmode
);
847 if(!priv
->surface
) { // cannot SetVideoMode
848 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_SDL_FailedToSetVideoMode
, SDL_GetError());
855 /* Free priv->rgbsurface or priv->overlay if they are != NULL.
856 * Setup priv->rgbsurface or priv->overlay depending on source format.
857 * The size of the created surface or overlay depends on the size of
858 * priv->surface, priv->width, priv->height, priv->dstwidth and priv->dstheight.
860 static int setup_surfaces(void)
862 struct sdl_priv_s
*priv
= &sdl_priv
;
863 float v_scale
= ((float) priv
->dstheight
) / priv
->height
;
864 int surfwidth
, surfheight
;
866 surfwidth
= priv
->width
;
867 surfheight
= priv
->height
+ (priv
->surface
->h
- priv
->dstheight
) / v_scale
;
869 /* Place the image in the middle of the screen */
870 priv
->y
= (surfheight
- priv
->height
) / 2;
871 priv
->y_screen_top
= priv
->y
* v_scale
;
872 priv
->y_screen_bottom
= priv
->y_screen_top
+ priv
->dstheight
;
874 priv
->dirty_off_frame
[0].x
= -1;
875 priv
->dirty_off_frame
[0].y
= -1;
876 priv
->dirty_off_frame
[1].x
= -1;
877 priv
->dirty_off_frame
[1].y
= -1;
879 /* Make sure the entire screen is updated */
883 SDL_FreeSurface(priv
->rgbsurface
);
884 else if(priv
->overlay
)
885 SDL_FreeYUVOverlay(priv
->overlay
);
887 priv
->rgbsurface
= NULL
;
888 priv
->overlay
= NULL
;
890 if(priv
->mode
!= YUV
&& (priv
->format
&0xFF) == priv
->bpp
) {
891 if(strcmp(priv
->driver
, "x11") == 0) {
893 priv
->framePlaneRGB
= priv
->width
* priv
->height
* priv
->surface
->format
->BytesPerPixel
;
894 priv
->stridePlaneRGB
= priv
->width
* priv
->surface
->format
->BytesPerPixel
;
895 erase_rectangle(0, 0, priv
->surface
->w
, priv
->surface
->h
);
900 switch(priv
->format
) {
901 /* Initialize and create the RGB Surface used for video out in BGR/RGB mode */
902 //SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
903 // SDL_SWSURFACE,SDL_HWSURFACE,SDL_SRCCOLORKEY, priv->flags? guess: exchange Rmask and Bmask for BGR<->RGB
904 // 32 bit: a:ff000000 r:ff000 g:ff00 b:ff
905 // 24 bit: r:ff0000 g:ff00 b:ff
906 // 16 bit: r:1111100000000000b g:0000011111100000b b:0000000000011111b
907 // 15 bit: r:111110000000000b g:000001111100000b b:000000000011111b
908 // FIXME: colorkey detect based on bpp, FIXME static bpp value, FIXME alpha value correct?
910 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 15, 31, 992, 31744, 0);
913 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 15, 31744, 992, 31, 0);
916 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 16, 31, 2016, 63488, 0);
919 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 16, 63488, 2016, 31, 0);
922 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0);
925 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 24, 0xFF0000, 0x00FF00, 0x0000FF, 0);
928 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0/*0xFF000000*/);
931 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0/*0xFF000000*/);
934 /* Initialize and create the YUV Overlay used for video out */
935 if (!(priv
->overlay
= SDL_CreateYUVOverlay (surfwidth
, surfheight
, priv
->format
, priv
->surface
))) {
936 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_SDL_CouldntCreateAYUVOverlay
, SDL_GetError());
939 priv
->framePlaneY
= priv
->width
* priv
->height
;
940 priv
->framePlaneUV
= (priv
->width
* priv
->height
) >> 2;
941 priv
->framePlaneYUY
= priv
->width
* priv
->height
* 2;
942 priv
->stridePlaneY
= priv
->width
;
943 priv
->stridePlaneUV
= priv
->width
/2;
944 priv
->stridePlaneYUY
= priv
->width
* 2;
947 if(priv
->mode
!= YUV
) {
948 if(!priv
->rgbsurface
) {
949 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_SDL_CouldntCreateARGBSurface
, SDL_GetError());
955 if((priv
->format
&0xFF) != priv
->bpp
)
956 mp_msg(MSGT_VO
,MSGL_INFO
, MSGTR_LIBVO_SDL_UsingDepthColorspaceConversion
, priv
->format
&0xFF, priv
->bpp
);
958 priv
->framePlaneRGB
= priv
->width
* priv
->height
* priv
->rgbsurface
->format
->BytesPerPixel
;
959 priv
->stridePlaneRGB
= priv
->width
* priv
->rgbsurface
->format
->BytesPerPixel
;
962 erase_rectangle(0, 0, surfwidth
, surfheight
);
969 * Draw a frame to the SDL YUV overlay.
971 * params : *src[] == the Y, U, and V planes that make up the frame.
972 * returns : non-zero on success, zero on error.
975 //static int sdl_draw_frame (frame_t *frame)
976 static int draw_frame(uint8_t *src
[])
978 struct sdl_priv_s
*priv
= &sdl_priv
;
981 uint8_t *mysrc
= src
[0];
983 switch(priv
->format
){
988 dst
= (uint8_t *) *(priv
->overlay
->pixels
) + priv
->overlay
->pitches
[0]*priv
->y
;
990 mysrc
+=priv
->framePlaneYUY
;
991 for(i
= 0; i
< priv
->height
; i
++) {
992 mysrc
-=priv
->stridePlaneYUY
;
993 fast_memcpy (dst
, mysrc
, priv
->stridePlaneYUY
);
994 dst
+=priv
->overlay
->pitches
[0];
997 else fast_memcpy (dst
, src
[0], priv
->framePlaneYUY
);
1010 SDL_SRF_LOCK(priv
->surface
, -1)
1011 dst
= (uint8_t *) priv
->surface
->pixels
+ priv
->y
*priv
->surface
->pitch
;
1013 mysrc
+=priv
->framePlaneRGB
;
1014 for(i
= 0; i
< priv
->height
; i
++) {
1015 mysrc
-=priv
->stridePlaneRGB
;
1016 fast_memcpy (dst
, mysrc
, priv
->stridePlaneRGB
);
1017 dst
+= priv
->surface
->pitch
;
1020 else fast_memcpy (dst
, src
[0], priv
->framePlaneRGB
);
1021 SDL_SRF_UNLOCK(priv
->surface
)
1023 SDL_SRF_LOCK(priv
->rgbsurface
, -1)
1024 dst
= (uint8_t *) priv
->rgbsurface
->pixels
+ priv
->y
*priv
->rgbsurface
->pitch
;
1026 mysrc
+=priv
->framePlaneRGB
;
1027 for(i
= 0; i
< priv
->height
; i
++) {
1028 mysrc
-=priv
->stridePlaneRGB
;
1029 fast_memcpy (dst
, mysrc
, priv
->stridePlaneRGB
);
1030 dst
+= priv
->rgbsurface
->pitch
;
1033 else fast_memcpy (dst
, src
[0], priv
->framePlaneRGB
);
1034 SDL_SRF_UNLOCK(priv
->rgbsurface
)
1045 * Draw a slice (16 rows of image) to the SDL YUV overlay.
1047 * params : *src[] == the Y, U, and V planes that make up the slice.
1048 * returns : non-zero on error, zero on success.
1051 //static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
1052 static int draw_slice(uint8_t *image
[], int stride
[], int w
,int h
,int x
,int y
)
1054 struct sdl_priv_s
*priv
= &sdl_priv
;
1061 dst
= priv
->overlay
->pixels
[0] + priv
->overlay
->pitches
[0]*y
+ x
;
1062 memcpy_pic(dst
, image
[0], w
, h
, priv
->overlay
->pitches
[0], stride
[0]);
1063 x
/=2;y
/=2;w
/=2;h
/=2;
1065 switch(priv
->format
) {
1067 dst
= priv
->overlay
->pixels
[2] + priv
->overlay
->pitches
[2]*y
+ x
;
1068 memcpy_pic(dst
, image
[1], w
, h
, priv
->overlay
->pitches
[2], stride
[1]);
1070 dst
= priv
->overlay
->pixels
[1] + priv
->overlay
->pitches
[1]*y
+ x
;
1071 memcpy_pic(dst
, image
[2], w
, h
, priv
->overlay
->pitches
[1], stride
[2]);
1076 dst
= priv
->overlay
->pixels
[1] + priv
->overlay
->pitches
[1]*y
+ x
;
1077 memcpy_pic(dst
, image
[1], w
, h
, priv
->overlay
->pitches
[1], stride
[1]);
1079 dst
= priv
->overlay
->pixels
[2] + priv
->overlay
->pitches
[2]*y
+ x
;
1080 memcpy_pic(dst
, image
[2], w
, h
, priv
->overlay
->pitches
[2], stride
[2]);
1084 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_SDL_UnsupportedImageFormatInDrawslice
);
1095 * Checks for SDL keypress and window resize events
1098 * returns : doesn't return
1101 #include "osdep/keycodes.h"
1103 #define shift_key (event.key.keysym.mod==(KMOD_LSHIFT||KMOD_RSHIFT))
1104 static void check_events (void)
1106 struct sdl_priv_s
*priv
= &sdl_priv
;
1108 SDLKey keypressed
= SDLK_UNKNOWN
;
1110 /* Poll the waiting SDL Events */
1111 while ( SDL_PollEvent(&event
) ) {
1112 switch (event
.type
) {
1114 /* capture window resize events */
1115 case SDL_VIDEORESIZE
:
1117 set_video_mode(event
.resize
.w
, event
.resize
.h
, priv
->bpp
, priv
->sdlflags
);
1119 /* save video extents, to restore them after going fullscreen */
1120 //if(!(priv->surface->flags & SDL_FULLSCREEN)) {
1121 priv
->windowsize
.w
= priv
->surface
->w
;
1122 priv
->windowsize
.h
= priv
->surface
->h
;
1124 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Window resize\n");
1127 case SDL_MOUSEBUTTONDOWN
:
1128 if(vo_nomouse_input
)
1130 mplayer_put_key((MOUSE_BTN0
+event
.button
.button
-1) | MP_KEY_DOWN
);
1133 case SDL_MOUSEBUTTONUP
:
1134 if(vo_nomouse_input
)
1136 mplayer_put_key(MOUSE_BTN0
+event
.button
.button
-1);
1139 /* graphics mode selection shortcuts */
1142 switch(event
.key
.keysym
.sym
) {
1143 case SDLK_UP
: mplayer_put_key(KEY_UP
); break;
1144 case SDLK_DOWN
: mplayer_put_key(KEY_DOWN
); break;
1145 case SDLK_LEFT
: mplayer_put_key(KEY_LEFT
); break;
1146 case SDLK_RIGHT
: mplayer_put_key(KEY_RIGHT
); break;
1147 case SDLK_LESS
: mplayer_put_key(shift_key
?'>':'<'); break;
1148 case SDLK_GREATER
: mplayer_put_key('>'); break;
1150 case SDLK_KP_MULTIPLY
:
1152 case SDLK_KP_DIVIDE
:
1160 keypressed
= event
.key
.keysym
.sym
;
1161 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Key pressed: '%i'\n", keypressed
);
1163 /* c key pressed. c cycles through available fullscreenmodes, if we have some */
1164 if ( ((keypressed
== SDLK_c
)) && (priv
->fullmodes
) ) {
1165 /* select next fullscreen mode */
1167 if (priv
->fullmode
> (findArrayEnd(priv
->fullmodes
) - 1)) priv
->fullmode
= 0;
1168 set_fullmode(priv
->fullmode
);
1170 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Set next available fullscreen mode.\n");
1173 else if ( keypressed
== SDLK_n
) {
1175 aspect(&priv
->dstwidth
, &priv
->dstheight
,A_NOZOOM
);
1177 if (priv
->surface
->w
!= priv
->dstwidth
|| priv
->surface
->h
!= priv
->dstheight
) {
1178 set_video_mode(priv
->dstwidth
, priv
->dstheight
, priv
->bpp
, priv
->sdlflags
);
1179 priv
->windowsize
.w
= priv
->surface
->w
;
1180 priv
->windowsize
.h
= priv
->surface
->h
;
1181 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Normal size\n");
1183 if (priv
->surface
->w
!= priv
->dstwidth
* 2 || priv
->surface
->h
!= priv
->dstheight
* 2) {
1184 set_video_mode(priv
->dstwidth
* 2, priv
->dstheight
* 2, priv
->bpp
, priv
->sdlflags
);
1185 priv
->windowsize
.w
= priv
->surface
->w
;
1186 priv
->windowsize
.h
= priv
->surface
->h
;
1187 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Double size\n");
1191 else switch(keypressed
){
1192 case SDLK_RETURN
: mplayer_put_key(KEY_ENTER
);break;
1193 case SDLK_ESCAPE
: mplayer_put_key(KEY_ESC
);break;
1194 case SDLK_q
: mplayer_put_key('q');break;
1195 case SDLK_F1
: mplayer_put_key(KEY_F
+1);break;
1196 case SDLK_F2
: mplayer_put_key(KEY_F
+2);break;
1197 case SDLK_F3
: mplayer_put_key(KEY_F
+3);break;
1198 case SDLK_F4
: mplayer_put_key(KEY_F
+4);break;
1199 case SDLK_F5
: mplayer_put_key(KEY_F
+5);break;
1200 case SDLK_F6
: mplayer_put_key(KEY_F
+6);break;
1201 case SDLK_F7
: mplayer_put_key(KEY_F
+7);break;
1202 case SDLK_F8
: mplayer_put_key(KEY_F
+8);break;
1203 case SDLK_F9
: mplayer_put_key(KEY_F
+9);break;
1204 case SDLK_F10
: mplayer_put_key(KEY_F
+10);break;
1205 case SDLK_F11
: mplayer_put_key(KEY_F
+11);break;
1206 case SDLK_F12
: mplayer_put_key(KEY_F
+12);break;
1207 /*case SDLK_o: mplayer_put_key('o');break;
1208 case SDLK_SPACE: mplayer_put_key(' ');break;
1209 case SDLK_p: mplayer_put_key('p');break;*/
1210 case SDLK_7
: mplayer_put_key(shift_key
?'/':'7');break;
1211 case SDLK_PLUS
: mplayer_put_key(shift_key
?'*':'+');break;
1212 case SDLK_KP_PLUS
: mplayer_put_key('+');break;
1214 case SDLK_KP_MINUS
: mplayer_put_key('-');break;
1215 case SDLK_TAB
: mplayer_put_key('\t');break;
1216 case SDLK_PAGEUP
: mplayer_put_key(KEY_PAGE_UP
);break;
1217 case SDLK_PAGEDOWN
: mplayer_put_key(KEY_PAGE_DOWN
);break;
1224 case SDLK_KP_MULTIPLY
:
1226 case SDLK_KP_DIVIDE
:
1229 case SDLK_UP
: mplayer_put_key(KEY_UP
);break;
1230 case SDLK_DOWN
: mplayer_put_key(KEY_DOWN
);break;
1231 case SDLK_LEFT
: mplayer_put_key(KEY_LEFT
);break;
1232 case SDLK_RIGHT
: mplayer_put_key(KEY_RIGHT
);break;
1233 case SDLK_LESS
: mplayer_put_key(shift_key
?'>':'<'); break;
1234 case SDLK_GREATER
: mplayer_put_key('>'); break;
1236 case SDLK_KP_MULTIPLY
: mplayer_put_key('*'); break;
1238 case SDLK_KP_DIVIDE
: mplayer_put_key('/'); break;
1240 case SDLK_KP0
: mplayer_put_key(KEY_KP0
); break;
1241 case SDLK_KP1
: mplayer_put_key(KEY_KP1
); break;
1242 case SDLK_KP2
: mplayer_put_key(KEY_KP2
); break;
1243 case SDLK_KP3
: mplayer_put_key(KEY_KP3
); break;
1244 case SDLK_KP4
: mplayer_put_key(KEY_KP4
); break;
1245 case SDLK_KP5
: mplayer_put_key(KEY_KP5
); break;
1246 case SDLK_KP6
: mplayer_put_key(KEY_KP6
); break;
1247 case SDLK_KP7
: mplayer_put_key(KEY_KP7
); break;
1248 case SDLK_KP8
: mplayer_put_key(KEY_KP8
); break;
1249 case SDLK_KP9
: mplayer_put_key(KEY_KP9
); break;
1250 case SDLK_KP_PERIOD
: mplayer_put_key(KEY_KPDEC
); break;
1251 case SDLK_KP_ENTER
: mplayer_put_key(KEY_KPENTER
); break;
1253 //printf("got scancode: %d keysym: %d mod: %d %d\n", event.key.keysym.scancode, keypressed, event.key.keysym.mod);
1254 mplayer_put_key(keypressed
);
1258 case SDL_QUIT
: mplayer_put_key(KEY_CLOSE_WIN
);break;
1264 /* Erase (paint it black) the rectangle specified by x, y, w and h in the surface
1265 or overlay which is used for OSD
1267 static void erase_rectangle(int x
, int y
, int w
, int h
)
1269 struct sdl_priv_s
*priv
= &sdl_priv
;
1271 switch(priv
->format
) {
1276 SDL_OVR_LOCK((void) 0)
1279 erase_area_1(x
, w
, h
,
1280 priv
->overlay
->pitches
[0], 0,
1281 priv
->overlay
->pixels
[0] +
1282 priv
->overlay
->pitches
[0]*y
);
1284 /* Erase U and V planes */
1290 erase_area_1(x
, w
, h
,
1291 priv
->overlay
->pitches
[1], 128,
1292 priv
->overlay
->pixels
[1] +
1293 priv
->overlay
->pitches
[1]*y
);
1295 erase_area_1(x
, w
, h
,
1296 priv
->overlay
->pitches
[2], 128,
1297 priv
->overlay
->pixels
[2] +
1298 priv
->overlay
->pitches
[2]*y
);
1306 /* yuy2 and yvyu represent black the same way */
1307 uint8_t yuy2_black
[] = {0, 128, 0, 128};
1309 SDL_OVR_LOCK((void) 0)
1310 erase_area_4(x
*2, w
*2, h
,
1311 priv
->overlay
->pitches
[0],
1312 *((uint32_t*) yuy2_black
),
1313 priv
->overlay
->pixels
[0] +
1314 priv
->overlay
->pitches
[0]*y
);
1321 uint8_t uyvy_black
[] = {128, 0, 128, 0};
1323 SDL_OVR_LOCK((void) 0)
1324 erase_area_4(x
*2, w
*2, h
,
1325 priv
->overlay
->pitches
[0],
1326 *((uint32_t*) uyvy_black
),
1327 priv
->overlay
->pixels
[0] +
1328 priv
->overlay
->pitches
[0]*y
);
1343 rect
.w
= w
; rect
.h
= h
;
1344 rect
.x
= x
; rect
.y
= y
;
1347 SDL_SRF_LOCK(priv
->surface
, (void) 0)
1348 SDL_FillRect(priv
->surface
, &rect
, 0);
1349 SDL_SRF_UNLOCK(priv
->surface
)
1352 SDL_SRF_LOCK(priv
->rgbsurface
, (void) 0)
1353 SDL_FillRect(priv
->rgbsurface
, &rect
, 0);
1354 SDL_SRF_UNLOCK(priv
->rgbsurface
)
1361 static void draw_osd(void)
1362 { struct sdl_priv_s
*priv
= &sdl_priv
;
1364 priv
->osd_has_changed
= vo_osd_changed(0);
1366 if(priv
->osd_has_changed
)
1370 for(i
= 0; i
< 2; i
++) {
1371 if(priv
->dirty_off_frame
[i
].x
< 0 || priv
->dirty_off_frame
[i
].y
< 0)
1374 erase_rectangle(priv
->dirty_off_frame
[i
].x
, priv
->dirty_off_frame
[i
].y
,
1375 priv
->dirty_off_frame
[i
].w
, priv
->dirty_off_frame
[i
].h
);
1377 priv
->dirty_off_frame
[i
].x
= -1;
1378 priv
->dirty_off_frame
[i
].y
= -1;
1382 /* update osd/subtitles */
1383 if(priv
->mode
== YUV
)
1384 vo_draw_text(priv
->overlay
->w
, priv
->overlay
->h
, draw_alpha
);
1387 vo_draw_text(priv
->surface
->w
, priv
->surface
->h
, draw_alpha
);
1389 vo_draw_text(priv
->rgbsurface
->w
, priv
->rgbsurface
->h
, draw_alpha
);
1393 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1394 * are given in bytes. 4 bytes at a time.
1396 static void erase_area_4(int x_start
, int width
, int height
, int pitch
, uint32_t color
, uint8_t* pixels
)
1398 int x_end
= x_start
/4 + width
/4;
1400 uint32_t* data
= (uint32_t*) pixels
;
1405 for(y
= 0; y
< height
; y
++) {
1406 for(x
= x_start
; x
< x_end
; x
++)
1407 data
[y
*pitch
+ x
] = color
;
1411 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1412 * are given in bytes. 1 byte at a time.
1414 static void erase_area_1(int x_start
, int width
, int height
, int pitch
, uint8_t color
, uint8_t* pixels
)
1418 for(y
= 0; y
< height
; y
++) {
1419 memset(&pixels
[y
*pitch
+ x_start
], color
, width
);
1424 * Display the surface we have written our data to
1426 * params : mode == index of the desired fullscreen mode
1427 * returns : doesn't return
1430 static void flip_page (void)
1432 struct sdl_priv_s
*priv
= &sdl_priv
;
1434 switch(priv
->format
) {
1444 /* blit to the RGB surface */
1445 if(SDL_BlitSurface (priv
->rgbsurface
, NULL
, priv
->surface
, NULL
))
1446 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_SDL_BlitFailed
, SDL_GetError());
1450 //SDL_UpdateRect(priv->surface, 0, 0, priv->surface->clip_rect.w, priv->surface->clip_rect.h);
1451 if(priv
->osd_has_changed
) {
1452 priv
->osd_has_changed
= 0;
1453 SDL_UpdateRects(priv
->surface
, 1, &priv
->surface
->clip_rect
);
1456 SDL_UpdateRect(priv
->surface
, 0, priv
->y_screen_top
,
1457 priv
->surface
->clip_rect
.w
, priv
->y_screen_bottom
);
1459 /* check if we have a double buffered surface and flip() if we do. */
1460 if ( priv
->surface
->flags
& SDL_DOUBLEBUF
)
1461 SDL_Flip(priv
->surface
);
1465 /* blit to the YUV overlay */
1466 SDL_DisplayYUVOverlay (priv
->overlay
, &priv
->surface
->clip_rect
);
1468 /* check if we have a double buffered surface and flip() if we do. */
1469 if ( priv
->surface
->flags
& SDL_DOUBLEBUF
)
1470 SDL_Flip(priv
->surface
);
1472 //SDL_LockYUVOverlay (priv->overlay); // removed because unused!?
1477 query_format(uint32_t format
)
1481 // it seems buggy (not hw accelerated), so just use YV12 instead!
1482 // case IMGFMT_I420:
1483 // case IMGFMT_IYUV:
1487 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_OSD
|
1488 VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
;
1497 return VFCAP_CSP_SUPPORTED
| VFCAP_OSD
| VFCAP_FLIP
;
1507 struct sdl_priv_s
*priv
= &sdl_priv
;
1509 mp_msg(MSGT_VO
,MSGL_V
, "SDL: activating XScreensaver/DPMS\n");
1516 if(SDL_WasInit(SDL_INIT_VIDEO
))
1517 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
1519 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Closed Plugin\n");
1523 static int preinit(const char *arg
)
1525 struct sdl_priv_s
*priv
= &sdl_priv
;
1526 char * sdl_driver
= NULL
;
1530 {"forcexv", OPT_ARG_BOOL
, &sdl_forcexv
, NULL
, 0},
1531 {"hwaccel", OPT_ARG_BOOL
, &sdl_hwaccel
, NULL
, 0},
1532 {"driver", OPT_ARG_MSTRZ
, &sdl_driver
, NULL
, 0},
1533 {NULL
, 0, NULL
, NULL
, 0}
1539 if (subopt_parse(arg
, subopts
) != 0) return -1;
1541 priv
->rgbsurface
= NULL
;
1542 priv
->overlay
= NULL
;
1543 priv
->surface
= NULL
;
1545 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Opening Plugin\n");
1548 setenv("SDL_VIDEODRIVER", sdl_driver
, 1);
1552 /* does the user want SDL to try and force Xv */
1553 if(sdl_forcexv
) setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1);
1554 else setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "0", 1);
1556 /* does the user want to disable Xv and use software scaling instead */
1557 if(sdl_hwaccel
) setenv("SDL_VIDEO_YUV_HWACCEL", "1", 1);
1558 else setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
1560 /* default to no fullscreen mode, we'll set this as soon we have the avail. modes */
1561 priv
->fullmode
= -2;
1563 priv
->fullmodes
= NULL
;
1566 /* initialize the SDL Video system */
1567 if (!SDL_WasInit(SDL_INIT_VIDEO
)) {
1568 if (SDL_Init (SDL_INIT_VIDEO
|SDL_INIT_NOPARACHUTE
)) {
1569 mp_msg(MSGT_VO
,MSGL_ERR
, MSGTR_LIBVO_SDL_InitializationFailed
, SDL_GetError());
1575 SDL_VideoDriverName(priv
->driver
, 8);
1576 mp_msg(MSGT_VO
,MSGL_INFO
, MSGTR_LIBVO_SDL_UsingDriver
, priv
->driver
);
1581 mp_msg(MSGT_VO
,MSGL_V
, "SDL: deactivating XScreensaver/DPMS\n");
1582 priv
->XWidth
= vo_screenwidth
;
1583 priv
->XHeight
= vo_screenheight
;
1585 mp_msg(MSGT_VO
,MSGL_V
, "SDL: X11 Resolution %ix%i\n", priv
->XWidth
, priv
->XHeight
);
1592 static uint32_t get_image(mp_image_t
*mpi
)
1594 struct sdl_priv_s
*priv
= &sdl_priv
;
1596 if(priv
->format
!= mpi
->imgfmt
) return VO_FALSE
;
1597 if(mpi
->type
== MP_IMGTYPE_STATIC
|| mpi
->type
== MP_IMGTYPE_TEMP
) {
1598 if(mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1599 mpi
->planes
[0] = priv
->overlay
->pixels
[0] + priv
->y
*priv
->overlay
->pitches
[0];
1600 mpi
->stride
[0] = priv
->overlay
->pitches
[0];
1601 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
) {
1602 mpi
->planes
[1] = priv
->overlay
->pixels
[1] + priv
->y
*priv
->overlay
->pitches
[1]/2;
1603 mpi
->stride
[1] = priv
->overlay
->pitches
[1];
1604 mpi
->planes
[2] = priv
->overlay
->pixels
[2] + priv
->y
*priv
->overlay
->pitches
[2]/2;
1605 mpi
->stride
[2] = priv
->overlay
->pitches
[2];
1607 mpi
->planes
[2] = priv
->overlay
->pixels
[1] + priv
->y
*priv
->overlay
->pitches
[1]/2;
1608 mpi
->stride
[2] = priv
->overlay
->pitches
[1];
1609 mpi
->planes
[1] = priv
->overlay
->pixels
[2] + priv
->y
*priv
->overlay
->pitches
[2]/2;
1610 mpi
->stride
[1] = priv
->overlay
->pitches
[2];
1613 else if(IMGFMT_IS_RGB(priv
->format
) || IMGFMT_IS_BGR(priv
->format
)) {
1615 if(mpi
->type
== MP_IMGTYPE_STATIC
&& (priv
->surface
->flags
& SDL_DOUBLEBUF
))
1618 mpi
->planes
[0] = (uint8_t *)priv
->surface
->pixels
+ priv
->y
*priv
->surface
->pitch
;
1619 mpi
->stride
[0] = priv
->surface
->pitch
;
1622 mpi
->planes
[0] = (uint8_t *)priv
->rgbsurface
->pixels
+ priv
->y
*priv
->rgbsurface
->pitch
;
1623 mpi
->stride
[0] = priv
->rgbsurface
->pitch
;
1627 mpi
->planes
[0] = priv
->overlay
->pixels
[0] + priv
->y
*priv
->overlay
->pitches
[0];
1628 mpi
->stride
[0] = priv
->overlay
->pitches
[0];
1631 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1638 static int control(uint32_t request
, void *data
)
1640 struct sdl_priv_s
*priv
= &sdl_priv
;
1642 case VOCTRL_GET_IMAGE
:
1643 return get_image(data
);
1644 case VOCTRL_QUERY_FORMAT
:
1645 return query_format(*((uint32_t*)data
));
1646 case VOCTRL_FULLSCREEN
:
1647 if (priv
->surface
->flags
& SDL_FULLSCREEN
) {
1648 set_video_mode(priv
->windowsize
.w
, priv
->windowsize
.h
, priv
->bpp
, priv
->sdlflags
);
1650 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Windowed mode\n");
1651 } else if (priv
->fullmodes
) {
1652 set_fullmode(priv
->fullmode
);
1653 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Set fullscreen mode\n");