src/video/SDL_video.c
author Holmes Futrell <hfutrell@umail.ucsb.edu>
Tue, 02 Sep 2008 20:11:06 +0000
changeset 2744 1aede15771d0
parent 2743 453ec0c21f6f
child 2745 587d2b5fb805
permissions -rw-r--r--
Ran GNU indent on file
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
/* The high-level video driver subsystem */
slouken@0
    25
slouken@0
    26
#include "SDL.h"
slouken@0
    27
#include "SDL_sysvideo.h"
slouken@0
    28
#include "SDL_blit.h"
slouken@0
    29
#include "SDL_pixels_c.h"
slouken@1918
    30
#include "SDL_renderer_gl.h"
slouken@1895
    31
#include "SDL_renderer_sw.h"
slouken@1361
    32
#include "../events/SDL_sysevents.h"
slouken@1361
    33
#include "../events/SDL_events_c.h"
slouken@0
    34
slouken@1926
    35
#if SDL_VIDEO_OPENGL
slouken@1926
    36
#include "SDL_opengl.h"
slouken@1926
    37
slouken@1926
    38
/* On Windows, windows.h defines CreateWindow */
slouken@1926
    39
#ifdef CreateWindow
slouken@1926
    40
#undef CreateWindow
slouken@1926
    41
#endif
hfutrell@2744
    42
#endif				/* SDL_VIDEO_OPENGL */
slouken@1926
    43
slouken@0
    44
/* Available video drivers */
slouken@0
    45
static VideoBootStrap *bootstrap[] = {
slouken@1931
    46
#if SDL_VIDEO_DRIVER_COCOA
hfutrell@2744
    47
	&COCOA_bootstrap,
icculus@1133
    48
#endif
slouken@1361
    49
#if SDL_VIDEO_DRIVER_X11
hfutrell@2744
    50
	&X11_bootstrap,
slouken@0
    51
#endif
slouken@1361
    52
#if SDL_VIDEO_DRIVER_NANOX
hfutrell@2744
    53
	&NX_bootstrap,
slouken@30
    54
#endif
slouken@1361
    55
#if SDL_VIDEO_DRIVER_IPOD
hfutrell@2744
    56
	&iPod_bootstrap,
icculus@1140
    57
#endif
slouken@1361
    58
#if SDL_VIDEO_DRIVER_WSCONS
hfutrell@2744
    59
	&WSCONS_bootstrap,
icculus@1187
    60
#endif
slouken@1361
    61
#if SDL_VIDEO_DRIVER_FBCON
hfutrell@2744
    62
	&FBCON_bootstrap,
slouken@0
    63
#endif
slouken@1361
    64
#if SDL_VIDEO_DRIVER_DIRECTFB
hfutrell@2744
    65
	&DirectFB_bootstrap,
slouken@167
    66
#endif
slouken@1361
    67
#if SDL_VIDEO_DRIVER_PS2GS
hfutrell@2744
    68
	&PS2GS_bootstrap,
slouken@0
    69
#endif
slouken@1361
    70
#if SDL_VIDEO_DRIVER_VGL
hfutrell@2744
    71
	&VGL_bootstrap,
slouken@75
    72
#endif
slouken@1361
    73
#if SDL_VIDEO_DRIVER_SVGALIB
hfutrell@2744
    74
	&SVGALIB_bootstrap,
slouken@0
    75
#endif
slouken@1361
    76
#if SDL_VIDEO_DRIVER_GAPI
hfutrell@2744
    77
	&GAPI_bootstrap,
slouken@1361
    78
#endif
slouken@1895
    79
#if SDL_VIDEO_DRIVER_WIN32
hfutrell@2744
    80
	&WIN32_bootstrap,
slouken@1361
    81
#endif
slouken@1361
    82
#if SDL_VIDEO_DRIVER_BWINDOW
hfutrell@2744
    83
	&BWINDOW_bootstrap,
slouken@1361
    84
#endif
slouken@1361
    85
#if SDL_VIDEO_DRIVER_PHOTON
hfutrell@2744
    86
	&ph_bootstrap,
slouken@1361
    87
#endif
slouken@1361
    88
#if SDL_VIDEO_DRIVER_EPOC
hfutrell@2744
    89
	&EPOC_bootstrap,
slouken@1361
    90
#endif
slouken@1361
    91
#if SDL_VIDEO_DRIVER_XBIOS
hfutrell@2744
    92
	&XBIOS_bootstrap,
slouken@1361
    93
#endif
slouken@1361
    94
#if SDL_VIDEO_DRIVER_GEM
hfutrell@2744
    95
	&GEM_bootstrap,
slouken@1361
    96
#endif
slouken@1361
    97
#if SDL_VIDEO_DRIVER_DC
hfutrell@2744
    98
	&DC_bootstrap,
slouken@1361
    99
#endif
slouken@1361
   100
#if SDL_VIDEO_DRIVER_RISCOS
hfutrell@2744
   101
	&RISCOS_bootstrap,
slouken@1361
   102
#endif
slouken@1361
   103
#if SDL_VIDEO_DRIVER_OS2FS
hfutrell@2744
   104
	&OS2FSLib_bootstrap,
slouken@1361
   105
#endif
hfutrell@2743
   106
#if SDL_VIDEO_DRIVER_NDS
hfutrell@2744
   107
	&NDS_bootstrap,
slouken@2735
   108
#endif
slouken@1361
   109
#if SDL_VIDEO_DRIVER_DUMMY
hfutrell@2744
   110
	&DUMMY_bootstrap,
slouken@610
   111
#endif
hfutrell@2744
   112
	NULL
slouken@0
   113
};
slouken@173
   114
slouken@1895
   115
static SDL_VideoDevice *_this = NULL;
slouken@0
   116
slouken@0
   117
/* Various local functions */
hfutrell@2744
   118
int             SDL_VideoInit(const char *driver_name, Uint32 flags);
hfutrell@2744
   119
void            SDL_VideoQuit(void);
slouken@0
   120
slouken@1895
   121
static int
slouken@1895
   122
cmpmodes(const void *A, const void *B)
slouken@1895
   123
{
hfutrell@2744
   124
	SDL_DisplayMode a = *(const SDL_DisplayMode *) A;
hfutrell@2744
   125
	SDL_DisplayMode b = *(const SDL_DisplayMode *) B;
slouken@0
   126
hfutrell@2744
   127
	if (a.w != b.w) {
hfutrell@2744
   128
		return b.w - a.w;
hfutrell@2744
   129
	}
hfutrell@2744
   130
	if (a.h != b.h) {
hfutrell@2744
   131
		return b.h - a.h;
hfutrell@2744
   132
	}
hfutrell@2744
   133
	if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) {
hfutrell@2744
   134
		return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format);
hfutrell@2744
   135
	}
hfutrell@2744
   136
	if (a.refresh_rate != b.refresh_rate) {
hfutrell@2744
   137
		return b.refresh_rate - a.refresh_rate;
hfutrell@2744
   138
	}
hfutrell@2744
   139
	return 0;
slouken@1895
   140
}
slouken@1895
   141
slouken@1912
   142
static void
slouken@1912
   143
SDL_UninitializedVideo()
slouken@1912
   144
{
hfutrell@2744
   145
	SDL_SetError("Video subsystem has not been initialized");
slouken@1912
   146
}
slouken@1912
   147
slouken@1895
   148
int
slouken@1895
   149
SDL_GetNumVideoDrivers(void)
slouken@1895
   150
{
hfutrell@2744
   151
	return SDL_arraysize(bootstrap) - 1;
slouken@1895
   152
}
slouken@1895
   153
hfutrell@2744
   154
const char     *
slouken@1895
   155
SDL_GetVideoDriver(int index)
slouken@1895
   156
{
hfutrell@2744
   157
	if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
hfutrell@2744
   158
		return bootstrap[index]->name;
hfutrell@2744
   159
	}
hfutrell@2744
   160
	return NULL;
slouken@1895
   161
}
slouken@0
   162
slouken@0
   163
/*
slouken@0
   164
 * Initialize the video and event subsystems -- determine native pixel format
slouken@0
   165
 */
slouken@1895
   166
int
slouken@1895
   167
SDL_VideoInit(const char *driver_name, Uint32 flags)
slouken@0
   168
{
hfutrell@2744
   169
	SDL_VideoDevice *video;
hfutrell@2744
   170
	int             index;
hfutrell@2744
   171
	int             i;
slouken@0
   172
hfutrell@2744
   173
	/* Toggle the event thread flags, based on OS requirements */
slouken@0
   174
#if defined(MUST_THREAD_EVENTS)
hfutrell@2744
   175
	flags |= SDL_INIT_EVENTTHREAD;
slouken@0
   176
#elif defined(CANT_THREAD_EVENTS)
hfutrell@2744
   177
	if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
hfutrell@2744
   178
		SDL_SetError("OS doesn't support threaded events");
hfutrell@2744
   179
		return -1;
hfutrell@2744
   180
	}
slouken@0
   181
#endif
slouken@0
   182
hfutrell@2744
   183
	/* Start the event loop */
hfutrell@2744
   184
	if (SDL_StartEventLoop(flags) < 0) {
hfutrell@2744
   185
		return -1;
hfutrell@2744
   186
	}
hfutrell@2744
   187
	/* Check to make sure we don't overwrite '_this' */
hfutrell@2744
   188
	if (_this != NULL) {
hfutrell@2744
   189
		SDL_VideoQuit();
hfutrell@2744
   190
	}
hfutrell@2744
   191
	/* Select the proper video driver */
hfutrell@2744
   192
	index = 0;
hfutrell@2744
   193
	video = NULL;
hfutrell@2744
   194
	if (driver_name == NULL) {
hfutrell@2744
   195
		driver_name = SDL_getenv("SDL_VIDEODRIVER");
hfutrell@2744
   196
	}
hfutrell@2744
   197
	if (driver_name != NULL) {
hfutrell@2744
   198
		for (i = 0; bootstrap[i]; ++i) {
hfutrell@2744
   199
			if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) {
hfutrell@2744
   200
				if (bootstrap[i]->available()) {
hfutrell@2744
   201
					video = bootstrap[i]->create(index);
hfutrell@2744
   202
				}
hfutrell@2744
   203
				break;
hfutrell@2744
   204
			}
hfutrell@2744
   205
		}
hfutrell@2744
   206
	} else {
hfutrell@2744
   207
		for (i = 0; bootstrap[i]; ++i) {
hfutrell@2744
   208
			if (bootstrap[i]->available()) {
hfutrell@2744
   209
				video = bootstrap[i]->create(index);
hfutrell@2744
   210
				if (video != NULL) {
hfutrell@2744
   211
					break;
hfutrell@2744
   212
				}
hfutrell@2744
   213
			}
hfutrell@2744
   214
		}
hfutrell@2744
   215
	}
hfutrell@2744
   216
	if (video == NULL) {
hfutrell@2744
   217
		if (driver_name) {
hfutrell@2744
   218
			SDL_SetError("%s not available", driver_name);
hfutrell@2744
   219
		} else {
hfutrell@2744
   220
			SDL_SetError("No available video device");
hfutrell@2744
   221
		}
hfutrell@2744
   222
		return -1;
hfutrell@2744
   223
	}
hfutrell@2744
   224
	_this = video;
hfutrell@2744
   225
	_this->name = bootstrap[i]->name;
hfutrell@2744
   226
	_this->next_object_id = 1;
slouken@0
   227
slouken@0
   228
hfutrell@2744
   229
	/* Set some very sane GL defaults */
hfutrell@2744
   230
	_this->gl_config.driver_loaded = 0;
hfutrell@2744
   231
	_this->gl_config.dll_handle = NULL;
hfutrell@2744
   232
	_this->gl_config.red_size = 3;
hfutrell@2744
   233
	_this->gl_config.green_size = 3;
hfutrell@2744
   234
	_this->gl_config.blue_size = 2;
hfutrell@2744
   235
	_this->gl_config.alpha_size = 0;
hfutrell@2744
   236
	_this->gl_config.buffer_size = 0;
hfutrell@2744
   237
	_this->gl_config.depth_size = 16;
hfutrell@2744
   238
	_this->gl_config.stencil_size = 0;
hfutrell@2744
   239
	_this->gl_config.double_buffer = 1;
hfutrell@2744
   240
	_this->gl_config.accum_red_size = 0;
hfutrell@2744
   241
	_this->gl_config.accum_green_size = 0;
hfutrell@2744
   242
	_this->gl_config.accum_blue_size = 0;
hfutrell@2744
   243
	_this->gl_config.accum_alpha_size = 0;
hfutrell@2744
   244
	_this->gl_config.stereo = 0;
hfutrell@2744
   245
	_this->gl_config.multisamplebuffers = 0;
hfutrell@2744
   246
	_this->gl_config.multisamplesamples = 0;
hfutrell@2744
   247
	_this->gl_config.accelerated = -1;	/* not known, don't set */
slouken@0
   248
hfutrell@2744
   249
	/* Initialize the video subsystem */
hfutrell@2744
   250
	if (_this->VideoInit(_this) < 0) {
hfutrell@2744
   251
		SDL_VideoQuit();
hfutrell@2744
   252
		return -1;
hfutrell@2744
   253
	}
hfutrell@2744
   254
	/* Make sure some displays were added */
hfutrell@2744
   255
	if (_this->num_displays == 0) {
hfutrell@2744
   256
		SDL_SetError("The video driver did not add any displays");
hfutrell@2744
   257
		SDL_VideoQuit();
hfutrell@2744
   258
		return (-1);
hfutrell@2744
   259
	}
hfutrell@2744
   260
	/* The software renderer is always available */
hfutrell@2744
   261
	for (i = 0; i < _this->num_displays; ++i) {
hfutrell@2744
   262
#if SDL_VIDEO_RENDER_OGL
hfutrell@2744
   263
		SDL_AddRenderDriver(i, &GL_RenderDriver);
hfutrell@2744
   264
#endif
hfutrell@2744
   265
		if (_this->displays[i].num_render_drivers > 0) {
hfutrell@2744
   266
			SDL_AddRenderDriver(i, &SW_RenderDriver);
hfutrell@2744
   267
		}
hfutrell@2744
   268
	}
slouken@0
   269
hfutrell@2744
   270
	/* We're ready to go! */
hfutrell@2744
   271
	return 0;
slouken@0
   272
}
slouken@0
   273
hfutrell@2744
   274
const char     *
slouken@1895
   275
SDL_GetCurrentVideoDriver()
slouken@0
   276
{
hfutrell@2744
   277
	if (!_this) {
hfutrell@2744
   278
		SDL_UninitializedVideo();
hfutrell@2744
   279
		return NULL;
hfutrell@2744
   280
	}
hfutrell@2744
   281
	return _this->name;
slouken@0
   282
}
slouken@0
   283
slouken@1895
   284
SDL_VideoDevice *
slouken@1895
   285
SDL_GetVideoDevice()
slouken@0
   286
{
hfutrell@2744
   287
	return _this;
slouken@0
   288
}
slouken@0
   289
slouken@1895
   290
int
slouken@1895
   291
SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
slouken@0
   292
{
hfutrell@2744
   293
	SDL_VideoDisplay display;
slouken@0
   294
hfutrell@2744
   295
	SDL_zero(display);
hfutrell@2744
   296
	if (desktop_mode) {
hfutrell@2744
   297
		display.desktop_mode = *desktop_mode;
hfutrell@2744
   298
	}
hfutrell@2744
   299
	display.current_mode = display.desktop_mode;
slouken@1895
   300
hfutrell@2744
   301
	return SDL_AddVideoDisplay(&display);
slouken@0
   302
}
slouken@0
   303
slouken@1895
   304
int
slouken@1895
   305
SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
slouken@0
   306
{
hfutrell@2744
   307
	SDL_VideoDisplay *displays;
hfutrell@2744
   308
	int             index = -1;
slouken@0
   309
hfutrell@2744
   310
	displays =
hfutrell@2744
   311
		SDL_realloc(_this->displays,
hfutrell@2744
   312
			    (_this->num_displays + 1) * sizeof(*displays));
hfutrell@2744
   313
	if (displays) {
hfutrell@2744
   314
		index = _this->num_displays++;
hfutrell@2744
   315
		displays[index] = *display;
hfutrell@2744
   316
		displays[index].device = _this;
hfutrell@2744
   317
		_this->displays = displays;
hfutrell@2744
   318
	} else {
hfutrell@2744
   319
		SDL_OutOfMemory();
hfutrell@2744
   320
	}
hfutrell@2744
   321
	return index;
slouken@0
   322
}
slouken@0
   323
slouken@1895
   324
int
slouken@1895
   325
SDL_GetNumVideoDisplays(void)
slouken@0
   326
{
hfutrell@2744
   327
	if (!_this) {
hfutrell@2744
   328
		SDL_UninitializedVideo();
hfutrell@2744
   329
		return 0;
hfutrell@2744
   330
	}
hfutrell@2744
   331
	return _this->num_displays;
slouken@0
   332
}
slouken@0
   333
slouken@1895
   334
int
slouken@1895
   335
