2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 /* The high-level video driver subsystem */
35 #include "SDL_error.h"
36 #include "SDL_video.h"
37 #include "SDL_events.h"
38 #include "SDL_mutex.h"
39 #include "SDL_sysvideo.h"
40 #include "SDL_sysevents.h"
42 #include "SDL_pixels_c.h"
43 #include "SDL_events_c.h"
44 #include "SDL_cursor_c.h"
46 /* Available video drivers */
47 static VideoBootStrap *bootstrap[] = {
60 #ifdef ENABLE_DIRECTFB
90 #ifdef ENABLE_DRAWSPROCKET
96 #ifdef ENABLE_CYBERGRAPHICS
105 #ifdef ENABLE_DUMMYVIDEO
117 #ifdef ENABLE_PICOGUI
123 SDL_VideoDevice *current_video = NULL;
125 /* Various local functions */
126 int SDL_VideoInit(const char *driver_name, Uint32 flags);
127 void SDL_VideoQuit(void);
128 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect* rects);
130 static SDL_GrabMode SDL_WM_GrabInputOff(void);
132 static int lock_count = 0;
137 * Initialize the video and event subsystems -- determine native pixel format
139 int SDL_VideoInit (const char *driver_name, Uint32 flags)
141 SDL_VideoDevice *video;
144 SDL_PixelFormat vformat;
147 /* Toggle the event thread flags, based on OS requirements */
148 #if defined(MUST_THREAD_EVENTS)
149 flags |= SDL_INIT_EVENTTHREAD;
150 #elif defined(CANT_THREAD_EVENTS)
151 if ( (flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) {
152 SDL_SetError("OS doesn't support threaded events");
157 /* Check to make sure we don't overwrite 'current_video' */
158 if ( current_video != NULL ) {
162 /* Select the proper video driver */
165 if ( driver_name != NULL ) {
166 #if 0 /* This will be replaced with a better driver selection API */
167 if ( strrchr(driver_name, ':') != NULL ) {
168 index = atoi(strrchr(driver_name, ':')+1);
171 for ( i=0; bootstrap[i]; ++i ) {
172 if ( strncmp(bootstrap[i]->name, driver_name,
173 strlen(bootstrap[i]->name)) == 0 ) {
174 if ( bootstrap[i]->available() ) {
175 video = bootstrap[i]->create(index);
181 for ( i=0; bootstrap[i]; ++i ) {
182 if ( bootstrap[i]->available() ) {
183 video = bootstrap[i]->create(index);
184 if ( video != NULL ) {
190 if ( video == NULL ) {
191 SDL_SetError("No available video device");
194 current_video = video;
195 current_video->name = bootstrap[i]->name;
197 /* Do some basic variable initialization */
198 video->screen = NULL;
199 video->shadow = NULL;
200 video->visible = NULL;
201 video->physpal = NULL;
202 video->gammacols = NULL;
204 video->wm_title = NULL;
205 video->wm_icon = NULL;
208 memset(&video->info, 0, (sizeof video->info));
210 /* Set some very sane GL defaults */
211 video->gl_config.driver_loaded = 0;
212 video->gl_config.dll_handle = NULL;
213 video->gl_config.red_size = 5;
214 #if 1 /* This seems to work on more video cards, as a default */
215 video->gl_config.green_size = 5;
217 video->gl_config.green_size = 6;
219 video->gl_config.blue_size = 5;
220 video->gl_config.alpha_size = 0;
221 video->gl_config.buffer_size = 0;
222 video->gl_config.depth_size = 16;
223 video->gl_config.stencil_size = 0;
224 video->gl_config.double_buffer = 1;
225 video->gl_config.accum_red_size = 0;
226 video->gl_config.accum_green_size = 0;
227 video->gl_config.accum_blue_size = 0;
228 video->gl_config.accum_alpha_size = 0;
229 video->gl_config.stereo = 0;
231 /* Initialize the video subsystem */
232 memset(&vformat, 0, sizeof(vformat));
233 if ( video->VideoInit(video, &vformat) < 0 ) {
238 /* Create a zero sized video surface of the appropriate format */
239 video_flags = SDL_SWSURFACE;
240 SDL_VideoSurface = SDL_CreateRGBSurface(video_flags, 0, 0,
241 vformat.BitsPerPixel,
242 vformat.Rmask, vformat.Gmask, vformat.Bmask, 0);
243 if ( SDL_VideoSurface == NULL ) {
247 SDL_PublicSurface = NULL; /* Until SDL_SetVideoMode() */
249 #if 0 /* Don't change the current palette - may be used by other programs.
250 * The application can't do anything with the display surface until
251 * a video mode has been set anyway. :)
253 /* If we have a palettized surface, create a default palette */
254 if ( SDL_VideoSurface->format->palette ) {
255 SDL_PixelFormat *vf = SDL_VideoSurface->format;
256 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel);
257 video->SetColors(video,
258 0, vf->palette->ncolors, vf->palette->colors);
261 video->info.vfmt = SDL_VideoSurface->format;
263 /* Start the event loop */
264 if ( SDL_StartEventLoop(flags) < 0 ) {
268 SDL_CursorInit(flags & SDL_INIT_EVENTTHREAD);
270 /* We're ready to go! */
274 char *SDL_VideoDriverName(char *namebuf, int maxlen)
276 if ( current_video != NULL ) {
277 strncpy(namebuf, current_video->name, maxlen-1);
278 namebuf[maxlen-1] = '\0';
285 * Get the current display surface
287 SDL_Surface *SDL_GetVideoSurface(void)
289 SDL_Surface *visible;
292 if ( current_video ) {
293 visible = current_video->visible;
299 * Get the current information about the video hardware
301 const SDL_VideoInfo *SDL_GetVideoInfo(void)
303 const SDL_VideoInfo *info;
306 if ( current_video ) {
307 info = ¤t_video->info;
313 * Return a pointer to an array of available screen dimensions for the
314 * given format, sorted largest to smallest. Returns NULL if there are
315 * no dimensions available for a particular format, or (SDL_Rect **)-1
316 * if any dimension is okay for the given format. If 'format' is NULL,
317 * the mode list will be for the format given by SDL_GetVideoInfo()->vfmt
319 SDL_Rect ** SDL_ListModes (SDL_PixelFormat *format, Uint32 flags)
321 SDL_VideoDevice *video = current_video;
322 SDL_VideoDevice *this = current_video;
326 if ( SDL_VideoSurface ) {
327 if ( format == NULL ) {
328 format = SDL_VideoSurface->format;
330 modes = video->ListModes(this, format, flags);
336 * Check to see if a particular video mode is supported.
337 * It returns 0 if the requested mode is not supported under any bit depth,
338 * or returns the bits-per-pixel of the closest available mode with the
339 * given width and height. If this bits-per-pixel is different from the
340 * one used when setting the video mode, SDL_SetVideoMode() will succeed,
341 * but will emulate the requested bits-per-pixel with a shadow surface.
343 static Uint8 SDL_closest_depths[4][8] = {
344 /* 8 bit closest depth ordering */
345 { 0, 8, 16, 15, 32, 24, 0, 0 },
346 /* 15,16 bit closest depth ordering */
347 { 0, 16, 15, 32, 24, 8, 0, 0 },
348 /* 24 bit closest depth ordering */
349 { 0, 24, 32, 16, 15, 8, 0, 0 },
350 /* 32 bit closest depth ordering */
351 { 0, 32, 16, 15, 24, 8, 0, 0 }
354 int SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags)
358 SDL_PixelFormat format;
361 /* Currently 1 and 4 bpp are not supported */
362 if ( bpp < 8 || bpp > 32 ) {
365 if ( (width <= 0) || (height <= 0) ) {
369 /* Search through the list valid of modes */
370 memset(&format, 0, sizeof(format));
372 table = ((bpp+7)/8)-1;
373 SDL_closest_depths[table][0] = bpp;
374 SDL_closest_depths[table][7] = 0;
375 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
376 format.BitsPerPixel = SDL_closest_depths[table][b];
377 sizes = SDL_ListModes(&format, flags);
378 if ( sizes == (SDL_Rect **)0 ) {
379 /* No sizes supported at this bit-depth */
382 #ifdef macintosh /* MPW optimization bug? */
383 if ( (sizes == (SDL_Rect **)0xFFFFFFFF) ||
385 if ( (sizes == (SDL_Rect **)-1) ||
387 current_video->handles_any_size ) {
388 /* Any size supported at this bit-depth */
392 for ( i=0; sizes[i]; ++i ) {
393 if ((sizes[i]->w == width) && (sizes[i]->h == height)) {
401 return(SDL_closest_depths[table][b]);
408 * Get the closest non-emulated video mode to the one requested
410 static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags)
415 SDL_PixelFormat format;
418 /* Check parameters */
419 if ( *BitsPerPixel < 8 || *BitsPerPixel > 32 ) {
420 SDL_SetError("Invalid bits per pixel (range is {8...32})");
423 if ((*w <= 0) || (*h <= 0)) {
424 SDL_SetError("Invalid width or height");
428 /* Try the original video mode, get the closest depth */
429 native_bpp = SDL_VideoModeOK(*w, *h, *BitsPerPixel, flags);
430 if ( native_bpp == *BitsPerPixel ) {
433 if ( native_bpp > 0 ) {
434 *BitsPerPixel = native_bpp;
438 /* No exact size match at any depth, look for closest match */
439 memset(&format, 0, sizeof(format));
441 table = ((*BitsPerPixel+7)/8)-1;
442 SDL_closest_depths[table][0] = *BitsPerPixel;
443 SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel;
444 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
445 format.BitsPerPixel = SDL_closest_depths[table][b];
446 sizes = SDL_ListModes(&format, flags);
447 if ( sizes == (SDL_Rect **)0 ) {
448 /* No sizes supported at this bit-depth */
451 for ( i=0; sizes[i]; ++i ) {
452 if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) {
457 *BitsPerPixel = SDL_closest_depths[table][b];
460 /* Largest mode too small... */;
465 if ( (i > 0) && ! sizes[i] ) {
466 /* The smallest mode was larger than requested, OK */
470 *BitsPerPixel = SDL_closest_depths[table][b];
475 SDL_SetError("No video mode large enough for %dx%d", *w, *h);
480 /* This should probably go somewhere else -- like SDL_surface.c */
481 static void SDL_ClearSurface(SDL_Surface *surface)
485 black = SDL_MapRGB(surface->format, 0, 0, 0);
486 SDL_FillRect(surface, NULL, black);
487 if ((surface->flags&SDL_HWSURFACE) && (surface->flags&SDL_DOUBLEBUF)) {
489 SDL_FillRect(surface, NULL, black);
495 * Create a shadow surface suitable for fooling the app. :-)
497 static void SDL_CreateShadowSurface(int depth)
499 Uint32 Rmask, Gmask, Bmask;
501 /* Allocate the shadow surface */
502 if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) {
503 Rmask = (SDL_VideoSurface->format)->Rmask;
504 Gmask = (SDL_VideoSurface->format)->Gmask;
505 Bmask = (SDL_VideoSurface->format)->Bmask;
507 Rmask = Gmask = Bmask = 0;
509 SDL_ShadowSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
510 SDL_VideoSurface->w, SDL_VideoSurface->h,
511 depth, Rmask, Gmask, Bmask, 0);
512 if ( SDL_ShadowSurface == NULL ) {
516 /* 8-bit shadow surfaces report that they have exclusive palette */
517 if ( SDL_ShadowSurface->format->palette ) {
518 SDL_ShadowSurface->flags |= SDL_HWPALETTE;
519 if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) {
520 memcpy(SDL_ShadowSurface->format->palette->colors,
521 SDL_VideoSurface->format->palette->colors,
522 SDL_VideoSurface->format->palette->ncolors*
526 SDL_ShadowSurface->format->palette->colors, depth);
530 /* If the video surface is resizable, the shadow should say so */
531 if ( (SDL_VideoSurface->flags & SDL_RESIZABLE) == SDL_RESIZABLE ) {
532 SDL_ShadowSurface->flags |= SDL_RESIZABLE;
534 /* If the video surface has no frame, the shadow should say so */
535 if ( (SDL_VideoSurface->flags & SDL_NOFRAME) == SDL_NOFRAME ) {
536 SDL_ShadowSurface->flags |= SDL_NOFRAME;
538 /* If the video surface is fullscreen, the shadow should say so */
539 if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
540 SDL_ShadowSurface->flags |= SDL_FULLSCREEN;
542 /* If the video surface is flippable, the shadow should say so */
543 if ( (SDL_VideoSurface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
544 SDL_ShadowSurface->flags |= SDL_DOUBLEBUF;
550 * Set the requested video mode, allocating a shadow buffer if necessary.
552 SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
554 SDL_VideoDevice *video, *this;
555 SDL_Surface *prev_mode, *mode;
560 SDL_GrabMode saved_grab;
562 /* Start up the video driver, if necessary..
563 WARNING: This is the only function protected this way!
565 if ( ! current_video ) {
566 if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 ) {
570 this = video = current_video;
572 /* Default to the current video bpp */
574 flags |= SDL_ANYFORMAT;
575 bpp = SDL_VideoSurface->format->BitsPerPixel;
578 /* Get a good video mode, the closest one possible */
582 if ( ! SDL_GetVideoMode(&video_w, &video_h, &video_bpp, flags) ) {
586 /* Check the requested flags */
587 /* There's no palette in > 8 bits-per-pixel mode */
588 if ( video_bpp > 8 ) {
589 flags &= ~SDL_HWPALETTE;
592 if ( (flags&SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
593 /* There's no windowed double-buffering */
594 flags &= ~SDL_DOUBLEBUF;
597 if ( (flags&SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
598 /* Use hardware surfaces when double-buffering */
599 flags |= SDL_HWSURFACE;
602 is_opengl = ( ( flags & SDL_OPENGL ) == SDL_OPENGL );
604 /* These flags are for 2D video modes only */
605 flags &= ~(SDL_HWSURFACE|SDL_DOUBLEBUF);
608 /* Reset the keyboard here so event callbacks can run */
612 /* Clean up any previous video mode */
613 if ( SDL_PublicSurface != NULL ) {
614 SDL_PublicSurface = NULL;
616 if ( SDL_ShadowSurface != NULL ) {
617 SDL_Surface *ready_to_go;
618 ready_to_go = SDL_ShadowSurface;
619 SDL_ShadowSurface = NULL;
620 SDL_FreeSurface(ready_to_go);
622 if ( video->physpal ) {
623 free(video->physpal->colors);
624 free(video->physpal);
625 video->physpal = NULL;
627 if( video->gammacols) {
628 free(video->gammacols);
629 video->gammacols = NULL;
632 /* Save the previous grab state and turn off grab for mode switch */
633 saved_grab = SDL_WM_GrabInputOff();
635 /* Try to set the video mode, along with offset and clipping */
636 prev_mode = SDL_VideoSurface;
638 SDL_VideoSurface = NULL; /* In case it's freed by driver */
639 mode = video->SetVideoMode(this, prev_mode,video_w,video_h,video_bpp,flags);
640 if ( mode ) { /* Prevent resize events from mode change */
641 SDL_PrivateResize(mode->w, mode->h);
643 /* Sam - If we asked for OpenGL mode, and didn't get it, fail */
644 if ( is_opengl && !(mode->flags & SDL_OPENGL) ) {
650 * If you try to set an SDL_OPENGL surface, and fail to find a
651 * matching visual, then the next call to SDL_SetVideoMode()
652 * will segfault, since we no longer point to a dummy surface,
655 * WARNING, we need to make sure that the previous mode hasn't
656 * already been freed by the video driver. What do we do in
657 * that case? Should we call SDL_VideoInit() again?
659 SDL_VideoSurface = (mode != NULL) ? mode : prev_mode;
661 if ( (mode != NULL) && (!is_opengl) ) {
663 if ( (mode->w < width) || (mode->h < height) ) {
664 SDL_SetError("Video mode smaller than requested");
668 /* If we have a palettized surface, create a default palette */
669 if ( mode->format->palette ) {
670 SDL_PixelFormat *vf = mode->format;
671 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel);
672 video->SetColors(this, 0, vf->palette->ncolors,
673 vf->palette->colors);
676 /* Clear the surface to black */
680 SDL_SetClipRect(mode, NULL);
681 SDL_ClearSurface(mode);
683 /* Now adjust the offsets to match the desired mode */
684 video->offset_x = (mode->w-width)/2;
685 video->offset_y = (mode->h-height)/2;
686 mode->offset = video->offset_y*mode->pitch +
687 video->offset_x*mode->format->BytesPerPixel;
690 "Requested mode: %dx%dx%d, obtained mode %dx%dx%d (offset %d)\n",
692 mode->w, mode->h, mode->format->BitsPerPixel, mode->offset);
696 SDL_SetClipRect(mode, NULL);
701 /* If we failed setting a video mode, return NULL... (Uh Oh!) */
702 if ( mode == NULL ) {
706 /* If there is no window manager, set the SDL_NOFRAME flag */
707 if ( ! video->info.wm_available ) {
708 mode->flags |= SDL_NOFRAME;
711 /* Reset the mouse cursor and grab for new video mode */
713 if ( video->UpdateMouse ) {
714 video->UpdateMouse(this);
716 SDL_WM_GrabInput(saved_grab);
717 SDL_GetRelativeMouseState(NULL, NULL); /* Clear first large delta */
719 /* If we're running OpenGL, make the context current */
720 if ( (video->screen->flags & SDL_OPENGL) &&
721 video->GL_MakeCurrent ) {
722 if ( video->GL_MakeCurrent(this) < 0 ) {
727 /* Set up a fake SDL surface for OpenGL "blitting" */
728 if ( (flags & SDL_OPENGLBLIT) == SDL_OPENGLBLIT ) {
729 /* Load GL functions for performing the texture updates */
731 #define SDL_PROC(ret,func,params) \
733 video->func = SDL_GL_GetProcAddress(#func); \
734 if ( ! video->func ) { \
735 SDL_SetError("Couldn't load GL function: %s\n", #func); \
739 #include "SDL_glfuncs.h"
742 /* Create a software surface for blitting */
743 #ifdef GL_VERSION_1_2
744 /* If the implementation either supports the packed pixels
745 extension, or implements the core OpenGL 1.2 API, it will
746 support the GL_UNSIGNED_SHORT_5_6_5 texture format.
749 (strstr((const char *)video->glGetString(GL_EXTENSIONS), "GL_EXT_packed_pixels") ||
750 (atof((const char *)video->glGetString(GL_VERSION)) >= 1.2f))
753 SDL_VideoSurface = SDL_CreateRGBSurface(
765 #endif /* OpenGL 1.2 */
768 SDL_VideoSurface = SDL_CreateRGBSurface(
773 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
786 if ( ! SDL_VideoSurface ) {
789 SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT;
791 /* Free the original video mode surface (is this safe?) */
792 SDL_FreeSurface(mode);
794 /* Set the surface completely opaque & white by default */
795 memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch );
796 video->glGenTextures( 1, &video->texture );
797 video->glBindTexture( GL_TEXTURE_2D, video->texture );
801 video->is_32bit ? GL_RGBA : GL_RGB,
805 video->is_32bit ? GL_RGBA : GL_RGB,
806 #ifdef GL_VERSION_1_2
807 video->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,
813 video->UpdateRects = SDL_GL_UpdateRectsLock;
815 SDL_SetError("Somebody forgot to #define HAVE_OPENGL");
820 /* Create a shadow surface if necessary */
821 /* There are three conditions under which we create a shadow surface:
822 1. We need a particular bits-per-pixel that we didn't get.
823 2. We need a hardware palette and didn't get one.
824 3. We need a software surface and got a hardware surface.
826 if ( !(SDL_VideoSurface->flags & SDL_OPENGL) &&
828 ( !(flags&SDL_ANYFORMAT) &&
829 (SDL_VideoSurface->format->BitsPerPixel != bpp)) ||
830 ( (flags&SDL_HWPALETTE) &&
831 !(SDL_VideoSurface->flags&SDL_HWPALETTE)) ||
832 /* If the surface is in hardware, video writes are visible
833 as soon as they are performed, so we need to buffer them
835 ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) &&
836 (SDL_VideoSurface->flags&SDL_HWSURFACE))
838 SDL_CreateShadowSurface(bpp);
839 if ( SDL_ShadowSurface == NULL ) {
840 SDL_SetError("Couldn't create shadow surface");
843 SDL_PublicSurface = SDL_ShadowSurface;
845 SDL_PublicSurface = SDL_VideoSurface;
847 video->info.vfmt = SDL_VideoSurface->format;
850 return(SDL_PublicSurface);
854 * Convert a surface into the video pixel format.
856 SDL_Surface * SDL_DisplayFormat (SDL_Surface *surface)
860 if ( ! SDL_PublicSurface ) {
861 SDL_SetError("No video mode has been set");
864 /* Set the flags appropriate for copying to display surface */
865 if (((SDL_PublicSurface->flags&SDL_HWSURFACE) == SDL_HWSURFACE) && current_video->info.blit_hw)
866 flags = SDL_HWSURFACE;
868 flags = SDL_SWSURFACE;
869 #ifdef AUTORLE_DISPLAYFORMAT
870 flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA));
871 flags |= SDL_RLEACCELOK;
873 flags |= surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA|SDL_RLEACCELOK);
875 return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));
879 * Convert a surface into a format that's suitable for blitting to
880 * the screen, but including an alpha channel.
882 SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface)
885 SDL_PixelFormat *format;
886 SDL_Surface *converted;
888 /* default to ARGB8888 */
889 Uint32 amask = 0xff000000;
890 Uint32 rmask = 0x00ff0000;
891 Uint32 gmask = 0x0000ff00;
892 Uint32 bmask = 0x000000ff;
894 if ( ! SDL_PublicSurface ) {
895 SDL_SetError("No video mode has been set");
898 vf = SDL_PublicSurface->format;
900 switch(vf->BytesPerPixel) {
902 /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
903 For anything else (like ARGB4444) it doesn't matter
904 since we have no special code for it anyway */
905 if ( (vf->Rmask == 0x1f) &&
906 (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
914 /* Keep the video format, as long as the high 8 bits are
916 if ( (vf->Rmask == 0xff) && (vf->Bmask == 0xff0000) ) {
923 /* We have no other optimised formats right now. When/if a new
924 optimised alpha format is written, add the converter here */
927 format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
928 flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
929 flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
930 converted = SDL_ConvertSurface(surface, format, flags);
931 SDL_FreeFormat(format);
936 * Update a specific portion of the physical screen
938 void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
943 /* Perform some checking */
948 if ( (int)(x+w) > screen->w )
950 if ( (int)(y+h) > screen->h )
953 /* Fill the rectangle */
958 SDL_UpdateRects(screen, 1, &rect);
961 void SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects)
964 SDL_VideoDevice *video = current_video;
965 SDL_VideoDevice *this = current_video;
967 if ( screen == SDL_ShadowSurface ) {
968 /* Blit the shadow surface using saved mapping */
969 SDL_Palette *pal = screen->format->palette;
970 SDL_Color *saved_colors = NULL;
971 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) {
972 /* simulated 8bpp, use correct physical palette */
973 saved_colors = pal->colors;
974 if ( video->gammacols ) {
975 /* gamma-corrected palette */
976 pal->colors = video->gammacols;
977 } else if ( video->physpal ) {
978 /* physical palette different from logical */
979 pal->colors = video->physpal->colors;
982 if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
984 SDL_DrawCursor(SDL_ShadowSurface);
985 for ( i=0; i<numrects; ++i ) {
986 SDL_LowerBlit(SDL_ShadowSurface, &rects[i],
987 SDL_VideoSurface, &rects[i]);
989 SDL_EraseCursor(SDL_ShadowSurface);
992 for ( i=0; i<numrects; ++i ) {
993 SDL_LowerBlit(SDL_ShadowSurface, &rects[i],
994 SDL_VideoSurface, &rects[i]);
998 pal->colors = saved_colors;
1000 /* Fall through to video surface update */
1001 screen = SDL_VideoSurface;
1003 if ( screen == SDL_VideoSurface ) {
1004 /* Update the video surface */
1005 if ( screen->offset ) {
1006 for ( i=0; i<numrects; ++i ) {
1007 rects[i].x += video->offset_x;
1008 rects[i].y += video->offset_y;
1010 video->UpdateRects(this, numrects, rects);
1011 for ( i=0; i<numrects; ++i ) {
1012 rects[i].x -= video->offset_x;
1013 rects[i].y -= video->offset_y;
1016 video->UpdateRects(this, numrects, rects);
1022 * Performs hardware double buffering, if possible, or a full update if not.
1024 int SDL_Flip(SDL_Surface *screen)
1026 SDL_VideoDevice *video = current_video;
1027 /* Copy the shadow surface to the video surface */
1028 if ( screen == SDL_ShadowSurface ) {
1030 SDL_Palette *pal = screen->format->palette;
1031 SDL_Color *saved_colors = NULL;
1032 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) {
1033 /* simulated 8bpp, use correct physical palette */
1034 saved_colors = pal->colors;
1035 if ( video->gammacols ) {
1036 /* gamma-corrected palette */
1037 pal->colors = video->gammacols;
1038 } else if ( video->physpal ) {
1039 /* physical palette different from logical */
1040 pal->colors = video->physpal->colors;
1048 SDL_LowerBlit(SDL_ShadowSurface,&rect, SDL_VideoSurface,&rect);
1051 pal->colors = saved_colors;
1052 screen = SDL_VideoSurface;
1054 if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
1055 SDL_VideoDevice *this = current_video;
1056 return(video->FlipHWSurface(this, SDL_VideoSurface));
1058 SDL_UpdateRect(screen, 0, 0, 0, 0);
1063 static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors,
1064 int firstcolor, int ncolors)
1066 SDL_Palette *pal = screen->format->palette;
1067 SDL_Palette *vidpal;
1069 if ( colors != (pal->colors + firstcolor) ) {
1070 memcpy(pal->colors + firstcolor, colors,
1071 ncolors * sizeof(*colors));
1074 vidpal = SDL_VideoSurface->format->palette;
1075 if ( (screen == SDL_ShadowSurface) && vidpal ) {
1077 * This is a shadow surface, and the physical
1078 * framebuffer is also indexed. Propagate the
1079 * changes to its logical palette so that
1080 * updates are always identity blits
1082 memcpy(vidpal->colors + firstcolor, colors,
1083 ncolors * sizeof(*colors));
1085 SDL_FormatChanged(screen);
1088 static int SetPalette_physical(SDL_Surface *screen,
1089 SDL_Color *colors, int firstcolor, int ncolors)
1091 SDL_VideoDevice *video = current_video;
1094 if ( video->physpal ) {
1095 /* We need to copy the new colors, since we haven't
1096 * already done the copy in the logical set above.
1098 memcpy(video->physpal->colors + firstcolor,
1099 colors, ncolors * sizeof(*colors));
1101 if ( screen == SDL_ShadowSurface ) {
1102 if ( SDL_VideoSurface->flags & SDL_HWPALETTE ) {
1104 * The real screen is also indexed - set its physical
1105 * palette. The physical palette does not include the
1106 * gamma modification, we apply it directly instead,
1107 * but this only happens if we have hardware palette.
1109 screen = SDL_VideoSurface;
1112 * The video surface is not indexed - invalidate any
1113 * active shadow-to-video blit mappings.
1115 if ( screen->map->dst == SDL_VideoSurface ) {
1116 SDL_InvalidateMap(screen->map);
1118 if ( video->gamma ) {
1119 if( ! video->gammacols ) {
1120 SDL_Palette *pp = video->physpal;
1122 pp = screen->format->palette;
1123 video->gammacols = malloc(pp->ncolors
1124 * sizeof(SDL_Color));
1125 SDL_ApplyGamma(video->gamma,
1130 SDL_ApplyGamma(video->gamma, colors,
1136 SDL_UpdateRect(screen, 0, 0, 0, 0);
1140 if ( screen == SDL_VideoSurface ) {
1141 SDL_Color gcolors[256];
1143 if ( video->gamma ) {
1144 SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors);
1147 gotall = video->SetColors(video, firstcolor, ncolors, colors);
1149 /* The video flags shouldn't have SDL_HWPALETTE, and
1150 the video driver is responsible for copying back the
1151 correct colors into the video surface palette.
1155 SDL_CursorPaletteChanged();
1161 * Set the physical and/or logical colormap of a surface:
1162 * Only the screen has a physical colormap. It determines what is actually
1163 * sent to the display.
1164 * The logical colormap is used to map blits to/from the surface.
1165 * 'which' is one or both of SDL_LOGPAL, SDL_PHYSPAL
1167 * Return nonzero if all colours were set as requested, or 0 otherwise.
1169 int SDL_SetPalette(SDL_Surface *screen, int which,
1170 SDL_Color *colors, int firstcolor, int ncolors)
1176 if ( ! current_video ) {
1179 if ( screen != SDL_PublicSurface ) {
1180 /* only screens have physical palettes */
1181 which &= ~SDL_PHYSPAL;
1182 } else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) {
1183 /* hardware palettes required for split colormaps */
1184 which |= SDL_PHYSPAL | SDL_LOGPAL;
1187 /* Verify the parameters */
1188 pal = screen->format->palette;
1190 return 0; /* not a palettized surface */
1193 palsize = 1 << screen->format->BitsPerPixel;
1194 if ( ncolors > (palsize - firstcolor) ) {
1195 ncolors = (palsize - firstcolor);
1199 if ( which & SDL_LOGPAL ) {
1201 * Logical palette change: The actual screen isn't affected,
1202 * but the internal colormap is altered so that the
1203 * interpretation of the pixel values (for blits etc) is
1206 SetPalette_logical(screen, colors, firstcolor, ncolors);
1208 if ( which & SDL_PHYSPAL ) {
1209 SDL_VideoDevice *video = current_video;
1211 * Physical palette change: This doesn't affect the
1212 * program's idea of what the screen looks like, but changes
1213 * its actual appearance.
1216 return gotall; /* video not yet initialized */
1217 if(!video->physpal && !(which & SDL_LOGPAL) ) {
1218 /* Lazy physical palette allocation */
1220 SDL_Palette *pp = malloc(sizeof(*pp));
1221 current_video->physpal = pp;
1222 pp->ncolors = pal->ncolors;
1223 size = pp->ncolors * sizeof(SDL_Color);
1224 pp->colors = malloc(size);
1225 memcpy(pp->colors, pal->colors, size);
1227 if ( ! SetPalette_physical(screen,
1228 colors, firstcolor, ncolors) ) {
1235 int SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor,
1238 return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL,
1239 colors, firstcolor, ncolors);
1243 * Clean up the video subsystem
1245 void SDL_VideoQuit (void)
1247 SDL_Surface *ready_to_go;
1249 if ( current_video ) {
1250 SDL_VideoDevice *video = current_video;
1251 SDL_VideoDevice *this = current_video;
1253 /* Halt event processing before doing anything else */
1254 SDL_StopEventLoop();
1256 /* Clean up allocated window manager items */
1257 if ( SDL_PublicSurface ) {
1258 SDL_PublicSurface = NULL;
1262 /* Just in case... */
1263 SDL_WM_GrabInputOff();
1265 /* Clean up the system video */
1266 video->VideoQuit(this);
1268 /* Free any lingering surfaces */
1269 ready_to_go = SDL_ShadowSurface;
1270 SDL_ShadowSurface = NULL;
1271 SDL_FreeSurface(ready_to_go);
1272 if ( SDL_VideoSurface != NULL ) {
1273 ready_to_go = SDL_VideoSurface;
1274 SDL_VideoSurface = NULL;
1275 SDL_FreeSurface(ready_to_go);
1277 SDL_PublicSurface = NULL;
1279 /* Clean up miscellaneous memory */
1280 if ( video->physpal ) {
1281 free(video->physpal->colors);
1282 free(video->physpal);
1283 video->physpal = NULL;
1285 if ( video->gammacols ) {
1286 free(video->gammacols);
1287 video->gammacols = NULL;
1289 if ( video->gamma ) {
1291 video->gamma = NULL;
1293 if ( video->wm_title != NULL ) {
1294 free(video->wm_title);
1295 video->wm_title = NULL;
1297 if ( video->wm_icon != NULL ) {
1298 free(video->wm_icon);
1299 video->wm_icon = NULL;
1302 /* Finish cleaning up video subsystem */
1304 current_video = NULL;
1309 /* Load the GL driver library */
1310 int SDL_GL_LoadLibrary(const char *path)
1312 SDL_VideoDevice *video = current_video;
1313 SDL_VideoDevice *this = current_video;
1317 if ( video == NULL ) {
1318 SDL_SetError("Video subsystem has not been initialized");
1320 if ( video->GL_LoadLibrary ) {
1321 retval = video->GL_LoadLibrary(this, path);
1323 SDL_SetError("No dynamic GL support in video driver");
1329 void *SDL_GL_GetProcAddress(const char* proc)
1331 SDL_VideoDevice *video = current_video;
1332 SDL_VideoDevice *this = current_video;
1336 if ( video->GL_GetProcAddress ) {
1337 if ( video->gl_config.driver_loaded ) {
1338 func = video->GL_GetProcAddress(this, proc);
1340 SDL_SetError("No GL driver has been loaded");
1343 SDL_SetError("No dynamic GL support in video driver");
1348 /* Set the specified GL attribute for setting up a GL video mode */
1349 int SDL_GL_SetAttribute( SDL_GLattr attr, int value )
1352 SDL_VideoDevice *video = current_video;
1356 case SDL_GL_RED_SIZE:
1357 video->gl_config.red_size = value;
1359 case SDL_GL_GREEN_SIZE:
1360 video->gl_config.green_size = value;
1362 case SDL_GL_BLUE_SIZE:
1363 video->gl_config.blue_size = value;
1365 case SDL_GL_ALPHA_SIZE:
1366 video->gl_config.alpha_size = value;
1368 case SDL_GL_DOUBLEBUFFER:
1369 video->gl_config.double_buffer = value;
1371 case SDL_GL_BUFFER_SIZE:
1372 video->gl_config.buffer_size = value;
1374 case SDL_GL_DEPTH_SIZE:
1375 video->gl_config.depth_size = value;
1377 case SDL_GL_STENCIL_SIZE:
1378 video->gl_config.stencil_size = value;
1380 case SDL_GL_ACCUM_RED_SIZE:
1381 video->gl_config.accum_red_size = value;
1383 case SDL_GL_ACCUM_GREEN_SIZE:
1384 video->gl_config.accum_green_size = value;
1386 case SDL_GL_ACCUM_BLUE_SIZE:
1387 video->gl_config.accum_blue_size = value;
1389 case SDL_GL_ACCUM_ALPHA_SIZE:
1390 video->gl_config.accum_alpha_size = value;
1393 video->gl_config.stereo = value;
1396 SDL_SetError("Unknown OpenGL attribute");
1403 /* Retrieve an attribute value from the windowing system. */
1404 int SDL_GL_GetAttribute(SDL_GLattr attr, int* value)
1407 SDL_VideoDevice* video = current_video;
1408 SDL_VideoDevice* this = current_video;
1410 if ( video->GL_GetAttribute ) {
1411 retval = this->GL_GetAttribute(this, attr, value);
1414 SDL_SetError("GL_GetAttribute not supported");
1419 /* Perform a GL buffer swap on the current GL context */
1420 void SDL_GL_SwapBuffers(void)
1422 SDL_VideoDevice *video = current_video;
1423 SDL_VideoDevice *this = current_video;
1425 if ( video->screen->flags & SDL_OPENGL ) {
1426 video->GL_SwapBuffers(this);
1428 SDL_SetError("OpenGL video mode has not been set");
1432 /* Update rects with locking */
1433 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects)
1436 SDL_GL_UpdateRects(numrects, rects);
1440 /* Update rects without state setting and changing (the caller is responsible for it) */
1441 void SDL_GL_UpdateRects(int numrects, SDL_Rect *rects)
1444 SDL_VideoDevice *this = current_video;
1445 SDL_Rect update, tmp;
1448 for ( i = 0; i < numrects; i++ )
1452 for ( y = 0; y <= rects[i].h / 256; y++ )
1456 for ( x = 0; x <= rects[i].w / 256; x++ )
1463 if ( update.w > 256 )
1466 if ( update.h > 256 )
1470 this->glTexSubImage2D(
1477 this->is_32bit? GL_RGBA : GL_RGB,
1478 #ifdef GL_VERSION_1_2
1479 this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,
1483 (Uint8 *)this->screen->pixels +
1484 this->screen->format->BytesPerPixel * update.x +
1485 update.y * this->screen->pitch );
1489 * Note the parens around the function name:
1490 * This is because some OpenGL implementations define glTexCoord etc
1491 * as macros, and we don't want them expanded here.
1493 this->glBegin(GL_TRIANGLE_STRIP);
1494 (this->glTexCoord2f)( 0.0, 0.0 );
1495 (this->glVertex2i)( update.x, update.y );
1496 (this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 );
1497 (this->glVertex2i)( update.x + update.w, update.y );
1498 (this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) );
1499 (this->glVertex2i)( update.x, update.y + update.h );
1500 (this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) );
1501 (this->glVertex2i)( update.x + update.w , update.y + update.h );
1514 /* Lock == save current state */
1521 SDL_VideoDevice *this = current_video;
1523 this->glPushAttrib( GL_ALL_ATTRIB_BITS ); /* TODO: narrow range of what is saved */
1524 #ifdef GL_CLIENT_PIXEL_STORE_BIT
1525 this->glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
1528 this->glEnable(GL_TEXTURE_2D);
1529 this->glEnable(GL_BLEND);
1530 this->glDisable(GL_FOG);
1531 this->glDisable(GL_ALPHA_TEST);
1532 this->glDisable(GL_DEPTH_TEST);
1533 this->glDisable(GL_SCISSOR_TEST);
1534 this->glDisable(GL_STENCIL_TEST);
1535 this->glDisable(GL_CULL_FACE);
1537 this->glBindTexture( GL_TEXTURE_2D, this->texture );
1538 this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1539 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1540 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1541 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
1542 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
1544 this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel );
1545 this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1546 (this->glColor4f)(1.0, 1.0, 1.0, 1.0); /* Solaris workaround */
1548 this->glViewport(0, 0, this->screen->w, this->screen->h);
1549 this->glMatrixMode(GL_PROJECTION);
1550 this->glPushMatrix();
1551 this->glLoadIdentity();
1553 this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0);
1555 this->glMatrixMode(GL_MODELVIEW);
1556 this->glPushMatrix();
1557 this->glLoadIdentity();
1562 /* Unlock == restore saved state */
1563 void SDL_GL_Unlock()
1569 SDL_VideoDevice *this = current_video;
1571 this->glPopMatrix();
1572 this->glMatrixMode(GL_PROJECTION);
1573 this->glPopMatrix();
1575 this->glPopClientAttrib();
1576 this->glPopAttrib();
1582 * Sets/Gets the title and icon text of the display window, if any.
1584 void SDL_WM_SetCaption (const char *title, const char *icon)
1586 SDL_VideoDevice *video = current_video;
1587 SDL_VideoDevice *this = current_video;
1591 if ( video->wm_title ) {
1592 free(video->wm_title);
1594 video->wm_title = (char *)malloc(strlen(title)+1);
1595 if ( video->wm_title != NULL ) {
1596 strcpy(video->wm_title, title);
1600 if ( video->wm_icon ) {
1601 free(video->wm_icon);
1603 video->wm_icon = (char *)malloc(strlen(icon)+1);
1604 if ( video->wm_icon != NULL ) {
1605 strcpy(video->wm_icon, icon);
1608 if ( (title || icon) && (video->SetCaption != NULL) ) {
1609 video->SetCaption(this, video->wm_title,video->wm_icon);
1613 void SDL_WM_GetCaption (char **title, char **icon)
1615 SDL_VideoDevice *video = current_video;
1619 *title = video->wm_title;
1622 *icon = video->wm_icon;
1627 /* Utility function used by SDL_WM_SetIcon() */
1628 static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask)
1632 #define SET_MASKBIT(icon, x, y, mask) \
1633 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
1635 colorkey = icon->format->colorkey;
1636 switch (icon->format->BytesPerPixel) {
1637 case 1: { Uint8 *pixels;
1638 for ( y=0; y<icon->h; ++y ) {
1639 pixels = (Uint8 *)icon->pixels + y*icon->pitch;
1640 for ( x=0; x<icon->w; ++x ) {
1641 if ( *pixels++ == colorkey ) {
1642 SET_MASKBIT(icon, x, y, mask);
1649 case 2: { Uint16 *pixels;
1650 for ( y=0; y<icon->h; ++y ) {
1651 pixels = (Uint16 *)icon->pixels +
1653 for ( x=0; x<icon->w; ++x ) {
1654 if ( *pixels++ == colorkey ) {
1655 SET_MASKBIT(icon, x, y, mask);
1662 case 4: { Uint32 *pixels;
1663 for ( y=0; y<icon->h; ++y ) {
1664 pixels = (Uint32 *)icon->pixels +
1666 for ( x=0; x<icon->w; ++x ) {
1667 if ( *pixels++ == colorkey ) {
1668 SET_MASKBIT(icon, x, y, mask);
1678 * Sets the window manager icon for the display window.
1680 void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask)
1682 SDL_VideoDevice *video = current_video;
1683 SDL_VideoDevice *this = current_video;
1685 if ( icon && video->SetIcon ) {
1686 /* Generate a mask if necessary, and create the icon! */
1687 if ( mask == NULL ) {
1688 int mask_len = icon->h*(icon->w+7)/8;
1689 mask = (Uint8 *)malloc(mask_len);
1690 if ( mask == NULL ) {
1693 memset(mask, ~0, mask_len);
1694 if ( icon->flags & SDL_SRCCOLORKEY ) {
1695 CreateMaskFromColorKey(icon, mask);
1697 video->SetIcon(video, icon, mask);
1700 video->SetIcon(this, icon, mask);
1706 * Grab or ungrab the keyboard and mouse input.
1707 * This function returns the final grab mode after calling the
1708 * driver dependent function.
1710 static SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode)
1712 SDL_VideoDevice *video = current_video;
1713 SDL_VideoDevice *this = current_video;
1715 /* Only do something if we have support for grabs */
1716 if ( video->GrabInput == NULL ) {
1717 return(video->input_grab);
1720 /* If the final grab mode if off, only then do we actually grab */
1722 printf("SDL_WM_GrabInputRaw(%d) ... ", mode);
1724 if ( mode == SDL_GRAB_OFF ) {
1725 if ( video->input_grab != SDL_GRAB_OFF ) {
1726 mode = video->GrabInput(this, mode);
1729 if ( video->input_grab == SDL_GRAB_OFF ) {
1730 mode = video->GrabInput(this, mode);
1733 if ( mode != video->input_grab ) {
1734 video->input_grab = mode;
1735 if ( video->CheckMouseMode ) {
1736 video->CheckMouseMode(this);
1740 printf("Final mode %d\n", video->input_grab);
1743 /* Return the final grab state */
1744 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1745 mode -= SDL_GRAB_FULLSCREEN;
1749 SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode)
1751 SDL_VideoDevice *video = current_video;
1753 /* If the video isn't initialized yet, we can't do anything */
1755 return SDL_GRAB_OFF;
1758 /* Return the current mode on query */
1759 if ( mode == SDL_GRAB_QUERY ) {
1760 mode = video->input_grab;
1761 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1762 mode -= SDL_GRAB_FULLSCREEN;
1768 printf("SDL_WM_GrabInput(%d) ... ", mode);
1770 /* If the video surface is fullscreen, we always grab */
1771 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1772 mode -= SDL_GRAB_FULLSCREEN;
1774 if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {
1775 mode += SDL_GRAB_FULLSCREEN;
1777 return(SDL_WM_GrabInputRaw(mode));
1779 static SDL_GrabMode SDL_WM_GrabInputOff(void)
1783 /* First query the current grab state */
1784 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
1786 /* Now explicitly turn off input grab */
1787 SDL_WM_GrabInputRaw(SDL_GRAB_OFF);
1789 /* Return the old state */
1794 * Iconify the window in window managed environments.
1795 * A successful iconification will result in an SDL_APPACTIVE loss event.
1797 int SDL_WM_IconifyWindow(void)
1799 SDL_VideoDevice *video = current_video;
1800 SDL_VideoDevice *this = current_video;
1804 if ( video->IconifyWindow ) {
1805 retval = video->IconifyWindow(this);
1811 * Toggle fullscreen mode
1813 int SDL_WM_ToggleFullScreen(SDL_Surface *surface)
1815 SDL_VideoDevice *video = current_video;
1816 SDL_VideoDevice *this = current_video;
1820 if ( SDL_PublicSurface && (surface == SDL_PublicSurface) &&
1821 video->ToggleFullScreen ) {
1822 if ( surface->flags & SDL_FULLSCREEN ) {
1823 toggled = video->ToggleFullScreen(this, 0);
1825 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN;
1826 SDL_PublicSurface->flags &= ~SDL_FULLSCREEN;
1829 toggled = video->ToggleFullScreen(this, 1);
1831 SDL_VideoSurface->flags |= SDL_FULLSCREEN;
1832 SDL_PublicSurface->flags |= SDL_FULLSCREEN;
1835 /* Double-check the grab state inside SDL_WM_GrabInput() */
1837 SDL_WM_GrabInput(video->input_grab);
1844 * Get some platform dependent window manager information
1846 int SDL_GetWMInfo (SDL_SysWMinfo *info)
1848 SDL_VideoDevice *video = current_video;
1849 SDL_VideoDevice *this = current_video;
1851 if ( video && video->GetWMInfo ) {
1852 return(video->GetWMInfo(this, info));