From 27d5fc9fd6aa20630d371a35bcee67883e76a37f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 22 Jan 2012 18:11:41 -0500 Subject: [PATCH] Removed the SDL 1.2 compatibility API... we'll see how painful this is. --- Makefile.in | 1 - include/SDL.h | 1 - include/SDL_compat.h | 365 -------- include/SDL_events.h | 44 - src/SDL_compat.c | 1816 --------------------------------------- src/video/SDL_surface.c | 15 - test/Makefile.in | 66 -- test/common.h | 1 - test/testalpha.c | 552 ------------ test/testbitmap.c | 203 ----- test/testblitspeed.c | 433 ---------- test/testcursor.c | 260 ------ test/testdyngl.c | 221 ----- test/testdyngles.c | 226 ----- test/testfill.c | 118 --- test/testgamma.c | 179 ---- test/testgl.c | 782 ----------------- test/testime.c | 10 + test/testjoystick.c | 10 + test/testnative.c | 2 +- test/testoverlay.c | 571 ------------ test/testoverlay2.c | 10 + test/testshader.c | 10 + test/testsprite.c | 339 -------- test/testtimer.c | 10 + test/testvidinfo.c | 546 ------------ test/testwin.c | 351 -------- test/testwm.c | 465 ---------- test/threadwin.c | 337 -------- 29 files changed, 51 insertions(+), 7893 deletions(-) delete mode 100644 include/SDL_compat.h delete mode 100755 src/SDL_compat.c delete mode 100644 test/testalpha.c delete mode 100644 test/testbitmap.c delete mode 100644 test/testblitspeed.c delete mode 100644 test/testcursor.c delete mode 100644 test/testdyngl.c delete mode 100644 test/testdyngles.c delete mode 100644 test/testfill.c delete mode 100644 test/testgamma.c delete mode 100644 test/testgl.c delete mode 100644 test/testoverlay.c delete mode 100644 test/testsprite.c delete mode 100644 test/testvidinfo.c delete mode 100644 test/testwin.c delete mode 100644 test/testwm.c delete mode 100644 test/threadwin.c diff --git a/Makefile.in b/Makefile.in index 9102cbc9d..183ffe9ef 100644 --- a/Makefile.in +++ b/Makefile.in @@ -46,7 +46,6 @@ HDRS = \ SDL_audio.h \ SDL_blendmode.h \ SDL_clipboard.h \ - SDL_compat.h \ SDL_cpuinfo.h \ SDL_endian.h \ SDL_error.h \ diff --git a/include/SDL.h b/include/SDL.h index 7fcfe1748..6b584b7bd 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -90,7 +90,6 @@ #include "SDL_timer.h" #include "SDL_version.h" #include "SDL_video.h" -#include "SDL_compat.h" #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ diff --git a/include/SDL_compat.h b/include/SDL_compat.h deleted file mode 100644 index 25c484bbb..000000000 --- a/include/SDL_compat.h +++ /dev/null @@ -1,365 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - - /** - * \defgroup Compatibility SDL 1.2 Compatibility API - */ -/*@{*/ - -/** - * \file SDL_compat.h - * - * This file contains functions for backwards compatibility with SDL 1.2. - */ - -/** - * \def SDL_NO_COMPAT - * - * #define SDL_NO_COMPAT to prevent SDL_compat.h from being included. - * SDL_NO_COMPAT is intended to make it easier to covert SDL 1.2 code to - * SDL 1.3/2.0. - */ - - /*@}*/ - -#ifdef SDL_NO_COMPAT -#define _SDL_compat_h -#endif - -#ifndef _SDL_compat_h -#define _SDL_compat_h - -#include "SDL_video.h" -#include "SDL_version.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -/* *INDENT-OFF* */ -extern "C" { -/* *INDENT-ON* */ -#endif - -/** - * \addtogroup Compatibility - */ -/*@{*/ - -/* Platform */ -#ifdef __WIN32__ -#undef __WIN32__ -#define __WIN32__ 1 -#endif - -/** - * \name Surface flags - */ -/*@{*/ -#define SDL_SWSURFACE 0x00000000 /**< \note Not used */ -#define SDL_SRCALPHA 0x00010000 -#define SDL_SRCCOLORKEY 0x00020000 -#define SDL_ANYFORMAT 0x00100000 -#define SDL_HWPALETTE 0x00200000 -#define SDL_DOUBLEBUF 0x00400000 -#define SDL_FULLSCREEN 0x00800000 -#define SDL_RESIZABLE 0x01000000 -#define SDL_NOFRAME 0x02000000 -#define SDL_OPENGL 0x04000000 -#define SDL_HWSURFACE 0x08000001 /**< \note Not used */ -#define SDL_ASYNCBLIT 0x08000000 /**< \note Not used */ -#define SDL_RLEACCELOK 0x08000000 /**< \note Not used */ -#define SDL_HWACCEL 0x08000000 /**< \note Not used */ -/*@}*//*Surface flags*/ - -#define SDL_APPMOUSEFOCUS 0x01 -#define SDL_APPINPUTFOCUS 0x02 -#define SDL_APPACTIVE 0x04 - -#define SDL_LOGPAL 0x01 -#define SDL_PHYSPAL 0x02 - -#define SDL_ACTIVEEVENT SDL_EVENT_COMPAT1 -#define SDL_VIDEORESIZE SDL_EVENT_COMPAT2 -#define SDL_VIDEOEXPOSE SDL_EVENT_COMPAT3 -#define SDL_ACTIVEEVENTMASK SDL_ACTIVEEVENT, SDL_ACTIVEEVENT -#define SDL_VIDEORESIZEMASK SDL_VIDEORESIZE, SDL_VIDEORESIZE -#define SDL_VIDEOEXPOSEMASK SDL_VIDEOEXPOSE, SDL_VIDEOEXPOSE -#define SDL_WINDOWEVENTMASK SDL_WINDOWEVENT, SDL_WINDOWEVENT -#define SDL_KEYDOWNMASK SDL_KEYDOWN, SDL_KEYDOWN -#define SDL_KEYUPMASK SDL_KEYUP, SDL_KEYUP -#define SDL_KEYEVENTMASK SDL_KEYDOWN, SDL_KEYUP -#define SDL_TEXTEDITINGMASK SDL_TEXTEDITING, SDL_TEXTEDITING -#define SDL_TEXTINPUTMASK SDL_TEXTINPUT, SDL_TEXTINPUT -#define SDL_MOUSEMOTIONMASK SDL_MOUSEMOTION, SDL_MOUSEMOTION -#define SDL_MOUSEBUTTONDOWNMASK SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN -#define SDL_MOUSEBUTTONUPMASK SDL_MOUSEBUTTONUP, SDL_MOUSEBUTTONUP -#define SDL_MOUSEWHEELMASK SDL_MOUSEWHEEL, SDL_MOUSEWHEEL -#define SDL_MOUSEEVENTMASK SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP -#define SDL_JOYAXISMOTIONMASK SDL_JOYAXISMOTION, SDL_JOYAXISMOTION -#define SDL_JOYBALLMOTIONMASK SDL_JOYBALLMOTION, SDL_JOYBALLMOTION -#define SDL_JOYHATMOTIONMASK SDL_JOYHATMOTION, SDL_JOYHATMOTION -#define SDL_JOYBUTTONDOWNMASK SDL_JOYBUTTONDOWN, SDL_JOYBUTTONDOWN -#define SDL_JOYBUTTONUPMASK SDL_JOYBUTTONUP, SDL_JOYBUTTONUP -#define SDL_JOYEVENTMASK SDL_JOYAXISMOTION, SDL_JOYBUTTONUP -#define SDL_QUITMASK SDL_QUIT, SDL_QUIT -#define SDL_SYSWMEVENTMASK SDL_SYSWMEVENT, SDL_SYSWMEVENT -#define SDL_PROXIMITYINMASK SDL_PROXIMITYIN, SDL_PROXIMITYIN -#define SDL_PROXIMITYOUTMASK SDL_PROXIMITYOUT, SDL_PROXIMITYOUT -#define SDL_ALLEVENTS SDL_FIRSTEVENT, SDL_LASTEVENT - -#define SDL_BUTTON_WHEELUP 4 -#define SDL_BUTTON_WHEELDOWN 5 - -#define SDL_DEFAULT_REPEAT_DELAY 500 -#define SDL_DEFAULT_REPEAT_INTERVAL 30 - -typedef struct SDL_VideoInfo -{ - Uint32 hw_available:1; - Uint32 wm_available:1; - Uint32 UnusedBits1:6; - Uint32 UnusedBits2:1; - Uint32 blit_hw:1; - Uint32 blit_hw_CC:1; - Uint32 blit_hw_A:1; - Uint32 blit_sw:1; - Uint32 blit_sw_CC:1; - Uint32 blit_sw_A:1; - Uint32 blit_fill:1; - Uint32 UnusedBits3:16; - Uint32 video_mem; - - SDL_PixelFormat *vfmt; - - int current_w; - int current_h; -} SDL_VideoInfo; - -/** - * \name Overlay formats - * - * The most common video overlay formats. - * - * For an explanation of these pixel formats, see: - * http://www.webartz.com/fourcc/indexyuv.htm - * - * For information on the relationship between color spaces, see: - * http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html - */ -/*@{*/ -#define SDL_YV12_OVERLAY 0x32315659 /**< Planar mode: Y + V + U (3 planes) */ -#define SDL_IYUV_OVERLAY 0x56555949 /**< Planar mode: Y + U + V (3 planes) */ -#define SDL_YUY2_OVERLAY 0x32595559 /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */ -#define SDL_UYVY_OVERLAY 0x59565955 /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */ -#define SDL_YVYU_OVERLAY 0x55595659 /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */ -/*@}*//*Overlay formats*/ - -/** - * The YUV hardware video overlay. - */ -typedef struct SDL_Overlay -{ - Uint32 format; /**< Read-only */ - int w, h; /**< Read-only */ - int planes; /**< Read-only */ - Uint16 *pitches; /**< Read-only */ - Uint8 **pixels; /**< Read-write */ - - /** - * \name Hardware-specific surface info - */ - /*@{*/ - struct private_yuvhwfuncs *hwfuncs; - struct private_yuvhwdata *hwdata; - /*@}*//*Hardware-specific surface info*/ - - /** - * \name Special flags - */ - /*@{*/ - Uint32 hw_overlay:1; /**< Flag: This overlay hardware accelerated? */ - Uint32 UnusedBits:31; - /*@}*//*Special flags*/ -} SDL_Overlay; - -typedef enum -{ - SDL_GRAB_QUERY = -1, - SDL_GRAB_OFF = 0, - SDL_GRAB_ON = 1 -} SDL_GrabMode; - -struct SDL_SysWMinfo; - -/** - * \name Obsolete or renamed key codes - */ -/*@{*/ - -#define SDL_keysym SDL_Keysym -#define SDL_KeySym SDL_Keysym -#define SDL_scancode SDL_Scancode -#define SDL_ScanCode SDL_Scancode -#define SDLKey SDL_Keycode -#define SDLMod SDL_Keymod - -/** - * \name Renamed keys - * - * These key constants were renamed for clarity or consistency. - */ -/*@{*/ -#define SDLK_KP0 SDLK_KP_0 -#define SDLK_KP1 SDLK_KP_1 -#define SDLK_KP2 SDLK_KP_2 -#define SDLK_KP3 SDLK_KP_3 -#define SDLK_KP4 SDLK_KP_4 -#define SDLK_KP5 SDLK_KP_5 -#define SDLK_KP6 SDLK_KP_6 -#define SDLK_KP7 SDLK_KP_7 -#define SDLK_KP8 SDLK_KP_8 -#define SDLK_KP9 SDLK_KP_9 -#define SDLK_NUMLOCK SDLK_NUMLOCKCLEAR -#define SDLK_SCROLLOCK SDLK_SCROLLLOCK -#define SDLK_PRINT SDLK_PRINTSCREEN -#define SDLK_LMETA SDLK_LGUI -#define SDLK_RMETA SDLK_RGUI -/*@}*//*Renamed keys*/ - -/** - * \name META modifier - * - * The META modifier is equivalent to the GUI modifier from the USB standard. - */ -/*@{*/ -#define KMOD_LMETA KMOD_LGUI -#define KMOD_RMETA KMOD_RGUI -#define KMOD_META KMOD_GUI -/*@}*//*META modifier*/ - -/** - * \name Not in USB - * - * These keys don't appear in the USB specification (or at least not under - * those names). I'm unsure if the following assignments make sense or if these - * codes should be defined as actual additional SDLK_ constants. - */ -/*@{*/ -#define SDLK_LSUPER SDLK_LMETA -#define SDLK_RSUPER SDLK_RMETA -#define SDLK_COMPOSE SDLK_APPLICATION -#define SDLK_BREAK SDLK_STOP -#define SDLK_EURO SDLK_2 -/*@}*//*Not in USB*/ - -/*@}*//*Obsolete or renamed key codes*/ - -#define SDL_SetModuleHandle(x) -#define SDL_AllocSurface SDL_CreateRGBSurface - -extern DECLSPEC const SDL_version *SDLCALL SDL_Linked_Version(void); -extern DECLSPEC const char *SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen); -extern DECLSPEC const char *SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen); -extern DECLSPEC const SDL_VideoInfo *SDLCALL SDL_GetVideoInfo(void); -extern DECLSPEC int SDLCALL SDL_VideoModeOK(int width, - int height, - int bpp, Uint32 flags); -extern DECLSPEC SDL_Rect **SDLCALL SDL_ListModes(const SDL_PixelFormat * - format, Uint32 flags); -extern DECLSPEC SDL_Surface *SDLCALL SDL_SetVideoMode(int width, int height, - int bpp, Uint32 flags); -extern DECLSPEC SDL_Surface *SDLCALL SDL_GetVideoSurface(void); -extern DECLSPEC void SDLCALL SDL_UpdateRects(SDL_Surface * screen, - int numrects, SDL_Rect * rects); -extern DECLSPEC void SDLCALL SDL_UpdateRect(SDL_Surface * screen, - Sint32 x, - Sint32 y, Uint32 w, Uint32 h); -extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface * screen); -extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface * surface, - Uint32 flag, Uint8 alpha); -extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormat(SDL_Surface * surface); -extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormatAlpha(SDL_Surface * - surface); -extern DECLSPEC void SDLCALL SDL_WM_SetCaption(const char *title, - const char *icon); -extern DECLSPEC void SDLCALL SDL_WM_GetCaption(const char **title, - const char **icon); -extern DECLSPEC void SDLCALL SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask); -extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void); -extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface * surface); -extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode); -extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface, - int flags, - const SDL_Color * colors, - int firstcolor, int ncolors); -extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface * surface, - const SDL_Color * colors, - int firstcolor, int ncolors); -extern DECLSPEC int SDLCALL SDL_GetWMInfo(struct SDL_SysWMinfo *info); -extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void); -extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y); -extern DECLSPEC SDL_Overlay *SDLCALL SDL_CreateYUVOverlay(int width, - int height, - Uint32 format, - SDL_Surface * - display); -extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay * overlay); -extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay * overlay); -extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay, - SDL_Rect * dstrect); -extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay); -extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void); -extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue); -extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 * red, - const Uint16 * green, - const Uint16 * blue); -extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 * red, Uint16 * green, - Uint16 * blue); -extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); -extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); -extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); - -typedef SDL_Window* SDL_WindowID; - -#define SDL_KillThread(X) - -/* The timeslice and timer resolution are no longer relevant */ -#define SDL_TIMESLICE 10 -#define TIMER_RESOLUTION 10 - -typedef Uint32 (SDLCALL * SDL_OldTimerCallback) (Uint32 interval); -extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_OldTimerCallback callback); - -extern DECLSPEC int SDLCALL SDL_putenv(const char *variable); - -/*@}*//*Compatibility*/ - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -/* *INDENT-OFF* */ -} -/* *INDENT-ON* */ -#endif -#include "close_code.h" - -#endif /* _SDL_compat_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_events.h b/include/SDL_events.h index bbf678adb..39648af4d 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -109,12 +109,6 @@ typedef enum /* Drag and drop events */ SDL_DROPFILE = 0x1000, /**< The system requests a file open */ - /* Obsolete events */ - SDL_EVENT_COMPAT1 = 0x7000, /**< SDL 1.2 events for compatibility */ - SDL_EVENT_COMPAT2, - SDL_EVENT_COMPAT3, - - /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use, * and should be allocated with SDL_RegisterEvents() */ @@ -419,36 +413,6 @@ typedef struct SDL_SysWMEvent SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */ } SDL_SysWMEvent; -#ifndef SDL_NO_COMPAT -/** - * \addtogroup Compatibility - */ -/*@{*/ - -/** - * \name Typedefs for backwards compatibility - */ -/*@{*/ -typedef struct SDL_ActiveEvent -{ - Uint32 type; - Uint32 timestamp; - Uint8 gain; - Uint8 state; -} SDL_ActiveEvent; - -typedef struct SDL_ResizeEvent -{ - Uint32 type; - Uint32 timestamp; - int w; - int h; -} SDL_ResizeEvent; -/*@}*/ - -/*@}*//*Compatibility*/ -#endif - /** * \brief General event structure */ @@ -474,14 +438,6 @@ typedef union SDL_Event SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */ SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */ SDL_DropEvent drop; /**< Drag and drop event data */ - - /** Temporarily here for backwards compatibility */ - /*@{*/ -#ifndef SDL_NO_COMPAT - SDL_ActiveEvent active; - SDL_ResizeEvent resize; -#endif - /*@}*/ } SDL_Event; diff --git a/src/SDL_compat.c b/src/SDL_compat.c deleted file mode 100755 index 0b8676208..000000000 --- a/src/SDL_compat.c +++ /dev/null @@ -1,1816 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#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" -#include "render/SDL_yuv_sw_c.h" - - -static SDL_Window *SDL_VideoWindow = NULL; -static SDL_Surface *SDL_WindowSurface = NULL; -static SDL_Surface *SDL_VideoSurface = NULL; -static SDL_Surface *SDL_ShadowSurface = NULL; -static SDL_Surface *SDL_PublicSurface = NULL; -static SDL_GLContext *SDL_VideoContext = NULL; -static Uint32 SDL_VideoFlags = 0; -static SDL_Rect SDL_VideoViewport; -static char *wm_title = NULL; -static SDL_Surface *SDL_VideoIcon; -static int SDL_enabled_UNICODE = 0; - -const char * -SDL_AudioDriverName(char *namebuf, int maxlen) -{ - const char *name = SDL_GetCurrentAudioDriver(); - if (name) { - if (namebuf) { - SDL_strlcpy(namebuf, name, maxlen); - return namebuf; - } else { - return name; - } - } - return NULL; -} - -const char * -SDL_VideoDriverName(char *namebuf, int maxlen) -{ - const char *name = SDL_GetCurrentVideoDriver(); - if (name) { - if (namebuf) { - SDL_strlcpy(namebuf, name, maxlen); - return namebuf; - } else { - return name; - } - } - return NULL; -} - -static int -GetVideoDisplay() -{ - const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY"); - if ( !variable ) { - variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD"); - } - if ( variable ) { - return SDL_atoi(variable); - } else { - return 0; - } -} - -const SDL_VideoInfo * -SDL_GetVideoInfo(void) -{ - static SDL_VideoInfo info; - SDL_DisplayMode mode; - - /* Memory leak, compatibility code, who cares? */ - if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) { - info.vfmt = SDL_AllocFormat(mode.format); - info.current_w = mode.w; - info.current_h = mode.h; - } - return &info; -} - -int -SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags) -{ - int i, actual_bpp = 0; - - if (!SDL_GetVideoDevice()) { - return 0; - } - - if (!(flags & SDL_FULLSCREEN)) { - SDL_DisplayMode mode; - SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode); - return SDL_BITSPERPIXEL(mode.format); - } - - for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) { - SDL_DisplayMode mode; - SDL_GetDisplayMode(GetVideoDisplay(), i, &mode); - if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) { - if (!mode.format) { - return bpp; - } - if (SDL_BITSPERPIXEL(mode.format) >= (Uint32) bpp) { - actual_bpp = SDL_BITSPERPIXEL(mode.format); - } - } - } - return actual_bpp; -} - -SDL_Rect ** -SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags) -{ - int i, nmodes; - SDL_Rect **modes; - - if (!SDL_GetVideoDevice()) { - return NULL; - } - - if (!(flags & SDL_FULLSCREEN)) { - return (SDL_Rect **) (-1); - } - - if (!format) { - format = SDL_GetVideoInfo()->vfmt; - } - - /* Memory leak, but this is a compatibility function, who cares? */ - nmodes = 0; - modes = NULL; - for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) { - SDL_DisplayMode mode; - int bpp; - - SDL_GetDisplayMode(GetVideoDisplay(), i, &mode); - if (!mode.w || !mode.h) { - return (SDL_Rect **) (-1); - } - - /* Copied from src/video/SDL_pixels.c:SDL_PixelFormatEnumToMasks */ - if (SDL_BYTESPERPIXEL(mode.format) <= 2) { - bpp = SDL_BITSPERPIXEL(mode.format); - } else { - bpp = SDL_BYTESPERPIXEL(mode.format) * 8; - } - - if (bpp != format->BitsPerPixel) { - continue; - } - if (nmodes > 0 && modes[nmodes - 1]->w == mode.w - && modes[nmodes - 1]->h == mode.h) { - 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; - modes[nmodes]->w = mode.w; - modes[nmodes]->h = mode.h; - ++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_VIDEOEXPOSE)) { - fake.type = SDL_VIDEOEXPOSE; - SDL_PushEvent(&fake); - } - break; - case SDL_WINDOWEVENT_RESIZED: - SDL_FlushEvent(SDL_VIDEORESIZE); - /* We don't want to expose that the window width and height will - be different if we don't get the desired fullscreen mode. - */ - if (SDL_VideoWindow && !(SDL_GetWindowFlags(SDL_VideoWindow) & SDL_WINDOW_FULLSCREEN)) { - 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; - fake.active.gain = 0; - 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; - } - case SDL_TEXTINPUT: - { - /* FIXME: Generate an old style key repeat event if needed */ - //printf("TEXTINPUT: '%s'\n", event->text.text); - break; - } - case SDL_MOUSEMOTION: - { - event->motion.x -= SDL_VideoViewport.x; - event->motion.y -= SDL_VideoViewport.y; - break; - } - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - { - event->button.x -= SDL_VideoViewport.x; - event->button.y -= SDL_VideoViewport.y; - break; - } - case SDL_MOUSEWHEEL: - { - Uint8 button; - int x, y; - - if (event->wheel.y == 0) { - break; - } - - SDL_GetMouseState(&x, &y); - - if (event->wheel.y > 0) { - button = SDL_BUTTON_WHEELUP; - } else { - button = SDL_BUTTON_WHEELDOWN; - } - - fake.button.button = button; - fake.button.x = x; - fake.button.y = y; - fake.button.windowID = event->wheel.windowID; - - fake.type = SDL_MOUSEBUTTONDOWN; - fake.button.state = SDL_PRESSED; - SDL_PushEvent(&fake); - - fake.type = SDL_MOUSEBUTTONUP; - fake.button.state = SDL_RELEASED; - SDL_PushEvent(&fake); - break; - } - - } - return 1; -} - -static void -GetEnvironmentWindowPosition(int w, int h, int *x, int *y) -{ - int display = GetVideoDisplay(); - 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) { - *x = SDL_WINDOWPOS_CENTERED_DISPLAY(display); - *y = SDL_WINDOWPOS_CENTERED_DISPLAY(display); - } -} - -static void -ClearVideoSurface() -{ - if (SDL_ShadowSurface) { - SDL_FillRect(SDL_ShadowSurface, NULL, - SDL_MapRGB(SDL_ShadowSurface->format, 0, 0, 0)); - } - SDL_FillRect(SDL_WindowSurface, NULL, 0); - SDL_UpdateWindowSurface(SDL_VideoWindow); -} - -static void -SetupScreenSaver(int flags) -{ - const char *env; - SDL_bool allow_screensaver; - - /* 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; - } - if (allow_screensaver) { - SDL_EnableScreenSaver(); - } else { - SDL_DisableScreenSaver(); - } -} - -static int -SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags) -{ - int w, h; - - /* We can't resize something we don't have... */ - if (!SDL_VideoSurface) { - 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; - } - if (bpp != SDL_VideoSurface->format->BitsPerPixel) { - 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; - } - - SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow); - if (!SDL_WindowSurface) { - return -1; - } - if (SDL_VideoSurface->format != SDL_WindowSurface->format) { - return -1; - } - SDL_VideoSurface->w = width; - SDL_VideoSurface->h = height; - SDL_VideoSurface->pixels = SDL_WindowSurface->pixels; - SDL_VideoSurface->pitch = SDL_WindowSurface->pitch; - SDL_SetClipRect(SDL_VideoSurface, NULL); - - if (SDL_ShadowSurface) { - SDL_ShadowSurface->w = width; - SDL_ShadowSurface->h = height; - SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface); - SDL_ShadowSurface->pixels = - SDL_realloc(SDL_ShadowSurface->pixels, - SDL_ShadowSurface->h * SDL_ShadowSurface->pitch); - SDL_SetClipRect(SDL_ShadowSurface, NULL); - SDL_InvalidateMap(SDL_ShadowSurface->map); - } else { - SDL_PublicSurface = SDL_VideoSurface; - } - - ClearVideoSurface(); - - return 0; -} - -SDL_Surface * -SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) -{ - SDL_DisplayMode desktop_mode; - int display = GetVideoDisplay(); - int window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display); - int window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display); - int window_w; - int window_h; - Uint32 window_flags; - Uint32 surface_flags; - - if (!SDL_GetVideoDevice()) { - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { - return NULL; - } - } - - SDL_GetDesktopDisplayMode(display, &desktop_mode); - - if (width == 0) { - width = desktop_mode.w; - } - if (height == 0) { - height = desktop_mode.h; - } - if (bpp == 0) { - bpp = SDL_BITSPERPIXEL(desktop_mode.format); - } - - /* See if we can simply resize the existing window and surface */ - if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) { - return SDL_PublicSurface; - } - - /* Destroy existing window */ - SDL_PublicSurface = NULL; - if (SDL_ShadowSurface) { - SDL_ShadowSurface->flags &= ~SDL_DONTFREE; - SDL_FreeSurface(SDL_ShadowSurface); - SDL_ShadowSurface = NULL; - } - if (SDL_VideoSurface) { - SDL_VideoSurface->flags &= ~SDL_DONTFREE; - SDL_FreeSurface(SDL_VideoSurface); - SDL_VideoSurface = NULL; - } - if (SDL_VideoContext) { - /* SDL_GL_MakeCurrent(0, NULL); *//* Doesn't do anything */ - SDL_GL_DeleteContext(SDL_VideoContext); - SDL_VideoContext = NULL; - } - if (SDL_VideoWindow) { - SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y); - SDL_DestroyWindow(SDL_VideoWindow); - } - - /* 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; - } - SDL_SetWindowIcon(SDL_VideoWindow, SDL_VideoIcon); - - SetupScreenSaver(flags); - - 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) && (flags & SDL_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; - } - - SDL_VideoFlags = flags; - - /* If we're in OpenGL mode, just create a stub surface and we're done! */ - if (flags & SDL_OPENGL) { - SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow); - if (!SDL_VideoContext) { - return NULL; - } - if (SDL_GL_MakeCurrent(SDL_VideoWindow, SDL_VideoContext) < 0) { - return NULL; - } - 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 the screen surface */ - SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow); - if (!SDL_WindowSurface) { - return NULL; - } - - /* Center the public surface in the window surface */ - SDL_GetWindowSize(SDL_VideoWindow, &window_w, &window_h); - SDL_VideoViewport.x = (window_w - width)/2; - SDL_VideoViewport.y = (window_h - height)/2; - SDL_VideoViewport.w = width; - SDL_VideoViewport.h = height; - - SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0); - SDL_VideoSurface->flags |= surface_flags; - SDL_VideoSurface->flags |= SDL_DONTFREE; - SDL_FreeFormat(SDL_VideoSurface->format); - SDL_VideoSurface->format = SDL_WindowSurface->format; - SDL_VideoSurface->format->refcount++; - SDL_VideoSurface->w = width; - SDL_VideoSurface->h = height; - SDL_VideoSurface->pitch = SDL_WindowSurface->pitch; - SDL_VideoSurface->pixels = (void *)((Uint8 *)SDL_WindowSurface->pixels + - SDL_VideoViewport.y * SDL_VideoSurface->pitch + - SDL_VideoViewport.x * SDL_VideoSurface->format->BytesPerPixel); - SDL_SetClipRect(SDL_VideoSurface, NULL); - - /* Create a shadow surface if necessary */ - if ((bpp != SDL_VideoSurface->format->BitsPerPixel) - && !(flags & SDL_ANYFORMAT)) { - SDL_ShadowSurface = - SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0); - if (!SDL_ShadowSurface) { - return NULL; - } - SDL_ShadowSurface->flags |= surface_flags; - SDL_ShadowSurface->flags |= SDL_DONTFREE; - - /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */ - if (SDL_ShadowSurface->format->palette) { - SDL_ShadowSurface->flags |= SDL_HWPALETTE; - SDL_DitherColors(SDL_ShadowSurface->format->palette->colors, - SDL_ShadowSurface->format->BitsPerPixel); - } - SDL_FillRect(SDL_ShadowSurface, NULL, - SDL_MapRGB(SDL_ShadowSurface->format, 0, 0, 0)); - } - SDL_PublicSurface = - (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface); - - ClearVideoSurface(); - - /* We're finally done! */ - return SDL_PublicSurface; -} - -SDL_Surface * -SDL_GetVideoSurface(void) -{ - return SDL_PublicSurface; -} - -int -SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value) -{ - if (flag & SDL_SRCALPHA) { - /* According to the docs, value is ignored for alpha surfaces */ - if (surface->format->Amask) { - value = 0xFF; - } - SDL_SetSurfaceAlphaMod(surface, value); - SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); - } else { - SDL_SetSurfaceAlphaMod(surface, 0xFF); - SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE); - } - SDL_SetSurfaceRLE(surface, (flag & SDL_RLEACCEL)); - - return 0; -} - -SDL_Surface * -SDL_DisplayFormat(SDL_Surface * surface) -{ - SDL_PixelFormat *format; - - if (!SDL_PublicSurface) { - SDL_SetError("No video mode has been set"); - return NULL; - } - format = SDL_PublicSurface->format; - - /* Set the flags appropriate for copying to display surface */ - return SDL_ConvertSurface(surface, format, SDL_RLEACCEL); -} - -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(SDL_MasksToPixelFormatEnum(32, rmask, - gmask, - bmask, - amask)); - if (!format) { - return NULL; - } - converted = SDL_ConvertSurface(surface, format, SDL_RLEACCEL); - 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 */ - rect.x = (int) x; - rect.y = (int) y; - rect.w = (int) (w ? w : screen->w); - rect.h = (int) (h ? h : screen->h); - SDL_UpdateRects(screen, 1, &rect); - } -} - -void -SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects) -{ - int i; - - if (screen == SDL_ShadowSurface) { - for (i = 0; i < numrects; ++i) { - SDL_BlitSurface(SDL_ShadowSurface, &rects[i], SDL_VideoSurface, - &rects[i]); - } - - /* Fall through to video surface update */ - screen = SDL_VideoSurface; - } - if (screen == SDL_VideoSurface) { - if (SDL_VideoViewport.x || SDL_VideoViewport.y) { - SDL_Rect *stackrects = SDL_stack_alloc(SDL_Rect, numrects); - SDL_Rect *stackrect; - const SDL_Rect *rect; - - /* Offset all the rectangles before updating */ - for (i = 0; i < numrects; ++i) { - rect = &rects[i]; - stackrect = &stackrects[i]; - stackrect->x = SDL_VideoViewport.x + rect->x; - stackrect->y = SDL_VideoViewport.y + rect->y; - stackrect->w = rect->w; - stackrect->h = rect->h; - } - SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, stackrects, numrects); - SDL_stack_free(stackrects); - } else { - SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, rects, numrects); - } - } -} - -void -SDL_WM_SetCaption(const char *title, const char *icon) -{ - if (wm_title) { - SDL_free(wm_title); - } - if (title) { - wm_title = SDL_strdup(title); - } else { - wm_title = NULL; - } - SDL_SetWindowTitle(SDL_VideoWindow, wm_title); -} - -void -SDL_WM_GetCaption(const char **title, const char **icon) -{ - if (title) { - *title = wm_title; - } - if (icon) { - *icon = ""; - } -} - -void -SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) -{ - SDL_VideoIcon = icon; - ++SDL_VideoIcon->refcount; -} - -int -SDL_WM_IconifyWindow(void) -{ - SDL_MinimizeWindow(SDL_VideoWindow); - return 0; -} - -int -SDL_WM_ToggleFullScreen(SDL_Surface * surface) -{ - int length; - void *pixels; - Uint8 *src, *dst; - int row; - int window_w; - int window_h; - - if (!SDL_PublicSurface) { - SDL_SetError("SDL_SetVideoMode() hasn't been called"); - return 0; - } - - /* Copy the old bits out */ - length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel; - pixels = SDL_malloc(SDL_PublicSurface->h * length); - if (pixels && SDL_PublicSurface->pixels) { - src = (Uint8*)SDL_PublicSurface->pixels; - dst = (Uint8*)pixels; - for (row = 0; row < SDL_PublicSurface->h; ++row) { - SDL_memcpy(dst, src, length); - src += SDL_PublicSurface->pitch; - dst += length; - } - } - - /* Do the physical mode switch */ - 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; - } - - /* Recreate the screen surface */ - SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow); - if (!SDL_WindowSurface) { - /* We're totally hosed... */ - return 0; - } - - /* Center the public surface in the window surface */ - SDL_GetWindowSize(SDL_VideoWindow, &window_w, &window_h); - SDL_VideoViewport.x = (window_w - SDL_VideoSurface->w)/2; - SDL_VideoViewport.y = (window_h - SDL_VideoSurface->h)/2; - SDL_VideoViewport.w = SDL_VideoSurface->w; - SDL_VideoViewport.h = SDL_VideoSurface->h; - - /* Do some shuffling behind the application's back if format changes */ - if (SDL_VideoSurface->format->format != SDL_WindowSurface->format->format) { - if (SDL_ShadowSurface) { - if (SDL_ShadowSurface->format->format == SDL_WindowSurface->format->format) { - /* Whee! We don't need a shadow surface anymore! */ - SDL_VideoSurface->flags &= ~SDL_DONTFREE; - SDL_FreeSurface(SDL_VideoSurface); - SDL_free(SDL_ShadowSurface->pixels); - SDL_VideoSurface = SDL_ShadowSurface; - SDL_VideoSurface->flags |= SDL_PREALLOC; - SDL_ShadowSurface = NULL; - } else { - /* No problem, just change the video surface format */ - SDL_FreeFormat(SDL_VideoSurface->format); - SDL_VideoSurface->format = SDL_WindowSurface->format; - SDL_VideoSurface->format->refcount++; - SDL_InvalidateMap(SDL_ShadowSurface->map); - } - } else { - /* We can make the video surface the shadow surface */ - SDL_ShadowSurface = SDL_VideoSurface; - SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface); - SDL_ShadowSurface->pixels = SDL_malloc(SDL_ShadowSurface->h * SDL_ShadowSurface->pitch); - if (!SDL_ShadowSurface->pixels) { - /* Uh oh, we're hosed */ - SDL_ShadowSurface = NULL; - return 0; - } - SDL_ShadowSurface->flags &= ~SDL_PREALLOC; - - SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0); - SDL_VideoSurface->flags = SDL_ShadowSurface->flags; - SDL_VideoSurface->flags |= SDL_PREALLOC; - SDL_FreeFormat(SDL_VideoSurface->format); - SDL_VideoSurface->format = SDL_WindowSurface->format; - SDL_VideoSurface->format->refcount++; - SDL_VideoSurface->w = SDL_ShadowSurface->w; - SDL_VideoSurface->h = SDL_ShadowSurface->h; - } - } - - /* Update the video surface */ - SDL_VideoSurface->pitch = SDL_WindowSurface->pitch; - SDL_VideoSurface->pixels = (void *)((Uint8 *)SDL_WindowSurface->pixels + - SDL_VideoViewport.y * SDL_VideoSurface->pitch + - SDL_VideoViewport.x * SDL_VideoSurface->format->BytesPerPixel); - SDL_SetClipRect(SDL_VideoSurface, NULL); - - /* Copy the old bits back */ - if (pixels) { - src = (Uint8*)pixels; - dst = (Uint8*)SDL_PublicSurface->pixels; - for (row = 0; row < SDL_PublicSurface->h; ++row) { - SDL_memcpy(dst, src, length); - src += length; - dst += SDL_PublicSurface->pitch; - } - SDL_Flip(SDL_PublicSurface); - SDL_free(pixels); - } - - /* We're done! */ - 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); - } - if (screen->flags & SDL_SCREEN_SURFACE) { - 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); - } - if (screen->flags & SDL_SCREEN_SURFACE) { - 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 -{ - SDL_SW_YUVTexture *texture; - SDL_Surface *display; - Uint32 display_format; -}; - -SDL_Overlay * -SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display) -{ - SDL_Overlay *overlay; - Uint32 texture_format; - SDL_SW_YUVTexture *texture; - - 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: - texture_format = SDL_PIXELFORMAT_YV12; - break; - case SDL_IYUV_OVERLAY: - texture_format = SDL_PIXELFORMAT_IYUV; - break; - case SDL_YUY2_OVERLAY: - texture_format = SDL_PIXELFORMAT_YUY2; - break; - case SDL_UYVY_OVERLAY: - texture_format = SDL_PIXELFORMAT_UYVY; - break; - case SDL_YVYU_OVERLAY: - texture_format = SDL_PIXELFORMAT_YVYU; - 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; - } - - texture = SDL_SW_CreateYUVTexture(texture_format, w, h); - if (!texture) { - SDL_free(overlay->hwdata); - SDL_free(overlay); - return NULL; - } - overlay->hwdata->texture = texture; - overlay->hwdata->display = NULL; - overlay->hwdata->display_format = SDL_PIXELFORMAT_UNKNOWN; - - 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 = texture->pitches; - overlay->pixels = texture->planes; - - return overlay; -} - -int -SDL_LockYUVOverlay(SDL_Overlay * overlay) -{ - SDL_Rect rect; - void *pixels; - int pitch; - - if (!overlay) { - SDL_SetError("Passed a NULL overlay"); - return -1; - } - - rect.x = 0; - rect.y = 0; - rect.w = overlay->w; - rect.h = overlay->h; - - if (SDL_SW_LockYUVTexture(overlay->hwdata->texture, &rect, &pixels, &pitch) < 0) { - return -1; - } - - overlay->pixels[0] = (Uint8 *) pixels; - overlay->pitches[0] = pitch; - switch (overlay->format) { - case SDL_YV12_OVERLAY: - case SDL_IYUV_OVERLAY: - overlay->pitches[1] = pitch / 2; - overlay->pitches[2] = pitch / 2; - overlay->pixels[1] = - overlay->pixels[0] + overlay->pitches[0] * overlay->h; - overlay->pixels[2] = - overlay->pixels[1] + overlay->pitches[1] * overlay->h / 2; - break; - case SDL_YUY2_OVERLAY: - case SDL_UYVY_OVERLAY: - case SDL_YVYU_OVERLAY: - break; - } - return 0; -} - -void -SDL_UnlockYUVOverlay(SDL_Overlay * overlay) -{ - if (!overlay) { - return; - } - - SDL_SW_UnlockYUVTexture(overlay->hwdata->texture); -} - -int -SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect) -{ - SDL_Surface *display; - SDL_Rect src_rect; - SDL_Rect dst_rect; - void *pixels; - - if (!overlay || !dstrect) { - SDL_SetError("Passed a NULL overlay or dstrect"); - return -1; - } - - display = overlay->hwdata->display; - if (display != SDL_VideoSurface) { - overlay->hwdata->display = display = SDL_VideoSurface; - overlay->hwdata->display_format = SDL_MasksToPixelFormatEnum( - display->format->BitsPerPixel, - display->format->Rmask, - display->format->Gmask, - display->format->Bmask, - display->format->Amask); - } - - src_rect.x = 0; - src_rect.y = 0; - src_rect.w = overlay->w; - src_rect.h = overlay->h; - - if (!SDL_IntersectRect(&display->clip_rect, dstrect, &dst_rect)) { - return 0; - } - - pixels = (void *)((Uint8 *)display->pixels + - dst_rect.y * display->pitch + - dst_rect.x * display->format->BytesPerPixel); - - if (SDL_SW_CopyYUVToRGB(overlay->hwdata->texture, &src_rect, - overlay->hwdata->display_format, - dst_rect.w, dst_rect.h, - pixels, display->pitch) < 0) { - return -1; - } - SDL_UpdateWindowSurface(SDL_VideoWindow); - return 0; -} - -void -SDL_FreeYUVOverlay(SDL_Overlay * overlay) -{ - if (!overlay) { - return; - } - if (overlay->hwdata) { - if (overlay->hwdata->texture) { - SDL_SW_DestroyYUVTexture(overlay->hwdata->texture); - } - SDL_free(overlay->hwdata); - } - SDL_free(overlay); -} - -void -SDL_GL_SwapBuffers(void) -{ - SDL_GL_SwapWindow(SDL_VideoWindow); -} - -int -SDL_SetGamma(float red, float green, float blue) -{ - Uint16 red_ramp[256]; - Uint16 green_ramp[256]; - Uint16 blue_ramp[256]; - - SDL_CalculateGammaRamp(red, red_ramp); - if (green == red) { - SDL_memcpy(green_ramp, red_ramp, sizeof(red_ramp)); - } else { - SDL_CalculateGammaRamp(green, green_ramp); - } - if (blue == red) { - SDL_memcpy(blue_ramp, red_ramp, sizeof(red_ramp)); - } else { - SDL_CalculateGammaRamp(blue, blue_ramp); - } - return SDL_SetWindowGammaRamp(SDL_VideoWindow, red_ramp, green_ramp, blue_ramp); -} - -int -SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue) -{ - return SDL_SetWindowGammaRamp(SDL_VideoWindow, red, green, blue); -} - -int -SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue) -{ - return SDL_GetWindowGammaRamp(SDL_VideoWindow, red, green, blue); -} - -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; - } -} - -int -SDL_EnableUNICODE(int enable) -{ - 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; -} - -static Uint32 -SDL_SetTimerCallback(Uint32 interval, void* param) -{ - return ((SDL_OldTimerCallback)param)(interval); -} - -int -SDL_SetTimer(Uint32 interval, SDL_OldTimerCallback callback) -{ - static SDL_TimerID compat_timer; - - if (compat_timer) { - SDL_RemoveTimer(compat_timer); - compat_timer = 0; - } - - if (interval && callback) { - compat_timer = SDL_AddTimer(interval, SDL_SetTimerCallback, callback); - if (!compat_timer) { - return -1; - } - } - return 0; -} - -int -SDL_putenv(const char *_var) -{ - char *ptr = NULL; - char *var = SDL_strdup(_var); - if (var == NULL) { - return -1; /* we don't set errno. */ - } - - ptr = SDL_strchr(var, '='); - 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; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 05b259d81..eb63904ea 100755 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -21,7 +21,6 @@ #include "SDL_config.h" #include "SDL_video.h" -#include "SDL_compat.h" #include "SDL_sysvideo.h" #include "SDL_blit.h" #include "SDL_RLEaccel_c.h" @@ -195,13 +194,6 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) SDL_InvalidateMap(surface->map); } - /* Compatibility mode */ - if (surface->map->info.flags & SDL_COPY_COLORKEY) { - surface->flags |= SDL_SRCCOLORKEY; - } else { - surface->flags &= ~SDL_SRCCOLORKEY; - } - return 0; } @@ -405,13 +397,6 @@ SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode) SDL_InvalidateMap(surface->map); } - /* Compatibility mode */ - if (surface->map->info.flags & SDL_COPY_BLEND) { - surface->flags |= SDL_SRCALPHA; - } else { - surface->flags &= ~SDL_SRCALPHA; - } - return status; } diff --git a/test/Makefile.in b/test/Makefile.in index 38dd6f5ef..2e5fb9949 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -9,23 +9,11 @@ LIBS = @LIBS@ TARGETS = \ checkkeys$(EXE) \ - graywin$(EXE) \ loopwave$(EXE) \ - testalpha$(EXE) \ - testatomic$(EXE) \ - testaudioinfo$(EXE) \ - testbitmap$(EXE) \ - testblitspeed$(EXE) \ - testcursor$(EXE) \ testdraw2$(EXE) \ - testdyngl$(EXE) \ - testdyngles$(EXE) \ testerror$(EXE) \ testfile$(EXE) \ - testfill$(EXE) \ - testgamma$(EXE) \ testgesture$(EXE) \ - testgl$(EXE) \ testgl2$(EXE) \ testgles$(EXE) \ testhaptic$(EXE) \ @@ -40,7 +28,6 @@ TARGETS = \ testlock$(EXE) \ testmultiaudio$(EXE) \ testnative$(EXE) \ - testoverlay$(EXE) \ testoverlay2$(EXE) \ testplatform$(EXE) \ testpower$(EXE) \ @@ -50,17 +37,12 @@ TARGETS = \ testsem$(EXE) \ testshader$(EXE) \ testshape$(EXE) \ - testsprite$(EXE) \ testsprite2$(EXE) \ testspriteminimal$(EXE) \ teststreaming$(EXE) \ testtimer$(EXE) \ testver$(EXE) \ - testvidinfo$(EXE) \ - testwin$(EXE) \ - testwm$(EXE) \ testwm2$(EXE) \ - threadwin$(EXE) \ torturethread$(EXE) \ all: Makefile $(TARGETS) @@ -71,9 +53,6 @@ Makefile: $(srcdir)/Makefile.in checkkeys$(EXE): $(srcdir)/checkkeys.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) -graywin$(EXE): $(srcdir)/graywin.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - loopwave$(EXE): $(srcdir)/loopwave.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) @@ -86,51 +65,24 @@ testaudioinfo$(EXE): $(srcdir)/testaudioinfo.c testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) -testalpha$(EXE): $(srcdir)/testalpha.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@ - testatomic$(EXE): $(srcdir)/testatomic.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) -testbitmap$(EXE): $(srcdir)/testbitmap.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - -testblitspeed$(EXE): $(srcdir)/testblitspeed.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - -testcursor$(EXE): $(srcdir)/testcursor.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - testintersections$(EXE): $(srcdir)/testintersections.c $(srcdir)/common.c $(CC) -o $@ $(srcdir)/testintersections.c $(srcdir)/common.c $(CFLAGS) $(LIBS) testdraw2$(EXE): $(srcdir)/testdraw2.c $(srcdir)/common.c $(CC) -o $@ $(srcdir)/testdraw2.c $(srcdir)/common.c $(CFLAGS) $(LIBS) -testdyngl$(EXE): $(srcdir)/testdyngl.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - -testdyngles$(EXE): $(srcdir)/testdyngles.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - testerror$(EXE): $(srcdir)/testerror.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) testfile$(EXE): $(srcdir)/testfile.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) -testfill$(EXE): $(srcdir)/testfill.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - -testgamma$(EXE): $(srcdir)/testgamma.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - testgesture$(EXE): $(srcdir)/testgesture.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@ -testgl$(EXE): $(srcdir)/testgl.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@ - testgl2$(EXE): $(srcdir)/testgl2.c $(srcdir)/common.c $(CC) -o $@ $(srcdir)/testgl2.c $(srcdir)/common.c $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@ @@ -173,9 +125,6 @@ testnative$(EXE): $(srcdir)/testnative.c \ testoverlay2$(EXE): $(srcdir)/testoverlay2.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) -testoverlay$(EXE): $(srcdir)/testoverlay.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - testplatform$(EXE): $(srcdir)/testplatform.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) @@ -197,9 +146,6 @@ testshader$(EXE): $(srcdir)/testshader.c testshape$(EXE): $(srcdir)/testshape.c $(CC) -o $@ $? -std=c99 $(CFLAGS) $(LIBS) -testsprite$(EXE): $(srcdir)/testsprite.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@ - testsprite2$(EXE): $(srcdir)/testsprite2.c $(srcdir)/common.c $(CC) -o $@ $(srcdir)/testsprite2.c $(srcdir)/common.c $(CFLAGS) $(LIBS) @MATHLIB@ @@ -215,21 +161,9 @@ testtimer$(EXE): $(srcdir)/testtimer.c testver$(EXE): $(srcdir)/testver.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) -testvidinfo$(EXE): $(srcdir)/testvidinfo.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - -testwin$(EXE): $(srcdir)/testwin.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - -testwm$(EXE): $(srcdir)/testwm.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - testwm2$(EXE): $(srcdir)/testwm2.c $(srcdir)/common.c $(CC) -o $@ $(srcdir)/testwm2.c $(srcdir)/common.c $(CFLAGS) $(LIBS) -threadwin$(EXE): $(srcdir)/threadwin.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - torturethread$(EXE): $(srcdir)/torturethread.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) diff --git a/test/common.h b/test/common.h index 1f34b7bbd..b93207a49 100644 --- a/test/common.h +++ b/test/common.h @@ -12,7 +12,6 @@ /* A simple test program framework */ -#define SDL_NO_COMPAT #include "SDL.h" #ifdef __NDS__ diff --git a/test/testalpha.c b/test/testalpha.c deleted file mode 100644 index 52b88ca30..000000000 --- a/test/testalpha.c +++ /dev/null @@ -1,552 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ - -/* Simple program: Fill a colormap with gray and stripe it down the screen, - Then move an alpha valued sprite around the screen. - */ - -#include -#include -#include -#include - -#include "SDL.h" - -#define FRAME_TICKS (1000/30) /* 30 frames/second */ - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -/* Fill the screen with a gradient */ -static void -FillBackground(SDL_Surface * screen) -{ - Uint8 *buffer; - Uint8 gradient; - int i, k; - - /* Set the surface pixels and refresh! */ - if (SDL_LockSurface(screen) < 0) { - fprintf(stderr, "Couldn't lock the display surface: %s\n", - SDL_GetError()); - quit(2); - } - buffer = (Uint8 *) screen->pixels; - switch (screen->format->BytesPerPixel) { - case 1: - case 3: - for (i = 0; i < screen->h; ++i) { - memset(buffer, (i * 255) / screen->h, - screen->w * screen->format->BytesPerPixel); - buffer += screen->pitch; - } - break; - case 2: - for (i = 0; i < screen->h; ++i) { - Uint16 *buffer16; - Uint16 color; - - gradient = ((i * 255) / screen->h); - color = (Uint16) SDL_MapRGB(screen->format, - gradient, gradient, gradient); - buffer16 = (Uint16 *) buffer; - for (k = 0; k < screen->w; k++) { - *buffer16++ = color; - } - buffer += screen->pitch; - } - break; - case 4: - for (i = 0; i < screen->h; ++i) { - Uint32 *buffer32; - Uint32 color; - - gradient = ((i * 255) / screen->h); - color = SDL_MapRGB(screen->format, gradient, gradient, gradient); - buffer32 = (Uint32 *) buffer; - for (k = 0; k < screen->w; k++) { - *buffer32++ = color; - } - buffer += screen->pitch; - } - break; - } - - SDL_UnlockSurface(screen); - SDL_UpdateRect(screen, 0, 0, 0, 0); -} - -/* Create a "light" -- a yellowish surface with variable alpha */ -SDL_Surface * -CreateLight(int radius) -{ - Uint8 trans, alphamask; - int range, addition; - int xdist, ydist; - Uint16 x, y; - Uint16 skip; - Uint32 pixel; - SDL_Surface *light; - -#ifdef LIGHT_16BIT - Uint16 *buf; - - /* Create a 16 (4/4/4/4) bpp square with a full 4-bit alpha channel */ - /* Note: this isn't any faster than a 32 bit alpha surface */ - alphamask = 0x0000000F; - light = SDL_CreateRGBSurface(SDL_SWSURFACE, 2 * radius, 2 * radius, 16, - 0x0000F000, 0x00000F00, 0x000000F0, - alphamask); -#else - Uint32 *buf; - - /* Create a 32 (8/8/8/8) bpp square with a full 8-bit alpha channel */ - alphamask = 0x000000FF; - light = SDL_CreateRGBSurface(SDL_SWSURFACE, 2 * radius, 2 * radius, 32, - 0xFF000000, 0x00FF0000, 0x0000FF00, - alphamask); - if (light == NULL) { - fprintf(stderr, "Couldn't create light: %s\n", SDL_GetError()); - return (NULL); - } -#endif - - /* Fill with a light yellow-orange color */ - skip = light->pitch - (light->w * light->format->BytesPerPixel); -#ifdef LIGHT_16BIT - buf = (Uint16 *) light->pixels; -#else - buf = (Uint32 *) light->pixels; -#endif - /* Get a tranparent pixel value - we'll add alpha later */ - pixel = SDL_MapRGBA(light->format, 0xFF, 0xDD, 0x88, 0); - for (y = 0; y < light->h; ++y) { - for (x = 0; x < light->w; ++x) { - *buf++ = pixel; - } - buf += skip; /* Almost always 0, but just in case... */ - } - - /* Calculate alpha values for the surface. */ -#ifdef LIGHT_16BIT - buf = (Uint16 *) light->pixels; -#else - buf = (Uint32 *) light->pixels; -#endif - for (y = 0; y < light->h; ++y) { - for (x = 0; x < light->w; ++x) { - /* Slow distance formula (from center of light) */ - xdist = x - (light->w / 2); - ydist = y - (light->h / 2); - range = (int) sqrt(xdist * xdist + ydist * ydist); - - /* Scale distance to range of transparency (0-255) */ - if (range > radius) { - trans = alphamask; - } else { - /* Increasing transparency with distance */ - trans = (Uint8) ((range * alphamask) / radius); - - /* Lights are very transparent */ - addition = (alphamask + 1) / 8; - if ((int) trans + addition > alphamask) { - trans = alphamask; - } else { - trans += addition; - } - } - /* We set the alpha component as the right N bits */ - *buf++ |= (255 - trans); - } - buf += skip; /* Almost always 0, but just in case... */ - } - /* Enable RLE acceleration of this alpha surface */ - SDL_SetAlpha(light, SDL_SRCALPHA | SDL_RLEACCEL, 0); - - /* We're done! */ - return (light); -} - -static Uint32 flashes = 0; -static Uint32 flashtime = 0; - -void -FlashLight(SDL_Surface * screen, SDL_Surface * light, int x, int y) -{ - SDL_Rect position; - Uint32 ticks1; - Uint32 ticks2; - - /* Easy, center light */ - position.x = x - (light->w / 2); - position.y = y - (light->h / 2); - position.w = light->w; - position.h = light->h; - ticks1 = SDL_GetTicks(); - SDL_BlitSurface(light, NULL, screen, &position); - ticks2 = SDL_GetTicks(); - SDL_UpdateRects(screen, 1, &position); - ++flashes; - - /* Update time spend doing alpha blitting */ - flashtime += (ticks2 - ticks1); -} - -static int sprite_visible = 0; -static SDL_Surface *sprite; -static SDL_Surface *backing; -static SDL_Rect position; -static int x_vel, y_vel; -static int alpha_vel; - -int -LoadSprite(SDL_Surface * screen, char *file) -{ - SDL_Surface *converted; - - /* Load the sprite image */ - sprite = SDL_LoadBMP(file); - if (sprite == NULL) { - fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); - return (-1); - } - - /* Set transparent pixel as the pixel at (0,0) */ - if (sprite->format->palette) { - SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, *(Uint8 *) sprite->pixels); - } - - /* Convert sprite to video format */ - converted = SDL_DisplayFormat(sprite); - SDL_FreeSurface(sprite); - if (converted == NULL) { - fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError()); - return (-1); - } - sprite = converted; - - /* Create the background */ - backing = SDL_CreateRGBSurface(SDL_SWSURFACE, sprite->w, sprite->h, 8, - 0, 0, 0, 0); - if (backing == NULL) { - fprintf(stderr, "Couldn't create background: %s\n", SDL_GetError()); - SDL_FreeSurface(sprite); - return (-1); - } - - /* Convert background to video format */ - converted = SDL_DisplayFormat(backing); - SDL_FreeSurface(backing); - if (converted == NULL) { - fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError()); - SDL_FreeSurface(sprite); - return (-1); - } - backing = converted; - - /* Set the initial position of the sprite */ - position.x = (screen->w - sprite->w) / 2; - position.y = (screen->h - sprite->h) / 2; - position.w = sprite->w; - position.h = sprite->h; - x_vel = 0; - y_vel = 0; - alpha_vel = 1; - - /* We're ready to roll. :) */ - return (0); -} - -void -AttractSprite(Uint16 x, Uint16 y) -{ - x_vel = ((int) x - position.x) / 10; - y_vel = ((int) y - position.y) / 10; -} - -void -MoveSprite(SDL_Surface * screen, SDL_Surface * light) -{ - SDL_Rect updates[2]; - Uint8 alpha; - - /* Erase the sprite if it was visible */ - if (sprite_visible) { - updates[0] = position; - SDL_BlitSurface(backing, NULL, screen, &updates[0]); - } else { - updates[0].x = 0; - updates[0].y = 0; - updates[0].w = 0; - updates[0].h = 0; - sprite_visible = 1; - } - - /* Since the sprite is off the screen, we can do other drawing - without being overwritten by the saved area behind the sprite. - */ - if (light != NULL) { - int x, y; - - SDL_GetMouseState(&x, &y); - FlashLight(screen, light, x, y); - } - - /* Move the sprite, bounce at the wall */ - position.x += x_vel; - if ((position.x < 0) || (position.x >= screen->w)) { - x_vel = -x_vel; - position.x += x_vel; - } - position.y += y_vel; - if ((position.y < 0) || (position.y >= screen->h)) { - y_vel = -y_vel; - position.y += y_vel; - } - - /* Update transparency (fade in and out) */ - SDL_GetSurfaceAlphaMod(sprite, &alpha); - if (((int) alpha + alpha_vel) < 0) { - alpha_vel = -alpha_vel; - } else if (((int) alpha + alpha_vel) > 255) { - alpha_vel = -alpha_vel; - } - SDL_SetAlpha(sprite, SDL_SRCALPHA, (Uint8) (alpha + alpha_vel)); - - /* Save the area behind the sprite */ - updates[1] = position; - SDL_BlitSurface(screen, &updates[1], backing, NULL); - - /* Blit the sprite onto the screen */ - updates[1] = position; - SDL_BlitSurface(sprite, NULL, screen, &updates[1]); - - /* Make it so! */ - SDL_UpdateRects(screen, 2, updates); -} - -int -main(int argc, char *argv[]) -{ - const SDL_VideoInfo *info; - SDL_Surface *screen; - int w, h; - Uint8 video_bpp; - Uint32 videoflags; - int i, done; - SDL_Event event; - SDL_Surface *light; - int mouse_pressed; - Uint32 ticks, lastticks; - - - /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - /* Alpha blending doesn't work well at 8-bit color */ -#ifdef _WIN32_WCE - /* Pocket PC */ - w = 240; - h = 320; -#else - w = 640; - h = 480; -#endif - info = SDL_GetVideoInfo(); - if (info->vfmt->BitsPerPixel > 8) { - video_bpp = info->vfmt->BitsPerPixel; - } else { - video_bpp = 16; - fprintf(stderr, "forced 16 bpp mode\n"); - } - videoflags = SDL_SWSURFACE; - for (i = 1; argv[i]; ++i) { - if (strcmp(argv[i], "-bpp") == 0) { - video_bpp = atoi(argv[++i]); - if (video_bpp <= 8) { - video_bpp = 16; - fprintf(stderr, "forced 16 bpp mode\n"); - } - } else if (strcmp(argv[i], "-hw") == 0) { - videoflags |= SDL_HWSURFACE; - } else if (strcmp(argv[i], "-warp") == 0) { - videoflags |= SDL_HWPALETTE; - } else if (strcmp(argv[i], "-width") == 0 && argv[i + 1]) { - w = atoi(argv[++i]); - } else if (strcmp(argv[i], "-height") == 0 && argv[i + 1]) { - h = atoi(argv[++i]); - } else if (strcmp(argv[i], "-resize") == 0) { - videoflags |= SDL_RESIZABLE; - } else if (strcmp(argv[i], "-noframe") == 0) { - videoflags |= SDL_NOFRAME; - } else if (strcmp(argv[i], "-fullscreen") == 0) { - videoflags |= SDL_FULLSCREEN; - } else { - fprintf(stderr, - "Usage: %s [-width N] [-height N] [-bpp N] [-warp] [-hw] [-fullscreen]\n", - argv[0]); - quit(1); - } - } - - /* Set video mode */ - if ((screen = SDL_SetVideoMode(w, h, video_bpp, videoflags)) == NULL) { - fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", - w, h, video_bpp, SDL_GetError()); - quit(2); - } - FillBackground(screen); - - /* Create the light */ - light = CreateLight(82); - if (light == NULL) { - quit(1); - } - - /* Load the sprite */ - if (LoadSprite(screen, "icon.bmp") < 0) { - SDL_FreeSurface(light); - quit(1); - } - - /* Print out information about our surfaces */ - printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel); - if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { - printf("Screen is in video memory\n"); - } else { - printf("Screen is in system memory\n"); - } - if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { - printf("Screen has double-buffering enabled\n"); - } - if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { - printf("Sprite is in video memory\n"); - } else { - printf("Sprite is in system memory\n"); - } - - /* Run a sample blit to trigger blit acceleration */ - MoveSprite(screen, NULL); - if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) { - printf("Sprite blit uses hardware alpha acceleration\n"); - } else { - printf("Sprite blit dosn't uses hardware alpha acceleration\n"); - } - - /* Set a clipping rectangle to clip the outside edge of the screen */ - { - SDL_Rect clip; - clip.x = 32; - clip.y = 32; - clip.w = screen->w - (2 * 32); - clip.h = screen->h - (2 * 32); - SDL_SetClipRect(screen, &clip); - } - - /* Wait for a keystroke */ - lastticks = SDL_GetTicks(); - done = 0; - mouse_pressed = 0; - while (!done) { - /* Update the frame -- move the sprite */ - if (mouse_pressed) { - MoveSprite(screen, light); - mouse_pressed = 0; - } else { - MoveSprite(screen, NULL); - } - - /* Slow down the loop to 30 frames/second */ - ticks = SDL_GetTicks(); - if ((ticks - lastticks) < FRAME_TICKS) { -#ifdef CHECK_SLEEP_GRANULARITY - fprintf(stderr, "Sleeping %d ticks\n", - FRAME_TICKS - (ticks - lastticks)); -#endif - SDL_Delay(FRAME_TICKS - (ticks - lastticks)); -#ifdef CHECK_SLEEP_GRANULARITY - fprintf(stderr, "Slept %d ticks\n", (SDL_GetTicks() - ticks)); -#endif - } - lastticks = ticks; - - /* Check for events */ - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_VIDEORESIZE: - screen = - SDL_SetVideoMode(event.resize.w, event.resize.h, - video_bpp, videoflags); - if (screen) { - FillBackground(screen); - } - break; - /* Attract sprite while mouse is held down */ - case SDL_MOUSEMOTION: - if (event.motion.state != 0) { - AttractSprite(event.motion.x, event.motion.y); - mouse_pressed = 1; - } - break; - case SDL_MOUSEBUTTONDOWN: - if (event.button.button == 1) { - AttractSprite(event.button.x, event.button.y); - mouse_pressed = 1; - } else { - SDL_Rect area; - - area.x = event.button.x - 16; - area.y = event.button.y - 16; - area.w = 32; - area.h = 32; - SDL_FillRect(screen, &area, - SDL_MapRGB(screen->format, 0, 0, 0)); - SDL_UpdateRects(screen, 1, &area); - } - break; - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_ESCAPE) { - done = 1; - } - if (event.key.keysym.sym == SDLK_RETURN) { - SDL_WM_ToggleFullScreen(screen); - } - break; - case SDL_QUIT: - done = 1; - break; - default: - break; - } - } - } - SDL_FreeSurface(light); - SDL_FreeSurface(sprite); - SDL_FreeSurface(backing); - - /* Print out some timing information */ - if (flashes > 0) { - printf("%d alpha blits, ~%4.4f ms per blit\n", - flashes, (float) flashtime / flashes); - } - - SDL_Quit(); - return (0); -} diff --git a/test/testbitmap.c b/test/testbitmap.c deleted file mode 100644 index 19a39431d..000000000 --- a/test/testbitmap.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ - -/* Simple program: Test bitmap blits */ - -#include -#include -#include - -#include "SDL.h" -#include "picture.xbm" - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -SDL_Surface * -LoadXBM(SDL_Surface * screen, int w, int h, Uint8 * bits) -{ - SDL_Surface *bitmap; - Uint8 *line; - - /* Allocate the bitmap */ - bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 1, 0, 0, 0, 0); - if (bitmap == NULL) { - fprintf(stderr, "Couldn't allocate bitmap: %s\n", SDL_GetError()); - return (NULL); - } - - /* Copy the pixels */ - line = (Uint8 *) bitmap->pixels; - w = (w + 7) / 8; - while (h--) { - memcpy(line, bits, w); - /* X11 Bitmap images have the bits reversed */ - { - int i, j; - Uint8 *buf, byte; - for (buf = line, i = 0; i < w; ++i, ++buf) { - byte = *buf; - *buf = 0; - for (j = 7; j >= 0; --j) { - *buf |= (byte & 0x01) << j; - byte >>= 1; - } - } - } - line += bitmap->pitch; - bits += w; - } - return (bitmap); -} - -int -main(int argc, char *argv[]) -{ - SDL_Surface *screen; - SDL_Surface *bitmap; - Uint8 video_bpp; - Uint32 videoflags; - Uint8 *buffer; - int i, k, done; - SDL_Event event; - Uint16 *buffer16; - Uint16 color; - Uint8 gradient; - SDL_Color palette[256]; - - int video_w, video_h; - - /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - video_bpp = 0; - videoflags = SDL_SWSURFACE; - while (argc > 1) { - --argc; - if (strcmp(argv[argc - 1], "-bpp") == 0) { - video_bpp = atoi(argv[argc]); - --argc; - } else if (strcmp(argv[argc], "-warp") == 0) { - videoflags |= SDL_HWPALETTE; - } else if (strcmp(argv[argc], "-hw") == 0) { - videoflags |= SDL_HWSURFACE; - } else if (strcmp(argv[argc], "-fullscreen") == 0) { - videoflags |= SDL_FULLSCREEN; - } else { - fprintf(stderr, - "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n", - argv[0]); - quit(1); - } - } - -#ifdef __IPHONEOS__ - video_w = 320; - video_h = 480; -#else - video_w = 640; - video_h = 480; -#endif - - /* Set 640x480 video mode */ - if ((screen = - SDL_SetVideoMode(video_w, video_h, video_bpp, videoflags)) == NULL) { - fprintf(stderr, "Couldn't set %dx%d %d video mode: %s\n", video_w, - video_h, video_bpp, SDL_GetError()); - quit(2); - } - - if (video_bpp == 8) { - /* Set a gray colormap, reverse order from white to black */ - for (i = 0; i < 256; ++i) { - palette[i].r = 255 - i; - palette[i].g = 255 - i; - palette[i].b = 255 - i; - } - SDL_SetColors(screen, palette, 0, 256); - } - - /* Set the surface pixels and refresh! */ - if (SDL_LockSurface(screen) < 0) { - fprintf(stderr, "Couldn't lock the display surface: %s\n", - SDL_GetError()); - quit(2); - } - buffer = (Uint8 *) screen->pixels; - if (screen->format->BytesPerPixel != 2) { - for (i = 0; i < screen->h; ++i) { - memset(buffer, (i * 255) / screen->h, screen->pitch); - buffer += screen->pitch; - } - } else { - for (i = 0; i < screen->h; ++i) { - gradient = ((i * 255) / screen->h); - color = SDL_MapRGB(screen->format, gradient, gradient, gradient); - buffer16 = (Uint16 *) buffer; - for (k = 0; k < screen->w; k++) { - *(buffer16 + k) = color; - } - buffer += screen->pitch; - } - } - SDL_UnlockSurface(screen); - SDL_UpdateRect(screen, 0, 0, 0, 0); - - /* Load the bitmap */ - bitmap = LoadXBM(screen, picture_width, picture_height, - (Uint8 *) picture_bits); - if (bitmap == NULL) { - quit(1); - } - - /* Wait for a keystroke */ - done = 0; - while (!done) { - /* Check for events */ - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_MOUSEBUTTONDOWN: - { - SDL_Rect dst; - - dst.x = event.button.x - bitmap->w / 2; - dst.y = event.button.y - bitmap->h / 2; - dst.w = bitmap->w; - dst.h = bitmap->h; - SDL_BlitSurface(bitmap, NULL, screen, &dst); - SDL_UpdateRects(screen, 1, &dst); - } - break; - case SDL_KEYDOWN: - /* Any key press quits the app... */ - done = 1; - break; - case SDL_QUIT: - done = 1; - break; - default: - break; - } - } - } - SDL_FreeSurface(bitmap); - SDL_Quit(); - return (0); -} diff --git a/test/testblitspeed.c b/test/testblitspeed.c deleted file mode 100644 index 83a83c2ec..000000000 --- a/test/testblitspeed.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ -/* - * Benchmarks surface-to-surface blits in various formats. - * - * Written by Ryan C. Gordon. - */ - -#include -#include -#include - -#include "SDL.h" - -static SDL_Surface *dest = NULL; -static SDL_Surface *src = NULL; -static int testSeconds = 10; - - -static int -percent(int val, int total) -{ - return ((int) ((((float) val) / ((float) total)) * 100.0f)); -} - -static int -randRange(int lo, int hi) -{ - return (lo + (int) (((double) hi) * rand() / (RAND_MAX + 1.0))); -} - -static void -copy_trunc_str(char *str, size_t strsize, const char *flagstr) -{ - if ((strlen(str) + strlen(flagstr)) >= (strsize - 1)) - strcpy(str + (strsize - 5), " ..."); - else - strcat(str, flagstr); -} - -static void -__append_sdl_surface_flag(SDL_Surface * _surface, char *str, - size_t strsize, Uint32 flag, const char *flagstr) -{ - if (_surface->flags & flag) - copy_trunc_str(str, strsize, flagstr); -} - - -#define append_sdl_surface_flag(a, b, c, fl) __append_sdl_surface_flag(a, b, c, fl, " " #fl) -#define print_tf_state(str, val) printf("%s: {%s}\n", str, (val) ? "true" : "false" ) - -static void -output_videoinfo_details(void) -{ - const SDL_VideoInfo *info = SDL_GetVideoInfo(); - printf("SDL_GetVideoInfo():\n"); - if (info == NULL) - printf(" (null.)\n"); - else { - print_tf_state(" hardware surface available", info->hw_available); - print_tf_state(" window manager available", info->wm_available); - print_tf_state(" accelerated hardware->hardware blits", - info->blit_hw); - print_tf_state(" accelerated hardware->hardware colorkey blits", - info->blit_hw_CC); - print_tf_state(" accelerated hardware->hardware alpha blits", - info->blit_hw_A); - print_tf_state(" accelerated software->hardware blits", - info->blit_sw); - print_tf_state(" accelerated software->hardware colorkey blits", - info->blit_sw_CC); - print_tf_state(" accelerated software->hardware alpha blits", - info->blit_sw_A); - print_tf_state(" accelerated color fills", info->blit_fill); - printf(" video memory: (%d)\n", info->video_mem); - } - - printf("\n"); -} - -static void -output_surface_details(const char *name, SDL_Surface * surface) -{ - printf("Details for %s:\n", name); - - if (surface == NULL) { - printf("-WARNING- You've got a NULL surface!"); - } else { - char f[256]; - printf(" width : %d\n", surface->w); - printf(" height : %d\n", surface->h); - printf(" depth : %d bits per pixel\n", - surface->format->BitsPerPixel); - printf(" pitch : %d\n", (int) surface->pitch); - - printf(" red bits : 0x%08X mask, %d shift, %d loss\n", - (int) surface->format->Rmask, - (int) surface->format->Rshift, (int) surface->format->Rloss); - printf(" green bits : 0x%08X mask, %d shift, %d loss\n", - (int) surface->format->Gmask, - (int) surface->format->Gshift, (int) surface->format->Gloss); - printf(" blue bits : 0x%08X mask, %d shift, %d loss\n", - (int) surface->format->Bmask, - (int) surface->format->Bshift, (int) surface->format->Bloss); - printf(" alpha bits : 0x%08X mask, %d shift, %d loss\n", - (int) surface->format->Amask, - (int) surface->format->Ashift, (int) surface->format->Aloss); - - f[0] = '\0'; - - /*append_sdl_surface_flag(surface, f, sizeof (f), SDL_SWSURFACE); */ - if ((surface->flags & SDL_HWSURFACE) == 0) - copy_trunc_str(f, sizeof(f), " SDL_SWSURFACE"); - - append_sdl_surface_flag(surface, f, sizeof(f), SDL_HWSURFACE); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_ASYNCBLIT); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_ANYFORMAT); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_HWPALETTE); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_DOUBLEBUF); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_FULLSCREEN); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_OPENGL); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_RESIZABLE); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_NOFRAME); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_HWACCEL); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_SRCCOLORKEY); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_RLEACCELOK); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_RLEACCEL); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_SRCALPHA); - append_sdl_surface_flag(surface, f, sizeof(f), SDL_PREALLOC); - - if (f[0] == '\0') - strcpy(f, " (none)"); - - printf(" flags :%s\n", f); - } - - printf("\n"); -} - -static void -output_details(void) -{ - output_videoinfo_details(); - output_surface_details("Source Surface", src); - output_surface_details("Destination Surface", dest); -} - -static Uint32 -blit(SDL_Surface * dst, SDL_Surface * src, int x, int y) -{ - Uint32 start = 0; - SDL_Rect srcRect; - SDL_Rect dstRect; - - srcRect.x = 0; - srcRect.y = 0; - dstRect.x = x; - dstRect.y = y; - dstRect.w = srcRect.w = src->w; /* SDL will clip as appropriate. */ - dstRect.h = srcRect.h = src->h; - - start = SDL_GetTicks(); - SDL_BlitSurface(src, &srcRect, dst, &dstRect); - return (SDL_GetTicks() - start); -} - -static void -blitCentered(SDL_Surface * dst, SDL_Surface * src) -{ - int x = (dst->w - src->w) / 2; - int y = (dst->h - src->h) / 2; - blit(dst, src, x, y); -} - -static int -atoi_hex(const char *str) -{ - if (str == NULL) - return 0; - - if (strlen(str) > 2) { - int retval = 0; - if ((str[0] == '0') && (str[1] == 'x')) - sscanf(str + 2, "%X", &retval); - return (retval); - } - - return (atoi(str)); -} - - -static int -setup_test(int argc, char **argv) -{ - const char *dumpfile = NULL; - SDL_Surface *bmp = NULL; - Uint32 dstbpp = 32; - Uint32 dstrmask = 0x00FF0000; - Uint32 dstgmask = 0x0000FF00; - Uint32 dstbmask = 0x000000FF; - Uint32 dstamask = 0x00000000; - Uint32 dstflags = 0; - int dstw = 640; - int dsth = 480; - Uint32 srcbpp = 32; - Uint32 srcrmask = 0x00FF0000; - Uint32 srcgmask = 0x0000FF00; - Uint32 srcbmask = 0x000000FF; - Uint32 srcamask = 0x00000000; - Uint32 srcflags = 0; - int srcw = 640; - int srch = 480; - Uint32 origsrcalphaflags = 0; - Uint32 origdstalphaflags = 0; - Uint32 srcalphaflags = 0; - Uint32 dstalphaflags = 0; - Uint8 origsrcalpha = 255; - Uint8 origdstalpha = 255; - Uint8 srcalpha = 255; - Uint8 dstalpha = 255; - int screenSurface = 0; - int i = 0; - - for (i = 1; i < argc; i++) { - const char *arg = argv[i]; - - if (strcmp(arg, "--dstbpp") == 0) - dstbpp = atoi(argv[++i]); - else if (strcmp(arg, "--dstrmask") == 0) - dstrmask = atoi_hex(argv[++i]); - else if (strcmp(arg, "--dstgmask") == 0) - dstgmask = atoi_hex(argv[++i]); - else if (strcmp(arg, "--dstbmask") == 0) - dstbmask = atoi_hex(argv[++i]); - else if (strcmp(arg, "--dstamask") == 0) - dstamask = atoi_hex(argv[++i]); - else if (strcmp(arg, "--dstwidth") == 0) - dstw = atoi(argv[++i]); - else if (strcmp(arg, "--dstheight") == 0) - dsth = atoi(argv[++i]); - else if (strcmp(arg, "--dsthwsurface") == 0) - dstflags |= SDL_HWSURFACE; - else if (strcmp(arg, "--srcbpp") == 0) - srcbpp = atoi(argv[++i]); - else if (strcmp(arg, "--srcrmask") == 0) - srcrmask = atoi_hex(argv[++i]); - else if (strcmp(arg, "--srcgmask") == 0) - srcgmask = atoi_hex(argv[++i]); - else if (strcmp(arg, "--srcbmask") == 0) - srcbmask = atoi_hex(argv[++i]); - else if (strcmp(arg, "--srcamask") == 0) - srcamask = atoi_hex(argv[++i]); - else if (strcmp(arg, "--srcwidth") == 0) - srcw = atoi(argv[++i]); - else if (strcmp(arg, "--srcheight") == 0) - srch = atoi(argv[++i]); - else if (strcmp(arg, "--srchwsurface") == 0) - srcflags |= SDL_HWSURFACE; - else if (strcmp(arg, "--seconds") == 0) - testSeconds = atoi(argv[++i]); - else if (strcmp(arg, "--screen") == 0) - screenSurface = 1; - else if (strcmp(arg, "--dumpfile") == 0) - dumpfile = argv[++i]; - /* !!! FIXME: set colorkey. */ - else if (0) { /* !!! FIXME: we handle some commandlines elsewhere now */ - fprintf(stderr, "Unknown commandline option: %s\n", arg); - return (0); - } - } - - if (SDL_Init(SDL_INIT_VIDEO) == -1) { - fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); - return (0); - } - - bmp = SDL_LoadBMP("sample.bmp"); - if (bmp == NULL) { - fprintf(stderr, "SDL_LoadBMP failed: %s\n", SDL_GetError()); - SDL_Quit(); - return (0); - } - - if ((dstflags & SDL_HWSURFACE) == 0) - dstflags |= SDL_SWSURFACE; - if ((srcflags & SDL_HWSURFACE) == 0) - srcflags |= SDL_SWSURFACE; - - if (screenSurface) - dest = SDL_SetVideoMode(dstw, dsth, dstbpp, dstflags); - else { - dest = SDL_CreateRGBSurface(dstflags, dstw, dsth, dstbpp, - dstrmask, dstgmask, dstbmask, dstamask); - } - - if (dest == NULL) { - fprintf(stderr, "dest surface creation failed: %s\n", SDL_GetError()); - SDL_Quit(); - return (0); - } - - src = SDL_CreateRGBSurface(srcflags, srcw, srch, srcbpp, - srcrmask, srcgmask, srcbmask, srcamask); - if (src == NULL) { - fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError()); - SDL_Quit(); - return (0); - } - - /* handle alpha settings... */ - srcalphaflags = (src->flags & SDL_SRCALPHA) | (src->flags & SDL_RLEACCEL); - dstalphaflags = - (dest->flags & SDL_SRCALPHA) | (dest->flags & SDL_RLEACCEL); - origsrcalphaflags = srcalphaflags; - origdstalphaflags = dstalphaflags; - SDL_GetSurfaceAlphaMod(src, &srcalpha); - SDL_GetSurfaceAlphaMod(dest, &dstalpha); - origsrcalpha = srcalpha; - origdstalpha = dstalpha; - for (i = 1; i < argc; i++) { - const char *arg = argv[i]; - - if (strcmp(arg, "--srcalpha") == 0) - srcalpha = atoi(argv[++i]); - else if (strcmp(arg, "--dstalpha") == 0) - dstalpha = atoi(argv[++i]); - else if (strcmp(arg, "--srcsrcalpha") == 0) - srcalphaflags |= SDL_SRCALPHA; - else if (strcmp(arg, "--srcnosrcalpha") == 0) - srcalphaflags &= ~SDL_SRCALPHA; - else if (strcmp(arg, "--srcrleaccel") == 0) - srcalphaflags |= SDL_RLEACCEL; - else if (strcmp(arg, "--srcnorleaccel") == 0) - srcalphaflags &= ~SDL_RLEACCEL; - else if (strcmp(arg, "--dstsrcalpha") == 0) - dstalphaflags |= SDL_SRCALPHA; - else if (strcmp(arg, "--dstnosrcalpha") == 0) - dstalphaflags &= ~SDL_SRCALPHA; - else if (strcmp(arg, "--dstrleaccel") == 0) - dstalphaflags |= SDL_RLEACCEL; - else if (strcmp(arg, "--dstnorleaccel") == 0) - dstalphaflags &= ~SDL_RLEACCEL; - } - if ((dstalphaflags != origdstalphaflags) || (origdstalpha != dstalpha)) - SDL_SetAlpha(dest, dstalphaflags, dstalpha); - if ((srcalphaflags != origsrcalphaflags) || (origsrcalpha != srcalpha)) - SDL_SetAlpha(src, srcalphaflags, srcalpha); - - /* set some sane defaults so we can see if the blit code is broken... */ - SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0)); - SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0)); - - blitCentered(src, bmp); - SDL_FreeSurface(bmp); - - if (dumpfile) - SDL_SaveBMP(src, dumpfile); /* make sure initial convert is sane. */ - - output_details(); - - return (1); -} - - -static void -test_blit_speed(void) -{ - Uint32 clearColor = SDL_MapRGB(dest->format, 0, 0, 0); - Uint32 iterations = 0; - Uint32 elasped = 0; - Uint32 end = 0; - Uint32 now = 0; - Uint32 last = 0; - int testms = testSeconds * 1000; - int wmax = (dest->w - src->w); - int hmax = (dest->h - src->h); - int isScreen = (SDL_GetVideoSurface() == dest); - SDL_Event event; - - printf("Testing blit speed for %d seconds...\n", testSeconds); - - now = SDL_GetTicks(); - end = now + testms; - - do { - /* pump the event queue occasionally to keep OS happy... */ - if (now - last > 1000) { - last = now; - while (SDL_PollEvent(&event)) { /* no-op. */ - } - } - - iterations++; - elasped += blit(dest, src, randRange(0, wmax), randRange(0, hmax)); - if (isScreen) { - SDL_Flip(dest); /* show it! */ - SDL_FillRect(dest, NULL, clearColor); /* blank it for next time! */ - } - - now = SDL_GetTicks(); - } while (now < end); - - printf("Non-blitting crap accounted for %d percent of this run.\n", - percent(testms - elasped, testms)); - - printf("%d blits took %d ms (%d fps).\n", - (int) iterations, - (int) elasped, - (int) (((float) iterations) / (((float) elasped) / 1000.0f))); -} - -int -main(int argc, char **argv) -{ - int initialized = setup_test(argc, argv); - if (initialized) { - test_blit_speed(); - SDL_Quit(); - } - return (!initialized); -} - -/* end of testblitspeed.c ... */ diff --git a/test/testcursor.c b/test/testcursor.c deleted file mode 100644 index d31df93af..000000000 --- a/test/testcursor.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ -#include -#include - -#include "SDL.h" - -/* This is an example 16x16 cursor - top left : black - top right : inverted color or black - bottom left: white - bottom right: transparent - (swap left and right for different endianness) -*/ - -Uint16 cursor_data[16] = { - 0xffff, - 0xffff, - 0xffff, - 0xffff, - - 0xffff, - 0xffff, - 0xffff, - 0xffff, - - 0x0000, - 0x0000, - 0x0000, - 0x0000, - - 0x0000, - 0x0000, - 0x0000, - 0x0000 -}; - -Uint16 cursor_mask[16] = { - 0xff00, - 0xff00, - 0xff00, - 0xff00, - - 0xff00, - 0xff00, - 0xff00, - 0xff00, - - 0xff00, - 0xff00, - 0xff00, - 0xff00, - - 0xff00, - 0xff00, - 0xff00, - 0xff00 -}; - -/* another test cursor: smaller than 16x16, and with an odd height */ - -Uint8 small_cursor_data[11] = - { 0x00, 0x18, 0x08, 0x38, 0x44, 0x54, 0x44, 0x38, 0x20, 0x20, 0x00 }; -Uint8 small_cursor_mask[11] = - { 0x3C, 0x3C, 0x3C, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x78, 0x70, 0x70 }; - -/* XPM */ -static const char *arrow[] = { - /* width height num_colors chars_per_pixel */ - " 32 32 3 1", - /* colors */ - "X c #000000", - ". c #ffffff", - " c None", - /* pixels */ - "X ", - "XX ", - "X.X ", - "X..X ", - "X...X ", - "X....X ", - "X.....X ", - "X......X ", - "X.......X ", - "X........X ", - "X.....XXXXX ", - "X..X..X ", - "X.X X..X ", - "XX X..X ", - "X X..X ", - " X..X ", - " X..X ", - " X..X ", - " XX ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "0,0" -}; - -static SDL_Cursor * -create_arrow_cursor() -{ - int i, row, col; - Uint8 data[4 * 32]; - Uint8 mask[4 * 32]; - int hot_x, hot_y; - - i = -1; - for (row = 0; row < 32; ++row) { - for (col = 0; col < 32; ++col) { - if (col % 8) { - data[i] <<= 1; - mask[i] <<= 1; - } else { - ++i; - data[i] = mask[i] = 0; - } - switch (arrow[4 + row][col]) { - case 'X': - data[i] |= 0x01; - mask[i] |= 0x01; - break; - case '.': - mask[i] |= 0x01; - break; - case ' ': - break; - } - } - } - SDL_sscanf(arrow[4 + row], "%d,%d", &hot_x, &hot_y); - return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y); -} - -SDL_Surface * -LoadSprite(char *file) -{ - SDL_Surface *sprite; - - /* Load the sprite image */ - sprite = SDL_LoadBMP(file); - if (sprite == NULL) { - fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); - return NULL; - } - - /* Set transparent pixel as the pixel at (0,0) */ - if (sprite->format->palette) { - SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY | SDL_RLEACCEL), - *(Uint8 *) sprite->pixels); - } - - /* We're ready to roll. :) */ - return sprite; -} - -int -main(int argc, char *argv[]) -{ - SDL_Surface *screen; - SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE; - SDL_Cursor *cursor[5]; - int current; - - /* Load the SDL library */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - screen = SDL_SetVideoMode(640, 480, 8, SDL_ANYFORMAT); - if (screen == NULL) { - fprintf(stderr, "Couldn't initialize video mode: %s\n", - SDL_GetError()); - return (1); - } - - SDL_FillRect(screen, NULL, 0x664422); - - cursor[0] = SDL_CreateCursor((Uint8 *) cursor_data, (Uint8 *) cursor_mask, - 16, 16, 8, 8); - if (cursor[0] == NULL) { - fprintf(stderr, "Couldn't initialize test cursor: %s\n", - SDL_GetError()); - SDL_Quit(); - return (1); - } - cursor[1] = create_arrow_cursor(); - if (cursor[1] == NULL) { - fprintf(stderr, "Couldn't initialize arrow cursor: %s\n", - SDL_GetError()); - SDL_FreeCursor(cursor[0]); - SDL_Quit(); - return (1); - } - cursor[2] = SDL_CreateCursor(small_cursor_data, small_cursor_mask, - 8, 11, 3, 5); - if (cursor[2] == NULL) { - fprintf(stderr, "Couldn't initialize test cursor: %s\n", - SDL_GetError()); - SDL_Quit(); - return (1); - } - cursor[3] = SDL_CreateColorCursor(LoadSprite("icon.bmp"), 0, 0); - cursor[4] = SDL_GetCursor(); - - current = SDL_arraysize(cursor)-1; - SDL_SetCursor(cursor[current]); - - while (!quit) { - SDL_Event event; - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_MOUSEBUTTONDOWN: - current = (current + 1) % SDL_arraysize(cursor); - SDL_SetCursor(cursor[current]); - break; - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_ESCAPE) { - quit = SDL_TRUE; - } - break; - case SDL_QUIT: - quit = SDL_TRUE; - break; - } - } - SDL_Flip(screen); - SDL_Delay(1); - } - - for (current = 0; current < SDL_arraysize(cursor); ++current) { - SDL_FreeCursor(cursor[current]); - } - - SDL_Quit(); - return (0); -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testdyngl.c b/test/testdyngl.c deleted file mode 100644 index a11e96cd7..000000000 --- a/test/testdyngl.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ -/* - * Small SDL example to demonstrate dynamically loading - * OpenGL lib and functions - * - * (FYI it was supposed to look like snow in the wind or something...) - * - * Compile with : - * gcc testdyngl.c `sdl-config --libs --cflags` -o testdyngl -DHAVE_OPENGL - * - * You can specify a different OpenGL lib on the command line, i.e. : - * ./testdyngl /usr/X11R6/lib/libGL.so.1.2 - * or - * ./testdyngl /usr/lib/libGL.so.1.0.4496 - * - */ - -#include -#include - -#include "SDL.h" - -#ifdef __MACOS__ -#define HAVE_OPENGL -#endif - -#ifdef HAVE_OPENGL - -#include "SDL_opengl.h" - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -void * -get_funcaddr(const char *p) -{ - void *f = SDL_GL_GetProcAddress(p); - if (f) { - return f; - } else { - printf("Unable to get function pointer for %s\n", p); - quit(1); - } - return NULL; -} - -typedef struct -{ - void (APIENTRY * glBegin) (GLenum); - void (APIENTRY * glEnd) (); - void (APIENTRY * glVertex3f) (GLfloat, GLfloat, GLfloat); - void (APIENTRY * glClearColor) (GLfloat, GLfloat, GLfloat, GLfloat); - void (APIENTRY * glClear) (GLbitfield); - void (APIENTRY * glDisable) (GLenum); - void (APIENTRY * glEnable) (GLenum); - void (APIENTRY * glColor4ub) (GLubyte, GLubyte, GLubyte, GLubyte); - void (APIENTRY * glPointSize) (GLfloat); - void (APIENTRY * glHint) (GLenum, GLenum); - void (APIENTRY * glBlendFunc) (GLenum, GLenum); - void (APIENTRY * glMatrixMode) (GLenum); - void (APIENTRY * glLoadIdentity) (); - void (APIENTRY * glOrtho) (GLdouble, GLdouble, GLdouble, GLdouble, - GLdouble, GLdouble); - void (APIENTRY * glRotatef) (GLfloat, GLfloat, GLfloat, GLfloat); - void (APIENTRY * glViewport) (GLint, GLint, GLsizei, GLsizei); - void (APIENTRY * glFogf) (GLenum, GLfloat); - const GLubyte* (APIENTRY * glGetString) (GLenum); -} -glfuncs; - -void -init_glfuncs(glfuncs * f) -{ - f->glBegin = get_funcaddr("glBegin"); - f->glEnd = get_funcaddr("glEnd"); - f->glVertex3f = get_funcaddr("glVertex3f"); - f->glClearColor = get_funcaddr("glClearColor"); - f->glClear = get_funcaddr("glClear"); - f->glDisable = get_funcaddr("glDisable"); - f->glEnable = get_funcaddr("glEnable"); - f->glColor4ub = get_funcaddr("glColor4ub"); - f->glPointSize = get_funcaddr("glPointSize"); - f->glHint = get_funcaddr("glHint"); - f->glBlendFunc = get_funcaddr("glBlendFunc"); - f->glMatrixMode = get_funcaddr("glMatrixMode"); - f->glLoadIdentity = get_funcaddr("glLoadIdentity"); - f->glOrtho = get_funcaddr("glOrtho"); - f->glRotatef = get_funcaddr("glRotatef"); - f->glViewport = get_funcaddr("glViewport"); - f->glFogf = get_funcaddr("glFogf"); - f->glGetString = get_funcaddr("glGetString"); - - printf("Vendor : %s\n", f->glGetString(GL_VENDOR)); - printf("Renderer : %s\n", f->glGetString(GL_RENDERER)); - printf("Version : %s\n", f->glGetString(GL_VERSION)); - printf("Extensions : %s\n", f->glGetString(GL_EXTENSIONS)); -} - -#define NB_PIXELS 1000 - -int -main(int argc, char *argv[]) -{ - glfuncs f; - int i; - SDL_Event event; - int done = 0; - GLfloat pixels[NB_PIXELS * 3]; - const char *gl_library = NULL; /* Use the default GL library */ - - if (argv[1]) { - gl_library = argv[1]; - } - - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - printf("Unable to init SDL : %s\n", SDL_GetError()); - return (1); - } - - if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) < 0) { - printf("Unable to set GL attribute : %s\n", SDL_GetError()); - quit(1); - } - - if (SDL_GL_LoadLibrary(gl_library) < 0) { - printf("Unable to dynamically open GL lib : %s\n", SDL_GetError()); - quit(1); - } - - if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL) { - printf("Unable to open video mode : %s\n", SDL_GetError()); - quit(1); - } - - /* Set the window manager title bar */ - SDL_WM_SetCaption("SDL Dynamic OpenGL Loading Test", "testdyngl"); - - init_glfuncs(&f); - - for (i = 0; i < NB_PIXELS; i++) { - pixels[3 * i] = rand() % 250 - 125; - pixels[3 * i + 1] = rand() % 250 - 125; - pixels[3 * i + 2] = rand() % 250 - 125; - } - - f.glViewport(0, 0, 640, 480); - - f.glMatrixMode(GL_PROJECTION); - f.glLoadIdentity(); - f.glOrtho(-100, 100, -100, 100, -500, 500); - - f.glMatrixMode(GL_MODELVIEW); - f.glLoadIdentity(); - - f.glEnable(GL_DEPTH_TEST); - f.glDisable(GL_TEXTURE_2D); - f.glEnable(GL_BLEND); - f.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - f.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - f.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - f.glEnable(GL_POINT_SMOOTH); - f.glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); - f.glPointSize(5.0f); - f.glEnable(GL_FOG); - f.glFogf(GL_FOG_START, -500); - f.glFogf(GL_FOG_END, 500); - f.glFogf(GL_FOG_DENSITY, 0.005); - - do { - f.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - f.glRotatef(2.0, 1.0, 1.0, 1.0); - f.glRotatef(1.0, 0.0, 1.0, 1.0); - - f.glColor4ub(255, 255, 255, 255); - f.glBegin(GL_POINTS); - for (i = 0; i < NB_PIXELS; i++) { - f.glVertex3f(pixels[3 * i], pixels[3 * i + 1], pixels[3 * i + 2]); - } - f.glEnd(); - SDL_GL_SwapBuffers(); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - done = 1; - } - - SDL_Delay(20); - } while (!done); - - SDL_Quit(); - return 0; -} - -#else /* HAVE_OPENGL */ - -int -main(int argc, char *argv[]) -{ - printf("No OpenGL support on this system\n"); - return 1; -} - -#endif /* HAVE_OPENGL */ diff --git a/test/testdyngles.c b/test/testdyngles.c deleted file mode 100644 index f83b7e236..000000000 --- a/test/testdyngles.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ -/* - * Small SDL example to demonstrate dynamically loading - * OpenGL lib and functions - * - * (FYI it was supposed to look like snow in the wind or something...) - * - * Compile with : - * gcc testdyngl.c `sdl-config --libs --cflags` -o testdyngl -DHAVE_OPENGL - * - * You can specify a different OpenGL lib on the command line, i.e. : - * ./testdyngl /usr/X11R6/lib/libGL.so.1.2 - * or - * ./testdyngl /usr/lib/libGL.so.1.0.4496 - * - */ - -#include -#include - -#include "SDL.h" - -#ifdef __IPHONEOS__ -#define HAVE_OPENGLES -#endif - -#ifdef HAVE_OPENGLES - -#include "SDL_opengles.h" - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -void * -get_funcaddr(const char *p) -{ - void *f = SDL_GL_GetProcAddress(p); - if (f) { - return f; - } else { - printf("Unable to get function pointer for %s\n", p); - quit(1); - } - return NULL; -} - -typedef struct -{ - void (APIENTRY * glEnableClientState) (GLenum array); - void (APIENTRY * glDisableClientState) (GLenum array); - void (APIENTRY * glVertexPointer) (GLint size, GLenum type, - GLsizei stride, - const GLvoid * pointer); - void (APIENTRY * glDrawArrays) (GLenum mode, GLint first, GLsizei count); - - - void (APIENTRY * glClearColor) (GLfloat, GLfloat, GLfloat, GLfloat); - void (APIENTRY * glClear) (GLbitfield); - void (APIENTRY * glDisable) (GLenum); - void (APIENTRY * glEnable) (GLenum); - void (APIENTRY * glColor4f) (GLfloat, GLfloat, GLfloat, GLfloat); - void (APIENTRY * glPointSize) (GLfloat); - void (APIENTRY * glHint) (GLenum, GLenum); - void (APIENTRY * glBlendFunc) (GLenum, GLenum); - void (APIENTRY * glMatrixMode) (GLenum); - void (APIENTRY * glLoadIdentity) (); - void (APIENTRY * glOrthof) (GLfloat, GLfloat, GLfloat, GLfloat, - GLfloat, GLfloat); - void (APIENTRY * glRotatef) (GLfloat, GLfloat, GLfloat, GLfloat); - void (APIENTRY * glViewport) (GLint, GLint, GLsizei, GLsizei); - void (APIENTRY * glFogf) (GLenum, GLfloat); -} -glfuncs; - -void -init_glfuncs(glfuncs * f) -{ - f->glEnableClientState = get_funcaddr("glEnableClientState"); - f->glDisableClientState = get_funcaddr("glDisableClientState"); - f->glVertexPointer = get_funcaddr("glVertexPointer"); - f->glDrawArrays = get_funcaddr("glDrawArrays"); - f->glClearColor = get_funcaddr("glClearColor"); - f->glClear = get_funcaddr("glClear"); - f->glDisable = get_funcaddr("glDisable"); - f->glEnable = get_funcaddr("glEnable"); - f->glColor4f = get_funcaddr("glColor4f"); - f->glPointSize = get_funcaddr("glPointSize"); - f->glHint = get_funcaddr("glHint"); - f->glBlendFunc = get_funcaddr("glBlendFunc"); - f->glMatrixMode = get_funcaddr("glMatrixMode"); - f->glLoadIdentity = get_funcaddr("glLoadIdentity"); - f->glOrthof = get_funcaddr("glOrthof"); - f->glRotatef = get_funcaddr("glRotatef"); - f->glViewport = get_funcaddr("glViewport"); - f->glFogf = get_funcaddr("glFogf"); -} - -#define NB_PIXELS 1000 - -int -main(int argc, char *argv[]) -{ - glfuncs f; - int i; - SDL_Event event; - int done = 0; - GLfloat pixels[NB_PIXELS * 3]; - const char *gl_library = NULL; /* Use the default GL library */ - - int video_w, video_h; - - /* you may want to change these according to the platform */ - video_w = 320; - video_h = 480; - - if (argv[1]) { - gl_library = argv[1]; - } - - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - printf("Unable to init SDL : %s\n", SDL_GetError()); - return (1); - } - - if (SDL_GL_LoadLibrary(gl_library) < 0) { - printf("Unable to dynamically open GL ES lib : %s\n", SDL_GetError()); - quit(1); - } - - if (SDL_SetVideoMode(video_h, video_w, 0, SDL_OPENGL) == NULL) { - printf("Unable to open video mode : %s\n", SDL_GetError()); - quit(1); - } - - /* Set the window manager title bar */ - SDL_WM_SetCaption("SDL Dynamic OpenGL ES Loading Test", "testdyngles"); - - init_glfuncs(&f); - - for (i = 0; i < NB_PIXELS; i++) { - pixels[3 * i] = rand() % 250 - 125; - pixels[3 * i + 1] = rand() % 250 - 125; - pixels[3 * i + 2] = rand() % 250 - 125; - } - - f.glViewport(0, 0, video_w, video_h); - f.glMatrixMode(GL_PROJECTION); - f.glLoadIdentity(); - f.glOrthof(-100, 100, -100, 100, -500, 500); - - f.glMatrixMode(GL_MODELVIEW); - f.glLoadIdentity(); - - f.glEnable(GL_DEPTH_TEST); - f.glDisable(GL_TEXTURE_2D); - f.glEnable(GL_BLEND); - f.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - f.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - f.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - f.glEnable(GL_POINT_SMOOTH); - f.glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); - f.glPointSize(1.0f); - f.glEnable(GL_FOG); - f.glFogf(GL_FOG_START, -500); - f.glFogf(GL_FOG_END, 500); - f.glFogf(GL_FOG_DENSITY, 0.005); - - f.glVertexPointer(3, GL_FLOAT, 0, pixels); - f.glEnableClientState(GL_VERTEX_ARRAY); - - do { - f.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - f.glRotatef(2.0, 1.0, 1.0, 1.0); - f.glRotatef(1.0, 0.0, 1.0, 1.0); - - f.glColor4f(1.0, 1.0, 1.0, 1.0); - - f.glDrawArrays(GL_POINTS, 0, NB_PIXELS); - - SDL_GL_SwapBuffers(); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) - done = 1; - if (event.type == SDL_KEYDOWN) - done = 1; - } - - SDL_Delay(20); - } - while (!done); - - f.glDisableClientState(GL_VERTEX_ARRAY); - - SDL_Quit(); - return 0; -} - -#else /* HAVE_OPENGLES */ - -int -main(int argc, char *argv[]) -{ - printf("No OpenGL ES support on this system\n"); - return 1; -} - -#endif /* HAVE_OPENGLES */ diff --git a/test/testfill.c b/test/testfill.c deleted file mode 100644 index 81a104ae3..000000000 --- a/test/testfill.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ -/* Simple program: Fill the screen with colors as fast as possible */ - -#include -#include -#include -#include - -#include "SDL.h" - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -int -main(int argc, char *argv[]) -{ - SDL_Surface *screen; - int width, height; - Uint8 video_bpp; - Uint32 videoflags; - Uint32 colors[3]; - int i, done; - SDL_Event event; - Uint32 then, now, frames; - - /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - width = 640; - height = 480; - video_bpp = 8; - videoflags = 0; - while (argc > 1) { - --argc; - if (strcmp(argv[argc - 1], "-width") == 0) { - width = atoi(argv[argc]); - --argc; - } else if (strcmp(argv[argc - 1], "-height") == 0) { - height = atoi(argv[argc]); - --argc; - } else if (strcmp(argv[argc - 1], "-bpp") == 0) { - video_bpp = atoi(argv[argc]); - --argc; - } else if (strcmp(argv[argc], "-fullscreen") == 0) { - videoflags ^= SDL_FULLSCREEN; - } else { - fprintf(stderr, - "Usage: %s [-width N] [-height N] [-bpp N] [-fullscreen]\n", - argv[0]); - quit(1); - } - } - - /* Set video mode */ - screen = SDL_SetVideoMode(width, height, video_bpp, 0); - if (!screen) { - fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", - width, height, SDL_GetError()); - quit(2); - } - - /* Get the colors */ - colors[0] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0x00); - colors[1] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00); - colors[2] = SDL_MapRGB(screen->format, 0x00, 0x00, 0xFF); - - /* Loop, filling and waiting for a keystroke */ - frames = 0; - then = SDL_GetTicks(); - done = 0; - while (!done) { - /* Check for events */ - ++frames; - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_MOUSEBUTTONDOWN: - SDL_WarpMouse(screen->w / 2, screen->h / 2); - break; - case SDL_KEYDOWN: - /* Any keypress quits the app... */ - case SDL_QUIT: - done = 1; - break; - default: - break; - } - } - SDL_FillRect(screen, NULL, colors[frames%3]); - SDL_Flip(screen); - } - - /* Print out some timing information */ - now = SDL_GetTicks(); - if (now > then) { - double fps = ((double) frames * 1000) / (now - then); - printf("%2.2f frames per second\n", fps); - } - SDL_Quit(); - return (0); -} diff --git a/test/testgamma.c b/test/testgamma.c deleted file mode 100644 index a0037e49b..000000000 --- a/test/testgamma.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ - -/* Bring up a window and manipulate the gamma on it */ - -#include -#include -#include -#include - -#include "SDL.h" - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -/* This can be used as a general routine for all of the test programs */ -int -get_video_args(char *argv[], int *w, int *h, int *bpp, Uint32 * flags) -{ - int i; - - *w = 640; - *h = 480; - *bpp = 0; - *flags = SDL_SWSURFACE; - - for (i = 1; argv[i]; ++i) { - if (strcmp(argv[i], "-width") == 0) { - if (argv[i + 1]) { - *w = atoi(argv[++i]); - } - } else if (strcmp(argv[i], "-height") == 0) { - if (argv[i + 1]) { - *h = atoi(argv[++i]); - } - } else if (strcmp(argv[i], "-bpp") == 0) { - if (argv[i + 1]) { - *bpp = atoi(argv[++i]); - } - } else if (strcmp(argv[i], "-fullscreen") == 0) { - *flags |= SDL_FULLSCREEN; - } else if (strcmp(argv[i], "-hw") == 0) { - *flags |= SDL_HWSURFACE; - } else if (strcmp(argv[i], "-hwpalette") == 0) { - *flags |= SDL_HWPALETTE; - } else - break; - } - return i; -} - -int -main(int argc, char *argv[]) -{ - SDL_Surface *screen; - SDL_Surface *image; - float gamma; - int i; - int w, h, bpp; - Uint32 flags; - Uint16 ramp[256]; - Uint16 red_ramp[256]; - Uint32 then, timeout; - - /* Check command line arguments */ - argv += get_video_args(argv, &w, &h, &bpp, &flags); - - /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - /* Initialize the display, always use hardware palette */ - screen = SDL_SetVideoMode(w, h, bpp, flags | SDL_HWPALETTE); - if (screen == NULL) { - fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", - w, h, SDL_GetError()); - quit(1); - } - - /* Set the window manager title bar */ - SDL_WM_SetCaption("SDL gamma test", "testgamma"); - - /* Set the desired gamma, if any */ - gamma = 1.0f; - if (*argv) { - gamma = (float) atof(*argv); - } - if (SDL_SetGamma(gamma, gamma, gamma) < 0) { - fprintf(stderr, "Unable to set gamma: %s\n", SDL_GetError()); - quit(1); - } - - /* Do all the drawing work */ - image = SDL_LoadBMP("sample.bmp"); - if (image) { - SDL_Rect dst; - - dst.x = (screen->w - image->w) / 2; - dst.y = (screen->h - image->h) / 2; - dst.w = image->w; - dst.h = image->h; - SDL_BlitSurface(image, NULL, screen, &dst); - SDL_UpdateRects(screen, 1, &dst); - } - - /* Wait a bit, handling events */ - then = SDL_GetTicks(); - timeout = (5 * 1000); - while ((SDL_GetTicks() - then) < timeout) { - SDL_Event event; - - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: /* Quit now */ - timeout = 0; - break; - case SDL_KEYDOWN: - switch (event.key.keysym.sym) { - case SDLK_SPACE: /* Go longer.. */ - timeout += (5 * 1000); - break; - case SDLK_UP: - gamma += 0.2f; - SDL_SetGamma(gamma, gamma, gamma); - break; - case SDLK_DOWN: - gamma -= 0.2f; - SDL_SetGamma(gamma, gamma, gamma); - break; - case SDLK_ESCAPE: - timeout = 0; - break; - default: - break; - } - break; - } - } - } - - /* Perform a gamma flash to red using color ramps */ - while (gamma < 10.0) { - /* Increase the red gamma and decrease everything else... */ - gamma += 0.1f; - SDL_CalculateGammaRamp(gamma, red_ramp); - SDL_CalculateGammaRamp(1.0f / gamma, ramp); - SDL_SetGammaRamp(red_ramp, ramp, ramp); - } - /* Finish completely red */ - memset(red_ramp, 255, sizeof(red_ramp)); - memset(ramp, 0, sizeof(ramp)); - SDL_SetGammaRamp(red_ramp, ramp, ramp); - - /* Now fade out to black */ - for (i = (red_ramp[0] >> 8); i >= 0; --i) { - memset(red_ramp, i, sizeof(red_ramp)); - SDL_SetGammaRamp(red_ramp, NULL, NULL); - } - SDL_Delay(1 * 1000); - - SDL_Quit(); - return (0); -} diff --git a/test/testgl.c b/test/testgl.c deleted file mode 100644 index d7cbc1d94..000000000 --- a/test/testgl.c +++ /dev/null @@ -1,782 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ -#include -#include -#include -#include - -#include "SDL.h" - -#ifdef __MACOS__ -#define HAVE_OPENGL -#endif - -#ifdef HAVE_OPENGL - -#include "SDL_opengl.h" - -/* Undefine this if you want a flat cube instead of a rainbow cube */ -#define SHADED_CUBE - -/* Define this to be the name of the logo image to use with -logo */ -#define LOGO_FILE "icon.bmp" - -static SDL_Surface *global_image = NULL; -static GLuint global_texture = 0; -static GLuint cursor_texture = 0; - -/**********************************************************************/ - -void -HotKey_ToggleFullScreen(void) -{ - SDL_Surface *screen; - - screen = SDL_GetVideoSurface(); - if (SDL_WM_ToggleFullScreen(screen)) { - printf("Toggled fullscreen mode - now %s\n", - (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); - } else { - printf("Unable to toggle fullscreen mode\n"); - } -} - -void -HotKey_ToggleGrab(void) -{ - SDL_GrabMode mode; - - printf("Ctrl-G: toggling input grab!\n"); - mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); - if (mode == SDL_GRAB_ON) { - printf("Grab was on\n"); - } else { - printf("Grab was off\n"); - } - mode = SDL_WM_GrabInput(!mode); - if (mode == SDL_GRAB_ON) { - printf("Grab is now on\n"); - } else { - printf("Grab is now off\n"); - } -} - -void -HotKey_Iconify(void) -{ - printf("Ctrl-Z: iconifying window!\n"); - SDL_WM_IconifyWindow(); -} - -int -HandleEvent(SDL_Event * event) -{ - int done; - - done = 0; - switch (event->type) { - case SDL_ACTIVEEVENT: - /* See what happened */ - printf("app %s ", event->active.gain ? "gained" : "lost"); - if (event->active.state & SDL_APPACTIVE) { - printf("active "); - } else if (event->active.state & SDL_APPMOUSEFOCUS) { - printf("mouse "); - } else if (event->active.state & SDL_APPINPUTFOCUS) { - printf("input "); - } - printf("focus\n"); - break; - - - case SDL_KEYDOWN: - if (event->key.keysym.sym == SDLK_ESCAPE) { - done = 1; - } - if ((event->key.keysym.sym == SDLK_g) && - (event->key.keysym.mod & KMOD_CTRL)) { - HotKey_ToggleGrab(); - } - if ((event->key.keysym.sym == SDLK_z) && - (event->key.keysym.mod & KMOD_CTRL)) { - HotKey_Iconify(); - } - if ((event->key.keysym.sym == SDLK_RETURN) && - (event->key.keysym.mod & KMOD_ALT)) { - HotKey_ToggleFullScreen(); - } - printf("key '%s' pressed\n", SDL_GetKeyName(event->key.keysym.sym)); - break; - case SDL_QUIT: - done = 1; - break; - } - return (done); -} - -void -SDL_GL_Enter2DMode() -{ - SDL_Surface *screen = SDL_GetVideoSurface(); - - /* Note, there may be other things you need to change, - depending on how you have your OpenGL state set up. - */ - glPushAttrib(GL_ENABLE_BIT); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glEnable(GL_TEXTURE_2D); - - /* This allows alpha blending of 2D textures with the scene */ - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glViewport(0, 0, screen->w, screen->h); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - glOrtho(0.0, (GLdouble) screen->w, (GLdouble) screen->h, 0.0, 0.0, 1.0); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); -} - -void -SDL_GL_Leave2DMode() -{ - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - glPopAttrib(); -} - -/* Quick utility function for texture creation */ -static int -power_of_two(int input) -{ - int value = 1; - - while (value < input) { - value <<= 1; - } - return value; -} - -GLuint -SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord) -{ - GLuint texture; - int w, h; - SDL_Surface *image; - SDL_Rect area; - Uint32 saved_flags; - Uint8 saved_alpha; - - /* Use the surface width and height expanded to powers of 2 */ - w = power_of_two(surface->w); - h = power_of_two(surface->h); - texcoord[0] = 0.0f; /* Min X */ - texcoord[1] = 0.0f; /* Min Y */ - texcoord[2] = (GLfloat) surface->w / w; /* Max X */ - texcoord[3] = (GLfloat) surface->h / h; /* Max Y */ - - image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, -#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ - 0x000000FF, - 0x0000FF00, 0x00FF0000, 0xFF000000 -#else - 0xFF000000, - 0x00FF0000, 0x0000FF00, 0x000000FF -#endif - ); - if (image == NULL) { - return 0; - } - - /* Save the alpha blending attributes */ - saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); - SDL_GetSurfaceAlphaMod(surface, &saved_alpha); - if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { - SDL_SetAlpha(surface, 0, 0); - } - - /* Copy the surface into the GL texture image */ - area.x = 0; - area.y = 0; - area.w = surface->w; - area.h = surface->h; - SDL_BlitSurface(surface, &area, image, &area); - - /* Restore the alpha blending attributes */ - if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { - SDL_SetAlpha(surface, saved_flags, saved_alpha); - } - - /* Create an OpenGL texture for the image */ - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, - 0, - GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); - SDL_FreeSurface(image); /* No longer needed */ - - return texture; -} - -void -DrawLogoCursor(void) -{ - static GLfloat texMinX, texMinY; - static GLfloat texMaxX, texMaxY; - static int w, h; - int x, y; - - if (!cursor_texture) { - SDL_Surface *image; - GLfloat texcoord[4]; - - /* Load the image (could use SDL_image library here) */ - image = SDL_LoadBMP(LOGO_FILE); - if (image == NULL) { - return; - } - w = image->w; - h = image->h; - - /* Convert the image into an OpenGL texture */ - cursor_texture = SDL_GL_LoadTexture(image, texcoord); - - /* Make texture coordinates easy to understand */ - texMinX = texcoord[0]; - texMinY = texcoord[1]; - texMaxX = texcoord[2]; - texMaxY = texcoord[3]; - - /* We don't need the original image anymore */ - SDL_FreeSurface(image); - - /* Make sure that the texture conversion is okay */ - if (!cursor_texture) { - return; - } - } - - /* Move the image around */ - SDL_GetMouseState(&x, &y); - x -= w / 2; - y -= h / 2; - - /* Show the image on the screen */ - SDL_GL_Enter2DMode(); - glBindTexture(GL_TEXTURE_2D, cursor_texture); - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(texMinX, texMinY); - glVertex2i(x, y); - glTexCoord2f(texMaxX, texMinY); - glVertex2i(x + w, y); - glTexCoord2f(texMinX, texMaxY); - glVertex2i(x, y + h); - glTexCoord2f(texMaxX, texMaxY); - glVertex2i(x + w, y + h); - glEnd(); - SDL_GL_Leave2DMode(); -} - -void -DrawLogoTexture(void) -{ - static GLfloat texMinX, texMinY; - static GLfloat texMaxX, texMaxY; - static int x = 0; - static int y = 0; - static int w, h; - static int delta_x = 1; - static int delta_y = 1; - - SDL_Surface *screen = SDL_GetVideoSurface(); - - if (!global_texture) { - SDL_Surface *image; - GLfloat texcoord[4]; - - /* Load the image (could use SDL_image library here) */ - image = SDL_LoadBMP(LOGO_FILE); - if (image == NULL) { - return; - } - w = image->w; - h = image->h; - - /* Convert the image into an OpenGL texture */ - global_texture = SDL_GL_LoadTexture(image, texcoord); - - /* Make texture coordinates easy to understand */ - texMinX = texcoord[0]; - texMinY = texcoord[1]; - texMaxX = texcoord[2]; - texMaxY = texcoord[3]; - - /* We don't need the original image anymore */ - SDL_FreeSurface(image); - - /* Make sure that the texture conversion is okay */ - if (!global_texture) { - return; - } - } - - /* Move the image around */ - x += delta_x; - if (x < 0) { - x = 0; - delta_x = -delta_x; - } else if ((x + w) > screen->w) { - x = screen->w - w; - delta_x = -delta_x; - } - y += delta_y; - if (y < 0) { - y = 0; - delta_y = -delta_y; - } else if ((y + h) > screen->h) { - y = screen->h - h; - delta_y = -delta_y; - } - - /* Show the image on the screen */ - SDL_GL_Enter2DMode(); - glBindTexture(GL_TEXTURE_2D, global_texture); - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(texMinX, texMinY); - glVertex2i(x, y); - glTexCoord2f(texMaxX, texMinY); - glVertex2i(x + w, y); - glTexCoord2f(texMinX, texMaxY); - glVertex2i(x, y + h); - glTexCoord2f(texMaxX, texMaxY); - glVertex2i(x + w, y + h); - glEnd(); - SDL_GL_Leave2DMode(); -} - -int -RunGLTest(int argc, char *argv[], - int logo, int logocursor, int slowly, int bpp, float gamma, - int noframe, int fsaa, int sync, int accel) -{ - int i; - int rgb_size[3]; - int w = 640; - int h = 480; - int done = 0; - int frames; - Uint32 start_time, this_time; - float color[8][3] = { {1.0, 1.0, 0.0}, - {1.0, 0.0, 0.0}, - {0.0, 0.0, 0.0}, - {0.0, 1.0, 0.0}, - {0.0, 1.0, 1.0}, - {1.0, 1.0, 1.0}, - {1.0, 0.0, 1.0}, - {0.0, 0.0, 1.0} - }; - float cube[8][3] = { {0.5, 0.5, -0.5}, - {0.5, -0.5, -0.5}, - {-0.5, -0.5, -0.5}, - {-0.5, 0.5, -0.5}, - {-0.5, 0.5, 0.5}, - {0.5, 0.5, 0.5}, - {0.5, -0.5, 0.5}, - {-0.5, -0.5, 0.5} - }; - Uint32 video_flags; - int value; - - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); - } - - /* See if we should detect the display depth */ - if (bpp == 0) { - if (SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8) { - bpp = 8; - } else { - bpp = 16; /* More doesn't seem to work */ - } - } - - /* Set the flags we want to use for setting the video mode */ - video_flags = SDL_OPENGL; - for (i = 1; argv[i]; ++i) { - if (strcmp(argv[i], "-fullscreen") == 0) { - video_flags |= SDL_FULLSCREEN; - } - } - - if (noframe) { - video_flags |= SDL_NOFRAME; - } - - /* Initialize the display */ - switch (bpp) { - case 8: - rgb_size[0] = 3; - rgb_size[1] = 3; - rgb_size[2] = 2; - break; - case 15: - case 16: - rgb_size[0] = 5; - rgb_size[1] = 5; - rgb_size[2] = 5; - break; - default: - rgb_size[0] = 8; - rgb_size[1] = 8; - rgb_size[2] = 8; - break; - } - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (fsaa) { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); - } - if (accel >= 0) { - SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, accel); - } - if (SDL_SetVideoMode(w, h, bpp, video_flags) == NULL) { - fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); - SDL_Quit(); - exit(1); - } - if (sync) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - - printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel); - printf("\n"); - printf("Vendor : %s\n", glGetString(GL_VENDOR)); - printf("Renderer : %s\n", glGetString(GL_RENDERER)); - printf("Version : %s\n", glGetString(GL_VERSION)); - printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); - printf("\n"); - - SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); - printf("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); - SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); - printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1], value); - SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); - printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value); - SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); - printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value); - SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value); - printf("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); - if (fsaa) { - SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); - printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); - SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); - printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, - value); - } - if (accel >= 0) { - SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); - printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel, - value); - } - if (sync) { - printf("Buffer swap interval: requested 1, got %d\n", - SDL_GL_GetSwapInterval()); - } - - /* Set the window manager title bar */ - SDL_WM_SetCaption("SDL GL test", "testgl"); - - /* Set the gamma for the window */ - if (gamma != 0.0) { - SDL_SetGamma(gamma, gamma, gamma); - } - - glViewport(0, 0, w, h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glEnable(GL_DEPTH_TEST); - - glDepthFunc(GL_LESS); - - glShadeModel(GL_SMOOTH); - - /* Loop until done. */ - start_time = SDL_GetTicks(); - frames = 0; - while (!done) { - GLenum gl_error; - char *sdl_error; - SDL_Event event; - - /* Do our drawing, too. */ - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glBegin(GL_QUADS); - -#ifdef SHADED_CUBE - glColor3fv(color[0]); - glVertex3fv(cube[0]); - glColor3fv(color[1]); - glVertex3fv(cube[1]); - glColor3fv(color[2]); - glVertex3fv(cube[2]); - glColor3fv(color[3]); - glVertex3fv(cube[3]); - - glColor3fv(color[3]); - glVertex3fv(cube[3]); - glColor3fv(color[4]); - glVertex3fv(cube[4]); - glColor3fv(color[7]); - glVertex3fv(cube[7]); - glColor3fv(color[2]); - glVertex3fv(cube[2]); - - glColor3fv(color[0]); - glVertex3fv(cube[0]); - glColor3fv(color[5]); - glVertex3fv(cube[5]); - glColor3fv(color[6]); - glVertex3fv(cube[6]); - glColor3fv(color[1]); - glVertex3fv(cube[1]); - - glColor3fv(color[5]); - glVertex3fv(cube[5]); - glColor3fv(color[4]); - glVertex3fv(cube[4]); - glColor3fv(color[7]); - glVertex3fv(cube[7]); - glColor3fv(color[6]); - glVertex3fv(cube[6]); - - glColor3fv(color[5]); - glVertex3fv(cube[5]); - glColor3fv(color[0]); - glVertex3fv(cube[0]); - glColor3fv(color[3]); - glVertex3fv(cube[3]); - glColor3fv(color[4]); - glVertex3fv(cube[4]); - - glColor3fv(color[6]); - glVertex3fv(cube[6]); - glColor3fv(color[1]); - glVertex3fv(cube[1]); - glColor3fv(color[2]); - glVertex3fv(cube[2]); - glColor3fv(color[7]); - glVertex3fv(cube[7]); -#else /* flat cube */ - glColor3f(1.0, 0.0, 0.0); - glVertex3fv(cube[0]); - glVertex3fv(cube[1]); - glVertex3fv(cube[2]); - glVertex3fv(cube[3]); - - glColor3f(0.0, 1.0, 0.0); - glVertex3fv(cube[3]); - glVertex3fv(cube[4]); - glVertex3fv(cube[7]); - glVertex3fv(cube[2]); - - glColor3f(0.0, 0.0, 1.0); - glVertex3fv(cube[0]); - glVertex3fv(cube[5]); - glVertex3fv(cube[6]); - glVertex3fv(cube[1]); - - glColor3f(0.0, 1.0, 1.0); - glVertex3fv(cube[5]); - glVertex3fv(cube[4]); - glVertex3fv(cube[7]); - glVertex3fv(cube[6]); - - glColor3f(1.0, 1.0, 0.0); - glVertex3fv(cube[5]); - glVertex3fv(cube[0]); - glVertex3fv(cube[3]); - glVertex3fv(cube[4]); - - glColor3f(1.0, 0.0, 1.0); - glVertex3fv(cube[6]); - glVertex3fv(cube[1]); - glVertex3fv(cube[2]); - glVertex3fv(cube[7]); -#endif /* SHADED_CUBE */ - - glEnd(); - - glMatrixMode(GL_MODELVIEW); - glRotatef(5.0, 1.0, 1.0, 1.0); - - /* Draw 2D logo onto the 3D display */ - if (logo) { - DrawLogoTexture(); - } - if (logocursor) { - DrawLogoCursor(); - } - - SDL_GL_SwapBuffers(); - - /* Check for error conditions. */ - gl_error = glGetError(); - - if (gl_error != GL_NO_ERROR) { - fprintf(stderr, "testgl: OpenGL error: %d\n", gl_error); - } - - sdl_error = (char *)SDL_GetError(); - - if (sdl_error[0] != '\0') { - fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error); - SDL_ClearError(); - } - - /* Allow the user to see what's happening */ - if (slowly) { - SDL_Delay(20); - } - - /* Check if there's a pending event. */ - while (SDL_PollEvent(&event)) { - done |= HandleEvent(&event); - } - ++frames; - } - - /* Print out the frames per second */ - this_time = SDL_GetTicks(); - if (this_time != start_time) { - printf("%2.2f FPS\n", - ((float) frames / (this_time - start_time)) * 1000.0); - } - - if (global_image) { - SDL_FreeSurface(global_image); - global_image = NULL; - } - if (global_texture) { - glDeleteTextures(1, &global_texture); - global_texture = 0; - } - if (cursor_texture) { - glDeleteTextures(1, &cursor_texture); - cursor_texture = 0; - } - - /* Destroy our GL context, etc. */ - SDL_Quit(); - return (0); -} - -int -main(int argc, char *argv[]) -{ - int i, logo, logocursor = 0; - int numtests; - int bpp = 0; - int slowly; - float gamma = 0.0; - int noframe = 0; - int fsaa = 0; - int accel = -1; - int sync = 0; - - logo = 0; - slowly = 0; - numtests = 1; - for (i = 1; argv[i]; ++i) { - if (strcmp(argv[i], "-twice") == 0) { - ++numtests; - } - if (strcmp(argv[i], "-logo") == 0) { - logo = 1; - } - if (strcmp(argv[i], "-logocursor") == 0) { - logocursor = 1; - } - if (strcmp(argv[i], "-slow") == 0) { - slowly = 1; - } - if (strcmp(argv[i], "-bpp") == 0) { - bpp = atoi(argv[++i]); - } - if (strcmp(argv[i], "-gamma") == 0) { - gamma = (float) atof(argv[++i]); - } - if (strcmp(argv[i], "-noframe") == 0) { - noframe = 1; - } - if (strcmp(argv[i], "-fsaa") == 0) { - ++fsaa; - } - if (strcmp(argv[i], "-accel") == 0) { - accel = atoi(argv[++i]); - } - if (strcmp(argv[i], "-sync") == 0) { - ++sync; - } - if (strncmp(argv[i], "-h", 2) == 0) { - printf - ("Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-accel n] [-sync] [-fullscreen]\n", - argv[0]); - exit(0); - } - } - for (i = 0; i < numtests; ++i) { - RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, - noframe, fsaa, sync, accel); - } - return 0; -} - -#else /* HAVE_OPENGL */ - -int -main(int argc, char *argv[]) -{ - printf("No OpenGL support on this system\n"); - return 1; -} - -#endif /* HAVE_OPENGL */ diff --git a/test/testime.c b/test/testime.c index 7c2efe68b..a10390c33 100644 --- a/test/testime.c +++ b/test/testime.c @@ -11,6 +11,15 @@ */ /* A simple program to test the Input Method support in the SDL library (2.0+) */ +#if 1 /* FIXME: Rework this using the 2.0 API */ +#include + +int main(int argc, char *argv[]) +{ + printf("FIXME\n"); + return 0; +} +#else #include #include #include @@ -383,5 +392,6 @@ int main(int argc, char *argv[]) CleanupVideo(); return 0; } +#endif /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testjoystick.c b/test/testjoystick.c index 43f38bdc2..e514f1c42 100644 --- a/test/testjoystick.c +++ b/test/testjoystick.c @@ -12,6 +12,15 @@ /* Simple program to test the SDL joystick routines */ +#if 1 /* FIXME: Rework this using the 2.0 API */ +#include + +int main(int argc, char *argv[]) +{ + printf("FIXME\n"); + return 0; +} +#else #include #include #include @@ -202,3 +211,4 @@ main(int argc, char *argv[]) return (0); } +#endif diff --git a/test/testnative.c b/test/testnative.c index 6e9b24916..ec66c18aa 100644 --- a/test/testnative.c +++ b/test/testnative.c @@ -62,7 +62,7 @@ LoadSprite(SDL_Renderer *renderer, char *file) /* Set transparent pixel as the pixel at (0,0) */ if (temp->format->palette) { - SDL_SetColorKey(temp, SDL_SRCCOLORKEY, *(Uint8 *) temp->pixels); + SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels); } /* Create textures from the image */ diff --git a/test/testoverlay.c b/test/testoverlay.c deleted file mode 100644 index 231cdf063..000000000 --- a/test/testoverlay.c +++ /dev/null @@ -1,571 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ - -/* Bring up a window and play with it */ - -#include -#include -#include - -#define BENCHMARK_SDL - -#define NOTICE(X) printf("%s", X); - -#define WINDOW_WIDTH 640 -#define WINDOW_HEIGHT 480 - -#include "SDL.h" - -SDL_Surface *screen, *pic; -SDL_Overlay *overlay; -int scale; -int monochrome; -int luminance; -int w, h; - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -/* NOTE: These RGB conversion functions are not intended for speed, - only as examples. -*/ - -void -RGBtoYUV(Uint8 * rgb, int *yuv, int monochrome, int luminance) -{ - if (monochrome) { -#if 1 /* these are the two formulas that I found on the FourCC site... */ - yuv[0] = (int)(0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]); - yuv[1] = 128; - yuv[2] = 128; -#else - yuv[0] = (int)((0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16); - yuv[1] = 128; - yuv[2] = 128; -#endif - } else { -#if 1 /* these are the two formulas that I found on the FourCC site... */ - yuv[0] = (int)(0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]); - yuv[1] = (int)((rgb[2] - yuv[0]) * 0.565 + 128); - yuv[2] = (int)((rgb[0] - yuv[0]) * 0.713 + 128); -#else - yuv[0] = (int)((0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16); - yuv[1] = (int)(128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2])); - yuv[2] = (int)(128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2])); -#endif - } - - if (luminance != 100) { - yuv[0] = yuv[0] * luminance / 100; - if (yuv[0] > 255) - yuv[0] = 255; - } - - /* clamp values...if you need to, we don't seem to have a need */ - /* - for(i=0;i<3;i++) - { - if(yuv[i]<0) - yuv[i]=0; - if(yuv[i]>255) - yuv[i]=255; - } - */ -} - -void -ConvertRGBtoYV12(SDL_Surface * s, SDL_Overlay * o, int monochrome, - int luminance) -{ - int x, y; - int yuv[3]; - Uint8 *p, *op[3]; - - SDL_LockSurface(s); - SDL_LockYUVOverlay(o); - - /* Black initialization */ - /* - memset(o->pixels[0],0,o->pitches[0]*o->h); - memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); - memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2)); - */ - - /* Convert */ - for (y = 0; y < s->h && y < o->h; y++) { - p = ((Uint8 *) s->pixels) + s->pitch * y; - op[0] = o->pixels[0] + o->pitches[0] * y; - op[1] = o->pixels[1] + o->pitches[1] * (y / 2); - op[2] = o->pixels[2] + o->pitches[2] * (y / 2); - for (x = 0; x < s->w && x < o->w; x++) { - RGBtoYUV(p, yuv, monochrome, luminance); - *(op[0]++) = yuv[0]; - if (x % 2 == 0 && y % 2 == 0) { - *(op[1]++) = yuv[2]; - *(op[2]++) = yuv[1]; - } - p += s->format->BytesPerPixel; - } - } - - SDL_UnlockYUVOverlay(o); - SDL_UnlockSurface(s); -} - -void -ConvertRGBtoIYUV(SDL_Surface * s, SDL_Overlay * o, int monochrome, - int luminance) -{ - int x, y; - int yuv[3]; - Uint8 *p, *op[3]; - - SDL_LockSurface(s); - SDL_LockYUVOverlay(o); - - /* Black initialization */ - /* - memset(o->pixels[0],0,o->pitches[0]*o->h); - memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); - memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2)); - */ - - /* Convert */ - for (y = 0; y < s->h && y < o->h; y++) { - p = ((Uint8 *) s->pixels) + s->pitch * y; - op[0] = o->pixels[0] + o->pitches[0] * y; - op[1] = o->pixels[1] + o->pitches[1] * (y / 2); - op[2] = o->pixels[2] + o->pitches[2] * (y / 2); - for (x = 0; x < s->w && x < o->w; x++) { - RGBtoYUV(p, yuv, monochrome, luminance); - *(op[0]++) = yuv[0]; - if (x % 2 == 0 && y % 2 == 0) { - *(op[1]++) = yuv[1]; - *(op[2]++) = yuv[2]; - } - p += s->format->BytesPerPixel; - } - } - - SDL_UnlockYUVOverlay(o); - SDL_UnlockSurface(s); -} - -void -ConvertRGBtoUYVY(SDL_Surface * s, SDL_Overlay * o, int monochrome, - int luminance) -{ - int x, y; - int yuv[3]; - Uint8 *p, *op; - - SDL_LockSurface(s); - SDL_LockYUVOverlay(o); - - for (y = 0; y < s->h && y < o->h; y++) { - p = ((Uint8 *) s->pixels) + s->pitch * y; - op = o->pixels[0] + o->pitches[0] * y; - for (x = 0; x < s->w && x < o->w; x++) { - RGBtoYUV(p, yuv, monochrome, luminance); - if (x % 2 == 0) { - *(op++) = yuv[1]; - *(op++) = yuv[0]; - *(op++) = yuv[2]; - } else - *(op++) = yuv[0]; - - p += s->format->BytesPerPixel; - } - } - - SDL_UnlockYUVOverlay(o); - SDL_UnlockSurface(s); -} - -void -ConvertRGBtoYVYU(SDL_Surface * s, SDL_Overlay * o, int monochrome, - int luminance) -{ - int x, y; - int yuv[3]; - Uint8 *p, *op; - - SDL_LockSurface(s); - SDL_LockYUVOverlay(o); - - for (y = 0; y < s->h && y < o->h; y++) { - p = ((Uint8 *) s->pixels) + s->pitch * y; - op = o->pixels[0] + o->pitches[0] * y; - for (x = 0; x < s->w && x < o->w; x++) { - RGBtoYUV(p, yuv, monochrome, luminance); - if (x % 2 == 0) { - *(op++) = yuv[0]; - *(op++) = yuv[2]; - op[1] = yuv[1]; - } else { - *op = yuv[0]; - op += 2; - } - - p += s->format->BytesPerPixel; - } - } - - SDL_UnlockYUVOverlay(o); - SDL_UnlockSurface(s); -} - -void -ConvertRGBtoYUY2(SDL_Surface * s, SDL_Overlay * o, int monochrome, - int luminance) -{ - int x, y; - int yuv[3]; - Uint8 *p, *op; - - SDL_LockSurface(s); - SDL_LockYUVOverlay(o); - - for (y = 0; y < s->h && y < o->h; y++) { - p = ((Uint8 *) s->pixels) + s->pitch * y; - op = o->pixels[0] + o->pitches[0] * y; - for (x = 0; x < s->w && x < o->w; x++) { - RGBtoYUV(p, yuv, monochrome, luminance); - if (x % 2 == 0) { - *(op++) = yuv[0]; - *(op++) = yuv[1]; - op[1] = yuv[2]; - } else { - *op = yuv[0]; - op += 2; - } - - p += s->format->BytesPerPixel; - } - } - - SDL_UnlockYUVOverlay(o); - SDL_UnlockSurface(s); -} - -void -Draw() -{ - SDL_Rect rect; - int i; - int disp; - - if (!scale) { - rect.w = overlay->w; - rect.h = overlay->h; - for (i = 0; i < h - rect.h && i < w - rect.w; i++) { - rect.x = i; - rect.y = i; - SDL_DisplayYUVOverlay(overlay, &rect); - } - } else { - rect.w = overlay->w / 2; - rect.h = overlay->h / 2; - rect.x = (w - rect.w) / 2; - rect.y = (h - rect.h) / 2; - disp = rect.y - 1; - for (i = 0; i < disp; i++) { - rect.w += 2; - rect.h += 2; - rect.x--; - rect.y--; - SDL_DisplayYUVOverlay(overlay, &rect); - } - } - printf("Displayed %d times.\n", i); -} - -static void -PrintUsage(char *argv0) -{ - fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0); - fprintf(stderr, "Where 'arg' is one of:\n"); - fprintf(stderr, " -delay \n"); - fprintf(stderr, " -width \n"); - fprintf(stderr, " -height \n"); - fprintf(stderr, " -bpp \n"); - fprintf(stderr, - " -format (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n"); - fprintf(stderr, " -hw\n"); - fprintf(stderr, " -flip\n"); - fprintf(stderr, - " -scale (test scaling features, from 50%% upto window size)\n"); - fprintf(stderr, " -mono (use monochromatic RGB2YUV conversion)\n"); - fprintf(stderr, - " -lum (use luminance correction during RGB2YUV conversion,\n"); - fprintf(stderr, - " from 0%% to unlimited, normal is 100%%)\n"); - fprintf(stderr, " -help (shows this help)\n"); - fprintf(stderr, " -fullscreen (test overlay in fullscreen mode)\n"); -} - -int -main(int argc, char **argv) -{ - char *argv0 = argv[0]; - int flip; - int delay; - int desired_bpp; - Uint32 video_flags, overlay_format; - char *bmpfile; -#ifdef BENCHMARK_SDL - Uint32 then, now; -#endif - int i; - - /* Set default options and check command-line */ - flip = 0; - scale = 0; - monochrome = 0; - luminance = 100; - delay = 1; - w = WINDOW_WIDTH; - h = WINDOW_HEIGHT; - desired_bpp = 0; - video_flags = 0; - overlay_format = SDL_YV12_OVERLAY; - - while (argc > 1) { - if (strcmp(argv[1], "-delay") == 0) { - if (argv[2]) { - delay = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -delay option requires an argument\n"); - return (1); - } - } else if (strcmp(argv[1], "-width") == 0) { - if (argv[2] && ((w = atoi(argv[2])) > 0)) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -width option requires an argument\n"); - return (1); - } - } else if (strcmp(argv[1], "-height") == 0) { - if (argv[2] && ((h = atoi(argv[2])) > 0)) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -height option requires an argument\n"); - return (1); - } - } else if (strcmp(argv[1], "-bpp") == 0) { - if (argv[2]) { - desired_bpp = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -bpp option requires an argument\n"); - return (1); - } - } else if (strcmp(argv[1], "-lum") == 0) { - if (argv[2]) { - luminance = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -lum option requires an argument\n"); - return (1); - } - } else if (strcmp(argv[1], "-format") == 0) { - if (argv[2]) { - if (!strcmp(argv[2], "YV12")) - overlay_format = SDL_YV12_OVERLAY; - else if (!strcmp(argv[2], "IYUV")) - overlay_format = SDL_IYUV_OVERLAY; - else if (!strcmp(argv[2], "YUY2")) - overlay_format = SDL_YUY2_OVERLAY; - else if (!strcmp(argv[2], "UYVY")) - overlay_format = SDL_UYVY_OVERLAY; - else if (!strcmp(argv[2], "YVYU")) - overlay_format = SDL_YVYU_OVERLAY; - else { - fprintf(stderr, - "The -format option %s is not recognized\n", - argv[2]); - return (1); - } - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -format option requires an argument\n"); - return (1); - } - } else if (strcmp(argv[1], "-hw") == 0) { - video_flags |= SDL_HWSURFACE; - argv += 1; - argc -= 1; - } else if (strcmp(argv[1], "-flip") == 0) { - video_flags |= SDL_DOUBLEBUF; - argv += 1; - argc -= 1; - } else if (strcmp(argv[1], "-scale") == 0) { - scale = 1; - argv += 1; - argc -= 1; - } else if (strcmp(argv[1], "-mono") == 0) { - monochrome = 1; - argv += 1; - argc -= 1; - } else if ((strcmp(argv[1], "-help") == 0) - || (strcmp(argv[1], "-h") == 0)) { - PrintUsage(argv0); - return (1); - } else if (strcmp(argv[1], "-fullscreen") == 0) { - video_flags |= SDL_FULLSCREEN; - argv += 1; - argc -= 1; - } else - break; - } - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - /* Initialize the display */ - screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); - if (screen == NULL) { - fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", - w, h, desired_bpp, SDL_GetError()); - quit(1); - } - printf("Set%s %dx%dx%d mode\n", - screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", - screen->w, screen->h, screen->format->BitsPerPixel); - printf("(video surface located in %s memory)\n", - (screen->flags & SDL_HWSURFACE) ? "video" : "system"); - if (screen->flags & SDL_DOUBLEBUF) { - printf("Double-buffering enabled\n"); - flip = 1; - } - - /* Set the window manager title bar */ - SDL_WM_SetCaption("SDL test overlay", "testoverlay"); - - /* Load picture */ - bmpfile = (argv[1] ? argv[1] : "sample.bmp"); - pic = SDL_LoadBMP(bmpfile); - if (pic == NULL) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - quit(1); - } - - /* Convert the picture to 32bits, for easy conversion */ - { - SDL_Surface *newsurf; - SDL_PixelFormat format; - - format.palette = NULL; - format.BitsPerPixel = 32; - format.BytesPerPixel = 4; -#if SDL_BYTEORDER == SDL_LIL_ENDIAN - format.Rshift = 0; - format.Gshift = 8; - format.Bshift = 16; -#else - format.Rshift = 24; - format.Gshift = 16; - format.Bshift = 8; -#endif - format.Ashift = 0; - format.Rmask = 0xff << format.Rshift; - format.Gmask = 0xff << format.Gshift; - format.Bmask = 0xff << format.Bshift; - format.Amask = 0; - format.Rloss = 0; - format.Gloss = 0; - format.Bloss = 0; - format.Aloss = 8; - - newsurf = SDL_ConvertSurface(pic, &format, SDL_SWSURFACE); - if (!newsurf) { - fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", - SDL_GetError()); - quit(1); - } - SDL_FreeSurface(pic); - pic = newsurf; - } - - /* Create the overlay */ - overlay = SDL_CreateYUVOverlay(pic->w, pic->h, overlay_format, screen); - if (overlay == NULL) { - fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError()); - quit(1); - } - printf("Created %dx%dx%d %s %s overlay\n", overlay->w, overlay->h, - overlay->planes, overlay->hw_overlay ? "hardware" : "software", - overlay->format == SDL_YV12_OVERLAY ? "YV12" : overlay->format == - SDL_IYUV_OVERLAY ? "IYUV" : overlay->format == - SDL_YUY2_OVERLAY ? "YUY2" : overlay->format == - SDL_UYVY_OVERLAY ? "UYVY" : overlay->format == - SDL_YVYU_OVERLAY ? "YVYU" : "Unknown"); - for (i = 0; i < overlay->planes; i++) { - printf(" plane %d: pitch=%d\n", i, overlay->pitches[i]); - } - - /* Convert to YUV, and draw to the overlay */ -#ifdef BENCHMARK_SDL - then = SDL_GetTicks(); -#endif - switch (overlay->format) { - case SDL_YV12_OVERLAY: - ConvertRGBtoYV12(pic, overlay, monochrome, luminance); - break; - case SDL_UYVY_OVERLAY: - ConvertRGBtoUYVY(pic, overlay, monochrome, luminance); - break; - case SDL_YVYU_OVERLAY: - ConvertRGBtoYVYU(pic, overlay, monochrome, luminance); - break; - case SDL_YUY2_OVERLAY: - ConvertRGBtoYUY2(pic, overlay, monochrome, luminance); - break; - case SDL_IYUV_OVERLAY: - ConvertRGBtoIYUV(pic, overlay, monochrome, luminance); - break; - default: - printf("cannot convert RGB picture to obtained YUV format!\n"); - quit(1); - break; - } -#ifdef BENCHMARK_SDL - now = SDL_GetTicks(); - printf("Conversion Time: %d milliseconds\n", now - then); -#endif - - /* Do all the drawing work */ -#ifdef BENCHMARK_SDL - then = SDL_GetTicks(); -#endif - Draw(); -#ifdef BENCHMARK_SDL - now = SDL_GetTicks(); - printf("Time: %d milliseconds\n", now - then); -#endif - SDL_Delay(delay * 1000); - SDL_Quit(); - return (0); -} diff --git a/test/testoverlay2.c b/test/testoverlay2.c index 529969fba..f8d36945f 100644 --- a/test/testoverlay2.c +++ b/test/testoverlay2.c @@ -16,6 +16,15 @@ * * ********************************************************************************/ +#if 1 /* FIXME: Rework this using the 2.0 API */ +#include + +int main(int argc, char *argv[]) +{ + printf("FIXME\n"); + return 0; +} +#else #include #include #include @@ -591,5 +600,6 @@ main(int argc, char **argv) quit(0); return 0; } +#endif /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testshader.c b/test/testshader.c index 6b27c3447..5d3963652 100644 --- a/test/testshader.c +++ b/test/testshader.c @@ -11,6 +11,15 @@ */ /* This is a simple example of using GLSL shaders with SDL */ +#if 1 /* FIXME: Rework this using the 2.0 API */ +#include + +int main(int argc, char *argv[]) +{ + printf("FIXME\n"); + return 0; +} +#else #include "SDL.h" #ifdef HAVE_OPENGL @@ -494,5 +503,6 @@ main(int argc, char *argv[]) } #endif /* HAVE_OPENGL */ +#endif /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testsprite.c b/test/testsprite.c deleted file mode 100644 index 1d2a42af1..000000000 --- a/test/testsprite.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ -/* Simple program: Move N sprites around on the screen as fast as possible */ - -#include -#include -#include -#include -#include -#include - -#include "SDL.h" - -#define NUM_SPRITES 100 -#define MAX_SPEED 1 - -SDL_Surface *sprite; -int numsprites; -SDL_Rect *sprite_rects; -SDL_Rect *positions; -SDL_Rect *velocities; -int sprites_visible; -int debug_flip; -Uint16 sprite_w, sprite_h; - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -int -LoadSprite(char *file) -{ - SDL_Surface *temp; - - /* Load the sprite image */ - sprite = SDL_LoadBMP(file); - if (sprite == NULL) { - fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); - return (-1); - } - - /* Set transparent pixel as the pixel at (0,0) */ - if (sprite->format->palette) { - SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY | SDL_RLEACCEL), - *(Uint8 *) sprite->pixels); - } - - /* Convert sprite to video format */ - temp = SDL_DisplayFormat(sprite); - SDL_FreeSurface(sprite); - if (temp == NULL) { - fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError()); - return (-1); - } - sprite = temp; - - /* We're ready to roll. :) */ - return (0); -} - -void -MoveSprites(SDL_Surface * screen, Uint32 background) -{ - int i, nupdates; - SDL_Rect area, *position, *velocity; - - nupdates = 0; - /* Erase all the sprites if necessary */ - if (sprites_visible) { - SDL_FillRect(screen, NULL, background); - } - - /* Move the sprite, bounce at the wall, and draw */ - for (i = 0; i < numsprites; ++i) { - position = &positions[i]; - velocity = &velocities[i]; - position->x += velocity->x; - if ((position->x < 0) || (position->x >= (screen->w - sprite_w))) { - velocity->x = -velocity->x; - position->x += velocity->x; - } - position->y += velocity->y; - if ((position->y < 0) || (position->y >= (screen->h - sprite_w))) { - velocity->y = -velocity->y; - position->y += velocity->y; - } - - /* Blit the sprite onto the screen */ - area = *position; - SDL_BlitSurface(sprite, NULL, screen, &area); - sprite_rects[nupdates++] = area; - } - - if (debug_flip) { - if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { - static int t = 0; - - Uint32 color = SDL_MapRGB(screen->format, 255, 0, 0); - SDL_Rect r; - r.x = - (int)((sin((float) t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w - 20)); - r.y = 0; - r.w = 20; - r.h = screen->h; - - SDL_FillRect(screen, &r, color); - t += 2; - } - } - - /* Update the screen! */ - if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { - SDL_Flip(screen); - } else { - SDL_UpdateRects(screen, nupdates, sprite_rects); - } - sprites_visible = 1; -} - -/* This is a way of telling whether or not to use hardware surfaces */ -Uint32 -FastestFlags(Uint32 flags, int width, int height, int bpp) -{ - const SDL_VideoInfo *info; - - /* Hardware acceleration is only used in fullscreen mode */ - flags |= SDL_FULLSCREEN; - - /* Check for various video capabilities */ - info = SDL_GetVideoInfo(); - if (info->blit_hw_CC && info->blit_fill) { - /* We use accelerated colorkeying and color filling */ - flags |= SDL_HWSURFACE; - } - /* If we have enough video memory, and will use accelerated - blits directly to it, then use page flipping. - */ - if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) { - /* Direct hardware blitting without double-buffering - causes really bad flickering. - */ - if (info->video_mem * 1024 > (Uint32)(height * width * bpp / 8)) { - flags |= SDL_DOUBLEBUF; - } else { - flags &= ~SDL_HWSURFACE; - } - } - - /* Return the flags */ - return (flags); -} - -int -main(int argc, char *argv[]) -{ - SDL_Surface *screen; - Uint8 *mem; - int width, height; - Uint8 video_bpp; - Uint32 videoflags; - Uint32 background; - int i, done; - SDL_Event event; - Uint32 then, now, frames; - - /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - numsprites = NUM_SPRITES; - videoflags = SDL_SWSURFACE | SDL_ANYFORMAT | SDL_RESIZABLE; - width = 640; - height = 480; - video_bpp = 8; - debug_flip = 0; - while (argc > 1) { - --argc; - if (strcmp(argv[argc - 1], "-width") == 0) { - width = atoi(argv[argc]); - --argc; - } else if (strcmp(argv[argc - 1], "-height") == 0) { - height = atoi(argv[argc]); - --argc; - } else if (strcmp(argv[argc - 1], "-bpp") == 0) { - video_bpp = atoi(argv[argc]); - videoflags &= ~SDL_ANYFORMAT; - --argc; - } else if (strcmp(argv[argc], "-fast") == 0) { - videoflags = FastestFlags(videoflags, width, height, video_bpp); - } else if (strcmp(argv[argc], "-hw") == 0) { - videoflags ^= SDL_HWSURFACE; - } else if (strcmp(argv[argc], "-flip") == 0) { - videoflags ^= SDL_DOUBLEBUF; - } else if (strcmp(argv[argc], "-debugflip") == 0) { - debug_flip ^= 1; - } else if (strcmp(argv[argc], "-fullscreen") == 0) { - videoflags ^= SDL_FULLSCREEN; - } else if (isdigit(argv[argc][0])) { - numsprites = atoi(argv[argc]); - } else { - fprintf(stderr, - "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n", - argv[0]); - quit(1); - } - } - - /* Set video mode */ - screen = SDL_SetVideoMode(width, height, video_bpp, videoflags); - if (!screen) { - fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", - width, height, SDL_GetError()); - quit(2); - } - - /* Load the sprite */ - if (LoadSprite("icon.bmp") < 0) { - quit(1); - } - - /* Allocate memory for the sprite info */ - mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites); - if (mem == NULL) { - SDL_FreeSurface(sprite); - fprintf(stderr, "Out of memory!\n"); - quit(2); - } - sprite_rects = (SDL_Rect *) mem; - positions = sprite_rects; - sprite_rects += numsprites; - velocities = sprite_rects; - sprite_rects += numsprites; - sprite_w = sprite->w; - sprite_h = sprite->h; - srand((unsigned int)time(NULL)); - for (i = 0; i < numsprites; ++i) { - positions[i].x = rand() % (screen->w - sprite_w); - positions[i].y = rand() % (screen->h - sprite_h); - positions[i].w = sprite->w; - positions[i].h = sprite->h; - velocities[i].x = 0; - velocities[i].y = 0; - while (!velocities[i].x && !velocities[i].y) { - velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; - velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; - } - } - - /* Clear the background to grey */ - background = SDL_MapRGB(screen->format, 0xA0, 0xA0, 0xA0); - SDL_FillRect(screen, NULL, background); - SDL_Flip(screen); - - /* Print out information about our surfaces */ - printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel); - if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { - printf("Screen is in video memory\n"); - } else { - printf("Screen is in system memory\n"); - } - if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { - printf("Screen has double-buffering enabled\n"); - } - if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { - printf("Sprite is in video memory\n"); - } else { - printf("Sprite is in system memory\n"); - } - /* Run a sample blit to trigger blit acceleration */ - { - SDL_Rect dst; - dst.x = 0; - dst.y = 0; - dst.w = sprite->w; - dst.h = sprite->h; - SDL_BlitSurface(sprite, NULL, screen, &dst); - SDL_FillRect(screen, &dst, background); - } - if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) { - printf("Sprite blit uses hardware acceleration\n"); - } - if ((sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { - printf("Sprite blit uses RLE acceleration\n"); - } - - /* Loop, blitting sprites and waiting for a keystroke */ - frames = 0; - then = SDL_GetTicks(); - done = 0; - sprites_visible = 0; - while (!done) { - /* Check for events */ - ++frames; - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_VIDEORESIZE: - screen = SDL_SetVideoMode(event.resize.w, event.resize.h, video_bpp, videoflags); - break; - case SDL_MOUSEBUTTONDOWN: - SDL_WarpMouse(screen->w / 2, screen->h / 2); - break; - case SDL_KEYDOWN: - /* Any keypress quits the app... */ - case SDL_QUIT: - done = 1; - break; - default: - break; - } - } - MoveSprites(screen, background); - } - SDL_FreeSurface(sprite); - free(mem); - - /* Print out some timing information */ - now = SDL_GetTicks(); - if (now > then) { - double fps = ((double) frames * 1000) / (now - then); - printf("%2.2f frames per second\n", fps); - } - SDL_Quit(); - return (0); -} diff --git a/test/testtimer.c b/test/testtimer.c index 910e889c0..13d94490d 100644 --- a/test/testtimer.c +++ b/test/testtimer.c @@ -14,6 +14,15 @@ platform */ +#if 1 /* FIXME: Rework this using the 2.0 API */ +#include + +int main(int argc, char *argv[]) +{ + printf("FIXME\n"); + return 0; +} +#else #include #include @@ -107,5 +116,6 @@ main(int argc, char *argv[]) SDL_Quit(); return (0); } +#endif /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testvidinfo.c b/test/testvidinfo.c deleted file mode 100644 index 0c2b8a597..000000000 --- a/test/testvidinfo.c +++ /dev/null @@ -1,546 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ - -/* Simple program -- figure out what kind of video display we have */ - -#include -#include -#include -#include - -#include "SDL.h" - -#define NUM_BLITS 10 -#define NUM_UPDATES 500 - -#define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF | \ - SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCEL | \ - SDL_RLEACCELOK) - -#if 0 -void -PrintFlags(Uint32 flags) -{ - printf("0x%8.8x", (flags & FLAG_MASK)); - if (flags & SDL_HWSURFACE) { - printf(" SDL_HWSURFACE"); - } else { - printf(" SDL_SWSURFACE"); - } - if (flags & SDL_FULLSCREEN) { - printf(" | SDL_FULLSCREEN"); - } - if (flags & SDL_DOUBLEBUF) { - printf(" | SDL_DOUBLEBUF"); - } - if (flags & SDL_SRCCOLORKEY) { - printf(" | SDL_SRCCOLORKEY"); - } - if (flags & SDL_SRCALPHA) { - printf(" | SDL_SRCALPHA"); - } - if (flags & SDL_RLEACCEL) { - printf(" | SDL_RLEACCEL"); - } - if (flags & SDL_RLEACCELOK) { - printf(" | SDL_RLEACCELOK"); - } -} - -int -RunBlitTests(SDL_Surface * screen, SDL_Surface * bmp, int blitcount) -{ - int i, j; - int maxx; - int maxy; - SDL_Rect dst; - - maxx = (int) screen->w - bmp->w + 1; - maxy = (int) screen->h - bmp->h + 1; - for (i = 0; i < NUM_UPDATES; ++i) { - for (j = 0; j < blitcount; ++j) { - if (maxx) { - dst.x = rand() % maxx; - } else { - dst.x = 0; - } - if (maxy) { - dst.y = rand() % maxy; - } else { - dst.y = 0; - } - dst.w = bmp->w; - dst.h = bmp->h; - SDL_BlitSurface(bmp, NULL, screen, &dst); - } - SDL_Flip(screen); - } - - return i; -} - -int -RunModeTests(SDL_Surface * screen) -{ - Uint32 then, now; - Uint32 frames; - float seconds; - int i; - Uint8 r, g, b; - SDL_Surface *bmp, *bmpcc, *tmp; - SDL_Event event; - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - return 0; - } - - /* First test fills and screen update speed */ - printf("Running color fill and fullscreen update test\n"); - then = SDL_GetTicks(); - frames = 0; - for (i = 0; i < 256; ++i) { - r = i; - g = 0; - b = 0; - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); - SDL_Flip(screen); - ++frames; - } - for (i = 0; i < 256; ++i) { - r = 0; - g = i; - b = 0; - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); - SDL_Flip(screen); - ++frames; - } - for (i = 0; i < 256; ++i) { - r = 0; - g = 0; - b = i; - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); - SDL_Flip(screen); - ++frames; - } - now = SDL_GetTicks(); - seconds = (float) (now - then) / 1000.0f; - if (seconds > 0.0f) { - printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, - seconds, (float) frames / seconds); - } else { - printf("%d fills and flips in zero seconds!n", frames); - } - - /* clear the screen after fill test */ - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); - SDL_Flip(screen); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - return 0; - } - - /* run the generic blit test */ - bmp = SDL_LoadBMP("sample.bmp"); - if (!bmp) { - printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); - return 0; - } - printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ", - bmp->w, bmp->h, bmp->format->BitsPerPixel); - PrintFlags(bmp->flags); - printf("\n"); - then = SDL_GetTicks(); - frames = RunBlitTests(screen, bmp, NUM_BLITS); - now = SDL_GetTicks(); - seconds = (float) (now - then) / 1000.0f; - if (seconds > 0.0f) { - printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", - NUM_BLITS * frames, frames, seconds, (float) frames / seconds); - } else { - printf("%d blits / %d updates in zero seconds!\n", - NUM_BLITS * frames, frames); - } - - /* clear the screen after blit test */ - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); - SDL_Flip(screen); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - return 0; - } - - /* run the colorkeyed blit test */ - bmpcc = SDL_LoadBMP("sample.bmp"); - if (!bmpcc) { - printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); - return 0; - } - printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ", - bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); - SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, - *(Uint8 *) bmpcc->pixels); - - PrintFlags(bmpcc->flags); - printf("\n"); - then = SDL_GetTicks(); - frames = RunBlitTests(screen, bmpcc, NUM_BLITS); - now = SDL_GetTicks(); - seconds = (float) (now - then) / 1000.0f; - if (seconds > 0.0f) { - printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", - NUM_BLITS * frames, frames, seconds, (float) frames / seconds); - } else { - printf("%d cc blits / %d updates in zero seconds!\n", - NUM_BLITS * frames, frames); - } - - /* clear the screen after cc blit test */ - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); - SDL_Flip(screen); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - return 0; - } - - /* run the generic blit test */ - tmp = bmp; - bmp = SDL_DisplayFormat(bmp); - SDL_FreeSurface(tmp); - if (!bmp) { - printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); - return 0; - } - printf("Running display format blit test: %dx%d at %d bpp, flags: ", - bmp->w, bmp->h, bmp->format->BitsPerPixel); - PrintFlags(bmp->flags); - printf("\n"); - then = SDL_GetTicks(); - frames = RunBlitTests(screen, bmp, NUM_BLITS); - now = SDL_GetTicks(); - seconds = (float) (now - then) / 1000.0f; - if (seconds > 0.0f) { - printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", - NUM_BLITS * frames, frames, seconds, (float) frames / seconds); - } else { - printf("%d blits / %d updates in zero seconds!\n", - NUM_BLITS * frames, frames); - } - - /* clear the screen after blit test */ - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); - SDL_Flip(screen); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - return 0; - } - - /* run the colorkeyed blit test */ - tmp = bmpcc; - bmpcc = SDL_DisplayFormat(bmpcc); - SDL_FreeSurface(tmp); - if (!bmpcc) { - printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); - return 0; - } - printf("Running display format cc blit test: %dx%d at %d bpp, flags: ", - bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); - PrintFlags(bmpcc->flags); - printf("\n"); - then = SDL_GetTicks(); - frames = RunBlitTests(screen, bmpcc, NUM_BLITS); - now = SDL_GetTicks(); - seconds = (float) (now - then) / 1000.0f; - if (seconds > 0.0f) { - printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", - NUM_BLITS * frames, frames, seconds, (float) frames / seconds); - } else { - printf("%d cc blits / %d updates in zero seconds!\n", - NUM_BLITS * frames, frames); - } - - /* clear the screen after cc blit test */ - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); - SDL_Flip(screen); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - return 0; - } - - /* run the alpha blit test only if screen bpp>8 */ - if (bmp->format->BitsPerPixel > 8) { - SDL_FreeSurface(bmp); - bmp = SDL_LoadBMP("sample.bmp"); - SDL_SetAlpha(bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ - tmp = bmp; - bmp = SDL_DisplayFormat(bmp); - SDL_FreeSurface(tmp); - if (!bmp) { - printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); - return 0; - } - printf - ("Running display format alpha blit test: %dx%d at %d bpp, flags: ", - bmp->w, bmp->h, bmp->format->BitsPerPixel); - PrintFlags(bmp->flags); - printf("\n"); - then = SDL_GetTicks(); - frames = RunBlitTests(screen, bmp, NUM_BLITS); - now = SDL_GetTicks(); - seconds = (float) (now - then) / 1000.0f; - if (seconds > 0.0f) { - printf - ("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", - NUM_BLITS * frames, frames, seconds, - (float) frames / seconds); - } else { - printf("%d alpha blits / %d updates in zero seconds!\n", - NUM_BLITS * frames, frames); - } - } - - /* clear the screen after alpha blit test */ - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); - SDL_Flip(screen); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - return 0; - } - - /* run the cc+alpha blit test only if screen bpp>8 */ - if (bmp->format->BitsPerPixel > 8) { - SDL_FreeSurface(bmpcc); - bmpcc = SDL_LoadBMP("sample.bmp"); - SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ - SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, - *(Uint8 *) bmpcc->pixels); - tmp = bmpcc; - bmpcc = SDL_DisplayFormat(bmpcc); - SDL_FreeSurface(tmp); - if (!bmpcc) { - printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); - return 0; - } - printf - ("Running display format cc+alpha blit test: %dx%d at %d bpp, flags: ", - bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); - PrintFlags(bmpcc->flags); - printf("\n"); - then = SDL_GetTicks(); - frames = RunBlitTests(screen, bmpcc, NUM_BLITS); - now = SDL_GetTicks(); - seconds = (float) (now - then) / 1000.0f; - if (seconds > 0.0f) { - printf - ("%d cc+alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", - NUM_BLITS * frames, frames, seconds, - (float) frames / seconds); - } else { - printf("%d cc+alpha blits / %d updates in zero seconds!\n", - NUM_BLITS * frames, frames); - } - } - - SDL_FreeSurface(bmpcc); - SDL_FreeSurface(bmp); - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) - return 0; - } - return 1; -} - -void -RunVideoTests() -{ - static const struct - { - int w, h, bpp; - } mode_list[] = { - { - 640, 480, 8}, { - 640, 480, 16}, { - 640, 480, 32}, { - 800, 600, 8}, { - 800, 600, 16}, { - 800, 600, 32}, { - 1024, 768, 8}, { - 1024, 768, 16}, { - 1024, 768, 32} - }; - static const Uint32 flags[] = { - (SDL_SWSURFACE), - (SDL_SWSURFACE | SDL_FULLSCREEN), - (SDL_HWSURFACE | SDL_FULLSCREEN), - (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF) - }; - int i, j; - SDL_Surface *screen; - - /* Test out several different video mode combinations */ - SDL_WM_SetCaption("SDL Video Benchmark", "vidtest"); - SDL_ShowCursor(0); - for (i = 0; i < SDL_TABLESIZE(mode_list); ++i) { - for (j = 0; j < SDL_TABLESIZE(flags); ++j) { - printf("===================================\n"); - printf("Setting video mode: %dx%d at %d bpp, flags: ", - mode_list[i].w, mode_list[i].h, mode_list[i].bpp); - PrintFlags(flags[j]); - printf("\n"); - screen = SDL_SetVideoMode(mode_list[i].w, - mode_list[i].h, - mode_list[i].bpp, flags[j]); - if (!screen) { - printf("Setting video mode failed: %s\n", SDL_GetError()); - continue; - } - if ((screen->flags & FLAG_MASK) != flags[j]) { - printf("Flags didn't match: "); - PrintFlags(screen->flags); - printf("\n"); - continue; - } - if (!RunModeTests(screen)) { - return; - } - } - } -} -#endif - -int -main(int argc, char *argv[]) -{ - const SDL_VideoInfo *info; - int i, d, n; - const char *driver; - SDL_DisplayMode mode; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - int nmodes; - - /* Print available video drivers */ - n = SDL_GetNumVideoDrivers(); - if (n == 0) { - printf("No built-in video drivers\n"); - } else { - printf("Built-in video drivers:"); - for (i = 0; i < n; ++i) { - if (i > 0) { - printf(","); - } - printf(" %s", SDL_GetVideoDriver(i)); - } - printf("\n"); - } - - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); - } - driver = SDL_GetCurrentVideoDriver(); - if (driver) { - printf("Video driver: %s\n", driver); - } - printf("Number of displays: %d\n", SDL_GetNumVideoDisplays()); - for (d = 0; d < SDL_GetNumVideoDisplays(); ++d) { - SDL_Rect bounds; - - SDL_GetDisplayBounds(d, &bounds); - printf("Display %d: %dx%d at %d,%d\n", d, - bounds.w, bounds.h, bounds.x, bounds.y); - - SDL_GetDesktopDisplayMode(d, &mode); - SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask, - &Amask); - printf(" Current mode: %dx%d@%dHz, %d bits-per-pixel\n", mode.w, - mode.h, mode.refresh_rate, bpp); - if (Rmask || Gmask || Bmask) { - printf(" Red Mask = 0x%.8x\n", Rmask); - printf(" Green Mask = 0x%.8x\n", Gmask); - printf(" Blue Mask = 0x%.8x\n", Bmask); - if (Amask) - printf(" Alpha Mask = 0x%.8x\n", Amask); - } - - /* Print available fullscreen video modes */ - nmodes = SDL_GetNumDisplayModes(d); - if (nmodes == 0) { - printf("No available fullscreen video modes\n"); - } else { - printf(" Fullscreen video modes:\n"); - for (i = 0; i < nmodes; ++i) { - SDL_GetDisplayMode(d, i, &mode); - SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, - &Gmask, &Bmask, &Amask); - printf(" Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i, - mode.w, mode.h, mode.refresh_rate, bpp); - if (Rmask || Gmask || Bmask) { - printf(" Red Mask = 0x%.8x\n", Rmask); - printf(" Green Mask = 0x%.8x\n", Gmask); - printf(" Blue Mask = 0x%.8x\n", Bmask); - if (Amask) - printf(" Alpha Mask = 0x%.8x\n", Amask); - } - } - } - } - - info = SDL_GetVideoInfo(); - if (info->wm_available) { - printf("A window manager is available\n"); - } - if (info->hw_available) { - printf("Hardware surfaces are available (%dK video memory)\n", - info->video_mem); - } - if (info->blit_hw) { - printf("Copy blits between hardware surfaces are accelerated\n"); - } - if (info->blit_hw_CC) { - printf("Colorkey blits between hardware surfaces are accelerated\n"); - } - if (info->blit_hw_A) { - printf("Alpha blits between hardware surfaces are accelerated\n"); - } - if (info->blit_sw) { - printf - ("Copy blits from software surfaces to hardware surfaces are accelerated\n"); - } - if (info->blit_sw_CC) { - printf - ("Colorkey blits from software surfaces to hardware surfaces are accelerated\n"); - } - if (info->blit_sw_A) { - printf - ("Alpha blits from software surfaces to hardware surfaces are accelerated\n"); - } - if (info->blit_fill) { - printf("Color fills on hardware surfaces are accelerated\n"); - } - printf("Current resolution: %dx%d\n", info->current_w, info->current_h); -#if 0 - if (argv[1] && (strcmp(argv[1], "-benchmark") == 0)) { - RunVideoTests(); - } -#endif - - SDL_Quit(); - return (0); -} diff --git a/test/testwin.c b/test/testwin.c deleted file mode 100644 index f6ded45d9..000000000 --- a/test/testwin.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ - -/* Bring up a window and play with it */ - -#include -#include -#include - -#define BENCHMARK_SDL - -#define NOTICE(X) printf("%s", X); - -#include "SDL.h" - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -void -DrawPict(SDL_Surface * screen, char *bmpfile, - int speedy, int flip, int nofade) -{ - SDL_Surface *picture; - SDL_Rect dest, update; - int i, centered; - int ncolors; - SDL_Color *colors, *cmap; - - /* Load the image into a surface */ - if (bmpfile == NULL) { - bmpfile = "sample.bmp"; /* Sample image */ - } - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if (picture == NULL) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - /* Set the display colors -- on a hicolor display this is a no-op */ - if (picture->format->palette) { - ncolors = picture->format->palette->ncolors; - colors = (SDL_Color *) malloc(ncolors * sizeof(SDL_Color)); - cmap = (SDL_Color *) malloc(ncolors * sizeof(SDL_Color)); - memcpy(colors, picture->format->palette->colors, - ncolors * sizeof(SDL_Color)); - } else { - int r, g, b; - - /* Allocate 256 color palette */ - ncolors = 256; - colors = (SDL_Color *) malloc(ncolors * sizeof(SDL_Color)); - cmap = (SDL_Color *) malloc(ncolors * sizeof(SDL_Color)); - - /* Set a 3,3,2 color cube */ - for (r = 0; r < 8; ++r) { - for (g = 0; g < 8; ++g) { - for (b = 0; b < 4; ++b) { - i = ((r << 5) | (g << 2) | b); - colors[i].r = r << 5; - colors[i].g = g << 5; - colors[i].b = b << 6; - } - } - } - } - NOTICE("testwin: setting colors\n"); - if (!SDL_SetColors(screen, colors, 0, ncolors) && - (screen->format->palette != NULL)) { - fprintf(stderr, - "Warning: Couldn't set all of the colors, but SDL will map the image\n" - " (colormap fading will suffer - try the -warp option)\n"); - } - - /* Display the picture */ - if (speedy) { - SDL_Surface *displayfmt; - - fprintf(stderr, "Converting picture\n"); - displayfmt = SDL_DisplayFormat(picture); - if (displayfmt == NULL) { - fprintf(stderr, "Couldn't convert image: %s\n", SDL_GetError()); - goto done; - } - SDL_FreeSurface(picture); - picture = displayfmt; - } - printf("(image surface located in %s memory)\n", - (picture->flags & SDL_HWSURFACE) ? "video" : "system"); - centered = (screen->w - picture->w) / 2; - if (centered < 0) { - centered = 0; - } - dest.y = (screen->h - picture->h) / 2; - dest.w = picture->w; - dest.h = picture->h; - NOTICE("testwin: moving image\n"); - for (i = 0; i <= centered; ++i) { - dest.x = i; - update = dest; - if (SDL_BlitSurface(picture, NULL, screen, &update) < 0) { - fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); - break; - } - if (flip) { - SDL_Flip(screen); - } else { - SDL_UpdateRects(screen, 1, &update); - } - } - -#ifdef SCREENSHOT - if (SDL_SaveBMP(screen, "screen.bmp") < 0) - printf("Couldn't save screen: %s\n", SDL_GetError()); -#endif - -#ifndef BENCHMARK_SDL - /* Let it sit there for a while */ - SDL_Delay(5 * 1000); -#endif - /* Fade the colormap */ - if (!nofade) { - int maxstep; - SDL_Color final; - SDL_Color palcolors[256]; - struct - { - Sint16 r, g, b; - } cdist[256]; - - NOTICE("testwin: fading out...\n"); - memcpy(cmap, colors, ncolors * sizeof(SDL_Color)); - maxstep = 32 - 1; - final.r = 0xFF; - final.g = 0x00; - final.b = 0x00; - memcpy(palcolors, colors, ncolors * sizeof(SDL_Color)); - for (i = 0; i < ncolors; ++i) { - cdist[i].r = final.r - palcolors[i].r; - cdist[i].g = final.g - palcolors[i].g; - cdist[i].b = final.b - palcolors[i].b; - } - for (i = 0; i <= maxstep / 2; ++i) { /* halfway fade */ - int c; - for (c = 0; c < ncolors; ++c) { - colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep; - colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep; - colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep; - } - SDL_SetColors(screen, colors, 0, ncolors); - SDL_Delay(1); - } - final.r = 0x00; - final.g = 0x00; - final.b = 0x00; - memcpy(palcolors, colors, ncolors * sizeof(SDL_Color)); - for (i = 0; i < ncolors; ++i) { - cdist[i].r = final.r - palcolors[i].r; - cdist[i].g = final.g - palcolors[i].g; - cdist[i].b = final.b - palcolors[i].b; - } - maxstep /= 2; - for (i = 0; i <= maxstep; ++i) { /* finish fade out */ - int c; - for (c = 0; c < ncolors; ++c) { - colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep; - colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep; - colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep; - } - SDL_SetColors(screen, colors, 0, ncolors); - SDL_Delay(1); - } - for (i = 0; i < ncolors; ++i) { - colors[i].r = final.r; - colors[i].g = final.g; - colors[i].b = final.b; - } - SDL_SetColors(screen, colors, 0, ncolors); - NOTICE("testwin: fading in...\n"); - memcpy(palcolors, colors, ncolors * sizeof(SDL_Color)); - for (i = 0; i < ncolors; ++i) { - cdist[i].r = cmap[i].r - palcolors[i].r; - cdist[i].g = cmap[i].g - palcolors[i].g; - cdist[i].b = cmap[i].b - palcolors[i].b; - } - for (i = 0; i <= maxstep; ++i) { /* 32 step fade in */ - int c; - for (c = 0; c < ncolors; ++c) { - colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep; - colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep; - colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep; - } - SDL_SetColors(screen, colors, 0, ncolors); - SDL_Delay(1); - } - NOTICE("testwin: fading over\n"); - } - - done: - /* Free the picture and return */ - SDL_FreeSurface(picture); - free(colors); - free(cmap); - return; -} - -int -main(int argc, char *argv[]) -{ - SDL_Surface *screen; - /* Options */ - int speedy, flip, nofade; - int delay; - int w, h; - int desired_bpp; - Uint32 video_flags; -#ifdef BENCHMARK_SDL - Uint32 then, now; -#endif - /* Set default options and check command-line */ - speedy = 0; - flip = 0; - nofade = 0; - delay = 1; - -#ifdef _WIN32_WCE - w = 240; - h = 320; - desired_bpp = 8; - video_flags = SDL_FULLSCREEN; -#else - w = 640; - h = 480; - desired_bpp = 0; - video_flags = 0; -#endif - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - while (argc > 1) { - if (strcmp(argv[1], "-speedy") == 0) { - speedy = 1; - argv += 1; - argc -= 1; - } else if (strcmp(argv[1], "-nofade") == 0) { - nofade = 1; - argv += 1; - argc -= 1; - } else if (strcmp(argv[1], "-delay") == 0) { - if (argv[2]) { - delay = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -delay option requires an argument\n"); - quit(1); - } - } else if (strcmp(argv[1], "-width") == 0) { - if (argv[2] && ((w = atoi(argv[2])) > 0)) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -width option requires an argument\n"); - quit(1); - } - } else if (strcmp(argv[1], "-height") == 0) { - if (argv[2] && ((h = atoi(argv[2])) > 0)) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -height option requires an argument\n"); - quit(1); - } - } else if (strcmp(argv[1], "-bpp") == 0) { - if (argv[2]) { - desired_bpp = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, "The -bpp option requires an argument\n"); - quit(1); - } - } else if (strcmp(argv[1], "-warp") == 0) { - video_flags |= SDL_HWPALETTE; - argv += 1; - argc -= 1; - } else if (strcmp(argv[1], "-hw") == 0) { - video_flags |= SDL_HWSURFACE; - argv += 1; - argc -= 1; - } else if (strcmp(argv[1], "-flip") == 0) { - video_flags |= SDL_DOUBLEBUF; - argv += 1; - argc -= 1; - } else if (strcmp(argv[1], "-fullscreen") == 0) { - video_flags |= SDL_FULLSCREEN; - argv += 1; - argc -= 1; - } else - break; - } - - /* Initialize the display */ - screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); - if (screen == NULL) { - fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", - w, h, desired_bpp, SDL_GetError()); - quit(1); - } - printf("Set%s %dx%dx%d mode\n", - screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", - screen->w, screen->h, screen->format->BitsPerPixel); - printf("(video surface located in %s memory)\n", - (screen->flags & SDL_HWSURFACE) ? "video" : "system"); - if (screen->flags & SDL_DOUBLEBUF) { - printf("Double-buffering enabled\n"); - flip = 1; - } - - /* Set the window manager title bar */ - SDL_WM_SetCaption("SDL test window", "testwin"); - - /* Do all the drawing work */ -#ifdef BENCHMARK_SDL - then = SDL_GetTicks(); - DrawPict(screen, argv[1], speedy, flip, nofade); - now = SDL_GetTicks(); - printf("Time: %d milliseconds\n", now - then); -#else - DrawPict(screen, argv[1], speedy, flip, nofade); -#endif - SDL_Delay(delay * 1000); - SDL_Quit(); - return (0); -} diff --git a/test/testwm.c b/test/testwm.c deleted file mode 100644 index 56c4f49e4..000000000 --- a/test/testwm.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ - -/* Test out the window manager interaction functions */ - -#include -#include -#include - -#include "SDL.h" - -/* Is the cursor visible? */ -static int visible = 1; - -static Uint8 video_bpp; -static Uint32 video_flags; - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -int -SetVideoMode(int w, int h) -{ - SDL_Surface *screen; - int i; - Uint8 *buffer; - SDL_Color palette[256]; - - screen = SDL_SetVideoMode(w, h, video_bpp, video_flags); - if (screen == NULL) { - fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", - w, h, video_bpp, SDL_GetError()); - return (-1); - } - printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ? - "fullscreen" : "windowed"); - - /* Set the surface pixels and refresh! */ - for (i = 0; i < 256; ++i) { - palette[i].r = 255 - i; - palette[i].g = 255 - i; - palette[i].b = 255 - i; - } - SDL_SetColors(screen, palette, 0, 256); - if (SDL_LockSurface(screen) < 0) { - fprintf(stderr, "Couldn't lock display surface: %s\n", - SDL_GetError()); - return (-1); - } - buffer = (Uint8 *) screen->pixels; - for (i = 0; i < screen->h; ++i) { - memset(buffer, (i * 255) / screen->h, - screen->w * screen->format->BytesPerPixel); - buffer += screen->pitch; - } - SDL_UnlockSurface(screen); - SDL_UpdateRect(screen, 0, 0, 0, 0); - - return (0); -} - -SDL_Surface * -LoadIconSurface(char *file, Uint8 ** maskp) -{ - SDL_Surface *icon; - Uint8 *pixels; - Uint8 *mask; - int mlen, i, j; - - *maskp = NULL; - - /* Load the icon surface */ - icon = SDL_LoadBMP(file); - if (icon == NULL) { - fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); - return (NULL); - } - - /* Check width and height - if ( (icon->w%8) != 0 ) { - fprintf(stderr, "Icon width must be a multiple of 8!\n"); - SDL_FreeSurface(icon); - return(NULL); - } - */ - - - if (icon->format->palette == NULL) { - fprintf(stderr, "Icon must have a palette!\n"); - SDL_FreeSurface(icon); - return (NULL); - } - - /* Set the colorkey */ - SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *) icon->pixels)); - - /* Create the mask */ - pixels = (Uint8 *) icon->pixels; - printf("Transparent pixel: (%d,%d,%d)\n", - icon->format->palette->colors[*pixels].r, - icon->format->palette->colors[*pixels].g, - icon->format->palette->colors[*pixels].b); - mlen = (icon->w * icon->h + 7) / 8; - mask = (Uint8 *) malloc(mlen); - if (mask == NULL) { - fprintf(stderr, "Out of memory!\n"); - SDL_FreeSurface(icon); - return (NULL); - } - memset(mask, 0, mlen); - for (i = 0; i < icon->h; i++) - for (j = 0; j < icon->w; j++) { - int pindex = i * icon->pitch + j; - int mindex = i * icon->w + j; - if (pixels[pindex] != *pixels) - mask[mindex >> 3] |= 1 << (7 - (mindex & 7)); - } - *maskp = mask; - return (icon); -} - -void -HotKey_ToggleFullScreen(void) -{ - SDL_Surface *screen; - - screen = SDL_GetVideoSurface(); - if (SDL_WM_ToggleFullScreen(screen)) { - printf("Toggled fullscreen mode - now %s\n", - (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); - } else { - printf("Unable to toggle fullscreen mode\n"); - video_flags ^= SDL_FULLSCREEN; - SetVideoMode(screen->w, screen->h); - } -} - -void -HotKey_ToggleGrab(void) -{ - SDL_GrabMode mode; - - printf("Ctrl-G: toggling input grab!\n"); - mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); - if (mode == SDL_GRAB_ON) { - printf("Grab was on\n"); - } else { - printf("Grab was off\n"); - } - mode = SDL_WM_GrabInput(mode ? SDL_GRAB_OFF : SDL_GRAB_ON); - if (mode == SDL_GRAB_ON) { - printf("Grab is now on\n"); - } else { - printf("Grab is now off\n"); - } -} - -void -HotKey_Iconify(void) -{ - printf("Ctrl-Z: iconifying window!\n"); - SDL_WM_IconifyWindow(); -} - -void -HotKey_Quit(void) -{ - SDL_Event event; - - printf("Posting internal quit request\n"); - event.type = SDL_USEREVENT; - SDL_PushEvent(&event); -} - - -static void -print_modifiers(void) -{ - int mod; - printf(" modifiers:"); - mod = SDL_GetModState(); - if(!mod) { - printf(" (none)"); - return; - } - if(mod & KMOD_LSHIFT) - printf(" LSHIFT"); - if(mod & KMOD_RSHIFT) - printf(" RSHIFT"); - if(mod & KMOD_LCTRL) - printf(" LCTRL"); - if(mod & KMOD_RCTRL) - printf(" RCTRL"); - if(mod & KMOD_LALT) - printf(" LALT"); - if(mod & KMOD_RALT) - printf(" RALT"); - if(mod & KMOD_LMETA) - printf(" LMETA"); - if(mod & KMOD_RMETA) - printf(" RMETA"); - if(mod & KMOD_NUM) - printf(" NUM"); - if(mod & KMOD_CAPS) - printf(" CAPS"); - if(mod & KMOD_MODE) - printf(" MODE"); -} - -static void PrintKey(const SDL_Keysym *sym, int pressed) -{ - /* Print the keycode, name and state */ - if ( sym->sym ) { - printf("Key %s: %d-%s ", pressed ? "pressed" : "released", - sym->sym, SDL_GetKeyName(sym->sym)); - } else { - printf("Unknown Key (scancode = %d) %s ", sym->scancode, - pressed ? "pressed" : "released"); - } - - /* Print the translated character, if one exists */ - if ( sym->unicode ) { - /* Is it a control-character? */ - if ( sym->unicode < ' ' ) { - printf(" (^%c)", sym->unicode+'@'); - } else { -#ifdef UNICODE - printf(" (%c)", sym->unicode); -#else - /* This is a Latin-1 program, so only show 8-bits */ - if ( !(sym->unicode & 0xFF00) ) - printf(" (%c)", sym->unicode); - else - printf(" (0x%X)", sym->unicode); -#endif - } - } - print_modifiers(); - printf("\n"); -} - - -static int (SDLCALL * old_filterfunc) (void *, SDL_Event *); -static void *old_filterdata; - -int SDLCALL -FilterEvents(void *userdata, SDL_Event * event) -{ - static int reallyquit = 0; - - if (old_filterfunc) { - old_filterfunc(old_filterdata, event); - } - - switch (event->type) { - - case SDL_ACTIVEEVENT: - /* See what happened */ - printf("App %s ", event->active.gain ? "gained" : "lost"); - if (event->active.state & SDL_APPACTIVE) - printf("active "); - if (event->active.state & SDL_APPINPUTFOCUS) - printf("input "); - if (event->active.state & SDL_APPMOUSEFOCUS) - printf("mouse "); - printf("focus\n"); - - /* See if we are iconified or restored */ - if (event->active.state & SDL_APPACTIVE) { - printf("App has been %s\n", - event->active.gain ? "restored" : "iconified"); - } - return (0); - - /* We want to toggle visibility on buttonpress */ - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - if (event->button.state == SDL_PRESSED) { - visible = !visible; - SDL_ShowCursor(visible); - } - printf("Mouse button %d has been %s at %d,%d\n", - event->button.button, - (event->button.state == SDL_PRESSED) ? "pressed" : "released", - event->button.x, event->button.y); - return (0); - - /* Show relative mouse motion */ - case SDL_MOUSEMOTION: -#if 0 - printf("Mouse motion: {%d,%d} (%d,%d)\n", - event->motion.x, event->motion.y, - event->motion.xrel, event->motion.yrel); -#endif - return (0); - - case SDL_KEYDOWN: - PrintKey(&event->key.keysym, 1); - if (event->key.keysym.sym == SDLK_ESCAPE) { - HotKey_Quit(); - } - if ((event->key.keysym.sym == SDLK_g) && - (event->key.keysym.mod & KMOD_CTRL)) { - HotKey_ToggleGrab(); - } - if ((event->key.keysym.sym == SDLK_z) && - (event->key.keysym.mod & KMOD_CTRL)) { - HotKey_Iconify(); - } - if ((event->key.keysym.sym == SDLK_RETURN) && - (event->key.keysym.mod & (KMOD_ALT|KMOD_META))) { - HotKey_ToggleFullScreen(); - } - return (0); - - case SDL_KEYUP: - PrintKey(&event->key.keysym, 0); - return(0); - - /* Pass the video resize event through .. */ - case SDL_VIDEORESIZE: - return (1); - - /* This is important! Queue it if we want to quit. */ - case SDL_QUIT: - if (!reallyquit) { - reallyquit = 1; - printf("Quit requested\n"); - return (0); - } - printf("Quit demanded\n"); - return (1); - - /* This will never happen because events queued directly - to the event queue are not filtered. - */ - case SDL_USEREVENT: - return (1); - - /* Drop all other events */ - default: - return (0); - } -} - -int -main(int argc, char *argv[]) -{ - SDL_Event event; - const char *title; - SDL_Surface *icon; - Uint8 *icon_mask; - int parsed; - int w, h; - - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - /* Check command line arguments */ - w = 640; - h = 480; - video_bpp = 8; - video_flags = SDL_SWSURFACE; - parsed = 1; - while (parsed) { - if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) { - video_flags |= SDL_FULLSCREEN; - argc -= 1; - argv += 1; - } else if ((argc >= 2) && (strcmp(argv[1], "-resize") == 0)) { - video_flags |= SDL_RESIZABLE; - argc -= 1; - argv += 1; - } else if ((argc >= 2) && (strcmp(argv[1], "-noframe") == 0)) { - video_flags |= SDL_NOFRAME; - argc -= 1; - argv += 1; - } else if ((argc >= 3) && (strcmp(argv[1], "-width") == 0)) { - w = atoi(argv[2]); - argc -= 2; - argv += 2; - } else if ((argc >= 3) && (strcmp(argv[1], "-height") == 0)) { - h = atoi(argv[2]); - argc -= 2; - argv += 2; - } else if ((argc >= 3) && (strcmp(argv[1], "-bpp") == 0)) { - video_bpp = atoi(argv[2]); - argc -= 2; - argv += 2; - } else { - parsed = 0; - } - } - - /* Set the icon -- this must be done before the first mode set */ - icon = LoadIconSurface("icon.bmp", &icon_mask); - if (icon != NULL) { - SDL_WM_SetIcon(icon, icon_mask); - } - if (icon_mask != NULL) - free(icon_mask); - - /* Set the title bar */ - if (argv[1] == NULL) - title = "Testing 1.. 2.. 3..."; - else - title = argv[1]; - SDL_WM_SetCaption(title, "testwm"); - - /* See if it's really set */ - SDL_WM_GetCaption(&title, NULL); - if (title) - printf("Title was set to: %s\n", title); - else - printf("No window title was set!\n"); - - /* Initialize the display */ - if (SetVideoMode(w, h) < 0) { - quit(1); - } - - /* Set an event filter that discards everything but QUIT */ - SDL_GetEventFilter(&old_filterfunc, &old_filterdata); - SDL_SetEventFilter(FilterEvents, NULL); - - /* Loop, waiting for QUIT */ - while (SDL_WaitEvent(&event)) { - switch (event.type) { - case SDL_VIDEORESIZE: - printf("Got a resize event: %dx%d\n", - event.resize.w, event.resize.h); - SetVideoMode(event.resize.w, event.resize.h); - break; - case SDL_USEREVENT: - printf("Handling internal quit request\n"); - /* Fall through to the quit handler */ - case SDL_QUIT: - printf("Bye bye..\n"); - quit(0); - default: - /* This should never happen */ - printf("Warning: Event %d wasn't filtered\n", event.type); - break; - } - } - printf("SDL_WaitEvent() error: %s\n", SDL_GetError()); - SDL_Quit(); - return (255); -} diff --git a/test/threadwin.c b/test/threadwin.c deleted file mode 100644 index 1388cdc14..000000000 --- a/test/threadwin.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely. -*/ - -/* Test out the multi-threaded event handling functions */ - -#include -#include -#include - -#include "SDL.h" -#include "SDL_thread.h" - -/* Are we done yet? */ -static int done = 0; - -/* Is the cursor visible? */ -static int visible = 1; - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -SDL_Surface * -LoadIconSurface(char *file, Uint8 ** maskp) -{ - SDL_Surface *icon; - Uint8 *pixels; - Uint8 *mask; - int mlen, i; - - *maskp = NULL; - - /* Load the icon surface */ - icon = SDL_LoadBMP(file); - if (icon == NULL) { - fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); - return (NULL); - } - - /* Check width and height */ - if ((icon->w % 8) != 0) { - fprintf(stderr, "Icon width must be a multiple of 8!\n"); - SDL_FreeSurface(icon); - return (NULL); - } - if (icon->format->palette == NULL) { - fprintf(stderr, "Icon must have a palette!\n"); - SDL_FreeSurface(icon); - return (NULL); - } - - /* Set the colorkey */ - SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *) icon->pixels)); - - /* Create the mask */ - pixels = (Uint8 *) icon->pixels; - printf("Transparent pixel: (%d,%d,%d)\n", - icon->format->palette->colors[*pixels].r, - icon->format->palette->colors[*pixels].g, - icon->format->palette->colors[*pixels].b); - mlen = icon->w * icon->h; - mask = (Uint8 *) malloc(mlen / 8); - if (mask == NULL) { - fprintf(stderr, "Out of memory!\n"); - SDL_FreeSurface(icon); - return (NULL); - } - memset(mask, 0, mlen / 8); - for (i = 0; i < mlen;) { - if (pixels[i] != *pixels) - mask[i / 8] |= 0x01; - ++i; - if ((i % 8) != 0) - mask[i / 8] <<= 1; - } - *maskp = mask; - return (icon); -} - -int SDLCALL -FilterEvents(void *userdata, SDL_Event * event) -{ - static int reallyquit = 0; - - switch (event->type) { - - case SDL_ACTIVEEVENT: - /* See what happened */ - printf("App %s ", event->active.gain ? "gained" : "lost"); - if (event->active.state & SDL_APPACTIVE) - printf("active "); - if (event->active.state & SDL_APPMOUSEFOCUS) - printf("mouse "); - if (event->active.state & SDL_APPINPUTFOCUS) - printf("input "); - printf("focus\n"); - - /* See if we are iconified or restored */ - if (event->active.state & SDL_APPACTIVE) { - printf("App has been %s\n", - event->active.gain ? "restored" : "iconified"); - } - return (0); - - /* This is important! Queue it if we want to quit. */ - case SDL_QUIT: - if (!reallyquit) { - reallyquit = 1; - printf("Quit requested\n"); - return (0); - } - printf("Quit demanded\n"); - return (1); - - /* Mouse and keyboard events go to threads */ - case SDL_MOUSEMOTION: - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - case SDL_KEYDOWN: - case SDL_KEYUP: - return (1); - - /* Drop all other events */ - default: - return (0); - } -} - -int SDLCALL -HandleMouse(void *unused) -{ - SDL_Event events[10]; - int i, found; - - /* Handle mouse events here */ - while (!done) { - found = SDL_PeepEvents(events, 10, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP); - for (i = 0; i < found; ++i) { - switch (events[i].type) { - /* We want to toggle visibility on buttonpress */ - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - if (events[i].button.state == SDL_PRESSED) { - visible = !visible; - SDL_ShowCursor(visible); - } - printf("Mouse button %d has been %s\n", - events[i].button.button, - (events[i].button.state == SDL_PRESSED) ? - "pressed" : "released"); - break; - /* Show relative mouse motion */ - case SDL_MOUSEMOTION: - printf("Mouse relative motion: {%d,%d}\n", - events[i].motion.xrel, events[i].motion.yrel); - break; - } - } - /* Give up some CPU to allow events to arrive */ - SDL_Delay(20); - } - return (0); -} - -int SDLCALL -HandleKeyboard(void *unused) -{ - SDL_Event events[10]; - int i, found; - - /* Handle mouse events here */ - while (!done) { - found = SDL_PeepEvents(events, 10, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP); - for (i = 0; i < found; ++i) { - switch (events[i].type) { - /* We want to toggle visibility on buttonpress */ - case SDL_KEYDOWN: - case SDL_KEYUP: - printf("Key '%c' (keysym==%d) has been %s\n", - events[i].key.keysym.unicode, - (int) events[i].key.keysym.sym, - (events[i].key.state == SDL_PRESSED) ? - "pressed" : "released"); - - /* Allow hitting to quit the app */ - if (events[i].key.keysym.sym == SDLK_ESCAPE) { - done = 1; - } - - /* skip events now that aren't KEYUPs... */ - if (events[i].key.state == SDL_PRESSED) - break; - - if (events[i].key.keysym.sym == SDLK_f) { - int rc = 0; - printf("attempting to toggle fullscreen...\n"); - rc = SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); - printf("SDL_WM_ToggleFullScreen returned %d.\n", rc); - } - - if (events[i].key.keysym.sym == SDLK_g) { - SDL_GrabMode m; - m = SDL_WM_GrabInput(SDL_GRAB_QUERY) == - SDL_GRAB_ON ? SDL_GRAB_OFF : SDL_GRAB_ON; - printf - ("attempting to toggle input grab to %s...\n", - m == SDL_GRAB_ON ? "ON" : "OFF"); - SDL_WM_GrabInput(m); - printf("attempt finished.\n"); - } - - break; - } - } - /* Give up some CPU to allow events to arrive */ - SDL_Delay(20); - } - return (0); -} - -int -main(int argc, char *argv[]) -{ - SDL_Surface *screen; - SDL_Surface *icon; - Uint8 *icon_mask; - int i, parsed; - Uint8 *buffer; - SDL_Color palette[256]; - Uint32 init_flags; - Uint8 video_bpp; - Uint32 video_flags; - SDL_Thread *mouse_thread; - SDL_Thread *keybd_thread; - - /* Set the options, based on command line arguments */ - init_flags = SDL_INIT_VIDEO; - video_bpp = 8; - video_flags = SDL_SWSURFACE; - parsed = 1; - while (parsed) { - if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) { - video_flags |= SDL_FULLSCREEN; - argc -= 1; - argv += 1; - } else if ((argc >= 3) && (strcmp(argv[1], "-bpp") == 0)) { - video_bpp = atoi(argv[2]); - argc -= 2; - argv += 2; - } else { - parsed = 0; - } - } - - /* Initialize SDL with the requested flags */ - if (SDL_Init(init_flags) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - /* Set the icon -- this must be done before the first mode set */ - icon = LoadIconSurface("icon.bmp", &icon_mask); - if (icon != NULL) { - SDL_WM_SetIcon(icon, icon_mask); - } - if (icon_mask != NULL) - free(icon_mask); - - /* Initialize the display */ - screen = SDL_SetVideoMode(640, 480, video_bpp, video_flags); - if (screen == NULL) { - fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n", - video_bpp, SDL_GetError()); - quit(1); - } - printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ? - "fullscreen" : "windowed"); - - /* Enable printable characters */ - SDL_EnableUNICODE(1); - - /* Set an event filter that discards everything but QUIT */ - SDL_SetEventFilter(FilterEvents, NULL); - - /* Create the event handling threads */ - mouse_thread = SDL_CreateThread(HandleMouse, "MouseHandler", NULL); - keybd_thread = SDL_CreateThread(HandleKeyboard, "KeyboardHandler", NULL); - - /* Set the surface pixels and refresh! */ - for (i = 0; i < 256; ++i) { - palette[i].r = 255 - i; - palette[i].g = 255 - i; - palette[i].b = 255 - i; - } - SDL_SetColors(screen, palette, 0, 256); - if (SDL_LockSurface(screen) < 0) { - fprintf(stderr, "Couldn't lock display surface: %s\n", - SDL_GetError()); - quit(2); - } - buffer = (Uint8 *) screen->pixels; - for (i = 0; i < screen->h; ++i) { - memset(buffer, (i * 255) / screen->h, - screen->w * screen->format->BytesPerPixel); - buffer += screen->pitch; - } - SDL_UnlockSurface(screen); - SDL_UpdateRect(screen, 0, 0, 0, 0); - - /* Loop, waiting for QUIT */ - while (!done) { - SDL_PumpEvents(); - - if (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT)) { - done = 1; - } - /* Give up some CPU so the events can accumulate */ - SDL_Delay(20); - } - SDL_WaitThread(mouse_thread, NULL); - SDL_WaitThread(keybd_thread, NULL); - SDL_Quit(); - return (0); -}