SDL_SelectVideoDisplay(int index)
slouken@0
   336
{
hfutrell@2744
   337
	if (!_this) {
hfutrell@2744
   338
		SDL_UninitializedVideo();
hfutrell@2744
   339
		return (-1);
hfutrell@2744
   340
	}
hfutrell@2744
   341
	if (index < 0 || index >= _this->num_displays) {
hfutrell@2744
   342
		SDL_SetError("index must be in the range 0 - %d",
hfutrell@2744
   343
			     _this->num_displays - 1);
hfutrell@2744
   344
		return -1;
hfutrell@2744
   345
	}
hfutrell@2744
   346
	_this->current_display = index;
hfutrell@2744
   347
	return 0;
slouken@1963
   348
}
slouken@1963
   349
slouken@1963
   350
int
slouken@1963
   351
SDL_GetCurrentVideoDisplay(void)
slouken@1963
   352
{
hfutrell@2744
   353
	if (!_this) {
hfutrell@2744
   354
		SDL_UninitializedVideo();
hfutrell@2744
   355
		return (-1);
hfutrell@2744
   356
	}
hfutrell@2744
   357
	return _this->current_display;
slouken@0
   358
}
slouken@0
   359
slouken@1895
   360
SDL_bool
slouken@1895
   361
SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
slouken@0
   362
{
hfutrell@2744
   363
	SDL_VideoDisplay *display = &_this->displays[displayIndex];
hfutrell@2744
   364
	SDL_DisplayMode *modes;
hfutrell@2744
   365
	int             i, nmodes;
slouken@0
   366
hfutrell@2744
   367
	/* Make sure we don't already have the mode in the list */
hfutrell@2744
   368
	modes = display->display_modes;
hfutrell@2744
   369
	nmodes = display->num_display_modes;
hfutrell@2744
   370
	for (i = nmodes; i--;) {
hfutrell@2744
   371
		if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
hfutrell@2744
   372
			return SDL_FALSE;
hfutrell@2744
   373
		}
hfutrell@2744
   374
	}
slouken@1895
   375
hfutrell@2744
   376
	/* Go ahead and add the new mode */
hfutrell@2744
   377
	if (nmodes == display->max_display_modes) {
hfutrell@2744
   378
		modes =
hfutrell@2744
   379
			SDL_realloc(modes,
hfutrell@2744
   380
			(display->max_display_modes + 32) * sizeof(*modes));
hfutrell@2744
   381
		if (!modes) {
hfutrell@2744
   382
			return SDL_FALSE;
hfutrell@2744
   383
		}
hfutrell@2744
   384
		display->display_modes = modes;
hfutrell@2744
   385
		display->max_display_modes += 32;
hfutrell@2744
   386
	}
hfutrell@2744
   387
	modes[nmodes] = *mode;
hfutrell@2744
   388
	display->num_display_modes++;
slouken@1895
   389
hfutrell@2744
   390
	return SDL_TRUE;
slouken@0
   391
}
slouken@0
   392
slouken@1895
   393
int
slouken@1895
   394
SDL_GetNumDisplayModes()
slouken@0
   395
{
hfutrell@2744
   396
	if (_this) {
hfutrell@2744
   397
		SDL_VideoDisplay *display = &SDL_CurrentDisplay;
hfutrell@2744
   398
		if (!display->num_display_modes && _this->GetDisplayModes) {
hfutrell@2744
   399
			_this->GetDisplayModes(_this);
hfutrell@2744
   400
			SDL_qsort(display->display_modes, display->num_display_modes,
hfutrell@2744
   401
				  sizeof(SDL_DisplayMode), cmpmodes);
hfutrell@2744
   402
		}
hfutrell@2744
   403
		return display->num_display_modes;
hfutrell@2744
   404
	}
hfutrell@2744
   405
	return 0;
slouken@0
   406
}
slouken@0
   407
slouken@1967
   408
int
slouken@1967
   409
SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
slouken@0
   410
{
hfutrell@2744
   411
	if (index < 0 || index >= SDL_GetNumDisplayModes()) {
hfutrell@2744
   412
		SDL_SetError("index must be in the range of 0 - %d",
hfutrell@2744
   413
			     SDL_GetNumDisplayModes() - 1);
hfutrell@2744
   414
		return -1;
hfutrell@2744
   415
	}
hfutrell@2744
   416
	if (mode) {
hfutrell@2744
   417
		*mode = SDL_CurrentDisplay.display_modes[index];
hfutrell@2744
   418
	}
hfutrell@2744
   419
	return 0;
slouken@0
   420
}
slouken@0
   421
slouken@1967
   422
int
slouken@1967
   423
SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode)
slouken@0
   424
{
hfutrell@2744
   425
	if (!_this) {
hfutrell@2744
   426
		SDL_UninitializedVideo();
hfutrell@2744
   427
		return -1;
hfutrell@2744
   428
	}
hfutrell@2744
   429
	if (mode) {
hfutrell@2744
   430
		*mode = SDL_CurrentDisplay.desktop_mode;
hfutrell@2744
   431
	}
hfutrell@2744
   432
	return 0;
slouken@0
   433
}
slouken@0
   434
slouken@1967
   435
int
slouken@1967
   436
SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
slouken@0
   437
{
hfutrell@2744
   438
	if (!_this) {
hfutrell@2744
   439
		SDL_UninitializedVideo();
hfutrell@2744
   440
		return -1;
hfutrell@2744
   441
	}
hfutrell@2744
   442
	if (mode) {
hfutrell@2744
   443
		*mode = SDL_CurrentDisplay.current_mode;
hfutrell@2744
   444
	}
hfutrell@2744
   445
	return 0;
slouken@0
   446
}
slouken@0
   447
slouken@1895
   448
SDL_DisplayMode *
slouken@1895
   449
SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode,
hfutrell@2744
   450
			  SDL_DisplayMode * closest)
slouken@0
   451
{
hfutrell@2744
   452
	Uint32          target_format;
hfutrell@2744
   453
	int             target_refresh_rate;
hfutrell@2744
   454
	int             i;
hfutrell@2744
   455
	SDL_DisplayMode *current, *match;
slouken@0
   456
hfutrell@2744
   457
	if (!_this || !mode || !closest) {
hfutrell@2744
   458
		return NULL;
hfutrell@2744
   459
	}
hfutrell@2744
   460
	/* Default to the desktop format */
hfutrell@2744
   461
	if (mode->format) {
hfutrell@2744
   462
		target_format = mode->format;
hfutrell@2744
   463
	} else {
hfutrell@2744
   464
		target_format = SDL_CurrentDisplay.desktop_mode.format;
hfutrell@2744
   465
	}
slouken@0
   466
hfutrell@2744
   467
	/* Default to the desktop refresh rate */
hfutrell@2744
   468
	if (mode->refresh_rate) {
hfutrell@2744
   469
		target_refresh_rate = mode->refresh_rate;
hfutrell@2744
   470
	} else {
hfutrell@2744
   471
		target_refresh_rate = SDL_CurrentDisplay.desktop_mode.refresh_rate;
hfutrell@2744
   472
	}
slouken@0
   473
hfutrell@2744
   474
	match = NULL;
hfutrell@2744
   475
	for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
hfutrell@2744
   476
		current = &SDL_CurrentDisplay.display_modes[i];
slouken@0
   477
hfutrell@2744
   478
		if ((current->w && current->h) &&
hfutrell@2744
   479
		    (current->w < mode->w || current->h < mode->h)) {
hfutrell@2744
   480
			/* Out of sorted modes large enough here */
hfutrell@2744
   481
			break;
hfutrell@2744
   482
		}
hfutrell@2744
   483
		if (!match || current->w < match->w || current->h < match->h) {
hfutrell@2744
   484
			match = current;
hfutrell@2744
   485
			continue;
hfutrell@2744
   486
		}
hfutrell@2744
   487
		if (current->format != match->format) {
hfutrell@2744
   488
			/* Sorted highest depth to lowest */
hfutrell@2744
   489
			if (current->format == target_format ||
hfutrell@2744
   490
			    (SDL_BITSPERPIXEL(current->format) >=
hfutrell@2744
   491
			     SDL_BITSPERPIXEL(target_format)
hfutrell@2744
   492
			     && SDL_PIXELTYPE(current->format) ==
hfutrell@2744
   493
			     SDL_PIXELTYPE(target_format))) {
hfutrell@2744
   494
				match = current;
hfutrell@2744
   495
			}
hfutrell@2744
   496
			continue;
hfutrell@2744
   497
		}
hfutrell@2744
   498
		if (current->refresh_rate != match->refresh_rate) {
hfutrell@2744
   499
			/* Sorted highest refresh to lowest */
hfutrell@2744
   500
			if (current->refresh_rate >= target_refresh_rate) {
hfutrell@2744
   501
				match = current;
hfutrell@2744
   502
			}
hfutrell@2744
   503
		}
hfutrell@2744
   504
	}
hfutrell@2744
   505
	if (match) {
hfutrell@2744
   506
		if (match->format) {
hfutrell@2744
   507
			closest->format = match->format;
hfutrell@2744
   508
		} else {
hfutrell@2744
   509
			closest->format = mode->format;
hfutrell@2744
   510
		}
hfutrell@2744
   511
		if (match->w && match->h) {
hfutrell@2744
   512
			closest->w = match->w;
hfutrell@2744
   513
			closest->h = match->h;
hfutrell@2744
   514
		} else {
hfutrell@2744
   515
			closest->w = mode->w;
hfutrell@2744
   516
			closest->h = mode->h;
hfutrell@2744
   517
		}
hfutrell@2744
   518
		if (match->refresh_rate) {
hfutrell@2744
   519
			closest->refresh_rate = match->refresh_rate;
hfutrell@2744
   520
		} else {
hfutrell@2744
   521
			closest->refresh_rate = mode->refresh_rate;
hfutrell@2744
   522
		}
hfutrell@2744
   523
		closest->driverdata = match->driverdata;
slouken@1895
   524
hfutrell@2744
   525
		/*
hfutrell@2744
   526
		 * Pick some reasonable defaults if the app and driver don't
hfutrell@2744
   527
		 * care
hfutrell@2744
   528
		 */
hfutrell@2744
   529
		if (!closest->format) {
hfutrell@2744
   530
			closest->format = SDL_PIXELFORMAT_RGB888;
hfutrell@2744
   531
		}
hfutrell@2744
   532
		if (!closest->w) {
hfutrell@2744
   533
			closest->w = 640;
hfutrell@2744
   534
		}
hfutrell@2744
   535
		if (!closest->h) {
hfutrell@2744
   536
			closest->h = 480;
hfutrell@2744
   537
		}
hfutrell@2744
   538
		return closest;
hfutrell@2744
   539
	}
hfutrell@2744
   540
	return NULL;
slouken@0
   541
}
slouken@0
   542
slouken@1895
   543
int
slouken@1895
   544
SDL_SetDisplayMode(const SDL_DisplayMode * mode)
slouken@0
   545
{
hfutrell@2744
   546
	SDL_VideoDisplay *display;
hfutrell@2744
   547
	SDL_DisplayMode display_mode;
hfutrell@2744
   548
	SDL_DisplayMode current_mode;
hfutrell@2744
   549
	int             i, ncolors;
slouken@0
   550
hfutrell@2744
   551
	if (!_this) {
hfutrell@2744
   552
		SDL_UninitializedVideo();
hfutrell@2744
   553
		return -1;
hfutrell@2744
   554
	}
hfutrell@2744
   555
	display = &SDL_CurrentDisplay;
hfutrell@2744
   556
	if (!mode) {
hfutrell@2744
   557
		mode = &display->desktop_mode;
hfutrell@2744
   558
	}
hfutrell@2744
   559
	display_mode = *mode;
slouken@0
   560
hfutrell@2744
   561
	/* Default to the current mode */
hfutrell@2744
   562
	if (!display_mode.format) {
hfutrell@2744
   563
		display_mode.format = display->current_mode.format;
hfutrell@2744
   564
	}
hfutrell@2744
   565
	if (!display_mode.w) {
hfutrell@2744
   566
		display_mode.w = display->current_mode.w;
hfutrell@2744
   567
	}
hfutrell@2744
   568
	if (!display_mode.h) {
hfutrell@2744
   569
		display_mode.h = display->current_mode.h;
hfutrell@2744
   570
	}
hfutrell@2744
   571
	if (!display_mode.refresh_rate) {
hfutrell@2744
   572
		display_mode.refresh_rate = display->current_mode.refresh_rate;
hfutrell@2744
   573
	}
hfutrell@2744
   574
	/* Get a good video mode, the closest one possible */
hfutrell@2744
   575
	if (!SDL_GetClosestDisplayMode(&display_mode, &display_mode)) {
hfutrell@2744
   576
		SDL_SetError("No video mode large enough for %dx%d",
hfutrell@2744
   577
			     display_mode.w, display_mode.h);
hfutrell@2744
   578
		return -1;
hfutrell@2744
   579
	}
hfutrell@2744
   580
	/* See if there's anything left to do */
hfutrell@2744
   581
	SDL_GetCurrentDisplayMode(&current_mode);
hfutrell@2744
   582
	if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) {
hfutrell@2744
   583
		return 0;
hfutrell@2744
   584
	}
hfutrell@2744
   585
	/* Actually change the display mode */
hfutrell@2744
   586
	if (_this->SetDisplayMode(_this, &display_mode) < 0) {
hfutrell@2744
   587
		return -1;
hfutrell@2744
   588
	}
hfutrell@2744
   589
	display->current_mode = display_mode;
slouken@1895
   590
hfutrell@2744
   591
	/* Set up a palette, if necessary */
hfutrell@2744
   592
	if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
hfutrell@2744
   593
		ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format));
hfutrell@2744
   594
	} else {
hfutrell@2744
   595
		ncolors = 0;
hfutrell@2744
   596
	}
hfutrell@2744
   597
	if ((!ncolors && display->palette) || (ncolors && !display->palette)
hfutrell@2744
   598
	    || (ncolors && ncolors != display->palette->ncolors)) {
hfutrell@2744
   599
		if (display->palette) {
hfutrell@2744
   600
			SDL_FreePalette(display->palette);
hfutrell@2744
   601
			display->palette = NULL;
hfutrell@2744
   602
		}
hfutrell@2744
   603
		if (ncolors) {
hfutrell@2744
   604
			display->palette = SDL_AllocPalette(ncolors);
hfutrell@2744
   605
			if (!display->palette) {
hfutrell@2744
   606
				return -1;
hfutrell@2744
   607
			}
hfutrell@2744
   608
			SDL_DitherColors(display->palette->colors,
hfutrell@2744
   609
				     SDL_BITSPERPIXEL(display_mode.format));
hfutrell@2744
   610
		}
hfutrell@2744
   611
	}
hfutrell@2744
   612
	/* Move any fullscreen windows into position */
hfutrell@2744
   613
	for (i = 0; i < display->num_windows; ++i) {
hfutrell@2744
   614
		SDL_Window     *window = &display->windows[i];
hfutrell@2744
   615
		if (FULLSCREEN_VISIBLE(window)) {
hfutrell@2744
   616
			SDL_SetWindowPosition(window->id, SDL_WINDOWPOS_CENTERED,
hfutrell@2744
   617
					      SDL_WINDOWPOS_CENTERED);
hfutrell@2744
   618
		}
hfutrell@2744
   619
	}
slouken@1895
   620
hfutrell@2744
   621
	return 0;
slouken@0
   622
}
slouken@0
   623
slouken@1895
   624
int
slouken@1895
   625
SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode)
slouken@0
   626
{
hfutrell@2744
   627
	SDL_VideoDisplay *display;
hfutrell@2744
   628
	SDL_DisplayMode fullscreen_mode;
hfutrell@2744
   629
	int             i;
slouken@0
   630
hfutrell@2744
   631
	if (!_this) {
hfutrell@2744
   632
		SDL_UninitializedVideo();
hfutrell@2744
   633
		return -1;
hfutrell@2744
   634
	}
hfutrell@2744
   635
	display = &SDL_CurrentDisplay;
hfutrell@2744
   636
	if (!mode) {
hfutrell@2744
   637
		mode = &display->desktop_mode;
hfutrell@2744
   638
	}
hfutrell@2744
   639
	SDL_GetClosestDisplayMode(mode, &fullscreen_mode);
hfutrell@2744
   640
	if (SDL_memcmp
hfutrell@2744
   641
	    (&fullscreen_mode, &display->fullscreen_mode,
hfutrell@2744
   642
	     sizeof(fullscreen_mode)) == 0) {
hfutrell@2744
   643
		/* Nothing to do... */
hfutrell@2744
   644
		return 0;
hfutrell@2744
   645
	}
hfutrell@2744
   646
	display->fullscreen_mode = fullscreen_mode;
slouken@0
   647
hfutrell@2744
   648
	/* Actually set the mode if we have a fullscreen window visible */
hfutrell@2744
   649
	for (i = 0; i < display->num_windows; ++i) {
hfutrell@2744
   650
		SDL_Window     *window = &display->windows[i];
hfutrell@2744
   651
		if (FULLSCREEN_VISIBLE(window)) {
hfutrell@2744
   652
			if (SDL_SetDisplayMode(&display->fullscreen_mode) < 0) {
hfutrell@2744
   653
				return -1;
hfutrell@2744
   654
			}
hfutrell@2744
   655
		}
hfutrell@2744
   656
		if (window->flags & SDL_WINDOW_FULLSCREEN) {
hfutrell@2744
   657
			SDL_OnWindowResized(window);
hfutrell@2744
   658
		}
hfutrell@2744
   659
	}
hfutrell@2744
   660
	return 0;
slouken@0
   661
}
slouken@0
   662
