2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
21 #include "../SDL_internal.h"
23 /* The high-level video driver subsystem */
26 #include "SDL_video.h"
27 #include "SDL_sysvideo.h"
29 #include "SDL_pixels_c.h"
30 #include "SDL_rect_c.h"
31 #include "../events/SDL_events_c.h"
32 #include "../timer/SDL_timer_c.h"
34 #include "SDL_syswm.h"
37 #include "SDL_opengl.h"
38 #endif /* SDL_VIDEO_OPENGL */
40 #if SDL_VIDEO_OPENGL_ES
41 #include "SDL_opengles.h"
42 #endif /* SDL_VIDEO_OPENGL_ES */
44 /* GL and GLES2 headers conflict on Linux 32 bits */
45 #if SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
46 #include "SDL_opengles2.h"
47 #endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */
49 #ifndef GL_CONTEXT_RELEASE_BEHAVIOR_KHR
50 #define GL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x82FB
53 /* On Windows, windows.h defines CreateWindow */
58 /* Available video drivers */
59 static VideoBootStrap *bootstrap[] = {
60 #if SDL_VIDEO_DRIVER_COCOA
63 #if SDL_VIDEO_DRIVER_X11
66 #if SDL_VIDEO_DRIVER_MIR
69 #if SDL_VIDEO_DRIVER_WAYLAND
72 #if SDL_VIDEO_DRIVER_VIVANTE
75 #if SDL_VIDEO_DRIVER_DIRECTFB
78 #if SDL_VIDEO_DRIVER_WINDOWS
81 #if SDL_VIDEO_DRIVER_WINRT
84 #if SDL_VIDEO_DRIVER_HAIKU
87 #if SDL_VIDEO_DRIVER_PANDORA
90 #if SDL_VIDEO_DRIVER_UIKIT
93 #if SDL_VIDEO_DRIVER_ANDROID
96 #if SDL_VIDEO_DRIVER_PSP
99 #if SDL_VIDEO_DRIVER_RPI
102 #if SDL_VIDEO_DRIVER_NACL
105 #if SDL_VIDEO_DRIVER_EMSCRIPTEN
106 &Emscripten_bootstrap,
108 #if SDL_VIDEO_DRIVER_DUMMY
114 static SDL_VideoDevice *_this = NULL;
116 #define CHECK_WINDOW_MAGIC(window, retval) \
118 SDL_UninitializedVideo(); \
121 if (!window || window->magic != &_this->window_magic) { \
122 SDL_SetError("Invalid window"); \
126 #define CHECK_DISPLAY_INDEX(displayIndex, retval) \
128 SDL_UninitializedVideo(); \
131 SDL_assert(_this->displays != NULL); \
132 if (displayIndex < 0 || displayIndex >= _this->num_displays) { \
133 SDL_SetError("displayIndex must be in the range 0 - %d", \
134 _this->num_displays - 1); \
138 #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
141 /* Support for Mac OS X fullscreen spaces */
142 extern SDL_bool Cocoa_IsWindowInFullscreenSpace(SDL_Window * window);
143 extern SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state);
147 /* Support for framebuffer emulation using an accelerated renderer */
149 #define SDL_WINDOWTEXTUREDATA "_SDL_WindowTextureData"
152 SDL_Renderer *renderer;
153 SDL_Texture *texture;
157 } SDL_WindowTextureData;
160 ShouldUseTextureFramebuffer()
164 /* If there's no native framebuffer support then there's no option */
165 if (!_this->CreateWindowFramebuffer) {
169 /* If the user has specified a software renderer we can't use a
170 texture framebuffer, or renderer creation will go recursive.
172 hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
173 if (hint && SDL_strcasecmp(hint, "software") == 0) {
177 /* See if the user or application wants a specific behavior */
178 hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
187 /* Each platform has different performance characteristics */
188 #if defined(__WIN32__)
189 /* GDI BitBlt() is way faster than Direct3D dynamic textures right now.
193 #elif defined(__MACOSX__)
194 /* Mac OS X uses OpenGL as the native fast path */
197 #elif defined(__LINUX__)
198 /* Properly configured OpenGL drivers are faster than MIT-SHM */
200 /* Ugh, find a way to cache this value! */
203 SDL_GLContext context;
204 SDL_bool hasAcceleratedOpenGL = SDL_FALSE;
206 window = SDL_CreateWindow("OpenGL test", -32, -32, 32, 32, SDL_WINDOW_OPENGL|SDL_WINDOW_HIDDEN);
208 context = SDL_GL_CreateContext(window);
210 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
211 const char *vendor = NULL;
213 glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
214 if (glGetStringFunc) {
215 vendor = (const char *) glGetStringFunc(GL_VENDOR);
217 /* Add more vendors here at will... */
219 (SDL_strstr(vendor, "ATI Technologies") ||
220 SDL_strstr(vendor, "NVIDIA"))) {
221 hasAcceleratedOpenGL = SDL_TRUE;
223 SDL_GL_DeleteContext(context);
225 SDL_DestroyWindow(window);
227 return hasAcceleratedOpenGL;
229 #elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
230 /* Let's be optimistic about this! */
237 /* Play it safe, assume that if there is a framebuffer driver that it's
238 optimized for the current platform.
245 SDL_CreateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
247 SDL_WindowTextureData *data;
249 data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
251 SDL_Renderer *renderer = NULL;
253 const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
255 /* Check to see if there's a specific driver requested */
256 if (hint && *hint != '0' && *hint != '1' &&
257 SDL_strcasecmp(hint, "software") != 0) {
258 for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
259 SDL_RendererInfo info;
260 SDL_GetRenderDriverInfo(i, &info);
261 if (SDL_strcasecmp(info.name, hint) == 0) {
262 renderer = SDL_CreateRenderer(window, i, 0);
269 for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
270 SDL_RendererInfo info;
271 SDL_GetRenderDriverInfo(i, &info);
272 if (SDL_strcmp(info.name, "software") != 0) {
273 renderer = SDL_CreateRenderer(window, i, 0);
281 return SDL_SetError("No hardware accelerated renderers available");
284 /* Create the data after we successfully create the renderer (bug #1116) */
285 data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
287 SDL_DestroyRenderer(renderer);
288 return SDL_OutOfMemory();
290 SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
292 data->renderer = renderer;
295 /* Free any old texture and pixel data */
297 SDL_DestroyTexture(data->texture);
298 data->texture = NULL;
300 SDL_free(data->pixels);
304 SDL_RendererInfo info;
307 if (SDL_GetRendererInfo(data->renderer, &info) < 0) {
311 /* Find the first format without an alpha channel */
312 *format = info.texture_formats[0];
314 for (i = 0; i < info.num_texture_formats; ++i) {
315 if (!SDL_ISPIXELFORMAT_FOURCC(info.texture_formats[i]) &&
316 !SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
317 *format = info.texture_formats[i];
323 data->texture = SDL_CreateTexture(data->renderer, *format,
324 SDL_TEXTUREACCESS_STREAMING,
325 window->w, window->h);
326 if (!data->texture) {
330 /* Create framebuffer data */
331 data->bytes_per_pixel = SDL_BYTESPERPIXEL(*format);
332 data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3);
333 data->pixels = SDL_malloc(window->h * data->pitch);
335 return SDL_OutOfMemory();
338 *pixels = data->pixels;
339 *pitch = data->pitch;
341 /* Make sure we're not double-scaling the viewport */
342 SDL_RenderSetViewport(data->renderer, NULL);
348 SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, const SDL_Rect * rects, int numrects)
350 SDL_WindowTextureData *data;
354 data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
355 if (!data || !data->texture) {
356 return SDL_SetError("No window texture data");
359 /* Update a single rect that contains subrects for best DMA performance */
360 if (SDL_GetSpanEnclosingRect(window->w, window->h, numrects, rects, &rect)) {
361 src = (void *)((Uint8 *)data->pixels +
362 rect.y * data->pitch +
363 rect.x * data->bytes_per_pixel);
364 if (SDL_UpdateTexture(data->texture, &rect, src, data->pitch) < 0) {
368 if (SDL_RenderCopy(data->renderer, data->texture, NULL, NULL) < 0) {
372 SDL_RenderPresent(data->renderer);
378 SDL_DestroyWindowTexture(SDL_VideoDevice *unused, SDL_Window * window)
380 SDL_WindowTextureData *data;
382 data = SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, NULL);
387 SDL_DestroyTexture(data->texture);
389 if (data->renderer) {
390 SDL_DestroyRenderer(data->renderer);
392 SDL_free(data->pixels);
398 cmpmodes(const void *A, const void *B)
400 const SDL_DisplayMode *a = (const SDL_DisplayMode *) A;
401 const SDL_DisplayMode *b = (const SDL_DisplayMode *) B;
404 } else if (a->w != b->w) {
406 } else if (a->h != b->h) {
408 } else if (SDL_BITSPERPIXEL(a->format) != SDL_BITSPERPIXEL(b->format)) {
409 return SDL_BITSPERPIXEL(b->format) - SDL_BITSPERPIXEL(a->format);
410 } else if (SDL_PIXELLAYOUT(a->format) != SDL_PIXELLAYOUT(b->format)) {
411 return SDL_PIXELLAYOUT(b->format) - SDL_PIXELLAYOUT(a->format);
412 } else if (a->refresh_rate != b->refresh_rate) {
413 return b->refresh_rate - a->refresh_rate;
419 SDL_UninitializedVideo()
421 return SDL_SetError("Video subsystem has not been initialized");
425 SDL_GetNumVideoDrivers(void)
427 return SDL_arraysize(bootstrap) - 1;
431 SDL_GetVideoDriver(int index)
433 if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
434 return bootstrap[index]->name;
440 * Initialize the video and event subsystems -- determine native pixel format
443 SDL_VideoInit(const char *driver_name)
445 SDL_VideoDevice *video;
449 SDL_bool allow_screensaver;
451 /* Check to make sure we don't overwrite '_this' */
456 #if !SDL_TIMERS_DISABLED
460 /* Start the event loop */
461 if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0 ||
462 SDL_KeyboardInit() < 0 ||
463 SDL_MouseInit() < 0 ||
464 SDL_TouchInit() < 0) {
468 /* Select the proper video driver */
471 if (driver_name == NULL) {
472 driver_name = SDL_getenv("SDL_VIDEODRIVER");
474 if (driver_name != NULL) {
475 for (i = 0; bootstrap[i]; ++i) {
476 if (SDL_strncasecmp(bootstrap[i]->name, driver_name, SDL_strlen(driver_name)) == 0) {
477 if (bootstrap[i]->available()) {
478 video = bootstrap[i]->create(index);
484 for (i = 0; bootstrap[i]; ++i) {
485 if (bootstrap[i]->available()) {
486 video = bootstrap[i]->create(index);
495 return SDL_SetError("%s not available", driver_name);
497 return SDL_SetError("No available video device");
500 _this->name = bootstrap[i]->name;
501 _this->next_object_id = 1;
504 /* Set some very sane GL defaults */
505 _this->gl_config.driver_loaded = 0;
506 _this->gl_config.dll_handle = NULL;
507 SDL_GL_ResetAttributes();
509 _this->current_glwin_tls = SDL_TLSCreate();
510 _this->current_glctx_tls = SDL_TLSCreate();
512 /* Initialize the video subsystem */
513 if (_this->VideoInit(_this) < 0) {
518 /* Make sure some displays were added */
519 if (_this->num_displays == 0) {
521 return SDL_SetError("The video driver did not add any displays");
524 /* Add the renderer framebuffer emulation if desired */
525 if (ShouldUseTextureFramebuffer()) {
526 _this->CreateWindowFramebuffer = SDL_CreateWindowTexture;
527 _this->UpdateWindowFramebuffer = SDL_UpdateWindowTexture;
528 _this->DestroyWindowFramebuffer = SDL_DestroyWindowTexture;
531 /* Disable the screen saver by default. This is a change from <= 2.0.1,
532 but most things using SDL are games or media players; you wouldn't
533 want a screensaver to trigger if you're playing exclusively with a
534 joystick, or passively watching a movie. Things that use SDL but
535 function more like a normal desktop app should explicitly reenable the
537 hint = SDL_GetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER);
539 allow_screensaver = SDL_atoi(hint) ? SDL_TRUE : SDL_FALSE;
541 allow_screensaver = SDL_FALSE;
543 if (!allow_screensaver) {
544 SDL_DisableScreenSaver();
547 /* If we don't use a screen keyboard, turn on text input by default,
548 otherwise programs that expect to get text events without enabling
549 UNICODE input won't get any events.
551 Actually, come to think of it, you needed to call SDL_EnableUNICODE(1)
552 in SDL 1.2 before you got text input events. Hmm...
554 if (!SDL_HasScreenKeyboardSupport()) {
555 SDL_StartTextInput();
558 /* We're ready to go! */
563 SDL_GetCurrentVideoDriver()
566 SDL_UninitializedVideo();
573 SDL_GetVideoDevice(void)
579 SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
581 SDL_VideoDisplay display;
585 display.desktop_mode = *desktop_mode;
587 display.current_mode = display.desktop_mode;
589 return SDL_AddVideoDisplay(&display);
593 SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
595 SDL_VideoDisplay *displays;
599 SDL_realloc(_this->displays,
600 (_this->num_displays + 1) * sizeof(*displays));
602 index = _this->num_displays++;
603 displays[index] = *display;
604 displays[index].device = _this;
605 _this->displays = displays;
608 displays[index].name = SDL_strdup(display->name);
612 SDL_itoa(index, name, 10);
613 displays[index].name = SDL_strdup(name);
622 SDL_GetNumVideoDisplays(void)
625 SDL_UninitializedVideo();
628 return _this->num_displays;
632 SDL_GetIndexOfDisplay(SDL_VideoDisplay *display)
636 for (displayIndex = 0; displayIndex < _this->num_displays; ++displayIndex) {
637 if (display == &_this->displays[displayIndex]) {
642 /* Couldn't find the display, just use index 0 */
647 SDL_GetDisplayDriverData(int displayIndex)
649 CHECK_DISPLAY_INDEX(displayIndex, NULL);
651 return _this->displays[displayIndex].driverdata;
655 SDL_GetDisplayName(int displayIndex)
657 CHECK_DISPLAY_INDEX(displayIndex, NULL);
659 return _this->displays[displayIndex].name;
663 SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
665 CHECK_DISPLAY_INDEX(displayIndex, -1);
668 SDL_VideoDisplay *display = &_this->displays[displayIndex];
670 if (_this->GetDisplayBounds) {
671 if (_this->GetDisplayBounds(_this, display, rect) == 0) {
676 /* Assume that the displays are left to right */
677 if (displayIndex == 0) {
681 SDL_GetDisplayBounds(displayIndex-1, rect);
684 rect->w = display->current_mode.w;
685 rect->h = display->current_mode.h;
691 SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi)
693 SDL_VideoDisplay *display;
695 CHECK_DISPLAY_INDEX(displayIndex, -1);
697 display = &_this->displays[displayIndex];
699 if (_this->GetDisplayDPI) {
700 if (_this->GetDisplayDPI(_this, display, ddpi, hdpi, vdpi) == 0) {
709 SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
711 SDL_DisplayMode *modes;
714 /* Make sure we don't already have the mode in the list */
715 modes = display->display_modes;
716 nmodes = display->num_display_modes;
717 for (i = 0; i < nmodes; ++i) {
718 if (cmpmodes(mode, &modes[i]) == 0) {
723 /* Go ahead and add the new mode */
724 if (nmodes == display->max_display_modes) {
727 (display->max_display_modes + 32) * sizeof(*modes));
731 display->display_modes = modes;
732 display->max_display_modes += 32;
734 modes[nmodes] = *mode;
735 display->num_display_modes++;
737 /* Re-sort video modes */
738 SDL_qsort(display->display_modes, display->num_display_modes,
739 sizeof(SDL_DisplayMode), cmpmodes);
745 SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
747 if (!display->num_display_modes && _this->GetDisplayModes) {
748 _this->GetDisplayModes(_this, display);
749 SDL_qsort(display->display_modes, display->num_display_modes,
750 sizeof(SDL_DisplayMode), cmpmodes);
752 return display->num_display_modes;
756 SDL_GetNumDisplayModes(int displayIndex)
758 CHECK_DISPLAY_INDEX(displayIndex, -1);
760 return SDL_GetNumDisplayModesForDisplay(&_this->displays[displayIndex]);
764 SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode)
766 SDL_VideoDisplay *display;
768 CHECK_DISPLAY_INDEX(displayIndex, -1);
770 display = &_this->displays[displayIndex];
771 if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) {
772 return SDL_SetError("index must be in the range of 0 - %d",
773 SDL_GetNumDisplayModesForDisplay(display) - 1);
776 *mode = display->display_modes[index];
782 SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode)
784 SDL_VideoDisplay *display;
786 CHECK_DISPLAY_INDEX(displayIndex, -1);
788 display = &_this->displays[displayIndex];
790 *mode = display->desktop_mode;
796 SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode)
798 SDL_VideoDisplay *display;
800 CHECK_DISPLAY_INDEX(displayIndex, -1);
802 display = &_this->displays[displayIndex];
804 *mode = display->current_mode;
809 static SDL_DisplayMode *
810 SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
811 const SDL_DisplayMode * mode,
812 SDL_DisplayMode * closest)
814 Uint32 target_format;
815 int target_refresh_rate;
817 SDL_DisplayMode *current, *match;
819 if (!mode || !closest) {
820 SDL_SetError("Missing desired mode or closest mode parameter");
824 /* Default to the desktop format */
826 target_format = mode->format;
828 target_format = display->desktop_mode.format;
831 /* Default to the desktop refresh rate */
832 if (mode->refresh_rate) {
833 target_refresh_rate = mode->refresh_rate;
835 target_refresh_rate = display->desktop_mode.refresh_rate;
839 for (i = 0; i < SDL_GetNumDisplayModesForDisplay(display); ++i) {
840 current = &display->display_modes[i];
842 if (current->w && (current->w < mode->w)) {
843 /* Out of sorted modes large enough here */
846 if (current->h && (current->h < mode->h)) {
847 if (current->w && (current->w == mode->w)) {
848 /* Out of sorted modes large enough here */
851 /* Wider, but not tall enough, due to a different
852 aspect ratio. This mode must be skipped, but closer
853 modes may still follow. */
856 if (!match || current->w < match->w || current->h < match->h) {
860 if (current->format != match->format) {
861 /* Sorted highest depth to lowest */
862 if (current->format == target_format ||
863 (SDL_BITSPERPIXEL(current->format) >=
864 SDL_BITSPERPIXEL(target_format)
865 && SDL_PIXELTYPE(current->format) ==
866 SDL_PIXELTYPE(target_format))) {
871 if (current->refresh_rate != match->refresh_rate) {
872 /* Sorted highest refresh to lowest */
873 if (current->refresh_rate >= target_refresh_rate) {
880 closest->format = match->format;
882 closest->format = mode->format;
884 if (match->w && match->h) {
885 closest->w = match->w;
886 closest->h = match->h;
888 closest->w = mode->w;
889 closest->h = mode->h;
891 if (match->refresh_rate) {
892 closest->refresh_rate = match->refresh_rate;
894 closest->refresh_rate = mode->refresh_rate;
896 closest->driverdata = match->driverdata;
899 * Pick some reasonable defaults if the app and driver don't
902 if (!closest->format) {
903 closest->format = SDL_PIXELFORMAT_RGB888;
917 SDL_GetClosestDisplayMode(int displayIndex,
918 const SDL_DisplayMode * mode,
919 SDL_DisplayMode * closest)
921 SDL_VideoDisplay *display;
923 CHECK_DISPLAY_INDEX(displayIndex, NULL);
925 display = &_this->displays[displayIndex];
926 return SDL_GetClosestDisplayModeForDisplay(display, mode, closest);
930 SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
932 SDL_DisplayMode display_mode;
933 SDL_DisplayMode current_mode;
936 display_mode = *mode;
938 /* Default to the current mode */
939 if (!display_mode.format) {
940 display_mode.format = display->current_mode.format;
942 if (!display_mode.w) {
943 display_mode.w = display->current_mode.w;
945 if (!display_mode.h) {
946 display_mode.h = display->current_mode.h;
948 if (!display_mode.refresh_rate) {
949 display_mode.refresh_rate = display->current_mode.refresh_rate;
952 /* Get a good video mode, the closest one possible */
953 if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
954 return SDL_SetError("No video mode large enough for %dx%d",
955 display_mode.w, display_mode.h);
958 display_mode = display->desktop_mode;
961 /* See if there's anything left to do */
962 current_mode = display->current_mode;
963 if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) {
967 /* Actually change the display mode */
968 if (!_this->SetDisplayMode) {
969 return SDL_SetError("Video driver doesn't support changing display mode");
971 if (_this->SetDisplayMode(_this, display, &display_mode) < 0) {
974 display->current_mode = display_mode;
979 SDL_GetWindowDisplayIndex(SDL_Window * window)
984 int closest_dist = 0x7FFFFFFF;
989 CHECK_WINDOW_MAGIC(window, -1);
991 if (SDL_WINDOWPOS_ISUNDEFINED(window->x) ||
992 SDL_WINDOWPOS_ISCENTERED(window->x)) {
993 displayIndex = (window->x & 0xFFFF);
994 if (displayIndex >= _this->num_displays) {
999 if (SDL_WINDOWPOS_ISUNDEFINED(window->y) ||
1000 SDL_WINDOWPOS_ISCENTERED(window->y)) {
1001 displayIndex = (window->y & 0xFFFF);
1002 if (displayIndex >= _this->num_displays) {
1005 return displayIndex;
1008 /* Find the display containing the window */
1009 for (i = 0; i < _this->num_displays; ++i) {
1010 SDL_VideoDisplay *display = &_this->displays[i];
1012 if (display->fullscreen_window == window) {
1016 center.x = window->x + window->w / 2;
1017 center.y = window->y + window->h / 2;
1018 for (i = 0; i < _this->num_displays; ++i) {
1019 SDL_GetDisplayBounds(i, &rect);
1020 if (SDL_EnclosePoints(¢er, 1, &rect, NULL)) {
1024 delta.x = center.x - (rect.x + rect.w / 2);
1025 delta.y = center.y - (rect.y + rect.h / 2);
1026 dist = (delta.x*delta.x + delta.y*delta.y);
1027 if (dist < closest_dist) {
1029 closest_dist = dist;
1033 SDL_SetError("Couldn't find any displays");
1039 SDL_GetDisplayForWindow(SDL_Window *window)
1041 int displayIndex = SDL_GetWindowDisplayIndex(window);
1042 if (displayIndex >= 0) {
1043 return &_this->displays[displayIndex];
1050 SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
1052 CHECK_WINDOW_MAGIC(window, -1);
1055 window->fullscreen_mode = *mode;
1057 SDL_zero(window->fullscreen_mode);
1060 if (FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
1061 SDL_DisplayMode fullscreen_mode;
1062 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
1063 SDL_SetDisplayModeForDisplay(SDL_GetDisplayForWindow(window), &fullscreen_mode);
1070 SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
1072 SDL_DisplayMode fullscreen_mode;
1073 SDL_VideoDisplay *display;
1075 CHECK_WINDOW_MAGIC(window, -1);
1078 return SDL_InvalidParamError("mode");
1081 fullscreen_mode = window->fullscreen_mode;
1082 if (!fullscreen_mode.w) {
1083 fullscreen_mode.w = window->windowed.w;
1085 if (!fullscreen_mode.h) {
1086 fullscreen_mode.h = window->windowed.h;
1089 display = SDL_GetDisplayForWindow(window);
1091 /* if in desktop size mode, just return the size of the desktop */
1092 if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
1093 fullscreen_mode = display->desktop_mode;
1094 } else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
1096 &fullscreen_mode)) {
1097 return SDL_SetError("Couldn't find display mode match");
1101 *mode = fullscreen_mode;
1107 SDL_GetWindowPixelFormat(SDL_Window * window)
1109 SDL_VideoDisplay *display;
1111 CHECK_WINDOW_MAGIC(window, SDL_PIXELFORMAT_UNKNOWN);
1113 display = SDL_GetDisplayForWindow(window);
1114 return display->current_mode.format;
1118 SDL_RestoreMousePosition(SDL_Window *window)
1122 if (window == SDL_GetMouseFocus()) {
1123 SDL_GetMouseState(&x, &y);
1124 SDL_WarpMouseInWindow(window, x, y);
1129 extern Uint32 WINRT_DetectWindowFlags(SDL_Window * window);
1133 SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
1135 SDL_VideoDisplay *display;
1138 CHECK_WINDOW_MAGIC(window,-1);
1140 /* if we are in the process of hiding don't go back to fullscreen */
1141 if ( window->is_hiding && fullscreen )
1145 /* if the window is going away and no resolution change is necessary,
1146 do nothing, or else we may trigger an ugly double-transition
1148 if (window->is_destroying && (window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP)
1151 /* If we're switching between a fullscreen Space and "normal" fullscreen, we need to get back to normal first. */
1152 if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN)) {
1153 if (!Cocoa_SetWindowFullscreenSpace(window, SDL_FALSE)) {
1156 } else if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
1157 display = SDL_GetDisplayForWindow(window);
1158 SDL_SetDisplayModeForDisplay(display, NULL);
1159 if (_this->SetWindowFullscreen) {
1160 _this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
1164 if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {
1165 if (Cocoa_IsWindowInFullscreenSpace(window) != fullscreen) {
1168 window->last_fullscreen_flags = window->flags;
1171 #elif __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
1172 /* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
1173 or not. The user can choose this, via OS-provided UI, but this can't
1174 be set programmatically.
1176 Just look at what SDL's WinRT video backend code detected with regards
1177 to fullscreen (being active, or not), and figure out a return/error code
1180 if (fullscreen == !(WINRT_DetectWindowFlags(window) & FULLSCREEN_MASK)) {
1182 1. fullscreen was requested, and we're already windowed
1183 2. windowed-mode was requested, and we're already fullscreen
1185 WinRT 8.x can't resolve either programmatically, so we're
1190 /* Whatever was requested, fullscreen or windowed mode, is already
1197 display = SDL_GetDisplayForWindow(window);
1200 /* Hide any other fullscreen windows */
1201 if (display->fullscreen_window &&
1202 display->fullscreen_window != window) {
1203 SDL_MinimizeWindow(display->fullscreen_window);
1207 /* See if anything needs to be done now */
1208 if ((display->fullscreen_window == window) == fullscreen) {
1209 if ((window->last_fullscreen_flags & FULLSCREEN_MASK) == (window->flags & FULLSCREEN_MASK)) {
1214 /* See if there are any fullscreen windows */
1215 for (other = _this->windows; other; other = other->next) {
1216 SDL_bool setDisplayMode = SDL_FALSE;
1218 if (other == window) {
1219 setDisplayMode = fullscreen;
1220 } else if (FULLSCREEN_VISIBLE(other) &&
1221 SDL_GetDisplayForWindow(other) == display) {
1222 setDisplayMode = SDL_TRUE;
1225 if (setDisplayMode) {
1226 SDL_DisplayMode fullscreen_mode;
1228 SDL_zero(fullscreen_mode);
1230 if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
1231 SDL_bool resized = SDL_TRUE;
1233 if (other->w == fullscreen_mode.w && other->h == fullscreen_mode.h) {
1234 resized = SDL_FALSE;
1237 /* only do the mode change if we want exclusive fullscreen */
1238 if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
1239 if (SDL_SetDisplayModeForDisplay(display, &fullscreen_mode) < 0) {
1243 if (SDL_SetDisplayModeForDisplay(display, NULL) < 0) {
1248 if (_this->SetWindowFullscreen) {
1249 _this->SetWindowFullscreen(_this, other, display, SDL_TRUE);
1251 display->fullscreen_window = other;
1253 /* Generate a mode change event here */
1255 SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
1256 fullscreen_mode.w, fullscreen_mode.h);
1258 SDL_OnWindowResized(other);
1261 SDL_RestoreMousePosition(other);
1263 window->last_fullscreen_flags = window->flags;
1269 /* Nope, restore the desktop mode */
1270 SDL_SetDisplayModeForDisplay(display, NULL);
1272 if (_this->SetWindowFullscreen) {
1273 _this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
1275 display->fullscreen_window = NULL;
1277 /* Generate a mode change event here */
1278 SDL_OnWindowResized(window);
1280 /* Restore the cursor position */
1281 SDL_RestoreMousePosition(window);
1283 window->last_fullscreen_flags = window->flags;
1287 #define CREATE_FLAGS \
1288 (SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI)
1291 SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
1293 window->windowed.x = window->x;
1294 window->windowed.y = window->y;
1295 window->windowed.w = window->w;
1296 window->windowed.h = window->h;
1298 if (flags & SDL_WINDOW_MAXIMIZED) {
1299 SDL_MaximizeWindow(window);
1301 if (flags & SDL_WINDOW_MINIMIZED) {
1302 SDL_MinimizeWindow(window);
1304 if (flags & SDL_WINDOW_FULLSCREEN) {
1305 SDL_SetWindowFullscreen(window, flags);
1307 if (flags & SDL_WINDOW_INPUT_GRABBED) {
1308 SDL_SetWindowGrab(window, SDL_TRUE);
1310 if (!(flags & SDL_WINDOW_HIDDEN)) {
1311 SDL_ShowWindow(window);
1316 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
1322 /* Initialize the video system if needed */
1323 if (SDL_VideoInit(NULL) < 0) {
1328 /* Some platforms can't create zero-sized windows */
1336 /* Some platforms blow up if the windows are too large. Raise it later? */
1337 if ((w > 16384) || (h > 16384)) {
1338 SDL_SetError("Window is too large.");
1342 /* Some platforms have OpenGL enabled by default */
1343 #if (SDL_VIDEO_OPENGL && __MACOSX__) || __IPHONEOS__ || __ANDROID__ || __NACL__
1344 flags |= SDL_WINDOW_OPENGL;
1346 if (flags & SDL_WINDOW_OPENGL) {
1347 if (!_this->GL_CreateContext) {
1348 SDL_SetError("No OpenGL support in video driver");
1351 if (SDL_GL_LoadLibrary(NULL) < 0) {
1356 /* Unless the user has specified the high-DPI disabling hint, respect the
1357 * SDL_WINDOW_ALLOW_HIGHDPI flag.
1359 if (flags & SDL_WINDOW_ALLOW_HIGHDPI) {
1360 hint = SDL_GetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED);
1361 if (hint && SDL_atoi(hint) > 0) {
1362 flags &= ~SDL_WINDOW_ALLOW_HIGHDPI;
1366 window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
1371 window->magic = &_this->window_magic;
1372 window->id = _this->next_object_id++;
1377 if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) ||
1378 SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
1379 SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
1383 displayIndex = SDL_GetIndexOfDisplay(display);
1384 SDL_GetDisplayBounds(displayIndex, &bounds);
1385 if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
1386 window->x = bounds.x + (bounds.w - w) / 2;
1388 if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
1389 window->y = bounds.y + (bounds.h - h) / 2;
1392 window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
1393 window->last_fullscreen_flags = window->flags;
1394 window->brightness = 1.0f;
1395 window->next = _this->windows;
1396 window->is_destroying = SDL_FALSE;
1398 if (_this->windows) {
1399 _this->windows->prev = window;
1401 _this->windows = window;
1403 if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
1404 SDL_DestroyWindow(window);
1408 #if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
1409 /* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
1410 or not. The user can choose this, via OS-provided UI, but this can't
1411 be set programmatically.
1413 Just look at what SDL's WinRT video backend code detected with regards
1414 to fullscreen (being active, or not), and figure out a return/error code
1417 flags = window->flags;
1421 SDL_SetWindowTitle(window, title);
1423 SDL_FinishWindowCreation(window, flags);
1425 /* If the window was created fullscreen, make sure the mode code matches */
1426 SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window));
1432 SDL_CreateWindowFrom(const void *data)
1437 SDL_UninitializedVideo();
1440 if (!_this->CreateWindowFrom) {
1444 window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
1449 window->magic = &_this->window_magic;
1450 window->id = _this->next_object_id++;
1451 window->flags = SDL_WINDOW_FOREIGN;
1452 window->last_fullscreen_flags = window->flags;
1453 window->is_destroying = SDL_FALSE;
1454 window->brightness = 1.0f;
1455 window->next = _this->windows;
1456 if (_this->windows) {
1457 _this->windows->prev = window;
1459 _this->windows = window;
1461 if (_this->CreateWindowFrom(_this, window, data) < 0) {
1462 SDL_DestroyWindow(window);
1469 SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
1471 SDL_bool loaded_opengl = SDL_FALSE;
1473 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
1474 return SDL_SetError("No OpenGL support in video driver");
1477 if (window->flags & SDL_WINDOW_FOREIGN) {
1478 /* Can't destroy and re-create foreign windows, hrm */
1479 flags |= SDL_WINDOW_FOREIGN;
1481 flags &= ~SDL_WINDOW_FOREIGN;
1484 /* Restore video mode, etc. */
1485 SDL_HideWindow(window);
1487 /* Tear down the old native window */
1488 if (window->surface) {
1489 window->surface->flags &= ~SDL_DONTFREE;
1490 SDL_FreeSurface(window->surface);
1491 window->surface = NULL;
1493 if (_this->DestroyWindowFramebuffer) {
1494 _this->DestroyWindowFramebuffer(_this, window);
1496 if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
1497 _this->DestroyWindow(_this, window);
1500 if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
1501 if (flags & SDL_WINDOW_OPENGL) {
1502 if (SDL_GL_LoadLibrary(NULL) < 0) {
1505 loaded_opengl = SDL_TRUE;
1507 SDL_GL_UnloadLibrary();
1511 window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
1512 window->last_fullscreen_flags = window->flags;
1513 window->is_destroying = SDL_FALSE;
1515 if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) {
1516 if (_this->CreateWindow(_this, window) < 0) {
1517 if (loaded_opengl) {
1518 SDL_GL_UnloadLibrary();
1519 window->flags &= ~SDL_WINDOW_OPENGL;
1525 if (flags & SDL_WINDOW_FOREIGN) {
1526 window->flags |= SDL_WINDOW_FOREIGN;
1529 if (_this->SetWindowTitle && window->title) {
1530 _this->SetWindowTitle(_this, window);
1533 if (_this->SetWindowIcon && window->icon) {
1534 _this->SetWindowIcon(_this, window, window->icon);
1537 if (window->hit_test) {
1538 _this->SetWindowHitTest(window, SDL_TRUE);
1541 SDL_FinishWindowCreation(window, flags);
1547 SDL_GetWindowID(SDL_Window * window)
1549 CHECK_WINDOW_MAGIC(window, 0);
1555 SDL_GetWindowFromID(Uint32 id)
1562 for (window = _this->windows; window; window = window->next) {
1563 if (window->id == id) {
1571 SDL_GetWindowFlags(SDL_Window * window)
1573 CHECK_WINDOW_MAGIC(window, 0);
1575 return window->flags;
1579 SDL_SetWindowTitle(SDL_Window * window, const char *title)
1581 CHECK_WINDOW_MAGIC(window,);
1583 if (title == window->title) {
1586 SDL_free(window->title);
1588 window->title = SDL_strdup(title ? title : "");
1590 if (_this->SetWindowTitle) {
1591 _this->SetWindowTitle(_this, window);
1596 SDL_GetWindowTitle(SDL_Window * window)
1598 CHECK_WINDOW_MAGIC(window, "");
1600 return window->title ? window->title : "";
1604 SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
1606 CHECK_WINDOW_MAGIC(window,);
1612 SDL_FreeSurface(window->icon);
1614 /* Convert the icon into ARGB8888 */
1615 window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
1616 if (!window->icon) {
1620 if (_this->SetWindowIcon) {
1621 _this->SetWindowIcon(_this, window, window->icon);
1626 SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata)
1628 SDL_WindowUserData *prev, *data;
1630 CHECK_WINDOW_MAGIC(window, NULL);
1632 /* Input validation */
1633 if (name == NULL || name[0] == '\0') {
1634 SDL_InvalidParamError("name");
1638 /* See if the named data already exists */
1640 for (data = window->data; data; prev = data, data = data->next) {
1641 if (data->name && SDL_strcmp(data->name, name) == 0) {
1642 void *last_value = data->data;
1645 /* Set the new value */
1646 data->data = userdata;
1648 /* Delete this value */
1650 prev->next = data->next;
1652 window->data = data->next;
1654 SDL_free(data->name);
1661 /* Add new data to the window */
1663 data = (SDL_WindowUserData *)SDL_malloc(sizeof(*data));
1664 data->name = SDL_strdup(name);
1665 data->data = userdata;
1666 data->next = window->data;
1667 window->data = data;
1673 SDL_GetWindowData(SDL_Window * window, const char *name)
1675 SDL_WindowUserData *data;
1677 CHECK_WINDOW_MAGIC(window, NULL);
1679 /* Input validation */
1680 if (name == NULL || name[0] == '\0') {
1681 SDL_InvalidParamError("name");
1685 for (data = window->data; data; data = data->next) {
1686 if (data->name && SDL_strcmp(data->name, name) == 0) {
1694 SDL_SetWindowPosition(SDL_Window * window, int x, int y)
1696 CHECK_WINDOW_MAGIC(window,);
1698 if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
1699 int displayIndex = (x & 0xFFFF);
1701 if (displayIndex > _this->num_displays) {
1707 SDL_GetDisplayBounds(displayIndex, &bounds);
1708 if (SDL_WINDOWPOS_ISCENTERED(x)) {
1709 x = bounds.x + (bounds.w - window->w) / 2;
1711 if (SDL_WINDOWPOS_ISCENTERED(y)) {
1712 y = bounds.y + (bounds.h - window->h) / 2;
1716 if ((window->flags & SDL_WINDOW_FULLSCREEN)) {
1717 if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
1718 window->windowed.x = x;
1720 if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
1721 window->windowed.y = y;
1724 if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
1727 if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
1731 if (_this->SetWindowPosition) {
1732 _this->SetWindowPosition(_this, window);
1734 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
1739 SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
1741 CHECK_WINDOW_MAGIC(window,);
1743 /* Fullscreen windows are always at their display's origin */
1744 if (window->flags & SDL_WINDOW_FULLSCREEN) {
1754 /* Find the window's monitor and update to the
1756 displayIndex = SDL_GetWindowDisplayIndex(window);
1757 if (displayIndex >= 0) {
1762 SDL_GetDisplayBounds(displayIndex, &bounds);
1781 SDL_SetWindowBordered(SDL_Window * window, SDL_bool bordered)
1783 CHECK_WINDOW_MAGIC(window,);
1784 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
1785 const int want = (bordered != SDL_FALSE); /* normalize the flag. */
1786 const int have = ((window->flags & SDL_WINDOW_BORDERLESS) == 0);
1787 if ((want != have) && (_this->SetWindowBordered)) {
1789 window->flags &= ~SDL_WINDOW_BORDERLESS;
1791 window->flags |= SDL_WINDOW_BORDERLESS;
1793 _this->SetWindowBordered(_this, window, (SDL_bool) want);
1799 SDL_SetWindowSize(SDL_Window * window, int w, int h)
1801 CHECK_WINDOW_MAGIC(window,);
1803 SDL_InvalidParamError("w");
1807 SDL_InvalidParamError("h");
1811 /* Make sure we don't exceed any window size limits */
1812 if (window->min_w && w < window->min_w)
1816 if (window->max_w && w > window->max_w)
1820 if (window->min_h && h < window->min_h)
1824 if (window->max_h && h > window->max_h)
1829 window->windowed.w = w;
1830 window->windowed.h = h;
1832 if (window->flags & SDL_WINDOW_FULLSCREEN) {
1833 if (FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
1834 window->last_fullscreen_flags = 0;
1835 SDL_UpdateFullscreenMode(window, SDL_TRUE);
1840 if (_this->SetWindowSize) {
1841 _this->SetWindowSize(_this, window);
1843 if (window->w == w && window->h == h) {
1844 /* We didn't get a SDL_WINDOWEVENT_RESIZED event (by design) */
1845 SDL_OnWindowResized(window);
1851 SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
1853 CHECK_WINDOW_MAGIC(window,);
1863 SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
1865 CHECK_WINDOW_MAGIC(window,);
1867 SDL_InvalidParamError("min_w");
1871 SDL_InvalidParamError("min_h");
1875 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
1876 window->min_w = min_w;
1877 window->min_h = min_h;
1878 if (_this->SetWindowMinimumSize) {
1879 _this->SetWindowMinimumSize(_this, window);
1881 /* Ensure that window is not smaller than minimal size */
1882 SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
1887 SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
1889 CHECK_WINDOW_MAGIC(window,);
1891 *min_w = window->min_w;
1894 *min_h = window->min_h;
1899 SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h)
1901 CHECK_WINDOW_MAGIC(window,);
1903 SDL_InvalidParamError("max_w");
1907 SDL_InvalidParamError("max_h");
1911 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
1912 window->max_w = max_w;
1913 window->max_h = max_h;
1914 if (_this->SetWindowMaximumSize) {
1915 _this->SetWindowMaximumSize(_this, window);
1917 /* Ensure that window is not larger than maximal size */
1918 SDL_SetWindowSize(window, SDL_min(window->w, window->max_w), SDL_min(window->h, window->max_h));
1923 SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h)
1925 CHECK_WINDOW_MAGIC(window,);
1927 *max_w = window->max_w;
1930 *max_h = window->max_h;
1935 SDL_ShowWindow(SDL_Window * window)
1937 CHECK_WINDOW_MAGIC(window,);
1939 if (window->flags & SDL_WINDOW_SHOWN) {
1943 if (_this->ShowWindow) {
1944 _this->ShowWindow(_this, window);
1946 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
1950 SDL_HideWindow(SDL_Window * window)
1952 CHECK_WINDOW_MAGIC(window,);
1954 if (!(window->flags & SDL_WINDOW_SHOWN)) {
1958 window->is_hiding = SDL_TRUE;
1959 SDL_UpdateFullscreenMode(window, SDL_FALSE);
1961 if (_this->HideWindow) {
1962 _this->HideWindow(_this, window);
1964 window->is_hiding = SDL_FALSE;
1965 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
1969 SDL_RaiseWindow(SDL_Window * window)
1971 CHECK_WINDOW_MAGIC(window,);
1973 if (!(window->flags & SDL_WINDOW_SHOWN)) {
1976 if (_this->RaiseWindow) {
1977 _this->RaiseWindow(_this, window);
1982 SDL_MaximizeWindow(SDL_Window * window)
1984 CHECK_WINDOW_MAGIC(window,);
1986 if (window->flags & SDL_WINDOW_MAXIMIZED) {
1990 /* !!! FIXME: should this check if the window is resizable? */
1992 if (_this->MaximizeWindow) {
1993 _this->MaximizeWindow(_this, window);
1998 SDL_MinimizeWindow(SDL_Window * window)
2000 CHECK_WINDOW_MAGIC(window,);
2002 if (window->flags & SDL_WINDOW_MINIMIZED) {
2006 SDL_UpdateFullscreenMode(window, SDL_FALSE);
2008 if (_this->MinimizeWindow) {
2009 _this->MinimizeWindow(_this, window);
2014 SDL_RestoreWindow(SDL_Window * window)
2016 CHECK_WINDOW_MAGIC(window,);
2018 if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
2022 if (_this->RestoreWindow) {
2023 _this->RestoreWindow(_this, window);
2028 SDL_SetWindowFullscreen(SDL_Window * window, Uint32 flags)
2031 CHECK_WINDOW_MAGIC(window, -1);
2033 flags &= FULLSCREEN_MASK;
2035 if (flags == (window->flags & FULLSCREEN_MASK)) {
2039 /* clear the previous flags and OR in the new ones */
2040 oldflags = window->flags & FULLSCREEN_MASK;
2041 window->flags &= ~FULLSCREEN_MASK;
2042 window->flags |= flags;
2044 if (SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window)) == 0) {
2048 window->flags &= ~FULLSCREEN_MASK;
2049 window->flags |= oldflags;
2053 static SDL_Surface *
2054 SDL_CreateWindowFramebuffer(SDL_Window * window)
2060 Uint32 Rmask, Gmask, Bmask, Amask;
2062 if (!_this->CreateWindowFramebuffer || !_this->UpdateWindowFramebuffer) {
2066 if (_this->CreateWindowFramebuffer(_this, window, &format, &pixels, &pitch) < 0) {
2070 if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
2074 return SDL_CreateRGBSurfaceFrom(pixels, window->w, window->h, bpp, pitch, Rmask, Gmask, Bmask, Amask);
2078 SDL_GetWindowSurface(SDL_Window * window)
2080 CHECK_WINDOW_MAGIC(window, NULL);
2082 if (!window->surface_valid) {
2083 if (window->surface) {
2084 window->surface->flags &= ~SDL_DONTFREE;
2085 SDL_FreeSurface(window->surface);
2087 window->surface = SDL_CreateWindowFramebuffer(window);
2088 if (window->surface) {
2089 window->surface_valid = SDL_TRUE;
2090 window->surface->flags |= SDL_DONTFREE;
2093 return window->surface;
2097 SDL_UpdateWindowSurface(SDL_Window * window)
2101 CHECK_WINDOW_MAGIC(window, -1);
2105 full_rect.w = window->w;
2106 full_rect.h = window->h;
2107 return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1);
2111 SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects,
2114 CHECK_WINDOW_MAGIC(window, -1);
2116 if (!window->surface_valid) {
2117 return SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface");
2120 return _this->UpdateWindowFramebuffer(_this, window, rects, numrects);
2124 SDL_SetWindowBrightness(SDL_Window * window, float brightness)
2129 CHECK_WINDOW_MAGIC(window, -1);
2131 SDL_CalculateGammaRamp(brightness, ramp);
2132 status = SDL_SetWindowGammaRamp(window, ramp, ramp, ramp);
2134 window->brightness = brightness;
2140 SDL_GetWindowBrightness(SDL_Window * window)
2142 CHECK_WINDOW_MAGIC(window, 1.0f);
2144 return window->brightness;
2148 SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red,
2149 const Uint16 * green,
2150 const Uint16 * blue)
2152 CHECK_WINDOW_MAGIC(window, -1);
2154 if (!_this->SetWindowGammaRamp) {
2155 return SDL_Unsupported();
2158 if (!window->gamma) {
2159 if (SDL_GetWindowGammaRamp(window, NULL, NULL, NULL) < 0) {
2162 SDL_assert(window->gamma != NULL);
2166 SDL_memcpy(&window->gamma[0*256], red, 256*sizeof(Uint16));
2169 SDL_memcpy(&window->gamma[1*256], green, 256*sizeof(Uint16));
2172 SDL_memcpy(&window->gamma[2*256], blue, 256*sizeof(Uint16));
2174 if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
2175 return _this->SetWindowGammaRamp(_this, window, window->gamma);
2182 SDL_GetWindowGammaRamp(SDL_Window * window, Uint16 * red,
2186 CHECK_WINDOW_MAGIC(window, -1);
2188 if (!window->gamma) {
2191 window->gamma = (Uint16 *)SDL_malloc(256*6*sizeof(Uint16));
2192 if (!window->gamma) {
2193 return SDL_OutOfMemory();
2195 window->saved_gamma = window->gamma + 3*256;
2197 if (_this->GetWindowGammaRamp) {
2198 if (_this->GetWindowGammaRamp(_this, window, window->gamma) < 0) {
2202 /* Create an identity gamma ramp */
2203 for (i = 0; i < 256; ++i) {
2204 Uint16 value = (Uint16)((i << 8) | i);
2206 window->gamma[0*256+i] = value;
2207 window->gamma[1*256+i] = value;
2208 window->gamma[2*256+i] = value;
2211 SDL_memcpy(window->saved_gamma, window->gamma, 3*256*sizeof(Uint16));
2215 SDL_memcpy(red, &window->gamma[0*256], 256*sizeof(Uint16));
2218 SDL_memcpy(green, &window->gamma[1*256], 256*sizeof(Uint16));
2221 SDL_memcpy(blue, &window->gamma[2*256], 256*sizeof(Uint16));
2227 SDL_UpdateWindowGrab(SDL_Window * window)
2229 SDL_Window *grabbed_window;
2231 if ((SDL_GetMouse()->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
2232 (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
2235 grabbed = SDL_FALSE;
2238 grabbed_window = _this->grabbed_window;
2240 if (grabbed_window && (grabbed_window != window)) {
2241 /* stealing a grab from another window! */
2242 grabbed_window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
2243 if (_this->SetWindowGrab) {
2244 _this->SetWindowGrab(_this, grabbed_window, SDL_FALSE);
2247 _this->grabbed_window = window;
2248 } else if (grabbed_window == window) {
2249 _this->grabbed_window = NULL; /* ungrabbing. */
2252 if (_this->SetWindowGrab) {
2253 _this->SetWindowGrab(_this, window, grabbed);
2258 SDL_SetWindowGrab(SDL_Window * window, SDL_bool grabbed)
2260 CHECK_WINDOW_MAGIC(window,);
2262 if (!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
2266 window->flags |= SDL_WINDOW_INPUT_GRABBED;
2268 window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
2270 SDL_UpdateWindowGrab(window);
2274 SDL_GetWindowGrab(SDL_Window * window)
2276 CHECK_WINDOW_MAGIC(window, SDL_FALSE);
2277 SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
2278 return window == _this->grabbed_window;
2282 SDL_GetGrabbedWindow(void)
2284 SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
2285 return _this->grabbed_window;
2289 SDL_OnWindowShown(SDL_Window * window)
2291 SDL_OnWindowRestored(window);
2295 SDL_OnWindowHidden(SDL_Window * window)
2297 SDL_UpdateFullscreenMode(window, SDL_FALSE);
2301 SDL_OnWindowResized(SDL_Window * window)
2303 window->surface_valid = SDL_FALSE;
2304 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
2308 SDL_OnWindowMinimized(SDL_Window * window)
2310 SDL_UpdateFullscreenMode(window, SDL_FALSE);
2314 SDL_OnWindowRestored(SDL_Window * window)
2317 * FIXME: Is this fine to just remove this, or should it be preserved just
2318 * for the fullscreen case? In principle it seems like just hiding/showing
2319 * windows shouldn't affect the stacking order; maybe the right fix is to
2320 * re-decouple OnWindowShown and OnWindowRestored.
2322 /*SDL_RaiseWindow(window);*/
2324 if (FULLSCREEN_VISIBLE(window)) {
2325 SDL_UpdateFullscreenMode(window, SDL_TRUE);
2330 SDL_OnWindowEnter(SDL_Window * window)
2332 if (_this->OnWindowEnter) {
2333 _this->OnWindowEnter(_this, window);
2338 SDL_OnWindowLeave(SDL_Window * window)
2343 SDL_OnWindowFocusGained(SDL_Window * window)
2345 SDL_Mouse *mouse = SDL_GetMouse();
2347 if (window->gamma && _this->SetWindowGammaRamp) {
2348 _this->SetWindowGammaRamp(_this, window, window->gamma);
2351 if (mouse && mouse->relative_mode) {
2352 SDL_SetMouseFocus(window);
2353 SDL_WarpMouseInWindow(window, window->w/2, window->h/2);
2356 SDL_UpdateWindowGrab(window);
2360 ShouldMinimizeOnFocusLoss(SDL_Window * window)
2364 if (!(window->flags & SDL_WINDOW_FULLSCREEN) || window->is_destroying) {
2369 if (Cocoa_IsWindowInFullscreenSpace(window)) {
2374 hint = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS);
2387 SDL_OnWindowFocusLost(SDL_Window * window)
2389 if (window->gamma && _this->SetWindowGammaRamp) {
2390 _this->SetWindowGammaRamp(_this, window, window->saved_gamma);
2393 SDL_UpdateWindowGrab(window);
2395 if (ShouldMinimizeOnFocusLoss(window)) {
2396 SDL_MinimizeWindow(window);
2400 /* !!! FIXME: is this different than SDL_GetKeyboardFocus()?
2401 !!! FIXME: Also, SDL_GetKeyboardFocus() is O(1), this isn't. */
2403 SDL_GetFocusWindow(void)
2410 for (window = _this->windows; window; window = window->next) {
2411 if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
2419 SDL_DestroyWindow(SDL_Window * window)
2421 SDL_VideoDisplay *display;
2423 CHECK_WINDOW_MAGIC(window,);
2425 window->is_destroying = SDL_TRUE;
2427 /* Restore video mode, etc. */
2428 SDL_HideWindow(window);
2430 /* Make sure this window no longer has focus */
2431 if (SDL_GetKeyboardFocus() == window) {
2432 SDL_SetKeyboardFocus(NULL);
2434 if (SDL_GetMouseFocus() == window) {
2435 SDL_SetMouseFocus(NULL);
2438 /* make no context current if this is the current context window. */
2439 if (window->flags & SDL_WINDOW_OPENGL) {
2440 if (_this->current_glwin == window) {
2441 SDL_GL_MakeCurrent(window, NULL);
2445 if (window->surface) {
2446 window->surface->flags &= ~SDL_DONTFREE;
2447 SDL_FreeSurface(window->surface);
2449 if (_this->DestroyWindowFramebuffer) {
2450 _this->DestroyWindowFramebuffer(_this, window);
2452 if (_this->DestroyWindow) {
2453 _this->DestroyWindow(_this, window);
2455 if (window->flags & SDL_WINDOW_OPENGL) {
2456 SDL_GL_UnloadLibrary();
2459 display = SDL_GetDisplayForWindow(window);
2460 if (display->fullscreen_window == window) {
2461 display->fullscreen_window = NULL;
2464 /* Now invalidate magic */
2465 window->magic = NULL;
2467 /* Free memory associated with the window */
2468 SDL_free(window->title);
2469 SDL_FreeSurface(window->icon);
2470 SDL_free(window->gamma);
2471 while (window->data) {
2472 SDL_WindowUserData *data = window->data;
2474 window->data = data->next;
2475 SDL_free(data->name);
2479 /* Unlink the window from the list */
2481 window->next->prev = window->prev;
2484 window->prev->next = window->next;
2486 _this->windows = window->next;
2493 SDL_IsScreenSaverEnabled()
2498 return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
2502 SDL_EnableScreenSaver()
2507 if (!_this->suspend_screensaver) {
2510 _this->suspend_screensaver = SDL_FALSE;
2511 if (_this->SuspendScreenSaver) {
2512 _this->SuspendScreenSaver(_this);
2517 SDL_DisableScreenSaver()
2522 if (_this->suspend_screensaver) {
2525 _this->suspend_screensaver = SDL_TRUE;
2526 if (_this->SuspendScreenSaver) {
2527 _this->SuspendScreenSaver(_this);
2540 /* Halt event processing before doing anything else */
2544 SDL_QuitSubSystem(SDL_INIT_EVENTS);
2546 SDL_EnableScreenSaver();
2548 /* Clean up the system video */
2549 while (_this->windows) {
2550 SDL_DestroyWindow(_this->windows);
2552 _this->VideoQuit(_this);
2554 for (i = 0; i < _this->num_displays; ++i) {
2555 SDL_VideoDisplay *display = &_this->displays[i];
2556 for (j = display->num_display_modes; j--;) {
2557 SDL_free(display->display_modes[j].driverdata);
2558 display->display_modes[j].driverdata = NULL;
2560 SDL_free(display->display_modes);
2561 display->display_modes = NULL;
2562 SDL_free(display->desktop_mode.driverdata);
2563 display->desktop_mode.driverdata = NULL;
2564 SDL_free(display->driverdata);
2565 display->driverdata = NULL;
2567 if (_this->displays) {
2568 for (i = 0; i < _this->num_displays; ++i) {
2569 SDL_free(_this->displays[i].name);
2571 SDL_free(_this->displays);
2572 _this->displays = NULL;
2573 _this->num_displays = 0;
2575 SDL_free(_this->clipboard_text);
2576 _this->clipboard_text = NULL;
2582 SDL_GL_LoadLibrary(const char *path)
2587 return SDL_UninitializedVideo();
2589 if (_this->gl_config.driver_loaded) {
2590 if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) {
2591 return SDL_SetError("OpenGL library already loaded");
2595 if (!_this->GL_LoadLibrary) {
2596 return SDL_SetError("No dynamic GL support in video driver");
2598 retval = _this->GL_LoadLibrary(_this, path);
2601 ++_this->gl_config.driver_loaded;
2603 if (_this->GL_UnloadLibrary) {
2604 _this->GL_UnloadLibrary(_this);
2611 SDL_GL_GetProcAddress(const char *proc)
2616 SDL_UninitializedVideo();
2620 if (_this->GL_GetProcAddress) {
2621 if (_this->gl_config.driver_loaded) {
2622 func = _this->GL_GetProcAddress(_this, proc);
2624 SDL_SetError("No GL driver has been loaded");
2627 SDL_SetError("No dynamic GL support in video driver");
2633 SDL_GL_UnloadLibrary(void)
2636 SDL_UninitializedVideo();
2639 if (_this->gl_config.driver_loaded > 0) {
2640 if (--_this->gl_config.driver_loaded > 0) {
2643 if (_this->GL_UnloadLibrary) {
2644 _this->GL_UnloadLibrary(_this);
2649 static SDL_INLINE SDL_bool
2650 isAtLeastGL3(const char *verstr)
2652 return (verstr && (SDL_atoi(verstr) >= 3));
2656 SDL_GL_ExtensionSupported(const char *extension)
2658 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
2659 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
2660 const char *extensions;
2662 const char *where, *terminator;
2664 /* Extension names should not have spaces. */
2665 where = SDL_strchr(extension, ' ');
2666 if (where || *extension == '\0') {
2669 /* See if there's an environment variable override */
2670 start = SDL_getenv(extension);
2671 if (start && *start == '0') {
2675 /* Lookup the available extensions */
2677 glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
2678 if (!glGetStringFunc) {
2682 if (isAtLeastGL3((const char *) glGetStringFunc(GL_VERSION))) {
2683 const GLubyte *(APIENTRY * glGetStringiFunc) (GLenum, GLuint);
2684 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
2688 glGetStringiFunc = SDL_GL_GetProcAddress("glGetStringi");
2689 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
2690 if ((!glGetStringiFunc) || (!glGetIntegervFunc)) {
2694 #ifndef GL_NUM_EXTENSIONS
2695 #define GL_NUM_EXTENSIONS 0x821D
2697 glGetIntegervFunc(GL_NUM_EXTENSIONS, &num_exts);
2698 for (i = 0; i < num_exts; i++) {
2699 const char *thisext = (const char *) glGetStringiFunc(GL_EXTENSIONS, i);
2700 if (SDL_strcmp(thisext, extension) == 0) {
2708 /* Try the old way with glGetString(GL_EXTENSIONS) ... */
2710 extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
2715 * It takes a bit of care to be fool-proof about parsing the OpenGL
2716 * extensions string. Don't be fooled by sub-strings, etc.
2722 where = SDL_strstr(start, extension);
2726 terminator = where + SDL_strlen(extension);
2727 if (where == start || *(where - 1) == ' ')
2728 if (*terminator == ' ' || *terminator == '\0')
2740 SDL_GL_ResetAttributes()
2746 _this->gl_config.red_size = 3;
2747 _this->gl_config.green_size = 3;
2748 _this->gl_config.blue_size = 2;
2749 _this->gl_config.alpha_size = 0;
2750 _this->gl_config.buffer_size = 0;
2751 _this->gl_config.depth_size = 16;
2752 _this->gl_config.stencil_size = 0;
2753 _this->gl_config.double_buffer = 1;
2754 _this->gl_config.accum_red_size = 0;
2755 _this->gl_config.accum_green_size = 0;
2756 _this->gl_config.accum_blue_size = 0;
2757 _this->gl_config.accum_alpha_size = 0;
2758 _this->gl_config.stereo = 0;
2759 _this->gl_config.multisamplebuffers = 0;
2760 _this->gl_config.multisamplesamples = 0;
2761 _this->gl_config.retained_backing = 1;
2762 _this->gl_config.accelerated = -1; /* accelerated or not, both are fine */
2763 _this->gl_config.profile_mask = 0;
2764 #if SDL_VIDEO_OPENGL
2765 _this->gl_config.major_version = 2;
2766 _this->gl_config.minor_version = 1;
2767 #elif SDL_VIDEO_OPENGL_ES2
2768 _this->gl_config.major_version = 2;
2769 _this->gl_config.minor_version = 0;
2770 _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
2771 #elif SDL_VIDEO_OPENGL_ES
2772 _this->gl_config.major_version = 1;
2773 _this->gl_config.minor_version = 1;
2774 _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
2776 _this->gl_config.flags = 0;
2777 _this->gl_config.framebuffer_srgb_capable = 0;
2778 _this->gl_config.release_behavior = SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH;
2780 _this->gl_config.share_with_current_context = 0;
2784 SDL_GL_SetAttribute(SDL_GLattr attr, int value)
2786 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
2790 return SDL_UninitializedVideo();
2794 case SDL_GL_RED_SIZE:
2795 _this->gl_config.red_size = value;
2797 case SDL_GL_GREEN_SIZE:
2798 _this->gl_config.green_size = value;
2800 case SDL_GL_BLUE_SIZE:
2801 _this->gl_config.blue_size = value;
2803 case SDL_GL_ALPHA_SIZE:
2804 _this->gl_config.alpha_size = value;
2806 case SDL_GL_DOUBLEBUFFER:
2807 _this->gl_config.double_buffer = value;
2809 case SDL_GL_BUFFER_SIZE:
2810 _this->gl_config.buffer_size = value;
2812 case SDL_GL_DEPTH_SIZE:
2813 _this->gl_config.depth_size = value;
2815 case SDL_GL_STENCIL_SIZE:
2816 _this->gl_config.stencil_size = value;
2818 case SDL_GL_ACCUM_RED_SIZE:
2819 _this->gl_config.accum_red_size = value;
2821 case SDL_GL_ACCUM_GREEN_SIZE:
2822 _this->gl_config.accum_green_size = value;
2824 case SDL_GL_ACCUM_BLUE_SIZE:
2825 _this->gl_config.accum_blue_size = value;
2827 case SDL_GL_ACCUM_ALPHA_SIZE:
2828 _this->gl_config.accum_alpha_size = value;
2831 _this->gl_config.stereo = value;
2833 case SDL_GL_MULTISAMPLEBUFFERS:
2834 _this->gl_config.multisamplebuffers = value;
2836 case SDL_GL_MULTISAMPLESAMPLES:
2837 _this->gl_config.multisamplesamples = value;
2839 case SDL_GL_ACCELERATED_VISUAL:
2840 _this->gl_config.accelerated = value;
2842 case SDL_GL_RETAINED_BACKING:
2843 _this->gl_config.retained_backing = value;
2845 case SDL_GL_CONTEXT_MAJOR_VERSION:
2846 _this->gl_config.major_version = value;
2848 case SDL_GL_CONTEXT_MINOR_VERSION:
2849 _this->gl_config.minor_version = value;
2851 case SDL_GL_CONTEXT_EGL:
2852 /* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
2854 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
2856 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
2859 case SDL_GL_CONTEXT_FLAGS:
2860 if (value & ~(SDL_GL_CONTEXT_DEBUG_FLAG |
2861 SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG |
2862 SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG |
2863 SDL_GL_CONTEXT_RESET_ISOLATION_FLAG)) {
2864 retval = SDL_SetError("Unknown OpenGL context flag %d", value);
2867 _this->gl_config.flags = value;
2869 case SDL_GL_CONTEXT_PROFILE_MASK:
2871 value != SDL_GL_CONTEXT_PROFILE_CORE &&
2872 value != SDL_GL_CONTEXT_PROFILE_COMPATIBILITY &&
2873 value != SDL_GL_CONTEXT_PROFILE_ES) {
2874 retval = SDL_SetError("Unknown OpenGL context profile %d", value);
2877 _this->gl_config.profile_mask = value;
2879 case SDL_GL_SHARE_WITH_CURRENT_CONTEXT:
2880 _this->gl_config.share_with_current_context = value;
2882 case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE:
2883 _this->gl_config.framebuffer_srgb_capable = value;
2885 case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
2886 _this->gl_config.release_behavior = value;
2889 retval = SDL_SetError("Unknown OpenGL attribute");
2894 return SDL_Unsupported();
2895 #endif /* SDL_VIDEO_OPENGL */
2899 SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
2901 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
2902 GLenum (APIENTRY *glGetErrorFunc) (void);
2907 * Some queries in Core Profile desktop OpenGL 3+ contexts require
2908 * glGetFramebufferAttachmentParameteriv instead of glGetIntegerv. Note that
2909 * the enums we use for the former function don't exist in OpenGL ES 2, and
2910 * the function itself doesn't exist prior to OpenGL 3 and OpenGL ES 2.
2912 #if SDL_VIDEO_OPENGL
2913 const GLubyte *(APIENTRY *glGetStringFunc) (GLenum name);
2914 void (APIENTRY *glGetFramebufferAttachmentParameterivFunc) (GLenum target, GLenum attachment, GLenum pname, GLint* params);
2915 GLenum attachment = GL_BACK_LEFT;
2916 GLenum attachmentattrib = 0;
2919 /* Clear value in any case */
2923 case SDL_GL_RED_SIZE:
2924 #if SDL_VIDEO_OPENGL
2925 attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE;
2927 attrib = GL_RED_BITS;
2929 case SDL_GL_BLUE_SIZE:
2930 #if SDL_VIDEO_OPENGL
2931 attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE;
2933 attrib = GL_BLUE_BITS;
2935 case SDL_GL_GREEN_SIZE:
2936 #if SDL_VIDEO_OPENGL
2937 attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE;
2939 attrib = GL_GREEN_BITS;
2941 case SDL_GL_ALPHA_SIZE:
2942 #if SDL_VIDEO_OPENGL
2943 attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE;
2945 attrib = GL_ALPHA_BITS;
2947 case SDL_GL_DOUBLEBUFFER:
2948 #if SDL_VIDEO_OPENGL
2949 attrib = GL_DOUBLEBUFFER;
2952 /* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */
2953 /* parameter which switches double buffer to single buffer. OpenGL ES */
2954 /* SDL driver must set proper value after initialization */
2955 *value = _this->gl_config.double_buffer;
2958 case SDL_GL_DEPTH_SIZE:
2959 #if SDL_VIDEO_OPENGL
2960 attachment = GL_DEPTH;
2961 attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE;
2963 attrib = GL_DEPTH_BITS;
2965 case SDL_GL_STENCIL_SIZE:
2966 #if SDL_VIDEO_OPENGL
2967 attachment = GL_STENCIL;
2968 attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE;
2970 attrib = GL_STENCIL_BITS;
2972 #if SDL_VIDEO_OPENGL
2973 case SDL_GL_ACCUM_RED_SIZE:
2974 attrib = GL_ACCUM_RED_BITS;
2976 case SDL_GL_ACCUM_GREEN_SIZE:
2977 attrib = GL_ACCUM_GREEN_BITS;
2979 case SDL_GL_ACCUM_BLUE_SIZE:
2980 attrib = GL_ACCUM_BLUE_BITS;
2982 case SDL_GL_ACCUM_ALPHA_SIZE:
2983 attrib = GL_ACCUM_ALPHA_BITS;
2989 case SDL_GL_ACCUM_RED_SIZE:
2990 case SDL_GL_ACCUM_GREEN_SIZE:
2991 case SDL_GL_ACCUM_BLUE_SIZE:
2992 case SDL_GL_ACCUM_ALPHA_SIZE:
2994 /* none of these are supported in OpenGL ES */
2998 case SDL_GL_MULTISAMPLEBUFFERS:
2999 attrib = GL_SAMPLE_BUFFERS;
3001 case SDL_GL_MULTISAMPLESAMPLES:
3002 attrib = GL_SAMPLES;
3004 case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
3005 #if SDL_VIDEO_OPENGL
3006 attrib = GL_CONTEXT_RELEASE_BEHAVIOR;
3008 attrib = GL_CONTEXT_RELEASE_BEHAVIOR_KHR;
3011 case SDL_GL_BUFFER_SIZE:
3013 int rsize = 0, gsize = 0, bsize = 0, asize = 0;
3015 /* There doesn't seem to be a single flag in OpenGL for this! */
3016 if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &rsize) < 0) {
3019 if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &gsize) < 0) {
3022 if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &bsize) < 0) {
3025 if (SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &asize) < 0) {
3029 *value = rsize + gsize + bsize + asize;
3032 case SDL_GL_ACCELERATED_VISUAL:
3034 /* FIXME: How do we get this information? */
3035 *value = (_this->gl_config.accelerated != 0);
3038 case SDL_GL_RETAINED_BACKING:
3040 *value = _this->gl_config.retained_backing;
3043 case SDL_GL_CONTEXT_MAJOR_VERSION:
3045 *value = _this->gl_config.major_version;
3048 case SDL_GL_CONTEXT_MINOR_VERSION:
3050 *value = _this->gl_config.minor_version;
3053 case SDL_GL_CONTEXT_EGL:
3054 /* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
3056 if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
3064 case SDL_GL_CONTEXT_FLAGS:
3066 *value = _this->gl_config.flags;
3069 case SDL_GL_CONTEXT_PROFILE_MASK:
3071 *value = _this->gl_config.profile_mask;
3074 case SDL_GL_SHARE_WITH_CURRENT_CONTEXT:
3076 *value = _this->gl_config.share_with_current_context;
3079 case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE:
3081 *value = _this->gl_config.framebuffer_srgb_capable;
3085 return SDL_SetError("Unknown OpenGL attribute");
3088 #if SDL_VIDEO_OPENGL
3089 glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
3090 if (!glGetStringFunc) {
3091 return SDL_SetError("Failed getting OpenGL glGetString entry point");
3094 if (attachmentattrib && isAtLeastGL3((const char *) glGetStringFunc(GL_VERSION))) {
3095 glGetFramebufferAttachmentParameterivFunc = SDL_GL_GetProcAddress("glGetFramebufferAttachmentParameteriv");
3097 if (glGetFramebufferAttachmentParameterivFunc) {
3098 glGetFramebufferAttachmentParameterivFunc(GL_FRAMEBUFFER, attachment, attachmentattrib, (GLint *) value);
3100 return SDL_SetError("Failed getting OpenGL glGetFramebufferAttachmentParameteriv entry point");
3105 void (APIENTRY *glGetIntegervFunc) (GLenum pname, GLint * params);
3106 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
3107 if (glGetIntegervFunc) {
3108 glGetIntegervFunc(attrib, (GLint *) value);
3110 return SDL_SetError("Failed getting OpenGL glGetIntegerv entry point");
3114 glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
3115 if (!glGetErrorFunc) {
3116 return SDL_SetError("Failed getting OpenGL glGetError entry point");
3119 error = glGetErrorFunc();
3120 if (error != GL_NO_ERROR) {
3121 if (error == GL_INVALID_ENUM) {
3122 return SDL_SetError("OpenGL error: GL_INVALID_ENUM");
3123 } else if (error == GL_INVALID_VALUE) {
3124 return SDL_SetError("OpenGL error: GL_INVALID_VALUE");
3126 return SDL_SetError("OpenGL error: %08X", error);
3130 return SDL_Unsupported();
3131 #endif /* SDL_VIDEO_OPENGL */
3135 SDL_GL_CreateContext(SDL_Window * window)
3137 SDL_GLContext ctx = NULL;
3138 CHECK_WINDOW_MAGIC(window, NULL);
3140 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3141 SDL_SetError("The specified window isn't an OpenGL window");
3145 ctx = _this->GL_CreateContext(_this, window);
3147 /* Creating a context is assumed to make it current in the SDL driver. */
3149 _this->current_glwin = window;
3150 _this->current_glctx = ctx;
3151 SDL_TLSSet(_this->current_glwin_tls, window, NULL);
3152 SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
3158 SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
3162 if (window == SDL_GL_GetCurrentWindow() &&
3163 ctx == SDL_GL_GetCurrentContext()) {
3164 /* We're already current. */
3171 CHECK_WINDOW_MAGIC(window, -1);
3173 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3174 return SDL_SetError("The specified window isn't an OpenGL window");
3178 retval = _this->GL_MakeCurrent(_this, window, ctx);
3180 _this->current_glwin = window;
3181 _this->current_glctx = ctx;
3182 SDL_TLSSet(_this->current_glwin_tls, window, NULL);
3183 SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
3189 SDL_GL_GetCurrentWindow(void)
3192 SDL_UninitializedVideo();
3195 return (SDL_Window *)SDL_TLSGet(_this->current_glwin_tls);
3199 SDL_GL_GetCurrentContext(void)
3202 SDL_UninitializedVideo();
3205 return (SDL_GLContext)SDL_TLSGet(_this->current_glctx_tls);
3208 void SDL_GL_GetDrawableSize(SDL_Window * window, int *w, int *h)
3210 CHECK_WINDOW_MAGIC(window,);
3212 if (_this->GL_GetDrawableSize) {
3213 _this->GL_GetDrawableSize(_this, window, w, h);
3215 SDL_GetWindowSize(window, w, h);
3220 SDL_GL_SetSwapInterval(int interval)
3223 return SDL_UninitializedVideo();
3224 } else if (SDL_GL_GetCurrentContext() == NULL) {
3225 return SDL_SetError("No OpenGL context has been made current");
3226 } else if (_this->GL_SetSwapInterval) {
3227 return _this->GL_SetSwapInterval(_this, interval);
3229 return SDL_SetError("Setting the swap interval is not supported");
3234 SDL_GL_GetSwapInterval(void)
3238 } else if (SDL_GL_GetCurrentContext() == NULL) {
3240 } else if (_this->GL_GetSwapInterval) {
3241 return _this->GL_GetSwapInterval(_this);
3248 SDL_GL_SwapWindow(SDL_Window * window)
3250 CHECK_WINDOW_MAGIC(window,);
3252 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3253 SDL_SetError("The specified window isn't an OpenGL window");
3257 if (SDL_GL_GetCurrentWindow() != window) {
3258 SDL_SetError("The specified window has not been made current");
3262 _this->GL_SwapWindow(_this, window);
3266 SDL_GL_DeleteContext(SDL_GLContext context)
3268 if (!_this || !context) {
3272 if (SDL_GL_GetCurrentContext() == context) {
3273 SDL_GL_MakeCurrent(NULL, NULL);
3276 _this->GL_DeleteContext(_this, context);
3281 * Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
3282 * & 2 for alpha channel.
3285 CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags)
3289 #define SET_MASKBIT(icon, x, y, mask) \
3290 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
3292 colorkey = icon->format->colorkey;
3293 switch (icon->format->BytesPerPixel) {
3297 for (y = 0; y < icon->h; ++y) {
3298 pixels = (Uint8 *) icon->pixels + y * icon->pitch;
3299 for (x = 0; x < icon->w; ++x) {
3300 if (*pixels++ == colorkey) {
3301 SET_MASKBIT(icon, x, y, mask);
3311 for (y = 0; y < icon->h; ++y) {
3312 pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2;
3313 for (x = 0; x < icon->w; ++x) {
3314 if ((flags & 1) && *pixels == colorkey) {
3315 SET_MASKBIT(icon, x, y, mask);
3316 } else if ((flags & 2)
3317 && (*pixels & icon->format->Amask) == 0) {
3318 SET_MASKBIT(icon, x, y, mask);
3329 for (y = 0; y < icon->h; ++y) {
3330 pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4;
3331 for (x = 0; x < icon->w; ++x) {
3332 if ((flags & 1) && *pixels == colorkey) {
3333 SET_MASKBIT(icon, x, y, mask);
3334 } else if ((flags & 2)
3335 && (*pixels & icon->format->Amask) == 0) {
3336 SET_MASKBIT(icon, x, y, mask);
3347 * Sets the window manager icon for the display window.
3350 SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
3352 if (icon && _this->SetIcon) {
3353 /* Generate a mask if necessary, and create the icon! */
3355 int mask_len = icon->h * (icon->w + 7) / 8;
3357 mask = (Uint8 *) SDL_malloc(mask_len);
3361 SDL_memset(mask, ~0, mask_len);
3362 if (icon->flags & SDL_SRCCOLORKEY)
3364 if (icon->flags & SDL_SRCALPHA)
3367 CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
3369 _this->SetIcon(_this, icon, mask);
3372 _this->SetIcon(_this, icon, mask);
3379 SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info)
3381 CHECK_WINDOW_MAGIC(window, SDL_FALSE);
3384 SDL_InvalidParamError("info");
3387 info->subsystem = SDL_SYSWM_UNKNOWN;
3389 if (!_this->GetWindowWMInfo) {
3393 return (_this->GetWindowWMInfo(_this, window, info));
3397 SDL_StartTextInput(void)
3401 /* First, enable text events */
3402 SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
3403 SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
3405 /* Then show the on-screen keyboard, if any */
3406 window = SDL_GetFocusWindow();
3407 if (window && _this && _this->ShowScreenKeyboard) {
3408 _this->ShowScreenKeyboard(_this, window);
3411 /* Finally start the text input system */
3412 if (_this && _this->StartTextInput) {
3413 _this->StartTextInput(_this);
3418 SDL_IsTextInputActive(void)
3420 return (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE);
3424 SDL_StopTextInput(void)
3428 /* Stop the text input system */
3429 if (_this && _this->StopTextInput) {
3430 _this->StopTextInput(_this);
3433 /* Hide the on-screen keyboard, if any */
3434 window = SDL_GetFocusWindow();
3435 if (window && _this && _this->HideScreenKeyboard) {
3436 _this->HideScreenKeyboard(_this, window);
3439 /* Finally disable text events */
3440 SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
3441 SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
3445 SDL_SetTextInputRect(SDL_Rect *rect)
3447 if (_this && _this->SetTextInputRect) {
3448 _this->SetTextInputRect(_this, rect);
3453 SDL_HasScreenKeyboardSupport(void)
3455 if (_this && _this->HasScreenKeyboardSupport) {
3456 return _this->HasScreenKeyboardSupport(_this);
3462 SDL_IsScreenKeyboardShown(SDL_Window *window)
3464 if (window && _this && _this->IsScreenKeyboardShown) {
3465 return _this->IsScreenKeyboardShown(_this, window);
3470 #if SDL_VIDEO_DRIVER_ANDROID
3471 #include "android/SDL_androidmessagebox.h"
3473 #if SDL_VIDEO_DRIVER_WINDOWS
3474 #include "windows/SDL_windowsmessagebox.h"
3476 #if SDL_VIDEO_DRIVER_WINRT
3477 #include "winrt/SDL_winrtmessagebox.h"
3479 #if SDL_VIDEO_DRIVER_COCOA
3480 #include "cocoa/SDL_cocoamessagebox.h"
3482 #if SDL_VIDEO_DRIVER_UIKIT
3483 #include "uikit/SDL_uikitmessagebox.h"
3485 #if SDL_VIDEO_DRIVER_X11
3486 #include "x11/SDL_x11messagebox.h"
3489 // This function will be unused if none of the above video drivers are present.
3490 SDL_UNUSED static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
3493 SDL_Window *window = messageboxdata->window;
3499 SDL_VERSION(&info.version);
3500 if (!SDL_GetWindowWMInfo(window, &info)) {
3503 return (info.subsystem == drivertype);
3508 SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
3512 SDL_bool relative_mode;
3513 int show_cursor_prev;
3514 SDL_bool mouse_captured;
3515 SDL_Window *current_window;
3517 if (!messageboxdata) {
3518 return SDL_InvalidParamError("messageboxdata");
3521 current_window = SDL_GetKeyboardFocus();
3522 mouse_captured = current_window && ((SDL_GetWindowFlags(current_window) & SDL_WINDOW_MOUSE_CAPTURE) != 0);
3523 relative_mode = SDL_GetRelativeMouseMode();
3524 SDL_CaptureMouse(SDL_FALSE);
3525 SDL_SetRelativeMouseMode(SDL_FALSE);
3526 show_cursor_prev = SDL_ShowCursor(1);
3527 SDL_ResetKeyboard();
3530 buttonid = &dummybutton;
3533 if (_this && _this->ShowMessageBox) {
3534 retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
3537 /* It's completely fine to call this function before video is initialized */
3538 #if SDL_VIDEO_DRIVER_ANDROID
3540 Android_ShowMessageBox(messageboxdata, buttonid) == 0) {
3544 #if SDL_VIDEO_DRIVER_WINDOWS
3546 SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
3547 WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
3551 #if SDL_VIDEO_DRIVER_WINRT
3553 SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINRT) &&
3554 WINRT_ShowMessageBox(messageboxdata, buttonid) == 0) {
3558 #if SDL_VIDEO_DRIVER_COCOA
3560 SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
3561 Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
3565 #if SDL_VIDEO_DRIVER_UIKIT
3567 SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
3568 UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
3572 #if SDL_VIDEO_DRIVER_X11
3574 SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
3575 X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
3580 SDL_SetError("No message system available");
3583 if (current_window) {
3584 SDL_RaiseWindow(current_window);
3585 if (mouse_captured) {
3586 SDL_CaptureMouse(SDL_TRUE);
3590 SDL_ShowCursor(show_cursor_prev);
3591 SDL_SetRelativeMouseMode(relative_mode);
3597 SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window)
3599 SDL_MessageBoxData data;
3600 SDL_MessageBoxButtonData button;
3605 data.message = message;
3606 data.numbuttons = 1;
3607 data.buttons = &button;
3608 data.window = window;
3611 button.flags |= SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
3612 button.flags |= SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
3615 return SDL_ShowMessageBox(&data, NULL);
3619 SDL_ShouldAllowTopmost(void)
3621 const char *hint = SDL_GetHint(SDL_HINT_ALLOW_TOPMOST);
3633 SDL_SetWindowHitTest(SDL_Window * window, SDL_HitTest callback, void *userdata)
3635 CHECK_WINDOW_MAGIC(window, -1);
3637 if (!_this->SetWindowHitTest) {
3638 return SDL_Unsupported();
3639 } else if (_this->SetWindowHitTest(window, callback != NULL) == -1) {
3643 window->hit_test = callback;
3644 window->hit_test_data = userdata;
3649 float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
3651 float den2 = hinches * hinches + vinches * vinches;
3652 if ( den2 <= 0.0f ) {
3656 return (float)(SDL_sqrt((double)hpix * (double)hpix + (double)vpix * (double)vpix) /
3657 SDL_sqrt((double)den2));
3660 /* vi: set ts=4 sw=4 expandtab: */