2006-07-10 21:04:37 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2008-12-08 00:27:32 +00:00
|
|
|
Copyright (C) 1997-2009 Sam Lantinga
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
Sam Lantinga
|
|
|
|
slouken@libsdl.org
|
|
|
|
*/
|
|
|
|
#include "SDL_config.h"
|
|
|
|
|
|
|
|
/* This file contains functions for backwards compatibility with SDL 1.2 */
|
|
|
|
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_syswm.h"
|
|
|
|
|
|
|
|
#include "video/SDL_sysvideo.h"
|
|
|
|
#include "video/SDL_pixels_c.h"
|
2008-11-24 23:25:36 +00:00
|
|
|
#include "video/SDL_yuv_sw_c.h"
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
static SDL_Window *SDL_VideoWindow = NULL;
|
2006-07-15 09:46:36 +00:00
|
|
|
static SDL_RendererInfo SDL_VideoRendererInfo;
|
2010-01-21 06:21:52 +00:00
|
|
|
static SDL_Texture *SDL_VideoTexture = NULL;
|
2008-03-14 18:17:49 +00:00
|
|
|
static SDL_Surface *SDL_VideoSurface = NULL;
|
|
|
|
static SDL_Surface *SDL_ShadowSurface = NULL;
|
|
|
|
static SDL_Surface *SDL_PublicSurface = NULL;
|
|
|
|
static SDL_GLContext *SDL_VideoContext = NULL;
|
2008-12-04 16:54:22 +00:00
|
|
|
static Uint32 SDL_VideoFlags = 0;
|
2008-03-14 18:17:49 +00:00
|
|
|
static char *wm_title = NULL;
|
2009-01-02 17:39:48 +00:00
|
|
|
static SDL_Surface *SDL_VideoIcon;
|
2009-09-19 13:29:40 +00:00
|
|
|
static int SDL_enabled_UNICODE = 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
SDL_AudioDriverName(char *namebuf, int maxlen)
|
|
|
|
{
|
|
|
|
const char *name = SDL_GetCurrentAudioDriver();
|
|
|
|
if (name) {
|
|
|
|
SDL_strlcpy(namebuf, name, maxlen);
|
|
|
|
return namebuf;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
SDL_VideoDriverName(char *namebuf, int maxlen)
|
|
|
|
{
|
|
|
|
const char *name = SDL_GetCurrentVideoDriver();
|
|
|
|
if (name) {
|
|
|
|
SDL_strlcpy(namebuf, name, maxlen);
|
|
|
|
return namebuf;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-03 08:43:12 +00:00
|
|
|
static void
|
|
|
|
SelectVideoDisplay()
|
|
|
|
{
|
|
|
|
const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
|
|
|
|
if ( !variable ) {
|
|
|
|
variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
|
|
|
|
}
|
|
|
|
if ( variable ) {
|
|
|
|
SDL_SelectVideoDisplay(SDL_atoi(variable));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
const SDL_VideoInfo *
|
|
|
|
SDL_GetVideoInfo(void)
|
|
|
|
{
|
|
|
|
static SDL_VideoInfo info;
|
2006-08-05 22:34:23 +00:00
|
|
|
SDL_DisplayMode mode;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2009-12-03 08:43:12 +00:00
|
|
|
SelectVideoDisplay();
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Memory leak, compatibility code, who cares? */
|
2006-08-05 22:34:23 +00:00
|
|
|
if (!info.vfmt && SDL_GetDesktopDisplayMode(&mode) == 0) {
|
2006-07-10 21:04:37 +00:00
|
|
|
int bpp;
|
|
|
|
Uint32 Rmask, Gmask, Bmask, Amask;
|
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask,
|
|
|
|
&Amask);
|
2006-07-10 21:04:37 +00:00
|
|
|
info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
|
2008-12-12 06:46:20 +00:00
|
|
|
info.current_w = mode.w;
|
|
|
|
info.current_h = mode.h;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
return &info;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
|
|
|
|
{
|
|
|
|
int i, actual_bpp = 0;
|
|
|
|
|
|
|
|
if (!SDL_GetVideoDevice()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-03 08:43:12 +00:00
|
|
|
SelectVideoDisplay();
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!(flags & SDL_FULLSCREEN)) {
|
2006-08-05 22:34:23 +00:00
|
|
|
SDL_DisplayMode mode;
|
|
|
|
SDL_GetDesktopDisplayMode(&mode);
|
|
|
|
return SDL_BITSPERPIXEL(mode.format);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
|
2006-08-05 22:34:23 +00:00
|
|
|
SDL_DisplayMode mode;
|
|
|
|
SDL_GetDisplayMode(i, &mode);
|
|
|
|
if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) {
|
|
|
|
if (!mode.format) {
|
2006-07-10 21:04:37 +00:00
|
|
|
return bpp;
|
|
|
|
}
|
2006-08-05 22:34:23 +00:00
|
|
|
if (SDL_BITSPERPIXEL(mode.format) >= (Uint32) bpp) {
|
|
|
|
actual_bpp = SDL_BITSPERPIXEL(mode.format);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return actual_bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Rect **
|
2009-01-13 03:53:22 +00:00
|
|
|
SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
|
|
|
int i, nmodes;
|
|
|
|
SDL_Rect **modes;
|
|
|
|
|
|
|
|
if (!SDL_GetVideoDevice()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-03 08:43:12 +00:00
|
|
|
SelectVideoDisplay();
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!(flags & SDL_FULLSCREEN)) {
|
|
|
|
return (SDL_Rect **) (-1);
|
|
|
|
}
|
|
|
|
|
2009-01-13 03:53:22 +00:00
|
|
|
if (!format) {
|
|
|
|
format = SDL_GetVideoInfo()->vfmt;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Memory leak, but this is a compatibility function, who cares? */
|
|
|
|
nmodes = 0;
|
|
|
|
modes = NULL;
|
|
|
|
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
|
2006-08-05 22:34:23 +00:00
|
|
|
SDL_DisplayMode mode;
|
|
|
|
SDL_GetDisplayMode(i, &mode);
|
|
|
|
if (!mode.w || !mode.h) {
|
2006-07-10 21:04:37 +00:00
|
|
|
return (SDL_Rect **) (-1);
|
|
|
|
}
|
2006-08-05 22:34:23 +00:00
|
|
|
if (SDL_BITSPERPIXEL(mode.format) != format->BitsPerPixel) {
|
2006-07-10 21:04:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
2006-08-05 22:34:23 +00:00
|
|
|
if (nmodes > 0 && modes[nmodes - 1]->w == mode.w
|
|
|
|
&& modes[nmodes - 1]->h == mode.h) {
|
2006-07-10 21:04:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
|
|
|
|
if (!modes) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
|
|
|
|
if (!modes[nmodes]) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
modes[nmodes]->x = 0;
|
|
|
|
modes[nmodes]->y = 0;
|
2006-08-05 22:34:23 +00:00
|
|
|
modes[nmodes]->w = mode.w;
|
|
|
|
modes[nmodes]->h = mode.h;
|
2006-07-10 21:04:37 +00:00
|
|
|
++nmodes;
|
|
|
|
}
|
|
|
|
if (modes) {
|
|
|
|
modes[nmodes] = NULL;
|
|
|
|
}
|
|
|
|
return modes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SDL_CompatEventFilter(void *userdata, SDL_Event * event)
|
|
|
|
{
|
|
|
|
SDL_Event fake;
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
switch (event->window.event) {
|
|
|
|
case SDL_WINDOWEVENT_EXPOSED:
|
|
|
|
if (!SDL_HasEvent(SDL_VIDEOEXPOSEMASK)) {
|
|
|
|
fake.type = SDL_VIDEOEXPOSE;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_RESIZED:
|
2008-12-04 16:54:22 +00:00
|
|
|
SDL_PeepEvents(&fake, 1, SDL_GETEVENT, SDL_VIDEORESIZEMASK);
|
2006-07-10 21:04:37 +00:00
|
|
|
fake.type = SDL_VIDEORESIZE;
|
|
|
|
fake.resize.w = event->window.data1;
|
|
|
|
fake.resize.h = event->window.data2;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_MINIMIZED:
|
|
|
|
fake.type = SDL_ACTIVEEVENT;
|
|
|
|
fake.active.gain = 0;
|
|
|
|
fake.active.state = SDL_APPACTIVE;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_RESTORED:
|
|
|
|
fake.type = SDL_ACTIVEEVENT;
|
|
|
|
fake.active.gain = 1;
|
|
|
|
fake.active.state = SDL_APPACTIVE;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_ENTER:
|
|
|
|
fake.type = SDL_ACTIVEEVENT;
|
|
|
|
fake.active.gain = 1;
|
|
|
|
fake.active.state = SDL_APPMOUSEFOCUS;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_LEAVE:
|
|
|
|
fake.type = SDL_ACTIVEEVENT;
|
|
|
|
fake.active.gain = 0;
|
|
|
|
fake.active.state = SDL_APPMOUSEFOCUS;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
|
|
|
fake.type = SDL_ACTIVEEVENT;
|
|
|
|
fake.active.gain = 1;
|
|
|
|
fake.active.state = SDL_APPINPUTFOCUS;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
|
|
fake.type = SDL_ACTIVEEVENT;
|
2006-10-28 16:41:08 +00:00
|
|
|
fake.active.gain = 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
fake.active.state = SDL_APPINPUTFOCUS;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_CLOSE:
|
|
|
|
fake.type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(&fake);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
|
|
|
{
|
|
|
|
Uint32 unicode = 0;
|
|
|
|
if (event->key.type == SDL_KEYDOWN && event->key.keysym.sym < 256) {
|
|
|
|
unicode = event->key.keysym.sym;
|
|
|
|
if (unicode >= 'a' && unicode <= 'z') {
|
|
|
|
int shifted = !!(event->key.keysym.mod & KMOD_SHIFT);
|
|
|
|
int capslock = !!(event->key.keysym.mod & KMOD_CAPS);
|
|
|
|
if ((shifted ^ capslock) != 0) {
|
|
|
|
unicode = SDL_toupper(unicode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (unicode) {
|
|
|
|
event->key.keysym.unicode = unicode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-06-16 15:32:04 +00:00
|
|
|
case SDL_TEXTINPUT:
|
|
|
|
{
|
|
|
|
/* FIXME: Generate an old style key repeat event if needed */
|
2007-06-19 05:53:56 +00:00
|
|
|
//printf("TEXTINPUT: '%s'\n", event->text.text);
|
2007-06-16 15:32:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
case SDL_MOUSEWHEEL:
|
|
|
|
{
|
|
|
|
Uint8 button;
|
|
|
|
int selected;
|
|
|
|
int x, y;
|
|
|
|
|
2007-07-06 13:45:10 +00:00
|
|
|
if (event->wheel.y == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
selected = SDL_SelectMouse(event->wheel.which);
|
2009-12-16 19:50:51 +00:00
|
|
|
SDL_GetMouseState(&x, &y);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_SelectMouse(selected);
|
|
|
|
|
2007-07-06 13:45:10 +00:00
|
|
|
if (event->wheel.y > 0) {
|
|
|
|
button = SDL_BUTTON_WHEELUP;
|
|
|
|
} else {
|
|
|
|
button = SDL_BUTTON_WHEELDOWN;
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
fake.button.which = event->wheel.which;
|
2007-07-06 13:45:10 +00:00
|
|
|
fake.button.button = button;
|
2006-07-10 21:04:37 +00:00
|
|
|
fake.button.x = x;
|
|
|
|
fake.button.y = y;
|
|
|
|
fake.button.windowID = event->wheel.windowID;
|
|
|
|
|
2007-07-06 13:45:10 +00:00
|
|
|
fake.type = SDL_MOUSEBUTTONDOWN;
|
|
|
|
fake.button.state = SDL_PRESSED;
|
|
|
|
SDL_PushEvent(&fake);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2007-07-06 13:45:10 +00:00
|
|
|
fake.type = SDL_MOUSEBUTTONUP;
|
|
|
|
fake.button.state = SDL_RELEASED;
|
|
|
|
SDL_PushEvent(&fake);
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SDL_VideoPaletteChanged(void *userdata, SDL_Palette * palette)
|
|
|
|
{
|
|
|
|
if (userdata == SDL_ShadowSurface) {
|
|
|
|
/* If the shadow palette changed, make the changes visible */
|
|
|
|
if (!SDL_VideoSurface->format->palette) {
|
|
|
|
SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (userdata == SDL_VideoSurface) {
|
2006-08-06 23:34:59 +00:00
|
|
|
if (SDL_SetDisplayPalette(palette->colors, 0, palette->ncolors) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (SDL_SetTexturePalette
|
|
|
|
(SDL_VideoTexture, palette->colors, 0, palette->ncolors) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
|
|
|
|
{
|
|
|
|
const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
|
|
|
|
const char *center = SDL_getenv("SDL_VIDEO_CENTERED");
|
|
|
|
if (window) {
|
|
|
|
if (SDL_sscanf(window, "%d,%d", x, y) == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (SDL_strcmp(window, "center") == 0) {
|
|
|
|
center = window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (center) {
|
2006-08-05 22:34:23 +00:00
|
|
|
SDL_DisplayMode mode;
|
|
|
|
SDL_GetDesktopDisplayMode(&mode);
|
|
|
|
*x = (mode.w - w) / 2;
|
|
|
|
*y = (mode.h - h) / 2;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-11 20:54:31 +00:00
|
|
|
static SDL_Surface *
|
2010-01-21 06:21:52 +00:00
|
|
|
CreateVideoSurface(SDL_Texture * texture)
|
2007-08-11 20:54:31 +00:00
|
|
|
{
|
|
|
|
SDL_Surface *surface;
|
|
|
|
Uint32 format;
|
|
|
|
int w, h;
|
|
|
|
int bpp;
|
|
|
|
Uint32 Rmask, Gmask, Bmask, Amask;
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
if (SDL_QueryTexture(texture, &format, NULL, &w, &h) < 0) {
|
2007-08-11 20:54:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SDL_PixelFormatEnumToMasks
|
|
|
|
(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
|
|
|
|
SDL_SetError("Unknown texture format");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
if (SDL_QueryTexturePixels(texture, &pixels, &pitch) == 0) {
|
2007-08-11 20:54:31 +00:00
|
|
|
surface =
|
|
|
|
SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, Gmask,
|
|
|
|
Bmask, Amask);
|
|
|
|
} else {
|
|
|
|
surface =
|
|
|
|
SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
|
|
|
|
}
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2008-12-04 16:54:22 +00:00
|
|
|
static void
|
|
|
|
ClearVideoSurface()
|
|
|
|
{
|
|
|
|
Uint32 black;
|
|
|
|
|
|
|
|
/* Clear the surface for display */
|
|
|
|
black = SDL_MapRGB(SDL_PublicSurface->format, 0, 0, 0);
|
|
|
|
SDL_FillRect(SDL_PublicSurface, NULL, black);
|
|
|
|
SDL_UpdateRect(SDL_PublicSurface, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-01-12 06:19:05 +00:00
|
|
|
static void
|
2009-01-12 08:23:12 +00:00
|
|
|
SetupScreenSaver(int flags)
|
2009-01-12 06:19:05 +00:00
|
|
|
{
|
|
|
|
const char *env;
|
|
|
|
SDL_bool allow_screensaver;
|
|
|
|
|
2009-01-12 08:23:12 +00:00
|
|
|
/* Allow environment override of screensaver disable */
|
|
|
|
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
|
|
|
|
if (env) {
|
|
|
|
allow_screensaver = SDL_atoi(env) ? SDL_TRUE : SDL_FALSE;
|
|
|
|
} else if (flags & SDL_FULLSCREEN) {
|
|
|
|
allow_screensaver = SDL_FALSE;
|
|
|
|
} else {
|
|
|
|
allow_screensaver = SDL_TRUE;
|
|
|
|
}
|
2009-01-12 06:19:05 +00:00
|
|
|
if (allow_screensaver) {
|
|
|
|
SDL_EnableScreenSaver();
|
|
|
|
} else {
|
|
|
|
SDL_DisableScreenSaver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 16:54:22 +00:00
|
|
|
int
|
|
|
|
SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
Uint32 format;
|
|
|
|
int access;
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
|
|
|
|
|
|
|
/* We can't resize something we don't have... */
|
|
|
|
if (!SDL_VideoWindow) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We probably have to recreate the window in fullscreen mode */
|
|
|
|
if (flags & SDL_FULLSCREEN) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I don't think there's any change we can gracefully make in flags */
|
|
|
|
if (flags != SDL_VideoFlags) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize the window */
|
|
|
|
SDL_GetWindowSize(SDL_VideoWindow, &w, &h);
|
|
|
|
if (w != width || h != height) {
|
|
|
|
SDL_SetWindowSize(SDL_VideoWindow, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're in OpenGL mode, just resize the stub surface and we're done! */
|
|
|
|
if (flags & SDL_OPENGL) {
|
|
|
|
SDL_VideoSurface->w = width;
|
|
|
|
SDL_VideoSurface->h = height;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Destroy the screen texture and recreate it */
|
|
|
|
SDL_QueryTexture(SDL_VideoTexture, &format, &access, &w, &h);
|
|
|
|
SDL_DestroyTexture(SDL_VideoTexture);
|
|
|
|
SDL_VideoTexture = SDL_CreateTexture(format, access, width, height);
|
|
|
|
if (!SDL_VideoTexture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_VideoSurface->w = width;
|
|
|
|
SDL_VideoSurface->h = height;
|
|
|
|
if (SDL_QueryTexturePixels(SDL_VideoTexture, &pixels, &pitch) == 0) {
|
|
|
|
SDL_VideoSurface->pixels = pixels;
|
|
|
|
SDL_VideoSurface->pitch = pitch;
|
|
|
|
} else {
|
|
|
|
SDL_CalculatePitch(SDL_VideoSurface);
|
|
|
|
SDL_VideoSurface->pixels =
|
|
|
|
SDL_realloc(SDL_VideoSurface->pixels,
|
|
|
|
SDL_VideoSurface->h * SDL_VideoSurface->pitch);
|
|
|
|
}
|
|
|
|
SDL_SetClipRect(SDL_VideoSurface, NULL);
|
2008-12-05 06:19:49 +00:00
|
|
|
SDL_InvalidateMap(SDL_VideoSurface->map);
|
2008-12-04 16:54:22 +00:00
|
|
|
|
|
|
|
if (SDL_ShadowSurface) {
|
|
|
|
SDL_ShadowSurface->w = width;
|
|
|
|
SDL_ShadowSurface->h = height;
|
2008-12-05 06:19:49 +00:00
|
|
|
SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface);
|
2008-12-04 16:54:22 +00:00
|
|
|
SDL_ShadowSurface->pixels =
|
|
|
|
SDL_realloc(SDL_ShadowSurface->pixels,
|
|
|
|
SDL_ShadowSurface->h * SDL_ShadowSurface->pitch);
|
|
|
|
SDL_SetClipRect(SDL_ShadowSurface, NULL);
|
2008-12-05 06:19:49 +00:00
|
|
|
SDL_InvalidateMap(SDL_ShadowSurface->map);
|
2008-12-04 16:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ClearVideoSurface();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_Surface *
|
|
|
|
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
|
|
|
|
{
|
2006-08-05 22:34:23 +00:00
|
|
|
SDL_DisplayMode desktop_mode;
|
2006-07-10 21:04:37 +00:00
|
|
|
int window_x = SDL_WINDOWPOS_UNDEFINED;
|
|
|
|
int window_y = SDL_WINDOWPOS_UNDEFINED;
|
|
|
|
Uint32 window_flags;
|
|
|
|
Uint32 desktop_format;
|
|
|
|
Uint32 desired_format;
|
|
|
|
Uint32 surface_flags;
|
|
|
|
|
|
|
|
if (!SDL_GetVideoDevice()) {
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-05-23 22:41:08 +00:00
|
|
|
|
2009-12-03 08:43:12 +00:00
|
|
|
SelectVideoDisplay();
|
|
|
|
|
2009-03-23 05:37:45 +00:00
|
|
|
SDL_GetDesktopDisplayMode(&desktop_mode);
|
|
|
|
|
|
|
|
if (width == 0) {
|
|
|
|
width = desktop_mode.w;
|
|
|
|
}
|
|
|
|
if (height == 0) {
|
|
|
|
height = desktop_mode.h;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-12-04 16:54:22 +00:00
|
|
|
/* See if we can simply resize the existing window and surface */
|
|
|
|
if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) {
|
|
|
|
return SDL_PublicSurface;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Destroy existing window */
|
|
|
|
SDL_PublicSurface = NULL;
|
|
|
|
if (SDL_ShadowSurface) {
|
|
|
|
SDL_FreeSurface(SDL_ShadowSurface);
|
|
|
|
SDL_ShadowSurface = NULL;
|
|
|
|
}
|
|
|
|
if (SDL_VideoSurface) {
|
|
|
|
SDL_DelPaletteWatch(SDL_VideoSurface->format->palette,
|
|
|
|
SDL_VideoPaletteChanged, NULL);
|
|
|
|
SDL_FreeSurface(SDL_VideoSurface);
|
|
|
|
SDL_VideoSurface = NULL;
|
|
|
|
}
|
2006-07-16 09:34:01 +00:00
|
|
|
if (SDL_VideoContext) {
|
2008-03-14 18:17:49 +00:00
|
|
|
/* SDL_GL_MakeCurrent(0, NULL); *//* Doesn't do anything */
|
2006-07-16 09:34:01 +00:00
|
|
|
SDL_GL_DeleteContext(SDL_VideoContext);
|
|
|
|
SDL_VideoContext = NULL;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_VideoWindow) {
|
|
|
|
SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y);
|
2008-03-06 17:08:10 +00:00
|
|
|
SDL_DestroyWindow(SDL_VideoWindow);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the event filter */
|
|
|
|
if (!SDL_GetEventFilter(NULL, NULL)) {
|
|
|
|
SDL_SetEventFilter(SDL_CompatEventFilter, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new window */
|
|
|
|
window_flags = SDL_WINDOW_SHOWN;
|
|
|
|
if (flags & SDL_FULLSCREEN) {
|
|
|
|
window_flags |= SDL_WINDOW_FULLSCREEN;
|
|
|
|
}
|
|
|
|
if (flags & SDL_OPENGL) {
|
|
|
|
window_flags |= SDL_WINDOW_OPENGL;
|
|
|
|
}
|
|
|
|
if (flags & SDL_RESIZABLE) {
|
|
|
|
window_flags |= SDL_WINDOW_RESIZABLE;
|
|
|
|
}
|
|
|
|
if (flags & SDL_NOFRAME) {
|
|
|
|
window_flags |= SDL_WINDOW_BORDERLESS;
|
|
|
|
}
|
|
|
|
GetEnvironmentWindowPosition(width, height, &window_x, &window_y);
|
|
|
|
SDL_VideoWindow =
|
|
|
|
SDL_CreateWindow(wm_title, window_x, window_y, width, height,
|
|
|
|
window_flags);
|
|
|
|
if (!SDL_VideoWindow) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-02 17:39:48 +00:00
|
|
|
SDL_SetWindowIcon(SDL_VideoWindow, SDL_VideoIcon);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
|
|
|
|
surface_flags = 0;
|
|
|
|
if (window_flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
surface_flags |= SDL_FULLSCREEN;
|
|
|
|
}
|
|
|
|
if (window_flags & SDL_WINDOW_OPENGL) {
|
|
|
|
surface_flags |= SDL_OPENGL;
|
|
|
|
}
|
|
|
|
if (window_flags & SDL_WINDOW_RESIZABLE) {
|
|
|
|
surface_flags |= SDL_RESIZABLE;
|
|
|
|
}
|
|
|
|
if (window_flags & SDL_WINDOW_BORDERLESS) {
|
|
|
|
surface_flags |= SDL_NOFRAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the desired display mode */
|
2006-08-05 22:34:23 +00:00
|
|
|
desktop_format = desktop_mode.format;
|
2006-07-10 21:04:37 +00:00
|
|
|
if (desktop_format && ((flags & SDL_ANYFORMAT)
|
|
|
|
|| (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
|
|
|
|
desired_format = desktop_format;
|
|
|
|
} else {
|
|
|
|
switch (bpp) {
|
|
|
|
case 0:
|
|
|
|
if (desktop_format) {
|
|
|
|
desired_format = desktop_format;
|
|
|
|
} else {
|
2006-08-05 17:09:42 +00:00
|
|
|
desired_format = SDL_PIXELFORMAT_RGB888;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2007-08-15 03:18:24 +00:00
|
|
|
bpp = SDL_BITSPERPIXEL(desired_format);
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
2006-08-05 17:09:42 +00:00
|
|
|
desired_format = SDL_PIXELFORMAT_INDEX8;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case 15:
|
2006-08-05 17:09:42 +00:00
|
|
|
desired_format = SDL_PIXELFORMAT_RGB555;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case 16:
|
2006-08-05 17:09:42 +00:00
|
|
|
desired_format = SDL_PIXELFORMAT_RGB565;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case 24:
|
2006-08-05 17:09:42 +00:00
|
|
|
desired_format = SDL_PIXELFORMAT_RGB24;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case 32:
|
2006-08-05 17:09:42 +00:00
|
|
|
desired_format = SDL_PIXELFORMAT_RGB888;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SDL_SetError("Unsupported bpp in SDL_SetVideoMode()");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
/* Set up the desired display mode */
|
2006-07-10 21:04:37 +00:00
|
|
|
if (flags & SDL_FULLSCREEN) {
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_DisplayMode mode;
|
|
|
|
|
|
|
|
SDL_zero(mode);
|
|
|
|
mode.format = desired_format;
|
|
|
|
if (SDL_SetWindowDisplayMode(SDL_VideoWindow, &mode) < 0) {
|
2006-07-10 21:04:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're in OpenGL mode, just create a stub surface and we're done! */
|
|
|
|
if (flags & SDL_OPENGL) {
|
2006-07-16 09:34:01 +00:00
|
|
|
SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow);
|
|
|
|
if (!SDL_VideoContext) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (SDL_GL_MakeCurrent(SDL_VideoWindow, SDL_VideoContext) < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_VideoSurface =
|
|
|
|
SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
|
|
|
|
if (!SDL_VideoSurface) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
SDL_VideoSurface->flags |= surface_flags;
|
|
|
|
SDL_PublicSurface = SDL_VideoSurface;
|
|
|
|
return SDL_PublicSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a renderer for the window */
|
2006-07-15 09:46:36 +00:00
|
|
|
if (SDL_CreateRenderer
|
|
|
|
(SDL_VideoWindow, -1,
|
2006-08-05 17:09:42 +00:00
|
|
|
SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD) < 0) {
|
2006-07-10 21:04:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-11 20:54:31 +00:00
|
|
|
SDL_GetRendererInfo(&SDL_VideoRendererInfo);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
/* Create a texture for the screen surface */
|
|
|
|
SDL_VideoTexture =
|
2007-08-11 20:54:31 +00:00
|
|
|
SDL_CreateTexture(desired_format, SDL_TEXTUREACCESS_STREAMING, width,
|
2006-07-10 21:04:37 +00:00
|
|
|
height);
|
2008-10-04 06:46:59 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!SDL_VideoTexture) {
|
|
|
|
SDL_VideoTexture =
|
2008-12-16 17:40:30 +00:00
|
|
|
SDL_CreateTexture(desktop_format,
|
2007-08-11 20:54:31 +00:00
|
|
|
SDL_TEXTUREACCESS_STREAMING, width, height);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
if (!SDL_VideoTexture) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the screen surface */
|
2007-08-11 20:54:31 +00:00
|
|
|
SDL_VideoSurface = CreateVideoSurface(SDL_VideoTexture);
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!SDL_VideoSurface) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
SDL_VideoSurface->flags |= surface_flags;
|
|
|
|
|
|
|
|
/* Set a default screen palette */
|
|
|
|
if (SDL_VideoSurface->format->palette) {
|
|
|
|
SDL_VideoSurface->flags |= SDL_HWPALETTE;
|
|
|
|
SDL_DitherColors(SDL_VideoSurface->format->palette->colors,
|
|
|
|
SDL_VideoSurface->format->BitsPerPixel);
|
|
|
|
SDL_AddPaletteWatch(SDL_VideoSurface->format->palette,
|
2008-12-07 22:48:06 +00:00
|
|
|
SDL_VideoPaletteChanged, SDL_VideoSurface);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_SetPaletteColors(SDL_VideoSurface->format->palette,
|
|
|
|
SDL_VideoSurface->format->palette->colors, 0,
|
|
|
|
SDL_VideoSurface->format->palette->ncolors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a shadow surface if necessary */
|
2007-08-11 20:54:31 +00:00
|
|
|
if ((bpp != SDL_VideoSurface->format->BitsPerPixel)
|
|
|
|
&& !(flags & SDL_ANYFORMAT)) {
|
|
|
|
SDL_ShadowSurface =
|
|
|
|
SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0);
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!SDL_ShadowSurface) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
SDL_ShadowSurface->flags |= surface_flags;
|
|
|
|
|
|
|
|
/* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
|
|
|
|
if (SDL_ShadowSurface->format->palette) {
|
|
|
|
SDL_ShadowSurface->flags |= SDL_HWPALETTE;
|
|
|
|
if (SDL_VideoSurface->format->palette) {
|
|
|
|
SDL_SetSurfacePalette(SDL_ShadowSurface,
|
|
|
|
SDL_VideoSurface->format->palette);
|
|
|
|
} else {
|
|
|
|
SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
|
|
|
|
SDL_ShadowSurface->format->BitsPerPixel);
|
|
|
|
}
|
2008-12-07 22:48:06 +00:00
|
|
|
SDL_AddPaletteWatch(SDL_ShadowSurface->format->palette,
|
|
|
|
SDL_VideoPaletteChanged, SDL_ShadowSurface);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_PublicSurface =
|
|
|
|
(SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface);
|
|
|
|
|
2008-12-04 16:54:22 +00:00
|
|
|
SDL_VideoFlags = flags;
|
|
|
|
|
|
|
|
ClearVideoSurface();
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2009-01-12 08:23:12 +00:00
|
|
|
SetupScreenSaver(flags);
|
2009-01-12 06:19:05 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* We're finally done! */
|
|
|
|
return SDL_PublicSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Surface *
|
|
|
|
SDL_GetVideoSurface(void)
|
|
|
|
{
|
|
|
|
return SDL_PublicSurface;
|
|
|
|
}
|
|
|
|
|
2007-08-18 01:44:21 +00:00
|
|
|
int
|
|
|
|
SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
|
|
|
|
{
|
2008-12-06 05:49:53 +00:00
|
|
|
if (flag & SDL_SRCALPHA) {
|
|
|
|
/* According to the docs, value is ignored for alpha surfaces */
|
|
|
|
if (surface->format->Amask) {
|
|
|
|
value = 0xFF;
|
|
|
|
}
|
2007-08-18 01:44:21 +00:00
|
|
|
SDL_SetSurfaceAlphaMod(surface, value);
|
Date: Fri, 19 Dec 2008 20:17:35 +0100
From: Couriersud
Subject: Re: Aw: Experience using SDL1.3 in sdlmame/Proposal for api additions
> For consistency you'd probably want:
> SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
> SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode);
> SDL_RenderLine(int x1, int y1, int x2, int y2);
> SDL_RenderFill(SDL_Rect *rect);
>
> You probably also want to add API functions query the current state.
>
I have implemented the above api for the opengl, x11, directfb and
software renderers. I have also renamed *TEXTUREBLENDMODE* constants to
BLENDMODE*. The unix build compiles. The windows renderer still needs to
be updated, but I have no windows development machine at hand. Have a
look at the x11 renderer for a sample.
Vector games now run at 90% both on opengl and directfb in comparison to
sdlmame's own opengl renderer. The same applies to raster games.
The diff also includes
a) Changed XDrawRect to XFillRect in x11 renderer
b) A number of changes to fix blending and modulation issues in the
directfb renderer.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
|
2007-08-18 01:44:21 +00:00
|
|
|
} else {
|
|
|
|
SDL_SetSurfaceAlphaMod(surface, 0xFF);
|
Date: Fri, 19 Dec 2008 20:17:35 +0100
From: Couriersud
Subject: Re: Aw: Experience using SDL1.3 in sdlmame/Proposal for api additions
> For consistency you'd probably want:
> SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
> SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode);
> SDL_RenderLine(int x1, int y1, int x2, int y2);
> SDL_RenderFill(SDL_Rect *rect);
>
> You probably also want to add API functions query the current state.
>
I have implemented the above api for the opengl, x11, directfb and
software renderers. I have also renamed *TEXTUREBLENDMODE* constants to
BLENDMODE*. The unix build compiles. The windows renderer still needs to
be updated, but I have no windows development machine at hand. Have a
look at the x11 renderer for a sample.
Vector games now run at 90% both on opengl and directfb in comparison to
sdlmame's own opengl renderer. The same applies to raster games.
The diff also includes
a) Changed XDrawRect to XFillRect in x11 renderer
b) A number of changes to fix blending and modulation issues in the
directfb renderer.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
|
2007-08-18 01:44:21 +00:00
|
|
|
}
|
2008-12-06 05:49:53 +00:00
|
|
|
SDL_SetSurfaceRLE(surface, (flag & SDL_RLEACCEL));
|
|
|
|
|
2007-08-18 01:44:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_Surface *
|
|
|
|
SDL_DisplayFormat(SDL_Surface * surface)
|
|
|
|
{
|
2008-11-29 11:26:01 +00:00
|
|
|
SDL_PixelFormat *format;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
if (!SDL_PublicSurface) {
|
|
|
|
SDL_SetError("No video mode has been set");
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-29 11:26:01 +00:00
|
|
|
format = SDL_PublicSurface->format;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
/* Set the flags appropriate for copying to display surface */
|
2008-11-29 11:26:01 +00:00
|
|
|
return SDL_ConvertSurface(surface, format, SDL_RLEACCEL);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Surface *
|
|
|
|
SDL_DisplayFormatAlpha(SDL_Surface * surface)
|
|
|
|
{
|
|
|
|
SDL_PixelFormat *vf;
|
|
|
|
SDL_PixelFormat *format;
|
|
|
|
SDL_Surface *converted;
|
|
|
|
/* default to ARGB8888 */
|
|
|
|
Uint32 amask = 0xff000000;
|
|
|
|
Uint32 rmask = 0x00ff0000;
|
|
|
|
Uint32 gmask = 0x0000ff00;
|
|
|
|
Uint32 bmask = 0x000000ff;
|
|
|
|
|
|
|
|
if (!SDL_PublicSurface) {
|
|
|
|
SDL_SetError("No video mode has been set");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
vf = SDL_PublicSurface->format;
|
|
|
|
|
|
|
|
switch (vf->BytesPerPixel) {
|
|
|
|
case 2:
|
|
|
|
/* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
|
|
|
|
For anything else (like ARGB4444) it doesn't matter
|
|
|
|
since we have no special code for it anyway */
|
|
|
|
if ((vf->Rmask == 0x1f) &&
|
|
|
|
(vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
|
|
|
|
rmask = 0xff;
|
|
|
|
bmask = 0xff0000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
/* Keep the video format, as long as the high 8 bits are
|
|
|
|
unused or alpha */
|
|
|
|
if ((vf->Rmask == 0xff) && (vf->Bmask == 0xff0000)) {
|
|
|
|
rmask = 0xff;
|
|
|
|
bmask = 0xff0000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* We have no other optimised formats right now. When/if a new
|
|
|
|
optimised alpha format is written, add the converter here */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
|
2008-11-29 11:26:01 +00:00
|
|
|
converted = SDL_ConvertSurface(surface, format, SDL_RLEACCEL);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_FreeFormat(format);
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_Flip(SDL_Surface * screen)
|
|
|
|
{
|
|
|
|
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
|
|
|
|
{
|
|
|
|
if (screen) {
|
|
|
|
SDL_Rect rect;
|
|
|
|
|
|
|
|
/* Fill the rectangle */
|
2006-07-12 06:39:26 +00:00
|
|
|
rect.x = (int) x;
|
|
|
|
rect.y = (int) y;
|
|
|
|
rect.w = (int) (w ? w : screen->w);
|
|
|
|
rect.h = (int) (h ? h : screen->h);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_UpdateRects(screen, 1, &rect);
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 15:10:03 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (screen == SDL_ShadowSurface) {
|
|
|
|
for (i = 0; i < numrects; ++i) {
|
|
|
|
SDL_LowerBlit(SDL_ShadowSurface, &rects[i], SDL_VideoSurface,
|
|
|
|
&rects[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fall through to video surface update */
|
|
|
|
screen = SDL_VideoSurface;
|
|
|
|
}
|
|
|
|
if (screen == SDL_VideoSurface) {
|
2007-08-11 20:54:31 +00:00
|
|
|
if (screen->flags & SDL_PREALLOC) {
|
|
|
|
/* The surface memory is maintained by the renderer */
|
|
|
|
SDL_DirtyTexture(SDL_VideoTexture, numrects, rects);
|
|
|
|
} else {
|
|
|
|
/* The surface memory needs to be copied to texture */
|
|
|
|
int pitch = screen->pitch;
|
|
|
|
int psize = screen->format->BytesPerPixel;
|
|
|
|
for (i = 0; i < numrects; ++i) {
|
|
|
|
const SDL_Rect *rect = &rects[i];
|
|
|
|
void *pixels =
|
|
|
|
(Uint8 *) screen->pixels + rect->y * pitch +
|
|
|
|
rect->x * psize;
|
|
|
|
SDL_UpdateTexture(SDL_VideoTexture, rect, pixels, pitch);
|
|
|
|
}
|
|
|
|
}
|
2006-08-05 17:09:42 +00:00
|
|
|
if (SDL_VideoRendererInfo.flags & SDL_RENDERER_PRESENTCOPY) {
|
2006-07-15 09:46:36 +00:00
|
|
|
for (i = 0; i < numrects; ++i) {
|
2006-08-28 03:17:39 +00:00
|
|
|
SDL_RenderCopy(SDL_VideoTexture, &rects[i], &rects[i]);
|
2006-07-15 09:46:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDL_Rect rect;
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.w = screen->w;
|
|
|
|
rect.h = screen->h;
|
2006-08-28 03:17:39 +00:00
|
|
|
SDL_RenderCopy(SDL_VideoTexture, &rect, &rect);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
SDL_RenderPresent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_WM_SetCaption(const char *title, const char *icon)
|
|
|
|
{
|
|
|
|
if (wm_title) {
|
|
|
|
SDL_free(wm_title);
|
2006-09-23 22:51:37 +00:00
|
|
|
}
|
|
|
|
if (title) {
|
2006-07-10 21:04:37 +00:00
|
|
|
wm_title = SDL_strdup(title);
|
2006-09-23 22:51:37 +00:00
|
|
|
} else {
|
|
|
|
wm_title = NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
SDL_SetWindowTitle(SDL_VideoWindow, wm_title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-09-23 22:51:37 +00:00
|
|
|
SDL_WM_GetCaption(const char **title, const char **icon)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
|
|
|
if (title) {
|
|
|
|
*title = wm_title;
|
|
|
|
}
|
|
|
|
if (icon) {
|
|
|
|
*icon = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
|
|
|
|
{
|
2009-01-02 17:39:48 +00:00
|
|
|
SDL_VideoIcon = icon;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_WM_IconifyWindow(void)
|
|
|
|
{
|
|
|
|
SDL_MinimizeWindow(SDL_VideoWindow);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_WM_ToggleFullScreen(SDL_Surface * surface)
|
|
|
|
{
|
|
|
|
if (SDL_GetWindowFlags(SDL_VideoWindow) & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
if (SDL_SetWindowFullscreen(SDL_VideoWindow, 0) < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SDL_PublicSurface->flags &= ~SDL_FULLSCREEN;
|
|
|
|
} else {
|
|
|
|
if (SDL_SetWindowFullscreen(SDL_VideoWindow, 1) < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SDL_PublicSurface->flags |= SDL_FULLSCREEN;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_GrabMode
|
|
|
|
SDL_WM_GrabInput(SDL_GrabMode mode)
|
|
|
|
{
|
|
|
|
if (mode != SDL_GRAB_QUERY) {
|
|
|
|
SDL_SetWindowGrab(SDL_VideoWindow, mode);
|
|
|
|
}
|
|
|
|
return (SDL_GrabMode) SDL_GetWindowGrab(SDL_VideoWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_WarpMouse(Uint16 x, Uint16 y)
|
|
|
|
{
|
|
|
|
SDL_WarpMouseInWindow(SDL_VideoWindow, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
Uint8
|
|
|
|
SDL_GetAppState(void)
|
|
|
|
{
|
|
|
|
Uint8 state = 0;
|
|
|
|
Uint32 flags = 0;
|
|
|
|
|
|
|
|
flags = SDL_GetWindowFlags(SDL_VideoWindow);
|
|
|
|
if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
|
|
|
|
state |= SDL_APPACTIVE;
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_INPUT_FOCUS) {
|
|
|
|
state |= SDL_APPINPUTFOCUS;
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_MOUSE_FOCUS) {
|
|
|
|
state |= SDL_APPMOUSEFOCUS;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SDL_version *
|
|
|
|
SDL_Linked_Version(void)
|
|
|
|
{
|
|
|
|
static SDL_version version;
|
|
|
|
SDL_VERSION(&version);
|
|
|
|
return &version;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
|
|
|
|
int firstcolor, int ncolors)
|
|
|
|
{
|
|
|
|
return SDL_SetColors(surface, colors, firstcolor, ncolors);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
|
|
|
|
int ncolors)
|
|
|
|
{
|
|
|
|
if (SDL_SetPaletteColors
|
|
|
|
(surface->format->palette, colors, firstcolor, ncolors) == 0) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetWMInfo(SDL_SysWMinfo * info)
|
|
|
|
{
|
|
|
|
return SDL_GetWindowWMInfo(SDL_VideoWindow, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void
|
|
|
|
SDL_MoveCursor(int x, int y)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
|
|
|
|
/* Erase and update the current mouse position */
|
|
|
|
if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
|
|
|
|
/* Erase and redraw mouse cursor in new position */
|
|
|
|
SDL_LockCursor();
|
|
|
|
SDL_EraseCursor(SDL_VideoSurface);
|
|
|
|
SDL_cursor->area.x = (x - SDL_cursor->hot_x);
|
|
|
|
SDL_cursor->area.y = (y - SDL_cursor->hot_y);
|
|
|
|
SDL_DrawCursor(SDL_VideoSurface);
|
|
|
|
SDL_UnlockCursor();
|
|
|
|
} else if (_this->MoveWMCursor) {
|
|
|
|
_this->MoveWMCursor(_this, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep track of the current cursor colors */
|
|
|
|
static int palette_changed = 1;
|
|
|
|
static Uint8 pixels8[2];
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_CursorPaletteChanged(void)
|
|
|
|
{
|
|
|
|
palette_changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_MouseRect(SDL_Rect * area)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
int clip_diff;
|
|
|
|
|
|
|
|
*area = SDL_cursor->area;
|
|
|
|
if (area->x < 0) {
|
|
|
|
area->w += area->x;
|
|
|
|
area->x = 0;
|
|
|
|
}
|
|
|
|
if (area->y < 0) {
|
|
|
|
area->h += area->y;
|
|
|
|
area->y = 0;
|
|
|
|
}
|
|
|
|
clip_diff = (area->x + area->w) - SDL_VideoSurface->w;
|
|
|
|
if (clip_diff > 0) {
|
|
|
|
area->w = area->w < clip_diff ? 0 : area->w - clip_diff;
|
|
|
|
}
|
|
|
|
clip_diff = (area->y + area->h) - SDL_VideoSurface->h;
|
|
|
|
if (clip_diff > 0) {
|
|
|
|
area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
|
|
|
|
{
|
|
|
|
const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
|
|
|
|
int i, w, h;
|
|
|
|
Uint8 *data, datab;
|
|
|
|
Uint8 *mask, maskb;
|
|
|
|
|
|
|
|
data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
|
|
|
|
mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
|
|
|
|
switch (screen->format->BytesPerPixel) {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
Uint8 *dst;
|
|
|
|
int dstskip;
|
|
|
|
|
|
|
|
if (palette_changed) {
|
|
|
|
pixels8[0] =
|
|
|
|
(Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
|
|
|
|
pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
|
|
|
|
palette_changed = 0;
|
|
|
|
}
|
|
|
|
dst = (Uint8 *) screen->pixels +
|
|
|
|
(SDL_cursor->area.y + area->y) * screen->pitch +
|
|
|
|
SDL_cursor->area.x;
|
|
|
|
dstskip = screen->pitch - area->w;
|
|
|
|
|
|
|
|
for (h = area->h; h; h--) {
|
|
|
|
for (w = area->w / 8; w; w--) {
|
|
|
|
maskb = *mask++;
|
|
|
|
datab = *data++;
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
if (maskb & 0x80) {
|
|
|
|
*dst = pixels8[datab >> 7];
|
|
|
|
}
|
|
|
|
maskb <<= 1;
|
|
|
|
datab <<= 1;
|
|
|
|
dst++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += dstskip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
Uint16 *dst;
|
|
|
|
int dstskip;
|
|
|
|
|
|
|
|
dst = (Uint16 *) screen->pixels +
|
|
|
|
(SDL_cursor->area.y + area->y) * screen->pitch / 2 +
|
|
|
|
SDL_cursor->area.x;
|
|
|
|
dstskip = (screen->pitch / 2) - area->w;
|
|
|
|
|
|
|
|
for (h = area->h; h; h--) {
|
|
|
|
for (w = area->w / 8; w; w--) {
|
|
|
|
maskb = *mask++;
|
|
|
|
datab = *data++;
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
if (maskb & 0x80) {
|
|
|
|
*dst = (Uint16) pixels[datab >> 7];
|
|
|
|
}
|
|
|
|
maskb <<= 1;
|
|
|
|
datab <<= 1;
|
|
|
|
dst++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += dstskip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
Uint8 *dst;
|
|
|
|
int dstskip;
|
|
|
|
|
|
|
|
dst = (Uint8 *) screen->pixels +
|
|
|
|
(SDL_cursor->area.y + area->y) * screen->pitch +
|
|
|
|
SDL_cursor->area.x * 3;
|
|
|
|
dstskip = screen->pitch - area->w * 3;
|
|
|
|
|
|
|
|
for (h = area->h; h; h--) {
|
|
|
|
for (w = area->w / 8; w; w--) {
|
|
|
|
maskb = *mask++;
|
|
|
|
datab = *data++;
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
if (maskb & 0x80) {
|
|
|
|
SDL_memset(dst, pixels[datab >> 7], 3);
|
|
|
|
}
|
|
|
|
maskb <<= 1;
|
|
|
|
datab <<= 1;
|
|
|
|
dst += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += dstskip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
Uint32 *dst;
|
|
|
|
int dstskip;
|
|
|
|
|
|
|
|
dst = (Uint32 *) screen->pixels +
|
|
|
|
(SDL_cursor->area.y + area->y) * screen->pitch / 4 +
|
|
|
|
SDL_cursor->area.x;
|
|
|
|
dstskip = (screen->pitch / 4) - area->w;
|
|
|
|
|
|
|
|
for (h = area->h; h; h--) {
|
|
|
|
for (w = area->w / 8; w; w--) {
|
|
|
|
maskb = *mask++;
|
|
|
|
datab = *data++;
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
if (maskb & 0x80) {
|
|
|
|
*dst = pixels[datab >> 7];
|
|
|
|
}
|
|
|
|
maskb <<= 1;
|
|
|
|
datab <<= 1;
|
|
|
|
dst++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += dstskip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
|
|
|
|
{
|
|
|
|
const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
|
|
|
|
int h;
|
|
|
|
int x, minx, maxx;
|
|
|
|
Uint8 *data, datab = 0;
|
|
|
|
Uint8 *mask, maskb = 0;
|
|
|
|
Uint8 *dst;
|
|
|
|
int dstbpp, dstskip;
|
|
|
|
|
|
|
|
data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
|
|
|
|
mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
|
|
|
|
dstbpp = screen->format->BytesPerPixel;
|
|
|
|
dst = (Uint8 *) screen->pixels +
|
|
|
|
(SDL_cursor->area.y + area->y) * screen->pitch +
|
|
|
|
SDL_cursor->area.x * dstbpp;
|
|
|
|
dstskip = screen->pitch - SDL_cursor->area.w * dstbpp;
|
|
|
|
|
|
|
|
minx = area->x;
|
|
|
|
maxx = area->x + area->w;
|
|
|
|
if (screen->format->BytesPerPixel == 1) {
|
|
|
|
if (palette_changed) {
|
|
|
|
pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
|
|
|
|
pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
|
|
|
|
palette_changed = 0;
|
|
|
|
}
|
|
|
|
for (h = area->h; h; h--) {
|
|
|
|
for (x = 0; x < SDL_cursor->area.w; ++x) {
|
|
|
|
if ((x % 8) == 0) {
|
|
|
|
maskb = *mask++;
|
|
|
|
datab = *data++;
|
|
|
|
}
|
|
|
|
if ((x >= minx) && (x < maxx)) {
|
|
|
|
if (maskb & 0x80) {
|
|
|
|
SDL_memset(dst, pixels8[datab >> 7], dstbpp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maskb <<= 1;
|
|
|
|
datab <<= 1;
|
|
|
|
dst += dstbpp;
|
|
|
|
}
|
|
|
|
dst += dstskip;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (h = area->h; h; h--) {
|
|
|
|
for (x = 0; x < SDL_cursor->area.w; ++x) {
|
|
|
|
if ((x % 8) == 0) {
|
|
|
|
maskb = *mask++;
|
|
|
|
datab = *data++;
|
|
|
|
}
|
|
|
|
if ((x >= minx) && (x < maxx)) {
|
|
|
|
if (maskb & 0x80) {
|
|
|
|
SDL_memset(dst, pixels[datab >> 7], dstbpp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maskb <<= 1;
|
|
|
|
datab <<= 1;
|
|
|
|
dst += dstbpp;
|
|
|
|
}
|
|
|
|
dst += dstskip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This handles the ugly work of converting the saved cursor background from
|
|
|
|
the pixel format of the shadow surface to that of the video surface.
|
|
|
|
This is only necessary when blitting from a shadow surface of a different
|
|
|
|
pixel format than the video surface, and using a software rendered cursor.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
SDL_BlitInfo info;
|
|
|
|
SDL_loblit RunBlit;
|
|
|
|
|
|
|
|
/* Make sure we can steal the blit mapping */
|
|
|
|
if (screen->map->dst != SDL_VideoSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the blit information */
|
|
|
|
info.s_pixels = SDL_cursor->save[1];
|
|
|
|
info.s_width = w;
|
|
|
|
info.s_height = h;
|
|
|
|
info.s_skip = 0;
|
|
|
|
info.d_pixels = SDL_cursor->save[0];
|
|
|
|
info.d_width = w;
|
|
|
|
info.d_height = h;
|
|
|
|
info.d_skip = 0;
|
|
|
|
info.aux_data = screen->map->sw_data->aux_data;
|
|
|
|
info.src = screen->format;
|
|
|
|
info.table = screen->map->table;
|
|
|
|
info.dst = SDL_VideoSurface->format;
|
|
|
|
RunBlit = screen->map->sw_data->blit;
|
|
|
|
|
|
|
|
/* Run the actual software blit */
|
|
|
|
RunBlit(&info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_DrawCursorNoLock(SDL_Surface * screen)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
SDL_Rect area;
|
|
|
|
|
|
|
|
/* Get the mouse rectangle, clipped to the screen */
|
|
|
|
SDL_MouseRect(&area);
|
|
|
|
if ((area.w == 0) || (area.h == 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy mouse background */
|
|
|
|
{
|
|
|
|
int w, h, screenbpp;
|
|
|
|
Uint8 *src, *dst;
|
|
|
|
|
|
|
|
/* Set up the copy pointers */
|
|
|
|
screenbpp = screen->format->BytesPerPixel;
|
|
|
|
if ((screen == SDL_VideoSurface) ||
|
|
|
|
FORMAT_EQUAL(screen->format, SDL_VideoSurface->format)) {
|
|
|
|
dst = SDL_cursor->save[0];
|
|
|
|
} else {
|
|
|
|
dst = SDL_cursor->save[1];
|
|
|
|
}
|
|
|
|
src = (Uint8 *) screen->pixels + area.y * screen->pitch +
|
|
|
|
area.x * screenbpp;
|
|
|
|
|
|
|
|
/* Perform the copy */
|
|
|
|
w = area.w * screenbpp;
|
|
|
|
h = area.h;
|
|
|
|
while (h--) {
|
|
|
|
SDL_memcpy(dst, src, w);
|
|
|
|
dst += w;
|
|
|
|
src += screen->pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the mouse cursor */
|
|
|
|
area.x -= SDL_cursor->area.x;
|
|
|
|
area.y -= SDL_cursor->area.y;
|
|
|
|
if ((area.x == 0) && (area.w == SDL_cursor->area.w)) {
|
|
|
|
SDL_DrawCursorFast(screen, &area);
|
|
|
|
} else {
|
|
|
|
SDL_DrawCursorSlow(screen, &area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_DrawCursor(SDL_Surface * screen)
|
|
|
|
{
|
|
|
|
/* Lock the screen if necessary */
|
|
|
|
if (screen == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (SDL_MUSTLOCK(screen)) {
|
|
|
|
if (SDL_LockSurface(screen) < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_DrawCursorNoLock(screen);
|
|
|
|
|
|
|
|
/* Unlock the screen and update if necessary */
|
|
|
|
if (SDL_MUSTLOCK(screen)) {
|
|
|
|
SDL_UnlockSurface(screen);
|
|
|
|
}
|
2007-08-11 20:54:31 +00:00
|
|
|
if (screen->flags & SDL_SCREEN_SURFACE) {
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_Rect area;
|
|
|
|
|
|
|
|
window = SDL_GetWindowFromSurface(screen);
|
|
|
|
if (!window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_MouseRect(&area);
|
|
|
|
|
|
|
|
if (_this->UpdateWindowSurface) {
|
|
|
|
_this->UpdateWindowSurface(_this, window, 1, &area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_EraseCursorNoLock(SDL_Surface * screen)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_Rect area;
|
|
|
|
|
|
|
|
/* Get the window associated with the surface */
|
|
|
|
window = SDL_GetWindowFromSurface(screen);
|
|
|
|
if (!window || !window->surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the mouse rectangle, clipped to the screen */
|
|
|
|
SDL_MouseRect(&area);
|
|
|
|
if ((area.w == 0) || (area.h == 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy mouse background */
|
|
|
|
{
|
|
|
|
int w, h, screenbpp;
|
|
|
|
Uint8 *src, *dst;
|
|
|
|
|
|
|
|
/* Set up the copy pointers */
|
|
|
|
screenbpp = screen->format->BytesPerPixel;
|
|
|
|
if ((screen->flags & SDL_SCREEN_SURFACE) ||
|
|
|
|
FORMAT_EQUAL(screen->format, window->surface->format)) {
|
|
|
|
src = SDL_cursor->save[0];
|
|
|
|
} else {
|
|
|
|
src = SDL_cursor->save[1];
|
|
|
|
}
|
|
|
|
dst = (Uint8 *) screen->pixels + area.y * screen->pitch +
|
|
|
|
area.x * screenbpp;
|
|
|
|
|
|
|
|
/* Perform the copy */
|
|
|
|
w = area.w * screenbpp;
|
|
|
|
h = area.h;
|
|
|
|
while (h--) {
|
|
|
|
SDL_memcpy(dst, src, w);
|
|
|
|
src += w;
|
|
|
|
dst += screen->pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform pixel conversion on cursor background */
|
|
|
|
if (src > SDL_cursor->save[1]) {
|
|
|
|
SDL_ConvertCursorSave(screen, area.w, area.h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_EraseCursor(SDL_Surface * screen)
|
|
|
|
{
|
|
|
|
/* Lock the screen if necessary */
|
|
|
|
if (screen == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (SDL_MUSTLOCK(screen)) {
|
|
|
|
if (SDL_LockSurface(screen) < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_EraseCursorNoLock(screen);
|
|
|
|
|
|
|
|
/* Unlock the screen and update if necessary */
|
|
|
|
if (SDL_MUSTLOCK(screen)) {
|
|
|
|
SDL_UnlockSurface(screen);
|
|
|
|
}
|
2007-08-11 20:54:31 +00:00
|
|
|
if (screen->flags & SDL_SCREEN_SURFACE) {
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_Rect area;
|
|
|
|
|
|
|
|
window = SDL_GetWindowFromSurface(screen);
|
|
|
|
if (!window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_MouseRect(&area);
|
|
|
|
|
|
|
|
if (_this->UpdateWindowSurface) {
|
|
|
|
_this->UpdateWindowSurface(_this, window, 1, &area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the cursor on video mode change
|
|
|
|
FIXME: Keep track of all cursors, and reset them all.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SDL_ResetCursor(void)
|
|
|
|
{
|
|
|
|
int savelen;
|
|
|
|
|
|
|
|
if (SDL_cursor) {
|
|
|
|
savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h;
|
|
|
|
SDL_cursor->area.x = 0;
|
|
|
|
SDL_cursor->area.y = 0;
|
|
|
|
SDL_memset(SDL_cursor->save[0], 0, savelen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct private_yuvhwdata
|
|
|
|
{
|
|
|
|
Uint16 pitches[3];
|
|
|
|
Uint8 *planes[3];
|
|
|
|
|
2008-11-25 02:21:53 +00:00
|
|
|
SDL_SW_YUVTexture *sw;
|
2008-11-24 23:25:36 +00:00
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Texture *texture;
|
2008-11-29 06:27:26 +00:00
|
|
|
Uint32 texture_format;
|
2006-07-10 21:04:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SDL_Overlay *
|
|
|
|
SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display)
|
|
|
|
{
|
|
|
|
SDL_Overlay *overlay;
|
|
|
|
Uint32 texture_format;
|
|
|
|
|
|
|
|
if ((display->flags & SDL_OPENGL) == SDL_OPENGL) {
|
|
|
|
SDL_SetError("YUV overlays are not supported in OpenGL mode");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (display != SDL_PublicSurface) {
|
|
|
|
SDL_SetError("YUV display is only supported on the screen surface");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case SDL_YV12_OVERLAY:
|
2006-08-05 17:09:42 +00:00
|
|
|
texture_format = SDL_PIXELFORMAT_YV12;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case SDL_IYUV_OVERLAY:
|
2006-08-05 17:09:42 +00:00
|
|
|
texture_format = SDL_PIXELFORMAT_IYUV;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case SDL_YUY2_OVERLAY:
|
2006-08-05 17:09:42 +00:00
|
|
|
texture_format = SDL_PIXELFORMAT_YUY2;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case SDL_UYVY_OVERLAY:
|
2006-08-05 17:09:42 +00:00
|
|
|
texture_format = SDL_PIXELFORMAT_UYVY;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case SDL_YVYU_OVERLAY:
|
2006-08-05 17:09:42 +00:00
|
|
|
texture_format = SDL_PIXELFORMAT_YVYU;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SDL_SetError("Unknown YUV format");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
overlay = (SDL_Overlay *) SDL_malloc(sizeof(*overlay));
|
|
|
|
if (!overlay) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
SDL_zerop(overlay);
|
|
|
|
|
|
|
|
overlay->hwdata =
|
|
|
|
(struct private_yuvhwdata *) SDL_malloc(sizeof(*overlay->hwdata));
|
|
|
|
if (!overlay->hwdata) {
|
|
|
|
SDL_free(overlay);
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
overlay->format = format;
|
|
|
|
overlay->w = w;
|
|
|
|
overlay->h = h;
|
|
|
|
if (format == SDL_YV12_OVERLAY || format == SDL_IYUV_OVERLAY) {
|
|
|
|
overlay->planes = 3;
|
|
|
|
} else {
|
|
|
|
overlay->planes = 1;
|
|
|
|
}
|
|
|
|
overlay->pitches = overlay->hwdata->pitches;
|
|
|
|
overlay->pixels = overlay->hwdata->planes;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case SDL_YV12_OVERLAY:
|
|
|
|
case SDL_IYUV_OVERLAY:
|
|
|
|
overlay->pitches[0] = overlay->w;
|
|
|
|
overlay->pitches[1] = overlay->w / 2;
|
|
|
|
overlay->pitches[2] = overlay->w / 2;
|
|
|
|
break;
|
|
|
|
case SDL_YUY2_OVERLAY:
|
|
|
|
case SDL_UYVY_OVERLAY:
|
|
|
|
case SDL_YVYU_OVERLAY:
|
|
|
|
overlay->pitches[0] = overlay->w * 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
overlay->hwdata->texture =
|
2007-08-11 20:54:31 +00:00
|
|
|
SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h);
|
2010-01-21 06:21:52 +00:00
|
|
|
if (overlay->hwdata->texture) {
|
2008-11-25 02:21:53 +00:00
|
|
|
overlay->hwdata->sw = NULL;
|
|
|
|
} else {
|
2008-11-28 17:42:40 +00:00
|
|
|
SDL_DisplayMode current_mode;
|
|
|
|
|
2008-11-25 02:21:53 +00:00
|
|
|
overlay->hwdata->sw = SDL_SW_CreateYUVTexture(texture_format, w, h);
|
|
|
|
if (!overlay->hwdata->sw) {
|
|
|
|
SDL_FreeYUVOverlay(overlay);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a supported RGB format texture for display */
|
2008-11-28 17:42:40 +00:00
|
|
|
SDL_GetCurrentDisplayMode(¤t_mode);
|
2008-11-29 06:27:26 +00:00
|
|
|
texture_format = current_mode.format;
|
2010-01-21 06:21:52 +00:00
|
|
|
overlay->hwdata->texture =
|
2008-11-29 06:27:26 +00:00
|
|
|
SDL_CreateTexture(texture_format,
|
2008-11-25 02:21:53 +00:00
|
|
|
SDL_TEXTUREACCESS_STREAMING, w, h);
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
if (!overlay->hwdata->texture) {
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_FreeYUVOverlay(overlay);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-29 06:27:26 +00:00
|
|
|
overlay->hwdata->texture_format = texture_format;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
return overlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_LockYUVOverlay(SDL_Overlay * overlay)
|
|
|
|
{
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
2007-07-15 21:54:16 +00:00
|
|
|
|
|
|
|
if (!overlay) {
|
|
|
|
SDL_SetError("Passed a NULL overlay");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-25 02:21:53 +00:00
|
|
|
if (overlay->hwdata->sw) {
|
|
|
|
if (SDL_SW_QueryYUVTexturePixels(overlay->hwdata->sw, &pixels, &pitch)
|
|
|
|
< 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (SDL_LockTexture
|
2010-01-21 06:21:52 +00:00
|
|
|
(overlay->hwdata->texture, NULL, 1, &pixels, &pitch)
|
2008-11-25 02:21:53 +00:00
|
|
|
< 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2007-08-11 21:51:19 +00:00
|
|
|
overlay->pixels[0] = (Uint8 *) pixels;
|
|
|
|
overlay->pitches[0] = pitch;
|
2006-07-10 21:04:37 +00:00
|
|
|
switch (overlay->format) {
|
|
|
|
case SDL_YV12_OVERLAY:
|
|
|
|
case SDL_IYUV_OVERLAY:
|
2007-08-11 21:51:19 +00:00
|
|
|
overlay->pitches[1] = pitch / 2;
|
|
|
|
overlay->pitches[2] = pitch / 2;
|
2006-07-10 21:04:37 +00:00
|
|
|
overlay->pixels[1] =
|
|
|
|
overlay->pixels[0] + overlay->pitches[0] * overlay->h;
|
|
|
|
overlay->pixels[2] =
|
2007-08-11 21:51:19 +00:00
|
|
|
overlay->pixels[1] + overlay->pitches[1] * overlay->h / 2;
|
2006-07-10 21:04:37 +00:00
|
|
|
break;
|
|
|
|
case SDL_YUY2_OVERLAY:
|
|
|
|
case SDL_UYVY_OVERLAY:
|
|
|
|
case SDL_YVYU_OVERLAY:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_UnlockYUVOverlay(SDL_Overlay * overlay)
|
|
|
|
{
|
2007-07-15 21:54:16 +00:00
|
|
|
if (!overlay) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-25 02:21:53 +00:00
|
|
|
if (overlay->hwdata->sw) {
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
|
|
|
if (SDL_LockTexture
|
2010-01-21 06:21:52 +00:00
|
|
|
(overlay->hwdata->texture, NULL, 1, &pixels, &pitch) == 0) {
|
2008-11-25 02:21:53 +00:00
|
|
|
SDL_Rect srcrect;
|
|
|
|
|
|
|
|
srcrect.x = 0;
|
|
|
|
srcrect.y = 0;
|
|
|
|
srcrect.w = overlay->w;
|
|
|
|
srcrect.h = overlay->h;
|
|
|
|
SDL_SW_CopyYUVToRGB(overlay->hwdata->sw, &srcrect,
|
2008-11-29 06:27:26 +00:00
|
|
|
overlay->hwdata->texture_format,
|
|
|
|
overlay->w, overlay->h, pixels, pitch);
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_UnlockTexture(overlay->hwdata->texture);
|
2008-11-25 02:21:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_UnlockTexture(overlay->hwdata->texture);
|
2008-11-25 02:21:53 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect)
|
|
|
|
{
|
2007-07-15 21:54:16 +00:00
|
|
|
if (!overlay || !dstrect) {
|
|
|
|
SDL_SetError("Passed a NULL overlay or dstrect");
|
|
|
|
return -1;
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
if (SDL_RenderCopy(overlay->hwdata->texture, NULL, dstrect) < 0) {
|
2006-07-10 21:04:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
SDL_RenderPresent();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_FreeYUVOverlay(SDL_Overlay * overlay)
|
|
|
|
{
|
2007-07-15 21:54:16 +00:00
|
|
|
if (!overlay) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (overlay->hwdata) {
|
2010-01-21 06:21:52 +00:00
|
|
|
if (overlay->hwdata->texture) {
|
|
|
|
SDL_DestroyTexture(overlay->hwdata->texture);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2007-07-15 21:54:16 +00:00
|
|
|
SDL_free(overlay->hwdata);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2007-07-15 21:54:16 +00:00
|
|
|
SDL_free(overlay);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 09:34:01 +00:00
|
|
|
void
|
|
|
|
SDL_GL_SwapBuffers(void)
|
|
|
|
{
|
|
|
|
SDL_GL_SwapWindow(SDL_VideoWindow);
|
|
|
|
}
|
|
|
|
|
2007-06-16 15:32:04 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
SDL_EnableKeyRepeat(int delay, int interval)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_GetKeyRepeat(int *delay, int *interval)
|
|
|
|
{
|
|
|
|
if (delay) {
|
|
|
|
*delay = SDL_DEFAULT_REPEAT_DELAY;
|
|
|
|
}
|
|
|
|
if (interval) {
|
|
|
|
*interval = SDL_DEFAULT_REPEAT_INTERVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-05 07:19:23 +00:00
|
|
|
int
|
|
|
|
SDL_EnableUNICODE(int enable)
|
|
|
|
{
|
2009-09-19 13:29:40 +00:00
|
|
|
int previous = SDL_enabled_UNICODE;
|
|
|
|
|
|
|
|
switch (enable) {
|
|
|
|
case 1:
|
|
|
|
SDL_enabled_UNICODE = 1;
|
|
|
|
SDL_StartTextInput();
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
SDL_enabled_UNICODE = 0;
|
|
|
|
SDL_StopTextInput();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return previous;
|
2008-02-05 07:19:23 +00:00
|
|
|
}
|
|
|
|
|
2009-12-16 10:59:51 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
SDL_putenv(const char *_var)
|
|
|
|
{
|
|
|
|
char *ptr = NULL;
|
|
|
|
char *var = SDL_strdup(_var);
|
|
|
|
if (var == NULL) {
|
|
|
|
return -1; /* we don't set errno. */
|
|
|
|
}
|
|
|
|
|
2009-12-17 07:47:03 +00:00
|
|
|
ptr = SDL_strchr(var, '=');
|
2009-12-16 10:59:51 +00:00
|
|
|
if (ptr == NULL) {
|
|
|
|
SDL_free(var);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr = '\0'; /* split the string into name and value. */
|
|
|
|
SDL_setenv(var, ptr + 1, 1);
|
|
|
|
SDL_free(var);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|