slouken@1967
   663
int
slouken@1967
   664
SDL_GetFullscreenDisplayMode(SDL_DisplayMode * mode)
slouken@0
   665
{
hfutrell@2744
   666
	if (!_this) {
hfutrell@2744
   667
		SDL_UninitializedVideo();
hfutrell@2744
   668
		return -1;
hfutrell@2744
   669
	}
hfutrell@2744
   670
	if (mode) {
hfutrell@2744
   671
		*mode = SDL_CurrentDisplay.fullscreen_mode;
hfutrell@2744
   672
	}
hfutrell@2744
   673
	return 0;
slouken@0
   674
}
slouken@0
   675
slouken@1895
   676
int
slouken@1895
   677
SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors)
slouken@0
   678
{
hfutrell@2744
   679
	SDL_Palette    *palette;
hfutrell@2744
   680
	int             status = 0;
slouken@0
   681
hfutrell@2744
   682
	if (!_this) {
hfutrell@2744
   683
		SDL_UninitializedVideo();
hfutrell@2744
   684
		return -1;
hfutrell@2744
   685
	}
hfutrell@2744
   686
	palette = SDL_CurrentDisplay.palette;
hfutrell@2744
   687
	if (!palette) {
hfutrell@2744
   688
		SDL_SetError("Display mode does not have a palette");
hfutrell@2744
   689
		return -1;
hfutrell@2744
   690
	}
hfutrell@2744
   691
	status = SDL_SetPaletteColors(palette, colors, firstcolor, ncolors);
slouken@0
   692
hfutrell@2744
   693
	if (_this->SetDisplayPalette) {
hfutrell@2744
   694
		if (_this->SetDisplayPalette(_this, palette) < 0) {
hfutrell@2744
   695
			status = -1;
hfutrell@2744
   696
		}
hfutrell@2744
   697
	}
hfutrell@2744
   698
	return status;
slouken@0
   699
}
slouken@0
   700
slouken@1895
   701
int
slouken@1895
   702
SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors)
slouken@0
   703
{
hfutrell@2744
   704
	SDL_Palette    *palette;
slouken@1895
   705
hfutrell@2744
   706
	if (!_this) {
hfutrell@2744
   707
		SDL_UninitializedVideo();
hfutrell@2744
   708
		return -1;
hfutrell@2744
   709
	}
hfutrell@2744
   710
	palette = SDL_CurrentDisplay.palette;
hfutrell@2744
   711
	if (!palette->ncolors) {
hfutrell@2744
   712
		SDL_SetError("Display mode does not have a palette");
hfutrell@2744
   713
		return -1;
hfutrell@2744
   714
	}
hfutrell@2744
   715
	if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) {
hfutrell@2744
   716
		SDL_SetError("Palette indices are out of range");
hfutrell@2744
   717
		return -1;
hfutrell@2744
   718
	}
hfutrell@2744
   719
	SDL_memcpy(colors, &palette->colors[firstcolor],
hfutrell@2744
   720
		   ncolors * sizeof(*colors));
hfutrell@2744
   721
	return 0;
slouken@0
   722
}
slouken@0
   723
slouken@1895
   724
SDL_WindowID
slouken@1895
   725
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
slouken@0
   726
{
hfutrell@2744
   727
	const Uint32    allowed_flags = (SDL_WINDOW_FULLSCREEN |
hfutrell@2744
   728
					 SDL_WINDOW_OPENGL |
hfutrell@2744
   729
					 SDL_WINDOW_BORDERLESS |
hfutrell@2744
   730
					 SDL_WINDOW_RESIZABLE);
hfutrell@2744
   731
	SDL_VideoDisplay *display;
hfutrell@2744
   732
	SDL_Window      window;
hfutrell@2744
   733
	int             num_windows;
hfutrell@2744
   734
	SDL_Window     *windows;
slouken@0
   735
hfutrell@2744
   736
	if (!_this) {
hfutrell@2744
   737
		SDL_UninitializedVideo();
hfutrell@2744
   738
		return 0;
hfutrell@2744
   739
	}
hfutrell@2744
   740
	if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
hfutrell@2744
   741
		SDL_SetError("No OpenGL support in video driver");
hfutrell@2744
   742
		return 0;
hfutrell@2744
   743
	}
hfutrell@2744
   744
	/* Fullscreen windows don't have any window decorations */
hfutrell@2744
   745
	if (flags & SDL_WINDOW_FULLSCREEN) {
hfutrell@2744
   746
		flags |= SDL_WINDOW_BORDERLESS;
hfutrell@2744
   747
		flags &= ~SDL_WINDOW_RESIZABLE;
hfutrell@2744
   748
	}
hfutrell@2744
   749
	SDL_zero(window);
hfutrell@2744
   750
	window.id = _this->next_object_id++;
hfutrell@2744
   751
	window.x = x;
hfutrell@2744
   752
	window.y = y;
hfutrell@2744
   753
	window.w = w;
hfutrell@2744
   754
	window.h = h;
hfutrell@2744
   755
	window.flags = (flags & allowed_flags);
hfutrell@2744
   756
	window.display = _this->current_display;
slouken@1912
   757
hfutrell@2744
   758
	if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
hfutrell@2744
   759
		return 0;
hfutrell@2744
   760
	}
hfutrell@2744
   761
	display = &SDL_CurrentDisplay;
hfutrell@2744
   762
	num_windows = display->num_windows;
hfutrell@2744
   763
	windows =
hfutrell@2744
   764
		SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
hfutrell@2744
   765
	if (!windows) {
hfutrell@2744
   766
		if (_this->DestroyWindow) {
hfutrell@2744
   767
			_this->DestroyWindow(_this, &window);
hfutrell@2744
   768
		}
hfutrell@2744
   769
		return 0;
hfutrell@2744
   770
	}
hfutrell@2744
   771
	windows[num_windows] = window;
hfutrell@2744
   772
	display->windows = windows;
hfutrell@2744
   773
	display->num_windows++;
slouken@0
   774
hfutrell@2744
   775
	if (title) {
hfutrell@2744
   776
		SDL_SetWindowTitle(window.id, title);
hfutrell@2744
   777
	}
hfutrell@2744
   778
	if (flags & SDL_WINDOW_MAXIMIZED) {
hfutrell@2744
   779
		SDL_MaximizeWindow(window.id);
hfutrell@2744
   780
	}
hfutrell@2744
   781
	if (flags & SDL_WINDOW_MINIMIZED) {
hfutrell@2744
   782
		SDL_MinimizeWindow(window.id);
hfutrell@2744
   783
	}
hfutrell@2744
   784
	if (flags & SDL_WINDOW_SHOWN) {
hfutrell@2744
   785
		SDL_ShowWindow(window.id);
hfutrell@2744
   786
	}
hfutrell@2744
   787
	if (flags & SDL_WINDOW_INPUT_GRABBED) {
hfutrell@2744
   788
		SDL_SetWindowGrab(window.id, 1);
hfutrell@2744
   789
	}
hfutrell@2744
   790
	return window.id;
slouken@1895
   791
}
slouken@0
   792
slouken@1895
   793
SDL_WindowID
slouken@1895
   794
SDL_CreateWindowFrom(const void *data)
slouken@1895
   795
{
hfutrell@2744
   796
	SDL_VideoDisplay *display;
hfutrell@2744
   797
	SDL_Window      window;
hfutrell@2744
   798
	int             num_windows;
hfutrell@2744
   799
	SDL_Window     *windows;
slouken@0
   800
hfutrell@2744
   801
	if (!_this) {
hfutrell@2744
   802
		SDL_UninitializedVideo();
hfutrell@2744
   803
		return (0);
hfutrell@2744
   804
	}
hfutrell@2744
   805
	SDL_zero(window);
hfutrell@2744
   806
	window.id = _this->next_object_id++;
hfutrell@2744
   807
	window.display = _this->current_display;
slouken@1895
   808
hfutrell@2744
   809
	if (!_this->CreateWindowFrom ||
hfutrell@2744
   810
	    _this->CreateWindowFrom(_this, &window, data) < 0) {
hfutrell@2744
   811
		return 0;
hfutrell@2744
   812
	}
hfutrell@2744
   813
	display = &SDL_CurrentDisplay;
hfutrell@2744
   814
	num_windows = display->num_windows;
hfutrell@2744
   815
	windows =
hfutrell@2744
   816
		SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
hfutrell@2744
   817
	if (!windows) {
hfutrell@2744
   818
		if (_this->DestroyWindow) {
hfutrell@2744
   819
			_this->DestroyWindow(_this, &window);
hfutrell@2744
   820
		}
hfutrell@2744
   821
		if (window.title) {
hfutrell@2744
   822
			SDL_free(window.title);
hfutrell@2744
   823
		}
hfutrell@2744
   824
		return 0;
hfutrell@2744
   825
	}
hfutrell@2744
   826
	windows[num_windows] = window;
hfutrell@2744
   827
	display->windows = windows;
hfutrell@2744
   828
	display->num_windows++;
slouken@1895
   829
hfutrell@2744
   830
	return window.id;
slouken@1895
   831
}
slouken@1895
   832
slouken@1924
   833
int
slouken@1928
   834
SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
slouken@1924
   835
{
hfutrell@2744
   836
	char           *title = window->title;
slouken@1956
   837
hfutrell@2744
   838
	if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
hfutrell@2744
   839
		SDL_SetError("No OpenGL support in video driver");
hfutrell@2744
   840
		return -1;
hfutrell@2744
   841
	}
hfutrell@2744
   842
	if (_this->DestroyWindow) {
hfutrell@2744
   843
		_this->DestroyWindow(_this, window);
hfutrell@2744
   844
	}
hfutrell@2744
   845
	window->title = NULL;
hfutrell@2744
   846
	window->flags =
hfutrell@2744
   847
		(flags &
hfutrell@2744
   848
	  ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_SHOWN |
hfutrell@2744
   849
	    SDL_WINDOW_INPUT_GRABBED));
slouken@1956
   850
hfutrell@2744
   851
	if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
hfutrell@2744
   852
		return -1;
hfutrell@2744
   853
	}
hfutrell@2744
   854
	if (title) {
hfutrell@2744
   855
		SDL_SetWindowTitle(window->id, title);
hfutrell@2744
   856
		SDL_free(title);
hfutrell@2744
   857
	}
hfutrell@2744
   858
	if (flags & SDL_WINDOW_MAXIMIZED) {
hfutrell@2744
   859
		SDL_MaximizeWindow(window->id);
hfutrell@2744
   860
	}
hfutrell@2744
   861
	if (flags & SDL_WINDOW_MINIMIZED) {
hfutrell@2744
   862
		SDL_MinimizeWindow(window->id);
hfutrell@2744
   863
	}
hfutrell@2744
   864
	if (flags & SDL_WINDOW_SHOWN) {
hfutrell@2744
   865
		SDL_ShowWindow(window->id);
hfutrell@2744
   866
	}
hfutrell@2744
   867
	if (flags & SDL_WINDOW_INPUT_GRABBED) {
hfutrell@2744
   868
		SDL_SetWindowGrab(window->id, 1);
hfutrell@2744
   869
	}
hfutrell@2744
   870
	return 0;
slouken@1924
   871
}
slouken@1924
   872
hfutrell@2744
   873
SDL_Window     *
slouken@1895
   874
SDL_GetWindowFromID(SDL_WindowID windowID)
slouken@1895
   875
{
hfutrell@2744
   876
	int             i, j;
slouken@1895
   877
hfutrell@2744
   878
	if (!_this) {
hfutrell@2744
   879
		SDL_UninitializedVideo();
hfutrell@2744
   880
		return NULL;
hfutrell@2744
   881
	}
hfutrell@2744
   882
	for (i = 0; i < _this->num_displays; ++i) {
hfutrell@2744
   883
		SDL_VideoDisplay *display = &_this->displays[i];
hfutrell@2744
   884
		for (j = 0; j < display->num_windows; ++j) {
hfutrell@2744
   885
			SDL_Window     *window = &display->windows[j];
hfutrell@2744
   886
			if (window->id == windowID) {
hfutrell@2744
   887
				return window;
hfutrell@2744
   888
			}
hfutrell@2744
   889
		}
hfutrell@2744
   890
	}
hfutrell@2744
   891
	return NULL;
slouken@1895
   892
}
slouken@1895
   893
slouken@1895
   894
SDL_VideoDisplay *
slouken@1895
   895
SDL_GetDisplayFromWindow(SDL_Window * window)
slouken@1895
   896
{
hfutrell@2744
   897
	if (!_this) {
hfutrell@2744
   898
		SDL_UninitializedVideo();
hfutrell@2744
   899
		return NULL;
hfutrell@2744
   900
	}
hfutrell@2744
   901
	if (!window) {
hfutrell@2744
   902
		return NULL;
hfutrell@2744
   903
	}
hfutrell@2744
   904
	return &_this->displays[window->display];
slouken@1895
   905
}
slouken@1895
   906
slouken@1895
   907
Uint32
slouken@1895
   908
SDL_GetWindowFlags(SDL_WindowID windowID)
slouken@1895
   909
{
hfutrell@2744
   910
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
   911
hfutrell@2744
   912
	if (!window) {
hfutrell@2744
   913
		return 0;
hfutrell@2744
   914
	}
hfutrell@2744
   915
	return window->flags;
slouken@1895
   916
}
slouken@1895
   917
slouken@1895
   918
void
slouken@1895
   919
SDL_SetWindowTitle(SDL_WindowID windowID, const char *title)
slouken@1895
   920
{
hfutrell@2744
   921
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
   922
hfutrell@2744
   923
	if (!window || title == window->title) {
hfutrell@2744
   924
		return;
hfutrell@2744
   925
	}
hfutrell@2744
   926
	if (window->title) {
hfutrell@2744
   927
		SDL_free(window->title);
hfutrell@2744
   928
	}
hfutrell@2744
   929
	if (title) {
hfutrell@2744
   930
		window->title = SDL_strdup(title);
hfutrell@2744
   931
	} else {
hfutrell@2744
   932
		window->title = NULL;
hfutrell@2744
   933
	}
slouken@1956
   934
hfutrell@2744
   935
	if (_this->SetWindowTitle) {
hfutrell@2744
   936
		_this->SetWindowTitle(_this, window);
hfutrell@2744
   937
	}
slouken@1895
   938
}
slouken@1895
   939
hfutrell@2744
   940
const char     *
slouken@1895
   941
SDL_GetWindowTitle(SDL_WindowID windowID)
slouken@1895
   942
{
hfutrell@2744
   943
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
   944
hfutrell@2744
   945
	if (!window) {
hfutrell@2744
   946
		return NULL;
hfutrell@2744
   947
	}
hfutrell@2744
   948
	return window->title;
slouken@1895
   949
}
slouken@1895
   950
slouken@1895
   951
void
slouken@1895
   952
SDL_SetWindowData(SDL_WindowID windowID, void *userdata)
slouken@1895
   953
{
hfutrell@2744
   954
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
   955
hfutrell@2744
   956
	if (!window) {
hfutrell@2744
   957
		return;
hfutrell@2744
   958
	}
hfutrell@2744
   959
	window->userdata = userdata;
slouken@1895
   960
}
slouken@1895
   961
hfutrell@2744
   962
void           *
slouken@1895
   963
SDL_GetWindowData(SDL_WindowID windowID)
slouken@1895
   964
{
hfutrell@2744
   965
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
   966
hfutrell@2744
   967
	if (!window) {
hfutrell@2744
   968
		return NULL;
hfutrell@2744
   969
	}
hfutrell@2744
   970
	return window->userdata;
slouken@1895
   971
}
slouken@1895
   972
slouken@1895
   973
void
slouken@1895
   974
SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y)
slouken@1895
   975
{
hfutrell@2744
   976
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
hfutrell@2744
   977
	SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1895
   978
hfutrell@2744
   979
	if (!window) {
hfutrell@2744
   980
		return;
hfutrell@2744
   981
	}
hfutrell@2744
   982
	if (x == SDL_WINDOWPOS_CENTERED) {
hfutrell@2744
   983
		window->x = (display->current_mode.w - window->w) / 2;
hfutrell@2744
   984
	} else if (x != SDL_WINDOWPOS_UNDEFINED) {
hfutrell@2744
   985
		window->x = x;
hfutrell@2744
   986
	}
hfutrell@2744
   987
	if (y == SDL_WINDOWPOS_CENTERED) {
hfutrell@2744
   988
		window->y = (display->current_mode.h - window->h) / 2;
hfutrell@2744
   989
	} else if (y != SDL_WINDOWPOS_UNDEFINED) {
hfutrell@2744
   990
		window->y = y;
hfutrell@2744
   991
	}
hfutrell@2744
   992
	if (_this->SetWindowPosition) {
hfutrell@2744
   993
		_this->SetWindowPosition(_this, window);
hfutrell@2744
   994
	}
slouken@1895
   995
}
slouken@1895
   996
