2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 /* The high-level video driver subsystem */
27 #include "SDL_video.h"
28 #include "SDL_sysvideo.h"
30 #include "SDL_pixels_c.h"
31 #include "SDL_renderer_gl.h"
32 #include "SDL_renderer_gles.h"
33 #include "SDL_renderer_sw.h"
34 #include "../events/SDL_sysevents.h"
35 #include "../events/SDL_events_c.h"
37 #if SDL_VIDEO_OPENGL_ES
38 #include "SDL_opengles.h"
39 #endif /* SDL_VIDEO_OPENGL_ES */
42 #include "SDL_opengl.h"
44 /* On Windows, windows.h defines CreateWindow */
48 #endif /* SDL_VIDEO_OPENGL */
50 /* Available video drivers */
51 static VideoBootStrap *bootstrap[] = {
52 #if SDL_VIDEO_DRIVER_COCOA
55 #if SDL_VIDEO_DRIVER_X11
58 #if SDL_VIDEO_DRIVER_FBCON
61 #if SDL_VIDEO_DRIVER_DIRECTFB
64 #if SDL_VIDEO_DRIVER_PS2GS
67 #if SDL_VIDEO_DRIVER_PS3
70 #if SDL_VIDEO_DRIVER_SVGALIB
73 #if SDL_VIDEO_DRIVER_GAPI
76 #if SDL_VIDEO_DRIVER_WIN32
79 #if SDL_VIDEO_DRIVER_BWINDOW
82 #if SDL_VIDEO_DRIVER_PHOTON
85 #if SDL_VIDEO_DRIVER_QNXGF
88 #if SDL_VIDEO_DRIVER_EPOC
91 #if SDL_VIDEO_DRIVER_RISCOS
94 #if SDL_VIDEO_DRIVER_NDS
97 #if SDL_VIDEO_DRIVER_UIKIT
100 #if SDL_VIDEO_DRIVER_DUMMY
103 #if SDL_VIDEO_DRIVER_PANDORA
109 static SDL_VideoDevice *_this = NULL;
111 /* Various local functions */
112 static void SDL_UpdateWindowGrab(SDL_Window * window);
115 cmpmodes(const void *A, const void *B)
117 SDL_DisplayMode a = *(const SDL_DisplayMode *) A;
118 SDL_DisplayMode b = *(const SDL_DisplayMode *) B;
126 if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) {
127 return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format);
129 if (SDL_PIXELLAYOUT(a.format) != SDL_PIXELLAYOUT(b.format)) {
130 return SDL_PIXELLAYOUT(b.format) - SDL_PIXELLAYOUT(a.format);
132 if (a.refresh_rate != b.refresh_rate) {
133 return b.refresh_rate - a.refresh_rate;
139 SDL_UninitializedVideo()
141 SDL_SetError("Video subsystem has not been initialized");
145 SDL_GetNumVideoDrivers(void)
147 return SDL_arraysize(bootstrap) - 1;
151 SDL_GetVideoDriver(int index)
153 if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
154 return bootstrap[index]->name;
160 * Initialize the video and event subsystems -- determine native pixel format
163 SDL_VideoInit(const char *driver_name, Uint32 flags)
165 SDL_VideoDevice *video;
169 /* Toggle the event thread flags, based on OS requirements */
170 #if defined(MUST_THREAD_EVENTS)
171 flags |= SDL_INIT_EVENTTHREAD;
172 #elif defined(CANT_THREAD_EVENTS)
173 if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
174 SDL_SetError("OS doesn't support threaded events");
179 /* Start the event loop */
180 if (SDL_StartEventLoop(flags) < 0) {
183 /* Check to make sure we don't overwrite '_this' */
187 /* Select the proper video driver */
190 if (driver_name == NULL) {
191 driver_name = SDL_getenv("SDL_VIDEODRIVER");
193 if (driver_name != NULL) {
194 for (i = 0; bootstrap[i]; ++i) {
195 if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) {
196 video = bootstrap[i]->create(index);
201 for (i = 0; bootstrap[i]; ++i) {
202 if (bootstrap[i]->available()) {
203 video = bootstrap[i]->create(index);
212 SDL_SetError("%s not available", driver_name);
214 SDL_SetError("No available video device");
219 _this->name = bootstrap[i]->name;
220 _this->next_object_id = 1;
223 /* Set some very sane GL defaults */
224 _this->gl_config.driver_loaded = 0;
225 _this->gl_config.dll_handle = NULL;
226 _this->gl_config.red_size = 3;
227 _this->gl_config.green_size = 3;
228 _this->gl_config.blue_size = 2;
229 _this->gl_config.alpha_size = 0;
230 _this->gl_config.buffer_size = 0;
231 _this->gl_config.depth_size = 16;
232 _this->gl_config.stencil_size = 0;
233 _this->gl_config.double_buffer = 1;
234 _this->gl_config.accum_red_size = 0;
235 _this->gl_config.accum_green_size = 0;
236 _this->gl_config.accum_blue_size = 0;
237 _this->gl_config.accum_alpha_size = 0;
238 _this->gl_config.stereo = 0;
239 _this->gl_config.multisamplebuffers = 0;
240 _this->gl_config.multisamplesamples = 0;
241 _this->gl_config.retained_backing = 1;
242 _this->gl_config.accelerated = -1; /* not known, don't set */
243 _this->gl_config.major_version = 2;
244 _this->gl_config.minor_version = 1;
246 /* Initialize the video subsystem */
247 if (_this->VideoInit(_this) < 0) {
251 /* Make sure some displays were added */
252 if (_this->num_displays == 0) {
253 SDL_SetError("The video driver did not add any displays");
257 /* The software renderer is always available */
258 for (i = 0; i < _this->num_displays; ++i) {
259 SDL_VideoDisplay *display = &_this->displays[i];
260 if (_this->GL_CreateContext) {
261 #if SDL_VIDEO_RENDER_OGL
262 SDL_AddRenderDriver(display, &GL_RenderDriver);
264 #if SDL_VIDEO_RENDER_OGL_ES
265 SDL_AddRenderDriver(display, &GL_ES_RenderDriver);
268 if (display->num_render_drivers > 0) {
269 SDL_AddRenderDriver(display, &SW_RenderDriver);
273 /* We're ready to go! */
278 SDL_GetCurrentVideoDriver()
281 SDL_UninitializedVideo();
294 SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
296 SDL_VideoDisplay display;
300 display.desktop_mode = *desktop_mode;
302 display.current_mode = display.desktop_mode;
304 return SDL_AddVideoDisplay(&display);
308 SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
310 SDL_VideoDisplay *displays;
314 SDL_realloc(_this->displays,
315 (_this->num_displays + 1) * sizeof(*displays));
317 index = _this->num_displays++;
318 displays[index] = *display;
319 displays[index].device = _this;
320 _this->displays = displays;
328 SDL_GetNumVideoDisplays(void)
331 SDL_UninitializedVideo();
334 return _this->num_displays;
338 SDL_SelectVideoDisplay(int index)
341 SDL_UninitializedVideo();
344 if (index < 0 || index >= _this->num_displays) {
345 SDL_SetError("index must be in the range 0 - %d",
346 _this->num_displays - 1);
349 _this->current_display = index;
354 SDL_GetCurrentVideoDisplay(void)
357 SDL_UninitializedVideo();
360 return _this->current_display;
364 SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
366 SDL_DisplayMode *modes;
369 /* Make sure we don't already have the mode in the list */
370 modes = display->display_modes;
371 nmodes = display->num_display_modes;
372 for (i = nmodes; i--;) {
373 if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
378 /* Go ahead and add the new mode */
379 if (nmodes == display->max_display_modes) {
382 (display->max_display_modes + 32) * sizeof(*modes));
386 display->display_modes = modes;
387 display->max_display_modes += 32;
389 modes[nmodes] = *mode;
390 display->num_display_modes++;
392 /* Re-sort video modes */
393 SDL_qsort(display->display_modes, display->num_display_modes,
394 sizeof(SDL_DisplayMode), cmpmodes);
400 SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
402 if (!display->num_display_modes && _this->GetDisplayModes) {
403 _this->GetDisplayModes(_this, display);
404 SDL_qsort(display->display_modes, display->num_display_modes,
405 sizeof(SDL_DisplayMode), cmpmodes);
407 return display->num_display_modes;
411 SDL_GetNumDisplayModes()
414 return SDL_GetNumDisplayModesForDisplay(&SDL_CurrentDisplay);
420 SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode)
422 if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) {
423 SDL_SetError("index must be in the range of 0 - %d",
424 SDL_GetNumDisplayModesForDisplay(display) - 1);
428 *mode = display->display_modes[index];
434 SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
436 return SDL_GetDisplayModeForDisplay(&SDL_CurrentDisplay, index, mode);
440 SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode)
443 *mode = display->desktop_mode;
449 SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode)
452 SDL_UninitializedVideo();
455 return SDL_GetDesktopDisplayModeForDisplay(&SDL_CurrentDisplay, mode);
459 SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode)
462 *mode = display->current_mode;
468 SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
471 SDL_UninitializedVideo();
474 return SDL_GetCurrentDisplayModeForDisplay(&SDL_CurrentDisplay, mode);
478 SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
479 const SDL_DisplayMode * mode,
480 SDL_DisplayMode * closest)
482 Uint32 target_format;
483 int target_refresh_rate;
485 SDL_DisplayMode *current, *match;
487 if (!mode || !closest) {
488 SDL_SetError("Missing desired mode or closest mode parameter");
492 /* Default to the desktop format */
494 target_format = mode->format;
496 target_format = display->desktop_mode.format;
499 /* Default to the desktop refresh rate */
500 if (mode->refresh_rate) {
501 target_refresh_rate = mode->refresh_rate;
503 target_refresh_rate = display->desktop_mode.refresh_rate;
507 for (i = 0; i < SDL_GetNumDisplayModesForDisplay(display); ++i) {
508 current = &display->display_modes[i];
510 if (current->w && (current->w < mode->w)) {
511 /* Out of sorted modes large enough here */
514 if (current->h && (current->h < mode->h)) {
515 if (current->w && (current->w == mode->w)) {
516 /* Out of sorted modes large enough here */
519 /* Wider, but not tall enough, due to a different
520 aspect ratio. This mode must be skipped, but closer
521 modes may still follow. */
524 if (!match || current->w < match->w || current->h < match->h) {
528 if (current->format != match->format) {
529 /* Sorted highest depth to lowest */
530 if (current->format == target_format ||
531 (SDL_BITSPERPIXEL(current->format) >=
532 SDL_BITSPERPIXEL(target_format)
533 && SDL_PIXELTYPE(current->format) ==
534 SDL_PIXELTYPE(target_format))) {
539 if (current->refresh_rate != match->refresh_rate) {
540 /* Sorted highest refresh to lowest */
541 if (current->refresh_rate >= target_refresh_rate) {
548 closest->format = match->format;
550 closest->format = mode->format;
552 if (match->w && match->h) {
553 closest->w = match->w;
554 closest->h = match->h;
556 closest->w = mode->w;
557 closest->h = mode->h;
559 if (match->refresh_rate) {
560 closest->refresh_rate = match->refresh_rate;
562 closest->refresh_rate = mode->refresh_rate;
564 closest->driverdata = match->driverdata;
567 * Pick some reasonable defaults if the app and driver don't
570 if (!closest->format) {
571 closest->format = SDL_PIXELFORMAT_RGB888;
585 SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode,
586 SDL_DisplayMode * closest)
589 SDL_UninitializedVideo();
592 return SDL_GetClosestDisplayModeForDisplay(&SDL_CurrentDisplay, mode, closest);
596 SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
598 SDL_DisplayMode display_mode;
599 SDL_DisplayMode current_mode;
603 mode = &display->desktop_mode;
605 display_mode = *mode;
607 /* Default to the current mode */
608 if (!display_mode.format) {
609 display_mode.format = display->current_mode.format;
611 if (!display_mode.w) {
612 display_mode.w = display->current_mode.w;
614 if (!display_mode.h) {
615 display_mode.h = display->current_mode.h;
617 if (!display_mode.refresh_rate) {
618 display_mode.refresh_rate = display->current_mode.refresh_rate;
621 /* Get a good video mode, the closest one possible */
622 if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
623 SDL_SetError("No video mode large enough for %dx%d",
624 display_mode.w, display_mode.h);
628 /* See if there's anything left to do */
629 SDL_GetCurrentDisplayModeForDisplay(display, ¤t_mode);
630 if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) {
634 /* Actually change the display mode */
635 if (_this->SetDisplayMode(_this, display, &display_mode) < 0) {
638 display->current_mode = display_mode;
640 /* Set up a palette, if necessary */
641 if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
642 ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format));
646 if ((!ncolors && display->palette) || (ncolors && !display->palette)
647 || (ncolors && ncolors != display->palette->ncolors)) {
648 if (display->palette) {
649 SDL_FreePalette(display->palette);
650 display->palette = NULL;
653 display->palette = SDL_AllocPalette(ncolors);
654 if (!display->palette) {
657 SDL_DitherColors(display->palette->colors,
658 SDL_BITSPERPIXEL(display_mode.format));
666 SDL_SetDisplayMode(const SDL_DisplayMode * mode)
669 SDL_UninitializedVideo();
672 return SDL_SetDisplayModeForDisplay(&SDL_CurrentDisplay, mode);
676 SDL_SetWindowDisplayMode(SDL_WindowID windowID, const SDL_DisplayMode * mode)
678 SDL_Window *window = SDL_GetWindowFromID(windowID);
685 window->fullscreen_mode = *mode;
687 SDL_zero(window->fullscreen_mode);
692 SDL_GetWindowDisplayMode(SDL_WindowID windowID, SDL_DisplayMode * mode)
694 SDL_Window *window = SDL_GetWindowFromID(windowID);
695 SDL_DisplayMode fullscreen_mode;
701 fullscreen_mode = window->fullscreen_mode;
702 if (!fullscreen_mode.w) {
703 fullscreen_mode.w = window->w;
705 if (!fullscreen_mode.h) {
706 fullscreen_mode.h = window->h;
709 if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayFromWindow(window),
712 SDL_SetError("Couldn't find display mode match");
717 *mode = fullscreen_mode;
723 SDL_SetPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors)
725 SDL_Palette *palette;
728 palette = display->palette;
730 SDL_SetError("Display mode does not have a palette");
733 status = SDL_SetPaletteColors(palette, colors, firstcolor, ncolors);
735 if (_this->SetDisplayPalette) {
736 if (_this->SetDisplayPalette(_this, display, palette) < 0) {
744 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors)
747 SDL_UninitializedVideo();
750 return SDL_SetPaletteForDisplay(&SDL_CurrentDisplay, colors, firstcolor, ncolors);
754 SDL_GetPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors)
756 SDL_Palette *palette;
758 palette = display->palette;
759 if (!palette || !palette->ncolors) {
760 SDL_SetError("Display mode does not have a palette");
763 if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) {
764 SDL_SetError("Palette indices are out of range");
767 SDL_memcpy(colors, &palette->colors[firstcolor],
768 ncolors * sizeof(*colors));
773 SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors)
775 SDL_Palette *palette;
778 SDL_UninitializedVideo();
781 return SDL_GetPaletteForDisplay(&SDL_CurrentDisplay, colors, firstcolor, ncolors);
785 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
787 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
789 SDL_WINDOW_BORDERLESS |
790 SDL_WINDOW_RESIZABLE |
791 SDL_WINDOW_INPUT_GRABBED);
792 SDL_VideoDisplay *display;
798 /* Initialize the video system if needed */
799 if (SDL_VideoInit(NULL, 0) < 0) {
803 if (flags & SDL_WINDOW_OPENGL) {
804 if (!_this->GL_CreateContext) {
805 SDL_SetError("No OpenGL support in video driver");
808 SDL_GL_LoadLibrary(NULL);
811 window.id = _this->next_object_id++;
816 window.flags = (flags & allowed_flags);
817 window.display = _this->current_display;
819 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
820 if (flags & SDL_WINDOW_OPENGL) {
821 SDL_GL_UnloadLibrary();
825 display = &SDL_CurrentDisplay;
826 num_windows = display->num_windows;
828 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
830 if (_this->DestroyWindow) {
831 _this->DestroyWindow(_this, &window);
833 if (flags & SDL_WINDOW_OPENGL) {
834 SDL_GL_UnloadLibrary();
838 windows[num_windows] = window;
839 display->windows = windows;
840 display->num_windows++;
843 SDL_SetWindowTitle(window.id, title);
845 if (flags & SDL_WINDOW_MAXIMIZED) {
846 SDL_MaximizeWindow(window.id);
848 if (flags & SDL_WINDOW_MINIMIZED) {
849 SDL_MinimizeWindow(window.id);
851 if (flags & SDL_WINDOW_SHOWN) {
852 SDL_ShowWindow(window.id);
854 SDL_UpdateWindowGrab(&window);
860 SDL_CreateWindowFrom(const void *data)
862 SDL_VideoDisplay *display;
868 SDL_UninitializedVideo();
872 window.id = _this->next_object_id++;
873 window.display = _this->current_display;
874 window.flags = SDL_WINDOW_FOREIGN;
876 if (!_this->CreateWindowFrom ||
877 _this->CreateWindowFrom(_this, &window, data) < 0) {
880 /* FIXME: Find out what display this window is actually on... */
881 display = &SDL_CurrentDisplay;
882 num_windows = display->num_windows;
884 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
886 if (_this->DestroyWindow) {
887 _this->DestroyWindow(_this, &window);
890 SDL_free(window.title);
894 windows[num_windows] = window;
895 display->windows = windows;
896 display->num_windows++;
902 SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
904 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
906 SDL_WINDOW_BORDERLESS |
907 SDL_WINDOW_RESIZABLE |
908 SDL_WINDOW_INPUT_GRABBED |
910 char *title = window->title;
912 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
913 SDL_SetError("No OpenGL support in video driver");
916 if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
917 if (flags & SDL_WINDOW_OPENGL) {
918 SDL_GL_LoadLibrary(NULL);
920 SDL_GL_UnloadLibrary();
924 if (window->flags & SDL_WINDOW_FOREIGN) {
925 /* Can't destroy and re-create foreign windows, hrm */
926 flags |= SDL_WINDOW_FOREIGN;
928 flags &= ~SDL_WINDOW_FOREIGN;
931 if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
932 _this->DestroyWindow(_this, window);
935 window->title = NULL;
936 window->flags = (flags & allowed_flags);
938 if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) {
939 if (_this->CreateWindow(_this, window) < 0) {
940 if (flags & SDL_WINDOW_OPENGL) {
941 SDL_GL_UnloadLibrary();
948 SDL_SetWindowTitle(window->id, title);
951 if (flags & SDL_WINDOW_MAXIMIZED) {
952 SDL_MaximizeWindow(window->id);
954 if (flags & SDL_WINDOW_MINIMIZED) {
955 SDL_MinimizeWindow(window->id);
957 if (flags & SDL_WINDOW_SHOWN) {
958 SDL_ShowWindow(window->id);
960 SDL_UpdateWindowGrab(window);
966 SDL_GetWindowFromID(SDL_WindowID windowID)
971 SDL_UninitializedVideo();
975 for (i = 0; i < _this->num_displays; ++i) {
976 SDL_VideoDisplay *display = &_this->displays[i];
977 for (j = 0; j < display->num_windows; ++j) {
978 SDL_Window *window = &display->windows[j];
979 if (window->id == windowID) {
985 /* Just return the first active window */
986 for (i = 0; i < _this->num_displays; ++i) {
987 SDL_VideoDisplay *display = &_this->displays[i];
988 for (j = 0; j < display->num_windows; ++j) {
989 SDL_Window *window = &display->windows[j];
994 /* Couldn't find the window with the requested ID */
995 SDL_SetError("Invalid window ID");
1000 SDL_GetDisplayFromWindow(SDL_Window * window)
1003 SDL_UninitializedVideo();
1009 return &_this->displays[window->display];
1012 static __inline__ SDL_Renderer *
1013 SDL_GetCurrentRenderer(SDL_bool create)
1016 SDL_UninitializedVideo();
1019 if (!SDL_CurrentRenderer) {
1021 SDL_SetError("Use SDL_CreateRenderer() to create a renderer");
1024 if (SDL_CreateRenderer(0, -1, 0) < 0) {
1028 return SDL_CurrentRenderer;
1032 SDL_GetWindowFlags(SDL_WindowID windowID)
1034 SDL_Window *window = SDL_GetWindowFromID(windowID);
1039 return window->flags;
1043 SDL_SetWindowTitle(SDL_WindowID windowID, const char *title)
1045 SDL_Window *window = SDL_GetWindowFromID(windowID);
1047 if (!window || title == window->title) {
1050 if (window->title) {
1051 SDL_free(window->title);
1054 window->title = SDL_strdup(title);
1056 window->title = NULL;
1059 if (_this->SetWindowTitle) {
1060 _this->SetWindowTitle(_this, window);
1065 SDL_GetWindowTitle(SDL_WindowID windowID)
1067 SDL_Window *window = SDL_GetWindowFromID(windowID);
1072 return window->title;
1076 SDL_SetWindowIcon(SDL_WindowID windowID, SDL_Surface * icon)
1078 SDL_Window *window = SDL_GetWindowFromID(windowID);
1083 if (_this->SetWindowIcon) {
1084 _this->SetWindowIcon(_this, window, icon);
1089 SDL_SetWindowData(SDL_WindowID windowID, void *userdata)
1091 SDL_Window *window = SDL_GetWindowFromID(windowID);
1096 window->userdata = userdata;
1100 SDL_GetWindowData(SDL_WindowID windowID)
1102 SDL_Window *window = SDL_GetWindowFromID(windowID);
1107 return window->userdata;
1111 SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y)
1113 SDL_Window *window = SDL_GetWindowFromID(windowID);
1114 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1119 if (x != SDL_WINDOWPOS_UNDEFINED) {
1122 if (y != SDL_WINDOWPOS_UNDEFINED) {
1125 if (_this->SetWindowPosition) {
1126 _this->SetWindowPosition(_this, window);
1128 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, x, y);
1132 SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y)
1134 SDL_Window *window = SDL_GetWindowFromID(windowID);
1148 SDL_SetWindowSize(SDL_WindowID windowID, int w, int h)
1150 SDL_Window *window = SDL_GetWindowFromID(windowID);
1158 if (_this->SetWindowSize) {
1159 _this->SetWindowSize(_this, window);
1161 SDL_OnWindowResized(window);
1165 SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h)
1167 SDL_Window *window = SDL_GetWindowFromID(windowID);
1187 SDL_ShowWindow(SDL_WindowID windowID)
1189 SDL_Window *window = SDL_GetWindowFromID(windowID);
1191 if (!window || (window->flags & SDL_WINDOW_SHOWN)) {
1195 if (_this->ShowWindow) {
1196 _this->ShowWindow(_this, window);
1198 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
1202 SDL_HideWindow(SDL_WindowID windowID)
1204 SDL_Window *window = SDL_GetWindowFromID(windowID);
1206 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
1210 if (_this->HideWindow) {
1211 _this->HideWindow(_this, window);
1213 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
1217 SDL_RaiseWindow(SDL_WindowID windowID)
1219 SDL_Window *window = SDL_GetWindowFromID(windowID);
1221 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
1224 if (_this->RaiseWindow) {
1225 _this->RaiseWindow(_this, window);
1230 SDL_MaximizeWindow(SDL_WindowID windowID)
1232 SDL_Window *window = SDL_GetWindowFromID(windowID);
1234 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) {
1238 if (_this->MaximizeWindow) {
1239 _this->MaximizeWindow(_this, window);
1241 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
1245 SDL_MinimizeWindow(SDL_WindowID windowID)
1247 SDL_Window *window = SDL_GetWindowFromID(windowID);
1249 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) {
1253 if (_this->MinimizeWindow) {
1254 _this->MinimizeWindow(_this, window);
1256 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
1260 SDL_RestoreWindow(SDL_WindowID windowID)
1262 SDL_Window *window = SDL_GetWindowFromID(windowID);
1265 || !(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
1269 if (_this->RestoreWindow) {
1270 _this->RestoreWindow(_this, window);
1272 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
1276 SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen)
1278 SDL_Window *window = SDL_GetWindowFromID(windowID);
1284 fullscreen = SDL_WINDOW_FULLSCREEN;
1286 if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
1290 window->flags |= SDL_WINDOW_FULLSCREEN;
1292 if (FULLSCREEN_VISIBLE(window)) {
1293 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1294 SDL_DisplayMode fullscreen_mode;
1296 /* Hide any other fullscreen windows */
1298 for (i = 0; i < display->num_windows; ++i) {
1299 SDL_Window *other = &display->windows[i];
1300 if (other->id != windowID && FULLSCREEN_VISIBLE(other)) {
1301 SDL_MinimizeWindow(other->id);
1305 if (SDL_GetWindowDisplayMode(windowID, &fullscreen_mode) == 0) {
1306 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
1310 window->flags &= ~SDL_WINDOW_FULLSCREEN;
1312 if (FULLSCREEN_VISIBLE(window)) {
1313 SDL_SetDisplayMode(NULL);
1320 SDL_SetWindowGrab(SDL_WindowID windowID, int mode)
1322 SDL_Window *window = SDL_GetWindowFromID(windowID);
1324 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
1328 window->flags |= SDL_WINDOW_INPUT_GRABBED;
1330 window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
1332 SDL_UpdateWindowGrab(window);
1336 SDL_UpdateWindowGrab(SDL_Window * window)
1338 if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) {
1339 _this->SetWindowGrab(_this, window);
1344 SDL_GetWindowGrab(SDL_WindowID windowID)
1346 SDL_Window *window = SDL_GetWindowFromID(windowID);
1351 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
1355 SDL_OnWindowShown(SDL_Window * window)
1357 if (window->flags & SDL_WINDOW_FULLSCREEN) {
1358 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
1363 SDL_OnWindowHidden(SDL_Window * window)
1365 if (window->flags & SDL_WINDOW_FULLSCREEN) {
1366 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
1371 SDL_OnWindowResized(SDL_Window * window)
1373 SDL_Renderer *renderer = window->renderer;
1375 if (renderer && renderer->DisplayModeChanged) {
1376 renderer->DisplayModeChanged(renderer);
1381 SDL_OnWindowFocusGained(SDL_Window * window)
1383 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1385 if (FULLSCREEN_VISIBLE(window)) {
1386 SDL_SetDisplayMode(&window->fullscreen_mode);
1388 if (display->gamma && _this->SetDisplayGammaRamp) {
1389 _this->SetDisplayGammaRamp(_this, display, display->gamma);
1391 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
1392 && _this->SetWindowGrab) {
1393 _this->SetWindowGrab(_this, window);
1398 SDL_OnWindowFocusLost(SDL_Window * window)
1400 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1402 if (FULLSCREEN_VISIBLE(window)) {
1403 SDL_MinimizeWindow(window->id);
1404 SDL_SetDisplayMode(NULL);
1406 if (display->gamma && _this->SetDisplayGammaRamp) {
1407 _this->SetDisplayGammaRamp(_this, display, display->saved_gamma);
1409 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
1410 && _this->SetWindowGrab) {
1411 _this->SetWindowGrab(_this, window);
1416 SDL_GetFocusWindow(void)
1418 SDL_VideoDisplay *display;
1424 display = &SDL_CurrentDisplay;
1425 for (i = 0; i < display->num_windows; ++i) {
1426 SDL_Window *window = &display->windows[i];
1428 if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
1436 SDL_DestroyWindow(SDL_WindowID windowID)
1443 /* Restore video mode, etc. */
1444 SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
1446 for (i = 0; i < _this->num_displays; ++i) {
1447 SDL_VideoDisplay *display = &_this->displays[i];
1448 for (j = 0; j < display->num_windows; ++j) {
1449 SDL_Window *window = &display->windows[j];
1450 if (window->id != windowID) {
1453 if (window->title) {
1454 SDL_free(window->title);
1455 window->title = NULL;
1457 if (window->renderer) {
1458 SDL_DestroyRenderer(window->id);
1459 window->renderer = NULL;
1461 if (_this->DestroyWindow) {
1462 _this->DestroyWindow(_this, window);
1464 if (window->flags & SDL_WINDOW_OPENGL) {
1465 SDL_GL_UnloadLibrary();
1467 if (j != display->num_windows - 1) {
1468 SDL_memcpy(&display->windows[i],
1469 &display->windows[i + 1],
1470 (display->num_windows - i - 1) * sizeof(*window));
1472 --display->num_windows;
1479 SDL_AddRenderDriver(SDL_VideoDisplay * display, const SDL_RenderDriver * driver)
1481 SDL_RenderDriver *render_drivers;
1484 SDL_realloc(display->render_drivers,
1485 (display->num_render_drivers +
1486 1) * sizeof(*render_drivers));
1487 if (render_drivers) {
1488 render_drivers[display->num_render_drivers] = *driver;
1489 display->render_drivers = render_drivers;
1490 display->num_render_drivers++;
1495 SDL_GetNumRenderDrivers(void)
1498 return SDL_CurrentDisplay.num_render_drivers;
1504 SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info)
1507 SDL_UninitializedVideo();
1510 if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
1511 SDL_SetError("index must be in the range of 0 - %d",
1512 SDL_GetNumRenderDrivers() - 1);
1515 *info = SDL_CurrentDisplay.render_drivers[index].info;
1520 SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags)
1522 SDL_Window *window = SDL_GetWindowFromID(windowID);
1525 SDL_SetError("Invalid window ID");
1529 /* Free any existing renderer */
1530 SDL_DestroyRenderer(windowID);
1533 char *override = SDL_getenv("SDL_VIDEO_RENDERER");
1534 int n = SDL_GetNumRenderDrivers();
1536 #if SDL_VIDEO_RENDER_OGL
1537 if (!override && (window->flags & SDL_WINDOW_OPENGL)) {
1538 override = "opengl";
1540 #endif /* SDL_VIDEO_RENDER_OGL */
1541 #if SDL_VIDEO_RENDER_OGL_ES
1542 if (!override && (window->flags & SDL_WINDOW_OPENGL)) {
1543 override = "opengl_es";
1545 #endif /* SDL_VIDEO_RENDER_OGL_ES */
1547 for (index = 0; index < n; ++index) {
1548 SDL_RenderDriver *driver =
1549 &SDL_CurrentDisplay.render_drivers[index];
1551 if (SDL_strcasecmp(override, driver->info.name) == 0) {
1552 /* Create a new renderer instance */
1553 window->renderer = driver->CreateRenderer(window, flags);
1558 for (index = 0; index < n; ++index) {
1559 SDL_RenderDriver *driver =
1560 &SDL_CurrentDisplay.render_drivers[index];
1562 if ((driver->info.flags & flags) == flags) {
1563 /* Create a new renderer instance */
1564 window->renderer = driver->CreateRenderer(window, flags);
1565 if (window->renderer) {
1566 /* Yay, we got one! */
1573 SDL_SetError("Couldn't find matching render driver");
1577 if (index >= SDL_GetNumRenderDrivers()) {
1578 SDL_SetError("index must be -1 or in the range of 0 - %d",
1579 SDL_GetNumRenderDrivers() - 1);
1582 /* Create a new renderer instance */
1583 window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
1586 if (window->renderer == NULL) {
1587 /* Assuming renderer set its error */
1591 SDL_SelectRenderer(window->id);
1597 SDL_SelectRenderer(SDL_WindowID windowID)
1599 SDL_Window *window = SDL_GetWindowFromID(windowID);
1600 SDL_Renderer *renderer;
1603 SDL_SetError("Invalid window ID");
1606 renderer = window->renderer;
1608 SDL_SetError("Use SDL_CreateRenderer() to create a renderer");
1611 if (renderer->ActivateRenderer) {
1612 if (renderer->ActivateRenderer(renderer) < 0) {
1616 SDL_CurrentDisplay.current_renderer = renderer;
1621 SDL_GetRendererInfo(SDL_RendererInfo * info)
1623 SDL_Renderer *renderer = SDL_GetCurrentRenderer(SDL_FALSE);
1627 *info = renderer->info;
1632 SDL_CreateTexture(Uint32 format, int access, int w, int h)
1635 SDL_Renderer *renderer;
1636 SDL_Texture *texture;
1638 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
1642 if (!renderer->CreateTexture) {
1646 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
1651 texture->id = _this->next_object_id++;
1652 texture->format = format;
1653 texture->access = access;
1660 texture->renderer = renderer;
1662 if (renderer->CreateTexture(renderer, texture) < 0) {
1663 if (renderer->DestroyTexture) {
1664 renderer->DestroyTexture(renderer, texture);
1669 hash = (texture->id % SDL_arraysize(SDL_CurrentDisplay.textures));
1670 texture->next = SDL_CurrentDisplay.textures[hash];
1671 SDL_CurrentDisplay.textures[hash] = texture;
1677 SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
1679 SDL_TextureID textureID;
1680 Uint32 requested_format = format;
1681 SDL_PixelFormat *fmt;
1682 SDL_Renderer *renderer;
1684 Uint32 Rmask, Gmask, Bmask, Amask;
1687 SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
1690 fmt = surface->format;
1692 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
1698 if (!SDL_PixelFormatEnumToMasks
1699 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
1700 SDL_SetError("Unknown pixel format");
1704 if (surface->format->Amask
1705 || !(surface->map->info.flags &
1706 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) {
1710 /* Pixel formats, sorted by best first */
1711 static const Uint32 sdl_pformats[] = {
1712 SDL_PIXELFORMAT_ARGB8888,
1713 SDL_PIXELFORMAT_RGBA8888,
1714 SDL_PIXELFORMAT_ABGR8888,
1715 SDL_PIXELFORMAT_BGRA8888,
1716 SDL_PIXELFORMAT_RGB888,
1717 SDL_PIXELFORMAT_BGR888,
1718 SDL_PIXELFORMAT_RGB24,
1719 SDL_PIXELFORMAT_BGR24,
1720 SDL_PIXELFORMAT_RGB565,
1721 SDL_PIXELFORMAT_BGR565,
1722 SDL_PIXELFORMAT_ARGB1555,
1723 SDL_PIXELFORMAT_ABGR1555,
1724 SDL_PIXELFORMAT_RGB555,
1725 SDL_PIXELFORMAT_BGR555,
1726 SDL_PIXELFORMAT_ARGB4444,
1727 SDL_PIXELFORMAT_ABGR4444,
1728 SDL_PIXELFORMAT_RGB444,
1729 SDL_PIXELFORMAT_ARGB2101010,
1730 SDL_PIXELFORMAT_INDEX8,
1731 SDL_PIXELFORMAT_INDEX4LSB,
1732 SDL_PIXELFORMAT_INDEX4MSB,
1733 SDL_PIXELFORMAT_RGB332,
1734 SDL_PIXELFORMAT_INDEX1LSB,
1735 SDL_PIXELFORMAT_INDEX1MSB,
1736 SDL_PIXELFORMAT_UNKNOWN
1739 bpp = fmt->BitsPerPixel;
1746 SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
1748 SDL_SetError("Unknown pixel format");
1752 /* Search requested format in the supported texture */
1753 /* formats by current renderer */
1754 for (it = 0; it < renderer->info.num_texture_formats; it++) {
1755 if (renderer->info.texture_formats[it] == format) {
1760 /* If requested format can't be found, search any best */
1761 /* format which renderer provides */
1762 if (it == renderer->info.num_texture_formats) {
1765 if (sdl_pformats[pfmt] == SDL_PIXELFORMAT_UNKNOWN) {
1769 for (it = 0; it < renderer->info.num_texture_formats;
1771 if (renderer->info.texture_formats[it] ==
1772 sdl_pformats[pfmt]) {
1777 if (it != renderer->info.num_texture_formats) {
1778 /* The best format has been found */
1784 /* If any format can't be found, then return an error */
1785 if (it == renderer->info.num_texture_formats) {
1787 ("Any of the supported pixel formats can't be found");
1791 /* Convert found pixel format back to color masks */
1792 if (SDL_PixelFormatEnumToMasks
1793 (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask,
1794 &Bmask, &Amask) != SDL_TRUE) {
1795 SDL_SetError("Unknown pixel format");
1800 /* Need a format with alpha */
1804 /* Pixel formats with alpha, sorted by best first */
1805 static const Uint32 sdl_alpha_pformats[] = {
1806 SDL_PIXELFORMAT_ARGB8888,
1807 SDL_PIXELFORMAT_RGBA8888,
1808 SDL_PIXELFORMAT_ABGR8888,
1809 SDL_PIXELFORMAT_BGRA8888,
1810 SDL_PIXELFORMAT_ARGB1555,
1811 SDL_PIXELFORMAT_ABGR1555,
1812 SDL_PIXELFORMAT_ARGB4444,
1813 SDL_PIXELFORMAT_ABGR4444,
1814 SDL_PIXELFORMAT_ARGB2101010,
1815 SDL_PIXELFORMAT_UNKNOWN
1818 if (surface->format->Amask) {
1819 /* If surface already has alpha, then try an original */
1820 /* surface format first */
1821 bpp = fmt->BitsPerPixel;
1835 SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
1837 SDL_SetError("Unknown pixel format");
1841 /* Search this format in the supported texture formats */
1842 /* by current renderer */
1843 for (it = 0; it < renderer->info.num_texture_formats; it++) {
1844 if (renderer->info.texture_formats[it] == format) {
1849 /* If this format can't be found, search any best */
1850 /* compatible format with alpha which renderer provides */
1851 if (it == renderer->info.num_texture_formats) {
1854 if (sdl_alpha_pformats[apfmt] == SDL_PIXELFORMAT_UNKNOWN) {
1858 for (it = 0; it < renderer->info.num_texture_formats;
1860 if (renderer->info.texture_formats[it] ==
1861 sdl_alpha_pformats[apfmt]) {
1866 if (it != renderer->info.num_texture_formats) {
1867 /* Compatible format has been found */
1873 /* If compatible format can't be found, then return an error */
1874 if (it == renderer->info.num_texture_formats) {
1875 SDL_SetError("Compatible pixel format can't be found");
1879 /* Convert found pixel format back to color masks */
1880 if (SDL_PixelFormatEnumToMasks
1881 (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask,
1882 &Bmask, &Amask) != SDL_TRUE) {
1883 SDL_SetError("Unknown pixel format");
1889 format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
1891 SDL_SetError("Unknown pixel format");
1897 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
1899 if (!textureID && !requested_format) {
1900 SDL_DisplayMode desktop_mode;
1901 SDL_GetDesktopDisplayMode(&desktop_mode);
1902 format = desktop_mode.format;
1904 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
1910 if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask
1911 && Bmask == fmt->Bmask && Amask == fmt->Amask) {
1912 if (SDL_MUSTLOCK(surface)) {
1913 SDL_LockSurface(surface);
1914 SDL_UpdateTexture(textureID, NULL, surface->pixels,
1916 SDL_UnlockSurface(surface);
1918 SDL_UpdateTexture(textureID, NULL, surface->pixels,
1922 SDL_PixelFormat dst_fmt;
1923 SDL_Surface *dst = NULL;
1925 /* Set up a destination surface for the texture update */
1926 SDL_InitFormat(&dst_fmt, bpp, Rmask, Gmask, Bmask, Amask);
1927 if (SDL_ISPIXELFORMAT_INDEXED(format)) {
1929 SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
1930 if (dst_fmt.palette) {
1932 * FIXME: Should we try to copy
1935 SDL_DitherColors(dst_fmt.palette->colors,
1936 SDL_BITSPERPIXEL(format));
1939 dst = SDL_ConvertSurface(surface, &dst_fmt, 0);
1941 SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
1942 SDL_FreeSurface(dst);
1944 if (dst_fmt.palette) {
1945 SDL_FreePalette(dst_fmt.palette);
1948 SDL_DestroyTexture(textureID);
1958 SDL_GetSurfaceColorMod(surface, &r, &g, &b);
1959 SDL_SetTextureColorMod(textureID, r, g, b);
1961 SDL_GetSurfaceAlphaMod(surface, &a);
1962 SDL_SetTextureAlphaMod(textureID, a);
1964 SDL_GetSurfaceBlendMode(surface, &blendMode);
1965 SDL_SetTextureBlendMode(textureID, blendMode);
1967 SDL_GetSurfaceScaleMode(surface, &scaleMode);
1968 SDL_SetTextureScaleMode(textureID, scaleMode);
1971 if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) {
1972 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
1973 fmt->palette->ncolors);
1978 static __inline__ SDL_Texture *
1979 SDL_GetTextureFromID(SDL_TextureID textureID)
1982 SDL_Texture *texture;
1987 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
1988 for (texture = SDL_CurrentDisplay.textures[hash]; texture;
1989 texture = texture->next) {
1990 if (texture->id == textureID) {
1998 SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access,
2001 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2007 *format = texture->format;
2010 *access = texture->access;
2022 SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch)
2024 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2025 SDL_Renderer *renderer;
2030 renderer = texture->renderer;
2031 if (!renderer->QueryTexturePixels) {
2035 return renderer->QueryTexturePixels(renderer, texture, pixels, pitch);
2039 SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors,
2040 int firstcolor, int ncolors)
2042 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2043 SDL_Renderer *renderer;
2048 renderer = texture->renderer;
2049 if (!renderer->SetTexturePalette) {
2053 return renderer->SetTexturePalette(renderer, texture, colors, firstcolor,
2058 SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
2059 int firstcolor, int ncolors)
2061 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2062 SDL_Renderer *renderer;
2067 renderer = texture->renderer;
2068 if (!renderer->GetTexturePalette) {
2072 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor,
2077 SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b)
2079 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2080 SDL_Renderer *renderer;
2085 renderer = texture->renderer;
2086 if (!renderer->SetTextureColorMod) {
2090 if (r < 255 || g < 255 || b < 255) {
2091 texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
2093 texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
2098 return renderer->SetTextureColorMod(renderer, texture);
2102 SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g,
2105 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2106 SDL_Renderer *renderer;
2111 renderer = texture->renderer;
2125 SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha)
2127 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2128 SDL_Renderer *renderer;
2133 renderer = texture->renderer;
2134 if (!renderer->SetTextureAlphaMod) {
2139 texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
2141 texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
2144 return renderer->SetTextureAlphaMod(renderer, texture);
2148 SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha)
2150 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2156 *alpha = texture->a;
2162 SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode)
2164 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2165 SDL_Renderer *renderer;
2170 renderer = texture->renderer;
2171 if (!renderer->SetTextureBlendMode) {
2175 texture->blendMode = blendMode;
2176 return renderer->SetTextureBlendMode(renderer, texture);
2180 SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode)
2182 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2188 *blendMode = texture->blendMode;
2194 SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode)
2196 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2197 SDL_Renderer *renderer;
2202 renderer = texture->renderer;
2203 if (!renderer->SetTextureScaleMode) {
2207 texture->scaleMode = scaleMode;
2208 return renderer->SetTextureScaleMode(renderer, texture);
2212 SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode)
2214 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2220 *scaleMode = texture->scaleMode;
2226 SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect,
2227 const void *pixels, int pitch)
2229 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2230 SDL_Renderer *renderer;
2236 renderer = texture->renderer;
2237 if (!renderer->UpdateTexture) {
2244 full_rect.w = texture->w;
2245 full_rect.h = texture->h;
2248 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
2252 SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty,
2253 void **pixels, int *pitch)
2255 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2256 SDL_Renderer *renderer;
2262 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2263 SDL_SetError("SDL_LockTexture(): texture must be streaming");
2266 renderer = texture->renderer;
2267 if (!renderer->LockTexture) {
2274 full_rect.w = texture->w;
2275 full_rect.h = texture->h;
2278 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels,
2283 SDL_UnlockTexture(SDL_TextureID textureID)
2285 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2286 SDL_Renderer *renderer;
2291 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2294 renderer = texture->renderer;
2295 if (!renderer->UnlockTexture) {
2298 renderer->UnlockTexture(renderer, texture);
2302 SDL_DirtyTexture(SDL_TextureID textureID, int numrects,
2303 const SDL_Rect * rects)
2305 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2306 SDL_Renderer *renderer;
2311 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2314 renderer = texture->renderer;
2315 if (!renderer->DirtyTexture) {
2318 renderer->DirtyTexture(renderer, texture, numrects, rects);
2322 SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2324 SDL_Renderer *renderer;
2326 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2334 if (renderer->SetDrawColor) {
2335 return renderer->SetDrawColor(renderer);
2342 SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
2344 SDL_Renderer *renderer;
2346 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2366 SDL_SetRenderDrawBlendMode(int blendMode)
2368 SDL_Renderer *renderer;
2370 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2374 renderer->blendMode = blendMode;
2375 if (renderer->SetDrawBlendMode) {
2376 return renderer->SetDrawBlendMode(renderer);
2383 SDL_GetRenderDrawBlendMode(int *blendMode)
2385 SDL_Renderer *renderer;
2387 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2391 *blendMode = renderer->blendMode;
2396 SDL_RenderPoint(int x, int y)
2398 SDL_Renderer *renderer;
2401 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2405 if (!renderer->RenderPoint) {
2409 window = SDL_GetWindowFromID(renderer->window);
2410 if (x < 0 || y < 0 || x >= window->w || y >= window->h) {
2413 return renderer->RenderPoint(renderer, x, y);
2417 SDL_RenderLine(int x1, int y1, int x2, int y2)
2419 SDL_Renderer *renderer;
2423 if (x1 == x2 && y1 == y2) {
2424 return SDL_RenderPoint(x1, y1);
2427 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2431 if (!renderer->RenderLine) {
2435 window = SDL_GetWindowFromID(renderer->window);
2439 real_rect.w = window->w;
2440 real_rect.h = window->h;
2441 if (!SDL_IntersectRectAndLine(&real_rect, &x1, &y1, &x2, &y2)) {
2444 return renderer->RenderLine(renderer, x1, y1, x2, y2);
2448 SDL_RenderFill(const SDL_Rect * rect)
2450 SDL_Renderer *renderer;
2454 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2458 if (!renderer->RenderFill) {
2462 window = SDL_GetWindowFromID(renderer->window);
2466 real_rect.w = window->w;
2467 real_rect.h = window->h;
2469 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2473 return renderer->RenderFill(renderer, &real_rect);
2477 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
2478 const SDL_Rect * dstrect)
2480 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2481 SDL_Renderer *renderer;
2483 SDL_Rect real_srcrect;
2484 SDL_Rect real_dstrect;
2486 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2491 SDL_SetError("Texture not found");
2494 if (texture->renderer != renderer) {
2495 SDL_SetError("Texture was not created with this renderer");
2498 if (!renderer->RenderCopy) {
2502 window = SDL_GetWindowFromID(renderer->window);
2506 real_srcrect.w = texture->w;
2507 real_srcrect.h = texture->h;
2509 if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
2516 real_dstrect.w = window->w;
2517 real_dstrect.h = window->h;
2519 if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
2522 /* Clip srcrect by the same amount as dstrect was clipped */
2523 if (dstrect->w != real_dstrect.w) {
2524 int deltax = (real_dstrect.x - dstrect->x);
2525 int deltaw = (real_dstrect.w - dstrect->w);
2526 real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
2527 real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
2529 if (dstrect->h != real_dstrect.h) {
2530 int deltay = (real_dstrect.y - dstrect->y);
2531 int deltah = (real_dstrect.h - dstrect->h);
2532 real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
2533 real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;
2537 return renderer->RenderCopy(renderer, texture, &real_srcrect,
2542 SDL_RenderReadPixels(const SDL_Rect * rect, Uint32 format,
2543 void * pixels, int pitch)
2545 SDL_Renderer *renderer;
2549 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2553 if (!renderer->RenderReadPixels) {
2557 window = SDL_GetWindowFromID(renderer->window);
2560 format = SDL_GetDisplayFromWindow(window)->current_mode.format;
2565 real_rect.w = window->w;
2566 real_rect.h = window->h;
2568 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2571 if (real_rect.y > rect->y) {
2572 pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
2574 if (real_rect.x > rect->x) {
2575 Uint32 format = SDL_CurrentDisplay.current_mode.format;
2576 int bpp = SDL_BYTESPERPIXEL(format);
2577 pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2581 return renderer->RenderReadPixels(renderer, &real_rect,
2582 format, pixels, pitch);
2586 SDL_RenderWritePixels(const SDL_Rect * rect, Uint32 format,
2587 const void * pixels, int pitch)
2589 SDL_Renderer *renderer;
2593 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2597 if (!renderer->RenderWritePixels) {
2601 window = SDL_GetWindowFromID(renderer->window);
2604 format = SDL_GetDisplayFromWindow(window)->current_mode.format;
2609 real_rect.w = window->w;
2610 real_rect.h = window->h;
2612 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2615 if (real_rect.y > rect->y) {
2616 pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y);
2618 if (real_rect.x > rect->x) {
2619 Uint32 format = SDL_CurrentDisplay.current_mode.format;
2620 int bpp = SDL_BYTESPERPIXEL(format);
2621 pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2625 return renderer->RenderWritePixels(renderer, &real_rect,
2626 format, pixels, pitch);
2630 SDL_RenderPresent(void)
2632 SDL_Renderer *renderer;
2634 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2635 if (!renderer || !renderer->RenderPresent) {
2638 renderer->RenderPresent(renderer);
2642 SDL_DestroyTexture(SDL_TextureID textureID)
2645 SDL_Texture *prev, *texture;
2646 SDL_Renderer *renderer;
2649 SDL_UninitializedVideo();
2652 /* Look up the texture in the hash table */
2653 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
2655 for (texture = SDL_CurrentDisplay.textures[hash]; texture;
2656 prev = texture, texture = texture->next) {
2657 if (texture->id == textureID) {
2664 /* Unlink the texture from the list */
2666 prev->next = texture->next;
2668 SDL_CurrentDisplay.textures[hash] = texture->next;
2671 /* Free the texture */
2672 renderer = texture->renderer;
2673 renderer->DestroyTexture(renderer, texture);
2678 SDL_DestroyRenderer(SDL_WindowID windowID)
2680 SDL_Window *window = SDL_GetWindowFromID(windowID);
2681 SDL_Renderer *renderer;
2687 renderer = window->renderer;
2691 /* Free existing textures for this renderer */
2692 for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) {
2693 SDL_Texture *texture;
2694 SDL_Texture *prev = NULL;
2696 for (texture = SDL_CurrentDisplay.textures[i]; texture;
2698 next = texture->next;
2699 if (texture->renderer == renderer) {
2703 SDL_CurrentDisplay.textures[i] = next;
2705 renderer->DestroyTexture(renderer, texture);
2713 /* Free the renderer instance */
2714 renderer->DestroyRenderer(renderer);
2716 /* Clear references */
2717 window->renderer = NULL;
2718 if (SDL_CurrentDisplay.current_renderer == renderer) {
2719 SDL_CurrentDisplay.current_renderer = NULL;
2724 SDL_IsScreenSaverEnabled()
2729 return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
2733 SDL_EnableScreenSaver()
2738 if (!_this->suspend_screensaver) {
2741 _this->suspend_screensaver = SDL_FALSE;
2742 if (_this->SuspendScreenSaver) {
2743 _this->SuspendScreenSaver(_this);
2748 SDL_DisableScreenSaver()
2753 if (_this->suspend_screensaver) {
2756 _this->suspend_screensaver = SDL_TRUE;
2757 if (_this->SuspendScreenSaver) {
2758 _this->SuspendScreenSaver(_this);
2770 /* Halt event processing before doing anything else */
2771 SDL_StopEventLoop();
2772 SDL_EnableScreenSaver();
2774 /* Clean up the system video */
2775 for (i = _this->num_displays; i--;) {
2776 SDL_VideoDisplay *display = &_this->displays[i];
2777 for (j = display->num_windows; j--;) {
2778 SDL_DestroyWindow(display->windows[i].id);
2780 if (display->windows) {
2781 SDL_free(display->windows);
2782 display->windows = NULL;
2784 display->num_windows = 0;
2785 if (display->render_drivers) {
2786 SDL_free(display->render_drivers);
2787 display->render_drivers = NULL;
2789 display->num_render_drivers = 0;
2791 _this->VideoQuit(_this);
2793 for (i = _this->num_displays; i--;) {
2794 SDL_VideoDisplay *display = &_this->displays[i];
2795 for (j = display->num_display_modes; j--;) {
2796 if (display->display_modes[j].driverdata) {
2797 SDL_free(display->display_modes[j].driverdata);
2798 display->display_modes[j].driverdata = NULL;
2801 if (display->display_modes) {
2802 SDL_free(display->display_modes);
2803 display->display_modes = NULL;
2805 if (display->desktop_mode.driverdata) {
2806 SDL_free(display->desktop_mode.driverdata);
2807 display->desktop_mode.driverdata = NULL;
2809 if (display->palette) {
2810 SDL_FreePalette(display->palette);
2811 display->palette = NULL;
2813 if (display->gamma) {
2814 SDL_free(display->gamma);
2815 display->gamma = NULL;
2817 if (display->driverdata) {
2818 SDL_free(display->driverdata);
2819 display->driverdata = NULL;
2822 if (_this->displays) {
2823 SDL_free(_this->displays);
2824 _this->displays = NULL;
2831 SDL_GL_LoadLibrary(const char *path)
2836 SDL_UninitializedVideo();
2839 if (_this->gl_config.driver_loaded) {
2840 if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) {
2841 SDL_SetError("OpenGL library already loaded");
2846 if (!_this->GL_LoadLibrary) {
2847 SDL_SetError("No dynamic GL support in video driver");
2850 retval = _this->GL_LoadLibrary(_this, path);
2853 ++_this->gl_config.driver_loaded;
2859 SDL_GL_GetProcAddress(const char *proc)
2864 SDL_UninitializedVideo();
2868 if (_this->GL_GetProcAddress) {
2869 if (_this->gl_config.driver_loaded) {
2870 func = _this->GL_GetProcAddress(_this, proc);
2872 SDL_SetError("No GL driver has been loaded");
2875 SDL_SetError("No dynamic GL support in video driver");
2881 SDL_GL_UnloadLibrary(void)
2884 SDL_UninitializedVideo();
2887 if (_this->gl_config.driver_loaded > 0) {
2888 if (--_this->gl_config.driver_loaded > 0) {
2891 if (_this->GL_UnloadLibrary) {
2892 _this->GL_UnloadLibrary(_this);
2898 SDL_GL_ExtensionSupported(const char *extension)
2900 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
2901 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
2902 const char *extensions;
2904 const char *where, *terminator;
2906 /* Extension names should not have spaces. */
2907 where = SDL_strchr(extension, ' ');
2908 if (where || *extension == '\0') {
2911 /* See if there's an environment variable override */
2912 start = SDL_getenv(extension);
2913 if (start && *start == '0') {
2916 /* Lookup the available extensions */
2917 glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
2918 if (glGetStringFunc) {
2919 extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
2927 * It takes a bit of care to be fool-proof about parsing the OpenGL
2928 * extensions string. Don't be fooled by sub-strings, etc.
2934 where = SDL_strstr(start, extension);
2938 terminator = where + SDL_strlen(extension);
2939 if (where == start || *(where - 1) == ' ')
2940 if (*terminator == ' ' || *terminator == '\0')
2952 SDL_GL_SetAttribute(SDL_GLattr attr, int value)
2954 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
2958 SDL_UninitializedVideo();
2963 case SDL_GL_RED_SIZE:
2964 _this->gl_config.red_size = value;
2966 case SDL_GL_GREEN_SIZE:
2967 _this->gl_config.green_size = value;
2969 case SDL_GL_BLUE_SIZE:
2970 _this->gl_config.blue_size = value;
2972 case SDL_GL_ALPHA_SIZE:
2973 _this->gl_config.alpha_size = value;
2975 case SDL_GL_DOUBLEBUFFER:
2976 _this->gl_config.double_buffer = value;
2978 case SDL_GL_BUFFER_SIZE:
2979 _this->gl_config.buffer_size = value;
2981 case SDL_GL_DEPTH_SIZE:
2982 _this->gl_config.depth_size = value;
2984 case SDL_GL_STENCIL_SIZE:
2985 _this->gl_config.stencil_size = value;
2987 case SDL_GL_ACCUM_RED_SIZE:
2988 _this->gl_config.accum_red_size = value;
2990 case SDL_GL_ACCUM_GREEN_SIZE:
2991 _this->gl_config.accum_green_size = value;
2993 case SDL_GL_ACCUM_BLUE_SIZE:
2994 _this->gl_config.accum_blue_size = value;
2996 case SDL_GL_ACCUM_ALPHA_SIZE:
2997 _this->gl_config.accum_alpha_size = value;
3000 _this->gl_config.stereo = value;
3002 case SDL_GL_MULTISAMPLEBUFFERS:
3003 _this->gl_config.multisamplebuffers = value;
3005 case SDL_GL_MULTISAMPLESAMPLES:
3006 _this->gl_config.multisamplesamples = value;
3008 case SDL_GL_ACCELERATED_VISUAL:
3009 _this->gl_config.accelerated = value;
3011 case SDL_GL_RETAINED_BACKING:
3012 _this->gl_config.retained_backing = value;
3014 case SDL_GL_CONTEXT_MAJOR_VERSION:
3015 _this->gl_config.major_version = value;
3017 case SDL_GL_CONTEXT_MINOR_VERSION:
3018 _this->gl_config.minor_version = value;
3021 SDL_SetError("Unknown OpenGL attribute");
3029 #endif /* SDL_VIDEO_OPENGL */
3033 SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
3035 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
3036 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
3037 GLenum(APIENTRY * glGetErrorFunc) (void);
3041 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
3042 if (!glGetIntegervFunc) {
3046 glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
3047 if (!glGetErrorFunc) {
3051 /* Clear value in any case */
3055 case SDL_GL_RETAINED_BACKING:
3056 *value = _this->gl_config.retained_backing;
3058 case SDL_GL_RED_SIZE:
3059 attrib = GL_RED_BITS;
3061 case SDL_GL_BLUE_SIZE:
3062 attrib = GL_BLUE_BITS;
3064 case SDL_GL_GREEN_SIZE:
3065 attrib = GL_GREEN_BITS;
3067 case SDL_GL_ALPHA_SIZE:
3068 attrib = GL_ALPHA_BITS;
3070 case SDL_GL_DOUBLEBUFFER:
3071 #ifndef SDL_VIDEO_OPENGL_ES
3072 attrib = GL_DOUBLEBUFFER;
3075 /* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */
3076 /* parameter which switches double buffer to single buffer. OpenGL ES */
3077 /* SDL driver must set proper value after initialization */
3078 *value = _this->gl_config.double_buffer;
3081 case SDL_GL_DEPTH_SIZE:
3082 attrib = GL_DEPTH_BITS;
3084 case SDL_GL_STENCIL_SIZE:
3085 attrib = GL_STENCIL_BITS;
3087 #ifndef SDL_VIDEO_OPENGL_ES
3088 case SDL_GL_ACCUM_RED_SIZE:
3089 attrib = GL_ACCUM_RED_BITS;
3091 case SDL_GL_ACCUM_GREEN_SIZE:
3092 attrib = GL_ACCUM_GREEN_BITS;
3094 case SDL_GL_ACCUM_BLUE_SIZE:
3095 attrib = GL_ACCUM_BLUE_BITS;
3097 case SDL_GL_ACCUM_ALPHA_SIZE:
3098 attrib = GL_ACCUM_ALPHA_BITS;
3104 case SDL_GL_ACCUM_RED_SIZE:
3105 case SDL_GL_ACCUM_GREEN_SIZE:
3106 case SDL_GL_ACCUM_BLUE_SIZE:
3107 case SDL_GL_ACCUM_ALPHA_SIZE:
3109 /* none of these are supported in OpenGL ES */
3113 case SDL_GL_MULTISAMPLEBUFFERS:
3114 #ifndef SDL_VIDEO_OPENGL_ES
3115 attrib = GL_SAMPLE_BUFFERS_ARB;
3117 attrib = GL_SAMPLE_BUFFERS;
3120 case SDL_GL_MULTISAMPLESAMPLES:
3121 #ifndef SDL_VIDEO_OPENGL_ES
3122 attrib = GL_SAMPLES_ARB;
3124 attrib = GL_SAMPLES;
3127 case SDL_GL_BUFFER_SIZE:
3133 * there doesn't seem to be a single flag in OpenGL
3136 glGetIntegervFunc(GL_RED_BITS, &component);
3138 glGetIntegervFunc(GL_GREEN_BITS, &component);
3140 glGetIntegervFunc(GL_BLUE_BITS, &component);
3142 glGetIntegervFunc(GL_ALPHA_BITS, &component);
3148 case SDL_GL_ACCELERATED_VISUAL:
3150 /* FIXME: How do we get this information? */
3151 *value = (_this->gl_config.accelerated != 0);
3155 SDL_SetError("Unknown OpenGL attribute");
3159 glGetIntegervFunc(attrib, (GLint *) value);
3160 error = glGetErrorFunc();
3161 if (error != GL_NO_ERROR) {
3163 case GL_INVALID_ENUM:
3165 SDL_SetError("OpenGL error: GL_INVALID_ENUM");
3168 case GL_INVALID_VALUE:
3170 SDL_SetError("OpenGL error: GL_INVALID_VALUE");
3175 SDL_SetError("OpenGL error: %08X", error);
3185 #endif /* SDL_VIDEO_OPENGL */
3189 SDL_GL_CreateContext(SDL_WindowID windowID)
3191 SDL_Window *window = SDL_GetWindowFromID(windowID);
3196 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3197 SDL_SetError("The specified window isn't an OpenGL window");
3200 return _this->GL_CreateContext(_this, window);
3204 SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
3206 SDL_Window *window = SDL_GetWindowFromID(windowID);
3208 if (window && !(window->flags & SDL_WINDOW_OPENGL)) {
3209 SDL_SetError("The specified window isn't an OpenGL window");
3215 return _this->GL_MakeCurrent(_this, window, context);
3219 SDL_GL_SetSwapInterval(int interval)
3222 SDL_UninitializedVideo();
3225 if (_this->GL_SetSwapInterval) {
3226 return _this->GL_SetSwapInterval(_this, interval);
3228 SDL_SetError("Setting the swap interval is not supported");
3234 SDL_GL_GetSwapInterval(void)
3237 SDL_UninitializedVideo();
3240 if (_this->GL_GetSwapInterval) {
3241 return _this->GL_GetSwapInterval(_this);
3243 SDL_SetError("Getting the swap interval is not supported");
3249 SDL_GL_SwapWindow(SDL_WindowID windowID)
3251 SDL_Window *window = SDL_GetWindowFromID(windowID);
3256 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3257 SDL_SetError("The specified window isn't an OpenGL window");
3260 _this->GL_SwapWindow(_this, window);
3264 SDL_GL_DeleteContext(SDL_GLContext context)
3266 if (!_this || !context) {
3269 _this->GL_MakeCurrent(_this, NULL, NULL);
3270 _this->GL_DeleteContext(_this, context);
3275 * Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
3276 * & 2 for alpha channel.
3279 CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags)
3283 #define SET_MASKBIT(icon, x, y, mask) \
3284 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
3286 colorkey = icon->format->colorkey;
3287 switch (icon->format->BytesPerPixel) {
3291 for (y = 0; y < icon->h; ++y) {
3292 pixels = (Uint8 *) icon->pixels + y * icon->pitch;
3293 for (x = 0; x < icon->w; ++x) {
3294 if (*pixels++ == colorkey) {
3295 SET_MASKBIT(icon, x, y, mask);
3305 for (y = 0; y < icon->h; ++y) {
3306 pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2;
3307 for (x = 0; x < icon->w; ++x) {
3308 if ((flags & 1) && *pixels == colorkey) {
3309 SET_MASKBIT(icon, x, y, mask);
3310 } else if ((flags & 2)
3311 && (*pixels & icon->format->Amask) == 0) {
3312 SET_MASKBIT(icon, x, y, mask);
3323 for (y = 0; y < icon->h; ++y) {
3324 pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4;
3325 for (x = 0; x < icon->w; ++x) {
3326 if ((flags & 1) && *pixels == colorkey) {
3327 SET_MASKBIT(icon, x, y, mask);
3328 } else if ((flags & 2)
3329 && (*pixels & icon->format->Amask) == 0) {
3330 SET_MASKBIT(icon, x, y, mask);
3341 * Sets the window manager icon for the display window.
3344 SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
3346 if (icon && _this->SetIcon) {
3347 /* Generate a mask if necessary, and create the icon! */
3349 int mask_len = icon->h * (icon->w + 7) / 8;
3351 mask = (Uint8 *) SDL_malloc(mask_len);
3355 SDL_memset(mask, ~0, mask_len);
3356 if (icon->flags & SDL_SRCCOLORKEY)
3358 if (icon->flags & SDL_SRCALPHA)
3361 CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
3363 _this->SetIcon(_this, icon, mask);
3366 _this->SetIcon(_this, icon, mask);
3373 SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info)
3375 SDL_Window *window = SDL_GetWindowFromID(windowID);
3377 if (!window || !_this->GetWindowWMInfo) {
3380 return (_this->GetWindowWMInfo(_this, window, info));
3384 SDL_StartTextInput(void)
3386 if (_this->StartTextInput) {
3387 _this->StartTextInput(_this);
3389 SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
3390 SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
3394 SDL_StopTextInput(void)
3396 if (_this->StopTextInput) {
3397 _this->StopTextInput(_this);
3399 SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
3400 SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
3404 SDL_SetTextInputRect(SDL_Rect *rect)
3406 if (_this->SetTextInputRect) {
3407 _this->SetTextInputRect(_this, rect);
3411 /* vi: set ts=4 sw=4 expandtab: */