2001-04-26 16:45:43 +00:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2018-01-03 10:03:25 -08:00
|
|
|
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2013-11-24 23:56:17 -05:00
|
|
|
#include "../SDL_internal.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* The high-level video driver subsystem */
|
|
|
|
|
2009-01-04 23:48:23 +00:00
|
|
|
#include "SDL.h"
|
2009-01-04 05:41:52 +00:00
|
|
|
#include "SDL_video.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
#include "SDL_sysvideo.h"
|
|
|
|
#include "SDL_blit.h"
|
|
|
|
#include "SDL_pixels_c.h"
|
2011-02-13 23:09:18 -08:00
|
|
|
#include "SDL_rect_c.h"
|
2006-02-16 10:11:48 +00:00
|
|
|
#include "../events/SDL_events_c.h"
|
2013-05-02 21:40:59 -04:00
|
|
|
#include "../timer/SDL_timer_c.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2014-03-13 21:21:26 -07:00
|
|
|
#include "SDL_syswm.h"
|
|
|
|
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
#include "SDL_opengl.h"
|
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
|
|
|
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_OPENGL_ES
|
|
|
|
#include "SDL_opengles.h"
|
2008-09-15 04:32:36 +00:00
|
|
|
#endif /* SDL_VIDEO_OPENGL_ES */
|
2008-09-02 20:19:45 +00:00
|
|
|
|
2013-08-25 11:48:49 -03:00
|
|
|
/* GL and GLES2 headers conflict on Linux 32 bits */
|
|
|
|
#if SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
|
2011-02-06 10:22:25 -08:00
|
|
|
#include "SDL_opengles2.h"
|
2013-08-25 11:48:49 -03:00
|
|
|
#endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */
|
2010-09-27 01:24:05 -07:00
|
|
|
|
2016-11-13 22:57:41 -08:00
|
|
|
#if !SDL_VIDEO_OPENGL
|
2015-03-21 00:09:22 -04:00
|
|
|
#ifndef GL_CONTEXT_RELEASE_BEHAVIOR_KHR
|
|
|
|
#define GL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x82FB
|
|
|
|
#endif
|
2016-11-13 22:57:41 -08:00
|
|
|
#endif
|
2015-03-21 00:09:22 -04:00
|
|
|
|
2016-09-06 13:13:03 -04:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
#include <emscripten.h>
|
|
|
|
#endif
|
|
|
|
|
2001-04-26 16:45:43 +00:00
|
|
|
/* Available video drivers */
|
2009-06-05 07:35:06 +00:00
|
|
|
static VideoBootStrap *bootstrap[] = {
|
2006-07-23 09:11:10 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_COCOA
|
2008-09-15 04:32:36 +00:00
|
|
|
&COCOA_bootstrap,
|
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
To: SDL Developers <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Mon, 30 May 2005 23:29:04 +0200
Subject: [SDL] Mac OS X Video Drivers [patch]
I've updated/added the Carbon and X11 video drivers
to the Mac OS X port of SDL 1.2 (the CVS version),
and made the Cocoa driver and runtime *optional*.
The default is still Cocoa, and the "Quartz" driver.
But you can now also use "toolbox" for Carbon, and
"x11" for running with Apple's (or other) X11 server:
export SDL_VIDEODRIVER=x11
export SDL_VIDEO_GL_DRIVER=/usr/X11R6/lib/libGL.dylib
It also checks if the frameworks are available, by a:
#include <Carbon/Carbon.h> or #import <Cocoa/Cocoa.h>
(this should make it configure on plain Darwin as well?)
Here are the new configure targets:
--enable-video-cocoa use Cocoa/Quartz video driver default=yes
--enable-video-carbon use Carbon/QuickDraw video driver default=yes
--enable-video-x11 use X11 video driver default=no
./configure --enable-video-cocoa --enable-video-carbon
--enable-video-x11 \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
The Carbon version is just an updated version of the old
SDL driver for Mac OS 9, and could probably be improved...
(but it does work, including the Carbon version of SDLmain)
If you disable cocoa, you can run with -framework Carbon only,
and the C version of SDL_main.c. And if you disable carbon too,
you can still use the X11 version which doesn't require SDLmain.
I updated the DrawSprocket version, but did not include it.
(no blitters or VRAM GWorlds etc. available on OS X anyway)
Besides for Mac OS 9, I don't think there's any use for it ?
And note that any performance on Mac OS X equals OpenGL anyway...
You can get "fair" software SDL results on captured CG displays,
but for decent frame rates you need to be using GL for rendering.
Finally, here is the patch itself:
http://www.algonet.se/~afb/SDL-12CVS-macvideo.patch
--anders
PS. It says "video", but as usual it applies to mouse/keyboard too.
------
To: A list for developers using the SDL library <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Sun, 4 Sep 2005 10:02:15 +0200
Subject: [SDL] Updated Mac patch
Updated the previous Mac patch to disable Carbon by default.
Also "fixed" the SDL.spec again, so that it builds on Darwin.
http://www.algonet.se/~afb/SDL-1.2.9-mac.patch
Also applied fine to SDL12 CVS, when I tried it.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401136
2005-09-08 06:16:14 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_X11
|
2008-09-15 04:32:36 +00:00
|
|
|
&X11_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2014-02-02 23:41:46 -05:00
|
|
|
#if SDL_VIDEO_DRIVER_MIR
|
|
|
|
&MIR_bootstrap,
|
|
|
|
#endif
|
2014-10-15 09:18:17 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_WAYLAND
|
|
|
|
&Wayland_bootstrap,
|
|
|
|
#endif
|
|
|
|
#if SDL_VIDEO_DRIVER_VIVANTE
|
|
|
|
&VIVANTE_bootstrap,
|
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_DIRECTFB
|
2008-09-15 04:32:36 +00:00
|
|
|
&DirectFB_bootstrap,
|
2001-09-04 22:53:46 +00:00
|
|
|
#endif
|
2011-01-20 18:04:05 -08:00
|
|
|
#if SDL_VIDEO_DRIVER_WINDOWS
|
|
|
|
&WINDOWS_bootstrap,
|
2006-01-01 23:34:06 +00:00
|
|
|
#endif
|
2014-03-09 11:06:11 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_WINRT
|
|
|
|
&WINRT_bootstrap,
|
|
|
|
#endif
|
2013-11-14 11:51:24 -05:00
|
|
|
#if SDL_VIDEO_DRIVER_HAIKU
|
|
|
|
&HAIKU_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2011-02-01 21:40:03 -08:00
|
|
|
#if SDL_VIDEO_DRIVER_PANDORA
|
|
|
|
&PND_bootstrap,
|
2001-09-11 20:38:49 +00:00
|
|
|
#endif
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_UIKIT
|
2008-09-15 04:32:36 +00:00
|
|
|
&UIKIT_bootstrap,
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2010-06-10 18:54:23 +12:00
|
|
|
#if SDL_VIDEO_DRIVER_ANDROID
|
|
|
|
&Android_bootstrap,
|
2011-02-01 21:40:03 -08:00
|
|
|
#endif
|
2013-03-17 20:07:02 +08:00
|
|
|
#if SDL_VIDEO_DRIVER_PSP
|
|
|
|
&PSP_bootstrap,
|
|
|
|
#endif
|
2016-01-03 21:27:57 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_MALI
|
|
|
|
&MALI_bootstrap,
|
|
|
|
#endif
|
2017-08-02 10:22:48 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_KMSDRM
|
|
|
|
&KMSDRM_bootstrap,
|
|
|
|
#endif
|
2017-11-04 09:03:20 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_RPI
|
|
|
|
&RPI_bootstrap,
|
|
|
|
#endif
|
2014-06-06 15:45:59 -03:00
|
|
|
#if SDL_VIDEO_DRIVER_NACL
|
|
|
|
&NACL_bootstrap,
|
|
|
|
#endif
|
Initial merge of Emscripten port!
With this commit, you can compile SDL2 with Emscripten
( http://emscripten.org/ ), and make your SDL-based C/C++ program
into a web app.
This port was due to the efforts of several people, including: Charlie Birks,
Sathyanarayanan Gunasekaran, Jukka Jylänki, Alon Zakai, Edward Rudd,
Bruce Mitchener, and Martin Gerhardy. (Thanks, everyone!)
--HG--
extra : rebase_source : 97af74c8a5121e926ebe89f123536b5dd6681695
2014-12-18 00:19:52 -05:00
|
|
|
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
|
|
|
|
&Emscripten_bootstrap,
|
|
|
|
#endif
|
2017-07-01 17:50:47 -04:00
|
|
|
#if SDL_VIDEO_DRIVER_QNX
|
|
|
|
&QNX_bootstrap,
|
|
|
|
#endif
|
2014-01-20 20:25:43 -03:00
|
|
|
#if SDL_VIDEO_DRIVER_DUMMY
|
|
|
|
&DUMMY_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
NULL
|
2001-04-26 16:45:43 +00:00
|
|
|
};
|
2001-09-11 20:38:49 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static SDL_VideoDevice *_this = NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2010-01-24 20:21:51 +00:00
|
|
|
#define CHECK_WINDOW_MAGIC(window, retval) \
|
|
|
|
if (!_this) { \
|
|
|
|
SDL_UninitializedVideo(); \
|
|
|
|
return retval; \
|
|
|
|
} \
|
2017-08-14 16:34:54 -07:00
|
|
|
SDL_assert(window && window->magic == &_this->window_magic); \
|
2010-02-01 01:19:37 +00:00
|
|
|
if (!window || window->magic != &_this->window_magic) { \
|
2010-01-24 20:21:51 +00:00
|
|
|
SDL_SetError("Invalid window"); \
|
|
|
|
return retval; \
|
|
|
|
}
|
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
#define CHECK_DISPLAY_INDEX(displayIndex, retval) \
|
|
|
|
if (!_this) { \
|
|
|
|
SDL_UninitializedVideo(); \
|
|
|
|
return retval; \
|
|
|
|
} \
|
2014-03-20 11:14:02 -04:00
|
|
|
SDL_assert(_this->displays != NULL); \
|
2017-08-14 16:34:54 -07:00
|
|
|
SDL_assert(displayIndex >= 0 && displayIndex < _this->num_displays); \
|
2011-02-10 12:14:37 -08:00
|
|
|
if (displayIndex < 0 || displayIndex >= _this->num_displays) { \
|
|
|
|
SDL_SetError("displayIndex must be in the range 0 - %d", \
|
|
|
|
_this->num_displays - 1); \
|
|
|
|
return retval; \
|
|
|
|
}
|
|
|
|
|
2014-06-04 10:56:37 -07:00
|
|
|
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
|
2013-11-12 01:52:54 -08:00
|
|
|
|
|
|
|
#ifdef __MACOSX__
|
|
|
|
/* Support for Mac OS X fullscreen spaces */
|
2013-11-12 02:02:12 -08:00
|
|
|
extern SDL_bool Cocoa_IsWindowInFullscreenSpace(SDL_Window * window);
|
2013-11-12 01:52:54 -08:00
|
|
|
extern SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
/* Support for framebuffer emulation using an accelerated renderer */
|
|
|
|
|
|
|
|
#define SDL_WINDOWTEXTUREDATA "_SDL_WindowTextureData"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
SDL_Texture *texture;
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
2011-02-04 12:24:28 -08:00
|
|
|
int bytes_per_pixel;
|
2011-02-03 15:49:37 -08:00
|
|
|
} SDL_WindowTextureData;
|
|
|
|
|
2011-02-05 10:03:12 -08:00
|
|
|
static SDL_bool
|
|
|
|
ShouldUseTextureFramebuffer()
|
|
|
|
{
|
|
|
|
const char *hint;
|
|
|
|
|
|
|
|
/* If there's no native framebuffer support then there's no option */
|
|
|
|
if (!_this->CreateWindowFramebuffer) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2016-12-11 12:01:01 -08:00
|
|
|
/* If this is the dummy driver there is no texture support */
|
|
|
|
if (_this->is_dummy) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-05 10:35:36 -08:00
|
|
|
/* If the user has specified a software renderer we can't use a
|
|
|
|
texture framebuffer, or renderer creation will go recursive.
|
|
|
|
*/
|
|
|
|
hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
|
|
|
|
if (hint && SDL_strcasecmp(hint, "software") == 0) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-05 10:03:12 -08:00
|
|
|
/* See if the user or application wants a specific behavior */
|
|
|
|
hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
|
|
|
|
if (hint) {
|
2016-10-07 23:40:44 -07:00
|
|
|
if (*hint == '0' || SDL_strcasecmp(hint, "false") == 0) {
|
2011-02-05 10:03:12 -08:00
|
|
|
return SDL_FALSE;
|
|
|
|
} else {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Each platform has different performance characteristics */
|
|
|
|
#if defined(__WIN32__)
|
|
|
|
/* GDI BitBlt() is way faster than Direct3D dynamic textures right now.
|
|
|
|
*/
|
|
|
|
return SDL_FALSE;
|
|
|
|
|
|
|
|
#elif defined(__MACOSX__)
|
2017-01-07 19:55:29 -05:00
|
|
|
/* Mac OS X uses OpenGL as the native fast path (for cocoa and X11) */
|
2011-02-05 10:03:12 -08:00
|
|
|
return SDL_TRUE;
|
|
|
|
|
|
|
|
#elif defined(__LINUX__)
|
|
|
|
/* Properly configured OpenGL drivers are faster than MIT-SHM */
|
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
/* Ugh, find a way to cache this value! */
|
|
|
|
{
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_GLContext context;
|
|
|
|
SDL_bool hasAcceleratedOpenGL = SDL_FALSE;
|
|
|
|
|
2011-02-21 22:52:07 -08:00
|
|
|
window = SDL_CreateWindow("OpenGL test", -32, -32, 32, 32, SDL_WINDOW_OPENGL|SDL_WINDOW_HIDDEN);
|
2011-02-05 10:03:12 -08:00
|
|
|
if (window) {
|
|
|
|
context = SDL_GL_CreateContext(window);
|
|
|
|
if (context) {
|
|
|
|
const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
|
|
|
|
const char *vendor = NULL;
|
|
|
|
|
2018-02-12 17:00:00 +03:00
|
|
|
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
2011-02-05 10:03:12 -08:00
|
|
|
if (glGetStringFunc) {
|
|
|
|
vendor = (const char *) glGetStringFunc(GL_VENDOR);
|
|
|
|
}
|
2017-03-01 15:05:54 -08:00
|
|
|
/* Add more vendors here at will... */
|
2011-02-05 10:03:12 -08:00
|
|
|
if (vendor &&
|
|
|
|
(SDL_strstr(vendor, "ATI Technologies") ||
|
|
|
|
SDL_strstr(vendor, "NVIDIA"))) {
|
|
|
|
hasAcceleratedOpenGL = SDL_TRUE;
|
|
|
|
}
|
|
|
|
SDL_GL_DeleteContext(context);
|
|
|
|
}
|
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
}
|
2017-03-01 15:05:54 -08:00
|
|
|
return hasAcceleratedOpenGL;
|
2011-02-05 10:03:12 -08:00
|
|
|
}
|
Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Scott Percival 2011-07-03 06:41:51 PDT
This submission is aimed at making life easier for OpenGL ES capable devices
running a X11 stack (e.g. Maemo, Meego, TrimSlice, other ARM SoC boards not
running Android). SDL's Pandora support already has the neccesary GLES-to-X11
glue code, however it's all ghetto'd off in Makefile.pandora and not very
flexible.
The patch:
- adds an awesome --enable-video-opengles option to configure
- re-modifies the opengles and opengles2 SDL_renderers to use function pointers
- no idea why this was removed?
- for SDL_Renderers, links in libGLESv1_CM, libGLES_CM (for PowerVR fans) or
libGLESv2 at runtime
- links in libEGL.so at runtime - the old code made an assumption that
eglFunctions could be pulled from the active GLES library, PowerVR for one
doesn't let you do that with their libGLESv2
- allows you to pick which of GLES v1 or v2 to load via
SDL_GL_CONTEXT_MAJOR_VERSION
So far I've tested this on a Nokia N900 (OMAP 3430/SGX 530 running Maemo 5) and
a Toshiba AC100 (Tegra 2 running Ubuntu 10.10). I haven't tested it on... well,
everything that isn't those two, such as a Pandora, iOS or Android device. The
Pandora specific code should be kept intact (fingers crossed), and nothing
painfully drastic has been added to the SDL_renderers. The library loading
sequence in SDL_x11opengles has been updated to accomodate both NVIDIA's
propensity to let developers get away with murder and PowerVR's alternative of
punishing every missed step.
The test apps work okay with GLES or GLES2 as the renderer. For some reason
alpha blending doesn't seem to work on the Tegra 2; last week NVIDIA pushed out
a new set of X11 GLES drivers, so I'll try and investigate once I upgrade
those. Also, this patch adds things to configure.in, include/SDL_config.h.in
and test/configure.in. I didn't know what the policy was re. committing
generated spaghetti from autotools, so ./autogen.sh has to be run again. Sorry.
I think that's about everything, let me know if there's anything I've
overlooked.
2012-01-08 02:23:37 -05:00
|
|
|
#elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
|
|
|
/* Let's be optimistic about this! */
|
|
|
|
return SDL_TRUE;
|
2011-02-05 10:03:12 -08:00
|
|
|
#else
|
|
|
|
return SDL_FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* Play it safe, assume that if there is a framebuffer driver that it's
|
|
|
|
optimized for the current platform.
|
|
|
|
*/
|
|
|
|
return SDL_FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
static int
|
2014-06-25 00:43:10 -07:00
|
|
|
SDL_CreateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
|
2011-02-03 15:49:37 -08:00
|
|
|
{
|
|
|
|
SDL_WindowTextureData *data;
|
|
|
|
|
|
|
|
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
|
|
|
|
if (!data) {
|
2011-02-13 14:05:33 -08:00
|
|
|
SDL_Renderer *renderer = NULL;
|
2011-02-03 17:42:58 -08:00
|
|
|
int i;
|
2011-02-05 10:11:27 -08:00
|
|
|
const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
|
|
|
|
|
|
|
|
/* Check to see if there's a specific driver requested */
|
|
|
|
if (hint && *hint != '0' && *hint != '1' &&
|
2016-10-07 23:40:44 -07:00
|
|
|
SDL_strcasecmp(hint, "true") != 0 &&
|
|
|
|
SDL_strcasecmp(hint, "false") != 0 &&
|
2011-02-05 10:11:27 -08:00
|
|
|
SDL_strcasecmp(hint, "software") != 0) {
|
|
|
|
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
|
2014-06-25 00:43:10 -07:00
|
|
|
SDL_RendererInfo info;
|
2011-02-05 10:11:27 -08:00
|
|
|
SDL_GetRenderDriverInfo(i, &info);
|
|
|
|
if (SDL_strcasecmp(info.name, hint) == 0) {
|
|
|
|
renderer = SDL_CreateRenderer(window, i, 0);
|
2011-02-03 17:42:58 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-06 15:45:59 -03:00
|
|
|
|
2011-02-05 10:11:27 -08:00
|
|
|
if (!renderer) {
|
|
|
|
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
|
2014-06-25 00:43:10 -07:00
|
|
|
SDL_RendererInfo info;
|
2011-02-05 10:11:27 -08:00
|
|
|
SDL_GetRenderDriverInfo(i, &info);
|
|
|
|
if (SDL_strcmp(info.name, "software") != 0) {
|
|
|
|
renderer = SDL_CreateRenderer(window, i, 0);
|
|
|
|
if (renderer) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
if (!renderer) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("No hardware accelerated renderers available");
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
2011-02-12 17:51:47 -08:00
|
|
|
|
|
|
|
/* Create the data after we successfully create the renderer (bug #1116) */
|
|
|
|
data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
|
|
|
|
if (!data) {
|
|
|
|
SDL_DestroyRenderer(renderer);
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_OutOfMemory();
|
2011-02-12 17:51:47 -08:00
|
|
|
}
|
|
|
|
SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
data->renderer = renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free any old texture and pixel data */
|
|
|
|
if (data->texture) {
|
|
|
|
SDL_DestroyTexture(data->texture);
|
|
|
|
data->texture = NULL;
|
|
|
|
}
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(data->pixels);
|
|
|
|
data->pixels = NULL;
|
2011-02-03 15:49:37 -08:00
|
|
|
|
2014-06-25 00:43:10 -07:00
|
|
|
{
|
|
|
|
SDL_RendererInfo info;
|
|
|
|
Uint32 i;
|
2011-02-03 15:49:37 -08:00
|
|
|
|
2014-06-25 00:43:10 -07:00
|
|
|
if (SDL_GetRendererInfo(data->renderer, &info) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the first format without an alpha channel */
|
|
|
|
*format = info.texture_formats[0];
|
|
|
|
|
|
|
|
for (i = 0; i < info.num_texture_formats; ++i) {
|
|
|
|
if (!SDL_ISPIXELFORMAT_FOURCC(info.texture_formats[i]) &&
|
|
|
|
!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
|
|
|
|
*format = info.texture_formats[i];
|
|
|
|
break;
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-13 14:05:33 -08:00
|
|
|
data->texture = SDL_CreateTexture(data->renderer, *format,
|
2011-02-03 15:49:37 -08:00
|
|
|
SDL_TEXTUREACCESS_STREAMING,
|
|
|
|
window->w, window->h);
|
|
|
|
if (!data->texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create framebuffer data */
|
2011-02-04 12:24:28 -08:00
|
|
|
data->bytes_per_pixel = SDL_BYTESPERPIXEL(*format);
|
|
|
|
data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3);
|
2016-11-24 21:41:09 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
/* Make static analysis happy about potential malloc(0) calls. */
|
|
|
|
const size_t allocsize = window->h * data->pitch;
|
|
|
|
data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1);
|
|
|
|
if (!data->pixels) {
|
|
|
|
return SDL_OutOfMemory();
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
*pixels = data->pixels;
|
|
|
|
*pitch = data->pitch;
|
2011-02-15 13:59:59 -08:00
|
|
|
|
|
|
|
/* Make sure we're not double-scaling the viewport */
|
|
|
|
SDL_RenderSetViewport(data->renderer, NULL);
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-06-25 00:43:10 -07:00
|
|
|
SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, const SDL_Rect * rects, int numrects)
|
2011-02-03 15:49:37 -08:00
|
|
|
{
|
|
|
|
SDL_WindowTextureData *data;
|
2011-02-13 23:09:18 -08:00
|
|
|
SDL_Rect rect;
|
|
|
|
void *src;
|
2011-02-03 15:49:37 -08:00
|
|
|
|
|
|
|
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
|
|
|
|
if (!data || !data->texture) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("No window texture data");
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
2011-02-13 23:09:18 -08:00
|
|
|
/* Update a single rect that contains subrects for best DMA performance */
|
|
|
|
if (SDL_GetSpanEnclosingRect(window->w, window->h, numrects, rects, &rect)) {
|
2011-02-04 12:24:28 -08:00
|
|
|
src = (void *)((Uint8 *)data->pixels +
|
2011-02-13 23:09:18 -08:00
|
|
|
rect.y * data->pitch +
|
|
|
|
rect.x * data->bytes_per_pixel);
|
|
|
|
if (SDL_UpdateTexture(data->texture, &rect, src, data->pitch) < 0) {
|
2011-02-04 12:24:28 -08:00
|
|
|
return -1;
|
|
|
|
}
|
2011-02-13 23:09:18 -08:00
|
|
|
|
|
|
|
if (SDL_RenderCopy(data->renderer, data->texture, NULL, NULL) < 0) {
|
|
|
|
return -1;
|
2011-02-04 12:24:28 -08:00
|
|
|
}
|
|
|
|
|
2011-02-13 23:09:18 -08:00
|
|
|
SDL_RenderPresent(data->renderer);
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 00:43:10 -07:00
|
|
|
SDL_DestroyWindowTexture(SDL_VideoDevice *unused, SDL_Window * window)
|
2011-02-03 15:49:37 -08:00
|
|
|
{
|
|
|
|
SDL_WindowTextureData *data;
|
|
|
|
|
|
|
|
data = SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, NULL);
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data->texture) {
|
|
|
|
SDL_DestroyTexture(data->texture);
|
|
|
|
}
|
|
|
|
if (data->renderer) {
|
|
|
|
SDL_DestroyRenderer(data->renderer);
|
|
|
|
}
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(data->pixels);
|
2011-02-03 15:49:37 -08:00
|
|
|
SDL_free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static int
|
|
|
|
cmpmodes(const void *A, const void *B)
|
|
|
|
{
|
2013-07-13 21:50:40 -04:00
|
|
|
const SDL_DisplayMode *a = (const SDL_DisplayMode *) A;
|
|
|
|
const SDL_DisplayMode *b = (const SDL_DisplayMode *) B;
|
|
|
|
if (a == b) {
|
|
|
|
return 0;
|
|
|
|
} else if (a->w != b->w) {
|
|
|
|
return b->w - a->w;
|
|
|
|
} else if (a->h != b->h) {
|
|
|
|
return b->h - a->h;
|
|
|
|
} else if (SDL_BITSPERPIXEL(a->format) != SDL_BITSPERPIXEL(b->format)) {
|
|
|
|
return SDL_BITSPERPIXEL(b->format) - SDL_BITSPERPIXEL(a->format);
|
|
|
|
} else if (SDL_PIXELLAYOUT(a->format) != SDL_PIXELLAYOUT(b->format)) {
|
|
|
|
return SDL_PIXELLAYOUT(b->format) - SDL_PIXELLAYOUT(a->format);
|
|
|
|
} else if (a->refresh_rate != b->refresh_rate) {
|
|
|
|
return b->refresh_rate - a->refresh_rate;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2013-03-31 12:48:50 -04:00
|
|
|
static int
|
2006-07-16 09:34:01 +00:00
|
|
|
SDL_UninitializedVideo()
|
|
|
|
{
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("Video subsystem has not been initialized");
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetNumVideoDrivers(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_arraysize(bootstrap) - 1;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetVideoDriver(int index)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
|
|
|
|
return bootstrap[index]->name;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the video and event subsystems -- determine native pixel format
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
2011-01-27 22:44:08 -08:00
|
|
|
SDL_VideoInit(const char *driver_name)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDevice *video;
|
|
|
|
int index;
|
|
|
|
int i;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2010-01-24 19:47:17 +00:00
|
|
|
/* Check to make sure we don't overwrite '_this' */
|
|
|
|
if (_this != NULL) {
|
|
|
|
SDL_VideoQuit();
|
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2013-05-02 21:40:59 -04:00
|
|
|
#if !SDL_TIMERS_DISABLED
|
2014-03-01 09:50:52 -08:00
|
|
|
SDL_TicksInit();
|
2013-05-02 21:40:59 -04:00
|
|
|
#endif
|
2010-01-24 19:47:17 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Start the event loop */
|
2013-07-06 12:28:57 -07:00
|
|
|
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0 ||
|
2011-01-27 22:44:08 -08:00
|
|
|
SDL_KeyboardInit() < 0 ||
|
|
|
|
SDL_MouseInit() < 0 ||
|
2013-07-06 12:28:57 -07:00
|
|
|
SDL_TouchInit() < 0) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-01-24 19:47:17 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Select the proper video driver */
|
|
|
|
index = 0;
|
|
|
|
video = NULL;
|
|
|
|
if (driver_name == NULL) {
|
|
|
|
driver_name = SDL_getenv("SDL_VIDEODRIVER");
|
|
|
|
}
|
|
|
|
if (driver_name != NULL) {
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
2013-02-18 20:14:24 -08:00
|
|
|
if (SDL_strncasecmp(bootstrap[i]->name, driver_name, SDL_strlen(driver_name)) == 0) {
|
2014-01-20 20:25:43 -03:00
|
|
|
if (bootstrap[i]->available()) {
|
|
|
|
video = bootstrap[i]->create(index);
|
|
|
|
break;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
|
|
|
if (bootstrap[i]->available()) {
|
|
|
|
video = bootstrap[i]->create(index);
|
|
|
|
if (video != NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (video == NULL) {
|
|
|
|
if (driver_name) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("%s not available", driver_name);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("No available video device");
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
_this = video;
|
|
|
|
_this->name = bootstrap[i]->name;
|
|
|
|
_this->next_object_id = 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Set some very sane GL defaults */
|
|
|
|
_this->gl_config.driver_loaded = 0;
|
|
|
|
_this->gl_config.dll_handle = NULL;
|
2014-01-29 18:38:13 -08:00
|
|
|
SDL_GL_ResetAttributes();
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2013-07-11 22:59:20 -07:00
|
|
|
_this->current_glwin_tls = SDL_TLSCreate();
|
|
|
|
_this->current_glctx_tls = SDL_TLSCreate();
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Initialize the video subsystem */
|
|
|
|
if (_this->VideoInit(_this) < 0) {
|
|
|
|
SDL_VideoQuit();
|
|
|
|
return -1;
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Make sure some displays were added */
|
|
|
|
if (_this->num_displays == 0) {
|
|
|
|
SDL_VideoQuit();
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("The video driver did not add any displays");
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-05 10:03:12 -08:00
|
|
|
/* Add the renderer framebuffer emulation if desired */
|
|
|
|
if (ShouldUseTextureFramebuffer()) {
|
2011-02-03 15:49:37 -08:00
|
|
|
_this->CreateWindowFramebuffer = SDL_CreateWindowTexture;
|
|
|
|
_this->UpdateWindowFramebuffer = SDL_UpdateWindowTexture;
|
|
|
|
_this->DestroyWindowFramebuffer = SDL_DestroyWindowTexture;
|
|
|
|
}
|
|
|
|
|
2014-02-27 22:06:41 -05:00
|
|
|
/* Disable the screen saver by default. This is a change from <= 2.0.1,
|
|
|
|
but most things using SDL are games or media players; you wouldn't
|
|
|
|
want a screensaver to trigger if you're playing exclusively with a
|
|
|
|
joystick, or passively watching a movie. Things that use SDL but
|
|
|
|
function more like a normal desktop app should explicitly reenable the
|
|
|
|
screensaver. */
|
2016-10-07 23:40:44 -07:00
|
|
|
if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, SDL_FALSE)) {
|
2014-02-28 14:23:41 -08:00
|
|
|
SDL_DisableScreenSaver();
|
|
|
|
}
|
2014-02-27 22:06:41 -05:00
|
|
|
|
2012-11-09 02:18:27 -08:00
|
|
|
/* If we don't use a screen keyboard, turn on text input by default,
|
|
|
|
otherwise programs that expect to get text events without enabling
|
|
|
|
UNICODE input won't get any events.
|
|
|
|
|
|
|
|
Actually, come to think of it, you needed to call SDL_EnableUNICODE(1)
|
|
|
|
in SDL 1.2 before you got text input events. Hmm...
|
|
|
|
*/
|
|
|
|
if (!SDL_HasScreenKeyboardSupport()) {
|
|
|
|
SDL_StartTextInput();
|
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* We're ready to go! */
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetCurrentVideoDriver()
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return _this->name;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_VideoDevice *
|
2010-06-26 08:56:48 -07:00
|
|
|
SDL_GetVideoDevice(void)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
return _this;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay display;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_zero(display);
|
|
|
|
if (desktop_mode) {
|
|
|
|
display.desktop_mode = *desktop_mode;
|
|
|
|
}
|
|
|
|
display.current_mode = display.desktop_mode;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_AddVideoDisplay(&display);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *displays;
|
|
|
|
int index = -1;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
displays =
|
|
|
|
SDL_realloc(_this->displays,
|
|
|
|
(_this->num_displays + 1) * sizeof(*displays));
|
|
|
|
if (displays) {
|
|
|
|
index = _this->num_displays++;
|
|
|
|
displays[index] = *display;
|
|
|
|
displays[index].device = _this;
|
|
|
|
_this->displays = displays;
|
2012-12-31 11:07:46 -08:00
|
|
|
|
|
|
|
if (display->name) {
|
|
|
|
displays[index].name = SDL_strdup(display->name);
|
|
|
|
} else {
|
|
|
|
char name[32];
|
|
|
|
|
|
|
|
SDL_itoa(index, name, 10);
|
|
|
|
displays[index].name = SDL_strdup(name);
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
} else {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
}
|
|
|
|
return index;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetNumVideoDisplays(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return _this->num_displays;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 21:48:28 -07:00
|
|
|
int
|
2011-02-21 22:03:39 -08:00
|
|
|
SDL_GetIndexOfDisplay(SDL_VideoDisplay *display)
|
|
|
|
{
|
|
|
|
int displayIndex;
|
|
|
|
|
|
|
|
for (displayIndex = 0; displayIndex < _this->num_displays; ++displayIndex) {
|
|
|
|
if (display == &_this->displays[displayIndex]) {
|
|
|
|
return displayIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Couldn't find the display, just use index 0 */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-13 17:42:46 -07:00
|
|
|
void *
|
2014-06-04 10:56:37 -07:00
|
|
|
SDL_GetDisplayDriverData(int displayIndex)
|
2013-09-13 17:42:46 -07:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, NULL);
|
2013-09-13 17:42:46 -07:00
|
|
|
|
2013-11-10 14:10:00 -08:00
|
|
|
return _this->displays[displayIndex].driverdata;
|
2013-09-13 17:42:46 -07:00
|
|
|
}
|
|
|
|
|
2012-12-31 11:07:46 -08:00
|
|
|
const char *
|
|
|
|
SDL_GetDisplayName(int displayIndex)
|
|
|
|
{
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, NULL);
|
|
|
|
|
|
|
|
return _this->displays[displayIndex].name;
|
|
|
|
}
|
|
|
|
|
2009-12-06 08:03:38 +00:00
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
|
2009-12-06 08:03:38 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
2009-12-06 08:03:38 +00:00
|
|
|
if (rect) {
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display = &_this->displays[displayIndex];
|
2009-12-06 08:03:38 +00:00
|
|
|
|
|
|
|
if (_this->GetDisplayBounds) {
|
2011-02-11 00:25:44 -08:00
|
|
|
if (_this->GetDisplayBounds(_this, display, rect) == 0) {
|
|
|
|
return 0;
|
2009-12-06 08:03:38 +00:00
|
|
|
}
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Assume that the displays are left to right */
|
|
|
|
if (displayIndex == 0) {
|
|
|
|
rect->x = 0;
|
|
|
|
rect->y = 0;
|
2009-12-06 08:03:38 +00:00
|
|
|
} else {
|
2011-02-11 00:25:44 -08:00
|
|
|
SDL_GetDisplayBounds(displayIndex-1, rect);
|
|
|
|
rect->x += rect->w;
|
2009-12-06 08:03:38 +00:00
|
|
|
}
|
2012-09-29 17:23:40 -07:00
|
|
|
rect->w = display->current_mode.w;
|
|
|
|
rect->h = display->current_mode.h;
|
2009-12-06 08:03:38 +00:00
|
|
|
}
|
2016-01-04 23:52:40 -05:00
|
|
|
return 0; /* !!! FIXME: should this be an error if (rect==NULL) ? */
|
|
|
|
}
|
|
|
|
|
|
|
|
int SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect)
|
|
|
|
{
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
if (rect) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[displayIndex];
|
|
|
|
|
|
|
|
if (_this->GetDisplayUsableBounds) {
|
|
|
|
if (_this->GetDisplayUsableBounds(_this, display, rect) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Oh well, just give the entire display bounds. */
|
|
|
|
return SDL_GetDisplayBounds(displayIndex, rect);
|
|
|
|
}
|
|
|
|
return 0; /* !!! FIXME: should this be an error if (rect==NULL) ? */
|
2009-12-06 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 17:18:56 -07:00
|
|
|
int
|
|
|
|
SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi)
|
|
|
|
{
|
2017-09-10 12:40:45 -07:00
|
|
|
SDL_VideoDisplay *display;
|
2015-07-29 17:18:56 -07:00
|
|
|
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
|
|
|
|
2017-09-10 12:40:45 -07:00
|
|
|
if (_this->GetDisplayDPI) {
|
|
|
|
if (_this->GetDisplayDPI(_this, display, ddpi, hdpi, vdpi) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-10 21:14:36 +02:00
|
|
|
} else {
|
|
|
|
return SDL_Unsupported();
|
|
|
|
}
|
2015-07-29 17:18:56 -07:00
|
|
|
|
2017-09-10 12:40:45 -07:00
|
|
|
return -1;
|
2015-07-29 17:18:56 -07:00
|
|
|
}
|
|
|
|
|
2018-08-22 21:48:28 -07:00
|
|
|
SDL_DisplayOrientation
|
|
|
|
SDL_GetDisplayOrientation(int displayIndex)
|
|
|
|
{
|
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, SDL_ORIENTATION_UNKNOWN);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
|
|
|
return display->orientation;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_DisplayMode *modes;
|
|
|
|
int i, nmodes;
|
|
|
|
|
|
|
|
/* Make sure we don't already have the mode in the list */
|
|
|
|
modes = display->display_modes;
|
|
|
|
nmodes = display->num_display_modes;
|
2013-07-13 21:56:31 -04:00
|
|
|
for (i = 0; i < nmodes; ++i) {
|
2013-07-13 21:42:57 -04:00
|
|
|
if (cmpmodes(mode, &modes[i]) == 0) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go ahead and add the new mode */
|
|
|
|
if (nmodes == display->max_display_modes) {
|
|
|
|
modes =
|
|
|
|
SDL_realloc(modes,
|
|
|
|
(display->max_display_modes + 32) * sizeof(*modes));
|
|
|
|
if (!modes) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
display->display_modes = modes;
|
|
|
|
display->max_display_modes += 32;
|
|
|
|
}
|
|
|
|
modes[nmodes] = *mode;
|
|
|
|
display->num_display_modes++;
|
|
|
|
|
2009-06-09 08:56:43 +00:00
|
|
|
/* Re-sort video modes */
|
|
|
|
SDL_qsort(display->display_modes, display->num_display_modes,
|
2009-06-10 13:34:20 +00:00
|
|
|
sizeof(SDL_DisplayMode), cmpmodes);
|
2009-06-09 08:56:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_TRUE;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
static int
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
|
|
|
|
{
|
|
|
|
if (!display->num_display_modes && _this->GetDisplayModes) {
|
|
|
|
_this->GetDisplayModes(_this, display);
|
|
|
|
SDL_qsort(display->display_modes, display->num_display_modes,
|
|
|
|
sizeof(SDL_DisplayMode), cmpmodes);
|
|
|
|
}
|
|
|
|
return display->num_display_modes;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetNumDisplayModes(int displayIndex)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
return SDL_GetNumDisplayModesForDisplay(&_this->displays[displayIndex]);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
2009-12-01 05:57:15 +00:00
|
|
|
if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("index must be in the range of 0 - %d",
|
|
|
|
SDL_GetNumDisplayModesForDisplay(display) - 1);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
if (mode) {
|
2009-12-01 05:57:15 +00:00
|
|
|
*mode = display->display_modes[index];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode)
|
2009-12-01 05:57:15 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display;
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
2009-12-01 05:57:15 +00:00
|
|
|
if (mode) {
|
|
|
|
*mode = display->desktop_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display;
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
2008-09-15 04:32:36 +00:00
|
|
|
if (mode) {
|
2009-12-01 05:57:15 +00:00
|
|
|
*mode = display->current_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
static SDL_DisplayMode *
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
|
|
|
|
const SDL_DisplayMode * mode,
|
|
|
|
SDL_DisplayMode * closest)
|
2008-09-15 04:32:36 +00:00
|
|
|
{
|
|
|
|
Uint32 target_format;
|
|
|
|
int target_refresh_rate;
|
|
|
|
int i;
|
|
|
|
SDL_DisplayMode *current, *match;
|
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
if (!mode || !closest) {
|
|
|
|
SDL_SetError("Missing desired mode or closest mode parameter");
|
2008-09-15 04:32:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Default to the desktop format */
|
|
|
|
if (mode->format) {
|
|
|
|
target_format = mode->format;
|
|
|
|
} else {
|
2009-12-01 05:57:15 +00:00
|
|
|
target_format = display->desktop_mode.format;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Default to the desktop refresh rate */
|
|
|
|
if (mode->refresh_rate) {
|
|
|
|
target_refresh_rate = mode->refresh_rate;
|
|
|
|
} else {
|
2009-12-01 05:57:15 +00:00
|
|
|
target_refresh_rate = display->desktop_mode.refresh_rate;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match = NULL;
|
2009-12-01 05:57:15 +00:00
|
|
|
for (i = 0; i < SDL_GetNumDisplayModesForDisplay(display); ++i) {
|
|
|
|
current = &display->display_modes[i];
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2008-11-25 20:06:27 +00:00
|
|
|
if (current->w && (current->w < mode->w)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Out of sorted modes large enough here */
|
|
|
|
break;
|
|
|
|
}
|
2008-11-25 20:06:27 +00:00
|
|
|
if (current->h && (current->h < mode->h)) {
|
|
|
|
if (current->w && (current->w == mode->w)) {
|
|
|
|
/* Out of sorted modes large enough here */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Wider, but not tall enough, due to a different
|
|
|
|
aspect ratio. This mode must be skipped, but closer
|
|
|
|
modes may still follow. */
|
|
|
|
continue;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!match || current->w < match->w || current->h < match->h) {
|
|
|
|
match = current;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (current->format != match->format) {
|
|
|
|
/* Sorted highest depth to lowest */
|
|
|
|
if (current->format == target_format ||
|
|
|
|
(SDL_BITSPERPIXEL(current->format) >=
|
|
|
|
SDL_BITSPERPIXEL(target_format)
|
|
|
|
&& SDL_PIXELTYPE(current->format) ==
|
|
|
|
SDL_PIXELTYPE(target_format))) {
|
|
|
|
match = current;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (current->refresh_rate != match->refresh_rate) {
|
|
|
|
/* Sorted highest refresh to lowest */
|
|
|
|
if (current->refresh_rate >= target_refresh_rate) {
|
|
|
|
match = current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (match) {
|
|
|
|
if (match->format) {
|
|
|
|
closest->format = match->format;
|
|
|
|
} else {
|
|
|
|
closest->format = mode->format;
|
|
|
|
}
|
|
|
|
if (match->w && match->h) {
|
|
|
|
closest->w = match->w;
|
|
|
|
closest->h = match->h;
|
|
|
|
} else {
|
|
|
|
closest->w = mode->w;
|
|
|
|
closest->h = mode->h;
|
|
|
|
}
|
|
|
|
if (match->refresh_rate) {
|
|
|
|
closest->refresh_rate = match->refresh_rate;
|
|
|
|
} else {
|
|
|
|
closest->refresh_rate = mode->refresh_rate;
|
|
|
|
}
|
|
|
|
closest->driverdata = match->driverdata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pick some reasonable defaults if the app and driver don't
|
|
|
|
* care
|
|
|
|
*/
|
|
|
|
if (!closest->format) {
|
|
|
|
closest->format = SDL_PIXELFORMAT_RGB888;
|
|
|
|
}
|
|
|
|
if (!closest->w) {
|
|
|
|
closest->w = 640;
|
|
|
|
}
|
|
|
|
if (!closest->h) {
|
|
|
|
closest->h = 480;
|
|
|
|
}
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2004-02-24 07:42:19 +00:00
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_DisplayMode *
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetClosestDisplayMode(int displayIndex,
|
|
|
|
const SDL_DisplayMode * mode,
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_DisplayMode * closest)
|
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, NULL);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
|
|
|
return SDL_GetClosestDisplayModeForDisplay(display, mode, closest);
|
2009-12-01 05:57:15 +00:00
|
|
|
}
|
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
static int
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_DisplayMode display_mode;
|
|
|
|
SDL_DisplayMode current_mode;
|
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
if (mode) {
|
|
|
|
display_mode = *mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
/* Default to the current mode */
|
|
|
|
if (!display_mode.format) {
|
|
|
|
display_mode.format = display->current_mode.format;
|
|
|
|
}
|
|
|
|
if (!display_mode.w) {
|
|
|
|
display_mode.w = display->current_mode.w;
|
|
|
|
}
|
|
|
|
if (!display_mode.h) {
|
|
|
|
display_mode.h = display->current_mode.h;
|
|
|
|
}
|
|
|
|
if (!display_mode.refresh_rate) {
|
|
|
|
display_mode.refresh_rate = display->current_mode.refresh_rate;
|
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
/* Get a good video mode, the closest one possible */
|
|
|
|
if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("No video mode large enough for %dx%d",
|
|
|
|
display_mode.w, display_mode.h);
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
display_mode = display->desktop_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* See if there's anything left to do */
|
2011-02-10 12:14:37 -08:00
|
|
|
current_mode = display->current_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Actually change the display mode */
|
2011-01-12 13:46:37 -08:00
|
|
|
if (!_this->SetDisplayMode) {
|
2018-04-23 22:29:14 -07:00
|
|
|
return SDL_SetError("SDL video driver doesn't support changing display mode");
|
2011-01-12 13:46:37 -08:00
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
if (_this->SetDisplayMode(_this, display, &display_mode) < 0) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
display->current_mode = display_mode;
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 21:48:28 -07:00
|
|
|
SDL_VideoDisplay *
|
|
|
|
SDL_GetDisplay(int displayIndex)
|
|
|
|
{
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, NULL);
|
|
|
|
|
|
|
|
return &_this->displays[displayIndex];
|
|
|
|
}
|
|
|
|
|
2011-02-10 14:44:25 -08:00
|
|
|
int
|
2012-12-31 10:29:17 -08:00
|
|
|
SDL_GetWindowDisplayIndex(SDL_Window * window)
|
2011-02-10 14:44:25 -08:00
|
|
|
{
|
|
|
|
int displayIndex;
|
|
|
|
int i, dist;
|
|
|
|
int closest = -1;
|
|
|
|
int closest_dist = 0x7FFFFFFF;
|
|
|
|
SDL_Point center;
|
|
|
|
SDL_Point delta;
|
|
|
|
SDL_Rect rect;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(window->x) ||
|
|
|
|
SDL_WINDOWPOS_ISCENTERED(window->x)) {
|
|
|
|
displayIndex = (window->x & 0xFFFF);
|
|
|
|
if (displayIndex >= _this->num_displays) {
|
|
|
|
displayIndex = 0;
|
|
|
|
}
|
|
|
|
return displayIndex;
|
|
|
|
}
|
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(window->y) ||
|
|
|
|
SDL_WINDOWPOS_ISCENTERED(window->y)) {
|
|
|
|
displayIndex = (window->y & 0xFFFF);
|
|
|
|
if (displayIndex >= _this->num_displays) {
|
|
|
|
displayIndex = 0;
|
|
|
|
}
|
|
|
|
return displayIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the display containing the window */
|
2012-10-03 18:54:31 -07:00
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
|
|
|
|
if (display->fullscreen_window == window) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
center.x = window->x + window->w / 2;
|
|
|
|
center.y = window->y + window->h / 2;
|
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
|
SDL_GetDisplayBounds(i, &rect);
|
2012-10-03 18:54:31 -07:00
|
|
|
if (SDL_EnclosePoints(¢er, 1, &rect, NULL)) {
|
2011-02-10 14:44:25 -08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
delta.x = center.x - (rect.x + rect.w / 2);
|
|
|
|
delta.y = center.y - (rect.y + rect.h / 2);
|
|
|
|
dist = (delta.x*delta.x + delta.y*delta.y);
|
|
|
|
if (dist < closest_dist) {
|
|
|
|
closest = i;
|
|
|
|
closest_dist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (closest < 0) {
|
|
|
|
SDL_SetError("Couldn't find any displays");
|
|
|
|
}
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_VideoDisplay *
|
|
|
|
SDL_GetDisplayForWindow(SDL_Window *window)
|
|
|
|
{
|
2012-12-31 10:29:17 -08:00
|
|
|
int displayIndex = SDL_GetWindowDisplayIndex(window);
|
2011-02-21 15:08:36 -08:00
|
|
|
if (displayIndex >= 0) {
|
|
|
|
return &_this->displays[displayIndex];
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
}
|
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
int
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
|
2009-12-01 05:57:15 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
if (mode) {
|
|
|
|
window->fullscreen_mode = *mode;
|
|
|
|
} else {
|
|
|
|
SDL_zero(window->fullscreen_mode);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2014-06-04 10:56:37 -07:00
|
|
|
|
|
|
|
if (FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
|
|
|
|
SDL_DisplayMode fullscreen_mode;
|
|
|
|
if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
|
|
|
|
SDL_SetDisplayModeForDisplay(SDL_GetDisplayForWindow(window), &fullscreen_mode);
|
|
|
|
}
|
|
|
|
}
|
2009-12-05 22:13:36 +00:00
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_DisplayMode fullscreen_mode;
|
2013-05-18 14:17:52 -07:00
|
|
|
SDL_VideoDisplay *display;
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
2013-02-28 09:11:04 -08:00
|
|
|
if (!mode) {
|
2014-06-04 10:56:37 -07:00
|
|
|
return SDL_InvalidParamError("mode");
|
2013-02-28 09:11:04 -08:00
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
fullscreen_mode = window->fullscreen_mode;
|
|
|
|
if (!fullscreen_mode.w) {
|
2014-06-04 10:57:52 -07:00
|
|
|
fullscreen_mode.w = window->windowed.w;
|
2009-12-01 05:57:15 +00:00
|
|
|
}
|
|
|
|
if (!fullscreen_mode.h) {
|
2014-06-04 10:57:52 -07:00
|
|
|
fullscreen_mode.h = window->windowed.h;
|
2009-12-01 05:57:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
display = SDL_GetDisplayForWindow(window);
|
|
|
|
|
|
|
|
/* if in desktop size mode, just return the size of the desktop */
|
2014-06-04 10:56:37 -07:00
|
|
|
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
|
2013-05-18 14:17:52 -07:00
|
|
|
fullscreen_mode = display->desktop_mode;
|
2014-06-04 10:56:37 -07:00
|
|
|
} else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
|
2009-12-01 05:57:15 +00:00
|
|
|
&fullscreen_mode,
|
|
|
|
&fullscreen_mode)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("Couldn't find display mode match");
|
2009-12-01 05:57:15 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (mode) {
|
2009-12-01 05:57:15 +00:00
|
|
|
*mode = fullscreen_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2004-07-18 19:46:38 +00:00
|
|
|
|
2011-02-02 14:34:54 -08:00
|
|
|
Uint32
|
|
|
|
SDL_GetWindowPixelFormat(SDL_Window * window)
|
|
|
|
{
|
2011-02-10 14:44:25 -08:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, SDL_PIXELFORMAT_UNKNOWN);
|
|
|
|
|
|
|
|
display = SDL_GetDisplayForWindow(window);
|
|
|
|
return display->current_mode.format;
|
2011-02-02 14:34:54 -08:00
|
|
|
}
|
|
|
|
|
2011-03-11 18:16:39 -08:00
|
|
|
static void
|
|
|
|
SDL_RestoreMousePosition(SDL_Window *window)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
if (window == SDL_GetMouseFocus()) {
|
|
|
|
SDL_GetMouseState(&x, &y);
|
|
|
|
SDL_WarpMouseInWindow(window, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 00:41:39 -05:00
|
|
|
#if __WINRT__
|
|
|
|
extern Uint32 WINRT_DetectWindowFlags(SDL_Window * window);
|
|
|
|
#endif
|
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
static int
|
2011-02-27 21:17:06 -08:00
|
|
|
SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
|
2009-12-01 08:56:12 +00:00
|
|
|
{
|
2013-11-12 01:52:54 -08:00
|
|
|
SDL_VideoDisplay *display;
|
2014-06-04 10:57:52 -07:00
|
|
|
SDL_Window *other;
|
2014-06-04 10:56:56 -07:00
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
CHECK_WINDOW_MAGIC(window,-1);
|
2009-12-01 08:56:12 +00:00
|
|
|
|
2014-07-30 17:45:52 -07:00
|
|
|
/* if we are in the process of hiding don't go back to fullscreen */
|
2016-12-11 11:45:33 -08:00
|
|
|
if (window->is_hiding && fullscreen) {
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
return 0;
|
2016-12-11 11:45:33 -08:00
|
|
|
}
|
2015-10-06 00:10:54 -04:00
|
|
|
|
2013-11-12 01:52:54 -08:00
|
|
|
#ifdef __MACOSX__
|
2015-11-09 08:55:01 -08:00
|
|
|
/* if the window is going away and no resolution change is necessary,
|
2016-12-11 11:45:33 -08:00
|
|
|
do nothing, or else we may trigger an ugly double-transition
|
2015-11-09 08:55:01 -08:00
|
|
|
*/
|
2017-01-07 19:55:29 -05:00
|
|
|
if (SDL_strcmp(_this->name, "cocoa") == 0) { /* don't do this for X11, etc */
|
|
|
|
if (window->is_destroying && (window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
|
|
|
return 0;
|
2015-11-09 08:55:01 -08:00
|
|
|
|
2017-08-29 22:24:59 -07:00
|
|
|
/* If we're switching between a fullscreen Space and "normal" fullscreen, we need to get back to normal first. */
|
|
|
|
if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN)) {
|
|
|
|
if (!Cocoa_SetWindowFullscreenSpace(window, SDL_FALSE)) {
|
|
|
|
return -1;
|
2016-12-11 11:45:33 -08:00
|
|
|
}
|
2017-08-29 22:24:59 -07:00
|
|
|
} else if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
|
|
|
display = SDL_GetDisplayForWindow(window);
|
|
|
|
SDL_SetDisplayModeForDisplay(display, NULL);
|
|
|
|
if (_this->SetWindowFullscreen) {
|
|
|
|
_this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2015-10-06 00:10:54 -04:00
|
|
|
|
2017-08-29 22:24:59 -07:00
|
|
|
if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {
|
|
|
|
if (Cocoa_IsWindowInFullscreenSpace(window) != fullscreen) {
|
|
|
|
return -1;
|
2016-12-11 11:45:33 -08:00
|
|
|
}
|
2017-08-29 22:24:59 -07:00
|
|
|
window->last_fullscreen_flags = window->flags;
|
|
|
|
return 0;
|
2015-11-09 08:54:49 -08:00
|
|
|
}
|
2013-11-12 01:52:54 -08:00
|
|
|
}
|
2015-11-29 19:33:11 -05:00
|
|
|
#elif __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
|
2015-11-26 00:41:39 -05:00
|
|
|
/* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
|
|
|
|
or not. The user can choose this, via OS-provided UI, but this can't
|
|
|
|
be set programmatically.
|
|
|
|
|
|
|
|
Just look at what SDL's WinRT video backend code detected with regards
|
|
|
|
to fullscreen (being active, or not), and figure out a return/error code
|
|
|
|
from that.
|
|
|
|
*/
|
|
|
|
if (fullscreen == !(WINRT_DetectWindowFlags(window) & FULLSCREEN_MASK)) {
|
|
|
|
/* Uh oh, either:
|
|
|
|
1. fullscreen was requested, and we're already windowed
|
|
|
|
2. windowed-mode was requested, and we're already fullscreen
|
|
|
|
|
|
|
|
WinRT 8.x can't resolve either programmatically, so we're
|
|
|
|
giving up.
|
|
|
|
*/
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
/* Whatever was requested, fullscreen or windowed mode, is already
|
|
|
|
in-place.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
2013-11-12 01:52:54 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
display = SDL_GetDisplayForWindow(window);
|
|
|
|
|
2011-02-27 21:17:06 -08:00
|
|
|
if (fullscreen) {
|
2009-12-01 08:56:12 +00:00
|
|
|
/* Hide any other fullscreen windows */
|
2011-02-11 00:25:44 -08:00
|
|
|
if (display->fullscreen_window &&
|
|
|
|
display->fullscreen_window != window) {
|
2011-02-10 14:44:25 -08:00
|
|
|
SDL_MinimizeWindow(display->fullscreen_window);
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-15 23:07:14 -08:00
|
|
|
/* See if anything needs to be done now */
|
2011-02-27 21:17:06 -08:00
|
|
|
if ((display->fullscreen_window == window) == fullscreen) {
|
2014-01-15 11:17:09 -08:00
|
|
|
if ((window->last_fullscreen_flags & FULLSCREEN_MASK) == (window->flags & FULLSCREEN_MASK)) {
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
return 0;
|
2014-01-15 11:17:09 -08:00
|
|
|
}
|
2011-02-15 23:07:14 -08:00
|
|
|
}
|
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
/* See if there are any fullscreen windows */
|
2011-02-11 00:25:44 -08:00
|
|
|
for (other = _this->windows; other; other = other->next) {
|
2011-02-27 21:17:06 -08:00
|
|
|
SDL_bool setDisplayMode = SDL_FALSE;
|
|
|
|
|
|
|
|
if (other == window) {
|
|
|
|
setDisplayMode = fullscreen;
|
|
|
|
} else if (FULLSCREEN_VISIBLE(other) &&
|
|
|
|
SDL_GetDisplayForWindow(other) == display) {
|
|
|
|
setDisplayMode = SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setDisplayMode) {
|
2009-12-01 08:56:12 +00:00
|
|
|
SDL_DisplayMode fullscreen_mode;
|
2011-02-27 21:17:06 -08:00
|
|
|
|
2014-03-20 16:54:20 -04:00
|
|
|
SDL_zero(fullscreen_mode);
|
|
|
|
|
2011-02-11 00:25:44 -08:00
|
|
|
if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
|
2011-02-16 00:11:48 -08:00
|
|
|
SDL_bool resized = SDL_TRUE;
|
|
|
|
|
|
|
|
if (other->w == fullscreen_mode.w && other->h == fullscreen_mode.h) {
|
|
|
|
resized = SDL_FALSE;
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* only do the mode change if we want exclusive fullscreen */
|
2013-11-11 01:59:40 -08:00
|
|
|
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
if (SDL_SetDisplayModeForDisplay(display, &fullscreen_mode) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-11-11 01:59:40 -08:00
|
|
|
} else {
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
if (SDL_SetDisplayModeForDisplay(display, NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-11-11 01:59:40 -08:00
|
|
|
}
|
2012-12-15 00:30:17 +00:00
|
|
|
|
2011-02-11 00:25:44 -08:00
|
|
|
if (_this->SetWindowFullscreen) {
|
2011-02-15 23:07:14 -08:00
|
|
|
_this->SetWindowFullscreen(_this, other, display, SDL_TRUE);
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
|
|
|
display->fullscreen_window = other;
|
|
|
|
|
2011-02-16 00:11:48 -08:00
|
|
|
/* Generate a mode change event here */
|
|
|
|
if (resized) {
|
2018-06-12 13:22:58 -07:00
|
|
|
#ifndef ANDROID
|
|
|
|
// Android may not resize the window to exactly what our fullscreen mode is, especially on
|
|
|
|
// windowed Android environments like the Chromebook or Samsung DeX. Given this, we shouldn't
|
|
|
|
// use fullscreen_mode.w and fullscreen_mode.h, but rather get our current native size. As such,
|
|
|
|
// Android's SetWindowFullscreen will generate the window event for us with the proper final size.
|
|
|
|
|
2011-02-16 00:11:48 -08:00
|
|
|
SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
|
|
|
|
fullscreen_mode.w, fullscreen_mode.h);
|
2018-06-12 13:22:58 -07:00
|
|
|
#endif
|
2011-02-16 00:11:48 -08:00
|
|
|
} else {
|
|
|
|
SDL_OnWindowResized(other);
|
|
|
|
}
|
2011-03-11 18:16:39 -08:00
|
|
|
|
|
|
|
SDL_RestoreMousePosition(other);
|
2014-01-15 11:17:09 -08:00
|
|
|
|
|
|
|
window->last_fullscreen_flags = window->flags;
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
return 0;
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nope, restore the desktop mode */
|
|
|
|
SDL_SetDisplayModeForDisplay(display, NULL);
|
2011-02-11 00:25:44 -08:00
|
|
|
|
|
|
|
if (_this->SetWindowFullscreen) {
|
2011-02-15 23:07:14 -08:00
|
|
|
_this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
2009-12-03 08:33:39 +00:00
|
|
|
display->fullscreen_window = NULL;
|
2011-02-16 00:11:48 -08:00
|
|
|
|
|
|
|
/* Generate a mode change event here */
|
|
|
|
SDL_OnWindowResized(window);
|
2011-03-11 18:16:39 -08:00
|
|
|
|
|
|
|
/* Restore the cursor position */
|
|
|
|
SDL_RestoreMousePosition(window);
|
2014-01-15 11:17:09 -08:00
|
|
|
|
|
|
|
window->last_fullscreen_flags = window->flags;
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
return 0;
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
#define CREATE_FLAGS \
|
2018-06-05 12:46:09 -07:00
|
|
|
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN | SDL_WINDOW_MINIMIZED)
|
2011-02-21 22:03:39 -08:00
|
|
|
|
2018-08-02 16:03:47 -04:00
|
|
|
static SDL_INLINE SDL_bool
|
|
|
|
IsAcceptingDragAndDrop(void)
|
|
|
|
{
|
|
|
|
if ((SDL_GetEventState(SDL_DROPFILE) == SDL_ENABLE) ||
|
|
|
|
(SDL_GetEventState(SDL_DROPTEXT) == SDL_ENABLE)) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prepare a newly-created window */
|
|
|
|
static SDL_INLINE void
|
|
|
|
PrepareDragAndDropSupport(SDL_Window *window)
|
|
|
|
{
|
|
|
|
if (_this->AcceptDragAndDrop) {
|
|
|
|
_this->AcceptDragAndDrop(window, IsAcceptingDragAndDrop());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* toggle d'n'd for all existing windows. */
|
|
|
|
void
|
|
|
|
SDL_ToggleDragAndDropSupport(void)
|
|
|
|
{
|
|
|
|
if (_this && _this->AcceptDragAndDrop) {
|
|
|
|
const SDL_bool enable = IsAcceptingDragAndDrop();
|
|
|
|
SDL_Window *window;
|
|
|
|
for (window = _this->windows; window; window = window->next) {
|
|
|
|
_this->AcceptDragAndDrop(window, enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
static void
|
|
|
|
SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
|
|
|
|
{
|
2018-08-02 16:03:47 -04:00
|
|
|
PrepareDragAndDropSupport(window);
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
if (flags & SDL_WINDOW_MAXIMIZED) {
|
|
|
|
SDL_MaximizeWindow(window);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_MINIMIZED) {
|
|
|
|
SDL_MinimizeWindow(window);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_FULLSCREEN) {
|
2012-12-15 00:30:17 +00:00
|
|
|
SDL_SetWindowFullscreen(window, flags);
|
2011-02-21 22:03:39 -08:00
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_INPUT_GRABBED) {
|
|
|
|
SDL_SetWindowGrab(window, SDL_TRUE);
|
|
|
|
}
|
|
|
|
if (!(flags & SDL_WINDOW_HIDDEN)) {
|
|
|
|
SDL_ShowWindow(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
if (!_this) {
|
2009-10-28 06:04:07 +00:00
|
|
|
/* Initialize the video system if needed */
|
2011-01-27 22:44:08 -08:00
|
|
|
if (SDL_VideoInit(NULL) < 0) {
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2009-10-28 06:04:07 +00:00
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2011-02-11 00:25:44 -08:00
|
|
|
|
2016-12-11 11:45:33 -08:00
|
|
|
if ((((flags & SDL_WINDOW_UTILITY) != 0) + ((flags & SDL_WINDOW_TOOLTIP) != 0) + ((flags & SDL_WINDOW_POPUP_MENU) != 0)) > 1) {
|
2016-01-05 01:30:40 -05:00
|
|
|
SDL_SetError("Conflicting window flags specified");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-22 23:51:46 -05:00
|
|
|
/* Some platforms can't create zero-sized windows */
|
|
|
|
if (w < 1) {
|
|
|
|
w = 1;
|
|
|
|
}
|
|
|
|
if (h < 1) {
|
|
|
|
h = 1;
|
|
|
|
}
|
|
|
|
|
2015-04-06 18:26:13 -04:00
|
|
|
/* Some platforms blow up if the windows are too large. Raise it later? */
|
|
|
|
if ((w > 16384) || (h > 16384)) {
|
|
|
|
SDL_SetError("Window is too large.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-11 00:25:44 -08:00
|
|
|
/* Some platforms have OpenGL enabled by default */
|
2014-06-06 15:45:59 -03:00
|
|
|
#if (SDL_VIDEO_OPENGL && __MACOSX__) || __IPHONEOS__ || __ANDROID__ || __NACL__
|
2017-08-27 22:15:57 -04:00
|
|
|
if (!_this->is_dummy && !(flags & SDL_WINDOW_VULKAN)) {
|
2016-10-07 18:09:09 -07:00
|
|
|
flags |= SDL_WINDOW_OPENGL;
|
|
|
|
}
|
2011-02-11 00:25:44 -08:00
|
|
|
#endif
|
2009-02-09 05:32:12 +00:00
|
|
|
if (flags & SDL_WINDOW_OPENGL) {
|
|
|
|
if (!_this->GL_CreateContext) {
|
2018-04-23 22:29:14 -07:00
|
|
|
SDL_SetError("OpenGL support is either not configured in SDL "
|
|
|
|
"or not available in current SDL video driver "
|
|
|
|
"(%s) or platform", _this->name);
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2009-02-09 05:32:12 +00:00
|
|
|
}
|
2012-10-28 14:16:18 -07:00
|
|
|
if (SDL_GL_LoadLibrary(NULL) < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2013-11-12 02:18:52 -08:00
|
|
|
|
2017-08-27 23:39:55 -07:00
|
|
|
if (flags & SDL_WINDOW_VULKAN) {
|
|
|
|
if (!_this->Vulkan_CreateSurface) {
|
2017-08-27 22:15:57 -04:00
|
|
|
SDL_SetError("Vulkan support is either not configured in SDL "
|
2018-04-23 22:29:14 -07:00
|
|
|
"or not available in current SDL video driver "
|
|
|
|
"(%s) or platform", _this->name);
|
2017-08-27 22:15:57 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (flags & SDL_WINDOW_OPENGL) {
|
2017-08-27 22:15:57 -04:00
|
|
|
SDL_SetError("Vulkan and OpenGL not supported on same window");
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (SDL_Vulkan_LoadLibrary(NULL) < 0) {
|
2017-08-27 22:15:57 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 02:18:52 -08:00
|
|
|
/* Unless the user has specified the high-DPI disabling hint, respect the
|
|
|
|
* SDL_WINDOW_ALLOW_HIGHDPI flag.
|
|
|
|
*/
|
|
|
|
if (flags & SDL_WINDOW_ALLOW_HIGHDPI) {
|
2016-10-07 23:40:44 -07:00
|
|
|
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_HIGHDPI_DISABLED, SDL_FALSE)) {
|
2013-11-12 02:18:52 -08:00
|
|
|
flags &= ~SDL_WINDOW_ALLOW_HIGHDPI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
|
2013-07-10 22:13:19 -07:00
|
|
|
if (!window) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-24 20:21:51 +00:00
|
|
|
window->magic = &_this->window_magic;
|
2010-01-21 06:21:52 +00:00
|
|
|
window->id = _this->next_object_id++;
|
|
|
|
window->x = x;
|
|
|
|
window->y = y;
|
|
|
|
window->w = w;
|
|
|
|
window->h = h;
|
2011-02-21 22:03:39 -08:00
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) ||
|
|
|
|
SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
|
|
|
int displayIndex;
|
|
|
|
SDL_Rect bounds;
|
|
|
|
|
|
|
|
displayIndex = SDL_GetIndexOfDisplay(display);
|
|
|
|
SDL_GetDisplayBounds(displayIndex, &bounds);
|
2011-02-27 21:17:06 -08:00
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
|
2011-02-21 22:03:39 -08:00
|
|
|
window->x = bounds.x + (bounds.w - w) / 2;
|
|
|
|
}
|
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
|
|
|
|
window->y = bounds.y + (bounds.h - h) / 2;
|
|
|
|
}
|
|
|
|
}
|
2016-01-22 13:12:16 -08:00
|
|
|
window->windowed.x = window->x;
|
|
|
|
window->windowed.y = window->y;
|
|
|
|
window->windowed.w = window->w;
|
|
|
|
window->windowed.h = window->h;
|
|
|
|
|
|
|
|
if (flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
|
|
|
int displayIndex;
|
|
|
|
SDL_Rect bounds;
|
|
|
|
|
|
|
|
displayIndex = SDL_GetIndexOfDisplay(display);
|
|
|
|
SDL_GetDisplayBounds(displayIndex, &bounds);
|
|
|
|
|
|
|
|
window->x = bounds.x;
|
|
|
|
window->y = bounds.y;
|
|
|
|
window->w = bounds.w;
|
|
|
|
window->h = bounds.h;
|
|
|
|
}
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
|
2014-01-15 11:17:09 -08:00
|
|
|
window->last_fullscreen_flags = window->flags;
|
2016-01-05 02:46:10 -05:00
|
|
|
window->opacity = 1.0f;
|
2011-03-11 08:49:20 -08:00
|
|
|
window->brightness = 1.0f;
|
2011-02-10 14:44:25 -08:00
|
|
|
window->next = _this->windows;
|
2014-01-15 11:34:03 -08:00
|
|
|
window->is_destroying = SDL_FALSE;
|
2013-09-20 13:43:00 -04:00
|
|
|
|
2011-02-10 14:44:25 -08:00
|
|
|
if (_this->windows) {
|
|
|
|
_this->windows->prev = window;
|
2010-01-22 16:17:11 +00:00
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
_this->windows = window;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2017-08-28 00:43:14 -07:00
|
|
|
if (_this->CreateSDLWindow && _this->CreateSDLWindow(_this, window) < 0) {
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
return NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 11:49:25 -07:00
|
|
|
/* Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation,
|
|
|
|
* but it's important or window focus will get broken on windows!
|
|
|
|
*/
|
2018-06-05 12:46:09 -07:00
|
|
|
#if !defined(__WIN32__)
|
2018-09-24 11:49:25 -07:00
|
|
|
if (window->flags & SDL_WINDOW_MINIMIZED) {
|
|
|
|
window->flags &= ~SDL_WINDOW_MINIMIZED;
|
2018-08-26 10:34:23 -07:00
|
|
|
}
|
2018-06-05 12:46:09 -07:00
|
|
|
#endif
|
|
|
|
|
2015-11-29 19:33:11 -05:00
|
|
|
#if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
|
2015-11-26 00:41:39 -05:00
|
|
|
/* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
|
|
|
|
or not. The user can choose this, via OS-provided UI, but this can't
|
|
|
|
be set programmatically.
|
|
|
|
|
|
|
|
Just look at what SDL's WinRT video backend code detected with regards
|
|
|
|
to fullscreen (being active, or not), and figure out a return/error code
|
|
|
|
from that.
|
|
|
|
*/
|
|
|
|
flags = window->flags;
|
|
|
|
#endif
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (title) {
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowTitle(window, title);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2011-02-21 22:03:39 -08:00
|
|
|
SDL_FinishWindowCreation(window, flags);
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2011-11-08 00:03:54 -05:00
|
|
|
/* If the window was created fullscreen, make sure the mode code matches */
|
|
|
|
SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window));
|
2008-12-17 07:17:54 +00:00
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
return window;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_CreateWindowFrom(const void *data)
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2017-08-28 00:43:14 -07:00
|
|
|
if (!_this->CreateSDLWindowFrom) {
|
2014-10-15 09:14:09 -07:00
|
|
|
SDL_Unsupported();
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
|
2013-07-10 22:13:19 -07:00
|
|
|
if (!window) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-24 20:21:51 +00:00
|
|
|
window->magic = &_this->window_magic;
|
2010-01-21 06:21:52 +00:00
|
|
|
window->id = _this->next_object_id++;
|
|
|
|
window->flags = SDL_WINDOW_FOREIGN;
|
2014-01-15 11:17:09 -08:00
|
|
|
window->last_fullscreen_flags = window->flags;
|
2014-01-15 11:34:03 -08:00
|
|
|
window->is_destroying = SDL_FALSE;
|
2016-01-05 02:46:10 -05:00
|
|
|
window->opacity = 1.0f;
|
2011-03-11 08:49:20 -08:00
|
|
|
window->brightness = 1.0f;
|
2011-02-10 14:44:25 -08:00
|
|
|
window->next = _this->windows;
|
|
|
|
if (_this->windows) {
|
|
|
|
_this->windows->prev = window;
|
2010-01-22 16:17:11 +00:00
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
_this->windows = window;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2017-08-28 00:43:14 -07:00
|
|
|
if (_this->CreateSDLWindowFrom(_this, window, data) < 0) {
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
return NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2018-08-02 16:03:47 -04:00
|
|
|
|
|
|
|
PrepareDragAndDropSupport(window);
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
return window;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 21:02:57 +00:00
|
|
|
int
|
2006-07-23 00:19:12 +00:00
|
|
|
SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
|
2006-07-22 21:02:57 +00:00
|
|
|
{
|
2014-06-22 02:48:43 -07:00
|
|
|
SDL_bool loaded_opengl = SDL_FALSE;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
|
2018-04-23 22:29:14 -07:00
|
|
|
return SDL_SetError("OpenGL support is either not configured in SDL "
|
|
|
|
"or not available in current SDL video driver "
|
|
|
|
"(%s) or platform", _this->name);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_FOREIGN) {
|
|
|
|
/* Can't destroy and re-create foreign windows, hrm */
|
|
|
|
flags |= SDL_WINDOW_FOREIGN;
|
|
|
|
} else {
|
|
|
|
flags &= ~SDL_WINDOW_FOREIGN;
|
|
|
|
}
|
|
|
|
|
2011-02-11 00:25:44 -08:00
|
|
|
/* Restore video mode, etc. */
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_HideWindow(window);
|
2011-02-11 00:25:44 -08:00
|
|
|
|
|
|
|
/* Tear down the old native window */
|
|
|
|
if (window->surface) {
|
2011-02-13 13:46:10 -08:00
|
|
|
window->surface->flags &= ~SDL_DONTFREE;
|
2011-02-11 00:25:44 -08:00
|
|
|
SDL_FreeSurface(window->surface);
|
2015-12-29 19:13:56 +01:00
|
|
|
window->surface = NULL;
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
|
|
|
if (_this->DestroyWindowFramebuffer) {
|
|
|
|
_this->DestroyWindowFramebuffer(_this, window);
|
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->DestroyWindow(_this, window);
|
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
|
2011-02-11 00:25:44 -08:00
|
|
|
if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
if (flags & SDL_WINDOW_OPENGL) {
|
2012-12-28 14:46:03 -08:00
|
|
|
if (SDL_GL_LoadLibrary(NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-06-22 02:48:43 -07:00
|
|
|
loaded_opengl = SDL_TRUE;
|
2011-02-11 00:25:44 -08:00
|
|
|
} else {
|
|
|
|
SDL_GL_UnloadLibrary();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-27 22:15:57 -04:00
|
|
|
if ((window->flags & SDL_WINDOW_VULKAN) != (flags & SDL_WINDOW_VULKAN)) {
|
|
|
|
SDL_SetError("Can't change SDL_WINDOW_VULKAN window flag");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((window->flags & SDL_WINDOW_VULKAN) && (flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
SDL_SetError("Vulkan and OpenGL not supported on same window");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
|
2014-01-15 11:17:09 -08:00
|
|
|
window->last_fullscreen_flags = window->flags;
|
2014-01-15 11:34:03 -08:00
|
|
|
window->is_destroying = SDL_FALSE;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2017-08-28 00:43:14 -07:00
|
|
|
if (_this->CreateSDLWindow && !(flags & SDL_WINDOW_FOREIGN)) {
|
|
|
|
if (_this->CreateSDLWindow(_this, window) < 0) {
|
2014-06-22 02:48:43 -07:00
|
|
|
if (loaded_opengl) {
|
2009-02-09 05:32:12 +00:00
|
|
|
SDL_GL_UnloadLibrary();
|
2014-06-22 02:48:43 -07:00
|
|
|
window->flags &= ~SDL_WINDOW_OPENGL;
|
2009-02-09 05:32:12 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2015-06-22 23:36:06 -07:00
|
|
|
|
2014-04-17 20:15:44 -07:00
|
|
|
if (flags & SDL_WINDOW_FOREIGN) {
|
|
|
|
window->flags |= SDL_WINDOW_FOREIGN;
|
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
|
2015-06-22 23:36:06 -07:00
|
|
|
if (_this->SetWindowTitle && window->title) {
|
|
|
|
_this->SetWindowTitle(_this, window);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2015-06-22 23:36:06 -07:00
|
|
|
|
|
|
|
if (_this->SetWindowIcon && window->icon) {
|
|
|
|
_this->SetWindowIcon(_this, window, window->icon);
|
2013-07-14 18:17:28 -07:00
|
|
|
}
|
2014-05-27 01:27:42 -04:00
|
|
|
|
2014-06-25 17:06:12 -04:00
|
|
|
if (window->hit_test) {
|
2014-05-28 01:22:47 -04:00
|
|
|
_this->SetWindowHitTest(window, SDL_TRUE);
|
2014-05-27 01:27:42 -04:00
|
|
|
}
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
SDL_FinishWindowCreation(window, flags);
|
2008-12-17 07:17:54 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-12 17:41:59 -07:00
|
|
|
SDL_bool
|
2017-08-15 18:29:47 -03:00
|
|
|
SDL_HasWindows(void)
|
2017-08-12 17:41:59 -07:00
|
|
|
{
|
|
|
|
return (_this && _this->windows != NULL);
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
Uint32
|
|
|
|
SDL_GetWindowID(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, 0);
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
return window->id;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *
|
|
|
|
SDL_GetWindowFromID(Uint32 id)
|
2009-10-28 06:04:07 +00:00
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window;
|
|
|
|
|
2009-10-28 06:04:07 +00:00
|
|
|
if (!_this) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
for (window = _this->windows; window; window = window->next) {
|
|
|
|
if (window->id == id) {
|
|
|
|
return window;
|
2009-10-28 06:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2009-10-28 06:04:07 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
Uint32
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowFlags(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, 0);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return window->flags;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowTitle(SDL_Window * window, const char *title)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
|
|
|
if (title == window->title) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(window->title);
|
2015-04-08 02:00:14 -04:00
|
|
|
|
|
|
|
window->title = SDL_strdup(title ? title : "");
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->SetWindowTitle) {
|
|
|
|
_this->SetWindowTitle(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowTitle(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-08-29 16:28:04 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window, "");
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2010-08-29 16:26:35 -07:00
|
|
|
return window->title ? window->title : "";
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:39:48 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
|
2009-01-02 17:39:48 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2011-02-21 16:45:23 -08:00
|
|
|
if (!icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-29 08:29:51 -07:00
|
|
|
SDL_FreeSurface(window->icon);
|
2013-07-14 18:17:28 -07:00
|
|
|
|
|
|
|
/* Convert the icon into ARGB8888 */
|
|
|
|
window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
|
|
|
|
if (!window->icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-02 17:39:48 +00:00
|
|
|
if (_this->SetWindowIcon) {
|
2013-07-14 18:17:28 -07:00
|
|
|
_this->SetWindowIcon(_this, window, window->icon);
|
2009-01-02 17:39:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 11:16:57 -08:00
|
|
|
void*
|
|
|
|
SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-03 11:16:57 -08:00
|
|
|
SDL_WindowUserData *prev, *data;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, NULL);
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2013-04-02 08:38:52 -07:00
|
|
|
/* Input validation */
|
2013-08-29 08:30:21 -07:00
|
|
|
if (name == NULL || name[0] == '\0') {
|
2013-04-02 08:38:52 -07:00
|
|
|
SDL_InvalidParamError("name");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-02-03 11:16:57 -08:00
|
|
|
|
|
|
|
/* See if the named data already exists */
|
|
|
|
prev = NULL;
|
|
|
|
for (data = window->data; data; prev = data, data = data->next) {
|
2013-04-02 08:38:52 -07:00
|
|
|
if (data->name && SDL_strcmp(data->name, name) == 0) {
|
2011-02-03 11:16:57 -08:00
|
|
|
void *last_value = data->data;
|
|
|
|
|
|
|
|
if (userdata) {
|
|
|
|
/* Set the new value */
|
|
|
|
data->data = userdata;
|
|
|
|
} else {
|
|
|
|
/* Delete this value */
|
|
|
|
if (prev) {
|
|
|
|
prev->next = data->next;
|
|
|
|
} else {
|
|
|
|
window->data = data->next;
|
|
|
|
}
|
|
|
|
SDL_free(data->name);
|
|
|
|
SDL_free(data);
|
|
|
|
}
|
|
|
|
return last_value;
|
|
|
|
}
|
|
|
|
}
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2011-02-03 11:16:57 -08:00
|
|
|
/* Add new data to the window */
|
|
|
|
if (userdata) {
|
|
|
|
data = (SDL_WindowUserData *)SDL_malloc(sizeof(*data));
|
|
|
|
data->name = SDL_strdup(name);
|
|
|
|
data->data = userdata;
|
|
|
|
data->next = window->data;
|
|
|
|
window->data = data;
|
|
|
|
}
|
|
|
|
return NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
void *
|
2011-02-03 11:16:57 -08:00
|
|
|
SDL_GetWindowData(SDL_Window * window, const char *name)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2011-02-03 11:16:57 -08:00
|
|
|
SDL_WindowUserData *data;
|
|
|
|
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, NULL);
|
|
|
|
|
2013-04-02 08:38:52 -07:00
|
|
|
/* Input validation */
|
2013-08-29 08:30:21 -07:00
|
|
|
if (name == NULL || name[0] == '\0') {
|
2013-04-02 08:38:52 -07:00
|
|
|
SDL_InvalidParamError("name");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-03 11:16:57 -08:00
|
|
|
for (data = window->data; data; data = data->next) {
|
2013-04-02 08:38:52 -07:00
|
|
|
if (data->name && SDL_strcmp(data->name, name) == 0) {
|
2011-02-03 11:16:57 -08:00
|
|
|
return data->data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowPosition(SDL_Window * window, int x, int y)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2011-03-11 16:54:43 -08:00
|
|
|
if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
|
2015-02-19 19:40:58 -05:00
|
|
|
int displayIndex = (x & 0xFFFF);
|
2011-03-11 16:54:43 -08:00
|
|
|
SDL_Rect bounds;
|
2016-12-31 10:30:07 -08:00
|
|
|
if (displayIndex >= _this->num_displays) {
|
2015-02-19 19:40:58 -05:00
|
|
|
displayIndex = 0;
|
|
|
|
}
|
2011-03-11 16:54:43 -08:00
|
|
|
|
2014-03-20 16:25:30 -04:00
|
|
|
SDL_zero(bounds);
|
|
|
|
|
2011-03-11 16:54:43 -08:00
|
|
|
SDL_GetDisplayBounds(displayIndex, &bounds);
|
|
|
|
if (SDL_WINDOWPOS_ISCENTERED(x)) {
|
2013-05-19 22:36:54 -07:00
|
|
|
x = bounds.x + (bounds.w - window->w) / 2;
|
2011-03-11 16:54:43 -08:00
|
|
|
}
|
|
|
|
if (SDL_WINDOWPOS_ISCENTERED(y)) {
|
2013-05-19 22:36:54 -07:00
|
|
|
y = bounds.y + (bounds.h - window->h) / 2;
|
2011-03-11 16:54:43 -08:00
|
|
|
}
|
|
|
|
}
|
2013-05-19 22:36:54 -07:00
|
|
|
|
2013-10-07 14:16:38 -07:00
|
|
|
if ((window->flags & SDL_WINDOW_FULLSCREEN)) {
|
|
|
|
if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
|
|
|
|
window->windowed.x = x;
|
|
|
|
}
|
|
|
|
if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
|
|
|
|
window->windowed.y = y;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
|
|
|
|
window->x = x;
|
|
|
|
}
|
|
|
|
if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
|
|
|
|
window->y = y;
|
|
|
|
}
|
2013-05-19 22:36:54 -07:00
|
|
|
|
2011-02-10 14:44:25 -08:00
|
|
|
if (_this->SetWindowPosition) {
|
|
|
|
_this->SetWindowPosition(_this, window);
|
|
|
|
}
|
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2011-02-10 14:44:25 -08:00
|
|
|
|
|
|
|
/* Fullscreen windows are always at their display's origin */
|
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
2015-07-29 17:19:11 -07:00
|
|
|
int displayIndex;
|
|
|
|
|
2013-03-03 17:22:51 -08:00
|
|
|
if (x) {
|
|
|
|
*x = 0;
|
|
|
|
}
|
|
|
|
if (y) {
|
|
|
|
*y = 0;
|
|
|
|
}
|
2015-07-29 17:19:11 -07:00
|
|
|
|
|
|
|
/* Find the window's monitor and update to the
|
|
|
|
monitor offset. */
|
|
|
|
displayIndex = SDL_GetWindowDisplayIndex(window);
|
|
|
|
if (displayIndex >= 0) {
|
|
|
|
SDL_Rect bounds;
|
|
|
|
|
|
|
|
SDL_zero(bounds);
|
|
|
|
|
|
|
|
SDL_GetDisplayBounds(displayIndex, &bounds);
|
|
|
|
if (x) {
|
|
|
|
*x = bounds.x;
|
|
|
|
}
|
|
|
|
if (y) {
|
|
|
|
*y = bounds.y;
|
|
|
|
}
|
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
} else {
|
2011-02-10 10:37:35 -08:00
|
|
|
if (x) {
|
|
|
|
*x = window->x;
|
|
|
|
}
|
|
|
|
if (y) {
|
|
|
|
*y = window->y;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2012-09-13 01:43:53 -04:00
|
|
|
void
|
|
|
|
SDL_SetWindowBordered(SDL_Window * window, SDL_bool bordered)
|
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2012-09-13 01:43:53 -04:00
|
|
|
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
|
|
|
const int want = (bordered != SDL_FALSE); /* normalize the flag. */
|
|
|
|
const int have = ((window->flags & SDL_WINDOW_BORDERLESS) == 0);
|
|
|
|
if ((want != have) && (_this->SetWindowBordered)) {
|
|
|
|
if (want) {
|
|
|
|
window->flags &= ~SDL_WINDOW_BORDERLESS;
|
|
|
|
} else {
|
|
|
|
window->flags |= SDL_WINDOW_BORDERLESS;
|
|
|
|
}
|
|
|
|
_this->SetWindowBordered(_this, window, (SDL_bool) want);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-29 22:52:41 -04:00
|
|
|
void
|
|
|
|
SDL_SetWindowResizable(SDL_Window * window, SDL_bool resizable)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
|
|
|
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
|
|
|
const int want = (resizable != SDL_FALSE); /* normalize the flag. */
|
|
|
|
const int have = ((window->flags & SDL_WINDOW_RESIZABLE) != 0);
|
|
|
|
if ((want != have) && (_this->SetWindowResizable)) {
|
|
|
|
if (want) {
|
|
|
|
window->flags |= SDL_WINDOW_RESIZABLE;
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_RESIZABLE;
|
|
|
|
}
|
|
|
|
_this->SetWindowResizable(_this, window, (SDL_bool) want);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowSize(SDL_Window * window, int w, int h)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2013-03-08 23:33:07 -08:00
|
|
|
if (w <= 0) {
|
|
|
|
SDL_InvalidParamError("w");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (h <= 0) {
|
|
|
|
SDL_InvalidParamError("h");
|
|
|
|
return;
|
|
|
|
}
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2013-11-10 14:10:00 -08:00
|
|
|
/* Make sure we don't exceed any window size limits */
|
2017-08-27 23:39:55 -07:00
|
|
|
if (window->min_w && w < window->min_w) {
|
2013-11-10 14:10:00 -08:00
|
|
|
w = window->min_w;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (window->max_w && w > window->max_w) {
|
2013-11-10 14:10:00 -08:00
|
|
|
w = window->max_w;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (window->min_h && h < window->min_h) {
|
2013-11-10 14:10:00 -08:00
|
|
|
h = window->min_h;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (window->max_h && h > window->max_h) {
|
2013-11-10 14:10:00 -08:00
|
|
|
h = window->max_h;
|
|
|
|
}
|
|
|
|
|
2014-06-04 10:57:52 -07:00
|
|
|
window->windowed.w = w;
|
|
|
|
window->windowed.h = h;
|
2014-06-04 10:56:37 -07:00
|
|
|
|
2014-06-04 10:57:52 -07:00
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
2014-06-04 10:56:37 -07:00
|
|
|
if (FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
|
2014-06-04 10:57:52 -07:00
|
|
|
window->last_fullscreen_flags = 0;
|
|
|
|
SDL_UpdateFullscreenMode(window, SDL_TRUE);
|
2014-06-04 10:56:37 -07:00
|
|
|
}
|
2013-11-10 14:10:00 -08:00
|
|
|
} else {
|
2011-02-12 19:02:14 -08:00
|
|
|
window->w = w;
|
|
|
|
window->h = h;
|
2011-02-11 00:25:44 -08:00
|
|
|
if (_this->SetWindowSize) {
|
|
|
|
_this->SetWindowSize(_this, window);
|
|
|
|
}
|
2011-02-12 19:02:14 -08:00
|
|
|
if (window->w == w && window->h == h) {
|
|
|
|
/* We didn't get a SDL_WINDOWEVENT_RESIZED event (by design) */
|
|
|
|
SDL_OnWindowResized(window);
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2013-03-08 23:33:07 -08:00
|
|
|
if (w) {
|
2012-11-18 15:45:12 +03:00
|
|
|
*w = window->w;
|
|
|
|
}
|
2013-03-08 23:33:07 -08:00
|
|
|
if (h) {
|
|
|
|
*h = window->h;
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
2012-11-18 15:45:12 +03:00
|
|
|
}
|
|
|
|
|
2016-01-05 02:29:06 -05:00
|
|
|
int
|
|
|
|
SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, int *right)
|
|
|
|
{
|
|
|
|
int dummy = 0;
|
|
|
|
|
|
|
|
if (!top) { top = &dummy; }
|
|
|
|
if (!left) { left = &dummy; }
|
|
|
|
if (!right) { right = &dummy; }
|
|
|
|
if (!bottom) { bottom = &dummy; }
|
|
|
|
|
|
|
|
/* Always initialize, so applications don't have to care */
|
|
|
|
*top = *left = *bottom = *right = 0;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (!_this->GetWindowBordersSize) {
|
|
|
|
return SDL_Unsupported();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _this->GetWindowBordersSize(_this, window, top, left, bottom, right);
|
|
|
|
}
|
|
|
|
|
2017-01-27 21:16:38 -08:00
|
|
|
void
|
|
|
|
SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
|
|
|
if (min_w <= 0) {
|
|
|
|
SDL_InvalidParamError("min_w");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (min_h <= 0) {
|
|
|
|
SDL_InvalidParamError("min_h");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-02 00:41:58 -08:00
|
|
|
if ((window->max_w && min_w >= window->max_w) ||
|
|
|
|
(window->max_h && min_h >= window->max_h)) {
|
2017-01-27 21:16:38 -08:00
|
|
|
SDL_SetError("SDL_SetWindowMinimumSize(): Tried to set minimum size larger than maximum size");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window->min_w = min_w;
|
|
|
|
window->min_h = min_h;
|
|
|
|
|
|
|
|
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
|
|
|
if (_this->SetWindowMinimumSize) {
|
|
|
|
_this->SetWindowMinimumSize(_this, window);
|
|
|
|
}
|
|
|
|
/* Ensure that window is not smaller than minimal size */
|
|
|
|
SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-18 15:45:12 +03:00
|
|
|
void
|
|
|
|
SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
|
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2013-03-08 23:33:07 -08:00
|
|
|
if (min_w) {
|
2012-11-18 15:45:12 +03:00
|
|
|
*min_w = window->min_w;
|
2013-03-08 23:33:07 -08:00
|
|
|
}
|
|
|
|
if (min_h) {
|
2012-11-18 15:45:12 +03:00
|
|
|
*min_h = window->min_h;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 12:15:25 -08:00
|
|
|
void
|
|
|
|
SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h)
|
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2013-03-08 23:33:07 -08:00
|
|
|
if (max_w <= 0) {
|
|
|
|
SDL_InvalidParamError("max_w");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (max_h <= 0) {
|
|
|
|
SDL_InvalidParamError("max_h");
|
|
|
|
return;
|
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2017-01-27 21:16:38 -08:00
|
|
|
if (max_w <= window->min_w || max_h <= window->min_h) {
|
|
|
|
SDL_SetError("SDL_SetWindowMaximumSize(): Tried to set maximum size smaller than minimum size");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window->max_w = max_w;
|
|
|
|
window->max_h = max_h;
|
|
|
|
|
2012-12-31 12:15:25 -08:00
|
|
|
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
|
|
|
if (_this->SetWindowMaximumSize) {
|
|
|
|
_this->SetWindowMaximumSize(_this, window);
|
|
|
|
}
|
|
|
|
/* Ensure that window is not larger than maximal size */
|
|
|
|
SDL_SetWindowSize(window, SDL_min(window->w, window->max_w), SDL_min(window->h, window->max_h));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h)
|
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2013-03-08 23:33:07 -08:00
|
|
|
if (max_w) {
|
2012-12-31 12:15:25 -08:00
|
|
|
*max_w = window->max_w;
|
2013-03-08 23:33:07 -08:00
|
|
|
}
|
|
|
|
if (max_h) {
|
2012-12-31 12:15:25 -08:00
|
|
|
*max_h = window->max_h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_ShowWindow(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_SHOWN) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->ShowWindow) {
|
|
|
|
_this->ShowWindow(_this, window);
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_HideWindow(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
|
|
|
if (!(window->flags & SDL_WINDOW_SHOWN)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2017-09-10 12:40:45 -07:00
|
|
|
window->is_hiding = SDL_TRUE;
|
2011-02-27 21:17:06 -08:00
|
|
|
SDL_UpdateFullscreenMode(window, SDL_FALSE);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->HideWindow) {
|
|
|
|
_this->HideWindow(_this, window);
|
|
|
|
}
|
2017-09-10 12:40:45 -07:00
|
|
|
window->is_hiding = SDL_FALSE;
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_RaiseWindow(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
|
|
|
if (!(window->flags & SDL_WINDOW_SHOWN)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->RaiseWindow) {
|
|
|
|
_this->RaiseWindow(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_MaximizeWindow(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_MAXIMIZED) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2013-08-20 19:49:24 -03:00
|
|
|
/* !!! FIXME: should this check if the window is resizable? */
|
2013-08-03 02:20:00 -04:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->MaximizeWindow) {
|
|
|
|
_this->MaximizeWindow(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_MinimizeWindow(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_MINIMIZED) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-02-27 21:17:06 -08:00
|
|
|
SDL_UpdateFullscreenMode(window, SDL_FALSE);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->MinimizeWindow) {
|
|
|
|
_this->MinimizeWindow(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_RestoreWindow(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
|
|
|
if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->RestoreWindow) {
|
|
|
|
_this->RestoreWindow(_this, window);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-12-15 00:30:17 +00:00
|
|
|
SDL_SetWindowFullscreen(SDL_Window * window, Uint32 flags)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2015-11-09 08:54:56 -08:00
|
|
|
Uint32 oldflags;
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
flags &= FULLSCREEN_MASK;
|
|
|
|
|
2014-06-04 10:56:37 -07:00
|
|
|
if (flags == (window->flags & FULLSCREEN_MASK)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
|
|
|
/* clear the previous flags and OR in the new ones */
|
2015-11-09 08:54:56 -08:00
|
|
|
oldflags = window->flags & FULLSCREEN_MASK;
|
2013-05-18 14:17:52 -07:00
|
|
|
window->flags &= ~FULLSCREEN_MASK;
|
2012-12-15 00:30:17 +00:00
|
|
|
window->flags |= flags;
|
|
|
|
|
2015-11-09 08:54:56 -08:00
|
|
|
if (SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window)) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
window->flags &= ~FULLSCREEN_MASK;
|
|
|
|
window->flags |= oldflags;
|
|
|
|
return -1;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
static SDL_Surface *
|
|
|
|
SDL_CreateWindowFramebuffer(SDL_Window * window)
|
|
|
|
{
|
|
|
|
Uint32 format;
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
|
|
|
int bpp;
|
|
|
|
Uint32 Rmask, Gmask, Bmask, Amask;
|
|
|
|
|
|
|
|
if (!_this->CreateWindowFramebuffer || !_this->UpdateWindowFramebuffer) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->CreateWindowFramebuffer(_this, window, &format, &pixels, &pitch) < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SDL_CreateRGBSurfaceFrom(pixels, window->w, window->h, bpp, pitch, Rmask, Gmask, Bmask, Amask);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Surface *
|
|
|
|
SDL_GetWindowSurface(SDL_Window * window)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, NULL);
|
|
|
|
|
2011-02-04 12:24:28 -08:00
|
|
|
if (!window->surface_valid) {
|
|
|
|
if (window->surface) {
|
2011-02-13 13:46:10 -08:00
|
|
|
window->surface->flags &= ~SDL_DONTFREE;
|
2011-02-04 12:24:28 -08:00
|
|
|
SDL_FreeSurface(window->surface);
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
window->surface = SDL_CreateWindowFramebuffer(window);
|
2011-02-03 21:13:55 -08:00
|
|
|
if (window->surface) {
|
2011-02-04 12:24:28 -08:00
|
|
|
window->surface_valid = SDL_TRUE;
|
2011-02-13 13:46:10 -08:00
|
|
|
window->surface->flags |= SDL_DONTFREE;
|
2011-02-03 21:13:55 -08:00
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
return window->surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_UpdateWindowSurface(SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_Rect full_rect;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
full_rect.x = 0;
|
|
|
|
full_rect.y = 0;
|
|
|
|
full_rect.w = window->w;
|
|
|
|
full_rect.h = window->h;
|
2011-02-15 13:59:59 -08:00
|
|
|
return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1);
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-03-19 21:53:33 -07:00
|
|
|
SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects,
|
2011-02-15 13:59:59 -08:00
|
|
|
int numrects)
|
2011-02-03 15:49:37 -08:00
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
2011-02-04 12:24:28 -08:00
|
|
|
if (!window->surface_valid) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface");
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
return _this->UpdateWindowFramebuffer(_this, window, rects, numrects);
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
2011-03-11 08:49:20 -08:00
|
|
|
int
|
|
|
|
SDL_SetWindowBrightness(SDL_Window * window, float brightness)
|
|
|
|
{
|
|
|
|
Uint16 ramp[256];
|
|
|
|
int status;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
SDL_CalculateGammaRamp(brightness, ramp);
|
|
|
|
status = SDL_SetWindowGammaRamp(window, ramp, ramp, ramp);
|
|
|
|
if (status == 0) {
|
|
|
|
window->brightness = brightness;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
SDL_GetWindowBrightness(SDL_Window * window)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, 1.0f);
|
|
|
|
|
|
|
|
return window->brightness;
|
|
|
|
}
|
|
|
|
|
2016-01-05 02:46:10 -05:00
|
|
|
int
|
|
|
|
SDL_SetWindowOpacity(SDL_Window * window, float opacity)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (!_this->SetWindowOpacity) {
|
|
|
|
return SDL_Unsupported();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opacity < 0.0f) {
|
|
|
|
opacity = 0.0f;
|
|
|
|
} else if (opacity > 1.0f) {
|
|
|
|
opacity = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = _this->SetWindowOpacity(_this, window, opacity);
|
|
|
|
if (retval == 0) {
|
|
|
|
window->opacity = opacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetWindowOpacity(SDL_Window * window, float * out_opacity)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (out_opacity) {
|
|
|
|
*out_opacity = window->opacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-21 09:45:58 -04:00
|
|
|
int
|
|
|
|
SDL_SetWindowModalFor(SDL_Window * modal_window, SDL_Window * parent_window)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(modal_window, -1);
|
|
|
|
CHECK_WINDOW_MAGIC(parent_window, -1);
|
|
|
|
|
|
|
|
if (!_this->SetWindowModalFor) {
|
|
|
|
return SDL_Unsupported();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _this->SetWindowModalFor(_this, modal_window, parent_window);
|
|
|
|
}
|
|
|
|
|
2016-01-05 02:28:56 -05:00
|
|
|
int
|
|
|
|
SDL_SetWindowInputFocus(SDL_Window * window)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (!_this->SetWindowInputFocus) {
|
|
|
|
return SDL_Unsupported();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _this->SetWindowInputFocus(_this, window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-11 08:49:20 -08:00
|
|
|
int
|
|
|
|
SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red,
|
|
|
|
const Uint16 * green,
|
|
|
|
const Uint16 * blue)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (!_this->SetWindowGammaRamp) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_Unsupported();
|
2011-03-11 08:49:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!window->gamma) {
|
|
|
|
if (SDL_GetWindowGammaRamp(window, NULL, NULL, NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-04-10 21:40:50 -04:00
|
|
|
SDL_assert(window->gamma != NULL);
|
2011-03-11 08:49:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (red) {
|
|
|
|
SDL_memcpy(&window->gamma[0*256], red, 256*sizeof(Uint16));
|
|
|
|
}
|
|
|
|
if (green) {
|
|
|
|
SDL_memcpy(&window->gamma[1*256], green, 256*sizeof(Uint16));
|
|
|
|
}
|
|
|
|
if (blue) {
|
|
|
|
SDL_memcpy(&window->gamma[2*256], blue, 256*sizeof(Uint16));
|
|
|
|
}
|
|
|
|
if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
|
|
|
|
return _this->SetWindowGammaRamp(_this, window, window->gamma);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetWindowGammaRamp(SDL_Window * window, Uint16 * red,
|
|
|
|
Uint16 * green,
|
|
|
|
Uint16 * blue)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (!window->gamma) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
window->gamma = (Uint16 *)SDL_malloc(256*6*sizeof(Uint16));
|
|
|
|
if (!window->gamma) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_OutOfMemory();
|
2011-03-11 08:49:20 -08:00
|
|
|
}
|
|
|
|
window->saved_gamma = window->gamma + 3*256;
|
|
|
|
|
|
|
|
if (_this->GetWindowGammaRamp) {
|
|
|
|
if (_this->GetWindowGammaRamp(_this, window, window->gamma) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Create an identity gamma ramp */
|
|
|
|
for (i = 0; i < 256; ++i) {
|
|
|
|
Uint16 value = (Uint16)((i << 8) | i);
|
|
|
|
|
|
|
|
window->gamma[0*256+i] = value;
|
|
|
|
window->gamma[1*256+i] = value;
|
|
|
|
window->gamma[2*256+i] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_memcpy(window->saved_gamma, window->gamma, 3*256*sizeof(Uint16));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (red) {
|
|
|
|
SDL_memcpy(red, &window->gamma[0*256], 256*sizeof(Uint16));
|
|
|
|
}
|
|
|
|
if (green) {
|
|
|
|
SDL_memcpy(green, &window->gamma[1*256], 256*sizeof(Uint16));
|
|
|
|
}
|
|
|
|
if (blue) {
|
|
|
|
SDL_memcpy(blue, &window->gamma[2*256], 256*sizeof(Uint16));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-07 15:55:43 -08:00
|
|
|
void
|
2011-02-27 20:06:45 -08:00
|
|
|
SDL_UpdateWindowGrab(SDL_Window * window)
|
|
|
|
{
|
2015-06-15 23:44:08 -07:00
|
|
|
SDL_Window *grabbed_window;
|
|
|
|
SDL_bool grabbed;
|
|
|
|
if ((SDL_GetMouse()->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
|
|
|
|
(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
|
|
|
|
grabbed = SDL_TRUE;
|
|
|
|
} else {
|
|
|
|
grabbed = SDL_FALSE;
|
|
|
|
}
|
2015-03-28 00:48:03 -04:00
|
|
|
|
2015-06-15 23:44:08 -07:00
|
|
|
grabbed_window = _this->grabbed_window;
|
|
|
|
if (grabbed) {
|
|
|
|
if (grabbed_window && (grabbed_window != window)) {
|
|
|
|
/* stealing a grab from another window! */
|
|
|
|
grabbed_window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
|
|
|
|
if (_this->SetWindowGrab) {
|
2015-03-28 00:48:03 -04:00
|
|
|
_this->SetWindowGrab(_this, grabbed_window, SDL_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2015-06-15 23:44:08 -07:00
|
|
|
_this->grabbed_window = window;
|
|
|
|
} else if (grabbed_window == window) {
|
|
|
|
_this->grabbed_window = NULL; /* ungrabbing. */
|
|
|
|
}
|
2015-03-28 00:48:03 -04:00
|
|
|
|
2015-06-15 23:44:08 -07:00
|
|
|
if (_this->SetWindowGrab) {
|
2012-11-07 15:55:43 -08:00
|
|
|
_this->SetWindowGrab(_this, window, grabbed);
|
2011-02-27 20:06:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2011-02-27 20:06:45 -08:00
|
|
|
SDL_SetWindowGrab(SDL_Window * window, SDL_bool grabbed)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2011-02-27 21:17:06 -08:00
|
|
|
if (!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-02-27 20:06:45 -08:00
|
|
|
if (grabbed) {
|
2008-09-15 04:32:36 +00:00
|
|
|
window->flags |= SDL_WINDOW_INPUT_GRABBED;
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_UpdateWindowGrab(window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-02-27 20:06:45 -08:00
|
|
|
SDL_bool
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowGrab(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2011-03-11 08:49:20 -08:00
|
|
|
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
|
2015-03-28 00:48:03 -04:00
|
|
|
SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
|
|
|
|
return window == _this->grabbed_window;
|
|
|
|
}
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2015-03-28 00:48:03 -04:00
|
|
|
SDL_Window *
|
|
|
|
SDL_GetGrabbedWindow(void)
|
|
|
|
{
|
|
|
|
SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
|
|
|
|
return _this->grabbed_window;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowShown(SDL_Window * window)
|
|
|
|
{
|
2011-02-27 21:17:06 -08:00
|
|
|
SDL_OnWindowRestored(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_OnWindowHidden(SDL_Window * window)
|
|
|
|
{
|
2011-02-27 21:17:06 -08:00
|
|
|
SDL_UpdateFullscreenMode(window, SDL_FALSE);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
void
|
|
|
|
SDL_OnWindowResized(SDL_Window * window)
|
|
|
|
{
|
2011-02-04 12:24:28 -08:00
|
|
|
window->surface_valid = SDL_FALSE;
|
2011-02-12 19:02:14 -08:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowMinimized(SDL_Window * window)
|
|
|
|
{
|
2011-02-27 21:17:06 -08:00
|
|
|
SDL_UpdateFullscreenMode(window, SDL_FALSE);
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_OnWindowRestored(SDL_Window * window)
|
|
|
|
{
|
2014-03-26 12:54:51 -07:00
|
|
|
/*
|
|
|
|
* FIXME: Is this fine to just remove this, or should it be preserved just
|
|
|
|
* for the fullscreen case? In principle it seems like just hiding/showing
|
|
|
|
* windows shouldn't affect the stacking order; maybe the right fix is to
|
|
|
|
* re-decouple OnWindowShown and OnWindowRestored.
|
|
|
|
*/
|
2014-03-26 16:19:52 -04:00
|
|
|
/*SDL_RaiseWindow(window);*/
|
2011-02-27 21:17:06 -08:00
|
|
|
|
|
|
|
if (FULLSCREEN_VISIBLE(window)) {
|
|
|
|
SDL_UpdateFullscreenMode(window, SDL_TRUE);
|
|
|
|
}
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 18:14:55 -07:00
|
|
|
void
|
|
|
|
SDL_OnWindowEnter(SDL_Window * window)
|
|
|
|
{
|
|
|
|
if (_this->OnWindowEnter) {
|
|
|
|
_this->OnWindowEnter(_this, window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_OnWindowLeave(SDL_Window * window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowFocusGained(SDL_Window * window)
|
|
|
|
{
|
2013-04-24 12:20:51 -07:00
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
|
|
|
|
2011-03-11 08:49:20 -08:00
|
|
|
if (window->gamma && _this->SetWindowGammaRamp) {
|
|
|
|
_this->SetWindowGammaRamp(_this, window, window->gamma);
|
|
|
|
}
|
|
|
|
|
2013-04-24 12:20:51 -07:00
|
|
|
if (mouse && mouse->relative_mode) {
|
|
|
|
SDL_SetMouseFocus(window);
|
|
|
|
SDL_WarpMouseInWindow(window, window->w/2, window->h/2);
|
|
|
|
}
|
|
|
|
|
2012-11-07 15:55:43 -08:00
|
|
|
SDL_UpdateWindowGrab(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 03:02:42 -08:00
|
|
|
static SDL_bool
|
|
|
|
ShouldMinimizeOnFocusLoss(SDL_Window * window)
|
2012-12-15 00:30:17 +00:00
|
|
|
{
|
2014-01-15 11:34:03 -08:00
|
|
|
if (!(window->flags & SDL_WINDOW_FULLSCREEN) || window->is_destroying) {
|
2013-11-11 03:02:42 -08:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-11-12 02:02:12 -08:00
|
|
|
#ifdef __MACOSX__
|
2017-01-07 19:55:29 -05:00
|
|
|
if (SDL_strcmp(_this->name, "cocoa") == 0) { /* don't do this for X11, etc */
|
|
|
|
if (Cocoa_IsWindowInFullscreenSpace(window)) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
2013-11-11 03:02:42 -08:00
|
|
|
}
|
2013-11-12 02:02:12 -08:00
|
|
|
#endif
|
2013-11-11 03:02:42 -08:00
|
|
|
|
2016-10-07 23:40:44 -07:00
|
|
|
return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_TRUE);
|
2012-12-15 00:30:17 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowFocusLost(SDL_Window * window)
|
|
|
|
{
|
2011-03-11 08:49:20 -08:00
|
|
|
if (window->gamma && _this->SetWindowGammaRamp) {
|
|
|
|
_this->SetWindowGammaRamp(_this, window, window->saved_gamma);
|
2009-12-02 07:42:10 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 15:55:43 -08:00
|
|
|
SDL_UpdateWindowGrab(window);
|
2011-03-11 08:49:20 -08:00
|
|
|
|
2013-11-11 03:02:42 -08:00
|
|
|
if (ShouldMinimizeOnFocusLoss(window)) {
|
2013-08-02 18:25:20 -04:00
|
|
|
SDL_MinimizeWindow(window);
|
2011-03-11 08:49:20 -08:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2014-05-24 01:27:19 -04:00
|
|
|
/* !!! FIXME: is this different than SDL_GetKeyboardFocus()?
|
|
|
|
!!! FIXME: Also, SDL_GetKeyboardFocus() is O(1), this isn't. */
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetFocusWindow(void)
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
for (window = _this->windows; window; window = window->next) {
|
2008-09-15 04:32:36 +00:00
|
|
|
if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
|
2010-01-21 06:21:52 +00:00
|
|
|
return window;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_DestroyWindow(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_VideoDisplay *display;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2009-12-01 09:04:28 +00:00
|
|
|
|
2014-01-15 11:34:03 -08:00
|
|
|
window->is_destroying = SDL_TRUE;
|
|
|
|
|
2012-01-14 01:38:11 -05:00
|
|
|
/* Restore video mode, etc. */
|
|
|
|
SDL_HideWindow(window);
|
|
|
|
|
|
|
|
/* Make sure this window no longer has focus */
|
|
|
|
if (SDL_GetKeyboardFocus() == window) {
|
|
|
|
SDL_SetKeyboardFocus(NULL);
|
|
|
|
}
|
|
|
|
if (SDL_GetMouseFocus() == window) {
|
|
|
|
SDL_SetMouseFocus(NULL);
|
|
|
|
}
|
|
|
|
|
2011-07-15 17:05:32 -07:00
|
|
|
/* make no context current if this is the current context window. */
|
|
|
|
if (window->flags & SDL_WINDOW_OPENGL) {
|
|
|
|
if (_this->current_glwin == window) {
|
2012-09-28 04:03:06 -07:00
|
|
|
SDL_GL_MakeCurrent(window, NULL);
|
2011-07-15 17:05:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 21:13:55 -08:00
|
|
|
if (window->surface) {
|
2011-02-13 13:46:10 -08:00
|
|
|
window->surface->flags &= ~SDL_DONTFREE;
|
2011-02-03 21:13:55 -08:00
|
|
|
SDL_FreeSurface(window->surface);
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
if (_this->DestroyWindowFramebuffer) {
|
|
|
|
_this->DestroyWindowFramebuffer(_this, window);
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
if (_this->DestroyWindow) {
|
|
|
|
_this->DestroyWindow(_this, window);
|
|
|
|
}
|
|
|
|
if (window->flags & SDL_WINDOW_OPENGL) {
|
|
|
|
SDL_GL_UnloadLibrary();
|
|
|
|
}
|
2017-08-27 22:15:57 -04:00
|
|
|
if (window->flags & SDL_WINDOW_VULKAN) {
|
|
|
|
SDL_Vulkan_UnloadLibrary();
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
|
2011-02-10 14:44:25 -08:00
|
|
|
display = SDL_GetDisplayForWindow(window);
|
|
|
|
if (display->fullscreen_window == window) {
|
|
|
|
display->fullscreen_window = NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-27 01:30:42 -07:00
|
|
|
/* Now invalidate magic */
|
2010-09-27 00:49:34 -07:00
|
|
|
window->magic = NULL;
|
|
|
|
|
2011-02-03 11:16:57 -08:00
|
|
|
/* Free memory associated with the window */
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(window->title);
|
2013-08-29 08:29:51 -07:00
|
|
|
SDL_FreeSurface(window->icon);
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(window->gamma);
|
2011-02-03 11:16:57 -08:00
|
|
|
while (window->data) {
|
|
|
|
SDL_WindowUserData *data = window->data;
|
|
|
|
|
|
|
|
window->data = data->next;
|
|
|
|
SDL_free(data->name);
|
|
|
|
SDL_free(data);
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
/* Unlink the window from the list */
|
2010-01-22 16:17:11 +00:00
|
|
|
if (window->next) {
|
|
|
|
window->next->prev = window->prev;
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
if (window->prev) {
|
|
|
|
window->prev->next = window->next;
|
|
|
|
} else {
|
2011-02-10 14:44:25 -08:00
|
|
|
_this->windows = window->next;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
|
|
|
|
SDL_free(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 06:19:05 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_IsScreenSaverEnabled()
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_EnableScreenSaver()
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_this->suspend_screensaver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_this->suspend_screensaver = SDL_FALSE;
|
|
|
|
if (_this->SuspendScreenSaver) {
|
|
|
|
_this->SuspendScreenSaver(_this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_DisableScreenSaver()
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->suspend_screensaver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_this->suspend_screensaver = SDL_TRUE;
|
|
|
|
if (_this->SuspendScreenSaver) {
|
|
|
|
_this->SuspendScreenSaver(_this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_VideoQuit(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-27 22:44:08 -08:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Halt event processing before doing anything else */
|
2013-07-06 12:28:57 -07:00
|
|
|
SDL_TouchQuit();
|
2011-01-27 22:44:08 -08:00
|
|
|
SDL_MouseQuit();
|
|
|
|
SDL_KeyboardQuit();
|
2013-07-06 12:28:57 -07:00
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
2011-01-27 22:44:08 -08:00
|
|
|
|
2009-01-12 08:23:47 +00:00
|
|
|
SDL_EnableScreenSaver();
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
/* Clean up the system video */
|
2011-02-10 14:44:25 -08:00
|
|
|
while (_this->windows) {
|
|
|
|
SDL_DestroyWindow(_this->windows);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
_this->VideoQuit(_this);
|
|
|
|
|
2013-07-13 21:56:31 -04:00
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
for (j = display->num_display_modes; j--;) {
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(display->display_modes[j].driverdata);
|
|
|
|
display->display_modes[j].driverdata = NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(display->display_modes);
|
|
|
|
display->display_modes = NULL;
|
|
|
|
SDL_free(display->desktop_mode.driverdata);
|
|
|
|
display->desktop_mode.driverdata = NULL;
|
|
|
|
SDL_free(display->driverdata);
|
|
|
|
display->driverdata = NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
if (_this->displays) {
|
2012-12-31 11:07:46 -08:00
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
|
SDL_free(_this->displays[i].name);
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_free(_this->displays);
|
|
|
|
_this->displays = NULL;
|
2012-12-31 11:07:46 -08:00
|
|
|
_this->num_displays = 0;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(_this->clipboard_text);
|
|
|
|
_this->clipboard_text = NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->free(_this);
|
|
|
|
_this = NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_LoadLibrary(const char *path)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int retval;
|
2006-07-16 09:34:01 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_UninitializedVideo();
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
if (_this->gl_config.driver_loaded) {
|
|
|
|
if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("OpenGL library already loaded");
|
2009-02-09 05:32:12 +00:00
|
|
|
}
|
|
|
|
retval = 0;
|
2008-09-15 04:32:36 +00:00
|
|
|
} else {
|
2009-02-09 05:32:12 +00:00
|
|
|
if (!_this->GL_LoadLibrary) {
|
2018-04-23 22:29:14 -07:00
|
|
|
return SDL_SetError("No dynamic GL support in current SDL video driver (%s)", _this->name);
|
2009-02-09 05:32:12 +00:00
|
|
|
}
|
|
|
|
retval = _this->GL_LoadLibrary(_this, path);
|
|
|
|
}
|
|
|
|
if (retval == 0) {
|
|
|
|
++_this->gl_config.driver_loaded;
|
2013-10-21 00:15:24 -07:00
|
|
|
} else {
|
|
|
|
if (_this->GL_UnloadLibrary) {
|
|
|
|
_this->GL_UnloadLibrary(_this);
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return (retval);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
void *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GL_GetProcAddress(const char *proc)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
void *func;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
func = NULL;
|
|
|
|
if (_this->GL_GetProcAddress) {
|
|
|
|
if (_this->gl_config.driver_loaded) {
|
|
|
|
func = _this->GL_GetProcAddress(_this, proc);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No GL driver has been loaded");
|
|
|
|
}
|
|
|
|
} else {
|
2018-04-23 22:29:14 -07:00
|
|
|
SDL_SetError("No dynamic GL support in current SDL video driver (%s)", _this->name);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return func;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 05:32:12 +00:00
|
|
|
void
|
|
|
|
SDL_GL_UnloadLibrary(void)
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->gl_config.driver_loaded > 0) {
|
|
|
|
if (--_this->gl_config.driver_loaded > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->GL_UnloadLibrary) {
|
|
|
|
_this->GL_UnloadLibrary(_this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 16:38:45 -05:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
2013-10-20 21:56:15 -07:00
|
|
|
static SDL_INLINE SDL_bool
|
2013-05-22 01:31:04 -04:00
|
|
|
isAtLeastGL3(const char *verstr)
|
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
return (verstr && (SDL_atoi(verstr) >= 3));
|
2013-05-22 01:31:04 -04:00
|
|
|
}
|
2017-03-03 16:38:45 -05:00
|
|
|
#endif
|
2013-05-22 01:31:04 -04:00
|
|
|
|
2006-07-22 21:58:17 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_GL_ExtensionSupported(const char *extension)
|
|
|
|
{
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
2008-09-15 04:32:36 +00:00
|
|
|
const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
|
|
|
|
const char *extensions;
|
|
|
|
const char *start;
|
|
|
|
const char *where, *terminator;
|
|
|
|
|
|
|
|
/* Extension names should not have spaces. */
|
|
|
|
where = SDL_strchr(extension, ' ');
|
|
|
|
if (where || *extension == '\0') {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
/* See if there's an environment variable override */
|
|
|
|
start = SDL_getenv(extension);
|
|
|
|
if (start && *start == '0') {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
2013-05-22 01:31:04 -04:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Lookup the available extensions */
|
2013-05-22 01:31:04 -04:00
|
|
|
|
2018-02-12 17:00:00 +03:00
|
|
|
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
2013-05-22 01:31:04 -04:00
|
|
|
if (!glGetStringFunc) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAtLeastGL3((const char *) glGetStringFunc(GL_VERSION))) {
|
|
|
|
const GLubyte *(APIENTRY * glGetStringiFunc) (GLenum, GLuint);
|
|
|
|
void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
|
|
|
|
GLint num_exts = 0;
|
|
|
|
GLint i;
|
|
|
|
|
2018-02-12 17:00:00 +03:00
|
|
|
glGetStringiFunc = SDL_GL_GetProcAddress("glGetStringi");
|
|
|
|
glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
|
2013-05-22 01:31:04 -04:00
|
|
|
if ((!glGetStringiFunc) || (!glGetIntegervFunc)) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-22 01:36:37 -04:00
|
|
|
#ifndef GL_NUM_EXTENSIONS
|
|
|
|
#define GL_NUM_EXTENSIONS 0x821D
|
|
|
|
#endif
|
2013-05-22 01:31:04 -04:00
|
|
|
glGetIntegervFunc(GL_NUM_EXTENSIONS, &num_exts);
|
|
|
|
for (i = 0; i < num_exts; i++) {
|
|
|
|
const char *thisext = (const char *) glGetStringiFunc(GL_EXTENSIONS, i);
|
|
|
|
if (SDL_strcmp(thisext, extension) == 0) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SDL_FALSE;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2013-05-22 01:31:04 -04:00
|
|
|
|
|
|
|
/* Try the old way with glGetString(GL_EXTENSIONS) ... */
|
|
|
|
|
|
|
|
extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!extensions) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* It takes a bit of care to be fool-proof about parsing the OpenGL
|
|
|
|
* extensions string. Don't be fooled by sub-strings, etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
start = extensions;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
where = SDL_strstr(start, extension);
|
|
|
|
if (!where)
|
|
|
|
break;
|
|
|
|
|
|
|
|
terminator = where + SDL_strlen(extension);
|
2017-08-02 10:22:48 -07:00
|
|
|
if (where == extensions || *(where - 1) == ' ')
|
2008-09-15 04:32:36 +00:00
|
|
|
if (*terminator == ' ' || *terminator == '\0')
|
|
|
|
return SDL_TRUE;
|
|
|
|
|
|
|
|
start = terminator;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2006-07-22 21:58:17 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_FALSE;
|
2006-07-22 21:58:17 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-01-10 08:54:33 -08:00
|
|
|
/* Deduce supported ES profile versions from the supported
|
|
|
|
ARB_ES*_compatibility extensions. There is no direct query.
|
|
|
|
|
|
|
|
This is normally only called when the OpenGL driver supports
|
|
|
|
{GLX,WGL}_EXT_create_context_es2_profile.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor)
|
|
|
|
{
|
2017-09-01 13:27:53 -04:00
|
|
|
/* THIS REQUIRES AN EXISTING GL CONTEXT THAT HAS BEEN MADE CURRENT. */
|
|
|
|
/* Please refer to https://bugzilla.libsdl.org/show_bug.cgi?id=3725 for discussion. */
|
2017-01-10 08:54:33 -08:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
2017-09-10 12:40:45 -07:00
|
|
|
/* XXX This is fragile; it will break in the event of release of
|
|
|
|
* new versions of OpenGL ES.
|
2017-01-10 08:54:33 -08:00
|
|
|
*/
|
|
|
|
if (SDL_GL_ExtensionSupported("GL_ARB_ES3_2_compatibility")) {
|
|
|
|
*major = 3;
|
|
|
|
*minor = 2;
|
|
|
|
} else if (SDL_GL_ExtensionSupported("GL_ARB_ES3_1_compatibility")) {
|
|
|
|
*major = 3;
|
|
|
|
*minor = 1;
|
|
|
|
} else if (SDL_GL_ExtensionSupported("GL_ARB_ES3_compatibility")) {
|
|
|
|
*major = 3;
|
|
|
|
*minor = 0;
|
|
|
|
} else {
|
|
|
|
*major = 2;
|
|
|
|
*minor = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-01-29 18:38:13 -08:00
|
|
|
void
|
|
|
|
SDL_GL_ResetAttributes()
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_this->gl_config.red_size = 3;
|
|
|
|
_this->gl_config.green_size = 3;
|
|
|
|
_this->gl_config.blue_size = 2;
|
|
|
|
_this->gl_config.alpha_size = 0;
|
|
|
|
_this->gl_config.buffer_size = 0;
|
|
|
|
_this->gl_config.depth_size = 16;
|
|
|
|
_this->gl_config.stencil_size = 0;
|
|
|
|
_this->gl_config.double_buffer = 1;
|
|
|
|
_this->gl_config.accum_red_size = 0;
|
|
|
|
_this->gl_config.accum_green_size = 0;
|
|
|
|
_this->gl_config.accum_blue_size = 0;
|
|
|
|
_this->gl_config.accum_alpha_size = 0;
|
|
|
|
_this->gl_config.stereo = 0;
|
|
|
|
_this->gl_config.multisamplebuffers = 0;
|
|
|
|
_this->gl_config.multisamplesamples = 0;
|
|
|
|
_this->gl_config.retained_backing = 1;
|
|
|
|
_this->gl_config.accelerated = -1; /* accelerated or not, both are fine */
|
2017-09-02 19:35:32 -04:00
|
|
|
|
|
|
|
if (_this->GL_DefaultProfileConfig) {
|
|
|
|
_this->GL_DefaultProfileConfig(_this, &_this->gl_config.profile_mask,
|
|
|
|
&_this->gl_config.major_version,
|
|
|
|
&_this->gl_config.minor_version);
|
|
|
|
} else {
|
2014-03-10 18:45:07 -07:00
|
|
|
#if SDL_VIDEO_OPENGL
|
2017-09-02 19:35:32 -04:00
|
|
|
_this->gl_config.major_version = 2;
|
|
|
|
_this->gl_config.minor_version = 1;
|
|
|
|
_this->gl_config.profile_mask = 0;
|
2014-01-29 18:38:13 -08:00
|
|
|
#elif SDL_VIDEO_OPENGL_ES2
|
2017-09-02 19:35:32 -04:00
|
|
|
_this->gl_config.major_version = 2;
|
|
|
|
_this->gl_config.minor_version = 0;
|
|
|
|
_this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
|
2014-01-29 18:38:13 -08:00
|
|
|
#elif SDL_VIDEO_OPENGL_ES
|
2017-09-02 19:35:32 -04:00
|
|
|
_this->gl_config.major_version = 1;
|
|
|
|
_this->gl_config.minor_version = 1;
|
|
|
|
_this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
|
2014-01-29 18:38:13 -08:00
|
|
|
#endif
|
2017-09-02 19:35:32 -04:00
|
|
|
}
|
|
|
|
|
2014-01-29 18:38:13 -08:00
|
|
|
_this->gl_config.flags = 0;
|
|
|
|
_this->gl_config.framebuffer_srgb_capable = 0;
|
2017-08-24 21:30:53 -04:00
|
|
|
_this->gl_config.no_error = 0;
|
2015-03-06 16:03:40 +00:00
|
|
|
_this->gl_config.release_behavior = SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH;
|
2017-08-19 15:02:03 -04:00
|
|
|
_this->gl_config.reset_notification = SDL_GL_CONTEXT_RESET_NO_NOTIFICATION;
|
2014-01-29 18:38:13 -08:00
|
|
|
|
|
|
|
_this->gl_config.share_with_current_context = 0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
|
|
|
|
{
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
2008-09-15 04:32:36 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!_this) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_UninitializedVideo();
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
retval = 0;
|
|
|
|
switch (attr) {
|
|
|
|
case SDL_GL_RED_SIZE:
|
|
|
|
_this->gl_config.red_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_GREEN_SIZE:
|
|
|
|
_this->gl_config.green_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BLUE_SIZE:
|
|
|
|
_this->gl_config.blue_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ALPHA_SIZE:
|
|
|
|
_this->gl_config.alpha_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DOUBLEBUFFER:
|
|
|
|
_this->gl_config.double_buffer = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BUFFER_SIZE:
|
|
|
|
_this->gl_config.buffer_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DEPTH_SIZE:
|
|
|
|
_this->gl_config.depth_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STENCIL_SIZE:
|
|
|
|
_this->gl_config.stencil_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
_this->gl_config.accum_red_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
_this->gl_config.accum_green_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
_this->gl_config.accum_blue_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
_this->gl_config.accum_alpha_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
_this->gl_config.stereo = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLEBUFFERS:
|
|
|
|
_this->gl_config.multisamplebuffers = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLESAMPLES:
|
|
|
|
_this->gl_config.multisamplesamples = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCELERATED_VISUAL:
|
|
|
|
_this->gl_config.accelerated = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_RETAINED_BACKING:
|
|
|
|
_this->gl_config.retained_backing = value;
|
|
|
|
break;
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
case SDL_GL_CONTEXT_MAJOR_VERSION:
|
|
|
|
_this->gl_config.major_version = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_CONTEXT_MINOR_VERSION:
|
|
|
|
_this->gl_config.minor_version = value;
|
|
|
|
break;
|
Improved simultaneous support for OpenGL and OpenGL ES
From Scott Percival
Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.
- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider
This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
2012-07-18 15:17:27 -07:00
|
|
|
case SDL_GL_CONTEXT_EGL:
|
2013-08-29 15:02:32 -03:00
|
|
|
/* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
|
|
|
|
if (value != 0) {
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
|
|
} else {
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
|
|
|
|
};
|
Improved simultaneous support for OpenGL and OpenGL ES
From Scott Percival
Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.
- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider
This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
2012-07-18 15:17:27 -07:00
|
|
|
break;
|
2012-02-20 23:37:57 -05:00
|
|
|
case SDL_GL_CONTEXT_FLAGS:
|
2014-06-04 10:56:37 -07:00
|
|
|
if (value & ~(SDL_GL_CONTEXT_DEBUG_FLAG |
|
|
|
|
SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG |
|
|
|
|
SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG |
|
|
|
|
SDL_GL_CONTEXT_RESET_ISOLATION_FLAG)) {
|
|
|
|
retval = SDL_SetError("Unknown OpenGL context flag %d", value);
|
|
|
|
break;
|
|
|
|
}
|
2012-02-20 23:37:57 -05:00
|
|
|
_this->gl_config.flags = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_CONTEXT_PROFILE_MASK:
|
2014-06-04 10:56:37 -07:00
|
|
|
if (value != 0 &&
|
|
|
|
value != SDL_GL_CONTEXT_PROFILE_CORE &&
|
|
|
|
value != SDL_GL_CONTEXT_PROFILE_COMPATIBILITY &&
|
|
|
|
value != SDL_GL_CONTEXT_PROFILE_ES) {
|
|
|
|
retval = SDL_SetError("Unknown OpenGL context profile %d", value);
|
|
|
|
break;
|
|
|
|
}
|
2012-02-20 23:37:57 -05:00
|
|
|
_this->gl_config.profile_mask = value;
|
|
|
|
break;
|
2012-08-12 11:16:24 -07:00
|
|
|
case SDL_GL_SHARE_WITH_CURRENT_CONTEXT:
|
|
|
|
_this->gl_config.share_with_current_context = value;
|
2013-10-20 21:18:05 -04:00
|
|
|
break;
|
|
|
|
case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE:
|
|
|
|
_this->gl_config.framebuffer_srgb_capable = value;
|
|
|
|
break;
|
2015-03-06 16:03:40 +00:00
|
|
|
case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
|
|
|
|
_this->gl_config.release_behavior = value;
|
2017-08-19 15:02:03 -04:00
|
|
|
break;
|
|
|
|
case SDL_GL_CONTEXT_RESET_NOTIFICATION:
|
|
|
|
_this->gl_config.reset_notification = value;
|
2015-03-06 16:03:40 +00:00
|
|
|
break;
|
2017-08-24 21:30:53 -04:00
|
|
|
case SDL_GL_CONTEXT_NO_ERROR:
|
|
|
|
_this->gl_config.no_error = value;
|
|
|
|
break;
|
2008-09-15 04:32:36 +00:00
|
|
|
default:
|
2013-03-31 12:48:50 -04:00
|
|
|
retval = SDL_SetError("Unknown OpenGL attribute");
|
2008-09-15 04:32:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return retval;
|
2006-07-25 06:22:42 +00:00
|
|
|
#else
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-07-25 06:22:42 +00:00
|
|
|
SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
2015-05-06 12:54:51 -03:00
|
|
|
GLenum (APIENTRY *glGetErrorFunc) (void);
|
2008-09-15 04:32:36 +00:00
|
|
|
GLenum attrib = 0;
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
GLenum error = 0;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2015-05-06 12:54:51 -03:00
|
|
|
/*
|
|
|
|
* Some queries in Core Profile desktop OpenGL 3+ contexts require
|
|
|
|
* glGetFramebufferAttachmentParameteriv instead of glGetIntegerv. Note that
|
|
|
|
* the enums we use for the former function don't exist in OpenGL ES 2, and
|
|
|
|
* the function itself doesn't exist prior to OpenGL 3 and OpenGL ES 2.
|
|
|
|
*/
|
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
const GLubyte *(APIENTRY *glGetStringFunc) (GLenum name);
|
|
|
|
void (APIENTRY *glGetFramebufferAttachmentParameterivFunc) (GLenum target, GLenum attachment, GLenum pname, GLint* params);
|
|
|
|
GLenum attachment = GL_BACK_LEFT;
|
|
|
|
GLenum attachmentattrib = 0;
|
|
|
|
#endif
|
|
|
|
|
2017-07-31 12:57:15 -07:00
|
|
|
if (!value) {
|
|
|
|
return SDL_InvalidParamError("value");
|
|
|
|
}
|
|
|
|
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
/* Clear value in any case */
|
2009-05-23 22:41:08 +00:00
|
|
|
*value = 0;
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
|
2017-07-31 12:57:15 -07:00
|
|
|
if (!_this) {
|
|
|
|
return SDL_UninitializedVideo();
|
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
switch (attr) {
|
|
|
|
case SDL_GL_RED_SIZE:
|
2015-05-06 12:54:51 -03:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE;
|
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_RED_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BLUE_SIZE:
|
2015-05-06 12:54:51 -03:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE;
|
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_BLUE_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_GREEN_SIZE:
|
2015-05-06 12:54:51 -03:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE;
|
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_GREEN_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ALPHA_SIZE:
|
2015-05-06 12:54:51 -03:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE;
|
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_ALPHA_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DOUBLEBUFFER:
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_DOUBLEBUFFER;
|
|
|
|
break;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
/* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */
|
|
|
|
/* parameter which switches double buffer to single buffer. OpenGL ES */
|
|
|
|
/* SDL driver must set proper value after initialization */
|
|
|
|
*value = _this->gl_config.double_buffer;
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_DEPTH_SIZE:
|
2015-05-06 12:54:51 -03:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
attachment = GL_DEPTH;
|
|
|
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE;
|
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_DEPTH_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STENCIL_SIZE:
|
2015-05-06 12:54:51 -03:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
attachment = GL_STENCIL;
|
|
|
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE;
|
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_STENCIL_BITS;
|
|
|
|
break;
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
attrib = GL_ACCUM_RED_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
attrib = GL_ACCUM_GREEN_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
attrib = GL_ACCUM_BLUE_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
attrib = GL_ACCUM_ALPHA_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
attrib = GL_STEREO;
|
|
|
|
break;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
/* none of these are supported in OpenGL ES */
|
|
|
|
*value = 0;
|
|
|
|
return 0;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_MULTISAMPLEBUFFERS:
|
|
|
|
attrib = GL_SAMPLE_BUFFERS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLESAMPLES:
|
|
|
|
attrib = GL_SAMPLES;
|
2015-03-06 16:03:40 +00:00
|
|
|
break;
|
|
|
|
case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
|
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
attrib = GL_CONTEXT_RELEASE_BEHAVIOR;
|
|
|
|
#else
|
|
|
|
attrib = GL_CONTEXT_RELEASE_BEHAVIOR_KHR;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
break;
|
|
|
|
case SDL_GL_BUFFER_SIZE:
|
|
|
|
{
|
2015-05-06 12:54:51 -03:00
|
|
|
int rsize = 0, gsize = 0, bsize = 0, asize = 0;
|
|
|
|
|
|
|
|
/* There doesn't seem to be a single flag in OpenGL for this! */
|
|
|
|
if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &rsize) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &gsize) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &bsize) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &asize) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = rsize + gsize + bsize + asize;
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SDL_GL_ACCELERATED_VISUAL:
|
|
|
|
{
|
|
|
|
/* FIXME: How do we get this information? */
|
2009-12-15 20:53:09 +00:00
|
|
|
*value = (_this->gl_config.accelerated != 0);
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-06 10:24:08 -08:00
|
|
|
case SDL_GL_RETAINED_BACKING:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.retained_backing;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SDL_GL_CONTEXT_MAJOR_VERSION:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.major_version;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SDL_GL_CONTEXT_MINOR_VERSION:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.minor_version;
|
|
|
|
return 0;
|
|
|
|
}
|
Improved simultaneous support for OpenGL and OpenGL ES
From Scott Percival
Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.
- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider
This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
2012-07-18 15:17:27 -07:00
|
|
|
case SDL_GL_CONTEXT_EGL:
|
2013-08-29 15:02:32 -03:00
|
|
|
/* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
|
Improved simultaneous support for OpenGL and OpenGL ES
From Scott Percival
Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.
- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider
This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
2012-07-18 15:17:27 -07:00
|
|
|
{
|
2013-08-29 15:02:32 -03:00
|
|
|
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
|
|
|
|
*value = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*value = 0;
|
|
|
|
}
|
Improved simultaneous support for OpenGL and OpenGL ES
From Scott Percival
Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.
- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider
This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
2012-07-18 15:17:27 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2012-02-20 23:37:57 -05:00
|
|
|
case SDL_GL_CONTEXT_FLAGS:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.flags;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SDL_GL_CONTEXT_PROFILE_MASK:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.profile_mask;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-08-12 11:16:24 -07:00
|
|
|
case SDL_GL_SHARE_WITH_CURRENT_CONTEXT:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.share_with_current_context;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-10-20 21:18:05 -04:00
|
|
|
case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.framebuffer_srgb_capable;
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-24 21:30:53 -04:00
|
|
|
case SDL_GL_CONTEXT_NO_ERROR:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.no_error;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
default:
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("Unknown OpenGL attribute");
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
|
2015-05-06 12:54:51 -03:00
|
|
|
#if SDL_VIDEO_OPENGL
|
2018-02-12 17:00:00 +03:00
|
|
|
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
2015-12-10 20:25:34 -04:00
|
|
|
if (!glGetStringFunc) {
|
2017-08-12 15:55:54 -07:00
|
|
|
return -1;
|
2015-12-10 20:25:34 -04:00
|
|
|
}
|
|
|
|
|
2015-05-06 12:54:51 -03:00
|
|
|
if (attachmentattrib && isAtLeastGL3((const char *) glGetStringFunc(GL_VERSION))) {
|
2018-02-12 17:00:00 +03:00
|
|
|
glGetFramebufferAttachmentParameterivFunc = SDL_GL_GetProcAddress("glGetFramebufferAttachmentParameteriv");
|
2015-05-06 12:54:51 -03:00
|
|
|
|
|
|
|
if (glGetFramebufferAttachmentParameterivFunc) {
|
|
|
|
glGetFramebufferAttachmentParameterivFunc(GL_FRAMEBUFFER, attachment, attachmentattrib, (GLint *) value);
|
|
|
|
} else {
|
2017-08-12 15:55:54 -07:00
|
|
|
return -1;
|
2015-05-06 12:54:51 -03:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2015-05-26 10:25:15 -04:00
|
|
|
void (APIENTRY *glGetIntegervFunc) (GLenum pname, GLint * params);
|
2018-02-12 17:00:00 +03:00
|
|
|
glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
|
2015-05-26 10:25:15 -04:00
|
|
|
if (glGetIntegervFunc) {
|
|
|
|
glGetIntegervFunc(attrib, (GLint *) value);
|
|
|
|
} else {
|
2017-08-12 15:55:54 -07:00
|
|
|
return -1;
|
2015-05-26 10:25:15 -04:00
|
|
|
}
|
2015-05-06 12:54:51 -03:00
|
|
|
}
|
|
|
|
|
2018-02-12 17:00:00 +03:00
|
|
|
glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
|
2015-12-10 20:25:34 -04:00
|
|
|
if (!glGetErrorFunc) {
|
2017-08-12 15:55:54 -07:00
|
|
|
return -1;
|
2015-12-10 20:25:34 -04:00
|
|
|
}
|
|
|
|
|
2009-05-23 22:41:08 +00:00
|
|
|
error = glGetErrorFunc();
|
|
|
|
if (error != GL_NO_ERROR) {
|
2013-03-31 12:48:50 -04:00
|
|
|
if (error == GL_INVALID_ENUM) {
|
|
|
|
return SDL_SetError("OpenGL error: GL_INVALID_ENUM");
|
|
|
|
} else if (error == GL_INVALID_VALUE) {
|
|
|
|
return SDL_SetError("OpenGL error: GL_INVALID_VALUE");
|
2009-05-23 22:41:08 +00:00
|
|
|
}
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("OpenGL error: %08X", error);
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
2006-07-25 06:22:42 +00:00
|
|
|
#else
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 09:34:01 +00:00
|
|
|
SDL_GLContext
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GL_CreateContext(SDL_Window * window)
|
2006-07-16 09:34:01 +00:00
|
|
|
{
|
2011-07-18 14:30:46 -07:00
|
|
|
SDL_GLContext ctx = NULL;
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, NULL);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-18 14:30:46 -07:00
|
|
|
|
|
|
|
ctx = _this->GL_CreateContext(_this, window);
|
|
|
|
|
|
|
|
/* Creating a context is assumed to make it current in the SDL driver. */
|
2013-07-12 23:28:34 -07:00
|
|
|
if (ctx) {
|
|
|
|
_this->current_glwin = window;
|
|
|
|
_this->current_glctx = ctx;
|
|
|
|
SDL_TLSSet(_this->current_glwin_tls, window, NULL);
|
|
|
|
SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
|
|
|
|
}
|
2011-07-18 14:30:46 -07:00
|
|
|
return ctx;
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-07-15 17:05:32 -07:00
|
|
|
SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
|
2006-07-16 09:34:01 +00:00
|
|
|
{
|
2011-07-15 17:05:32 -07:00
|
|
|
int retval;
|
2013-07-11 22:59:20 -07:00
|
|
|
|
|
|
|
if (window == SDL_GL_GetCurrentWindow() &&
|
|
|
|
ctx == SDL_GL_GetCurrentContext()) {
|
|
|
|
/* We're already current. */
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-15 17:05:32 -07:00
|
|
|
|
|
|
|
if (!ctx) {
|
2008-09-15 04:32:36 +00:00
|
|
|
window = NULL;
|
2013-04-22 18:15:08 -07:00
|
|
|
} else {
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
return SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2011-07-15 17:05:32 -07:00
|
|
|
|
2013-07-11 22:59:20 -07:00
|
|
|
retval = _this->GL_MakeCurrent(_this, window, ctx);
|
|
|
|
if (retval == 0) {
|
|
|
|
_this->current_glwin = window;
|
|
|
|
_this->current_glctx = ctx;
|
|
|
|
SDL_TLSSet(_this->current_glwin_tls, window, NULL);
|
|
|
|
SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
|
2011-07-15 17:05:32 -07:00
|
|
|
}
|
|
|
|
return retval;
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 22:59:20 -07:00
|
|
|
SDL_Window *
|
|
|
|
SDL_GL_GetCurrentWindow(void)
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (SDL_Window *)SDL_TLSGet(_this->current_glwin_tls);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_GLContext
|
|
|
|
SDL_GL_GetCurrentContext(void)
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (SDL_GLContext)SDL_TLSGet(_this->current_glctx_tls);
|
|
|
|
}
|
|
|
|
|
2013-09-20 13:43:00 -04:00
|
|
|
void SDL_GL_GetDrawableSize(SDL_Window * window, int *w, int *h)
|
|
|
|
{
|
2014-06-04 10:56:37 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2013-09-20 13:43:00 -04:00
|
|
|
|
|
|
|
if (_this->GL_GetDrawableSize) {
|
|
|
|
_this->GL_GetDrawableSize(_this, window, w, h);
|
|
|
|
} else {
|
|
|
|
SDL_GetWindowSize(window, w, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-16 09:34:01 +00:00
|
|
|
int
|
|
|
|
SDL_GL_SetSwapInterval(int interval)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_UninitializedVideo();
|
2013-07-11 22:59:20 -07:00
|
|
|
} else if (SDL_GL_GetCurrentContext() == NULL) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("No OpenGL context has been made current");
|
2011-07-18 14:31:37 -07:00
|
|
|
} else if (_this->GL_SetSwapInterval) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return _this->GL_SetSwapInterval(_this, interval);
|
|
|
|
} else {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("Setting the swap interval is not supported");
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_GetSwapInterval(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
2012-08-01 20:29:36 -04:00
|
|
|
return 0;
|
2013-07-11 22:59:20 -07:00
|
|
|
} else if (SDL_GL_GetCurrentContext() == NULL) {
|
2012-08-01 20:29:36 -04:00
|
|
|
return 0;
|
2011-07-18 14:31:37 -07:00
|
|
|
} else if (_this->GL_GetSwapInterval) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return _this->GL_GetSwapInterval(_this);
|
|
|
|
} else {
|
2012-08-01 20:29:36 -04:00
|
|
|
return 0;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 12:01:44 -08:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GL_SwapWindow(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2016-12-11 12:01:44 -08:00
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
2016-12-11 12:01:44 -08:00
|
|
|
SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
return;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2013-08-07 16:29:28 -07:00
|
|
|
|
|
|
|
if (SDL_GL_GetCurrentWindow() != window) {
|
2016-12-11 12:01:44 -08:00
|
|
|
SDL_SetError("The specified window has not been made current");
|
|
|
|
return;
|
2013-08-07 16:29:28 -07:00
|
|
|
}
|
|
|
|
|
2016-12-11 12:01:44 -08:00
|
|
|
_this->GL_SwapWindow(_this, window);
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_GL_DeleteContext(SDL_GLContext context)
|
|
|
|
{
|
2012-09-30 01:08:48 -07:00
|
|
|
if (!_this || !context) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-04-22 18:15:08 -07:00
|
|
|
|
2013-07-11 22:59:20 -07:00
|
|
|
if (SDL_GL_GetCurrentContext() == context) {
|
2013-04-22 18:15:08 -07:00
|
|
|
SDL_GL_MakeCurrent(NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->GL_DeleteContext(_this, context);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
#if 0 /* FIXME */
|
2008-09-02 20:11:06 +00:00
|
|
|
/*
|
|
|
|
* Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
|
|
|
|
* & 2 for alpha channel.
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
|
|
|
CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int x, y;
|
|
|
|
Uint32 colorkey;
|
2006-07-10 21:04:37 +00:00
|
|
|
#define SET_MASKBIT(icon, x, y, mask) \
|
2013-05-18 14:17:52 -07:00
|
|
|
mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
colorkey = icon->format->colorkey;
|
|
|
|
switch (icon->format->BytesPerPixel) {
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
Uint8 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint8 *) icon->pixels + y * icon->pitch;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if (*pixels++ == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
Uint16 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if ((flags & 1) && *pixels == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
} else if ((flags & 2)
|
|
|
|
&& (*pixels & icon->format->Amask) == 0) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
pixels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
Uint32 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if ((flags & 1) && *pixels == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
} else if ((flags & 2)
|
|
|
|
&& (*pixels & icon->format->Amask) == 0) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
pixels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-07-10 21:04:37 +00:00
|
|
|
* Sets the window manager icon for the display window.
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (icon && _this->SetIcon) {
|
|
|
|
/* Generate a mask if necessary, and create the icon! */
|
|
|
|
if (mask == NULL) {
|
|
|
|
int mask_len = icon->h * (icon->w + 7) / 8;
|
|
|
|
int flags = 0;
|
|
|
|
mask = (Uint8 *) SDL_malloc(mask_len);
|
|
|
|
if (mask == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SDL_memset(mask, ~0, mask_len);
|
|
|
|
if (icon->flags & SDL_SRCCOLORKEY)
|
|
|
|
flags |= 1;
|
|
|
|
if (icon->flags & SDL_SRCALPHA)
|
|
|
|
flags |= 2;
|
|
|
|
if (flags) {
|
|
|
|
CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
|
|
|
|
}
|
|
|
|
_this->SetIcon(_this, icon, mask);
|
|
|
|
SDL_free(mask);
|
|
|
|
} else {
|
|
|
|
_this->SetIcon(_this, icon, mask);
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SDL_bool
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
|
|
|
|
|
2010-09-27 01:24:05 -07:00
|
|
|
if (!info) {
|
2014-10-15 09:14:09 -07:00
|
|
|
SDL_InvalidParamError("info");
|
2010-09-27 01:24:05 -07:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
info->subsystem = SDL_SYSWM_UNKNOWN;
|
|
|
|
|
2010-01-24 20:21:51 +00:00
|
|
|
if (!_this->GetWindowWMInfo) {
|
2014-10-15 09:14:09 -07:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
return (_this->GetWindowWMInfo(_this, window, info));
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2009-09-19 13:29:40 +00:00
|
|
|
void
|
|
|
|
SDL_StartTextInput(void)
|
|
|
|
{
|
2012-11-04 21:53:28 -08:00
|
|
|
SDL_Window *window;
|
|
|
|
|
|
|
|
/* First, enable text events */
|
|
|
|
SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
|
|
|
|
SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
|
|
|
|
|
|
|
|
/* Then show the on-screen keyboard, if any */
|
|
|
|
window = SDL_GetFocusWindow();
|
2013-05-02 23:12:03 +02:00
|
|
|
if (window && _this && _this->ShowScreenKeyboard) {
|
|
|
|
_this->ShowScreenKeyboard(_this, window);
|
2012-11-04 21:53:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally start the text input system */
|
2010-01-19 07:28:51 +00:00
|
|
|
if (_this && _this->StartTextInput) {
|
2009-09-19 13:29:40 +00:00
|
|
|
_this->StartTextInput(_this);
|
|
|
|
}
|
2012-11-04 21:53:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_bool
|
|
|
|
SDL_IsTextInputActive(void)
|
|
|
|
{
|
|
|
|
return (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE);
|
2009-09-19 13:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_StopTextInput(void)
|
|
|
|
{
|
2012-11-04 21:53:28 -08:00
|
|
|
SDL_Window *window;
|
|
|
|
|
|
|
|
/* Stop the text input system */
|
2010-01-19 07:28:51 +00:00
|
|
|
if (_this && _this->StopTextInput) {
|
2009-09-19 13:29:40 +00:00
|
|
|
_this->StopTextInput(_this);
|
|
|
|
}
|
2012-11-04 21:53:28 -08:00
|
|
|
|
|
|
|
/* Hide the on-screen keyboard, if any */
|
|
|
|
window = SDL_GetFocusWindow();
|
2013-05-02 23:12:03 +02:00
|
|
|
if (window && _this && _this->HideScreenKeyboard) {
|
|
|
|
_this->HideScreenKeyboard(_this, window);
|
2012-11-04 21:53:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally disable text events */
|
2009-09-19 13:29:40 +00:00
|
|
|
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
|
|
|
|
SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_SetTextInputRect(SDL_Rect *rect)
|
|
|
|
{
|
2010-01-19 07:28:51 +00:00
|
|
|
if (_this && _this->SetTextInputRect) {
|
2009-09-19 13:29:40 +00:00
|
|
|
_this->SetTextInputRect(_this, rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 10:15:59 -07:00
|
|
|
SDL_bool
|
2012-11-04 21:53:28 -08:00
|
|
|
SDL_HasScreenKeyboardSupport(void)
|
2012-08-11 10:15:59 -07:00
|
|
|
{
|
2013-05-02 23:12:03 +02:00
|
|
|
if (_this && _this->HasScreenKeyboardSupport) {
|
|
|
|
return _this->HasScreenKeyboardSupport(_this);
|
2012-08-11 10:15:59 -07:00
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_bool
|
|
|
|
SDL_IsScreenKeyboardShown(SDL_Window *window)
|
|
|
|
{
|
2013-05-02 23:12:03 +02:00
|
|
|
if (window && _this && _this->IsScreenKeyboardShown) {
|
|
|
|
return _this->IsScreenKeyboardShown(_this, window);
|
2012-08-11 10:15:59 -07:00
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-09-13 02:15:18 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_ANDROID
|
|
|
|
#include "android/SDL_androidmessagebox.h"
|
|
|
|
#endif
|
2012-10-30 18:59:56 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_WINDOWS
|
|
|
|
#include "windows/SDL_windowsmessagebox.h"
|
|
|
|
#endif
|
2014-03-23 22:07:01 -04:00
|
|
|
#if SDL_VIDEO_DRIVER_WINRT
|
|
|
|
#include "winrt/SDL_winrtmessagebox.h"
|
|
|
|
#endif
|
2012-10-30 12:31:26 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_COCOA
|
|
|
|
#include "cocoa/SDL_cocoamessagebox.h"
|
|
|
|
#endif
|
2012-10-30 13:44:59 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_UIKIT
|
|
|
|
#include "uikit/SDL_uikitmessagebox.h"
|
|
|
|
#endif
|
2012-10-23 17:11:22 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_X11
|
2012-10-30 12:31:26 -07:00
|
|
|
#include "x11/SDL_x11messagebox.h"
|
2012-10-23 17:11:22 -07:00
|
|
|
#endif
|
|
|
|
|
2016-11-13 22:57:41 -08:00
|
|
|
|
|
|
|
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT || SDL_VIDEO_DRIVER_COCOA || SDL_VIDEO_DRIVER_UIKIT || SDL_VIDEO_DRIVER_X11
|
|
|
|
static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
|
2013-07-14 11:41:57 -07:00
|
|
|
{
|
|
|
|
SDL_SysWMinfo info;
|
|
|
|
SDL_Window *window = messageboxdata->window;
|
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_VERSION(&info.version);
|
2013-07-23 17:40:13 -07:00
|
|
|
if (!SDL_GetWindowWMInfo(window, &info)) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
} else {
|
|
|
|
return (info.subsystem == drivertype);
|
|
|
|
}
|
2013-07-14 11:41:57 -07:00
|
|
|
}
|
2016-11-13 22:57:41 -08:00
|
|
|
#endif
|
2013-07-14 11:41:57 -07:00
|
|
|
|
2012-10-23 17:11:22 -07:00
|
|
|
int
|
|
|
|
SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|
|
|
{
|
|
|
|
int dummybutton;
|
2013-05-18 14:17:52 -07:00
|
|
|
int retval = -1;
|
2013-07-14 11:11:42 -07:00
|
|
|
SDL_bool relative_mode;
|
|
|
|
int show_cursor_prev;
|
2014-05-24 01:30:37 -04:00
|
|
|
SDL_bool mouse_captured;
|
|
|
|
SDL_Window *current_window;
|
2013-02-14 13:22:05 -08:00
|
|
|
|
2013-07-14 11:11:42 -07:00
|
|
|
if (!messageboxdata) {
|
|
|
|
return SDL_InvalidParamError("messageboxdata");
|
Fixed bug 3804 - Message box on Windows truncates button ID
Simon Hug
I just wanted to fix a simple compiler warning in SDL_ShowMessageBox on Windows (which Sam fixed recently) and ended up finding some issues.
Attached patch fixes these issues:
- Because Windows only reports the lower 16 bits of the control identifier that was pushed, the button IDs used by SDL (C type int, most likely 32 bits) can get cut off.
- The documentation states (somewhat ambiguously) that the button ID will be -1 if the dialog was closed, but the current code sets 0. For SDL 2.1, I think this should be a return code of SDL_ShowMessageBox itself. That will free up the button ID and it seems a more appropriate place for signaling this event.
- Ampersands in controls will create mnemonics on Windows (underlined letters that, if combined with the Alt key, will push the button). I was thinking of adding a hint or flag to let the users enable it, but that might have unexpected results.
- When the size of the text gets calculated, it doesn't use the same parameters as the static control. This can cut off text or wrap it weirdly.
- On Windows, the Tab key is used to switch between control groups and sometimes between buttons in dialogs. This didn't seem to work correctly.
Attached patch also adds:
- Icons. Just the system ones that can be loaded with the ordinals IDI_ERROR, IDI_WARNING and IDI_INFORMATION.
- A button limit of 2^16 - 101.
- Some more specific error messages, but they never reach the user because how SDL_ShowMessageBox handles them if an implementation returns with an error.
2018-03-24 10:26:40 -07:00
|
|
|
} else if (messageboxdata->numbuttons < 0) {
|
|
|
|
return SDL_SetError("Invalid number of buttons");
|
2013-07-14 11:11:42 -07:00
|
|
|
}
|
|
|
|
|
2014-05-24 01:30:37 -04:00
|
|
|
current_window = SDL_GetKeyboardFocus();
|
|
|
|
mouse_captured = current_window && ((SDL_GetWindowFlags(current_window) & SDL_WINDOW_MOUSE_CAPTURE) != 0);
|
2013-07-14 11:11:42 -07:00
|
|
|
relative_mode = SDL_GetRelativeMouseMode();
|
2014-05-24 01:30:37 -04:00
|
|
|
SDL_CaptureMouse(SDL_FALSE);
|
2013-07-14 11:11:42 -07:00
|
|
|
SDL_SetRelativeMouseMode(SDL_FALSE);
|
|
|
|
show_cursor_prev = SDL_ShowCursor(1);
|
2015-05-26 20:49:27 -04:00
|
|
|
SDL_ResetKeyboard();
|
2012-10-23 17:11:22 -07:00
|
|
|
|
|
|
|
if (!buttonid) {
|
|
|
|
buttonid = &dummybutton;
|
|
|
|
}
|
2013-07-14 11:41:57 -07:00
|
|
|
|
2012-10-23 17:11:22 -07:00
|
|
|
if (_this && _this->ShowMessageBox) {
|
2013-07-14 11:11:42 -07:00
|
|
|
retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
|
2013-07-14 11:41:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* It's completely fine to call this function before video is initialized */
|
2014-09-13 02:15:18 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_ANDROID
|
|
|
|
if (retval == -1 &&
|
|
|
|
Android_ShowMessageBox(messageboxdata, buttonid) == 0) {
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-30 18:59:56 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_WINDOWS
|
2013-07-14 11:41:57 -07:00
|
|
|
if (retval == -1 &&
|
|
|
|
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
|
|
|
|
WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
|
|
|
|
retval = 0;
|
|
|
|
}
|
2012-10-30 18:59:56 -07:00
|
|
|
#endif
|
2014-03-23 22:07:01 -04:00
|
|
|
#if SDL_VIDEO_DRIVER_WINRT
|
|
|
|
if (retval == -1 &&
|
|
|
|
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINRT) &&
|
|
|
|
WINRT_ShowMessageBox(messageboxdata, buttonid) == 0) {
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-30 12:31:26 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_COCOA
|
2013-07-14 11:41:57 -07:00
|
|
|
if (retval == -1 &&
|
|
|
|
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
|
|
|
|
Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
|
|
|
|
retval = 0;
|
|
|
|
}
|
2012-10-30 12:31:26 -07:00
|
|
|
#endif
|
2012-10-30 13:44:59 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_UIKIT
|
2013-07-14 11:41:57 -07:00
|
|
|
if (retval == -1 &&
|
|
|
|
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
|
|
|
|
UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
|
|
|
|
retval = 0;
|
|
|
|
}
|
2012-10-30 13:44:59 -07:00
|
|
|
#endif
|
2012-10-23 17:11:22 -07:00
|
|
|
#if SDL_VIDEO_DRIVER_X11
|
2013-07-14 11:41:57 -07:00
|
|
|
if (retval == -1 &&
|
|
|
|
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
|
|
|
|
X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
|
|
|
|
retval = 0;
|
|
|
|
}
|
2012-10-23 17:11:22 -07:00
|
|
|
#endif
|
2013-07-14 11:41:57 -07:00
|
|
|
if (retval == -1) {
|
|
|
|
SDL_SetError("No message system available");
|
2013-07-14 11:11:42 -07:00
|
|
|
}
|
2012-10-23 17:11:22 -07:00
|
|
|
|
2014-05-24 01:30:37 -04:00
|
|
|
if (current_window) {
|
|
|
|
SDL_RaiseWindow(current_window);
|
|
|
|
if (mouse_captured) {
|
|
|
|
SDL_CaptureMouse(SDL_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-14 11:11:42 -07:00
|
|
|
SDL_ShowCursor(show_cursor_prev);
|
|
|
|
SDL_SetRelativeMouseMode(relative_mode);
|
2013-02-14 13:22:05 -08:00
|
|
|
|
|
|
|
return retval;
|
2012-10-23 17:11:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window)
|
|
|
|
{
|
2016-09-06 13:13:03 -04:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
/* !!! FIXME: propose a browser API for this, get this #ifdef out of here? */
|
|
|
|
/* Web browsers don't (currently) have an API for a custom message box
|
|
|
|
that can block, but for the most common case (SDL_ShowSimpleMessageBox),
|
|
|
|
we can use the standard Javascript alert() function. */
|
|
|
|
EM_ASM_({
|
|
|
|
alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1));
|
|
|
|
}, title, message);
|
|
|
|
return 0;
|
|
|
|
#else
|
2012-10-23 17:11:22 -07:00
|
|
|
SDL_MessageBoxData data;
|
|
|
|
SDL_MessageBoxButtonData button;
|
|
|
|
|
|
|
|
SDL_zero(data);
|
|
|
|
data.flags = flags;
|
|
|
|
data.title = title;
|
|
|
|
data.message = message;
|
|
|
|
data.numbuttons = 1;
|
|
|
|
data.buttons = &button;
|
|
|
|
data.window = window;
|
|
|
|
|
|
|
|
SDL_zero(button);
|
|
|
|
button.flags |= SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
|
|
|
|
button.flags |= SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
|
|
|
|
button.text = "OK";
|
|
|
|
|
|
|
|
return SDL_ShowMessageBox(&data, NULL);
|
2016-09-06 13:13:03 -04:00
|
|
|
#endif
|
2012-10-23 17:11:22 -07:00
|
|
|
}
|
|
|
|
|
2012-12-31 10:14:38 -08:00
|
|
|
SDL_bool
|
2013-05-15 22:25:00 +02:00
|
|
|
SDL_ShouldAllowTopmost(void)
|
2012-12-31 10:14:38 -08:00
|
|
|
{
|
2016-10-07 23:40:44 -07:00
|
|
|
return SDL_GetHintBoolean(SDL_HINT_ALLOW_TOPMOST, SDL_TRUE);
|
2012-12-31 10:14:38 -08:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:27:42 -04:00
|
|
|
int
|
2014-05-28 01:22:47 -04:00
|
|
|
SDL_SetWindowHitTest(SDL_Window * window, SDL_HitTest callback, void *userdata)
|
2014-05-27 01:27:42 -04:00
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
2014-05-28 01:22:47 -04:00
|
|
|
if (!_this->SetWindowHitTest) {
|
2014-05-27 01:27:42 -04:00
|
|
|
return SDL_Unsupported();
|
2014-05-28 01:22:47 -04:00
|
|
|
} else if (_this->SetWindowHitTest(window, callback != NULL) == -1) {
|
2014-05-27 01:27:42 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:22:47 -04:00
|
|
|
window->hit_test = callback;
|
|
|
|
window->hit_test_data = userdata;
|
|
|
|
|
|
|
|
return 0;
|
2014-05-27 01:27:42 -04:00
|
|
|
}
|
|
|
|
|
2017-01-04 09:33:47 -05:00
|
|
|
float
|
|
|
|
SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
|
2015-07-29 17:18:56 -07:00
|
|
|
{
|
2017-09-10 12:40:45 -07:00
|
|
|
float den2 = hinches * hinches + vinches * vinches;
|
|
|
|
if (den2 <= 0.0f) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (float)(SDL_sqrt((double)hpix * (double)hpix + (double)vpix * (double)vpix) /
|
|
|
|
SDL_sqrt((double)den2));
|
2015-07-29 17:18:56 -07:00
|
|
|
}
|
|
|
|
|
2017-05-09 03:19:58 -07:00
|
|
|
/*
|
|
|
|
* Functions used by iOS application delegates
|
|
|
|
*/
|
2017-07-15 17:41:58 -03:00
|
|
|
void SDL_OnApplicationWillTerminate(void)
|
2017-05-09 10:10:42 -07:00
|
|
|
{
|
|
|
|
SDL_SendAppEvent(SDL_APP_TERMINATING);
|
|
|
|
}
|
|
|
|
|
2017-07-15 17:41:58 -03:00
|
|
|
void SDL_OnApplicationDidReceiveMemoryWarning(void)
|
2017-05-09 10:10:42 -07:00
|
|
|
{
|
|
|
|
SDL_SendAppEvent(SDL_APP_LOWMEMORY);
|
|
|
|
}
|
|
|
|
|
2017-07-15 17:41:58 -03:00
|
|
|
void SDL_OnApplicationWillResignActive(void)
|
2017-05-09 10:10:42 -07:00
|
|
|
{
|
|
|
|
if (_this) {
|
|
|
|
SDL_Window *window;
|
|
|
|
for (window = _this->windows; window != NULL; window = window->next) {
|
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
|
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
|
|
|
|
}
|
|
|
|
|
2017-07-15 17:41:58 -03:00
|
|
|
void SDL_OnApplicationDidEnterBackground(void)
|
2017-05-09 10:10:42 -07:00
|
|
|
{
|
|
|
|
SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
|
|
|
|
}
|
|
|
|
|
2017-07-15 17:41:58 -03:00
|
|
|
void SDL_OnApplicationWillEnterForeground(void)
|
2017-05-09 10:10:42 -07:00
|
|
|
{
|
|
|
|
SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
|
|
|
|
}
|
|
|
|
|
2017-07-15 17:41:58 -03:00
|
|
|
void SDL_OnApplicationDidBecomeActive(void)
|
2017-05-09 10:10:42 -07:00
|
|
|
{
|
|
|
|
SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
|
|
|
|
|
|
|
|
if (_this) {
|
|
|
|
SDL_Window *window;
|
|
|
|
for (window = _this->windows; window != NULL; window = window->next) {
|
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
|
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-27 23:39:55 -07:00
|
|
|
#define NOT_A_VULKAN_WINDOW "The specified window isn't a Vulkan window"
|
2017-08-27 22:15:57 -04:00
|
|
|
|
|
|
|
int SDL_Vulkan_LoadLibrary(const char *path)
|
|
|
|
{
|
|
|
|
int retval;
|
2017-08-27 23:39:55 -07:00
|
|
|
if (!_this) {
|
2017-08-27 22:15:57 -04:00
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (_this->vulkan_config.loader_loaded) {
|
|
|
|
if (path && SDL_strcmp(path, _this->vulkan_config.loader_path) != 0) {
|
2017-08-27 22:15:57 -04:00
|
|
|
return SDL_SetError("Vulkan loader library already loaded");
|
|
|
|
}
|
|
|
|
retval = 0;
|
2017-08-27 23:39:55 -07:00
|
|
|
} else {
|
|
|
|
if (!_this->Vulkan_LoadLibrary) {
|
2018-04-23 22:29:14 -07:00
|
|
|
return SDL_SetError("Vulkan support is either not configured in SDL "
|
|
|
|
"or not available in current SDL video driver "
|
|
|
|
"(%s) or platform", _this->name);
|
2017-08-27 22:15:57 -04:00
|
|
|
}
|
|
|
|
retval = _this->Vulkan_LoadLibrary(_this, path);
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (retval == 0) {
|
2017-08-27 22:15:57 -04:00
|
|
|
_this->vulkan_config.loader_loaded++;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *SDL_Vulkan_GetVkGetInstanceProcAddr(void)
|
|
|
|
{
|
2017-08-27 23:39:55 -07:00
|
|
|
if (!_this) {
|
2017-08-27 22:15:57 -04:00
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (!_this->vulkan_config.loader_loaded) {
|
2017-08-27 22:15:57 -04:00
|
|
|
SDL_SetError("No Vulkan loader has been loaded");
|
2018-01-30 18:08:34 -08:00
|
|
|
return NULL;
|
2017-08-27 22:15:57 -04:00
|
|
|
}
|
2018-02-12 17:00:00 +03:00
|
|
|
return _this->vulkan_config.vkGetInstanceProcAddr;
|
2017-08-27 22:15:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SDL_Vulkan_UnloadLibrary(void)
|
|
|
|
{
|
2017-08-27 23:39:55 -07:00
|
|
|
if (!_this) {
|
2017-08-27 22:15:57 -04:00
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (_this->vulkan_config.loader_loaded > 0) {
|
|
|
|
if (--_this->vulkan_config.loader_loaded > 0) {
|
2017-08-27 22:15:57 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-08-27 23:39:55 -07:00
|
|
|
if (_this->Vulkan_UnloadLibrary) {
|
2017-08-27 22:15:57 -04:00
|
|
|
_this->Vulkan_UnloadLibrary(_this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_bool SDL_Vulkan_GetInstanceExtensions(SDL_Window *window, unsigned *count, const char **names)
|
|
|
|
{
|
2018-08-24 09:49:48 -04:00
|
|
|
if (window) {
|
|
|
|
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
|
2017-08-27 22:15:57 -04:00
|
|
|
|
2018-08-24 09:49:48 -04:00
|
|
|
if (!(window->flags & SDL_WINDOW_VULKAN))
|
|
|
|
{
|
|
|
|
SDL_SetError(NOT_A_VULKAN_WINDOW);
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
2017-08-27 22:15:57 -04:00
|
|
|
}
|
|
|
|
|
2017-08-27 23:39:55 -07:00
|
|
|
if (!count) {
|
|
|
|
SDL_InvalidParamError("count");
|
2017-08-27 22:15:57 -04:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _this->Vulkan_GetInstanceExtensions(_this, window, count, names);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_bool SDL_Vulkan_CreateSurface(SDL_Window *window,
|
|
|
|
VkInstance instance,
|
|
|
|
VkSurfaceKHR *surface)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
|
|
|
|
|
2017-08-27 23:39:55 -07:00
|
|
|
if (!(window->flags & SDL_WINDOW_VULKAN)) {
|
2017-08-27 22:15:57 -04:00
|
|
|
SDL_SetError(NOT_A_VULKAN_WINDOW);
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2017-08-27 23:39:55 -07:00
|
|
|
if (!instance) {
|
|
|
|
SDL_InvalidParamError("instance");
|
2017-08-27 22:15:57 -04:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2017-08-27 23:39:55 -07:00
|
|
|
if (!surface) {
|
|
|
|
SDL_InvalidParamError("surface");
|
2017-08-27 22:15:57 -04:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _this->Vulkan_CreateSurface(_this, window, instance, surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDL_Vulkan_GetDrawableSize(SDL_Window * window, int *w, int *h)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window,);
|
|
|
|
|
|
|
|
if (_this->Vulkan_GetDrawableSize) {
|
|
|
|
_this->Vulkan_GetDrawableSize(_this, window, w, h);
|
|
|
|
} else {
|
|
|
|
SDL_GetWindowSize(window, w, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|