slouken@1895
   997
void
slouken@1895
   998
SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y)
slouken@1895
   999
{
hfutrell@2744
  1000
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1001
hfutrell@2744
  1002
	if (!window) {
hfutrell@2744
  1003
		return;
hfutrell@2744
  1004
	}
hfutrell@2744
  1005
	if (x) {
hfutrell@2744
  1006
		*x = window->x;
hfutrell@2744
  1007
	}
hfutrell@2744
  1008
	if (y) {
hfutrell@2744
  1009
		*y = window->y;
hfutrell@2744
  1010
	}
slouken@1895
  1011
}
slouken@1895
  1012
slouken@1895
  1013
void
slouken@1895
  1014
SDL_SetWindowSize(SDL_WindowID windowID, int w, int h)
slouken@1895
  1015
{
hfutrell@2744
  1016
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1017
hfutrell@2744
  1018
	if (!window) {
hfutrell@2744
  1019
		return;
hfutrell@2744
  1020
	}
hfutrell@2744
  1021
	window->w = w;
hfutrell@2744
  1022
	window->h = h;
slouken@1895
  1023
hfutrell@2744
  1024
	if (_this->SetWindowSize) {
hfutrell@2744
  1025
		_this->SetWindowSize(_this, window);
hfutrell@2744
  1026
	}
slouken@1895
  1027
}
slouken@1895
  1028
slouken@1895
  1029
void
slouken@1895
  1030
SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h)
slouken@1895
  1031
{
hfutrell@2744
  1032
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1033
hfutrell@2744
  1034
	if (!window) {
hfutrell@2744
  1035
		return;
hfutrell@2744
  1036
	}
hfutrell@2744
  1037
	if (w) {
hfutrell@2744
  1038
		*w = window->w;
hfutrell@2744
  1039
	}
hfutrell@2744
  1040
	if (h) {
hfutrell@2744
  1041
		*h = window->h;
hfutrell@2744
  1042
	}
slouken@1895
  1043
}
slouken@1895
  1044
slouken@1895
  1045
void
slouken@1895
  1046
SDL_ShowWindow(SDL_WindowID windowID)
slouken@1895
  1047
{
hfutrell@2744
  1048
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1049
hfutrell@2744
  1050
	if (!window || (window->flags & SDL_WINDOW_SHOWN)) {
hfutrell@2744
  1051
		return;
hfutrell@2744
  1052
	}
hfutrell@2744
  1053
	SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@1895
  1054
hfutrell@2744
  1055
	if (_this->ShowWindow) {
hfutrell@2744
  1056
		_this->ShowWindow(_this, window);
hfutrell@2744
  1057
	}
slouken@1895
  1058
}
slouken@1895
  1059
slouken@1895
  1060
void
slouken@1895
  1061
SDL_HideWindow(SDL_WindowID windowID)
slouken@1895
  1062
{
hfutrell@2744
  1063
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1064
hfutrell@2744
  1065
	if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
hfutrell@2744
  1066
		return;
hfutrell@2744
  1067
	}
hfutrell@2744
  1068
	SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@1895
  1069
hfutrell@2744
  1070
	if (_this->HideWindow) {
hfutrell@2744
  1071
		_this->HideWindow(_this, window);
hfutrell@2744
  1072
	}
slouken@1895
  1073
}
slouken@1895
  1074
slouken@1895
  1075
void
slouken@1895
  1076
SDL_RaiseWindow(SDL_WindowID windowID)
slouken@1895
  1077
{
hfutrell@2744
  1078
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1079
hfutrell@2744
  1080
	if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
hfutrell@2744
  1081
		return;
hfutrell@2744
  1082
	}
hfutrell@2744
  1083
	if (_this->RaiseWindow) {
hfutrell@2744
  1084
		_this->RaiseWindow(_this, window);
hfutrell@2744
  1085
	}
slouken@1895
  1086
}
slouken@1895
  1087
slouken@1895
  1088
void
slouken@1895
  1089
SDL_MaximizeWindow(SDL_WindowID windowID)
slouken@1895
  1090
{
hfutrell@2744
  1091
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1092
hfutrell@2744
  1093
	if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) {
hfutrell@2744
  1094
		return;
hfutrell@2744
  1095
	}
hfutrell@2744
  1096
	SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
slouken@1895
  1097
hfutrell@2744
  1098
	if (_this->MaximizeWindow) {
hfutrell@2744
  1099
		_this->MaximizeWindow(_this, window);
hfutrell@2744
  1100
	}
slouken@1895
  1101
}
slouken@1895
  1102
slouken@1895
  1103
void
slouken@1895
  1104
SDL_MinimizeWindow(SDL_WindowID windowID)
slouken@1895
  1105
{
hfutrell@2744
  1106
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1107
hfutrell@2744
  1108
	if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) {
hfutrell@2744
  1109
		return;
hfutrell@2744
  1110
	}
hfutrell@2744
  1111
	SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1895
  1112
hfutrell@2744
  1113
	if (_this->MinimizeWindow) {
hfutrell@2744
  1114
		_this->MinimizeWindow(_this, window);
hfutrell@2744
  1115
	}
slouken@1895
  1116
}
slouken@1895
  1117
slouken@1895
  1118
void
slouken@1895
  1119
SDL_RestoreWindow(SDL_WindowID windowID)
slouken@1895
  1120
{
hfutrell@2744
  1121
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1122
hfutrell@2744
  1123
	if (!window
hfutrell@2744
  1124
	|| (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
hfutrell@2744
  1125
		return;
hfutrell@2744
  1126
	}
hfutrell@2744
  1127
	SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@1895
  1128
hfutrell@2744
  1129
	if (_this->RestoreWindow) {
hfutrell@2744
  1130
		_this->RestoreWindow(_this, window);
hfutrell@2744
  1131
	}
slouken@1895
  1132
}
slouken@1895
  1133
slouken@1895
  1134
int
slouken@1895
  1135
SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen)
slouken@1895
  1136
{
hfutrell@2744
  1137
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1138
hfutrell@2744
  1139
	if (!window) {
hfutrell@2744
  1140
		return -1;
hfutrell@2744
  1141
	}
hfutrell@2744
  1142
	if (fullscreen) {
hfutrell@2744
  1143
		fullscreen = SDL_WINDOW_FULLSCREEN;
hfutrell@2744
  1144
	}
hfutrell@2744
  1145
	if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
hfutrell@2744
  1146
		return 0;
hfutrell@2744
  1147
	}
hfutrell@2744
  1148
	if (fullscreen) {
hfutrell@2744
  1149
		window->flags |= SDL_WINDOW_FULLSCREEN;
slouken@1895
  1150
hfutrell@2744
  1151
		if (FULLSCREEN_VISIBLE(window)) {
hfutrell@2744
  1152
			SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1895
  1153
hfutrell@2744
  1154
			/* Hide any other fullscreen windows */
hfutrell@2744
  1155
			int             i;
hfutrell@2744
  1156
			for (i = 0; i < display->num_windows; ++i) {
hfutrell@2744
  1157
				SDL_Window     *other = &display->windows[i];
hfutrell@2744
  1158
				if (other->id != windowID && FULLSCREEN_VISIBLE(other)) {
hfutrell@2744
  1159
					SDL_MinimizeWindow(other->id);
hfutrell@2744
  1160
				}
hfutrell@2744
  1161
			}
slouken@1895
  1162
hfutrell@2744
  1163
			SDL_SetDisplayMode(&display->fullscreen_mode);
hfutrell@2744
  1164
		}
hfutrell@2744
  1165
	} else {
hfutrell@2744
  1166
		window->flags &= ~SDL_WINDOW_FULLSCREEN;
slouken@1895
  1167
hfutrell@2744
  1168
		if (FULLSCREEN_VISIBLE(window)) {
hfutrell@2744
  1169
			SDL_SetDisplayMode(NULL);
hfutrell@2744
  1170
		}
hfutrell@2744
  1171
	}
hfutrell@2744
  1172
	return 0;
slouken@1895
  1173
}
slouken@1895
  1174
slouken@1895
  1175
void
slouken@1895
  1176
SDL_SetWindowGrab(SDL_WindowID windowID, int mode)
slouken@1895
  1177
{
hfutrell@2744
  1178
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1179
hfutrell@2744
  1180
	if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
hfutrell@2744
  1181
		return;
hfutrell@2744
  1182
	}
hfutrell@2744
  1183
	if (mode) {
hfutrell@2744
  1184
		window->flags |= SDL_WINDOW_INPUT_GRABBED;
hfutrell@2744
  1185
	} else {
hfutrell@2744
  1186
		window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
hfutrell@2744
  1187
	}
slouken@1895
  1188
hfutrell@2744
  1189
	if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) {
hfutrell@2744
  1190
		_this->SetWindowGrab(_this, window);
hfutrell@2744
  1191
	}
slouken@1895
  1192
}
slouken@1895
  1193
slouken@1895
  1194
int
slouken@1895
  1195
SDL_GetWindowGrab(SDL_WindowID windowID)
slouken@1895
  1196
{
hfutrell@2744
  1197
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1198
hfutrell@2744
  1199
	if (!window) {
hfutrell@2744
  1200
		return 0;
hfutrell@2744
  1201
	}
hfutrell@2744
  1202
	return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
slouken@1895
  1203
}
slouken@1895
  1204
slouken@1895
  1205
void
slouken@1895
  1206
SDL_OnWindowShown(SDL_Window * window)
slouken@1895
  1207
{
slouken@1895
  1208
}
slouken@1895
  1209
slouken@1895
  1210
void
slouken@1895
  1211
SDL_OnWindowHidden(SDL_Window * window)
slouken@1895
  1212
{
slouken@1895
  1213
}
slouken@1895
  1214
slouken@1895
  1215
void
slouken@1970
  1216
SDL_OnWindowResized(SDL_Window * window)
slouken@1970
  1217
{
hfutrell@2744
  1218
	SDL_Renderer   *renderer = window->renderer;
slouken@1970
  1219
hfutrell@2744
  1220
	if (renderer && renderer->DisplayModeChanged) {
hfutrell@2744
  1221
		renderer->DisplayModeChanged(renderer);
hfutrell@2744
  1222
	}
slouken@1970
  1223
}
slouken@1970
  1224
slouken@1970
  1225
void
slouken@1895
  1226
SDL_OnWindowFocusGained(SDL_Window * window)
slouken@1895
  1227
{
hfutrell@2744
  1228
	SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1895
  1229
hfutrell@2744
  1230
	if (window->flags & SDL_WINDOW_FULLSCREEN) {
hfutrell@2744
  1231
		SDL_SetDisplayMode(&display->fullscreen_mode);
hfutrell@2744
  1232
	}
hfutrell@2744
  1233
	if (display->gamma && _this->SetDisplayGammaRamp) {
hfutrell@2744
  1234
		_this->SetDisplayGammaRamp(_this, display->gamma);
hfutrell@2744
  1235
	}
hfutrell@2744
  1236
	if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) {
hfutrell@2744
  1237
		_this->SetWindowGrab(_this, window);
hfutrell@2744
  1238
	}
slouken@1895
  1239
}
slouken@1895
  1240
slouken@1895
  1241
void
slouken@1895
  1242
SDL_OnWindowFocusLost(SDL_Window * window)
slouken@1895
  1243
{
hfutrell@2744
  1244
	SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1895
  1245
hfutrell@2744
  1246
	if (window->flags & SDL_WINDOW_FULLSCREEN) {
hfutrell@2744
  1247
		SDL_MinimizeWindow(window->id);
hfutrell@2744
  1248
		SDL_SetDisplayMode(NULL);
hfutrell@2744
  1249
	}
hfutrell@2744
  1250
	if (display->gamma && _this->SetDisplayGammaRamp) {
hfutrell@2744
  1251
		_this->SetDisplayGammaRamp(_this, display->saved_gamma);
hfutrell@2744
  1252
	}
hfutrell@2744
  1253
	if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) {
hfutrell@2744
  1254
		_this->SetWindowGrab(_this, window);
hfutrell@2744
  1255
	}
slouken@1895
  1256
}
slouken@1895
  1257
slouken@1895
  1258
SDL_WindowID
slouken@1895
  1259
SDL_GetFocusWindow(void)
slouken@1895
  1260
{
hfutrell@2744
  1261
	SDL_VideoDisplay *display;
hfutrell@2744
  1262
	int             i;
slouken@1895
  1263
hfutrell@2744
  1264
	if (!_this) {
hfutrell@2744
  1265
		return 0;
hfutrell@2744
  1266
	}
hfutrell@2744
  1267
	display = &SDL_CurrentDisplay;
hfutrell@2744
  1268
	for (i = 0; i < display->num_windows; ++i) {
hfutrell@2744
  1269
		SDL_Window     *window = &display->windows[i];
slouken@1895
  1270
hfutrell@2744
  1271
		if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
hfutrell@2744
  1272
			return window->id;
hfutrell@2744
  1273
		}
hfutrell@2744
  1274
	}
hfutrell@2744
  1275
	return 0;
slouken@1895
  1276
}
slouken@1895
  1277
slouken@1895
  1278
void
slouken@1895
  1279
SDL_DestroyWindow(SDL_WindowID windowID)
slouken@1895
  1280
{
hfutrell@2744
  1281
	int             i, j;
slouken@1895
  1282
hfutrell@2744
  1283
	if (!_this) {
hfutrell@2744
  1284
		return;
hfutrell@2744
  1285
	}
hfutrell@2744
  1286
	/* Restore video mode, etc. */
hfutrell@2744
  1287
	SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
slouken@1895
  1288
hfutrell@2744
  1289
	for (i = 0; i < _this->num_displays; ++i) {
hfutrell@2744
  1290
		SDL_VideoDisplay *display = &_this->displays[i];
hfutrell@2744
  1291
		for (j = 0; j < display->num_windows; ++j) {
hfutrell@2744
  1292
			SDL_Window     *window = &display->windows[j];
hfutrell@2744
  1293
			if (window->id != windowID) {
hfutrell@2744
  1294
				continue;
hfutrell@2744
  1295
			}
hfutrell@2744
  1296
			if (window->title) {
hfutrell@2744
  1297
				SDL_free(window->title);
hfutrell@2744
  1298
				window->title = NULL;
hfutrell@2744
  1299
			}
hfutrell@2744
  1300
			if (window->renderer) {
hfutrell@2744
  1301
				SDL_DestroyRenderer(window->id);
hfutrell@2744
  1302
				window->renderer = NULL;
hfutrell@2744
  1303
			}
hfutrell@2744
  1304
			if (_this->DestroyWindow) {
hfutrell@2744
  1305
				_this->DestroyWindow(_this, window);
hfutrell@2744
  1306
			}
hfutrell@2744
  1307
			if (j != display->num_windows - 1) {
hfutrell@2744
  1308
				SDL_memcpy(&display->windows[i],
hfutrell@2744
  1309
					   &display->windows[i + 1],
hfutrell@2744
  1310
					   (display->num_windows - i - 1) * sizeof(*window));
hfutrell@2744
  1311
			}
hfutrell@2744
  1312
			--display->num_windows;
hfutrell@2744
  1313
			return;
hfutrell@2744
  1314
		}
hfutrell@2744
  1315
	}
slouken@1895
  1316
}
slouken@1895
  1317
slouken@1895
  1318
void
slouken@1895
  1319
SDL_AddRenderDriver(int displayIndex, const SDL_RenderDriver * driver)
slouken@1895
  1320
{
hfutrell@2744
  1321
	SDL_VideoDisplay *display;
hfutrell@2744
  1322
	SDL_RenderDriver *render_drivers;
slouken@1895
  1323
hfutrell@2744
  1324
	if (displayIndex >= _this->num_displays) {
hfutrell@2744
  1325
		return;
hfutrell@2744
  1326
	}
hfutrell@2744
  1327
	display = &_this->displays[displayIndex];
slouken@2119
  1328
hfutrell@2744
  1329
	render_drivers =
hfutrell@2744
  1330
		SDL_realloc(display->render_drivers,
hfutrell@2744
  1331
			    (display->num_render_drivers +
hfutrell@2744
  1332
			     1) * sizeof(*render_drivers));
hfutrell@2744
  1333
	if (render_drivers) {
hfutrell@2744
  1334
		render_drivers[display->num_render_drivers] = *driver;
hfutrell@2744
  1335
		display->render_drivers = render_drivers;
hfutrell@2744
  1336
		display->num_render_drivers++;
hfutrell@2744
  1337
	}
slouken@1895
  1338
}
slouken@1895
  1339
slouken@1895
  1340
int
slouken@1969
  1341
SDL_GetNumRenderDrivers(void)
slouken@1895
  1342
{
hfutrell@2744
  1343
	if (_this) {
hfutrell@2744
  1344
		return SDL_CurrentDisplay.num_render_drivers;
hfutrell@2744
  1345
	}
hfutrell@2744
  1346
	return 0;
slouken@1895
  1347
}
slouken@1895
  1348
