2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 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
20 slouken@devolution.com
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
111 SDL_VideoDevice *current_video = NULL;
113 /* Various local functions */
114 int SDL_VideoInit(const char *driver_name, Uint32 flags);
115 void SDL_VideoQuit(void);
116 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect* rects);
118 static SDL_GrabMode SDL_WM_GrabInputOff(void);
120 static int lock_count = 0;
125 * Initialize the video and event subsystems -- determine native pixel format
127 int SDL_VideoInit (const char *driver_name, Uint32 flags)
129 SDL_VideoDevice *video;
132 SDL_PixelFormat vformat;
135 /* Toggle the event thread flags, based on OS requirements */
136 #if defined(MUST_THREAD_EVENTS)
137 flags |= SDL_INIT_EVENTTHREAD;
138 #elif defined(CANT_THREAD_EVENTS)
139 if ( (flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) {
140 SDL_SetError("OS doesn't support threaded events");
145 /* Check to make sure we don't overwrite 'current_video' */
146 if ( current_video != NULL ) {
150 /* Select the proper video driver */
153 if ( driver_name != NULL ) {
154 #if 0 /* This will be replaced with a better driver selection API */
155 if ( strrchr(driver_name, ':') != NULL ) {
156 index = atoi(strrchr(driver_name, ':')+1);
159 for ( i=0; bootstrap[i]; ++i ) {
160 if ( strncmp(bootstrap[i]->name, driver_name,
161 strlen(bootstrap[i]->name)) == 0 ) {
162 if ( bootstrap[i]->available() ) {
163 video = bootstrap[i]->create(index);
169 for ( i=0; bootstrap[i]; ++i ) {
170 if ( bootstrap[i]->available() ) {
171 video = bootstrap[i]->create(index);
172 if ( video != NULL ) {
178 if ( video == NULL ) {
179 SDL_SetError("No available video device");
182 current_video = video;
183 current_video->name = bootstrap[i]->name;
185 /* Do some basic variable initialization */
186 video->screen = NULL;
187 video->shadow = NULL;
188 video->visible = NULL;
189 video->physpal = NULL;
190 video->gammacols = NULL;
192 video->wm_title = NULL;
193 video->wm_icon = NULL;
196 memset(&video->info, 0, (sizeof video->info));
198 /* Set some very sane GL defaults */
199 video->gl_config.driver_loaded = 0;
200 video->gl_config.dll_handle = NULL;
201 video->gl_config.red_size = 5;
202 #if 1 /* This seems to work on more video cards, as a default */
203 video->gl_config.green_size = 5;
205 video->gl_config.green_size = 6;
207 video->gl_config.blue_size = 5;
208 video->gl_config.alpha_size = 0;
209 video->gl_config.buffer_size = 0;
210 video->gl_config.depth_size = 16;
211 video->gl_config.stencil_size = 0;
212 video->gl_config.double_buffer = 1;
213 video->gl_config.accum_red_size = 0;
214 video->gl_config.accum_green_size = 0;
215 video->gl_config.accum_blue_size = 0;
216 video->gl_config.accum_alpha_size = 0;
218 /* Initialize the video subsystem */
219 memset(&vformat, 0, sizeof(vformat));
220 if ( video->VideoInit(video, &vformat) < 0 ) {
225 /* Create a zero sized video surface of the appropriate format */
226 video_flags = SDL_SWSURFACE;
227 SDL_VideoSurface = SDL_CreateRGBSurface(video_flags, 0, 0,
228 vformat.BitsPerPixel,
229 vformat.Rmask, vformat.Gmask, vformat.Bmask, 0);
230 if ( SDL_VideoSurface == NULL ) {
234 SDL_PublicSurface = NULL; /* Until SDL_SetVideoMode() */
236 #if 0 /* Don't change the current palette - may be used by other programs.
237 * The application can't do anything with the display surface until
238 * a video mode has been set anyway. :)
240 /* If we have a palettized surface, create a default palette */
241 if ( SDL_VideoSurface->format->palette ) {
242 SDL_PixelFormat *vf = SDL_VideoSurface->format;
243 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel);
244 video->SetColors(video,
245 0, vf->palette->ncolors, vf->palette->colors);
248 video->info.vfmt = SDL_VideoSurface->format;
250 /* Start the event loop */
251 if ( SDL_StartEventLoop(flags) < 0 ) {
255 SDL_CursorInit(flags & SDL_INIT_EVENTTHREAD);
257 /* We're ready to go! */
261 char *SDL_VideoDriverName(char *namebuf, int maxlen)
263 if ( current_video != NULL ) {
264 strncpy(namebuf, current_video->name, maxlen-1);
265 namebuf[maxlen-1] = '\0';
272 * Get the current display surface
274 SDL_Surface *SDL_GetVideoSurface(void)
276 SDL_Surface *visible;
279 if ( current_video ) {
280 visible = current_video->visible;
286 * Get the current information about the video hardware
288 const SDL_VideoInfo *SDL_GetVideoInfo(void)
290 const SDL_VideoInfo *info;
293 if ( current_video ) {
294 info = ¤t_video->info;
300 * Return a pointer to an array of available screen dimensions for the
301 * given format, sorted largest to smallest. Returns NULL if there are
302 * no dimensions available for a particular format, or (SDL_Rect **)-1
303 * if any dimension is okay for the given format. If 'format' is NULL,
304 * the mode list will be for the format given by SDL_GetVideoInfo()->vfmt
306 SDL_Rect ** SDL_ListModes (SDL_PixelFormat *format, Uint32 flags)
308 SDL_VideoDevice *video = current_video;
309 SDL_VideoDevice *this = current_video;
313 if ( SDL_VideoSurface ) {
314 if ( format == NULL ) {
315 format = SDL_VideoSurface->format;
317 modes = video->ListModes(this, format, flags);
323 * Check to see if a particular video mode is supported.
324 * It returns 0 if the requested mode is not supported under any bit depth,
325 * or returns the bits-per-pixel of the closest available mode with the
326 * given width and height. If this bits-per-pixel is different from the
327 * one used when setting the video mode, SDL_SetVideoMode() will succeed,
328 * but will emulate the requested bits-per-pixel with a shadow surface.
330 static Uint8 SDL_closest_depths[4][8] = {
331 /* 8 bit closest depth ordering */
332 { 0, 8, 16, 15, 32, 24, 0, 0 },
333 /* 15,16 bit closest depth ordering */
334 { 0, 16, 15, 32, 24, 8, 0, 0 },
335 /* 24 bit closest depth ordering */
336 { 0, 24, 32, 16, 15, 8, 0, 0 },
337 /* 32 bit closest depth ordering */
338 { 0, 32, 16, 15, 24, 8, 0, 0 }
341 int SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags)
345 SDL_PixelFormat format;
348 /* Currently 1 and 4 bpp are not supported */
349 if ( bpp < 8 || bpp > 32 ) {
352 if ( (width == 0) || (height == 0) ) {
356 /* Search through the list valid of modes */
357 memset(&format, 0, sizeof(format));
359 table = ((bpp+7)/8)-1;
360 SDL_closest_depths[table][0] = bpp;
361 SDL_closest_depths[table][7] = 0;
362 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
363 format.BitsPerPixel = SDL_closest_depths[table][b];
364 sizes = SDL_ListModes(&format, flags);
365 if ( sizes == (SDL_Rect **)0 ) {
366 /* No sizes supported at this bit-depth */
369 #ifdef macintosh /* MPW optimization bug? */
370 if ( (sizes == (SDL_Rect **)0xFFFFFFFF) ||
372 if ( (sizes == (SDL_Rect **)-1) ||
374 current_video->handles_any_size ) {
375 /* Any size supported at this bit-depth */
379 for ( i=0; sizes[i]; ++i ) {
380 if ((sizes[i]->w == width) && (sizes[i]->h == height)) {
388 return(SDL_closest_depths[table][b]);
395 * Get the closest non-emulated video mode to the one requested
397 static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags)
402 SDL_PixelFormat format;
405 /* Try the original video mode, get the closest depth */
406 native_bpp = SDL_VideoModeOK(*w, *h, *BitsPerPixel, flags);
407 if ( native_bpp == *BitsPerPixel ) {
410 if ( native_bpp > 0 ) {
411 *BitsPerPixel = native_bpp;
415 /* No exact size match at any depth, look for closest match */
416 memset(&format, 0, sizeof(format));
418 table = ((*BitsPerPixel+7)/8)-1;
419 SDL_closest_depths[table][0] = *BitsPerPixel;
420 SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel;
421 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
422 format.BitsPerPixel = SDL_closest_depths[table][b];
423 sizes = SDL_ListModes(&format, flags);
424 if ( sizes == (SDL_Rect **)0 ) {
425 /* No sizes supported at this bit-depth */
428 for ( i=0; sizes[i]; ++i ) {
429 if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) {
434 *BitsPerPixel = SDL_closest_depths[table][b];
437 /* Largest mode too small... */;
442 if ( (i > 0) && ! sizes[i] ) {
443 /* The smallest mode was larger than requested, OK */
447 *BitsPerPixel = SDL_closest_depths[table][b];
452 SDL_SetError("No video mode large enough for %dx%d", *w, *h);
457 /* This should probably go somewhere else -- like SDL_surface.c */
458 static void SDL_ClearSurface(SDL_Surface *surface)
462 black = SDL_MapRGB(surface->format, 0, 0, 0);
463 SDL_FillRect(surface, NULL, black);
464 if ((surface->flags&SDL_HWSURFACE) && (surface->flags&SDL_DOUBLEBUF)) {
466 SDL_FillRect(surface, NULL, black);
472 * Create a shadow surface suitable for fooling the app. :-)
474 static void SDL_CreateShadowSurface(int depth)
476 Uint32 Rmask, Gmask, Bmask;
478 /* Allocate the shadow surface */
479 if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) {
480 Rmask = (SDL_VideoSurface->format)->Rmask;
481 Gmask = (SDL_VideoSurface->format)->Gmask;
482 Bmask = (SDL_VideoSurface->format)->Bmask;
484 Rmask = Gmask = Bmask = 0;
486 SDL_ShadowSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
487 SDL_VideoSurface->w, SDL_VideoSurface->h,
488 depth, Rmask, Gmask, Bmask, 0);
489 if ( SDL_ShadowSurface == NULL ) {
493 /* 8-bit shadow surfaces report that they have exclusive palette */
494 if ( SDL_ShadowSurface->format->palette ) {
495 SDL_ShadowSurface->flags |= SDL_HWPALETTE;
496 if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) {
497 memcpy(SDL_ShadowSurface->format->palette->colors,
498 SDL_VideoSurface->format->palette->colors,
499 SDL_VideoSurface->format->palette->ncolors*
503 SDL_ShadowSurface->format->palette->colors, depth);
507 /* If the video surface is resizable, the shadow should say so */
508 if ( (SDL_VideoSurface->flags & SDL_RESIZABLE) == SDL_RESIZABLE ) {
509 SDL_ShadowSurface->flags |= SDL_RESIZABLE;
511 /* If the video surface has no frame, the shadow should say so */
512 if ( (SDL_VideoSurface->flags & SDL_NOFRAME) == SDL_NOFRAME ) {
513 SDL_ShadowSurface->flags |= SDL_NOFRAME;
515 /* If the video surface is fullscreen, the shadow should say so */
516 if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
517 SDL_ShadowSurface->flags |= SDL_FULLSCREEN;
519 /* If the video surface is flippable, the shadow should say so */
520 if ( (SDL_VideoSurface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
521 SDL_ShadowSurface->flags |= SDL_DOUBLEBUF;
527 * Set the requested video mode, allocating a shadow buffer if necessary.
529 SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
531 SDL_VideoDevice *video, *this;
532 SDL_Surface *prev_mode, *mode;
537 SDL_GrabMode saved_grab;
539 /* Start up the video driver, if necessary..
540 WARNING: This is the only function protected this way!
542 if ( ! current_video ) {
543 if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 ) {
547 this = video = current_video;
549 /* Default to the current video bpp */
551 flags |= SDL_ANYFORMAT;
552 bpp = SDL_VideoSurface->format->BitsPerPixel;
555 /* Get a good video mode, the closest one possible */
559 if ( ! SDL_GetVideoMode(&video_w, &video_h, &video_bpp, flags) ) {
563 /* Check the requested flags */
564 /* There's no palette in > 8 bits-per-pixel mode */
565 if ( video_bpp > 8 ) {
566 flags &= ~SDL_HWPALETTE;
569 if ( (flags&SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
570 /* There's no windowed double-buffering */
571 flags &= ~SDL_DOUBLEBUF;
574 if ( (flags&SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
575 /* Use hardware surfaces when double-buffering */
576 flags |= SDL_HWSURFACE;
579 is_opengl = ( ( flags & SDL_OPENGL ) == SDL_OPENGL );
581 /* These flags are for 2D video modes only */
582 flags &= ~(SDL_HWSURFACE|SDL_DOUBLEBUF);
585 /* Reset the keyboard here so event callbacks can run */
588 /* Clean up any previous video mode */
589 if ( SDL_PublicSurface != NULL ) {
590 SDL_PublicSurface = NULL;
592 if ( SDL_ShadowSurface != NULL ) {
593 SDL_Surface *ready_to_go;
594 ready_to_go = SDL_ShadowSurface;
595 SDL_ShadowSurface = NULL;
596 SDL_FreeSurface(ready_to_go);
598 if ( video->physpal ) {
599 free(video->physpal->colors);
600 free(video->physpal);
601 video->physpal = NULL;
603 if( video->gammacols) {
604 free(video->gammacols);
605 video->gammacols = NULL;
608 /* Save the previous grab state and turn off grab for mode switch */
609 saved_grab = SDL_WM_GrabInputOff();
611 /* Try to set the video mode, along with offset and clipping */
612 prev_mode = SDL_VideoSurface;
614 SDL_VideoSurface = NULL; /* In case it's freed by driver */
615 mode = video->SetVideoMode(this, prev_mode,video_w,video_h,video_bpp,flags);
616 if ( mode ) { /* Prevent resize events from mode change */
617 SDL_PrivateResize(mode->w, mode->h);
621 * If you try to set an SDL_OPENGL surface, and fail to find a
622 * matching visual, then the next call to SDL_SetVideoMode()
623 * will segfault, since we no longer point to a dummy surface,
626 * WARNING, we need to make sure that the previous mode hasn't
627 * already been freed by the video driver. What do we do in
628 * that case? Should we call SDL_VideoInit() again?
630 SDL_VideoSurface = (mode != NULL) ? mode : prev_mode;
632 if ( (mode != NULL) && (!is_opengl) ) {
634 if ( (mode->w < width) || (mode->h < height) ) {
635 SDL_SetError("Video mode smaller than requested");
639 /* If we have a palettized surface, create a default palette */
640 if ( mode->format->palette ) {
641 SDL_PixelFormat *vf = mode->format;
642 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel);
643 video->SetColors(this, 0, vf->palette->ncolors,
644 vf->palette->colors);
647 /* Clear the surface to black */
651 SDL_SetClipRect(mode, NULL);
652 SDL_ClearSurface(mode);
654 /* Now adjust the offsets to match the desired mode */
655 video->offset_x = (mode->w-width)/2;
656 video->offset_y = (mode->h-height)/2;
657 mode->offset = video->offset_y*mode->pitch +
658 video->offset_x*mode->format->BytesPerPixel;
661 "Requested mode: %dx%dx%d, obtained mode %dx%dx%d (offset %d)\n",
663 mode->w, mode->h, mode->format->BitsPerPixel, mode->offset);
667 SDL_SetClipRect(mode, NULL);
672 /* If we failed setting a video mode, return NULL... (Uh Oh!) */
673 if ( mode == NULL ) {
677 /* If there is no window manager, set the SDL_NOFRAME flag */
678 if ( ! video->info.wm_available ) {
679 mode->flags |= SDL_NOFRAME;
682 /* Reset the mouse cursor and grab for new video mode */
684 if ( video->UpdateMouse ) {
685 video->UpdateMouse(this);
687 SDL_WM_GrabInput(saved_grab);
688 SDL_GetRelativeMouseState(NULL, NULL); /* Clear first large delta */
690 /* If we're running OpenGL, make the context current */
691 if ( (video->screen->flags & SDL_OPENGL) &&
692 video->GL_MakeCurrent ) {
693 if ( video->GL_MakeCurrent(this) < 0 ) {
698 /* Set up a fake SDL surface for OpenGL "blitting" */
699 if ( (flags & SDL_OPENGLBLIT) == SDL_OPENGLBLIT ) {
700 /* Load GL functions for performing the texture updates */
702 #define SDL_PROC(ret,func,params) \
704 video->func = SDL_GL_GetProcAddress(#func); \
705 if ( ! video->func ) { \
706 SDL_SetError("Couldn't load GL function: %s\n", #func); \
710 #include "SDL_glfuncs.h"
713 /* Create a software surface for blitting */
714 #ifdef GL_VERSION_1_2
715 /* If the implementation either supports the packed pixels
716 extension, or implements the core OpenGL 1.2 API, it will
717 support the GL_UNSIGNED_SHORT_5_6_5 texture format.
720 (strstr((const char *)video->glGetString(GL_EXTENSIONS),
721 "GL_EXT_packed_pixels") ||
722 (strncmp((const char *)video->glGetString(GL_VERSION),
726 SDL_VideoSurface = SDL_CreateRGBSurface(
738 #endif /* OpenGL 1.2 */
741 SDL_VideoSurface = SDL_CreateRGBSurface(
746 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
759 if ( ! SDL_VideoSurface ) {
762 SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT;
764 /* Free the original video mode surface (is this safe?) */
765 SDL_FreeSurface(mode);
767 /* Set the surface completely opaque & white by default */
768 memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch );
769 video->glGenTextures( 1, &video->texture );
770 video->glBindTexture( GL_TEXTURE_2D, video->texture );
774 video->is_32bit ? GL_RGBA : GL_RGB,
778 video->is_32bit ? GL_RGBA : GL_RGB,
779 #ifdef GL_VERSION_1_2
780 video->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,
786 video->UpdateRects = SDL_GL_UpdateRectsLock;
788 SDL_SetError("Somebody forgot to #define HAVE_OPENGL");
793 /* Create a shadow surface if necessary */
794 /* There are three conditions under which we create a shadow surface:
795 1. We need a particular bits-per-pixel that we didn't get.
796 2. We need a hardware palette and didn't get one.
797 3. We need a software surface and got a hardware surface.
799 if ( !(SDL_VideoSurface->flags & SDL_OPENGL) &&
801 ( !(flags&SDL_ANYFORMAT) &&
802 (SDL_VideoSurface->format->BitsPerPixel != bpp)) ||
803 ( (flags&SDL_HWPALETTE) &&
804 !(SDL_VideoSurface->flags&SDL_HWPALETTE)) ||
805 /* If the surface is in hardware, video writes are visible
806 as soon as they are performed, so we need to buffer them
808 ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) &&
809 (SDL_VideoSurface->flags&SDL_HWSURFACE))
811 SDL_CreateShadowSurface(bpp);
812 if ( SDL_ShadowSurface == NULL ) {
813 SDL_SetError("Couldn't create shadow surface");
816 SDL_PublicSurface = SDL_ShadowSurface;
818 SDL_PublicSurface = SDL_VideoSurface;
820 video->info.vfmt = SDL_VideoSurface->format;
823 return(SDL_PublicSurface);
827 * Convert a surface into the video pixel format.
829 SDL_Surface * SDL_DisplayFormat (SDL_Surface *surface)
833 if ( ! SDL_PublicSurface ) {
834 SDL_SetError("No video mode has been set");
837 /* Set the flags appropriate for copying to display surface */
838 flags = (SDL_PublicSurface->flags&SDL_HWSURFACE);
839 #ifdef AUTORLE_DISPLAYFORMAT
840 flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA));
841 flags |= SDL_RLEACCELOK;
843 flags |= surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA|SDL_RLEACCELOK);
845 return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));
849 * Convert a surface into a format that's suitable for blitting to
850 * the screen, but including an alpha channel.
852 SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface)
855 SDL_PixelFormat *format;
856 SDL_Surface *converted;
858 /* default to ARGB8888 */
859 Uint32 amask = 0xff000000;
860 Uint32 rmask = 0x00ff0000;
861 Uint32 gmask = 0x0000ff00;
862 Uint32 bmask = 0x000000ff;
864 if ( ! SDL_PublicSurface ) {
865 SDL_SetError("No video mode has been set");
868 vf = SDL_PublicSurface->format;
870 switch(vf->BytesPerPixel) {
872 /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
873 For anything else (like ARGB4444) it doesn't matter
874 since we have no special code for it anyway */
875 if ( (vf->Rmask == 0x1f) &&
876 (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
884 /* Keep the video format, as long as the high 8 bits are
886 if ( (vf->Rmask == 0xff) && (vf->Bmask == 0xff0000) ) {
893 /* We have no other optimised formats right now. When/if a new
894 optimised alpha format is written, add the converter here */
897 format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
898 flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
899 flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
900 converted = SDL_ConvertSurface(surface, format, flags);
901 SDL_FreeFormat(format);
906 * Update a specific portion of the physical screen
908 void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
913 /* Perform some checking */
918 if ( (int)(x+w) > screen->w )
920 if ( (int)(y+h) > screen->h )
923 /* Fill the rectangle */
928 SDL_UpdateRects(screen, 1, &rect);
931 void SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects)
934 SDL_VideoDevice *video = current_video;
935 SDL_VideoDevice *this = current_video;
937 if ( screen == SDL_ShadowSurface ) {
938 /* Blit the shadow surface using saved mapping */
939 SDL_Palette *pal = screen->format->palette;
940 SDL_Color *saved_colors = NULL;
941 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) {
942 /* simulated 8bpp, use correct physical palette */
943 saved_colors = pal->colors;
944 if ( video->gammacols ) {
945 /* gamma-corrected palette */
946 pal->colors = video->gammacols;
947 } else if ( video->physpal ) {
948 /* physical palette different from logical */
949 pal->colors = video->physpal->colors;
952 if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
954 SDL_DrawCursor(SDL_ShadowSurface);
955 for ( i=0; i<numrects; ++i ) {
956 SDL_LowerBlit(SDL_ShadowSurface, &rects[i],
957 SDL_VideoSurface, &rects[i]);
959 SDL_EraseCursor(SDL_ShadowSurface);
962 for ( i=0; i<numrects; ++i ) {
963 SDL_LowerBlit(SDL_ShadowSurface, &rects[i],
964 SDL_VideoSurface, &rects[i]);
968 pal->colors = saved_colors;
970 /* Fall through to video surface update */
971 screen = SDL_VideoSurface;
973 if ( screen == SDL_VideoSurface ) {
974 /* Update the video surface */
975 if ( screen->offset ) {
976 for ( i=0; i<numrects; ++i ) {
977 rects[i].x += video->offset_x;
978 rects[i].y += video->offset_y;
980 video->UpdateRects(this, numrects, rects);
981 for ( i=0; i<numrects; ++i ) {
982 rects[i].x -= video->offset_x;
983 rects[i].y -= video->offset_y;
986 video->UpdateRects(this, numrects, rects);
992 * Performs hardware double buffering, if possible, or a full update if not.
994 int SDL_Flip(SDL_Surface *screen)
996 SDL_VideoDevice *video = current_video;
997 /* Copy the shadow surface to the video surface */
998 if ( screen == SDL_ShadowSurface ) {
1000 SDL_Palette *pal = screen->format->palette;
1001 SDL_Color *saved_colors = NULL;
1002 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) {
1003 /* simulated 8bpp, use correct physical palette */
1004 saved_colors = pal->colors;
1005 if ( video->gammacols ) {
1006 /* gamma-corrected palette */
1007 pal->colors = video->gammacols;
1008 } else if ( video->physpal ) {
1009 /* physical palette different from logical */
1010 pal->colors = video->physpal->colors;
1018 SDL_LowerBlit(SDL_ShadowSurface,&rect, SDL_VideoSurface,&rect);
1021 pal->colors = saved_colors;
1022 screen = SDL_VideoSurface;
1024 if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
1025 SDL_VideoDevice *this = current_video;
1026 return(video->FlipHWSurface(this, SDL_VideoSurface));
1028 SDL_UpdateRect(screen, 0, 0, 0, 0);
1033 static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors,
1034 int firstcolor, int ncolors)
1036 SDL_Palette *pal = screen->format->palette;
1037 SDL_Palette *vidpal;
1039 if ( colors != (pal->colors + firstcolor) ) {
1040 memcpy(pal->colors + firstcolor, colors,
1041 ncolors * sizeof(*colors));
1044 vidpal = SDL_VideoSurface->format->palette;
1045 if ( (screen == SDL_ShadowSurface) && vidpal ) {
1047 * This is a shadow surface, and the physical
1048 * framebuffer is also indexed. Propagate the
1049 * changes to its logical palette so that
1050 * updates are always identity blits
1052 memcpy(vidpal->colors + firstcolor, colors,
1053 ncolors * sizeof(*colors));
1055 SDL_FormatChanged(screen);
1058 static int SetPalette_physical(SDL_Surface *screen,
1059 SDL_Color *colors, int firstcolor, int ncolors)
1061 SDL_VideoDevice *video = current_video;
1064 if ( video->physpal ) {
1065 /* We need to copy the new colors, since we haven't
1066 * already done the copy in the logical set above.
1068 memcpy(video->physpal->colors + firstcolor,
1069 colors, ncolors * sizeof(*colors));
1071 if ( screen == SDL_ShadowSurface ) {
1072 if ( SDL_VideoSurface->flags & SDL_HWPALETTE ) {
1074 * The real screen is also indexed - set its physical
1075 * palette. The physical palette does not include the
1076 * gamma modification, we apply it directly instead,
1077 * but this only happens if we have hardware palette.
1079 screen = SDL_VideoSurface;
1082 * The video surface is not indexed - invalidate any
1083 * active shadow-to-video blit mappings.
1085 if ( screen->map->dst == SDL_VideoSurface ) {
1086 SDL_InvalidateMap(screen->map);
1088 if ( video->gamma ) {
1089 if( ! video->gammacols ) {
1090 SDL_Palette *pp = video->physpal;
1092 pp = screen->format->palette;
1093 video->gammacols = malloc(pp->ncolors
1094 * sizeof(SDL_Color));
1095 SDL_ApplyGamma(video->gamma,
1100 SDL_ApplyGamma(video->gamma, colors,
1106 SDL_UpdateRect(screen, 0, 0, 0, 0);
1110 if ( screen == SDL_VideoSurface ) {
1111 SDL_Color gcolors[256];
1113 if ( video->gamma ) {
1114 SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors);
1117 gotall = video->SetColors(video, firstcolor, ncolors, colors);
1119 /* The video flags shouldn't have SDL_HWPALETTE, and
1120 the video driver is responsible for copying back the
1121 correct colors into the video surface palette.
1125 SDL_CursorPaletteChanged();
1131 * Set the physical and/or logical colormap of a surface:
1132 * Only the screen has a physical colormap. It determines what is actually
1133 * sent to the display.
1134 * The logical colormap is used to map blits to/from the surface.
1135 * 'which' is one or both of SDL_LOGPAL, SDL_PHYSPAL
1137 * Return nonzero if all colours were set as requested, or 0 otherwise.
1139 int SDL_SetPalette(SDL_Surface *screen, int which,
1140 SDL_Color *colors, int firstcolor, int ncolors)
1146 if ( ! current_video ) {
1149 if ( screen != SDL_PublicSurface ) {
1150 /* only screens have physical palettes */
1151 which &= ~SDL_PHYSPAL;
1152 } else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) {
1153 /* hardware palettes required for split colormaps */
1154 which |= SDL_PHYSPAL | SDL_LOGPAL;
1157 /* Verify the parameters */
1158 pal = screen->format->palette;
1160 return 0; /* not a palettized surface */
1163 palsize = 1 << screen->format->BitsPerPixel;
1164 if ( ncolors > (palsize - firstcolor) ) {
1165 ncolors = (palsize - firstcolor);
1169 if ( which & SDL_LOGPAL ) {
1171 * Logical palette change: The actual screen isn't affected,
1172 * but the internal colormap is altered so that the
1173 * interpretation of the pixel values (for blits etc) is
1176 SetPalette_logical(screen, colors, firstcolor, ncolors);
1178 if ( which & SDL_PHYSPAL ) {
1179 SDL_VideoDevice *video = current_video;
1181 * Physical palette change: This doesn't affect the
1182 * program's idea of what the screen looks like, but changes
1183 * its actual appearance.
1186 return gotall; /* video not yet initialized */
1187 if(!video->physpal && !(which & SDL_LOGPAL) ) {
1188 /* Lazy physical palette allocation */
1190 SDL_Palette *pp = malloc(sizeof(*pp));
1191 current_video->physpal = pp;
1192 pp->ncolors = pal->ncolors;
1193 size = pp->ncolors * sizeof(SDL_Color);
1194 pp->colors = malloc(size);
1195 memcpy(pp->colors, pal->colors, size);
1197 if ( ! SetPalette_physical(screen,
1198 colors, firstcolor, ncolors) ) {
1205 int SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor,
1208 return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL,
1209 colors, firstcolor, ncolors);
1213 * Clean up the video subsystem
1215 void SDL_VideoQuit (void)
1217 SDL_Surface *ready_to_go;
1219 if ( current_video ) {
1220 SDL_VideoDevice *video = current_video;
1221 SDL_VideoDevice *this = current_video;
1223 /* Halt event processing before doing anything else */
1224 SDL_StopEventLoop();
1226 /* Clean up allocated window manager items */
1227 if ( SDL_PublicSurface ) {
1228 SDL_PublicSurface = NULL;
1232 /* Just in case... */
1233 SDL_WM_GrabInputOff();
1235 /* Clean up the system video */
1236 video->VideoQuit(this);
1238 /* Free any lingering surfaces */
1239 ready_to_go = SDL_ShadowSurface;
1240 SDL_ShadowSurface = NULL;
1241 SDL_FreeSurface(ready_to_go);
1242 if ( SDL_VideoSurface != NULL ) {
1243 ready_to_go = SDL_VideoSurface;
1244 SDL_VideoSurface = NULL;
1245 SDL_FreeSurface(ready_to_go);
1247 SDL_PublicSurface = NULL;
1249 /* Clean up miscellaneous memory */
1250 if ( video->physpal ) {
1251 free(video->physpal->colors);
1252 free(video->physpal);
1253 video->physpal = NULL;
1255 if ( video->gammacols ) {
1256 free(video->gammacols);
1257 video->gammacols = NULL;
1259 if ( video->gamma ) {
1261 video->gamma = NULL;
1263 if ( video->wm_title != NULL ) {
1264 free(video->wm_title);
1265 video->wm_title = NULL;
1267 if ( video->wm_icon != NULL ) {
1268 free(video->wm_icon);
1269 video->wm_icon = NULL;
1272 /* Finish cleaning up video subsystem */
1274 current_video = NULL;
1279 /* Load the GL driver library */
1280 int SDL_GL_LoadLibrary(const char *path)
1282 SDL_VideoDevice *video = current_video;
1283 SDL_VideoDevice *this = current_video;
1287 if ( video && video->GL_LoadLibrary ) {
1288 retval = video->GL_LoadLibrary(this, path);
1290 SDL_SetError("No dynamic GL support in video driver");
1295 void *SDL_GL_GetProcAddress(const char* proc)
1297 SDL_VideoDevice *video = current_video;
1298 SDL_VideoDevice *this = current_video;
1302 if ( video->GL_GetProcAddress ) {
1303 if ( video->gl_config.driver_loaded ) {
1304 func = video->GL_GetProcAddress(this, proc);
1306 SDL_SetError("No GL driver has been loaded");
1309 SDL_SetError("No dynamic GL support in video driver");
1314 /* Set the specified GL attribute for setting up a GL video mode */
1315 int SDL_GL_SetAttribute( SDL_GLattr attr, int value )
1318 SDL_VideoDevice *video = current_video;
1322 case SDL_GL_RED_SIZE:
1323 video->gl_config.red_size = value;
1325 case SDL_GL_GREEN_SIZE:
1326 video->gl_config.green_size = value;
1328 case SDL_GL_BLUE_SIZE:
1329 video->gl_config.blue_size = value;
1331 case SDL_GL_ALPHA_SIZE:
1332 video->gl_config.alpha_size = value;
1334 case SDL_GL_DOUBLEBUFFER:
1335 video->gl_config.double_buffer = value;
1337 case SDL_GL_BUFFER_SIZE:
1338 video->gl_config.buffer_size = value;
1340 case SDL_GL_DEPTH_SIZE:
1341 video->gl_config.depth_size = value;
1343 case SDL_GL_STENCIL_SIZE:
1344 video->gl_config.stencil_size = value;
1346 case SDL_GL_ACCUM_RED_SIZE:
1347 video->gl_config.accum_red_size = value;
1349 case SDL_GL_ACCUM_GREEN_SIZE:
1350 video->gl_config.accum_green_size = value;
1352 case SDL_GL_ACCUM_BLUE_SIZE:
1353 video->gl_config.accum_blue_size = value;
1355 case SDL_GL_ACCUM_ALPHA_SIZE:
1356 video->gl_config.accum_alpha_size = value;
1359 SDL_SetError("Unknown OpenGL attribute");
1366 /* Retrieve an attribute value from the windowing system. */
1367 int SDL_GL_GetAttribute(SDL_GLattr attr, int* value)
1370 SDL_VideoDevice* video = current_video;
1371 SDL_VideoDevice* this = current_video;
1373 if ( video->GL_GetAttribute ) {
1374 retval = this->GL_GetAttribute(this, attr, value);
1377 SDL_SetError("GL_GetAttribute not supported");
1382 /* Perform a GL buffer swap on the current GL context */
1383 void SDL_GL_SwapBuffers(void)
1385 SDL_VideoDevice *video = current_video;
1386 SDL_VideoDevice *this = current_video;
1388 if ( video->screen->flags & SDL_OPENGL ) {
1389 video->GL_SwapBuffers( this );
1393 /* Update rects with locking */
1394 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects)
1397 SDL_GL_UpdateRects(numrects, rects);
1401 /* Update rects without state setting and changing (the caller is responsible for it) */
1402 void SDL_GL_UpdateRects(int numrects, SDL_Rect *rects)
1405 SDL_VideoDevice *this = current_video;
1406 SDL_Rect update, tmp;
1409 for ( i = 0; i < numrects; i++ )
1413 for ( y = 0; y <= rects[i].h / 256; y++ )
1417 for ( x = 0; x <= rects[i].w / 256; x++ )
1424 if ( update.w > 256 )
1427 if ( update.h > 256 )
1431 this->glTexSubImage2D(
1438 this->is_32bit? GL_RGBA : GL_RGB,
1439 #ifdef GL_VERSION_1_2
1440 this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,
1444 (Uint8 *)this->screen->pixels +
1445 this->screen->format->BytesPerPixel * update.x +
1446 update.y * this->screen->pitch );
1450 * Note the parens around the function name:
1451 * This is because some OpenGL implementations define glTexCoord etc
1452 * as macros, and we don't want them expanded here.
1454 this->glBegin(GL_TRIANGLE_STRIP);
1455 (this->glTexCoord2f)( 0.0, 0.0 );
1456 (this->glVertex2i)( update.x, update.y );
1457 (this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 );
1458 (this->glVertex2i)( update.x + update.w, update.y );
1459 (this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) );
1460 (this->glVertex2i)( update.x, update.y + update.h );
1461 (this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) );
1462 (this->glVertex2i)( update.x + update.w , update.y + update.h );
1475 /* Lock == save current state */
1482 SDL_VideoDevice *this = current_video;
1484 this->glPushAttrib( GL_ALL_ATTRIB_BITS ); /* TODO: narrow range of what is saved */
1485 #ifdef GL_CLIENT_PIXEL_STORE_BIT
1486 this->glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
1489 this->glEnable(GL_TEXTURE_2D);
1490 this->glEnable(GL_BLEND);
1491 this->glDisable(GL_FOG);
1492 this->glDisable(GL_ALPHA_TEST);
1493 this->glDisable(GL_DEPTH_TEST);
1494 this->glDisable(GL_SCISSOR_TEST);
1495 this->glDisable(GL_STENCIL_TEST);
1496 this->glDisable(GL_CULL_FACE);
1498 this->glBindTexture( GL_TEXTURE_2D, this->texture );
1499 this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1500 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1501 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1502 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
1503 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
1505 this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel );
1506 this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1507 (this->glColor4f)(1.0, 1.0, 1.0, 1.0); /* Solaris workaround */
1509 this->glViewport(0, 0, this->screen->w, this->screen->h);
1510 this->glMatrixMode(GL_PROJECTION);
1511 this->glPushMatrix();
1512 this->glLoadIdentity();
1514 this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0);
1516 this->glMatrixMode(GL_MODELVIEW);
1517 this->glPushMatrix();
1518 this->glLoadIdentity();
1523 /* Unlock == restore saved state */
1524 void SDL_GL_Unlock()
1530 SDL_VideoDevice *this = current_video;
1532 this->glPopMatrix();
1533 this->glMatrixMode(GL_PROJECTION);
1534 this->glPopMatrix();
1536 this->glPopClientAttrib();
1537 this->glPopAttrib();
1543 * Sets/Gets the title and icon text of the display window, if any.
1545 void SDL_WM_SetCaption (const char *title, const char *icon)
1547 SDL_VideoDevice *video = current_video;
1548 SDL_VideoDevice *this = current_video;
1552 if ( video->wm_title ) {
1553 free(video->wm_title);
1555 video->wm_title = (char *)malloc(strlen(title)+1);
1556 if ( video->wm_title != NULL ) {
1557 strcpy(video->wm_title, title);
1561 if ( video->wm_icon ) {
1562 free(video->wm_icon);
1564 video->wm_icon = (char *)malloc(strlen(icon)+1);
1565 if ( video->wm_icon != NULL ) {
1566 strcpy(video->wm_icon, icon);
1569 if ( (title || icon) && (video->SetCaption != NULL) ) {
1570 video->SetCaption(this, video->wm_title,video->wm_icon);
1574 void SDL_WM_GetCaption (char **title, char **icon)
1576 SDL_VideoDevice *video = current_video;
1580 *title = video->wm_title;
1583 *icon = video->wm_icon;
1588 /* Utility function used by SDL_WM_SetIcon() */
1589 static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask)
1593 #define SET_MASKBIT(icon, x, y, mask) \
1594 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
1596 colorkey = icon->format->colorkey;
1597 switch (icon->format->BytesPerPixel) {
1598 case 1: { Uint8 *pixels;
1599 for ( y=0; y<icon->h; ++y ) {
1600 pixels = (Uint8 *)icon->pixels + y*icon->pitch;
1601 for ( x=0; x<icon->w; ++x ) {
1602 if ( *pixels++ == colorkey ) {
1603 SET_MASKBIT(icon, x, y, mask);
1610 case 2: { Uint16 *pixels;
1611 for ( y=0; y<icon->h; ++y ) {
1612 pixels = (Uint16 *)icon->pixels +
1614 for ( x=0; x<icon->w; ++x ) {
1615 if ( *pixels++ == colorkey ) {
1616 SET_MASKBIT(icon, x, y, mask);
1623 case 4: { Uint32 *pixels;
1624 for ( y=0; y<icon->h; ++y ) {
1625 pixels = (Uint32 *)icon->pixels +
1627 for ( x=0; x<icon->w; ++x ) {
1628 if ( *pixels++ == colorkey ) {
1629 SET_MASKBIT(icon, x, y, mask);
1639 * Sets the window manager icon for the display window.
1641 void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask)
1643 SDL_VideoDevice *video = current_video;
1644 SDL_VideoDevice *this = current_video;
1646 if ( icon && video->SetIcon ) {
1647 /* Generate a mask if necessary, and create the icon! */
1648 if ( mask == NULL ) {
1649 int mask_len = icon->h*(icon->w+7)/8;
1650 mask = (Uint8 *)malloc(mask_len);
1651 if ( mask == NULL ) {
1654 memset(mask, ~0, mask_len);
1655 if ( icon->flags & SDL_SRCCOLORKEY ) {
1656 CreateMaskFromColorKey(icon, mask);
1658 video->SetIcon(video, icon, mask);
1661 video->SetIcon(this, icon, mask);
1667 * Grab or ungrab the keyboard and mouse input.
1668 * This function returns the final grab mode after calling the
1669 * driver dependent function.
1671 static SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode)
1673 SDL_VideoDevice *video = current_video;
1674 SDL_VideoDevice *this = current_video;
1676 /* Only do something if we have support for grabs */
1677 if ( video->GrabInput == NULL ) {
1678 return(video->input_grab);
1681 /* If the final grab mode if off, only then do we actually grab */
1683 printf("SDL_WM_GrabInputRaw(%d) ... ", mode);
1685 if ( mode == SDL_GRAB_OFF ) {
1686 if ( video->input_grab != SDL_GRAB_OFF ) {
1687 mode = video->GrabInput(this, mode);
1690 if ( video->input_grab == SDL_GRAB_OFF ) {
1691 mode = video->GrabInput(this, mode);
1694 if ( mode != video->input_grab ) {
1695 video->input_grab = mode;
1696 if ( video->CheckMouseMode ) {
1697 video->CheckMouseMode(this);
1701 printf("Final mode %d\n", video->input_grab);
1704 /* Return the final grab state */
1705 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1706 mode -= SDL_GRAB_FULLSCREEN;
1710 SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode)
1712 SDL_VideoDevice *video = current_video;
1714 /* If the video isn't initialized yet, we can't do anything */
1716 return SDL_GRAB_OFF;
1719 /* Return the current mode on query */
1720 if ( mode == SDL_GRAB_QUERY ) {
1721 mode = video->input_grab;
1722 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1723 mode -= SDL_GRAB_FULLSCREEN;
1729 printf("SDL_WM_GrabInput(%d) ... ", mode);
1731 /* If the video surface is fullscreen, we always grab */
1732 if ( mode >= SDL_GRAB_FULLSCREEN ) {
1733 mode -= SDL_GRAB_FULLSCREEN;
1735 if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {
1736 mode += SDL_GRAB_FULLSCREEN;
1738 return(SDL_WM_GrabInputRaw(mode));
1740 static SDL_GrabMode SDL_WM_GrabInputOff(void)
1744 /* First query the current grab state */
1745 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
1747 /* Now explicitly turn off input grab */
1748 SDL_WM_GrabInputRaw(SDL_GRAB_OFF);
1750 /* Return the old state */
1755 * Iconify the window in window managed environments.
1756 * A successful iconification will result in an SDL_APPACTIVE loss event.
1758 int SDL_WM_IconifyWindow(void)
1760 SDL_VideoDevice *video = current_video;
1761 SDL_VideoDevice *this = current_video;
1765 if ( video->IconifyWindow ) {
1766 retval = video->IconifyWindow(this);
1772 * Toggle fullscreen mode
1774 int SDL_WM_ToggleFullScreen(SDL_Surface *surface)
1776 SDL_VideoDevice *video = current_video;
1777 SDL_VideoDevice *this = current_video;
1781 if ( SDL_PublicSurface && (surface == SDL_PublicSurface) &&
1782 video->ToggleFullScreen ) {
1783 if ( surface->flags & SDL_FULLSCREEN ) {
1784 toggled = video->ToggleFullScreen(this, 0);
1786 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN;
1787 SDL_PublicSurface->flags &= ~SDL_FULLSCREEN;
1790 toggled = video->ToggleFullScreen(this, 1);
1792 SDL_VideoSurface->flags |= SDL_FULLSCREEN;
1793 SDL_PublicSurface->flags |= SDL_FULLSCREEN;
1796 /* Double-check the grab state inside SDL_WM_GrabInput() */
1798 SDL_WM_GrabInput(video->input_grab);
1805 * Get some platform dependent window manager information
1807 int SDL_GetWMInfo (SDL_SysWMinfo *info)
1809 SDL_VideoDevice *video = current_video;
1810 SDL_VideoDevice *this = current_video;
1812 if ( video && video->GetWMInfo ) {
1813 return(video->GetWMInfo(this, info));