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[] = {
63 #ifdef ENABLE_DIRECTFB
93 #ifdef ENABLE_DRAWSPROCKET
99 #ifdef ENABLE_CYBERGRAPHICS
108 #ifdef ENABLE_DUMMYVIDEO
117 #ifdef ENABLE_PICOGUI
126 SDL_VideoDevice *current_video = NULL;
128 /* Various local functions */
129 int SDL_VideoInit(const char *driver_name, Uint32 flags);
130 void SDL_VideoQuit(void);
131 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect* rects);
133 static SDL_GrabMode SDL_WM_GrabInputOff(void);
135 static int lock_count = 0;
140 * Initialize the video and event subsystems -- determine native pixel format
142 int SDL_VideoInit (const char *driver_name, Uint32 flags)
144 SDL_VideoDevice *video;
147 SDL_PixelFormat vformat;
150 /* Toggle the event thread flags, based on OS requirements */
151 #if defined(MUST_THREAD_EVENTS)
152 flags |= SDL_INIT_EVENTTHREAD;
153 #elif defined(CANT_THREAD_EVENTS)
154 if ( (flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) {
155 SDL_SetError("OS doesn't support threaded events");
160 /* Check to make sure we don't overwrite 'current_video' */
161 if ( current_video != NULL ) {
165 /* Select the proper video driver */
168 if ( driver_name != NULL ) {
169 #if 0 /* This will be replaced with a better driver selection API */
170 if ( strrchr(driver_name, ':') != NULL ) {
171 index = atoi(strrchr(driver_name, ':')+1);
174 for ( i=0; bootstrap[i]; ++i ) {
175 if ( strncmp(bootstrap[i]->name, driver_name,
176 strlen(bootstrap[i]->name)) == 0 ) {
177 if ( bootstrap[i]->available() ) {
178 video = bootstrap[i]->create(index);
184 for ( i=0; bootstrap[i]; ++i ) {
185 if ( bootstrap[i]->available() ) {
186 video = bootstrap[i]->create(index);
187 if ( video != NULL ) {
193 if ( video == NULL ) {
194 SDL_SetError("No available video device");
197 current_video = video;
198 current_video->name = bootstrap[i]->name;
200 /* Do some basic variable initialization */
201 video->screen = NULL;
202 video->shadow = NULL;
203 video->visible = NULL;
204 video->physpal = NULL;
205 video->gammacols = NULL;
207 video->wm_title = NULL;
208 video->wm_icon = NULL;
211 memset(&video->info, 0, (sizeof video->info));
213 /* Set some very sane GL defaults */
214 video->gl_config.driver_loaded = 0;
215 video->gl_config.dll_handle = NULL;
216 video->gl_config.red_size = 5;
217 #if 1 /* This seems to work on more video cards, as a default */
218 video->gl_config.green_size = 5;
220 video->gl_config.green_size = 6;
222 video->gl_config.blue_size = 5;
223 video->gl_config.alpha_size = 0;
224 video->gl_config.buffer_size = 0;
225 video->gl_config.depth_size = 16;
226 video->gl_config.stencil_size = 0;
227 video->gl_config.double_buffer = 1;
228 video->gl_config.accum_red_size = 0;
229 video->gl_config.accum_green_size = 0;
230 video->gl_config.accum_blue_size = 0;
231 video->gl_config.accum_alpha_size = 0;
232 video->gl_config.stereo = 0;
234 /* Initialize the video subsystem */
235 memset(&vformat, 0, sizeof(vformat));
236 if ( video->VideoInit(video, &vformat) < 0 ) {
241 /* Create a zero sized video surface of the appropriate format */
242 video_flags = SDL_SWSURFACE;
243 SDL_VideoSurface = SDL_CreateRGBSurface(video_flags, 0, 0,
244 vformat.BitsPerPixel,
245 vformat.Rmask, vformat.Gmask, vformat.Bmask, 0);
246 if ( SDL_VideoSurface == NULL ) {
250 SDL_PublicSurface = NULL; /* Until SDL_SetVideoMode() */
252 #if 0 /* Don't change the current palette - may be used by other programs.
253 * The application can't do anything with the display surface until
254 * a video mode has been set anyway. :)
256 /* If we have a palettized surface, create a default palette */
257 if ( SDL_VideoSurface->format->palette ) {
258 SDL_PixelFormat *vf = SDL_VideoSurface->format;
259 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel);
260 video->SetColors(video,
261 0, vf->palette->ncolors, vf->palette->colors);
264 video->info.vfmt = SDL_VideoSurface->format;
266 /* Start the event loop */
267 if ( SDL_StartEventLoop(flags) < 0 ) {
271 SDL_CursorInit(flags & SDL_INIT_EVENTTHREAD);
273 /* We're ready to go! */
277 char *SDL_VideoDriverName(char *namebuf, int maxlen)
279 if ( current_video != NULL ) {
280 strncpy(namebuf, current_video->name, maxlen-1);
281 namebuf[maxlen-1] = '\0';
288 * Get the current display surface
290 SDL_Surface *SDL_GetVideoSurface(void)
292 SDL_Surface *visible;
295 if ( current_video ) {
296 visible = current_video->visible;
302 * Get the current information about the video hardware
304 const SDL_VideoInfo *SDL_GetVideoInfo(void)
306 const SDL_VideoInfo *info;
309 if ( current_video ) {
310 info = ¤t_video->info;
316 * Return a pointer to an array of available screen dimensions for the
317 * given format, sorted largest to smallest. Returns NULL if there are
318 * no dimensions available for a particular format, or (SDL_Rect **)-1
319 * if any dimension is okay for the given format. If 'format' is NULL,
320 * the mode list will be for the format given by SDL_GetVideoInfo()->vfmt
322 SDL_Rect ** SDL_ListModes (SDL_PixelFormat *format, Uint32 flags)
324 SDL_VideoDevice *video = current_video;
325 SDL_VideoDevice *this = current_video;
329 if ( SDL_VideoSurface ) {
330 if ( format == NULL ) {
331 format = SDL_VideoSurface->format;
333 modes = video->ListModes(this, format, flags);
339 * Check to see if a particular video mode is supported.
340 * It returns 0 if the requested mode is not supported under any bit depth,
341 * or returns the bits-per-pixel of the closest available mode with the
342 * given width and height. If this bits-per-pixel is different from the
343 * one used when setting the video mode, SDL_SetVideoMode() will succeed,
344 * but will emulate the requested bits-per-pixel with a shadow surface.
346 static Uint8 SDL_closest_depths[4][8] = {
347 /* 8 bit closest depth ordering */
348 { 0, 8, 16, 15, 32, 24, 0, 0 },
349 /* 15,16 bit closest depth ordering */
350 { 0, 16, 15, 32, 24, 8, 0, 0 },
351 /* 24 bit closest depth ordering */
352 { 0, 24, 32, 16, 15, 8, 0, 0 },
353 /* 32 bit closest depth ordering */
354 { 0, 32, 16, 15, 24, 8, 0, 0 }
357 int SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags)
361 SDL_PixelFormat format;
364 /* Currently 1 and 4 bpp are not supported */
365 if ( bpp < 8 || bpp > 32 ) {
368 if ( (width <= 0) || (height <= 0) ) {
372 /* Search through the list valid of modes */
373 memset(&format, 0, sizeof(format));
375 table = ((bpp+7)/8)-1;
376 SDL_closest_depths[table][0] = bpp;
377 SDL_closest_depths[table][7] = 0;
378 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
379 format.BitsPerPixel = SDL_closest_depths[table][b];
380 sizes = SDL_ListModes(&format, flags);
381 if ( sizes == (SDL_Rect **)0 ) {
382 /* No sizes supported at this bit-depth */
385 #ifdef macintosh /* MPW optimization bug? */
386 if ( (sizes == (SDL_Rect **)0xFFFFFFFF) ||
388 if ( (sizes == (SDL_Rect **)-1) ||
390 current_video->handles_any_size ) {
391 /* Any size supported at this bit-depth */
395 for ( i=0; sizes[i]; ++i ) {
396 if ((sizes[i]->w == width) && (sizes[i]->h == height)) {
404 return(SDL_closest_depths[table][b]);
411 * Get the closest non-emulated video mode to the one requested
413 static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags)
418 SDL_PixelFormat format;
421 /* Check parameters */
422 if ( *BitsPerPixel < 8 || *BitsPerPixel > 32 ) {
423 SDL_SetError("Invalid bits per pixel (range is {8...32})");
426 if ((*w <= 0) || (*h <= 0)) {
427 SDL_SetError("Invalid width or height");
431 /* Try the original video mode, get the closest depth */
432 native_bpp = SDL_VideoModeOK(*w, *h, *BitsPerPixel, flags);
433 if ( native_bpp == *BitsPerPixel ) {
436 if ( native_bpp > 0 ) {
437 *BitsPerPixel = native_bpp;
441 /* No exact size match at any depth, look for closest match */
442 memset(&format, 0, sizeof(format));
444 table = ((*BitsPerPixel+7)/8)-1;
445 SDL_closest_depths[table][0] = *BitsPerPixel;
446 SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel;
447 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
448 format.BitsPerPixel = SDL_closest_depths[table][b];
449 sizes = SDL_ListModes(&format, flags);
450 if ( sizes == (SDL_Rect **)0 ) {
451 /* No sizes supported at this bit-depth */
454 for ( i=0; sizes[i]; ++i ) {
455 if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) {
460 *BitsPerPixel = SDL_closest_depths[table][b];
463 /* Largest mode too small... */;
468 if ( (i > 0) && ! sizes[i] ) {
469 /* The smallest mode was larger than requested, OK */
473 *BitsPerPixel = SDL_closest_depths[table][b];
478 SDL_SetError("No video mode large enough for %dx%d", *w, *h);
483 /* This should probably go somewhere else -- like SDL_surface.c */
484 static void SDL_ClearSurface(SDL_Surface *surface)
488 black = SDL_MapRGB(surface->format, 0, 0, 0);
489 SDL_FillRect(surface, NULL, black);
490 if ((surface->flags&SDL_HWSURFACE) && (surface->flags&SDL_DOUBLEBUF)) {
492 SDL_FillRect(surface, NULL, black);
498 * Create a shadow surface suitable for fooling the app. :-)
500 static void SDL_CreateShadowSurface(int depth)
502 Uint32 Rmask, Gmask, Bmask;
504 /* Allocate the shadow surface */
505 if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) {
506 Rmask = (SDL_VideoSurface->format)->Rmask;
507 Gmask = (SDL_VideoSurface->format)->Gmask;
508 Bmask = (SDL_VideoSurface->format)->Bmask;
510 Rmask = Gmask = Bmask = 0;
512 SDL_ShadowSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
513 SDL_VideoSurface->w, SDL_VideoSurface->h,
514 depth, Rmask, Gmask, Bmask, 0);
515 if ( SDL_ShadowSurface == NULL ) {
519 /* 8-bit shadow surfaces report that they have exclusive palette */
520 if ( SDL_ShadowSurface->format->palette ) {
521 SDL_ShadowSurface->flags |= SDL_HWPALETTE;
522 if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) {
523 memcpy(SDL_ShadowSurface->format->palette->colors,
524 SDL_VideoSurface->format->palette->colors,
525 SDL_VideoSurface->format->palette->ncolors*
529 SDL_ShadowSurface->format->palette->colors, depth);
533 /* If the video surface is resizable, the shadow should say so */
534 if ( (SDL_VideoSurface->flags & SDL_RESIZABLE) == SDL_RESIZABLE ) {
535 SDL_ShadowSurface->flags |= SDL_RESIZABLE;
537 /* If the video surface has no frame, the shadow should say so */
538 if ( (SDL_VideoSurface->flags & SDL_NOFRAME) == SDL_NOFRAME ) {
539 SDL_ShadowSurface->flags |= SDL_NOFRAME;
541 /* If the video surface is fullscreen, the shadow should say so */
542 if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
543 SDL_ShadowSurface->flags |= SDL_FULLSCREEN;
545 /* If the video surface is flippable, the shadow should say so */
546 if ( (SDL_VideoSurface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
547 SDL_ShadowSurface->flags |= SDL_DOUBLEBUF;
553 * Set the requested video mode, allocating a shadow buffer if necessary.
555 SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
557 SDL_VideoDevice *video, *this;
558 SDL_Surface *prev_mode, *mode;
563 SDL_GrabMode saved_grab;
565 /* Start up the video driver, if necessary..
566 WARNING: This is the only function protected this way!
568 if ( ! current_video ) {
569 if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 ) {
573 this = video = current_video;
575 /* Default to the current video bpp */
577 flags |= SDL_ANYFORMAT;
578 bpp = SDL_VideoSurface->format->BitsPerPixel;
581 /* Get a good video mode, the closest one possible */
585 if ( ! SDL_GetVideoMode(&video_w, &video_h, &video_bpp, flags) ) {
589 /* Check the requested flags */
590 /* There's no palette in > 8 bits-per-pixel mode */
591 if ( video_bpp > 8 ) {
592 flags &= ~SDL_HWPALETTE;
595 if ( (flags&SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
596 /* There's no windowed double-buffering */
597 flags &= ~SDL_DOUBLEBUF;
600 if ( (flags&SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
601 /* Use hardware surfaces when double-buffering */
602 flags |= SDL_HWSURFACE;
605 is_opengl = ( ( flags & SDL_OPENGL ) == SDL_OPENGL );
607 /* These flags are for 2D video modes only */
608 flags &= ~(SDL_HWSURFACE|SDL_DOUBLEBUF);
611 /* Reset the keyboard here so event callbacks can run */
615 /* Clean up any previous video mode */
616 if ( SDL_PublicSurface != NULL ) {
617 SDL_PublicSurface = NULL;
619 if ( SDL_ShadowSurface != NULL ) {
620 SDL_Surface *ready_to_go;
621 ready_to_go = SDL_ShadowSurface;
622 SDL_ShadowSurface = NULL;
623 SDL_FreeSurface(ready_to_go);
625 if ( video->physpal ) {
626 free(video->physpal->colors);
627 free(video->physpal);
628 video->physpal = NULL;
630 if( video->gammacols) {
631 free(video->gammacols);
632 video->gammacols = NULL;
635 /* Save the previous grab state and turn off grab for mode switch */
636 saved_grab = SDL_WM_GrabInputOff();
638 /* Try to set the video mode, along with offset and clipping */
639 prev_mode = SDL_VideoSurface;
641 SDL_VideoSurface = NULL; /* In case it's freed by driver */
642 mode = video->SetVideoMode(this, prev_mode,video_w,video_h,video_bpp,flags);
643 if ( mode ) { /* Prevent resize events from mode change */
644 SDL_PrivateResize(mode->w, mode->h);
646 /* Sam - If we asked for OpenGL mode, and didn't get it, fail */
647 if ( is_opengl && !(mode->flags & SDL_OPENGL) ) {
653 * If you try to set an SDL_OPENGL surface, and fail to find a
654 * matching visual, then the next call to SDL_SetVideoMode()
655 * will segfault, since we no longer point to a dummy surface,
658 * WARNING, we need to make sure that the previous mode hasn't
659 * already been freed by the video driver. What do we do in
660 * that case? Should we call SDL_VideoInit() again?
662 SDL_VideoSurface = (mode != NULL) ? mode : prev_mode;
664 if ( (mode != NULL) && (!is_opengl) ) {
666 if ( (mode->w < width) || (mode->h < height) ) {
667 SDL_SetError("Video mode smaller than requested");
671 /* If we have a palettized surface, create a default palette */
672 if ( mode->format->palette ) {
673 SDL_PixelFormat *vf = mode->format;
674 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel);
675 video->SetColors(this, 0, vf->palette->ncolors,
676 vf->palette->colors);
679 /* Clear the surface to black */
683 SDL_SetClipRect(mode, NULL);
684 SDL_ClearSurface(mode);
686 /* Now adjust the offsets to match the desired mode */
687 video->offset_x = (mode->w-width)/2;
688 video->offset_y = (mode->h-height)/2;
689 mode->offset = video->offset_y*mode->pitch +
690 video->offset_x*mode->format->BytesPerPixel;
693 "Requested mode: %dx%dx%d, obtained mode %dx%dx%d (offset %d)\n",
695 mode->w, mode->h, mode->format->BitsPerPixel, mode->offset);
699 SDL_SetClipRect(mode, NULL);
704 /* If we failed setting a video mode, return NULL... (Uh Oh!) */
705 if ( mode == NULL ) {
709 /* If there is no window manager, set the SDL_NOFRAME flag */
710 if ( ! video->info.wm_available ) {
711 mode->flags |= SDL_NOFRAME;
714 /* Reset the mouse cursor and grab for new video mode */
716 if ( video->UpdateMouse ) {
717 video->UpdateMouse(this);
719 SDL_WM_GrabInput(saved_grab);
720 SDL_GetRelativeMouseState(NULL, NULL); /* Clear first large delta */
722 /* If we're running OpenGL, make the context current */
723 if ( (video->screen->flags & SDL_OPENGL) &&
724 video->GL_MakeCurrent ) {
725 if ( video->GL_MakeCurrent(this) < 0 ) {
730 /* Set up a fake SDL surface for OpenGL "blitting" */
731 if ( (flags & SDL_OPENGLBLIT) == SDL_OPENGLBLIT ) {
732 /* Load GL functions for performing the texture updates */
734 #define SDL_PROC(ret,func,params) \
736 video->func = SDL_GL_GetProcAddress(#func); \
737 if ( ! video->func ) { \
738 SDL_SetError("Couldn't load GL function: %s\n", #func); \
742 #include "SDL_glfuncs.h"
745 /* Create a software surface for blitting */
746 #ifdef GL_VERSION_1_2
747 /* If the implementation either supports the packed pixels
748 extension, or implements the core OpenGL 1.2 API, it will
749 support the GL_UNSIGNED_SHORT_5_6_5 texture format.
752 (strstr((const char *)video->glGetString(GL_EXTENSIONS), "GL_EXT_packed_pixels") ||
753 (atof((const char *)video->glGetString(GL_VERSION)) >= 1.2f))
756 SDL_VideoSurface = SDL_CreateRGBSurface(
768 #endif /* OpenGL 1.2 */
771 SDL_VideoSurface = SDL_CreateRGBSurface(
776 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
789 if ( ! SDL_VideoSurface ) {
792 SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT;
794 /* Free the original video mode surface (is this safe?) */
795 SDL_FreeSurface(mode);
797 /* Set the surface completely opaque & white by default */
798 memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch );
799 video->glGenTextures( 1, &video->texture );
800 video->glBindTexture( GL_TEXTURE_2D, video->texture );
804 video->is_32bit ? GL_RGBA : GL_RGB,
808 video->is_32bit ? GL_RGBA : GL_RGB,
809 #ifdef GL_VERSION_1_2
810 video->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,
816 video->UpdateRects = SDL_GL_UpdateRectsLock;
818 SDL_SetError("Somebody forgot to #define HAVE_OPENGL");
823 /* Create a shadow surface if necessary */
824 /* There are three conditions under which we create a shadow surface:
825 1. We need a particular bits-per-pixel that we didn't get.
826 2. We need a hardware palette and didn't get one.
827 3. We need a software surface and got a hardware surface.
829 if ( !(SDL_VideoSurface->flags & SDL_OPENGL) &&
831 ( !(flags&SDL_ANYFORMAT) &&
832 (SDL_VideoSurface->format->BitsPerPixel != bpp)) ||
833 ( (flags&SDL_HWPALETTE) &&
834 !(SDL_VideoSurface->flags&SDL_HWPALETTE)) ||
835 /* If the surface is in hardware, video writes are visible
836 as soon as they are performed, so we need to buffer them
838 ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) &&
839 (SDL_VideoSurface->flags&SDL_HWSURFACE))
841 SDL_CreateShadowSurface(bpp);
842 if ( SDL_ShadowSurface == NULL ) {
843 SDL_SetError("Couldn't create shadow surface");
846 SDL_PublicSurface = SDL_ShadowSurface;
848 SDL_PublicSurface = SDL_VideoSurface;
850 video->info.vfmt = SDL_VideoSurface->format;
853 return(SDL_PublicSurface);
857 * Convert a surface into the video pixel format.
859 SDL_Surface * SDL_DisplayFormat (SDL_Surface *surface)
863 if ( ! SDL_PublicSurface ) {
864 SDL_SetError("No video mode has been set");
867 /* Set the flags appropriate for copying to display surface */
868 if (((SDL_PublicSurface->flags&SDL_HWSURFACE) == SDL_HWSURFACE) && current_video->info.blit_hw)
869 flags = SDL_HWSURFACE;
871 flags = SDL_SWSURFACE;
872 #ifdef AUTORLE_DISPLAYFORMAT
873 flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA));
874 flags |= SDL_RLEACCELOK;
876 flags |= surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA|SDL_RLEACCELOK);
878 return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));
882 * Convert a surface into a format that's suitable for blitting to
883 * the screen, but including an alpha channel.
885 SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface)
888 SDL_PixelFormat *format;
889 SDL_Surface *converted;
891 /* default to ARGB8888 */
892 Uint32 amask = 0xff000000;
893 Uint32 rmask = 0x00ff0000;
894 Uint32 gmask = 0x0000ff00;
895 Uint32 bmask = 0x000000ff;
897 if ( ! SDL_PublicSurface ) {
898 SDL_SetError("No video mode has been set");
901 vf = SDL_PublicSurface->format;
903 switch(vf->BytesPerPixel) {
905 /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
906 For anything else (like ARGB4444) it doesn't matter
907 since we have no special code for it anyway */
908 if ( (vf->Rmask == 0x1f) &&
909 (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
917 /* Keep the video format, as long as the high 8 bits are
919 if ( (vf->Rmask == 0xff) && (vf->Bmask == 0xff0000) ) {
926 /* We have no other optimised formats right now. When/if a new
927 optimised alpha format is written, add the converter here */
930 format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
931 flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
932 flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
933 converted = SDL_ConvertSurface(surface, format, flags);
934 SDL_FreeFormat(format);
939 * Update a specific portion of the physical screen
941 void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
946 /* Perform some checking */
951 if ( (int)(x+w) > screen->w )
953 if ( (int)(y+h) > screen->h )
956 /* Fill the rectangle */
961 SDL_UpdateRects(screen, 1, &rect);
964 void SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects)
967 SDL_VideoDevice *video = current_video;
968 SDL_VideoDevice *this = current_video;
970 if ( screen == SDL_ShadowSurface ) {
971 /* Blit the shadow surface using saved mapping */
972 SDL_Palette *pal = screen->format->palette;
973 SDL_Color *saved_colors = NULL;
974 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) {
975 /* simulated 8bpp, use correct physical palette */
976 saved_colors = pal->colors;
977 if ( video->gammacols ) {
978 /* gamma-corrected palette */
979 pal->colors = video->gammacols;
980 } else if ( video->physpal ) {
981 /* physical palette different from logical */
982 pal->colors = video->physpal->colors;
985 if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
987 SDL_DrawCursor(SDL_ShadowSurface);
988 for ( i=0; i<numrects; ++i ) {
989 SDL_LowerBlit(SDL_ShadowSurface, &rects[i],
990 SDL_VideoSurface, &rects[i]);
992 SDL_EraseCursor(SDL_ShadowSurface);
995 for ( i=0; i<numrects; ++i ) {
996 SDL_LowerBlit(SDL_ShadowSurface, &rects[i],
997 SDL_VideoSurface, &rects[i]);
1000 if ( saved_colors ) {
1001 pal->colors = saved_colors;
1004 /* Fall through to video surface update */
1005 screen = SDL_VideoSurface;
1007 if ( screen == SDL_VideoSurface ) {
1008 /* Update the video surface */
1009 if ( screen->offset ) {
1010 for ( i=0; i<numrects; ++i ) {
1011 rects[i].x += video->offset_x;
1012 rects[i].y += video->offset_y;
1014 video->UpdateRects(this, numrects, rects);
1015 for ( i=0; i<numrects; ++i ) {
1016 rects[i].x -= video->offset_x;
1017 rects[i].y -= video->offset_y;
1020 video->UpdateRects(this, numrects, rects);
1026 * Performs hardware double buffering, if possible, or a full update if not.
1028 int SDL_Flip(SDL_Surface *screen)
1030 SDL_VideoDevice *video = current_video;
1031 /* Copy the shadow surface to the video surface */
1032 if ( screen == SDL_ShadowSurface ) {
1034 SDL_Palette *pal = screen->format->palette;
1035 SDL_Color *saved_colors = NULL;
1036 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) {
1037 /* simulated 8bpp, use correct physical palette */
1038 saved_colors = pal->colors;
1039 if ( video->gammacols ) {
1040 /* gamma-corrected palette */
1041 pal->colors = video->gammacols;
1042 } else if ( video->physpal ) {
1043 /* physical palette different from logical */
1044 pal->colors = video->physpal->colors;
1052 if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
1054 SDL_DrawCursor(SDL_ShadowSurface);
1055 SDL_LowerBlit(SDL_ShadowSurface, &rect,
1056 SDL_VideoSurface, &rect);
1057 SDL_EraseCursor(SDL_ShadowSurface);
1060 SDL_LowerBlit(SDL_ShadowSurface, &rect,
1061 SDL_VideoSurface, &rect);
1063 if ( saved_colors ) {
1064 pal->colors = saved_colors;
1067 /* Fall through to video surface update */
1068 screen = SDL_VideoSurface;
1070 if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
1071 SDL_VideoDevice *this = current_video;
1072 return(video->FlipHWSurface(this, SDL_VideoSurface));
1074 SDL_UpdateRect(screen, 0, 0, 0, 0);
1079 static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors,
1080 int firstcolor, int ncolors)
1082 SDL_Palette *pal = screen->format->palette;
1083 SDL_Palette *vidpal;
1085 if ( colors != (pal->colors + firstcolor) ) {
1086 memcpy(pal->colors + firstcolor, colors,
1087 ncolors * sizeof(*colors));
1090 vidpal = SDL_VideoSurface->format->palette;
1091 if ( (screen == SDL_ShadowSurface) && vidpal ) {
1093 * This is a shadow surface, and the physical
1094 * framebuffer is also indexed. Propagate the
1095 * changes to its logical palette so that
1096 * updates are always identity blits
1098 memcpy(vidpal->colors + firstcolor, colors,
1099 ncolors * sizeof(*colors));
1101 SDL_FormatChanged(screen);
1104 static int SetPalette_physical(SDL_Surface *screen,
1105 SDL_Color *colors, int firstcolor, int ncolors)
1107 SDL_VideoDevice *video = current_video;
1110 if ( video->physpal ) {
1111 /* We need to copy the new colors, since we haven't
1112 * already done the copy in the logical set above.
1114 memcpy(video->physpal->colors + firstcolor,
1115 colors, ncolors * sizeof(*colors));
1117 if ( screen == SDL_ShadowSurface ) {
1118 if ( SDL_VideoSurface->flags & SDL_HWPALETTE ) {
1120 * The real screen is also indexed - set its physical
1121 * palette. The physical palette does not include the
1122 * gamma modification, we apply it directly instead,
1123 * but this only happens if we have hardware palette.
1125 screen = SDL_VideoSurface;
1128 * The video surface is not indexed - invalidate any
1129 * active shadow-to-video blit mappings.
1131 if ( screen->map->dst == SDL_VideoSurface ) {
1132 SDL_InvalidateMap(screen->map);
1134 if ( video->gamma ) {
1135 if( ! video->gammacols ) {
1136 SDL_Palette *pp = video->physpal;
1138 pp = screen->format->palette;
1139 video->gammacols = malloc(pp->ncolors
1140 * sizeof(SDL_Color));
1141 SDL_ApplyGamma(video->gamma,
1146 SDL_ApplyGamma(video->gamma, colors,
1152 SDL_UpdateRect(screen, 0, 0, 0, 0);
1156 if ( screen == SDL_VideoSurface ) {
1157 SDL_Color gcolors[256];
1159 if ( video->gamma ) {
1160 SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors);
1163 gotall = video->SetColors(video, firstcolor, ncolors, colors);
1165 /* The video flags shouldn't have SDL_HWPALETTE, and
1166 the video driver is responsible for copying back the
1167 correct colors into the video surface palette.
1171 SDL_CursorPaletteChanged();
1177 * Set the physical and/or logical colormap of a surface:
1178 * Only the screen has a physical colormap. It determines what is actually
1179 * sent to the display.
1180 * The logical colormap is used to map blits to/from the surface.
1181 * 'which' is one or both of SDL_LOGPAL, SDL_PHYSPAL
1183 * Return nonzero if all colours were set as requested, or 0 otherwise.
1185 int SDL_SetPalette(SDL_Surface *screen, int which,
1186 SDL_Color *colors, int firstcolor, int ncolors)
1192 if ( ! current_video ) {
1195 if ( screen != SDL_PublicSurface ) {
1196 /* only screens have physical palettes */
1197 which &= ~SDL_PHYSPAL;
1198 } else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) {
1199 /* hardware palettes required for split colormaps */
1200 which |= SDL_PHYSPAL | SDL_LOGPAL;
1203 /* Verify the parameters */
1204 pal = screen->format->palette;
1206 return 0; /* not a palettized surface */
1209 palsize = 1 << screen->format->BitsPerPixel;
1210 if ( ncolors > (palsize - firstcolor) ) {
1211 ncolors = (palsize - firstcolor);
1215 if ( which & SDL_LOGPAL ) {
1217 * Logical palette change: The actual screen isn't affected,
1218 * but the internal colormap is altered so that the
1219 * interpretation of the pixel values (for blits etc) is
1222 SetPalette_logical(screen, colors, firstcolor, ncolors);
1224 if ( which & SDL_PHYSPAL ) {
1225 SDL_VideoDevice *video = current_video;
1227 * Physical palette change: This doesn't affect the
1228 * program's idea of what the screen looks like, but changes
1229 * its actual appearance.
1232 return gotall; /* video not yet initialized */
1233 if(!video->physpal && !(which & SDL_LOGPAL) ) {
1234 /* Lazy physical palette allocation */
1236 SDL_Palette *pp = malloc(sizeof(*pp));
1237 current_video->physpal = pp;
1238 pp->ncolors = pal->ncolors;
1239 size = pp->ncolors * sizeof(SDL_Color);
1240 pp->colors = malloc(size);
1241 memcpy(pp->colors, pal->colors, size);
1243 if ( ! SetPalette_physical(screen,
1244 colors, firstcolor, ncolors) ) {
1251 int SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor,
1254 return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL,
1255 colors, firstcolor, ncolors);
1259 * Clean up the video subsystem
1261 void SDL_VideoQuit (void)
1263 SDL_Surface *ready_to_go;
1265 if ( current_video ) {
1266 SDL_VideoDevice *video = current_video;
1267 SDL_VideoDevice *this = current_video;
1269 /* Halt event processing before doing anything else */
1270 SDL_StopEventLoop();
1272 /* Clean up allocated window manager items */
1273 if ( SDL_PublicSurface ) {
1274 SDL_PublicSurface = NULL;
1278 /* Just in case... */
1279 SDL_WM_GrabInputOff();
1281 /* Clean up the system video */
1282 video->VideoQuit(this);
1284 /* Free any lingering surfaces */
1285 ready_to_go = SDL_ShadowSurface;
1286 SDL_ShadowSurface = NULL;
1287 SDL_FreeSurface(ready_to_go);
1288 if ( SDL_VideoSurface != NULL ) {
1289 ready_to_go = SDL_VideoSurface;
1290 SDL_VideoSurface = NULL;
1291 SDL_FreeSurface(ready_to_go);
1293 SDL_PublicSurface = NULL;
1295 /* Clean up miscellaneous memory */
1296 if ( video->physpal ) {
1297 free(video->physpal->colors);
1298 free(video->physpal);
1299 video->physpal = NULL;
1301 if ( video->gammacols ) {
1302 free(video->gammacols);
1303 video->gammacols = NULL;
1305 if ( video->gamma ) {
1307 video->gamma = NULL;
1309 if ( video->wm_title != NULL ) {
1310 free(video->wm_title);
1311 video->wm_title = NULL;
1313 if ( video->wm_icon != NULL ) {
1314 free(video->wm_icon);
1315 video->wm_icon = NULL;
1318 /* Finish cleaning up video subsystem */
1320 current_video = NULL;
1325 /* Load the GL driver library */
1326 int SDL_GL_LoadLibrary(const char *path)
1328 SDL_VideoDevice *video = current_video;
1329 SDL_VideoDevice *this = current_video;
1333 if ( video == NULL ) {
1334 SDL_SetError("Video subsystem has not been initialized");
1336 if ( video->GL_LoadLibrary ) {
1337 retval = video->GL_LoadLibrary(this, path);
1339 SDL_SetError("No dynamic GL support in video driver");
1345 void *SDL_GL_GetProcAddress(const char* proc)
1347 SDL_VideoDevice *video = current_video;
1348 SDL_VideoDevice *this = current_video;
1352 if ( video->GL_GetProcAddress ) {
1353 if ( video->gl_config.driver_loaded ) {
1354 func = video->GL_GetProcAddress(this, proc);
1356 SDL_SetError("No GL driver has been loaded");
1359 SDL_SetError("No dynamic GL support in video driver");
1364 /* Set the specified GL attribute for setting up a GL video mode */
1365 int SDL_GL_SetAttribute( SDL_GLattr attr, int value )
1368 SDL_VideoDevice *video = current_video;
1372 case SDL_GL_RED_SIZE:
1373 video->gl_config.red_size = value;
1375 case SDL_GL_GREEN_SIZE:
1376 video->gl_config.green_size = value;
1378 case SDL_GL_BLUE_SIZE:
1379 video->gl_config.blue_size = value;
1381 case SDL_GL_ALPHA_SIZE:
1382 video->gl_config.alpha_size = value;
1384 case SDL_GL_DOUBLEBUFFER:
1385 video->gl_config.double_buffer = value;
1387 case SDL_GL_BUFFER_SIZE:
1388 video->gl_config.buffer_size = value;
1390 case SDL_GL_DEPTH_SIZE:
1391 video->gl_config.depth_size = value;
1393 case SDL_GL_STENCIL_SIZE:
1394 video->gl_config.stencil_size = value;
1396 case SDL_GL_ACCUM_RED_SIZE:
1397 video->gl_config.accum_red_size = value;
1399 case SDL_GL_ACCUM_GREEN_SIZE:
1400 video->gl_config.accum_green_size = value;
1402 case SDL_GL_ACCUM_BLUE_SIZE:
1403 video->gl_config.accum_blue_size = value;
1405 case SDL_GL_ACCUM_ALPHA_SIZE:
1406 video->gl_config.accum_alpha_size = value;
1409 video->gl_config.stereo = value;
1412 SDL_SetError("Unknown OpenGL attribute");
1419 /* Retrieve an attribute value from the windowing system. */
1420 int SDL_GL_GetAttribute(SDL_GLattr attr, int* value)
1423 SDL_VideoDevice* video = current_video;
1424 SDL_VideoDevice* this = current_video;
1426 if ( video->GL_GetAttribute ) {
1427 retval = this->GL_GetAttribute(this, attr, value);
1430 SDL_SetError("GL_GetAttribute not supported");
1435 /* Perform a GL buffer swap on the current GL context */
1436 void SDL_GL_SwapBuffers(void)
1438 SDL_VideoDevice *video = current_video;
1439 SDL_VideoDevice *this = current_video;
1441 if ( video->screen->flags & SDL_OPENGL ) {
1442 video->GL_SwapBuffers(this);
1444 SDL_SetError("OpenGL video mode has not been set");
1448 /* Update rects with locking */
1449 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects)
1452 SDL_GL_UpdateRects(numrects, rects);
1456 /* Update rects without state setting and changing (the caller is responsible for it) */
1457 void SDL_GL_UpdateRects(int numrects, SDL_Rect *rects)
1460 SDL_VideoDevice *this = current_video;
1461 SDL_Rect update, tmp;
1464 for ( i = 0; i < numrects; i++ )
1468 for ( y = 0; y <= rects[i].h / 256; y++ )
1472 for ( x = 0; x <= rects[i].w / 256; x++ )
1479 if ( update.w > 256 )
1482 if ( update.h > 256 )
1486 this->glTexSubImage2D(
1493 this->is_32bit? GL_RGBA : GL_RGB,
1494 #ifdef GL_VERSION_1_2
1495 this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,
1499 (Uint8 *)this->screen->pixels +
1500 this->screen->format->BytesPerPixel * update.x +
1501 update.y * this->screen->pitch );
1505 * Note the parens around the function name:
1506 * This is because some OpenGL implementations define glTexCoord etc
1507 * as macros, and we don't want them expanded here.
1509 this->glBegin(GL_TRIANGLE_STRIP);
1510 (this->glTexCoord2f)( 0.0, 0.0 );
1511 (this->glVertex2i)( update.x, update.y );
1512 (this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 );
1513 (this->glVertex2i)( update.x + update.w, update.y );
1514 (this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) );
1515 (this->glVertex2i)( update.x, update.y + update.h );
1516 (this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) );
1517 (this->glVertex2i)( update.x + update.w , update.y + update.h );
1530 /* Lock == save current state */
1537 SDL_VideoDevice *this = current_video;
1539 this->glPushAttrib( GL_ALL_ATTRIB_BITS ); /* TODO: narrow range of what is saved */
1540 #ifdef GL_CLIENT_PIXEL_STORE_BIT
1541 this->glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
1544 this->glEnable(GL_TEXTURE_2D);
1545 this->glEnable(GL_BLEND);
1546 this->glDisable(GL_FOG);
1547 this->glDisable(GL_ALPHA_TEST);
1548 this->glDisable(GL_DEPTH_TEST);
1549 this->glDisable(GL_SCISSOR_TEST);
1550 this->glDisable(GL_STENCIL_TEST);
1551 this->glDisable(GL_CULL_FACE);
1553 this->glBindTexture( GL_TEXTURE_2D, this->texture );
1554 this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1555 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1556 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1557 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
1558 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
1560 this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel );
1561 this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1562 (this->glColor4f)(1.0, 1.0, 1.0, 1.0); /* Solaris workaround */
1564 this->glViewport(0, 0, this->screen->w, this->screen->h);
1565 this->glMatrixMode(GL_PROJECTION);
1566 this->glPushMatrix();
1567 this->glLoadIdentity();
1569 this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0);
1571 this->glMatrixMode(GL_MODELVIEW);
1572 this->glPushMatrix();
1573 this->glLoadIdentity();
1578 /* Unlock == restore saved state */
1579 void SDL_GL_Unlock()
1585 SDL_VideoDevice *this = current_video;
1587 this->glPopMatrix();
1588 this->glMatrixMode(GL_PROJECTION);
1589 this->glPopMatrix();
1591 this->glPopClientAttrib();
1592 this->glPopAttrib();
1598 * Sets/Gets the title and icon text of the display window, if any.
1600 void SDL_WM_SetCaption (const char *title, const char *icon)
1602 SDL_VideoDevice *video = current_video;
1603 SDL_VideoDevice *this = current_video;
1607 if ( video->wm_title ) {
1608 free(video->wm_title);
1610 video->wm_title = (char *)malloc(strlen(title)+1);
1611 if ( video->wm_title != NULL ) {
1612 strcpy(video->wm_title, title);
1616 if ( video->wm_icon ) {
1617 free(video->wm_icon);
1619 video->wm_icon = (char *)malloc(strlen(icon)+1);
1620 if ( video->wm_icon != NULL ) {
1621 strcpy(video->wm_icon, icon);
1624 if ( (title || icon) && (video->SetCaption != NULL) ) {
1625 video->SetCaption(this, video->wm_title,video->wm_icon);
1629 void SDL_WM_GetCaption (char **title, char **icon)
1631 SDL_VideoDevice *video = current_video;
1635 *title = video->wm_title;
1638 *icon = video->wm_icon;
1643 /* Utility function used by SDL_WM_SetIcon();
1644 * flags & 1 for color key, flags & 2 for alpha channel. */
1645 static void CreateMaskFromColorKeyOrAlpha(SDL_Surface *icon, Uint8 *mask, int flags)
1649 #define SET_MASKBIT(icon, x, y, mask) \
1650 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
1652 colorkey = icon->format->colorkey;
1653 switch (icon->format->BytesPerPixel) {
1654 case 1: { Uint8 *pixels;
1655 for ( y=0; y<icon->h; ++y ) {
1656 pixels = (Uint8 *)icon->pixels + y*icon->pitch;
1657 for ( x=0; x<icon->w; ++x ) {
1658 if ( *pixels++ == colorkey ) {
1659 SET_MASKBIT(icon, x, y, mask);
1666 case 2: { Uint16 *pixels;
1667 for ( y=0; y<icon->h; ++y ) {
1668 pixels = (Uint16 *)icon->pixels +
1670 for ( x=0; x<icon->w; ++x ) {
1671 if ( (flags & 1) && *pixels == colorkey ) {
1672 SET_MASKBIT(icon, x, y, mask);
1673 } else if((flags & 2) && (*pixels & icon->format->Amask) == 0) {
1674 SET_MASKBIT(icon, x, y, mask);
1682 case 4: { Uint32 *pixels;
1683 for ( y=0; y<icon->h; ++y ) {
1684 pixels = (Uint32 *)icon->pixels +
1686 for ( x=0; x<icon->w; ++x ) {
1687 if ( (flags & 1) && *pixels == colorkey ) {
1688 SET_MASKBIT(icon, x, y, mask);
1689 } else if((flags & 2) && (*pixels & icon->format->Amask) == 0) {
1690 SET_MASKBIT(icon, x, y, mask);
1701 * Sets the window manager icon for the display window.
1703 void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask)
1705 SDL_VideoDevice *video = current_video;
1706 SDL_VideoDevice *this = current_video;
1708 if ( icon && video->SetIcon ) {
1709 /* Generate a mask if necessary, and create the icon! */
1710 if ( mask == NULL ) {
1711 int mask_len = icon->h*(icon->w+7)/8;
1713 mask = (Uint8 *)malloc(mask_len);
1714 if ( mask == NULL ) {
1717 memset(mask, ~0, mask_len);
1718 if ( icon->flags & SDL_SRCCOLORKEY ) flags |= 1;
1719 if ( icon->flags & SDL_SRCALPHA ) flags |= 2;
1721 CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
1723 video->SetIcon(video, icon, mask);
1726 video->SetIcon(this, icon, mask);
1732 * Grab or ungrab the keyboard and mouse input.
1733 * This function returns the final grab mode after calling the
1734 * driver dependent function.
1736 static SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode)
1738 SDL_VideoDevice *video = current_video;
1739 SDL_VideoDevice *this = current_video;
1741 /* Only do something if we have support for grabs */
1742 if ( video->GrabInput == NULL ) {
1743 return(video->input_grab);
1746 /* If the final grab mode if off, only then do we actually grab */
1748 printf("SDL_WM_GrabInputRaw(%d) ... ", mode);
1750 if ( mode == SDL_GRAB_OFF ) {
1751 if ( video->input_grab != SDL_GRAB_OFF ) {
1752 mode = video->GrabInput(this, mode);
1755 if ( video->input_grab == SDL_GRAB_OFF ) {
1756 mode = video->GrabInput(this, mode);
1759 if ( mode != video->input_grab ) {
1760 video->input_grab = mode;
1761 if ( video->CheckMouseMode ) {
1762 video->CheckMouseMode(this);
1766 printf("Final mode %d\n", video->input_grab);
1769 /* Return the final grab state */
1770 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1771 mode -= SDL_GRAB_FULLSCREEN;
1775 SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode)
1777 SDL_VideoDevice *video = current_video;
1779 /* If the video isn't initialized yet, we can't do anything */
1781 return SDL_GRAB_OFF;
1784 /* Return the current mode on query */
1785 if ( mode == SDL_GRAB_QUERY ) {
1786 mode = video->input_grab;
1787 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1788 mode -= SDL_GRAB_FULLSCREEN;
1794 printf("SDL_WM_GrabInput(%d) ... ", mode);
1796 /* If the video surface is fullscreen, we always grab */
1797 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1798 mode -= SDL_GRAB_FULLSCREEN;
1800 if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {
1801 mode += SDL_GRAB_FULLSCREEN;
1803 return(SDL_WM_GrabInputRaw(mode));
1805 static SDL_GrabMode SDL_WM_GrabInputOff(void)
1809 /* First query the current grab state */
1810 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
1812 /* Now explicitly turn off input grab */
1813 SDL_WM_GrabInputRaw(SDL_GRAB_OFF);
1815 /* Return the old state */
1820 * Iconify the window in window managed environments.
1821 * A successful iconification will result in an SDL_APPACTIVE loss event.
1823 int SDL_WM_IconifyWindow(void)
1825 SDL_VideoDevice *video = current_video;
1826 SDL_VideoDevice *this = current_video;
1830 if ( video->IconifyWindow ) {
1831 retval = video->IconifyWindow(this);
1837 * Toggle fullscreen mode
1839 int SDL_WM_ToggleFullScreen(SDL_Surface *surface)
1841 SDL_VideoDevice *video = current_video;
1842 SDL_VideoDevice *this = current_video;
1846 if ( SDL_PublicSurface && (surface == SDL_PublicSurface) &&
1847 video->ToggleFullScreen ) {
1848 if ( surface->flags & SDL_FULLSCREEN ) {
1849 toggled = video->ToggleFullScreen(this, 0);
1851 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN;
1852 SDL_PublicSurface->flags &= ~SDL_FULLSCREEN;
1855 toggled = video->ToggleFullScreen(this, 1);
1857 SDL_VideoSurface->flags |= SDL_FULLSCREEN;
1858 SDL_PublicSurface->flags |= SDL_FULLSCREEN;
1861 /* Double-check the grab state inside SDL_WM_GrabInput() */
1863 SDL_WM_GrabInput(video->input_grab);
1870 * Get some platform dependent window manager information
1872 int SDL_GetWMInfo (SDL_SysWMinfo *info)
1874 SDL_VideoDevice *video = current_video;
1875 SDL_VideoDevice *this = current_video;
1877 if ( video && video->GetWMInfo ) {
1878 return(video->GetWMInfo(this, info));