slouken@1895
  1349
int
slouken@1969
  1350
SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info)
slouken@1895
  1351
{
hfutrell@2744
  1352
	if (!_this) {
hfutrell@2744
  1353
		SDL_UninitializedVideo();
hfutrell@2744
  1354
		return -1;
hfutrell@2744
  1355
	}
hfutrell@2744
  1356
	if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
hfutrell@2744
  1357
		SDL_SetError("index must be in the range of 0 - %d",
hfutrell@2744
  1358
			     SDL_GetNumRenderDrivers() - 1);
hfutrell@2744
  1359
		return -1;
hfutrell@2744
  1360
	}
hfutrell@2744
  1361
	*info = SDL_CurrentDisplay.render_drivers[index].info;
hfutrell@2744
  1362
	return 0;
slouken@1895
  1363
}
slouken@1895
  1364
slouken@1895
  1365
int
slouken@1895
  1366
SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags)
slouken@1895
  1367
{
hfutrell@2744
  1368
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  1369
hfutrell@2744
  1370
	if (!window) {
hfutrell@2744
  1371
		return 0;
hfutrell@2744
  1372
	}
hfutrell@2744
  1373
	if (index < 0) {
hfutrell@2744
  1374
		const char     *override = SDL_getenv("SDL_VIDEO_RENDERER");
hfutrell@2744
  1375
		int             n = SDL_GetNumRenderDrivers();
hfutrell@2744
  1376
		for (index = 0; index < n; ++index) {
hfutrell@2744
  1377
			SDL_RenderDriver *driver =
hfutrell@2744
  1378
			&SDL_CurrentDisplay.render_drivers[index];
slouken@1895
  1379
hfutrell@2744
  1380
			if (override) {
hfutrell@2744
  1381
				if (SDL_strcasecmp(override, driver->info.name) == 0) {
hfutrell@2744
  1382
					break;
hfutrell@2744
  1383
				}
hfutrell@2744
  1384
			} else {
hfutrell@2744
  1385
				if ((driver->info.flags & flags) == flags) {
hfutrell@2744
  1386
					break;
hfutrell@2744
  1387
				}
hfutrell@2744
  1388
			}
hfutrell@2744
  1389
		}
hfutrell@2744
  1390
		if (index == n) {
hfutrell@2744
  1391
			SDL_SetError("Couldn't find matching render driver");
hfutrell@2744
  1392
			return -1;
hfutrell@2744
  1393
		}
hfutrell@2744
  1394
	}
hfutrell@2744
  1395
	if (index >= SDL_GetNumRenderDrivers()) {
hfutrell@2744
  1396
		SDL_SetError("index must be -1 or in the range of 0 - %d",
hfutrell@2744
  1397
			     SDL_GetNumRenderDrivers() - 1);
hfutrell@2744
  1398
		return -1;
hfutrell@2744
  1399
	}
hfutrell@2744
  1400
	/* Free any existing renderer */
hfutrell@2744
  1401
	SDL_DestroyRenderer(windowID);
slouken@1895
  1402
hfutrell@2744
  1403
	/* Create a new renderer instance */
hfutrell@2744
  1404
	window->renderer = SDL_CurrentDisplay.render_drivers[index]
hfutrell@2744
  1405
		.CreateRenderer(window, flags);
hfutrell@2744
  1406
	SDL_SelectRenderer(window->id);
slouken@1895
  1407
hfutrell@2744
  1408
	return 0;
slouken@1895
  1409
}
slouken@1895
  1410
slouken@1895
  1411
int
slouken@1895
  1412
SDL_SelectRenderer(SDL_WindowID windowID)
slouken@1895
  1413
{
hfutrell@2744
  1414
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
hfutrell@2744
  1415
	SDL_Renderer   *renderer;
slouken@1895
  1416
hfutrell@2744
  1417
	if (!window || !window->renderer) {
hfutrell@2744
  1418
		return -1;
hfutrell@2744
  1419
	}
hfutrell@2744
  1420
	renderer = window->renderer;
hfutrell@2744
  1421
	if (renderer && renderer->ActivateRenderer) {
hfutrell@2744
  1422
		if (renderer->ActivateRenderer(renderer) < 0) {
hfutrell@2744
  1423
			return -1;
hfutrell@2744
  1424
		}
hfutrell@2744
  1425
	}
hfutrell@2744
  1426
	SDL_CurrentDisplay.current_renderer = renderer;
hfutrell@2744
  1427
	return 0;
slouken@1895
  1428
}
slouken@1895
  1429
slouken@1969
  1430
int
slouken@1969
  1431
SDL_GetRendererInfo(SDL_RendererInfo * info)
slouken@1969
  1432
{
hfutrell@2744
  1433
	if (!_this) {
hfutrell@2744
  1434
		SDL_UninitializedVideo();
hfutrell@2744
  1435
		return -1;
hfutrell@2744
  1436
	}
hfutrell@2744
  1437
	if (!SDL_CurrentDisplay.current_renderer) {
hfutrell@2744
  1438
		SDL_SetError("There is no current renderer");
hfutrell@2744
  1439
		return -1;
hfutrell@2744
  1440
	}
hfutrell@2744
  1441
	*info = SDL_CurrentDisplay.current_renderer->info;
hfutrell@2744
  1442
	return 0;
slouken@1969
  1443
}
slouken@1969
  1444
slouken@1895
  1445
SDL_TextureID
slouken@1895
  1446
SDL_CreateTexture(Uint32 format, int access, int w, int h)
slouken@1895
  1447
{
hfutrell@2744
  1448
	int             hash;
hfutrell@2744
  1449
	SDL_Renderer   *renderer;
hfutrell@2744
  1450
	SDL_Texture    *texture;
slouken@1895
  1451
hfutrell@2744
  1452
	if (!_this) {
hfutrell@2744
  1453
		SDL_UninitializedVideo();
hfutrell@2744
  1454
		return 0;
hfutrell@2744
  1455
	}
hfutrell@2744
  1456
	renderer = SDL_CurrentDisplay.current_renderer;
hfutrell@2744
  1457
	if (!renderer || !renderer->CreateTexture) {
hfutrell@2744
  1458
		return 0;
hfutrell@2744
  1459
	}
hfutrell@2744
  1460
	texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
hfutrell@2744
  1461
	if (!texture) {
hfutrell@2744
  1462
		SDL_OutOfMemory();
hfutrell@2744
  1463
		return 0;
hfutrell@2744
  1464
	}
hfutrell@2744
  1465
	texture->id = _this->next_object_id++;
hfutrell@2744
  1466
	texture->format = format;
hfutrell@2744
  1467
	texture->access = access;
hfutrell@2744
  1468
	texture->w = w;
hfutrell@2744
  1469
	texture->h = h;
hfutrell@2744
  1470
	texture->r = 255;
hfutrell@2744
  1471
	texture->g = 255;
hfutrell@2744
  1472
	texture->b = 255;
hfutrell@2744
  1473
	texture->a = 255;
hfutrell@2744
  1474
	texture->renderer = renderer;
slouken@1895
  1475
hfutrell@2744
  1476
	if (renderer->CreateTexture(renderer, texture) < 0) {
hfutrell@2744
  1477
		if (renderer->DestroyTexture) {
hfutrell@2744
  1478
			renderer->DestroyTexture(renderer, texture);
hfutrell@2744
  1479
		}
hfutrell@2744
  1480
		SDL_free(texture);
hfutrell@2744
  1481
		return 0;
hfutrell@2744
  1482
	}
hfutrell@2744
  1483
	hash = (texture->id % SDL_arraysize(SDL_CurrentDisplay.textures));
hfutrell@2744
  1484
	texture->next = SDL_CurrentDisplay.textures[hash];
hfutrell@2744
  1485
	SDL_CurrentDisplay.textures[hash] = texture;
slouken@1895
  1486
hfutrell@2744
  1487
	return texture->id;
slouken@1895
  1488
}
slouken@1895
  1489
slouken@1895
  1490
SDL_TextureID
slouken@2222
  1491
SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
slouken@1895
  1492
{
hfutrell@2744
  1493
	SDL_TextureID   textureID;
hfutrell@2744
  1494
	SDL_PixelFormat *fmt;
hfutrell@2744
  1495
	int             bpp;
hfutrell@2744
  1496
	Uint32          Rmask, Gmask, Bmask, Amask;
slouken@1895
  1497
hfutrell@2744
  1498
	if (!surface) {
hfutrell@2744
  1499
		SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
hfutrell@2744
  1500
		return 0;
hfutrell@2744
  1501
	}
hfutrell@2744
  1502
	fmt = surface->format;
slouken@1895
  1503
hfutrell@2744
  1504
	if (format) {
hfutrell@2744
  1505
		if (!SDL_PixelFormatEnumToMasks
hfutrell@2744
  1506
		    (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
hfutrell@2744
  1507
			SDL_SetError("Unknown pixel format");
hfutrell@2744
  1508
			return 0;
hfutrell@2744
  1509
		}
hfutrell@2744
  1510
	} else {
hfutrell@2744
  1511
		if (surface->format->Amask
hfutrell@2744
  1512
		    || !(surface->map->info.flags &
hfutrell@2744
  1513
		    (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) {
hfutrell@2744
  1514
			bpp = fmt->BitsPerPixel;
hfutrell@2744
  1515
			Rmask = fmt->Rmask;
hfutrell@2744
  1516
			Gmask = fmt->Gmask;
hfutrell@2744
  1517
			Bmask = fmt->Bmask;
hfutrell@2744
  1518
			Amask = fmt->Amask;
hfutrell@2744
  1519
		} else {
hfutrell@2744
  1520
			/* Need a format with alpha */
hfutrell@2744
  1521
			bpp = 32;
hfutrell@2744
  1522
			Rmask = 0x00FF0000;
hfutrell@2744
  1523
			Gmask = 0x0000FF00;
hfutrell@2744
  1524
			Bmask = 0x000000FF;
hfutrell@2744
  1525
			Amask = 0xFF000000;
hfutrell@2744
  1526
		}
hfutrell@2744
  1527
		format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
hfutrell@2744
  1528
		if (!format) {
hfutrell@2744
  1529
			SDL_SetError("Unknown pixel format");
hfutrell@2744
  1530
			return 0;
hfutrell@2744
  1531
		}
hfutrell@2744
  1532
	}
slouken@1895
  1533
hfutrell@2744
  1534
	textureID =
hfutrell@2744
  1535
		SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
hfutrell@2744
  1536
				  surface->h);
hfutrell@2744
  1537
	if (!textureID) {
hfutrell@2744
  1538
		return 0;
hfutrell@2744
  1539
	}
hfutrell@2744
  1540
	if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask
hfutrell@2744
  1541
	    && Bmask == fmt->Bmask && Amask == fmt->Amask) {
hfutrell@2744
  1542
		if (SDL_MUSTLOCK(surface)) {
hfutrell@2744
  1543
			if (SDL_LockSurface(surface) < 0) {
hfutrell@2744
  1544
				SDL_DestroyTexture(textureID);
hfutrell@2744
  1545
				return 0;
hfutrell@2744
  1546
			}
hfutrell@2744
  1547
			SDL_UpdateTexture(textureID, NULL, surface->pixels,
hfutrell@2744
  1548
					  surface->pitch);
hfutrell@2744
  1549
			SDL_UnlockSurface(surface);
hfutrell@2744
  1550
		} else {
hfutrell@2744
  1551
			SDL_UpdateTexture(textureID, NULL, surface->pixels,
hfutrell@2744
  1552
					  surface->pitch);
hfutrell@2744
  1553
		}
hfutrell@2744
  1554
	} else {
hfutrell@2744
  1555
		SDL_PixelFormat *dst_fmt;
hfutrell@2744
  1556
		SDL_Surface    *dst = NULL;
slouken@1895
  1557
hfutrell@2744
  1558
		/* Set up a destination surface for the texture update */
hfutrell@2744
  1559
		dst_fmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
hfutrell@2744
  1560
		if (dst_fmt) {
hfutrell@2744
  1561
			if (SDL_ISPIXELFORMAT_INDEXED(format)) {
hfutrell@2744
  1562
				dst_fmt->palette =
hfutrell@2744
  1563
					SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
hfutrell@2744
  1564
				if (dst_fmt->palette) {
hfutrell@2744
  1565
					/*
hfutrell@2744
  1566
					 * FIXME: Should we try to copy
hfutrell@2744
  1567
					 * fmt->palette?
hfutrell@2744
  1568
					 */
hfutrell@2744
  1569
					SDL_DitherColors(dst_fmt->palette->colors,
hfutrell@2744
  1570
						  SDL_BITSPERPIXEL(format));
hfutrell@2744
  1571
				}
hfutrell@2744
  1572
			}
hfutrell@2744
  1573
			dst = SDL_ConvertSurface(surface, dst_fmt, 0);
hfutrell@2744
  1574
			if (dst) {
hfutrell@2744
  1575
				SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
hfutrell@2744
  1576
				SDL_FreeSurface(dst);
hfutrell@2744
  1577
			}
hfutrell@2744
  1578
			if (dst_fmt->palette) {
hfutrell@2744
  1579
				SDL_FreePalette(dst_fmt->palette);
hfutrell@2744
  1580
			}
hfutrell@2744
  1581
			SDL_FreeFormat(dst_fmt);
hfutrell@2744
  1582
		}
hfutrell@2744
  1583
		if (!dst) {
hfutrell@2744
  1584
			SDL_DestroyTexture(textureID);
hfutrell@2744
  1585
			return 0;
hfutrell@2744
  1586
		}
hfutrell@2744
  1587
	}
slouken@2222
  1588
hfutrell@2744
  1589
	if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) {
hfutrell@2744
  1590
		SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
hfutrell@2744
  1591
				      fmt->palette->ncolors);
hfutrell@2744
  1592
	}
hfutrell@2744
  1593
	return textureID;
slouken@1895
  1594
}
slouken@1895
  1595
slouken@1895
  1596
static __inline__ SDL_Texture *
slouken@1895
  1597
SDL_GetTextureFromID(SDL_TextureID textureID)
slouken@1895
  1598
{
hfutrell@2744
  1599
	int             hash;
hfutrell@2744
  1600
	SDL_Texture    *texture;
slouken@1895
  1601
hfutrell@2744
  1602
	if (!_this) {
hfutrell@2744
  1603
		return NULL;
hfutrell@2744
  1604
	}
hfutrell@2744
  1605
	hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
hfutrell@2744
  1606
	for (texture = SDL_CurrentDisplay.textures[hash]; texture;
hfutrell@2744
  1607
	     texture = texture->next) {
hfutrell@2744
  1608
		if (texture->id == textureID) {
hfutrell@2744
  1609
			return texture;
hfutrell@2744
  1610
		}
hfutrell@2744
  1611
	}
hfutrell@2744
  1612
	return NULL;
slouken@1895
  1613
}
slouken@1895
  1614
slouken@1895
  1615
int
slouken@1895
  1616
SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access,
hfutrell@2744
  1617
		 int *w, int *h)
slouken@1895
  1618
{
hfutrell@2744
  1619
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
slouken@1895
  1620
hfutrell@2744
  1621
	if (!texture) {
hfutrell@2744
  1622
		return -1;
hfutrell@2744
  1623
	}
hfutrell@2744
  1624
	if (format) {
hfutrell@2744
  1625
		*format = texture->format;
hfutrell@2744
  1626
	}
hfutrell@2744
  1627
	if (access) {
hfutrell@2744
  1628
		*access = texture->access;
hfutrell@2744
  1629
	}
hfutrell@2744
  1630
	if (w) {
hfutrell@2744
  1631
		*w = texture->w;
hfutrell@2744
  1632
	}
hfutrell@2744
  1633
	if (h) {
hfutrell@2744
  1634
		*h = texture->h;
hfutrell@2744
  1635
	}
hfutrell@2744
  1636
	return 0;
slouken@1895
  1637
}
slouken@1895
  1638
slouken@1895
  1639
int
slouken@1895
  1640
SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch)
slouken@1895
  1641
{
hfutrell@2744
  1642
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1643
	SDL_Renderer   *renderer;
slouken@1895
  1644
hfutrell@2744
  1645
	if (!texture) {
hfutrell@2744
  1646
		return -1;
hfutrell@2744
  1647
	}
hfutrell@2744
  1648
	renderer = texture->renderer;
hfutrell@2744
  1649
	if (!renderer->QueryTexturePixels) {
hfutrell@2744
  1650
		return -1;
hfutrell@2744
  1651
	}
hfutrell@2744
  1652
	return renderer->QueryTexturePixels(renderer, texture, pixels, pitch);
slouken@1895
  1653
}
slouken@1895
  1654
slouken@1895
  1655
int
slouken@1895
  1656
SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors,
hfutrell@2744
  1657
		      int firstcolor, int ncolors)
slouken@1895
  1658
{
hfutrell@2744
  1659
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1660
	SDL_Renderer   *renderer;
slouken@1895
  1661
hfutrell@2744
  1662
	if (!texture) {
hfutrell@2744
  1663
		return -1;
hfutrell@2744
  1664
	}
hfutrell@2744
  1665
	renderer = texture->renderer;
hfutrell@2744
  1666
	if (!renderer->SetTexturePalette) {
hfutrell@2744
  1667
		return -1;
hfutrell@2744
  1668
	}
hfutrell@2744
  1669
	return renderer->SetTexturePalette(renderer, texture, colors, firstcolor,
hfutrell@2744
  1670
					   ncolors);
slouken@1895
  1671
}
slouken@1895
  1672
slouken@1895
  1673
int
slouken@1895
  1674
SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
hfutrell@2744
  1675
		      int firstcolor, int ncolors)
slouken@1895
  1676
{
hfutrell@2744
  1677
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1678
	SDL_Renderer   *renderer;
slouken@1895
  1679
hfutrell@2744
  1680
	if (!texture) {
hfutrell@2744
  1681
		return -1;
hfutrell@2744
  1682
	}
hfutrell@2744
  1683
	renderer = texture->renderer;
hfutrell@2744
  1684
	if (!renderer->GetTexturePalette) {
hfutrell@2744
  1685
		return -1;
hfutrell@2744
  1686
	}
hfutrell@2744
  1687
	return renderer->GetTexturePalette(renderer, texture, colors, firstcolor,
hfutrell@2744
  1688
					   ncolors);
slouken@1895
  1689
}
slouken@1895
  1690
slouken@1895
  1691
int
slouken@1985
  1692
SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b)
slouken@1985
  1693
{
hfutrell@2744
  1694
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1695
	SDL_Renderer   *renderer;
slouken@1985
  1696
hfutrell@2744
  1697
	if (!texture) {
hfutrell@2744
  1698
		return -1;
hfutrell@2744
  1699
	}
hfutrell@2744
  1700
	renderer = texture->renderer;
hfutrell@2744
  1701
	if (!renderer->SetTextureColorMod) {
hfutrell@2744
  1702
		return -1;
hfutrell@2744
  1703
	}
hfutrell@2744
  1704
	if (r < 255 || g < 255 || b < 255) {
hfutrell@2744
  1705
		texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
hfutrell@2744
  1706
	} else {
hfutrell@2744
  1707
		texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
hfutrell@2744
  1708
	}
hfutrell@2744
  1709
	texture->r = r;
hfutrell@2744
  1710
	texture->g = g;
hfutrell@2744
  1711
	texture->b = b;
hfutrell@2744
  1712
	return renderer->SetTextureColorMod(renderer, texture);
slouken@1985
  1713
}
slouken@1985
  1714
slouken@1985
  1715
int
slouken@1985
  1716
SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g,
hfutrell@2744
  1717
		       Uint8 * b)
slouken@1985
  1718
{
hfutrell@2744
  1719
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1720
	SDL_Renderer   *renderer;
slouken@1985
  1721
hfutrell@2744
  1722
	if (!texture) {
hfutrell@2744
  1723
		return -1;
hfutrell@2744
  1724
	}
hfutrell@2744
  1725
	renderer = texture->renderer;
hfutrell@2744
  1726
	if (r) {
hfutrell@2744
  1727
		*r = texture->r;
hfutrell@2744
  1728
	}
hfutrell@2744
  1729
	if (g) {
hfutrell@2744
  1730
		*g = texture->g;
hfutrell@2744
  1731
	}
hfutrell@2744
  1732
	if (b) {
hfutrell@2744
  1733
		*b = texture->b;
hfutrell@2744
  1734
	}
hfutrell@2744
  1735
	return 0;
slouken@1985
  1736
}
slouken@1985
  1737
slouken@1985
  1738
int
slouken@1985
  1739
SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha)
slouken@1985
  1740
{
hfutrell@2744
  1741
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1742
	SDL_Renderer   *renderer;
slouken@1985
  1743
hfutrell@2744
  1744
	if (!texture) {
hfutrell@2744
  1745
		return -1;
hfutrell@2744
  1746
	}
hfutrell@2744
  1747
	renderer = texture->renderer;
hfutrell@2744
  1748
	if (!renderer->SetTextureAlphaMod) {
hfutrell@2744
  1749
		return -1;
hfutrell@2744
  1750
	}
hfutrell@2744
  1751
	if (alpha < 255) {
hfutrell@2744
  1752
		texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
hfutrell@2744
  1753
	} else {
hfutrell@2744
  1754
		texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
hfutrell@2744
  1755
	}
hfutrell@2744
  1756
	texture->a = alpha;
hfutrell@2744
  1757
	return renderer->SetTextureAlphaMod(renderer, texture);
slouken@1985
  1758
}
slouken@1985
  1759
slouken@1985
  1760
int
slouken@1985
  1761
SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha)
slouken@1985
  1762
{
hfutrell@2744
  1763
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
slouken@1985
  1764
hfutrell@2744
  1765
	if (!texture) {
hfutrell@2744
  1766
		return -1;
hfutrell@2744
  1767
	}
hfutrell@2744
  1768
	if (alpha) {
hfutrell@2744
  1769
		*alpha = texture->a;
hfutrell@2744
  1770
	}
hfutrell@2744
  1771
	return 0;
slouken@1985
  1772
}
slouken@1985
  1773
slouken@1985
  1774
int
slouken@1985
  1775
SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode)
slouken@1985
  1776
{
hfutrell@2744
  1777
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1778
	SDL_Renderer   *renderer;
slouken@1985
  1779
hfutrell@2744
  1780
	if (!texture) {
hfutrell@2744
  1781
		return -1;
hfutrell@2744
  1782
	}
hfutrell@2744
  1783
	renderer = texture->renderer;
hfutrell@2744
  1784
	if (!renderer->SetTextureBlendMode) {
hfutrell@2744
  1785
		return -1;
hfutrell@2744
  1786
	}
hfutrell@2744
  1787
	texture->blendMode = blendMode;
hfutrell@2744
  1788
	return renderer->SetTextureBlendMode(renderer, texture);
slouken@1985
  1789
}
slouken@1985
  1790
slouken@1985
  1791
int
slouken@1985
  1792
SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode)
slouken@1985
  1793
{
hfutrell@2744
  1794
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
slouken@1985
  1795
hfutrell@2744
  1796
	if (!texture) {
hfutrell@2744
  1797
		return -1;
hfutrell@2744
  1798
	}
hfutrell@2744
  1799
	if (blendMode) {
hfutrell@2744
  1800
		*blendMode = texture->blendMode;
hfutrell@2744
  1801
	}
hfutrell@2744
  1802
	return 0;
slouken@1985
  1803
}
slouken@1985
  1804
slouken@1985
  1805
int
slouken@1985
  1806
SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode)
slouken@1985
  1807
{
hfutrell@2744
  1808
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1809
	SDL_Renderer   *renderer;
slouken@1985
  1810
hfutrell@2744
  1811
	if (!texture) {
hfutrell@2744
  1812
		return -1;
hfutrell@2744
  1813
	}
hfutrell@2744
  1814
	renderer = texture->renderer;
hfutrell@2744
  1815
	if (!renderer->SetTextureScaleMode) {
hfutrell@2744
  1816
		return -1;
hfutrell@2744
  1817
	}
hfutrell@2744
  1818
	texture->scaleMode = scaleMode;
hfutrell@2744
  1819
	return renderer->SetTextureScaleMode(renderer, texture);
slouken@1985
  1820
}
slouken@1985
  1821
slouken@1985
  1822
int
slouken@1985
  1823
SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode)
slouken@1985
  1824
{
hfutrell@2744
  1825
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
slouken@1985
  1826
hfutrell@2744
  1827
	if (!texture) {
hfutrell@2744
  1828
		return -1;
hfutrell@2744
  1829
	}
hfutrell@2744
  1830
	if (scaleMode) {
hfutrell@2744
  1831
		*scaleMode = texture->scaleMode;
hfutrell@2744
  1832
	}
hfutrell@2744
  1833
	return 0;
slouken@1985
  1834
}
slouken@1985
  1835
slouken@1985
  1836
int
slouken@1895
  1837
SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect,
hfutrell@2744
  1838
		  const void *pixels, int pitch)
slouken@1895
  1839
{
hfutrell@2744
  1840
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1841
	SDL_Renderer   *renderer;
hfutrell@2744
  1842
	SDL_Rect        full_rect;
slouken@1895
  1843
hfutrell@2744
  1844
	if (!texture) {
hfutrell@2744
  1845
		return -1;
hfutrell@2744
  1846
	}
hfutrell@2744
  1847
	renderer = texture->renderer;
hfutrell@2744
  1848
	if (!renderer->UpdateTexture) {
hfutrell@2744
  1849
		return -1;
hfutrell@2744
  1850
	}
hfutrell@2744
  1851
	if (!rect) {
hfutrell@2744
  1852
		full_rect.x = 0;
hfutrell@2744
  1853
		full_rect.y = 0;
hfutrell@2744
  1854
		full_rect.w = texture->w;
hfutrell@2744
  1855
		full_rect.h = texture->h;
hfutrell@2744
  1856
		rect = &full_rect;
hfutrell@2744
  1857
	}
hfutrell@2744
  1858
	return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
slouken@1895
  1859
}
slouken@1895
  1860
slouken@1895
  1861
int
slouken@1895
  1862
SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty,
hfutrell@2744
  1863
		void **pixels, int *pitch)
slouken@1895
  1864
{
hfutrell@2744
  1865
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1866
	SDL_Renderer   *renderer;
hfutrell@2744
  1867
	SDL_Rect        full_rect;
slouken@1895
  1868
hfutrell@2744
  1869
	if (!texture) {
hfutrell@2744
  1870
		return -1;
hfutrell@2744
  1871
	}
hfutrell@2744
  1872
	if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
hfutrell@2744
  1873
		SDL_SetError("SDL_LockTexture(): texture must be streaming");
hfutrell@2744
  1874
		return -1;
hfutrell@2744
  1875
	}
hfutrell@2744
  1876
	renderer = texture->renderer;
hfutrell@2744
  1877
	if (!renderer->LockTexture) {
hfutrell@2744
  1878
		return -1;
hfutrell@2744
  1879
	}
hfutrell@2744
  1880
	if (!rect) {
hfutrell@2744
  1881
		full_rect.x = 0;
hfutrell@2744
  1882
		full_rect.y = 0;
hfutrell@2744
  1883
		full_rect.w = texture->w;
hfutrell@2744
  1884
		full_rect.h = texture->h;
hfutrell@2744
  1885
		rect = &full_rect;
hfutrell@2744
  1886
	}
hfutrell@2744
  1887
	return renderer->LockTexture(renderer, texture, rect, markDirty, pixels,
hfutrell@2744
  1888
				     pitch);
slouken@1895
  1889
}
slouken@1895
  1890
slouken@1895
  1891
void
slouken@1895
  1892
SDL_UnlockTexture(SDL_TextureID textureID)
slouken@1895
  1893
{
hfutrell@2744
  1894
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1895
	SDL_Renderer   *renderer;
slouken@1895
  1896
hfutrell@2744
  1897
	if (!texture) {
hfutrell@2744
  1898
		return;
hfutrell@2744
  1899
	}
hfutrell@2744
  1900
	if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
hfutrell@2744
  1901
		return;
hfutrell@2744
  1902
	}
hfutrell@2744
  1903
	renderer = texture->renderer;
hfutrell@2744
  1904
	if (!renderer->UnlockTexture) {
hfutrell@2744
  1905
		return;
hfutrell@2744
  1906
	}
hfutrell@2744
  1907
	renderer->UnlockTexture(renderer, texture);
slouken@1895
  1908
}
slouken@1895
  1909
slouken@1895
  1910
void
slouken@1895
  1911
SDL_DirtyTexture(SDL_TextureID textureID, int numrects,
hfutrell@2744
  1912
		 const SDL_Rect * rects)
slouken@1895
  1913
{
hfutrell@2744
  1914
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1915
	SDL_Renderer   *renderer;
slouken@1895
  1916
hfutrell@2744
  1917
	if (!texture) {
hfutrell@2744
  1918
		return;
hfutrell@2744
  1919
	}
hfutrell@2744
  1920
	if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
hfutrell@2744
  1921
		return;
hfutrell@2744
  1922
	}
hfutrell@2744
  1923
	renderer = texture->renderer;
hfutrell@2744
  1924
	if (!renderer->DirtyTexture) {
hfutrell@2744
  1925
		return;
hfutrell@2744
  1926
	}
hfutrell@2744
  1927
	renderer->DirtyTexture(renderer, texture, numrects, rects);
slouken@1895
  1928
}
slouken@1895
  1929
slouken@1895
  1930
int
slouken@1985
  1931
SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect)
slouken@1895
  1932
{
hfutrell@2744
  1933
	SDL_Renderer   *renderer;
hfutrell@2744
  1934
	SDL_Window     *window;
hfutrell@2744
  1935
	SDL_Rect        real_rect;
slouken@1895
  1936
hfutrell@2744
  1937
	if (!_this) {
hfutrell@2744
  1938
		SDL_UninitializedVideo();
hfutrell@2744
  1939
		return -1;
hfutrell@2744
  1940
	}
hfutrell@2744
  1941
	renderer = SDL_CurrentDisplay.current_renderer;
hfutrell@2744
  1942
	if (!renderer || !renderer->RenderFill) {
hfutrell@2744
  1943
		return -1;
hfutrell@2744
  1944
	}
hfutrell@2744
  1945
	window = SDL_GetWindowFromID(renderer->window);
hfutrell@2744
  1946
	real_rect.x = 0;
hfutrell@2744
  1947
	real_rect.y = 0;
hfutrell@2744
  1948
	real_rect.w = window->w;
hfutrell@2744
  1949
	real_rect.h = window->h;
hfutrell@2744
  1950
	if (rect) {
hfutrell@2744
  1951
		if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
hfutrell@2744
  1952
			return 0;
hfutrell@2744
  1953
		}
hfutrell@2744
  1954
	}
hfutrell@2744
  1955
	return renderer->RenderFill(renderer, r, g, b, a, &real_rect);
slouken@1895
  1956
}
slouken@1895
  1957
slouken@1895
  1958
int
slouken@1895
  1959
SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
hfutrell@2744
  1960
	       const SDL_Rect * dstrect)
slouken@1895
  1961
{
hfutrell@2744
  1962
	SDL_Texture    *texture = SDL_GetTextureFromID(textureID);
hfutrell@2744
  1963
	SDL_Renderer   *renderer;
hfutrell@2744
  1964
	SDL_Window     *window;
hfutrell@2744
  1965
	SDL_Rect        real_srcrect;
hfutrell@2744
  1966
	SDL_Rect        real_dstrect;
slouken@1895
  1967
hfutrell@2744
  1968
	if (!texture || texture->renderer != SDL_CurrentDisplay.current_renderer) {
hfutrell@2744
  1969
		return -1;
hfutrell@2744
  1970
	}
hfutrell@2744
  1971
	renderer = SDL_CurrentDisplay.current_renderer;
hfutrell@2744
  1972
	if (!renderer || !renderer->RenderCopy) {
hfutrell@2744
  1973
		return -1;
hfutrell@2744
  1974
	}
hfutrell@2744
  1975
	window = SDL_GetWindowFromID(renderer->window);
hfutrell@2744
  1976
	if (srcrect) {
hfutrell@2744
  1977
		real_srcrect = *srcrect;
hfutrell@2744
  1978
	} else {
hfutrell@2744
  1979
		real_srcrect.x = 0;
hfutrell@2744
  1980
		real_srcrect.y = 0;
hfutrell@2744
  1981
		real_srcrect.w = texture->w;
hfutrell@2744
  1982
		real_srcrect.h = texture->h;
hfutrell@2744
  1983
	}
hfutrell@2744
  1984
	if (dstrect) {
hfutrell@2744
  1985
		real_dstrect = *dstrect;
hfutrell@2744
  1986
	} else {
hfutrell@2744
  1987
		real_dstrect.x = 0;
hfutrell@2744
  1988
		real_dstrect.y = 0;
hfutrell@2744
  1989
		real_dstrect.w = window->w;
hfutrell@2744
  1990
		real_dstrect.h = window->h;
hfutrell@2744
  1991
	}
slouken@1895
  1992
hfutrell@2744
  1993
	return renderer->RenderCopy(renderer, texture, &real_srcrect,
hfutrell@2744
  1994
				    &real_dstrect);
slouken@1895
  1995
}
slouken@1895
  1996
slouken@1895
  1997
void
slouken@1895
  1998
SDL_RenderPresent(void)
slouken@1895
  1999
{
hfutrell@2744
  2000
	SDL_Renderer   *renderer;
slouken@1895
  2001
hfutrell@2744
  2002
	if (!_this) {
hfutrell@2744
  2003
		SDL_UninitializedVideo();
hfutrell@2744
  2004
		return;
hfutrell@2744
  2005
	}
hfutrell@2744
  2006
	renderer = SDL_CurrentDisplay.current_renderer;
hfutrell@2744
  2007
	if (!renderer || !renderer->RenderPresent) {
hfutrell@2744
  2008
		return;
hfutrell@2744
  2009
	}
hfutrell@2744
  2010
	renderer->RenderPresent(renderer);
slouken@1895
  2011
}
slouken@1895
  2012
slouken@1895
  2013
void
slouken@1895
  2014
SDL_DestroyTexture(SDL_TextureID textureID)
slouken@1895
  2015
{
hfutrell@2744
  2016
	int             hash;
hfutrell@2744
  2017
	SDL_Texture    *prev, *texture;
hfutrell@2744
  2018
	SDL_Renderer   *renderer;
slouken@1895
  2019
hfutrell@2744
  2020
	if (!_this) {
hfutrell@2744
  2021
		SDL_UninitializedVideo();
hfutrell@2744
  2022
		return;
hfutrell@2744
  2023
	}
hfutrell@2744
  2024
	/* Look up the texture in the hash table */
hfutrell@2744
  2025
	hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
hfutrell@2744
  2026
	prev = NULL;
hfutrell@2744
  2027
	for (texture = SDL_CurrentDisplay.textures[hash]; texture;
hfutrell@2744
  2028
	     prev = texture, texture = texture->next) {
hfutrell@2744
  2029
		if (texture->id == textureID) {
hfutrell@2744
  2030
			break;
hfutrell@2744
  2031
		}
hfutrell@2744
  2032
	}
hfutrell@2744
  2033
	if (!texture) {
hfutrell@2744
  2034
		return;
hfutrell@2744
  2035
	}
hfutrell@2744
  2036
	/* Unlink the texture from the list */
hfutrell@2744
  2037
	if (prev) {
hfutrell@2744
  2038
		prev->next = texture->next;
hfutrell@2744
  2039
	} else {
hfutrell@2744
  2040
		SDL_CurrentDisplay.textures[hash] = texture->next;
hfutrell@2744
  2041
	}
slouken@1895
  2042
hfutrell@2744
  2043
	/* Free the texture */
hfutrell@2744
  2044
	renderer = texture->renderer;
hfutrell@2744
  2045
	renderer->DestroyTexture(renderer, texture);
hfutrell@2744
  2046
	SDL_free(texture);
slouken@1895
  2047
}
slouken@1895
  2048
slouken@1895
  2049
void
slouken@1895
  2050
SDL_DestroyRenderer(SDL_WindowID windowID)
slouken@1895
  2051
{
hfutrell@2744
  2052
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
hfutrell@2744
  2053
	SDL_Renderer   *renderer;
hfutrell@2744
  2054
	int             i;
slouken@1895
  2055
hfutrell@2744
  2056
	if (!window) {
hfutrell@2744
  2057
		return;
hfutrell@2744
  2058
	}
hfutrell@2744
  2059
	renderer = window->renderer;
hfutrell@2744
  2060
	if (!renderer) {
hfutrell@2744
  2061
		return;
hfutrell@2744
  2062
	}
hfutrell@2744
  2063
	/* Free existing textures for this renderer */
hfutrell@2744
  2064
	for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) {
hfutrell@2744
  2065
		SDL_Texture    *texture;
hfutrell@2744
  2066
		SDL_Texture    *prev = NULL;
hfutrell@2744
  2067
		SDL_Texture    *next;
hfutrell@2744
  2068
		for (texture = SDL_CurrentDisplay.textures[i]; texture;
hfutrell@2744
  2069
		     texture = next) {
hfutrell@2744
  2070
			next = texture->next;
hfutrell@2744
  2071
			if (texture->renderer == renderer) {
hfutrell@2744
  2072
				if (prev) {
hfutrell@2744
  2073
					prev->next = next;
hfutrell@2744
  2074
				} else {
hfutrell@2744
  2075
					SDL_CurrentDisplay.textures[i] = next;
hfutrell@2744
  2076
				}
hfutrell@2744
  2077
				renderer->DestroyTexture(renderer, texture);
hfutrell@2744
  2078
				SDL_free(texture);
hfutrell@2744
  2079
			} else {
hfutrell@2744
  2080
				prev = texture;
hfutrell@2744
  2081
			}
hfutrell@2744
  2082
		}
hfutrell@2744
  2083
	}
slouken@1895
  2084
hfutrell@2744
  2085
	/* Free the renderer instance */
hfutrell@2744
  2086
	renderer->DestroyRenderer(renderer);
slouken@1895
  2087
hfutrell@2744
  2088
	/* Clear references */
hfutrell@2744
  2089
	window->renderer = NULL;
hfutrell@2744
  2090
	if (SDL_CurrentDisplay.current_renderer == renderer) {
hfutrell@2744
  2091
		SDL_CurrentDisplay.current_renderer = NULL;
hfutrell@2744
  2092
	}
slouken@1895
  2093
}
slouken@1895
  2094
slouken@1895
  2095
void
slouken@1895
  2096
SDL_VideoQuit(void)
slouken@1895
  2097
{
hfutrell@2744
  2098
	int             i, j;
slouken@1895
  2099
hfutrell@2744
  2100
	if (!_this) {
hfutrell@2744
  2101
		return;
hfutrell@2744
  2102
	}
hfutrell@2744
  2103
	/* Halt event processing before doing anything else */
hfutrell@2744
  2104
	SDL_StopEventLoop();
slouken@1895
  2105
hfutrell@2744
  2106
	/* Clean up the system video */
hfutrell@2744
  2107
	for (i = _this->num_displays; i--;) {
hfutrell@2744
  2108
		SDL_VideoDisplay *display = &_this->displays[i];
hfutrell@2744
  2109
		for (j = display->num_windows; j--;) {
hfutrell@2744
  2110
			SDL_DestroyWindow(display->windows[i].id);
hfutrell@2744
  2111
		}
hfutrell@2744
  2112
		if (display->windows) {
hfutrell@2744
  2113
			SDL_free(display->windows);
hfutrell@2744
  2114
			display->windows = NULL;
hfutrell@2744
  2115
		}
hfutrell@2744
  2116
		display->num_windows = 0;
hfutrell@2744
  2117
		if (display->render_drivers) {
hfutrell@2744
  2118
			SDL_free(display->render_drivers);
hfutrell@2744
  2119
			display->render_drivers = NULL;
hfutrell@2744
  2120
		}
hfutrell@2744
  2121
		display->num_render_drivers = 0;
hfutrell@2744
  2122
	}
hfutrell@2744
  2123
	_this->VideoQuit(_this);
slouken@1895
  2124
hfutrell@2744
  2125
	for (i = _this->num_displays; i--;) {
hfutrell@2744
  2126
		SDL_VideoDisplay *display = &_this->displays[i];
hfutrell@2744
  2127
		for (j = display->num_display_modes; j--;) {
hfutrell@2744
  2128
			if (display->display_modes[j].driverdata) {
hfutrell@2744
  2129
				SDL_free(display->display_modes[j].driverdata);
hfutrell@2744
  2130
				display->display_modes[j].driverdata = NULL;
hfutrell@2744
  2131
			}
hfutrell@2744
  2132
		}
hfutrell@2744
  2133
		if (display->display_modes) {
hfutrell@2744
  2134
			SDL_free(display->display_modes);
hfutrell@2744
  2135
			display->display_modes = NULL;
hfutrell@2744
  2136
		}
hfutrell@2744
  2137
		if (display->desktop_mode.driverdata) {
hfutrell@2744
  2138
			SDL_free(display->desktop_mode.driverdata);
hfutrell@2744
  2139
			display->desktop_mode.driverdata = NULL;
hfutrell@2744
  2140
		}
hfutrell@2744
  2141
		if (display->palette) {
hfutrell@2744
  2142
			SDL_FreePalette(display->palette);
hfutrell@2744
  2143
			display->palette = NULL;
hfutrell@2744
  2144
		}
hfutrell@2744
  2145
		if (display->gamma) {
hfutrell@2744
  2146
			SDL_free(display->gamma);
hfutrell@2744
  2147
			display->gamma = NULL;
hfutrell@2744
  2148
		}
hfutrell@2744
  2149
		if (display->driverdata) {
hfutrell@2744
  2150
			SDL_free(display->driverdata);
hfutrell@2744
  2151
			display->driverdata = NULL;
hfutrell@2744
  2152
		}
hfutrell@2744
  2153
	}
hfutrell@2744
  2154
	if (_this->displays) {
hfutrell@2744
  2155
		SDL_free(_this->displays);
hfutrell@2744
  2156
		_this->displays = NULL;
hfutrell@2744
  2157
	}
hfutrell@2744
  2158
	_this->free(_this);
hfutrell@2744
  2159
	_this = NULL;
slouken@0
  2160
}
slouken@0
  2161
slouken@1895
  2162
int
slouken@1895
  2163
SDL_GL_LoadLibrary(const char *path)
slouken@0
  2164
{
hfutrell@2744
  2165
	int             retval;
slouken@0
  2166
hfutrell@2744
  2167
	if (!_this) {
hfutrell@2744
  2168
		SDL_UninitializedVideo();
hfutrell@2744
  2169
		return -1;
hfutrell@2744
  2170
	}
hfutrell@2744
  2171
	if (_this->GL_LoadLibrary) {
hfutrell@2744
  2172
		retval = _this->GL_LoadLibrary(_this, path);
hfutrell@2744
  2173
	} else {
hfutrell@2744
  2174
		SDL_SetError("No dynamic GL support in video driver");
hfutrell@2744
  2175
		retval = -1;
hfutrell@2744
  2176
	}
hfutrell@2744
  2177
	return (retval);
slouken@0
  2178
}
slouken@0
  2179
hfutrell@2744
  2180
void           *
slouken@1895
  2181
SDL_GL_GetProcAddress(const char *proc)
slouken@0
  2182
{
hfutrell@2744
  2183
	void           *func;
slouken@0
  2184
hfutrell@2744
  2185
	if (!_this) {
hfutrell@2744
  2186
		SDL_UninitializedVideo();
hfutrell@2744
  2187
		return NULL;
hfutrell@2744
  2188
	}
hfutrell@2744
  2189
	func = NULL;
hfutrell@2744
  2190
	if (_this->GL_GetProcAddress) {
hfutrell@2744
  2191
		if (_this->gl_config.driver_loaded) {
hfutrell@2744
  2192
			func = _this->GL_GetProcAddress(_this, proc);
hfutrell@2744
  2193
		} else {
hfutrell@2744
  2194
			SDL_SetError("No GL driver has been loaded");
hfutrell@2744
  2195
		}
hfutrell@2744
  2196
	} else {
hfutrell@2744
  2197
		SDL_SetError("No dynamic GL support in video driver");
hfutrell@2744
  2198
	}
hfutrell@2744
  2199
	return func;
slouken@0
  2200
}
slouken@0
  2201
slouken@1926
  2202
SDL_bool
slouken@1926
  2203
SDL_GL_ExtensionSupported(const char *extension)
slouken@1926
  2204
{
hfutrell@2743
  2205
#if SDL_VIDEO_OPENGL
hfutrell@2744
  2206
	const GLubyte  *(APIENTRY * glGetStringFunc) (GLenum);
hfutrell@2744
  2207
	const char     *extensions;
hfutrell@2744
  2208
	const char     *start;
hfutrell@2744
  2209
	const char     *where, *terminator;
slouken@1926
  2210
hfutrell@2744
  2211
	/* Extension names should not have spaces. */
hfutrell@2744
  2212
	where = SDL_strchr(extension, ' ');
hfutrell@2744
  2213
	if (where || *extension == '\0') {
hfutrell@2744
  2214
		return SDL_FALSE;
hfutrell@2744
  2215
	}
hfutrell@2744
  2216
	/* See if there's an environment variable override */
hfutrell@2744
  2217
	start = SDL_getenv(extension);
hfutrell@2744
  2218
	if (start && *start == '0') {
hfutrell@2744
  2219
		return SDL_FALSE;
hfutrell@2744
  2220
	}
hfutrell@2744
  2221
	/* Lookup the available extensions */
hfutrell@2744
  2222
	glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
hfutrell@2744
  2223
	if (glGetStringFunc) {
hfutrell@2744
  2224
		extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
hfutrell@2744
  2225
	} else {
hfutrell@2744
  2226
		extensions = NULL;
hfutrell@2744
  2227
	}
hfutrell@2744
  2228
	if (!extensions) {
hfutrell@2744
  2229
		return SDL_FALSE;
hfutrell@2744
  2230
	}
hfutrell@2744
  2231
	/*
hfutrell@2744
  2232
	 * It takes a bit of care to be fool-proof about parsing the OpenGL
hfutrell@2744
  2233
	 * extensions string. Don't be fooled by sub-strings, etc.
hfutrell@2744
  2234
	 */
slouken@1926
  2235
hfutrell@2744
  2236
	start = extensions;
slouken@1926
  2237
hfutrell@2744
  2238
	for (;;) {
hfutrell@2744
  2239
		where = SDL_strstr(start, extension);
hfutrell@2744
  2240
		if (!where)
hfutrell@2744
  2241
			break;
slouken@1926
  2242
hfutrell@2744
  2243
		terminator = where + SDL_strlen(extension);
hfutrell@2744
  2244
		if (where == start || *(where - 1) == ' ')
hfutrell@2744
  2245
			if (*terminator == ' ' || *terminator == '\0')
hfutrell@2744
  2246
				return SDL_TRUE;
slouken@1926
  2247
hfutrell@2744
  2248
		start = terminator;
hfutrell@2744
  2249
	}
hfutrell@2744
  2250
	return SDL_FALSE;
slouken@1926
  2251
#else
hfutrell@2744
  2252
	return SDL_FALSE;
slouken@1926
  2253
#endif
slouken@1926
  2254
}
slouken@1926
  2255
slouken@1895
  2256
int
slouken@1895
  2257
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
slouken@0
  2258
{
hfutrell@2743
  2259
#if SDL_VIDEO_OPENGL
hfutrell@2744
  2260
	int             retval;
slouken@0
  2261
hfutrell@2744
  2262
	if (!_this) {
hfutrell@2744
  2263
		SDL_UninitializedVideo();
hfutrell@2744
  2264
		return -1;
hfutrell@2744
  2265
	}
hfutrell@2744
  2266
	retval = 0;
hfutrell@2744
  2267
	switch (attr) {
hfutrell@2744
  2268
	case SDL_GL_RED_SIZE:
hfutrell@2744
  2269
		_this->gl_config.red_size = value;
hfutrell@2744
  2270
		break;
hfutrell@2744
  2271
	case SDL_GL_GREEN_SIZE:
hfutrell@2744
  2272
		_this->gl_config.green_size = value;
hfutrell@2744
  2273
		break;
hfutrell@2744
  2274
	case SDL_GL_BLUE_SIZE:
hfutrell@2744
  2275
		_this->gl_config.blue_size = value;
hfutrell@2744
  2276
		break;
hfutrell@2744
  2277
	case SDL_GL_ALPHA_SIZE:
hfutrell@2744
  2278
		_this->gl_config.alpha_size = value;
hfutrell@2744
  2279
		break;
hfutrell@2744
  2280
	case SDL_GL_DOUBLEBUFFER:
hfutrell@2744
  2281
		_this->gl_config.double_buffer = value;
hfutrell@2744
  2282
		break;
hfutrell@2744
  2283
	case SDL_GL_BUFFER_SIZE:
hfutrell@2744
  2284
		_this->gl_config.buffer_size = value;
hfutrell@2744
  2285
		break;
hfutrell@2744
  2286
	case SDL_GL_DEPTH_SIZE:
hfutrell@2744
  2287
		_this->gl_config.depth_size = value;
hfutrell@2744
  2288
		break;
hfutrell@2744
  2289
	case SDL_GL_STENCIL_SIZE:
hfutrell@2744
  2290
		_this->gl_config.stencil_size = value;
hfutrell@2744
  2291
		break;
hfutrell@2744
  2292
	case SDL_GL_ACCUM_RED_SIZE:
hfutrell@2744
  2293
		_this->gl_config.accum_red_size = value;
hfutrell@2744
  2294
		break;
hfutrell@2744
  2295
	case SDL_GL_ACCUM_GREEN_SIZE:
hfutrell@2744
  2296
		_this->gl_config.accum_green_size = value;
hfutrell@2744
  2297
		break;
hfutrell@2744
  2298
	case SDL_GL_ACCUM_BLUE_SIZE:
hfutrell@2744
  2299
		_this->gl_config.accum_blue_size = value;
hfutrell@2744
  2300
		break;
hfutrell@2744
  2301
	case SDL_GL_ACCUM_ALPHA_SIZE:
hfutrell@2744
  2302
		_this->gl_config.accum_alpha_size = value;
hfutrell@2744
  2303
		break;
hfutrell@2744
  2304
	case SDL_GL_STEREO:
hfutrell@2744
  2305
		_this->gl_config.stereo = value;
hfutrell@2744
  2306
		break;
hfutrell@2744
  2307
	case SDL_GL_MULTISAMPLEBUFFERS:
hfutrell@2744
  2308
		_this->gl_config.multisamplebuffers = value;
hfutrell@2744
  2309
		break;
hfutrell@2744
  2310
	case SDL_GL_MULTISAMPLESAMPLES:
hfutrell@2744
  2311
		_this->gl_config.multisamplesamples = value;
hfutrell@2744
  2312
		break;
hfutrell@2744
  2313
	case SDL_GL_ACCELERATED_VISUAL:
hfutrell@2744
  2314
		_this->gl_config.accelerated = value;
hfutrell@2744
  2315
		break;
hfutrell@2744
  2316
	default:
hfutrell@2744
  2317
		SDL_SetError("Unknown OpenGL attribute");
hfutrell@2744
  2318
		retval = -1;
hfutrell@2744
  2319
		break;
hfutrell@2744
  2320
	}
hfutrell@2744
  2321
	return retval;
slouken@1936
  2322
#else
hfutrell@2744
  2323
	SDL_Unsupported();
hfutrell@2744
  2324
	return -1;
hfutrell@2744
  2325
#endif				/* SDL_VIDEO_OPENGL */
slouken@0
  2326
}
slouken@0
  2327
slouken@1895
  2328
int
slouken@1936
  2329
SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
slouken@0
  2330
{
hfutrell@2743
  2331
#if SDL_VIDEO_OPENGL
hfutrell@2744
  2332
	void            (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
hfutrell@2744
  2333
	GLenum          attrib = 0;
slouken@1912
  2334
hfutrell@2744
  2335
	glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
hfutrell@2744
  2336
	if (!glGetIntegervFunc) {
hfutrell@2744
  2337
		return -1;
hfutrell@2744
  2338
	}
hfutrell@2744
  2339
	switch (attr) {
hfutrell@2744
  2340
	case SDL_GL_RED_SIZE:
hfutrell@2744
  2341
		attrib = GL_RED_BITS;
hfutrell@2744
  2342
		break;
hfutrell@2744
  2343
	case SDL_GL_BLUE_SIZE:
hfutrell@2744
  2344
		attrib = GL_BLUE_BITS;
hfutrell@2744
  2345
		break;
hfutrell@2744
  2346
	case SDL_GL_GREEN_SIZE:
hfutrell@2744
  2347
		attrib = GL_GREEN_BITS;
hfutrell@2744
  2348
		break;
hfutrell@2744
  2349
	case SDL_GL_ALPHA_SIZE:
hfutrell@2744
  2350
		attrib = GL_ALPHA_BITS;
hfutrell@2744
  2351
		break;
hfutrell@2744
  2352
	case SDL_GL_DOUBLEBUFFER:
hfutrell@2744
  2353
		attrib = GL_DOUBLEBUFFER;
hfutrell@2744
  2354
		break;
hfutrell@2744
  2355
	case SDL_GL_DEPTH_SIZE:
hfutrell@2744
  2356
		attrib = GL_DEPTH_BITS;
hfutrell@2744
  2357
		break;
hfutrell@2744
  2358
	case SDL_GL_STENCIL_SIZE:
hfutrell@2744
  2359
		attrib = GL_STENCIL_BITS;
hfutrell@2744
  2360
		break;
hfutrell@2744
  2361
	case SDL_GL_ACCUM_RED_SIZE:
hfutrell@2744
  2362
		attrib = GL_ACCUM_RED_BITS;
hfutrell@2744
  2363
		break;
hfutrell@2744
  2364
	case SDL_GL_ACCUM_GREEN_SIZE:
hfutrell@2744
  2365
		attrib = GL_ACCUM_GREEN_BITS;
hfutrell@2744
  2366
		break;
hfutrell@2744
  2367
	case SDL_GL_ACCUM_BLUE_SIZE:
hfutrell@2744
  2368
		attrib = GL_ACCUM_BLUE_BITS;
hfutrell@2744
  2369
		break;
hfutrell@2744
  2370
	case SDL_GL_ACCUM_ALPHA_SIZE:
hfutrell@2744
  2371
		attrib = GL_ACCUM_ALPHA_BITS;
hfutrell@2744
  2372
		break;
hfutrell@2744
  2373
	case SDL_GL_STEREO:
hfutrell@2744
  2374
		attrib = GL_STEREO;
hfutrell@2744
  2375
		break;
hfutrell@2744
  2376
	case SDL_GL_MULTISAMPLEBUFFERS:
hfutrell@2744
  2377
		attrib = GL_SAMPLE_BUFFERS_ARB;
hfutrell@2744
  2378
		break;
hfutrell@2744
  2379
	case SDL_GL_MULTISAMPLESAMPLES:
hfutrell@2744
  2380
		attrib = GL_SAMPLES_ARB;
hfutrell@2744
  2381
		break;
hfutrell@2744
  2382
	case SDL_GL_BUFFER_SIZE:
hfutrell@2744
  2383
		{
hfutrell@2744
  2384
			GLint           bits = 0;
hfutrell@2744
  2385
			GLint           component;
slouken@1936
  2386
hfutrell@2744
  2387
			/*
hfutrell@2744
  2388
			 * there doesn't seem to be a single flag in OpenGL
hfutrell@2744
  2389
			 * for this!
hfutrell@2744
  2390
			 */
hfutrell@2744
  2391
			glGetIntegervFunc(GL_RED_BITS, &component);
hfutrell@2744
  2392
			bits += component;
hfutrell@2744
  2393
			glGetIntegervFunc(GL_GREEN_BITS, &component);
hfutrell@2744
  2394
			bits += component;
hfutrell@2744
  2395
			glGetIntegervFunc(GL_BLUE_BITS, &component);
hfutrell@2744
  2396
			bits += component;
hfutrell@2744
  2397
			glGetIntegervFunc(GL_ALPHA_BITS, &component);
hfutrell@2744
  2398
			bits += component;
slouken@1936
  2399
hfutrell@2744
  2400
			*value = bits;
hfutrell@2744
  2401
			return 0;
hfutrell@2744
  2402
		}
hfutrell@2744
  2403
	case SDL_GL_ACCELERATED_VISUAL:
hfutrell@2744
  2404
		{
hfutrell@2744
  2405
			/* FIXME: How do we get this information? */
hfutrell@2744
  2406
			*value = (_this->gl_config.accelerated != 0);
hfutrell@2744
  2407
			return 0;
hfutrell@2744
  2408
		}
hfutrell@2744
  2409
	default:
hfutrell@2744
  2410
		SDL_SetError("Unknown OpenGL attribute");
hfutrell@2744
  2411
		return -1;
hfutrell@2744
  2412
	}
slouken@0
  2413
hfutrell@2744
  2414
	glGetIntegervFunc(attrib, (GLint *) value);
hfutrell@2744
  2415
	return 0;
slouken@1936
  2416
#else
hfutrell@2744
  2417
	SDL_Unsupported();
hfutrell@2744
  2418
	return -1;
hfutrell@2744
  2419
#endif				/* SDL_VIDEO_OPENGL */
slouken@0
  2420
}
slouken@0
  2421
slouken@1912
  2422
SDL_GLContext
slouken@1912
  2423
SDL_GL_CreateContext(SDL_WindowID windowID)
slouken@1912
  2424
{
hfutrell@2744
  2425
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1912
  2426
hfutrell@2744
  2427
	if (!window) {
hfutrell@2744
  2428
		return NULL;
hfutrell@2744
  2429
	}
hfutrell@2744
  2430
	if (!(window->flags & SDL_WINDOW_OPENGL)) {
hfutrell@2744
  2431
		SDL_SetError("The specified window isn't an OpenGL window");
hfutrell@2744
  2432
		return NULL;
hfutrell@2744
  2433
	}
hfutrell@2744
  2434
	return _this->GL_CreateContext(_this, window);
slouken@1912
  2435
}
slouken@1912
  2436
slouken@1912
  2437
int
slouken@1912
  2438
SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
slouken@1912
  2439
{
hfutrell@2744
  2440
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1912
  2441
hfutrell@2744
  2442
	if (window && !(window->flags & SDL_WINDOW_OPENGL)) {
hfutrell@2744
  2443
		SDL_SetError("The specified window isn't an OpenGL window");
hfutrell@2744
  2444
		return -1;
hfutrell@2744
  2445
	}
hfutrell@2744
  2446
	if (!context) {
hfutrell@2744
  2447
		window = NULL;
hfutrell@2744
  2448
	}
hfutrell@2744
  2449
	return _this->GL_MakeCurrent(_this, window, context);
slouken@1912
  2450
}
slouken@1912
  2451
slouken@1912
  2452
int
slouken@1912
  2453
SDL_GL_SetSwapInterval(int interval)
slouken@1912
  2454
{
hfutrell@2744
  2455
	if (!_this) {
hfutrell@2744
  2456
		SDL_UninitializedVideo();
hfutrell@2744
  2457
		return -1;
hfutrell@2744
  2458
	}
hfutrell@2744
  2459
	if (_this->GL_SetSwapInterval) {
hfutrell@2744
  2460
		return _this->GL_SetSwapInterval(_this, interval);
hfutrell@2744
  2461
	} else {
hfutrell@2744
  2462
		SDL_SetError("Setting the swap interval is not supported");
hfutrell@2744
  2463
		return -1;
hfutrell@2744
  2464
	}
slouken@1912
  2465
}
slouken@1912
  2466
slouken@1912
  2467
int
slouken@1912
  2468
SDL_GL_GetSwapInterval(void)
slouken@1912
  2469
{
hfutrell@2744
  2470
	if (!_this) {
hfutrell@2744
  2471
		SDL_UninitializedVideo();
hfutrell@2744
  2472
		return -1;
hfutrell@2744
  2473
	}
hfutrell@2744
  2474
	if (_this->GL_GetSwapInterval) {
hfutrell@2744
  2475
		return _this->GL_GetSwapInterval(_this);
hfutrell@2744
  2476
	} else {
hfutrell@2744
  2477
		SDL_SetError("Getting the swap interval is not supported");
hfutrell@2744
  2478
		return -1;
hfutrell@2744
  2479
	}
slouken@1912
  2480
}
slouken@1912
  2481
slouken@1895
  2482
void
slouken@1912
  2483
SDL_GL_SwapWindow(SDL_WindowID windowID)
slouken@0
  2484
{
hfutrell@2744
  2485
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1912
  2486
hfutrell@2744
  2487
	if (!window) {
hfutrell@2744
  2488
		return;
hfutrell@2744
  2489
	}
hfutrell@2744
  2490
	if (!(window->flags & SDL_WINDOW_OPENGL)) {
hfutrell@2744
  2491
		SDL_SetError("The specified window isn't an OpenGL window");
hfutrell@2744
  2492
		return;
hfutrell@2744
  2493
	}
hfutrell@2744
  2494
	_this->GL_SwapWindow(_this, window);
slouken@1912
  2495
}
slouken@1912
  2496
slouken@1912
  2497
void
slouken@1912
  2498
SDL_GL_DeleteContext(SDL_GLContext context)
slouken@1912
  2499
{
hfutrell@2744
  2500
	if (!_this || !context) {
hfutrell@2744
  2501
		return;
hfutrell@2744
  2502
	}
hfutrell@2744
  2503
	_this->GL_MakeCurrent(_this, NULL, NULL);
hfutrell@2744
  2504
	_this->GL_DeleteContext(_this, context);
slouken@0
  2505
}
slouken@0
  2506
slouken@1895
  2507
#if 0                           // FIXME
hfutrell@2744
  2508
/*
hfutrell@2744
  2509
 * Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
hfutrell@2744
  2510
 * & 2 for alpha channel.
hfutrell@2744
  2511
 */
slouken@1895
  2512
static void
slouken@1895
  2513
CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags)
slouken@0
  2514
{
hfutrell@2744
  2515
	int             x, y;
hfutrell@2744
  2516
	Uint32          colorkey;
slouken@0
  2517
#define SET_MASKBIT(icon, x, y, mask) \
slouken@0
  2518
	mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
slouken@0
  2519
hfutrell@2744
  2520
	colorkey = icon->format->colorkey;
hfutrell@2744
  2521
	switch (icon->format->BytesPerPixel) {
hfutrell@2744
  2522
	case 1:
hfutrell@2744
  2523
		{
hfutrell@2744
  2524
			Uint8          *pixels;
hfutrell@2744
  2525
			for (y = 0; y < icon->h; ++y) {
hfutrell@2744
  2526
				pixels = (Uint8 *) icon->pixels + y * icon->pitch;
hfutrell@2744
  2527
				for (x = 0; x < icon->w; ++x) {
hfutrell@2744
  2528
					if (*pixels++ == colorkey) {
hfutrell@2744
  2529
						SET_MASKBIT(icon, x, y, mask);
hfutrell@2744
  2530
					}
hfutrell@2744
  2531
				}
hfutrell@2744
  2532
			}
hfutrell@2744
  2533
		}
hfutrell@2744
  2534
		break;
slouken@0
  2535
hfutrell@2744
  2536
	case 2:
hfutrell@2744
  2537
		{
hfutrell@2744
  2538
			Uint16         *pixels;
hfutrell@2744
  2539
			for (y = 0; y < icon->h; ++y) {
hfutrell@2744
  2540
				pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2;
hfutrell@2744
  2541
				for (x = 0; x < icon->w; ++x) {
hfutrell@2744
  2542
					if ((flags & 1) && *pixels == colorkey) {
hfutrell@2744
  2543
						SET_MASKBIT(icon, x, y, mask);
hfutrell@2744
  2544
					} else if ((flags & 2)
hfutrell@2744
  2545
						   && (*pixels & icon->format->Amask) == 0) {
hfutrell@2744
  2546
						SET_MASKBIT(icon, x, y, mask);
hfutrell@2744
  2547
					}
hfutrell@2744
  2548
					pixels++;
hfutrell@2744
  2549
				}
hfutrell@2744
  2550
			}
hfutrell@2744
  2551
		}
hfutrell@2744
  2552
		break;
slouken@0
  2553
hfutrell@2744
  2554
	case 4:
hfutrell@2744
  2555
		{
hfutrell@2744
  2556
			Uint32         *pixels;
hfutrell@2744
  2557
			for (y = 0; y < icon->h; ++y) {
hfutrell@2744
  2558
				pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4;
hfutrell@2744
  2559
				for (x = 0; x < icon->w; ++x) {
hfutrell@2744
  2560
					if ((flags & 1) && *pixels == colorkey) {
hfutrell@2744
  2561
						SET_MASKBIT(icon, x, y, mask);
hfutrell@2744
  2562
					} else if ((flags & 2)
hfutrell@2744
  2563
						   && (*pixels & icon->format->Amask) == 0) {
hfutrell@2744
  2564
						SET_MASKBIT(icon, x, y, mask);
hfutrell@2744
  2565
					}
hfutrell@2744
  2566
					pixels++;
hfutrell@2744
  2567
				}
hfutrell@2744
  2568
			}
hfutrell@2744
  2569
		}
hfutrell@2744
  2570
		break;
hfutrell@2744
  2571
	}
slouken@0
  2572
}
slouken@0
  2573
slouken@0
  2574
/*
slouken@0
  2575
 * Sets the window manager icon for the display window.
slouken@0
  2576
 */
slouken@1895
  2577
void
slouken@1895
  2578
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
slouken@0
  2579
{
hfutrell@2744
  2580
	if (icon && _this->SetIcon) {
hfutrell@2744
  2581
		/* Generate a mask if necessary, and create the icon! */
hfutrell@2744
  2582
		if (mask == NULL) {
hfutrell@2744
  2583
			int             mask_len = icon->h * (icon->w + 7) / 8;
hfutrell@2744
  2584
			int             flags = 0;
hfutrell@2744
  2585
			mask = (Uint8 *) SDL_malloc(mask_len);
hfutrell@2744
  2586
			if (mask == NULL) {
hfutrell@2744
  2587
				return;
hfutrell@2744
  2588
			}
hfutrell@2744
  2589
			SDL_memset(mask, ~0, mask_len);
hfutrell@2744
  2590
			if (icon->flags & SDL_SRCCOLORKEY)
hfutrell@2744
  2591
				flags |= 1;
hfutrell@2744
  2592
			if (icon->flags & SDL_SRCALPHA)
hfutrell@2744
  2593
				flags |= 2;
hfutrell@2744
  2594
			if (flags) {
hfutrell@2744
  2595
				CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
hfutrell@2744
  2596
			}
hfutrell@2744
  2597
			_this->SetIcon(_this, icon, mask);
hfutrell@2744
  2598
			SDL_free(mask);
hfutrell@2744
  2599
		} else {
hfutrell@2744
  2600
			_this->SetIcon(_this, icon, mask);
hfutrell@2744
  2601
		}
hfutrell@2744
  2602
	}
slouken@1895
  2603
}
slouken@1895
  2604
#endif
slouken@0
  2605
slouken@1895
  2606
SDL_bool
hfutrell@2744
  2607
SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo * info)
slouken@1895
  2608
{
hfutrell@2744
  2609
	SDL_Window     *window = SDL_GetWindowFromID(windowID);
slouken@1895
  2610
hfutrell@2744
  2611
	if (!window || !_this->GetWindowWMInfo) {
hfutrell@2744
  2612
		return SDL_FALSE;
hfutrell@2744
  2613
	}
hfutrell@2744
  2614
	return (_this->GetWindowWMInfo(_this, window, info));
slouken@0
  2615
}
slouken@0
  2616
slouken@1895
  2617
/* vi: set ts=4 sw=4 expandtab: */