From 22f666c86c78694cc4da22f0cbdb09a4457c3e61 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 24 Feb 2013 12:55:51 -0800 Subject: [PATCH 001/151] Fixed compiling on older Linux systems without libudev --- configure.in | 15 +++++++++++++-- src/joystick/linux/SDL_sysjoystick.c | 10 +++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/configure.in b/configure.in index 56f96054a..f2f6b6468 100644 --- a/configure.in +++ b/configure.in @@ -1767,9 +1767,20 @@ AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]]) pthread_cflags="-D_REENTRANT" pthread_lib="-pthread" ;; - *-*-solaris*) + *-*-solaris2.9) + # From Solaris 9+, posix4's preferred name is rt. pthread_cflags="-D_REENTRANT" - pthread_lib="-lpthread -lposix4" + pthread_lib="-lpthread -lrt" + ;; + *-*-solaris2.10) + # Solaris 10+ merged pthread into libc. + pthread_cflags="-D_REENTRANT" + pthread_lib="-lrt" + ;; + *-*-solaris*) + # Solaris 11+ merged rt into libc. + pthread_cflags="-D_REENTRANT" + pthread_lib="" ;; *-*-sysv5*) pthread_cflags="-D_REENTRANT -Kthread" diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index c402a625b..956316c7e 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -47,6 +47,11 @@ #include "../../events/SDL_events_c.h" #endif +/* This isn't defined in older Linux kernel headers */ +#ifndef SYN_DROPPED +#define SYN_DROPPED 3 +#endif + /* * !!! FIXME: move all the udev stuff to src/core/linux, so I can reuse it * !!! FIXME: for audio hardware disconnects. @@ -59,11 +64,6 @@ #include #include -/* This isn't defined in older Linux kernel headers */ -#ifndef SYN_DROPPED -#define SYN_DROPPED 3 -#endif - /* we never link directly to libudev. */ /* !!! FIXME: can we generalize this? ALSA, etc, do the same things. */ static const char *udev_library = "libudev.so.0"; From c63c6c510316fc347db1d82bb17d261759595166 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 24 Feb 2013 12:56:29 -0800 Subject: [PATCH 002/151] Removed duplicate include --- src/joystick/linux/SDL_sysjoystick.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 956316c7e..cf1afeb41 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -62,7 +62,6 @@ #include #include #include -#include /* we never link directly to libudev. */ /* !!! FIXME: can we generalize this? ALSA, etc, do the same things. */ From 2452978990954b9759ff0456a78706880c0634aa Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 24 Feb 2013 22:56:24 -0500 Subject: [PATCH 003/151] Added an X360 game controller config for Linux. --- src/joystick/SDL_gamecontroller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index d7d170a53..ccae64a5a 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -96,7 +96,7 @@ const char *s_ControllerMappings [] = "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", #elif defined(__LINUX__) - + "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", #endif NULL }; From 6c4a53f561a1c191cdf49f1666e45325282ed320 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 24 Feb 2013 22:56:35 -0500 Subject: [PATCH 004/151] Fixed a minor typo. --- src/joystick/SDL_gamecontroller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index ccae64a5a..12f53f54d 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -435,7 +435,7 @@ void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char } else if ( axis != SDL_CONTROLLER_AXIS_INVALID ) { - SDL_assert( !"Support has as axis" ); + SDL_assert( !"Support hat as axis" ); } else { From e4ef7cba60cd3ed7397186ea03fa9ed199e04ac7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 24 Feb 2013 22:57:25 -0500 Subject: [PATCH 005/151] Made testgamecontroller minimally more useful. --- test/testgamecontroller.c | 73 ++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index 7c1d9bcc2..ededfe523 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -40,9 +40,58 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h) SDL_RenderFillRect(r, &area); } +static const char * +ControllerAxisName(const SDL_CONTROLLER_AXIS axis) +{ + switch (axis) + { + #define AXIS_CASE(ax) case SDL_CONTROLLER_AXIS_##ax: return #ax + AXIS_CASE(INVALID); + AXIS_CASE(LEFTX); + AXIS_CASE(LEFTY); + AXIS_CASE(RIGHTX); + AXIS_CASE(RIGHTY); + AXIS_CASE(TRIGGERLEFT); + AXIS_CASE(TRIGGERRIGHT); + #undef AXIS_CASE + default: return "???"; + } +} + +static const char * +ControllerButtonName(const SDL_CONTROLLER_BUTTON button) +{ + switch (button) + { + #define BUTTON_CASE(btn) case SDL_CONTROLLER_BUTTON_##btn: return #btn + BUTTON_CASE(INVALID); + BUTTON_CASE(A); + BUTTON_CASE(B); + BUTTON_CASE(X); + BUTTON_CASE(Y); + BUTTON_CASE(BACK); + BUTTON_CASE(GUIDE); + BUTTON_CASE(START); + BUTTON_CASE(LEFTSTICK); + BUTTON_CASE(RIGHTSTICK); + BUTTON_CASE(LEFTSHOULDER); + BUTTON_CASE(RIGHTSHOULDER); + BUTTON_CASE(DPAD_UP); + BUTTON_CASE(DPAD_DOWN); + BUTTON_CASE(DPAD_LEFT); + BUTTON_CASE(DPAD_RIGHT); + #undef BUTTON_CASE + default: return "???"; + } +} + void WatchGameController(SDL_GameController * gamecontroller) { + const char *controllername = gamecontroller ? SDL_GameControllerName(gamecontroller) : "???"; + const char *basetitle = "Game Controller Test: "; + const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(controllername) + 1; + char *title = SDL_malloc(titlelen); SDL_Window *window = NULL; SDL_Renderer *screen = NULL; const char *name = NULL; @@ -50,8 +99,12 @@ WatchGameController(SDL_GameController * gamecontroller) SDL_Event event; int i; + if (title) { + SDL_snprintf(title, titlelen, "%s%s", basetitle, controllername); + } + /* Create a window to display controller axis position */ - window = SDL_CreateWindow("Game Controller Test", SDL_WINDOWPOS_CENTERED, + window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (window == NULL) { @@ -84,17 +137,21 @@ WatchGameController(SDL_GameController * gamecontroller) while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_CONTROLLERAXISMOTION: - printf("Controller %d axis %d value: %d\n", + printf("Controller %d axis %d ('%s') value: %d\n", event.caxis.which, - event.caxis.axis, event.caxis.value); + event.caxis.axis, + ControllerAxisName(event.caxis.axis), + event.caxis.value); break; case SDL_CONTROLLERBUTTONDOWN: - printf("Controller %d button %d down\n", - event.cbutton.which, event.cbutton.button); + printf("Controller %d button %d ('%s') down\n", + event.cbutton.which, event.cbutton.button, + ControllerButtonName(event.cbutton.button)); break; case SDL_CONTROLLERBUTTONUP: - printf("Controller %d button %d up\n", - event.cbutton.which, event.cbutton.button); + printf("Controller %d button %d ('%s') up\n", + event.cbutton.which, event.cbutton.button, + ControllerButtonName(event.cbutton.button)); break; case SDL_KEYDOWN: if (event.key.keysym.sym != SDLK_ESCAPE) { @@ -103,7 +160,7 @@ WatchGameController(SDL_GameController * gamecontroller) /* Fall through to signal quit */ case SDL_QUIT: done = 1; - s_ForceQuit = SDL_TRUE; + s_ForceQuit = SDL_TRUE; break; default: break; From 3d19f803d8f59cb44302154987a49882a44047a8 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 25 Feb 2013 00:45:25 -0500 Subject: [PATCH 006/151] Added PS3 game controller config for Linux. --- src/joystick/SDL_gamecontroller.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 12f53f54d..93854154c 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -97,6 +97,7 @@ const char *s_ControllerMappings [] = "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", #elif defined(__LINUX__) "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", + "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,x:b15,y:b12,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", #endif NULL }; From db73a392c2481c1c506f663b71b0a59fc6f76875 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 25 Feb 2013 00:47:47 -0500 Subject: [PATCH 007/151] Minor cleanup. --- test/testgamecontroller.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index ededfe523..3bc813b45 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -88,19 +88,18 @@ ControllerButtonName(const SDL_CONTROLLER_BUTTON button) void WatchGameController(SDL_GameController * gamecontroller) { - const char *controllername = gamecontroller ? SDL_GameControllerName(gamecontroller) : "???"; + const char *name = SDL_GameControllerName(gamecontroller); const char *basetitle = "Game Controller Test: "; - const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(controllername) + 1; + const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1; char *title = SDL_malloc(titlelen); SDL_Window *window = NULL; SDL_Renderer *screen = NULL; - const char *name = NULL; int done = 0; SDL_Event event; int i; if (title) { - SDL_snprintf(title, titlelen, "%s%s", basetitle, controllername); + SDL_snprintf(title, titlelen, "%s%s", basetitle, name); } /* Create a window to display controller axis position */ @@ -125,7 +124,6 @@ WatchGameController(SDL_GameController * gamecontroller) SDL_RaiseWindow(window); /* Print info about the controller we are watching */ - name = SDL_GameControllerName(gamecontroller); printf("Watching controller %s\n", name ? name : "Unknown Controller"); /* Loop, getting controller events! */ From a5862a96a34194c4328f756e55293dc10cf985af Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 25 Feb 2013 00:56:21 -0500 Subject: [PATCH 008/151] Changed the game controller enum types to match SDL naming conventions. --- include/SDL_events.h | 4 ++-- include/SDL_gamecontroller.h | 21 ++++++++++--------- src/joystick/SDL_gamecontroller.c | 34 +++++++++++++++---------------- test/testgamecontroller.c | 4 ++-- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index 4065e2b93..35e36f60d 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -314,7 +314,7 @@ typedef struct SDL_ControllerAxisEvent Uint32 type; /**< ::SDL_CONTROLLERAXISMOTION */ Uint32 timestamp; Uint8 which; /**< The joystick instance id */ - SDL_CONTROLLER_AXIS axis; /**< The joystick axis index */ + SDL_GameControllerAxis axis; /**< The joystick axis index */ int value; /**< The axis value (range: -32768 to 32767) */ } SDL_ControllerAxisEvent; @@ -327,7 +327,7 @@ typedef struct SDL_ControllerButtonEvent Uint32 type; /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */ Uint32 timestamp; Uint8 which; /**< The joystick instance id */ - SDL_CONTROLLER_BUTTON button; /**< The joystick button index */ + SDL_GameControllerButton button; /**< The joystick button index */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ } SDL_ControllerButtonEvent; diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h index 1969a2914..ee182732e 100644 --- a/include/SDL_gamecontroller.h +++ b/include/SDL_gamecontroller.h @@ -59,7 +59,8 @@ typedef enum SDL_CONTROLLER_BINDTYPE_BUTTON, SDL_CONTROLLER_BINDTYPE_AXIS, SDL_CONTROLLER_BINDTYPE_HAT -} SDL_CONTROLLER_BINDTYPE; +} SDL_GameControllerBindType; + /** * get the sdl joystick layer binding for this controller button/axis mapping */ @@ -71,7 +72,7 @@ struct _SDL_GameControllerHatBind typedef struct _SDL_GameControllerButtonBind { - SDL_CONTROLLER_BINDTYPE m_eBindType; + SDL_GameControllerBindType m_eBindType; union { int button; @@ -172,19 +173,19 @@ typedef enum SDL_CONTROLLER_AXIS_TRIGGERLEFT, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, SDL_CONTROLLER_AXIS_MAX -} SDL_CONTROLLER_AXIS; +} SDL_GameControllerAxis; /** * turn this string into a axis mapping */ -extern DECLSPEC SDL_CONTROLLER_AXIS SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString); +extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString); /** * get the sdl joystick layer binding for this controller button mapping */ extern DECLSPEC SDL_GameControllerButtonBind SDLCALL SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller, - SDL_CONTROLLER_AXIS button); + SDL_GameControllerAxis axis); /** * Get the current state of an axis control on a game controller. @@ -195,7 +196,7 @@ SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller, */ extern DECLSPEC Sint16 SDLCALL SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, - SDL_CONTROLLER_AXIS axis); + SDL_GameControllerAxis axis); /** * The list of buttons available from a controller @@ -219,12 +220,12 @@ typedef enum SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDL_CONTROLLER_BUTTON_MAX -} SDL_CONTROLLER_BUTTON; +} SDL_GameControllerButton; /** * turn this string into a button mapping */ -extern DECLSPEC SDL_CONTROLLER_BUTTON SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString); +extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString); /** @@ -232,7 +233,7 @@ extern DECLSPEC SDL_CONTROLLER_BUTTON SDLCALL SDL_GameControllerGetButtonFromStr */ extern DECLSPEC SDL_GameControllerButtonBind SDLCALL SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller, - SDL_CONTROLLER_BUTTON button); + SDL_GameControllerButton button); /** @@ -241,7 +242,7 @@ SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller, * The button indices start at index 0. */ extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller, - SDL_CONTROLLER_BUTTON button); + SDL_GameControllerButton button); /** * Close a controller previously opened with SDL_GameControllerOpen(). diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 93854154c..b8ec61509 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -64,12 +64,12 @@ struct _SDL_ControllerMapping struct _SDL_HatMapping hatasbutton[SDL_CONTROLLER_BUTTON_MAX]; // reverse mapping, joystick indices to buttons - SDL_CONTROLLER_AXIS raxes[k_nMaxReverseEntries]; - SDL_CONTROLLER_AXIS rbuttonasaxis[k_nMaxReverseEntries]; + SDL_GameControllerAxis raxes[k_nMaxReverseEntries]; + SDL_GameControllerAxis rbuttonasaxis[k_nMaxReverseEntries]; - SDL_CONTROLLER_BUTTON rbuttons[k_nMaxReverseEntries]; - SDL_CONTROLLER_BUTTON raxesasbutton[k_nMaxReverseEntries]; - SDL_CONTROLLER_BUTTON rhatasbutton[k_nMaxHatEntries]; + SDL_GameControllerButton rbuttons[k_nMaxReverseEntries]; + SDL_GameControllerButton raxesasbutton[k_nMaxReverseEntries]; + SDL_GameControllerButton rhatasbutton[k_nMaxHatEntries]; }; @@ -118,8 +118,8 @@ struct _SDL_GameController }; -int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis, Sint16 value); -int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button, Uint8 state); +int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value); +int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state); /* * Event filter to fire controller events from joystick ones @@ -296,7 +296,7 @@ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) /* * convert a string to its enum equivalent */ -SDL_CONTROLLER_AXIS SDL_GameControllerGetAxisFromString( const char *pchString ) +SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchString ) { if ( !pchString || !pchString[0] ) return SDL_CONTROLLER_AXIS_INVALID; @@ -321,7 +321,7 @@ SDL_CONTROLLER_AXIS SDL_GameControllerGetAxisFromString( const char *pchString ) /* * convert a string to its enum equivalent */ -SDL_CONTROLLER_BUTTON SDL_GameControllerGetButtonFromString( const char *pchString ) +SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchString ) { if ( !pchString || !pchString[0] ) return SDL_CONTROLLER_BUTTON_INVALID; @@ -367,8 +367,8 @@ SDL_CONTROLLER_BUTTON SDL_GameControllerGetButtonFromString( const char *pchStri void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping ) { int iSDLButton = 0; - SDL_CONTROLLER_BUTTON button; - SDL_CONTROLLER_AXIS axis; + SDL_GameControllerButton button; + SDL_GameControllerAxis axis; button = SDL_GameControllerGetButtonFromString( szGameButton ); axis = SDL_GameControllerGetAxisFromString( szGameButton ); iSDLButton = SDL_atoi( &szJoystickButton[1] ); @@ -829,7 +829,7 @@ SDL_GameControllerOpen(int device_index) * Get the current state of an axis control on a controller */ Sint16 -SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis) +SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis) { if ( !gamecontroller ) return 0; @@ -854,7 +854,7 @@ SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AX * Get the current state of a button on a controller */ Uint8 -SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button) +SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button) { if ( !gamecontroller ) return 0; @@ -925,7 +925,7 @@ SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller) /** * get the sdl joystick layer binding for this controller axi mapping */ -SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis ) +SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis) { SDL_GameControllerButtonBind bind; SDL_memset( &bind, 0x0, sizeof(bind) ); @@ -951,7 +951,7 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( SDL_GameControlle /** * get the sdl joystick layer binding for this controller button mapping */ -SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton( SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button ) +SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button) { SDL_GameControllerButtonBind bind; SDL_memset( &bind, 0x0, sizeof(bind) ); @@ -1053,7 +1053,7 @@ SDL_GameControllerQuit(void) * Event filter to transform joystick events into appropriate game controller ones */ int -SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis, Sint16 value) +SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value) { int posted; @@ -1077,7 +1077,7 @@ SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLE * Event filter to transform joystick events into appropriate game controller ones */ int -SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button, Uint8 state) +SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state) { int posted; #if !SDL_EVENTS_DISABLED diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index 3bc813b45..8a4413c57 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -41,7 +41,7 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h) } static const char * -ControllerAxisName(const SDL_CONTROLLER_AXIS axis) +ControllerAxisName(const SDL_GameControllerAxis axis) { switch (axis) { @@ -59,7 +59,7 @@ ControllerAxisName(const SDL_CONTROLLER_AXIS axis) } static const char * -ControllerButtonName(const SDL_CONTROLLER_BUTTON button) +ControllerButtonName(const SDL_GameControllerButton button) { switch (button) { From 4de257c5d26a54bedbbfcd5253e39fd5aee9fdc7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 25 Feb 2013 01:50:59 -0500 Subject: [PATCH 009/151] Added SDL_haptic.h to SDL.h. --- include/SDL.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/SDL.h b/include/SDL.h index 2058ae15c..01613da6c 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -73,7 +73,9 @@ #include "SDL_endian.h" #include "SDL_error.h" #include "SDL_events.h" +#include "SDL_joystick.h" #include "SDL_gamecontroller.h" +#include "SDL_haptic.h" #include "SDL_hints.h" #include "SDL_loadso.h" #include "SDL_log.h" From ad1d82cf83f7a76f337c779390c8a090397a170c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 25 Feb 2013 01:51:21 -0500 Subject: [PATCH 010/151] Added SDL_GameControllerUpdate(). --- include/SDL_gamecontroller.h | 9 +++++++++ src/joystick/SDL_gamecontroller.c | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h index ee182732e..7cb9ed1f4 100644 --- a/include/SDL_gamecontroller.h +++ b/include/SDL_gamecontroller.h @@ -160,6 +160,15 @@ extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameCont */ extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state); +/** + * Update the current state of the open game controllers. + * + * This is called automatically by the event loop if any game controller + * events are enabled. + */ +extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void); + + /** * The list of axii available from a controller */ diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index b8ec61509..24bf07a00 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -824,6 +824,16 @@ SDL_GameControllerOpen(int device_index) return (gamecontroller); } +/* + * Manually pump for controller updates. + */ +void +SDL_GameControllerUpdate(void) +{ + /* Just for API completeness; the joystick API does all the work. */ + SDL_JoystickUpdate(); +} + /* * Get the current state of an axis control on a controller From 95adf91d71f93b8958fc045c5861bb410c1964f9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 25 Feb 2013 00:54:25 -0800 Subject: [PATCH 011/151] Don't crash if we are asked to convert a surface to a NULl buffer. --- src/video/SDL_surface.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index c866f4753..710508ed3 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -935,6 +935,16 @@ int SDL_ConvertPixels(int width, int height, SDL_Rect rect; void *nonconst_src = (void *) src; + /* Check to make sure we are bliting somewhere, so we don't crash */ + if (!dst) { + SDL_InvalidParamError("dst"); + return -1; + } + if (!dst_pitch) { + SDL_InvalidParamError("dst_pitch"); + return -1; + } + /* Fast path for same format copy */ if (src_format == dst_format) { int bpp; From c5865bdd873cf801978693fcc81fc09352435299 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Mon, 25 Feb 2013 08:05:26 -0800 Subject: [PATCH 012/151] Add tests to video suite --- test/testautomation_mouse.c | 18 +-- test/testautomation_video.c | 276 ++++++++++++++++++++++++++++++++---- 2 files changed, 258 insertions(+), 36 deletions(-) diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index f236f7095..69d82dd09 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -413,13 +413,13 @@ mouse_getSetRelativeMouseMode(void *arg) #define MOUSE_TESTWINDOW_HEIGHT 200 /** - * Create s test window + * Creates a test window */ -SDL_Window *_createTestWindow() +SDL_Window *_createMouseSuiteTestWindow() { int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT; SDL_Window *window; - window = SDL_CreateWindow("mouse_createTestWindow", posX, posY, width, height, 0); + window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0); SDLTest_AssertPass("SDL_CreateWindow()"); SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); return window; @@ -428,12 +428,12 @@ SDL_Window *_createTestWindow() /* * Destroy test window */ -void _destroyTestWindow(SDL_Window *window) +void _destroyMouseSuiteTestWindow(SDL_Window *window) { if (window != NULL) { SDL_DestroyWindow(window); window = NULL; - SDLTest_AssertPass("SDL_DestroyWindow"); + SDLTest_AssertPass("SDL_DestroyWindow()"); } } @@ -453,7 +453,7 @@ mouse_warpMouseInWindow(void *arg) SDL_Window *window; /* Create test window */ - window = _createTestWindow(); + window = _createMouseSuiteTestWindow(); if (window == NULL) return TEST_ABORTED; /* Mouse to random position inside window */ @@ -482,7 +482,7 @@ mouse_warpMouseInWindow(void *arg) /* Clean up test window */ - _destroyTestWindow(window); + _destroyMouseSuiteTestWindow(window); return TEST_COMPLETED; } @@ -505,7 +505,7 @@ mouse_getMouseFocus(void *arg) SDLTest_AssertPass("SDL_GetMouseFocus()"); /* Create test window */ - window = _createTestWindow(); + window = _createMouseSuiteTestWindow(); if (window == NULL) return TEST_ABORTED; /* Mouse to random position inside window */ @@ -531,7 +531,7 @@ mouse_getMouseFocus(void *arg) SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); /* Clean up test window */ - _destroyTestWindow(window); + _destroyMouseSuiteTestWindow(window); /* Pump events to update focus state */ SDL_PumpEvents(); diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 49c7f4c9f..d9ec69f16 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -7,6 +7,43 @@ #include "SDL.h" #include "SDL_test.h" +/* Private helpers */ + +/* + * Create a test window + */ +SDL_Window *_createVideoSuiteTestWindow(const char *title) +{ + SDL_Window* window; + int x, y, w, h; + SDL_WindowFlags flags; + + /* Standard window */ + x = SDLTest_RandomIntegerInRange(1, 100); + y = SDLTest_RandomIntegerInRange(1, 100); + w = SDLTest_RandomIntegerInRange(320, 1024); + h = SDLTest_RandomIntegerInRange(320, 768); + flags = SDL_WINDOW_SHOWN; + + window = SDL_CreateWindow(title, x, y, w, h, flags); + SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); + SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); + + return window; +} + +/* + * Destroy test window + */ +void _destroyVideoSuiteTestWindow(SDL_Window *window) +{ + if (window != NULL) { + SDL_DestroyWindow(window); + window = NULL; + SDLTest_AssertPass("Call to SDL_DestroyWindow"); + } +} + /* Test case functions */ /** @@ -133,10 +170,9 @@ video_createWindowVariousPositions(void *arg) window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } } @@ -191,10 +227,9 @@ video_createWindowVariousSizes(void *arg) window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } } @@ -269,15 +304,16 @@ video_createWindowVariousFlags(void *arg) window = SDL_CreateWindow(title, x, y, w, h, flags); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } return TEST_COMPLETED; } + /** * @brief Tests the functionality of the SDL_GetWindowFlags function */ @@ -286,30 +322,200 @@ video_getWindowFlags(void *arg) { SDL_Window* window; const char* title = "video_getWindowFlags Test Window"; - int x, y, w, h; SDL_WindowFlags flags; Uint32 actualFlags; - /* Standard window */ - x = SDLTest_RandomIntegerInRange(1, 100); - y = SDLTest_RandomIntegerInRange(1, 100); - w = SDLTest_RandomIntegerInRange(320, 1024); - h = SDLTest_RandomIntegerInRange(320, 768); - - /* Reliable flag */ + /* Reliable flag set always set in test window */ flags = SDL_WINDOW_SHOWN; - window = SDL_CreateWindow(title, x, y, w, h, flags); - SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); - SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); if (window != NULL) { actualFlags = SDL_GetWindowFlags(window); SDLTest_AssertPass("Call to SDL_GetWindowFlags"); SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags); - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); } + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetNumDisplayModes function + */ +int +video_getNumDisplayModes(void *arg) +{ + int result; + int displayNum; + int i; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make call for each display */ + for (i=0; i= 1, "Validate returned value from function; expected: >=1; got: %d", result); + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests negative call to SDL_GetNumDisplayModes function + */ +int +video_getNumDisplayModesNegative(void *arg) +{ + int result; + int displayNum; + int displayIndex; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Invalid boundary values */ + displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + /* Large (out-of-bounds) display index */ + displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + displayIndex = SDLTest_RandomIntegerInRange(1000, 2000); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution + */ +int +video_getClosestDisplayModeCurrentResolution(void *arg) +{ + int result; + SDL_DisplayMode current; + SDL_DisplayMode target; + SDL_DisplayMode closest; + SDL_DisplayMode* dResult; + int displayNum; + int i; + int variation; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make calls for each display */ + for (i=0; iw, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w); + SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h); + } + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution + */ +int +video_getClosestDisplayModeRandomResolution(void *arg) +{ + SDL_DisplayMode target; + SDL_DisplayMode closest; + SDL_DisplayMode* dResult; + int displayNum; + int i; + int variation; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make calls for each display */ + for (i=0; i= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result); + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + return TEST_COMPLETED; } @@ -329,11 +535,27 @@ static const SDLTest_TestCaseReference videoTest4 = { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED }; static const SDLTest_TestCaseReference videoTest5 = - { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Set and get window flags", TEST_ENABLED }; + { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest6 = + { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest7 = + { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest8 = + { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest9 = + { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest10 = + { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED }; /* Sequence of Video test cases */ static const SDLTest_TestCaseReference *videoTests[] = { - &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, NULL + &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, + &videoTest7, &videoTest8, &videoTest9, &videoTest10, NULL }; /* Video test suite (global) */ From cf58b7736096b683a6a288620b6e35f0b7f82c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Mon, 25 Feb 2013 16:52:42 -0800 Subject: [PATCH 013/151] sdl2 - change the windows scancode logic to use the scan code value in lparam rather than VK's to get a stable scancode value across different KB layouts --- include/SDL_scancode.h | 3 + src/events/scancodes_windows.h | 287 +++--------------------- src/video/windows/SDL_windowsevents.c | 148 ++++++++++-- src/video/windows/SDL_windowskeyboard.c | 25 ++- test/checkkeys.c | 6 +- 5 files changed, 186 insertions(+), 283 deletions(-) diff --git a/include/SDL_scancode.h b/include/SDL_scancode.h index 32d9f4c71..b05ca5cca 100644 --- a/include/SDL_scancode.h +++ b/include/SDL_scancode.h @@ -385,6 +385,9 @@ typedef enum SDL_SCANCODE_EJECT = 281, SDL_SCANCODE_SLEEP = 282, + SDL_SCANCODE_APP1 = 283, + SDL_SCANCODE_APP2 = 284, + /*@}*//*Walther keys*/ /* Add any other keys here. */ diff --git a/src/events/scancodes_windows.h b/src/events/scancodes_windows.h index 496227984..e2c91ab38 100644 --- a/src/events/scancodes_windows.h +++ b/src/events/scancodes_windows.h @@ -25,262 +25,35 @@ - msdn.microsoft.com */ /* *INDENT-OFF* */ -static const SDL_Scancode windows_scancode_table[] = { - /* 0, 0x00 */ SDL_SCANCODE_UNKNOWN, - /* 1, 0x01 */ SDL_SCANCODE_UNKNOWN, - /* 2, 0x02 */ SDL_SCANCODE_UNKNOWN, - /* 3, 0x03 */ SDL_SCANCODE_UNKNOWN, - /* 4, 0x04 */ SDL_SCANCODE_UNKNOWN, - /* 5, 0x05 */ SDL_SCANCODE_UNKNOWN, - /* 6, 0x06 */ SDL_SCANCODE_UNKNOWN, - /* 7, 0x07 */ SDL_SCANCODE_UNKNOWN, - /* 8, 0x08 */ SDL_SCANCODE_BACKSPACE, - /* 9, 0x09 */ SDL_SCANCODE_TAB, - /* 10, 0x0a */ SDL_SCANCODE_KP_ENTER, /* Not a VKEY, SDL specific */ - /* 11, 0x0b */ SDL_SCANCODE_UNKNOWN, - /* 12, 0x0c */ SDL_SCANCODE_CLEAR, - /* 13, 0x0d */ SDL_SCANCODE_RETURN, - /* 14, 0x0e */ SDL_SCANCODE_UNKNOWN, - /* 15, 0x0f */ SDL_SCANCODE_UNKNOWN, - /* 16, 0x10 */ SDL_SCANCODE_UNKNOWN, - /* 17, 0x11 */ SDL_SCANCODE_UNKNOWN, - /* 18, 0x12 */ SDL_SCANCODE_APPLICATION, - /* 19, 0x13 */ SDL_SCANCODE_PAUSE, - /* 20, 0x14 */ SDL_SCANCODE_CAPSLOCK, - /* 21, 0x15 */ SDL_SCANCODE_UNKNOWN, - /* 22, 0x16 */ SDL_SCANCODE_UNKNOWN, - /* 23, 0x17 */ SDL_SCANCODE_UNKNOWN, - /* 24, 0x18 */ SDL_SCANCODE_UNKNOWN, - /* 25, 0x19 */ SDL_SCANCODE_UNKNOWN, - /* 26, 0x1a */ SDL_SCANCODE_UNKNOWN, - /* 27, 0x1b */ SDL_SCANCODE_ESCAPE, - /* 28, 0x1c */ SDL_SCANCODE_UNKNOWN, - /* 29, 0x1d */ SDL_SCANCODE_UNKNOWN, - /* 30, 0x1e */ SDL_SCANCODE_UNKNOWN, - /* 31, 0x1f */ SDL_SCANCODE_MODE, - /* 32, 0x20 */ SDL_SCANCODE_SPACE, - /* 33, 0x21 */ SDL_SCANCODE_PAGEUP, - /* 34, 0x22 */ SDL_SCANCODE_PAGEDOWN, - /* 35, 0x23 */ SDL_SCANCODE_END, - /* 36, 0x24 */ SDL_SCANCODE_HOME, - /* 37, 0x25 */ SDL_SCANCODE_LEFT, - /* 38, 0x26 */ SDL_SCANCODE_UP, - /* 39, 0x27 */ SDL_SCANCODE_RIGHT, - /* 40, 0x28 */ SDL_SCANCODE_DOWN, - /* 41, 0x29 */ SDL_SCANCODE_SELECT, - /* 42, 0x2a */ SDL_SCANCODE_UNKNOWN, /* VK_PRINT */ - /* 43, 0x2b */ SDL_SCANCODE_EXECUTE, - /* 44, 0x2c */ SDL_SCANCODE_PRINTSCREEN, - /* 45, 0x2d */ SDL_SCANCODE_INSERT, - /* 46, 0x2e */ SDL_SCANCODE_DELETE, - /* 47, 0x2f */ SDL_SCANCODE_HELP, - /* 48, 0x30 */ SDL_SCANCODE_0, - /* 49, 0x31 */ SDL_SCANCODE_1, - /* 50, 0x32 */ SDL_SCANCODE_2, - /* 51, 0x33 */ SDL_SCANCODE_3, - /* 52, 0x34 */ SDL_SCANCODE_4, - /* 53, 0x35 */ SDL_SCANCODE_5, - /* 54, 0x36 */ SDL_SCANCODE_6, - /* 55, 0x37 */ SDL_SCANCODE_7, - /* 56, 0x38 */ SDL_SCANCODE_8, - /* 57, 0x39 */ SDL_SCANCODE_9, - /* 58, 0x3a */ SDL_SCANCODE_UNKNOWN, - /* 59, 0x3b */ SDL_SCANCODE_UNKNOWN, - /* 60, 0x3c */ SDL_SCANCODE_UNKNOWN, - /* 61, 0x3d */ SDL_SCANCODE_UNKNOWN, - /* 62, 0x3e */ SDL_SCANCODE_UNKNOWN, - /* 63, 0x3f */ SDL_SCANCODE_UNKNOWN, - /* 64, 0x40 */ SDL_SCANCODE_UNKNOWN, - /* 65, 0x41 */ SDL_SCANCODE_A, - /* 66, 0x42 */ SDL_SCANCODE_B, - /* 67, 0x43 */ SDL_SCANCODE_C, - /* 68, 0x44 */ SDL_SCANCODE_D, - /* 69, 0x45 */ SDL_SCANCODE_E, - /* 70, 0x46 */ SDL_SCANCODE_F, - /* 71, 0x47 */ SDL_SCANCODE_G, - /* 72, 0x48 */ SDL_SCANCODE_H, - /* 73, 0x49 */ SDL_SCANCODE_I, - /* 74, 0x4a */ SDL_SCANCODE_J, - /* 75, 0x4b */ SDL_SCANCODE_K, - /* 76, 0x4c */ SDL_SCANCODE_L, - /* 77, 0x4d */ SDL_SCANCODE_M, - /* 78, 0x4e */ SDL_SCANCODE_N, - /* 79, 0x4f */ SDL_SCANCODE_O, - /* 80, 0x50 */ SDL_SCANCODE_P, - /* 81, 0x51 */ SDL_SCANCODE_Q, - /* 82, 0x52 */ SDL_SCANCODE_R, - /* 83, 0x53 */ SDL_SCANCODE_S, - /* 84, 0x54 */ SDL_SCANCODE_T, - /* 85, 0x55 */ SDL_SCANCODE_U, - /* 86, 0x56 */ SDL_SCANCODE_V, - /* 87, 0x57 */ SDL_SCANCODE_W, - /* 88, 0x58 */ SDL_SCANCODE_X, - /* 89, 0x59 */ SDL_SCANCODE_Y, - /* 90, 0x5a */ SDL_SCANCODE_Z, - /* 91, 0x5b */ SDL_SCANCODE_LGUI, - /* 92, 0x5c */ SDL_SCANCODE_RGUI, - /* 93, 0x5d */ SDL_SCANCODE_APPLICATION, - /* 94, 0x5e */ SDL_SCANCODE_UNKNOWN, - /* 95, 0x5f */ SDL_SCANCODE_UNKNOWN, - /* 96, 0x60 */ SDL_SCANCODE_KP_0, - /* 97, 0x61 */ SDL_SCANCODE_KP_1, - /* 98, 0x62 */ SDL_SCANCODE_KP_2, - /* 99, 0x63 */ SDL_SCANCODE_KP_3, - /* 100, 0x64 */ SDL_SCANCODE_KP_4, - /* 101, 0x65 */ SDL_SCANCODE_KP_5, - /* 102, 0x66 */ SDL_SCANCODE_KP_6, - /* 103, 0x67 */ SDL_SCANCODE_KP_7, - /* 104, 0x68 */ SDL_SCANCODE_KP_8, - /* 105, 0x69 */ SDL_SCANCODE_KP_9, - /* 106, 0x6a */ SDL_SCANCODE_KP_MULTIPLY, - /* 107, 0x6b */ SDL_SCANCODE_KP_PLUS, - /* 108, 0x6c */ SDL_SCANCODE_SEPARATOR, - /* 109, 0x6d */ SDL_SCANCODE_KP_MINUS, - /* 110, 0x6e */ SDL_SCANCODE_KP_DECIMAL, - /* 111, 0x6f */ SDL_SCANCODE_KP_DIVIDE, - /* 112, 0x70 */ SDL_SCANCODE_F1, - /* 113, 0x71 */ SDL_SCANCODE_F2, - /* 114, 0x72 */ SDL_SCANCODE_F3, - /* 115, 0x73 */ SDL_SCANCODE_F4, - /* 116, 0x74 */ SDL_SCANCODE_F5, - /* 117, 0x75 */ SDL_SCANCODE_F6, - /* 118, 0x76 */ SDL_SCANCODE_F7, - /* 119, 0x77 */ SDL_SCANCODE_F8, - /* 120, 0x78 */ SDL_SCANCODE_F9, - /* 121, 0x79 */ SDL_SCANCODE_F10, - /* 122, 0x7a */ SDL_SCANCODE_F11, - /* 123, 0x7b */ SDL_SCANCODE_F12, - /* 124, 0x7c */ SDL_SCANCODE_F13, - /* 125, 0x7d */ SDL_SCANCODE_F14, - /* 126, 0x7e */ SDL_SCANCODE_F15, - /* 127, 0x7f */ SDL_SCANCODE_F16, - /* 128, 0x80 */ SDL_SCANCODE_F17, /* or SDL_SCANCODE_AUDIONEXT */ - /* 129, 0x81 */ SDL_SCANCODE_F18, /* or SDL_SCANCODE_AUDIOPREV */ - /* 130, 0x82 */ SDL_SCANCODE_F19, /* or SDL_SCANCODE_AUDIOSTOP */ - /* 131, 0x83 */ SDL_SCANCODE_F20, /* or SDL_SCANCODE_AUDIOPLAY */ - /* 132, 0x84 */ SDL_SCANCODE_F21, /* or SDL_SCANCODE_MAIL */ - /* 133, 0x85 */ SDL_SCANCODE_F22, /* or SDL_SCANCODE_MEDIASELECT */ - /* 134, 0x86 */ SDL_SCANCODE_F23, /* or SDL_SCANCODE_WWW */ - /* 135, 0x87 */ SDL_SCANCODE_F24, /* or SDL_SCANCODE_CALCULATOR */ - /* 136, 0x88 */ SDL_SCANCODE_UNKNOWN, - /* 137, 0x89 */ SDL_SCANCODE_UNKNOWN, - /* 138, 0x8a */ SDL_SCANCODE_UNKNOWN, - /* 139, 0x8b */ SDL_SCANCODE_UNKNOWN, - /* 140, 0x8c */ SDL_SCANCODE_UNKNOWN, - /* 141, 0x8d */ SDL_SCANCODE_UNKNOWN, - /* 142, 0x8e */ SDL_SCANCODE_UNKNOWN, - /* 143, 0x8f */ SDL_SCANCODE_UNKNOWN, - /* 144, 0x90 */ SDL_SCANCODE_NUMLOCKCLEAR, - /* 145, 0x91 */ SDL_SCANCODE_SCROLLLOCK, - /* 146, 0x92 */ SDL_SCANCODE_KP_EQUALS, - /* 147, 0x93 */ SDL_SCANCODE_UNKNOWN, - /* 148, 0x94 */ SDL_SCANCODE_UNKNOWN, - /* 149, 0x95 */ SDL_SCANCODE_UNKNOWN, - /* 150, 0x96 */ SDL_SCANCODE_UNKNOWN, - /* 151, 0x97 */ SDL_SCANCODE_UNKNOWN, - /* 152, 0x98 */ SDL_SCANCODE_UNKNOWN, - /* 153, 0x99 */ SDL_SCANCODE_UNKNOWN, - /* 154, 0x9a */ SDL_SCANCODE_UNKNOWN, - /* 155, 0x9b */ SDL_SCANCODE_UNKNOWN, - /* 156, 0x9c */ SDL_SCANCODE_UNKNOWN, - /* 157, 0x9d */ SDL_SCANCODE_UNKNOWN, - /* 158, 0x9e */ SDL_SCANCODE_UNKNOWN, - /* 159, 0x9f */ SDL_SCANCODE_UNKNOWN, - /* 160, 0xa0 */ SDL_SCANCODE_LSHIFT, - /* 161, 0xa1 */ SDL_SCANCODE_RSHIFT, - /* 162, 0xa2 */ SDL_SCANCODE_LCTRL, - /* 163, 0xa3 */ SDL_SCANCODE_RCTRL, - /* 164, 0xa4 */ SDL_SCANCODE_LALT, - /* 165, 0xa5 */ SDL_SCANCODE_RALT, - /* 166, 0xa6 */ SDL_SCANCODE_AC_BACK, - /* 167, 0xa7 */ SDL_SCANCODE_AC_FORWARD, - /* 168, 0xa8 */ SDL_SCANCODE_AC_REFRESH, - /* 169, 0xa9 */ SDL_SCANCODE_AC_STOP, - /* 170, 0xaa */ SDL_SCANCODE_AC_SEARCH, - /* 171, 0xab */ SDL_SCANCODE_AC_BOOKMARKS, - /* 172, 0xac */ SDL_SCANCODE_AC_HOME, - /* 173, 0xad */ SDL_SCANCODE_AUDIOMUTE, - /* 174, 0xae */ SDL_SCANCODE_VOLUMEDOWN, - /* 175, 0xaf */ SDL_SCANCODE_VOLUMEUP, - /* 176, 0xb0 */ SDL_SCANCODE_AUDIONEXT, - /* 177, 0xb1 */ SDL_SCANCODE_AUDIOPREV, - /* 178, 0xb2 */ SDL_SCANCODE_AUDIOSTOP, - /* 179, 0xb3 */ SDL_SCANCODE_AUDIOPLAY, - /* 180, 0xb4 */ SDL_SCANCODE_MAIL, - /* 181, 0xb5 */ SDL_SCANCODE_MEDIASELECT, - /* 182, 0xb6 */ SDL_SCANCODE_UNKNOWN, /* VK_LAUNCH_APP1 */ - /* 183, 0xb7 */ SDL_SCANCODE_UNKNOWN, /* VK_LAUNCH_APP2 */ - /* 184, 0xb8 */ SDL_SCANCODE_UNKNOWN, - /* 185, 0xb9 */ SDL_SCANCODE_UNKNOWN, - /* 186, 0xba */ SDL_SCANCODE_SEMICOLON, - /* 187, 0xbb */ SDL_SCANCODE_EQUALS, - /* 188, 0xbc */ SDL_SCANCODE_COMMA, - /* 189, 0xbd */ SDL_SCANCODE_MINUS, - /* 190, 0xbe */ SDL_SCANCODE_PERIOD, - /* 191, 0xbf */ SDL_SCANCODE_SLASH, - /* 192, 0xc0 */ SDL_SCANCODE_GRAVE, - /* 193, 0xc1 */ SDL_SCANCODE_UNKNOWN, - /* 194, 0xc2 */ SDL_SCANCODE_UNKNOWN, - /* 195, 0xc3 */ SDL_SCANCODE_UNKNOWN, - /* 196, 0xc4 */ SDL_SCANCODE_UNKNOWN, - /* 197, 0xc5 */ SDL_SCANCODE_UNKNOWN, - /* 198, 0xc6 */ SDL_SCANCODE_UNKNOWN, - /* 199, 0xc7 */ SDL_SCANCODE_UNKNOWN, - /* 200, 0xc8 */ SDL_SCANCODE_UNKNOWN, - /* 201, 0xc9 */ SDL_SCANCODE_UNKNOWN, - /* 202, 0xca */ SDL_SCANCODE_UNKNOWN, - /* 203, 0xcb */ SDL_SCANCODE_UNKNOWN, - /* 204, 0xcc */ SDL_SCANCODE_UNKNOWN, - /* 205, 0xcd */ SDL_SCANCODE_UNKNOWN, - /* 206, 0xce */ SDL_SCANCODE_UNKNOWN, - /* 207, 0xcf */ SDL_SCANCODE_UNKNOWN, - /* 208, 0xd0 */ SDL_SCANCODE_UNKNOWN, - /* 209, 0xd1 */ SDL_SCANCODE_UNKNOWN, - /* 210, 0xd2 */ SDL_SCANCODE_UNKNOWN, - /* 211, 0xd3 */ SDL_SCANCODE_UNKNOWN, - /* 212, 0xd4 */ SDL_SCANCODE_UNKNOWN, - /* 213, 0xd5 */ SDL_SCANCODE_UNKNOWN, - /* 214, 0xd6 */ SDL_SCANCODE_UNKNOWN, - /* 215, 0xd7 */ SDL_SCANCODE_UNKNOWN, - /* 216, 0xd8 */ SDL_SCANCODE_UNKNOWN, - /* 217, 0xd9 */ SDL_SCANCODE_UNKNOWN, - /* 218, 0xda */ SDL_SCANCODE_UNKNOWN, - /* 219, 0xdb */ SDL_SCANCODE_LEFTBRACKET, - /* 220, 0xdc */ SDL_SCANCODE_BACKSLASH, - /* 221, 0xdd */ SDL_SCANCODE_RIGHTBRACKET, - /* 222, 0xde */ SDL_SCANCODE_APOSTROPHE, - /* 223, 0xdf */ SDL_SCANCODE_UNKNOWN, - /* 224, 0xe0 */ SDL_SCANCODE_UNKNOWN, - /* 225, 0xe1 */ SDL_SCANCODE_UNKNOWN, - /* 226, 0xe2 */ SDL_SCANCODE_NONUSBACKSLASH, - /* 227, 0xe3 */ SDL_SCANCODE_UNKNOWN, - /* 228, 0xe4 */ SDL_SCANCODE_UNKNOWN, - /* 229, 0xe5 */ SDL_SCANCODE_UNKNOWN, - /* 230, 0xe6 */ SDL_SCANCODE_UNKNOWN, - /* 231, 0xe7 */ SDL_SCANCODE_UNKNOWN, - /* 232, 0xe8 */ SDL_SCANCODE_UNKNOWN, - /* 233, 0xe9 */ SDL_SCANCODE_UNKNOWN, - /* 234, 0xea */ SDL_SCANCODE_UNKNOWN, - /* 235, 0xeb */ SDL_SCANCODE_UNKNOWN, - /* 236, 0xec */ SDL_SCANCODE_UNKNOWN, - /* 237, 0xed */ SDL_SCANCODE_UNKNOWN, - /* 238, 0xee */ SDL_SCANCODE_UNKNOWN, - /* 239, 0xef */ SDL_SCANCODE_UNKNOWN, - /* 240, 0xf0 */ SDL_SCANCODE_UNKNOWN, - /* 241, 0xf1 */ SDL_SCANCODE_UNKNOWN, - /* 242, 0xf2 */ SDL_SCANCODE_UNKNOWN, - /* 243, 0xf3 */ SDL_SCANCODE_UNKNOWN, - /* 244, 0xf4 */ SDL_SCANCODE_UNKNOWN, - /* 245, 0xf5 */ SDL_SCANCODE_UNKNOWN, - /* 246, 0xf6 */ SDL_SCANCODE_SYSREQ, - /* 247, 0xf7 */ SDL_SCANCODE_CRSEL, - /* 248, 0xf8 */ SDL_SCANCODE_EXSEL, - /* 249, 0xf9 */ SDL_SCANCODE_UNKNOWN, /* VK_EREOF */ - /* 250, 0xfa */ SDL_SCANCODE_UNKNOWN, /* VK_PLAY */ - /* 251, 0xfb */ SDL_SCANCODE_UNKNOWN, /* VK_ZOOM */ - /* 252, 0xfc */ SDL_SCANCODE_UNKNOWN, - /* 253, 0xfd */ SDL_SCANCODE_UNKNOWN, /* VK_PA1 */ - /* 254, 0xfe */ SDL_SCANCODE_CLEAR, - /* 255, 0xff */ SDL_SCANCODE_UNKNOWN, +// this maps non-translated keyboard scan codes to engine key codes +// Google for 'Keyboard Scan Code Specification' +static const SDL_Scancode windows_scancode_table[] = +{ + // 0 1 2 3 4 5 6 7 + // 8 9 A B C D E F + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, // 0 + SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, // 0 + + SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, // 1 + SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, // 1 + + SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, // 2 + SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, // 2 + + SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,// 3 + SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, // 3 + + SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK,SDL_SCANCODE_HOME, // 4 + SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, // 4 + + SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F11, // 5 + SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 5 + + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6 + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6 + + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 7 + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN // 7 }; + /* *INDENT-ON* */ diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 863daf7ec..34baac8da 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -105,6 +105,126 @@ RemapVKEY(WPARAM wParam, LPARAM lParam) return wParam; } +static SDL_Scancode +WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map ) +{ + SDL_Scancode code; + char bIsExtended; + int nScanCode = ( lParam >> 16 ) & 0xFF; + + if ( nScanCode == 0 ) + { + switch( wParam ) + { + case VK_CLEAR: return SDL_SCANCODE_CLEAR; + case VK_MODECHANGE: return SDL_SCANCODE_MODE; + case VK_SELECT: return SDL_SCANCODE_SELECT; + case VK_EXECUTE: return SDL_SCANCODE_EXECUTE; + case VK_HELP: return SDL_SCANCODE_HELP; + + case VK_F13: return SDL_SCANCODE_F13; + case VK_F14: return SDL_SCANCODE_F14; + case VK_F15: return SDL_SCANCODE_F15; + case VK_F16: return SDL_SCANCODE_F16; + case VK_F17: return SDL_SCANCODE_F17; + case VK_F18: return SDL_SCANCODE_F18; + case VK_F19: return SDL_SCANCODE_F19; + case VK_F20: return SDL_SCANCODE_F20; + case VK_F21: return SDL_SCANCODE_F21; + case VK_F22: return SDL_SCANCODE_F22; + case VK_F23: return SDL_SCANCODE_F23; + case VK_F24: return SDL_SCANCODE_F24; + + case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS; + case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK; + case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD; + case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH; + case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP; + case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH; + case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS; + case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME; + case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE; + case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN; + case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP; + + case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT; + case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV; + case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP; + case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY; + case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL; + case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT; + + case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH; + + case VK_ATTN: return SDL_SCANCODE_SYSREQ; + case VK_CRSEL: return SDL_SCANCODE_CRSEL; + case VK_EXSEL: return SDL_SCANCODE_EXSEL; + case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR; + + case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1; + case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2; + + default: return SDL_SCANCODE_UNKNOWN; + } + } + + if ( nScanCode > 127 ) + return SDL_SCANCODE_UNKNOWN; + + code = key_map[nScanCode]; + + bIsExtended = ( lParam & ( 1 << 24 ) ) != 0; + if ( !bIsExtended ) + { + switch ( code ) + { + case SDL_SCANCODE_HOME: + return SDL_SCANCODE_KP_7; + case SDL_SCANCODE_UP: + return SDL_SCANCODE_KP_8; + case SDL_SCANCODE_PAGEUP: + return SDL_SCANCODE_KP_9; + case SDL_SCANCODE_LEFT: + return SDL_SCANCODE_KP_4; + case SDL_SCANCODE_RIGHT: + return SDL_SCANCODE_KP_6; + case SDL_SCANCODE_END: + return SDL_SCANCODE_KP_1; + case SDL_SCANCODE_DOWN: + return SDL_SCANCODE_KP_2; + case SDL_SCANCODE_PAGEDOWN: + return SDL_SCANCODE_KP_3; + case SDL_SCANCODE_INSERT: + return SDL_SCANCODE_KP_0; + case SDL_SCANCODE_DELETE: + return SDL_SCANCODE_KP_DECIMAL; + case SDL_SCANCODE_PRINTSCREEN: + return SDL_SCANCODE_KP_MULTIPLY; + default: + break; + } + } + else + { + switch ( code ) + { + case SDL_SCANCODE_RETURN: + return SDL_SCANCODE_KP_ENTER; + case SDL_SCANCODE_LALT: + return SDL_SCANCODE_RALT; + case SDL_SCANCODE_LCTRL: + return SDL_SCANCODE_RCTRL; + case SDL_SCANCODE_SLASH: + return SDL_SCANCODE_KP_DIVIDE; + case SDL_SCANCODE_CAPSLOCK: + return SDL_SCANCODE_KP_PLUS; + } + } + + return code; +} + + LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -311,6 +431,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYDOWN: case WM_KEYDOWN: { + SDL_Scancode code; wParam = RemapVKEY(wParam, lParam); switch (wParam) { case VK_CONTROL: @@ -346,9 +467,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) wParam = VK_ENTER; break; } - if (wParam < 256) { - SDL_SendKeyboardKey(SDL_PRESSED, - data->videodata->key_layout[wParam]); + code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); + if ( code != SDL_SCANCODE_UNKNOWN ) { + SDL_SendKeyboardKey(SDL_PRESSED, code ); } } returnCode = 0; @@ -357,7 +478,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYUP: case WM_KEYUP: { - wParam = RemapVKEY(wParam, lParam); + SDL_Scancode code; + wParam = RemapVKEY(wParam, lParam); switch (wParam) { case VK_CONTROL: if (lParam & EXTENDED_KEYMASK) @@ -394,15 +516,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } /* Windows only reports keyup for print screen */ - if (wParam == VK_SNAPSHOT - && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == - SDL_RELEASED) { - SDL_SendKeyboardKey(SDL_PRESSED, - data->videodata->key_layout[wParam]); - } - if (wParam < 256) { - SDL_SendKeyboardKey(SDL_RELEASED, - data->videodata->key_layout[wParam]); + code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); + if ( code != SDL_SCANCODE_UNKNOWN ) { + if (wParam == VK_SNAPSHOT + && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == + SDL_RELEASED) { + SDL_SendKeyboardKey(SDL_PRESSED, + code); + } + SDL_SendKeyboardKey(SDL_RELEASED, code ); } } returnCode = 0; diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index dcdd78455..26695f7a0 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -90,6 +90,7 @@ WIN_InitKeyboard(_THIS) } } + // windows scancode to SDL scancode table data->key_layout = windows_scancode_table; data->ime_com_initialized = SDL_FALSE; @@ -150,24 +151,28 @@ WIN_UpdateKeymap() SDL_Scancode scancode; SDL_Keycode keymap[SDL_NUM_SCANCODES]; - SDL_GetDefaultKeymap(keymap); + for (i = 0; i < SDL_arraysize(keymap); ++i) + { + keymap[i] = SDL_SCANCODE_TO_KEYCODE( i ); + } for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) { - + int vk; /* Make sure this scancode is a valid character scancode */ scancode = windows_scancode_table[i]; - if (scancode == SDL_SCANCODE_UNKNOWN || keymap[scancode] >= 127) { + if (scancode == SDL_SCANCODE_UNKNOWN ) { continue; } - /* Alphabetic keys are handled specially, since Windows remaps them */ - if (i >= 'A' && i <= 'Z') { - BYTE vsc = alpha_scancodes[i - 'A']; - keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20; - } else { - keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF); - } + vk = MapVirtualKey(i, MAPVK_VSC_TO_VK); + if ( vk ) { + int ch; + ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF); + if ( ch ) + keymap[scancode] = ch; + } } + SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); } diff --git a/test/checkkeys.c b/test/checkkeys.c index fdbce60dd..49dc277b2 100644 --- a/test/checkkeys.c +++ b/test/checkkeys.c @@ -105,7 +105,7 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) "Unknown Key (scancode %d = %s) %s ", sym->scancode, SDL_GetScancodeName(sym->scancode), - pressed ? "pressed" : "released"); + pressed ? "pressed " : "released"); } /* Print the translated character, if one exists */ @@ -129,13 +129,13 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) if (repeat) { print_string(&spot, &left, " (repeat)"); } - SDL_Log("%s", message); + SDL_Log("%s\n", message); } static void PrintText(char *text) { - SDL_Log("Text: %s", text); + SDL_Log("Text: %s\n", text); } int From a3482e3ac04b1620014b278755eec648a80794d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Mon, 25 Feb 2013 16:52:48 -0800 Subject: [PATCH 014/151] sdl2 - fix atomic header to compile happily under msvc 6.0 --- include/SDL_atomic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index 2f1734963..bba530102 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -126,7 +126,7 @@ extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock); * The compiler barrier prevents the compiler from reordering * reads and writes to globally visible variables across the call. */ -#ifdef _MSC_VER +#if defined(_MSC_VER) && (_MSC_VER > 1200) void _ReadWriteBarrier(void); #pragma intrinsic(_ReadWriteBarrier) #define SDL_CompilerBarrier() _ReadWriteBarrier() @@ -134,7 +134,7 @@ void _ReadWriteBarrier(void); #define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory") #else #define SDL_CompilerBarrier() \ -({ SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }) +{ SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); } #endif /* Platform specific optimized versions of the atomic functions, From ef5e7f5c65074e804ba4cf90959f2c7396db4d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Mon, 25 Feb 2013 16:52:50 -0800 Subject: [PATCH 015/151] sdl2 - fix ref counting on init, make sure you refcount each init calls and not just the first one --- src/SDL.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/SDL.c b/src/SDL.c index 6011612a9..53e0e7449 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -105,10 +105,12 @@ SDL_InitSubSystem(Uint32 flags) #endif /* Initialize the timer subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_TIMER)) { + if ((flags & SDL_INIT_TIMER) ){ + if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_TIMER)) { #if !SDL_TIMERS_DISABLED - if (SDL_TimerInit() < 0) { - return (-1); + if (SDL_TimerInit() < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER); #else @@ -118,10 +120,12 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the video/event subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_VIDEO)) { + if ((flags & SDL_INIT_VIDEO) ){ + if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_VIDEO)) { #if !SDL_VIDEO_DISABLED - if (SDL_VideoInit(NULL) < 0) { - return (-1); + if (SDL_VideoInit(NULL) < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO); #else @@ -131,10 +135,12 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the audio subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_AUDIO)) { + if ((flags & SDL_INIT_AUDIO) ){ + if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_AUDIO)) { #if !SDL_AUDIO_DISABLED - if (SDL_AudioInit(NULL) < 0) { - return (-1); + if (SDL_AudioInit(NULL) < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO); #else @@ -149,10 +155,12 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the joystick subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_JOYSTICK)) { + if ((flags & SDL_INIT_JOYSTICK) ){ + if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_JOYSTICK)) { #if !SDL_JOYSTICK_DISABLED - if (SDL_JoystickInit() < 0) { - return (-1); + if (SDL_JoystickInit() < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK); #else @@ -161,10 +169,12 @@ SDL_InitSubSystem(Uint32 flags) #endif } - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_GAMECONTROLLER)) { + if ((flags & SDL_INIT_GAMECONTROLLER) ){ + if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_GAMECONTROLLER)) { #if !SDL_JOYSTICK_DISABLED - if (SDL_GameControllerInit() < 0) { - return (-1); + if (SDL_GameControllerInit() < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER); #else @@ -174,10 +184,12 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the haptic subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_HAPTIC)) { + if ((flags & SDL_INIT_HAPTIC) ){ + if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_HAPTIC)) { #if !SDL_HAPTIC_DISABLED - if (SDL_HapticInit() < 0) { - return (-1); + if (SDL_HapticInit() < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC); #else From 383deb9a6139e5b2ed72b33b604625759eda676d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Mon, 25 Feb 2013 16:52:51 -0800 Subject: [PATCH 016/151] sdl2 - more scancode goodness, removing now dead wparam translation code - add scancode for SDL_SCANCODE_NONUSBACKSLASH - don't translate sdl key values for numeric and grave key CR: SamL --- src/events/scancodes_windows.h | 36 ++++---- src/video/windows/SDL_windowsevents.c | 118 +----------------------- src/video/windows/SDL_windowskeyboard.c | 6 ++ 3 files changed, 26 insertions(+), 134 deletions(-) diff --git a/src/events/scancodes_windows.h b/src/events/scancodes_windows.h index e2c91ab38..3aee7e609 100644 --- a/src/events/scancodes_windows.h +++ b/src/events/scancodes_windows.h @@ -29,31 +29,31 @@ // Google for 'Keyboard Scan Code Specification' static const SDL_Scancode windows_scancode_table[] = { - // 0 1 2 3 4 5 6 7 - // 8 9 A B C D E F - SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, // 0 - SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, // 0 + // 0 1 2 3 4 5 6 7 + // 8 9 A B C D E F + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, // 0 + SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, // 0 - SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, // 1 - SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, // 1 + SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, // 1 + SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, // 1 - SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, // 2 - SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, // 2 + SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, // 2 + SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, // 2 - SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,// 3 - SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, // 3 + SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,// 3 + SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, // 3 - SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK,SDL_SCANCODE_HOME, // 4 - SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, // 4 + SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, // 4 + SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, // 4 - SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F11, // 5 - SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 5 + SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH,SDL_SCANCODE_F11, // 5 + SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 5 - SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6 - SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6 + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6 + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6 - SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 7 - SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN // 7 + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 7 + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN // 7 }; /* *INDENT-ON* */ diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 34baac8da..658845e93 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -65,46 +65,6 @@ #endif -static WPARAM -RemapVKEY(WPARAM wParam, LPARAM lParam) -{ - int i; - BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF); - - /* Windows remaps alphabetic keys based on current layout. - We try to provide USB scancodes, so undo this mapping. - */ - if (wParam >= 'A' && wParam <= 'Z') { - if (scancode != alpha_scancodes[wParam - 'A']) { - for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) { - if (scancode == alpha_scancodes[i]) { - wParam = 'A' + i; - break; - } - } - } - } - - /* Keypad keys are a little trickier, we always scan for them. - Keypad arrow keys have the same scancode as normal arrow keys, - except they don't have the extended bit (0x1000000) set. - */ - if (!(lParam & 0x1000000)) { - if (wParam == VK_DELETE) { - wParam = VK_DECIMAL; - } else { - for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) { - if (scancode == keypad_scancodes[i]) { - wParam = VK_NUMPAD0 + i; - break; - } - } - } - } - - return wParam; -} - static SDL_Scancode WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map ) { @@ -431,43 +391,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYDOWN: case WM_KEYDOWN: { - SDL_Scancode code; - wParam = RemapVKEY(wParam, lParam); - switch (wParam) { - case VK_CONTROL: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_RCONTROL; - else - wParam = VK_LCONTROL; - break; - case VK_SHIFT: - /* EXTENDED trick doesn't work here */ - { - Uint8 *state = SDL_GetKeyboardState(NULL); - if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED - && (GetKeyState(VK_LSHIFT) & 0x8000)) { - wParam = VK_LSHIFT; - } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED - && (GetKeyState(VK_RSHIFT) & 0x8000)) { - wParam = VK_RSHIFT; - } else { - /* Probably a key repeat */ - wParam = 256; - } - } - break; - case VK_MENU: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_RMENU; - else - wParam = VK_LMENU; - break; - case VK_RETURN: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_ENTER; - break; - } - code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); + SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); if ( code != SDL_SCANCODE_UNKNOWN ) { SDL_SendKeyboardKey(SDL_PRESSED, code ); } @@ -478,45 +402,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYUP: case WM_KEYUP: { - SDL_Scancode code; - wParam = RemapVKEY(wParam, lParam); - switch (wParam) { - case VK_CONTROL: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_RCONTROL; - else - wParam = VK_LCONTROL; - break; - case VK_SHIFT: - /* EXTENDED trick doesn't work here */ - { - Uint8 *state = SDL_GetKeyboardState(NULL); - if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED - && !(GetKeyState(VK_LSHIFT) & 0x8000)) { - wParam = VK_LSHIFT; - } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED - && !(GetKeyState(VK_RSHIFT) & 0x8000)) { - wParam = VK_RSHIFT; - } else { - /* Probably a key repeat */ - wParam = 256; - } - } - break; - case VK_MENU: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_RMENU; - else - wParam = VK_LMENU; - break; - case VK_RETURN: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_ENTER; - break; - } - - /* Windows only reports keyup for print screen */ - code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); + SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); if ( code != SDL_SCANCODE_UNKNOWN ) { if (wParam == VK_SNAPSHOT && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index 26695f7a0..9dfc369c9 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -163,6 +163,12 @@ WIN_UpdateKeymap() if (scancode == SDL_SCANCODE_UNKNOWN ) { continue; } + /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */ + /* not mapping numbers fixes the AZERTY layout (french) causing non-shifted number to appear by default */ + if ( ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) || + scancode == SDL_SCANCODE_GRAVE ) { + continue; + } vk = MapVirtualKey(i, MAPVK_VSC_TO_VK); if ( vk ) { From 05631f0599c447d5a58cc5d46aee2179557b4fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Mon, 25 Feb 2013 16:52:52 -0800 Subject: [PATCH 017/151] sdl - fix win32 mapping of alpha-numeric keys after scancode changes --- src/video/windows/SDL_windowskeyboard.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index 9dfc369c9..fd2510413 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -165,8 +165,12 @@ WIN_UpdateKeymap() } /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */ /* not mapping numbers fixes the AZERTY layout (french) causing non-shifted number to appear by default */ - if ( ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) || - scancode == SDL_SCANCODE_GRAVE ) { + if ( scancode == SDL_SCANCODE_GRAVE ) { + keymap[scancode] = SDLK_BACKQUOTE; + continue; + } + if ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) { + keymap[scancode] = SDLK_1 + ( scancode - SDL_SCANCODE_1 ); continue; } @@ -175,7 +179,13 @@ WIN_UpdateKeymap() int ch; ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF); if ( ch ) - keymap[scancode] = ch; + { + if ( ch >= 'A' && ch <= 'Z' ) + keymap[scancode] = SDLK_a + ( ch - 'A' ); + else + keymap[scancode] = ch; + } + } } From e02925eca9b55d61a63ed49428a3c8a4d668d01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Mon, 25 Feb 2013 16:52:54 -0800 Subject: [PATCH 018/151] Cleanup of SDL_PrivateShouldInitSubsystem. Also fixes a build error if a module was disabled. --- src/SDL.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/SDL.c b/src/SDL.c index 53e0e7449..ae279860d 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -68,14 +68,9 @@ SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem) /* Private helper to check if a system needs init. */ static SDL_bool -SDL_PrivateShouldInitSubsystem(Uint32 flags, Uint32 subsystem) +SDL_PrivateShouldInitSubsystem(Uint32 subsystem) { - int subsystem_index; - if ((flags & subsystem) == 0) { - return SDL_FALSE; - } - - subsystem_index = SDL_MostSignificantBitIndex32(subsystem); + int subsystem_index = SDL_MostSignificantBitIndex32(subsystem); SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255); return (SDL_SubsystemRefCount[subsystem_index] == 0); } @@ -106,8 +101,8 @@ SDL_InitSubSystem(Uint32 flags) /* Initialize the timer subsystem */ if ((flags & SDL_INIT_TIMER) ){ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_TIMER)) { #if !SDL_TIMERS_DISABLED + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) { if (SDL_TimerInit() < 0) { return (-1); } @@ -121,8 +116,8 @@ SDL_InitSubSystem(Uint32 flags) /* Initialize the video/event subsystem */ if ((flags & SDL_INIT_VIDEO) ){ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_VIDEO)) { #if !SDL_VIDEO_DISABLED + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) { if (SDL_VideoInit(NULL) < 0) { return (-1); } @@ -136,8 +131,8 @@ SDL_InitSubSystem(Uint32 flags) /* Initialize the audio subsystem */ if ((flags & SDL_INIT_AUDIO) ){ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_AUDIO)) { #if !SDL_AUDIO_DISABLED + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) { if (SDL_AudioInit(NULL) < 0) { return (-1); } @@ -156,8 +151,8 @@ SDL_InitSubSystem(Uint32 flags) /* Initialize the joystick subsystem */ if ((flags & SDL_INIT_JOYSTICK) ){ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_JOYSTICK)) { #if !SDL_JOYSTICK_DISABLED + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) { if (SDL_JoystickInit() < 0) { return (-1); } @@ -170,8 +165,8 @@ SDL_InitSubSystem(Uint32 flags) } if ((flags & SDL_INIT_GAMECONTROLLER) ){ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_GAMECONTROLLER)) { #if !SDL_JOYSTICK_DISABLED + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) { if (SDL_GameControllerInit() < 0) { return (-1); } @@ -185,11 +180,11 @@ SDL_InitSubSystem(Uint32 flags) /* Initialize the haptic subsystem */ if ((flags & SDL_INIT_HAPTIC) ){ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_HAPTIC)) { #if !SDL_HAPTIC_DISABLED + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) { if (SDL_HapticInit() < 0) { - return (-1); - } + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC); #else @@ -441,4 +436,4 @@ _DllMainCRTStartup(HANDLE hModule, #endif /* __WIN32__ */ -/* vi: set ts=4 sw=4 expandtab: */ +/* vi: set sts=4 ts=4 sw=4 expandtab: */ From 7065167e8c47d58183c16a39ecacb47e28b29346 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Feb 2013 03:34:34 -0800 Subject: [PATCH 019/151] Fixed bug 1728 - fixed compiler warnings --- src/render/opengles2/SDL_render_gles2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 457bfc87d..51e3e37e5 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -1258,6 +1258,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s case SDL_PIXELFORMAT_RGB888: sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; break; + default: + return -1; } } if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0) @@ -1424,6 +1426,8 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect case SDL_PIXELFORMAT_RGB888: sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; break; + default: + return -1; } } if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0) From 3269062684ea50dfca5a5a7cf8a51ed86a4fc06a Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Tue, 26 Feb 2013 07:50:42 -0800 Subject: [PATCH 020/151] Fix cygwin compile --- src/video/windows/SDL_windowsevents.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 658845e93..6a9762a9d 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -64,6 +64,10 @@ #define WM_TOUCH 0x0240 #endif +/* Fix cygwin compile */ +#ifndef VK_OEM_NEC_EQUAL +#define VK_OEM_NEC_EQUAL 0x92 +#endif static SDL_Scancode WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map ) From 1984b3b92ed338dc34725a51f72b940db3e2de79 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Tue, 26 Feb 2013 13:53:02 -0300 Subject: [PATCH 021/151] Fixes wrong assignment of SDL_Color "unused" member in DirectFB backend. --- src/video/directfb/SDL_DirectFB_render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/directfb/SDL_DirectFB_render.c b/src/video/directfb/SDL_DirectFB_render.c index da8110427..9fb0b26b2 100644 --- a/src/video/directfb/SDL_DirectFB_render.c +++ b/src/video/directfb/SDL_DirectFB_render.c @@ -669,7 +669,7 @@ DirectFB_GetTexturePalette(SDL_Renderer * renderer, colors[i].r = entries[i].r; colors[i].g = entries[i].g; colors[i].b = entries[i].b; - colors->unused = SDL_ALPHA_OPAQUE; + colors[i].unused = SDL_ALPHA_OPAQUE; } return 0; } else { From a2dccaee2bf077e489b66cf3ae2b53c3b643ea23 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Feb 2013 20:32:11 -0800 Subject: [PATCH 022/151] Fixed cygwin compile --- src/video/windows/SDL_windowsevents.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 6a9762a9d..5c2be9ad8 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -46,6 +46,9 @@ #define EXTENDED_KEYMASK (1<<24) #define VK_ENTER 10 /* Keypad Enter ... no VKEY defined? */ +#ifndef VK_OEM_NEC_EQUAL +#define VK_OEM_NEC_EQUAL 0x92 +#endif /* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */ #ifndef WM_XBUTTONDOWN @@ -64,11 +67,6 @@ #define WM_TOUCH 0x0240 #endif -/* Fix cygwin compile */ -#ifndef VK_OEM_NEC_EQUAL -#define VK_OEM_NEC_EQUAL 0x92 -#endif - static SDL_Scancode WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map ) { From 2204530a1b96e0c15d07ddea03973dd0ac647ec3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Feb 2013 20:41:28 -0800 Subject: [PATCH 023/151] Fixed gcc pedantic warnings in public headers --- include/SDL_gamecontroller.h | 23 ++++++++++------------- src/joystick/SDL_gamecontroller.c | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h index 7cb9ed1f4..b379d7eec 100644 --- a/include/SDL_gamecontroller.h +++ b/include/SDL_gamecontroller.h @@ -62,23 +62,20 @@ typedef enum } SDL_GameControllerBindType; /** - * get the sdl joystick layer binding for this controller button/axis mapping + * Get the SDL joystick layer binding for this controller button/axis mapping */ -struct _SDL_GameControllerHatBind +typedef struct SDL_GameControllerButtonBind { - int hat; - int hat_mask; -}; - -typedef struct _SDL_GameControllerButtonBind -{ - SDL_GameControllerBindType m_eBindType; + SDL_GameControllerBindType bindType; union { int button; int axis; - struct _SDL_GameControllerHatBind hat; - }; + struct { + int hat; + int hat_mask; + } hat; + } value; } SDL_GameControllerButtonBind; @@ -190,7 +187,7 @@ typedef enum extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString); /** - * get the sdl joystick layer binding for this controller button mapping + * Get the SDL joystick layer binding for this controller button mapping */ extern DECLSPEC SDL_GameControllerButtonBind SDLCALL SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller, @@ -238,7 +235,7 @@ extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFrom /** - * get the sdl joystick layer binding for this controller button mapping + * Get the SDL joystick layer binding for this controller button mapping */ extern DECLSPEC SDL_GameControllerButtonBind SDLCALL SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller, diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 24bf07a00..34c239a0e 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -945,13 +945,13 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController if (gamecontroller->mapping.axes[axis] >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_AXIS; - bind.button = gamecontroller->mapping.axes[axis]; + bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS; + bind.value.button = gamecontroller->mapping.axes[axis]; } else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_BUTTON; - bind.button = gamecontroller->mapping.buttonasaxis[axis]; + bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON; + bind.value.button = gamecontroller->mapping.buttonasaxis[axis]; } return bind; @@ -971,19 +971,19 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameControll if ( gamecontroller->mapping.buttons[button] >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_BUTTON; - bind.button = gamecontroller->mapping.buttons[button]; + bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON; + bind.value.button = gamecontroller->mapping.buttons[button]; } else if ( gamecontroller->mapping.axesasbutton[button] >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_AXIS; - bind.axis = gamecontroller->mapping.axesasbutton[button]; + bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS; + bind.value.axis = gamecontroller->mapping.axesasbutton[button]; } else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_HAT; - bind.hat.hat = gamecontroller->mapping.hatasbutton[button].hat; - bind.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask; + bind.bindType = SDL_CONTROLLER_BINDTYPE_HAT; + bind.value.hat.hat = gamecontroller->mapping.hatasbutton[button].hat; + bind.value.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask; } return bind; From 90cde1bd46f215d199ebabea2c7c11769829ed8e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Feb 2013 16:31:52 -0800 Subject: [PATCH 024/151] Check to make sure we can connect to PulseAudio before we use it. --- src/audio/pulseaudio/SDL_pulseaudio.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index 2d3897546..b5479861a 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -205,6 +205,27 @@ load_pulseaudio_syms(void) } +/* Check to see if we can connect to PulseAudio */ +static SDL_bool +CheckPulseAudioAvailable() +{ + pa_simple *s; + pa_sample_spec ss; + + ss.format = PA_SAMPLE_S16NE; + ss.channels = 1; + ss.rate = 22050; + + s = PULSEAUDIO_pa_simple_new(NULL, "SDL", PA_STREAM_PLAYBACK, NULL, + "Test", &ss, NULL, NULL, NULL); + if (s) { + PULSEAUDIO_pa_simple_free(s); + return SDL_TRUE; + } else { + return SDL_FALSE; + } +} + /* This function waits until it is possible to write a full sound buffer */ static void PULSEAUDIO_WaitDevice(_THIS) @@ -476,7 +497,6 @@ PULSEAUDIO_Deinitialize(void) UnloadPulseAudioLibrary(); } - static int PULSEAUDIO_Init(SDL_AudioDriverImpl * impl) { @@ -484,6 +504,10 @@ PULSEAUDIO_Init(SDL_AudioDriverImpl * impl) return 0; } + if (!CheckPulseAudioAvailable()) { + return 0; + } + /* Set the function pointers */ impl->OpenDevice = PULSEAUDIO_OpenDevice; impl->PlayDevice = PULSEAUDIO_PlayDevice; From a5e77bb96fdc7ab12b9703bc4b3ac9d161fccf98 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Feb 2013 23:26:00 -0800 Subject: [PATCH 025/151] Unload the PulseAudio library if the pulseaudio connection isn't available. --- src/audio/pulseaudio/SDL_pulseaudio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index b5479861a..cf3522b1b 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -505,6 +505,7 @@ PULSEAUDIO_Init(SDL_AudioDriverImpl * impl) } if (!CheckPulseAudioAvailable()) { + UnloadPulseAudioLibrary(); return 0; } From ee2441440697359ce5cc723c42581e1f9f40e44a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 27 Feb 2013 11:39:38 -0800 Subject: [PATCH 026/151] Generate debug info for all configurations on all platforms Turned off C++ exception handling for all configurations and all platforms Turned on comdat folding and optimized references for all optimized builds CR: Bruce Dawson --- VisualC/SDL/SDL_VS2008.vcproj | 1332 +---------------- VisualC/SDL/SDL_VS2010.vcxproj | 11 +- VisualC/SDL/SDL_VS2012.vcxproj | 924 ++++++------ .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes 6 files changed, 487 insertions(+), 1780 deletions(-) diff --git a/VisualC/SDL/SDL_VS2008.vcproj b/VisualC/SDL/SDL_VS2008.vcproj index 5fca5ab1d..8a6c37a2c 100644 --- a/VisualC/SDL/SDL_VS2008.vcproj +++ b/VisualC/SDL/SDL_VS2008.vcproj @@ -1,2644 +1,1332 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/VisualC/SDL/SDL_VS2010.vcxproj b/VisualC/SDL/SDL_VS2010.vcxproj index 7960d70a7..00c15332f 100644 --- a/VisualC/SDL/SDL_VS2010.vcxproj +++ b/VisualC/SDL/SDL_VS2010.vcxproj @@ -92,6 +92,7 @@ true EditAndContinue Default + false _DEBUG;%(PreprocessorDefinitions) @@ -123,6 +124,7 @@ Level3 ProgramDatabase + false _DEBUG;%(PreprocessorDefinitions) @@ -159,6 +161,7 @@ Level3 true Default + false NDEBUG;%(PreprocessorDefinitions) @@ -170,6 +173,8 @@ Windows $(DXSDK_DIR)\lib\x86 true + true + true @@ -191,6 +196,7 @@ Level3 + false NDEBUG;%(PreprocessorDefinitions) @@ -201,6 +207,9 @@ true Windows $(DXSDK_DIR)\lib\x64 + true + true + true @@ -451,4 +460,4 @@ - + \ No newline at end of file diff --git a/VisualC/SDL/SDL_VS2012.vcxproj b/VisualC/SDL/SDL_VS2012.vcxproj index 7ef76082f..cdc427e66 100644 --- a/VisualC/SDL/SDL_VS2012.vcxproj +++ b/VisualC/SDL/SDL_VS2012.vcxproj @@ -1,457 +1,467 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - SDL - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - SDL - - - - DynamicLibrary - false - v110 - - - DynamicLibrary - false - v110 - - - DynamicLibrary - false - v110 - - - DynamicLibrary - false - MultiByte - v110 - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - Win32 - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include"; - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - false - - - Level3 - true - EditAndContinue - Default - - - _DEBUG;%(PreprocessorDefinitions) - 0x0409 - - - winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies) - true - true - Windows - false - $(DXSDK_DIR)\lib\x86 - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - X64 - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include"; - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - false - - - Level3 - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0409 - - - winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies) - true - true - Windows - false - $(DXSDK_DIR)\lib\x64 - - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - - - OnlyExplicitInline - false - ..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include"; - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - MultiThreadedDLL - false - true - - - Level3 - true - Default - - - NDEBUG;%(PreprocessorDefinitions) - 0x0409 - - - winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies) - true - Windows - $(DXSDK_DIR)\lib\x86 - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - - - OnlyExplicitInline - false - ..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include"; - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - MultiThreadedDLL - false - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0409 - - - winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies) - true - Windows - $(DXSDK_DIR)\lib\x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + SDL + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} + SDL + + + + DynamicLibrary + false + v110 + + + DynamicLibrary + false + v110 + + + DynamicLibrary + false + v110 + + + DynamicLibrary + false + MultiByte + v110 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Win32 + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include"; + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + false + + + Level3 + true + EditAndContinue + Default + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies) + true + true + Windows + false + $(DXSDK_DIR)\lib\x86 + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + X64 + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include"; + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + false + + + Level3 + ProgramDatabase + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies) + true + true + Windows + false + $(DXSDK_DIR)\lib\x64 + + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + + + OnlyExplicitInline + false + ..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include"; + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + MultiThreadedDLL + false + true + + + Level3 + true + Default + false + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies) + true + Windows + $(DXSDK_DIR)\lib\x86 + true + true + true + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + X64 + + + OnlyExplicitInline + false + ..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include"; + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + MultiThreadedDLL + false + true + + + Level3 + false + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies) + true + Windows + $(DXSDK_DIR)\lib\x64 + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Xcode/TemplatesForXcodeTiger/SDL Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL Application/English.lproj/InfoPlist.strings index 38224b5a6dc9494230bdffbcad9c8bd915f478d9..e612457676d964a8021d20ec90290d5c6c3d88c1 100755 GIT binary patch delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> diff --git a/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/English.lproj/InfoPlist.strings index 38224b5a6dc9494230bdffbcad9c8bd915f478d9..e612457676d964a8021d20ec90290d5c6c3d88c1 100755 GIT binary patch delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> diff --git a/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/English.lproj/InfoPlist.strings index 38224b5a6dc9494230bdffbcad9c8bd915f478d9..e612457676d964a8021d20ec90290d5c6c3d88c1 100755 GIT binary patch delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> From f4e5303f466ddb851d340fe944ba6c65354e3db1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 27 Feb 2013 11:39:39 -0800 Subject: [PATCH 027/151] sdl - use the wParam and rawinput data for mouse state rather than just the message type, fixes missing mouse up events when alt-tabing out of the window CR: SamL --- src/video/windows/SDL_windowsevents.c | 105 ++++++++++++++++---------- src/video/windows/SDL_windowswindow.c | 2 +- src/video/windows/SDL_windowswindow.h | 2 +- 3 files changed, 69 insertions(+), 40 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 5c2be9ad8..a50f8b748 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -187,6 +187,54 @@ WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_ma } +void +WIN_CheckWParamMouseButton( SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button ) +{ + if ( bwParamMousePressed && !bSDLMousePressed ) + { + SDL_SendMouseButton(data->window, SDL_PRESSED, button); + } + else if ( !bwParamMousePressed && bSDLMousePressed ) + { + SDL_SendMouseButton(data->window, SDL_RELEASED, button); + } +} + +/* +* Some windows systems fail to send a WM_LBUTTONDOWN sometimes, but each mouse move contains the current button state also +* so this funciton reconciles our view of the world with the current buttons reported by windows +*/ +void +WIN_CheckWParamMouseButtons( WPARAM wParam, SDL_WindowData *data ) +{ + if ( wParam != data->mouse_button_flags ) + { + Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL ); + WIN_CheckWParamMouseButton( (wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + WIN_CheckWParamMouseButton( (wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE ); + WIN_CheckWParamMouseButton( (wParam & MK_RBUTTON), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT ); + WIN_CheckWParamMouseButton( (wParam & MK_XBUTTON1), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + WIN_CheckWParamMouseButton( (wParam & MK_XBUTTON2), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + data->mouse_button_flags = wParam; + } +} + + +void +WIN_CheckRawMouseButtons( ULONG rawButtons, SDL_WindowData *data ) +{ + if ( rawButtons != data->mouse_button_flags ) + { + Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL ); + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_RIGHT ); + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_MIDDLE ); + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + data->mouse_button_flags = rawButtons; + } +} + LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -257,6 +305,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if (SDL_GetKeyboardFocus() != data->window) { SDL_SetKeyboardFocus(data->window); } + /* mouse buttons may have changed state here, in theory we would need + to resync them, but we will get a WM_MOUSEMOVE right away which will fix + things up + */ if(SDL_GetMouse()->relative_mode) { LONG cx, cy; @@ -293,10 +345,20 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) break; case WM_MOUSEMOVE: - if(SDL_GetMouse()->relative_mode) - break; - SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam)); - break; + if( !SDL_GetMouse()->relative_mode ) + SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam)); + /* don't break here, fall through to check the wParam like the button presses */ + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_XBUTTONDOWN: + case WM_XBUTTONUP: + if(!SDL_GetMouse()->relative_mode) + WIN_CheckWParamMouseButtons( wParam, data ); + break; case WM_INPUT: { @@ -333,44 +395,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) initialMousePoint.x = mouse->lLastX; initialMousePoint.y = mouse->lLastY; } + WIN_CheckRawMouseButtons( mouse->usButtonFlags, data ); } break; } - case WM_LBUTTONDOWN: - SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_LEFT); - break; - - case WM_LBUTTONUP: - SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_LEFT); - break; - - case WM_RBUTTONDOWN: - SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_RIGHT); - break; - - case WM_RBUTTONUP: - SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_RIGHT); - break; - - case WM_MBUTTONDOWN: - SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_MIDDLE); - break; - - case WM_MBUTTONUP: - SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_MIDDLE); - break; - - case WM_XBUTTONDOWN: - SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_X1 + GET_XBUTTON_WPARAM(wParam) - 1); - returnCode = TRUE; - break; - - case WM_XBUTTONUP: - SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_X1 + GET_XBUTTON_WPARAM(wParam) - 1); - returnCode = TRUE; - break; - case WM_MOUSEWHEEL: { // FIXME: This may need to accumulate deltas up to WHEEL_DELTA diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index b6c46c34e..08894ecd6 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -89,7 +89,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) data->hwnd = hwnd; data->hdc = GetDC(hwnd); data->created = created; - data->mouse_pressed = SDL_FALSE; + data->mouse_button_flags = 0; data->videodata = videodata; window->driverdata = data; diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index f4002558f..b3b9a39a8 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -32,7 +32,7 @@ typedef struct HBITMAP hbm; WNDPROC wndproc; SDL_bool created; - int mouse_pressed; + Uint32 mouse_button_flags; struct SDL_VideoData *videodata; } SDL_WindowData; From 6b945c8586de795c80417a40628c75cdd06a65db Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 27 Feb 2013 11:39:41 -0800 Subject: [PATCH 028/151] sdl - don't use the RAWMOUSE struct to get button press information, it lies badly to you, just use the usual windows message path --- src/video/windows/SDL_windowsevents.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index a50f8b748..c1396790a 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -356,8 +356,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_MBUTTONUP: case WM_XBUTTONDOWN: case WM_XBUTTONUP: - if(!SDL_GetMouse()->relative_mode) - WIN_CheckWParamMouseButtons( wParam, data ); + WIN_CheckWParamMouseButtons( wParam, data ); break; case WM_INPUT: @@ -395,7 +394,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) initialMousePoint.x = mouse->lLastX; initialMousePoint.y = mouse->lLastY; } - WIN_CheckRawMouseButtons( mouse->usButtonFlags, data ); + / * this call doesn't actually work, usButtonFlags gets zero'd if you hold down button 1 and then move the mouse + WIN_CheckRawMouseButtons( mouse->usButtonFlags, data ); */ } break; } From 176d7c570cf98bab23727ab8573a81b49f33fd61 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 27 Feb 2013 11:39:43 -0800 Subject: [PATCH 029/151] sdl - check for both the up and down flags being set in the raw input calls. Also use WM_ACTIVE to resync mouse buttons on activate --- src/video/windows/SDL_windowsevents.c | 59 ++++++++++++++++++++------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index c1396790a..7f8e69a92 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -226,11 +226,26 @@ WIN_CheckRawMouseButtons( ULONG rawButtons, SDL_WindowData *data ) if ( rawButtons != data->mouse_button_flags ) { Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL ); - WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); - WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_RIGHT ); - WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_MIDDLE ); - WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); - WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + if ( (rawButtons & RI_MOUSE_BUTTON_1_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + if ( (rawButtons & RI_MOUSE_BUTTON_1_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_1_UP), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + if ( (rawButtons & RI_MOUSE_BUTTON_2_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT ); + if ( (rawButtons & RI_MOUSE_BUTTON_2_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_2_UP), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT ); + if ( (rawButtons & RI_MOUSE_BUTTON_3_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE ); + if ( (rawButtons & RI_MOUSE_BUTTON_3_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_3_UP), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE ); + if ( (rawButtons & RI_MOUSE_BUTTON_4_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + if ( (rawButtons & RI_MOUSE_BUTTON_4_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_4_UP), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + if ( (rawButtons & RI_MOUSE_BUTTON_5_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + if ( (rawButtons & RI_MOUSE_BUTTON_5_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_5_UP), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); data->mouse_button_flags = rawButtons; } } @@ -295,6 +310,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) minimized = HIWORD(wParam); if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { + Uint32 mouseFlags; + SHORT keyState; + SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0); @@ -305,10 +323,23 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if (SDL_GetKeyboardFocus() != data->window) { SDL_SetKeyboardFocus(data->window); } - /* mouse buttons may have changed state here, in theory we would need + /* mouse buttons may have changed state here, we need to resync them, but we will get a WM_MOUSEMOVE right away which will fix - things up + things up if in non raw mode also */ + mouseFlags = SDL_GetMouseState( NULL, NULL ); + + keyState = GetAsyncKeyState( VK_LBUTTON ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + keyState = GetAsyncKeyState( VK_RBUTTON ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT ); + keyState = GetAsyncKeyState( VK_MBUTTON ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE ); + keyState = GetAsyncKeyState( VK_XBUTTON1 ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + keyState = GetAsyncKeyState( VK_XBUTTON2 ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + data->mouse_button_flags = 0; if(SDL_GetMouse()->relative_mode) { LONG cx, cy; @@ -348,15 +379,16 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if( !SDL_GetMouse()->relative_mode ) SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam)); /* don't break here, fall through to check the wParam like the button presses */ - case WM_LBUTTONDOWN: case WM_LBUTTONUP: - case WM_RBUTTONDOWN: case WM_RBUTTONUP: - case WM_MBUTTONDOWN: case WM_MBUTTONUP: - case WM_XBUTTONDOWN: case WM_XBUTTONUP: - WIN_CheckWParamMouseButtons( wParam, data ); + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_MBUTTONDOWN: + case WM_XBUTTONDOWN: + if( !SDL_GetMouse()->relative_mode ) + WIN_CheckWParamMouseButtons( wParam, data ); break; case WM_INPUT: @@ -394,8 +426,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) initialMousePoint.x = mouse->lLastX; initialMousePoint.y = mouse->lLastY; } - / * this call doesn't actually work, usButtonFlags gets zero'd if you hold down button 1 and then move the mouse - WIN_CheckRawMouseButtons( mouse->usButtonFlags, data ); */ + WIN_CheckRawMouseButtons( mouse->usButtonFlags, data ); } break; } From e23532eac271ccf6180501b248832976af6dc9fa Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Thu, 28 Feb 2013 09:11:04 -0800 Subject: [PATCH 030/151] Add additional input validation to SDL_GetWindowDisplayMode; add tests to video suite --- src/video/SDL_video.c | 5 + test/testautomation_video.c | 232 +++++++++++++++++++++++++++++++++++- 2 files changed, 236 insertions(+), 1 deletion(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 5109cb977..9538ec5ee 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1020,6 +1020,11 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) SDL_DisplayMode fullscreen_mode; SDL_VideoDisplay *display; + if (!mode) { + SDL_InvalidParamError("mode"); + return -1; + } + CHECK_WINDOW_MAGIC(window, -1); fullscreen_mode = window->fullscreen_mode; diff --git a/test/testautomation_video.c b/test/testautomation_video.c index d9ec69f16..a38f0fd8b 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -497,6 +497,8 @@ video_getClosestDisplayModeRandomResolution(void *arg) /** * @brief Tests call to SDL_GetWindowBrightness + * +* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness */ int video_getWindowBrightness(void *arg) @@ -519,6 +521,218 @@ video_getWindowBrightness(void *arg) return TEST_COMPLETED; } +/** + * @brief Tests call to SDL_GetWindowBrightness with invalid input + * +* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness + */ +int +video_getWindowBrightnessNegative(void *arg) +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + const char* title = "video_getWindowBrightnessNegative Test Window"; + float result; + + /* Call against invalid window */ + result = SDL_GetWindowBrightness(NULL); + SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)"); + SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowDisplayMode + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode + */ +int +video_getWindowDisplayMode(void *arg) +{ + SDL_Window* window; + const char* title = "video_getWindowDisplayMode Test Window"; + SDL_DisplayMode mode; + int result; + + /* Invalidate part of the mode content so we can check values later */ + mode.w = -1; + mode.h = -1; + mode.refresh_rate = -1; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window != NULL) { + result = SDL_GetWindowDisplayMode(window, &mode); + SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w); + SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h); + SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate); + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowDisplayMode with invalid input + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode + */ +int +video_getWindowDisplayModeNegative(void *arg) +{ + const char *expectedError = "Parameter 'mode' is invalid"; + const char *invalidWindowError = "Invalid window"; + char *lastError; + SDL_Window* window; + const char* title = "video_getWindowDisplayModeNegative Test Window"; + SDL_DisplayMode mode; + int result; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window != NULL) { + result = SDL_GetWindowDisplayMode(window, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)"); + SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + expectedError, + lastError); + } + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Call against invalid window */ + result = SDL_GetWindowDisplayMode(NULL, &mode); + SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)"); + SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowGammaRamp + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp + */ +int +video_getWindowGammaRamp(void *arg) +{ + SDL_Window* window; + const char* title = "video_getWindowGammaRamp Test Window"; + Uint16 red[256]; + Uint16 green[256]; + Uint16 blue[256]; + int result; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window != NULL) { + /* Retrieve no channel */ + result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + /* Retrieve single channel */ + result = SDL_GetWindowGammaRamp(window, red, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + result = SDL_GetWindowGammaRamp(window, NULL, green, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + /* Retrieve two channels */ + result = SDL_GetWindowGammaRamp(window, red, green, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + result = SDL_GetWindowGammaRamp(window, NULL, green, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + result = SDL_GetWindowGammaRamp(window, red, NULL, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + /* Retrieve all channels */ + result = SDL_GetWindowGammaRamp(window, red, green, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowGammaRamp with invalid input + * +* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp + */ +int +video_getWindowGammaRampNegative(void *arg) +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + const char* title = "video_getWindowGammaRampNegative Test Window"; + Uint16 red[256]; + Uint16 green[256]; + Uint16 blue[256]; + int result; + + /* Call against invalid window */ + result = SDL_GetWindowGammaRamp(NULL, red, green, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)"); + SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %f", result); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + return TEST_COMPLETED; +} + /* ================= Test References ================== */ /* Video test cases */ @@ -552,10 +766,26 @@ static const SDLTest_TestCaseReference videoTest9 = static const SDLTest_TestCaseReference videoTest10 = { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED }; +static const SDLTest_TestCaseReference videoTest11 = + { (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative", "Get window brightness with invalid input", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest12 = + { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest13 = + { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest14 = + { (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp", "Get window gamma ramp", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest15 = + { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED }; + /* Sequence of Video test cases */ static const SDLTest_TestCaseReference *videoTests[] = { &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, - &videoTest7, &videoTest8, &videoTest9, &videoTest10, NULL + &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, + &videoTest13, &videoTest14, &videoTest15, NULL }; /* Video test suite (global) */ From 43f89a983618dcc383434de73c58d3b3a1dec106 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 28 Feb 2013 20:01:17 -0800 Subject: [PATCH 031/151] Updated the link to the USB usage page document --- include/SDL_scancode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL_scancode.h b/include/SDL_scancode.h index b05ca5cca..26b8f36b5 100644 --- a/include/SDL_scancode.h +++ b/include/SDL_scancode.h @@ -38,7 +38,7 @@ * SDL_Event structure. * * The values in this enumeration are based on the USB usage page standard: - * http://www.usb.org/developers/devclass_docs/Hut1_12.pdf + * http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf */ typedef enum { From 1b30d1a566ba91ca6695266b4d33a84ecdc64472 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 28 Feb 2013 21:40:08 -0800 Subject: [PATCH 032/151] Cleaned up and fixed the Windows keyboard mapping code. Use KP_PERIOD instead of KP_DECIMAL Don't remap keys which are always keycode named versions of scancodes --- src/video/windows/SDL_windowsevents.c | 27 ++++---- src/video/windows/SDL_windowskeyboard.c | 88 ++++++------------------- src/video/windows/SDL_windowskeyboard.h | 3 - src/video/windows/SDL_windowsvideo.h | 1 - 4 files changed, 33 insertions(+), 86 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 5c2be9ad8..9887a0bcb 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -28,13 +28,12 @@ #include "SDL_vkeys.h" #include "../../events/SDL_events_c.h" #include "../../events/SDL_touch_c.h" +#include "../../events/scancodes_windows.h" /* Dropfile support */ #include - - /*#define WMMSG_DEBUG*/ #ifdef WMMSG_DEBUG #include @@ -68,7 +67,7 @@ #endif static SDL_Scancode -WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map ) +WindowsScanCodeToSDLScanCode( int lParam, int wParam ) { SDL_Scancode code; char bIsExtended; @@ -133,7 +132,7 @@ WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_ma if ( nScanCode > 127 ) return SDL_SCANCODE_UNKNOWN; - code = key_map[nScanCode]; + code = windows_scancode_table[nScanCode]; bIsExtended = ( lParam & ( 1 << 24 ) ) != 0; if ( !bIsExtended ) @@ -159,7 +158,7 @@ WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_ma case SDL_SCANCODE_INSERT: return SDL_SCANCODE_KP_0; case SDL_SCANCODE_DELETE: - return SDL_SCANCODE_KP_DECIMAL; + return SDL_SCANCODE_KP_PERIOD; case SDL_SCANCODE_PRINTSCREEN: return SDL_SCANCODE_KP_MULTIPLY; default: @@ -393,7 +392,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYDOWN: case WM_KEYDOWN: { - SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); + SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam ); if ( code != SDL_SCANCODE_UNKNOWN ) { SDL_SendKeyboardKey(SDL_PRESSED, code ); } @@ -404,15 +403,13 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYUP: case WM_KEYUP: { - SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); - if ( code != SDL_SCANCODE_UNKNOWN ) { - if (wParam == VK_SNAPSHOT - && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == - SDL_RELEASED) { - SDL_SendKeyboardKey(SDL_PRESSED, - code); - } - SDL_SendKeyboardKey(SDL_RELEASED, code ); + SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam ); + if ( code != SDL_SCANCODE_UNKNOWN ) { + if (code == SDL_SCANCODE_PRINTSCREEN && + SDL_GetKeyboardState(NULL)[code] == SDL_RELEASED) { + SDL_SendKeyboardKey(SDL_PRESSED, code); + } + SDL_SendKeyboardKey(SDL_RELEASED, code); } } returnCode = 0; diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index fd2510413..74f078f86 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -48,50 +48,10 @@ static void IME_Quit(SDL_VideoData *videodata); #endif /* Alphabetic scancodes for PC keyboards */ -BYTE alpha_scancodes[26] = { - 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, - 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44 -}; - -BYTE keypad_scancodes[10] = { - 82, 79, 80, 81, 75, 76, 77, 71, 72, 73 -}; - void WIN_InitKeyboard(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; - int i; - - /* Make sure the alpha scancodes are correct. T isn't usually remapped */ - if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) { -#if 0 - printf - ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list , including a description of your keyboard hardware.\n"); -#endif - for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) { - alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC); -#if 0 - printf("%d = %d\n", i, alpha_scancodes[i]); -#endif - } - } - if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) { -#if 0 - printf - ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list , including a description of your keyboard hardware.\n"); -#endif - for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) { - keypad_scancodes[i] = - MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC); -#if 0 - printf("%d = %d\n", i, keypad_scancodes[i]); -#endif - } - } - - // windows scancode to SDL scancode table - data->key_layout = windows_scancode_table; data->ime_com_initialized = SDL_FALSE; data->ime_threadmgr = 0; @@ -151,42 +111,36 @@ WIN_UpdateKeymap() SDL_Scancode scancode; SDL_Keycode keymap[SDL_NUM_SCANCODES]; - for (i = 0; i < SDL_arraysize(keymap); ++i) - { - keymap[i] = SDL_SCANCODE_TO_KEYCODE( i ); - } + SDL_GetDefaultKeymap(keymap); for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) { - int vk; + int vk; /* Make sure this scancode is a valid character scancode */ scancode = windows_scancode_table[i]; if (scancode == SDL_SCANCODE_UNKNOWN ) { continue; } - /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */ - /* not mapping numbers fixes the AZERTY layout (french) causing non-shifted number to appear by default */ - if ( scancode == SDL_SCANCODE_GRAVE ) { - keymap[scancode] = SDLK_BACKQUOTE; - continue; - } - if ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) { - keymap[scancode] = SDLK_1 + ( scancode - SDL_SCANCODE_1 ); - continue; - } - vk = MapVirtualKey(i, MAPVK_VSC_TO_VK); - if ( vk ) { - int ch; - ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF); - if ( ch ) - { - if ( ch >= 'A' && ch <= 'Z' ) - keymap[scancode] = SDLK_a + ( ch - 'A' ); - else - keymap[scancode] = ch; - } + /* If this key is one of the non-mappable keys, ignore it */ + /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */ + /* Not mapping numbers fixes the French layout, giving numeric keycodes for the number keys, which is the expected behavior */ + if ((keymap[scancode] & SDLK_SCANCODE_MASK) || + scancode == SDL_SCANCODE_GRAVE || + (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0) ) { + continue; + } - } + vk = MapVirtualKey(i, MAPVK_VSC_TO_VK); + if ( vk ) { + int ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF); + if ( ch ) { + if ( ch >= 'A' && ch <= 'Z' ) { + keymap[scancode] = SDLK_a + ( ch - 'A' ); + } else { + keymap[scancode] = ch; + } + } + } } SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); diff --git a/src/video/windows/SDL_windowskeyboard.h b/src/video/windows/SDL_windowskeyboard.h index abe8a63e9..c79d1d0ff 100644 --- a/src/video/windows/SDL_windowskeyboard.h +++ b/src/video/windows/SDL_windowskeyboard.h @@ -23,9 +23,6 @@ #ifndef _SDL_windowskeyboard_h #define _SDL_windowskeyboard_h -extern BYTE alpha_scancodes[26]; -extern BYTE keypad_scancodes[10]; - extern void WIN_InitKeyboard(_THIS); extern void WIN_UpdateKeymap(void); extern void WIN_QuitKeyboard(_THIS); diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index 8a3c737ed..199a8ba8f 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -115,7 +115,6 @@ typedef struct SDL_VideoData { int render; - const SDL_Scancode *key_layout; DWORD clipboard_count; /* Touch input functions */ From c6ac556871fa670e5f24912e6f30bcbea905cce4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 28 Feb 2013 21:48:12 -0800 Subject: [PATCH 033/151] The table is now a scancode mapping table, not a virtual key mapping table --- src/events/scancodes_windows.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/events/scancodes_windows.h b/src/events/scancodes_windows.h index 3aee7e609..7bf69b0ad 100644 --- a/src/events/scancodes_windows.h +++ b/src/events/scancodes_windows.h @@ -20,13 +20,8 @@ */ #include "../../include/SDL_scancode.h" -/* Win32 virtual key code to SDL scancode mapping table - Sources: - - msdn.microsoft.com -*/ +/* Windows scancode to SDL scancode mapping table */ /* *INDENT-OFF* */ -// this maps non-translated keyboard scan codes to engine key codes -// Google for 'Keyboard Scan Code Specification' static const SDL_Scancode windows_scancode_table[] = { // 0 1 2 3 4 5 6 7 @@ -55,5 +50,4 @@ static const SDL_Scancode windows_scancode_table[] = SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 7 SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN // 7 }; - /* *INDENT-ON* */ From 7c3f6dcb242857ce09ebe2480f2d0fc9f805e018 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 28 Feb 2013 22:20:25 -0800 Subject: [PATCH 034/151] Fixed bug 1736 - Memory leak in X11_InitModes tomaszewski.p XRRListOutputProperties allocates Atom* array, which is not freed. XRRGetOutputProperty allocates 'unsigned char *prop' array, which is not freed. --- src/video/x11/SDL_x11modes.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index e7822f057..d49555ad9 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -576,26 +576,31 @@ X11_InitModes(_THIS) int actual_format; unsigned long nitems, bytes_after; Atom actual_type; - - if (props[i] == EDID) { - XRRGetOutputProperty(data->display, res->outputs[output], props[i], - 0, 100, False, False, - AnyPropertyType, - &actual_type, &actual_format, - &nitems, &bytes_after, &prop); - MonitorInfo *info = decode_edid(prop); - if (info) { -#ifdef X11MODES_DEBUG - printf("Found EDID data for %s\n", output_info->name); - dump_monitor_info(info); -#endif - SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name)); - free(info); + if (props[i] == EDID) { + if (XRRGetOutputProperty(data->display, + res->outputs[output], props[i], + 0, 100, False, False, + AnyPropertyType, + &actual_type, &actual_format, + &nitems, &bytes_after, &prop) == Success ) { + MonitorInfo *info = decode_edid(prop); + if (info) { + #ifdef X11MODES_DEBUG + printf("Found EDID data for %s\n", output_info->name); + dump_monitor_info(info); + #endif + SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name)); + free(info); + } + SDL_free(prop); } break; } } + if (props) { + SDL_free(props); + } if (*display_name && inches) { size_t len = SDL_strlen(display_name); From afdba2723640ad6f56387fbf9506f694db4d1aa8 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Fri, 1 Mar 2013 13:28:07 -0300 Subject: [PATCH 035/151] Use XFree to release X11 allocated data --- src/video/x11/SDL_x11modes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index d49555ad9..347e7bbdf 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -593,13 +593,13 @@ X11_InitModes(_THIS) SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name)); free(info); } - SDL_free(prop); + XFree(prop); } break; } } if (props) { - SDL_free(props); + XFree(props); } if (*display_name && inches) { From c6dc8b64e751dd8c45c4f7d5d03114a0da4e7fe3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 1 Mar 2013 11:27:01 -0800 Subject: [PATCH 036/151] Remove XSync from X11_GL_MakeCurrent() function --- src/video/x11/SDL_x11opengl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 0c3ab5065..43760d0b1 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -642,7 +642,6 @@ X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) SDL_SetError("Unable to make GL context current"); status = -1; } - XSync(display, False); return (status); } From c02018f85203f0e97cf639c51512244d22d7f276 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 2 Mar 2013 17:51:32 -0800 Subject: [PATCH 037/151] Fixed the joystick id usage in the joystick and game controller events. --- include/SDL_events.h | 54 +++++++++++++++++++++++----------- include/SDL_joystick.h | 2 +- src/events/SDL_events.c | 2 +- src/joystick/SDL_sysjoystick.h | 15 +++++----- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index 35e36f60d..1d39b3222 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -130,6 +130,15 @@ typedef enum SDL_LASTEVENT = 0xFFFF } SDL_EventType; +/** + * \brief Fields shared by every event + */ +typedef struct SDL_GenericEvent +{ + Uint32 type; + Uint32 timestamp; +} SDL_GenericEvent; + /** * \brief Window state change event data (event.window.*) */ @@ -241,11 +250,13 @@ typedef struct SDL_JoyAxisEvent { Uint32 type; /**< ::SDL_JOYAXISMOTION */ Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ + Uint32 which; /**< The joystick instance id */ Uint8 axis; /**< The joystick axis index */ Uint8 padding1; Uint8 padding2; - int value; /**< The axis value (range: -32768 to 32767) */ + Uint8 padding3; + Sint16 value; /**< The axis value (range: -32768 to 32767) */ + Uint16 padding4; } SDL_JoyAxisEvent; /** @@ -255,12 +266,13 @@ typedef struct SDL_JoyBallEvent { Uint32 type; /**< ::SDL_JOYBALLMOTION */ Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ + Uint32 which; /**< The joystick instance id */ Uint8 ball; /**< The joystick trackball index */ Uint8 padding1; Uint8 padding2; - int xrel; /**< The relative motion in the X direction */ - int yrel; /**< The relative motion in the Y direction */ + Uint8 padding3; + Sint16 xrel; /**< The relative motion in the X direction */ + Sint16 yrel; /**< The relative motion in the Y direction */ } SDL_JoyBallEvent; /** @@ -270,7 +282,7 @@ typedef struct SDL_JoyHatEvent { Uint32 type; /**< ::SDL_JOYHATMOTION */ Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ + Uint32 which; /**< The joystick instance id */ Uint8 hat; /**< The joystick hat index */ Uint8 value; /**< The hat position value. * \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP @@ -280,6 +292,7 @@ typedef struct SDL_JoyHatEvent * Note that zero means the POV is centered. */ Uint8 padding1; + Uint8 padding2; } SDL_JoyHatEvent; /** @@ -289,10 +302,11 @@ typedef struct SDL_JoyButtonEvent { Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */ Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ + Uint32 which; /**< The joystick instance id */ Uint8 button; /**< The joystick button index */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 padding1; + Uint8 padding2; } SDL_JoyButtonEvent; /** @@ -302,7 +316,7 @@ typedef struct SDL_JoyDeviceEvent { Uint32 type; /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */ Uint32 timestamp; - Uint32 which; /**< The joystick device index for ADD, instance_id for REMOVE*/ + Uint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */ } SDL_JoyDeviceEvent; @@ -313,9 +327,13 @@ typedef struct SDL_ControllerAxisEvent { Uint32 type; /**< ::SDL_CONTROLLERAXISMOTION */ Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ - SDL_GameControllerAxis axis; /**< The joystick axis index */ - int value; /**< The axis value (range: -32768 to 32767) */ + Uint32 which; /**< The joystick instance id */ + Uint8 axis; /**< The controller axis (SDL_GameControllerAxis) */ + Uint8 padding1; + Uint8 padding2; + Uint8 padding3; + Sint16 value; /**< The axis value (range: -32768 to 32767) */ + Uint16 padding4; } SDL_ControllerAxisEvent; @@ -326,9 +344,11 @@ typedef struct SDL_ControllerButtonEvent { Uint32 type; /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */ Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ - SDL_GameControllerButton button; /**< The joystick button index */ + Uint32 which; /**< The joystick instance id */ + Uint8 button; /**< The controller button (SDL_GameControllerButton) */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ + Uint8 padding1; + Uint8 padding2; } SDL_ControllerButtonEvent; @@ -339,7 +359,7 @@ typedef struct SDL_ControllerDeviceEvent { Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED or ::SDL_CONTROLLERDEVICEREMOVED */ Uint32 timestamp; - Uint32 which; /**< The joystick device index for ADD, instance_id for REMOVE*/ + Uint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */ } SDL_ControllerDeviceEvent; @@ -348,11 +368,10 @@ typedef struct SDL_ControllerDeviceEvent */ typedef struct SDL_TouchFingerEvent { - Uint32 type; /**< ::SDL_FINGERMOTION OR - SDL_FINGERDOWN OR SDL_FINGERUP*/ + Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */ Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device id */ + SDL_TouchID touchId; /**< The touch device id */ SDL_FingerID fingerId; Uint8 state; /**< The current button state */ Uint8 padding1; @@ -476,6 +495,7 @@ typedef struct SDL_SysWMEvent typedef union SDL_Event { Uint32 type; /**< Event type, shared with all events */ + SDL_GenericEvent generic; /**< Generic event data */ SDL_WindowEvent window; /**< Window event data */ SDL_KeyboardEvent key; /**< Keyboard event data */ SDL_TextEditingEvent edit; /**< Text editing event data */ diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index 1065f1682..7d218925c 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -67,7 +67,7 @@ typedef struct { Uint8 data[16]; } SDL_JoystickGUID; -typedef int SDL_JoystickID; +typedef Uint32 SDL_JoystickID; /* Function prototypes */ diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 40bf8b0b4..149add196 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -365,7 +365,7 @@ int SDL_PushEvent(SDL_Event * event) { SDL_EventWatcher *curr; - event->window.timestamp = SDL_GetTicks(); + event->generic.timestamp = SDL_GetTicks(); if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) { return 0; } diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h index b20ac23a9..4a5019e73 100644 --- a/src/joystick/SDL_sysjoystick.h +++ b/src/joystick/SDL_sysjoystick.h @@ -28,8 +28,8 @@ /* The SDL joystick structure */ struct _SDL_Joystick { - int instance_id; /* Device instance, monotonically increasing from 0 */ - char *name; /* Joystick name - system dependent */ + SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */ + char *name; /* Joystick name - system dependent */ int naxes; /* Number of axis controls on the joystick */ Sint16 *axes; /* Current axis states */ @@ -38,8 +38,7 @@ struct _SDL_Joystick Uint8 *hats; /* Current hat states */ int nballs; /* Number of trackballs on the joystick */ - struct balldelta - { + struct balldelta { int dx; int dy; } *balls; /* Current ball motion deltas */ @@ -50,10 +49,10 @@ struct _SDL_Joystick struct joystick_hwdata *hwdata; /* Driver dependent information */ int ref_count; /* Reference count for multiple opens */ - - Uint8 closed; /* 1 if this device is no longer valid */ - Uint8 uncentered; /* 1 if this device needs to have its state reset to 0 */ - struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */ + + Uint8 closed; /* 1 if this device is no longer valid */ + Uint8 uncentered; /* 1 if this device needs to have its state reset to 0 */ + struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */ }; /* Function to scan the system for joysticks. From 71ea3033fa363ae1c60dd9e2b75d7c15c7811a16 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 2 Mar 2013 20:44:16 -0800 Subject: [PATCH 038/151] Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input. --- include/SDL_events.h | 29 +++++++------ include/SDL_touch.h | 52 ++++++++++-------------- src/events/SDL_mouse.c | 15 ++++--- src/events/SDL_mouse_c.h | 9 ++-- src/main/beos/SDL_BApp.h | 6 +-- src/video/android/SDL_androidtouch.c | 8 ++-- src/video/cocoa/SDL_cocoamouse.m | 6 ++- src/video/cocoa/SDL_cocoawindow.m | 8 ++-- src/video/directfb/SDL_DirectFB_events.c | 8 ++-- src/video/nds/SDL_ndsevents.c | 6 +-- src/video/uikit/SDL_uikitview.m | 8 ++-- src/video/windows/SDL_windowsevents.c | 12 +++--- src/video/x11/SDL_x11events.c | 13 +++--- src/video/x11/SDL_x11xinput2.c | 2 +- 14 files changed, 91 insertions(+), 91 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index 1d39b3222..fce02bf75 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -151,8 +151,8 @@ typedef struct SDL_WindowEvent Uint8 padding1; Uint8 padding2; Uint8 padding3; - int data1; /**< event dependent data */ - int data2; /**< event dependent data */ + Sint32 data1; /**< event dependent data */ + Sint32 data2; /**< event dependent data */ } SDL_WindowEvent; /** @@ -180,8 +180,8 @@ typedef struct SDL_TextEditingEvent Uint32 timestamp; Uint32 windowID; /**< The window with keyboard focus, if any */ char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */ - int start; /**< The start cursor of selected editing text */ - int length; /**< The length of selected editing text */ + Sint32 start; /**< The start cursor of selected editing text */ + Sint32 length; /**< The length of selected editing text */ } SDL_TextEditingEvent; @@ -205,14 +205,15 @@ typedef struct SDL_MouseMotionEvent Uint32 type; /**< ::SDL_MOUSEMOTION */ Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ Uint8 state; /**< The current button state */ Uint8 padding1; Uint8 padding2; Uint8 padding3; - int x; /**< X coordinate, relative to window */ - int y; /**< Y coordinate, relative to window */ - int xrel; /**< The relative motion in the X direction */ - int yrel; /**< The relative motion in the Y direction */ + Sint32 x; /**< X coordinate, relative to window */ + Sint32 y; /**< Y coordinate, relative to window */ + Sint32 xrel; /**< The relative motion in the X direction */ + Sint32 yrel; /**< The relative motion in the Y direction */ } SDL_MouseMotionEvent; /** @@ -223,12 +224,13 @@ typedef struct SDL_MouseButtonEvent Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */ Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ Uint8 button; /**< The mouse button index */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 padding1; Uint8 padding2; - int x; /**< X coordinate, relative to window */ - int y; /**< Y coordinate, relative to window */ + Sint32 x; /**< X coordinate, relative to window */ + Sint32 y; /**< Y coordinate, relative to window */ } SDL_MouseButtonEvent; /** @@ -239,8 +241,9 @@ typedef struct SDL_MouseWheelEvent Uint32 type; /**< ::SDL_MOUSEWHEEL */ Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ - int x; /**< The amount scrolled horizontally */ - int y; /**< The amount scrolled vertically */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ + Sint32 x; /**< The amount scrolled horizontally */ + Sint32 y; /**< The amount scrolled vertically */ } SDL_MouseWheelEvent; /** @@ -467,7 +470,7 @@ typedef struct SDL_UserEvent Uint32 type; /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */ Uint32 timestamp; Uint32 windowID; /**< The associated window if any */ - int code; /**< User defined event code */ + Sint32 code; /**< User defined event code */ void *data1; /**< User defined data pointer */ void *data2; /**< User defined data pointer */ } SDL_UserEvent; diff --git a/include/SDL_touch.h b/include/SDL_touch.h index c4820792f..de7ccf48d 100644 --- a/include/SDL_touch.h +++ b/include/SDL_touch.h @@ -40,30 +40,25 @@ extern "C" { /* *INDENT-ON* */ #endif - typedef Sint64 SDL_TouchID; typedef Sint64 SDL_FingerID; +typedef struct SDL_Finger +{ + SDL_FingerID id; + Uint16 x; + Uint16 y; + Uint16 pressure; + Uint16 xdelta; + Uint16 ydelta; + Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */ + SDL_bool down; +} SDL_Finger; -struct SDL_Finger { - SDL_FingerID id; - Uint16 x; - Uint16 y; - Uint16 pressure; - Uint16 xdelta; - Uint16 ydelta; - Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */ - SDL_bool down; -}; - -typedef struct SDL_Touch SDL_Touch; -typedef struct SDL_Finger SDL_Finger; - - -struct SDL_Touch { - +typedef struct SDL_Touch +{ /* Free the touch when it's time */ - void (*FreeTouch) (SDL_Touch * touch); + void (*FreeTouch) (struct SDL_Touch * touch); /* data common for tablets */ float pressure_max, pressure_min; @@ -89,28 +84,23 @@ struct SDL_Touch { SDL_Finger** fingers; void *driverdata; -}; +} SDL_Touch; +/* Used as the device ID for mouse events simulated with touch input */ +#define SDL_TOUCH_MOUSEID ((Uint32)-1) /* Function prototypes */ /** - * \brief Get the touch object at the given id. - * - * + * \brief Get the touch object with the given id. */ - extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id); - - +extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id); /** - * \brief Get the finger object of the given touch, at the given id. - * - * + * \brief Get the finger object of the given touch, with the given id. */ - extern - DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id); +extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 35274c8b9..ba3eec2d1 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -81,7 +81,7 @@ SDL_ResetMouse(void) #endif for (i = 1; i <= sizeof(mouse->buttonstate)*8; ++i) { if (mouse->buttonstate & SDL_BUTTON(i)) { - SDL_SendMouseButton(mouse->focus, SDL_RELEASED, i); + SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i); } } SDL_assert(mouse->buttonstate == 0); @@ -174,7 +174,7 @@ SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate) } int -SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y) +SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -252,6 +252,7 @@ SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y) SDL_Event event; event.motion.type = SDL_MOUSEMOTION; event.motion.windowID = mouse->focus ? mouse->focus->id : 0; + event.motion.which = mouseID; event.motion.state = mouse->buttonstate; event.motion.x = mouse->x; event.motion.y = mouse->y; @@ -266,7 +267,7 @@ SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y) } int -SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button) +SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -304,11 +305,12 @@ SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button) if (SDL_GetEventState(type) == SDL_ENABLE) { SDL_Event event; event.type = type; + event.button.windowID = mouse->focus ? mouse->focus->id : 0; + event.button.which = mouseID; event.button.state = state; event.button.button = button; event.button.x = mouse->x; event.button.y = mouse->y; - event.button.windowID = mouse->focus ? mouse->focus->id : 0; posted = (SDL_PushEvent(&event) > 0); } @@ -321,7 +323,7 @@ SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button) } int -SDL_SendMouseWheel(SDL_Window * window, int x, int y) +SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -340,6 +342,7 @@ SDL_SendMouseWheel(SDL_Window * window, int x, int y) SDL_Event event; event.type = SDL_MOUSEWHEEL; event.wheel.windowID = mouse->focus ? mouse->focus->id : 0; + event.wheel.which = mouseID; event.wheel.x = x; event.wheel.y = y; posted = (SDL_PushEvent(&event) > 0); @@ -396,7 +399,7 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y) if (mouse->WarpMouse) { mouse->WarpMouse(window, x, y); } else { - SDL_SendMouseMotion(window, 0, x, y); + SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y); } } diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 2fc27eac7..7cb13cb3d 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -25,6 +25,8 @@ #include "SDL_mouse.h" +typedef Uint32 SDL_MouseID; + struct SDL_Cursor { struct SDL_Cursor *next; @@ -55,6 +57,7 @@ typedef struct int (*SetRelativeMouseMode) (SDL_bool enabled); /* Data common to all mice */ + SDL_MouseID mouseID; SDL_Window *focus; int x; int y; @@ -86,13 +89,13 @@ extern void SDL_SetDefaultCursor(SDL_Cursor * cursor); extern void SDL_SetMouseFocus(SDL_Window * window); /* Send a mouse motion event */ -extern int SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y); +extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y); /* Send a mouse button event */ -extern int SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button); +extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button); /* Send a mouse wheel event */ -extern int SDL_SendMouseWheel(SDL_Window * window, int x, int y); +extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y); /* Shutdown the mouse subsystem */ extern void SDL_MouseQuit(void); diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 5ac285551..5bde94c18 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -221,7 +221,7 @@ private: return; } win = GetSDLWindow(winID); - SDL_SendMouseMotion(win, 0, x, y); + SDL_SendMouseMotion(win, 0, 0, x, y); /* Tell the application that the mouse passed over, redraw needed */ BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); @@ -239,7 +239,7 @@ private: return; } win = GetSDLWindow(winID); - SDL_SendMouseButton(win, state, button); + SDL_SendMouseButton(win, 0, state, button); } void _HandleMouseWheel(BMessage *msg) { @@ -254,7 +254,7 @@ private: return; } win = GetSDLWindow(winID); - SDL_SendMouseWheel(win, xTicks, yTicks); + SDL_SendMouseWheel(win, 0, xTicks, yTicks); } void _HandleKey(BMessage *msg) { diff --git a/src/video/android/SDL_androidtouch.c b/src/video/android/SDL_androidtouch.c index 67e3f9426..87386de26 100644 --- a/src/video/android/SDL_androidtouch.c +++ b/src/video/android/SDL_androidtouch.c @@ -89,10 +89,10 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ - SDL_SendMouseMotion(NULL, 0, window_x, window_y); + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); /* send mouse down event */ - SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); leftFingerDown = fingerId; } @@ -103,7 +103,7 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ - SDL_SendMouseMotion(NULL, 0, window_x, window_y); + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); } SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; @@ -111,7 +111,7 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio case ACTION_POINTER_1_UP: if (fingerId == leftFingerDown) { /* send mouse up */ - SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); leftFingerDown = 0; } SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p); diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 158fa17cd..5b5981827 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -223,13 +223,15 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event) [event type] == NSOtherMouseDragged)) { float x = [event deltaX]; float y = [event deltaY]; - SDL_SendMouseMotion(mouse->focus, 1, (int)x, (int)y); + SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y); } } void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event) { + SDL_Mouse *mouse = SDL_GetMouse(); + float x = [event deltaX]; float y = [event deltaY]; @@ -243,7 +245,7 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event) } else if (y < 0) { y -= 0.9f; } - SDL_SendMouseWheel(window, (int)x, (int)y); + SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y); } void diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 5c9fd082d..5a3d6cc83 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -200,7 +200,7 @@ static __inline__ void ConvertNSRect(NSRect *r) y = (int)(window->h - point.y); if (x >= 0 && x < window->w && y >= 0 && y < window->h) { - SDL_SendMouseMotion(window, 0, x, y); + SDL_SendMouseMotion(window, 0, 0, x, y); SDL_SetCursor(NULL); } } @@ -263,7 +263,7 @@ static __inline__ void ConvertNSRect(NSRect *r) button = [theEvent buttonNumber] + 1; break; } - SDL_SendMouseButton(_data->window, SDL_PRESSED, button); + SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button); } - (void)rightMouseDown:(NSEvent *)theEvent @@ -294,7 +294,7 @@ static __inline__ void ConvertNSRect(NSRect *r) button = [theEvent buttonNumber] + 1; break; } - SDL_SendMouseButton(_data->window, SDL_RELEASED, button); + SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button); } - (void)rightMouseUp:(NSEvent *)theEvent @@ -342,7 +342,7 @@ static __inline__ void ConvertNSRect(NSRect *r) CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint); } } - SDL_SendMouseMotion(window, 0, x, y); + SDL_SendMouseMotion(window, 0, 0, x, y); } - (void)mouseDragged:(NSEvent *)theEvent diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c index c04eed499..8ee0b9085 100644 --- a/src/video/directfb/SDL_DirectFB_events.c +++ b/src/video/directfb/SDL_DirectFB_events.c @@ -40,13 +40,13 @@ #include "SDL_DirectFB_events.h" #if USE_MULTI_API -#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p) -#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(id, state, button) +#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y, p) +#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button) #define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode) #define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text) #else -#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, relative, x, y) -#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, state, button) +#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y) +#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button) #define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode) #define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text) #endif diff --git a/src/video/nds/SDL_ndsevents.c b/src/video/nds/SDL_ndsevents.c index 8132aae23..97933a46a 100644 --- a/src/video/nds/SDL_ndsevents.c +++ b/src/video/nds/SDL_ndsevents.c @@ -37,15 +37,15 @@ NDS_PumpEvents(_THIS) scanKeys(); /* TODO: defer click-age */ if (keysDown() & KEY_TOUCH) { - SDL_SendMouseButton(0, SDL_PRESSED, 0); + SDL_SendMouseButton(NULL, 0, SDL_PRESSED, 0); } else if (keysUp() & KEY_TOUCH) { - SDL_SendMouseButton(0, SDL_RELEASED, 0); + SDL_SendMouseButton(NULL, 0, SDL_RELEASED, 0); } if (keysHeld() & KEY_TOUCH) { touchPosition t; touchRead(&t); - SDL_SendMouseMotion(0, 0, t.px, t.py); + SDL_SendMouseMotion(NULL, 0, 0, t.px, t.py); } } diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index ddbfe8f5e..20701d84d 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -104,10 +104,10 @@ CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO]; /* send moved event */ - SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y); /* send mouse down event */ - SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); leftFingerDown = (SDL_FingerID)touch; } @@ -144,7 +144,7 @@ while(touch) { if ((SDL_FingerID)touch == leftFingerDown) { /* send mouse up */ - SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); leftFingerDown = 0; } @@ -189,7 +189,7 @@ CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO]; /* send moved event */ - SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y); } CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 356bcfd8c..1b3937833 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -191,11 +191,11 @@ WIN_CheckWParamMouseButton( SDL_bool bwParamMousePressed, SDL_bool bSDLMousePres { if ( bwParamMousePressed && !bSDLMousePressed ) { - SDL_SendMouseButton(data->window, SDL_PRESSED, button); + SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button); } else if ( !bwParamMousePressed && bSDLMousePressed ) { - SDL_SendMouseButton(data->window, SDL_RELEASED, button); + SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button); } } @@ -376,7 +376,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: if( !SDL_GetMouse()->relative_mode ) - SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam)); + SDL_SendMouseMotion(data->window, 0, 0, LOWORD(lParam), HIWORD(lParam)); /* don't break here, fall through to check the wParam like the button presses */ case WM_LBUTTONUP: case WM_RBUTTONUP: @@ -408,7 +408,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) { - SDL_SendMouseMotion(data->window, 1, (int)mouse->lLastX, (int)mouse->lLastY); + SDL_SendMouseMotion(data->window, 0, 1, (int)mouse->lLastX, (int)mouse->lLastY); } else { @@ -420,7 +420,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) initialMousePoint.y = mouse->lLastY; } - SDL_SendMouseMotion(data->window, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) ); + SDL_SendMouseMotion(data->window, 0, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) ); initialMousePoint.x = mouse->lLastX; initialMousePoint.y = mouse->lLastY; @@ -435,7 +435,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) // FIXME: This may need to accumulate deltas up to WHEEL_DELTA short motion = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA; - SDL_SendMouseWheel(data->window, 0, motion); + SDL_SendMouseWheel(data->window, 0, 0, motion); break; } diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index a377d4cec..fa8543d8e 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -448,24 +448,23 @@ X11_DispatchEvent(_THIS) printf("window %p: X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); #endif - SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y); + SDL_SendMouseMotion(data->window, 0, 0, xevent.xmotion.x, xevent.xmotion.y); } } break; case ButtonPress:{ int ticks = 0; - if (X11_IsWheelEvent(display,&xevent,&ticks) == SDL_TRUE) { - SDL_SendMouseWheel(data->window, 0, ticks); - } - else { - SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button); + if (X11_IsWheelEvent(display,&xevent,&ticks)) { + SDL_SendMouseWheel(data->window, 0, 0, ticks); + } else { + SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button); } } break; case ButtonRelease:{ - SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button); + SDL_SendMouseButton(data->window, 0, SDL_RELEASED, xevent.xbutton.button); } break; diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index 9a1b6e9aa..16fd252c5 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -142,7 +142,7 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie) parse_valuators(rawev->raw_values,rawev->valuators.mask, rawev->valuators.mask_len,relative_cords,2); - SDL_SendMouseMotion(mouse->focus,1,(int)relative_cords[0],(int)relative_cords[1]); + SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(int)relative_cords[0],(int)relative_cords[1]); return 1; } break; From bb0752e5734f5f535c49a98e1e2601ae47635b34 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Mar 2013 01:01:33 -0800 Subject: [PATCH 039/151] Updated touch API * Normalized touch coordinates as floats in the 0...1 range * Removed unused touchpad concepts from the API * Added API functions to get active touch devices and current finger state --- include/SDL_events.h | 56 +- include/SDL_touch.h | 59 +-- src/events/SDL_gesture.c | 27 +- src/events/SDL_gesture_c.h | 4 +- src/events/SDL_touch.c | 731 +++++++++----------------- src/events/SDL_touch_c.h | 51 +- src/video/android/SDL_androidtouch.c | 20 +- src/video/cocoa/SDL_cocoawindow.m | 27 +- src/video/uikit/SDL_uikitview.m | 45 +- src/video/windows/SDL_windowsevents.c | 24 +- src/video/x11/SDL_x11events.c | 90 ---- src/video/x11/SDL_x11touch.c | 87 +-- src/video/x11/SDL_x11touch.h | 10 - src/video/x11/SDL_x11xinput2.c | 31 +- test/testgesture.c | 11 +- 15 files changed, 356 insertions(+), 917 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index fce02bf75..762aba442 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -105,8 +105,6 @@ typedef enum SDL_FINGERDOWN = 0x700, SDL_FINGERUP, SDL_FINGERMOTION, - SDL_TOUCHBUTTONDOWN, - SDL_TOUCHBUTTONUP, /* Gesture events */ SDL_DOLLARGESTURE = 0x800, @@ -367,43 +365,22 @@ typedef struct SDL_ControllerDeviceEvent /** - * \brief Touch finger motion/finger event structure (event.tfinger.*) + * \brief Touch finger event structure (event.tfinger.*) */ typedef struct SDL_TouchFingerEvent { Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */ Uint32 timestamp; - Uint32 windowID; /**< The window with mouse focus, if any */ SDL_TouchID touchId; /**< The touch device id */ SDL_FingerID fingerId; - Uint8 state; /**< The current button state */ - Uint8 padding1; - Uint8 padding2; - Uint8 padding3; - Uint16 x; - Uint16 y; - Sint16 dx; - Sint16 dy; - Uint16 pressure; + float x; /**< Normalized in the range 0...1 */ + float y; /**< Normalized in the range 0...1 */ + float dx; /**< Normalized in the range 0...1 */ + float dy; /**< Normalized in the range 0...1 */ + float pressure; /**< Normalized in the range 0...1 */ } SDL_TouchFingerEvent; -/** - * \brief Touch finger motion/finger event structure (event.tbutton.*) - */ -typedef struct SDL_TouchButtonEvent -{ - Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */ - Uint32 timestamp; - Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device index */ - Uint8 state; /**< The current button state */ - Uint8 button; /**< The button changing state */ - Uint8 padding1; - Uint8 padding2; -} SDL_TouchButtonEvent; - - /** * \brief Multiple Finger Gesture Event (event.mgesture.*) */ @@ -411,31 +388,27 @@ typedef struct SDL_MultiGestureEvent { Uint32 type; /**< ::SDL_MULTIGESTURE */ Uint32 timestamp; - Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device index */ + SDL_TouchID touchId; /**< The touch device index */ float dTheta; float dDist; - float x; /* currently 0...1. Change to screen coords? */ + float x; float y; Uint16 numFingers; Uint16 padding; } SDL_MultiGestureEvent; + /* (event.dgesture.*) */ typedef struct SDL_DollarGestureEvent { Uint32 type; /**< ::SDL_DOLLARGESTURE */ Uint32 timestamp; - Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device index */ + SDL_TouchID touchId; /**< The touch device id */ SDL_GestureID gestureId; Uint32 numFingers; float error; - /* - //TODO: Enable to give location? - float x; //currently 0...1. Change to screen coords? - float y; - */ + float x; /**< Normalized center of gesture */ + float y; /**< Normalized center of gesture */ } SDL_DollarGestureEvent; @@ -518,9 +491,8 @@ typedef union SDL_Event SDL_UserEvent user; /**< Custom event data */ SDL_SysWMEvent syswm; /**< System dependent window event data */ SDL_TouchFingerEvent tfinger; /**< Touch finger event data */ - SDL_TouchButtonEvent tbutton; /**< Touch button event data */ - SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */ - SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */ + SDL_MultiGestureEvent mgesture; /**< Gesture event data */ + SDL_DollarGestureEvent dgesture; /**< Gesture event data */ SDL_DropEvent drop; /**< Drag and drop event data */ /* This is necessary for ABI compatibility between Visual C++ and GCC diff --git a/include/SDL_touch.h b/include/SDL_touch.h index de7ccf48d..55176a1d9 100644 --- a/include/SDL_touch.h +++ b/include/SDL_touch.h @@ -46,46 +46,11 @@ typedef Sint64 SDL_FingerID; typedef struct SDL_Finger { SDL_FingerID id; - Uint16 x; - Uint16 y; - Uint16 pressure; - Uint16 xdelta; - Uint16 ydelta; - Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */ - SDL_bool down; + float x; + float y; + float pressure; } SDL_Finger; -typedef struct SDL_Touch -{ - /* Free the touch when it's time */ - void (*FreeTouch) (struct SDL_Touch * touch); - - /* data common for tablets */ - float pressure_max, pressure_min; - float x_max,x_min; - float y_max,y_min; - Uint16 xres,yres,pressureres; - float native_xres,native_yres,native_pressureres; - float tilt_x; /* for future use */ - float tilt_y; /* for future use */ - float rotation; /* for future use */ - - /* Data common to all touch */ - SDL_TouchID id; - SDL_Window *focus; - - char *name; - Uint8 buttonstate; - SDL_bool relative_mode; - SDL_bool flush_motion; - - int num_fingers; - int max_fingers; - SDL_Finger** fingers; - - void *driverdata; -} SDL_Touch; - /* Used as the device ID for mouse events simulated with touch input */ #define SDL_TOUCH_MOUSEID ((Uint32)-1) @@ -93,14 +58,24 @@ typedef struct SDL_Touch /* Function prototypes */ /** - * \brief Get the touch object with the given id. + * \brief Get the number of registered touch devices. */ -extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id); +extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices(); /** - * \brief Get the finger object of the given touch, with the given id. + * \brief Get the touch ID with the given index, or 0 if the index is invalid. */ -extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id); +extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index); + +/** + * \brief Get the number of active fingers for a given touch device. + */ +extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID); + +/** + * \brief Get the finger object of the given touch, with the given index. + */ +extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/events/SDL_gesture.c b/src/events/SDL_gesture.c index 7d2ab7c45..b43e1f92e 100644 --- a/src/events/SDL_gesture.c +++ b/src/events/SDL_gesture.c @@ -64,7 +64,6 @@ typedef struct { typedef struct { SDL_TouchID id; - SDL_FloatPoint res; SDL_FloatPoint centroid; SDL_DollarPath dollarPath; Uint16 numDownFingers; @@ -410,7 +409,7 @@ static float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_Gestu return bestDiff; } -int SDL_GestureAddTouch(SDL_Touch* touch) +int SDL_GestureAddTouch(SDL_TouchID touchId) { SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch, (SDL_numGestureTouches + 1) * @@ -423,12 +422,8 @@ int SDL_GestureAddTouch(SDL_Touch* touch) SDL_gestureTouch = gestureTouch; - SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres; - SDL_gestureTouch[SDL_numGestureTouches].res.y = touch->yres; SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0; - - SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres; - SDL_gestureTouch[SDL_numGestureTouches].id = touch->id; + SDL_gestureTouch[SDL_numGestureTouches].id = touchId; SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0; @@ -468,11 +463,8 @@ static int SDL_SendGestureDollar(SDL_GestureTouch* touch, SDL_Event event; event.dgesture.type = SDL_DOLLARGESTURE; event.dgesture.touchId = touch->id; - /* - //TODO: Add this to give location of gesture? event.mgesture.x = touch->centroid.x; event.mgesture.y = touch->centroid.y; - */ event.dgesture.gestureId = gestureId; event.dgesture.error = error; //A finger came up to trigger this event. @@ -513,14 +505,8 @@ void SDL_GestureProcessEvent(SDL_Event* event) //Shouldn't be possible if (inTouch == NULL) return; - //printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x, - // (int)event->tfinger.y, - // (int)inTouch->res.x,(int)inTouch->res.y); - - - x = ((float)event->tfinger.x)/(float)inTouch->res.x; - y = ((float)event->tfinger.y)/(float)inTouch->res.y; - + x = event->tfinger.x; + y = event->tfinger.y; //Finger Up if (event->type == SDL_FINGERUP) { @@ -569,9 +555,8 @@ void SDL_GestureProcessEvent(SDL_Event* event) } } else if (event->type == SDL_FINGERMOTION) { - float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x; - float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y; - //printf("dx,dy: (%f,%f)\n",dx,dy); + float dx = event->tfinger.dx; + float dy = event->tfinger.dy; #ifdef ENABLE_DOLLAR SDL_DollarPath* path = &inTouch->dollarPath; if (path->numPoints < MAXPATHSIZE) { diff --git a/src/events/SDL_gesture_c.h b/src/events/SDL_gesture_c.h index eb994890f..08ba2e80c 100644 --- a/src/events/SDL_gesture_c.h +++ b/src/events/SDL_gesture_c.h @@ -23,12 +23,12 @@ #ifndef _SDL_gesture_c_h #define _SDL_gesture_c_h +extern int SDL_GestureAddTouch(SDL_TouchID touchId); + extern void SDL_GestureProcessEvent(SDL_Event* event); extern int SDL_RecordGesture(SDL_TouchID touchId); -extern int SDL_GestureAddTouch(SDL_Touch* touch); - #endif /* _SDL_gesture_c_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 6ba5f0bc9..4b41e2741 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -22,72 +22,46 @@ /* General touch handling code for SDL */ +#include "SDL_assert.h" #include "SDL_events.h" #include "SDL_events_c.h" -#include "../video/SDL_sysvideo.h" - -#include static int SDL_num_touch = 0; -static SDL_Touch **SDL_touchPads = NULL; +static SDL_Touch **SDL_touchDevices = NULL; /* Public functions */ int SDL_TouchInit(void) { - return (0); + return (0); } -SDL_Touch * -SDL_GetTouch(SDL_TouchID id) +int +SDL_GetNumTouchDevices() { - int index = SDL_GetTouchIndexId(id); - if (index < 0 || index >= SDL_num_touch) { - return NULL; - } - return SDL_touchPads[index]; + return SDL_num_touch; } -SDL_Touch * -SDL_GetTouchIndex(int index) +SDL_TouchID +SDL_GetTouchDevice(int index) { if (index < 0 || index >= SDL_num_touch) { - return NULL; + SDL_SetError("Unknown touch device"); + return 0; } - return SDL_touchPads[index]; + return SDL_touchDevices[index]->id; } static int -SDL_GetFingerIndexId(SDL_Touch* touch,SDL_FingerID fingerid) -{ - int i; - for(i = 0;i < touch->num_fingers;i++) - if(touch->fingers[i]->id == fingerid) - return i; - return -1; -} - - -SDL_Finger * -SDL_GetFinger(SDL_Touch* touch,SDL_FingerID id) -{ - int index = SDL_GetFingerIndexId(touch,id); - if(index < 0 || index >= touch->num_fingers) - return NULL; - return touch->fingers[index]; -} - - -int -SDL_GetTouchIndexId(SDL_TouchID id) +SDL_GetTouchIndex(SDL_TouchID id) { int index; SDL_Touch *touch; for (index = 0; index < SDL_num_touch; ++index) { - touch = SDL_touchPads[index]; + touch = SDL_touchDevices[index]; if (touch->id == id) { return index; } @@ -95,78 +69,284 @@ SDL_GetTouchIndexId(SDL_TouchID id) return -1; } -int -SDL_AddTouch(const SDL_Touch * touch, char *name) +SDL_Touch * +SDL_GetTouch(SDL_TouchID id) { - SDL_Touch **touchPads; - int index; - size_t length; + int index = SDL_GetTouchIndex(id); + if (index < 0 || index >= SDL_num_touch) { + SDL_SetError("Unknown touch device"); + return NULL; + } + return SDL_touchDevices[index]; +} - if (SDL_GetTouchIndexId(touch->id) != -1) { - SDL_SetError("Touch ID already in use"); +static int +SDL_GetFingerIndex(const SDL_Touch * touch, SDL_FingerID fingerid) +{ + int index; + for (index = 0; index < touch->num_fingers; ++index) { + if (touch->fingers[index]->id == fingerid) { + return index; + } + } + return -1; +} + +SDL_Finger * +SDL_GetFinger(const SDL_Touch * touch, SDL_FingerID id) +{ + int index = SDL_GetFingerIndex(touch, id); + if (index < 0 || index >= touch->num_fingers) { + return NULL; + } + return touch->fingers[index]; +} + +int +SDL_GetNumTouchFingers(SDL_TouchID touchID) +{ + SDL_Touch *touch = SDL_GetTouch(touchID); + if (touch) { + return touch->num_fingers; + } + return 0; +} + +SDL_Finger * +SDL_GetTouchFinger(SDL_TouchID touchID, int index) +{ + SDL_Touch *touch = SDL_GetTouch(touchID); + if (!touch) { + return NULL; + } + if (index < 0 || index >= touch->num_fingers) { + SDL_SetError("Unknown touch finger"); + return NULL; + } + return touch->fingers[index]; +} + +int +SDL_AddTouch(SDL_TouchID touchID, const char *name) +{ + SDL_Touch **touchDevices; + int index; + + index = SDL_GetTouchIndex(touchID); + if (index >= 0) { + return index; } /* Add the touch to the list of touch */ - touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads, - (SDL_num_touch + 1) * sizeof(*touch)); - if (!touchPads) { + touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices, + (SDL_num_touch + 1) * sizeof(*touchDevices)); + if (!touchDevices) { SDL_OutOfMemory(); return -1; } - SDL_touchPads = touchPads; + SDL_touchDevices = touchDevices; index = SDL_num_touch++; - SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index])); - if (!SDL_touchPads[index]) { + SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index])); + if (!SDL_touchDevices[index]) { SDL_OutOfMemory(); return -1; } - SDL_memcpy(SDL_touchPads[index], touch, sizeof(*touch)); /* we're setting the touch properties */ - length = SDL_strlen(name); - SDL_touchPads[index]->focus = 0; - SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char)); - SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1); + SDL_touchDevices[index]->id = touchID; + SDL_touchDevices[index]->num_fingers = 0; + SDL_touchDevices[index]->max_fingers = 0; + SDL_touchDevices[index]->fingers = NULL; - SDL_touchPads[index]->num_fingers = 0; - SDL_touchPads[index]->max_fingers = 1; - SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*)); - SDL_touchPads[index]->fingers[0] = NULL; - SDL_touchPads[index]->buttonstate = 0; - SDL_touchPads[index]->relative_mode = SDL_FALSE; - SDL_touchPads[index]->flush_motion = SDL_FALSE; - - SDL_touchPads[index]->xres = (1<<(16-1)); - SDL_touchPads[index]->yres = (1<<(16-1)); - SDL_touchPads[index]->pressureres = (1<<(16-1)); - //Do I want this here? Probably - SDL_GestureAddTouch(SDL_touchPads[index]); + /* Record this touch device for gestures */ + /* We could do this on the fly in the gesture code if we wanted */ + SDL_GestureAddTouch(touchID); return index; } +static int +SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure) +{ + SDL_Finger *finger; + + if (touch->num_fingers == touch->max_fingers) { + SDL_Finger **new_fingers; + new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers)); + if (!new_fingers) { + SDL_OutOfMemory(); + return -1; + } + touch->fingers = new_fingers; + touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger)); + if (!touch->fingers[touch->max_fingers]) { + SDL_OutOfMemory(); + return -1; + } + touch->max_fingers++; + } + + finger = touch->fingers[touch->num_fingers++]; + finger->id = fingerid; + finger->x = x; + finger->y = y; + finger->pressure = pressure; + return 0; +} + +static int +SDL_DelFinger(SDL_Touch* touch, SDL_FingerID fingerid) +{ + SDL_Finger *temp; + + int index = SDL_GetFingerIndex(touch, fingerid); + if (index < 0) { + return -1; + } + + touch->num_fingers--; + temp = touch->fingers[index]; + touch->fingers[index] = touch->fingers[touch->num_fingers]; + touch->fingers[touch->num_fingers] = temp; + return 0; +} + +int +SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, + SDL_bool down, float x, float y, float pressure) +{ + int posted; + SDL_Finger *finger; + + SDL_Touch* touch = SDL_GetTouch(id); + if (!touch) { + return -1; + } + + finger = SDL_GetFinger(touch, fingerid); + if (down) { + if (finger) { + /* This finger is already down */ + return 0; + } + + if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) { + return 0; + } + + posted = 0; + if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { + SDL_Event event; + event.tfinger.type = SDL_FINGERDOWN; + event.tfinger.touchId = id; + event.tfinger.fingerId = fingerid; + event.tfinger.x = x; + event.tfinger.y = y; + event.tfinger.dx = 0; + event.tfinger.dy = 0; + event.tfinger.pressure = pressure; + posted = (SDL_PushEvent(&event) > 0); + } + } else { + if (!finger) { + /* This finger is already up */ + return 0; + } + + posted = 0; + if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { + SDL_Event event; + event.tfinger.type = SDL_FINGERUP; + event.tfinger.touchId = id; + event.tfinger.fingerId = fingerid; + /* I don't trust the coordinates passed on fingerUp */ + event.tfinger.x = finger->x; + event.tfinger.y = finger->y; + event.tfinger.dx = 0; + event.tfinger.dy = 0; + event.tfinger.pressure = pressure; + posted = (SDL_PushEvent(&event) > 0); + } + + SDL_DelFinger(touch, fingerid); + } + return posted; +} + +int +SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, + float x, float y, float pressure) +{ + SDL_Touch *touch; + SDL_Finger *finger; + int posted; + float xrel, yrel, prel; + + touch = SDL_GetTouch(id); + if (!touch) { + return -1; + } + + finger = SDL_GetFinger(touch,fingerid); + if (!finger) { + return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure); + } + + xrel = x - finger->x; + yrel = y - finger->y; + prel = pressure - finger->pressure; + + /* Drop events that don't change state */ + if (!xrel && !yrel && !prel) { +#if 0 + printf("Touch event didn't change state - dropped!\n"); +#endif + return 0; + } + + /* Update internal touch coordinates */ + finger->x = x; + finger->y = y; + finger->pressure = pressure; + + /* Post the event, if desired */ + posted = 0; + if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { + SDL_Event event; + event.tfinger.type = SDL_FINGERMOTION; + event.tfinger.touchId = id; + event.tfinger.fingerId = fingerid; + event.tfinger.x = x; + event.tfinger.y = y; + event.tfinger.dx = xrel; + event.tfinger.dy = yrel; + event.tfinger.pressure = pressure; + posted = (SDL_PushEvent(&event) > 0); + } + return posted; +} + void SDL_DelTouch(SDL_TouchID id) { - int index = SDL_GetTouchIndexId(id); + int i; + int index = SDL_GetTouchIndex(id); SDL_Touch *touch = SDL_GetTouch(id); if (!touch) { return; } - - SDL_free(touch->name); - - if (touch->FreeTouch) { - touch->FreeTouch(touch); + for (i = 0; i < touch->max_fingers; ++i) { + SDL_free(touch->fingers[i]); } + SDL_free(touch->fingers); SDL_free(touch); SDL_num_touch--; - SDL_touchPads[index] = SDL_touchPads[SDL_num_touch]; + SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch]; } void @@ -174,400 +354,15 @@ SDL_TouchQuit(void) { int i; - for (i = SDL_num_touch-1; i > 0 ; --i) { - SDL_DelTouch(i); + for (i = SDL_num_touch; i--; ) { + SDL_DelTouch(SDL_touchDevices[i]->id); } - SDL_num_touch = 0; + SDL_assert(SDL_num_touch == 0); - if (SDL_touchPads) { - SDL_free(SDL_touchPads); - SDL_touchPads = NULL; + if (SDL_touchDevices) { + SDL_free(SDL_touchDevices); + SDL_touchDevices = NULL; } } -int -SDL_GetNumTouch(void) -{ - return SDL_num_touch; -} - -SDL_Window * -SDL_GetTouchFocusWindow(SDL_TouchID id) -{ - SDL_Touch *touch = SDL_GetTouch(id); - - if (!touch) { - return 0; - } - return touch->focus; -} - -void -SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window) -{ - int index = SDL_GetTouchIndexId(id); - SDL_Touch *touch = SDL_GetTouch(id); - int i; - SDL_bool focus; - - if (!touch || (touch->focus == window)) { - return; - } - - /* See if the current window has lost focus */ - if (touch->focus) { - focus = SDL_FALSE; - for (i = 0; i < SDL_num_touch; ++i) { - SDL_Touch *check; - if (i != index) { - check = SDL_touchPads[i]; - if (check && check->focus == touch->focus) { - focus = SDL_TRUE; - break; - } - } - } - if (!focus) { - SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0); - } - } - - touch->focus = window; - - if (touch->focus) { - focus = SDL_FALSE; - for (i = 0; i < SDL_num_touch; ++i) { - SDL_Touch *check; - if (i != index) { - check = SDL_touchPads[i]; - if (check && check->focus == touch->focus) { - focus = SDL_TRUE; - break; - } - } - } - if (!focus) { - SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0); - } - } -} - -int -SDL_AddFinger(SDL_Touch* touch,SDL_Finger *finger) -{ - int index; - SDL_Finger **fingers; - //printf("Adding Finger...\n"); - if (SDL_GetFingerIndexId(touch,finger->id) != -1) { - SDL_SetError("Finger ID already in use"); - } - - /* Add the touch to the list of touch */ - if(touch->num_fingers >= touch->max_fingers){ - //printf("Making room for it!\n"); - fingers = (SDL_Finger **) SDL_realloc(touch->fingers, - (touch->num_fingers + 1) * sizeof(SDL_Finger *)); - if (!fingers) { - SDL_OutOfMemory(); - return -1; - } else { - touch->max_fingers = touch->num_fingers+1; - touch->fingers = fingers; - } - } - - index = touch->num_fingers; - //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index); - - touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger)); - if (!touch->fingers[index]) { - SDL_OutOfMemory(); - return -1; - } - *(touch->fingers[index]) = *finger; - touch->num_fingers++; - - return index; -} - -int -SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid) -{ - int index = SDL_GetFingerIndexId(touch,fingerid); - SDL_Finger* finger = SDL_GetFinger(touch,fingerid); - - if (!finger) { - return -1; - } - - - SDL_free(finger); - touch->num_fingers--; - touch->fingers[index] = touch->fingers[touch->num_fingers]; - return 0; -} - - -int -SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, - float xin, float yin, float pressurein) -{ - int posted; - Uint16 x; - Uint16 y; - Uint16 pressure; - SDL_Finger *finger; - - SDL_Touch* touch = SDL_GetTouch(id); - - if(!touch) { - return SDL_TouchNotFoundError(id); - } - - - //scale to Integer coordinates - x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres)); - y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres)); - pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres)); - - finger = SDL_GetFinger(touch,fingerid); - if(down) { - if(finger == NULL) { - SDL_Finger nf; - nf.id = fingerid; - nf.x = x; - nf.y = y; - nf.pressure = pressure; - nf.xdelta = 0; - nf.ydelta = 0; - nf.last_x = x; - nf.last_y = y; - nf.last_pressure = pressure; - nf.down = SDL_FALSE; - if(SDL_AddFinger(touch,&nf) < 0) return 0; - finger = SDL_GetFinger(touch,fingerid); - } - else if(finger->down) return 0; - if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input - posted = 0; - if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { - SDL_Event event; - event.tfinger.type = SDL_FINGERDOWN; - event.tfinger.touchId = id; - event.tfinger.x = x; - event.tfinger.y = y; - event.tfinger.dx = 0; - event.tfinger.dy = 0; - event.tfinger.pressure = pressure; - event.tfinger.state = touch->buttonstate; - event.tfinger.windowID = touch->focus ? touch->focus->id : 0; - event.tfinger.fingerId = fingerid; - posted = (SDL_PushEvent(&event) > 0); - } - if(posted) finger->down = SDL_TRUE; - return posted; - } - else { - if(finger == NULL) { - SDL_SetError("Finger not found."); - return 0; - } - posted = 0; - if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { - SDL_Event event; - event.tfinger.type = SDL_FINGERUP; - event.tfinger.touchId = id; - event.tfinger.state = touch->buttonstate; - event.tfinger.windowID = touch->focus ? touch->focus->id : 0; - event.tfinger.fingerId = fingerid; - //I don't trust the coordinates passed on fingerUp - event.tfinger.x = finger->x; - event.tfinger.y = finger->y; - event.tfinger.dx = 0; - event.tfinger.dy = 0; - event.tfinger.pressure = pressure; - - if(SDL_DelFinger(touch,fingerid) < 0) return 0; - posted = (SDL_PushEvent(&event) > 0); - } - return posted; - } -} - -int -SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, - float xin, float yin, float pressurein) -{ - SDL_Touch *touch; - SDL_Finger *finger; - int posted; - Sint16 xrel, yrel; - Uint16 x; - Uint16 y; - Uint16 pressure; - - touch = SDL_GetTouch(id); - if (!touch) { - return SDL_TouchNotFoundError(id); - } - - //scale to Integer coordinates - x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres)); - y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres)); - pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres)); - if(touch->flush_motion) { - return 0; - } - - finger = SDL_GetFinger(touch,fingerid); - if(finger == NULL || !finger->down) { - return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein); - } else { - /* the relative motion is calculated regarding the last position */ - if (relative) { - xrel = x; - yrel = y; - x = (finger->last_x + x); - y = (finger->last_y + y); - } else { - if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/ - if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/ - if(pressurein < touch->pressure_min) pressure = finger->last_pressure; - xrel = x - finger->last_x; - yrel = y - finger->last_y; - //printf("xrel,yrel (%i,%i)\n",(int)xrel,(int)yrel); - } - - /* Drop events that don't change state */ - if (!xrel && !yrel) { -#if 0 - printf("Touch event didn't change state - dropped!\n"); -#endif - return 0; - } - - /* Update internal touch coordinates */ - - finger->x = x; - finger->y = y; - - /*Should scale to window? Normalize? Maintain Aspect?*/ - //SDL_GetWindowSize(touch->focus, &x_max, &y_max); - - /* make sure that the pointers find themselves inside the windows */ - /* only check if touch->xmax is set ! */ - /* - if (x_max && touch->x > x_max) { - touch->x = x_max; - } else if (touch->x < 0) { - touch->x = 0; - } - - if (y_max && touch->y > y_max) { - touch->y = y_max; - } else if (touch->y < 0) { - touch->y = 0; - } - */ - finger->xdelta = xrel; - finger->ydelta = yrel; - finger->pressure = pressure; - - - - /* Post the event, if desired */ - posted = 0; - if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { - SDL_Event event; - event.tfinger.type = SDL_FINGERMOTION; - event.tfinger.touchId = id; - event.tfinger.fingerId = fingerid; - event.tfinger.x = x; - event.tfinger.y = y; - event.tfinger.dx = xrel; - event.tfinger.dy = yrel; - - event.tfinger.pressure = pressure; - event.tfinger.state = touch->buttonstate; - event.tfinger.windowID = touch->focus ? touch->focus->id : 0; - posted = (SDL_PushEvent(&event) > 0); - } - finger->last_x = finger->x; - finger->last_y = finger->y; - finger->last_pressure = finger->pressure; - return posted; - } -} - -int -SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button) -{ - SDL_Touch *touch; - int posted; - Uint32 type; - - - touch = SDL_GetTouch(id); - if (!touch) { - return SDL_TouchNotFoundError(id); - } - - /* Figure out which event to perform */ - switch (state) { - case SDL_PRESSED: - if (touch->buttonstate & SDL_BUTTON(button)) { - /* Ignore this event, no state change */ - return 0; - } - type = SDL_TOUCHBUTTONDOWN; - touch->buttonstate |= SDL_BUTTON(button); - break; - case SDL_RELEASED: - if (!(touch->buttonstate & SDL_BUTTON(button))) { - /* Ignore this event, no state change */ - return 0; - } - type = SDL_TOUCHBUTTONUP; - touch->buttonstate &= ~SDL_BUTTON(button); - break; - default: - /* Invalid state -- bail */ - return 0; - } - - /* Post the event, if desired */ - posted = 0; - if (SDL_GetEventState(type) == SDL_ENABLE) { - SDL_Event event; - event.type = type; - event.tbutton.touchId = touch->id; - event.tbutton.state = state; - event.tbutton.button = button; - event.tbutton.windowID = touch->focus ? touch->focus->id : 0; - posted = (SDL_PushEvent(&event) > 0); - } - return posted; -} - -char * -SDL_GetTouchName(SDL_TouchID id) -{ - SDL_Touch *touch = SDL_GetTouch(id); - if (!touch) { - return NULL; - } - return touch->name; -} - -int SDL_TouchNotFoundError(SDL_TouchID id) { - //int i; - SDL_SetError("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id); -#if 0 - printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch); - for(i=0;i < SDL_num_touch;i++) { - printf("ERROR: %li\n",SDL_touchPads[i]->id); - } -#endif - return 0; -} /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_touch_c.h b/src/events/SDL_touch_c.h index c4addf364..8961d74e5 100644 --- a/src/events/SDL_touch_c.h +++ b/src/events/SDL_touch_c.h @@ -24,55 +24,38 @@ #ifndef _SDL_touch_c_h #define _SDL_touch_c_h +typedef struct SDL_Touch +{ + SDL_TouchID id; + int num_fingers; + int max_fingers; + SDL_Finger** fingers; +} SDL_Touch; /* Initialize the touch subsystem */ extern int SDL_TouchInit(void); -/*Get the touch at an index */ -extern SDL_Touch *SDL_GetTouchIndex(int index); - -/* Get the touch with id = id */ +/* Add a touch, returning the index of the touch, or -1 if there was an error. */ +extern int SDL_AddTouch(SDL_TouchID id, const char *name); + +/* Get the touch with a given id */ extern SDL_Touch *SDL_GetTouch(SDL_TouchID id); -/*Get the finger at an index */ -extern SDL_Finger *SDL_GetFingerIndex(SDL_Touch *touch, int index); - -/* Get the finger with id = id */ -extern SDL_Finger *SDL_GetFinger(SDL_Touch *touch,SDL_FingerID id); - - -/* Add a touch, possibly reattaching at a particular index (or -1), - returning the index of the touch, or -1 if there was an error. */ -extern int SDL_AddTouch(const SDL_Touch * touch, char *name); - - -/* Remove a touch at an index, clearing the slot for later */ -extern void SDL_DelTouch(SDL_TouchID id); - -/* Set the touch focus window */ -extern void SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window); +/* Send a touch down/up event for a touch */ +extern int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, + SDL_bool down, float x, float y, float pressure); /* Send a touch motion event for a touch */ extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, - int relative, float x, float y, float z); + float x, float y, float pressure); -/* Send a touch down/up event for a touch */ -extern int SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, - SDL_bool down, float x, float y, float pressure); - -/* Send a touch button event for a touch */ -extern int SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button); +/* Remove a touch */ +extern void SDL_DelTouch(SDL_TouchID id); /* Shutdown the touch subsystem */ extern void SDL_TouchQuit(void); -/* Get the index of a touch device */ -extern int SDL_GetTouchIndexId(SDL_TouchID id); - -/* Print a debug message for a nonexistent touch */ -extern int SDL_TouchNotFoundError(SDL_TouchID id); - #endif /* _SDL_touch_c_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/android/SDL_androidtouch.c b/src/video/android/SDL_androidtouch.c index 87386de26..4f4a8fdb2 100644 --- a/src/video/android/SDL_androidtouch.c +++ b/src/video/android/SDL_androidtouch.c @@ -64,19 +64,7 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio touchDeviceId = (SDL_TouchID)touch_device_id_in; if (!SDL_GetTouch(touchDeviceId)) { - SDL_Touch touch; - memset( &touch, 0, sizeof(touch) ); - touch.id = touchDeviceId; - touch.x_min = 0.0f; - touch.x_max = 1.0f; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0.0f; - touch.y_max = 1.0f; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0.0f; - touch.pressure_max = 1.0f; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - if (SDL_AddTouch(&touch, "") < 0) { + if (SDL_AddTouch(touchDeviceId, "") < 0) { SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } } @@ -96,7 +84,7 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio leftFingerDown = fingerId; } - SDL_SendFingerDown(touchDeviceId, fingerId, SDL_TRUE, x, y, p); + SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p); break; case ACTION_MOVE: if (!leftFingerDown) { @@ -105,7 +93,7 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio /* send moved event */ SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); } - SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p); + SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p); break; case ACTION_UP: case ACTION_POINTER_1_UP: @@ -114,7 +102,7 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); leftFingerDown = 0; } - SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p); + SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; default: break; diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 5a3d6cc83..f7f68828c 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -408,27 +408,14 @@ static __inline__ void ConvertNSRect(NSRect *r) enumerator = [touches objectEnumerator]; touch = (NSTouch*)[enumerator nextObject]; while (touch) { - const SDL_TouchID touchId = (SDL_TouchID) ((size_t) [touch device]); + const SDL_TouchID touchId = (SDL_TouchID)[touch device]; if (!SDL_GetTouch(touchId)) { - SDL_Touch touch; - - touch.id = touchId; - touch.x_min = 0; - touch.x_max = 1; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0; - touch.y_max = 1; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0; - touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - if (SDL_AddTouch(&touch, "") < 0) { + if (SDL_AddTouch(touchId, "") < 0) { return; } } - const SDL_FingerID fingerId = (SDL_FingerID) ((size_t) [touch identity]); + const SDL_FingerID fingerId = (SDL_FingerID)[touch identity]; float x = [touch normalizedPosition].x; float y = [touch normalizedPosition].y; /* Make the origin the upper left instead of the lower left */ @@ -436,17 +423,17 @@ static __inline__ void ConvertNSRect(NSRect *r) switch (type) { case COCOA_TOUCH_DOWN: - SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1); + SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f); break; case COCOA_TOUCH_UP: case COCOA_TOUCH_CANCELLED: - SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1); + SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f); break; case COCOA_TOUCH_MOVE: - SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1); + SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f); break; } - + touch = (NSTouch*)[enumerator nextObject]; } #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 */ diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index 20701d84d..a5eca6c9d 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -52,23 +52,8 @@ self.multipleTouchEnabled = YES; - SDL_Touch touch; - touch.id = 0; //TODO: Should be -1? - - //touch.driverdata = SDL_malloc(sizeof(EventTouchData)); - //EventTouchData* data = (EventTouchData*)(touch.driverdata); - - touch.x_min = 0; - touch.x_max = 1; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0; - touch.y_max = 1; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0; - touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - touchId = SDL_AddTouch(&touch, "IPHONE SCREEN"); + touchId = 1; + SDL_AddTouch(touchId, ""); return self; @@ -117,17 +102,15 @@ // FIXME: TODO: Using touch as the fingerId is potentially dangerous // It is also much more efficient than storing the UITouch pointer // and comparing it to the incoming event. - SDL_SendFingerDown(touchId, (SDL_FingerID)touch, - SDL_TRUE, locationInView.x, locationInView.y, - 1); + SDL_SendTouch(touchId, (SDL_FingerID)touch, + SDL_TRUE, locationInView.x, locationInView.y, 1.0f); #else int i; for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) { if (finger[i] == NULL) { finger[i] = touch; - SDL_SendFingerDown(touchId, i, - SDL_TRUE, locationInView.x, locationInView.y, - 1); + SDL_SendTouch(touchId, i, + SDL_TRUE, locationInView.x, locationInView.y, 1.0f); break; } } @@ -150,16 +133,14 @@ CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS - SDL_SendFingerDown(touchId, (long)touch, - SDL_FALSE, locationInView.x, locationInView.y, - 1); + SDL_SendTouch(touchId, (long)touch, + SDL_FALSE, locationInView.x, locationInView.y, 1.0f); #else int i; for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) { if (finger[i] == touch) { - SDL_SendFingerDown(touchId, i, - SDL_FALSE, locationInView.x, locationInView.y, - 1); + SDL_SendTouch(touchId, i, + SDL_FALSE, locationInView.x, locationInView.y, 1.0f); finger[i] = NULL; break; } @@ -195,15 +176,13 @@ CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS SDL_SendTouchMotion(touchId, (long)touch, - SDL_FALSE, locationInView.x, locationInView.y, - 1); + locationInView.x, locationInView.y, 1.0f); #else int i; for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) { if (finger[i] == touch) { SDL_SendTouchMotion(touchId, i, - SDL_FALSE, locationInView.x, locationInView.y, - 1); + locationInView.x, locationInView.y, 1.0f); break; } } diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 1b3937833..7a1087358 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -691,23 +691,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) for (i = 0; i < num_inputs; ++i) { PTOUCHINPUT input = &inputs[i]; - const SDL_TouchID touchId = (SDL_TouchID) - ((size_t)input->hSource); + const SDL_TouchID touchId = (SDL_TouchID)input->hSource; if (!SDL_GetTouch(touchId)) { - SDL_Touch touch; - - touch.id = touchId; - touch.x_min = 0; - touch.x_max = 1; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0; - touch.y_max = 1; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0; - touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - if (SDL_AddTouch(&touch, "") < 0) { + if (SDL_AddTouch(touchId, "") < 0) { continue; } } @@ -717,13 +703,13 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) y = (float)(input->y - rect.top)/(rect.bottom - rect.top); if (input->dwFlags & TOUCHEVENTF_DOWN) { - SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1); + SDL_SendTouch(touchId, input->dwID, SDL_TRUE, x, y, 1.0f); } if (input->dwFlags & TOUCHEVENTF_MOVE) { - SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1); + SDL_SendTouchMotion(touchId, input->dwID, x, y, 1.0f); } if (input->dwFlags & TOUCHEVENTF_UP) { - SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1); + SDL_SendTouch(touchId, input->dwID, SDL_FALSE, x, y, 1.0f); } } } diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index fa8543d8e..2e23bc7d9 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -41,12 +41,6 @@ #include -#ifdef SDL_INPUT_LINUXEV -/* Touch Input/event* includes */ -#include -#include -#endif - /*#define DEBUG_XEVENTS*/ /* Check to see if this is a repeated key. @@ -703,90 +697,6 @@ X11_PumpEvents(_THIS) /* FIXME: Only need to do this when there are pending focus changes */ X11_HandleFocusChanges(_this); - - /*Dont process evtouch events if XInput2 multitouch is supported*/ - if(X11_Xinput2IsMultitouchSupported()) { - return; - } - -#ifdef SDL_INPUT_LINUXEV - /* Process Touch events*/ - int i = 0,rd; - struct input_event ev[64]; - int size = sizeof (struct input_event); - -/* !!! FIXME: clean the tabstops out of here. */ - for(i = 0;i < SDL_GetNumTouch();++i) { - SDL_Touch* touch = SDL_GetTouchIndex(i); - if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch()); - EventTouchData* data; - data = (EventTouchData*)(touch->driverdata); - if(data == NULL) { - printf("No driver data\n"); - continue; - } - if(data->eventStream <= 0) - printf("Error: Couldn't open stream\n"); - rd = read(data->eventStream, ev, size * 64); - if(rd >= size) { - for (i = 0; i < rd / sizeof(struct input_event); i++) { - switch (ev[i].type) { - case EV_ABS: - switch (ev[i].code) { - case ABS_X: - data->x = ev[i].value; - break; - case ABS_Y: - data->y = ev[i].value; - break; - case ABS_PRESSURE: - data->pressure = ev[i].value; - if(data->pressure < 0) data->pressure = 0; - break; - case ABS_MISC: - if(ev[i].value == 0) - data->up = SDL_TRUE; - break; - } - break; - case EV_MSC: - if(ev[i].code == MSC_SERIAL) - data->finger = ev[i].value; - break; - case EV_KEY: - if(ev[i].code == BTN_TOUCH) - if(ev[i].value == 0) - data->up = SDL_TRUE; - break; - case EV_SYN: - if(!data->down) { - data->down = SDL_TRUE; - SDL_SendFingerDown(touch->id,data->finger, - data->down, data->x, data->y, - data->pressure); - } - else if(!data->up) - SDL_SendTouchMotion(touch->id,data->finger, - SDL_FALSE, data->x,data->y, - data->pressure); - else - { - data->down = SDL_FALSE; - SDL_SendFingerDown(touch->id,data->finger, - data->down, data->x,data->y, - data->pressure); - data->x = -1; - data->y = -1; - data->pressure = -1; - data->finger = 0; - data->up = SDL_FALSE; - } - break; - } - } - } - } -#endif } diff --git a/src/video/x11/SDL_x11touch.c b/src/video/x11/SDL_x11touch.c index 76ad78400..a6ce98160 100644 --- a/src/video/x11/SDL_x11touch.c +++ b/src/video/x11/SDL_x11touch.c @@ -28,97 +28,12 @@ #include "../../events/SDL_touch_c.h" -#ifdef SDL_INPUT_LINUXEV -#include -#include -#endif - void X11_InitTouch(_THIS) { - /*Initilized Xinput2 multitouch - * and return in order to not initialize - * evtouch also*/ - if(X11_Xinput2IsMultitouchSupported()) { + if (X11_Xinput2IsMultitouchSupported()) { X11_InitXinput2Multitouch(_this); - return; } -#ifdef SDL_INPUT_LINUXEV - FILE *fd; - fd = fopen("/proc/bus/input/devices","r"); - if (!fd) return; - - int i = 0; - int tsfd; - char line[256]; - char tstr[256]; - int vendor = -1,product = -1,event = -1; - while(!feof(fd)) { - if(fgets(line,256,fd) <=0) continue; - if(line[0] == '\n') { - if(vendor == 1386 || vendor==1) { - sprintf(tstr,"/dev/input/event%i",event); - - tsfd = open( tstr, O_RDONLY | O_NONBLOCK ); - if ( tsfd == -1 ) - continue; /* Maybe not enough permissions ? */ - - SDL_Touch touch; - touch.pressure_max = 0; - touch.pressure_min = 0; - touch.id = event; - - touch.driverdata = SDL_malloc(sizeof(EventTouchData)); - EventTouchData* data = (EventTouchData*)(touch.driverdata); - - data->x = -1; - data->y = -1; - data->pressure = -1; - data->finger = 0; - data->up = SDL_FALSE; - data->down = SDL_FALSE; - - data->eventStream = tsfd; - ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr); - - int abs[5]; - ioctl(data->eventStream,EVIOCGABS(0),abs); - touch.x_min = abs[1]; - touch.x_max = abs[2]; - touch.native_xres = touch.x_max - touch.x_min; - ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs); - touch.y_min = abs[1]; - touch.y_max = abs[2]; - touch.native_yres = touch.y_max - touch.y_min; - ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs); - touch.pressure_min = abs[1]; - touch.pressure_max = abs[2]; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - SDL_AddTouch(&touch, tstr); - } - vendor = -1; - product = -1; - event = -1; - } - else if(line[0] == 'I') { - i = 1; - while(line[i]) { - sscanf(&line[i],"Vendor=%x",&vendor); - sscanf(&line[i],"Product=%x",&product); - i++; - } - } - else if(line[0] == 'H') { - i = 1; - while(line[i]) { - sscanf(&line[i],"event%d",&event); - i++; - } - } - } - fclose(fd); -#endif } void diff --git a/src/video/x11/SDL_x11touch.h b/src/video/x11/SDL_x11touch.h index 350ac669f..ac451a857 100644 --- a/src/video/x11/SDL_x11touch.h +++ b/src/video/x11/SDL_x11touch.h @@ -23,16 +23,6 @@ #ifndef _SDL_x11touch_h #define _SDL_x11touch_h -#ifdef SDL_INPUT_LINUXEV -typedef struct EventTouchData -{ - int x,y,pressure,finger; /* Temporary Variables until sync */ - int eventStream; - SDL_bool up; - SDL_bool down; -} EventTouchData; -#endif - extern void X11_InitTouch(_THIS); extern void X11_QuitTouch(_THIS); diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index 16fd252c5..2bd466a54 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -121,8 +121,6 @@ X11_InitXinput2(_THIS) #endif } - - int X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie) { @@ -149,25 +147,22 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie) #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH case XI_TouchBegin: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; - SDL_SendFingerDown(xev->sourceid,xev->detail, - SDL_TRUE, (int)xev->event_x, (int)xev->event_y, - 1.0); + SDL_SendTouch(xev->sourceid,xev->detail, + SDL_TRUE, xev->event_x, xev->event_y, 1.0); return 1; } break; case XI_TouchEnd: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; - SDL_SendFingerDown(xev->sourceid,xev->detail, - SDL_FALSE, (int)xev->event_x, (int)xev->event_y, - 1.0); + SDL_SendTouch(xev->sourceid,xev->detail, + SDL_FALSE, xev->event_x, xev->event_y, 1.0); return 1; } break; case XI_TouchUpdate: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; SDL_SendTouchMotion(xev->sourceid,xev->detail, - SDL_FALSE, (int)xev->event_x, (int)xev->event_y, - 1.0); + xev->event_x, xev->event_y, 1.0); return 1; } break; @@ -198,22 +193,8 @@ X11_InitXinput2Multitouch(_THIS) continue; touchId = t->sourceid; - /*Add the touch*/ if (!SDL_GetTouch(touchId)) { - SDL_Touch touch; - - touch.id = touchId; - touch.x_min = 0; - touch.x_max = 1; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0; - touch.y_max = 1; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0; - touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - SDL_AddTouch(&touch,dev->name); + SDL_AddTouch(touchId, dev->name); } } } diff --git a/test/testgesture.c b/test/testgesture.c index 04c0e176b..53e7e8a55 100644 --- a/test/testgesture.c +++ b/test/testgesture.c @@ -167,11 +167,8 @@ void DrawScreen(SDL_Surface* screen) if(event->type == SDL_FINGERMOTION || event->type == SDL_FINGERDOWN || event->type == SDL_FINGERUP) { - SDL_Touch* inTouch = SDL_GetTouch(event->tfinger.touchId); - if(inTouch == NULL) continue; - - x = ((float)event->tfinger.x)/inTouch->xres; - y = ((float)event->tfinger.y)/inTouch->yres; + x = event->tfinger.x; + y = event->tfinger.y; //draw the touch: c = colors[event->tfinger.fingerId%7]; @@ -269,10 +266,6 @@ int main(int argc, char* argv[]) SDL_Log("Finger: %i,x: %i, y: %i",event.tfinger.fingerId, event.tfinger.x,event.tfinger.y); #endif - { - SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); - SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); - } break; case SDL_FINGERDOWN: #if VERBOSE From 7da56d26ddf0a2cff91ae1e057187a22ab32f51a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Mar 2013 08:32:08 -0800 Subject: [PATCH 040/151] Compile SDL on older versions of Xcode --- src/video/cocoa/SDL_cocoaopengl.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 20cc35b19..7fa382a28 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -35,9 +35,13 @@ #define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib" -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 +#ifndef kCGLPFAOpenGLProfile #define kCGLPFAOpenGLProfile 99 +#endif +#ifndef kCGLOGLPVersion_Legacy #define kCGLOGLPVersion_Legacy 0x1000 +#endif +#ifndef kCGLOGLPVersion_3_2_Core #define kCGLOGLPVersion_3_2_Core 0x3200 #endif From 05a3ae94ae8292d9c5e4f603ccdc0e5816c2104e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Mar 2013 08:41:50 -0800 Subject: [PATCH 041/151] Fix compiler warning in Cocoa touch code --- src/video/cocoa/SDL_cocoawindow.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index f7f68828c..63894ee11 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -408,14 +408,14 @@ static __inline__ void ConvertNSRect(NSRect *r) enumerator = [touches objectEnumerator]; touch = (NSTouch*)[enumerator nextObject]; while (touch) { - const SDL_TouchID touchId = (SDL_TouchID)[touch device]; + const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device]; if (!SDL_GetTouch(touchId)) { if (SDL_AddTouch(touchId, "") < 0) { return; } } - const SDL_FingerID fingerId = (SDL_FingerID)[touch identity]; + const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity]; float x = [touch normalizedPosition].x; float y = [touch normalizedPosition].y; /* Make the origin the upper left instead of the lower left */ From 7999859dda6bcb60bfd5880326a686b561c08934 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Mar 2013 11:25:09 -0800 Subject: [PATCH 042/151] Fixed formatting --- src/render/opengles/SDL_render_gles.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c index 700067563..17b7ee250 100644 --- a/src/render/opengles/SDL_render_gles.c +++ b/src/render/opengles/SDL_render_gles.c @@ -804,7 +804,6 @@ static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect) { - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; GLfloat minx, miny, maxx, maxy; @@ -1091,7 +1090,8 @@ GLES_DestroyRenderer(SDL_Renderer * renderer) SDL_free(renderer); } -static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) { +static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) +{ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; GLES_ActivateRenderer(renderer); @@ -1105,7 +1105,8 @@ static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, floa return 0; } -static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) { +static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) +{ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; GLES_ActivateRenderer(renderer); @@ -1114,7 +1115,6 @@ static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) { return 0; } - #endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */ From 4bb1b24573965ed7a8f395e137336d5383c40890 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Mar 2013 11:25:43 -0800 Subject: [PATCH 043/151] Don't specify the texture unit when binding a texture, instead use whatever has been set up by the application. This matches behavior in the OpenGL and OpenGL ES 1.1 renderers. --- src/render/opengles2/SDL_render_gles2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 51e3e37e5..14ee2a3c8 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -1580,7 +1580,6 @@ static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, flo GLES2_TextureData *texturedata = (GLES2_TextureData *)texture->driverdata; GLES2_ActivateRenderer(renderer); - data->glActiveTexture(GL_TEXTURE0); data->glBindTexture(texturedata->texture_type, texturedata->texture); if(texw) *texw = 1.0; From f7b0b73b6431b33e5ae65410eb425b313ffd3455 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Sun, 3 Mar 2013 17:22:51 -0800 Subject: [PATCH 044/151] Fix behavior of SDL_GetWindowPosition for invalid input; add test cases to video suite --- src/video/SDL_video.c | 14 +- test/testautomation_video.c | 453 +++++++++++++++++++++++++++++++++--- 2 files changed, 428 insertions(+), 39 deletions(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 9538ec5ee..8ea6e4243 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1524,18 +1524,16 @@ SDL_SetWindowPosition(SDL_Window * window, int x, int y) void SDL_GetWindowPosition(SDL_Window * window, int *x, int *y) { - /* Clear the values */ - if (x) { - *x = 0; - } - if (y) { - *y = 0; - } - CHECK_WINDOW_MAGIC(window, ); /* Fullscreen windows are always at their display's origin */ if (window->flags & SDL_WINDOW_FULLSCREEN) { + if (x) { + *x = 0; + } + if (y) { + *y = 0; + } } else { if (x) { *x = window->x; diff --git a/test/testautomation_video.c b/test/testautomation_video.c index a38f0fd8b..e9a632481 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -4,6 +4,16 @@ #include +/* Visual Studio 2008 doesn't have stdint.h */ +#if defined(_MSC_VER) && _MSC_VER <= 1500 +#define UINT8_MAX ~(Uint8)0 +#define UINT16_MAX ~(Uint16)0 +#define UINT32_MAX ~(Uint32)0 +#define UINT64_MAX ~(Uint64)0 +#else +#include +#endif + #include "SDL.h" #include "SDL_test.h" @@ -656,43 +666,43 @@ video_getWindowGammaRamp(void *arg) /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window != NULL) { - /* Retrieve no channel */ - result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL); - SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + if (window == NULL) return TEST_ABORTED; + + /* Retrieve no channel */ + result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); - /* Retrieve single channel */ - result = SDL_GetWindowGammaRamp(window, red, NULL, NULL); - SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + /* Retrieve single channel */ + result = SDL_GetWindowGammaRamp(window, red, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); - result = SDL_GetWindowGammaRamp(window, NULL, green, NULL); - SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + result = SDL_GetWindowGammaRamp(window, NULL, green, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); - result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue); - SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); - /* Retrieve two channels */ - result = SDL_GetWindowGammaRamp(window, red, green, NULL); - SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + /* Retrieve two channels */ + result = SDL_GetWindowGammaRamp(window, red, green, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); - result = SDL_GetWindowGammaRamp(window, NULL, green, blue); - SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + result = SDL_GetWindowGammaRamp(window, NULL, green, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); - result = SDL_GetWindowGammaRamp(window, red, NULL, blue); - SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + result = SDL_GetWindowGammaRamp(window, red, NULL, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); - /* Retrieve all channels */ - result = SDL_GetWindowGammaRamp(window, red, green, blue); - SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); - } + /* Retrieve all channels */ + result = SDL_GetWindowGammaRamp(window, red, green, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); /* Clean up */ _destroyVideoSuiteTestWindow(window); @@ -733,6 +743,374 @@ video_getWindowGammaRampNegative(void *arg) return TEST_COMPLETED; } +/* Helper for setting and checking the window grab state */ +void +_setAndCheckWindowGrabState(SDL_Window* window, SDL_bool desiredState) +{ + SDL_bool currentState; + + /* Set state */ + SDL_SetWindowGrab(window, desiredState); + SDLTest_AssertPass("Call to SDL_SetWindowGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); + + /* Get and check state */ + currentState = SDL_GetWindowGrab(window); + SDLTest_AssertPass("Call to SDL_GetWindowGrab()"); + SDLTest_AssertCheck( + currentState == desiredState, + "Validate returned state; expected: %s, got: %s", + (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE", + (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); +} + +/** + * @brief Tests call to SDL_GetWindowGrab and SDL_SetWindowGrab + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGrab + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowGrab + */ +int +video_getSetWindowGrab(void *arg) +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + const char* title = "video_getSetWindowGrab Test Window"; + SDL_Window* window; + SDL_bool originalState, dummyState, currentState, desiredState; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Get state */ + originalState = SDL_GetWindowGrab(window); + SDLTest_AssertPass("Call to SDL_GetWindowGrab()"); + + /* F */ + _setAndCheckWindowGrabState(window, SDL_FALSE); + + /* F --> F */ + _setAndCheckWindowGrabState(window, SDL_FALSE); + + /* F --> T */ + _setAndCheckWindowGrabState(window, SDL_TRUE); + + /* T --> T */ + _setAndCheckWindowGrabState(window, SDL_TRUE); + + /* T --> F */ + _setAndCheckWindowGrabState(window, SDL_FALSE); + + /* Negative tests */ + dummyState = SDL_GetWindowGrab(NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)"); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + SDL_SetWindowGrab(NULL, SDL_FALSE); + SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)"); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + SDL_SetWindowGrab(NULL, SDL_TRUE); + SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)"); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + /* State should still be F */ + desiredState = SDL_FALSE; + currentState = SDL_GetWindowGrab(window); + SDLTest_AssertPass("Call to SDL_GetWindowGrab()"); + SDLTest_AssertCheck( + currentState == desiredState, + "Validate returned state; expected: %s, got: %s", + (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE", + (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); + + /* Restore state */ + _setAndCheckWindowGrabState(window, originalState); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowID + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowFromID + */ +int +video_getWindowId(void *arg) +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + const char* title = "video_getWindowId Test Window"; + SDL_Window* window; + SDL_Window* result; + Uint32 id, randomId; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Get ID */ + id = SDL_GetWindowID(window); + SDLTest_AssertPass("Call to SDL_GetWindowID()"); + + /* Get window from ID */ + result = SDL_GetWindowFromID(id); + SDLTest_AssertPass("Call to SDL_GetWindowID(%d)", id); + SDLTest_AssertCheck(result == window, "Verify result matches window pointer"); + + /* Get window from random large ID, no result check */ + randomId = SDLTest_RandomIntegerInRange(UINT8_MAX,UINT16_MAX); + result = SDL_GetWindowFromID(randomId); + SDLTest_AssertPass("Call to SDL_GetWindowID(%d/random_large)", randomId); + + /* Get window from 0 and Uint32 max ID, no result check */ + result = SDL_GetWindowFromID(0); + SDLTest_AssertPass("Call to SDL_GetWindowID(0)"); + result = SDL_GetWindowFromID(UINT32_MAX); + SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)"); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Get window from ID for closed window*/ + result = SDL_GetWindowFromID(id); + SDLTest_AssertPass("Call to SDL_GetWindowID(%d/closed_window)", id); + SDLTest_AssertCheck(result == NULL, "Verify result is NULL"); + + /* Negative test */ + id = SDL_GetWindowID(NULL); + SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)"); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowPixelFormat + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPixelFormat + */ +int +video_getWindowPixelFormat(void *arg) +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + const char* title = "video_getWindowPixelFormat Test Window"; + SDL_Window* window; + Uint32 format; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Get format */ + format = SDL_GetWindowPixelFormat(window); + SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()"); + SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %d", SDL_PIXELFORMAT_UNKNOWN, format); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Negative test */ + format = SDL_GetWindowPixelFormat(NULL); + SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)"); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPosition + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowPosition + */ +int +video_getSetWindowPosition(void *arg) +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + const char* title = "video_getSetWindowPosition Test Window"; + SDL_Window* window; + int xVariation, yVariation; + int referenceX, referenceY; + int currentX, currentY; + int desiredX, desiredY; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + for (xVariation = 0; xVariation < 4; xVariation++) { + for (yVariation = 0; yVariation < 4; yVariation++) { + switch(xVariation) { + case 0: + /* Zero X Position */ + desiredX = 0; + break; + case 1: + /* Random X position inside screen */ + desiredX = SDLTest_RandomIntegerInRange(1, 100); + break; + case 2: + /* Random X position outside screen (positive) */ + desiredX = SDLTest_RandomIntegerInRange(10000, 11000); + break; + case 3: + /* Random X position outside screen (negative) */ + desiredX = SDLTest_RandomIntegerInRange(-1000, -100); + break; + } + + switch(yVariation) { + case 0: + /* Zero X Position */ + desiredY = 0; + break; + case 1: + /* Random X position inside screen */ + desiredY = SDLTest_RandomIntegerInRange(1, 100); + break; + case 2: + /* Random X position outside screen (positive) */ + desiredY = SDLTest_RandomIntegerInRange(10000, 11000); + break; + case 3: + /* Random Y position outside screen (negative) */ + desiredY = SDLTest_RandomIntegerInRange(-1000, -100); + break; + } + + /* Set position */ + SDL_SetWindowPosition(window, desiredX, desiredY); + SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY); + + /* Get position */ + currentX = desiredX + 1; + currentY = desiredY + 1; + SDL_GetWindowPosition(window, ¤tX, ¤tY); + SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); + SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX); + SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY); + + /* Get position X */ + currentX = desiredX + 1; + SDL_GetWindowPosition(window, ¤tX, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)"); + SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX); + + /* Get position Y */ + currentY = desiredY + 1; + SDL_GetWindowPosition(window, NULL, ¤tY); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)"); + SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY); + } + } + + /* Dummy call with both pointers NULL */ + SDL_GetWindowPosition(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)"); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Set some 'magic' value for later check that nothing was changed */ + referenceX = SDLTest_RandomSint32(); + referenceY = SDLTest_RandomSint32(); + currentX = referenceX; + currentY = referenceY; + desiredX = SDLTest_RandomSint32(); + desiredY = SDLTest_RandomSint32(); + + /* Negative tests */ + SDL_GetWindowPosition(NULL, ¤tX, ¤tY); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)"); + SDLTest_AssertCheck( + currentX == referenceX && currentY == referenceY, + "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d", + referenceX, referenceY, + currentX, currentY); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + SDL_GetWindowPosition(NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)"); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + SDL_SetWindowPosition(NULL, desiredX, desiredY); + SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)"); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + return TEST_COMPLETED; +} + /* ================= Test References ================== */ /* Video test cases */ @@ -781,11 +1159,24 @@ static const SDLTest_TestCaseReference videoTest14 = static const SDLTest_TestCaseReference videoTest15 = { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED }; +static const SDLTest_TestCaseReference videoTest16 = + { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest17 = + { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest18 = + { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest19 = + { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition", TEST_ENABLED }; + /* Sequence of Video test cases */ static const SDLTest_TestCaseReference *videoTests[] = { &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, - &videoTest13, &videoTest14, &videoTest15, NULL + &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17, + &videoTest18, &videoTest19, NULL }; /* Video test suite (global) */ From 6a40ac979addcf0dde370538d681d18e99a39165 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Mar 2013 21:52:51 -0800 Subject: [PATCH 045/151] Fixed bug 1740 - Android pixel format constants out of sync wjp In SDL HG (2.0) the pixel format constants in android-project/src/org/libsdl/app/SDLActivity.java seem to have gone out of sync with include/SDL_pixels.h in HG rev b1124b32b07d. E.g., at a glance it seems like 0x85151002 should have become 0x15151002. --- .../src/org/libsdl/app/SDLActivity.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index 1c77e730f..e0a850f42 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -509,7 +509,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, int format, int width, int height) { Log.v("SDL", "surfaceChanged()"); - int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default + int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default switch (format) { case PixelFormat.A_8: Log.v("SDL", "pixel format A_8"); @@ -522,32 +522,32 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, break; case PixelFormat.RGBA_4444: Log.v("SDL", "pixel format RGBA_4444"); - sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444 + sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444 break; case PixelFormat.RGBA_5551: Log.v("SDL", "pixel format RGBA_5551"); - sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551 + sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551 break; case PixelFormat.RGBA_8888: Log.v("SDL", "pixel format RGBA_8888"); - sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888 + sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888 break; case PixelFormat.RGBX_8888: Log.v("SDL", "pixel format RGBX_8888"); - sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888 + sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888 break; case PixelFormat.RGB_332: Log.v("SDL", "pixel format RGB_332"); - sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332 + sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332 break; case PixelFormat.RGB_565: Log.v("SDL", "pixel format RGB_565"); - sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 + sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 break; case PixelFormat.RGB_888: Log.v("SDL", "pixel format RGB_888"); // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? - sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888 + sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888 break; default: Log.v("SDL", "pixel format unknown " + format); From f8e304b6ed79d9fce11ac4532068b30a38074e3f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Mar 2013 22:06:27 -0800 Subject: [PATCH 046/151] Added new tests to the .hgignore file --- .hgignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.hgignore b/.hgignore index 6a4fe2bd7..c74c5047f 100644 --- a/.hgignore +++ b/.hgignore @@ -53,9 +53,11 @@ test/checkkeys test/loopwave test/testatomic test/testaudioinfo +test/testautomation test/testdraw2 test/testerror test/testfile +test/testgamecontroller test/testgesture test/testgl2 test/testgles From 2c077061e0ad624f3aa54432474c100989e96ffb Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Mar 2013 22:08:00 -0800 Subject: [PATCH 047/151] Fied bug 1719 - Remove unnecessary PrecompiledHeaderOutputFile. Hiroyuki Iwatsuki Patch for removing unnecessary PrecompiledHeaderOutputFile. --- VisualC/SDLmain/SDLmain_VS2012.vcxproj | 1 - VisualC/SDLtest/SDLtest_VS2012.vcxproj | 1 - VisualC/tests/testplatform/testplatform_VS2012.vcxproj | 1 - VisualC/tests/testpower/testpower_VS2012.vcxproj | 5 +---- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/VisualC/SDLmain/SDLmain_VS2012.vcxproj b/VisualC/SDLmain/SDLmain_VS2012.vcxproj index 5a86801c0..d95409bca 100644 --- a/VisualC/SDLmain/SDLmain_VS2012.vcxproj +++ b/VisualC/SDLmain/SDLmain_VS2012.vcxproj @@ -144,7 +144,6 @@ MultiThreadedDebugDLL - .\Debug/SDLmain.pch Level3 true OldStyle diff --git a/VisualC/SDLtest/SDLtest_VS2012.vcxproj b/VisualC/SDLtest/SDLtest_VS2012.vcxproj index 2e306c095..762f2b5fe 100644 --- a/VisualC/SDLtest/SDLtest_VS2012.vcxproj +++ b/VisualC/SDLtest/SDLtest_VS2012.vcxproj @@ -144,7 +144,6 @@ MultiThreadedDebugDLL - .\Debug/SDLtest.pch Level3 true OldStyle diff --git a/VisualC/tests/testplatform/testplatform_VS2012.vcxproj b/VisualC/tests/testplatform/testplatform_VS2012.vcxproj index ce8ef3d53..d4f0475e9 100644 --- a/VisualC/tests/testplatform/testplatform_VS2012.vcxproj +++ b/VisualC/tests/testplatform/testplatform_VS2012.vcxproj @@ -168,7 +168,6 @@ true MultiThreadedDLL true - .\Release/testplatform.pch $(IntDir) $(IntDir) $(IntDir)vc$(PlatformToolsetVersion).pdb diff --git a/VisualC/tests/testpower/testpower_VS2012.vcxproj b/VisualC/tests/testpower/testpower_VS2012.vcxproj index 3cf7d6435..3983a7bbb 100644 --- a/VisualC/tests/testpower/testpower_VS2012.vcxproj +++ b/VisualC/tests/testpower/testpower_VS2012.vcxproj @@ -223,10 +223,7 @@ - - .\Debug/testpower.pch - .\Debug/testpower.pch - + From 967e7efcc0d13cc1fa46742ba94ba7700dec7ec1 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Mon, 4 Mar 2013 10:33:48 -0300 Subject: [PATCH 048/151] Adds some required CFLAGS and LDFLAGS for the iOS platform --- configure | 9 +++++++++ configure.in | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/configure b/configure index 0ee54ca28..77df3dac4 100755 --- a/configure +++ b/configure @@ -22324,6 +22324,15 @@ $as_echo "#define SDL_POWER_BEOS 1" >>confdefs.h # The iOS platform requires special setup. SOURCES="$SOURCES $srcdir/src/video/uikit/*.m" SOURCES="$SOURCES $srcdir/src/video/uikit/*.c" + EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -liconv -lobjc" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Foundation" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,UIKit" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGLES" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuartzCore" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreAudio" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AudioToolbox" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreGraphics" ;; *-*-darwin* ) # This could be either full "Mac OS X", or plain "Darwin" which is diff --git a/configure.in b/configure.in index f2f6b6468..6f0a900d5 100644 --- a/configure.in +++ b/configure.in @@ -2510,6 +2510,15 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau # The iOS platform requires special setup. SOURCES="$SOURCES $srcdir/src/video/uikit/*.m" SOURCES="$SOURCES $srcdir/src/video/uikit/*.c" + EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -liconv -lobjc" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Foundation" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,UIKit" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGLES" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuartzCore" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreAudio" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AudioToolbox" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreGraphics" ;; *-*-darwin* ) # This could be either full "Mac OS X", or plain "Darwin" which is From 24df19a3d3914006987f5726c6506412ebd0a445 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Mon, 4 Mar 2013 10:39:21 -0300 Subject: [PATCH 049/151] Fixes AndroidManifest comment, Android API level 10 = Android 2.3.3 --- android-project/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-project/AndroidManifest.xml b/android-project/AndroidManifest.xml index c88b3fac3..7e6c43c34 100644 --- a/android-project/AndroidManifest.xml +++ b/android-project/AndroidManifest.xml @@ -29,7 +29,7 @@ - + From 0d5cf5e924d922e06ce33d10fc949ebcd491ba6d Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Mon, 4 Mar 2013 11:35:03 -0300 Subject: [PATCH 050/151] Updated the README.android file stating the required API level and reasons why. --- README.android | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.android b/README.android index 77b443bf4..ad1d7ef35 100644 --- a/README.android +++ b/README.android @@ -4,12 +4,13 @@ Simple DirectMedia Layer for Android Requirements: -Android SDK +Android SDK (version 10 or later) http://developer.android.com/sdk/index.html Android NDK r4 or later http://developer.android.com/sdk/ndk/index.html +Minimum API Level supported by SDL: 10 (Android 2.3.3) ================================================================================ How the port works @@ -342,6 +343,15 @@ output file: When you're done instrumenting with valgrind, you can disable the wrapper: adb shell setprop wrap.org.libsdl.app "" +================================================================================ + Why is API level 10 the minimum required? +================================================================================ + +Support for OpenGL ES/ES2 applications was introduced in the NDK for API level 9, +which has since then been obsoleted, and the recommendation to developers was to +bump the required level to 10. +As of this writing, according to http://developer.android.com/about/dashboards/index.html +about 90% of the existing Android devices support an API level 10 or higher. ================================================================================ Known issues From 979239e130c5beba1b3d439d79c0ecbe87db8bea Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 4 Mar 2013 20:27:51 -0800 Subject: [PATCH 051/151] Fixed bug 1553 - Fix USB joystick input for FreeBSD 9.0+ Marcus von Appen Receiving input from USB joysticks on FreeBSD 9.0 or newer is broken at the moment. The attached patch fixes this. --- src/joystick/bsd/SDL_sysjoystick.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c index f29d94dd2..ff1588764 100644 --- a/src/joystick/bsd/SDL_sysjoystick.c +++ b/src/joystick/bsd/SDL_sysjoystick.c @@ -83,7 +83,9 @@ struct report { -#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063) +#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000) + void *buf; /* Buffer */ +#elif defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063) struct usb_gen_descriptor *buf; /* Buffer */ #else struct usb_ctl_report *buf; /* Buffer */ @@ -149,8 +151,10 @@ static char *joydevnames[MAX_JOYS]; static int report_alloc(struct report *, struct report_desc *, int); static void report_free(struct report *); -#if defined(USBHID_UCR_DATA) +#if defined(USBHID_UCR_DATA) || (defined(__FreeBSD_kernel__) && __FreeBSD_kernel_version <= 800063) #define REP_BUF_DATA(rep) ((rep)->buf->ucr_data) +#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000)) +#define REP_BUF_DATA(rep) ((rep)->buf) #elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063)) #define REP_BUF_DATA(rep) ((rep)->buf->ugd_data) #else @@ -636,8 +640,12 @@ report_alloc(struct report *r, struct report_desc *rd, int repind) r->size = len; if (r->size > 0) { +#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000) + r->buf = SDL_malloc(r->size); +#else r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + r->size); +#endif if (r->buf == NULL) { SDL_OutOfMemory(); return (-1); From 5fd98b32979fc2e79286bf378bd3cfb903fb0f42 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Tue, 5 Mar 2013 17:59:36 -0500 Subject: [PATCH 052/151] add new gamecontroller APIs - add mappings after init (or even before w/o using the hint) - get string for axis - get string for button - get mapping string for controller or for GUID - new event to notify when a controller is remapped. (e.g. mapping was changed via the AddMapping method) --- include/SDL_events.h | 7 +- include/SDL_gamecontroller.h | 31 ++- src/joystick/SDL_gamecontroller.c | 341 +++++++++++++++++++----------- 3 files changed, 247 insertions(+), 132 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index 762aba442..49bdb9677 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -100,6 +100,7 @@ typedef enum SDL_CONTROLLERBUTTONUP, /**< Game controller button released */ SDL_CONTROLLERDEVICEADDED, /**< A new Game controller has been inserted into the system */ SDL_CONTROLLERDEVICEREMOVED, /**< An opened Game controller has been removed */ + SDL_CONTROLLERDEVICEREMAPPED, /**< The controller mapping was updated */ /* Touch events */ SDL_FINGERDOWN = 0x700, @@ -358,9 +359,9 @@ typedef struct SDL_ControllerButtonEvent */ typedef struct SDL_ControllerDeviceEvent { - Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED or ::SDL_CONTROLLERDEVICEREMOVED */ + Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */ Uint32 timestamp; - Uint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */ + Uint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */ } SDL_ControllerDeviceEvent; @@ -484,7 +485,7 @@ typedef union SDL_Event SDL_JoyHatEvent jhat; /**< Joystick hat event data */ SDL_JoyButtonEvent jbutton; /**< Joystick button event data */ SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */ - SDL_ControllerAxisEvent caxis; /**< Game Controller button event data */ + SDL_ControllerAxisEvent caxis; /**< Game Controller axis event data */ SDL_ControllerButtonEvent cbutton; /**< Game Controller button event data */ SDL_ControllerDeviceEvent cdevice; /**< Game Controller device event data */ SDL_QuitEvent quit; /**< Quit request event data */ diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h index b379d7eec..318e51aa1 100644 --- a/include/SDL_gamecontroller.h +++ b/include/SDL_gamecontroller.h @@ -90,7 +90,7 @@ typedef struct SDL_GameControllerButtonBind * } * } * - * Using the SDL_HINT_GAMECONTROLLERCONFIG hint you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is: + * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is: * guid,name,mappings * * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones. @@ -106,6 +106,26 @@ typedef struct SDL_GameControllerButtonBind * */ +/** + * Add or update an existing mapping configuration + * + * \return 1 if mapping is added, 0 if updated, -1 on error + */ +extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping( const char* mappingSring ); + +/** + * Get a mapping string for a GUID + * + * \return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available + */ +extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid ); + +/** + * Get a mapping string for an open GameController + * + * \return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available + */ +extern DECLSPEC char * SDLCALL SDL_GameControllerMapping( SDL_GameController * gamecontroller ); /** * Is the joystick on this index supported by the game controller interface? @@ -186,6 +206,11 @@ typedef enum */ extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString); +/** + * turn this axis enum into a string mapping + */ +extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis); + /** * Get the SDL joystick layer binding for this controller button mapping */ @@ -233,6 +258,10 @@ typedef enum */ extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString); +/** + * turn this button enum into a string mapping + */ +extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button); /** * Get the SDL joystick layer binding for this controller button mapping diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 34c239a0e..d312b854f 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -45,8 +45,10 @@ struct _SDL_HatMapping #define k_nMaxReverseEntries 20 -// We are encoding the "HAT" as 0xhm. where h == hat ID and m == mask -// MAX 4 hats supported +/** + * We are encoding the "HAT" as 0xhm. where h == hat ID and m == mask + * MAX 4 hats supported + */ #define k_nMaxHatEntries 0x3f + 1 /* our in memory mapping db between joystick objects and controller mappings*/ @@ -79,7 +81,7 @@ typedef struct _ControllerMapping_t { SDL_JoystickGUID guid; char *name; - const char *mapping; + char *mapping; struct _ControllerMapping_t *next; } ControllerMapping_t; @@ -261,15 +263,28 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) return 1; } +/* + * Helper function to scan the mappings database for a controller with the specified GUID + */ +ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid) +{ + ControllerMapping_t *pSupportedController = s_pSupportedControllers; + while ( pSupportedController ) + { + if ( !SDL_memcmp( guid, &pSupportedController->guid, sizeof(*guid) ) ) + { + return pSupportedController; + } + pSupportedController = pSupportedController->next; + } + return NULL; + } + /* * Helper function to determine pre-caclulated offset to certain joystick mappings */ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) { - if ( (device_index < 0) || (device_index >= SDL_NumJoysticks()) ) { - return NULL; - } - #ifdef SDL_JOYSTICK_DINPUT if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping ) { @@ -279,87 +294,98 @@ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) #endif { SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); - ControllerMapping_t *pSupportedController = s_pSupportedControllers; - while ( pSupportedController ) - { - if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) ) - { - return pSupportedController; - } - pSupportedController = pSupportedController->next; - } + return SDL_PrivateGetControllerMappingForGUID(&jGUID); } return NULL; } +static const char* map_StringForControllerAxis[] = { + "leftx", + "lefty", + "rightx", + "righty", + "lefttrigger", + "righttrigger", + NULL +}; + /* * convert a string to its enum equivalent */ SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchString ) { + int entry; if ( !pchString || !pchString[0] ) return SDL_CONTROLLER_AXIS_INVALID; - if ( !SDL_strcasecmp( pchString, "leftx" ) ) - return SDL_CONTROLLER_AXIS_LEFTX; - else if ( !SDL_strcasecmp( pchString, "lefty" ) ) - return SDL_CONTROLLER_AXIS_LEFTY; - else if ( !SDL_strcasecmp( pchString, "rightx" ) ) - return SDL_CONTROLLER_AXIS_RIGHTX; - else if ( !SDL_strcasecmp( pchString, "righty" ) ) - return SDL_CONTROLLER_AXIS_RIGHTY; - else if ( !SDL_strcasecmp( pchString, "lefttrigger" ) ) - return SDL_CONTROLLER_AXIS_TRIGGERLEFT; - else if ( !SDL_strcasecmp( pchString, "righttrigger" ) ) - return SDL_CONTROLLER_AXIS_TRIGGERRIGHT; - else + for ( entry = 0; map_StringForControllerAxis[entry]; ++entry) + { + if ( !SDL_strcasecmp( pchString, map_StringForControllerAxis[entry] ) ) + return entry; + } return SDL_CONTROLLER_AXIS_INVALID; } +/* + * convert an enum to its string equivalent + */ +const char* SDL_GameControllerGetStringForAxis( SDL_GameControllerAxis axis ) +{ + if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX) + { + return map_StringForControllerAxis[axis]; + } + return NULL; +} + +static const char* map_StringForControllerButton[] = { + "a", + "b", + "x", + "y", + "back", + "guide", + "start", + "leftstick", + "rightstick", + "leftshoulder", + "rightshoulder", + "dpup", + "dpdown", + "dpleft", + "dpright", + NULL +}; /* * convert a string to its enum equivalent */ SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchString ) { + int entry; if ( !pchString || !pchString[0] ) return SDL_CONTROLLER_BUTTON_INVALID; - if ( !SDL_strcasecmp( pchString, "a" ) ) - return SDL_CONTROLLER_BUTTON_A; - else if ( !SDL_strcasecmp( pchString, "b" ) ) - return SDL_CONTROLLER_BUTTON_B; - else if ( !SDL_strcasecmp( pchString, "x" ) ) - return SDL_CONTROLLER_BUTTON_X; - else if ( !SDL_strcasecmp( pchString, "y" ) ) - return SDL_CONTROLLER_BUTTON_Y; - else if ( !SDL_strcasecmp( pchString, "start" ) ) - return SDL_CONTROLLER_BUTTON_START; - else if ( !SDL_strcasecmp( pchString, "guide" ) ) - return SDL_CONTROLLER_BUTTON_GUIDE; - else if ( !SDL_strcasecmp( pchString, "back" ) ) - return SDL_CONTROLLER_BUTTON_BACK; - else if ( !SDL_strcasecmp( pchString, "dpup" ) ) - return SDL_CONTROLLER_BUTTON_DPAD_UP; - else if ( !SDL_strcasecmp( pchString, "dpdown" ) ) - return SDL_CONTROLLER_BUTTON_DPAD_DOWN; - else if ( !SDL_strcasecmp( pchString, "dpleft" ) ) - return SDL_CONTROLLER_BUTTON_DPAD_LEFT; - else if ( !SDL_strcasecmp( pchString, "dpright" ) ) - return SDL_CONTROLLER_BUTTON_DPAD_RIGHT; - else if ( !SDL_strcasecmp( pchString, "leftshoulder" ) ) - return SDL_CONTROLLER_BUTTON_LEFTSHOULDER; - else if ( !SDL_strcasecmp( pchString, "rightshoulder" ) ) - return SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; - else if ( !SDL_strcasecmp( pchString, "leftstick" ) ) - return SDL_CONTROLLER_BUTTON_LEFTSTICK; - else if ( !SDL_strcasecmp( pchString, "rightstick" ) ) - return SDL_CONTROLLER_BUTTON_RIGHTSTICK; - else - return SDL_CONTROLLER_BUTTON_INVALID; + for ( entry = 0; map_StringForControllerButton[entry]; ++entry) + { + if ( !SDL_strcasecmp( pchString, map_StringForControllerButton[entry] ) ) + return entry; + } + return SDL_CONTROLLER_BUTTON_INVALID; } +/* + * convert an enum to its string equivalent + */ +const char* SDL_GameControllerGetStringForButton( SDL_GameControllerButton axis ) +{ + if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) + { + return map_StringForControllerButton[axis]; + } + return NULL; +} /* * given a controller button name and a joystick name update our mapping structure with it @@ -602,7 +628,7 @@ char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping ) /* * grab the button mapping string from a mapping string */ -const char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping ) +char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping ) { const char *pFirstComma, *pSecondComma; @@ -614,9 +640,126 @@ const char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMappi if ( !pSecondComma ) return NULL; - return pSecondComma + 1; /* mapping is everything after the 3rd comma, no need to malloc it */ + return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */ } +void SDL_PrivateGameControllerRefreshMapping( ControllerMapping_t *pControllerMapping ) +{ + SDL_GameController *gamecontrollerlist = SDL_gamecontrollers; + while ( gamecontrollerlist ) + { + if ( !SDL_memcmp( &gamecontrollerlist->mapping.guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid) ) ) + { + SDL_Event event; + event.type = SDL_CONTROLLERDEVICEREMAPPED; + event.cdevice.which = gamecontrollerlist->joystick->instance_id; + SDL_PushEvent(&event); + + // Not really threadsafe. Should this lock access within SDL_GameControllerEventWatcher? + SDL_PrivateLoadButtonMapping(&gamecontrollerlist->mapping, pControllerMapping->guid, pControllerMapping->name, pControllerMapping->mapping); + } + + gamecontrollerlist = gamecontrollerlist->next; + } +} + +/* + * Add or update an entry into the Mappings Database + */ +int +SDL_GameControllerAddMapping( const char *mappingString ) +{ + char *pchGUID; + char *pchName; + char *pchMapping; + SDL_JoystickGUID jGUID; + ControllerMapping_t *pControllerMapping; +#ifdef SDL_JOYSTICK_DINPUT + SDL_bool is_xinput_mapping = SDL_FALSE; +#endif + + pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString ); + if (!pchGUID) return -1; +#ifdef SDL_JOYSTICK_DINPUT + if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) { + is_xinput_mapping = SDL_TRUE; + } +#endif + SDL_free(pchGUID); + + jGUID = SDL_JoystickGetGUIDFromString(pchGUID); + + pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID); + + pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString ); + if (!pchName) return -1; + + pchMapping = SDL_PrivateGetControllerMappingFromMappingString( mappingString ); + if (!pchMapping) { + SDL_free( pchName ); + return -1; + } + + if (pControllerMapping) { + // Update existing mapping + SDL_free( pControllerMapping->name ); + pControllerMapping->name = pchName; + SDL_free( pControllerMapping->mapping ); + pControllerMapping->mapping = pchMapping; + // refresh open controllers + SDL_PrivateGameControllerRefreshMapping( pControllerMapping ); + return 0; + } else { + pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); + if (!pControllerMapping) { + SDL_OutOfMemory(); + SDL_free( pchName ); + SDL_free( pchMapping ); + return -1; + } +#ifdef SDL_JOYSTICK_DINPUT + if ( is_xinput_mapping ) + { + s_pXInputMapping = pControllerMapping; + } +#endif + pControllerMapping->guid = jGUID; + pControllerMapping->name = pchName; + pControllerMapping->mapping = pchMapping; + pControllerMapping->next = s_pSupportedControllers; + s_pSupportedControllers = pControllerMapping; + return 1; + } +} + +/* + * Get the mapping string for this GUID + */ +char * +SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid ) +{ + char *pMappingString = NULL; + ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid); + if (mapping) { + char pchGUID[33]; + size_t needed; + SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID)); + // allocate enough memory for GUID + ',' + name + ',' + mapping + \0 + needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; + pMappingString = SDL_malloc( needed ); + SDL_snprintf( pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping ); + } + return pMappingString; +} + +/* + * Get the mapping string for this device + */ +char * +SDL_GameControllerMapping( SDL_GameController * gamecontroller ) +{ + return SDL_GameControllerMappingForGUID( gamecontroller->mapping.guid ); +} /* * Initialize the game controller system, mostly load our DB of controller config mappings @@ -630,36 +773,7 @@ SDL_GameControllerInit(void) pMappingString = s_ControllerMappings[i]; while ( pMappingString ) { - ControllerMapping_t *pControllerMapping; - char *pchGUID; - char *pchName; - const char *pchMapping; - pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); - if ( !pControllerMapping ) - { - SDL_OutOfMemory(); - return -1; - } - - pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( pMappingString ); - pchName = SDL_PrivateGetControllerNameFromMappingString( pMappingString ); - pchMapping = SDL_PrivateGetControllerMappingFromMappingString( pMappingString ); - if ( pchGUID && pchName ) - { -#ifdef SDL_JOYSTICK_DINPUT - if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) - { - s_pXInputMapping = pControllerMapping; - } -#endif - pControllerMapping->guid = SDL_JoystickGetGUIDFromString( pchGUID ); - pControllerMapping->name = pchName; - pControllerMapping->mapping = pchMapping; - pControllerMapping->next = s_pSupportedControllers; - s_pSupportedControllers = pControllerMapping; - - SDL_free( pchGUID ); - } + SDL_GameControllerAddMapping( pMappingString ); i++; pMappingString = s_ControllerMappings[i]; @@ -671,54 +785,25 @@ SDL_GameControllerInit(void) if ( hint && hint[0] ) { int nchHints = SDL_strlen( hint ); - char *pUserMappings = SDL_malloc( nchHints + 1 ); /* FIXME: memory leak, but we can't free it in this function because pchMapping below points into this memory */ - SDL_memcpy( pUserMappings, hint, nchHints + 1 ); + char *pUserMappings = SDL_malloc( nchHints + 1 ); + char *pTempMappings = pUserMappings; + SDL_memcpy( pUserMappings, hint, nchHints ); while ( pUserMappings ) { - char *pchGUID; - char *pchName; - const char *pchMapping; char *pchNewLine = NULL; - ControllerMapping_t *pControllerMapping; pchNewLine = SDL_strchr( pUserMappings, '\n' ); if ( pchNewLine ) *pchNewLine = '\0'; - pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); - if ( !pControllerMapping ) - { - SDL_OutOfMemory(); - return -1; - } - - pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( pUserMappings ); - pchName = SDL_PrivateGetControllerNameFromMappingString( pUserMappings ); - pchMapping = SDL_PrivateGetControllerMappingFromMappingString( pUserMappings ); - - if ( pchGUID && pchName ) - { -#ifdef SDL_JOYSTICK_DINPUT - if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) - { - s_pXInputMapping = pControllerMapping; - } -#endif - - pControllerMapping->guid = SDL_JoystickGetGUIDFromString( pchGUID ); - pControllerMapping->name = pchName; - pControllerMapping->mapping = pchMapping; - pControllerMapping->next = s_pSupportedControllers; - s_pSupportedControllers = pControllerMapping; - - SDL_free( pchGUID ); - } + SDL_GameControllerAddMapping( pUserMappings ); if ( pchNewLine ) pUserMappings = pchNewLine + 1; else pUserMappings = NULL; } + SDL_free(pTempMappings); } } @@ -1133,7 +1218,7 @@ SDL_GameControllerEventState(int state) #else const Uint32 event_list[] = { SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONUP, - SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, + SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, SDL_CONTROLLERDEVICEREMAPPED, }; unsigned int i; From 191718be4435a2b83ea728932a9498961d1d8be8 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Tue, 5 Mar 2013 18:01:59 -0500 Subject: [PATCH 053/151] add hint to allow disabling the use of Xinput. --- include/SDL_hints.h | 9 +++++ src/joystick/windows/SDL_dxjoystick.c | 47 +++++++++++++++++---------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 1d4a3e5a7..66da58f23 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -196,6 +196,15 @@ extern "C" { #define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS" +/** + * \brief A variable that lets you disable the detection and use of Xinput gamepad devices + * + * The variable can be set to the following values: + * "0" - Disable XInput timer (only uses direct input) + * "1" - Enable XInput timer (the default) + */ +#define SD_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED" + /** * \brief A variable that lets you manually hint extra gamecontroller db entries * diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index ba13f971c..552cbb0e2 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -73,6 +73,7 @@ static SDL_mutex *s_mutexJoyStickEnum = NULL; static SDL_Thread *s_threadJoystick = NULL; static SDL_bool s_bJoystickThreadQuit = SDL_FALSE; static HANDLE s_pXInputDLL = 0; +static SDL_bool s_bXInputEnabled = SDL_TRUE; extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * ppDI, @@ -364,6 +365,11 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput ) HRESULT hr; DWORD bCleanupCOM; + if (!s_bXInputEnabled) + { + return SDL_FALSE; + } + SDL_memset( pDevices, 0x0, sizeof(pDevices) ); // CoInit if needed @@ -569,7 +575,7 @@ SDL_JoystickThread(void *_data) } } - if ( XINPUTGETCAPABILITIES ) + if ( s_bXInputEnabled && XINPUTGETCAPABILITIES ) { // scan for any change in XInput devices for ( userId = 0; userId < 4; userId++ ) @@ -627,6 +633,10 @@ SDL_SYS_JoystickInit(void) { HRESULT result; HINSTANCE instance; + const char *env = SDL_GetHint(SD_HINT_XINPUT_ENABLED); + if (env && !SDL_atoi(env)) { + s_bXInputEnabled = SDL_FALSE; + } result = WIN_CoInitialize(); if (FAILED(result)) { @@ -666,23 +676,25 @@ SDL_SYS_JoystickInit(void) s_bDeviceAdded = SDL_TRUE; // force a scan of the system for joysticks this first time SDL_SYS_JoystickDetect(); - // try to load XInput support if available - s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); - if ( !s_pXInputDLL ) - s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); - if ( s_pXInputDLL ) - { - // 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... - PC_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); - PC_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); - PC_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); - if ( !PC_XInputGetState || !PC_XInputSetState || !PC_XInputGetCapabilities ) + if (s_bXInputEnabled) { + // try to load XInput support if available + s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); + if ( !s_pXInputDLL ) + s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); + if ( s_pXInputDLL ) { - SDL_SYS_JoystickQuit(); - SDL_SetError("GetProcAddress() failed when loading XInput.", GetLastError()); - return (-1); + // 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... + PC_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); + PC_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); + PC_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); + if ( !PC_XInputGetState || !PC_XInputSetState || !PC_XInputGetCapabilities ) + { + SDL_SYS_JoystickQuit(); + SDL_SetError("GetProcAddress() failed when loading XInput.", GetLastError()); + return (-1); + } } - } + } if ( !s_threadJoystick ) @@ -934,6 +946,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) /* allocate memory for system specific hardware data */ joystick->instance_id = joystickdevice->nInstanceID; + joystick->closed = 0; joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata)); if (joystick->hwdata == NULL) { @@ -959,7 +972,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) userId++; } - if ( XINPUTGETCAPABILITIES ) + if ( s_bXInputEnabled && XINPUTGETCAPABILITIES ) { result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities ); if ( result == ERROR_SUCCESS ) From ac51aff110a5bd0b73cc287a61eab5f26144f700 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Tue, 5 Mar 2013 18:54:55 -0500 Subject: [PATCH 054/151] Add SDL_TryLockMutex and implementations for all platforms --- include/SDL_mutex.h | 7 +++++ src/thread/generic/SDL_sysmutex.c | 36 ++++++++++++++++++++++- src/thread/nds/SDL_sysmutex.c | 36 ++++++++++++++++++++++- src/thread/pthread/SDL_sysmutex.c | 47 +++++++++++++++++++++++++++++++ src/thread/windows/SDL_sysmutex.c | 16 +++++++++++ 5 files changed, 140 insertions(+), 2 deletions(-) diff --git a/include/SDL_mutex.h b/include/SDL_mutex.h index 562c3b06f..7ef294e1a 100644 --- a/include/SDL_mutex.h +++ b/include/SDL_mutex.h @@ -73,6 +73,13 @@ extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void); #define SDL_LockMutex(m) SDL_mutexP(m) extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex); +/** + * Try to lock the mutex + * + * \return 0, SDL_MUTEX_TIMEDOUT, or -1 on error + */ +extern DECLSPEC int SDLCALL SDL_TryLockMutex(SDL_mutex * mutex); + /** * Unlock the mutex. * diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c index a68f238c7..6cc32ec70 100644 --- a/src/thread/generic/SDL_sysmutex.c +++ b/src/thread/generic/SDL_sysmutex.c @@ -68,7 +68,7 @@ SDL_DestroyMutex(SDL_mutex * mutex) } } -/* Lock the semaphore */ +/* Lock the mutex */ int SDL_mutexP(SDL_mutex * mutex) { @@ -99,6 +99,40 @@ SDL_mutexP(SDL_mutex * mutex) #endif /* SDL_THREADS_DISABLED */ } +/* try Lock the mutex */ +int +SDL_TryLockMutex(SDL_mutex * mutex) +{ +#if SDL_THREADS_DISABLED + return 0; +#else + int retval = 0; + SDL_threadID this_thread; + + if (mutex == NULL) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + this_thread = SDL_ThreadID(); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + retval = SDL_SemWait(mutex->sem); + if (retval == 0) { + mutex->owner = this_thread; + mutex->recursive = 0; + } + } + + return retval; +#endif /* SDL_THREADS_DISABLED */ +} + /* Unlock the mutex */ int SDL_mutexV(SDL_mutex * mutex) diff --git a/src/thread/nds/SDL_sysmutex.c b/src/thread/nds/SDL_sysmutex.c index 6b662c99f..ec940dd24 100644 --- a/src/thread/nds/SDL_sysmutex.c +++ b/src/thread/nds/SDL_sysmutex.c @@ -76,7 +76,7 @@ SDL_DestroyMutex(SDL_mutex * mutex) } } -/* Lock the semaphore */ +/* Lock the mutex */ int SDL_mutexP(SDL_mutex * mutex) { @@ -107,6 +107,40 @@ SDL_mutexP(SDL_mutex * mutex) #endif /* DISABLE_THREADS */ } +/* Try Lock the mutex */ +int +SDL_TryLockMutex(SDL_mutex * mutex) +{ +#ifdef DISABLE_THREADS + return 0; +#else + int retval = 0; + SDL_threadID this_thread; + + if (mutex == NULL) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + this_thread = SDL_ThreadID(); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + retval = SDL_SemTryWait(mutex->sem); + if (ret == 0) { + mutex->owner = this_thread; + mutex->recursive = 0; + } + } + + return retval; +#endif /* DISABLE_THREADS */ +} + /* Unlock the mutex */ int SDL_mutexV(SDL_mutex * mutex) diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index ce611c082..6d1a1d92e 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -22,6 +22,7 @@ #define _GNU_SOURCE #include +#include #include "SDL_thread.h" @@ -117,6 +118,52 @@ SDL_mutexP(SDL_mutex * mutex) return retval; } +int +SDL_TryLockMutex(SDL_mutex * mutex) +{ + int retval; +#if FAKE_RECURSIVE_MUTEX + pthread_t this_thread; +#endif + + if (mutex == NULL) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + retval = 0; +#if FAKE_RECURSIVE_MUTEX + this_thread = pthread_self(); + if (mutex->owner == this_thead) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + if (pthread_mutex_lock(&mutex->id) == 0) { + mutex->owner = this_thread; + mutex->recursive = 0; + } else if (errno == EBUSY) { + retval = SDL_MUTEX_TIMEDOUT; + } else { + SDL_SetError("pthread_mutex_trylock() failed"); + retval = -1; + } + } +#else + if (pthread_mutex_trylock(&mutex->id) != 0) { + if (errno == EBUSY) { + retval = SDL_MUTEX_TIMEDOUT; + } else { + SDL_SetError("pthread_mutex_trylock() failed"); + retval = -1; + } + } +#endif + return retval; +} + int SDL_mutexV(SDL_mutex * mutex) { diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index 7d88c79a2..02883dcc4 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -75,6 +75,22 @@ SDL_mutexP(SDL_mutex * mutex) return (0); } +/* TryLock the mutex */ +int +SDL_TryLockMutex(SDL_mutex * mutex) +{ + if (mutex == NULL) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + int retval = 0; + if (TryEnterCriticalSection(&mutex->cs) == 0) { + retval = SDL_MUTEX_TIMEDOUT; + } + return retval; +} + /* Unlock the mutex */ int SDL_mutexV(SDL_mutex * mutex) From 6398f00da76c71b4830e36e7324014d326f09cd5 Mon Sep 17 00:00:00 2001 From: Shawn Walker Date: Mon, 25 Feb 2013 22:46:21 +0000 Subject: [PATCH 055/151] Fix pulseaudio dynamic linking for Solaris builds. Fix Solaris Studio compilation errors. Fix sunaudio backend for SDL2. --- configure.in | 8 + src/audio/sun/SDL_sunaudio.c | 293 ++++++++++++++++------------------- src/audio/sun/SDL_sunaudio.h | 10 -- src/video/SDL_blit_0.c | 12 +- src/video/SDL_blit_1.c | 10 +- src/video/x11/edid.h | 4 - 6 files changed, 154 insertions(+), 183 deletions(-) diff --git a/configure.in b/configure.in index 6f0a900d5..9a0b7e1a9 100644 --- a/configure.in +++ b/configure.in @@ -794,6 +794,14 @@ AC_HELP_STRING([--enable-pulseaudio-shared], [dynamically load PulseAudio suppor test x$enable_pulseaudio_shared = xyes && test x$pulseaudio_lib != x; then echo "-- dynamic libpulse-simple -> $pulseaudio_lib" AC_DEFINE_UNQUOTED(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC, "$pulseaudio_lib", [ ]) + + case "$host" in + # On Solaris, pulseaudio must be linked deferred explicitly + # to prevent undefined symbol failures. + *-*-solaris*) + PULSEAUDIO_LIBS=`echo $PULSEAUDIO_LIBS | sed 's/\-l/-Wl,-l/g'` + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-zdeferred $PULSEAUDIO_LIBS -Wl,-znodeferred" + esac else EXTRA_LDFLAGS="$EXTRA_LDFLAGS $PULSEAUDIO_LIBS" fi diff --git a/src/audio/sun/SDL_sunaudio.c b/src/audio/sun/SDL_sunaudio.c index d7ffbdb41..2d643b503 100644 --- a/src/audio/sun/SDL_sunaudio.c +++ b/src/audio/sun/SDL_sunaudio.c @@ -22,11 +22,6 @@ #if SDL_AUDIO_DRIVER_SUNAUDIO -/* I'm gambling no one uses this audio backend...we'll see who emails. :) */ -#error this code has not been updated for SDL 1.3. -#error if no one emails icculus at icculus.org and tells him that this -#error code is needed, this audio backend will eventually be removed from SDL. - /* Allow access to a raw mixing buffer */ #include @@ -51,84 +46,21 @@ #include "SDL_sunaudio.h" /* Open the audio device for playback, and don't block if busy */ -#define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) #if defined(AUDIO_GETINFO) && !defined(AUDIO_GETBUFINFO) #define AUDIO_GETBUFINFO AUDIO_GETINFO #endif /* Audio driver functions */ -static int DSP_OpenAudio(_THIS, SDL_AudioSpec * spec); -static void DSP_WaitAudio(_THIS); -static void DSP_PlayAudio(_THIS); -static Uint8 *DSP_GetAudioBuf(_THIS); -static void DSP_CloseAudio(_THIS); - static Uint8 snd2au(int sample); /* Audio driver bootstrap functions */ - -static int -Audio_Available(void) -{ - int fd; - int available; - - available = 0; - fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 1); - if (fd >= 0) { - available = 1; - close(fd); - } - return (available); -} - static void -Audio_DeleteDevice(SDL_AudioDevice * device) +SUNAUDIO_DetectDevices(int iscapture, SDL_AddAudioDevice addfn) { - SDL_free(device->hidden); - SDL_free(device); + SDL_EnumUnixAudioDevices(iscapture, 1, (int (*)(int fd)) NULL, addfn); } -static SDL_AudioDevice * -Audio_CreateDevice(int devindex) -{ - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); - if (this) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ((this == NULL) || (this->hidden == NULL)) { - SDL_OutOfMemory(); - if (this) { - SDL_free(this); - } - return (0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - audio_fd = -1; - - /* Set the function pointers */ - this->OpenAudio = DSP_OpenAudio; - this->WaitAudio = DSP_WaitAudio; - this->PlayAudio = DSP_PlayAudio; - this->GetAudioBuf = DSP_GetAudioBuf; - this->CloseAudio = DSP_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; -} - -AudioBootStrap SUNAUDIO_bootstrap = { - "audio", "UNIX /dev/audio interface", - Audio_Available, Audio_CreateDevice, 0 -}; - #ifdef DEBUG_AUDIO void CheckUnderflow(_THIS) @@ -137,29 +69,29 @@ CheckUnderflow(_THIS) audio_info_t info; int left; - ioctl(audio_fd, AUDIO_GETBUFINFO, &info); - left = (written - info.play.samples); - if (written && (left == 0)) { + ioctl(this->hidden->audio_fd, AUDIO_GETBUFINFO, &info); + left = (this->hidden->written - info.play.samples); + if (this->hidden->written && (left == 0)) { fprintf(stderr, "audio underflow!\n"); } #endif } #endif -void -DSP_WaitAudio(_THIS) +static void +SUNAUDIO_WaitDevice(_THIS) { #ifdef AUDIO_GETBUFINFO #define SLEEP_FUDGE 10 /* 10 ms scheduling fudge factor */ audio_info_t info; Sint32 left; - ioctl(audio_fd, AUDIO_GETBUFINFO, &info); - left = (written - info.play.samples); - if (left > fragsize) { + ioctl(this->hidden->audio_fd, AUDIO_GETBUFINFO, &info); + left = (this->hidden->written - info.play.samples); + if (left > this->hidden->fragsize) { Sint32 sleepy; - sleepy = ((left - fragsize) / frequency); + sleepy = ((left - this->hidden->fragsize) / this->hidden->frequency); sleepy -= SLEEP_FUDGE; if (sleepy > 0) { SDL_Delay(sleepy); @@ -169,30 +101,30 @@ DSP_WaitAudio(_THIS) fd_set fdset; FD_ZERO(&fdset); - FD_SET(audio_fd, &fdset); - select(audio_fd + 1, NULL, &fdset, NULL, NULL); + FD_SET(this->hidden->audio_fd, &fdset); + select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, NULL); #endif } -void -DSP_PlayAudio(_THIS) +static void +SUNAUDIO_PlayDevice(_THIS) { /* Write the audio data */ - if (ulaw_only) { + if (this->hidden->ulaw_only) { /* Assuming that this->spec.freq >= 8000 Hz */ int accum, incr, pos; Uint8 *aubuf; accum = 0; incr = this->spec.freq / 8; - aubuf = ulaw_buf; - switch (audio_fmt & 0xFF) { + aubuf = this->hidden->ulaw_buf; + switch (this->hidden->audio_fmt & 0xFF) { case 8: { Uint8 *sndbuf; - sndbuf = mixbuf; - for (pos = 0; pos < fragsize; ++pos) { + sndbuf = this->hidden->mixbuf; + for (pos = 0; pos < this->hidden->fragsize; ++pos) { *aubuf = snd2au((0x80 - *sndbuf) * 64); accum += incr; while (accum > 0) { @@ -207,8 +139,8 @@ DSP_PlayAudio(_THIS) { Sint16 *sndbuf; - sndbuf = (Sint16 *) mixbuf; - for (pos = 0; pos < fragsize; ++pos) { + sndbuf = (Sint16 *) this->hidden->mixbuf; + for (pos = 0; pos < this->hidden->fragsize; ++pos) { *aubuf = snd2au(*sndbuf / 4); accum += incr; while (accum > 0) { @@ -223,63 +155,96 @@ DSP_PlayAudio(_THIS) #ifdef DEBUG_AUDIO CheckUnderflow(this); #endif - if (write(audio_fd, ulaw_buf, fragsize) < 0) { + if (write(this->hidden->audio_fd, this->hidden->ulaw_buf, + this->hidden->fragsize) < 0) { /* Assume fatal error, for now */ this->enabled = 0; } - written += fragsize; + this->hidden->written += this->hidden->fragsize; } else { #ifdef DEBUG_AUDIO CheckUnderflow(this); #endif - if (write(audio_fd, mixbuf, this->spec.size) < 0) { + if (write(this->hidden->audio_fd, this->hidden->mixbuf, + this->spec.size) < 0) { /* Assume fatal error, for now */ this->enabled = 0; } - written += fragsize; + this->hidden->written += this->hidden->fragsize; } } -Uint8 * -DSP_GetAudioBuf(_THIS) +static Uint8 * +SUNAUDIO_GetDeviceBuf(_THIS) { - return (mixbuf); + return (this->hidden->mixbuf); } -void -DSP_CloseAudio(_THIS) +static void +SUNAUDIO_CloseDevice(_THIS) { - if (mixbuf != NULL) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; + if (this->hidden != NULL) { + if (this->hidden->mixbuf != NULL) { + SDL_FreeAudioMem(this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + } + if (this->hidden->ulaw_buf != NULL) { + SDL_free(this->hidden->ulaw_buf); + this->hidden->ulaw_buf = NULL; + } + if (this->hidden->audio_fd >= 0) { + close(this->hidden->audio_fd); + this->hidden->audio_fd = -1; + } + SDL_free(this->hidden); + this->hidden = NULL; } - if (ulaw_buf != NULL) { - SDL_free(ulaw_buf); - ulaw_buf = NULL; - } - close(audio_fd); } -int -DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) +static int +SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) { - char audiodev[1024]; + const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT); + SDL_AudioFormat format = 0; + audio_info_t info; + + /* We don't care what the devname is...we'll try to open anything. */ + /* ...but default to first name in the list... */ + if (devname == NULL) { + devname = SDL_GetAudioDeviceName(0, iscapture); + if (devname == NULL) { + SDL_SetError("No such audio device"); + return 0; + } + } + + /* Initialize all variables that we clean on shutdown */ + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc((sizeof *this->hidden)); + if (this->hidden == NULL) { + SDL_OutOfMemory(); + return 0; + } + SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + + /* Open the audio device */ + this->hidden->audio_fd = open(devname, flags, 0); + if (this->hidden->audio_fd < 0) { + SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); + return 0; + } + #ifdef AUDIO_SETINFO int enc; #endif - int desired_freq = spec->freq; - - /* Initialize our freeable variables, in case we fail */ - audio_fd = -1; - mixbuf = NULL; - ulaw_buf = NULL; + int desired_freq = this->spec.freq; /* Determine the audio parameters from the AudioSpec */ - switch (SDL_AUDIO_BITSIZE(spec->format)) { + switch (SDL_AUDIO_BITSIZE(this->spec.format)) { case 8: { /* Unsigned 8 bit audio data */ - spec->format = AUDIO_U8; + this->spec.format = AUDIO_U8; #ifdef AUDIO_SETINFO enc = AUDIO_ENCODING_LINEAR8; #endif @@ -288,7 +253,7 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) case 16: { /* Signed 16 bit audio data */ - spec->format = AUDIO_S16SYS; + this->spec.format = AUDIO_S16SYS; #ifdef AUDIO_SETINFO enc = AUDIO_ENCODING_LINEAR; #endif @@ -302,40 +267,33 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) return (-1); } } - audio_fmt = spec->format; + this->hidden->audio_fmt = this->spec.format; - /* Open the audio device */ - audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 1); - if (audio_fd < 0) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return (-1); - } - - ulaw_only = 0; /* modern Suns do support linear audio */ + this->hidden->ulaw_only = 0; /* modern Suns do support linear audio */ #ifdef AUDIO_SETINFO for (;;) { audio_info_t info; AUDIO_INITINFO(&info); /* init all fields to "no change" */ /* Try to set the requested settings */ - info.play.sample_rate = spec->freq; - info.play.channels = spec->channels; + info.play.sample_rate = this->spec.freq; + info.play.channels = this->spec.channels; info.play.precision = (enc == AUDIO_ENCODING_ULAW) - ? 8 : spec->format & 0xff; + ? 8 : this->spec.format & 0xff; info.play.encoding = enc; - if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0) { + if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) { /* Check to be sure we got what we wanted */ - if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) { + if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) { SDL_SetError("Error getting audio parameters: %s", strerror(errno)); return -1; } if (info.play.encoding == enc - && info.play.precision == (spec->format & 0xff) - && info.play.channels == spec->channels) { + && info.play.precision == (this->spec.format & 0xff) + && info.play.channels == this->spec.channels) { /* Yow! All seems to be well! */ - spec->freq = info.play.sample_rate; + this->spec.freq = info.play.sample_rate; break; } } @@ -344,16 +302,16 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) case AUDIO_ENCODING_LINEAR8: /* unsigned 8bit apparently not supported here */ enc = AUDIO_ENCODING_LINEAR; - spec->format = AUDIO_S16SYS; + this->spec.format = AUDIO_S16SYS; break; /* try again */ case AUDIO_ENCODING_LINEAR: /* linear 16bit didn't work either, resort to µ-law */ enc = AUDIO_ENCODING_ULAW; - spec->channels = 1; - spec->freq = 8000; - spec->format = AUDIO_U8; - ulaw_only = 1; + this->spec.channels = 1; + this->spec.freq = 8000; + this->spec.format = AUDIO_U8; + this->hidden->ulaw_only = 1; break; default: @@ -364,43 +322,44 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) } } #endif /* AUDIO_SETINFO */ - written = 0; + this->hidden->written = 0; /* We can actually convert on-the-fly to U-Law */ - if (ulaw_only) { - spec->freq = desired_freq; - fragsize = (spec->samples * 1000) / (spec->freq / 8); - frequency = 8; - ulaw_buf = (Uint8 *) SDL_malloc(fragsize); - if (ulaw_buf == NULL) { + if (this->hidden->ulaw_only) { + this->spec.freq = desired_freq; + this->hidden->fragsize = (this->spec.samples * 1000) / + (this->spec.freq / 8); + this->hidden->frequency = 8; + this->hidden->ulaw_buf = (Uint8 *) SDL_malloc(this->hidden->fragsize); + if (this->hidden->ulaw_buf == NULL) { SDL_OutOfMemory(); return (-1); } - spec->channels = 1; + this->spec.channels = 1; } else { - fragsize = spec->samples; - frequency = spec->freq / 1000; + this->hidden->fragsize = this->spec.samples; + this->hidden->frequency = this->spec.freq / 1000; } #ifdef DEBUG_AUDIO fprintf(stderr, "Audio device %s U-Law only\n", - ulaw_only ? "is" : "is not"); + this->hidden->ulaw_only ? "is" : "is not"); fprintf(stderr, "format=0x%x chan=%d freq=%d\n", - spec->format, spec->channels, spec->freq); + this->spec.format, this->spec.channels, this->spec.freq); #endif /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec(&this->spec); /* Allocate mixing buffer */ - mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); - if (mixbuf == NULL) { + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size); + if (this->hidden->mixbuf == NULL) { SDL_OutOfMemory(); return (-1); } - SDL_memset(mixbuf, spec->silence, spec->size); + SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return (0); + return (1); } /************************************************************************/ @@ -456,6 +415,24 @@ snd2au(int sample) return (mask & sample); } +static int +SUNAUDIO_Init(SDL_AudioDriverImpl * impl) +{ + /* Set the function pointers */ + impl->DetectDevices = SUNAUDIO_DetectDevices; + impl->OpenDevice = SUNAUDIO_OpenDevice; + impl->PlayDevice = SUNAUDIO_PlayDevice; + impl->WaitDevice = SUNAUDIO_WaitDevice; + impl->GetDeviceBuf = SUNAUDIO_GetDeviceBuf; + impl->CloseDevice = SUNAUDIO_CloseDevice; + + return 1; /* this audio target is available. */ +} + +AudioBootStrap SUNAUDIO_bootstrap = { + "audio", "UNIX /dev/audio interface", SUNAUDIO_Init, 0 +}; + #endif /* SDL_AUDIO_DRIVER_SUNAUDIO */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/sun/SDL_sunaudio.h b/src/audio/sun/SDL_sunaudio.h index 67b01dc1d..1f2c0b4f2 100644 --- a/src/audio/sun/SDL_sunaudio.h +++ b/src/audio/sun/SDL_sunaudio.h @@ -42,16 +42,6 @@ struct SDL_PrivateAudioData int frequency; /* The audio frequency in KHz */ }; -/* Old variable names */ -#define audio_fd (this->hidden->audio_fd) -#define audio_fmt (this->hidden->audio_fmt) -#define mixbuf (this->hidden->mixbuf) -#define ulaw_only (this->hidden->ulaw_only) -#define ulaw_buf (this->hidden->ulaw_buf) -#define written (this->hidden->written) -#define fragsize (this->hidden->fragsize) -#define frequency (this->hidden->frequency) - #endif /* _SDL_sunaudio_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c index 54e6b8061..12cf8607b 100644 --- a/src/video/SDL_blit_0.c +++ b/src/video/SDL_blit_0.c @@ -443,11 +443,11 @@ BlitBtoNAlphaKey(SDL_BlitInfo * info) } static const SDL_BlitFunc bitmap_blit[] = { - NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 + (SDL_BlitFunc) NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 }; static const SDL_BlitFunc colorkey_blit[] = { - NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key + (SDL_BlitFunc) NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key }; SDL_BlitFunc @@ -457,7 +457,7 @@ SDL_CalculateBlit0(SDL_Surface * surface) if (surface->format->BitsPerPixel != 1) { /* We don't support sub 8-bit packed pixel modes */ - return NULL; + return (SDL_BlitFunc) NULL; } if (surface->map->dst->format->BitsPerPixel < 8) { which = 0; @@ -472,12 +472,12 @@ SDL_CalculateBlit0(SDL_Surface * surface) return colorkey_blit[which]; case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? BlitBtoNAlpha : NULL; + return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc) NULL; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? BlitBtoNAlphaKey : NULL; + return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc) NULL; } - return NULL; + return (SDL_BlitFunc) NULL; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c index 095660489..514edab01 100644 --- a/src/video/SDL_blit_1.c +++ b/src/video/SDL_blit_1.c @@ -511,11 +511,11 @@ Blit1toNAlphaKey(SDL_BlitInfo * info) } static const SDL_BlitFunc one_blit[] = { - NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 + (SDL_BlitFunc) NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 }; static const SDL_BlitFunc one_blitkey[] = { - NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key + (SDL_BlitFunc) NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key }; SDL_BlitFunc @@ -541,12 +541,12 @@ SDL_CalculateBlit1(SDL_Surface * surface) /* Supporting 8bpp->8bpp alpha is doable but requires lots of tables which consume space and takes time to precompute, so is better left to the user */ - return which >= 2 ? Blit1toNAlpha : NULL; + return which >= 2 ? Blit1toNAlpha : (SDL_BlitFunc) NULL; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? Blit1toNAlphaKey : NULL; + return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc) NULL; } - return NULL; + return (SDL_BlitFunc) NULL; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/x11/edid.h b/src/video/x11/edid.h index c0c14e8f0..8c217eba2 100644 --- a/src/video/x11/edid.h +++ b/src/video/x11/edid.h @@ -39,10 +39,6 @@ struct Timing int frequency; }; -struct DisplayDescriptor -{ -}; - struct DetailedTiming { int pixel_clock; From 4e631c1583edd39c63996612f4f1228347b32520 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 5 Mar 2013 18:52:25 -0800 Subject: [PATCH 056/151] Fixed warning messages when loading Direct3D DLL kmx I have investigated the warning "Failed loading D3DX9_*.dll" and come up with the enclosed patch (please forward it to relevant SDL2 mailing list/bugtracker). --- src/render/direct3d/SDL_render_d3d.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index a183413c4..0e078d77a 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -477,7 +477,9 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags) for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) { SDL_snprintf(d3dxDLLFile, 49, "D3DX9_%02d.dll", d3dxVersion); - data->d3dxDLL = SDL_LoadObject(d3dxDLLFile); + LPTSTR tmpstr = WIN_UTF8ToString(d3dxDLLFile); + data->d3dxDLL = (void *)LoadLibrary(tmpstr); /* not using SDL_LoadObject() as we want silently fail - no error message */ + SDL_free(tmpstr); if (data->d3dxDLL) { HRESULT (WINAPI *D3DXCreateMatrixStack) (DWORD Flags, LPD3DXMATRIXSTACK* ppStack); D3DXCreateMatrixStack = (HRESULT (WINAPI *) (DWORD, LPD3DXMATRIXSTACK*)) SDL_LoadFunction(data->d3dxDLL, "D3DXCreateMatrixStack"); From 3ab8d4ce1a7dd9d1082bb510cde8434ec5144d73 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Wed, 6 Mar 2013 10:37:27 -0500 Subject: [PATCH 057/151] move variable declaration to beginning of function --- src/thread/windows/SDL_sysmutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index 02883dcc4..78730ff64 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -79,12 +79,12 @@ SDL_mutexP(SDL_mutex * mutex) int SDL_TryLockMutex(SDL_mutex * mutex) { + int retval = 0; if (mutex == NULL) { SDL_SetError("Passed a NULL mutex"); return -1; } - int retval = 0; if (TryEnterCriticalSection(&mutex->cs) == 0) { retval = SDL_MUTEX_TIMEDOUT; } From 4a942814bd94179f1d5cfb9c9803f245f6d11784 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 6 Mar 2013 09:37:03 -0800 Subject: [PATCH 058/151] Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml --- src/video/x11/SDL_x11video.c | 1 + src/video/x11/SDL_x11video.h | 1 + src/video/x11/SDL_x11window.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 150b66012..351511b10 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -522,6 +522,7 @@ X11_VideoInit(_THIS) GET_ATOM(_NET_WM_ICON_NAME); GET_ATOM(_NET_WM_ICON); GET_ATOM(_NET_WM_PING); + GET_ATOM(_NET_ACTIVE_WINDOW); GET_ATOM(UTF8_STRING); /* Detect the window manager */ diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index 738cf73be..392c3896b 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -99,6 +99,7 @@ typedef struct SDL_VideoData Atom _NET_WM_ICON_NAME; Atom _NET_WM_ICON; Atom _NET_WM_PING; + Atom _NET_ACTIVE_WINDOW; Atom UTF8_STRING; SDL_Scancode key_layout[256]; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 4f935fc3c..5ebe574ac 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -927,10 +927,39 @@ X11_MinimizeWindow(_THIS, SDL_Window * window) XFlush(display); } +static void +SetWindowActive(_THIS, SDL_Window * window) +{ + SDL_WindowData *data = (SDL_WindowData *) window->driverdata; + SDL_DisplayData *displaydata = + (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; + Display *display = data->videodata->display; + Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW; + + if (X11_IsWindowMapped(_this, window)) { + XEvent e; + + SDL_zero(e); + e.xany.type = ClientMessage; + e.xclient.message_type = _NET_ACTIVE_WINDOW; + e.xclient.format = 32; + e.xclient.window = data->xwindow; + e.xclient.data.l[0] = 1; /* source indication. 1 = application */ + e.xclient.data.l[1] = CurrentTime; + e.xclient.data.l[2] = 0; + + XSendEvent(display, RootWindow(display, displaydata->screen), 0, + SubstructureNotifyMask | SubstructureRedirectMask, &e); + + XFlush(display); + } +} + void X11_RestoreWindow(_THIS, SDL_Window * window) { SetWindowMaximized(_this, window, SDL_FALSE); + SetWindowActive(_this, window); X11_ShowWindow(_this, window); } From 541a638836f0741f5473740eb62281191f8d45c4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 6 Mar 2013 09:45:53 -0800 Subject: [PATCH 059/151] Fixed compile errors on Windows --- src/joystick/windows/SDL_dxjoystick.c | 1 + src/render/direct3d/SDL_render_d3d.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index 552cbb0e2..cf909170b 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -42,6 +42,7 @@ #include "SDL_timer.h" #include "SDL_mutex.h" #include "SDL_events.h" +#include "SDL_hints.h" #if !SDL_EVENTS_DISABLED #include "../../events/SDL_events_c.h" #endif diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index 0e078d77a..a2bd41346 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -476,10 +476,11 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags) } for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) { - SDL_snprintf(d3dxDLLFile, 49, "D3DX9_%02d.dll", d3dxVersion); - LPTSTR tmpstr = WIN_UTF8ToString(d3dxDLLFile); - data->d3dxDLL = (void *)LoadLibrary(tmpstr); /* not using SDL_LoadObject() as we want silently fail - no error message */ - SDL_free(tmpstr); + LPTSTR dllName; + SDL_snprintf(d3dxDLLFile, sizeof(d3dxDLLFile), "D3DX9_%02d.dll", d3dxVersion); + dllName = WIN_UTF8ToString(d3dxDLLFile); + data->d3dxDLL = (void *)LoadLibrary(dllName); /* not using SDL_LoadObject() as we want silently fail - no error message */ + SDL_free(dllName); if (data->d3dxDLL) { HRESULT (WINAPI *D3DXCreateMatrixStack) (DWORD Flags, LPD3DXMATRIXSTACK* ppStack); D3DXCreateMatrixStack = (HRESULT (WINAPI *) (DWORD, LPD3DXMATRIXSTACK*)) SDL_LoadFunction(data->d3dxDLL, "D3DXCreateMatrixStack"); From 85d6d00788e863d85ed5240d7b7d90dd8103d896 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 6 Mar 2013 11:59:15 -0800 Subject: [PATCH 060/151] Removed multi-input events, since we removed the unimplemented API recently. --- include/SDL_events.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index 49bdb9677..27e23ee2a 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -77,14 +77,6 @@ typedef enum SDL_MOUSEBUTTONUP, /**< Mouse button released */ SDL_MOUSEWHEEL, /**< Mouse wheel motion */ - /* Tablet or multiple mice input device events */ - SDL_INPUTMOTION = 0x500, /**< Input moved */ - SDL_INPUTBUTTONDOWN, /**< Input button pressed */ - SDL_INPUTBUTTONUP, /**< Input button released */ - SDL_INPUTWHEEL, /**< Input wheel motion */ - SDL_INPUTPROXIMITYIN, /**< Input pen entered proximity */ - SDL_INPUTPROXIMITYOUT, /**< Input pen left proximity */ - /* Joystick events */ SDL_JOYAXISMOTION = 0x600, /**< Joystick axis motion */ SDL_JOYBALLMOTION, /**< Joystick trackball motion */ From fb49761922a2fca7fd693b5cad0810da552022e8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 6 Mar 2013 11:59:19 -0800 Subject: [PATCH 061/151] Fixed 64-bit compile warnings on Visual C++ --- src/video/windows/SDL_windowsevents.c | 2 +- src/video/windows/SDL_windowsmessagebox.c | 3 ++- src/video/windows/SDL_windowswindow.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 7a1087358..03491a846 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -67,7 +67,7 @@ #endif static SDL_Scancode -WindowsScanCodeToSDLScanCode( int lParam, int wParam ) +WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam ) { SDL_Scancode code; char bIsExtended; diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 867b468b7..9865d7778 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -231,7 +231,8 @@ int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) { WIN_DialogData *dialog; - int i, x, y, w, h, gap, which; + int i, x, y, w, h, gap; + INT_PTR which; const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; /* FIXME: Need a better algorithm for laying out the message box */ diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index b3b9a39a8..7339d7812 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -32,7 +32,7 @@ typedef struct HBITMAP hbm; WNDPROC wndproc; SDL_bool created; - Uint32 mouse_button_flags; + WPARAM mouse_button_flags; struct SDL_VideoData *videodata; } SDL_WindowData; From 69b81824194779fbd792e4a8ffe5e8fbac47e59c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 6 Mar 2013 11:59:21 -0800 Subject: [PATCH 062/151] The joystick events contain a joystick instance ID, which is a signed value, with -1 being invalid. --- include/SDL_events.h | 26 +++++++++++++------------- include/SDL_joystick.h | 4 ++-- src/joystick/windows/SDL_dxjoystick.c | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index 27e23ee2a..205467e9a 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -244,7 +244,7 @@ typedef struct SDL_JoyAxisEvent { Uint32 type; /**< ::SDL_JOYAXISMOTION */ Uint32 timestamp; - Uint32 which; /**< The joystick instance id */ + SDL_JoystickID which; /**< The joystick instance id */ Uint8 axis; /**< The joystick axis index */ Uint8 padding1; Uint8 padding2; @@ -259,8 +259,8 @@ typedef struct SDL_JoyAxisEvent typedef struct SDL_JoyBallEvent { Uint32 type; /**< ::SDL_JOYBALLMOTION */ - Uint32 timestamp; - Uint32 which; /**< The joystick instance id */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ Uint8 ball; /**< The joystick trackball index */ Uint8 padding1; Uint8 padding2; @@ -275,8 +275,8 @@ typedef struct SDL_JoyBallEvent typedef struct SDL_JoyHatEvent { Uint32 type; /**< ::SDL_JOYHATMOTION */ - Uint32 timestamp; - Uint32 which; /**< The joystick instance id */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ Uint8 hat; /**< The joystick hat index */ Uint8 value; /**< The hat position value. * \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP @@ -295,8 +295,8 @@ typedef struct SDL_JoyHatEvent typedef struct SDL_JoyButtonEvent { Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */ - Uint32 timestamp; - Uint32 which; /**< The joystick instance id */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ Uint8 button; /**< The joystick button index */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 padding1; @@ -310,7 +310,7 @@ typedef struct SDL_JoyDeviceEvent { Uint32 type; /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */ Uint32 timestamp; - Uint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */ + Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */ } SDL_JoyDeviceEvent; @@ -320,8 +320,8 @@ typedef struct SDL_JoyDeviceEvent typedef struct SDL_ControllerAxisEvent { Uint32 type; /**< ::SDL_CONTROLLERAXISMOTION */ - Uint32 timestamp; - Uint32 which; /**< The joystick instance id */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ Uint8 axis; /**< The controller axis (SDL_GameControllerAxis) */ Uint8 padding1; Uint8 padding2; @@ -337,8 +337,8 @@ typedef struct SDL_ControllerAxisEvent typedef struct SDL_ControllerButtonEvent { Uint32 type; /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */ - Uint32 timestamp; - Uint32 which; /**< The joystick instance id */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ Uint8 button; /**< The controller button (SDL_GameControllerButton) */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 padding1; @@ -353,7 +353,7 @@ typedef struct SDL_ControllerDeviceEvent { Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */ Uint32 timestamp; - Uint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */ + Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */ } SDL_ControllerDeviceEvent; diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index 7d218925c..c948c05b3 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -67,7 +67,7 @@ typedef struct { Uint8 data[16]; } SDL_JoystickGUID; -typedef Uint32 SDL_JoystickID; +typedef Sint32 SDL_JoystickID; /* Function prototypes */ @@ -126,7 +126,7 @@ extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const cha extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick); /** - * Get the instance ID of an opened joystick. + * Get the instance ID of an opened joystick or -1 if the joystick is invalid. */ extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick); diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index cf909170b..9c493cb20 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -67,7 +67,7 @@ static SDL_bool coinitialized = SDL_FALSE; static LPDIRECTINPUT8 dinput = NULL; static SDL_bool s_bDeviceAdded = SDL_FALSE; static SDL_bool s_bDeviceRemoved = SDL_FALSE; -static int s_nInstanceID = -1; +static SDL_JoystickID s_nInstanceID = -1; static GUID *s_pKnownJoystickGUIDs = NULL; static SDL_cond *s_condJoystickThread = NULL; static SDL_mutex *s_mutexJoyStickEnum = NULL; @@ -85,7 +85,7 @@ struct JoyStick_DeviceData_ DIDEVICEINSTANCE dxdevice; char *joystickname; Uint8 send_add_event; - int nInstanceID; + SDL_JoystickID nInstanceID; SDL_bool bXInputDevice; Uint8 XInputUserId; struct JoyStick_DeviceData_ *pNext; From 1dec4dd800157ac4ec9795c076b4bddd30463ad6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 7 Mar 2013 15:17:06 -0800 Subject: [PATCH 063/151] Fixed read after free bug in the game controller. --- src/joystick/SDL_gamecontroller.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index d312b854f..585e955cc 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -678,17 +678,18 @@ SDL_GameControllerAddMapping( const char *mappingString ) SDL_bool is_xinput_mapping = SDL_FALSE; #endif - pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString ); - if (!pchGUID) return -1; + pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString ); + if (!pchGUID) { + return -1; + } #ifdef SDL_JOYSTICK_DINPUT if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) { is_xinput_mapping = SDL_TRUE; } #endif + jGUID = SDL_JoystickGetGUIDFromString(pchGUID); SDL_free(pchGUID); - jGUID = SDL_JoystickGetGUIDFromString(pchGUID); - pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID); pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString ); From 0707530b3584ba6c3ab26b68b93b72af8ed7c895 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 7 Mar 2013 15:37:08 -0800 Subject: [PATCH 064/151] Load the game controller mapping hint when opening a game controller. --- src/joystick/SDL_gamecontroller.c | 62 ++++++++++++++++--------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 585e955cc..90fb7b903 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -762,6 +762,33 @@ SDL_GameControllerMapping( SDL_GameController * gamecontroller ) return SDL_GameControllerMappingForGUID( gamecontroller->mapping.guid ); } +static void +SDL_GameControllerLoadHints() +{ + const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG); + if ( hint && hint[0] ) { + int nchHints = SDL_strlen( hint ); + char *pUserMappings = SDL_malloc( nchHints + 1 ); + char *pTempMappings = pUserMappings; + SDL_memcpy( pUserMappings, hint, nchHints ); + while ( pUserMappings ) { + char *pchNewLine = NULL; + + pchNewLine = SDL_strchr( pUserMappings, '\n' ); + if ( pchNewLine ) + *pchNewLine = '\0'; + + SDL_GameControllerAddMapping( pUserMappings ); + + if ( pchNewLine ) + pUserMappings = pchNewLine + 1; + else + pUserMappings = NULL; + } + SDL_free(pTempMappings); + } +} + /* * Initialize the game controller system, mostly load our DB of controller config mappings */ @@ -781,35 +808,11 @@ SDL_GameControllerInit(void) } // load in any user supplied config - { - const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG); - if ( hint && hint[0] ) - { - int nchHints = SDL_strlen( hint ); - char *pUserMappings = SDL_malloc( nchHints + 1 ); - char *pTempMappings = pUserMappings; - SDL_memcpy( pUserMappings, hint, nchHints ); - while ( pUserMappings ) - { - char *pchNewLine = NULL; - - pchNewLine = SDL_strchr( pUserMappings, '\n' ); - if ( pchNewLine ) - *pchNewLine = '\0'; - - SDL_GameControllerAddMapping( pUserMappings ); - - if ( pchNewLine ) - pUserMappings = pchNewLine + 1; - else - pUserMappings = NULL; - } - SDL_free(pTempMappings); - } - } + SDL_GameControllerLoadHints(); /* watch for joy events and fire controller ones if needed */ SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL ); + return (0); } @@ -875,10 +878,11 @@ SDL_GameControllerOpen(int device_index) gamecontrollerlist = gamecontrollerlist->next; } - // Find a Controller Mapping + // Find a controller mapping + // Check for hints in case someone has changed them recently + SDL_GameControllerLoadHints(); pSupportedController = SDL_PrivateGetControllerMapping(device_index); - if ( !pSupportedController ) - { + if ( !pSupportedController ) { SDL_SetError("Couldn't find mapping for device (%d)", device_index ); return (NULL); } From c6388c87c1d4a8c90bd2d57673c5c1abcd07de57 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 7 Mar 2013 20:12:40 -0800 Subject: [PATCH 065/151] Changed the name of SDL_mutexP() SDL_mutexV() --- include/SDL_mutex.h | 8 ++++---- src/atomic/SDL_spinlock.c | 6 +++--- src/audio/SDL_audio.c | 12 ++++++------ src/audio/baudio/SDL_beaudio.cc | 8 ++++---- src/audio/coreaudio/SDL_coreaudio.c | 4 ++-- src/events/SDL_events.c | 12 ++++++------ src/joystick/windows/SDL_dxjoystick.c | 4 ++-- src/thread/SDL_thread.c | 6 +++--- src/thread/generic/SDL_sysmutex.c | 2 +- src/thread/generic/SDL_syssem.c | 4 ++-- src/thread/nds/SDL_sysmutex.c | 4 ++-- src/thread/nds/SDL_syssem.c | 4 ++-- src/thread/pthread/SDL_sysmutex.c | 4 ++-- src/thread/windows/SDL_sysmutex.c | 4 ++-- src/timer/SDL_timer.c | 8 ++++---- test/testatomic.c | 8 ++++---- test/testlock.c | 4 ++-- 17 files changed, 51 insertions(+), 51 deletions(-) diff --git a/include/SDL_mutex.h b/include/SDL_mutex.h index 7ef294e1a..30519b87f 100644 --- a/include/SDL_mutex.h +++ b/include/SDL_mutex.h @@ -70,8 +70,8 @@ extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void); * * \return 0, or -1 on error. */ -#define SDL_LockMutex(m) SDL_mutexP(m) -extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex); +#define SDL_mutexP(m) SDL_LockMutex(m) +extern DECLSPEC int SDLCALL SDL_LockMutex(SDL_mutex * mutex); /** * Try to lock the mutex @@ -88,8 +88,8 @@ extern DECLSPEC int SDLCALL SDL_TryLockMutex(SDL_mutex * mutex); * \warning It is an error to unlock a mutex that has not been locked by * the current thread, and doing so results in undefined behavior. */ -#define SDL_UnlockMutex(m) SDL_mutexV(m) -extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex * mutex); +#define SDL_mutexV(m) SDL_UnlockMutex(m) +extern DECLSPEC int SDLCALL SDL_UnlockMutex(SDL_mutex * mutex); /** * Destroy a mutex. diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index 3bb319e9c..12c06a33e 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -41,13 +41,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) /* Race condition on first lock... */ _spinlock_mutex = SDL_CreateMutex(); } - SDL_mutexP(_spinlock_mutex); + SDL_LockMutex(_spinlock_mutex); if (*lock == 0) { *lock = 1; - SDL_mutexV(_spinlock_mutex); + SDL_UnlockMutex(_spinlock_mutex); return SDL_TRUE; } else { - SDL_mutexV(_spinlock_mutex); + SDL_UnlockMutex(_spinlock_mutex); return SDL_FALSE; } diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 090e0144b..6e87e1a5a 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -200,7 +200,7 @@ SDL_AudioLockDevice_Default(SDL_AudioDevice * device) if (device->thread && (SDL_ThreadID() == device->threadid)) { return; } - SDL_mutexP(device->mixer_lock); + SDL_LockMutex(device->mixer_lock); } static void @@ -209,7 +209,7 @@ SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device) if (device->thread && (SDL_ThreadID() == device->threadid)) { return; } - SDL_mutexV(device->mixer_lock); + SDL_UnlockMutex(device->mixer_lock); } @@ -407,9 +407,9 @@ SDL_RunAudio(void *devicep) } /* Read from the callback into the _input_ stream */ - SDL_mutexP(device->mixer_lock); + SDL_LockMutex(device->mixer_lock); (*fill) (udata, istream, istream_len); - SDL_mutexV(device->mixer_lock); + SDL_UnlockMutex(device->mixer_lock); /* Convert the audio if necessary and write to the streamer */ if (device->convert.needed) { @@ -480,9 +480,9 @@ SDL_RunAudio(void *devicep) } } - SDL_mutexP(device->mixer_lock); + SDL_LockMutex(device->mixer_lock); (*fill) (udata, stream, stream_len); - SDL_mutexV(device->mixer_lock); + SDL_UnlockMutex(device->mixer_lock); /* Convert the audio if necessary */ if (device->convert.needed) { diff --git a/src/audio/baudio/SDL_beaudio.cc b/src/audio/baudio/SDL_beaudio.cc index 20396f31a..2a25cf0d2 100644 --- a/src/audio/baudio/SDL_beaudio.cc +++ b/src/audio/baudio/SDL_beaudio.cc @@ -54,18 +54,18 @@ FillSound(void *device, void *stream, size_t len, if (!audio->paused) { if (audio->convert.needed) { - SDL_mutexP(audio->mixer_lock); + SDL_LockMutex(audio->mixer_lock); (*audio->spec.callback) (audio->spec.userdata, (Uint8 *) audio->convert.buf, audio->convert.len); - SDL_mutexV(audio->mixer_lock); + SDL_UnlockMutex(audio->mixer_lock); SDL_ConvertAudio(&audio->convert); SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt); } else { - SDL_mutexP(audio->mixer_lock); + SDL_LockMutex(audio->mixer_lock); (*audio->spec.callback) (audio->spec.userdata, (Uint8 *) stream, len); - SDL_mutexV(audio->mixer_lock); + SDL_UnlockMutex(audio->mixer_lock); } } } diff --git a/src/audio/coreaudio/SDL_coreaudio.c b/src/audio/coreaudio/SDL_coreaudio.c index 533dcfdca..31eb32615 100644 --- a/src/audio/coreaudio/SDL_coreaudio.c +++ b/src/audio/coreaudio/SDL_coreaudio.c @@ -280,10 +280,10 @@ outputCallback(void *inRefCon, while (remaining > 0) { if (this->hidden->bufferOffset >= this->hidden->bufferSize) { /* Generate the data */ - SDL_mutexP(this->mixer_lock); + SDL_LockMutex(this->mixer_lock); (*this->spec.callback)(this->spec.userdata, this->hidden->buffer, this->hidden->bufferSize); - SDL_mutexV(this->mixer_lock); + SDL_UnlockMutex(this->mixer_lock); this->hidden->bufferOffset = 0; } diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 149add196..b608590c4 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -212,7 +212,7 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action, } /* Lock the event queue */ used = 0; - if (!SDL_EventQ.lock || SDL_mutexP(SDL_EventQ.lock) == 0) { + if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) { if (action == SDL_ADDEVENT) { for (i = 0; i < numevents; ++i) { used += SDL_AddEvent(&events[i]); @@ -242,7 +242,7 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action, } } } - SDL_mutexV(SDL_EventQ.lock); + SDL_UnlockMutex(SDL_EventQ.lock); } else { SDL_SetError("Couldn't lock event queue"); used = -1; @@ -285,7 +285,7 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType) #endif /* Lock the event queue */ - if (SDL_mutexP(SDL_EventQ.lock) == 0) { + if (SDL_LockMutex(SDL_EventQ.lock) == 0) { int spot = SDL_EventQ.head; while (spot != SDL_EventQ.tail) { Uint32 type = SDL_EventQ.event[spot].type; @@ -295,7 +295,7 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType) spot = (spot + 1) % MAXEVENTS; } } - SDL_mutexV(SDL_EventQ.lock); + SDL_UnlockMutex(SDL_EventQ.lock); } } @@ -446,7 +446,7 @@ SDL_DelEventWatch(SDL_EventFilter filter, void *userdata) void SDL_FilterEvents(SDL_EventFilter filter, void *userdata) { - if (SDL_mutexP(SDL_EventQ.lock) == 0) { + if (SDL_LockMutex(SDL_EventQ.lock) == 0) { int spot; spot = SDL_EventQ.head; @@ -458,7 +458,7 @@ SDL_FilterEvents(SDL_EventFilter filter, void *userdata) } } } - SDL_mutexV(SDL_EventQ.lock); + SDL_UnlockMutex(SDL_EventQ.lock); } Uint8 diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index 9c493cb20..6493388f3 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -819,7 +819,7 @@ void SDL_SYS_JoystickDetect() pCurList = SYS_Joystick; SYS_Joystick = NULL; s_iNewGUID = 0; - SDL_mutexP( s_mutexJoyStickEnum ); + SDL_LockMutex( s_mutexJoyStickEnum ); if ( !s_pKnownJoystickGUIDs ) s_pKnownJoystickGUIDs = SDL_malloc( sizeof(GUID)*MAX_JOYSTICKS ); @@ -832,7 +832,7 @@ void SDL_SYS_JoystickDetect() EnumJoysticksCallback, &pCurList, DIEDFL_ATTACHEDONLY); - SDL_mutexV( s_mutexJoyStickEnum ); + SDL_UnlockMutex( s_mutexJoyStickEnum ); } if ( pCurList ) diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 99258a4cd..e20f672ff 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -85,7 +85,7 @@ SDL_AddThread(SDL_Thread * thread) return; } } - SDL_mutexP(thread_lock); + SDL_LockMutex(thread_lock); /* Expand the list of threads, if necessary */ #ifdef DEBUG_THREADS @@ -118,7 +118,7 @@ SDL_DelThread(SDL_Thread * thread) if (!thread_lock) { return; } - SDL_mutexP(thread_lock); + SDL_LockMutex(thread_lock); for (i = 0; i < SDL_numthreads; ++i) { if (thread == SDL_Threads[i]) { break; @@ -164,7 +164,7 @@ SDL_GetErrBuf(void) SDL_threadID this_thread; this_thread = SDL_ThreadID(); - SDL_mutexP(thread_lock); + SDL_LockMutex(thread_lock); for (i = 0; i < SDL_numthreads; ++i) { if (this_thread == SDL_Threads[i]->threadid) { errbuf = &SDL_Threads[i]->errbuf; diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c index 6cc32ec70..4954f48e8 100644 --- a/src/thread/generic/SDL_sysmutex.c +++ b/src/thread/generic/SDL_sysmutex.c @@ -70,7 +70,7 @@ SDL_DestroyMutex(SDL_mutex * mutex) /* Lock the mutex */ int -SDL_mutexP(SDL_mutex * mutex) +SDL_LockMutex(SDL_mutex * mutex) { #if SDL_THREADS_DISABLED return 0; diff --git a/src/thread/generic/SDL_syssem.c b/src/thread/generic/SDL_syssem.c index 365c7872c..474c44662 100644 --- a/src/thread/generic/SDL_syssem.c +++ b/src/thread/generic/SDL_syssem.c @@ -123,8 +123,8 @@ SDL_DestroySemaphore(SDL_sem * sem) } SDL_DestroyCond(sem->count_nonzero); if (sem->count_lock) { - SDL_mutexP(sem->count_lock); - SDL_mutexV(sem->count_lock); + SDL_LockMutex(sem->count_lock); + SDL_UnlockMutex(sem->count_lock); SDL_DestroyMutex(sem->count_lock); } SDL_free(sem); diff --git a/src/thread/nds/SDL_sysmutex.c b/src/thread/nds/SDL_sysmutex.c index ec940dd24..ffdecc808 100644 --- a/src/thread/nds/SDL_sysmutex.c +++ b/src/thread/nds/SDL_sysmutex.c @@ -78,7 +78,7 @@ SDL_DestroyMutex(SDL_mutex * mutex) /* Lock the mutex */ int -SDL_mutexP(SDL_mutex * mutex) +SDL_LockMutex(SDL_mutex * mutex) { #ifdef DISABLE_THREADS return 0; @@ -143,7 +143,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) /* Unlock the mutex */ int -SDL_mutexV(SDL_mutex * mutex) +SDL_UnlockMutex(SDL_mutex * mutex) { #ifdef DISABLE_THREADS return 0; diff --git a/src/thread/nds/SDL_syssem.c b/src/thread/nds/SDL_syssem.c index 015f9c9d8..788fc9223 100644 --- a/src/thread/nds/SDL_syssem.c +++ b/src/thread/nds/SDL_syssem.c @@ -129,8 +129,8 @@ SDL_DestroySemaphore(SDL_sem * sem) SDL_Delay(10); } SDL_DestroyCond(sem->count_nonzero); - SDL_mutexP(sem->count_lock); - SDL_mutexV(sem->count_lock); + SDL_LockMutex(sem->count_lock); + SDL_UnlockMutex(sem->count_lock); SDL_DestroyMutex(sem->count_lock); free(sem); } diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index 6d1a1d92e..f67cdf6c4 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -79,7 +79,7 @@ SDL_DestroyMutex(SDL_mutex * mutex) /* Lock the mutex */ int -SDL_mutexP(SDL_mutex * mutex) +SDL_LockMutex(SDL_mutex * mutex) { int retval; #if FAKE_RECURSIVE_MUTEX @@ -165,7 +165,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) } int -SDL_mutexV(SDL_mutex * mutex) +SDL_UnlockMutex(SDL_mutex * mutex) { int retval; diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index 78730ff64..6455cbeab 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -64,7 +64,7 @@ SDL_DestroyMutex(SDL_mutex * mutex) /* Lock the mutex */ int -SDL_mutexP(SDL_mutex * mutex) +SDL_LockMutex(SDL_mutex * mutex) { if (mutex == NULL) { SDL_SetError("Passed a NULL mutex"); @@ -93,7 +93,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) /* Unlock the mutex */ int -SDL_mutexV(SDL_mutex * mutex) +SDL_UnlockMutex(SDL_mutex * mutex) { if (mutex == NULL) { SDL_SetError("Passed a NULL mutex"); diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index f30410aa1..60b3bdb12 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -334,10 +334,10 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param) entry->timer = timer; entry->timerID = timer->timerID; - SDL_mutexP(data->timermap_lock); + SDL_LockMutex(data->timermap_lock); entry->next = data->timermap; data->timermap = entry; - SDL_mutexV(data->timermap_lock); + SDL_UnlockMutex(data->timermap_lock); /* Add the timer to the pending list for the timer thread */ SDL_AtomicLock(&data->lock); @@ -359,7 +359,7 @@ SDL_RemoveTimer(SDL_TimerID id) SDL_bool canceled = SDL_FALSE; /* Find the timer */ - SDL_mutexP(data->timermap_lock); + SDL_LockMutex(data->timermap_lock); prev = NULL; for (entry = data->timermap; entry; prev = entry, entry = entry->next) { if (entry->timerID == id) { @@ -371,7 +371,7 @@ SDL_RemoveTimer(SDL_TimerID id) break; } } - SDL_mutexV(data->timermap_lock); + SDL_UnlockMutex(data->timermap_lock); if (entry) { if (!entry->timer->canceled) { diff --git a/test/testatomic.c b/test/testatomic.c index a05834080..7bcceb559 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -412,7 +412,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event int delta; SDL_bool status = SDL_FALSE; - SDL_mutexP(queue->mutex); + SDL_LockMutex(queue->mutex); queue_pos = (unsigned)queue->enqueue_pos.value; entry = &queue->entries[queue_pos & WRAP_MASK]; @@ -432,7 +432,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event printf("ERROR: mutex failed!\n"); } - SDL_mutexV(queue->mutex); + SDL_UnlockMutex(queue->mutex); return status; } @@ -445,7 +445,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) int delta; SDL_bool status = SDL_FALSE; - SDL_mutexP(queue->mutex); + SDL_LockMutex(queue->mutex); queue_pos = (unsigned)queue->dequeue_pos.value; entry = &queue->entries[queue_pos & WRAP_MASK]; @@ -465,7 +465,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) printf("ERROR: mutex failed!\n"); } - SDL_mutexV(queue->mutex); + SDL_UnlockMutex(queue->mutex); return status; } diff --git a/test/testlock.c b/test/testlock.c index 362d687cf..04abf3d7f 100644 --- a/test/testlock.c +++ b/test/testlock.c @@ -69,14 +69,14 @@ Run(void *data) signal(SIGTERM, closemutex); while (!doterminate) { printf("Process %lu ready to work\n", SDL_ThreadID()); - if (SDL_mutexP(mutex) < 0) { + if (SDL_LockMutex(mutex) < 0) { fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError()); exit(1); } printf("Process %lu, working!\n", SDL_ThreadID()); SDL_Delay(1 * 1000); printf("Process %lu, done!\n", SDL_ThreadID()); - if (SDL_mutexV(mutex) < 0) { + if (SDL_UnlockMutex(mutex) < 0) { fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError()); exit(1); } From 1494812f7c41169d19fda118b6fd44ad5f906711 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 7 Mar 2013 20:42:55 -0800 Subject: [PATCH 066/151] Put the real SDL_AtomicCAS() and SDL_AtomicCASPtr() symbols into the library. --- include/SDL_atomic.h | 6 ++---- src/atomic/SDL_atomic.c | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index bba530102..c89d0b71d 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -196,9 +196,8 @@ typedef struct { int value; } SDL_atomic_t; * \note If you don't know what this function is for, you shouldn't use it! */ #ifndef SDL_AtomicCAS -#define SDL_AtomicCAS SDL_AtomicCAS_ +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval); #endif -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval); /** * \brief Set an atomic variable to a value. @@ -271,9 +270,8 @@ static __inline__ int SDL_AtomicAdd(SDL_atomic_t *a, int v) * \note If you don't know what this function is for, you shouldn't use it! */ #ifndef SDL_AtomicCASPtr -#define SDL_AtomicCASPtr SDL_AtomicCASPtr_ +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void* *a, void *oldval, void *newval); #endif -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr_(void* *a, void *oldval, void *newval); /** * \brief Set a pointer to a value atomically. diff --git a/src/atomic/SDL_atomic.c b/src/atomic/SDL_atomic.c index 34a298edc..6cf2384a5 100644 --- a/src/atomic/SDL_atomic.c +++ b/src/atomic/SDL_atomic.c @@ -27,6 +27,8 @@ doesn't have that compiler. That way we always have a working set of atomic operations built into the library. */ +#undef SDL_AtomicCAS +#undef SDL_AtomicCASPtr /* If any of the operations are not provided then we must emulate some @@ -69,8 +71,8 @@ leaveLock(void *a) SDL_AtomicUnlock(&locks[index]); } -SDL_bool -SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval) +DECLSPEC SDL_bool SDLCALL +SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval) { SDL_bool retval = SDL_FALSE; @@ -84,8 +86,8 @@ SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval) return retval; } -SDL_bool -SDL_AtomicCASPtr_(void **a, void *oldval, void *newval) +DECLSPEC SDL_bool SDLCALL +SDL_AtomicCASPtr(void **a, void *oldval, void *newval) { SDL_bool retval = SDL_FALSE; From 3f118b42fe1e868a3cd0ac4eebe47072cbbd0bfc Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Fri, 8 Mar 2013 11:30:25 -0300 Subject: [PATCH 067/151] README.android updates regarding the use of dirty rectangles rendering technique --- README.android | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.android b/README.android index ad1d7ef35..15738c960 100644 --- a/README.android +++ b/README.android @@ -348,11 +348,29 @@ When you're done instrumenting with valgrind, you can disable the wrapper: ================================================================================ Support for OpenGL ES/ES2 applications was introduced in the NDK for API level 9, -which has since then been obsoleted, and the recommendation to developers was to +which has since then been obsoleted, with the recommendation to developers to bump the required level to 10. As of this writing, according to http://developer.android.com/about/dashboards/index.html about 90% of the existing Android devices support an API level 10 or higher. +================================================================================ + A note regarding the use of the "dirty rectangles" rendering technique +================================================================================ + +If your app uses a variation of the "dirty rectangles" rendering technique, +where you only update a portion of the screen on each frame, you may notice a +variety of visual glitches on Android, that are not present on other platforms. +This is caused by SDL's use of EGL as the support system to handle OpenGL ES/ES2 +contexts, in particular the use of the eglSwapBuffers function. As stated in the +documentation for the function "The contents of ancillary buffers are always +undefined after calling eglSwapBuffers". +Setting the EGL_SWAP_BEHAVIOR attribute of the surface to EGL_BUFFER_PRESERVED +is not possible for SDL as it requires EGL 1.4, available only on the API level +17+, so the only workaround available on this platform is to redraw the entire +screen each frame. + +Reference: http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html + ================================================================================ Known issues ================================================================================ From 7f2340dc6a56a9cd1161d44c37af438ea97c87b6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 8 Mar 2013 10:09:51 -0800 Subject: [PATCH 068/151] Don't re-read the hints when opening the game controller. Instead use SDL_GameControllerAddMapping() to add hints after initialization. --- include/SDL_hints.h | 3 +++ src/joystick/SDL_gamecontroller.c | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 66da58f23..a0b21039c 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -209,6 +209,9 @@ extern "C" { * \brief A variable that lets you manually hint extra gamecontroller db entries * * The variable expected newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h + * + * This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) + * You can update hints after the system is initialized with SDL_GameControllerAddMapping() */ #define SDL_HINT_GAMECONTROLLERCONFIG "SDL_GAMECONTROLLERCONFIG" diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 90fb7b903..e4929a30b 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -879,8 +879,6 @@ SDL_GameControllerOpen(int device_index) } // Find a controller mapping - // Check for hints in case someone has changed them recently - SDL_GameControllerLoadHints(); pSupportedController = SDL_PrivateGetControllerMapping(device_index); if ( !pSupportedController ) { SDL_SetError("Couldn't find mapping for device (%d)", device_index ); From bd9fdb80997316ea8f68614d4f81eeb44fe86e7e Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 8 Mar 2013 11:38:08 -0500 Subject: [PATCH 069/151] Changed SDL_INIT_EVERYTHING to only request currently-known subsystems. --- include/SDL.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/SDL.h b/include/SDL.h index 01613da6c..ac468ffd8 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -114,7 +114,10 @@ extern "C" { #define SDL_INIT_HAPTIC 0x00001000 #define SDL_INIT_GAMECONTROLLER 0x00002000 /**< turn on game controller also implicitly does JOYSTICK */ #define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */ -#define SDL_INIT_EVERYTHING 0x0000FFFF +#define SDL_INIT_EVERYTHING ( \ + SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | \ + SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \ + ) /*@}*/ /** From f41de44a36d84a8a2df92fc8d9023929845a6580 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 8 Mar 2013 16:27:05 -0800 Subject: [PATCH 070/151] Updated SDL_HINT_GAMECONTROLLERCONFIG documentation to reflect that it only takes effect before init. --- include/SDL_hints.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index a0b21039c..9c1080c53 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -205,13 +205,14 @@ extern "C" { */ #define SD_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED" + /** * \brief A variable that lets you manually hint extra gamecontroller db entries - * - * The variable expected newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h + * + * The variable should be newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h * * This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) - * You can update hints after the system is initialized with SDL_GameControllerAddMapping() + * You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping() */ #define SDL_HINT_GAMECONTROLLERCONFIG "SDL_GAMECONTROLLERCONFIG" From 5916b2bc1ed796784cf14952932818a8735ee9aa Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Fri, 8 Mar 2013 23:04:53 -0800 Subject: [PATCH 071/151] Fix Bug 1533 - SDL_Keycode value range allows segfaults with negative values; add test coverage to keyboard suite --- src/events/SDL_keyboard.c | 9 +- test/testautomation_keyboard.c | 181 +++++++++++++++++++++++---------- 2 files changed, 133 insertions(+), 57 deletions(-) diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index c79eaf462..3454bf8bb 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -861,7 +861,7 @@ SDL_GetKeyFromScancode(SDL_Scancode scancode) { SDL_Keyboard *keyboard = &SDL_keyboard; - if (scancode= SDL_NUM_SCANCODES) { + if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { SDL_InvalidParamError("scancode"); return 0; } @@ -887,8 +887,13 @@ SDL_GetScancodeFromKey(SDL_Keycode key) const char * SDL_GetScancodeName(SDL_Scancode scancode) { - const char *name = SDL_scancode_names[scancode]; + const char *name; + if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { + SDL_InvalidParamError("scancode"); + return ""; + } + name = SDL_scancode_names[scancode]; if (name) return name; else diff --git a/test/testautomation_keyboard.c b/test/testautomation_keyboard.c index 588b1c235..ca6d2e355 100644 --- a/test/testautomation_keyboard.c +++ b/test/testautomation_keyboard.c @@ -3,6 +3,7 @@ */ #include +#include #include "SDL_config.h" #include "SDL.h" @@ -103,6 +104,25 @@ keyboard_getKeyFromName(void *arg) return TEST_COMPLETED; } +/* + * Local helper to check for the invalid scancode error message + */ +void +_checkInvalidScancodeError() +{ + const char *expectedError = "Parameter 'scancode' is invalid"; + const char *error; + error = SDL_GetError(); + SDLTest_AssertPass("Call to SDL_GetError()"); + SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); + if (error != NULL) { + SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, + "Validate error message, expected: '%s', got: '%s'", expectedError, error); + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + } +} + /** * @brief Check call to SDL_GetKeyFromScancode * @@ -111,8 +131,6 @@ keyboard_getKeyFromName(void *arg) int keyboard_getKeyFromScancode(void *arg) { - const char *expectedError = "Parameter 'scancode' is invalid"; - const char *error; SDL_Keycode result; /* Case where input is valid */ @@ -125,6 +143,7 @@ keyboard_getKeyFromScancode(void *arg) SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)"); SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result); + /* Clear error message */ SDL_ClearError(); SDLTest_AssertPass("Call to SDL_ClearError()"); @@ -132,31 +151,13 @@ keyboard_getKeyFromScancode(void *arg) result = SDL_GetKeyFromScancode(-999); SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)"); SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidScancodeError(); /* Case where input is invalid (too big) */ result = SDL_GetKeyFromScancode(999); SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)"); SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidScancodeError(); return TEST_COMPLETED; } @@ -217,6 +218,78 @@ keyboard_getKeyName(void *arg) return TEST_COMPLETED; } +/** + * @brief SDL_GetScancodeName negative cases + * + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName + */ +int +keyboard_getScancodeNameNegative(void *arg) +{ + SDL_Scancode scancode; + char *result; + char *expected = ""; + + /* Clear error message */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + /* Negative scancode */ + scancode = (SDL_Scancode)SDLTest_RandomIntegerInRange(LONG_MIN, -1); + result = (char *)SDL_GetScancodeName(scancode); + SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/negative)", scancode); + SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL"); + SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result); + _checkInvalidScancodeError(); + + /* Large scancode */ + scancode = (SDL_Scancode)SDLTest_RandomIntegerInRange(SDL_NUM_SCANCODES, LONG_MAX); + result = (char *)SDL_GetScancodeName(scancode); + SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/large)", scancode); + SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL"); + SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result); + _checkInvalidScancodeError(); + + return TEST_COMPLETED; +} + +/** + * @brief SDL_GetKeyName negative cases + * + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName + */ +int +keyboard_getKeyNameNegative(void *arg) +{ + SDL_Keycode keycode; + char *result; + char *expected = ""; + + /* Unknown keycode */ + keycode = SDLK_UNKNOWN; + result = (char *)SDL_GetKeyName(keycode); + SDLTest_AssertPass("Call to SDL_GetKeyName(%d/unknown)", keycode); + SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL"); + SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result); + + /* Clear error message */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + /* Negative keycode */ + keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1); + result = (char *)SDL_GetKeyName(keycode); + SDLTest_AssertPass("Call to SDL_GetKeyName(%d/negative)", keycode); + SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL"); + SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result); + _checkInvalidScancodeError(); + + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + return TEST_COMPLETED; +} + /** * @brief Check call to SDL_GetModState and SDL_SetModState * @@ -521,6 +594,25 @@ keyboard_getScancodeFromName(void *arg) return TEST_COMPLETED; } +/* + * Local helper to check for the invalid scancode error message + */ +void +_checkInvalidNameError() +{ + const char *expectedError = "Parameter 'name' is invalid"; + const char *error; + error = SDL_GetError(); + SDLTest_AssertPass("Call to SDL_GetError()"); + SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); + if (error != NULL) { + SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, + "Validate error message, expected: '%s', got: '%s'", expectedError, error); + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + } +} + /** * @brief Check call to SDL_GetScancodeFromName with invalid data * @@ -532,9 +624,8 @@ keyboard_getScancodeFromNameNegative(void *arg) { char *name; SDL_Scancode scancode; - const char *expectedError = "Parameter 'name' is invalid"; - const char *error; + /* Clear error message */ SDL_ClearError(); SDLTest_AssertPass("Call to SDL_ClearError()"); @@ -548,48 +639,21 @@ keyboard_getScancodeFromNameNegative(void *arg) SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name); SDL_free(name); SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidNameError(); /* Zero length string input */ name = ""; scancode = SDL_GetScancodeFromName((const char *)name); SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidNameError(); /* NULL input */ name = NULL; scancode = SDL_GetScancodeFromName((const char *)name); SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidNameError(); return TEST_COMPLETED; } @@ -635,10 +699,17 @@ static const SDLTest_TestCaseReference keyboardTest11 = static const SDLTest_TestCaseReference keyboardTest12 = { (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED }; +static const SDLTest_TestCaseReference keyboardTest13 = + { (SDLTest_TestCaseFp)keyboard_getKeyNameNegative, "keyboard_getKeyNameNegative", "Check call to SDL_GetKeyName with invalid data", TEST_ENABLED }; + +static const SDLTest_TestCaseReference keyboardTest14 = + { (SDLTest_TestCaseFp)keyboard_getScancodeNameNegative, "keyboard_getScancodeNameNegative", "Check call to SDL_GetScancodeName with invalid data", TEST_ENABLED }; + /* Sequence of Keyboard test cases */ static const SDLTest_TestCaseReference *keyboardTests[] = { &keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, - &keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12, NULL + &keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12, + &keyboardTest13, &keyboardTest14, NULL }; /* Keyboard test suite (global) */ From edbf26b139ce12d34efe6aec4a2f26cdb544abda Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Fri, 8 Mar 2013 23:33:07 -0800 Subject: [PATCH 072/151] Add parameter checking to SetWindowSize functions; add tests to video suite --- include/SDL_video.h | 23 +- src/video/SDL_video.c | 77 +++-- test/testautomation_video.c | 593 +++++++++++++++++++++++++++++------- 3 files changed, 545 insertions(+), 148 deletions(-) diff --git a/include/SDL_video.h b/include/SDL_video.h index 8c3978ade..d20c7c27c 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -504,6 +504,9 @@ extern DECLSPEC void SDLCALL SDL_SetWindowPosition(SDL_Window * window, /** * \brief Get the position of a window. * + * \param x Pointer to variable for storing the x position, may be NULL + * \param y Pointer to variable for storing the y position, may be NULL + * * \sa SDL_SetWindowPosition() */ extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window * window, @@ -512,6 +515,9 @@ extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window * window, /** * \brief Set the size of a window's client area. * + * \param w The width of the window, must be >0 + * \param h The height of the window, must be >0 + * * \note You can't change the size of a fullscreen window, it automatically * matches the size of the display mode. * @@ -523,6 +529,9 @@ extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window * window, int w, /** * \brief Get the size of a window's client area. * + * \param w Pointer to variable for storing the width, may be NULL + * \param h Pointer to variable for storing the height, may be NULL + * * \sa SDL_SetWindowSize() */ extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w, @@ -530,6 +539,9 @@ extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w, /** * \brief Set the minimum size of a window's client area. + * + * \param min_w The minimum width of the window, must be >0 + * \param min_h The minimum height of the window, must be >0 * * \note You can't change the minimum size of a fullscreen window, it * automatically matches the size of the display mode. @@ -542,7 +554,10 @@ extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window, /** * \brief Get the minimum size of a window's client area. - * + * + * \param w Pointer to variable for storing the minimum width, may be NULL + * \param h Pointer to variable for storing the minimum height, may be NULL + * * \sa SDL_GetWindowMaximumSize() * \sa SDL_SetWindowMinimumSize() */ @@ -552,6 +567,9 @@ extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window, /** * \brief Set the maximum size of a window's client area. * + * \param max_w The maximum width of the window, must be >0 + * \param max_h The maximum height of the window, must be >0 + * * \note You can't change the maximum size of a fullscreen window, it * automatically matches the size of the display mode. * @@ -563,6 +581,9 @@ extern DECLSPEC void SDLCALL SDL_SetWindowMaximumSize(SDL_Window * window, /** * \brief Get the maximum size of a window's client area. + * + * \param w Pointer to variable for storing the maximum width, may be NULL + * \param h Pointer to variable for storing the maximum height, may be NULL * * \sa SDL_GetWindowMinimumSize() * \sa SDL_SetWindowMaximumSize() diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 8ea6e4243..0d48778f4 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1566,6 +1566,14 @@ void SDL_SetWindowSize(SDL_Window * window, int w, int h) { CHECK_WINDOW_MAGIC(window, ); + if (w <= 0) { + SDL_InvalidParamError("w"); + return; + } + if (h <= 0) { + SDL_InvalidParamError("h"); + return; + } /* FIXME: Should this change fullscreen modes? */ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { @@ -1584,30 +1592,27 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h) void SDL_GetWindowSize(SDL_Window * window, int *w, int *h) { - int dummy; - - if (!w) { - w = &dummy; - } - if (!h) { - h = &dummy; - } - - *w = 0; - *h = 0; - CHECK_WINDOW_MAGIC(window, ); - - if (_this && window && window->magic == &_this->window_magic) { + if (w) { *w = window->w; - *h = window->h; } + if (h) { + *h = window->h; + } } void SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h) { CHECK_WINDOW_MAGIC(window, ); + if (min_w <= 0) { + SDL_InvalidParamError("min_w"); + return; + } + if (min_h <= 0) { + SDL_InvalidParamError("min_h"); + return; + } if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { window->min_w = min_w; @@ -1623,22 +1628,11 @@ SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h) void SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h) { - int dummy; - - if (!min_w) { - min_w = &dummy; - } - if (!min_h) { - min_h = &dummy; - } - - *min_w = 0; - *min_h = 0; - CHECK_WINDOW_MAGIC(window, ); - - if (_this && window && window->magic == &_this->window_magic) { + if (min_w) { *min_w = window->min_w; + } + if (min_h) { *min_h = window->min_h; } } @@ -1647,6 +1641,14 @@ void SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h) { CHECK_WINDOW_MAGIC(window, ); + if (max_w <= 0) { + SDL_InvalidParamError("max_w"); + return; + } + if (max_h <= 0) { + SDL_InvalidParamError("max_h"); + return; + } if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { window->max_w = max_w; @@ -1662,22 +1664,11 @@ SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h) void SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h) { - int dummy; - - if (!max_w) { - max_w = &dummy; - } - if (!max_h) { - max_h = &dummy; - } - - *max_w = 0; - *max_h = 0; - CHECK_WINDOW_MAGIC(window, ); - - if (_this && window && window->magic == &_this->window_magic) { + if (max_w) { *max_w = window->max_w; + } + if (max_h) { *max_h = window->max_h; } } diff --git a/test/testautomation_video.c b/test/testautomation_video.c index e9a632481..be10baa70 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -33,7 +33,7 @@ SDL_Window *_createVideoSuiteTestWindow(const char *title) y = SDLTest_RandomIntegerInRange(1, 100); w = SDLTest_RandomIntegerInRange(320, 1024); h = SDLTest_RandomIntegerInRange(320, 768); - flags = SDL_WINDOW_SHOWN; + flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS; window = SDL_CreateWindow(title, x, y, w, h, flags); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); @@ -315,7 +315,6 @@ video_createWindowVariousFlags(void *arg) SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - /* Clean up */ _destroyVideoSuiteTestWindow(window); } @@ -596,6 +595,25 @@ video_getWindowDisplayMode(void *arg) return TEST_COMPLETED; } +/* Helper function that checks for an 'Invalid window' error */ +void _checkInvalidWindowError() +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + } +} + /** * @brief Tests call to SDL_GetWindowDisplayMode with invalid input * @@ -605,7 +623,6 @@ int video_getWindowDisplayModeNegative(void *arg) { const char *expectedError = "Parameter 'mode' is invalid"; - const char *invalidWindowError = "Invalid window"; char *lastError; SDL_Window* window; const char* title = "video_getWindowDisplayModeNegative Test Window"; @@ -636,16 +653,8 @@ video_getWindowDisplayModeNegative(void *arg) result = SDL_GetWindowDisplayMode(NULL, &mode); SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)"); SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } - + _checkInvalidWindowError(); + return TEST_COMPLETED; } @@ -718,28 +727,21 @@ video_getWindowGammaRamp(void *arg) int video_getWindowGammaRampNegative(void *arg) { - const char *invalidWindowError = "Invalid window"; - char *lastError; const char* title = "video_getWindowGammaRampNegative Test Window"; Uint16 red[256]; Uint16 green[256]; Uint16 blue[256]; int result; + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + /* Call against invalid window */ result = SDL_GetWindowGammaRamp(NULL, red, green, blue); SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)"); SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %f", result); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } - + _checkInvalidWindowError(); + return TEST_COMPLETED; } @@ -772,8 +774,6 @@ _setAndCheckWindowGrabState(SDL_Window* window, SDL_bool desiredState) int video_getSetWindowGrab(void *arg) { - const char *invalidWindowError = "Invalid window"; - char *lastError; const char* title = "video_getSetWindowGrab Test Window"; SDL_Window* window; SDL_bool originalState, dummyState, currentState, desiredState; @@ -804,39 +804,15 @@ video_getSetWindowGrab(void *arg) /* Negative tests */ dummyState = SDL_GetWindowGrab(NULL); SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)"); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } + _checkInvalidWindowError(); SDL_SetWindowGrab(NULL, SDL_FALSE); SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)"); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } + _checkInvalidWindowError(); SDL_SetWindowGrab(NULL, SDL_TRUE); SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)"); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } + _checkInvalidWindowError(); /* State should still be F */ desiredState = SDL_FALSE; @@ -857,6 +833,7 @@ video_getSetWindowGrab(void *arg) return TEST_COMPLETED; } + /** * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID * @@ -866,8 +843,6 @@ video_getSetWindowGrab(void *arg) int video_getWindowId(void *arg) { - const char *invalidWindowError = "Invalid window"; - char *lastError; const char* title = "video_getWindowId Test Window"; SDL_Window* window; SDL_Window* result; @@ -906,18 +881,12 @@ video_getWindowId(void *arg) SDLTest_AssertCheck(result == NULL, "Verify result is NULL"); /* Negative test */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); id = SDL_GetWindowID(NULL); SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)"); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } - + _checkInvalidWindowError(); + return TEST_COMPLETED; } @@ -929,8 +898,6 @@ video_getWindowId(void *arg) int video_getWindowPixelFormat(void *arg) { - const char *invalidWindowError = "Invalid window"; - char *lastError; const char* title = "video_getWindowPixelFormat Test Window"; SDL_Window* window; Uint32 format; @@ -948,17 +915,11 @@ video_getWindowPixelFormat(void *arg) _destroyVideoSuiteTestWindow(window); /* Negative test */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); format = SDL_GetWindowPixelFormat(NULL); SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)"); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } + _checkInvalidWindowError(); return TEST_COMPLETED; } @@ -972,8 +933,6 @@ video_getWindowPixelFormat(void *arg) int video_getSetWindowPosition(void *arg) { - const char *invalidWindowError = "Invalid window"; - char *lastError; const char* title = "video_getSetWindowPosition Test Window"; SDL_Window* window; int xVariation, yVariation; @@ -1065,8 +1024,10 @@ video_getSetWindowPosition(void *arg) currentY = referenceY; desiredX = SDLTest_RandomSint32(); desiredY = SDLTest_RandomSint32(); - + /* Negative tests */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); SDL_GetWindowPosition(NULL, ¤tX, ¤tY); SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)"); SDLTest_AssertCheck( @@ -1074,39 +1035,453 @@ video_getSetWindowPosition(void *arg) "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d", referenceX, referenceY, currentX, currentY); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } + _checkInvalidWindowError(); SDL_GetWindowPosition(NULL, NULL, NULL); SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)"); - lastError = (char *)SDL_GetError(); - SDLTest_AssertPass("SDL_GetError()"); - SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); - if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, - lastError); - } + _checkInvalidWindowError(); SDL_SetWindowPosition(NULL, desiredX, desiredY); SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)"); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/* Helper function that checks for an 'Invalid parameter' error */ +void _checkInvalidParameterError() +{ + const char *invalidParameterError = "Parameter"; + char *lastError; + lastError = (char *)SDL_GetError(); SDLTest_AssertPass("SDL_GetError()"); SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); if (lastError != NULL) { - SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, - "SDL_GetError(): expected message '%s', was message: '%s'", - invalidWindowError, + SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0, + "SDL_GetError(): expected message starts with '%s', was message: '%s'", + invalidParameterError, lastError); + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); } +} + +/** + * @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowSize + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowSize + */ +int +video_getSetWindowSize(void *arg) +{ + const char* title = "video_getSetWindowSize Test Window"; + SDL_Window* window; + int result; + SDL_Rect display; + int wVariation, hVariation; + int referenceW, referenceH; + int currentW, currentH; + int desiredW, desiredH; + + /* Get display bounds for size range */ + result = SDL_GetDisplayBounds(0, &display); + SDLTest_AssertPass("SDL_GetDisplayBounds()"); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + if (result != 0) return TEST_ABORTED; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + for (wVariation = 0; wVariation < 4; wVariation++) { + for (hVariation = 0; hVariation < 4; hVariation++) { + switch(wVariation) { + case 0: + /* 1 Pixel Wide */ + desiredW = 1; + break; + case 1: + /* Random width inside screen */ + desiredW = SDLTest_RandomIntegerInRange(1, 100); + break; + case 2: + /* Width at screen size */ + desiredW = display.w; + break; + case 3: + /* Width 1 pixel larger than screen */ + desiredW = display.w + 1; + break; + } + + switch(hVariation) { + case 0: + /* 1 Pixel High */ + desiredH = 1; + break; + case 1: + /* Random height inside screen */ + desiredH = SDLTest_RandomIntegerInRange(1, 100); + break; + case 2: + /* Height at screen size */ + desiredH = display.h; + break; + case 3: + /* Height 1 pixel larger than screen */ + desiredH = display.h + 1; + break; + } + + /* Set size */ + SDL_SetWindowSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH); + + /* Get size */ + currentW = desiredW + 1; + currentH = desiredH + 1; + SDL_GetWindowSize(window, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowSize()"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); + + /* Get just width */ + currentW = desiredW + 1; + SDL_GetWindowSize(window, ¤tW, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); + + /* Get just height */ + currentH = desiredH + 1; + SDL_GetWindowSize(window, NULL, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)"); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); + } + } + + /* Dummy call with both pointers NULL */ + SDL_GetWindowSize(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)"); + + /* Negative tests for parameter input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + for (desiredH = -2; desiredH < 2; desiredH++) { + for (desiredW = -2; desiredW < 2; desiredW++) { + if (desiredW <= 0 || desiredH <= 0) { + SDL_SetWindowSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH); + _checkInvalidParameterError(); + } + } + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Set some 'magic' value for later check that nothing was changed */ + referenceW = SDLTest_RandomSint32(); + referenceH = SDLTest_RandomSint32(); + currentW = referenceW; + currentH = referenceH; + desiredW = SDLTest_RandomSint32(); + desiredH = SDLTest_RandomSint32(); + + /* Negative tests for window input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + SDL_GetWindowSize(NULL, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)"); + SDLTest_AssertCheck( + currentW == referenceW && currentH == referenceH, + "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", + referenceW, referenceH, + currentW, currentH); + _checkInvalidWindowError(); + + SDL_GetWindowSize(NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)"); + _checkInvalidWindowError(); + + SDL_SetWindowSize(NULL, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)"); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize + * + */ +int +video_getSetWindowMinimumSize(void *arg) +{ + const char* title = "video_getSetWindowMinimumSize Test Window"; + SDL_Window* window; + int result; + SDL_Rect display; + int wVariation, hVariation; + int referenceW, referenceH; + int currentW, currentH; + int desiredW, desiredH; + + /* Get display bounds for size range */ + result = SDL_GetDisplayBounds(0, &display); + SDLTest_AssertPass("SDL_GetDisplayBounds()"); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + if (result != 0) return TEST_ABORTED; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + for (wVariation = 0; wVariation < 5; wVariation++) { + for (hVariation = 0; hVariation < 5; hVariation++) { + switch(wVariation) { + case 0: + /* 1 Pixel Wide */ + desiredW = 1; + break; + case 1: + /* Random width inside screen */ + desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1); + break; + case 2: + /* Width at screen size */ + desiredW = display.w; + break; + } + + switch(hVariation) { + case 0: + /* 1 Pixel High */ + desiredH = 1; + break; + case 1: + /* Random height inside screen */ + desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1); + break; + case 2: + /* Height at screen size */ + desiredH = display.h; + break; + case 4: + /* Height 1 pixel larger than screen */ + desiredH = display.h + 1; + break; + } + + /* Set size */ + SDL_SetWindowMinimumSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH); + + /* Get size */ + currentW = desiredW + 1; + currentH = desiredH + 1; + SDL_GetWindowMinimumSize(window, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); + + /* Get just width */ + currentW = desiredW + 1; + SDL_GetWindowMinimumSize(window, ¤tW, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); + + /* Get just height */ + currentH = desiredH + 1; + SDL_GetWindowMinimumSize(window, NULL, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)"); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); + } + } + + /* Dummy call with both pointers NULL */ + SDL_GetWindowMinimumSize(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)"); + + /* Negative tests for parameter input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + for (desiredH = -2; desiredH < 2; desiredH++) { + for (desiredW = -2; desiredW < 2; desiredW++) { + if (desiredW <= 0 || desiredH <= 0) { + SDL_SetWindowMinimumSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH); + _checkInvalidParameterError(); + } + } + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Set some 'magic' value for later check that nothing was changed */ + referenceW = SDLTest_RandomSint32(); + referenceH = SDLTest_RandomSint32(); + currentW = referenceW; + currentH = referenceH; + desiredW = SDLTest_RandomSint32(); + desiredH = SDLTest_RandomSint32(); + + /* Negative tests for window input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + SDL_GetWindowMinimumSize(NULL, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)"); + SDLTest_AssertCheck( + currentW == referenceW && currentH == referenceH, + "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", + referenceW, referenceH, + currentW, currentH); + _checkInvalidWindowError(); + + SDL_GetWindowMinimumSize(NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)"); + _checkInvalidWindowError(); + + SDL_SetWindowMinimumSize(NULL, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)"); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize + * + */ +int +video_getSetWindowMaximumSize(void *arg) +{ + const char* title = "video_getSetWindowMaximumSize Test Window"; + SDL_Window* window; + int result; + SDL_Rect display; + int wVariation, hVariation; + int referenceW, referenceH; + int currentW, currentH; + int desiredW, desiredH; + + /* Get display bounds for size range */ + result = SDL_GetDisplayBounds(0, &display); + SDLTest_AssertPass("SDL_GetDisplayBounds()"); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + if (result != 0) return TEST_ABORTED; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + for (wVariation = 0; wVariation < 3; wVariation++) { + for (hVariation = 0; hVariation < 3; hVariation++) { + switch(wVariation) { + case 0: + /* 1 Pixel Wide */ + desiredW = 1; + break; + case 1: + /* Random width inside screen */ + desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1); + break; + case 2: + /* Width at screen size */ + desiredW = display.w; + break; + } + + switch(hVariation) { + case 0: + /* 1 Pixel High */ + desiredH = 1; + break; + case 1: + /* Random height inside screen */ + desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1); + break; + case 2: + /* Height at screen size */ + desiredH = display.h; + break; + } + + /* Set size */ + SDL_SetWindowMaximumSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH); + + /* Get size */ + currentW = desiredW + 1; + currentH = desiredH + 1; + SDL_GetWindowMaximumSize(window, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); + + /* Get just width */ + currentW = desiredW + 1; + SDL_GetWindowMaximumSize(window, ¤tW, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); + + /* Get just height */ + currentH = desiredH + 1; + SDL_GetWindowMaximumSize(window, NULL, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)"); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); + } + } + + /* Dummy call with both pointers NULL */ + SDL_GetWindowMaximumSize(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)"); + + /* Negative tests for parameter input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + for (desiredH = -2; desiredH < 2; desiredH++) { + for (desiredW = -2; desiredW < 2; desiredW++) { + if (desiredW <= 0 || desiredH <= 0) { + SDL_SetWindowMaximumSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH); + _checkInvalidParameterError(); + } + } + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Set some 'magic' value for later check that nothing was changed */ + referenceW = SDLTest_RandomSint32(); + referenceH = SDLTest_RandomSint32(); + currentW = referenceW; + currentH = referenceH; + desiredW = SDLTest_RandomSint32(); + desiredH = SDLTest_RandomSint32(); + + /* Negative tests */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + SDL_GetWindowMaximumSize(NULL, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)"); + SDLTest_AssertCheck( + currentW == referenceW && currentH == referenceH, + "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", + referenceW, referenceH, + currentW, currentH); + _checkInvalidWindowError(); + + SDL_GetWindowMaximumSize(NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)"); + _checkInvalidWindowError(); + + SDL_SetWindowMaximumSize(NULL, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)"); + _checkInvalidWindowError(); return TEST_COMPLETED; } @@ -1160,7 +1535,7 @@ static const SDLTest_TestCaseReference videoTest15 = { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED }; static const SDLTest_TestCaseReference videoTest16 = - { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab", TEST_ENABLED }; + { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED }; static const SDLTest_TestCaseReference videoTest17 = { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED }; @@ -1169,14 +1544,24 @@ static const SDLTest_TestCaseReference videoTest18 = { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED }; static const SDLTest_TestCaseReference videoTest19 = - { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition", TEST_ENABLED }; + { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest20 = + { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest21 = + { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest22 = + { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED }; /* Sequence of Video test cases */ static const SDLTest_TestCaseReference *videoTests[] = { &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17, - &videoTest18, &videoTest19, NULL + &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22, + NULL }; /* Video test suite (global) */ From c51712467d1274481d5a69be37ca9bc76e1c4eea Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Sat, 9 Mar 2013 09:24:43 -0800 Subject: [PATCH 073/151] Fix SDL_TryLockMutex compile error when FAKE_RECURSIVE_MUTEX is defined --- src/thread/pthread/SDL_sysmutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index f67cdf6c4..faf178771 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -134,7 +134,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) retval = 0; #if FAKE_RECURSIVE_MUTEX this_thread = pthread_self(); - if (mutex->owner == this_thead) { + if (mutex->owner == this_thread) { ++mutex->recursive; } else { /* The order of operations is important. From 7ce1b4475f417b682669b7205bc851c6b36cb9b6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 9 Mar 2013 10:35:12 -0800 Subject: [PATCH 074/151] Fixed bug 1744 - DirectFB video and renderer API is not updated tomaszewski.p Recent changes in SDL_sysrenderer.h and SDL_sysvideo.h had no impact on directfb backend. Attached patch: - updates interface, - resolves uninitialized variable reading, - changes logging tio use SDL_Log API, - updates configure to use DIRECTFBCONFIG variable instead direct call to directfb-config. --- configure | 2 +- configure.in | 2 +- src/video/directfb/SDL_DirectFB_render.c | 45 +++++++++++++++--------- src/video/directfb/SDL_DirectFB_video.c | 3 +- src/video/directfb/SDL_DirectFB_video.h | 20 +++-------- src/video/directfb/SDL_DirectFB_window.c | 10 ++++-- src/video/directfb/SDL_DirectFB_window.h | 2 +- 7 files changed, 47 insertions(+), 37 deletions(-) diff --git a/configure b/configure index 77df3dac4..b6811fe34 100755 --- a/configure +++ b/configure @@ -20263,7 +20263,7 @@ fi else set -- `echo $DIRECTFB_REQUIRED_VERSION | sed 's/\./ /g'` NEED_VERSION=`expr $1 \* 10000 + $2 \* 100 + $3` - set -- `directfb-config --version | sed 's/\./ /g'` + set -- `$DIRECTFBCONFIG --version | sed 's/\./ /g'` HAVE_VERSION=`expr $1 \* 10000 + $2 \* 100 + $3` if test $HAVE_VERSION -ge $NEED_VERSION; then DIRECTFB_CFLAGS=`$DIRECTFBCONFIG --cflags` diff --git a/configure.in b/configure.in index 9a0b7e1a9..84444f3e6 100644 --- a/configure.in +++ b/configure.in @@ -1423,7 +1423,7 @@ AC_HELP_STRING([--enable-video-directfb], [use DirectFB video driver [[default=n else set -- `echo $DIRECTFB_REQUIRED_VERSION | sed 's/\./ /g'` NEED_VERSION=`expr $1 \* 10000 + $2 \* 100 + $3` - set -- `directfb-config --version | sed 's/\./ /g'` + set -- `$DIRECTFBCONFIG --version | sed 's/\./ /g'` HAVE_VERSION=`expr $1 \* 10000 + $2 \* 100 + $3` if test $HAVE_VERSION -ge $NEED_VERSION; then DIRECTFB_CFLAGS=`$DIRECTFBCONFIG --cflags` diff --git a/src/video/directfb/SDL_DirectFB_render.c b/src/video/directfb/SDL_DirectFB_render.c index 9fb0b26b2..c3b810d10 100644 --- a/src/video/directfb/SDL_DirectFB_render.c +++ b/src/video/directfb/SDL_DirectFB_render.c @@ -96,17 +96,17 @@ static void DirectFB_DirtyTexture(SDL_Renderer * renderer, const SDL_Rect * rects); static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer); static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_Point * points, int count); + const SDL_FPoint * points, int count); static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, - const SDL_Point * points, int count); + const SDL_FPoint * points, int count); static int DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count); static int DirectFB_RenderFillRects(SDL_Renderer * renderer, - const SDL_Rect * rects, int count); + const SDL_FRect * rects, int count); static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, - const SDL_Rect * dstrect); + const SDL_FRect * dstrect); static void DirectFB_RenderPresent(SDL_Renderer * renderer); static void DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); @@ -175,6 +175,14 @@ SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr) dr->h = sr->h; dr->w = sr->w; } +static __inline__ void +SDLtoDFBRect_Float(const SDL_FRect * sr, DFBRectangle * dr) +{ + dr->x = sr->x; + dr->y = sr->y; + dr->h = sr->h; + dr->w = sr->w; +} static int @@ -206,6 +214,8 @@ TextureHasAlpha(DirectFB_TextureData * data) static inline IDirectFBSurface *get_dfb_surface(SDL_Window *window) { SDL_SysWMinfo wm_info; + SDL_memset(&wm_info, 0, sizeof(SDL_SysWMinfo)); + SDL_VERSION(&wm_info.version); SDL_GetWindowWMInfo(window, &wm_info); @@ -215,6 +225,8 @@ static inline IDirectFBSurface *get_dfb_surface(SDL_Window *window) static inline IDirectFBWindow *get_dfb_window(SDL_Window *window) { SDL_SysWMinfo wm_info; + SDL_memset(&wm_info, 0, sizeof(SDL_SysWMinfo)); + SDL_VERSION(&wm_info.version); SDL_GetWindowWMInfo(window, &wm_info); @@ -917,7 +929,7 @@ PrepareDraw(SDL_Renderer * renderer) } static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_Point * points, int count) + const SDL_FPoint * points, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = get_dfb_surface(data->window); @@ -934,7 +946,7 @@ static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, } static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, - const SDL_Point * points, int count) + const SDL_FPoint * points, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = get_dfb_surface(data->window); @@ -977,7 +989,7 @@ DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int c } static int -DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int count) +DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = get_dfb_surface(data->window); @@ -998,16 +1010,20 @@ DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int co static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect) + const SDL_Rect * srcrect, const SDL_FRect * dstrect) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = get_dfb_surface(data->window); DirectFB_TextureData *texturedata = (DirectFB_TextureData *) texture->driverdata; Uint8 alpha, r, g, b; + DFBRectangle sr, dr; DirectFB_ActivateRenderer(renderer); + SDLtoDFBRect(srcrect, &sr); + SDLtoDFBRect_Float(dstrect, &dr); + if (texturedata->display) { int px, py; SDL_Window *window = renderer->window; @@ -1018,20 +1034,17 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, SDL_DFB_CHECKERR(dispdata-> vidlayer->SetSourceRectangle(dispdata->vidlayer, - srcrect->x, srcrect->y, - srcrect->w, - srcrect->h)); + sr.x, sr.y, sr.w, sr.h)); dfbwin->GetPosition(dfbwin, &px, &py); px += windata->client.x; py += windata->client.y; SDL_DFB_CHECKERR(dispdata-> vidlayer->SetScreenRectangle(dispdata->vidlayer, - px + dstrect->x, - py + dstrect->y, - dstrect->w, - dstrect->h)); + px + dr.x, + py + dr.y, + dr.w, + dr.h)); } else { - DFBRectangle sr, dr; DFBSurfaceBlittingFlags flags = 0; #if 0 diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c index 71f014b06..3f9bba2ba 100644 --- a/src/video/directfb/SDL_DirectFB_video.c +++ b/src/video/directfb/SDL_DirectFB_video.c @@ -102,8 +102,9 @@ DirectFB_CreateDevice(int devindex) { SDL_VideoDevice *device; - if (!SDL_DirectFB_LoadLibrary()) + if (!SDL_DirectFB_LoadLibrary()) { return NULL; + } /* Initialize all variables that we clean on shutdown */ SDL_DFB_ALLOC_CLEAR(device, sizeof(SDL_VideoDevice)); diff --git a/src/video/directfb/SDL_DirectFB_video.h b/src/video/directfb/SDL_DirectFB_video.h index 1923eadef..4980f7a5c 100644 --- a/src/video/directfb/SDL_DirectFB_video.h +++ b/src/video/directfb/SDL_DirectFB_video.h @@ -31,6 +31,8 @@ #include "SDL_scancode.h" #include "SDL_render.h" +#include "SDL_log.h" + #define DFB_VERSIONNUM(X, Y, Z) \ ((X)*1000 + (Y)*100 + (Z)) @@ -66,7 +68,6 @@ #endif #define DIRECTFB_DEBUG 1 -#define LOG_CHANNEL stdout #define DFBENV_USE_YUV_UNDERLAY "SDL_DIRECTFB_YUV_UNDERLAY" /* Default: off */ #define DFBENV_USE_YUV_DIRECT "SDL_DIRECTFB_YUV_DIRECT" /* Default: off */ @@ -80,23 +81,12 @@ #define SDL_DFB_CONTEXT "SDL_DirectFB" -#define SDL_DFB_ERR(x...) \ - do { \ - fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t", \ - SDL_DFB_CONTEXT, __FILE__, __LINE__ ); \ - fprintf(LOG_CHANNEL, x ); \ - } while (0) +#define SDL_DFB_ERR(x...) SDL_LogError(SDL_LOG_CATEGORY_ERROR, x) #if (DIRECTFB_DEBUG) +#define SDL_DFB_LOG(x...) SDL_LogInfo(SDL_LOG_CATEGORY_VIDEO, x) -#define SDL_DFB_LOG(x...) \ - do { \ - fprintf(LOG_CHANNEL, "%s: ", SDL_DFB_CONTEXT); \ - fprintf(LOG_CHANNEL, x ); \ - fprintf(LOG_CHANNEL, "\n"); \ - } while (0) - -#define SDL_DFB_DEBUG(x...) SDL_DFB_ERR( x ) +#define SDL_DFB_DEBUG(x...) SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, x) static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line) { if (ret != DFB_OK) { diff --git a/src/video/directfb/SDL_DirectFB_window.c b/src/video/directfb/SDL_DirectFB_window.c index 4fc712cfe..6f052b844 100644 --- a/src/video/directfb/SDL_DirectFB_window.c +++ b/src/video/directfb/SDL_DirectFB_window.c @@ -47,6 +47,7 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) int bshaped = 0; SDL_DFB_ALLOC_CLEAR(window->driverdata, sizeof(DFB_WindowData)); + SDL_memset(&desc, 0, sizeof(DFBWindowDescription)); windata = (DFB_WindowData *) window->driverdata; windata->is_managed = devdata->has_own_wm; @@ -89,7 +90,12 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) desc.height = windata->size.h; desc.pixelformat = dispdata->pixelformat; desc.surface_caps = DSCAPS_PREMULTIPLIED; - +#if DIRECTFB_MAJOR_VERSION == 1 && DIRECTFB_MINOR_VERSION >= 4 + if (window->flags & SDL_WINDOW_OPENGL) { + desc.surface_caps |= DSCAPS_GL; + } +#endif + /* Create the window. */ SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc, &windata->dfbwin)); @@ -378,7 +384,7 @@ DirectFB_RestoreWindow(_THIS, SDL_Window * window) } void -DirectFB_SetWindowGrab(_THIS, SDL_Window * window) +DirectFB_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) { SDL_DFB_DEVICEDATA(_this); SDL_DFB_WINDOWDATA(window); diff --git a/src/video/directfb/SDL_DirectFB_window.h b/src/video/directfb/SDL_DirectFB_window.h index 4cbbdc0d7..43a08d308 100644 --- a/src/video/directfb/SDL_DirectFB_window.h +++ b/src/video/directfb/SDL_DirectFB_window.h @@ -69,7 +69,7 @@ extern void DirectFB_RaiseWindow(_THIS, SDL_Window * window); extern void DirectFB_MaximizeWindow(_THIS, SDL_Window * window); extern void DirectFB_MinimizeWindow(_THIS, SDL_Window * window); extern void DirectFB_RestoreWindow(_THIS, SDL_Window * window); -extern void DirectFB_SetWindowGrab(_THIS, SDL_Window * window); +extern void DirectFB_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed); extern void DirectFB_DestroyWindow(_THIS, SDL_Window * window); extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info); From 1bb2a06fc7bee986f0c18ca5e8e6942f5f884418 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 10 Mar 2013 09:03:38 -0700 Subject: [PATCH 075/151] Fixed bug 1748 - Patch for errors and mistakes in SDL 2 README files. Philipp Wiesemann SDL's README files seem to contain multiple errors and mistakes. I attached a patch with changes and updates. README: * removed Windows CE because no more supported README-SDL.txt: * corrected spelling mistake README.DirectFB: * corrected spelling mistakes README.MacOSX: * corrected spelling mistakes README.Platforms: * changed Android version to match AndroidManifest.xml README.Porting: * added missing directories from list * removed cdrom directories from list README.android: * updated required NDK revision * add project.properties to list * changed lower limit for to android-10 and removed upper * added a statement why older devices not supported * added correct dates to statements about OpenGL ES * added info about Google's device numbers and date * corrected spelling mistakes README.gesture: * corrected spelling mistakes README.pandora: * corrected spelling mistake README.touch: * changed that values are no in range 0..1 * updated the names of some functions * updated the notes about usage * corrected spelling mistakes * added info that API changed near original author contact --- README | 2 +- README-SDL.txt | 2 +- README.DirectFB | 6 ++--- README.MacOSX | 14 +++++----- README.Platforms | 2 +- README.Porting | 8 ++++-- README.android | 27 +++++++++++-------- README.gesture | 12 ++++----- README.pandora | 2 +- README.touch | 69 ++++++++++++++++++------------------------------ 10 files changed, 68 insertions(+), 76 deletions(-) diff --git a/README b/README index ad4a364d8..65a07551a 100644 --- a/README +++ b/README @@ -12,7 +12,7 @@ This is the Simple DirectMedia Layer, a general API that provides low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D framebuffer across multiple platforms. -The current version supports Windows, Windows CE, Mac OS X, Linux, FreeBSD, +The current version supports Windows, Mac OS X, Linux, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, iOS, and Android. The code contains support for other operating systems but those are not officially supported. diff --git a/README-SDL.txt b/README-SDL.txt index 1a9feff5c..fade0b958 100644 --- a/README-SDL.txt +++ b/README-SDL.txt @@ -1,7 +1,7 @@ Please distribute this file with the SDL runtime environment: -The Simple DirectMedia Layer (SDL for short) is a cross-platfrom library +The Simple DirectMedia Layer (SDL for short) is a cross-platform library designed to make it easy to write multi-media software, such as games and emulators. diff --git a/README.DirectFB b/README.DirectFB index 68988136b..9c16a7b67 100644 --- a/README.DirectFB +++ b/README.DirectFB @@ -53,7 +53,7 @@ Simple Window Manager ===================== The driver has support for a very, very basic window manager you may -want to use when runnning with "wm=default". Use +want to use when running with "wm=default". Use export SDL_DIRECTFB_WM=1 @@ -62,10 +62,10 @@ you need to have the following font installed: /usr/share/fonts/truetype/freefont/FreeSans.ttf -OPENGL Support +OpenGL Support ============== -The following instructions will give you *software* opengl. However this +The following instructions will give you *software* OpenGL. However this works at least on all directfb supported platforms. As of this writing 20100802 you need to pull Mesa from git and do the following: diff --git a/README.MacOSX b/README.MacOSX index 3bc421371..572a86b19 100644 --- a/README.MacOSX +++ b/README.MacOSX @@ -56,7 +56,7 @@ usually is "TestGame". You might also want to use @PACKAGE@ to use the package name as specified in your configure.in file. If your project builds more than one application, you will have to do a bit -more. For each of your target applications, you need a seperate rule. +more. For each of your target applications, you need a separate rule. If you want the created bundles to be installed, you may want to add this rule to your Makefile.am: @@ -75,13 +75,13 @@ the make rule accordingly. But beware! That is only part of the story! With the above, you end up with a bare bone .app bundle, which is double clickable from the Finder. But -there are some more things you should do before shipping yor product... +there are some more things you should do before shipping your product... 1) The bundle right now probably is dynamically linked against SDL. That means that when you copy it to another computer, *it will not run*, unless you also install SDL on that other computer. A good solution for this dilemma is to static link against SDL. On OS X, you can - achieve that by linkinag against the libraries listed by + achieve that by linking against the libraries listed by sdl-config --static-libs instead of those listed by sdl-config --libs @@ -120,7 +120,7 @@ normally from the Finder. - Building the Framework The SDL Library is packaged as a framework bundle, an organized -relocatable folder heirarchy of executible code, interface headers, +relocatable folder hierarchy of executable code, interface headers, and additional resources. For practical purposes, you can think of a framework as a more user and system-friendly shared library, whose library file behaves more or less like a standard UNIX shared library. @@ -162,11 +162,11 @@ following locations: - Building from command line Use pbxbuild in the same directory as your .pbproj file - + - Running your app You can send command line args to your app by either invoking it from the command line (in *.app/Contents/MacOS) or by entering them in the - "Executibles" panel of the target settings. + "Executables" panel of the target settings. - Implementation Notes Some things that may be of interest about how it all works... @@ -181,6 +181,6 @@ following locations: You are free to modify your Cocoa app with generally no consequence to SDL. You cannot, however, easily change the SDL window itself. Functionality may be added in the future to help this. - + Known bugs are listed in the file "BUGS" diff --git a/README.Platforms b/README.Platforms index 32fb0d083..5009d7152 100644 --- a/README.Platforms +++ b/README.Platforms @@ -11,7 +11,7 @@ Windows 7 Mac OS X 10.4+ Linux 2.6+ iOS 3.1.3+ -Android 2.1+ +Android 2.3.3+ Unofficially supported platforms ================================ diff --git a/README.Porting b/README.Porting index 9bb4613e0..f8540b600 100644 --- a/README.Porting +++ b/README.Porting @@ -26,12 +26,15 @@ There are two basic ways of building SDL at the moment: Add the top level include directory to the header search path, and then add the following sources to the project: src/*.c + src/atomic/*.c src/audio/*.c - src/cdrom/*.c src/cpuinfo/*.c src/events/*.c src/file/*.c + src/haptic/*.c src/joystick/*.c + src/power/*.c + src/render/*.c src/stdlib/*.c src/thread/*.c src/timer/*.c @@ -39,8 +42,9 @@ There are two basic ways of building SDL at the moment: src/audio/disk/*.c src/audio/dummy/*.c src/video/dummy/*.c + src/haptic/dummy/*.c src/joystick/dummy/*.c - src/cdrom/dummy/*.c + src/main/dummy/*.c src/thread/generic/*.c src/timer/dummy/*.c src/loadso/dummy/*.c diff --git a/README.android b/README.android index 15738c960..29d8ca5dd 100644 --- a/README.android +++ b/README.android @@ -7,10 +7,10 @@ Requirements: Android SDK (version 10 or later) http://developer.android.com/sdk/index.html -Android NDK r4 or later +Android NDK r7 or later http://developer.android.com/sdk/ndk/index.html -Minimum API Level supported by SDL: 10 (Android 2.3.3) +Minimum API level supported by SDL: 10 (Android 2.3.3) ================================================================================ How the port works @@ -19,7 +19,7 @@ Minimum API Level supported by SDL: 10 (Android 2.3.3) - Android applications are Java-based, optionally with parts written in C - As SDL apps are C-based, we use a small Java shim that uses JNI to talk to the SDL library -- This means that your application C code must be placed inside an android +- This means that your application C code must be placed inside an Android Java project, along with some C support code that communicates with Java - This eventually produces a standard Android .apk package @@ -60,8 +60,8 @@ android-project/ build.properties - empty build.xml - build description file, used by ant. The actual application name is specified here. - default.properties - holds the target ABI for the application, can range between - android-5 and android-16 + default.properties - holds the target ABI for the application, android-10 and up + project.properties - holds the target ABI for the application, android-10 and up local.properties - holds the SDK path, you should change this to the path to your SDK jni/ - directory holding native code jni/Android.mk - Android makefile that can call recursively the Android.mk files @@ -172,10 +172,10 @@ manually or quit the app (which is actually the kind of behaviour you'll see under iOS, if the OS can not restore your GL context it will just kill your app) ================================================================================ - Threads and the JAVA VM + Threads and the Java VM ================================================================================ -For a quick tour on how Linux native threads interoperate with the JAVA VM, take +For a quick tour on how Linux native threads interoperate with the Java VM, take a look here: http://developer.android.com/guide/practices/jni.html If you want to use threads in your SDL app, it's strongly recommended that you do so by creating them using SDL functions. This way, the required attach/detach @@ -347,11 +347,16 @@ When you're done instrumenting with valgrind, you can disable the wrapper: Why is API level 10 the minimum required? ================================================================================ -Support for OpenGL ES/ES2 applications was introduced in the NDK for API level 9, -which has since then been obsoleted, with the recommendation to developers to -bump the required level to 10. +API level 10 is required because SDL requires some functionality for running not +available on older devices and some for building which is not in older NDK/SDKs. + +Support for native OpenGL ES and ES2 applications was introduced in the NDK for +API level 4 and 8. EGL was made a stable API in the NDK for API level 9, which +has since then been obsoleted, with the recommendation to developers to bump the +required API level to 10. As of this writing, according to http://developer.android.com/about/dashboards/index.html -about 90% of the existing Android devices support an API level 10 or higher. +about 90% of the Android devices accessing Google Play support API level 10 or +higher (March 2013). ================================================================================ A note regarding the use of the "dirty rectangles" rendering technique diff --git a/README.gesture b/README.gesture index 187a598b1..d52c4c5a2 100644 --- a/README.gesture +++ b/README.gesture @@ -16,7 +16,7 @@ Recording terminates as soon as a finger comes up. Recording is acknowledged by A SDL_DOLLARRECORD event is a dgesture with the following fields: event.dgesture.touchId - the Id of the touch used to record the gesture. -event.dgesture.gestureId - the unique id of the recoreded gesture. +event.dgesture.gestureId - the unique id of the recorded gesture. Performing: @@ -28,7 +28,7 @@ event.dgesture.gestureId - the unique id of the closest gesture to the performe event.dgesture.error - the difference between the gesture template and the actual performed gesture. Lower error is a better match. event.dgesture.numFingers - the number of fingers used to draw the stroke. -Most programs will want to define an appropriate error threshold and check to be sure taht the error of a gesture is not abnormally high (an indicator that no gesture was performed). +Most programs will want to define an appropriate error threshold and check to be sure that the error of a gesture is not abnormally high (an indicator that no gesture was performed). @@ -38,14 +38,14 @@ To save a template, call SDL_SaveDollarTemplate(gestureId, src) where gestureId To save all currently loaded templates, call SDL_SaveAllDollarTemplates(src) where source is an SDL_RWops pointer to the file where the gesture will be stored. -Both functions return the number of gestures sucessfully saved. +Both functions return the number of gestures successfully saved. Loading: -------- To load templates from a file, call SDL_LoadDollarTemplates(touchId,src) where touchId is the id of the touch to load to (or -1 to load to all touch devices), and src is an SDL_RWops pointer to a gesture save file. -SDL_LoadDollarTemplates returns the number of templates sucessfully loaded. +SDL_LoadDollarTemplates returns the number of templates successfully loaded. @@ -56,8 +56,8 @@ SDL provides simple support for pinch/rotate/swipe gestures. Every time a finger is moved an SDL_MULTIGESTURE event is sent with the following fields: event.mgesture.touchId - the Id of the touch on which the gesture was performed. -event.mgesture.x - the normalized x cooridinate of the gesture. (0..1) -event.mgesture.y - the normalized y cooridinate of the gesture. (0..1) +event.mgesture.x - the normalized x coordinate of the gesture. (0..1) +event.mgesture.y - the normalized y coordinate of the gesture. (0..1) event.mgesture.dTheta - the amount that the fingers rotated during this motion. event.mgesture.dDist - the amount that the fingers pinched during this motion. event.mgesture.numFingers - the number of fingers used in the gesture. diff --git a/README.pandora b/README.pandora index d360f84f3..d522bc77a 100644 --- a/README.pandora +++ b/README.pandora @@ -1,7 +1,7 @@ SDL 2.0 with open pandora console support ( http://openpandora.org/ ) ===================================================================== -- A pandora specific video driver was writed to allow SDL 2.0 with OpenGL ES +- A pandora specific video driver was written to allow SDL 2.0 with OpenGL ES support to work on the pandora under the framebuffer. This driver do not have input support for now, so if you use it you will have to add your own control code. The video driver name is "pandora" so if you have problem running it from diff --git a/README.touch b/README.touch index 68b97c1be..9e688330f 100644 --- a/README.touch +++ b/README.touch @@ -5,7 +5,7 @@ Linux: The linux touch system is currently based off event streams, and proc/bus/devices. The active user must be given permissions to read /dev/input/TOUCHDEVICE, where TOUCHDEVICE is the event stream for your device. Currently only Wacom tablets are supported. If you have an unsupported tablet contact me at jim.tla+sdl_touch@gmail.com and I will help you get support for it. Mac: -The Mac and Iphone API's are pretty. If your touch device supports them then you'll be fine. If it doesn't, then there isn't much we can do. +The Mac and iPhone APIs are pretty. If your touch device supports them then you'll be fine. If it doesn't, then there isn't much we can do. iPhone: Works out of box. @@ -21,18 +21,18 @@ Sent when a finger (or stylus) is placed on a touch device. Fields: event.tfinger.touchId - the Id of the touch device. event.tfinger.fingerId - the Id of the finger which just went down. -event.tfinger.x - the x coordinate of the touch (0..touch.xres) -event.tfinger.y - the y coordinate of the touch (0..touch.yres) -event.tfinger.pressure - the pressure of the touch (0..touch.pressureres) +event.tfinger.x - the x coordinate of the touch (0..1) +event.tfinger.y - the y coordinate of the touch (0..1) +event.tfinger.pressure - the pressure of the touch (0..1) SDL_FINGERMOTION: Sent when a finger (or stylus) is moved on the touch device. Fields: Same as FINGERDOWN but with additional: -event.tfginer.dx - change in x coordinate during this motion event. -event.tfginer.dy - change in y coordinate during this motion event. +event.tfinger.dx - change in x coordinate during this motion event. +event.tfinger.dy - change in y coordinate during this motion event. -SDL_FINGERMOTION: +SDL_FINGERUP: Sent when a finger (or stylus) is lifted from the touch device. Fields: Same as FINGERDOWN. @@ -41,56 +41,38 @@ Same as FINGERDOWN. =========================================================================== Functions =========================================================================== -SDL provides the ability to access the underlying Touch and Finger structures. +SDL provides the ability to access the underlying Finger structures. These structures should _never_ be modified. -The following functions are included from SDL_Touch.h +The following functions are included from SDL_touch.h -To get a SDL_Touch device call SDL_GetTouch(touchId). -This returns an SDL_Touch*. -IMPORTANT: If the touch has been removed, or there is no touch with the given ID, SDL_GetTouch will return null. Be sure to check for this! +To get a SDL_TouchID call SDL_GetTouchDevice(index). +This returns a SDL_TouchID. +IMPORTANT: If the touch has been removed, or there is no touch with the given ID, SDL_GetTouchID will return 0. Be sure to check for this! -An SDL_Touch has the following fields: ->xres,yres,pressures: - The resolution at which x,y, and pressure values are reported. Currently these will always be equal to 2^15, but this may not always be the case. +The number of touch devices can be queried with SDL_GetNumTouchDevices(). ->pressure_max, pressure_min, x_max, x_min, y_max, y_min - Which give, respectively, the maximum and minumum values that the touch digitizer can return for pressure, x coordiniate, and y coordinate AS REPORTED BY THE OPERATING SYSTEM. -On Mac/iPhone systems _max will always be 0, and _min will always be 1. +A SDL_Touch may be used to get pointers to SDL_Finger. ->native_xres,native_yres,native_pressureres: - The native resolution of the touch device AS REPORTED BY THE OPERATING SYSTEM. -On Mac/iPhone systems these will always be 1. +SDL_GetNumTouchFingers(touchID) may be used to get the number of fingers currently down on the device. ->num_fingers: - The number of fingers currently down on the device. +The most common reason to access SDL_Finger is to query the fingers outside the event. In most cases accessing the fingers is using the event. This would be accomplished by code like the following: ->fingers: - An array of pointers to the fingers which are on the device. - - -The most common reason to access a touch device is to normalize inputs. This would be accomplished by code like the following: - - SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); - if(inTouch == NULL) continue; //The touch has been removed - - float x = ((float)event.tfinger.x)/inTouch->xres; - float y = ((float)event.tfinger.y)/inTouch->yres; + float x = event.tfinger.x; + float y = event.tfinger.y; -To get an SDL_Finger, call SDL_GetFinger(touch,fingerId), where touch is a pointer to an SDL_Touch device, and fingerId is the id of the requested finger. -This returns an SDL_Finger*, or null if the finger does not exist, or has been removed. -An SDL_Finger is guaranteed to be persistent for the duration of a touch, but it will be de-allocated as soon as the finger is removed. This occurs when the SDL_FINGERUP event is _added_ to the event queue, and thus _before_ the FINGERUP event is polled. -As a result, be very careful to check for null return values. +To get a SDL_Finger, call SDL_GetTouchFinger(touchID,index), where touchID is a SDL_TouchID, and index is the requested finger. +This returns a SDL_Finger*, or NULL if the finger does not exist, or has been removed. +A SDL_Finger is guaranteed to be persistent for the duration of a touch, but it will be de-allocated as soon as the finger is removed. This occurs when the SDL_FINGERUP event is _added_ to the event queue, and thus _before_ the FINGERUP event is polled. +As a result, be very careful to check for NULL return values. -An SDL_Finger has the following fields: +A SDL_Finger has the following fields: >x,y,pressure: The current coordinates of the touch. ->xdelta,ydelta: - The change in position resulting from the last finger motion. ->last_x, last_y, last_pressure: - The previous coordinates of the touch. +>pressure: + The pressure of the touch. =========================================================================== Notes @@ -99,3 +81,4 @@ For a complete example see test/testgesture.c Please direct questions/comments to: jim.tla+sdl_touch@gmail.com + (original author, API was changed since) From 2422c520acb04d3a55fb92dd1c59445edfbacfa3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 10 Mar 2013 09:07:23 -0700 Subject: [PATCH 076/151] Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead Lee Salzman When using SDL_GL_CreateContext() to create a >= 3.0 version or core/forward-compatible context, internally glXCreateContextAttribsARB is used. Mesa in particular seems to be having trouble with this call and returning all sorts of errors, so it is dangerous to poll for the highest GL version by using calls to SDL_GL_CreateContext unless you are sure, a priori, that the call will suceed, defeating the point of its use. X11 protocol errors are of the following form, with varying details depending on user, but the cause is always SDL_GL_CreateContext as above... X Error of failed request: GLXBadFBConfig Major opcode of failed request: 153 (GLX) Minor opcode of failed request: 34 () Serial number of failed request: 215 Current serial number in output stream: 221 These sorts of errors can be temporarily filtered out by setting an X11 error handler to catch and ignore them, which is safe with respect to SDL_GL_CreateContext behavior because this function is allowed to return NULL to indicate failure. A patch is attached to do this temporary filtering/catching of errors generated by trying to use glXCreateContextAttribs and friends... --- src/video/x11/SDL_x11opengl.c | 36 ++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 43760d0b1..400ef84e9 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -496,6 +496,33 @@ X11_GL_GetVisual(_THIS, Display * display, int screen) return vinfo; } +#ifndef GLXBadContext +#define GLXBadContext 0 +#endif +#ifndef GLXBadFBConfig +#define GLXBadFBConfig 9 +#endif +#ifndef GLXBadProfileARB +#define GLXBadProfileARB 13 +#endif +static int (*handler) (Display *, XErrorEvent *) = NULL; +static int +X11_GL_CreateContextErrorHandler(Display * d, XErrorEvent * e) +{ + switch (e->error_code) { + case GLXBadContext: + case GLXBadFBConfig: + case GLXBadProfileARB: + case BadRequest: + case BadMatch: + case BadValue: + case BadAlloc: + return (0); + default: + return (handler(d, e)); + } +} + SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window) { @@ -516,6 +543,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) /* We do this to create a clean separation between X and GLX errors. */ XSync(display, False); + handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler); XGetWindowAttributes(display, data->xwindow, &xattr); v.screen = screen; v.visualid = XVisualIDFromVisual(xattr.visual); @@ -532,10 +560,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) context to grab the new context creation function */ GLXContext temp_context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); - if (!temp_context) { - SDL_SetError("Could not create GL context"); - return NULL; - } else { + if (temp_context) { /* max 8 attributes plus terminator */ int attribs[9] = { GLX_CONTEXT_MAJOR_VERSION_ARB, @@ -609,7 +634,8 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) XFree(vinfo); } XSync(display, False); - + XSetErrorHandler(handler); + if (!context) { SDL_SetError("Could not create GL context"); return NULL; From 203b9839d2a4ef3a6a55b1a1ed5b61a40148a502 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 10 Mar 2013 09:09:31 -0700 Subject: [PATCH 077/151] Fixed bug 1750 - Directfb renderer does not support SDL_RENDERER_TARGETTEXTURE tomaszewski.p DirectFB renderer does not support SDL_RENDERER_TARGETTEXTURE what makes it incompatible with GL or GLES(2) renderers. Attached patched: - adds support for SDL_RENDERER_TARGETTEXTURE, - DirectFB RenderCopy converts destination rectangle from floats to ints, - fixes whitespaces to be the same in whole file. --- src/video/directfb/SDL_DirectFB_render.c | 165 +++++++++++++---------- 1 file changed, 93 insertions(+), 72 deletions(-) diff --git a/src/video/directfb/SDL_DirectFB_render.c b/src/video/directfb/SDL_DirectFB_render.c index c3b810d10..4a1d52798 100644 --- a/src/video/directfb/SDL_DirectFB_render.c +++ b/src/video/directfb/SDL_DirectFB_render.c @@ -35,21 +35,21 @@ #ifndef DFB_VERSION_ATLEAST -#define DFB_VERSIONNUM(X, Y, Z) \ - ((X)*1000 + (Y)*100 + (Z)) +#define DFB_VERSIONNUM(X, Y, Z) \ + ((X)*1000 + (Y)*100 + (Z)) #define DFB_COMPILEDVERSION \ - DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION) + DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION) #define DFB_VERSION_ATLEAST(X, Y, Z) \ - (DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z)) + (DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z)) -#define SDL_DFB_CHECK(x) x +#define SDL_DFB_CHECK(x) x #endif /* the following is not yet tested ... */ -#define USE_DISPLAY_PALETTE (0) +#define USE_DISPLAY_PALETTE (0) #define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL) @@ -100,9 +100,9 @@ static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, int count); static int DirectFB_RenderDrawRects(SDL_Renderer * renderer, - const SDL_Rect ** rects, int count); + const SDL_Rect ** rects, int count); static int DirectFB_RenderFillRects(SDL_Renderer * renderer, - const SDL_FRect * rects, int count); + const SDL_FRect * rects, int count); static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, @@ -116,6 +116,7 @@ static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * r static int DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 format, const void * pixels, int pitch); static int DirectFB_UpdateViewport(SDL_Renderer * renderer); +static int DirectFB_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); static int PrepareDraw(SDL_Renderer * renderer); @@ -135,7 +136,7 @@ SDL_RenderDriver DirectFB_RenderDriver = { SDL_SCALEMODE_SLOW | SDL_SCALEMODE_BEST),*/ 0, { - /* formats filled in later */ + /* formats filled in later */ }, 0, 0} @@ -149,6 +150,7 @@ typedef struct int lastBlendMode; DFBSurfaceBlittingFlags blitFlags; DFBSurfaceDrawingFlags drawFlags; + IDirectFBSurface* target; } DirectFB_RenderData; typedef struct @@ -191,7 +193,7 @@ TextureHasAlpha(DirectFB_TextureData * data) /* Drawing primitive ? */ if (!data) return 0; - + return (DFB_PIXELFORMAT_HAS_ALPHA(DirectFB_SDLToDFBPixelFormat(data->format)) ? 1 : 0); #if 0 switch (data->format) { @@ -213,31 +215,31 @@ TextureHasAlpha(DirectFB_TextureData * data) static inline IDirectFBSurface *get_dfb_surface(SDL_Window *window) { - SDL_SysWMinfo wm_info; + SDL_SysWMinfo wm_info; SDL_memset(&wm_info, 0, sizeof(SDL_SysWMinfo)); - SDL_VERSION(&wm_info.version); - SDL_GetWindowWMInfo(window, &wm_info); + SDL_VERSION(&wm_info.version); + SDL_GetWindowWMInfo(window, &wm_info); - return wm_info.info.dfb.surface; + return wm_info.info.dfb.surface; } static inline IDirectFBWindow *get_dfb_window(SDL_Window *window) { - SDL_SysWMinfo wm_info; + SDL_SysWMinfo wm_info; SDL_memset(&wm_info, 0, sizeof(SDL_SysWMinfo)); - SDL_VERSION(&wm_info.version); - SDL_GetWindowWMInfo(window, &wm_info); + SDL_VERSION(&wm_info.version); + SDL_GetWindowWMInfo(window, &wm_info); - return wm_info.info.dfb.window; + return wm_info.info.dfb.window; } static void SetBlendMode(DirectFB_RenderData * data, int blendMode, DirectFB_TextureData * source) { - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; //FIXME: check for format change if (1 || data->lastBlendMode != blendMode) { @@ -268,7 +270,7 @@ SetBlendMode(DirectFB_RenderData * data, int blendMode, data->drawFlags = DSDRAW_BLEND; // FIXME: SRCALPHA kills performance on radeon ... // It will be cheaper to copy the surface to - // a temporay surface and premultiply + // a temporay surface and premultiply if (source && TextureHasAlpha(source)) SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); else @@ -339,7 +341,7 @@ int DirectFB_RenderClear(SDL_Renderer * renderer) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; DirectFB_ActivateRenderer(renderer); @@ -354,7 +356,7 @@ DirectFB_RenderClear(SDL_Renderer * renderer) SDL_Renderer * DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) { - IDirectFBSurface *winsurf = get_dfb_surface(window); + IDirectFBSurface *winsurf = get_dfb_surface(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_Renderer *renderer = NULL; DirectFB_RenderData *data = NULL; @@ -382,14 +384,15 @@ DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) /* RenderFillEllipse - no reference implementation yet */ renderer->RenderCopy = DirectFB_RenderCopy; renderer->RenderPresent = DirectFB_RenderPresent; - + /* FIXME: Yet to be tested */ renderer->RenderReadPixels = DirectFB_RenderReadPixels; //renderer->RenderWritePixels = DirectFB_RenderWritePixels; - + renderer->DestroyTexture = DirectFB_DestroyTexture; renderer->DestroyRenderer = DirectFB_DestroyRenderer; renderer->UpdateViewport = DirectFB_UpdateViewport; + renderer->SetRenderTarget = DirectFB_SetRenderTarget; #if 0 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; @@ -406,9 +409,10 @@ DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->driverdata = data; renderer->info.flags = - SDL_RENDERER_ACCELERATED; + SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; data->window = window; + data->target = winsurf; data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT; @@ -449,14 +453,13 @@ DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) static void DirectFB_ActivateRenderer(SDL_Renderer * renderer) { - SDL_DFB_RENDERERDATA(renderer); SDL_Window *window = renderer->window; SDL_DFB_WINDOWDATA(window); if (renddata->size_changed /*|| windata->wm_needs_redraw*/) { //DirectFB_AdjustWindowSurface(window); - renddata->size_changed = SDL_FALSE; + renddata->size_changed = SDL_FALSE; } } @@ -580,13 +583,13 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &data->palette)); #else /* DFB has issues with blitting LUT8 surfaces. - * Creating a new palette does not help. - */ - DFBPaletteDescription pal_desc; - pal_desc.flags = DPDESC_SIZE; // | DPDESC_ENTRIES - pal_desc.size = 256; - SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette)); - SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette)); + * Creating a new palette does not help. + */ + DFBPaletteDescription pal_desc; + pal_desc.flags = DPDESC_SIZE; // | DPDESC_ENTRIES + pal_desc.size = 256; + SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette)); + SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette)); #endif } @@ -642,7 +645,7 @@ DirectFB_SetTexturePalette(SDL_Renderer * renderer, int i; if (ncolors > 256) - ncolors = 256; + ncolors = 256; for (i = 0; i < ncolors; ++i) { entries[i].r = colors[i].r; @@ -788,7 +791,7 @@ DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, (texture->format == SDL_PIXELFORMAT_IYUV)) { bpp = 1; } - + SDL_DFB_CHECKERR(data->surface->Lock(data->surface, DSLF_WRITE | DSLF_READ, ((void **) &dpixels), &dpitch)); @@ -892,11 +895,28 @@ DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, } #endif +static int DirectFB_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) +{ + DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; + DirectFB_TextureData *tex_data = NULL; + + DirectFB_ActivateRenderer(renderer); + if (texture) { + tex_data = (DirectFB_TextureData *) texture->driverdata; + data->target = tex_data->surface; + } else { + data->target = get_dfb_surface(data->window); + } + data->lastBlendMode = 0; + return 0; +} + + static int PrepareDraw(SDL_Renderer * renderer) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; Uint8 r, g, b, a; @@ -932,14 +952,14 @@ static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; int i; DirectFB_ActivateRenderer(renderer); PrepareDraw(renderer); for (i=0; i < count; i++) - SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y)); + SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y)); return 0; error: return -1; @@ -949,7 +969,7 @@ static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; int i; DirectFB_ActivateRenderer(renderer); @@ -961,7 +981,7 @@ static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, #endif for (i=0; i < count - 1; i++) - SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i+1].x, points[i+1].y)); + SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i+1].x, points[i+1].y)); return 0; error: @@ -972,7 +992,7 @@ static int DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; int i; DirectFB_ActivateRenderer(renderer); @@ -980,8 +1000,8 @@ DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int c PrepareDraw(renderer); for (i=0; iDrawRectangle(destsurf, rects[i]->x, rects[i]->y, - rects[i]->w, rects[i]->h)); + SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y, + rects[i]->w, rects[i]->h)); return 0; error: @@ -992,7 +1012,7 @@ static int DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; int i; DirectFB_ActivateRenderer(renderer); @@ -1000,8 +1020,8 @@ DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int c PrepareDraw(renderer); for (i=0; iFillRectangle(destsurf, rects[i].x, rects[i].y, - rects[i].w, rects[i].h)); + SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, rects[i].x, rects[i].y, + rects[i].w, rects[i].h)); return 0; error: @@ -1013,7 +1033,7 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; DirectFB_TextureData *texturedata = (DirectFB_TextureData *) texture->driverdata; Uint8 alpha, r, g, b; @@ -1027,7 +1047,7 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, if (texturedata->display) { int px, py; SDL_Window *window = renderer->window; - IDirectFBWindow *dfbwin = get_dfb_window(window); + IDirectFBWindow *dfbwin = get_dfb_window(window); SDL_DFB_WINDOWDATA(window); SDL_VideoDisplay *display = texturedata->display; DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; @@ -1079,13 +1099,13 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, } SDLtoDFBRect(srcrect, &sr); - SDLtoDFBRect(dstrect, &dr); + SDLtoDFBRect_Float(dstrect, &dr); alpha = r = g = b = 0xff; - if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){ - alpha = texture->a; - flags |= DSBLIT_BLEND_COLORALPHA; - } + if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){ + alpha = texture->a; + flags |= DSBLIT_BLEND_COLORALPHA; + } if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { r = texture->r; @@ -1189,7 +1209,6 @@ DirectFB_DestroyRenderer(SDL_Renderer * renderer) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(data->window); - #if 0 if (display->palette) { SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged, data); @@ -1205,15 +1224,16 @@ DirectFB_DestroyRenderer(SDL_Renderer * renderer) static int DirectFB_UpdateViewport(SDL_Renderer * renderer) { - IDirectFBSurface *winsurf = get_dfb_surface(renderer->window); - DFBRegion dreg; + DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; + IDirectFBSurface *winsurf = data->target; + DFBRegion dreg; - dreg.x1 = renderer->viewport.x; - dreg.y1 = renderer->viewport.y; - dreg.x2 = dreg.x1 + renderer->viewport.w - 1; - dreg.y2 = dreg.y1 + renderer->viewport.h - 1; + dreg.x1 = renderer->viewport.x; + dreg.y1 = renderer->viewport.y; + dreg.x2 = dreg.x1 + renderer->viewport.w - 1; + dreg.y2 = dreg.y1 + renderer->viewport.h - 1; - winsurf->SetClip(winsurf, &dreg); + winsurf->SetClip(winsurf, &dreg); return 0; } @@ -1222,24 +1242,25 @@ DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 format, void * pixels, int pitch) { Uint32 sdl_format; - void * laypixels; - int laypitch; - DFBSurfacePixelFormat dfb_format; - IDirectFBSurface *winsurf = get_dfb_surface(renderer->window); + void * laypixels; + int laypitch; + DFBSurfacePixelFormat dfb_format; + DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; + IDirectFBSurface *winsurf = data->target; DirectFB_ActivateRenderer(renderer); winsurf->GetPixelFormat(winsurf, &dfb_format); sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format); winsurf->Lock(winsurf, DSLF_READ, (void **) &laypixels, &laypitch); - + laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) ); SDL_ConvertPixels(rect->w, rect->h, sdl_format, laypixels, laypitch, format, pixels, pitch); winsurf->Unlock(winsurf); - + return 0; } @@ -1251,15 +1272,15 @@ DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, SDL_Window *window = renderer->window; SDL_DFB_WINDOWDATA(window); Uint32 sdl_format; - void * laypixels; - int laypitch; - DFBSurfacePixelFormat dfb_format; + void * laypixels; + int laypitch; + DFBSurfacePixelFormat dfb_format; SDL_DFB_CHECK(windata->surface->GetPixelFormat(windata->surface, &dfb_format)); sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format); SDL_DFB_CHECK(windata->surface->Lock(windata->surface, DSLF_WRITE, (void **) &laypixels, &laypitch)); - + laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) ); SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch, From 3d572bdf89817c7f0fb906bc64b8709fca0ce46e Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 10 Mar 2013 13:05:47 -0400 Subject: [PATCH 078/151] First shot at Windows XInput haptics. --HG-- extra : rebase_source : 52e691a0917d173e891e67714a135373daea0ef5 --- include/SDL_hints.h | 2 +- src/core/windows/SDL_windows.c | 63 +++++++ src/core/windows/SDL_windows.h | 60 +++++- src/haptic/windows/SDL_syshaptic.c | 241 +++++++++++++++++++----- src/joystick/windows/SDL_dxjoystick.c | 74 ++------ src/joystick/windows/SDL_dxjoystick_c.h | 20 +- 6 files changed, 327 insertions(+), 133 deletions(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 9c1080c53..315a33133 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -203,7 +203,7 @@ extern "C" { * "0" - Disable XInput timer (only uses direct input) * "1" - Enable XInput timer (the default) */ -#define SD_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED" +#define SDL_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED" /** diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index b59e2cca2..49f2f04fd 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -24,10 +24,73 @@ #include "SDL_error.h" #include "SDL_windows.h" +#include "SDL_assert.h" #include /* for CoInitialize/CoUninitialize */ +XInputGetState_t SDL_XInputGetState = NULL; +XInputSetState_t SDL_XInputSetState = NULL; +XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL; +DWORD SDL_XInputVersion = 0; + +static HANDLE s_pXInputDLL = 0; +static int s_XInputDLLRefCount = 0; + +int +WIN_LoadXInputDLL(void) +{ + DWORD version = 0; + + if (s_pXInputDLL) { + SDL_assert(s_XInputDLLRefCount > 0); + s_XInputDLLRefCount++; + return 0; /* already loaded */ + } + + version = (1 << 16) | 4; + s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" ); // 1.4 Ships with Windows 8. + if (!s_pXInputDLL) { + version = (1 << 16) | 3; + s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); // 1.3 Ships with Vista and Win7, can be installed as a restributable component. + } + if (!s_pXInputDLL) { + s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); + } + if (!s_pXInputDLL) { + return -1; + } + + SDL_assert(s_XInputDLLRefCount == 0); + SDL_XInputVersion = version; + s_XInputDLLRefCount = 1; + + /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ + SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); + SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); + SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); + if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) { + WIN_UnloadXInputDLL(); + return -1; + } + + return 0; +} + +void +WIN_UnloadXInputDLL(void) +{ + if ( s_pXInputDLL ) { + SDL_assert(s_XInputDLLRefCount > 0); + if (--s_XInputDLLRefCount == 0) { + FreeLibrary( s_pXInputDLL ); + s_pXInputDLL = NULL; + } + } else { + SDL_assert(s_XInputDLLRefCount == 0); + } +} + /* Sets an error message based on GetLastError() */ void WIN_SetError(const char *prefix) diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index 9c57696d2..a68182777 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -33,7 +33,7 @@ #define _WIN32_WINNT 0x501 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */ #include - +#include /* Routines to convert from UTF8 to native Windows text */ #if UNICODE @@ -51,6 +51,64 @@ extern void WIN_SetError(const char *prefix); extern HRESULT WIN_CoInitialize(void); extern void WIN_CoUninitialize(void); +/* typedef's for XInput structs we use */ +typedef struct +{ + WORD wButtons; + BYTE bLeftTrigger; + BYTE bRightTrigger; + SHORT sThumbLX; + SHORT sThumbLY; + SHORT sThumbRX; + SHORT sThumbRY; + DWORD dwPaddingReserved; +} XINPUT_GAMEPAD_EX; + +typedef struct +{ + DWORD dwPacketNumber; + XINPUT_GAMEPAD_EX Gamepad; +} XINPUT_STATE_EX; + + +/* Forward decl's for XInput API's we load dynamically and use if available */ +typedef DWORD (WINAPI *XInputGetState_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + XINPUT_STATE_EX* pState // [out] Receives the current state + ); + +typedef DWORD (WINAPI *XInputSetState_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + XINPUT_VIBRATION* pVibration // [in, out] The vibration information to send to the controller + ); + +typedef DWORD (WINAPI *XInputGetCapabilities_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + DWORD dwFlags, // [in] Input flags that identify the device type + XINPUT_CAPABILITIES* pCapabilities // [out] Receives the capabilities + ); + +extern int WIN_LoadXInputDLL(void); +extern void WIN_UnloadXInputDLL(void); + +extern XInputGetState_t SDL_XInputGetState; +extern XInputSetState_t SDL_XInputSetState; +extern XInputGetCapabilities_t SDL_XInputGetCapabilities; +extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF) + +#define XINPUTGETSTATE SDL_XInputGetState +#define XINPUTSETSTATE SDL_XInputSetState +#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities +#define INVALID_XINPUT_USERID 255 +#define SDL_XINPUT_MAX_DEVICES 4 + +#ifndef XINPUT_CAPS_FFB_SUPPORTED +#define XINPUT_CAPS_FFB_SUPPORTED 0x0001 +#endif + #endif /* _INCLUDED_WINDOWS_H */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c index 9993a5b25..a4a2644a1 100644 --- a/src/haptic/windows/SDL_syshaptic.c +++ b/src/haptic/windows/SDL_syshaptic.c @@ -22,16 +22,16 @@ #ifdef SDL_HAPTIC_DINPUT +#include "SDL_assert.h" +#include "SDL_hints.h" #include "SDL_haptic.h" #include "../SDL_syshaptic.h" #include "SDL_joystick.h" #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ #include "../../joystick/windows/SDL_dxjoystick_c.h" /* For joystick hwdata */ - #define MAX_HAPTICS 32 - /* * List of available haptic devices. */ @@ -41,6 +41,8 @@ static struct char *name; SDL_Haptic *haptic; DIDEVCAPS capabilities; + Uint8 bXInputHaptic; // Supports force feedback via XInput. + Uint8 userid; // XInput userid index for this joystick } SDL_hapticlist[MAX_HAPTICS]; @@ -52,6 +54,8 @@ struct haptic_hwdata LPDIRECTINPUTDEVICE8 device; DWORD axes[3]; /* Axes to use. */ int is_joystick; /* Device is loaded as joystick. */ + Uint8 bXInputHaptic; // Supports force feedback via XInput. + Uint8 userid; // XInput userid index for this joystick }; @@ -62,6 +66,7 @@ struct haptic_hweffect { DIEFFECT effect; LPDIRECTINPUTEFFECT ref; + XINPUT_VIBRATION vibration; }; @@ -70,6 +75,7 @@ struct haptic_hweffect */ static SDL_bool coinitialized = SDL_FALSE; static LPDIRECTINPUT8 dinput = NULL; +static SDL_bool loaded_xinput = SDL_FALSE; /* @@ -87,6 +93,7 @@ static int SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance); static int SDL_SYS_HapticOpenFromDevice8(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device8); +static int SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, Uint8 userid); static DWORD DIGetTriggerButton(Uint16 button); static int SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes); @@ -130,6 +137,7 @@ DI_GUIDIsSame(const GUID * a, const GUID * b) int SDL_SYS_HapticInit(void) { + const char *env = SDL_GetHint(SDL_HINT_XINPUT_ENABLED); HRESULT ret; HINSTANCE instance; @@ -187,6 +195,30 @@ SDL_SYS_HapticInit(void) return -1; } + if (!env || SDL_atoi(env)) { + loaded_xinput = (WIN_LoadXInputDLL() == 0); + } + + if (loaded_xinput) { + DWORD i; + const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4)); + + for (i = 0; (i < SDL_XINPUT_MAX_DEVICES) && (SDL_numhaptics < MAX_HAPTICS); i++) { + XINPUT_CAPABILITIES caps; + if (XINPUTGETCAPABILITIES(i, XINPUT_FLAG_GAMEPAD, &caps) == ERROR_SUCCESS) { + if ((!bIs14OrLater) || (caps.Flags & XINPUT_CAPS_FFB_SUPPORTED)) { + /* !!! FIXME: I'm not bothering to query for a real name right now. */ + char buf[64]; + SDL_snprintf(buf, sizeof (buf), "XInput Controller #%u", i+1); + SDL_hapticlist[SDL_numhaptics].name = SDL_strdup(buf); + SDL_hapticlist[SDL_numhaptics].bXInputHaptic = 1; + SDL_hapticlist[SDL_numhaptics].userid = (Uint8) i; + SDL_numhaptics++; + } + } + } + } + return SDL_numhaptics; } @@ -363,6 +395,43 @@ SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance) return -1; } +static int +SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, Uint8 userid) +{ + XINPUT_VIBRATION vibration = { 0, 0 }; /* stop any current vibration */ + XINPUTSETSTATE(userid, &vibration); + + /* !!! FIXME: we can probably do more than SINE if we figure out how to set up the left and right motors properly. */ + haptic->supported = SDL_HAPTIC_SINE; + + haptic->neffects = 1; + haptic->nplaying = 1; + + /* Prepare effects memory. */ + haptic->effects = (struct haptic_effect *) + SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); + if (haptic->effects == NULL) { + SDL_OutOfMemory(); + return -1; + } + /* Clear the memory */ + SDL_memset(haptic->effects, 0, + sizeof(struct haptic_effect) * haptic->neffects); + + haptic->hwdata = (struct haptic_hwdata *) SDL_malloc(sizeof(*haptic->hwdata)); + if (haptic->hwdata == NULL) { + SDL_free(haptic->effects); + haptic->effects = NULL; + SDL_OutOfMemory(); + return -1; + } + SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); + + haptic->hwdata->bXInputHaptic = 1; + haptic->hwdata->userid = userid; + + return 0; + } /* * Opens the haptic device from the file descriptor. @@ -504,9 +573,11 @@ SDL_SYS_HapticOpenFromDevice8(SDL_Haptic * haptic, int SDL_SYS_HapticOpen(SDL_Haptic * haptic) { - return SDL_SYS_HapticOpenFromInstance(haptic, - SDL_hapticlist[haptic->index]. - instance); + if (SDL_hapticlist[haptic->index].bXInputHaptic) { + return SDL_SYS_HapticOpenFromXInput(haptic, SDL_hapticlist[haptic->index].userid); + } + + return SDL_SYS_HapticOpenFromInstance(haptic, SDL_hapticlist[haptic->index].instance); } @@ -535,11 +606,9 @@ SDL_SYS_HapticMouse(void) int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) { - if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) { - return SDL_TRUE; - } - - return SDL_FALSE; + const struct joystick_hwdata *hwdata = joystick->hwdata; + return ( (hwdata->bXInputHaptic) || + ((hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) != 0) ); } @@ -549,25 +618,30 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) { - HRESULT ret; - DIDEVICEINSTANCE hap_instance, joy_instance; - hap_instance.dwSize = sizeof(DIDEVICEINSTANCE); - joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); - - /* Get the device instances. */ - ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device, - &hap_instance); - if (FAILED(ret)) { - return 0; - } - ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, - &joy_instance); - if (FAILED(ret)) { - return 0; - } - - if (DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance)) + if ((joystick->hwdata->bXInputHaptic == haptic->hwdata->bXInputHaptic) && (haptic->hwdata->userid == joystick->hwdata->userid)) { return 1; + } else { + HRESULT ret; + DIDEVICEINSTANCE hap_instance, joy_instance; + + hap_instance.dwSize = sizeof(DIDEVICEINSTANCE); + joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); + + /* Get the device instances. */ + ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device, + &hap_instance); + if (FAILED(ret)) { + return 0; + } + ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, + &joy_instance); + if (FAILED(ret)) { + return 0; + } + + if (DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance)) + return 1; + } return 0; } @@ -585,16 +659,27 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */ - for (i=0; ihwdata->InputDevice, - &joy_instance); - if (FAILED(idret)) { - return -1; + if (joystick->hwdata->bXInputDevice) { + const Uint8 userid = joystick->hwdata->userid; + for (i=0; ihwdata->bXInputHaptic); + haptic->index = i; + break; + } } - if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance, - &joy_instance.guidInstance)) { - haptic->index = i; - break; + } else { + for (i=0; ihwdata->InputDevice, + &joy_instance); + if (FAILED(idret)) { + return -1; + } + if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance, + &joy_instance.guidInstance)) { + haptic->index = i; + break; + } } } if (i >= SDL_numhaptics) { @@ -611,14 +696,17 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); /* Now open the device. */ - ret = - SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice); - if (ret < 0) { - return -1; + if (!joystick->hwdata->bXInputHaptic) { + ret = SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice); + if (ret < 0) { + return -1; + } } /* It's using the joystick device. */ haptic->hwdata->is_joystick = 1; + haptic->hwdata->bXInputHaptic = joystick->hwdata->bXInputHaptic; + haptic->hwdata->userid = joystick->hwdata->userid; return 0; } @@ -638,10 +726,12 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic) haptic->neffects = 0; /* Clean up */ - IDirectInputDevice8_Unacquire(haptic->hwdata->device); - /* Only release if isn't grabbed by a joystick. */ - if (haptic->hwdata->is_joystick == 0) { - IDirectInputDevice8_Release(haptic->hwdata->device); + if (!haptic->hwdata->bXInputHaptic) { + IDirectInputDevice8_Unacquire(haptic->hwdata->device); + /* Only release if isn't grabbed by a joystick. */ + if (haptic->hwdata->is_joystick == 0) { + IDirectInputDevice8_Release(haptic->hwdata->device); + } } /* Free */ @@ -659,6 +749,11 @@ SDL_SYS_HapticQuit(void) { int i; + if (loaded_xinput) { + WIN_UnloadXInputDLL(); + loaded_xinput = SDL_FALSE; + } + for (i = 0; i < SDL_arraysize(SDL_hapticlist); ++i) { if (SDL_hapticlist[i].name) { SDL_free(SDL_hapticlist[i].name); @@ -1127,9 +1222,8 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base) { HRESULT ret; - - /* Get the type. */ REFGUID type = SDL_SYS_HapticEffectType(base); + if (type == NULL) { goto err_hweffect; } @@ -1142,6 +1236,13 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, goto err_hweffect; } + SDL_zerop(effect->hweffect); + + if (haptic->hwdata->bXInputHaptic) { + SDL_assert(base->type == SDL_HAPTIC_SINE); /* should catch this at higher level */ + return SDL_SYS_HapticUpdateEffect(haptic, effect, base); + } + /* Get the effect. */ if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) { goto err_effectdone; @@ -1181,6 +1282,23 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, DWORD flags; DIEFFECT temp; + if (haptic->hwdata->bXInputHaptic) { + // !!! FIXME: this isn't close to right. We only support "sine" effects, + // !!! FIXME: we ignore most of the parameters, and we probably get + // !!! FIXME: the ones we don't ignore wrong, too. + // !!! FIXME: if I had a better understanding of how the two motors + // !!! FIXME: could be used in unison, perhaps I could implement other + // !!! FIXME: effect types? + /* From MSDN: + "Note that the right motor is the high-frequency motor, the left + motor is the low-frequency motor. They do not always need to be + set to the same amount, as they provide different effects." */ + XINPUT_VIBRATION *vib = &effect->hweffect->vibration; + SDL_assert(data->type == SDL_HAPTIC_SINE); + vib->wLeftMotorSpeed = vib->wRightMotorSpeed = data->periodic.magnitude * 2; + return 0; + } + /* Get the effect. */ SDL_memset(&temp, 0, sizeof(DIEFFECT)); if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) { @@ -1226,6 +1344,11 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, HRESULT ret; DWORD iter; + if (haptic->hwdata->bXInputHaptic) { + XINPUT_VIBRATION *vib = &effect->hweffect->vibration; + return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS); + } + /* Check if it's infinite. */ if (iterations == SDL_HAPTIC_INFINITY) { iter = INFINITE; @@ -1251,6 +1374,11 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) { HRESULT ret; + if (haptic->hwdata->bXInputHaptic) { + XINPUT_VIBRATION vibration = { 0, 0 }; + return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS); + } + ret = IDirectInputEffect_Stop(effect->hweffect->ref); if (FAILED(ret)) { DI_SetError("Unable to stop effect", ret); @@ -1269,12 +1397,16 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect) { HRESULT ret; - ret = IDirectInputEffect_Unload(effect->hweffect->ref); - if (FAILED(ret)) { - DI_SetError("Removing effect from the device", ret); + if (haptic->hwdata->bXInputHaptic) { + SDL_SYS_HapticStopEffect(haptic, effect); + } else { + ret = IDirectInputEffect_Unload(effect->hweffect->ref); + if (FAILED(ret)) { + DI_SetError("Removing effect from the device", ret); + } + SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, + effect->effect.type); } - SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, - effect->effect.type); SDL_free(effect->hweffect); effect->hweffect = NULL; } @@ -1407,6 +1539,11 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic) { HRESULT ret; + if (haptic->hwdata->bXInputHaptic) { + XINPUT_VIBRATION vibration = { 0, 0 }; + return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS); + } + /* Try to stop the effects. */ ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, DISFFC_STOPALL); diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index 6493388f3..69f7da3aa 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -73,7 +73,6 @@ static SDL_cond *s_condJoystickThread = NULL; static SDL_mutex *s_mutexJoyStickEnum = NULL; static SDL_Thread *s_threadJoystick = NULL; static SDL_bool s_bJoystickThreadQuit = SDL_FALSE; -static HANDLE s_pXInputDLL = 0; static SDL_bool s_bXInputEnabled = SDL_TRUE; extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, @@ -91,36 +90,6 @@ struct JoyStick_DeviceData_ struct JoyStick_DeviceData_ *pNext; }; - -/* Forward decl's for XInput API's we load dynamically and use if available */ -typedef DWORD (WINAPI *XInputGetState_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - XINPUT_STATE_EX* pState // [out] Receives the current state - ); - -typedef DWORD (WINAPI *XInputSetState_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - XINPUT_VIBRATION* pVibration // [in, out] The vibration information to send to the controller - ); - -typedef DWORD (WINAPI *XInputGetCapabilities_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - DWORD dwFlags, // [in] Input flags that identify the device type - XINPUT_CAPABILITIES* pCapabilities // [out] Receives the capabilities - ); - -XInputGetState_t PC_XInputGetState; -XInputSetState_t PC_XInputSetState; -XInputGetCapabilities_t PC_XInputGetCapabilities; - -#define XINPUTGETSTATE PC_XInputGetState -#define XINPUTSETSTATE PC_XInputSetState -#define XINPUTGETCAPABILITIES PC_XInputGetCapabilities -#define INVALID_XINPUT_USERID 255 - typedef struct JoyStick_DeviceData_ JoyStick_DeviceData; static JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */ @@ -634,7 +603,7 @@ SDL_SYS_JoystickInit(void) { HRESULT result; HINSTANCE instance; - const char *env = SDL_GetHint(SD_HINT_XINPUT_ENABLED); + const char *env = SDL_GetHint(SDL_HINT_XINPUT_ENABLED); if (env && !SDL_atoi(env)) { s_bXInputEnabled = SDL_FALSE; } @@ -672,32 +641,15 @@ SDL_SYS_JoystickInit(void) return (-1); } - s_mutexJoyStickEnum = SDL_CreateMutex(); - s_condJoystickThread = SDL_CreateCond(); - s_bDeviceAdded = SDL_TRUE; // force a scan of the system for joysticks this first time - SDL_SYS_JoystickDetect(); + s_mutexJoyStickEnum = SDL_CreateMutex(); + s_condJoystickThread = SDL_CreateCond(); + s_bDeviceAdded = SDL_TRUE; // force a scan of the system for joysticks this first time + SDL_SYS_JoystickDetect(); - if (s_bXInputEnabled) { - // try to load XInput support if available - s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); - if ( !s_pXInputDLL ) - s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); - if ( s_pXInputDLL ) - { - // 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... - PC_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); - PC_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); - PC_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); - if ( !PC_XInputGetState || !PC_XInputSetState || !PC_XInputGetCapabilities ) - { - SDL_SYS_JoystickQuit(); - SDL_SetError("GetProcAddress() failed when loading XInput.", GetLastError()); - return (-1); - } - } + if ((s_bXInputEnabled) && (WIN_LoadXInputDLL() == -1)) { + s_bXInputEnabled = SDL_FALSE; /* oh well. */ } - if ( !s_threadJoystick ) { s_bJoystickThreadQuit = SDL_FALSE; @@ -978,6 +930,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities ); if ( result == ERROR_SUCCESS ) { + const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4)); SDL_bool bIsSupported = SDL_FALSE; // Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. bIsSupported = ( capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD ); @@ -990,6 +943,9 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) { // valid joystick->hwdata->bXInputDevice = SDL_TRUE; + if ((!bIs14OrLater) || (capabilities.Flags & XINPUT_CAPS_FFB_SUPPORTED)) { + joystick->hwdata->bXInputHaptic = SDL_TRUE; + } SDL_memset( joystick->hwdata->XInputState, 0x0, sizeof(joystick->hwdata->XInputState) ); joystickdevice->XInputUserId = userId; joystick->hwdata->userid = userId; @@ -1683,11 +1639,9 @@ SDL_SYS_JoystickQuit(void) s_pKnownJoystickGUIDs = NULL; } - if ( s_pXInputDLL ) - { - FreeLibrary( s_pXInputDLL ); - s_pXInputDLL = NULL; - } + if (s_bXInputEnabled) { + WIN_UnloadXInputDLL(); + } } diff --git a/src/joystick/windows/SDL_dxjoystick_c.h b/src/joystick/windows/SDL_dxjoystick_c.h index 631bab745..6d4957815 100644 --- a/src/joystick/windows/SDL_dxjoystick_c.h +++ b/src/joystick/windows/SDL_dxjoystick_c.h @@ -62,25 +62,6 @@ typedef struct input_t Uint8 num; } input_t; -/* typedef's for XInput structs we use */ -typedef struct -{ - WORD wButtons; - BYTE bLeftTrigger; - BYTE bRightTrigger; - SHORT sThumbLX; - SHORT sThumbLY; - SHORT sThumbRX; - SHORT sThumbRY; - DWORD dwPaddingReserved; -} XINPUT_GAMEPAD_EX; - -typedef struct -{ - DWORD dwPacketNumber; - XINPUT_GAMEPAD_EX Gamepad; -} XINPUT_STATE_EX; - /* The private structure used to keep track of a joystick */ struct joystick_hwdata { @@ -95,6 +76,7 @@ struct joystick_hwdata Uint8 removed; Uint8 send_remove_event; Uint8 bXInputDevice; // 1 if this device supports using the xinput API rather than DirectInput + Uint8 bXInputHaptic; // Supports force feedback via XInput. Uint8 userid; // XInput userid index for this joystick Uint8 currentXInputSlot; // the current position to write to in XInputState below, used so we can compare old and new values XINPUT_STATE_EX XInputState[2]; From 2e19fefe52c01cd48f122bf7cf8c0b9bd7a1ea60 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 10 Mar 2013 13:28:39 -0400 Subject: [PATCH 079/151] Attempt to get XInput haptics building on Cygwin (or rather, avoid building). --- src/core/windows/SDL_windows.c | 63 ------------------------- src/core/windows/SDL_windows.h | 59 ----------------------- src/joystick/windows/SDL_dxjoystick.c | 63 +++++++++++++++++++++++++ src/joystick/windows/SDL_dxjoystick_c.h | 59 +++++++++++++++++++++++ 4 files changed, 122 insertions(+), 122 deletions(-) diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index 49f2f04fd..0927832f0 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -28,69 +28,6 @@ #include /* for CoInitialize/CoUninitialize */ - -XInputGetState_t SDL_XInputGetState = NULL; -XInputSetState_t SDL_XInputSetState = NULL; -XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL; -DWORD SDL_XInputVersion = 0; - -static HANDLE s_pXInputDLL = 0; -static int s_XInputDLLRefCount = 0; - -int -WIN_LoadXInputDLL(void) -{ - DWORD version = 0; - - if (s_pXInputDLL) { - SDL_assert(s_XInputDLLRefCount > 0); - s_XInputDLLRefCount++; - return 0; /* already loaded */ - } - - version = (1 << 16) | 4; - s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" ); // 1.4 Ships with Windows 8. - if (!s_pXInputDLL) { - version = (1 << 16) | 3; - s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); // 1.3 Ships with Vista and Win7, can be installed as a restributable component. - } - if (!s_pXInputDLL) { - s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); - } - if (!s_pXInputDLL) { - return -1; - } - - SDL_assert(s_XInputDLLRefCount == 0); - SDL_XInputVersion = version; - s_XInputDLLRefCount = 1; - - /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ - SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); - SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); - SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); - if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) { - WIN_UnloadXInputDLL(); - return -1; - } - - return 0; -} - -void -WIN_UnloadXInputDLL(void) -{ - if ( s_pXInputDLL ) { - SDL_assert(s_XInputDLLRefCount > 0); - if (--s_XInputDLLRefCount == 0) { - FreeLibrary( s_pXInputDLL ); - s_pXInputDLL = NULL; - } - } else { - SDL_assert(s_XInputDLLRefCount == 0); - } -} - /* Sets an error message based on GetLastError() */ void WIN_SetError(const char *prefix) diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index a68182777..c30fa9be6 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -33,7 +33,6 @@ #define _WIN32_WINNT 0x501 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */ #include -#include /* Routines to convert from UTF8 to native Windows text */ #if UNICODE @@ -51,64 +50,6 @@ extern void WIN_SetError(const char *prefix); extern HRESULT WIN_CoInitialize(void); extern void WIN_CoUninitialize(void); -/* typedef's for XInput structs we use */ -typedef struct -{ - WORD wButtons; - BYTE bLeftTrigger; - BYTE bRightTrigger; - SHORT sThumbLX; - SHORT sThumbLY; - SHORT sThumbRX; - SHORT sThumbRY; - DWORD dwPaddingReserved; -} XINPUT_GAMEPAD_EX; - -typedef struct -{ - DWORD dwPacketNumber; - XINPUT_GAMEPAD_EX Gamepad; -} XINPUT_STATE_EX; - - -/* Forward decl's for XInput API's we load dynamically and use if available */ -typedef DWORD (WINAPI *XInputGetState_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - XINPUT_STATE_EX* pState // [out] Receives the current state - ); - -typedef DWORD (WINAPI *XInputSetState_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - XINPUT_VIBRATION* pVibration // [in, out] The vibration information to send to the controller - ); - -typedef DWORD (WINAPI *XInputGetCapabilities_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - DWORD dwFlags, // [in] Input flags that identify the device type - XINPUT_CAPABILITIES* pCapabilities // [out] Receives the capabilities - ); - -extern int WIN_LoadXInputDLL(void); -extern void WIN_UnloadXInputDLL(void); - -extern XInputGetState_t SDL_XInputGetState; -extern XInputSetState_t SDL_XInputSetState; -extern XInputGetCapabilities_t SDL_XInputGetCapabilities; -extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF) - -#define XINPUTGETSTATE SDL_XInputGetState -#define XINPUTSETSTATE SDL_XInputSetState -#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities -#define INVALID_XINPUT_USERID 255 -#define SDL_XINPUT_MAX_DEVICES 4 - -#ifndef XINPUT_CAPS_FFB_SUPPORTED -#define XINPUT_CAPS_FFB_SUPPORTED 0x0001 -#endif - #endif /* _INCLUDED_WINDOWS_H */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index 69f7da3aa..e67e66e68 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -75,6 +75,69 @@ static SDL_Thread *s_threadJoystick = NULL; static SDL_bool s_bJoystickThreadQuit = SDL_FALSE; static SDL_bool s_bXInputEnabled = SDL_TRUE; +XInputGetState_t SDL_XInputGetState = NULL; +XInputSetState_t SDL_XInputSetState = NULL; +XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL; +DWORD SDL_XInputVersion = 0; + +static HANDLE s_pXInputDLL = 0; +static int s_XInputDLLRefCount = 0; + +int +WIN_LoadXInputDLL(void) +{ + DWORD version = 0; + + if (s_pXInputDLL) { + SDL_assert(s_XInputDLLRefCount > 0); + s_XInputDLLRefCount++; + return 0; /* already loaded */ + } + + version = (1 << 16) | 4; + s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" ); // 1.4 Ships with Windows 8. + if (!s_pXInputDLL) { + version = (1 << 16) | 3; + s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); // 1.3 Ships with Vista and Win7, can be installed as a restributable component. + } + if (!s_pXInputDLL) { + s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); + } + if (!s_pXInputDLL) { + return -1; + } + + SDL_assert(s_XInputDLLRefCount == 0); + SDL_XInputVersion = version; + s_XInputDLLRefCount = 1; + + /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ + SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); + SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); + SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); + if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) { + WIN_UnloadXInputDLL(); + return -1; + } + + return 0; +} + +void +WIN_UnloadXInputDLL(void) +{ + if ( s_pXInputDLL ) { + SDL_assert(s_XInputDLLRefCount > 0); + if (--s_XInputDLLRefCount == 0) { + FreeLibrary( s_pXInputDLL ); + s_pXInputDLL = NULL; + } + } else { + SDL_assert(s_XInputDLLRefCount == 0); + } +} + + extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * ppDI, LPUNKNOWN punkOuter); diff --git a/src/joystick/windows/SDL_dxjoystick_c.h b/src/joystick/windows/SDL_dxjoystick_c.h index 6d4957815..13d0d451a 100644 --- a/src/joystick/windows/SDL_dxjoystick_c.h +++ b/src/joystick/windows/SDL_dxjoystick_c.h @@ -42,6 +42,65 @@ #include #include #include +#include + +/* typedef's for XInput structs we use */ +typedef struct +{ + WORD wButtons; + BYTE bLeftTrigger; + BYTE bRightTrigger; + SHORT sThumbLX; + SHORT sThumbLY; + SHORT sThumbRX; + SHORT sThumbRY; + DWORD dwPaddingReserved; +} XINPUT_GAMEPAD_EX; + +typedef struct +{ + DWORD dwPacketNumber; + XINPUT_GAMEPAD_EX Gamepad; +} XINPUT_STATE_EX; + +/* Forward decl's for XInput API's we load dynamically and use if available */ +typedef DWORD (WINAPI *XInputGetState_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + XINPUT_STATE_EX* pState // [out] Receives the current state + ); + +typedef DWORD (WINAPI *XInputSetState_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + XINPUT_VIBRATION* pVibration // [in, out] The vibration information to send to the controller + ); + +typedef DWORD (WINAPI *XInputGetCapabilities_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + DWORD dwFlags, // [in] Input flags that identify the device type + XINPUT_CAPABILITIES* pCapabilities // [out] Receives the capabilities + ); + +extern int WIN_LoadXInputDLL(void); +extern void WIN_UnloadXInputDLL(void); + +extern XInputGetState_t SDL_XInputGetState; +extern XInputSetState_t SDL_XInputSetState; +extern XInputGetCapabilities_t SDL_XInputGetCapabilities; +extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF) + +#define XINPUTGETSTATE SDL_XInputGetState +#define XINPUTSETSTATE SDL_XInputSetState +#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities +#define INVALID_XINPUT_USERID 255 +#define SDL_XINPUT_MAX_DEVICES 4 + +#ifndef XINPUT_CAPS_FFB_SUPPORTED +#define XINPUT_CAPS_FFB_SUPPORTED 0x0001 +#endif + #define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */ From f34606e3254d0f9807ab382cd080304551d32e26 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 10 Mar 2013 13:31:55 -0400 Subject: [PATCH 080/151] Fixed compiler warning. --- src/video/x11/edid-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/x11/edid-parse.c b/src/video/x11/edid-parse.c index 97831aadd..67e17e167 100644 --- a/src/video/x11/edid-parse.c +++ b/src/video/x11/edid-parse.c @@ -333,7 +333,7 @@ decode_standard_timings (const uchar *edid, MonitorInfo *info) if (first != 0x01 && second != 0x01) { int w = 8 * (first + 31); - int h; + int h = 0; switch (get_bits (second, 6, 7)) { From 8181152c53213aa577c6ac45347aee27dac1d628 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 10 Mar 2013 13:36:20 -0400 Subject: [PATCH 081/151] Patched to compile on Visual Studio. --- src/joystick/windows/SDL_dxjoystick.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index e67e66e68..aac20489f 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -33,6 +33,7 @@ * let it return 0 events. */ #include "SDL_error.h" +#include "SDL_assert.h" #include "SDL_events.h" #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" From 5bffed4b326ef3c822a218730dea161c766a5493 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Sun, 10 Mar 2013 16:28:20 -0700 Subject: [PATCH 082/151] Fix bug 1574 - updaterev.sh fails when path contains spaces --- build-scripts/updaterev.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build-scripts/updaterev.sh b/build-scripts/updaterev.sh index 61ae9b023..485d04580 100755 --- a/build-scripts/updaterev.sh +++ b/build-scripts/updaterev.sh @@ -10,11 +10,11 @@ header=$outdir/include/SDL_revision.h rev=`sh showrev.sh 2>/dev/null` if [ "$rev" != "" -a "$rev" != "hg-0:baadf00d" ]; then revnum=`echo $rev | sed 's,hg-\([0-9]*\).*,\1,'` - echo "#define SDL_REVISION \"$rev\"" >$header.new - echo "#define SDL_REVISION_NUMBER $revnum" >>$header.new + echo "#define SDL_REVISION \"$rev\"" >"$header.new" + echo "#define SDL_REVISION_NUMBER $revnum" >>"$header.new" if diff $header $header.new >/dev/null 2>&1; then - rm $header.new + rm "$header.new" else - mv $header.new $header + mv "$header.new" "$header" fi fi From f25403ba28a3a77ed29878933d43665f748f9e95 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 10 Mar 2013 21:10:10 -0700 Subject: [PATCH 083/151] Fixed bug 1751 - Direcftb renderer viewport behaviour differs from API description. tomaszewski.p According to API description: SDL_RenderSetViewport - Use this function to set the drawing area for rendering on the current target. DirectFB renderer in DirectFB_UpdateViewport function just sets clip on surface, instead of moving drawing area. Attached patch uses set clip rectangle to move {x,y} coordinates during draw and blit operations to be compatible with API description. --- src/video/directfb/SDL_DirectFB_render.c | 52 ++++++++++++++++++------ 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/video/directfb/SDL_DirectFB_render.c b/src/video/directfb/SDL_DirectFB_render.c index 4a1d52798..09a9bdd9d 100644 --- a/src/video/directfb/SDL_DirectFB_render.c +++ b/src/video/directfb/SDL_DirectFB_render.c @@ -953,13 +953,18 @@ static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = data->target; + DFBRegion clip_region; int i; DirectFB_ActivateRenderer(renderer); PrepareDraw(renderer); - for (i=0; i < count; i++) - SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y)); + destsurf->GetClip(destsurf, &clip_region); + for (i=0; i < count; i++) { + int x = points[i].x + clip_region.x1; + int y = points[i].y + clip_region.y1; + SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x, y, x, y)); + } return 0; error: return -1; @@ -970,6 +975,7 @@ static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = data->target; + DFBRegion clip_region; int i; DirectFB_ActivateRenderer(renderer); @@ -980,8 +986,14 @@ static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS)); #endif - for (i=0; i < count - 1; i++) - SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i+1].x, points[i+1].y)); + destsurf->GetClip(destsurf, &clip_region); + for (i=0; i < count - 1; i++) { + int x1 = points[i].x + clip_region.x1; + int y1 = points[i].y + clip_region.y1; + int x2 = points[i + 1].x + clip_region.x1; + int y2 = points[i + 1].y + clip_region.y1; + SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x1, y1, x2, y2)); + } return 0; error: @@ -993,15 +1005,21 @@ DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int c { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = data->target; + DFBRegion clip_region; int i; DirectFB_ActivateRenderer(renderer); PrepareDraw(renderer); - for (i=0; iDrawRectangle(destsurf, rects[i]->x, rects[i]->y, - rects[i]->w, rects[i]->h)); + destsurf->GetClip(destsurf, &clip_region); + for (i=0; ix, rects[i]->y, rects[i]->w, rects[i]->h}; + dst.x += clip_region.x1; + dst.y += clip_region.y1; + SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, dst.x, dst.y, + dst.w, dst.h)); + } return 0; error: @@ -1013,15 +1031,21 @@ DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int c { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = data->target; + DFBRegion clip_region; int i; DirectFB_ActivateRenderer(renderer); PrepareDraw(renderer); - for (i=0; iFillRectangle(destsurf, rects[i].x, rects[i].y, - rects[i].w, rects[i].h)); + destsurf->GetClip(destsurf, &clip_region); + for (i=0; iFillRectangle(destsurf, dst.x, dst.y, + dst.w, dst.h)); + } return 0; error: @@ -1037,6 +1061,7 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, DirectFB_TextureData *texturedata = (DirectFB_TextureData *) texture->driverdata; Uint8 alpha, r, g, b; + DFBRegion clip_region; DFBRectangle sr, dr; DirectFB_ActivateRenderer(renderer); @@ -1044,6 +1069,10 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, SDLtoDFBRect(srcrect, &sr); SDLtoDFBRect_Float(dstrect, &dr); + destsurf->GetClip(destsurf, &clip_region); + dr.x += clip_region.x1; + dr.y += clip_region.y1; + if (texturedata->display) { int px, py; SDL_Window *window = renderer->window; @@ -1098,9 +1127,6 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch); } - SDLtoDFBRect(srcrect, &sr); - SDLtoDFBRect_Float(dstrect, &dr); - alpha = r = g = b = 0xff; if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){ alpha = texture->a; From 6a2bff0cd16d99f01b5e34f753915527edf42692 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Tue, 12 Mar 2013 09:10:37 -0700 Subject: [PATCH 084/151] Fix bug 1560 - SDL_RWFromConstMem write operation returns -1 but should return 0. --- include/SDL_rwops.h | 2 +- src/file/SDL_rwops.c | 2 +- test/testautomation_rwops.c | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/SDL_rwops.h b/include/SDL_rwops.h index 933397bdf..68c8e5f0b 100644 --- a/include/SDL_rwops.h +++ b/include/SDL_rwops.h @@ -54,7 +54,7 @@ typedef struct SDL_RWops * Seek to \c offset relative to \c whence, one of stdio's whence values: * RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END * - * \return the final offset in the data stream. + * \return the final offset in the data stream, or -1 on error. */ Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset, int whence); diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 440294982..55f601e34 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -451,7 +451,7 @@ static size_t SDLCALL mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num) { SDL_SetError("Can't write to read-only memory"); - return (-1); + return (0); } static int SDLCALL diff --git a/test/testautomation_rwops.c b/test/testautomation_rwops.c index 6c12b28e1..101dccb2a 100644 --- a/test/testautomation_rwops.c +++ b/test/testautomation_rwops.c @@ -78,6 +78,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write) { char buf[sizeof(RWopsHelloWorldTestString)]; Sint64 i; + size_t s; int seekPos = SDLTest_RandomIntegerInRange(4, 8); /* Clear buffer */ @@ -89,13 +90,13 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write) SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i); /* Test write. */ - i = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1); + s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1); SDLTest_AssertPass("Call to SDL_RWwrite succeeded"); if (write) { - SDLTest_AssertCheck(i == (Sint64)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", i); + SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", s); } else { - SDLTest_AssertCheck(i != (Sint64)1, "Verify result of writing with SDL_RWwrite, expected !=1, got %i", i); + SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", s); } /* Test seek to random position */ @@ -109,13 +110,13 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write) SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i); /* Test read */ - i = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 ); + s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 ); SDLTest_AssertPass("Call to SDL_RWread succeeded"); SDLTest_AssertCheck( - i == (Sint64)(sizeof(RWopsHelloWorldTestString)-1), + s == (size_t)(sizeof(RWopsHelloWorldTestString)-1), "Verify result from SDL_RWread, expected %i, got %i", sizeof(RWopsHelloWorldTestString)-1, - i); + s); SDLTest_AssertCheck( SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0, "Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf); From fc436807a87eb7e1f153bd9fd5bc19f179466a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Tue, 12 Mar 2013 18:28:36 -0700 Subject: [PATCH 085/151] Add GameController mappings for popular controllers. This adds mappings for: - Another type of wired X360 controller - A wireless X360 controller - Logitech F710 (XInput and DInput modes) - Logitech F310 (XInput mode) - Logitech Cordless RumblePad 2 --- .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes src/joystick/SDL_gamecontroller.c | 6 ++++++ 4 files changed, 6 insertions(+) diff --git a/Xcode/TemplatesForXcodeTiger/SDL Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL Application/English.lproj/InfoPlist.strings index e612457676d964a8021d20ec90290d5c6c3d88c1..38224b5a6dc9494230bdffbcad9c8bd915f478d9 100755 GIT binary patch delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC diff --git a/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/English.lproj/InfoPlist.strings index e612457676d964a8021d20ec90290d5c6c3d88c1..38224b5a6dc9494230bdffbcad9c8bd915f478d9 100755 GIT binary patch delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC diff --git a/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/English.lproj/InfoPlist.strings index e612457676d964a8021d20ec90290d5c6c3d88c1..38224b5a6dc9494230bdffbcad9c8bd915f478d9 100755 GIT binary patch delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index e4929a30b..791e893bf 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -99,7 +99,13 @@ const char *s_ControllerMappings [] = "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", #elif defined(__LINUX__) "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", + "030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,x:b15,y:b12,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", + "030000006d0400001fc2000005030000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "030000006d04000019c2000011010000,Logitech F710 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // XXX: Guide. + "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7," #endif NULL }; From ae480eecfd0370c503b34c265517e686b9250f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Tue, 12 Mar 2013 18:28:40 -0700 Subject: [PATCH 086/151] Missing comma in one gamepad mapping. --- src/joystick/SDL_gamecontroller.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 791e893bf..c6e5b10a7 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -103,9 +103,9 @@ const char *s_ControllerMappings [] = "030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,x:b15,y:b12,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", "030000006d0400001fc2000005030000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", - "030000006d04000019c2000011010000,Logitech F710 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // XXX: Guide. + "030000006d04000019c2000011010000,Logitech F710 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // Guide button doesn't seem to be sent in DInput mode. "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", - "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7," + "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", #endif NULL }; From 42a673ce232f3613140a6f33296d2f33ac378f1a Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Wed, 13 Mar 2013 08:35:03 -0700 Subject: [PATCH 087/151] Fix bug 122 - SDL_RWops bug fixes: set RWops.type field, add input validation, add test coverage --- include/SDL_rwops.h | 8 ++ src/file/SDL_rwops.c | 26 ++++- test/testautomation_rwops.c | 195 +++++++++++++++++++++++++++++++++--- 3 files changed, 215 insertions(+), 14 deletions(-) diff --git a/include/SDL_rwops.h b/include/SDL_rwops.h index 68c8e5f0b..61c30920e 100644 --- a/include/SDL_rwops.h +++ b/include/SDL_rwops.h @@ -40,6 +40,14 @@ extern "C" { /* *INDENT-ON* */ #endif +/* RWops Types */ +#define SDL_RWOPS_UNKNOWN 0 /* Unknown stream type */ +#define SDL_RWOPS_WINFILE 1 /* Win32 file */ +#define SDL_RWOPS_STDFILE 2 /* Stdio file */ +#define SDL_RWOPS_JNIFILE 3 /* Android asset */ +#define SDL_RWOPS_MEMORY 4 /* Memory stream */ +#define SDL_RWOPS_MEMORY_RO 5 /* Read-Only memory stream */ + /** * This is the read/write operation structure -- very basic. */ diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 55f601e34..99010c3b7 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -513,6 +513,7 @@ SDL_RWFromFile(const char *file, const char *mode) rwops->read = Android_JNI_FileRead; rwops->write = Android_JNI_FileWrite; rwops->close = Android_JNI_FileClose; + rwops->type = SDL_RWOPS_JNIFILE; #elif defined(__WIN32__) rwops = SDL_AllocRW(); @@ -527,6 +528,7 @@ SDL_RWFromFile(const char *file, const char *mode) rwops->read = windows_file_read; rwops->write = windows_file_write; rwops->close = windows_file_close; + rwops->type = SDL_RWOPS_WINFILE; #elif HAVE_STDIO_H { @@ -570,6 +572,7 @@ SDL_RWFromFP(FILE * fp, SDL_bool autoclose) rwops->close = stdio_close; rwops->hidden.stdio.fp = fp; rwops->hidden.stdio.autoclose = autoclose; + rwops->type = SDL_RWOPS_STDFILE; } return (rwops); } @@ -585,7 +588,15 @@ SDL_RWFromFP(void * fp, SDL_bool autoclose) SDL_RWops * SDL_RWFromMem(void *mem, int size) { - SDL_RWops *rwops; + SDL_RWops *rwops = NULL; + if (!mem) { + SDL_InvalidParamError("mem"); + return (rwops); + } + if (!size) { + SDL_InvalidParamError("size"); + return (rwops); + } rwops = SDL_AllocRW(); if (rwops != NULL) { @@ -597,6 +608,7 @@ SDL_RWFromMem(void *mem, int size) rwops->hidden.mem.base = (Uint8 *) mem; rwops->hidden.mem.here = rwops->hidden.mem.base; rwops->hidden.mem.stop = rwops->hidden.mem.base + size; + rwops->type = SDL_RWOPS_MEMORY; } return (rwops); } @@ -604,7 +616,15 @@ SDL_RWFromMem(void *mem, int size) SDL_RWops * SDL_RWFromConstMem(const void *mem, int size) { - SDL_RWops *rwops; + SDL_RWops *rwops = NULL; + if (!mem) { + SDL_InvalidParamError("mem"); + return (rwops); + } + if (!size) { + SDL_InvalidParamError("size"); + return (rwops); + } rwops = SDL_AllocRW(); if (rwops != NULL) { @@ -616,6 +636,7 @@ SDL_RWFromConstMem(const void *mem, int size) rwops->hidden.mem.base = (Uint8 *) mem; rwops->hidden.mem.here = rwops->hidden.mem.base; rwops->hidden.mem.stop = rwops->hidden.mem.base + size; + rwops->type = SDL_RWOPS_MEMORY_RO; } return (rwops); } @@ -629,6 +650,7 @@ SDL_AllocRW(void) if (area == NULL) { SDL_OutOfMemory(); } + area->type = SDL_RWOPS_UNKNOWN; return (area); } diff --git a/test/testautomation_rwops.c b/test/testautomation_rwops.c index 101dccb2a..be93809db 100644 --- a/test/testautomation_rwops.c +++ b/test/testautomation_rwops.c @@ -21,16 +21,18 @@ const char* RWopsReadTestFilename = "rwops_read"; const char* RWopsWriteTestFilename = "rwops_write"; +const char* RWopsAlphabetFilename = "rwops_alphabet"; static const char RWopsHelloWorldTestString[] = "Hello World!"; static const char RWopsHelloWorldCompString[] = "Hello World!"; +static const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* Fixture */ void RWopsSetUp(void *arg) { - int fileLen = SDL_strlen(RWopsHelloWorldTestString); + int fileLen; FILE *handle; int writtenLen; int result; @@ -38,18 +40,32 @@ RWopsSetUp(void *arg) /* Clean up from previous runs (if any); ignore errors */ remove(RWopsReadTestFilename); remove(RWopsWriteTestFilename); + remove(RWopsAlphabetFilename); /* Create a test file */ handle = fopen(RWopsReadTestFilename, "w"); SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename); if (handle == NULL) return; - /* Write some known test into it */ + /* Write some known text into it */ + fileLen = SDL_strlen(RWopsHelloWorldTestString); writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle); SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen); result = fclose(handle); SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result); + /* Create a second test file */ + handle = fopen(RWopsAlphabetFilename, "w"); + SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsAlphabetFilename); + if (handle == NULL) return; + + /* Write alphabet text into it */ + fileLen = SDL_strlen(RWopsAlphabetString); + writtenLen = (int)fwrite(RWopsAlphabetString, 1, fileLen, handle); + SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen); + result = fclose(handle); + SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result); + SDLTest_AssertPass("Creation of test file completed"); } @@ -62,6 +78,8 @@ RWopsTearDown(void *arg) result = remove(RWopsReadTestFilename); SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result); remove(RWopsWriteTestFilename); + result = remove(RWopsAlphabetFilename); + SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsAlphabetFilename, result); SDLTest_AssertPass("Cleanup of test files completed"); } @@ -137,6 +155,14 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write) "Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i", sizeof(RWopsHelloWorldTestString)-2, i); + + /* Invalid whence seek */ + i = SDL_RWseek( rw, 0, 999 ); + SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded"); + SDLTest_AssertCheck( + i == (Sint64)(-1), + "Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i", + i); } /*! @@ -171,6 +197,18 @@ rwops_testParamNegative (void) SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded"); SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL"); + rwops = SDL_RWFromMem((void *)NULL, 10); + SDLTest_AssertPass("Call to SDL_RWFromMem(NULL, 10) succeeded"); + SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(NULL, 10) returns NULL"); + + rwops = SDL_RWFromMem((void *)RWopsAlphabetString, 0); + SDLTest_AssertPass("Call to SDL_RWFromMem(data, 0) succeeded"); + SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(data, 0) returns NULL"); + + rwops = SDL_RWFromConstMem((const void *)RWopsAlphabetString, 0); + SDLTest_AssertPass("Call to SDL_RWFromConstMem(data, 0) succeeded"); + SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromConstMem(data, 0) returns NULL"); + return TEST_COMPLETED; } @@ -178,13 +216,14 @@ rwops_testParamNegative (void) * @brief Tests opening from memory. * * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem - * http://wiki.libsdl.org/moin.cgi/SDL_RWClose + * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWClose */ int rwops_testMem (void) { char mem[sizeof(RWopsHelloWorldTestString)]; SDL_RWops *rw; + int result; /* Clear buffer */ SDL_zero(mem); @@ -197,12 +236,16 @@ rwops_testMem (void) /* Bail out if NULL */ if (rw == NULL) return TEST_ABORTED; + /* Check type */ + SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %d", SDL_RWOPS_MEMORY, rw->type); + /* Run generic tests */ _testGenericRWopsValidations(rw, 1); /* Close */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -219,6 +262,7 @@ int rwops_testConstMem (void) { SDL_RWops *rw; + int result; /* Open handle */ rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 ); @@ -228,12 +272,16 @@ rwops_testConstMem (void) /* Bail out if NULL */ if (rw == NULL) return TEST_ABORTED; + /* Check type */ + SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type); + /* Run generic tests */ _testGenericRWopsValidations( rw, 0 ); /* Close handle */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -250,6 +298,7 @@ int rwops_testFileRead(void) { SDL_RWops *rw; + int result; /* Read test. */ rw = SDL_RWFromFile(RWopsReadTestFilename, "r"); @@ -259,12 +308,28 @@ rwops_testFileRead(void) // Bail out if NULL if (rw == NULL) return TEST_ABORTED; + /* Check type */ +#if defined(ANDROID) + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE, + "Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type); +#elif defined(__WIN32__) + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_WINFILE, + "Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type); +#else + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE, + "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type); +#endif + /* Run generic tests */ _testGenericRWopsValidations( rw, 0 ); /* Close handle */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -280,6 +345,7 @@ int rwops_testFileWrite(void) { SDL_RWops *rw; + int result; /* Write test. */ rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+"); @@ -289,12 +355,28 @@ rwops_testFileWrite(void) // Bail out if NULL if (rw == NULL) return TEST_ABORTED; + /* Check type */ +#if defined(ANDROID) + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE, + "Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type); +#elif defined(__WIN32__) + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_WINFILE, + "Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type); +#else + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE, + "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type); +#endif + /* Run generic tests */ _testGenericRWopsValidations( rw, 1 ); /* Close handle */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -313,6 +395,7 @@ rwops_testFPRead(void) { FILE *fp; SDL_RWops *rw; + int result; /* Run read tests. */ fp = fopen(RWopsReadTestFilename, "r"); @@ -332,12 +415,18 @@ rwops_testFPRead(void) return TEST_ABORTED; } + /* Check type */ + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE, + "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type); + /* Run generic tests */ _testGenericRWopsValidations( rw, 0 ); /* Close handle - does fclose() */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -356,6 +445,7 @@ rwops_testFPWrite(void) { FILE *fp; SDL_RWops *rw; + int result; /* Run write tests. */ fp = fopen(RWopsWriteTestFilename, "w+"); @@ -375,12 +465,18 @@ rwops_testFPWrite(void) return TEST_ABORTED; } + /* Check type */ + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE, + "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type); + /* Run generic tests */ _testGenericRWopsValidations( rw, 1 ); /* Close handle - does fclose() */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -399,6 +495,11 @@ rwops_testAllocFree (void) SDLTest_AssertPass("Call to SDL_AllocRW() succeeded"); SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL"); if (rw==NULL) return TEST_ABORTED; + + /* Check type */ + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_UNKNOWN, + "Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %d", SDL_RWOPS_UNKNOWN, rw->type); /* Free context again */ SDL_FreeRW(rw); @@ -407,6 +508,72 @@ rwops_testAllocFree (void) return TEST_COMPLETED; } +/** + * @brief Compare memory and file reads + * + * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem + * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile + */ +int +rwops_testCompareRWFromMemWithRWFromFile(void) +{ + int slen = 26; + char buffer_file[27]; + char buffer_mem[27]; + size_t rv_file; + size_t rv_mem; + Uint64 sv_file; + Uint64 sv_mem; + SDL_RWops* rwops_file; + SDL_RWops* rwops_mem; + int size; + int result; + + + for (size=5; size<10; size++) + { + /* Terminate buffer */ + buffer_file[slen] = 0; + buffer_mem[slen] = 0; + + /* Read/seek from memory */ + rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen); + SDLTest_AssertPass("Call to SDL_RWFromMem()"); + rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6); + SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size); + sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END); + SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)"); + result = SDL_RWclose(rwops_mem); + SDLTest_AssertPass("Call to SDL_RWclose(mem)"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + + /* Read/see from file */ + rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r"); + SDLTest_AssertPass("Call to SDL_RWFromFile()"); + rv_file = SDL_RWread(rwops_file, buffer_file, size, 6); + SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size); + sv_file = SDL_RWseek(rwops_file, 0, SEEK_END); + SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)"); + result = SDL_RWclose(rwops_file); + SDLTest_AssertPass("Call to SDL_RWclose(file)"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + + /* Compare */ + SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", rv_mem, rv_file); + SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%llu sv_file=%llu", sv_mem, sv_file); + SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]); + SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]); + SDLTest_AssertCheck( + SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0, + "Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem); + SDLTest_AssertCheck( + SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0, + "Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file); + } + + return TEST_COMPLETED; +} + /** * @brief Tests writing and reading from file using endian aware functions. * @@ -435,6 +602,7 @@ rwops_testFileWriteReadEndian(void) Uint16 LE16test; Uint32 LE32test; Uint64 LE64test; + int cresult; for (mode = 0; mode < 3; mode++) { @@ -523,9 +691,9 @@ rwops_testFileWriteReadEndian(void) SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", LE64value, LE64test); /* Close handle */ - SDL_RWclose(rw); + cresult = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); - + SDLTest_AssertCheck(cresult == 0, "Verify result value is 0; got: %d", cresult); } return TEST_COMPLETED; @@ -562,10 +730,13 @@ static const SDLTest_TestCaseReference rwopsTest8 = static const SDLTest_TestCaseReference rwopsTest9 = { (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED }; +static const SDLTest_TestCaseReference rwopsTest10 = + { (SDLTest_TestCaseFp)rwops_testCompareRWFromMemWithRWFromFile, "rwops_testCompareRWFromMemWithRWFromFile", "Compare RWFromMem and RWFromFile RWops for read and seek", TEST_ENABLED }; + /* Sequence of RWops test cases */ static const SDLTest_TestCaseReference *rwopsTests[] = { &rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, - &rwopsTest7, &rwopsTest8, &rwopsTest9, NULL + &rwopsTest7, &rwopsTest8, &rwopsTest9, &rwopsTest10, NULL }; /* RWops test suite (global) */ From d1c430023ffdf104f1bfe86b1f77ef80d7093bf8 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Wed, 13 Mar 2013 09:14:45 -0700 Subject: [PATCH 088/151] Reformat SDL_VS2010.sln so WindowsExplorer VS type detection works again --- VisualC/SDL_VS2010.sln | 357 ++++++++++++++++++----------------------- 1 file changed, 160 insertions(+), 197 deletions(-) diff --git a/VisualC/SDL_VS2010.sln b/VisualC/SDL_VS2010.sln index f11f437b4..5b95292ab 100644 --- a/VisualC/SDL_VS2010.sln +++ b/VisualC/SDL_VS2010.sln @@ -1,197 +1,160 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "SDL\SDL_VS2010.vcxproj", "{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2main", "SDLmain\SDLmain_VS2010.vcxproj", "{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CE748C1F-3C21-4825-AA6A-F895A023F7E7}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loopwave", "tests\loopwave\loopwave_VS2010.vcxproj", "{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testplatform", "tests\testplatform\testplatform_VS2010.vcxproj", "{26932B24-EFC6-4E3A-B277-ED653DA37968}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testfile", "tests\testfile\testfile_VS2010.vcxproj", "{CAE4F1D0-314F-4B10-805B-0EFD670133A0}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgl2", "tests\testgl2\testgl2_VS2010.vcxproj", "{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checkkeys", "tests\checkkeys\checkkeys_VS2010.vcxproj", "{26828762-C95D-4637-9CB1-7F0979523813}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsprite2", "tests\testsprite2\testsprite2_VS2010.vcxproj", "{40FB7794-D3C3-4CFE-BCF4-A80C96635682}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testshape", "tests\testshape\testshape_VS2010.vcxproj", "{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testdraw2", "tests\testdraw2\testdraw2_VS2010.vcxproj", "{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testpower", "tests\testpower\testpower_VS2010.vcxproj", "{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2test", "SDLtest\SDLtest_VS2010.vcxproj", "{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testautomation", "tests\testautomation\testautomation_vs2010.vcxproj", "{FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|Win32.ActiveCfg = Debug|Win32 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|Win32.Build.0 = Debug|Win32 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.ActiveCfg = Debug|x64 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.Build.0 = Debug|x64 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.ActiveCfg = Release|Win32 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.Build.0 = Release|Win32 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.ActiveCfg = Release|x64 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.Build.0 = Release|x64 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|Win32.ActiveCfg = Debug|Win32 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|Win32.Build.0 = Debug|Win32 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.ActiveCfg = Debug|x64 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.Build.0 = Debug|x64 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|Win32.ActiveCfg = Release|Win32 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|Win32.Build.0 = Release|Win32 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.ActiveCfg = Release|x64 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.Build.0 = Release|x64 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|Win32.ActiveCfg = Debug|Win32 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|Win32.Build.0 = Debug|Win32 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.ActiveCfg = Debug|x64 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.Build.0 = Debug|x64 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.ActiveCfg = Release|Win32 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.Build.0 = Release|Win32 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.ActiveCfg = Release|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.ActiveCfg = Debug|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.Build.0 = Debug|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.ActiveCfg = Debug|x64 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.Build.0 = Debug|x64 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.ActiveCfg = Release|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.Build.0 = Release|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.ActiveCfg = Release|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.ActiveCfg = Debug|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.Build.0 = Debug|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.ActiveCfg = Debug|x64 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.Build.0 = Debug|x64 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.ActiveCfg = Release|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.Build.0 = Release|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.ActiveCfg = Release|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.ActiveCfg = Debug|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.Build.0 = Debug|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.ActiveCfg = Debug|x64 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.Build.0 = Debug|x64 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.ActiveCfg = Release|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.Build.0 = Release|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.ActiveCfg = Release|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.ActiveCfg = Debug|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.Build.0 = Debug|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.ActiveCfg = Debug|x64 - {26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.Build.0 = Debug|x64 - {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.ActiveCfg = Release|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.Build.0 = Release|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.ActiveCfg = Release|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.ActiveCfg = Debug|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.Build.0 = Debug|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.ActiveCfg = Debug|x64 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.Build.0 = Debug|x64 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.ActiveCfg = Release|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.Build.0 = Release|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.ActiveCfg = Release|Win32 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.ActiveCfg = Debug|Win32 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.Build.0 = Debug|Win32 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.ActiveCfg = Debug|x64 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.Build.0 = Debug|x64 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.ActiveCfg = Release|Win32 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.ActiveCfg = Release|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.ActiveCfg = Debug|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.Build.0 = Debug|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.ActiveCfg = Debug|x64 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.Build.0 = Debug|x64 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.ActiveCfg = Release|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.Build.0 = Release|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.ActiveCfg = Release|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.ActiveCfg = Debug|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.Build.0 = Debug|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.ActiveCfg = Debug|x64 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.Build.0 = Debug|x64 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.ActiveCfg = Release|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.Build.0 = Release|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.ActiveCfg = Release|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.ActiveCfg = Debug|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.Build.0 = Debug|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.ActiveCfg = Debug|x64 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.Build.0 = Debug|x64 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|Win32.ActiveCfg = Release|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|Win32.Build.0 = Release|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|x64.ActiveCfg = Release|x64 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|x64.Build.0 = Release|x64 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|Win32.ActiveCfg = Debug|Win32 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|Win32.Build.0 = Debug|Win32 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|x64.ActiveCfg = Debug|x64 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|x64.Build.0 = Debug|x64 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|Win32.ActiveCfg = Release|Win32 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|Win32.Build.0 = Release|Win32 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|x64.ActiveCfg = Release|x64 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {26932B24-EFC6-4E3A-B277-ED653DA37968} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {CAE4F1D0-314F-4B10-805B-0EFD670133A0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {26828762-C95D-4637-9CB1-7F0979523813} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {40FB7794-D3C3-4CFE-BCF4-A80C96635682} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "SDL\SDL_VS2010.vcxproj", "{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2main", "SDLmain\SDLmain_VS2010.vcxproj", "{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CE748C1F-3C21-4825-AA6A-F895A023F7E7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loopwave", "tests\loopwave\loopwave_VS2010.vcxproj", "{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testplatform", "tests\testplatform\testplatform_VS2010.vcxproj", "{26932B24-EFC6-4E3A-B277-ED653DA37968}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testfile", "tests\testfile\testfile_VS2010.vcxproj", "{CAE4F1D0-314F-4B10-805B-0EFD670133A0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgl2", "tests\testgl2\testgl2_VS2010.vcxproj", "{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checkkeys", "tests\checkkeys\checkkeys_VS2010.vcxproj", "{26828762-C95D-4637-9CB1-7F0979523813}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsprite2", "tests\testsprite2\testsprite2_VS2010.vcxproj", "{40FB7794-D3C3-4CFE-BCF4-A80C96635682}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testshape", "tests\testshape\testshape_VS2010.vcxproj", "{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testdraw2", "tests\testdraw2\testdraw2_VS2010.vcxproj", "{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testpower", "tests\testpower\testpower_VS2010.vcxproj", "{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2test", "SDLtest\SDLtest_VS2010.vcxproj", "{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testautomation", "tests\testautomation\testautomation_vs2010.vcxproj", "{FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|Win32.ActiveCfg = Debug|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|Win32.Build.0 = Debug|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.ActiveCfg = Debug|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.Build.0 = Debug|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.ActiveCfg = Release|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.Build.0 = Release|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.ActiveCfg = Release|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.Build.0 = Release|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|Win32.ActiveCfg = Debug|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|Win32.Build.0 = Debug|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.ActiveCfg = Debug|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.Build.0 = Debug|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|Win32.ActiveCfg = Release|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|Win32.Build.0 = Release|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.ActiveCfg = Release|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.Build.0 = Release|x64 + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|Win32.ActiveCfg = Debug|Win32 + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|Win32.Build.0 = Debug|Win32 + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.ActiveCfg = Debug|x64 + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.Build.0 = Debug|x64 + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.ActiveCfg = Release|Win32 + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.Build.0 = Release|Win32 + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.ActiveCfg = Release|x64 + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.Build.0 = Release|x64 + {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.ActiveCfg = Debug|Win32 + {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.Build.0 = Debug|Win32 + {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.ActiveCfg = Debug|x64 + {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.Build.0 = Debug|x64 + {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.ActiveCfg = Release|Win32 + {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.Build.0 = Release|Win32 + {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.ActiveCfg = Release|x64 + {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.Build.0 = Release|x64 + {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.ActiveCfg = Debug|Win32 + {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.Build.0 = Debug|Win32 + {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.ActiveCfg = Debug|x64 + {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.Build.0 = Debug|x64 + {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.ActiveCfg = Release|Win32 + {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.Build.0 = Release|Win32 + {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.ActiveCfg = Release|x64 + {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.Build.0 = Release|x64 + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.ActiveCfg = Debug|Win32 + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.Build.0 = Debug|Win32 + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.ActiveCfg = Debug|x64 + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.Build.0 = Debug|x64 + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.ActiveCfg = Release|Win32 + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.Build.0 = Release|Win32 + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.ActiveCfg = Release|x64 + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.Build.0 = Release|x64 + {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.ActiveCfg = Debug|Win32 + {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.Build.0 = Debug|Win32 + {26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.ActiveCfg = Debug|x64 + {26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.Build.0 = Debug|x64 + {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.ActiveCfg = Release|Win32 + {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.Build.0 = Release|Win32 + {26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.ActiveCfg = Release|x64 + {26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.Build.0 = Release|x64 + {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.ActiveCfg = Debug|Win32 + {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.Build.0 = Debug|Win32 + {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.ActiveCfg = Debug|x64 + {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.Build.0 = Debug|x64 + {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.ActiveCfg = Release|Win32 + {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.Build.0 = Release|Win32 + {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.ActiveCfg = Release|x64 + {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.Build.0 = Release|x64 + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.ActiveCfg = Debug|Win32 + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.Build.0 = Debug|Win32 + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.ActiveCfg = Debug|x64 + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.Build.0 = Debug|x64 + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.ActiveCfg = Release|Win32 + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.Build.0 = Release|Win32 + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.ActiveCfg = Release|x64 + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.Build.0 = Release|x64 + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.ActiveCfg = Debug|Win32 + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.Build.0 = Debug|Win32 + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.ActiveCfg = Debug|x64 + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.Build.0 = Debug|x64 + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.ActiveCfg = Release|Win32 + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.Build.0 = Release|Win32 + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.ActiveCfg = Release|x64 + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.Build.0 = Release|x64 + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.ActiveCfg = Debug|Win32 + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.Build.0 = Debug|Win32 + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.ActiveCfg = Debug|x64 + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.Build.0 = Debug|x64 + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.ActiveCfg = Release|Win32 + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.Build.0 = Release|Win32 + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.ActiveCfg = Release|x64 + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.Build.0 = Release|x64 + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.ActiveCfg = Debug|Win32 + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.Build.0 = Debug|Win32 + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.ActiveCfg = Debug|x64 + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.Build.0 = Debug|x64 + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|Win32.ActiveCfg = Release|Win32 + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|Win32.Build.0 = Release|Win32 + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|x64.ActiveCfg = Release|x64 + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|x64.Build.0 = Release|x64 + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|Win32.ActiveCfg = Debug|Win32 + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|Win32.Build.0 = Debug|Win32 + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|x64.ActiveCfg = Debug|x64 + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|x64.Build.0 = Debug|x64 + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|Win32.ActiveCfg = Release|Win32 + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|Win32.Build.0 = Release|Win32 + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|x64.ActiveCfg = Release|x64 + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {40FB7794-D3C3-4CFE-BCF4-A80C96635682} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {CAE4F1D0-314F-4B10-805B-0EFD670133A0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {8B5CFB38-CCBA-40A8-AD7A-89C57B070884} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {26932B24-EFC6-4E3A-B277-ED653DA37968} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {EDEA9D00-AF64-45DE-8F60-5957048F2F0F} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {26828762-C95D-4637-9CB1-7F0979523813} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} + EndGlobalSection +EndGlobal From 124288fdb9ef1944310aa8135d43976f85b8eeeb Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 13 Mar 2013 21:41:43 -0700 Subject: [PATCH 089/151] XDnD implementation from Davey Taylor, need some cleanup --- src/video/x11/SDL_x11events.c | 215 +++++++++++++++++++++++++++++++++- src/video/x11/SDL_x11video.c | 9 ++ src/video/x11/SDL_x11video.h | 11 +- src/video/x11/SDL_x11window.c | 6 + src/video/x11/SDL_x11window.h | 2 + 5 files changed, 240 insertions(+), 3 deletions(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 2e23bc7d9..916ca9662 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -41,6 +41,62 @@ #include +typedef struct { + unsigned char *data; + int format, count; + Atom type; +} SDL_x11Prop; + +/* Reads property + Must call XFree on results + */ +static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop) +{ + unsigned char *ret=NULL; + Atom type; + int fmt; + unsigned long count; + unsigned long bytes_left; + int bytes_fetch = 0; + + do { + if (ret != 0) XFree(ret); + XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret); + bytes_fetch += bytes_left; + } while (bytes_left != 0); + + p->data=ret; + p->format=fmt; + p->count=count; + p->type=type; +} + +/* Find text-uri-list in a list of targets and return it's atom + if available, else return None */ +static Atom X11_PickTarget(Display *disp, Atom list[], int list_count) +{ + Atom request = None; + char *name; + int i; + for (i=0; i < list_count && request == None; i++) { + name = XGetAtomName(disp, list[i]); + if (strcmp("text/uri-list", name)==0) request = list[i]; + XFree(name); + } + return request; +} + +/* Wrapper for X11_PickTarget for a maximum of three targets, a special + case in the Xdnd protocol */ +static Atom X11_PickTargetFromAtoms(Display *disp, Atom a0, Atom a1, Atom a2) +{ + int count=0; + Atom atom[3]; + if (a0 != None) atom[count++] = a0; + if (a1 != None) atom[count++] = a1; + if (a2 != None) atom[count++] = a2; + return X11_PickTarget(disp, atom, count); +} /*#define DEBUG_XEVENTS*/ /* Check to see if this is a repeated key. @@ -92,6 +148,41 @@ static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks) return SDL_FALSE; } +/* Convert URI to local filename + return filename if possible, else NULL +*/ +static char* X11_URIToLocal(char* uri) { + char *file = NULL; + + if (memcmp(uri,"file:/",6) == 0) uri += 6; /* local file? */ + else if (strstr(uri,":/") != NULL) return file; /* wrong scheme */ + + SDL_bool local = uri[0] != '/' || ( uri[0] != '\0' && uri[1] == '/' ); + + /* got a hostname? */ + if ( !local && uri[0] == '/' && uri[2] != '/' ) { + char* hostname_end = strchr( uri+1, '/' ); + if ( hostname_end != NULL ) { + char hostname[ 257 ]; + if ( gethostname( hostname, 255 ) == 0 ) { + hostname[ 256 ] = '\0'; + if ( memcmp( uri+1, hostname, hostname_end - ( uri+1 )) == 0 ) { + uri = hostname_end + 1; + local = SDL_TRUE; + } + } + } + } + if ( local ) { + file = uri; + if ( uri[1] == '/' ) { + file++; + } else { + file--; + } + } + return file; +} #if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS static void X11_HandleGenericEvent(SDL_VideoData *videodata,XEvent event) @@ -400,7 +491,68 @@ X11_DispatchEvent(_THIS) /* Have we been requested to quit (or another client message?) */ case ClientMessage:{ - if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) && + + int xdnd_version=0; + + if (xevent.xclient.message_type == videodata->XdndEnter) { + SDL_bool use_list = xevent.xclient.data.l[1] & 1; + data->xdnd_source = xevent.xclient.data.l[0]; + xdnd_version = ( xevent.xclient.data.l[1] >> 24); + if (use_list) { + /* fetch conversion targets */ + SDL_x11Prop p; + X11_ReadProperty(&p, display, data->xdnd_source, videodata->XdndTypeList); + /* pick one */ + data->xdnd_req = X11_PickTarget(display, (Atom*)p.data, p.count); + XFree(p.data); + } else { + /* pick from list of three */ + data->xdnd_req = X11_PickTargetFromAtoms(display, xevent.xclient.data.l[2], xevent.xclient.data.l[3], xevent.xclient.data.l[4]); + } + } + else if (xevent.xclient.message_type == videodata->XdndPosition) { + + /* reply with status */ + XClientMessageEvent m; + memset(&m, 0, sizeof(XClientMessageEvent)); + m.type = ClientMessage; + m.display = xevent.xclient.display; + m.window = xevent.xclient.data.l[0]; + m.message_type = videodata->XdndStatus; + m.format=32; + m.data.l[0] = data->xwindow; + m.data.l[1] = (data->xdnd_req != None); + m.data.l[2] = 0; /* specify an empty rectangle */ + m.data.l[3] = 0; + m.data.l[4] = videodata->XdndActionCopy; /* we only accept copying anyway */ + + XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); + XFlush(display); + } + else if(xevent.xclient.message_type == videodata->XdndDrop) { + if (data->xdnd_req == None) { + /* say again - not interested! */ + XClientMessageEvent m; + memset(&m, 0, sizeof(XClientMessageEvent)); + m.type = ClientMessage; + m.display = xevent.xclient.display; + m.window = xevent.xclient.data.l[0]; + m.message_type = videodata->XdndFinished; + m.format=32; + m.data.l[0] = data->xwindow; + m.data.l[1] = 0; + m.data.l[2] = None; /* fail! */ + XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); + } else { + /* convert */ + if(xdnd_version >= 1) { + XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent.xclient.data.l[2]); + } else { + XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, CurrentTime); + } + } + } + else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) && (xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == videodata->_NET_WM_PING)) { Window root = DefaultRootWindow(display); @@ -601,7 +753,66 @@ X11_DispatchEvent(_THIS) printf("window %p: SelectionNotify (requestor = %ld, target = %ld)\n", data, xevent.xselection.requestor, xevent.xselection.target); #endif - videodata->selection_waiting = SDL_FALSE; + Atom target = xevent.xselection.target; + if (target == data->xdnd_req) { + + /* read data */ + SDL_x11Prop p; + X11_ReadProperty(&p, display, data->xwindow, videodata->PRIMARY); + + if(p.format==8) { + SDL_bool expect_lf = SDL_FALSE; + char *start = NULL; + char *scan = (char*)p.data; + char *fn; + char *uri; + int length = 0; + while (p.count--) { + if (!expect_lf) { + if (*scan==0x0D) { + expect_lf = SDL_TRUE; + } else if(start == NULL) { + start = scan; + length = 0; + } + length++; + } else { + if (*scan==0x0A && length>0) { + uri = malloc(length--); + memcpy(uri, start, length); + uri[length] = 0; + fn = X11_URIToLocal(uri); + if (fn) SDL_SendDropFile(fn); + free(uri); + } + expect_lf = SDL_FALSE; + start = NULL; + } + scan++; + } + } + + XFree(p.data); + + /* send reply */ + XClientMessageEvent m; + memset(&m, 0, sizeof(XClientMessageEvent)); + m.type = ClientMessage; + m.display = display; + m.window = data->xdnd_source; + m.message_type = videodata->XdndFinished; + m.format=32; + m.data.l[0] = data->xwindow; + m.data.l[1] = 1; + m.data.l[2] = videodata->XdndActionCopy; + XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m); + + XSync(display, False); + + } else { + videodata->selection_waiting = SDL_FALSE; + } + } break; diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 351511b10..5288e520f 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -524,6 +524,15 @@ X11_VideoInit(_THIS) GET_ATOM(_NET_WM_PING); GET_ATOM(_NET_ACTIVE_WINDOW); GET_ATOM(UTF8_STRING); + GET_ATOM(PRIMARY); + GET_ATOM(XdndEnter); + GET_ATOM(XdndPosition); + GET_ATOM(XdndStatus); + GET_ATOM(XdndTypeList); + GET_ATOM(XdndActionCopy); + GET_ATOM(XdndDrop); + GET_ATOM(XdndFinished); + GET_ATOM(XdndSelection); /* Detect the window manager */ X11_CheckWindowManager(_this); diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index 392c3896b..9411b7b7e 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -101,7 +101,16 @@ typedef struct SDL_VideoData Atom _NET_WM_PING; Atom _NET_ACTIVE_WINDOW; Atom UTF8_STRING; - + Atom PRIMARY; + Atom XdndEnter; + Atom XdndPosition; + Atom XdndStatus; + Atom XdndTypeList; + Atom XdndActionCopy; + Atom XdndDrop; + Atom XdndFinished; + Atom XdndSelection; + SDL_Scancode key_layout[256]; SDL_bool selection_waiting; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 5ebe574ac..6e66149eb 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -344,6 +344,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) Atom _NET_WM_WINDOW_TYPE; Atom _NET_WM_WINDOW_TYPE_NORMAL; Atom _NET_WM_PID; + Atom XdndAware, xdnd_version = 5; Uint32 fevent = 0; #if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 @@ -567,6 +568,11 @@ X11_CreateWindow(_THIS, SDL_Window * window) PropertyChangeMask | StructureNotifyMask | KeymapStateMask | fevent)); + XdndAware = XInternAtom(display, "XdndAware", False); + XChangeProperty(display, w, XdndAware, XA_ATOM, 32, + PropModeReplace, + (unsigned char*)&xdnd_version, 1); + XFlush(display); return 0; diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h index 76e20549c..b9cb750b6 100644 --- a/src/video/x11/SDL_x11window.h +++ b/src/video/x11/SDL_x11window.h @@ -57,6 +57,8 @@ typedef struct Uint32 pending_focus_time; XConfigureEvent last_xconfigure; struct SDL_VideoData *videodata; + Atom xdnd_req; + Window xdnd_source; } SDL_WindowData; extern void X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags); From e79e3b23431dd4911825f239a8c4705a0f8fa4d1 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 15 Mar 2013 01:02:30 -0400 Subject: [PATCH 090/151] Added an SDL_FORCE_INLINE macro. --- include/begin_code.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/begin_code.h b/include/begin_code.h index cbfc14d8e..61b8250d1 100644 --- a/include/begin_code.h +++ b/include/begin_code.h @@ -128,6 +128,14 @@ #define __inline__ #endif +#if defined(_MSC_VER) +#define SDL_FORCE_INLINE __forceinline +#elif defined(__GNUC__) || defined(__clang__) +#define SDL_FORCE_INLINE __attribute__((always_inline)) static inline +#else +#define SDL_FORCE_INLINE static __inline__ +#endif + /* Apparently this is needed by several Windows compilers */ #if !defined(__MACH__) #ifndef NULL From 7e934f8f75a975a73556f3c8b68c1779b0eac547 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 15 Mar 2013 01:01:20 -0400 Subject: [PATCH 091/151] Improvements to stdlib. All SDL_* functions are always available as real symbols, so you can always link against them as a stable ABI. By default, however, all the things that might have dithered down to macros in your application are now force-inlined, to give you the same effect as before and theoretically better performance, but still solve the classic macro problems. Elsewhere, we provide real functions for these things that simply wrap the inline functions, in case one needs to have a real function available. Also: this exposed bugs: SDL_abs() does something different if you had the macro vs the libc function, SDL_memcpy() returns a void* in the function but not the macro, etc. --- include/SDL_stdinc.h | 654 +++++++++++++++++++++------------------- src/stdlib/SDL_getenv.c | 115 ++++--- src/stdlib/SDL_iconv.c | 18 +- src/stdlib/SDL_malloc.c | 13 +- src/stdlib/SDL_qsort.c | 15 +- src/stdlib/SDL_stdlib.c | 19 ++ src/stdlib/SDL_string.c | 206 ++++++++++--- 7 files changed, 626 insertions(+), 414 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 0bd372607..ca52376ff 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -194,6 +194,10 @@ SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ /** \endcond */ +#if !defined(wchar_t) && defined(__NINTENDODS__) +#define wchar_t short /* TODO: figure out why libnds doesn't have this */ +#endif + #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus @@ -202,30 +206,6 @@ extern "C" { /* *INDENT-ON* */ #endif -#ifdef HAVE_MALLOC -#define SDL_malloc malloc -#else -extern DECLSPEC void *SDLCALL SDL_malloc(size_t size); -#endif - -#ifdef HAVE_CALLOC -#define SDL_calloc calloc -#else -extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size); -#endif - -#ifdef HAVE_REALLOC -#define SDL_realloc realloc -#else -extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size); -#endif - -#ifdef HAVE_FREE -#define SDL_free free -#else -extern DECLSPEC void SDLCALL SDL_free(void *mem); -#endif - #if defined(HAVE_ALLOCA) && !defined(alloca) # if defined(HAVE_ALLOCA_H) # include @@ -256,380 +236,443 @@ char *alloca(); #define SDL_stack_free(data) SDL_free(data) #endif -#ifdef HAVE_GETENV -#define SDL_getenv getenv -#else + +/* SDL stdinc inline functions: + + The theory here is that, by default, we forcibly inline what we can--with + real inline functions that avoid macro side-effects--and your app will use + the inline version by default. However, we expose a non-inline version + too, which internally just wraps the inline version in a real function, + so the symbol is always available in the library even if your app + bypassed it with the inline version. The SDL_*_inline versions aren't + guaranteed to exist, so never call them directly; use SDL_* instead, + and trust the system to give you the right thing. + + The benefit here is that you can dlsym() these functions, which you + couldn't if you had macros, you can link against a foreign build of SDL + even if you configured differently, and you can drop the unconfigured SDL + headers into a project without #defining HAVE_MALLOC (etc) and still link. +*/ + +extern DECLSPEC void *SDLCALL SDL_malloc(size_t size); +#ifdef HAVE_MALLOC +SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); } +#define SDL_malloc SDL_malloc_inline +#endif + +extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size); +#ifdef HAVE_CALLOC +SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); } +#define SDL_calloc SDL_calloc_inline +#endif + +extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size); +#ifdef HAVE_REALLOC +SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); } +#define SDL_realloc SDL_realloc_inline +#endif + +extern DECLSPEC void SDLCALL SDL_free(void *mem); +#ifdef HAVE_FREE +SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); } +#define SDL_free SDL_free_inline +#endif + extern DECLSPEC char *SDLCALL SDL_getenv(const char *name); +#ifdef HAVE_GETENV +SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); } +#define SDL_getenv SDL_getenv_inline #endif -/* SDL_putenv() has moved to SDL_compat. */ +extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite); #ifdef HAVE_SETENV -#define SDL_setenv setenv -#else -extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, - int overwrite); +SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); } +#define SDL_setenv SDL_setenv_inline #endif +extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)); #ifdef HAVE_QSORT -#define SDL_qsort qsort -#else -extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, - int (*compare) (const void *, - const void *)); +SDL_FORCE_INLINE void SDL_qsort_inline(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { return qsort(base, nmemb, size, compare); } +#define SDL_qsort SDL_qsort_inline #endif +extern DECLSPEC int SDLCALL SDL_abs(int x); #ifdef HAVE_ABS -#define SDL_abs abs +SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); } #else -#define SDL_abs(X) ((X) < 0 ? -(X) : (X)) +SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); } #endif +#define SDL_abs SDL_abs_inline -#define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) -#define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) +/* !!! FIXME: these have side effects. You probably shouldn't use them. */ +/* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */ +#define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) +#define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) +extern DECLSPEC int SDLCALL SDL_isdigit(int x); +extern DECLSPEC int SDLCALL SDL_isspace(int x); +extern DECLSPEC int SDLCALL SDL_toupper(int x); +extern DECLSPEC int SDLCALL SDL_tolower(int x); #ifdef HAVE_CTYPE_H -#define SDL_isdigit(X) isdigit(X) -#define SDL_isspace(X) isspace(X) -#define SDL_toupper(X) toupper(X) -#define SDL_tolower(X) tolower(X) +SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); } +SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); } +SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); } +SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); } #else -#define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9')) -#define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n')) -#define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X)) -#define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X)) +SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); } +SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); } +SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); } +SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); } #endif +#define SDL_isdigit SDL_isdigit_inline +#define SDL_isspace SDL_isspace_inline +#define SDL_toupper SDL_toupper_inline +#define SDL_tolower SDL_tolower_inline -#ifdef HAVE_MEMSET -#define SDL_memset memset -#else extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len); +#ifdef HAVE_MEMSET +SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); } +#define SDL_memset SDL_memset_inline #endif -#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) -#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) +#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) +#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) + +/* !!! FIXME: does this _really_ beat memset() on any modern platform? */ +SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len) +{ #if defined(__GNUC__) && defined(i386) -#define SDL_memset4(dst, val, len) \ -do { \ - int u0, u1, u2; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; stosl\n\t" \ - : "=&D" (u0), "=&a" (u1), "=&c" (u2) \ - : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len)) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memset4 -#define SDL_memset4(dst, val, len) \ -do { \ - unsigned _count = (len); \ - unsigned _n = (_count + 3) / 4; \ - Uint32 *_p = SDL_static_cast(Uint32 *, dst); \ - Uint32 _val = (val); \ - if (len == 0) break; \ - switch (_count % 4) { \ - case 0: do { *_p++ = _val; \ - case 3: *_p++ = _val; \ - case 2: *_p++ = _val; \ - case 1: *_p++ = _val; \ - } while ( --_n ); \ - } \ -} while(0) + int u0, u1, u2; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; stosl \n\t" + : "=&D" (u0), "=&a" (u1), "=&c" (u2) + : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len)) + : "memory" + ); +/* !!! FIXME: amd64? */ +#else + unsigned int _count = (len); + unsigned int _n = (_count + 3) / 4; + Uint32 *_p = SDL_static_cast(Uint32 *, dst); + Uint32 _val = (val); + if (len == 0) + return; + switch (_count % 4) + { + case 0: do { *_p++ = _val; + case 3: *_p++ = _val; + case 2: *_p++ = _val; + case 1: *_p++ = _val; + } while ( --_n ); + } #endif +} -/* We can count on memcpy existing on Mac OS X and being well-tuned. */ + +extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len); #if defined(__MACOSX__) -#define SDL_memcpy memcpy +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + /* We can count on memcpy existing on Mac OS X and being well-tuned. */ + return memcpy(dst, src, len); +} +#define SDL_memcpy SDL_memcpy_inline #elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__) -#define SDL_memcpy(dst, src, len) \ -do { \ - int u0, u1, u2; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; movsl\n\t" \ - "testb $2,%b4\n\t" \ - "je 1f\n\t" \ - "movsw\n" \ - "1:\ttestb $1,%b4\n\t" \ - "je 2f\n\t" \ - "movsb\n" \ - "2:" \ - : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ - : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memcpy -#ifdef HAVE_MEMCPY -#define SDL_memcpy memcpy -#elif defined(HAVE_BCOPY) -#define SDL_memcpy(d, s, n) bcopy((s), (d), (n)) -#else -extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, - size_t len); -#endif +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */ + /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */ + /* !!! FIXME: amd64? */ + int u0, u1, u2; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; movsl \n\t" + "testb $2,%b4 \n\t" + "je 1f \n\t" + "movsw \n" + "1:\ttestb $1,%b4 \n\t" + "je 2f \n\t" + "movsb \n" + "2:" + : "=&c" (u0), "=&D" (u1), "=&S" (u2) + : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src) + : "memory" + ); + return dst; +} +#define SDL_memcpy SDL_memcpy_inline +#elif defined(HAVE_MEMCPY) +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + return memcpy(dst, src, len); +} +#define SDL_memcpy SDL_memcpy_inline +#elif defined(HAVE_BCOPY) /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */ +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + bcopy(src, dst, len); + return dst; +} +#define SDL_memcpy SDL_memcpy_inline #endif -/* We can count on memcpy existing on Mac OS X and being well-tuned. */ + +SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords) +{ #if defined(__MACOSX__) -#define SDL_memcpy4(dst, src, len) SDL_memcpy((dst), (src), (len) << 2) + /* We can count on memcpy existing on Mac OS X and being well-tuned. */ + return memcpy(dst, src, dwords * 4); #elif defined(__GNUC__) && defined(i386) -#define SDL_memcpy4(dst, src, len) \ -do { \ - int ecx, edi, esi; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; movsl" \ - : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \ - : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memcpy4 -#define SDL_memcpy4(dst, src, len) SDL_memcpy((dst), (src), (len) << 2) + /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */ + /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */ + /* !!! FIXME: amd64? */ + int ecx, edi, esi; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; movsl \n\t" + : "=&c" (ecx), "=&D" (edi), "=&S" (esi) + : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src) + : "memory" + ); + return dst; +#else + return SDL_memcpy(dst, src, dwords * 4); #endif +} +extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len); #ifdef HAVE_MEMMOVE -#define SDL_memmove memmove -#else -extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, - size_t len); +SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); } +#define SDL_memmove SDL_memmove_inline #endif +extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len); #ifdef HAVE_MEMCMP -#define SDL_memcmp memcmp -#else -extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, - size_t len); +SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); } +#define SDL_memcmp SDL_memcmp_inline #endif +extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str); #ifdef HAVE_STRLEN -#define SDL_strlen strlen -#else -extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); +SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); } +#define SDL_strlen SDL_strlen_inline #endif +extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr); #ifdef HAVE_WCSLEN -#define SDL_wcslen wcslen -#else -#if !defined(wchar_t) && defined(__NINTENDODS__) -#define wchar_t short /* TODO: figure out why libnds doesn't have this */ -#endif -extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string); +SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); } +#define SDL_wcslen SDL_wcslen_inline #endif -#ifdef HAVE_WCSLCPY -#define SDL_wcslcpy wcslcpy -#else extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen); +#ifdef HAVE_WCSLCPY +SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); } +#define SDL_wcslcpy SDL_wcslcpy_inline #endif -#ifdef HAVE_WCSLCAT -#define SDL_wcslcat wcslcat -#else extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen); +#ifdef HAVE_WCSLCAT +SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); } +#define SDL_wcslcat SDL_wcslcat_inline #endif - +extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen); #ifdef HAVE_STRLCPY -#define SDL_strlcpy strlcpy +SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); } +#define SDL_strlcpy SDL_strlcpy_inline #else -extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, - size_t maxlen); #endif -extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, - size_t dst_bytes); +extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes); +extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen); #ifdef HAVE_STRLCAT -#define SDL_strlcat strlcat -#else -extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, - size_t maxlen); +SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); } +#define SDL_strlcat SDL_strlcat_inline #endif +extern DECLSPEC char *SDLCALL SDL_strdup(const char *str); #ifdef HAVE_STRDUP -#define SDL_strdup strdup -#else -extern DECLSPEC char *SDLCALL SDL_strdup(const char *string); +SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); } +#define SDL_strdup SDL_strdup_inline #endif +extern DECLSPEC char *SDLCALL SDL_strrev(char *str); #ifdef HAVE__STRREV -#define SDL_strrev _strrev -#else -extern DECLSPEC char *SDLCALL SDL_strrev(char *string); +SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); } +#define SDL_strrev SDL_strrev_inline #endif +extern DECLSPEC char *SDLCALL SDL_strupr(char *str); #ifdef HAVE__STRUPR -#define SDL_strupr _strupr -#else -extern DECLSPEC char *SDLCALL SDL_strupr(char *string); +SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); } +#define SDL_strupr SDL_strupr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strlwr(char *str); #ifdef HAVE__STRLWR -#define SDL_strlwr _strlwr -#else -extern DECLSPEC char *SDLCALL SDL_strlwr(char *string); +SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); } +#define SDL_strlwr SDL_strlwr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c); #ifdef HAVE_STRCHR -#define SDL_strchr strchr -#elif defined(HAVE_INDEX) -#define SDL_strchr index -#else -extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c); +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return strchr(str, c); } +#define SDL_strchr SDL_strchr_inline +#elif defined(HAVE_INDEX) /* !!! FIXME: is there anywhere that has this but not strchr? */ +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); } +#define SDL_strchr SDL_strchr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c); #ifdef HAVE_STRRCHR -#define SDL_strrchr strrchr -#elif defined(HAVE_RINDEX) -#define SDL_strrchr rindex -#else -extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c); +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return strrchr(str, c); } +#define SDL_strrchr SDL_strrchr_inline +#elif defined(HAVE_RINDEX) /* !!! FIXME: is there anywhere that has this but not strrchr? */ +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return rindex(str, c); } +#define SDL_strrchr SDL_strrchr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle); #ifdef HAVE_STRSTR -#define SDL_strstr strstr -#else -extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, - const char *needle); -#endif - -#ifdef HAVE_ITOA -#define SDL_itoa itoa -#else -#define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix) +SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return strstr(haystack, needle); } +#define SDL_strstr SDL_strstr_inline #endif +extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix); #ifdef HAVE__LTOA -#define SDL_ltoa _ltoa -#else -extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix); +SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); } +#define SDL_ltoa SDL_ltoa_inline #endif -#ifdef HAVE__UITOA -#define SDL_uitoa _uitoa +extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix); +#ifdef HAVE_ITOA +SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); } #else -#define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix) +SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); } #endif +#define SDL_itoa SDL_itoa_inline +extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix); #ifdef HAVE__ULTOA -#define SDL_ultoa _ultoa -#else -extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); } +#define SDL_ultoa SDL_ultoa_inline #endif +extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix); +#ifdef HAVE__UITOA +SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); } +#else +SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); } +#endif +#define SDL_uitoa SDL_uitoa_inline + + +extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base); #ifdef HAVE_STRTOL -#define SDL_strtol strtol -#else -extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, - int base); +SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); } +#define SDL_strtol SDL_strtol_inline #endif +extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base); #ifdef HAVE_STRTOUL -#define SDL_strtoul strtoul -#else -extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, - char **endp, int base); +SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); } +#define SDL_strtoul SDL_strtoul_inline #endif +extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix); #ifdef HAVE__I64TOA -#define SDL_lltoa _i64toa -#else -extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); } +#define SDL_lltoa SDL_lltoa_inline #endif +extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix); #ifdef HAVE__UI64TOA -#define SDL_ulltoa _ui64toa -#else -extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); } +#define SDL_ulltoa SDL_ulltoa_inline #endif +extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base); #ifdef HAVE_STRTOLL -#define SDL_strtoll strtoll -#else -extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, - int base); +SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); } +#define SDL_strtoll SDL_strtoll_inline #endif +extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base); #ifdef HAVE_STRTOULL -#define SDL_strtoull strtoull -#else -extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, - int base); +SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); } +#define SDL_strtoull SDL_strtoull_inline #endif +extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp); #ifdef HAVE_STRTOD -#define SDL_strtod strtod -#else -extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp); +SDL_FORCE_INLINE Uint64 SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); } +#define SDL_strtod SDL_strtod_inline #endif +extern DECLSPEC int SDLCALL SDL_atoi(const char *str); #ifdef HAVE_ATOI -#define SDL_atoi atoi +SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); } #else -#define SDL_atoi(X) SDL_strtol(X, NULL, 0) +SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); } #endif +#define SDL_atoi SDL_atoi_inline +extern DECLSPEC double SDLCALL SDL_atof(const char *str); #ifdef HAVE_ATOF -#define SDL_atof atof +SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); } #else -#define SDL_atof(X) SDL_strtod(X, NULL) +SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); } #endif +#define SDL_atof SDL_atof_inline + -#ifdef HAVE_STRCMP -#define SDL_strcmp strcmp -#else extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2); +#ifdef HAVE_STRCMP +SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); } +#define SDL_strcmp SDL_strcmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen); #ifdef HAVE_STRNCMP -#define SDL_strncmp strncmp -#else -extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, - size_t maxlen); +SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); } +#define SDL_strncmp SDL_strncmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); #ifdef HAVE_STRCASECMP -#define SDL_strcasecmp strcasecmp +SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); } +#define SDL_strcasecmp SDL_strcasecmp_inline #elif defined(HAVE__STRICMP) -#define SDL_strcasecmp _stricmp -#else -extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, - const char *str2); +SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); } +#define SDL_strcasecmp SDL_strcasecmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len); #ifdef HAVE_STRNCASECMP -#define SDL_strncasecmp strncasecmp +SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); } +#define SDL_strncasecmp SDL_strncasecmp_inline #elif defined(HAVE__STRNICMP) -#define SDL_strncasecmp _strnicmp -#else -extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, - const char *str2, size_t maxlen); +SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); } +#define SDL_strncasecmp SDL_strncasecmp_inline #endif +/* Not doing SDL_*_inline functions for these, because of the varargs. */ +extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); #ifdef HAVE_SSCANF -#define SDL_sscanf sscanf -#else -extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, - ...); +#define SDL_sscanf sscanf #endif +extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...); #ifdef HAVE_SNPRINTF -#define SDL_snprintf snprintf -#else -extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, - const char *fmt, ...); +#define SDL_snprintf snprintf #endif +extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); #ifdef HAVE_VSNPRINTF -#define SDL_vsnprintf vsnprintf -#else -extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, - const char *fmt, va_list ap); +SDL_FORCE_INLINE int SDL_vsnprintf_inline(char *text, size_t maxlen, const char *fmt, va_list ap) { return vsnprintf(text, maxlen, fmt, ap); } +#define SDL_vsnprintf SDL_vsnprintf_inline #endif #ifndef HAVE_M_PI @@ -638,88 +681,94 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, #endif #endif -#ifdef HAVE_ATAN -#define SDL_atan atan -#else extern DECLSPEC double SDLCALL SDL_atan(double x); +#ifdef HAVE_ATAN +SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); } +#define SDL_atan SDL_atan_inline #endif +extern DECLSPEC double SDLCALL SDL_atan2(double x, double y); #ifdef HAVE_ATAN2 -#define SDL_atan2 atan2 -#else -extern DECLSPEC double SDLCALL SDL_atan2(double y, double x); +SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); } +#define SDL_atan2 SDL_atan2_inline #endif +extern DECLSPEC double SDLCALL SDL_ceil(double x); #ifdef HAVE_CEIL -#define SDL_ceil ceil +SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); } #else -#define SDL_ceil(x) ((double)(int)((x)+0.5)) +SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); } #endif +#define SDL_ceil SDL_ceil_inline -#ifdef HAVE_COPYSIGN -#define SDL_copysign copysign -#else extern DECLSPEC double SDLCALL SDL_copysign(double x, double y); +#ifdef HAVE_COPYSIGN +SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); } +#define SDL_copysign SDL_copysign_inline #endif -#ifdef HAVE_COS -#define SDL_cos cos -#else extern DECLSPEC double SDLCALL SDL_cos(double x); +#ifdef HAVE_COS +SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); } +#define SDL_cos SDL_cos_inline #endif +extern DECLSPEC float SDLCALL SDL_cosf(float x); #ifdef HAVE_COSF -#define SDL_cosf cosf +SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); } #else -#define SDL_cosf(x) (float)SDL_cos((double)x) +SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); } #endif +#define SDL_cosf SDL_cosf_inline -#ifdef HAVE_FABS -#define SDL_fabs fabs -#else extern DECLSPEC double SDLCALL SDL_fabs(double x); +#ifdef HAVE_FABS +SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); } +#define SDL_fabs SDL_fabs_inline #endif -#ifdef HAVE_FLOOR -#define SDL_floor floor -#else extern DECLSPEC double SDLCALL SDL_floor(double x); +#ifdef HAVE_FLOOR +SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); } +#define SDL_floor SDL_floor_inline #endif -#ifdef HAVE_LOG -#define SDL_log log -#else extern DECLSPEC double SDLCALL SDL_log(double x); +#ifdef HAVE_LOG +SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); } +#define SDL_log SDL_log_inline #endif -#ifdef HAVE_POW -#define SDL_pow pow -#else extern DECLSPEC double SDLCALL SDL_pow(double x, double y); +#ifdef HAVE_POW +SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); } +#define SDL_pow SDL_pow_inline #endif -#ifdef HAVE_SCALBN -#define SDL_scalbn scalbn -#else extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n); +#ifdef HAVE_SCALBN +SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); } +#define SDL_scalbn SDL_scalbn_inline #endif -#ifdef HAVE_SIN -#define SDL_sin sin -#else extern DECLSPEC double SDLCALL SDL_sin(double x); +#ifdef HAVE_SIN +SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); } +#define SDL_sin SDL_sin_inline #endif +extern DECLSPEC float SDLCALL SDL_sinf(float x); #ifdef HAVE_SINF -#define SDL_sinf sinf +SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); } #else -#define SDL_sinf(x) (float)SDL_sin((double)x) +SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); } #endif +#define SDL_sinf SDL_sinf_inline -#ifdef HAVE_SQRT -#define SDL_sqrt sqrt -#else extern DECLSPEC double SDLCALL SDL_sqrt(double x); +#ifdef HAVE_SQRT +SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); } +#define SDL_sqrt SDL_sqrt_inline #endif /* The SDL implementation of iconv() returns these error codes */ @@ -728,16 +777,11 @@ extern DECLSPEC double SDLCALL SDL_sqrt(double x); #define SDL_ICONV_EILSEQ (size_t)-3 #define SDL_ICONV_EINVAL (size_t)-4 -#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H) -#define SDL_iconv_t iconv_t -#define SDL_iconv_open iconv_open -#define SDL_iconv_close iconv_close -#else +/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */ typedef struct _SDL_iconv_t *SDL_iconv_t; extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode); extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd); -#endif extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft); diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index 161003004..9079387cd 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -22,18 +22,19 @@ #include "SDL_stdinc.h" -#ifndef HAVE_GETENV - -#if defined(__WIN32__) - +#if !defined(SDL_setenv) && defined(__WIN32__) #include "../core/windows/SDL_windows.h" - /* Note this isn't thread-safe! */ - static char *SDL_envmem = NULL; /* Ugh, memory leak */ static size_t SDL_envmemlen = 0; +#endif + /* Put a variable into the environment */ +#ifdef SDL_setenv +#undef SDL_setenv +int SDL_setenv(const char *name, const char *value, int overwrite) { return SDL_setenv_inline(name, value, overwrite); } +#elif defined(__WIN32__) int SDL_setenv(const char *name, const char *value, int overwrite) { @@ -49,35 +50,34 @@ SDL_setenv(const char *name, const char *value, int overwrite) } return 0; } - -/* Retrieve a variable named "name" from the environment */ -char * -SDL_getenv(const char *name) +/* We have a real environment table, but no real setenv? Fake it w/ putenv. */ +#elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) +int +SDL_setenv(const char *name, const char *value, int overwrite) { - size_t bufferlen; + size_t len; + char *new_variable; - bufferlen = - GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); - if (bufferlen == 0) { - return NULL; - } - if (bufferlen > SDL_envmemlen) { - char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen); - if (newmem == NULL) { - return NULL; + if (getenv(name) != NULL) { + if (overwrite) { + unsetenv(name); + } else { + return 0; /* leave the existing one there. */ } - SDL_envmem = newmem; - SDL_envmemlen = bufferlen; - GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); } - return SDL_envmem; + + /* This leaks. Sorry. Get a better OS so we don't have to do this. */ + len = SDL_strlen(name) + SDL_strlen(value) + 2; + new_variable = (char *) SDL_malloc(len); + if (!new_variable) { + return (-1); + } + + SDL_snprintf(new_variable, len, "%s=%s", name, value); + return putenv(new_variable); } - #else /* roll our own */ - static char **SDL_env = (char **) 0; - -/* Put a variable into the environment */ int SDL_setenv(const char *name, const char *value, int overwrite) { @@ -140,8 +140,35 @@ SDL_setenv(const char *name, const char *value, int overwrite) } return (added ? 0 : -1); } +#endif /* Retrieve a variable named "name" from the environment */ +#ifdef SDL_getenv +#undef SDL_getenv +char *SDL_getenv(const char *name) { return SDL_getenv_inline(name); } +#elif defined(__WIN32__) +char * +SDL_getenv(const char *name) +{ + size_t bufferlen; + + bufferlen = + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); + if (bufferlen == 0) { + return NULL; + } + if (bufferlen > SDL_envmemlen) { + char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen); + if (newmem == NULL) { + return NULL; + } + SDL_envmem = newmem; + SDL_envmemlen = bufferlen; + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); + } + return SDL_envmem; +} +#else char * SDL_getenv(const char *name) { @@ -160,38 +187,6 @@ SDL_getenv(const char *name) } return value; } - -#endif /* __WIN32__ */ - -#endif /* !HAVE_GETENV */ - - -/* We have a real environment table, but no real setenv? Fake it w/ putenv. */ -#if (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) -int -SDL_setenv(const char *name, const char *value, int overwrite) -{ - size_t len; - char *new_variable; - - if (getenv(name) != NULL) { - if (overwrite) { - unsetenv(name); - } else { - return 0; /* leave the existing one there. */ - } - } - - /* This leaks. Sorry. Get a better OS so we don't have to do this. */ - len = SDL_strlen(name) + SDL_strlen(value) + 2; - new_variable = (char *) SDL_malloc(len); - if (!new_variable) { - return (-1); - } - - SDL_snprintf(new_variable, len, "%s=%s", name, value); - return putenv(new_variable); -} #endif diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c index 8d2f2c034..4e5e51d87 100644 --- a/src/stdlib/SDL_iconv.c +++ b/src/stdlib/SDL_iconv.c @@ -38,6 +38,20 @@ #include +SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t)); + +SDL_iconv_t +SDL_iconv_open(const char *tocode, const char *fromcode) +{ + return (SDL_iconv_t) ((size_t) iconv_open(tocode, fromcode)); +} + +int +SDL_iconv_close(SDL_iconv_t cd) +{ + return iconv_close((iconv_t) ((size_t) cd)); +} + size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, @@ -45,9 +59,9 @@ SDL_iconv(SDL_iconv_t cd, { size_t retCode; #ifdef ICONV_INBUF_NONCONST - retCode = iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft); + retCode = iconv((iconv_t) ((size_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft); #else - retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft); + retCode = iconv((iconv_t) ((size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft); #endif if (retCode == (size_t) - 1) { switch (errno) { diff --git a/src/stdlib/SDL_malloc.c b/src/stdlib/SDL_malloc.c index 6533f0b97..65d1e1d16 100644 --- a/src/stdlib/SDL_malloc.c +++ b/src/stdlib/SDL_malloc.c @@ -24,7 +24,18 @@ #include "SDL_stdinc.h" -#ifndef HAVE_MALLOC +#ifdef SDL_malloc +/* expose the symbol, but use what we figured out elsewhere. */ +#undef SDL_malloc +#undef SDL_calloc +#undef SDL_realloc +#undef SDL_free +void *SDL_malloc(size_t size) { return SDL_malloc_inline(size); } +void *SDL_calloc(size_t nmemb, size_t size) { return SDL_calloc_inline(nmemb, size); } +void *SDL_realloc(void *ptr, size_t size) { return SDL_realloc_inline(ptr, size); } +void SDL_free(void *ptr) { SDL_free_inline(ptr); } + +#else /* the rest of this is a LOT of tapdancing to implement malloc. :) */ #define LACKS_SYS_TYPES_H #define LACKS_STDIO_H diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c index 6d56c6758..8c73419c9 100644 --- a/src/stdlib/SDL_qsort.c +++ b/src/stdlib/SDL_qsort.c @@ -51,6 +51,15 @@ #include "SDL_stdinc.h" #include "SDL_assert.h" +#ifdef SDL_qsort +#undef SDL_qsort +void +SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) +{ + SDL_qsort_inline(base, nmemb, size, compare); +} +#else + #ifdef assert #undef assert #endif @@ -76,9 +85,6 @@ #endif #define qsort SDL_qsort - -#ifndef HAVE_QSORT - static const char _ID[] = ""; /* How many bytes are there per word? (Must be a power of 2, @@ -466,5 +472,6 @@ qsort(void *base, size_t nmemb, size_t size, qsort_words(base, nmemb, compare); } -#endif /* !HAVE_QSORT */ +#endif /* !SDL_qsort */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 496b99e1f..1c19ab72f 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -24,6 +24,25 @@ #include "SDL_stdinc.h" +/* these are always #defined, make them real symbol in the library, too... */ +#undef SDL_ceil +#undef SDL_abs +#undef SDL_sinf +#undef SDL_cosf +#undef SDL_isdigit +#undef SDL_isspace +#undef SDL_toupper +#undef SDL_tolower +double SDL_ceil(double x) { return SDL_ceil_inline(x); } +float SDL_cosf(float x) { return SDL_cosf_inline(x); } +float SDL_sinf(float x) { return SDL_sinf_inline(x); } +int SDL_abs(int x) { return SDL_abs_inline(x); } +int SDL_isdigit(int x) { return SDL_isdigit_inline(x); } +int SDL_isspace(int x) { return SDL_isspace_inline(x); } +int SDL_toupper(int x) { return SDL_toupper_inline(x); } +int SDL_tolower(int x) { return SDL_tolower_inline(x); } + + #ifndef HAVE_LIBC /* These are some C runtime intrinsics that need to be defined */ diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 89c14d958..a1bfe6105 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -24,6 +24,17 @@ #include "SDL_stdinc.h" +/* these are always #defined, make them real symbol in the library, too... */ +#undef SDL_itoa +#undef SDL_uitoa +#undef SDL_atoi +#undef SDL_atof +char *SDL_itoa(int value, char *str, int radix) { return SDL_itoa_inline(value, str, radix); } +char *SDL_uitoa(unsigned int value, char *str, int radix) { return SDL_uitoa_inline(value, str, radix); } +int SDL_atoi(const char *str) { return SDL_atoi(str); } +double SDL_atof(const char *str) { return SDL_atof(str); } + + #define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F')) #define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f')) @@ -43,7 +54,7 @@ static int UTF8_TrailingBytes(unsigned char c) return 0; } -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL) +#if !defined(SDL_sscanf) || !defined(SDL_strtol) static size_t SDL_ScanLong(const char *text, int radix, long *valuep) { @@ -84,7 +95,7 @@ SDL_ScanLong(const char *text, int radix, long *valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) +#if !defined(SDL_sscanf) || !defined(SDL_strtoul) || !defined(SDL_strtod) static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) { @@ -116,7 +127,7 @@ SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) } #endif -#ifndef HAVE_SSCANF +#ifndef SDL_sscanf static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) { @@ -148,7 +159,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL) +#if !defined(SDL_sscanf) || !defined(SDL_strtoll) static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) { @@ -189,7 +200,7 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL) +#if !defined(SDL_sscanf) || !defined(SDL_strtoull) static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) { @@ -221,7 +232,7 @@ SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD) +#if !defined(SDL_sscanf) || !defined(SDL_strtod) static size_t SDL_ScanFloat(const char *text, double *valuep) { @@ -257,7 +268,11 @@ SDL_ScanFloat(const char *text, double *valuep) } #endif -#ifndef SDL_memset + +#ifdef SDL_memset +#undef SDL_memset +void *SDL_memset(void *dst, int c, size_t len) { return SDL_memset_inline(dst, c, len); } +#else void * SDL_memset(void *dst, int c, size_t len) { @@ -287,7 +302,11 @@ SDL_memset(void *dst, int c, size_t len) } #endif -#ifndef SDL_memcpy + +#ifdef SDL_memcpy +#undef SDL_memcpy +void *SDL_memcpy(void *dst, const void *src, size_t len) { return SDL_memcpy_inline(dst, src, len); } +#else void * SDL_memcpy(void *dst, const void *src, size_t len) { @@ -317,7 +336,11 @@ SDL_memcpy(void *dst, const void *src, size_t len) } #endif -#ifndef SDL_memmove + +#ifdef SDL_memmove +#undef SDL_memmove +void *SDL_memmove(void *dst, const void *src, size_t len) { return SDL_memmove_inline(dst, src, len); } +#else void * SDL_memmove(void *dst, const void *src, size_t len) { @@ -339,7 +362,10 @@ SDL_memmove(void *dst, const void *src, size_t len) } #endif -#ifndef SDL_memcmp +#ifdef SDL_memcmp +#undef SDL_memcmp +int SDL_memcmp(const void *s1, const void *s2, size_t len) { return SDL_memcmp_inline(s1, s2, len); } +#else int SDL_memcmp(const void *s1, const void *s2, size_t len) { @@ -356,7 +382,10 @@ SDL_memcmp(const void *s1, const void *s2, size_t len) } #endif -#ifndef HAVE_STRLEN +#ifdef SDL_strlen +#undef SDL_strlen +size_t SDL_strlen(const char *string) { return SDL_strlen_inline(string); } +#else size_t SDL_strlen(const char *string) { @@ -368,7 +397,10 @@ SDL_strlen(const char *string) } #endif -#ifndef HAVE_WCSLEN +#ifdef SDL_wcslen +#undef SDL_wcslen +size_t SDL_wcslen(const wchar_t * string) { return SDL_wcslen_inline(string); } +#else size_t SDL_wcslen(const wchar_t * string) { @@ -380,7 +412,10 @@ SDL_wcslen(const wchar_t * string) } #endif -#ifndef HAVE_WCSLCPY +#ifdef SDL_wcslcpy +#undef SDL_wcslcpy +size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcpy_inline(dst, src, maxlen); } +#else size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { @@ -394,7 +429,10 @@ SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) } #endif -#ifndef HAVE_WCSLCAT +#ifdef SDL_wcslcat +#undef SDL_wcslcat +size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcat_inline(dst, src, maxlen); } +#else size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { @@ -407,7 +445,10 @@ SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) } #endif -#ifndef HAVE_STRLCPY +#ifdef SDL_strlcpy +#undef SDL_strlcpy +size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { return SDL_strlcpy_inline(dst, src, maxlen); } +#else size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { @@ -453,7 +494,10 @@ size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes) return bytes; } -#ifndef HAVE_STRLCAT +#ifdef SDL_strlcat +#undef SDL_strlcat +size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { return SDL_strlcat_inline(dst, src, maxlen); } +#else size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { @@ -466,7 +510,10 @@ SDL_strlcat(char *dst, const char *src, size_t maxlen) } #endif -#ifndef HAVE_STRDUP +#ifdef SDL_strdup +#undef SDL_strdup +char *SDL_strdup(const char *string) { return SDL_strdup_inline(string); } +#else char * SDL_strdup(const char *string) { @@ -479,7 +526,10 @@ SDL_strdup(const char *string) } #endif -#ifndef HAVE__STRREV +#ifdef SDL_strrev +#undef SDL_strrev +char *SDL_strrev(char *string) { return SDL_strrev_inline(string); } +#else char * SDL_strrev(char *string) { @@ -496,7 +546,10 @@ SDL_strrev(char *string) } #endif -#ifndef HAVE__STRUPR +#ifdef SDL_strupr +#undef SDL_strupr +char *SDL_strupr(char *string) { return SDL_strupr_inline(string); } +#else char * SDL_strupr(char *string) { @@ -509,7 +562,10 @@ SDL_strupr(char *string) } #endif -#ifndef HAVE__STRLWR +#ifdef SDL_strlwr +#undef SDL_strlwr +char *SDL_strlwr(char *string) { return SDL_strlwr_inline(string); } +#else char * SDL_strlwr(char *string) { @@ -522,7 +578,10 @@ SDL_strlwr(char *string) } #endif -#ifndef HAVE_STRCHR +#ifdef SDL_strchr +#undef SDL_strchr +char *SDL_strchr(const char *string, int c) { return SDL_strchr_inline(string, c); } +#else char * SDL_strchr(const char *string, int c) { @@ -536,7 +595,10 @@ SDL_strchr(const char *string, int c) } #endif -#ifndef HAVE_STRRCHR +#ifdef SDL_strrchr +#undef SDL_strrchr +char *SDL_strrchr(const char *string, int c) { return SDL_strrchr_inline(string, c); } +#else char * SDL_strrchr(const char *string, int c) { @@ -551,7 +613,10 @@ SDL_strrchr(const char *string, int c) } #endif -#ifndef HAVE_STRSTR +#ifdef SDL_strstr +#undef SDL_strstr +char *SDL_strstr(const char *haystack, const char *needle) { return SDL_strstr_inline(haystack, needle); } +#else char * SDL_strstr(const char *haystack, const char *needle) { @@ -566,8 +631,8 @@ SDL_strstr(const char *haystack, const char *needle) } #endif -#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \ - !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA) +#if !defined(SDL_ltoa) || !defined(SDL_lltoa) || \ + !defined(SDL_ultoa) || !defined(SDL_ulltoa) static const char ntoa_table[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', @@ -576,7 +641,10 @@ static const char ntoa_table[] = { }; #endif /* ntoa() conversion table */ -#ifndef HAVE__LTOA +#ifdef SDL_ltoa +#undef SDL_ltoa +char *SDL_ltoa(long value, char *string, int radix) { return SDL_ltoa_inline(value, string, radix); } +#else char * SDL_ltoa(long value, char *string, int radix) { @@ -607,7 +675,10 @@ SDL_ltoa(long value, char *string, int radix) } #endif -#ifndef HAVE__ULTOA +#ifdef SDL_ultoa +#undef SDL_ultoa +char *SDL_ultoa(unsigned long value, char *string, int radix) { return SDL_ultoa_inline(value, string, radix); } +#else char * SDL_ultoa(unsigned long value, char *string, int radix) { @@ -630,7 +701,10 @@ SDL_ultoa(unsigned long value, char *string, int radix) } #endif -#ifndef HAVE_STRTOL +#ifdef SDL_strtol +#undef SDL_strtol +long SDL_strtol(const char *string, char **endp, int base) { return SDL_strtol_inline(string, endp, base); } +#else long SDL_strtol(const char *string, char **endp, int base) { @@ -653,7 +727,10 @@ SDL_strtol(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOUL +#ifdef SDL_strtoul +#undef SDL_strtoul +unsigned long SDL_strtoul(const char *string, char **endp, int base) { return SDL_strtoul_inline(string, endp, base); } +#else unsigned long SDL_strtoul(const char *string, char **endp, int base) { @@ -676,7 +753,10 @@ SDL_strtoul(const char *string, char **endp, int base) } #endif -#ifndef HAVE__I64TOA +#ifdef SDL_lltoa +#undef SDL_lltoa +char *SDL_lltoa(Sint64 value, char *string, int radix) { return SDL_lltoa_inline(value, string, radix); } +#else char * SDL_lltoa(Sint64 value, char *string, int radix) { @@ -707,7 +787,10 @@ SDL_lltoa(Sint64 value, char *string, int radix) } #endif -#ifndef HAVE__UI64TOA +#ifdef SDL_ulltoa +#undef SDL_ulltoa +char *SDL_ulltoa(Uint64 value, char *string, int radix) { return SDL_ulltoa_inline(value, string, radix); } +#else char * SDL_ulltoa(Uint64 value, char *string, int radix) { @@ -730,7 +813,10 @@ SDL_ulltoa(Uint64 value, char *string, int radix) } #endif -#ifndef HAVE_STRTOLL +#ifdef SDL_strtoll +#undef SDL_strtoll +Sint64 SDL_strtoll(const char *string, char **endp, int base) { return SDL_strtoll_inline(string, endp, base); } +#else Sint64 SDL_strtoll(const char *string, char **endp, int base) { @@ -753,7 +839,10 @@ SDL_strtoll(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOULL +#ifdef SDL_strtoull +#undef SDL_strtoull +Uint64 SDL_strtoull(const char *string, char **endp, int base) { return SDL_strtoull_inline(string, endp, base); } +#else Uint64 SDL_strtoull(const char *string, char **endp, int base) { @@ -776,7 +865,10 @@ SDL_strtoull(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOD +#ifdef SDL_strtod +#undef SDL_strtod +double SDL_strtod(const char *string, char **endp) { return SDL_strtod_inline(string, endp); } +#else double SDL_strtod(const char *string, char **endp) { @@ -791,7 +883,10 @@ SDL_strtod(const char *string, char **endp) } #endif -#ifndef HAVE_STRCMP +#ifdef SDL_strcmp +#undef SDL_strcmp +int SDL_strcmp(const char *str1, const char *str2) { return SDL_strcmp_inline(str1, str2); } +#else int SDL_strcmp(const char *str1, const char *str2) { @@ -805,7 +900,10 @@ SDL_strcmp(const char *str1, const char *str2) } #endif -#ifndef HAVE_STRNCMP +#ifdef SDL_strncmp +#undef SDL_strncmp +int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncmp_inline(str1, str2, maxlen); } +#else int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { @@ -823,7 +921,10 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen) } #endif -#if !defined(HAVE_STRCASECMP) && !defined(HAVE__STRICMP) +#ifdef SDL_strcasecmp +#undef SDL_strcasecmp +int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp(str1, str2); } +#else int SDL_strcasecmp(const char *str1, const char *str2) { @@ -843,7 +944,10 @@ SDL_strcasecmp(const char *str1, const char *str2) } #endif -#if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP) +#ifdef SDL_strncasecmp +#undef SDL_strncasecmp +int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncasecmp_inline(str1, str2, maxlen); } +#else int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { @@ -868,7 +972,19 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) } #endif -#ifndef HAVE_SSCANF +#ifdef SDL_sscanf +#undef SDL_sscanf +int +SDL_sscanf(const char *text, const char *fmt, ...) +{ + int rc; + va_list ap; + va_start(ap, fmt); + rc = vsscanf(text, fmt, ap); + va_end(ap); + return rc; +} +#else int SDL_sscanf(const char *text, const char *fmt, ...) { @@ -1136,7 +1252,10 @@ SDL_sscanf(const char *text, const char *fmt, ...) } #endif -#ifndef HAVE_SNPRINTF +/* just undef; the headers only define this to snprintf because of varargs. */ +#ifdef SDL_snprintf +#undef SDL_snprintf +#endif int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) { @@ -1149,9 +1268,11 @@ SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) return retval; } -#endif -#ifndef HAVE_VSNPRINTF +#ifdef SDL_vsnprintf +#undef SDL_vsnprintf +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); } +#else static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen) { @@ -1414,4 +1535,5 @@ SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) return (int)(text - textstart); } #endif + /* vi: set ts=4 sw=4 expandtab: */ From a26645f7b1300edd187240efaefbf7e3580a12d9 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 15 Mar 2013 01:09:19 -0400 Subject: [PATCH 092/151] Replace all the "static __inline__" functions with SDL_FORCE_INLINE. --- include/SDL_atomic.h | 10 +++++----- include/SDL_bits.h | 7 +------ include/SDL_endian.h | 33 ++++++++++++++------------------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index c89d0b71d..be60f9916 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -205,7 +205,7 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int * \return The previous value of the atomic variable. */ #ifndef SDL_AtomicSet -static __inline__ int SDL_AtomicSet(SDL_atomic_t *a, int v) +SDL_FORCE_INLINE int SDL_AtomicSet(SDL_atomic_t *a, int v) { int value; do { @@ -219,7 +219,7 @@ static __inline__ int SDL_AtomicSet(SDL_atomic_t *a, int v) * \brief Get the value of an atomic variable */ #ifndef SDL_AtomicGet -static __inline__ int SDL_AtomicGet(SDL_atomic_t *a) +SDL_FORCE_INLINE int SDL_AtomicGet(SDL_atomic_t *a) { int value = a->value; SDL_CompilerBarrier(); @@ -235,7 +235,7 @@ static __inline__ int SDL_AtomicGet(SDL_atomic_t *a) * \note This same style can be used for any number operation */ #ifndef SDL_AtomicAdd -static __inline__ int SDL_AtomicAdd(SDL_atomic_t *a, int v) +SDL_FORCE_INLINE int SDL_AtomicAdd(SDL_atomic_t *a, int v) { int value; do { @@ -279,7 +279,7 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void* *a, void *oldval, void * * \return The previous value of the pointer. */ #ifndef SDL_AtomicSetPtr -static __inline__ void* SDL_AtomicSetPtr(void* *a, void* v) +SDL_FORCE_INLINE void* SDL_AtomicSetPtr(void* *a, void* v) { void* value; do { @@ -293,7 +293,7 @@ static __inline__ void* SDL_AtomicSetPtr(void* *a, void* v) * \brief Get the value of a pointer atomically. */ #ifndef SDL_AtomicGetPtr -static __inline__ void* SDL_AtomicGetPtr(void* *a) +SDL_FORCE_INLINE void* SDL_AtomicGetPtr(void* *a) { void* value = *a; SDL_CompilerBarrier(); diff --git a/include/SDL_bits.h b/include/SDL_bits.h index 3192c8e41..4b35a77cf 100644 --- a/include/SDL_bits.h +++ b/include/SDL_bits.h @@ -40,11 +40,6 @@ extern "C" { /** * \file SDL_bits.h - * - * Uses inline functions for compilers that support them, and static - * functions for those that do not. Because these functions become - * static for compilers that do not support inline functions, this - * header should only be included in files that actually use them. */ /** @@ -54,7 +49,7 @@ extern "C" { * * \return Index of the most significant bit. */ -static __inline__ Sint8 +SDL_FORCE_INLINE Sint8 SDL_MostSignificantBitIndex32(Uint32 x) { #if defined(__GNUC__) diff --git a/include/SDL_endian.h b/include/SDL_endian.h index 5cfa32e30..a1a11df09 100644 --- a/include/SDL_endian.h +++ b/include/SDL_endian.h @@ -66,29 +66,24 @@ extern "C" { /** * \file SDL_endian.h - * - * Uses inline functions for compilers that support them, and static - * functions for those that do not. Because these functions become - * static for compilers that do not support inline functions, this - * header should only be included in files that actually use them. */ #if defined(__GNUC__) && defined(__i386__) && \ !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */) -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { __asm__("xchgb %b0,%h0": "=q"(x):"0"(x)); return x; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x)); return x; } #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { int result; @@ -97,14 +92,14 @@ SDL_Swap16(Uint16 x) return (Uint16)result; } #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) && !defined(__mcoldfire__) -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc"); return x; } #else -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { return SDL_static_cast(Uint16, ((x << 8) | (x >> 8))); @@ -112,21 +107,21 @@ SDL_Swap16(Uint16 x) #endif #if defined(__GNUC__) && defined(__i386__) -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { __asm__("bswap %0": "=r"(x):"0"(x)); return x; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { __asm__("bswapl %0": "=r"(x):"0"(x)); return x; } #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { Uint32 result; @@ -137,14 +132,14 @@ SDL_Swap32(Uint32 x) return result; } #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) && !defined(__mcoldfire__) -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc"); return x; } #else -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { return SDL_static_cast(Uint32, ((x << 24) | ((x << 8) & 0x00FF0000) | @@ -153,7 +148,7 @@ SDL_Swap32(Uint32 x) #endif #if defined(__GNUC__) && defined(__i386__) -static __inline__ Uint64 +SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x) { union @@ -171,14 +166,14 @@ SDL_Swap64(Uint64 x) return v.u; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint64 +SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x) { __asm__("bswapq %0": "=r"(x):"0"(x)); return x; } #else -static __inline__ Uint64 +SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x) { Uint32 hi, lo; @@ -195,7 +190,7 @@ SDL_Swap64(Uint64 x) #endif -static __inline__ float +SDL_FORCE_INLINE float SDL_SwapFloat(float x) { union From 6ea7a3490dfa025f99b2e1a21c580e423aa2a0da Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 14 Mar 2013 23:10:51 -0700 Subject: [PATCH 093/151] Clarified inline function documentation, removed obsolete Metrowerks compiler directive. --- include/SDL_stdinc.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index ca52376ff..e1a8adb91 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -175,10 +175,6 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); enums having the size of an int must be enabled. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11). */ -/* Enable enums always int in CodeWarrior (for MPW use "-enum int") */ -#ifdef __MWERKS__ -#pragma enumsalwaysint on -#endif /** \cond */ #ifndef DOXYGEN_SHOULD_IGNORE_THIS @@ -239,14 +235,12 @@ char *alloca(); /* SDL stdinc inline functions: - The theory here is that, by default, we forcibly inline what we can--with - real inline functions that avoid macro side-effects--and your app will use - the inline version by default. However, we expose a non-inline version - too, which internally just wraps the inline version in a real function, - so the symbol is always available in the library even if your app - bypassed it with the inline version. The SDL_*_inline versions aren't - guaranteed to exist, so never call them directly; use SDL_* instead, - and trust the system to give you the right thing. + The theory here is that by default we forcibly inline what we can, and your + app will use the inline version by default. However we expose a non-inline + version too, so the symbol is always available in the library even if your app + bypassed the inline version. The SDL_*_inline versions aren't guaranteed to + exist, so never call them directly; use SDL_* instead, and trust the system + to give you the right thing. The benefit here is that you can dlsym() these functions, which you couldn't if you had macros, you can link against a foreign build of SDL From 77815e31dba6bf94e8922896b96f0929d697b715 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 15 Mar 2013 11:56:28 -0700 Subject: [PATCH 094/151] Fixed const correctness issue with C++, and fixed building SDL_memcpy4 with 32-bit gcc. --- include/SDL_stdinc.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index e1a8adb91..14e339e96 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -414,19 +414,15 @@ SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords) { -#if defined(__MACOSX__) - /* We can count on memcpy existing on Mac OS X and being well-tuned. */ - return memcpy(dst, src, dwords * 4); -#elif defined(__GNUC__) && defined(i386) +#if defined(__GNUC__) && defined(i386) /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */ /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */ - /* !!! FIXME: amd64? */ int ecx, edi, esi; __asm__ __volatile__ ( "cld \n\t" "rep ; movsl \n\t" : "=&c" (ecx), "=&D" (edi), "=&S" (esi) - : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src) + : "0" (SDL_static_cast(unsigned, dwords)), "1" (dst), "2" (src) : "memory" ); return dst; @@ -512,7 +508,7 @@ SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); } extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c); #ifdef HAVE_STRCHR -SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return strchr(str, c); } +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return (char*)strchr(str, c); } #define SDL_strchr SDL_strchr_inline #elif defined(HAVE_INDEX) /* !!! FIXME: is there anywhere that has this but not strchr? */ SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); } From 6509d6080b94aca635f3ae638869bdab2f5e57b6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 15 Mar 2013 11:59:16 -0700 Subject: [PATCH 095/151] Fixed XIM crash when locale is set to something not supported by X11. --- src/video/x11/SDL_x11window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 6e66149eb..cb932a2c7 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -220,7 +220,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) data->window = window; data->xwindow = w; #ifdef X_HAVE_UTF8_STRING - if (SDL_X11_HAVE_UTF8) { + if (SDL_X11_HAVE_UTF8 && videodata->im) { data->ic = pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, From f227d45db9b1377bd5057bbb52ecfb0ae270db43 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 16 Mar 2013 11:00:04 -0700 Subject: [PATCH 096/151] Fixed more const issues with C++ --- include/SDL_stdinc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 14e339e96..f609eb0e3 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -517,16 +517,16 @@ SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index( extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c); #ifdef HAVE_STRRCHR -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return strrchr(str, c); } +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return (char*)strrchr(str, c); } #define SDL_strrchr SDL_strrchr_inline #elif defined(HAVE_RINDEX) /* !!! FIXME: is there anywhere that has this but not strrchr? */ -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return rindex(str, c); } +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return (char*)rindex(str, c); } #define SDL_strrchr SDL_strrchr_inline #endif extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle); #ifdef HAVE_STRSTR -SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return strstr(haystack, needle); } +SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return (char*)strstr(haystack, needle); } #define SDL_strstr SDL_strstr_inline #endif From 47dac69dc76d851dda440aa107ab4f18757613ee Mon Sep 17 00:00:00 2001 From: Captain Lex Date: Sun, 17 Mar 2013 20:07:02 +0800 Subject: [PATCH 097/151] Add PSP support --- Makefile.psp | 92 +++ README.psp | 17 + include/SDL_config.h | 2 + include/SDL_config_psp.h | 136 ++++ include/SDL_platform.h | 4 + include/SDL_test_common.h | 3 + src/SDL.c | 2 + src/SDL_log.c | 14 + src/audio/SDL_audio.c | 5 +- src/audio/psp/SDL_pspaudio.c | 199 ++++++ src/audio/psp/SDL_pspaudio.h | 45 ++ src/events/SDL_gesture.c | 3 + src/joystick/psp/SDL_sysjoystick.c | 276 ++++++++ src/main/psp/SDL_psp_main.c | 80 +++ src/power/SDL_power.c | 5 + src/power/psp/SDL_syspower.c | 68 ++ src/render/SDL_render.c | 3 + src/render/SDL_sysrender.h | 3 + src/render/psp/SDL_render_psp.c | 1024 ++++++++++++++++++++++++++++ src/thread/SDL_thread_c.h | 2 + src/thread/psp/SDL_syscond.c | 223 ++++++ src/thread/psp/SDL_sysmutex.c | 135 ++++ src/thread/psp/SDL_sysmutex_c.h | 22 + src/thread/psp/SDL_syssem.c | 159 +++++ src/thread/psp/SDL_systhread.c | 103 +++ src/thread/psp/SDL_systhread_c.h | 24 + src/timer/psp/SDL_systimer.c | 69 ++ src/video/SDL_sysvideo.h | 3 + src/video/SDL_video.c | 3 + src/video/psp/SDL_pspevents.c | 284 ++++++++ src/video/psp/SDL_pspevents_c.h | 31 + src/video/psp/SDL_pspgl.c | 207 ++++++ src/video/psp/SDL_pspgl_c.h | 52 ++ src/video/psp/SDL_pspmouse.c | 35 + src/video/psp/SDL_pspmouse_c.h | 24 + src/video/psp/SDL_pspvideo.c | 334 +++++++++ src/video/psp/SDL_pspvideo.h | 102 +++ 37 files changed, 3792 insertions(+), 1 deletion(-) create mode 100644 Makefile.psp create mode 100644 README.psp create mode 100644 include/SDL_config_psp.h create mode 100644 src/audio/psp/SDL_pspaudio.c create mode 100644 src/audio/psp/SDL_pspaudio.h create mode 100644 src/joystick/psp/SDL_sysjoystick.c create mode 100644 src/main/psp/SDL_psp_main.c create mode 100644 src/power/psp/SDL_syspower.c create mode 100644 src/render/psp/SDL_render_psp.c create mode 100644 src/thread/psp/SDL_syscond.c create mode 100644 src/thread/psp/SDL_sysmutex.c create mode 100644 src/thread/psp/SDL_sysmutex_c.h create mode 100644 src/thread/psp/SDL_syssem.c create mode 100644 src/thread/psp/SDL_systhread.c create mode 100644 src/thread/psp/SDL_systhread_c.h create mode 100644 src/timer/psp/SDL_systimer.c create mode 100644 src/video/psp/SDL_pspevents.c create mode 100644 src/video/psp/SDL_pspevents_c.h create mode 100644 src/video/psp/SDL_pspgl.c create mode 100644 src/video/psp/SDL_pspgl_c.h create mode 100644 src/video/psp/SDL_pspmouse.c create mode 100644 src/video/psp/SDL_pspmouse_c.h create mode 100644 src/video/psp/SDL_pspvideo.c create mode 100644 src/video/psp/SDL_pspvideo.h diff --git a/Makefile.psp b/Makefile.psp new file mode 100644 index 000000000..ec137806d --- /dev/null +++ b/Makefile.psp @@ -0,0 +1,92 @@ +TARGET_LIB = libSDL2.a +OBJS= src/SDL.o \ + src/SDL_assert.o \ + src/SDL_error.o \ + src/SDL_fatal.o \ + src/SDL_hints.o \ + src/SDL_log.o \ + src/atomic/SDL_atomic.o \ + src/atomic/SDL_spinlock.o \ + src/audio/SDL_audio.o \ + src/audio/SDL_audiocvt.o \ + src/audio/SDL_audiodev.o \ + src/audio/SDL_audiotypecvt.o \ + src/audio/SDL_mixer.o \ + src/audio/SDL_wave.o \ + src/audio/psp/SDL_pspaudio.o \ + src/cpuinfo/SDL_cpuinfo.o \ + src/events/SDL_clipboardevents.o \ + src/events/SDL_dropevents.o \ + src/events/SDL_events.o \ + src/events/SDL_gesture.o \ + src/events/SDL_keyboard.o \ + src/events/SDL_mouse.o \ + src/events/SDL_quit.o \ + src/events/SDL_touch.o \ + src/events/SDL_windowevents.o \ + src/file/SDL_rwops.o \ + src/haptic/SDL_haptic.o \ + src/haptic/dummy/SDL_syshaptic.o \ + src/joystick/SDL_joystick.o \ + src/joystick/SDL_gamecontroller.o \ + src/joystick/psp/SDL_sysjoystick.o \ + src/power/SDL_power.o \ + src/power/psp/SDL_syspower.o \ + src/render/SDL_render.o \ + src/render/SDL_yuv_sw.o \ + src/render/psp/SDL_render_psp.o \ + src/render/software/SDL_blendfillrect.o \ + src/render/software/SDL_blendline.o \ + src/render/software/SDL_blendpoint.o \ + src/render/software/SDL_drawline.o \ + src/render/software/SDL_drawpoint.o \ + src/render/software/SDL_render_sw.o \ + src/render/software/SDL_rotate.o \ + src/stdlib/SDL_getenv.o \ + src/stdlib/SDL_iconv.o \ + src/stdlib/SDL_malloc.o \ + src/stdlib/SDL_qsort.o \ + src/stdlib/SDL_stdlib.o \ + src/stdlib/SDL_string.o \ + src/thread/SDL_thread.o \ + src/thread/psp/SDL_syssem.o \ + src/thread/psp/SDL_systhread.o \ + src/thread/psp/SDL_sysmutex.o \ + src/thread/psp/SDL_syscond.o \ + src/timer/SDL_timer.o \ + src/timer/psp/SDL_systimer.o \ + src/video/SDL_RLEaccel.o \ + src/video/SDL_blit.o \ + src/video/SDL_blit_0.o \ + src/video/SDL_blit_1.o \ + src/video/SDL_blit_A.o \ + src/video/SDL_blit_N.o \ + src/video/SDL_blit_auto.o \ + src/video/SDL_blit_copy.o \ + src/video/SDL_blit_slow.o \ + src/video/SDL_bmp.o \ + src/video/SDL_clipboard.o \ + src/video/SDL_fillrect.o \ + src/video/SDL_pixels.o \ + src/video/SDL_rect.o \ + src/video/SDL_stretch.o \ + src/video/SDL_surface.o \ + src/video/SDL_video.o \ + src/video/psp/SDL_pspevents.o \ + src/video/psp/SDL_pspvideo.o \ + src/video/psp/SDL_pspgl.o \ + src/video/psp/SDL_pspmouse.o \ + +INCDIR = ./include +CFLAGS = -g -O2 -G0 -Wall -D__PSP__ -DHAVE_OPENGL +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti +ASFLAGS = $(CFLAGS) + +LIBDIR = +LIBS = -lGL -lGLU -lglut -lz \ + -lpspvfpu -lpsphprm -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgum -lpspgu -lpspaudiolib -lpspaudio -lpsphttp -lpspssl -lpspwlan \ + -lpspnet_adhocmatching -lpspnet_adhoc -lpspnet_adhocctl -lm -lpspvram + +PSPSDK=$(shell psp-config --pspsdk-path) +include $(PSPSDK)/lib/build.mak + diff --git a/README.psp b/README.psp new file mode 100644 index 000000000..469febb9a --- /dev/null +++ b/README.psp @@ -0,0 +1,17 @@ +SDL port for the Sony PSP contributed by + Captian Lex + +Credit to + Marcus R.Brown,Jim Paris,Matthew H for the original SDL 1.2 for PSP + Geecko for his PSP GU lib "Glib2d" + +Building +-------- +To build for the PSP, make sure psp-config is in the path and run: + make -f Makefile.psp + + + +To Do +------ +PSP Screen Keyboard \ No newline at end of file diff --git a/include/SDL_config.h b/include/SDL_config.h index f1c6c9be3..1ec9e406c 100644 --- a/include/SDL_config.h +++ b/include/SDL_config.h @@ -39,6 +39,8 @@ #include "SDL_config_android.h" #elif defined(__NINTENDODS__) #include "SDL_config_nintendods.h" +#elif defined(__PSP__) +#include "SDL_config_psp.h" #else /* This is a minimal configuration just to get SDL running on new platforms */ #include "SDL_config_minimal.h" diff --git a/include/SDL_config_psp.h b/include/SDL_config_psp.h new file mode 100644 index 000000000..036b30b28 --- /dev/null +++ b/include/SDL_config_psp.h @@ -0,0 +1,136 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + +#ifndef _SDL_config_psp_h +#define _SDL_config_psp_h + +#include "SDL_platform.h" + + + +#ifdef __GNUC__ +#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1 +#endif + +#define HAVE_GCC_ATOMICS 1 + +#define HAVE_ALLOCA_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_SIGNAL_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_SETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_SETENV 1 +#define HAVE_UNSETENV 1 +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_BCOPY 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_STRLEN 1 +#define HAVE_STRLCPY 1 +#define HAVE_STRLCAT 1 +#define HAVE_STRDUP 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOUL 1 +#define HAVE_STRTOLL 1 +#define HAVE_STRTOULL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE_STRCASECMP 1 +#define HAVE_STRNCASECMP 1 +#define HAVE_SSCANF 1 +#define HAVE_SNPRINTF 1 +#define HAVE_VSNPRINTF 1 +#define HAVE_M_PI 1 +#define HAVE_ATAN 1 +#define HAVE_ATAN2 1 +#define HAVE_CEIL 1 +#define HAVE_COPYSIGN 1 +#define HAVE_COS 1 +#define HAVE_COSF 1 +#define HAVE_FABS 1 +#define HAVE_FLOOR 1 +#define HAVE_LOG 1 +#define HAVE_POW 1 +#define HAVE_SCALBN 1 +#define HAVE_SIN 1 +#define HAVE_SINF 1 +#define HAVE_SQRT 1 +#define HAVE_SETJMP 1 +#define HAVE_NANOSLEEP 1 +//#define HAVE_SYSCONF 1 +//#define HAVE_SIGACTION 1 + + +/* PSP isn't that sophisticated */ +#define LACKS_SYS_MMAN_H 1 + +/* Enable the stub thread support (src/thread/psp/\*.c) */ +#define SDL_THREAD_PSP 1 + +/* Enable the stub timer support (src/timer/psp/\*.c) */ +#define SDL_TIMERS_PSP 1 + +/* Enable the stub joystick driver (src/joystick/psp/\*.c) */ +#define SDL_JOYSTICK_PSP 1 + +/* Enable the stub audio driver (src/audio/psp/\*.c) */ +#define SDL_AUDIO_DRIVER_PSP 1 + +/* PSP video dirver */ +#define SDL_VIDEO_DRIVER_PSP 1 + +/* PSP render dirver */ +#define SDL_VIDEO_RENDER_PSP 1 + +#define SDL_POWER_PSP 1 + +/* PSP doesn't have haptic device (src/haptic/dummy/\*.c) */ +#define SDL_HAPTIC_DISABLED 1 + +/* PSP can't load shared object (src/loadso/dummy/\*.c) */ +#define SDL_LOADSO_DISABLED 1 + + +#endif /* _SDL_config_minimal_h */ diff --git a/include/SDL_platform.h b/include/SDL_platform.h index e02ff4a52..86b45bc6a 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -124,6 +124,10 @@ #define __NINTENDODS__ 1 #endif +#if defined(__PSP__) +#undef __PLAYSTATIONPORTABLE__ +#define __PLAYSTATIONPORTABLE__ 1 +#endif #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ diff --git a/include/SDL_test_common.h b/include/SDL_test_common.h index 4977bed70..411d03347 100644 --- a/include/SDL_test_common.h +++ b/include/SDL_test_common.h @@ -37,6 +37,9 @@ #ifdef __NDS__ #define DEFAULT_WINDOW_WIDTH 256 #define DEFAULT_WINDOW_HEIGHT (2*192) +#elif defined(__PSP__) +#define DEFAULT_WINDOW_WIDTH 480 +#define DEFAULT_WINDOW_HEIGHT 272 #else #define DEFAULT_WINDOW_WIDTH 640 #define DEFAULT_WINDOW_HEIGHT 480 diff --git a/src/SDL.c b/src/SDL.c index ae279860d..a8707d7ec 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -408,6 +408,8 @@ SDL_GetPlatform() return "Windows"; #elif __IPHONEOS__ return "iPhone OS"; +#elif __PSP__ + return "PlayStation Portable"; #else return "Unknown (see SDL_platform.h)"; #endif diff --git a/src/SDL_log.c b/src/SDL_log.c index 6945689a6..b62f7fd5a 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -327,6 +327,20 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, return; } } +#elif defined(__PSP__) +//Simple Log System for PSP + { + unsigned int length; + char* output; + FILE* pFile; + length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1; + output = SDL_stack_alloc(char, length); + SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message); + pFile = fopen ("SDL_Log.txt", "a"); + fwrite (output, strlen (output), 1, pFile); + SDL_stack_free(output); + fclose (pFile); + } #endif #if HAVE_STDIO_H fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message); diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 6e87e1a5a..abe8c8b86 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -66,7 +66,7 @@ extern AudioBootStrap DART_bootstrap; extern AudioBootStrap NDSAUD_bootstrap; extern AudioBootStrap FUSIONSOUND_bootstrap; extern AudioBootStrap ANDROIDAUD_bootstrap; - +extern AudioBootStrap PSPAUD_bootstrap; /* Available audio drivers */ static const AudioBootStrap *const bootstrap[] = { @@ -129,6 +129,9 @@ static const AudioBootStrap *const bootstrap[] = { #endif #if SDL_AUDIO_DRIVER_ANDROID &ANDROIDAUD_bootstrap, +#endif +#if SDL_AUDIO_DRIVER_PSP + &PSPAUD_bootstrap, #endif NULL }; diff --git a/src/audio/psp/SDL_pspaudio.c b/src/audio/psp/SDL_pspaudio.c new file mode 100644 index 000000000..fc277e60d --- /dev/null +++ b/src/audio/psp/SDL_pspaudio.c @@ -0,0 +1,199 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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 +#include +#include +#include + +#include "SDL_audio.h" +#include "SDL_error.h" +#include "SDL_timer.h" +#include "../SDL_audiomem.h" +#include "../SDL_audio_c.h" +#include "../SDL_audiodev_c.h" +#include "../SDL_sysaudio.h" +#include "SDL_pspaudio.h" + +#include +#include + +/* The tag name used by PSP audio */ +#define PSPAUD_DRIVER_NAME "psp" + +static int +PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture) +{ + int format, mixlen, i; + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc(sizeof(*this->hidden)); + if (this->hidden == NULL) { + SDL_OutOfMemory(); + return 0; + } + SDL_memset(this->hidden, 0, sizeof(*this->hidden)); + switch (this->spec.format & 0xff) { + case 8: + case 16: + this->spec.format = AUDIO_S16LSB; + break; + default: + SDL_SetError("Unsupported audio format"); + return 0; + } + + /* The sample count must be a multiple of 64. */ + this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples); + this->spec.freq = 44100; + + /* Update the fragment size as size in bytes. */ +// SDL_CalculateAudioSpec(this->spec); MOD + switch (this->spec.format) { + case AUDIO_U8: + this->spec.silence = 0x80; + break; + default: + this->spec.silence = 0x00; + break; + } + this->spec.size = SDL_AUDIO_BITSIZE(this->spec.format) / 8; + this->spec.size *= this->spec.channels; + this->spec.size *= this->spec.samples; + +//========================================== + + /* Allocate the mixing buffer. Its size and starting address must + be a multiple of 64 bytes. Our sample count is already a multiple of + 64, so spec->size should be a multiple of 64 as well. */ + mixlen = this->spec.size * NUM_BUFFERS; + this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen); + if (this->hidden->rawbuf == NULL) { + SDL_SetError("Couldn't allocate mixing buffer"); + return 0; + } + + /* Setup the hardware channel. */ + if (this->spec.channels == 1) { + format = PSP_AUDIO_FORMAT_MONO; + } else { + format = PSP_AUDIO_FORMAT_STEREO; + } + this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format); + if (this->hidden->channel < 0) { + SDL_SetError("Couldn't reserve hardware channel"); + free(this->hidden->rawbuf); + this->hidden->rawbuf = NULL; + return 0; + } + + memset(this->hidden->rawbuf, 0, mixlen); + for (i = 0; i < NUM_BUFFERS; i++) { + this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size]; + } + + this->hidden->next_buffer = 0; + return 1; +} + +static void PSPAUD_PlayDevice(_THIS) +{ + Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer]; + + if (this->spec.channels == 1) { + sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf); + } else { + sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf); + } + + this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS; +} + +/* This function waits until it is possible to write a full sound buffer */ +static void PSPAUD_WaitDevice(_THIS) +{ + /* Because we block when sending audio, there's no need for this function to do anything. */ +} +static Uint8 *PSPAUD_GetDeviceBuf(_THIS) +{ + return this->hidden->mixbufs[this->hidden->next_buffer]; +} + +static void PSPAUD_CloseDevice(_THIS) +{ + if (this->hidden->channel >= 0) { + sceAudioChRelease(this->hidden->channel); + this->hidden->channel = -1; + } + + if (this->hidden->rawbuf != NULL) { + free(this->hidden->rawbuf); + this->hidden->rawbuf = NULL; + } +} +static void PSPAUD_ThreadInit(_THIS) +{ + /* Increase the priority of this audio thread by 1 to put it + ahead of other SDL threads. */ + SceUID thid; + SceKernelThreadInfo status; + thid = sceKernelGetThreadId(); + status.size = sizeof(SceKernelThreadInfo); + if (sceKernelReferThreadStatus(thid, &status) == 0) { + sceKernelChangeThreadPriority(thid, status.currentPriority - 1); + } +} + + +static int +PSPAUD_Init(SDL_AudioDriverImpl * impl) +{ + + // Set the function pointers + impl->OpenDevice = PSPAUD_OpenDevice; + impl->PlayDevice = PSPAUD_PlayDevice; + impl->WaitDevice = PSPAUD_WaitDevice; + impl->GetDeviceBuf = PSPAUD_GetDeviceBuf; + impl->WaitDone = PSPAUD_WaitDevice; + impl->CloseDevice = PSPAUD_CloseDevice; + impl->ThreadInit = PSPAUD_ThreadInit; + + //PSP audio device + impl->OnlyHasDefaultOutputDevice = 1; +/* + impl->HasCaptureSupport = 1; + + impl->OnlyHasDefaultInputDevice = 1; +*/ + /* + impl->DetectDevices = DSOUND_DetectDevices; + impl->Deinitialize = DSOUND_Deinitialize; + */ + return 1; /* this audio target is available. */ +} + +AudioBootStrap PSPAUD_bootstrap = { + "psp", "PSP audio driver", PSPAUD_Init, 0 +}; + + /* SDL_AUDI*/ + + + diff --git a/src/audio/psp/SDL_pspaudio.h b/src/audio/psp/SDL_pspaudio.h new file mode 100644 index 000000000..22cf2d327 --- /dev/null +++ b/src/audio/psp/SDL_pspaudio.h @@ -0,0 +1,45 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + +#ifndef _SDL_pspaudio_h +#define _SDL_pspaudio_h + +#include "../SDL_sysaudio.h" + +/* Hidden "this" pointer for the video functions */ +#define _THIS SDL_AudioDevice *this + +#define NUM_BUFFERS 2 + +struct SDL_PrivateAudioData { + /* The hardware output channel. */ + int channel; + /* The raw allocated mixing buffer. */ + Uint8 *rawbuf; + /* Individual mixing buffers. */ + Uint8 *mixbufs[NUM_BUFFERS]; + /* Index of the next available mixing buffer. */ + int next_buffer; +}; + +#endif /* _SDL_pspaudio_h */ +/* vim: ts=4 sw=4 + */ diff --git a/src/events/SDL_gesture.c b/src/events/SDL_gesture.c index b43e1f92e..bd7681e3a 100644 --- a/src/events/SDL_gesture.c +++ b/src/events/SDL_gesture.c @@ -27,7 +27,10 @@ #include "SDL_events_c.h" #include "SDL_gesture_c.h" +#if !defined(__PSP__) #include +#endif + #include #include #include diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c new file mode 100644 index 000000000..69cab8402 --- /dev/null +++ b/src/joystick/psp/SDL_sysjoystick.c @@ -0,0 +1,276 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + +/* This is the system specific header for the SDL joystick API */ +#include +#include + +#include /* For the definition of NULL */ +#include + +#include "../SDL_sysjoystick.h" +#include "../SDL_joystick_c.h" + +#include "SDL_events.h" +#include "SDL_error.h" +#include "SDL_thread.h" +#include "SDL_mutex.h" +#include "SDL_timer.h" + +/* Current pad state */ +static SceCtrlData pad = { .Lx = 0, .Ly = 0, .Buttons = 0 }; +static SDL_sem *pad_sem = NULL; +static SDL_Thread *thread = NULL; +static int running = 0; +static const enum PspCtrlButtons button_map[] = { + PSP_CTRL_TRIANGLE, PSP_CTRL_CIRCLE, PSP_CTRL_CROSS, PSP_CTRL_SQUARE, + PSP_CTRL_LTRIGGER, PSP_CTRL_RTRIGGER, + PSP_CTRL_DOWN, PSP_CTRL_LEFT, PSP_CTRL_UP, PSP_CTRL_RIGHT, + PSP_CTRL_SELECT, PSP_CTRL_START, PSP_CTRL_HOME, PSP_CTRL_HOLD }; +static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */ + +typedef struct +{ + int x; + int y; +} point; + +// 4 points define the bezier-curve. +static point a = { 0, 0 }; +static point b = { 50, 0 }; +static point c = { 78, 32767 }; +static point d = { 128, 32767 }; + +// simple linear interpolation between two points +static __inline__ void lerp (point *dest, point *a, point *b, float t) +{ + dest->x = a->x + (b->x - a->x)*t; + dest->y = a->y + (b->y - a->y)*t; +} + +// evaluate a point on a bezier-curve. t goes from 0 to 1.0 +static int calc_bezier_y(float t) +{ + point ab, bc, cd, abbc, bccd, dest; + lerp (&ab, &a, &b, t); // point between a and b + lerp (&bc, &b, &c, t); // point between b and c + lerp (&cd, &c, &d, t); // point between c and d + lerp (&abbc, &ab, &bc, t); // point between ab and bc + lerp (&bccd, &bc, &cd, t); // point between bc and cd + lerp (&dest, &abbc, &bccd, t); // point on the bezier-curve + return dest.y; +} + +/* + * Collect pad data about once per frame + */ +int JoystickUpdate(void *data) +{ + while (running) { + SDL_SemWait(pad_sem); + sceCtrlPeekBufferPositive(&pad, 1); + SDL_SemPost(pad_sem); + /* Delay 1/60th of a second */ + sceKernelDelayThread(1000000 / 60); + } + return 0; +} + + + +/* Function to scan the system for joysticks. + * This function should set SDL_numjoysticks to the number of available + * joysticks. Joystick 0 should be the system default joystick. + * It should return number of joysticks, or -1 on an unrecoverable fatal error. + */ +int SDL_SYS_JoystickInit(void) +{ + int i; + +// SDL_numjoysticks = 1; + + /* Setup input */ + sceCtrlSetSamplingCycle(0); + sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); + + /* Start thread to read data */ + if((pad_sem = SDL_CreateSemaphore(1)) == NULL) { + SDL_SetError("Can't create input semaphore\n"); + return -1; + } + running = 1; + if((thread = SDL_CreateThread(JoystickUpdate, "JoySitckThread",NULL)) == NULL) { + SDL_SetError("Can't create input thread\n"); + return -1; + } + + /* Create an accurate map from analog inputs (0 to 255) + to SDL joystick positions (-32768 to 32767) */ + for (i = 0; i < 128; i++) + { + float t = (float)i/127.0f; + analog_map[i+128] = calc_bezier_y(t); + analog_map[127-i] = -1 * analog_map[i+128]; + } + + return 1; +} + +int SDL_SYS_NumJoysticks() +{ + return 1; +} + +void SDL_SYS_JoystickDetect() +{ +} + +SDL_bool SDL_SYS_JoystickNeedsPolling() +{ + return SDL_FALSE; +} + +/* Function to get the device-dependent name of a joystick */ +const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index) +{ + return "PSP builtin joypad"; +} + +/* Function to perform the mapping from device index to the instance id for this index */ +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) +{ + return device_index; +} + +/* Function to get the device-dependent name of a joystick */ +const char *SDL_SYS_JoystickName(int index) +{ + if (index == 0) + return "PSP controller"; + + SDL_SetError("No joystick available with that index"); + return(NULL); +} + +/* Function to open a joystick for use. + The joystick to open is specified by the index field of the joystick. + This should fill the nbuttons and naxes fields of the joystick structure. + It returns 0, or -1 if there is an error. + */ +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index) +{ + joystick->nbuttons = 14; + joystick->naxes = 2; + joystick->nhats = 0; + + return 0; +} + +/* Function to determine is this joystick is attached to the system right now */ +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) +{ + return SDL_TRUE; +} +/* Function to update the state of a joystick - called as a device poll. + * This function shouldn't update the joystick structure directly, + * but instead should call SDL_PrivateJoystick*() to deliver events + * and update joystick device state. + */ + +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +{ + int i; + enum PspCtrlButtons buttons; + enum PspCtrlButtons changed; + unsigned char x, y; + static enum PspCtrlButtons old_buttons = 0; + static unsigned char old_x = 0, old_y = 0; + + SDL_SemWait(pad_sem); + buttons = pad.Buttons; + x = pad.Lx; + y = pad.Ly; + SDL_SemPost(pad_sem); + + /* Axes */ + if(old_x != x) { + SDL_PrivateJoystickAxis(joystick, 0, analog_map[x]); + old_x = x; + } + if(old_y != y) { + SDL_PrivateJoystickAxis(joystick, 1, analog_map[y]); + old_y = y; + } + + /* Buttons */ + changed = old_buttons ^ buttons; + old_buttons = buttons; + if(changed) { + for(i=0; iname; + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + +/* vim: ts=4 sw=4 + */ diff --git a/src/main/psp/SDL_psp_main.c b/src/main/psp/SDL_psp_main.c new file mode 100644 index 000000000..0286eadec --- /dev/null +++ b/src/main/psp/SDL_psp_main.c @@ -0,0 +1,80 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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_main.h" +#include +#include +#include +#include +#include +#include + +/* If application's main() is redefined as SDL_main, and libSDLmain is + linked, then this file will create the standard exit callback, + define the PSP_MODULE_INFO macro, and exit back to the browser when + the program is finished. + + You can still override other parameters in your own code if you + desire, such as PSP_HEAP_SIZE_KB, PSP_MAIN_THREAD_ATTR, + PSP_MAIN_THREAD_STACK_SIZE, etc. +*/ + +extern int SDL_main(int argc, char *argv[]); + +PSP_MODULE_INFO("SDL App", 0, 1, 1); + +int sdl_psp_exit_callback(int arg1, int arg2, void *common) +{ + exit(0); + return 0; +} + +int sdl_psp_callback_thread(SceSize args, void *argp) +{ + int cbid; + cbid = sceKernelCreateCallback("Exit Callback", + sdl_psp_exit_callback, NULL); + sceKernelRegisterExitCallback(cbid); + sceKernelSleepThreadCB(); + return 0; +} + +int sdl_psp_setup_callbacks(void) +{ + int thid = 0; + thid = sceKernelCreateThread("update_thread", + sdl_psp_callback_thread, 0x11, 0xFA0, 0, 0); + if(thid >= 0) + sceKernelStartThread(thid, 0, 0); + return thid; +} + +int main(int argc, char *argv[]) +{ + pspDebugScreenInit(); + sdl_psp_setup_callbacks(); + + /* Register sceKernelExitGame() to be called when we exit */ + atexit(sceKernelExitGame); + + (void)SDL_main(argc, argv); + return 0; +} diff --git a/src/power/SDL_power.c b/src/power/SDL_power.c index b8ad3657d..bb920600e 100644 --- a/src/power/SDL_power.c +++ b/src/power/SDL_power.c @@ -37,6 +37,7 @@ SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *); +SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *); #ifndef SDL_POWER_DISABLED #ifdef SDL_POWER_HARDWIRED @@ -77,6 +78,10 @@ static SDL_GetPowerInfo_Impl implementations[] = { #ifdef SDL_POWER_ANDROID /* handles Android. */ SDL_GetPowerInfo_Android, #endif +#ifdef SDL_POWER_PSP /* handles PSP. */ + SDL_GetPowerInfo_PSP, +#endif + #ifdef SDL_POWER_HARDWIRED SDL_GetPowerInfo_Hardwired, #endif diff --git a/src/power/psp/SDL_syspower.c b/src/power/psp/SDL_syspower.c new file mode 100644 index 000000000..363c952d0 --- /dev/null +++ b/src/power/psp/SDL_syspower.c @@ -0,0 +1,68 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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" + +#ifndef SDL_POWER_DISABLED +#if SDL_POWER_PSP + +#include "SDL_power.h" +#include + + +SDL_bool +SDL_GetPowerInfo_PSP(SDL_PowerState * state, int *seconds, + int *percent) +{ + int battery = scePowerIsBatteryExist(); + int plugged = scePowerIsPowerOnline(); + int charging = scePowerIsBatteryCharging(); + + *state = SDL_POWERSTATE_UNKNOWN; + *seconds = -1; + *percent = -1; + + if (!battery) { + *state = SDL_POWERSTATE_NO_BATTERY; + *seconds = -1; + *percent = -1; + } else if (charging) { + *state = SDL_POWERSTATE_CHARGING; + *percent = scePowerGetBatteryLifePercent(); + *seconds = scePowerGetBatteryLifeTime()*60; + } else if (plugged) { + *state = SDL_POWERSTATE_CHARGED; + *percent = scePowerGetBatteryLifePercent(); + *seconds = scePowerGetBatteryLifeTime()*60; + } else { + *state = SDL_POWERSTATE_ON_BATTERY; + *percent = scePowerGetBatteryLifePercent(); + *seconds = scePowerGetBatteryLifeTime()*60; + } + + + return SDL_TRUE; /* always the definitive answer on PSP. */ +} + +#endif /* SDL_POWER_PSP */ +#endif /* SDL_POWER_DISABLED */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index df2e22b24..c3f86ca1a 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -63,6 +63,9 @@ static const SDL_RenderDriver *render_drivers[] = { #endif #if SDL_VIDEO_RENDER_NDS &NDS_RenderDriver, +#endif +#if SDL_VIDEO_RENDER_PSP + &PSP_RenderDriver, #endif &SW_RenderDriver #endif /* !SDL_RENDER_DISABLED */ diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index 863db3cb3..95d3f67e0 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -176,6 +176,9 @@ extern SDL_RenderDriver DirectFB_RenderDriver; #if SDL_VIDEO_RENDER_NDS extern SDL_RenderDriver NDS_RenderDriver; #endif +#if SDL_VIDEO_RENDER_PSP +extern SDL_RenderDriver PSP_RenderDriver; +#endif extern SDL_RenderDriver SW_RenderDriver; #endif /* !SDL_RENDER_DISABLED */ diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c new file mode 100644 index 000000000..fb4e2289a --- /dev/null +++ b/src/render/psp/SDL_render_psp.c @@ -0,0 +1,1024 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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" + +#if SDL_VIDEO_RENDER_PSP + +#include "SDL_hints.h" +#include "../SDL_sysrender.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + + +/* PSP renderer implementation, based on the PGE */ + + +extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); + + +static SDL_Renderer *PSP_CreateRenderer(SDL_Window * window, Uint32 flags); +static void PSP_WindowEvent(SDL_Renderer * renderer, + const SDL_WindowEvent *event); +static int PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); +static int PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, + int pitch); +static int PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, void **pixels, int *pitch); +static void PSP_UnlockTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static int PSP_SetRenderTarget(SDL_Renderer * renderer, + SDL_Texture * texture); +static int PSP_UpdateViewport(SDL_Renderer * renderer); +static int PSP_RenderClear(SDL_Renderer * renderer); +static int PSP_RenderDrawPoints(SDL_Renderer * renderer, + const SDL_FPoint * points, int count); +static int PSP_RenderDrawLines(SDL_Renderer * renderer, + const SDL_FPoint * points, int count); +static int PSP_RenderFillRects(SDL_Renderer * renderer, + const SDL_FRect * rects, int count); +static int PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, + const SDL_FRect * dstrect); +static int PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 pixel_format, void * pixels, int pitch); +static int PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_FRect * dstrect, + const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip); +static void PSP_RenderPresent(SDL_Renderer * renderer); +static void PSP_DestroyTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void PSP_DestroyRenderer(SDL_Renderer * renderer); + +/* +SDL_RenderDriver PSP_RenderDriver = { + PSP_CreateRenderer, + { + "PSP", + (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), + 1, + {SDL_PIXELFORMAT_ABGR8888}, + 0, + 0} +}; +*/ +SDL_RenderDriver PSP_RenderDriver = { + .CreateRenderer = PSP_CreateRenderer, + .info = { + .name = "PSP", + .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE, + .num_texture_formats = 4, + .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565, + [1] = SDL_PIXELFORMAT_ABGR1555, + [2] = SDL_PIXELFORMAT_ABGR4444, + [3] = SDL_PIXELFORMAT_ABGR8888, + }, + .max_texture_width = 512, + .max_texture_height = 512, + } +}; + +#define PSP_SCREEN_WIDTH 480 +#define PSP_SCREEN_HEIGHT 272 + +#define PSP_FRAME_BUFFER_WIDTH 512 +#define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT) + +static unsigned int __attribute__((aligned(16))) DisplayList[262144]; + + +#define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11)) +#define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0)) +#define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12)) +#define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24)) + + +typedef struct +{ + void* frontbuffer ; + void* backbuffer ; + SDL_bool initialized ; + SDL_bool displayListAvail ; + unsigned int psm ; + unsigned int bpp ; + + SDL_bool vsync; + unsigned int currentColor; + int currentBlendMode; + +} PSP_RenderData; + + +typedef struct +{ + void *data; /**< Image data. */ + unsigned int size; /**< Size of data in bytes. */ + unsigned int width; /**< Image width. */ + unsigned int height; /**< Image height. */ + unsigned int textureWidth; /**< Texture width (power of two). */ + unsigned int textureHeight; /**< Texture height (power of two). */ + unsigned int bits; /**< Image bits per pixel. */ + unsigned int format; /**< Image format - one of ::pgePixelFormat. */ + unsigned int pitch; + SDL_bool swizzled; /**< Is image swizzled. */ + +} PSP_TextureData; + +typedef struct +{ + float x, y, z; +} VertV; + + +typedef struct +{ + float u, v; + float x, y, z; + +} VertTV; + + +// Return next power of 2 +static int +TextureNextPow2(unsigned int w) +{ + if(w == 0) + return 0; + + unsigned int n = 2; + + while(w > n) + n <<= 1; + + return n; +} + + +static int +GetScaleQuality(void) +{ + const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); + + if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { + return GU_NEAREST; // GU_NEAREST good for tile-map + } else { + return GU_LINEAR; // GU_LINEAR good for scaling + } +} + +static int +PixelFormatToPSPFMT(Uint32 format) +{ + switch (format) { + case SDL_PIXELFORMAT_BGR565: + return GU_PSM_5650; + case SDL_PIXELFORMAT_ABGR1555: + return GU_PSM_5551; + case SDL_PIXELFORMAT_ABGR4444: + return GU_PSM_4444; + case SDL_PIXELFORMAT_ABGR8888: + return GU_PSM_8888; + default: + return GU_PSM_8888; + } +} + +void +StartDrawing(SDL_Renderer * renderer) +{ + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; + if(data->displayListAvail) + return; + + sceGuStart(GU_DIRECT, DisplayList); + data->displayListAvail = SDL_TRUE; +} + + +int +TextureSwizzle(PSP_TextureData *psp_texture) +{ + if(psp_texture->swizzled) + return 1; + + int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); + int height = psp_texture->size / bytewidth; + + int rowblocks = (bytewidth>>4); + int rowblocksadd = (rowblocks-1)<<7; + unsigned int blockaddress = 0; + unsigned int *src = (unsigned int*) psp_texture->data; + + unsigned char *data = NULL; + data = malloc(psp_texture->size); + + int j; + + for(j = 0; j < height; j++, blockaddress += 16) + { + unsigned int *block; + + block = (unsigned int*)&data[blockaddress]; + + int i; + + for(i = 0; i < rowblocks; i++) + { + *block++ = *src++; + *block++ = *src++; + *block++ = *src++; + *block++ = *src++; + block += 28; + } + + if((j & 0x7) == 0x7) + blockaddress += rowblocksadd; + } + + free(psp_texture->data); + psp_texture->data = data; + psp_texture->swizzled = SDL_TRUE; + + return 1; +} +int TextureUnswizzle(PSP_TextureData *psp_texture) +{ + if(!psp_texture->swizzled) + return 1; + + int blockx, blocky; + + int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); + int height = psp_texture->size / bytewidth; + + int widthblocks = bytewidth/16; + int heightblocks = height/8; + + int dstpitch = (bytewidth - 16)/4; + int dstrow = bytewidth * 8; + + unsigned int *src = (unsigned int*) psp_texture->data; + + unsigned char *data = NULL; + + data = malloc(psp_texture->size); + + if(!data) + return 0; + + sceKernelDcacheWritebackAll(); + + int j; + + unsigned char *ydst = (unsigned char *)data; + + for(blocky = 0; blocky < heightblocks; ++blocky) + { + unsigned char *xdst = ydst; + + for(blockx = 0; blockx < widthblocks; ++blockx) + { + unsigned int *block; + + block = (unsigned int*)xdst; + + for(j = 0; j < 8; ++j) + { + *(block++) = *(src++); + *(block++) = *(src++); + *(block++) = *(src++); + *(block++) = *(src++); + block += dstpitch; + } + + xdst += 16; + } + + ydst += dstrow; + } + + free(psp_texture->data); + + psp_texture->data = data; + + psp_texture->swizzled = SDL_FALSE; + + return 1; +} + +SDL_Renderer * +PSP_CreateRenderer(SDL_Window * window, Uint32 flags) +{ + + SDL_Renderer *renderer; + PSP_RenderData *data; + int pixelformat; + renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); + if (!renderer) { + SDL_OutOfMemory(); + return NULL; + } + + data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data)); + if (!data) { + PSP_DestroyRenderer(renderer); + SDL_OutOfMemory(); + return NULL; + } + + + renderer->WindowEvent = PSP_WindowEvent; + renderer->CreateTexture = PSP_CreateTexture; + renderer->UpdateTexture = PSP_UpdateTexture; + renderer->LockTexture = PSP_LockTexture; + renderer->UnlockTexture = PSP_UnlockTexture; + renderer->SetRenderTarget = PSP_SetRenderTarget; + renderer->UpdateViewport = PSP_UpdateViewport; + renderer->RenderClear = PSP_RenderClear; + renderer->RenderDrawPoints = PSP_RenderDrawPoints; + renderer->RenderDrawLines = PSP_RenderDrawLines; + renderer->RenderFillRects = PSP_RenderFillRects; + renderer->RenderCopy = PSP_RenderCopy; + renderer->RenderReadPixels = PSP_RenderReadPixels; + renderer->RenderCopyEx = PSP_RenderCopyEx; + renderer->RenderPresent = PSP_RenderPresent; + renderer->DestroyTexture = PSP_DestroyTexture; + renderer->DestroyRenderer = PSP_DestroyRenderer; + renderer->info = PSP_RenderDriver.info; + renderer->info.flags = SDL_RENDERER_ACCELERATED; + renderer->driverdata = data; + renderer->window = window; + + if (data->initialized != SDL_FALSE) + return 0; + data->initialized = SDL_TRUE; + + if (flags & SDL_RENDERER_PRESENTVSYNC) { + data->vsync = SDL_TRUE; + } else { + data->vsync = SDL_FALSE; + } + + pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window)); + switch(pixelformat) + { + case GU_PSM_4444: + case GU_PSM_5650: + case GU_PSM_5551: + data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1); + data->backbuffer = (unsigned int *)(0); + data->bpp = 2; + data->psm = pixelformat; + break; + default: + data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2); + data->backbuffer = (unsigned int *)(0); + data->bpp = 4; + data->psm = GU_PSM_8888; + break; + } + + sceGuInit(); + // setup GU + sceGuStart(GU_DIRECT, DisplayList); + sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH); + sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH); + + + sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1)); + sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); + + data->frontbuffer = vabsptr(data->frontbuffer); + data->backbuffer = vabsptr(data->backbuffer); + + // Scissoring + sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); + sceGuEnable(GU_SCISSOR_TEST); + + // Backface culling + sceGuFrontFace(GU_CCW); + sceGuEnable(GU_CULL_FACE); + + // Texturing + sceGuEnable(GU_TEXTURE_2D); + sceGuShadeModel(GU_SMOOTH); + sceGuTexWrap(GU_REPEAT, GU_REPEAT); + + // Blending + sceGuEnable(GU_BLEND); + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); + + sceGuTexFilter(GU_LINEAR,GU_LINEAR); + + sceGuFinish(); + sceGuSync(0,0); + sceDisplayWaitVblankStartCB(); + sceGuDisplay(GU_TRUE); + + return renderer; +} + +static void +PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) +{ + +} + + +static int +PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ +// PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; + PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));; + + if(!psp_texture) + return -1; + + psp_texture->swizzled = SDL_FALSE; + psp_texture->width = texture->w; + psp_texture->height = texture->h; + psp_texture->textureHeight = TextureNextPow2(texture->h); + psp_texture->textureWidth = TextureNextPow2(texture->w); + psp_texture->format = PixelFormatToPSPFMT(texture->format); + + switch(psp_texture->format) + { + case GU_PSM_5650: + case GU_PSM_5551: + case GU_PSM_4444: + psp_texture->bits = 16; + break; + + case GU_PSM_8888: + psp_texture->bits = 32; + break; + + default: + return -1; + } + + psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format); + psp_texture->size = psp_texture->textureHeight*psp_texture->pitch; + psp_texture->data = SDL_calloc(1, psp_texture->size); + + if(!psp_texture->data) + { + SDL_OutOfMemory(); + SDL_free(psp_texture); + return -1; + } + texture->driverdata = psp_texture; + + return 0; +} + + +void +TextureActivate(SDL_Texture * texture) +{ + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + int scaleMode = GetScaleQuality(); + + // Swizzling is useless with small textures. + if (texture->w >= 16 || texture->h >= 16) + { + TextureSwizzle(psp_texture); + } + + sceGuEnable(GU_TEXTURE_2D); + sceGuTexWrap(GU_REPEAT, GU_REPEAT); + sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled); + sceGuTexFilter(scaleMode, scaleMode); // GU_NEAREST good for tile-map + // GU_LINEAR good for scaling + sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data); + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); +} + + +static int +PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, int pitch) +{ +// PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + const Uint8 *src; + Uint8 *dst; + int row, length,dpitch; + src = pixels; + + PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch); + length = rect->w * SDL_BYTESPERPIXEL(texture->format); + if (length == pitch && length == dpitch) { + SDL_memcpy(dst, src, length*rect->h); + } else { + for (row = 0; row < rect->h; ++row) { + SDL_memcpy(dst, src, length); + src += pitch; + dst += dpitch; + } + } + + sceKernelDcacheWritebackAll(); + return 0; +} + +static int +PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, void **pixels, int *pitch) +{ + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + + *pixels = + (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch + + rect->x * SDL_BYTESPERPIXEL(texture->format)); + *pitch = psp_texture->pitch; + return 0; +} + +static void +PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + SDL_Rect rect; + + /* We do whole texture updates, at least for now */ + rect.x = 0; + rect.y = 0; + rect.w = texture->w; + rect.h = texture->h; + PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch); +} + +static int +PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) +{ + + return 0; +} + +static int +PSP_UpdateViewport(SDL_Renderer * renderer) +{ + + return 0; +} + + +static void +PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode) +{ + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; + if (blendMode != data-> currentBlendMode) { + switch (blendMode) { + case SDL_BLENDMODE_NONE: + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + sceGuDisable(GU_BLEND); + break; + case SDL_BLENDMODE_BLEND: + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); + sceGuEnable(GU_BLEND); + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 ); + break; + case SDL_BLENDMODE_ADD: + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); + sceGuEnable(GU_BLEND); + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF ); + break; + case SDL_BLENDMODE_MOD: + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); + sceGuEnable(GU_BLEND); + sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0); + break; + } + data->currentBlendMode = blendMode; + } +} + + + +static int +PSP_RenderClear(SDL_Renderer * renderer) +{ + //start list + StartDrawing(renderer); + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; + sceGuClearColor(color); + sceGuClearDepth(0); + sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT); + + return 0; +} + +static int +PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, + int count) +{ + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; + int i; + StartDrawing(renderer); + VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV)); + + for (i = 0; i < count; ++i) { + vertices[i].x = points[i].x; + vertices[i].y = points[i].y; + vertices[i].z = 0.0f; + } + sceGuDisable(GU_TEXTURE_2D); + sceGuColor(color); + sceGuShadeModel(GU_FLAT); + sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices); + sceGuShadeModel(GU_SMOOTH); + sceGuEnable(GU_TEXTURE_2D); + + return 0; +} + +static int +PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, + int count) +{ + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; + int i; + StartDrawing(renderer); + VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV)); + + for (i = 0; i < count; ++i) { + vertices[i].x = points[i].x; + vertices[i].y = points[i].y; + vertices[i].z = 0.0f; + } + + sceGuDisable(GU_TEXTURE_2D); + sceGuColor(color); + sceGuShadeModel(GU_FLAT); + sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices); + sceGuShadeModel(GU_SMOOTH); + sceGuEnable(GU_TEXTURE_2D); + + return 0; +} + +static int +PSP_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, + int count) +{ + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; + int i; + StartDrawing(renderer); + + for (i = 0; i < count; ++i) { + const SDL_FRect *rect = &rects[i]; + VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1)); + vertices[0].x = rect->x; + vertices[0].y = rect->y; + vertices[0].z = 0.0f; + + vertices[1].x = rect->x + rect->w; + vertices[1].y = rect->y + rect->h; + vertices[1].z = 0.0f; + + sceGuDisable(GU_TEXTURE_2D); + sceGuColor(color); + sceGuShadeModel(GU_FLAT); + sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); + sceGuShadeModel(GU_SMOOTH); + sceGuEnable(GU_TEXTURE_2D); + } + + return 0; +} + + +#define PI 3.14159265358979f + +#define radToDeg(x) ((x)*180.f/PI) +#define degToRad(x) ((x)*PI/180.f) + +float MathAbs(float x) +{ + float result; + + __asm__ volatile ( + "mtv %1, S000\n" + "vabs.s S000, S000\n" + "mfv %0, S000\n" + : "=r"(result) : "r"(x)); + + return result; +} + +void MathSincos(float r, float *s, float *c) +{ + __asm__ volatile ( + "mtv %2, S002\n" + "vcst.s S003, VFPU_2_PI\n" + "vmul.s S002, S002, S003\n" + "vrot.p C000, S002, [s, c]\n" + "mfv %0, S000\n" + "mfv %1, S001\n" + : "=r"(*s), "=r"(*c): "r"(r)); +} + +void Swap(float *a, float *b) +{ + float n=*a; + *a = *b; + *b = n; +} + +static int +PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_FRect * dstrect) +{ + float x, y, width, height; + float u0, v0, u1, v1; + unsigned char alpha; + + x = dstrect->x; + y = dstrect->y; + width = dstrect->w; + height = dstrect->h; + + u0 = srcrect->x; + v0 = srcrect->y; + u1 = srcrect->x + srcrect->w; + v1 = srcrect->y + srcrect->h; + + alpha = texture->a; + + StartDrawing(renderer); + TextureActivate(texture); + PSP_SetBlendMode(renderer, renderer->blendMode); + + if(alpha != 255) + { + sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); + sceGuColor(GU_RGBA(255, 255, 255, alpha)); + }else{ + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + sceGuColor(0xFFFFFFFF); + } + + if((MathAbs(u1) - MathAbs(u0)) < 64.0f) + { + VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1); + + vertices[0].u = u0; + vertices[0].v = v0; + vertices[0].x = x; + vertices[0].y = y; + vertices[0].z = 0; + + vertices[1].u = u1; + vertices[1].v = v1; + vertices[1].x = x + width; + vertices[1].y = y + height; + vertices[1].z = 0; + + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); + } + else + { + float start, end; + float curU = u0; + float curX = x; + float endX = x + width; + float slice = 64.0f; + float ustep = (u1 - u0)/width * slice; + + if(ustep < 0.0f) + ustep = -ustep; + + for(start = 0, end = width; start < end; start += slice) + { + VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1); + + float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice; + float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep; + + vertices[0].u = curU; + vertices[0].v = v0; + vertices[0].x = curX; + vertices[0].y = y; + vertices[0].z = 0; + + curU += sourceWidth; + curX += polyWidth; + + vertices[1].u = curU; + vertices[1].v = v1; + vertices[1].x = curX; + vertices[1].y = (y + height); + vertices[1].z = 0; + + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); + } + } + + if(alpha != 255) + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + return 0; +} + +static int +PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 pixel_format, void * pixels, int pitch) + +{ + return 0; +} + + +static int +PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_FRect * dstrect, + const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip) +{ + float x, y, width, height; + float u0, v0, u1, v1; + unsigned char alpha; + float centerx, centery; + + x = dstrect->x; + y = dstrect->y; + width = dstrect->w; + height = dstrect->h; + + u0 = srcrect->x; + v0 = srcrect->y; + u1 = srcrect->x + srcrect->w; + v1 = srcrect->y + srcrect->h; + + centerx = center->x; + centery = center->y; + + alpha = texture->a; + + StartDrawing(renderer); + TextureActivate(texture); + PSP_SetBlendMode(renderer, renderer->blendMode); + + if(alpha != 255) + { + sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); + sceGuColor(GU_RGBA(255, 255, 255, alpha)); + }else{ + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + sceGuColor(0xFFFFFFFF); + } + +// x += width * 0.5f; +// y += height * 0.5f; + x += centerx; + y += centery; + + float c, s; + + MathSincos(degToRad(angle), &s, &c); + +// width *= 0.5f; +// height *= 0.5f; + width -= centerx; + height -= centery; + + + float cw = c*width; + float sw = s*width; + float ch = c*height; + float sh = s*height; + + VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2); + + vertices[0].u = u0; + vertices[0].v = v0; + vertices[0].x = x - cw + sh; + vertices[0].y = y - sw - ch; + vertices[0].z = 0; + + vertices[1].u = u0; + vertices[1].v = v1; + vertices[1].x = x - cw - sh; + vertices[1].y = y - sw + ch; + vertices[1].z = 0; + + vertices[2].u = u1; + vertices[2].v = v1; + vertices[2].x = x + cw - sh; + vertices[2].y = y + sw + ch; + vertices[2].z = 0; + + vertices[3].u = u1; + vertices[3].v = v0; + vertices[3].x = x + cw + sh; + vertices[3].y = y + sw - ch; + vertices[3].z = 0; + + if (flip & SDL_FLIP_HORIZONTAL) { + Swap(&vertices[0].v, &vertices[2].v); + Swap(&vertices[1].v, &vertices[3].v); + } + if (flip & SDL_FLIP_VERTICAL) { + Swap(&vertices[0].u, &vertices[2].u); + Swap(&vertices[1].u, &vertices[3].u); + } + + sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices); + + if(alpha != 255) + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + return 0; +} + +static void +PSP_RenderPresent(SDL_Renderer * renderer) +{ + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; + if(!data->displayListAvail) + return; + + data->displayListAvail = SDL_FALSE; + sceGuFinish(); + sceGuSync(0,0); + +// if(data->vsync) + sceDisplayWaitVblankStart(); + + data->backbuffer = data->frontbuffer; + data->frontbuffer = vabsptr(sceGuSwapBuffers()); + +} + +static void +PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + + if (renderdata == 0) + return; + + if(psp_texture == 0) + return; + + if(psp_texture->data != 0) + { + free(psp_texture->data); + } + free(texture); + texture->driverdata = NULL; +} + +static void +PSP_DestroyRenderer(SDL_Renderer * renderer) +{ + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; + if (data) { + if (!data->initialized) + return; + + StartDrawing(renderer); + + sceGuTerm(); +// vfree(data->backbuffer); +// vfree(data->frontbuffer); + + data->initialized = SDL_FALSE; + data->displayListAvail = SDL_FALSE; + SDL_free(data); + } + SDL_free(renderer); +} + +#endif /* SDL_VIDEO_RENDER_PSP */ + +/* vi: set ts=4 sw=4 expandtab: */ + diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h index 4791c5a20..f1c1c1ddf 100644 --- a/src/thread/SDL_thread_c.h +++ b/src/thread/SDL_thread_c.h @@ -36,6 +36,8 @@ #include "windows/SDL_systhread_c.h" #elif SDL_THREAD_NDS #include "nds/SDL_systhread_c.h" +#elif SDL_THREAD_PSP +#include "psp/SDL_systhread_c.h" #else #error Need thread implementation for this platform #include "generic/SDL_systhread_c.h" diff --git a/src/thread/psp/SDL_syscond.c b/src/thread/psp/SDL_syscond.c new file mode 100644 index 000000000..ca281521e --- /dev/null +++ b/src/thread/psp/SDL_syscond.c @@ -0,0 +1,223 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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" + +/* An implementation of condition variables using semaphores and mutexes */ +/* + This implementation borrows heavily from the BeOS condition variable + implementation, written by Christopher Tate and Owen Smith. Thanks! + */ + +#include "SDL_thread.h" + +struct SDL_cond +{ + SDL_mutex *lock; + int waiting; + int signals; + SDL_sem *wait_sem; + SDL_sem *wait_done; +}; + +/* Create a condition variable */ +SDL_cond * +SDL_CreateCond(void) +{ + SDL_cond *cond; + + cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); + if (cond) { + cond->lock = SDL_CreateMutex(); + cond->wait_sem = SDL_CreateSemaphore(0); + cond->wait_done = SDL_CreateSemaphore(0); + cond->waiting = cond->signals = 0; + if (!cond->lock || !cond->wait_sem || !cond->wait_done) { + SDL_DestroyCond(cond); + cond = NULL; + } + } else { + SDL_OutOfMemory(); + } + return (cond); +} + +/* Destroy a condition variable */ +void +SDL_DestroyCond(SDL_cond * cond) +{ + if (cond) { + if (cond->wait_sem) { + SDL_DestroySemaphore(cond->wait_sem); + } + if (cond->wait_done) { + SDL_DestroySemaphore(cond->wait_done); + } + if (cond->lock) { + SDL_DestroyMutex(cond->lock); + } + SDL_free(cond); + } +} + +/* Restart one of the threads that are waiting on the condition variable */ +int +SDL_CondSignal(SDL_cond * cond) +{ + if (!cond) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex(cond->lock); + if (cond->waiting > cond->signals) { + ++cond->signals; + SDL_SemPost(cond->wait_sem); + SDL_UnlockMutex(cond->lock); + SDL_SemWait(cond->wait_done); + } else { + SDL_UnlockMutex(cond->lock); + } + + return 0; +} + +/* Restart all threads that are waiting on the condition variable */ +int +SDL_CondBroadcast(SDL_cond * cond) +{ + if (!cond) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex(cond->lock); + if (cond->waiting > cond->signals) { + int i, num_waiting; + + num_waiting = (cond->waiting - cond->signals); + cond->signals = cond->waiting; + for (i = 0; i < num_waiting; ++i) { + SDL_SemPost(cond->wait_sem); + } + /* Now all released threads are blocked here, waiting for us. + Collect them all (and win fabulous prizes!) :-) + */ + SDL_UnlockMutex(cond->lock); + for (i = 0; i < num_waiting; ++i) { + SDL_SemWait(cond->wait_done); + } + } else { + SDL_UnlockMutex(cond->lock); + } + + return 0; +} + +/* Wait on the condition variable for at most 'ms' milliseconds. + The mutex must be locked before entering this function! + The mutex is unlocked during the wait, and locked again after the wait. + +Typical use: + +Thread A: + SDL_LockMutex(lock); + while ( ! condition ) { + SDL_CondWait(cond, lock); + } + SDL_UnlockMutex(lock); + +Thread B: + SDL_LockMutex(lock); + ... + condition = true; + ... + SDL_CondSignal(cond); + SDL_UnlockMutex(lock); + */ +int +SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) +{ + int retval; + + if (!cond) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* Obtain the protection mutex, and increment the number of waiters. + This allows the signal mechanism to only perform a signal if there + are waiting threads. + */ + SDL_LockMutex(cond->lock); + ++cond->waiting; + SDL_UnlockMutex(cond->lock); + + /* Unlock the mutex, as is required by condition variable semantics */ + SDL_UnlockMutex(mutex); + + /* Wait for a signal */ + if (ms == SDL_MUTEX_MAXWAIT) { + retval = SDL_SemWait(cond->wait_sem); + } else { + retval = SDL_SemWaitTimeout(cond->wait_sem, ms); + } + + /* Let the signaler know we have completed the wait, otherwise + the signaler can race ahead and get the condition semaphore + if we are stopped between the mutex unlock and semaphore wait, + giving a deadlock. See the following URL for details: + http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html + */ + SDL_LockMutex(cond->lock); + if (cond->signals > 0) { + /* If we timed out, we need to eat a condition signal */ + if (retval > 0) { + SDL_SemWait(cond->wait_sem); + } + /* We always notify the signal thread that we are done */ + SDL_SemPost(cond->wait_done); + + /* Signal handshake complete */ + --cond->signals; + } + --cond->waiting; + SDL_UnlockMutex(cond->lock); + + /* Lock the mutex, as is required by condition variable semantics */ + SDL_LockMutex(mutex); + + return retval; +} + +/* Wait on the condition variable forever */ +int +SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) +{ + return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/psp/SDL_sysmutex.c b/src/thread/psp/SDL_sysmutex.c new file mode 100644 index 000000000..a68f238c7 --- /dev/null +++ b/src/thread/psp/SDL_sysmutex.c @@ -0,0 +1,135 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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" + +/* An implementation of mutexes using semaphores */ + +#include "SDL_thread.h" +#include "SDL_systhread_c.h" + + +struct SDL_mutex +{ + int recursive; + SDL_threadID owner; + SDL_sem *sem; +}; + +/* Create a mutex */ +SDL_mutex * +SDL_CreateMutex(void) +{ + SDL_mutex *mutex; + + /* Allocate mutex memory */ + mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex)); + if (mutex) { + /* Create the mutex semaphore, with initial value 1 */ + mutex->sem = SDL_CreateSemaphore(1); + mutex->recursive = 0; + mutex->owner = 0; + if (!mutex->sem) { + SDL_free(mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory(); + } + return mutex; +} + +/* Free the mutex */ +void +SDL_DestroyMutex(SDL_mutex * mutex) +{ + if (mutex) { + if (mutex->sem) { + SDL_DestroySemaphore(mutex->sem); + } + SDL_free(mutex); + } +} + +/* Lock the semaphore */ +int +SDL_mutexP(SDL_mutex * mutex) +{ +#if SDL_THREADS_DISABLED + return 0; +#else + SDL_threadID this_thread; + + if (mutex == NULL) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + this_thread = SDL_ThreadID(); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + SDL_SemWait(mutex->sem); + mutex->owner = this_thread; + mutex->recursive = 0; + } + + return 0; +#endif /* SDL_THREADS_DISABLED */ +} + +/* Unlock the mutex */ +int +SDL_mutexV(SDL_mutex * mutex) +{ +#if SDL_THREADS_DISABLED + return 0; +#else + if (mutex == NULL) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + /* If we don't own the mutex, we can't unlock it */ + if (SDL_ThreadID() != mutex->owner) { + SDL_SetError("mutex not owned by this thread"); + return -1; + } + + if (mutex->recursive) { + --mutex->recursive; + } else { + /* The order of operations is important. + First reset the owner so another thread doesn't lock + the mutex and set the ownership before we reset it, + then release the lock semaphore. + */ + mutex->owner = 0; + SDL_SemPost(mutex->sem); + } + return 0; +#endif /* SDL_THREADS_DISABLED */ +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/psp/SDL_sysmutex_c.h b/src/thread/psp/SDL_sysmutex_c.h new file mode 100644 index 000000000..8d6dbdc2b --- /dev/null +++ b/src/thread/psp/SDL_sysmutex_c.h @@ -0,0 +1,22 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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" +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/psp/SDL_syssem.c b/src/thread/psp/SDL_syssem.c new file mode 100644 index 000000000..56638ca42 --- /dev/null +++ b/src/thread/psp/SDL_syssem.c @@ -0,0 +1,159 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + +/* Semaphore functions for the PSP. */ + +#include +#include + +#include "SDL_error.h" +#include "SDL_thread.h" + +#include +#include + +struct SDL_semaphore { + SceUID semid; +}; + + +/* Create a semaphore */ +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +{ + SDL_sem *sem; + + sem = (SDL_sem *) malloc(sizeof(*sem)); + if (sem != NULL) { + /* TODO: Figure out the limit on the maximum value. */ + sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL); + if (sem->semid < 0) { + SDL_SetError("Couldn't create semaphore"); + free(sem); + sem = NULL; + } + } else { + SDL_OutOfMemory(); + } + + return sem; +} + +/* Free the semaphore */ +void SDL_DestroySemaphore(SDL_sem *sem) +{ + if (sem != NULL) { + if (sem->semid > 0) { + sceKernelDeleteSema(sem->semid); + sem->semid = 0; + } + + free(sem); + } +} + +/* TODO: This routine is a bit overloaded. + * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass + * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout + * is specified, convert it to microseconds. */ +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +{ + Uint32 *pTimeout; + unsigned int res; + + if (sem == NULL) { + SDL_SetError("Passed a NULL sem"); + return 0; + } + + if (timeout == 0) { + res = sceKernelPollSema(sem->semid, 1); + if (res < 0) { + return SDL_MUTEX_TIMEDOUT; + } + return 0; + } + + if (timeout == SDL_MUTEX_MAXWAIT) { + pTimeout = NULL; + } else { + timeout *= 1000; /* Convert to microseconds. */ + pTimeout = &timeout; + } + + res = sceKernelWaitSema(sem->semid, 1, pTimeout); + switch (res) { + case SCE_KERNEL_ERROR_OK: + return 0; + case SCE_KERNEL_ERROR_WAIT_TIMEOUT: + return SDL_MUTEX_TIMEDOUT; + default: + SDL_SetError("WaitForSingleObject() failed"); + return -1; + } +} + +int SDL_SemTryWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, 0); +} + +int SDL_SemWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); +} + +/* Returns the current count of the semaphore */ +Uint32 SDL_SemValue(SDL_sem *sem) +{ + SceKernelSemaInfo info; + + if (sem == NULL) { + SDL_SetError("Passed a NULL sem"); + return 0; + } + + if (sceKernelReferSemaStatus(sem->semid, &info) >= 0) { + return info.currentCount; + } + + return 0; +} + +int SDL_SemPost(SDL_sem *sem) +{ + int res; + + if (sem == NULL) { + SDL_SetError("Passed a NULL sem"); + return -1; + } + + res = sceKernelSignalSema(sem->semid, 1); + if (res < 0) { + SDL_SetError("sceKernelSignalSema() failed"); + return -1; + } + + return 0; +} + +/* vim: ts=4 sw=4 + */ diff --git a/src/thread/psp/SDL_systhread.c b/src/thread/psp/SDL_systhread.c new file mode 100644 index 000000000..c786272b0 --- /dev/null +++ b/src/thread/psp/SDL_systhread.c @@ -0,0 +1,103 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + + +/* PSP thread management routines for SDL */ + +#include +#include + +#include "SDL_error.h" +#include "SDL_thread.h" +#include "../SDL_systhread.h" +#include "../SDL_thread_c.h" +#include +#include + + +static int ThreadEntry(SceSize args, void *argp) +{ + SDL_RunThread(*(void **) argp); + return 0; +} + +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +{ + SceKernelThreadInfo status; + int priority = 32; + + /* Set priority of new thread to the same as the current thread */ + status.size = sizeof(SceKernelThreadInfo); + if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) { + priority = status.currentPriority; + } + + thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry, + priority, 0x8000, + PSP_THREAD_ATTR_VFPU, NULL); + if (thread->handle < 0) { + SDL_SetError("sceKernelCreateThread() failed"); + return -1; + } + + sceKernelStartThread(thread->handle, 4, &args); + return 0; +} + +void SDL_SYS_SetupThread(const char *name) +{ + /* Do nothing. */ +} + +SDL_threadID SDL_ThreadID(void) +{ + return (SDL_threadID) sceKernelGetThreadId(); +} + +void SDL_SYS_WaitThread(SDL_Thread *thread) +{ + sceKernelWaitThreadEnd(thread->handle, NULL); + sceKernelDeleteThread(thread->handle); +} + +void SDL_SYS_KillThread(SDL_Thread *thread) +{ + sceKernelTerminateDeleteThread(thread->handle); +} + +int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +{ + int value; + + if (priority == SDL_THREAD_PRIORITY_LOW) { + value = 19; + } else if (priority == SDL_THREAD_PRIORITY_HIGH) { + value = -20; + } else { + value = 0; + } + + return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value); + +} + +/* vim: ts=4 sw=4 + */ diff --git a/src/thread/psp/SDL_systhread_c.h b/src/thread/psp/SDL_systhread_c.h new file mode 100644 index 000000000..a806edec9 --- /dev/null +++ b/src/thread/psp/SDL_systhread_c.h @@ -0,0 +1,24 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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 + +typedef SceUID SYS_ThreadHandle; diff --git a/src/timer/psp/SDL_systimer.c b/src/timer/psp/SDL_systimer.c new file mode 100644 index 000000000..cfb0aeb25 --- /dev/null +++ b/src/timer/psp/SDL_systimer.c @@ -0,0 +1,69 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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_thread.h" +#include "SDL_timer.h" +#include "SDL_error.h" +#include "../SDL_timer_c.h" +#include +#include +#include +#include + +static struct timeval start; + +void SDL_StartTicks(void) +{ + gettimeofday(&start, NULL); +} + +Uint32 SDL_GetTicks(void) +{ + struct timeval now; + Uint32 ticks; + + gettimeofday(&now, NULL); + ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; + return(ticks); +} + +Uint64 +SDL_GetPerformanceCounter(void) +{ + return SDL_GetTicks(); +} + +Uint64 +SDL_GetPerformanceFrequency(void) +{ + return 1000; +} + +void SDL_Delay(Uint32 ms) +{ + const Uint32 max_delay = 0xffffffffUL / 1000; + if(ms > max_delay) + ms = max_delay; + sceKernelDelayThreadCB(ms * 1000); +} + +/* vim: ts=4 sw=4 + */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 21540c66a..20c90e9c8 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -350,6 +350,9 @@ extern VideoBootStrap UIKIT_bootstrap; #if SDL_VIDEO_DRIVER_ANDROID extern VideoBootStrap Android_bootstrap; #endif +#if SDL_VIDEO_DRIVER_PSP +extern VideoBootStrap PSP_bootstrap; +#endif #if SDL_VIDEO_DRIVER_DUMMY extern VideoBootStrap DUMMY_bootstrap; #endif diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 0d48778f4..4ca466384 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -78,6 +78,9 @@ static VideoBootStrap *bootstrap[] = { #if SDL_VIDEO_DRIVER_ANDROID &Android_bootstrap, #endif +#if SDL_VIDEO_DRIVER_PSP + &PSP_bootstrap, +#endif #if SDL_VIDEO_DRIVER_DUMMY &DUMMY_bootstrap, #endif diff --git a/src/video/psp/SDL_pspevents.c b/src/video/psp/SDL_pspevents.c new file mode 100644 index 000000000..e418daae2 --- /dev/null +++ b/src/video/psp/SDL_pspevents.c @@ -0,0 +1,284 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + +/* Being a null driver, there's no event stream. We just define stubs for + most of the API. */ + +#include "SDL.h" +#include "../../events/SDL_sysevents.h" +#include "../../events/SDL_events_c.h" +#include "../../events/SDL_keyboard_c.h" +#include "SDL_pspvideo.h" +#include "SDL_pspevents_c.h" +#include "SDL_thread.h" +#include "SDL_keyboard.h" +#include + +#ifdef PSPIRKEYB +#include +#include + +#define IRKBD_CONFIG_FILE NULL /* this will take ms0:/seplugins/pspirkeyb.ini */ + +static int irkbd_ready = 0; +static SDLKey keymap[256]; +#endif + +static enum PspHprmKeys hprm = 0; +static SDL_sem *event_sem = NULL; +static SDL_Thread *thread = NULL; +static int running = 0; +static struct { + enum PspHprmKeys id; + SDL_Keycode sym; +} keymap_psp[] = { + { PSP_HPRM_PLAYPAUSE, SDLK_F10 }, + { PSP_HPRM_FORWARD, SDLK_F11 }, + { PSP_HPRM_BACK, SDLK_F12 }, + { PSP_HPRM_VOL_UP, SDLK_F13 }, + { PSP_HPRM_VOL_DOWN, SDLK_F14 }, + { PSP_HPRM_HOLD, SDLK_F15 } +}; + +int EventUpdate(void *data) +{ + while (running) { + SDL_SemWait(event_sem); + sceHprmPeekCurrentKey(&hprm); + SDL_SemPost(event_sem); + /* Delay 1/60th of a second */ + sceKernelDelayThread(1000000 / 60); + } + return 0; +} + +void PSP_PumpEvents(_THIS) +{ + int i; + enum PspHprmKeys keys; + enum PspHprmKeys changed; + static enum PspHprmKeys old_keys = 0; + SDL_Keysym sym; + + SDL_SemWait(event_sem); + keys = hprm; + SDL_SemPost(event_sem); + + /* HPRM Keyboard */ + changed = old_keys ^ keys; + old_keys = keys; + if(changed) { + for(i=0; i= 0) { + if((length % sizeof(SIrKeybScanCodeData)) == 0){ + count = length / sizeof(SIrKeybScanCodeData); + for( i=0; i < count; i++ ) { + unsigned char raw, pressed; + scanData=(SIrKeybScanCodeData*) buffer+i; + raw = scanData->raw; + pressed = scanData->pressed; + sym.scancode = raw; + sym.sym = keymap[raw]; + /* not tested*/ + //SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); + SDL_SendKeyboardKey((keys & keymap_psp[i].id) ? + SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]); + + } + } + } + } +#endif + sceKernelDelayThread(0); + + return; +} + +void PSP_InitOSKeymap(_THIS) +{ +#ifdef PSPIRKEYB + int i; + for (i=0; i + + 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_pspvideo.h" + +/* Variables and functions exported by SDL_sysevents.c to other parts + of the native video subsystem (SDL_sysvideo.c) +*/ +extern void PSP_InitOSKeymap(_THIS); +extern void PSP_PumpEvents(_THIS); + +/* end of SDL_pspevents_c.h ... */ + diff --git a/src/video/psp/SDL_pspgl.c b/src/video/psp/SDL_pspgl.c new file mode 100644 index 000000000..7a60b728d --- /dev/null +++ b/src/video/psp/SDL_pspgl.c @@ -0,0 +1,207 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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 +#include + +#include "SDL_error.h" +#include "SDL_pspvideo.h" +#include "SDL_pspgl_c.h" + +/*****************************************************************************/ +/* SDL OpenGL/OpenGL ES functions */ +/*****************************************************************************/ +#define EGLCHK(stmt) \ + do { \ + EGLint err; \ + \ + stmt; \ + err = eglGetError(); \ + if (err != EGL_SUCCESS) { \ + SDL_SetError("EGL error %d", err); \ + return 0; \ + } \ + } while (0) + +int +PSP_GL_LoadLibrary(_THIS, const char *path) +{ + if (!_this->gl_config.driver_loaded) { + _this->gl_config.driver_loaded = 1; + } + + return 0; +} + +/* pspgl doesn't provide this call, so stub it out since SDL requires it. +#define GLSTUB(func,params) void func params {} + +GLSTUB(glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, + GLdouble zNear, GLdouble zFar)) +*/ +void * +PSP_GL_GetProcAddress(_THIS, const char *proc) +{ + return eglGetProcAddress(proc); +} + +void +PSP_GL_UnloadLibrary(_THIS) +{ + eglTerminate(_this->gl_data->display); +} + +static EGLint width = 480; +static EGLint height = 272; + +SDL_GLContext +PSP_GL_CreateContext(_THIS, SDL_Window * window) +{ + + SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; + + EGLint attribs[32]; + EGLDisplay display; + EGLContext context; + EGLSurface surface; + EGLConfig config; + EGLint num_configs; + int i; + + + /* EGL init taken from glutCreateWindow() in PSPGL's glut.c. */ + EGLCHK(display = eglGetDisplay(0)); + EGLCHK(eglInitialize(display, NULL, NULL)); + wdata->uses_gles = SDL_TRUE; + window->flags |= SDL_WINDOW_FULLSCREEN; + + /* Setup the config based on SDL's current values. */ + i = 0; + attribs[i++] = EGL_RED_SIZE; + attribs[i++] = _this->gl_config.red_size; + attribs[i++] = EGL_GREEN_SIZE; + attribs[i++] = _this->gl_config.green_size; + attribs[i++] = EGL_BLUE_SIZE; + attribs[i++] = _this->gl_config.blue_size; + attribs[i++] = EGL_DEPTH_SIZE; + attribs[i++] = _this->gl_config.depth_size; + + if (_this->gl_config.alpha_size) + { + attribs[i++] = EGL_ALPHA_SIZE; + attribs[i++] = _this->gl_config.alpha_size; + } + if (_this->gl_config.stencil_size) + { + attribs[i++] = EGL_STENCIL_SIZE; + attribs[i++] = _this->gl_config.stencil_size; + } + + attribs[i++] = EGL_NONE; + + EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs)); + + if (num_configs == 0) + { + SDL_SetError("No valid EGL configs for requested mode"); + return 0; + } + + EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width)); + EGLCHK(eglGetConfigAttrib(display, config, EGL_HEIGHT, &height)); + + EGLCHK(context = eglCreateContext(display, config, NULL, NULL)); + EGLCHK(surface = eglCreateWindowSurface(display, config, 0, NULL)); + EGLCHK(eglMakeCurrent(display, surface, surface, context)); + + _this->gl_data->display = display; + _this->gl_data->context = context; + _this->gl_data->surface = surface; + + + return context; +} + +int +PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) +{ + if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface, + _this->gl_data->surface, _this->gl_data->context)) + { + SDL_SetError("Unable to make EGL context current"); + return -1; + } + return 0; +} + +int +PSP_GL_SetSwapInterval(_THIS, int interval) +{ + EGLBoolean status; + status = eglSwapInterval(_this->gl_data->display, interval); + if (status == EGL_TRUE) { + /* Return success to upper level */ + _this->gl_data->swapinterval = interval; + return 0; + } + /* Failed to set swap interval */ + SDL_SetError("Unable to set the EGL swap interval"); + return -1; +} + +int +PSP_GL_GetSwapInterval(_THIS) +{ + return _this->gl_data->swapinterval; +} + +void +PSP_GL_SwapWindow(_THIS, SDL_Window * window) +{ + eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface); +} + +void +PSP_GL_DeleteContext(_THIS, SDL_GLContext context) +{ + SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; + EGLBoolean status; + + if (phdata->egl_initialized != SDL_TRUE) { + SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support"); + return; + } + + /* Check if OpenGL ES connection has been initialized */ + if (_this->gl_data->display != EGL_NO_DISPLAY) { + if (context != EGL_NO_CONTEXT) { + status = eglDestroyContext(_this->gl_data->display, context); + if (status != EGL_TRUE) { + /* Error during OpenGL ES context destroying */ + SDL_SetError("PSP: OpenGL ES context destroy error"); + return; + } + } + } + + return; +} + diff --git a/src/video/psp/SDL_pspgl_c.h b/src/video/psp/SDL_pspgl_c.h new file mode 100644 index 000000000..73235ef68 --- /dev/null +++ b/src/video/psp/SDL_pspgl_c.h @@ -0,0 +1,52 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + +#ifndef _SDL_pspgl_c_h +#define _SDL_pspgl_c_h + + +#include +#include + +#include "SDL_pspvideo.h" + + +typedef struct SDL_GLDriverData { + EGLDisplay display; + EGLContext context; + EGLSurface surface; + uint32_t swapinterval; +}SDL_GLDriverData; + +extern void * PSP_GL_GetProcAddress(_THIS, const char *proc); +extern int PSP_GL_MakeCurrent(_THIS,SDL_Window * window, SDL_GLContext context); +extern void PSP_GL_SwapBuffers(_THIS); + +extern void PSP_GL_SwapWindow(_THIS, SDL_Window * window); +extern SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window * window); + +extern int PSP_GL_LoadLibrary(_THIS, const char *path); +extern void PSP_GL_UnloadLibrary(_THIS); +extern int PSP_GL_SetSwapInterval(_THIS, int interval); +extern int PSP_GL_GetSwapInterval(_THIS); + + +#endif /* _SDL_pspgl_c_h */ diff --git a/src/video/psp/SDL_pspmouse.c b/src/video/psp/SDL_pspmouse.c new file mode 100644 index 000000000..8f0ffdc7d --- /dev/null +++ b/src/video/psp/SDL_pspmouse.c @@ -0,0 +1,35 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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 + +#include "SDL_error.h" +#include "SDL_mouse.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_pspmouse_c.h" + + +/* The implementation dependent data for the window manager cursor */ +struct WMcursor { + int unused; +}; diff --git a/src/video/psp/SDL_pspmouse_c.h b/src/video/psp/SDL_pspmouse_c.h new file mode 100644 index 000000000..a0836a30a --- /dev/null +++ b/src/video/psp/SDL_pspmouse_c.h @@ -0,0 +1,24 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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_pspvideo.h" + +/* Functions to be exported */ diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c new file mode 100644 index 000000000..67aed9d86 --- /dev/null +++ b/src/video/psp/SDL_pspvideo.c @@ -0,0 +1,334 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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" + +#if SDL_VIDEO_DRIVER_PSP + +/* SDL internals */ +#include "../SDL_sysvideo.h" +#include "SDL_version.h" +#include "SDL_syswm.h" +#include "SDL_loadso.h" +#include "SDL_events.h" +#include "../../events/SDL_mouse_c.h" +#include "../../events/SDL_keyboard_c.h" + + + +/* PSP declarations */ +#include "SDL_pspvideo.h" +#include "SDL_pspevents_c.h" +#include "SDL_pspgl_c.h" + +/* unused +static SDL_bool PSP_initialized = SDL_FALSE; +*/ +static int +PSP_Available(void) +{ + return 1; +} + +static void +PSP_Destroy(SDL_VideoDevice * device) +{ +// SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata; + + if (device->driverdata != NULL) { + device->driverdata = NULL; + } +} + +static SDL_VideoDevice * +PSP_Create() +{ + SDL_VideoDevice *device; + SDL_VideoData *phdata; + SDL_GLDriverData *gldata; + int status; + + /* Check if pandora could be initialized */ + status = PSP_Available(); + if (status == 0) { + /* PSP could not be used */ + return NULL; + } + + /* Initialize SDL_VideoDevice structure */ + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); + if (device == NULL) { + SDL_OutOfMemory(); + return NULL; + } + + /* Initialize internal Pandora specific data */ + phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); + if (phdata == NULL) { + SDL_OutOfMemory(); + SDL_free(device); + return NULL; + } + + gldata = (SDL_GLDriverData *) SDL_calloc(1, sizeof(SDL_GLDriverData)); + if (gldata == NULL) { + SDL_OutOfMemory(); + SDL_free(device); + return NULL; + } + device->gl_data = gldata; + + device->driverdata = phdata; + + phdata->egl_initialized = SDL_TRUE; + + + /* Setup amount of available displays and current display */ + device->num_displays = 0; + + /* Set device free function */ + device->free = PSP_Destroy; + + /* Setup all functions which we can handle */ + device->VideoInit = PSP_VideoInit; + device->VideoQuit = PSP_VideoQuit; + device->GetDisplayModes = PSP_GetDisplayModes; + device->SetDisplayMode = PSP_SetDisplayMode; + device->CreateWindow = PSP_CreateWindow; + device->CreateWindowFrom = PSP_CreateWindowFrom; + device->SetWindowTitle = PSP_SetWindowTitle; + device->SetWindowIcon = PSP_SetWindowIcon; + device->SetWindowPosition = PSP_SetWindowPosition; + device->SetWindowSize = PSP_SetWindowSize; + device->ShowWindow = PSP_ShowWindow; + device->HideWindow = PSP_HideWindow; + device->RaiseWindow = PSP_RaiseWindow; + device->MaximizeWindow = PSP_MaximizeWindow; + device->MinimizeWindow = PSP_MinimizeWindow; + device->RestoreWindow = PSP_RestoreWindow; + device->SetWindowGrab = PSP_SetWindowGrab; + device->DestroyWindow = PSP_DestroyWindow; + device->GetWindowWMInfo = PSP_GetWindowWMInfo; + device->GL_LoadLibrary = PSP_GL_LoadLibrary; + device->GL_GetProcAddress = PSP_GL_GetProcAddress; + device->GL_UnloadLibrary = PSP_GL_UnloadLibrary; + device->GL_CreateContext = PSP_GL_CreateContext; + device->GL_MakeCurrent = PSP_GL_MakeCurrent; + device->GL_SetSwapInterval = PSP_GL_SetSwapInterval; + device->GL_GetSwapInterval = PSP_GL_GetSwapInterval; + device->GL_SwapWindow = PSP_GL_SwapWindow; + device->GL_DeleteContext = PSP_GL_DeleteContext; + device->SDL_HasScreenKeyboardSupport = PSP_SDL_HasScreenKeyboardSupport; + device->SDL_ShowScreenKeyboard = PSP_SDL_ShowScreenKeyboard; + device->SDL_HideScreenKeyboard = PSP_SDL_HideScreenKeyboard; + device->SDL_IsScreenKeyboardShown = PSP_SDL_IsScreenKeyboardShown; + + device->PumpEvents = PSP_PumpEvents; + + return device; +} + +VideoBootStrap PSP_bootstrap = { + "PSP", + "PSP Video Driver", + PSP_Available, + PSP_Create +}; + +/*****************************************************************************/ +/* SDL Video and Display initialization/handling functions */ +/*****************************************************************************/ +int +PSP_VideoInit(_THIS) +{ + SDL_VideoDisplay display; + SDL_DisplayMode current_mode; + + SDL_zero(current_mode); + + current_mode.w = 480; + current_mode.h = 272; + + current_mode.refresh_rate = 60; + // 32 bpp for default + // current_mode.format = SDL_PIXELFORMAT_RGBA8888; + current_mode.format = SDL_PIXELFORMAT_ABGR8888; + + current_mode.driverdata = NULL; + + SDL_zero(display); + display.desktop_mode = current_mode; + display.current_mode = current_mode; + display.driverdata = NULL; + + SDL_AddVideoDisplay(&display); + + return 1; +} + +void +PSP_VideoQuit(_THIS) +{ + +} + +void +PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display) +{ + +} + +int +PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) +{ + return 0; +} +#define EGLCHK(stmt) \ + do { \ + EGLint err; \ + \ + stmt; \ + err = eglGetError(); \ + if (err != EGL_SUCCESS) { \ + SDL_SetError("EGL error %d", err); \ + return 0; \ + } \ + } while (0) + +int +PSP_CreateWindow(_THIS, SDL_Window * window) +{ +// SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; + + SDL_WindowData *wdata; + + /* Allocate window internal data */ + wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); + if (wdata == NULL) { + SDL_OutOfMemory(); + return -1; + } + + /* Setup driver data for this window */ + window->driverdata = wdata; + + + /* Window has been successfully created */ + return 0; +} + +int +PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) +{ + return -1; +} + +void +PSP_SetWindowTitle(_THIS, SDL_Window * window) +{ +} +void +PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) +{ +} +void +PSP_SetWindowPosition(_THIS, SDL_Window * window) +{ +} +void +PSP_SetWindowSize(_THIS, SDL_Window * window) +{ +} +void +PSP_ShowWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_HideWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_RaiseWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_MaximizeWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_MinimizeWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_RestoreWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) +{ + +} +void +PSP_DestroyWindow(_THIS, SDL_Window * window) +{ + +// eglTerminate(_this->gl_data->display); +} + +/*****************************************************************************/ +/* SDL Window Manager function */ +/*****************************************************************************/ +SDL_bool +PSP_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info) +{ + if (info->version.major <= SDL_MAJOR_VERSION) { + return SDL_TRUE; + } else { + SDL_SetError("application not compiled with SDL %d.%d\n", + SDL_MAJOR_VERSION, SDL_MINOR_VERSION); + return SDL_FALSE; + } + + /* Failed to get window manager information */ + return SDL_FALSE; +} + + +/* TO Write Me*/ +SDL_bool PSP_SDL_HasScreenKeyboardSupport(_THIS) +{ + return SDL_TRUE; +} +void PSP_SDL_ShowScreenKeyboard(_THIS, SDL_Window *window) +{ +} +void PSP_SDL_HideScreenKeyboard(_THIS, SDL_Window *window) +{ +} +SDL_bool PSP_SDL_IsScreenKeyboardShown(_THIS, SDL_Window *window) +{ + return SDL_FALSE; +} + + +#endif /* SDL_VIDEO_DRIVER_PSP */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/psp/SDL_pspvideo.h b/src/video/psp/SDL_pspvideo.h new file mode 100644 index 000000000..7209cb156 --- /dev/null +++ b/src/video/psp/SDL_pspvideo.h @@ -0,0 +1,102 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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. +*/ + +#ifndef __SDL_PANDORA_H__ +#define __SDL_PANDORA_H__ + +#include + +#include "SDL_config.h" +#include "../SDL_sysvideo.h" + +typedef struct SDL_VideoData +{ + SDL_bool egl_initialized; /* OpenGL ES device initialization status */ + uint32_t egl_refcount; /* OpenGL ES reference count */ + + + +} SDL_VideoData; + + +typedef struct SDL_DisplayData +{ + +} SDL_DisplayData; + + +typedef struct SDL_WindowData +{ + SDL_bool uses_gles; /* if true window must support OpenGL ES */ + +} SDL_WindowData; + + + + +/****************************************************************************/ +/* SDL_VideoDevice functions declaration */ +/****************************************************************************/ + +/* Display and window functions */ +int PSP_VideoInit(_THIS); +void PSP_VideoQuit(_THIS); +void PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display); +int PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); +int PSP_CreateWindow(_THIS, SDL_Window * window); +int PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data); +void PSP_SetWindowTitle(_THIS, SDL_Window * window); +void PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon); +void PSP_SetWindowPosition(_THIS, SDL_Window * window); +void PSP_SetWindowSize(_THIS, SDL_Window * window); +void PSP_ShowWindow(_THIS, SDL_Window * window); +void PSP_HideWindow(_THIS, SDL_Window * window); +void PSP_RaiseWindow(_THIS, SDL_Window * window); +void PSP_MaximizeWindow(_THIS, SDL_Window * window); +void PSP_MinimizeWindow(_THIS, SDL_Window * window); +void PSP_RestoreWindow(_THIS, SDL_Window * window); +void PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed); +void PSP_DestroyWindow(_THIS, SDL_Window * window); + +/* Window manager function */ +SDL_bool PSP_GetWindowWMInfo(_THIS, SDL_Window * window, + struct SDL_SysWMinfo *info); + +/* OpenGL/OpenGL ES functions */ +int PSP_GL_LoadLibrary(_THIS, const char *path); +void *PSP_GL_GetProcAddress(_THIS, const char *proc); +void PSP_GL_UnloadLibrary(_THIS); +SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window * window); +int PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); +int PSP_GL_SetSwapInterval(_THIS, int interval); +int PSP_GL_GetSwapInterval(_THIS); +void PSP_GL_SwapWindow(_THIS, SDL_Window * window); +void PSP_GL_DeleteContext(_THIS, SDL_GLContext context); + +/*PSP on screen keyboard */ +SDL_bool PSP_SDL_HasScreenKeyboardSupport(_THIS); +void PSP_SDL_ShowScreenKeyboard(_THIS, SDL_Window *window); +void PSP_SDL_HideScreenKeyboard(_THIS, SDL_Window *window); +SDL_bool PSP_SDL_IsScreenKeyboardShown(_THIS, SDL_Window *window); + +#endif /* __SDL_PANDORA_H__ */ + +/* vi: set ts=4 sw=4 expandtab: */ From 72befa7332c06dffbda4bca6425523bf59be41f6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 17 Mar 2013 09:21:08 -0700 Subject: [PATCH 098/151] We have a new platform, yay! --- README.Platforms | 1 + 1 file changed, 1 insertion(+) diff --git a/README.Platforms b/README.Platforms index 5009d7152..80a6c3f44 100644 --- a/README.Platforms +++ b/README.Platforms @@ -25,6 +25,7 @@ Solaris Platforms supported by volunteers ================================= Pandora - maintained by Scott Smith +PSP - maintained by 527721088@qq.com Platforms that need maintainers =============================== From 3afbe992d57cfedb35cc823c6478c8615ed6d106 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 17 Mar 2013 09:44:58 -0700 Subject: [PATCH 099/151] Removed Nintendo DS support since nobody has volunteered to maintain it for over a year. --- CREDITS | 3 - Makefile.ds | 231 ---------- README.Platforms | 1 - README.ds | 64 --- .../project.pbxproj | 2 - include/SDL_config.h | 2 - include/SDL_config.h.cmake | 6 - include/SDL_config.h.in | 6 - include/SDL_config_nintendods.h | 129 ------ include/SDL_platform.h | 6 - include/SDL_stdinc.h | 6 +- include/SDL_test_common.h | 5 +- src/SDL.c | 2 - src/audio/SDL_audio.c | 3 - src/audio/nds/SDL_ndsaudio.c | 129 ------ src/audio/nds/SDL_ndsaudio.h | 42 -- src/events/nds/SDL_ndsgesture.c | 41 -- src/file/SDL_rwops.c | 12 - src/haptic/nds/SDL_syshaptic.c | 330 -------------- src/joystick/nds/SDL_sysjoystick.c | 209 --------- src/power/SDL_power.c | 4 - src/power/nds/SDL_syspower.c | 44 -- src/render/SDL_render.c | 3 - src/render/SDL_sysrender.h | 3 - src/render/nds/SDL_libgl2D.c | 315 ------------- src/render/nds/SDL_libgl2D.h | 154 ------- src/render/nds/SDL_ndsrender.c | 418 ------------------ src/test/SDL_test_common.c | 8 - src/thread/SDL_thread_c.h | 2 - src/thread/nds/SDL_syscond.c | 230 ---------- src/thread/nds/SDL_syscond_c.h | 25 -- src/thread/nds/SDL_sysmutex.c | 177 -------- src/thread/nds/SDL_sysmutex_c.h | 25 -- src/thread/nds/SDL_syssem.c | 229 ---------- src/thread/nds/SDL_syssem_c.h | 25 -- src/thread/nds/SDL_systhread.c | 64 --- src/thread/nds/SDL_systhread_c.h | 27 -- src/timer/nds/SDL_systimer.c | 78 ---- src/video/SDL_sysvideo.h | 3 - src/video/SDL_video.c | 3 - src/video/nds/SDL_ndsevents.c | 54 --- src/video/nds/SDL_ndsevents_c.h | 27 -- src/video/nds/SDL_ndsvideo.c | 401 ----------------- src/video/nds/SDL_ndsvideo.h | 59 --- src/video/nds/SDL_ndswindow.c | 37 -- src/video/nds/SDL_ndswindow.h | 30 -- test/nds-test-progs/Makefile | 7 - test/nds-test-progs/general/Makefile | 131 ------ test/nds-test-progs/general/source/main.c | 89 ---- test/nds-test-progs/testscale/Makefile | 147 ------ test/nds-test-progs/testsprite2/Makefile | 152 ------- .../nds-test-progs/testspriteminimal/Makefile | 147 ------ test/testspriteminimal.c | 5 - 53 files changed, 2 insertions(+), 4350 deletions(-) delete mode 100644 Makefile.ds delete mode 100644 README.ds delete mode 100644 include/SDL_config_nintendods.h delete mode 100644 src/audio/nds/SDL_ndsaudio.c delete mode 100644 src/audio/nds/SDL_ndsaudio.h delete mode 100644 src/events/nds/SDL_ndsgesture.c delete mode 100644 src/haptic/nds/SDL_syshaptic.c delete mode 100644 src/joystick/nds/SDL_sysjoystick.c delete mode 100644 src/power/nds/SDL_syspower.c delete mode 100644 src/render/nds/SDL_libgl2D.c delete mode 100644 src/render/nds/SDL_libgl2D.h delete mode 100644 src/render/nds/SDL_ndsrender.c delete mode 100644 src/thread/nds/SDL_syscond.c delete mode 100644 src/thread/nds/SDL_syscond_c.h delete mode 100644 src/thread/nds/SDL_sysmutex.c delete mode 100644 src/thread/nds/SDL_sysmutex_c.h delete mode 100644 src/thread/nds/SDL_syssem.c delete mode 100644 src/thread/nds/SDL_syssem_c.h delete mode 100644 src/thread/nds/SDL_systhread.c delete mode 100644 src/thread/nds/SDL_systhread_c.h delete mode 100644 src/timer/nds/SDL_systimer.c delete mode 100644 src/video/nds/SDL_ndsevents.c delete mode 100644 src/video/nds/SDL_ndsevents_c.h delete mode 100644 src/video/nds/SDL_ndsvideo.c delete mode 100644 src/video/nds/SDL_ndsvideo.h delete mode 100644 src/video/nds/SDL_ndswindow.c delete mode 100644 src/video/nds/SDL_ndswindow.h delete mode 100644 test/nds-test-progs/Makefile delete mode 100755 test/nds-test-progs/general/Makefile delete mode 100644 test/nds-test-progs/general/source/main.c delete mode 100644 test/nds-test-progs/testscale/Makefile delete mode 100644 test/nds-test-progs/testsprite2/Makefile delete mode 100644 test/nds-test-progs/testspriteminimal/Makefile diff --git a/CREDITS b/CREDITS index 29dd032c9..4bf1f96bf 100644 --- a/CREDITS +++ b/CREDITS @@ -19,9 +19,6 @@ Thanks to everyone who made this possible, including: * Holmes Futrell for port of SDL to the iPhone and iPod Touch during the Google Summer of Code 2008 -* Darren Alton for port of SDL to the Nintendo DS during the Google Summer - of Code 2008 - * Szymon "Wilku" Wilczek for adding support for multiple mice and tablets during the Google Summer of Code 2008 diff --git a/Makefile.ds b/Makefile.ds deleted file mode 100644 index 9a79f6f1b..000000000 --- a/Makefile.ds +++ /dev/null @@ -1,231 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := src -SOURCES := src -DATA := data -INCLUDES := include - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork \ - -D__NDS__ -DENABLE_NDS -DNO_SIGNAL_H -DDISABLE_THREADS -DPACKAGE=\"SDL\" \ - -DVERSION=\"2.0\" -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1 - -CFLAGS := -g -Wall -Os\ - -march=armv5te -mtune=arm946e-s \ - -fomit-frame-pointer -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -# Set to 0 to use a framer buffer, or 1 to use the GL like hardware -# renderer. Alas, both cannot be used at the same time for lack of -# display/texture memory. -USE_HW_RENDERER := 1 - -ifeq ($(USE_HW_RENDERER),1) -CFLAGS += -DUSE_HW_RENDERER -else -endif - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := \ - SDL.c \ - SDL_assert.c \ - SDL_error.c \ - SDL_fatal.c \ - SDL_hints.c \ - SDL_log.c \ - atomic/SDL_atomic.c \ - atomic/SDL_spinlock.arm.c \ - audio/SDL_audio.c \ - audio/SDL_audiocvt.c \ - audio/SDL_audiodev.c \ - audio/SDL_audiotypecvt.c \ - audio/SDL_mixer.c \ - audio/SDL_wave.c \ - audio/nds/SDL_ndsaudio.c \ - cpuinfo/SDL_cpuinfo.c \ - events/SDL_events.c \ - events/SDL_keyboard.c \ - events/SDL_mouse.c \ - events/SDL_quit.c \ - events/SDL_touch.c \ - events/SDL_windowevents.c \ - events/nds/SDL_ndsgesture.c \ - file/SDL_rwops.c \ - haptic/SDL_haptic.c \ - haptic/nds/SDL_syshaptic.c \ - joystick/SDL_joystick.c \ - joystick/nds/SDL_sysjoystick.c \ - power/SDL_power.c \ - power/nds/SDL_syspower.c \ - render/SDL_render.c \ - render/SDL_yuv_sw.c \ - render/nds/SDL_ndsrender.c \ - render/nds/SDL_libgl2D.c \ - render/software/SDL_blendfillrect.c \ - render/software/SDL_blendline.c \ - render/software/SDL_blendpoint.c \ - render/software/SDL_drawline.c \ - render/software/SDL_drawpoint.c \ - render/software/SDL_render_sw.c \ - stdlib/SDL_getenv.c \ - stdlib/SDL_iconv.c \ - stdlib/SDL_malloc.c \ - stdlib/SDL_qsort.c \ - stdlib/SDL_stdlib.c \ - stdlib/SDL_string.c \ - thread/SDL_thread.c \ - thread/nds/SDL_syscond.c \ - thread/nds/SDL_sysmutex.c \ - thread/nds/SDL_syssem.c \ - thread/nds/SDL_systhread.c \ - timer/SDL_timer.c \ - timer/nds/SDL_systimer.c \ - video/SDL_RLEaccel.c \ - video/SDL_blit.c \ - video/SDL_blit_0.c \ - video/SDL_blit_1.c \ - video/SDL_blit_A.c \ - video/SDL_blit_N.c \ - video/SDL_blit_auto.c \ - video/SDL_blit_copy.c \ - video/SDL_blit_slow.c \ - video/SDL_bmp.c \ - video/SDL_clipboard.c \ - video/SDL_fillrect.c \ - video/SDL_pixels.c \ - video/SDL_rect.c \ - video/SDL_stretch.c \ - video/SDL_surface.c \ - video/SDL_video.c \ - video/nds/SDL_ndsevents.c \ - video/nds/SDL_ndsvideo.c \ - video/nds/SDL_ndswindow.c - - -#CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -#SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -#BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/SDL - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: arm_only $(BUILD) install nds_test - -lib: - @[ -d $@ ] || mkdir -p $@ - -$(BUILD): lib - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.ds -s - -install: $(BUILD) - @mkdir -p $(PORTLIBS)/include/SDL/ - @rsync -a $(OUTPUT) $(PORTLIBS)/lib/ - @rsync -a include/*.h $(PORTLIBS)/include/SDL/ - -nds_test: - $(MAKE) -C test/nds-test-progs -s - -tags: - cd $(SOURCES); etags $(CFILES) - -# This file must be compiled with the ARM instruction set, not -# thumb. Use devkitpro way of doing things. -arm_only: src/atomic/SDL_spinlock.arm.c -src/atomic/SDL_spinlock.arm.c: src/atomic/SDL_spinlock.c - @cp $< $@ - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @cd src; rm -fr $(OFILES) $(OFILES:.o=.d) lib - @rm -f $(OUTPUT) - @make -C test/nds-test-progs -s clean - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT) : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/README.Platforms b/README.Platforms index 80a6c3f44..19a6e429a 100644 --- a/README.Platforms +++ b/README.Platforms @@ -29,5 +29,4 @@ PSP - maintained by 527721088@qq.com Platforms that need maintainers =============================== -Nintendo DS Haiku diff --git a/README.ds b/README.ds deleted file mode 100644 index 40bf8823e..000000000 --- a/README.ds +++ /dev/null @@ -1,64 +0,0 @@ -================================================================================ -Simple DirectMedia Layer for Nintendo DS -================================================================================ - --Requirements- -* The devkitpro SDK available at http://devkitpro.org. - Read the information at http://devkitpro.org/wiki/Getting_Started/devkitARM - The necessary packages are devkitARM, libnds, libfat and default arm7. -* Optionally, use a DS emulator, such as desmume (http://desmume.org/) - to program and debug. - --Building SDL- - -After setting the devkitpro environment, cd into your SDL directory and type: - make -f Makefile.ds - -This will compile and install the library and headers into the -devkitpro's portlibs directory (../portlibs/arm/lib/ and -../portlibs/arm/include/). Additionally it will compile several tests -that you can run either on the DS or with desmume. For instance: - desmume --cflash-path=test/ test/nds-test-progs/testsprite2/testsprite2.nds - desmume --cflash-path=test/ test/nds-test-progs/testspriteminimal/testspriteminimal.nds - desmume --cflash-path=test/ test/nds-test-progs/testscale/testscale.nds - desmume test/nds-test-progs/general/general.nds - --Notes- -* The renderer code is based on the gl like engine. It's not using the sprite engine. -* The hardware renderer is using the parts of the libgl2d abstraction library that can be found at: - http://rel.phatcode.net/junk.php?id=117 - Used with the author's permission. -* The port is very basic and incomplete: - - SDL currently has to be compiled for either framebuffer mode or renderer mode. - See USE_HW_RENDERER in Makefile.ds. - - some optional renderer functions are not implemented. - - no sound - --Limitations- -* in hardware renderer mode, don't load too many textures. The internal format is - 2 bytes per pixel. And there is only 256KB reserved for the textures. For instance, - testscale won't display sample.bmp, unless it's resized to a smaller picture. -* the screen size is 256 x 384. Anything else won't work. -* there is no 8 bits/pixel mode because SDL 2.0 doesn't support palettes. - --Joystick mapping- -The Joystick presented to SDL has 2 axes and 8 buttons - - KEY | Code - A | 0 - B | 1 - X | 2 - Y | 3 - L | 4 - R | 5 - select | 6 - start | 7 - - Left-right is axe 0. - Up-down is axe 1. - --Mouse mapping- -todo - --Examples- -Due to memory limitations, to be able to successfully run the testscale example, sample.bmp must be resized to 256x105. diff --git a/Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj b/Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj index f786799eb..3e0eb0c80 100755 --- a/Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj @@ -38,7 +38,6 @@ 0097E2A812F70C4D00724AC5 /* SDL_config_iphoneos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_iphoneos.h; sourceTree = ""; }; 0097E2A912F70C4D00724AC5 /* SDL_config_macosx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_macosx.h; sourceTree = ""; }; 0097E2AA12F70C4D00724AC5 /* SDL_config_minimal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_minimal.h; sourceTree = ""; }; - 0097E2AB12F70C4D00724AC5 /* SDL_config_nintendods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_nintendods.h; sourceTree = ""; }; 0097E2AC12F70C4D00724AC5 /* SDL_config_pandora.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_pandora.h; sourceTree = ""; }; 0097E2AD12F70C4D00724AC5 /* SDL_config_windows.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_windows.h; sourceTree = ""; }; 0097E2AE12F70C4D00724AC5 /* SDL_config_wiz.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_wiz.h; sourceTree = ""; }; @@ -142,7 +141,6 @@ 0097E2A812F70C4D00724AC5 /* SDL_config_iphoneos.h */, 0097E2A912F70C4D00724AC5 /* SDL_config_macosx.h */, 0097E2AA12F70C4D00724AC5 /* SDL_config_minimal.h */, - 0097E2AB12F70C4D00724AC5 /* SDL_config_nintendods.h */, 0097E2AC12F70C4D00724AC5 /* SDL_config_pandora.h */, 0097E2AD12F70C4D00724AC5 /* SDL_config_windows.h */, 0097E2AE12F70C4D00724AC5 /* SDL_config_wiz.h */, diff --git a/include/SDL_config.h b/include/SDL_config.h index 1ec9e406c..951a77d27 100644 --- a/include/SDL_config.h +++ b/include/SDL_config.h @@ -37,8 +37,6 @@ #include "SDL_config_iphoneos.h" #elif defined(__ANDROID__) #include "SDL_config_android.h" -#elif defined(__NINTENDODS__) -#include "SDL_config_nintendods.h" #elif defined(__PSP__) #include "SDL_config_psp.h" #else diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 5e5f6a769..c3b9bc708 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -195,7 +195,6 @@ #cmakedefine SDL_AUDIO_DRIVER_ESD_DYNAMIC @SDL_AUDIO_DRIVER_ESD_DYNAMIC@ #cmakedefine SDL_AUDIO_DRIVER_NAS @SDL_AUDIO_DRIVER_NAS@ #cmakedefine SDL_AUDIO_DRIVER_NAS_DYNAMIC @SDL_AUDIO_DRIVER_NAS_DYNAMIC@ -#cmakedefine SDL_AUDIO_DRIVER_NDS @SDL_AUDIO_DRIVER_NDS@ #cmakedefine SDL_AUDIO_DRIVER_OSS @SDL_AUDIO_DRIVER_OSS@ #cmakedefine SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H @SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H@ #cmakedefine SDL_AUDIO_DRIVER_PAUDIO @SDL_AUDIO_DRIVER_PAUDIO@ @@ -213,7 +212,6 @@ #cmakedefine SDL_JOYSTICK_DUMMY @SDL_JOYSTICK_DUMMY@ #cmakedefine SDL_JOYSTICK_IOKIT @SDL_JOYSTICK_IOKIT@ #cmakedefine SDL_JOYSTICK_LINUX @SDL_JOYSTICK_LINUX@ -#cmakedefine SDL_JOYSTICK_NDS @SDL_JOYSTICK_NDS@ #cmakedefine SDL_JOYSTICK_WINMM @SDL_JOYSTICK_WINMM@ #cmakedefine SDL_JOYSTICK_USBHID @SDL_JOYSTICK_USBHID@ #cmakedefine SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H @SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H@ @@ -231,7 +229,6 @@ /* Enable various threading systems */ #cmakedefine SDL_THREAD_BEOS @SDL_THREAD_BEOS@ -#cmakedefine SDL_THREAD_NDS @SDL_THREAD_NDS@ #cmakedefine SDL_THREAD_PTHREAD @SDL_THREAD_PTHREAD@ #cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX@ #cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP@ @@ -240,7 +237,6 @@ /* Enable various timer systems */ #cmakedefine SDL_TIMER_BEOS @SDL_TIMER_BEOS@ #cmakedefine SDL_TIMER_DUMMY @SDL_TIMER_DUMMY@ -#cmakedefine SDL_TIMER_NDS @SDL_TIMER_NDS@ #cmakedefine SDL_TIMER_UNIX @SDL_TIMER_UNIX@ #cmakedefine SDL_TIMER_WINDOWS @SDL_TIMER_WINDOWS@ #cmakedefine SDL_TIMER_WINCE @SDL_TIMER_WINCE@ @@ -251,7 +247,6 @@ #cmakedefine SDL_VIDEO_DRIVER_DIRECTFB @SDL_VIDEO_DRIVER_DIRECTFB@ #cmakedefine SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC @SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC@ #cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@ -#cmakedefine SDL_VIDEO_DRIVER_NDS @SDL_VIDEO_DRIVER_NDS@ #cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@ #cmakedefine SDL_VIDEO_DRIVER_X11 @SDL_VIDEO_DRIVER_X11@ #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC @SDL_VIDEO_DRIVER_X11_DYNAMIC@ @@ -295,7 +290,6 @@ #cmakedefine SDL_POWER_WINDOWS @SDL_POWER_WINDOWS@ #cmakedefine SDL_POWER_MACOSX @SDL_POWER_MACOSX@ #cmakedefine SDL_POWER_BEOS @SDL_POWER_BEOS@ -#cmakedefine SDL_POWER_NINTENDODS @SDL_POWER_NINTENDODS@ #cmakedefine SDL_POWER_HARDWIRED @SDL_POWER_HARDWIRED@ /* Enable assembly routines */ diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 59d102dd3..bd2be4b2f 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -198,7 +198,6 @@ #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC #undef SDL_AUDIO_DRIVER_NAS #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC -#undef SDL_AUDIO_DRIVER_NDS #undef SDL_AUDIO_DRIVER_OSS #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H #undef SDL_AUDIO_DRIVER_PAUDIO @@ -216,7 +215,6 @@ #undef SDL_JOYSTICK_DUMMY #undef SDL_JOYSTICK_IOKIT #undef SDL_JOYSTICK_LINUX -#undef SDL_JOYSTICK_NDS #undef SDL_JOYSTICK_WINMM #undef SDL_JOYSTICK_USBHID #undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H @@ -234,7 +232,6 @@ /* Enable various threading systems */ #undef SDL_THREAD_BEOS -#undef SDL_THREAD_NDS #undef SDL_THREAD_PTHREAD #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP @@ -243,7 +240,6 @@ /* Enable various timer systems */ #undef SDL_TIMER_BEOS #undef SDL_TIMER_DUMMY -#undef SDL_TIMER_NDS #undef SDL_TIMER_UNIX #undef SDL_TIMER_WINDOWS @@ -253,7 +249,6 @@ #undef SDL_VIDEO_DRIVER_DIRECTFB #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC #undef SDL_VIDEO_DRIVER_DUMMY -#undef SDL_VIDEO_DRIVER_NDS #undef SDL_VIDEO_DRIVER_WINDOWS #undef SDL_VIDEO_DRIVER_X11 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC @@ -297,7 +292,6 @@ #undef SDL_POWER_WINDOWS #undef SDL_POWER_MACOSX #undef SDL_POWER_BEOS -#undef SDL_POWER_NINTENDODS #undef SDL_POWER_HARDWIRED /* Enable assembly routines */ diff --git a/include/SDL_config_nintendods.h b/include/SDL_config_nintendods.h deleted file mode 100644 index 7b5c21e7c..000000000 --- a/include/SDL_config_nintendods.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -#ifndef _SDL_config_nintendods_h -#define _SDL_config_nintendods_h - -#include "SDL_platform.h" - -/* This is a set of defines to configure the SDL features */ - -#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; - -/* LiF: __PTRDIFF_TYPE__ was causing errors of conflicting typedefs with the - shipping with devkitARM. copied a similar ifdef from it. */ -#ifndef __PTRDIFF_TYPE__ -typedef unsigned long uintptr_t; -#else -typedef unsigned __PTRDIFF_TYPE__ uintptr_t; -#endif -#endif /* !_STDINT_H_ && !HAVE_STDINT_H */ - -#define SIZEOF_VOIDP 4 - -/* Useful headers */ -#define HAVE_SYS_TYPES_H 1 -#define HAVE_STDIO_H 1 -#define STDC_HEADERS 1 -#define HAVE_STRING_H 1 -#define HAVE_CTYPE_H 1 - -/* C library functions */ -#define HAVE_MALLOC 1 -#define HAVE_CALLOC 1 -#define HAVE_REALLOC 1 -#define HAVE_FREE 1 -#define HAVE_ALLOCA 1 -#define HAVE_GETENV 1 -#define HAVE_SETENV 1 -#define HAVE_PUTENV 1 -#define HAVE_QSORT 1 -#define HAVE_ABS 1 -#define HAVE_BCOPY 1 -#define HAVE_MEMSET 1 -#define HAVE_MEMCPY 1 -#define HAVE_MEMMOVE 1 -#define HAVE_MEMCMP 1 -#define HAVE_STRLEN 1 -#define HAVE_STRDUP 1 -#define HAVE_INDEX 1 -#define HAVE_RINDEX 1 -#define HAVE_STRCHR 1 -#define HAVE_STRRCHR 1 -#define HAVE_STRSTR 1 -#define HAVE_STRTOL 1 -#define HAVE_STRTOD 1 -#define HAVE_ATOI 1 -#define HAVE_ATOF 1 -#define HAVE_STRCMP 1 -#define HAVE_STRNCMP 1 -#define HAVE_STRICMP 1 -#define HAVE_STRCASECMP 1 -#define HAVE_SSCANF 1 -#define HAVE_SNPRINTF 1 -#define HAVE_VSNPRINTF 1 - -/* DS isn't that sophisticated */ -#define LACKS_SYS_MMAN_H 1 - -/* Enable various audio drivers */ -#define SDL_AUDIO_DRIVER_NDS 1 -/*#define SDL_AUDIO_DRIVER_DUMMY 1 TODO: uncomment this later*/ - -/* Enable various input drivers */ -#define SDL_JOYSTICK_NDS 1 -/*#define SDL_JOYSTICK_DUMMY 1 TODO: uncomment this later*/ - -/* DS has no dynamic linking afaik */ -#define SDL_LOADSO_DISABLED 1 - -/* Enable various threading systems */ -/*#define SDL_THREAD_NDS 1*/ -#define SDL_THREADS_DISABLED 1 - -/* Enable various timer systems */ -#define SDL_TIMER_NDS 1 - -/* Enable various video drivers */ -#define SDL_VIDEO_DRIVER_NDS 1 -#ifdef USE_HW_RENDERER -#define SDL_VIDEO_RENDER_NDS 1 -#else -#define SDL_VIDEO_RENDER_NDS 0 -#endif - -/* Enable system power support */ -#define SDL_POWER_NINTENDODS 1 - -/* Enable haptic support */ -#define SDL_HAPTIC_NDS 1 - -#define SDL_BYTEORDER SDL_LIL_ENDIAN - -#endif /* _SDL_config_nintendods_h */ diff --git a/include/SDL_platform.h b/include/SDL_platform.h index 86b45bc6a..d37964dfe 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -118,12 +118,6 @@ #undef __WIN32__ #define __WIN32__ 1 #endif - -#if defined(__NDS__) -#undef __NINTENDODS__ -#define __NINTENDODS__ 1 -#endif - #if defined(__PSP__) #undef __PLAYSTATIONPORTABLE__ #define __PLAYSTATIONPORTABLE__ 1 diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index f609eb0e3..f37678957 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -178,7 +178,7 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); /** \cond */ #ifndef DOXYGEN_SHOULD_IGNORE_THIS -#if !defined(__NINTENDODS__) && !defined(__ANDROID__) +#if !defined(__ANDROID__) /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */ typedef enum { @@ -190,10 +190,6 @@ SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ /** \endcond */ -#if !defined(wchar_t) && defined(__NINTENDODS__) -#define wchar_t short /* TODO: figure out why libnds doesn't have this */ -#endif - #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus diff --git a/include/SDL_test_common.h b/include/SDL_test_common.h index 411d03347..9e9122f1b 100644 --- a/include/SDL_test_common.h +++ b/include/SDL_test_common.h @@ -34,10 +34,7 @@ #include "SDL.h" -#ifdef __NDS__ -#define DEFAULT_WINDOW_WIDTH 256 -#define DEFAULT_WINDOW_HEIGHT (2*192) -#elif defined(__PSP__) +#if defined(__PSP__) #define DEFAULT_WINDOW_WIDTH 480 #define DEFAULT_WINDOW_HEIGHT 272 #else diff --git a/src/SDL.c b/src/SDL.c index a8707d7ec..aebc3fe36 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -390,8 +390,6 @@ SDL_GetPlatform() return "Mac OS X"; #elif __NETBSD__ return "NetBSD"; -#elif __NDS__ - return "Nintendo DS"; #elif __OPENBSD__ return "OpenBSD"; #elif __OS2__ diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index abe8c8b86..439e74d70 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -121,9 +121,6 @@ static const AudioBootStrap *const bootstrap[] = { #if SDL_AUDIO_DRIVER_DUMMY &DUMMYAUD_bootstrap, #endif -#if SDL_AUDIO_DRIVER_NDS - &NDSAUD_bootstrap, -#endif #if SDL_AUDIO_DRIVER_FUSIONSOUND &FUSIONSOUND_bootstrap, #endif diff --git a/src/audio/nds/SDL_ndsaudio.c b/src/audio/nds/SDL_ndsaudio.c deleted file mode 100644 index f729979ab..000000000 --- a/src/audio/nds/SDL_ndsaudio.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#if SDL_AUDIO_DRIVER_NDS - -/* Output audio to NDS */ - -#include - -#include "SDL_audio.h" -#include "../SDL_audio_c.h" -#include "SDL_ndsaudio.h" - -static int -NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture) -{ - SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); - int valid_datatype = 0; - - this->hidden = SDL_malloc(sizeof(*(this->hidden))); - if (!this->hidden) { - SDL_OutOfMemory(); - return 0; - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - while ((!valid_datatype) && (test_format)) { - this->spec.format = test_format; - switch (test_format) { - case AUDIO_S8: - /*case AUDIO_S16LSB: */ - valid_datatype = 1; - break; - default: - test_format = SDL_NextAudioFormat(); - break; - } - } - -#if 0 - /* set the generic sound parameters */ - setGenericSound(22050, /* sample rate */ - 127, /* volume */ - 64, /* panning/balance */ - 0); /* sound format */ -#endif - - return 1; -} - -static void -NDSAUD_PlayDevice(_THIS) -{ -#if 0 - playGenericSound(this->hidden->mixbuf, this->hidden->mixlen); - -// sound->data = this->hidden->mixbuf;/* pointer to raw audio data */ -// sound->len = this->hidden->mixlen; /* size of raw data pointed to above */ -// sound->rate = 22050; /* sample rate = 22050Hz */ -// sound->vol = 127; /* volume [0..127] for [min..max] */ -// sound->pan = 64; /* balance [0..127] for [left..right] */ -// sound->format = 0; /* 0 for 16-bit, 1 for 8-bit */ -// playSound(sound); -#endif -} - - -static Uint8 * -NDSAUD_GetDeviceBuf(_THIS) -{ - return this->hidden->mixbuf; /* is this right? */ -} - -static void -NDSAUD_WaitDevice(_THIS) -{ - /* stub */ -} - -static void -NDSAUD_CloseDevice(_THIS) -{ - /* stub */ -} - -static int -NDSAUD_Init(SDL_AudioDriverImpl * impl) -{ - /* Set the function pointers */ - impl->OpenDevice = NDSAUD_OpenDevice; - impl->PlayDevice = NDSAUD_PlayDevice; - impl->WaitDevice = NDSAUD_WaitDevice; - impl->GetDeviceBuf = NDSAUD_GetDeviceBuf; - impl->CloseDevice = NDSAUD_CloseDevice; - - /* and the capabilities */ - impl->HasCaptureSupport = 1; - impl->OnlyHasDefaultOutputDevice = 1; - impl->OnlyHasDefaultInputDevice = 1; - - return 1; /* this audio target is available. */ -} - -AudioBootStrap NDSAUD_bootstrap = { - "nds", "SDL NDS audio driver", NDSAUD_Init, 0 /*1? */ -}; - -#endif /* SDL_AUDIO_DRIVER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/nds/SDL_ndsaudio.h b/src/audio/nds/SDL_ndsaudio.h deleted file mode 100644 index 892c62f6b..000000000 --- a/src/audio/nds/SDL_ndsaudio.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#ifndef _SDL_ndsaudio_h -#define _SDL_ndsaudio_h - -#include "../SDL_sysaudio.h" -#include - -/* Hidden "this" pointer for the audio functions */ -#define _THIS SDL_AudioDevice *this - -struct SDL_PrivateAudioData -{ - /* The file descriptor for the audio device */ - Uint8 *mixbuf; - Uint32 mixlen; - Uint32 write_delay; - Uint32 initial_calls; -}; - -#endif /* _SDL_ndsaudio_h */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/nds/SDL_ndsgesture.c b/src/events/nds/SDL_ndsgesture.c deleted file mode 100644 index 16597c73e..000000000 --- a/src/events/nds/SDL_ndsgesture.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -/* No supported under the NDS because of math operations. */ - -#include "SDL_events.h" -#include "../SDL_events_c.h" -#include "../SDL_gesture_c.h" - -int SDL_GestureAddTouch(SDL_Touch* touch) -{ - return 0; -} - -void SDL_GestureProcessEvent(SDL_Event* event) -{ - return; -} - -/* vi: set ts=4 sw=4 expandtab: */ - diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 99010c3b7..0b67978d6 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -37,11 +37,6 @@ #include "../core/android/SDL_android.h" #endif -#ifdef __NDS__ -/* include libfat headers for fatInitDefault(). */ -#include -#endif /* __NDS__ */ - #ifdef __WIN32__ /* Functions to read/write Win32 API file pointers */ @@ -556,13 +551,6 @@ SDL_RWFromFP(FILE * fp, SDL_bool autoclose) { SDL_RWops *rwops = NULL; -#if 0 -/*#ifdef __NDS__*/ - /* set it up so we can use stdio file function */ - fatInitDefault(); - printf("called fatInitDefault()"); -#endif /* __NDS__ */ - rwops = SDL_AllocRW(); if (rwops != NULL) { rwops->size = stdio_size; diff --git a/src/haptic/nds/SDL_syshaptic.c b/src/haptic/nds/SDL_syshaptic.c deleted file mode 100644 index e46f178dc..000000000 --- a/src/haptic/nds/SDL_syshaptic.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#ifdef SDL_HAPTIC_NDS - -#include "SDL_haptic.h" -#include "../SDL_syshaptic.h" -#include "SDL_joystick.h" -#include -#include - -#define MAX_HAPTICS 1 -/* right now only the ezf3in1 (and maybe official rumble pak) are supported - and there can only be one of those in at a time (in GBA slot.) */ - -static SDL_Haptic *nds_haptic = NULL; - -struct haptic_hwdata -{ - enum - { NONE, OFFICIAL, EZF3IN1 } type; - int pos; -}; - - -void -NDS_EZF_OpenNorWrite() -{ - GBA_BUS[0x0FF0000] = 0xD200; - GBA_BUS[0x0000000] = 0x1500; - GBA_BUS[0x0010000] = 0xD200; - GBA_BUS[0x0020000] = 0x1500; - GBA_BUS[0x0E20000] = 0x1500; - GBA_BUS[0x0FE0000] = 0x1500; -} - -void -NDS_EZF_CloseNorWrite() -{ - GBA_BUS[0x0FF0000] = 0xD200; - GBA_BUS[0x0000000] = 0x1500; - GBA_BUS[0x0010000] = 0xD200; - GBA_BUS[0x0020000] = 0x1500; - GBA_BUS[0x0E20000] = 0xD200; - GBA_BUS[0x0FE0000] = 0x1500; -} - -void -NDS_EZF_ChipReset() -{ - GBA_BUS[0x0000] = 0x00F0; - GBA_BUS[0x1000] = 0x00F0; -} uint32 NDS_EZF_IsPresent() -{ - vuint16 id1, id2; - - NDS_EZF_OpenNorWrite(); - - GBA_BUS[0x0555] = 0x00AA; - GBA_BUS[0x02AA] = 0x0055; - GBA_BUS[0x0555] = 0x0090; - GBA_BUS[0x1555] = 0x00AA; - GBA_BUS[0x12AA] = 0x0055; - GBA_BUS[0x1555] = 0x0090; - id1 = GBA_BUS[0x0001]; - id2 = GBA_BUS[0x1001]; - if ((id1 != 0x227E) || (id2 != 0x227E)) { - NDS_EZF_CloseNorWrite(); - return 0; - } - id1 = GBA_BUS[0x000E]; - id2 = GBA_BUS[0x100E]; - - NDS_EZF_CloseNorWrite(); - if (id1 == 0x2218 && id2 == 0x2218) { - return 1; - } - return 0; -} -void -NDS_EZF_SetShake(u8 pos) -{ - u16 data = ((pos % 3) | 0x00F0); - GBA_BUS[0x0FF0000] = 0xD200; - GBA_BUS[0x0000000] = 0x1500; - GBA_BUS[0x0010000] = 0xD200; - GBA_BUS[0x0020000] = 0x1500; - GBA_BUS[0x0F10000] = data; - GBA_BUS[0x0FE0000] = 0x1500; - - GBA_BUS[0] = 0x0000; /* write any value for vibration. */ - GBA_BUS[0] = 0x0002; -} - -static int -SDL_SYS_LogicError(void) -{ - SDL_SetError("Logic error: No haptic devices available."); - return 0; -} - - -int -SDL_SYS_HapticInit(void) -{ - int ret = 0; - if (isRumbleInserted()) { - /* official rumble pak is present. */ - ret = 1; - printf("debug: haptic present: nintendo\n"); - } else if (NDS_EZF_IsPresent()) { - /* ezflash 3-in-1 pak is present. */ - ret = 1; - printf("debug: haptic present: ezf3in1\n"); - NDS_EZF_ChipReset(); - } else { - printf("debug: no haptic found\n"); - } - - return ret; -} - - -const char * -SDL_SYS_HapticName(int index) -{ - if (nds_haptic) { - switch (nds_haptic->hwdata->type) { - case OFFICIAL: - return "Nintendo DS Rumble Pak"; - case EZF3IN1: - return "EZFlash 3-in-1 Rumble"; - default: - return NULL; - } - } - return NULL; -} - - -int -SDL_SYS_HapticOpen(SDL_Haptic * haptic) -{ - if (!haptic) { - return -1; - } - - haptic->hwdata = SDL_malloc(sizeof(struct haptic_hwdata)); - if (!haptic->hwdata) { - SDL_OutOfMemory(); - return -1; - } - nds_haptic = haptic; - - haptic->supported = SDL_HAPTIC_CONSTANT; - - /* determine what is here, if anything */ - haptic->hwdata->type = NONE; - if (isRumbleInserted()) { - /* official rumble pak is present. */ - haptic->hwdata->type = OFFICIAL; - } else if (NDS_EZF_IsPresent()) { - /* ezflash 3-in-1 pak is present. */ - haptic->hwdata->type = EZF3IN1; - NDS_EZF_ChipReset(); - } else { - /* no haptic present */ - SDL_SYS_LogicError(); - return -1; - } - - return 0; -} - - -int -SDL_SYS_HapticMouse(void) -{ - return -1; -} - - -int -SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) -{ - return 0; -} - - -int -SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) -{ - /*SDL_SYS_LogicError(); */ - return -1; -} - - -int -SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) -{ - return 0; -} - - -void -SDL_SYS_HapticClose(SDL_Haptic * haptic) -{ - return; -} - - -void -SDL_SYS_HapticQuit(void) -{ - return; -} - - -int -SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, - struct haptic_effect *effect, SDL_HapticEffect * base) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, - struct haptic_effect *effect, - SDL_HapticEffect * data) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, - Uint32 iterations) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) -{ - SDL_SYS_LogicError(); - return -1; -} - - -void -SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect) -{ - SDL_SYS_LogicError(); - return; -} - - -int -SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, - struct haptic_effect *effect) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) -{ - SDL_SYS_LogicError(); - return -1; -} - -int -SDL_SYS_HapticPause(SDL_Haptic * haptic) -{ - SDL_SYS_LogicError(); - return -1; -} - -int -SDL_SYS_HapticUnpause(SDL_Haptic * haptic) -{ - SDL_SYS_LogicError(); - return -1; -} - -int -SDL_SYS_HapticStopAll(SDL_Haptic * haptic) -{ - SDL_SYS_LogicError(); - return -1; -} - - - -#endif /* SDL_HAPTIC_NDS */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/nds/SDL_sysjoystick.c b/src/joystick/nds/SDL_sysjoystick.c deleted file mode 100644 index a4ac18233..000000000 --- a/src/joystick/nds/SDL_sysjoystick.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#ifdef SDL_JOYSTICK_NDS - -/* This is the system specific header for the SDL joystick API */ -#include -#include /* For the definition of NULL */ - -#include "SDL_error.h" -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#include "../../video/nds/SDL_ndsevents_c.h" - -/* Function to scan the system for joysticks. - */ -int -SDL_SYS_JoystickInit(void) -{ - return (1); -} - -int SDL_SYS_NumJoysticks() -{ - return 1; -} - -void SDL_SYS_JoystickDetect() -{ -} - -SDL_bool SDL_SYS_JoystickNeedsPolling() -{ - return SDL_FALSE; -} - -/* Function to get the device-dependent name of a joystick */ -const char * -SDL_SYS_JoystickNameForDeviceIndex(int device_index) -{ - return "NDS builtin joypad"; -} - -/* Function to perform the mapping from device index to the instance id for this index */ -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) -{ - return device_index; -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int -SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) -{ - joystick->nbuttons = 8; - joystick->nhats = 0; - joystick->nballs = 0; - joystick->naxes = 2; - return 0; -} - -/* Function to determine is this joystick is attached to the system right now */ -SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) -{ - return SDL_TRUE; -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ - void -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) -{ - u32 keysd, keysu; - int magnitude = 16384; - - /*scanKeys(); - this is done in PumpEvents, because touch uses it too */ - keysd = keysDown(); - keysu = keysUp(); - - if ((keysd & KEY_UP)) { - SDL_PrivateJoystickAxis(joystick, 1, -magnitude); - } - if ((keysd & KEY_DOWN)) { - SDL_PrivateJoystickAxis(joystick, 1, magnitude); - } - if ((keysd & KEY_LEFT)) { - SDL_PrivateJoystickAxis(joystick, 0, -magnitude); - } - if ((keysd & KEY_RIGHT)) { - SDL_PrivateJoystickAxis(joystick, 0, magnitude); - } - if ((keysu & (KEY_UP | KEY_DOWN))) { - SDL_PrivateJoystickAxis(joystick, 1, 0); - } - if ((keysu & (KEY_LEFT | KEY_RIGHT))) { - SDL_PrivateJoystickAxis(joystick, 0, 0); - } - if ((keysd & KEY_A)) { - SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED); - } - if ((keysd & KEY_B)) { - SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED); - } - if ((keysd & KEY_X)) { - SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED); - } - if ((keysd & KEY_Y)) { - SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED); - } - if ((keysd & KEY_L)) { - SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED); - } - if ((keysd & KEY_R)) { - SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED); - } - if ((keysd & KEY_SELECT)) { - SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED); - } - if ((keysd & KEY_START)) { - SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED); - } - if ((keysu & KEY_A)) { - SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED); - } - if ((keysu & KEY_B)) { - SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED); - } - if ((keysu & KEY_X)) { - SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED); - } - if ((keysu & KEY_Y)) { - SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED); - } - if ((keysu & KEY_L)) { - SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED); - } - if ((keysu & KEY_R)) { - SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED); - } - if ((keysu & KEY_SELECT)) { - SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED); - } - if ((keysu & KEY_START)) { - SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED); - } -} - -/* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick * joystick) -{ -} - -/* Function to perform any system-specific joystick related cleanup */ -void -SDL_SYS_JoystickQuit(void) -{ -} - -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) -{ - SDL_JoystickGUID guid; - // the GUID is just the first 16 chars of the name for now - const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) -{ - SDL_JoystickGUID guid; - // the GUID is just the first 16 chars of the name for now - const char *name = joystick->name; - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -#endif /* SDL_JOYSTICK_NDS */ diff --git a/src/power/SDL_power.c b/src/power/SDL_power.c index bb920600e..b8f3ae40f 100644 --- a/src/power/SDL_power.c +++ b/src/power/SDL_power.c @@ -34,7 +34,6 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *); -SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *); @@ -69,9 +68,6 @@ static SDL_GetPowerInfo_Impl implementations[] = { #ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin. */ SDL_GetPowerInfo_MacOSX, #endif -#ifdef SDL_POWER_NINTENDODS /* handles Nintendo DS. */ - SDL_GetPowerInfo_NintendoDS, -#endif #ifdef SDL_POWER_BEOS /* handles BeOS, Zeta, with euc.jp apm driver. */ SDL_GetPowerInfo_BeOS, #endif diff --git a/src/power/nds/SDL_syspower.c b/src/power/nds/SDL_syspower.c deleted file mode 100644 index 0a1a01ce2..000000000 --- a/src/power/nds/SDL_syspower.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#ifndef SDL_POWER_DISABLED -#if SDL_POWER_NINTENDODS - -#include "SDL_power.h" - -SDL_bool -SDL_GetPowerInfo_NintendoDS(SDL_PowerState * state, int *seconds, - int *percent) -{ - /* !!! FIXME: write me. */ - - *state = SDL_POWERSTATE_UNKNOWN; - *percent = -1; - *seconds = -1; - - return SDL_TRUE; /* always the definitive answer on Nintendo DS. */ -} - -#endif /* SDL_POWER_NINTENDODS */ -#endif /* SDL_POWER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index c3f86ca1a..d007186e8 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -61,9 +61,6 @@ static const SDL_RenderDriver *render_drivers[] = { #if SDL_VIDEO_RENDER_DIRECTFB &DirectFB_RenderDriver, #endif -#if SDL_VIDEO_RENDER_NDS - &NDS_RenderDriver, -#endif #if SDL_VIDEO_RENDER_PSP &PSP_RenderDriver, #endif diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index 95d3f67e0..17f506ed8 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -173,9 +173,6 @@ extern SDL_RenderDriver GLES_RenderDriver; #if SDL_VIDEO_RENDER_DIRECTFB extern SDL_RenderDriver DirectFB_RenderDriver; #endif -#if SDL_VIDEO_RENDER_NDS -extern SDL_RenderDriver NDS_RenderDriver; -#endif #if SDL_VIDEO_RENDER_PSP extern SDL_RenderDriver PSP_RenderDriver; #endif diff --git a/src/render/nds/SDL_libgl2D.c b/src/render/nds/SDL_libgl2D.c deleted file mode 100644 index 7ba9be072..000000000 --- a/src/render/nds/SDL_libgl2D.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Note: The Nintendo DS port to SDL uses excerpts from the libGL2D, - * with permission of the original author. The following is mostly his - * code/comments. - * - * - * Easy GL2D - * - * Relminator 2010 - * Richard Eric M. Lope BSN RN - * - * http://rel.betterwebber.com - * - * A very small and simple DS rendering lib using the 3d core to render 2D stuff - */ -#include "SDL_config.h" - -#if SDL_VIDEO_RENDER_NDS - -#include "SDL_libgl2D.h" - -/* - * Our static global variable used for Depth values since we cannot - * disable depth testing in the DS hardware This value is incremented - * for every draw call. */ -v16 g_depth; -int gCurrentTexture; - -/* - * !!! PRIVATE !!! Set orthographic projection at 1:1 correspondence - * to screen coords glOrtho expects f32 values but if we use the - * standard f32 values, we need to rescale either every vert or the - * modelview matrix by the same amount to make it work. That's gonna - * give us lots of overflows and headaches. So we "scale down" and - * use an all integer value. - */ -void SetOrtho(void) -{ - glMatrixMode(GL_PROJECTION); // set matrixmode to projection - glLoadIdentity(); // reset - glOrthof32(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1 << 12, 1 << 12); // downscale projection matrix -} - -/* - * Initializes GL in 2D mode Also initializes GL in 3d mode so that we - * could combine 2D and 3D later Almost a direct copy from the DS - * example files - */ -void glScreen2D(void) -{ - // initialize gl - glInit(); - - // enable textures - glEnable(GL_TEXTURE_2D); - - // enable antialiasing - glEnable(GL_ANTIALIAS); - - // setup the rear plane - glClearColor(0, 0, 0, 31); // BG must be opaque for AA to work - glClearPolyID(63); // BG must have a unique polygon ID for AA to work - - glClearDepth(GL_MAX_DEPTH); - - // this should work the same as the normal gl call - glViewport(0,0,255,191); - - // any floating point gl call is being converted to fixed prior to being implemented - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(70, 256.0 / 192.0, 1, 200); - - gluLookAt( 0.0, 0.0, 1.0, //camera possition - 0.0, 0.0, 0.0, //look at - 0.0, 1.0, 0.0); //up - - glMaterialf(GL_AMBIENT, RGB15(31,31,31)); - glMaterialf(GL_DIFFUSE, RGB15(31,31,31)); - glMaterialf(GL_SPECULAR, BIT(15) | RGB15(31,31,31)); - glMaterialf(GL_EMISSION, RGB15(31,31,31)); - - // ds uses a table for shinyness..this generates a half-ass one - glMaterialShinyness(); - - // not a real gl function and will likely change - glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK); -} - -/* - * Sets up OpenGL for 2d rendering Call this before drawing any of - * GL2D's drawing or sprite functions. - */ -void glBegin2D(void) -{ - // save 3d perpective projection matrix - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - // save 3d modelview matrix for safety - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - - // what?!! No glDisable(GL_DEPTH_TEST)?!!!!!! - glEnable(GL_BLEND); - glEnable(GL_TEXTURE_2D); - glDisable(GL_ANTIALIAS); // disable AA - glDisable(GL_OUTLINE); // disable edge-marking - - glColor(0x7FFF); // max color - - glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); // no culling - - SetOrtho(); - - glMatrixMode(GL_TEXTURE); // reset texture matrix just in case we did some funky stuff with it - glLoadIdentity(); - - glMatrixMode(GL_MODELVIEW); // reset modelview matrix. No need to scale up by << 12 - glLoadIdentity(); - - gCurrentTexture = 0; // set current texture to 0 - g_depth = 0; // set depth to 0. We need this var since we cannot disable depth testing -} - -/* - * Issue this after drawing 2d so that we don't mess the matrix stack. - * The complement of glBegin2D. - */ -void glEnd2D(void) -{ - // restore 3d matrices and set current matrix to modelview - glMatrixMode(GL_PROJECTION); - glPopMatrix(1); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(1); -} - -/* - * Draws a pixel - * Parameters: - * x,y -> First coordinate of the line - * color -> RGB15/ARGB16 color - */ -void glPutPixel(int x, int y, int color) -{ - glBindTexture(0, 0); - glColor(color); - glBegin(GL_TRIANGLES); - gxVertex3i(x, y, g_depth); - gxVertex2i(x, y); - gxVertex2i(x, y); - glEnd(); - glColor(0x7FFF); - g_depth++; - gCurrentTexture = 0; -} - -/* - * Draws a line - * Parameters: - * x1,y1 -> First coordinate of the line - * x2,y2 -> Second coordinate of the line - * color -> RGB15/ARGB16 color - */ -void glLine(int x1, int y1, int x2, int y2, int color) -{ - x2++; - y2++; - - glBindTexture(0, 0); - glColor(color); - glBegin(GL_TRIANGLES); - gxVertex3i(x1, y1, g_depth); - gxVertex2i(x2, y2); - gxVertex2i(x2, y2); - glEnd(); - glColor(0x7FFF); - g_depth++; - gCurrentTexture = 0; -} - -/* - * Draws a Filled Box - * Parameters: - * x1,y1 -> Top-left corner of the box - * x2,y2 -> Bottom-Right corner of the box - * color -> RGB15/ARGB16 color -*/ -void glBoxFilled(int x1, int y1, int x2, int y2, int color) -{ - x2++; - y2++; - - glBindTexture(0, 0); - glColor(color); - glBegin(GL_QUADS); - gxVertex3i(x1, y1, g_depth); // use 3i for first vertex so that we increment HW depth - gxVertex2i(x1, y2); // no need for 3 vertices as 2i would share last depth call - gxVertex2i(x2, y2); - gxVertex2i(x2, y1); - glEnd(); - glColor(0x7FFF); - g_depth++; - gCurrentTexture = 0; -} - -/* - * - * Create a tile. - * Very rigid and prone to human error. - * - * Parameters: - * *sprite -> pointer to a glImage - * texture_width -> width/height of the texture; - * texture_height -> valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d) - * sprite_width - * sprite_height -> width/height of the picture in the texture. - * type -> The format of the texture (see glTexImage2d) - * param -> parameters for the texture (see glTexImage2d) - */ -int glLoadTile(glImage *sprite, - int texture_width, - int texture_height, - int sprite_width, - int sprite_height, - GL_TEXTURE_TYPE_ENUM type, - int param, - int pallette_width, - const u16 *palette, - const uint8 *texture) -{ - int textureID; - - glGenTextures(1, &textureID); - glBindTexture(0, textureID); - glTexImage2D(0, 0, type, texture_width, texture_height, 0, param, texture); - glColorTableEXT(0, 0, pallette_width, 0, 0, palette); - - sprite->width = sprite_width; - sprite->height = sprite_height; - sprite->textureID = textureID; - - return textureID; -} - -/* - * I made this since the scale wrappers are either the vectorized mode - * or does not permit you to scale only the axis you want to - * scale. Needed for sprite scaling. - */ -static inline void gxScalef32(s32 x, s32 y, s32 z) -{ - MATRIX_SCALE = x; - MATRIX_SCALE = y; - MATRIX_SCALE = z; -} - -/* - * I this made for future naming conflicts. - */ -static inline void gxTranslate3f32(int32 x, int32 y, int32 z) -{ - MATRIX_TRANSLATE = x; - MATRIX_TRANSLATE = y; - MATRIX_TRANSLATE = z; -} - -/* - * Draws an axis exclusive scaled sprite - * Parameters: - * x -> x position of the sprite - * y -> y position of the sprite - * scaleX -> 20.12 FP X axis scale value (1 << 12 is normal) - * scaleY -> 20.12 FP Y axis scale value (1 << 12 is normal) - * flipmode -> mode for flipping (see GL_FLIP_MODE enum) - * *spr -> pointer to a glImage - */ -void glSpriteScaleXY(int x, int y, s32 scaleX, s32 scaleY, int flipmode, const glImage *spr) -{ - const int x1 = 0; - const int y1 = 0; - const int x2 = spr->width; - const int y2 = spr->height; - const int u1 = ((flipmode & GL_FLIP_H) ? spr->width-1 : 0); - const int u2 = ((flipmode & GL_FLIP_H) ? 0 : spr->width-1); - const int v1 = ((flipmode & GL_FLIP_V) ? spr->height-1 : 0); - const int v2 = ((flipmode & GL_FLIP_V) ? 0 : spr->height-1); - - if (spr->textureID != gCurrentTexture) - { - glBindTexture(GL_TEXTURE_2D, spr->textureID); - gCurrentTexture = spr->textureID; - } - - glPushMatrix(); - - gxTranslate3f32(x, y, 0); - gxScalef32(scaleX, scaleY, 1 << 12); - - glBegin(GL_QUADS); - - gxTexcoord2i(u1, v1); gxVertex3i(x1, y1, g_depth); - gxTexcoord2i(u1, v2); gxVertex2i(x1, y2); - gxTexcoord2i(u2, v2); gxVertex2i(x2, y2); - gxTexcoord2i(u2, v1); gxVertex2i(x2, y1); - - glEnd(); - - glPopMatrix(1); - g_depth++; -} - -#endif /* SDL_VIDEO_RENDER_NDS */ diff --git a/src/render/nds/SDL_libgl2D.h b/src/render/nds/SDL_libgl2D.h deleted file mode 100644 index 4d56f0e89..000000000 --- a/src/render/nds/SDL_libgl2D.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Note: The Nintendo DS port to SDL uses excerpts from the libGL2D, - * with permission of the original author. The following is mostly his - * code/comments. - * - * - * Easy GL2D - * - * Relminator 2010 - * Richard Eric M. Lope BSN RN - * - * http://rel.betterwebber.com - * - * A very small and simple DS rendering lib using the 3d core to render 2D stuff - */ -#include "SDL_config.h" - -#if SDL_VIDEO_RENDER_NDS - -#include - -/* LibGL extension(s) */ -static inline void gxTexcoord2i(t16 u, t16 v) -{ - GFX_TEX_COORD = (v << 20) | ((u << 4) & 0xFFFF); -} - -static inline void gxVertex3i(v16 x, v16 y, v16 z) -{ - GFX_VERTEX16 = (y << 16) | (x & 0xFFFF); - GFX_VERTEX16 = ((uint32)(uint16)z); -} - -static inline void gxVertex2i(v16 x, v16 y) -{ - GFX_VERTEX_XY = (y << 16) | (x & 0xFFFF); -} - -/* - * Enums selecting flipping mode. - * - * These enums are bits for flipping the sprites. - * You can "|" (or) GL_FLIP_V and GL_FLIP_H to flip - * both ways. - */ -typedef enum -{ - GL_FLIP_NONE = (1 << 0), /* No flipping */ - GL_FLIP_V = (1 << 1), /* Sprite is rendered vertically flipped */ - GL_FLIP_H = (1 << 2), /* Sprite is rendered horizontally flipped */ -} GL_FLIP_MODE; - -/* Struct for out GL-Based Images. */ -typedef struct -{ - int width; /* Width of the Sprite */ - int height; /* Height of the Sprite */ - int textureID; /* Texture handle (used in glDeleteTextures()) - The texture handle in VRAM (returned by glGenTextures()) - ie. This references the actual texture stored in VRAM. */ -} glImage; - -extern v16 g_depth; -extern int gCurrentTexture; - -/* - * Draws an Axis Exclusive Scaled Sprite - * Parameters: - * x X position of the sprite. - * y Y position of the sprite. - * scaleX 20.12 fixed-point X-Axis scale value (1 << 12 is normal). - * scaleY 20.12 fixed-point Y-Axis scale value (1 << 12 is normal). - * flipmode mode for flipping (see GL_FLIP_MODE enum). - * *spr pointer to a glImage. -*/ -void glSpriteScaleXY(int x, int y, s32 scaleX, s32 scaleY, int flipmode, const glImage *spr); - -/* Initializes our Tileset (like glInitSpriteset()) but without the use of Texture Packer auto-generated files. - * Can only be used when tiles in a tilset are of the same dimensions. - * Parameters: - * *sprite Pointer to an array of glImage. - * tile_wid Width of each tile in the texture. - * tile_hei Height of each tile in the texture. - * bmp_wid Width of of the texture or tileset. - * bmp_hei height of of the texture or tileset. - * type The format of the texture (see glTexImage2d()). - * sizeX The horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d()). - * sizeY The vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d()). - * param parameters for the texture (see glTexImage2d()). - * pallette_width Length of the palette. Valid values are 4, 16, 32, 256 (if 0, then palette is removed from currently bound texture). - * *palette Pointer to the palette data to load (if NULL, then palette is removed from currently bound texture). - * *texture Pointer to the texture data to load. -*/ -int glLoadTile(glImage *sprite, - int texture_width, - int texture_height, - int sprite_width, - int sprite_height, - GL_TEXTURE_TYPE_ENUM type, - int param, - int pallette_width, - const u16 *palette, - const uint8 *texture); - -/* Initializes GL in 2D mode */ -void glScreen2D(void); - -/* - * Sets up OpenGL for 2d rendering. - * - * Call this before drawing any of GL2D's drawing or sprite functions. - */ -void glBegin2D(void); - -/* - * Issue this after drawing 2d so that we don't mess the matrix stack. - * - * The complement of glBegin2D(). - */ -void glEnd2D(void); - -/* - * Draws a Pixel - * x X position of the pixel. - * y Y position of the pixel. - * color RGB15/ARGB16 color. - */ -void glPutPixel(int x, int y, int color); - -/* - * Draws a Line - * x1,y1 Top-Left coordinate of the line. - * x2,y2 Bottom-Right coordinate of the line. - * color RGB15/ARGB16 color. - */ -void glLine(int x1, int y1, int x2, int y2, int color); - -/* - * Draws a Box - * x1,y1 Top-Left coordinate of the box. - * x2,y2 Bottom-Right coordinate of the box. - * color RGB15/ARGB16 color. -*/ -void glBox(int x1, int y1, int x2, int y2, int color); - -/* - * Draws a Filled Box - * x1,y1 Top-Left coordinate of the box. - * x2,y2 Bottom-Right coordinate of the box. - * color RGB15/ARGB16 color. - */ -void glBoxFilled(int x1, int y1, int x2, int y2, int color); - -#endif /* SDL_VIDEO_RENDER_NDS */ diff --git a/src/render/nds/SDL_ndsrender.c b/src/render/nds/SDL_ndsrender.c deleted file mode 100644 index b888f0aa8..000000000 --- a/src/render/nds/SDL_ndsrender.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#if SDL_VIDEO_RENDER_NDS - -#include -#include -#include - -#include "SDL_libgl2D.h" - -#include "SDL_video.h" -#include "../../video/SDL_sysvideo.h" -#include "SDL_render.h" -#include "../SDL_sysrender.h" -#include "SDL_log.h" - -/* Draws a partial sprite. Based on glSprite. */ -static void glSpritePartial(const SDL_Rect * srcrect, int x, int y, int flipmode, const glImage *spr) -{ - int x1 = x; - int y1 = y; - int x2 = x + srcrect->w; - int y2 = y + srcrect->h; - - int u1 = srcrect->x + ((flipmode & GL_FLIP_H) ? spr->width-1 : 0); - int u2 = srcrect->x + ((flipmode & GL_FLIP_H) ? 0 : srcrect->h); - int v1 = srcrect->y + ((flipmode & GL_FLIP_V) ? spr->height-1 : 0); - int v2 = srcrect->y + ((flipmode & GL_FLIP_V) ? 0 : srcrect->h); - - if (spr->textureID != gCurrentTexture) { - glBindTexture(GL_TEXTURE_2D, spr->textureID); - gCurrentTexture = spr->textureID; - } - - glBegin(GL_QUADS); - - gxTexcoord2i(u1, v1); gxVertex3i(x1, y1, g_depth); - gxTexcoord2i(u1, v2); gxVertex2i(x1, y2); - gxTexcoord2i(u2, v2); gxVertex2i(x2, y2); - gxTexcoord2i(u2, v1); gxVertex2i(x2, y1); - - glEnd(); - - g_depth++; -} - -/* SDL NDS renderer implementation */ - -extern SDL_RenderDriver NDS_RenderDriver; - -typedef struct -{ - /* Whether current 3D engine is on the main or sub screen. */ - int is_sub; -} NDS_RenderData; - -typedef struct -{ - glImage image[1]; -} NDS_TextureData; - -static int NDS_UpdateViewport(SDL_Renderer *renderer) -{ - /* Nothing to do. */ - return 0; -} - -static int -NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; - int dest_y; - - if (data->is_sub) { - dest_y = dstrect->y; - } else { - dest_y = dstrect->y-SCREEN_HEIGHT; - } - - if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { - /* No scaling */ - glSpritePartial(srcrect, dstrect->x, dest_y, GL_FLIP_NONE, txdat->image); - } else { - /* Convert the scaling proportion into a 20.12 value. */ - s32 scale_w = divf32(dstrect->w << 12, texture->w << 12); - s32 scale_h = divf32(dstrect->h << 12, texture->h << 12); - - glSpriteScaleXY(dstrect->x, dest_y, scale_w, scale_h, GL_FLIP_NONE, txdat->image); - } - - return 0; -} - -static int NDS_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - NDS_TextureData *txdat = NULL; - int i; - - SDL_Log("NDS_CreateTexture: NDS_CreateTexture.\n"); - - /* Sanity checks. */ - for (i=0; iformat == NDS_RenderDriver.info.texture_formats[i]) - break; - } - if (i == NDS_RenderDriver.info.num_texture_formats) { - SDL_SetError("Unsupported texture format (%x)", texture->format); - return -1; - } - - if (texture->w > NDS_RenderDriver.info.max_texture_width) { - SDL_SetError("Texture too large (%d)", texture->w); - return -1; - } - - if (texture->h > NDS_RenderDriver.info.max_texture_height) { - SDL_SetError("Texture too tall (%d)", texture->h); - return -1; - } - - texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); - txdat = (NDS_TextureData *) texture->driverdata; - if (!txdat) { - SDL_OutOfMemory(); - return -1; - } - - return 0; -} - -static void -NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - NDS_TextureData *txdat = texture->driverdata; - - /* free anything else allocated for texture */ - SDL_free(txdat); -} - -/* size is no more than 512. */ -static int get_gltexture_size(unsigned int size) -{ - if (size > 256) - return TEXTURE_SIZE_512; - else if (size > 128) - return TEXTURE_SIZE_256; - else if (size > 64) - return TEXTURE_SIZE_128; - else if (size > 32) - return TEXTURE_SIZE_64; - else if (size > 16) - return TEXTURE_SIZE_32; - else if (size > 8) - return TEXTURE_SIZE_16; - else - return TEXTURE_SIZE_8; -} - -static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; - char *new_pixels = NULL; - const int gl_w = get_gltexture_size(rect->w); - const int gl_h = get_gltexture_size(rect->h); - const int w = 1 << (3+gl_w); /* Texture sizes must be a power of 2. */ - const int h = 1 << (3+gl_h); /* Texture sizes must be a power of 2. */ - - if (w != rect->w || h != rect->h) { - /* Allocate a temporary surface and copy pixels into it while - * enlarging the pitch. */ - const char *src; - char *dst; - int new_pitch = 2 * w; - int i; - - new_pixels = malloc(2 * w * h); - if (!new_pixels) - return SDL_ENOMEM; - - src = pixels; - dst = new_pixels; - for (i=0; ih; i++) { - memcpy(dst, src, pitch); - src += pitch; - dst += new_pitch; - } - } - - glLoadTile(txdat->image, - gl_w, gl_h, - rect->w, rect->h, - texture->format == SDL_PIXELFORMAT_ABGR1555 ? GL_RGBA : GL_RGB, - TEXGEN_OFF, 0, NULL, - new_pixels? new_pixels : pixels); - - if (new_pixels) - free(new_pixels); - - return 0; -} - -static int NDS_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, - const SDL_Rect *rect, void **pixels, int *pitch) -{ - SDL_Log("enter %s (todo)\n", __func__); - - return 0; -} - -static void NDS_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - SDL_Log("enter %s\n", __func__); - /* stub! */ -} - -static int NDS_RenderClear(SDL_Renderer *renderer) -{ - glClearColor(renderer->r >> 3, - renderer->g >> 3, - renderer->b >> 3, - renderer->a >> 3); - - return 0; -} - -static void NDS_RenderPresent(SDL_Renderer * renderer) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - - glEnd2D(); - - glFlush(0); - - swiWaitForVBlank(); - - /* wait for capture unit to be ready */ - while(REG_DISPCAPCNT & DCAP_ENABLE); - - /* 3D engine can only work on one screen at a time. */ - data->is_sub = !data->is_sub; - if (data->is_sub) { - lcdMainOnBottom(); - vramSetBankC(VRAM_C_LCD); - vramSetBankD(VRAM_D_SUB_SPRITE); - REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3); - } else { - lcdMainOnTop(); - vramSetBankD(VRAM_D_LCD); - vramSetBankC(VRAM_C_SUB_BG); - REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3); - } - - glBegin2D(); -} - -static int NDS_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, - int count) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - int i; - int color = RGB15(renderer->r >> 3, - renderer->g >> 3, - renderer->b >> 3); - - for (i=0; i < count; i++) { - if (data->is_sub) { - glPutPixel(points[i].x, points[i].y, color); - } else { - glPutPixel(points[i].x, points[i].y - SCREEN_HEIGHT, color); - } - } - - return 0; -} - -static int NDS_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, - int count) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - int i; - int color = RGB15(renderer->r >> 3, - renderer->g >> 3, - renderer->b >> 3); - - for (i=0; i < count-1; i++) { - if (data->is_sub) { - glLine(points[i].x, points[i].y, points[i+1].x, points[i+1].y, color); - } else { - glLine(points[i].x, points[i].y - SCREEN_HEIGHT, - points[i+1].x, points[i+1].y - SCREEN_HEIGHT, color); - } - } - - return 0; -} - -static int NDS_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, - int count) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - int i; - int color = RGB15(renderer->r >> 3, - renderer->g >> 3, - renderer->b >> 3); - - for (i=0; iis_sub) { - glBoxFilled(rects[i].x, rects[i].y, - rects[i].x + rects[i].w, - rects[i].y + rects[i].h, color); - } else { - glBoxFilled(rects[i].x, rects[i].y - SCREEN_HEIGHT, - rects[i].x + rects[i].w, - rects[i].y + rects[i].h - SCREEN_HEIGHT, - color); - } - } - - return 0; -} - -static SDL_Renderer * -NDS_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayMode *displayMode = &display->current_mode; - SDL_Renderer *renderer; - NDS_RenderData *data; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - if (displayMode->format != SDL_PIXELFORMAT_ABGR1555) { - SDL_SetError("Unsupported pixel format (%x)", displayMode->format); - return NULL; - } - - if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, - &Rmask, &Gmask, &Bmask, &Amask)) { - SDL_SetError("Unknown display format"); - return NULL; - } - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (NDS_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - SDL_free(renderer); - SDL_OutOfMemory(); - return NULL; - } - - renderer->info = NDS_RenderDriver.info; - renderer->info.flags = SDL_RENDERER_ACCELERATED; - - renderer->CreateTexture = NDS_CreateTexture; - renderer->UpdateTexture = NDS_UpdateTexture; - renderer->LockTexture = NDS_LockTexture; - renderer->UnlockTexture = NDS_UnlockTexture; - renderer->UpdateViewport = NDS_UpdateViewport; - renderer->RenderClear = NDS_RenderClear; - renderer->RenderDrawPoints = NDS_RenderDrawPoints; - renderer->RenderDrawLines = NDS_RenderDrawLines; - renderer->RenderFillRects = NDS_RenderFillRects; - renderer->RenderCopy = NDS_RenderCopy; - /* renderer->RenderReadPixels = NDS_RenderReadPixels; - todo ? */ - renderer->RenderPresent = NDS_RenderPresent; - renderer->DestroyTexture = NDS_DestroyTexture; - /* renderer->DestroyRenderer = NDS_DestroyRenderer; - todo ? */ - - renderer->driverdata = data; - - return renderer; -} - -SDL_RenderDriver NDS_RenderDriver = { - .CreateRenderer = NDS_CreateRenderer, - .info = { - .name = "nds", - .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC, - .num_texture_formats = 2, - .texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555, - [1] = SDL_PIXELFORMAT_BGR555, - }, - .max_texture_width = 512, - .max_texture_height = 512, - } -}; - -#endif /* SDL_VIDEO_RENDER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 9f8bff878..e050de735 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -44,11 +44,7 @@ SDLTest_CommonCreateState(char **argv, Uint32 flags) /* Initialize some defaults */ state->argv = argv; state->flags = flags; -#ifdef __NDS__ - state->window_title = ""; -#else state->window_title = argv[0]; -#endif state->window_flags = 0; state->window_x = SDL_WINDOWPOS_UNDEFINED; state->window_y = SDL_WINDOWPOS_UNDEFINED; @@ -87,10 +83,6 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index) { char **argv = state->argv; -#ifdef __NDS__ - return 0; -#endif - if (SDL_strcasecmp(argv[index], "--video") == 0) { ++index; if (!argv[index]) { diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h index f1c1c1ddf..64fb77894 100644 --- a/src/thread/SDL_thread_c.h +++ b/src/thread/SDL_thread_c.h @@ -34,8 +34,6 @@ #include "pthread/SDL_systhread_c.h" #elif SDL_THREAD_WINDOWS #include "windows/SDL_systhread_c.h" -#elif SDL_THREAD_NDS -#include "nds/SDL_systhread_c.h" #elif SDL_THREAD_PSP #include "psp/SDL_systhread_c.h" #else diff --git a/src/thread/nds/SDL_syscond.c b/src/thread/nds/SDL_syscond.c deleted file mode 100644 index 6f41eaa5b..000000000 --- a/src/thread/nds/SDL_syscond.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syscond.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif - -/* An implementation of condition variables using semaphores and mutexes */ -/* - This implementation borrows heavily from the BeOS condition variable - implementation, written by Christopher Tate and Owen Smith. Thanks! - */ - -#include -#include - -#include "SDL_error.h" -#include "SDL_thread.h" - -struct SDL_cond -{ - SDL_mutex *lock; - int waiting; - int signals; - SDL_sem *wait_sem; - SDL_sem *wait_done; -}; - -/* Create a condition variable */ -SDL_cond * -SDL_CreateCond(void) -{ - SDL_cond *cond; - - cond = (SDL_cond *) malloc(sizeof(SDL_cond)); - if (cond) { - cond->lock = SDL_CreateMutex(); - cond->wait_sem = SDL_CreateSemaphore(0); - cond->wait_done = SDL_CreateSemaphore(0); - cond->waiting = cond->signals = 0; - if (!cond->lock || !cond->wait_sem || !cond->wait_done) { - SDL_DestroyCond(cond); - cond = NULL; - } - } else { - SDL_OutOfMemory(); - } - return (cond); -} - -/* Destroy a condition variable */ -void -SDL_DestroyCond(SDL_cond * cond) -{ - if (cond) { - if (cond->wait_sem) { - SDL_DestroySemaphore(cond->wait_sem); - } - if (cond->wait_done) { - SDL_DestroySemaphore(cond->wait_done); - } - if (cond->lock) { - SDL_DestroyMutex(cond->lock); - } - free(cond); - } -} - -/* Restart one of the threads that are waiting on the condition variable */ -int -SDL_CondSignal(SDL_cond * cond) -{ - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - SDL_LockMutex(cond->lock); - if (cond->waiting > cond->signals) { - ++cond->signals; - SDL_SemPost(cond->wait_sem); - SDL_UnlockMutex(cond->lock); - SDL_SemWait(cond->wait_done); - } else { - SDL_UnlockMutex(cond->lock); - } - - return 0; -} - -/* Restart all threads that are waiting on the condition variable */ -int -SDL_CondBroadcast(SDL_cond * cond) -{ - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - SDL_LockMutex(cond->lock); - if (cond->waiting > cond->signals) { - int i, num_waiting; - - num_waiting = (cond->waiting - cond->signals); - cond->signals = cond->waiting; - for (i = 0; i < num_waiting; ++i) { - SDL_SemPost(cond->wait_sem); - } - /* Now all released threads are blocked here, waiting for us. - Collect them all (and win fabulous prizes!) :-) - */ - SDL_UnlockMutex(cond->lock); - for (i = 0; i < num_waiting; ++i) { - SDL_SemWait(cond->wait_done); - } - } else { - SDL_UnlockMutex(cond->lock); - } - - return 0; -} - -/* Wait on the condition variable for at most 'ms' milliseconds. - The mutex must be locked before entering this function! - The mutex is unlocked during the wait, and locked again after the wait. - -Typical use: - -Thread A: - SDL_LockMutex(lock); - while ( ! condition ) { - SDL_CondWait(cond); - } - SDL_UnlockMutex(lock); - -Thread B: - SDL_LockMutex(lock); - ... - condition = true; - ... - SDL_UnlockMutex(lock); - */ -int -SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) -{ - int retval; - - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* Obtain the protection mutex, and increment the number of waiters. - This allows the signal mechanism to only perform a signal if there - are waiting threads. - */ - SDL_LockMutex(cond->lock); - ++cond->waiting; - SDL_UnlockMutex(cond->lock); - - /* Unlock the mutex, as is required by condition variable semantics */ - SDL_UnlockMutex(mutex); - - /* Wait for a signal */ - if (ms == SDL_MUTEX_MAXWAIT) { - retval = SDL_SemWait(cond->wait_sem); - } else { - retval = SDL_SemWaitTimeout(cond->wait_sem, ms); - } - - /* Let the signaler know we have completed the wait, otherwise - the signaler can race ahead and get the condition semaphore - if we are stopped between the mutex unlock and semaphore wait, - giving a deadlock. See the following URL for details: - http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html - */ - SDL_LockMutex(cond->lock); - if (cond->signals > 0) { - /* If we timed out, we need to eat a condition signal */ - if (retval > 0) { - SDL_SemWait(cond->wait_sem); - } - /* We always notify the signal thread that we are done */ - SDL_SemPost(cond->wait_done); - - /* Signal handshake complete */ - --cond->signals; - } - --cond->waiting; - SDL_UnlockMutex(cond->lock); - - /* Lock the mutex, as is required by condition variable semantics */ - SDL_LockMutex(mutex); - - return retval; -} - -/* Wait on the condition variable forever */ -int -SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) -{ - return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/nds/SDL_syscond_c.h b/src/thread/nds/SDL_syscond_c.h deleted file mode 100644 index d842d5929..000000000 --- a/src/thread/nds/SDL_syscond_c.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syscond_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif diff --git a/src/thread/nds/SDL_sysmutex.c b/src/thread/nds/SDL_sysmutex.c deleted file mode 100644 index ffdecc808..000000000 --- a/src/thread/nds/SDL_sysmutex.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_sysmutex.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif - -/* An implementation of mutexes using semaphores */ - -#include -#include - -#include "SDL_error.h" -#include "SDL_thread.h" -#include "SDL_systhread_c.h" - - -struct SDL_mutex -{ - int recursive; - SDL_threadID owner; - SDL_sem *sem; -}; - -/* Create a mutex */ -SDL_mutex * -SDL_CreateMutex(void) -{ - SDL_mutex *mutex; - - /* Allocate mutex memory */ - mutex = (SDL_mutex *) malloc(sizeof(*mutex)); - if (mutex) { - /* Create the mutex semaphore, with initial value 1 */ - mutex->sem = SDL_CreateSemaphore(1); - mutex->recursive = 0; - mutex->owner = 0; - if (!mutex->sem) { - free(mutex); - mutex = NULL; - } - } else { - SDL_OutOfMemory(); - } - return mutex; -} - -/* Free the mutex */ -void -SDL_DestroyMutex(SDL_mutex * mutex) -{ - if (mutex) { - if (mutex->sem) { - SDL_DestroySemaphore(mutex->sem); - } - free(mutex); - } -} - -/* Lock the mutex */ -int -SDL_LockMutex(SDL_mutex * mutex) -{ -#ifdef DISABLE_THREADS - return 0; -#else - SDL_threadID this_thread; - - if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - this_thread = SDL_ThreadID(); - if (mutex->owner == this_thread) { - ++mutex->recursive; - } else { - /* The order of operations is important. - We set the locking thread id after we obtain the lock - so unlocks from other threads will fail. - */ - SDL_SemWait(mutex->sem); - mutex->owner = this_thread; - mutex->recursive = 0; - } - - return 0; -#endif /* DISABLE_THREADS */ -} - -/* Try Lock the mutex */ -int -SDL_TryLockMutex(SDL_mutex * mutex) -{ -#ifdef DISABLE_THREADS - return 0; -#else - int retval = 0; - SDL_threadID this_thread; - - if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - this_thread = SDL_ThreadID(); - if (mutex->owner == this_thread) { - ++mutex->recursive; - } else { - /* The order of operations is important. - We set the locking thread id after we obtain the lock - so unlocks from other threads will fail. - */ - retval = SDL_SemTryWait(mutex->sem); - if (ret == 0) { - mutex->owner = this_thread; - mutex->recursive = 0; - } - } - - return retval; -#endif /* DISABLE_THREADS */ -} - -/* Unlock the mutex */ -int -SDL_UnlockMutex(SDL_mutex * mutex) -{ -#ifdef DISABLE_THREADS - return 0; -#else - if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - /* If we don't own the mutex, we can't unlock it */ - if (SDL_ThreadID() != mutex->owner) { - SDL_SetError("mutex not owned by this thread"); - return -1; - } - - if (mutex->recursive) { - --mutex->recursive; - } else { - /* The order of operations is important. - First reset the owner so another thread doesn't lock - the mutex and set the ownership before we reset it, - then release the lock semaphore. - */ - mutex->owner = 0; - SDL_SemPost(mutex->sem); - } - return 0; -#endif /* DISABLE_THREADS */ -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/nds/SDL_sysmutex_c.h b/src/thread/nds/SDL_sysmutex_c.h deleted file mode 100644 index d310519af..000000000 --- a/src/thread/nds/SDL_sysmutex_c.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_sysmutex_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif diff --git a/src/thread/nds/SDL_syssem.c b/src/thread/nds/SDL_syssem.c deleted file mode 100644 index 788fc9223..000000000 --- a/src/thread/nds/SDL_syssem.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syssem.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif - -/* An implementation of semaphores using mutexes and condition variables */ - -#include - -#include "SDL_error.h" -#include "SDL_timer.h" -#include "SDL_thread.h" -#include "SDL_systhread_c.h" - - -#ifdef DISABLE_THREADS - -SDL_sem * -SDL_CreateSemaphore(Uint32 initial_value) -{ - SDL_SetError("SDL not configured with thread support"); - return (SDL_sem *) 0; -} - -void -SDL_DestroySemaphore(SDL_sem * sem) -{ - return; -} - -int -SDL_SemTryWait(SDL_sem * sem) -{ - SDL_SetError("SDL not configured with thread support"); - return -1; -} - -int -SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) -{ - SDL_SetError("SDL not configured with thread support"); - return -1; -} - -int -SDL_SemWait(SDL_sem * sem) -{ - SDL_SetError("SDL not configured with thread support"); - return -1; -} - -Uint32 -SDL_SemValue(SDL_sem * sem) -{ - return 0; -} - -int -SDL_SemPost(SDL_sem * sem) -{ - SDL_SetError("SDL not configured with thread support"); - return -1; -} - -#else - -struct SDL_semaphore -{ - Uint32 count; - Uint32 waiters_count; - SDL_mutex *count_lock; - SDL_cond *count_nonzero; -}; - -SDL_sem * -SDL_CreateSemaphore(Uint32 initial_value) -{ - SDL_sem *sem; - - sem = (SDL_sem *) malloc(sizeof(*sem)); - if (!sem) { - SDL_OutOfMemory(); - return (0); - } - sem->count = initial_value; - sem->waiters_count = 0; - - sem->count_lock = SDL_CreateMutex(); - sem->count_nonzero = SDL_CreateCond(); - if (!sem->count_lock || !sem->count_nonzero) { - SDL_DestroySemaphore(sem); - return (0); - } - - return (sem); -} - -/* WARNING: - You cannot call this function when another thread is using the semaphore. -*/ -void -SDL_DestroySemaphore(SDL_sem * sem) -{ - if (sem) { - sem->count = 0xFFFFFFFF; - while (sem->waiters_count > 0) { - SDL_CondSignal(sem->count_nonzero); - SDL_Delay(10); - } - SDL_DestroyCond(sem->count_nonzero); - SDL_LockMutex(sem->count_lock); - SDL_UnlockMutex(sem->count_lock); - SDL_DestroyMutex(sem->count_lock); - free(sem); - } -} - -int -SDL_SemTryWait(SDL_sem * sem) -{ - int retval; - - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = SDL_MUTEX_TIMEDOUT; - SDL_LockMutex(sem->count_lock); - if (sem->count > 0) { - --sem->count; - retval = 0; - } - SDL_UnlockMutex(sem->count_lock); - - return retval; -} - -int -SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) -{ - int retval; - - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - /* A timeout of 0 is an easy case */ - if (timeout == 0) { - return SDL_SemTryWait(sem); - } - - SDL_LockMutex(sem->count_lock); - ++sem->waiters_count; - retval = 0; - while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) { - retval = SDL_CondWaitTimeout(sem->count_nonzero, - sem->count_lock, timeout); - } - --sem->waiters_count; - --sem->count; - SDL_UnlockMutex(sem->count_lock); - - return retval; -} - -int -SDL_SemWait(SDL_sem * sem) -{ - return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); -} - -Uint32 -SDL_SemValue(SDL_sem * sem) -{ - Uint32 value; - - value = 0; - if (sem) { - SDL_LockMutex(sem->count_lock); - value = sem->count; - SDL_UnlockMutex(sem->count_lock); - } - return value; -} - -int -SDL_SemPost(SDL_sem * sem) -{ - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - SDL_LockMutex(sem->count_lock); - if (sem->waiters_count > 0) { - SDL_CondSignal(sem->count_nonzero); - } - ++sem->count; - SDL_UnlockMutex(sem->count_lock); - - return 0; -} - -#endif /* DISABLE_THREADS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/nds/SDL_syssem_c.h b/src/thread/nds/SDL_syssem_c.h deleted file mode 100644 index b12f9ce6d..000000000 --- a/src/thread/nds/SDL_syssem_c.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syssem_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif diff --git a/src/thread/nds/SDL_systhread.c b/src/thread/nds/SDL_systhread.c deleted file mode 100644 index e94dcd774..000000000 --- a/src/thread/nds/SDL_systhread.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_systhread.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif - -/* Thread management routines for SDL */ - -#include "SDL_error.h" -#include "SDL_thread.h" -#include "../SDL_systhread.h" - -int -SDL_SYS_CreateThread(SDL_Thread * thread, void *args) -{ - SDL_SetError("Threads are not supported on this platform"); - return (-1); -} - -void -SDL_SYS_SetupThread(const char *name) -{ - return; -} - -SDL_threadID -SDL_ThreadID(void) -{ - return (0); -} - -void -SDL_SYS_WaitThread(SDL_Thread * thread) -{ - return; -} - -int -SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) -{ - return (0); -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/nds/SDL_systhread_c.h b/src/thread/nds/SDL_systhread_c.h deleted file mode 100644 index 8aaf10d9d..000000000 --- a/src/thread/nds/SDL_systhread_c.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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. -*/ - -/* Stub until we implement threads on this platform */ -typedef int SYS_ThreadHandle; - -#ifndef DISABLE_THREADS -#define DISABLE_THREADS -#endif diff --git a/src/timer/nds/SDL_systimer.c b/src/timer/nds/SDL_systimer.c deleted file mode 100644 index a44695593..000000000 --- a/src/timer/nds/SDL_systimer.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#ifdef SDL_TIMER_NDS - -#include -#include - -#include "SDL_timer.h" - -/* Will wrap after 49 days. Shouldn't be an issue. */ -static volatile Uint32 timer_ticks; - -static void -NDS_TimerInterrupt(void) -{ - timer_ticks++; -} - -void -SDL_StartTicks(void) -{ - timer_ticks = 0; - - /* Set timer 2 to fire every ms. */ - timerStart(2, ClockDivider_1024, TIMER_FREQ_1024(1000), NDS_TimerInterrupt); -} - -Uint32 -SDL_GetTicks(void) -{ - return timer_ticks; -} - -Uint64 -SDL_GetPerformanceCounter(void) -{ - return SDL_GetTicks(); -} - -Uint64 -SDL_GetPerformanceFrequency(void) -{ - return 1000; -} - -void -SDL_Delay(Uint32 ms) -{ - Uint32 start = SDL_GetTicks(); - while (1) { - if ((SDL_GetTicks() - start) >= ms) - break; - } -} - -#endif /* SDL_TIMER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 20c90e9c8..b51c5e4cd 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -341,9 +341,6 @@ extern VideoBootStrap BWINDOW_bootstrap; #if SDL_VIDEO_DRIVER_PANDORA extern VideoBootStrap PND_bootstrap; #endif -#if SDL_VIDEO_DRIVER_NDS -extern VideoBootStrap NDS_bootstrap; -#endif #if SDL_VIDEO_DRIVER_UIKIT extern VideoBootStrap UIKIT_bootstrap; #endif diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 4ca466384..1877a5870 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -69,9 +69,6 @@ static VideoBootStrap *bootstrap[] = { #if SDL_VIDEO_DRIVER_PANDORA &PND_bootstrap, #endif -#if SDL_VIDEO_DRIVER_NDS - &NDS_bootstrap, -#endif #if SDL_VIDEO_DRIVER_UIKIT &UIKIT_bootstrap, #endif diff --git a/src/video/nds/SDL_ndsevents.c b/src/video/nds/SDL_ndsevents.c deleted file mode 100644 index 97933a46a..000000000 --- a/src/video/nds/SDL_ndsevents.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#if SDL_VIDEO_DRIVER_NDS - -#include -#include -#include - -#include "../../events/SDL_events_c.h" - -#include "SDL_ndsvideo.h" -#include "SDL_ndsevents_c.h" - -void -NDS_PumpEvents(_THIS) -{ - scanKeys(); - /* TODO: defer click-age */ - if (keysDown() & KEY_TOUCH) { - SDL_SendMouseButton(NULL, 0, SDL_PRESSED, 0); - } else if (keysUp() & KEY_TOUCH) { - SDL_SendMouseButton(NULL, 0, SDL_RELEASED, 0); - } - if (keysHeld() & KEY_TOUCH) { - touchPosition t; - - touchRead(&t); - SDL_SendMouseMotion(NULL, 0, 0, t.px, t.py); - } -} - -#endif /* SDL_VIDEO_DRIVER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndsevents_c.h b/src/video/nds/SDL_ndsevents_c.h deleted file mode 100644 index 5c222a598..000000000 --- a/src/video/nds/SDL_ndsevents_c.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#include "SDL_ndsvideo.h" - -extern void NDS_PumpEvents(_THIS); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndsvideo.c b/src/video/nds/SDL_ndsvideo.c deleted file mode 100644 index 9fd412442..000000000 --- a/src/video/nds/SDL_ndsvideo.c +++ /dev/null @@ -1,401 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#if SDL_VIDEO_DRIVER_NDS - -/* SDL Nintendo DS video driver implementation */ - -#include -#include -#include -#include - -#include "SDL_video.h" -#include "SDL_ndsvideo.h" -#include "SDL_ndsevents_c.h" -#include "../../render/SDL_sysrender.h" -#include "../../render/nds/SDL_libgl2D.h" -#include "SDL_log.h" - -#define NDSVID_DRIVER_NAME "nds" - -static SDL_DisplayMode display_modes[] = -{ - /* Only one screen */ - { - .format = SDL_PIXELFORMAT_ABGR1555, - .w = SCREEN_WIDTH, - .h = SCREEN_HEIGHT, - .refresh_rate = 60, - }, - - /* Aggregated display (two screens) with no gap. */ - { - .format = SDL_PIXELFORMAT_ABGR1555, - .w = SCREEN_WIDTH, - .h = 2*SCREEN_HEIGHT+SCREEN_GAP, - .refresh_rate = 60, - }, - - /* Aggregated display (two screens) with a gap. */ - { - .format = SDL_PIXELFORMAT_ABGR1555, - .w = SCREEN_WIDTH, - .h = 2*SCREEN_HEIGHT, - .refresh_rate = 60, - }, - - /* Last entry */ - { - .w = 0, - } -}; - -/* This function must not be optimized nor inlined, else the pointer - * to the message will be in the wrong register, and the emulator won't - * find the string. */ -__attribute__ ((noinline, optimize (0))) -static void NDS_DebugOutput2(const char* message) -{ -#ifdef __thumb__ - asm volatile ("swi #0xfc"); -#else - asm volatile ("swi #0xfc0000"); -#endif -} - -static void NDS_DebugOutput(void *userdata, int category, SDL_LogPriority priority, const char *message) -{ - NDS_DebugOutput2(message); -} - -/* SDL NDS driver bootstrap functions */ -static int NDS_Available(void) -{ - return 1; /* always here */ -} - -#ifndef USE_HW_RENDERER -static int NDS_CreateWindowFramebuffer(_THIS, SDL_Window *window, - Uint32 *format, void **pixels, - int *pitch) -{ - struct NDS_WindowData *wdata; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - const SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - const SDL_DisplayMode *mode = display->driverdata; - const Uint32 fmt = mode->format; - - if (fmt != SDL_PIXELFORMAT_ABGR1555) { - SDL_SetError("Unsupported pixel format (%x)", fmt); - return -1; - } - - if (!SDL_PixelFormatEnumToMasks - (fmt, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { - SDL_SetError("Unknown texture format"); - return -1; - } - - wdata = SDL_calloc(1, sizeof(struct NDS_WindowData)); - if (!wdata) { - SDL_OutOfMemory(); - return -1; - } - - if (bpp == 8) { - wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH; - } else { - wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH*2; - } - wdata->pixels = SDL_calloc(1, wdata->pixels_length); - if (!wdata->pixels) { - SDL_free(wdata); - SDL_SetError("Not enough memory"); - return -1; - } - - if (bpp == 8) { - wdata->main.bg_id = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0, 0); - wdata->sub.bg_id = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0); - - wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH; - wdata->main.pixels = wdata->pixels; - - wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH; - wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length; /* or ...+SCREEN_GAP */ - - } else { - wdata->main.bg_id = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0); - wdata->sub.bg_id = bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); - - wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH*2; - wdata->main.pixels = wdata->pixels; - - wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH*2; - wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length; /* or ...+SCREEN_GAP */ - } - - wdata->pitch = (window->w) * ((bpp+1) / 8); - wdata->bpp = bpp; - wdata->rotate = 0; - wdata->scale.x = 0x100; - wdata->scale.y = 0x100; - wdata->scroll.x = 0; - wdata->scroll.y = 0; - - wdata->main.vram_pixels = bgGetGfxPtr(wdata->main.bg_id); - wdata->sub.vram_pixels = bgGetGfxPtr(wdata->sub.bg_id); - -#if 0 - bgSetCenter(wdata->main.bg_id, 0, 0); - bgSetRotateScale(wdata->main.bg_id, wdata->rotate, wdata->scale.x, - wdata->scale.y); - bgSetScroll(wdata->main.bg_id, wdata->scroll.x, wdata->scroll.y); -#endif - -#if 0 - bgSetCenter(wdata->sub.bg_id, 0, 0); - bgSetRotateScale(wdata->sub.bg_id, wdata->rotate, wdata->scale.x, - wdata->scale.y); - bgSetScroll(wdata->sub.bg_id, wdata->scroll.x, wdata->scroll.y); -#endif - - bgUpdate(); - - *format = fmt; - *pixels = wdata->pixels; - *pitch = wdata->pitch; - - window->driverdata = wdata; - - return 0; -} - -static int NDS_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects) -{ - struct NDS_WindowData *wdata = window->driverdata; - - /* Copy everything. TODO: use rects/numrects. */ - DC_FlushRange(wdata->pixels, wdata->pixels_length); - - swiWaitForVBlank(); - - dmaCopy(wdata->main.pixels, wdata->main.vram_pixels, wdata->main.length); - dmaCopy(wdata->sub.pixels, wdata->sub.vram_pixels, wdata->sub.length); - - return 0; -} - -static void NDS_DestroyWindowFramebuffer(_THIS, SDL_Window *window) -{ - struct NDS_WindowData *wdata = window->driverdata; - - SDL_free(wdata->pixels); - SDL_free(wdata); -} -#endif - -#ifdef USE_HW_RENDERER -/* Set up a 2D layer construced of bitmap sprites. This holds the - * image when rendering to the top screen. From libnds example. - */ -static void initSubSprites(void) -{ - oamInit(&oamSub, SpriteMapping_Bmp_2D_256, false); - - int x = 0; - int y = 0; - - int id = 0; - - //set up a 4x3 grid of 64x64 sprites to cover the screen - for(y = 0; y < 3; y++) - for(x = 0; x < 4; x++) - { - oamSub.oamMemory[id].attribute[0] = ATTR0_BMP | ATTR0_SQUARE | (64 * y); - oamSub.oamMemory[id].attribute[1] = ATTR1_SIZE_64 | (64 * x); - oamSub.oamMemory[id].attribute[2] = ATTR2_ALPHA(1) | (8 * 32 * y) | (8 * x); - id++; - } - - swiWaitForVBlank(); - - oamUpdate(&oamSub); -} -#endif - -static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) -{ - display->driverdata = mode->driverdata; - - powerOn(POWER_ALL_2D); - -#ifdef USE_HW_RENDERER - - videoSetMode(MODE_5_3D); - videoSetModeSub(MODE_5_2D); - - /* initialize gl2d */ - glScreen2D(); - glBegin2D(); - - vramSetBankA(VRAM_A_TEXTURE); - vramSetBankB(VRAM_B_TEXTURE ); - vramSetBankC(VRAM_C_SUB_BG_0x06200000); - vramSetBankE(VRAM_E_TEX_PALETTE); - - // sub sprites hold the bottom image when 3D directed to top - initSubSprites(); - - // sub background holds the top image when 3D directed to bottom - bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); -#else - - /* Select mode 5 for both screens. Can do Extended Rotation - * Background on both (BG 2 and 3). */ - videoSetMode(MODE_5_2D); - videoSetModeSub(MODE_5_2D); - - vramSetBankA(VRAM_A_MAIN_BG_0x06000000); - vramSetBankB(VRAM_B_TEXTURE ); - vramSetBankC(VRAM_C_SUB_BG_0x06200000); - vramSetBankE(VRAM_E_TEX_PALETTE); - -#endif - - return 0; -} - -void NDS_GetDisplayModes(_THIS, SDL_VideoDisplay * display) -{ - SDL_DisplayMode *mode; - - for (mode = display_modes; mode->w; mode++) { - mode->driverdata = mode; /* point back to self */ - SDL_AddDisplayMode(display, mode); - } -} - -static int NDS_VideoInit(_THIS) -{ - SDL_VideoDisplay display; - SDL_DisplayMode mode; - - SDL_zero(mode); - - mode.format = SDL_PIXELFORMAT_UNKNOWN; // should be SDL_PIXELFORMAT_ABGR1555; - mode.w = SCREEN_WIDTH; - mode.h = 2*SCREEN_HEIGHT+SCREEN_GAP; - mode.refresh_rate = 60; - - SDL_zero(display); - - display.desktop_mode = mode; - - SDL_AddVideoDisplay(&display); - - return 0; -} - -static void NDS_VideoQuit(_THIS) -{ - videoSetMode(DISPLAY_SCREEN_OFF); - videoSetModeSub(DISPLAY_SCREEN_OFF); - vramSetBankA(VRAM_A_LCD); - vramSetBankB(VRAM_B_LCD); - vramSetBankC(VRAM_C_LCD); - vramSetBankD(VRAM_D_LCD); - vramSetBankE(VRAM_E_LCD); - vramSetBankF(VRAM_F_LCD); - vramSetBankG(VRAM_G_LCD); - vramSetBankH(VRAM_H_LCD); - vramSetBankI(VRAM_I_LCD); -} - -static void NDS_DeleteDevice(SDL_VideoDevice * device) -{ - SDL_free(device); -} - -static SDL_VideoDevice *NDS_CreateDevice(int devindex) -{ - SDL_VideoDevice *device; - - fatInitDefault(); - - /* Initialize all variables that we clean on shutdown */ - device = SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { - SDL_OutOfMemory(); - return NULL; - } - - device->driverdata = SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { - SDL_free(device); - SDL_OutOfMemory(); - return NULL; - } - - /* Set the function pointers */ - device->VideoInit = NDS_VideoInit; - device->VideoQuit = NDS_VideoQuit; - device->GetDisplayModes = NDS_GetDisplayModes; - device->SetDisplayMode = NDS_SetDisplayMode; - device->CreateWindow = NDS_CreateWindow; -#ifndef USE_HW_RENDERER - device->CreateWindowFramebuffer = NDS_CreateWindowFramebuffer; - device->UpdateWindowFramebuffer = NDS_UpdateWindowFramebuffer; - device->DestroyWindowFramebuffer = NDS_DestroyWindowFramebuffer; -#endif - device->PumpEvents = NDS_PumpEvents; - device->free = NDS_DeleteDevice; - - /* Set the debug output. Use only under an emulator. Will crash the DS. */ -#if 0 - SDL_LogSetOutputFunction(NDS_DebugOutput, NULL); -#endif - - return device; -} - -VideoBootStrap NDS_bootstrap = { - NDSVID_DRIVER_NAME, "SDL NDS video driver", - NDS_Available, NDS_CreateDevice -}; - -double SDLCALL SDL_pow(double x, double y) -{ - static int once = 1; - if (once) { - SDL_Log("SDL_pow called but not supported on this platform"); - once = 0; - } - return 0; -} - -#endif /* SDL_VIDEO_DRIVER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndsvideo.h b/src/video/nds/SDL_ndsvideo.h deleted file mode 100644 index d0795c064..000000000 --- a/src/video/nds/SDL_ndsvideo.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#ifndef _SDL_ndsvideo_h -#define _SDL_ndsvideo_h - -#include "../SDL_sysvideo.h" - -#include "SDL_ndswindow.h" - -#define SCREEN_GAP 92 /* line-equivalent gap between the 2 screens */ - -/* Per Window information. */ -struct NDS_WindowData { - struct { - int bg_id; - void *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */ - void *pixels; /* area in user frame buffer */ - int length; - } main, sub; - - int pitch, bpp; /* useful information about the texture */ - struct { - int x, y; - } scale; /* x/y stretch (24.8 fixed point) */ - - struct { - int x, y; - } scroll; /* x/y offset */ - int rotate; /* -32768 to 32767, texture rotation */ - - /* user frame buffer - todo: better way to do double buffering */ - void *pixels; - int pixels_length; -}; - - -#endif /* _SDL_ndsvideo_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndswindow.c b/src/video/nds/SDL_ndswindow.c deleted file mode 100644 index a76c08f05..000000000 --- a/src/video/nds/SDL_ndswindow.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#if SDL_VIDEO_DRIVER_NDS - -#include "SDL_ndsvideo.h" - - -int NDS_CreateWindow(_THIS, SDL_Window * window) -{ - /* Nintendo DS windows are always fullscreen */ - window->flags |= SDL_WINDOW_FULLSCREEN; - return 0; -} - -#endif /* SDL_VIDEO_DRIVER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndswindow.h b/src/video/nds/SDL_ndswindow.h deleted file mode 100644 index 19bd49290..000000000 --- a/src/video/nds/SDL_ndswindow.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#ifndef _SDL_ndswindow_h -#define _SDL_ndswindow_h - -extern int NDS_CreateWindow(_THIS, SDL_Window * window); - -#endif /* _SDL_ndswindow_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/nds-test-progs/Makefile b/test/nds-test-progs/Makefile deleted file mode 100644 index ab7725a67..000000000 --- a/test/nds-test-progs/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -SUBDIRS:= $(shell ls | egrep -v '^(CVS)$$') - -all: - for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; - -clean: - for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; diff --git a/test/nds-test-progs/general/Makefile b/test/nds-test-progs/general/Makefile deleted file mode 100755 index 0dcaac884..000000000 --- a/test/nds-test-progs/general/Makefile +++ /dev/null @@ -1,131 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork - -# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD -# *insists* it has a FPU or VFP, and it won't take no for an answer! -CFLAGS := -save-temps -g -Wall -O0\ - -mcpu=arm9tdmi -mtune=arm9tdmi \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -lSDL -lfat -lnds9 - - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).ds.gba : $(OUTPUT).nds -$(OUTPUT).nds : $(OUTPUT).arm9 -$(OUTPUT).arm9 : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -%.pcx.o : %.pcx -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/general/source/main.c b/test/nds-test-progs/general/source/main.c deleted file mode 100644 index 087dc4da1..000000000 --- a/test/nds-test-progs/general/source/main.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Really basic sample for the NDS. - * - * Fills a rectangle increasingly smaller of random color every time a - * button (a, b, x, y) is pressed. - * - * The behaviour whether SDL is compiled with HW support or not (see - * USE_HW_RENDERER in Makefile.ds). - * - * In framebuffer mode, the old rectangles stay because the screen has - * not been cleared. - * - * In accelerated mode, old the last rectangle is visible. - * - * No text is displayed. - */ - -#include -#if defined(NDS) || defined(__NDS__) || defined (__NDS) -#include -#include -#else -#define consoleDemoInit() -#define fatInitDefault() -#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3)) -#endif - -int main(void) -{ - SDL_Window *window; - SDL_Renderer *renderer; - SDL_Joystick *stick; - SDL_Event event; - SDL_Rect rect = { 0, 0, 256, 192 }; - int i; - - consoleDemoInit(); - puts("Hello world! Initializing FAT..."); - - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { - puts("# error initializing SDL"); - puts(SDL_GetError()); - return 1; - } - puts("* initialized SDL"); - - if (SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_ACCELERATED, &window, &renderer) < 0 && - SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_SOFTWARE, &window, &renderer) < 0) { - exit(1); - } - - stick = SDL_JoystickOpen(0); - if (stick == NULL) { - puts("# error opening joystick"); - puts(SDL_GetError()); - } - puts("* opened joystick"); - - SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); - SDL_RenderFillRect(renderer, &rect); - SDL_RenderPresent(renderer); - - while (1) - while (SDL_PollEvent(&event)) - switch (event.type) { - case SDL_JOYBUTTONDOWN: - - SDL_SetRenderDrawColor(renderer, rand(), rand(), rand(), SDL_ALPHA_OPAQUE); - SDL_RenderFillRect(renderer, &rect); - SDL_RenderPresent(renderer); - if (rect.w > 8) { - rect.x += 4; - rect.y += 3; - rect.w -= 8; - rect.h -= 6; - } - /* - printf("button %d pressed at %d ticks\n", - event.jbutton.button, SDL_GetTicks()); - */ - break; - case SDL_QUIT: - SDL_Quit(); - return 0; - default: - break; - } - return 0; -} diff --git a/test/nds-test-progs/testscale/Makefile b/test/nds-test-progs/testscale/Makefile deleted file mode 100644 index 31a123220..000000000 --- a/test/nds-test-progs/testscale/Makefile +++ /dev/null @@ -1,147 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -# DATA is a list of directories containing binary files embedded using bin2o -# GRAPHICS is a list of directories containing image files to be converted with grit -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source -INCLUDES := include ../.. -DATA := data -GRAPHICS := gfx - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s - -CFLAGS := -g -Wall -O2\ - -fomit-frame-pointer\ - -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project (order is important) -#--------------------------------------------------------------------------------- -LIBS := -lSDL -lfat -lnds9 - - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ - $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := ../../../common.c ../../../testscale.c - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PNGFILES:.png=.o) \ - $(BMPFILES:.bmp=.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/SDL - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).nds : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - $(bin2o) - -#--------------------------------------------------------------------------------- -# This rule creates assembly source files using grit -# grit takes an image file and a .grit describing how the file is to be processed -# add additional rules like this for each image extension -# you use in the graphics folders -#--------------------------------------------------------------------------------- -%.s %.h : %.bmp %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - -#--------------------------------------------------------------------------------- -%.s %.h : %.png %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/testsprite2/Makefile b/test/nds-test-progs/testsprite2/Makefile deleted file mode 100644 index b765e6c84..000000000 --- a/test/nds-test-progs/testsprite2/Makefile +++ /dev/null @@ -1,152 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -# DATA is a list of directories containing binary files embedded using bin2o -# GRAPHICS is a list of directories containing image files to be converted with grit -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source -INCLUDES := include ../.. -DATA := data -GRAPHICS := gfx - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s - -CFLAGS := -g -Wall -O2\ - -fomit-frame-pointer\ - -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project (order is important) -#--------------------------------------------------------------------------------- -LIBS := -lSDL -lfat -lnds9 - - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ - $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := ../../../common.c ../../../testsprite2.c -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png))) -BMPFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.bmp))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PNGFILES:.png=.o) \ - $(BMPFILES:.bmp=.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/SDL - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).nds : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - $(bin2o) - -#--------------------------------------------------------------------------------- -# This rule creates assembly source files using grit -# grit takes an image file and a .grit describing how the file is to be processed -# add additional rules like this for each image extension -# you use in the graphics folders -#--------------------------------------------------------------------------------- -%.s %.h : %.bmp %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - -#--------------------------------------------------------------------------------- -%.s %.h : %.png %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/testspriteminimal/Makefile b/test/nds-test-progs/testspriteminimal/Makefile deleted file mode 100644 index e54101f9e..000000000 --- a/test/nds-test-progs/testspriteminimal/Makefile +++ /dev/null @@ -1,147 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -# DATA is a list of directories containing binary files embedded using bin2o -# GRAPHICS is a list of directories containing image files to be converted with grit -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source -INCLUDES := include -DATA := data -GRAPHICS := gfx - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s - -CFLAGS := -g -Wall -O2\ - -fomit-frame-pointer\ - -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project (order is important) -#--------------------------------------------------------------------------------- -LIBS := -lSDL -lfat -lnds9 - - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ - $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := ../../../testspriteminimal.c - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PNGFILES:.png=.o) \ - $(BMPFILES:.bmp=.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/SDL - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).nds : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - $(bin2o) - -#--------------------------------------------------------------------------------- -# This rule creates assembly source files using grit -# grit takes an image file and a .grit describing how the file is to be processed -# add additional rules like this for each image extension -# you use in the graphics folders -#--------------------------------------------------------------------------------- -%.s %.h : %.bmp %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - -#--------------------------------------------------------------------------------- -%.s %.h : %.png %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/test/testspriteminimal.c b/test/testspriteminimal.c index 48e996c01..76244c282 100644 --- a/test/testspriteminimal.c +++ b/test/testspriteminimal.c @@ -17,13 +17,8 @@ #include "SDL.h" -#ifdef __NDS__ -#define WINDOW_WIDTH 256 -#define WINDOW_HEIGHT (2*192) -#else #define WINDOW_WIDTH 640 #define WINDOW_HEIGHT 480 -#endif #define NUM_SPRITES 100 #define MAX_SPEED 1 From e64abd6e474515f6395ebdecacdf0a70366cf9cf Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 17 Mar 2013 09:45:40 -0700 Subject: [PATCH 100/151] The platform define for the PSP is __PSP__ --- include/SDL_platform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/SDL_platform.h b/include/SDL_platform.h index d37964dfe..d03bd3866 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -119,8 +119,8 @@ #define __WIN32__ 1 #endif #if defined(__PSP__) -#undef __PLAYSTATIONPORTABLE__ -#define __PLAYSTATIONPORTABLE__ 1 +#undef __PSP__ +#define __PSP__ 1 #endif #include "begin_code.h" From 63b082da83a89d91edfc1655ca00c9dbcfc61239 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 17 Mar 2013 09:47:25 -0700 Subject: [PATCH 101/151] Removed unused window size constants --- test/testrendercopyex.c | 2 -- test/testrendertarget.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/test/testrendercopyex.c b/test/testrendercopyex.c index 3d9ee9f47..dca3ee172 100644 --- a/test/testrendercopyex.c +++ b/test/testrendercopyex.c @@ -17,8 +17,6 @@ #include "SDL_test_common.h" -#define WINDOW_WIDTH 640 -#define WINDOW_HEIGHT 480 static SDLTest_CommonState *state; diff --git a/test/testrendertarget.c b/test/testrendertarget.c index c43d14ff9..b7fd11c88 100644 --- a/test/testrendertarget.c +++ b/test/testrendertarget.c @@ -17,8 +17,6 @@ #include "SDL_test_common.h" -#define WINDOW_WIDTH 640 -#define WINDOW_HEIGHT 480 static SDLTest_CommonState *state; From fecccf1718911ed55feb6a84bef70bc152f84cc0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 19 Mar 2013 21:53:33 -0700 Subject: [PATCH 102/151] Fixed bug 1763 - Constify SDL_UpdateWindowSurfaceRects() Ryan C. Gordon With this function... SDL_UpdateWindowSurfaceRects(SDL_Window * window, SDL_Rect * rects, int numrects); ...is there any reason rects isn't "const SDL_Rect *" ? --- include/SDL_video.h | 2 +- src/video/SDL_rect.c | 2 +- src/video/SDL_rect_c.h | 2 +- src/video/SDL_sysvideo.h | 2 +- src/video/SDL_video.c | 4 ++-- src/video/bwindow/SDL_bframebuffer.cc | 2 +- src/video/bwindow/SDL_bframebuffer.h | 2 +- src/video/dummy/SDL_nullframebuffer.c | 2 +- src/video/dummy/SDL_nullframebuffer_c.h | 2 +- src/video/windows/SDL_windowsframebuffer.c | 2 +- src/video/windows/SDL_windowsframebuffer.h | 2 +- src/video/x11/SDL_x11framebuffer.c | 2 +- src/video/x11/SDL_x11framebuffer.h | 2 +- 13 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/SDL_video.h b/include/SDL_video.h index d20c7c27c..4873da39b 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -694,7 +694,7 @@ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window); * \sa SDL_UpdateWindowSurfaceRect() */ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window, - SDL_Rect * rects, + const SDL_Rect * rects, int numrects); /** diff --git a/src/video/SDL_rect.c b/src/video/SDL_rect.c index e57381236..23894dc3d 100644 --- a/src/video/SDL_rect.c +++ b/src/video/SDL_rect.c @@ -412,7 +412,7 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, SDL_bool SDL_GetSpanEnclosingRect(int width, int height, - int numrects, SDL_Rect * rects, SDL_Rect *span) + int numrects, const SDL_Rect * rects, SDL_Rect *span) { int i; int span_y1, span_y2; diff --git a/src/video/SDL_rect_c.h b/src/video/SDL_rect_c.h index b360a54c2..a7fd49cf8 100644 --- a/src/video/SDL_rect_c.h +++ b/src/video/SDL_rect_c.h @@ -20,6 +20,6 @@ */ #include "SDL_config.h" -extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, SDL_Rect * rects, SDL_Rect *span); +extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, const SDL_Rect * rects, SDL_Rect *span); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index b51c5e4cd..4874014d7 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -199,7 +199,7 @@ struct SDL_VideoDevice void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed); void (*DestroyWindow) (_THIS, SDL_Window * window); int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); - int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, SDL_Rect * rects, int numrects); + int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window); /* * * */ diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 1877a5870..f04b13199 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -308,7 +308,7 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix } static int -SDL_UpdateWindowTexture(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) +SDL_UpdateWindowTexture(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { SDL_WindowTextureData *data; SDL_Rect rect; @@ -1841,7 +1841,7 @@ SDL_UpdateWindowSurface(SDL_Window * window) } int -SDL_UpdateWindowSurfaceRects(SDL_Window * window, SDL_Rect * rects, +SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects, int numrects) { CHECK_WINDOW_MAGIC(window, -1); diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 28bb842a4..11e60bd5f 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -98,7 +98,7 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects) { + const SDL_Rect * rects, int numrects) { if(!window) return 0; diff --git a/src/video/bwindow/SDL_bframebuffer.h b/src/video/bwindow/SDL_bframebuffer.h index 76d054b70..935f0e95a 100644 --- a/src/video/bwindow/SDL_bframebuffer.h +++ b/src/video/bwindow/SDL_bframebuffer.h @@ -34,7 +34,7 @@ extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects); + const SDL_Rect * rects, int numrects); extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); extern int32 BE_DrawThread(void *data); diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c index afcdfb807..242fb8209 100644 --- a/src/video/dummy/SDL_nullframebuffer.c +++ b/src/video/dummy/SDL_nullframebuffer.c @@ -58,7 +58,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * forma return 0; } -int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) +int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { static int frame_number; SDL_Surface *surface; diff --git a/src/video/dummy/SDL_nullframebuffer_c.h b/src/video/dummy/SDL_nullframebuffer_c.h index a7a2a1c16..57dd2adbc 100644 --- a/src/video/dummy/SDL_nullframebuffer_c.h +++ b/src/video/dummy/SDL_nullframebuffer_c.h @@ -21,7 +21,7 @@ #include "SDL_config.h" extern int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); -extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects); +extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); extern void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c index 8f2ad057c..5c22ff1f7 100644 --- a/src/video/windows/SDL_windowsframebuffer.c +++ b/src/video/windows/SDL_windowsframebuffer.c @@ -93,7 +93,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi return 0; } -int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) +int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; diff --git a/src/video/windows/SDL_windowsframebuffer.h b/src/video/windows/SDL_windowsframebuffer.h index ebd7d7a9b..4d7a2ba0d 100644 --- a/src/video/windows/SDL_windowsframebuffer.h +++ b/src/video/windows/SDL_windowsframebuffer.h @@ -21,7 +21,7 @@ #include "SDL_config.h" extern int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); -extern int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects); +extern int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); extern void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c index f7717416d..7f19ddd29 100644 --- a/src/video/x11/SDL_x11framebuffer.c +++ b/src/video/x11/SDL_x11framebuffer.c @@ -148,7 +148,7 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, } int -X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, +X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; diff --git a/src/video/x11/SDL_x11framebuffer.h b/src/video/x11/SDL_x11framebuffer.h index a538ef956..8e4c21ae7 100644 --- a/src/video/x11/SDL_x11framebuffer.h +++ b/src/video/x11/SDL_x11framebuffer.h @@ -25,7 +25,7 @@ extern int X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); extern int X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects); + const SDL_Rect * rects, int numrects); extern void X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window); /* vi: set ts=4 sw=4 expandtab: */ From db141a68e83ae4c428e241beaf2aaabebf4e8a8c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 19 Mar 2013 22:02:34 -0700 Subject: [PATCH 103/151] Fixed bug 1764 - Integer Precision Loss During Compilation Phil Sampson /Library/Frameworks/SDL2.framework/Headers/SDL_stdinc.h:345:28: Implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'unsigned int' --- include/SDL_stdinc.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index f37678957..bc400524b 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -342,13 +342,12 @@ SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len) ); /* !!! FIXME: amd64? */ #else - unsigned int _count = (len); - unsigned int _n = (_count + 3) / 4; + size_t _n = (len + 3) / 4; Uint32 *_p = SDL_static_cast(Uint32 *, dst); Uint32 _val = (val); if (len == 0) return; - switch (_count % 4) + switch (len % 4) { case 0: do { *_p++ = _val; case 3: *_p++ = _val; From e13a74ec9a85c1138017119077afcb54aef8f78e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 19 Mar 2013 22:15:07 -0700 Subject: [PATCH 104/151] Fixed bug 1760 - Update README.android about local.properties ny00 At the moment, the README.android file mentions this as one step in building an app: " 5. Edit /local.properties to point to the Android SDK directory " However, the local.properties file has recently been removed from the repository, so an update is desired. For instance: " 5. Create /local.properties and use that to point to the Android SDK directory, by writing a line with the following form: sdk.dir=/Users/slouken/android-sdk-macosx --- README.android | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.android b/README.android index 29d8ca5dd..efc3ab302 100644 --- a/README.android +++ b/README.android @@ -47,7 +47,8 @@ Instructions: If you want to use the Eclipse IDE, skip to the Eclipse section below. -5. Edit /local.properties to point to the Android SDK directory +5. Create /local.properties and use that to point to the Android SDK directory, by writing a line with the following form: +sdk.dir=PATH_TO_ANDROID_SDK 6. Run 'ant debug' in android/project. This compiles the .java and eventually creates a .apk with the native code embedded 7. 'ant debug install' will push the apk to the device or emulator (if connected) From 282adb772b19eaeec7f7d4891e9e8b8fc9c915c5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 19 Mar 2013 22:25:02 -0700 Subject: [PATCH 105/151] Fixed bug 1759 - Updates to testjoystick.c ny00 A minor patch is attached, with the following few changes to testjoystick.c: - Unused constant definitions have been removed. - Output for all analog axes is drawn, even when there is an odd number of axes. (I have a controller with 5 analog axes.) - Buttons are now drawn on two rows, so there's room for more. In fact, it has been used for testing a proposed joystick patch for Android, where large button ID numbers have been involved (20 and up). For more details see http://bugzilla.libsdl.org/show_bug.cgi?id=1700. - A few adaptations have been done for the Android platform, assuming joystick support is ever applied to it. One of them is that the very first joystick (in the enumeration of all joysticks) is opened for testing, if there is any. - It is now possible to quit from the calibration by pressing on a mouse button, tapping on a touchscreen or pressing/tapping on the "Back" button of an Android device. Technically, a press on a key identified by key code SDLK_AC_BACK results in that. --- test/testjoystick.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/test/testjoystick.c b/test/testjoystick.c index af990ad9a..df94631f1 100644 --- a/test/testjoystick.c +++ b/test/testjoystick.c @@ -28,9 +28,6 @@ #define SCREEN_HEIGHT 480 #endif -#define MAX_NUM_AXES 6 -#define MAX_NUM_HATS 2 - static void DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h) @@ -121,10 +118,13 @@ WatchJoystick(SDL_Joystick * joystick) event.jbutton.which, event.jbutton.button); break; case SDL_KEYDOWN: - if (event.key.keysym.sym != SDLK_ESCAPE) { + if ((event.key.keysym.sym != SDLK_ESCAPE) && + (event.key.keysym.sym != SDLK_AC_BACK)) { break; } /* Fall through to signal quit */ + case SDL_FINGERDOWN: + case SDL_MOUSEBUTTONDOWN: case SDL_QUIT: done = SDL_TRUE; break; @@ -136,15 +136,15 @@ WatchJoystick(SDL_Joystick * joystick) SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE); for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) { if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) { - DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32); + DrawRect(screen, (i%20) * 34, SCREEN_HEIGHT - 68 + (i/20) * 34, 32, 32); } } SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE); - for (i = 0; i < SDL_JoystickNumAxes(joystick) / 2; ++i) { + for (i = 0; i < SDL_JoystickNumAxes(joystick); ++i) { /* Draw the X/Y axis */ int x, y; - x = (((int) SDL_JoystickGetAxis(joystick, i * 2 + 0)) + 32768); + x = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768); x *= SCREEN_WIDTH; x /= 65535; if (x < 0) { @@ -152,7 +152,12 @@ WatchJoystick(SDL_Joystick * joystick) } else if (x > (SCREEN_WIDTH - 16)) { x = SCREEN_WIDTH - 16; } - y = (((int) SDL_JoystickGetAxis(joystick, i * 2 + 1)) + 32768); + ++i; + if (i < SDL_JoystickNumAxes(joystick)) { + y = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768); + } else { + y = 32768; + } y *= SCREEN_HEIGHT; y /= 65535; if (y < 0) { @@ -235,11 +240,19 @@ main(int argc, char *argv[]) } } +#ifdef ANDROID + if (SDL_NumJoysticks() > 0) { +#else if (argv[1]) { +#endif SDL_bool reportederror = SDL_FALSE; SDL_bool keepGoing = SDL_TRUE; SDL_Event event; +#ifdef ANDROID + joystick = SDL_JoystickOpen(0); +#else joystick = SDL_JoystickOpen(atoi(argv[1])); +#endif while ( keepGoing ) { if (joystick == NULL) { if ( !reportederror ) { @@ -259,7 +272,8 @@ main(int argc, char *argv[]) } while (keepGoing) { SDL_WaitEvent(&event); - if (event.type == SDL_QUIT) { + if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN) + || (event.type == SDL_MOUSEBUTTONDOWN)) { keepGoing = SDL_FALSE; } else if (event.type == SDL_JOYDEVICEADDED) { joystick = SDL_JoystickOpen(atoi(argv[1])); @@ -270,7 +284,11 @@ main(int argc, char *argv[]) } SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); +#ifdef ANDROID + exit(0); +#else return 0; +#endif } #else From 3c610adc98148d7a845c14a88acff949e66ab776 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 19 Mar 2013 23:03:57 -0700 Subject: [PATCH 106/151] Fixed bug 1700 - Joysticks not supported in Android --- android-project/project.properties | 2 +- .../src/org/libsdl/app/SDLActivity.java | 159 ++++++++++++++++-- src/core/android/SDL_android.cpp | 128 ++++++++++++++ src/core/android/SDL_android.h | 12 ++ 4 files changed, 286 insertions(+), 15 deletions(-) diff --git a/android-project/project.properties b/android-project/project.properties index b7c2081d5..0f507e530 100644 --- a/android-project/project.properties +++ b/android-project/project.properties @@ -11,4 +11,4 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-10 +target=android-12 diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index e0a850f42..55ab5cb4b 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -24,6 +24,8 @@ import android.hardware.*; import android.content.*; import java.lang.*; +import java.util.List; +import java.util.ArrayList; /** @@ -42,6 +44,11 @@ public class SDLActivity extends Activity { // This is what SDL runs in. It invokes SDL_main(), eventually private static Thread mSDLThread; + + // Joystick + private static List mJoyIdList; + // TODO: Have a (somewhat) more efficient way of storing these? + private static List> mJoyAxesLists; // Audio private static Thread mAudioThread; @@ -156,12 +163,15 @@ public class SDLActivity extends Activity { public static native void nativePause(); public static native void nativeResume(); public static native void onNativeResize(int x, int y, int format); + public static native void onNativePadDown(int padId, int keycode); + public static native void onNativePadUp(int padId, int keycode); + public static native void onNativeJoy(int joyId, int axisNum, float value); public static native void onNativeKeyDown(int keycode); public static native void onNativeKeyUp(int keycode); public static native void onNativeTouch(int touchDevId, int pointerFingerId, int action, float x, float y, float p); - public static native void onNativeAccel(float x, float y, float z); +// public static native void onNativeAccel(float x, float y, float z); public static native void nativeRunAudioThread(); @@ -180,6 +190,74 @@ public class SDLActivity extends Activity { mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title); } + // Call when initializing the joystick subsystem + public static void joystickInit() { + mJoyIdList = new ArrayList(); + mJoyAxesLists = new ArrayList>(); + + int[] deviceIds = InputDevice.getDeviceIds(); + for(int i=0; i axesList = new ArrayList(); + /* With API 12 and above we can get a list of all motion + * ranges, hence all axes. Some of them may be irrelevant + * (e.g. an embedded trackpad). We filter the desired axes. + */ + if(Build.VERSION.SDK_INT >= 12) { + List rangesList = InputDevice.getDevice(deviceIds[i]).getMotionRanges(); + for (InputDevice.MotionRange range : rangesList) { + // Skip any possibly unrelated axis + if ( (range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + axesList.add(range.getAxis()); + } + } + } else { + // In older versions, we can assume a sane X-Y default configuration + axesList.add(MotionEvent.AXIS_X); + axesList.add(MotionEvent.AXIS_Y); + } + mJoyAxesLists.add(axesList); + } + } + } + + // Call when one clears joystick subsystem resources + public static void joystickQuit() { + mJoyIdList = null; + mJoyAxesLists = null; + } + + public static int getNumJoysticks() { + if (mJoyIdList == null) + return -1; + return mJoyIdList.size(); + } + + public static String getJoystickName(int joy) { + if (mJoyIdList == null) + return null; + return InputDevice.getDevice(mJoyIdList.get(joy)).getName(); + } + + public static List getJoystickAxesList(int joy) { + if (mJoyIdList == null) + return null; + return mJoyAxesLists.get(joy); + } + + public static int getJoystickNumOfAxes(int joy) { + if (mJoyIdList == null) + return -1; + return mJoyAxesLists.get(joy).size(); + } + + public static int getJoyId(int devId) { + if (mJoyIdList == null) + return -1; + return mJoyIdList.indexOf(devId); + } + public static void sendMessage(int command, int param) { mSingleton.sendCommand(command, Integer.valueOf(param)); } @@ -478,7 +556,12 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, setFocusableInTouchMode(true); requestFocus(); setOnKeyListener(this); - setOnTouchListener(this); + setOnTouchListener(this); + + // Listen to joystick motion events if supported + if (Build.VERSION.SDK_INT >= 12) { + setOnGenericMotionListener(new SDLOnGenericMotionListener()); + } mSensorManager = (SensorManager)context.getSystemService("sensor"); @@ -568,18 +651,65 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, + // Listen to joystick motion events if supported (API >= 12) + private static class SDLOnGenericMotionListener implements View.OnGenericMotionListener { + @Override + public boolean onGenericMotion(View view, MotionEvent event) { + int actionPointerIndex = event.getActionIndex(); + int action = event.getActionMasked(); + + if ( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + switch(action) { + case MotionEvent.ACTION_MOVE: + int id = SDLActivity.getJoyId( event.getDeviceId() ); + // The joystick subsystem may be uninitialized, so ignore + if (id < 0) + return true; + // Update values for all joystick axes + List axes = SDLActivity.getJoystickAxesList(id); + for (int axisIndex = 0; axisIndex < axes.size(); axisIndex++) { + SDLActivity.onNativeJoy(id, axisIndex, event.getAxisValue(axes.get(axisIndex), actionPointerIndex)); + } + + return true; + } + } + return false; + } + } + // Key events public boolean onKey(View v, int keyCode, KeyEvent event) { - - if (event.getAction() == KeyEvent.ACTION_DOWN) { - //Log.v("SDL", "key down: " + keyCode); - SDLActivity.onNativeKeyDown(keyCode); - return true; - } - else if (event.getAction() == KeyEvent.ACTION_UP) { - //Log.v("SDL", "key up: " + keyCode); - SDLActivity.onNativeKeyUp(keyCode); - return true; + /* Dispatch the different events depending on where they come from: + * If the input device has some joystick source (probably differing + * from the source to which the given key belongs), assume it is a + * game controller button. Otherwise, assume a keyboard key. + * This should also take care of some kinds of manually toggled soft + * keyboards (i.e. not via the SDL text input API). + */ + if ( (event.getDevice().getSources() & 0x00000010 /* API 12: InputDevice.SOURCE_CLASS_JOYSTICK*/) != 0) { + int id = SDLActivity.getJoyId( event.getDeviceId() ); + // The joystick subsystem may be uninitialized, so ignore + if (id < 0) + return true; + if (event.getAction() == KeyEvent.ACTION_DOWN) { + SDLActivity.onNativePadDown(id, keyCode); + return true; + } else if (event.getAction() == KeyEvent.ACTION_UP) { + SDLActivity.onNativePadUp(id, keyCode); + return true; + } + } else { + if (event.getAction() == KeyEvent.ACTION_DOWN) { + //Log.v("SDL", "key down: " + keyCode); + SDLActivity.onNativeKeyDown(keyCode); + return true; + } + else if (event.getAction() == KeyEvent.ACTION_UP) { + //Log.v("SDL", "key up: " + keyCode); + SDLActivity.onNativeKeyUp(keyCode); + return true; + } } return false; @@ -614,7 +744,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, } } return true; - } + } // Sensor events public void enableSensor(int sensortype, boolean enabled) { @@ -634,13 +764,14 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, } public void onSensorChanged(SensorEvent event) { +/* if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH, event.values[1] / SensorManager.GRAVITY_EARTH, event.values[2] / SensorManager.GRAVITY_EARTH); } +*/ } - } /* This is a fake invisible editor view that receives the input and defines the diff --git a/src/core/android/SDL_android.cpp b/src/core/android/SDL_android.cpp index 02e28ff9a..d87e724c2 100644 --- a/src/core/android/SDL_android.cpp +++ b/src/core/android/SDL_android.cpp @@ -31,11 +31,15 @@ extern "C" { #include "../../events/SDL_events_c.h" +#include "../../joystick/android/SDL_androidjoystick.h" #include "../../video/android/SDL_androidkeyboard.h" #include "../../video/android/SDL_androidtouch.h" #include "../../video/android/SDL_androidvideo.h" #include +#if ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK +#include +#endif #include #include #include @@ -76,9 +80,11 @@ static jmethodID midAudioWriteShortBuffer; static jmethodID midAudioWriteByteBuffer; static jmethodID midAudioQuit; +#ifdef ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK // Accelerometer data storage static float fLastAccelerometer[3]; static bool bHasNewData; +#endif /******************************************************************************* Functions called by JNI @@ -130,7 +136,9 @@ extern "C" void SDL_Android_Init(JNIEnv* mEnv, jclass cls) midAudioQuit = mEnv->GetStaticMethodID(mActivityClass, "audioQuit", "()V"); +#ifdef ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK bHasNewData = false; +#endif if(!midCreateGLContext || !midFlipBuffers || !midAudioInit || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) { @@ -147,6 +155,27 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize( Android_SetScreenResolution(width, height, format); } +// Paddown +extern "C" void Java_org_libsdl_app_SDLActivity_onNativePadDown( + JNIEnv* env, jclass jcls, jint padId, jint keycode) +{ + Android_OnPadDown(padId, keycode); +} + +// Padup +extern "C" void Java_org_libsdl_app_SDLActivity_onNativePadUp( + JNIEnv* env, jclass jcls, jint padId, jint keycode) +{ + Android_OnPadUp(padId, keycode); +} + +// Joysticks +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeJoy( + JNIEnv* env, jclass jcls, jint joyId, jint axisNum, jfloat value) +{ + Android_OnJoy(joyId, axisNum, value); +} + // Keydown extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown( JNIEnv* env, jclass jcls, jint keycode) @@ -170,6 +199,7 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch( Android_OnTouch(touch_device_id_in, pointer_finger_id_in, action, x, y, p); } +#if ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK // Accelerometer extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel( JNIEnv* env, jclass jcls, @@ -180,6 +210,7 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel( fLastAccelerometer[2] = z; bHasNewData = true; } +#endif // Quit extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit( @@ -347,6 +378,7 @@ extern "C" void Android_JNI_SetActivityTitle(const char *title) } } +#if ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK extern "C" SDL_bool Android_JNI_GetAccelerometerValues(float values[3]) { int i; @@ -362,6 +394,7 @@ extern "C" SDL_bool Android_JNI_GetAccelerometerValues(float values[3]) return retval; } +#endif static void Android_JNI_ThreadDestroyed(void* value) { /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */ @@ -1082,6 +1115,101 @@ extern "C" int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery return 0; } +// Initialize the joystick subsystem on the Java side +int Android_JNI_JoystickInit() +{ + JNIEnv* env = Android_JNI_GetEnv(); + if (!env) { + return -1; + } + jmethodID mid = env->GetStaticMethodID(mActivityClass, "joystickInit", "()V"); + if (!mid) { + return -1; + } + env->CallStaticVoidMethod(mActivityClass, mid); + return 0; +} + +// Quit the joystick subsystem on the Java side +int Android_JNI_JoystickQuit() +{ + JNIEnv* env = Android_JNI_GetEnv(); + if (!env) { + return -1; + } + jmethodID mid = env->GetStaticMethodID(mActivityClass, "joystickQuit", "()V"); + if (!mid) { + return -1; + } + env->CallStaticVoidMethod(mActivityClass, mid); + return 0; +} + +// return the total number of plugged in joysticks +extern "C" int Android_JNI_GetNumJoysticks() +{ + JNIEnv* env = Android_JNI_GetEnv(); + if (!env) { + return -1; + } + jmethodID mid = env->GetStaticMethodID(mActivityClass, "getNumJoysticks", "()I"); + if (!mid) { + return -1; + } + + return env->CallStaticIntMethod(mActivityClass, mid); +} + +// Return the name of joystick number "index" +extern "C" char* Android_JNI_GetJoystickName(int index) +{ + JNIEnv* env = Android_JNI_GetEnv(); + if (!env) { + return SDL_strdup(""); + } + + jmethodID mid = env->GetStaticMethodID(mActivityClass, "getJoystickName", "(I)Ljava/lang/String;"); + if (!mid) { + return SDL_strdup(""); + } + jstring string = reinterpret_cast(env->CallStaticObjectMethod(mActivityClass, mid, index)); + const char* utf = env->GetStringUTFChars(string, 0); + if (!utf) { + return SDL_strdup(""); + } + + char* text = SDL_strdup(utf); + env->ReleaseStringUTFChars(string, utf); + return text; +} + +// return the number of axes in the given joystick +extern "C" int Android_JNI_GetJoystickNumOfAxes(int index) +{ + JNIEnv* env = Android_JNI_GetEnv(); + if (!env) { + return -1; + } + jmethodID mid = env->GetStaticMethodID(mActivityClass, "getJoystickNumOfAxes", "(I)I"); + if (!mid) { + return -1; + } + + return env->CallStaticIntMethod(mActivityClass, mid, index); +} + +#if ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK +// Return the name of the default accelerometer +// This is much easier to be done with NDK than with JNI +extern "C" char* Android_GetAccelName() +{ + ASensorManager* mSensorManager = ASensorManager_getInstance(); + ASensor const* mAccelerometer = ASensorManager_getDefaultSensor(mSensorManager, ASENSOR_TYPE_ACCELEROMETER); + + return SDL_strdup(ASensor_getName(mAccelerometer)); +} +#endif + // sends message to be handled on the UI event dispatch thread extern "C" int Android_JNI_SendMessage(int command, int param) { diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index 7eddcfac8..f57728461 100644 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -33,7 +33,9 @@ extern "C" { extern SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion, int red, int green, int blue, int alpha, int buffer, int depth, int stencil, int buffers, int samples); extern void Android_JNI_SwapWindow(); extern void Android_JNI_SetActivityTitle(const char *title); +#ifdef ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]); +#endif extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect); extern void Android_JNI_HideTextInput(); @@ -60,6 +62,16 @@ SDL_bool Android_JNI_HasClipboardText(); /* Power support */ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent); +/* Joystick/accelerometer support */ +int Android_JNI_JoystickInit(); +int Android_JNI_JoystickQuit(); +int Android_JNI_GetNumJoysticks(); +char* Android_JNI_GetJoystickName(int i); +int Android_JNI_GetJoystickNumOfAxes(int index); +#ifdef ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK +char* Android_GetAccelName(); +#endif + // Threads #include static void Android_JNI_ThreadDestroyed(void*); From 6dddee5200950e5d7fd596072303d263e613611e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 19 Mar 2013 23:07:49 -0700 Subject: [PATCH 107/151] Added missing files for the Android build --- src/joystick/android/SDL_androidjoystick.c | 244 +++++++++++++++++++++ src/joystick/android/SDL_androidjoystick.h | 27 +++ 2 files changed, 271 insertions(+) create mode 100644 src/joystick/android/SDL_androidjoystick.c create mode 100644 src/joystick/android/SDL_androidjoystick.h diff --git a/src/joystick/android/SDL_androidjoystick.c b/src/joystick/android/SDL_androidjoystick.c new file mode 100644 index 000000000..6bee7cbf7 --- /dev/null +++ b/src/joystick/android/SDL_androidjoystick.c @@ -0,0 +1,244 @@ +/* + 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" + +#ifdef SDL_JOYSTICK_ANDROID + +/* This is the system specific header for the SDL joystick API */ +#include /* For the definition of NULL */ + +#include "SDL_error.h" +#include "SDL_events.h" +#include "SDL_joystick.h" +#include "../SDL_sysjoystick.h" +#include "../SDL_joystick_c.h" +#include "../../core/android/SDL_android.h" + +//HACK!! +static SDL_Joystick **SYS_Joysticks; +static char **SYS_JoystickNames; +static int SYS_numjoysticks; + +/* Function to convert Android keyCodes into SDL ones. + * This code manipulation is done to get a sequential list of codes. + */ +int +keycode_to_SDL(int keycode) +{ + /* D-Pad key codes (API 1): + * KEYCODE_DPAD_UP=19, KEYCODE_DPAD_DOWN + * KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT, KEYCODE_DPAD_CENTER + */ + if(keycode < 96) + return keycode-19; + /* Some gamepad buttons (API 9): + * KEYCODE_BUTTON_A=96, KEYCODE_BUTTON_B, KEYCODE_BUTTON_C, + * KEYCODE_BUTTON_X, KEYCODE_BUTTON_Y, KEYCODE_BUTTON_Z, + * KEYCODE_BUTTON_L1, KEYCODE_BUTTON_L2, + * KEYCODE_BUTTON_R1, KEYCODE_BUTTON_R2, + * KEYCODE_BUTTON_THUMBL, KEYCODE_BUTTON_THUMBR, + * KEYCODE_BUTTON_START, KEYCODE_BUTTON_SELECT, KEYCODE_BUTTON_MODE + */ + else if(keycode < 188) + return keycode-91; + /* More gamepad buttons (API 12): + * KEYCODE_BUTTON_1=188 to KEYCODE_BUTTON_16 + */ + else + return keycode-168; +} + +/* Function to scan the system for joysticks. + * This function should set SYS_numjoysticks to the number of available + * joysticks. Joystick 0 should be the system default joystick. + * It should return 0, or -1 on an unrecoverable fatal error. + */ +int +SDL_SYS_JoystickInit(void) +{ + int i = 0; + if (Android_JNI_JoystickInit() < 0) + return (-1); + SYS_numjoysticks = Android_JNI_GetNumJoysticks(); + SYS_Joysticks = (SDL_Joystick **)SDL_malloc(SYS_numjoysticks*sizeof(SDL_Joystick *)); + if (SYS_Joysticks == NULL) + { + SDL_OutOfMemory(); + return (-1); + } + SYS_JoystickNames = (char **)SDL_malloc(SYS_numjoysticks*sizeof(char *)); + if (SYS_JoystickNames == NULL) + { + SDL_free(SYS_Joysticks); + SYS_Joysticks = NULL; + SDL_OutOfMemory(); + return (-1); + } + SDL_memset(SYS_JoystickNames, 0, (SYS_numjoysticks*sizeof(char *))); + SDL_memset(SYS_Joysticks, 0, (SYS_numjoysticks*sizeof(SDL_Joystick *))); + + for (i = 0; i < SYS_numjoysticks; i++) + { + SYS_JoystickNames[i] = Android_JNI_GetJoystickName(i); + } + + return (SYS_numjoysticks); +} + +int SDL_SYS_NumJoysticks() +{ + return SYS_numjoysticks; +} + +void SDL_SYS_JoystickDetect() +{ +} + +SDL_bool SDL_SYS_JoystickNeedsPolling() +{ + return SDL_FALSE; +} + +/* Function to get the device-dependent name of a joystick */ +const char * +SDL_SYS_JoystickNameForDeviceIndex(int device_index) +{ + return SYS_JoystickNames[device_index]; +} + +/* Function to perform the mapping from device index to the instance id for this index */ +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) +{ + return device_index; +} + +/* Function to open a joystick for use. + The joystick to open is specified by the index field of the joystick. + This should fill the nbuttons and naxes fields of the joystick structure. + It returns 0, or -1 if there is an error. + */ +int +SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) +{ + if( device_index < SYS_numjoysticks ) + { + // TODO: How to get the rest of the info?? + // 36 is the maximum number of handled buttons + joystick->nbuttons = 36; + joystick->nhats = 0; + joystick->nballs = 0; + joystick->naxes = Android_JNI_GetJoystickNumOfAxes(device_index); + } + else + { + return -1; + } + + // Extremely hacky + SYS_Joysticks[device_index] = joystick; + + return 0; +} + + +/* Function to update the state of a joystick - called as a device poll. + * This function shouldn't update the joystick structure directly, + * but instead should call SDL_PrivateJoystick*() to deliver events + * and update joystick device state. + */ +void +SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) +{ +} + +/* Function to determine is this joystick is attached to the system right now */ +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) +{ + return SDL_TRUE; +} + +/* Function to close a joystick after use */ +void +SDL_SYS_JoystickClose(SDL_Joystick * joystick) +{ +} + +/* Function to perform any system-specific joystick related cleanup */ +void +SDL_SYS_JoystickQuit(void) +{ + SDL_free(SYS_JoystickNames); + SDL_free(SYS_Joysticks); + SYS_JoystickNames = NULL; + SYS_Joysticks = NULL; + Android_JNI_JoystickQuit(); +} + +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) +{ + SDL_JoystickGUID guid; + // the GUID is just the first 16 chars of the name for now + const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) +{ + SDL_JoystickGUID guid; + // the GUID is just the first 16 chars of the name for now + const char *name = joystick->name; + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + +int +Android_OnPadDown(int padId, int keycode) +{ + SDL_PrivateJoystickButton(SYS_Joysticks[padId], keycode_to_SDL(keycode), SDL_PRESSED); + + return 0; +} + +int +Android_OnPadUp(int padId, int keycode) +{ + SDL_PrivateJoystickButton(SYS_Joysticks[padId], keycode_to_SDL(keycode), SDL_RELEASED); + + return 0; +} + +int +Android_OnJoy(int joyId, int axisnum, float value) +{ + // Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0] + // TODO: Are the reported values right? + SDL_PrivateJoystickAxis(SYS_Joysticks[joyId], axisnum, (Sint16) (32767.*value) ); + + return 0; +} + +#endif /* SDL_JOYSTICK_ANDROID */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/android/SDL_androidjoystick.h b/src/joystick/android/SDL_androidjoystick.h new file mode 100644 index 000000000..01a970232 --- /dev/null +++ b/src/joystick/android/SDL_androidjoystick.h @@ -0,0 +1,27 @@ +/* + 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" + +extern int Android_OnPadDown(int padId, int keycode); +extern int Android_OnPadUp(int padId, int keycode); +extern int Android_OnJoy(int joyId, int axisnum, float value); + +/* vi: set ts=4 sw=4 expandtab: */ From 3f660cc9ad2b7bc332fbc2a982f6db099307b21f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 19 Mar 2013 23:24:24 -0700 Subject: [PATCH 108/151] Removed old file from the Android build --- src/joystick/android/SDL_sysjoystick.c | 156 ------------------------- 1 file changed, 156 deletions(-) delete mode 100644 src/joystick/android/SDL_sysjoystick.c diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c deleted file mode 100644 index 2e2d98a02..000000000 --- a/src/joystick/android/SDL_sysjoystick.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 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" - -#ifdef SDL_JOYSTICK_ANDROID - -/* This is the system specific header for the SDL joystick API */ -#include /* For the definition of NULL */ - -#include "SDL_error.h" -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" -#include "../../core/android/SDL_android.h" - -static const char *accelerometerName = "Android accelerometer"; - -/* Function to scan the system for joysticks. - * This function should set SDL_numjoysticks to the number of available - * joysticks. Joystick 0 should be the system default joystick. - * It should return 0, or -1 on an unrecoverable fatal error. - */ -int -SDL_SYS_JoystickInit(void) -{ - return (1); -} - -int SDL_SYS_NumJoysticks() -{ - return 1; -} - -void SDL_SYS_JoystickDetect() -{ -} - -SDL_bool SDL_SYS_JoystickNeedsPolling() -{ - return SDL_FALSE; -} - -/* Function to get the device-dependent name of a joystick */ -const char * -SDL_SYS_JoystickNameForDeviceIndex(int device_index) -{ - return accelerometerName; -} - -/* Function to perform the mapping from device index to the instance id for this index */ -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) -{ - return device_index; -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int -SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) -{ - if (device_index == 0) { - joystick->nbuttons = 0; - joystick->nhats = 0; - joystick->nballs = 0; - joystick->naxes = 3; - return 0; - } else { - SDL_SetError("No joystick available with that index"); - return (-1); - } -} - -/* Function to determine is this joystick is attached to the system right now */ -SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) -{ - return SDL_TRUE; -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) -{ - int i; - Sint16 value; - float values[3]; - - if (Android_JNI_GetAccelerometerValues(values)) { - for ( i = 0; i < 3; i++ ) { - value = (Sint16)(values[i] * 32767.0f); - SDL_PrivateJoystickAxis(joystick, i, value); - } - } -} - -/* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick * joystick) -{ -} - -/* Function to perform any system-specific joystick related cleanup */ -void -SDL_SYS_JoystickQuit(void) -{ -} - -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) -{ - SDL_JoystickGUID guid; - // the GUID is just the first 16 chars of the name for now - const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) -{ - SDL_JoystickGUID guid; - // the GUID is just the first 16 chars of the name for now - const char *name = joystick->name; - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -#endif /* SDL_JOYSTICK_ANDROID */ - -/* vi: set ts=4 sw=4 expandtab: */ From 404d8c542994f2a52af26e0c67adce57c5252754 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 22 Mar 2013 11:42:31 -0700 Subject: [PATCH 109/151] Make SDL support the X11 clipboard TARGETS protocol, which advertises what formats text is available in from the application. This is necessary for many Linux programs to interact well with the clipboard. --- .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes src/video/x11/SDL_x11events.c | 8 ++++++++ 4 files changed, 8 insertions(+) diff --git a/Xcode/TemplatesForXcodeTiger/SDL Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL Application/English.lproj/InfoPlist.strings index 38224b5a6dc9494230bdffbcad9c8bd915f478d9..e612457676d964a8021d20ec90290d5c6c3d88c1 100755 GIT binary patch delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> diff --git a/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/English.lproj/InfoPlist.strings index 38224b5a6dc9494230bdffbcad9c8bd915f478d9..e612457676d964a8021d20ec90290d5c6c3d88c1 100755 GIT binary patch delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> diff --git a/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/English.lproj/InfoPlist.strings index 38224b5a6dc9494230bdffbcad9c8bd915f478d9..e612457676d964a8021d20ec90290d5c6c3d88c1 100755 GIT binary patch delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 916ca9662..6c54e9dc9 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -735,11 +735,19 @@ X11_DispatchEvent(_THIS) XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, &sevent.xselection.target, &seln_format, &nbytes, &overflow, &seln_data) == Success) { + Atom XA_TARGETS = XInternAtom(display, "TARGETS", 0); if (sevent.xselection.target == req->target) { XChangeProperty(display, req->requestor, req->property, sevent.xselection.target, seln_format, PropModeReplace, seln_data, nbytes); sevent.xselection.property = req->property; + } else if (XA_TARGETS == req->target) { + Atom SupportedFormats[] = { sevent.xselection.target, XA_TARGETS }; + XChangeProperty(display, req->requestor, req->property, + XA_ATOM, 32, PropModeReplace, + (unsigned char*)SupportedFormats, + sizeof(SupportedFormats)/sizeof(*SupportedFormats)); + sevent.xselection.property = req->property; } XFree(seln_data); } From 890d7ee57652d2bf9d5e9f5bea267eb9a36bf1cf Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 23 Mar 2013 13:03:36 -0700 Subject: [PATCH 110/151] Updated the license listed in the header, fixing bug 1768 --- include/SDL.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/SDL.h b/include/SDL.h index ac468ffd8..0cfcdc71a 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -41,10 +41,9 @@ * Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP, * Pike, Pliant, Python, Ruby, and Smalltalk. * - * This library is distributed under GNU LGPL version 2, which can be + * This library is distributed under the zlib license, which can be * found in the file "COPYING". This license allows you to use SDL - * freely in commercial programs as long as you link with the dynamic - * library. + * freely for any purpose as long as you retain the copyright notice. * * The best way to learn how to use SDL is to check out the header files in * the "include" subdirectory and the programs in the "test" subdirectory. From 8f9ae942350fba75503fd0ea4f53b19a129b30a4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 24 Mar 2013 09:51:01 -0700 Subject: [PATCH 111/151] The palette unused value is treated as alpha and updated when setting the colorkey. This fixes issues loading palettized images that have a colorkey with the same RGB values as another entry in the palette (e.g. bug 1746) --- src/video/SDL_pixels.c | 17 +++++++++-------- src/video/SDL_pixels_c.h | 2 +- src/video/SDL_surface.c | 41 +++++++++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 47843b034..b27520832 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -762,12 +762,12 @@ SDL_CalculatePitch(SDL_Surface * surface) * Match an RGB value to a particular palette index */ Uint8 -SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b) +SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { /* Do colorspace distance matching */ unsigned int smallest; unsigned int distance; - int rd, gd, bd; + int rd, gd, bd, ad; int i; Uint8 pixel = 0; @@ -776,7 +776,8 @@ SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b) rd = pal->colors[i].r - r; gd = pal->colors[i].g - g; bd = pal->colors[i].b - b; - distance = (rd * rd) + (gd * gd) + (bd * bd); + ad = pal->colors[i].unused - a; + distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad); if (distance < smallest) { pixel = i; if (distance == 0) { /* Perfect match! */ @@ -797,7 +798,7 @@ SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b) | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask; } else { - return SDL_FindColor(format->palette, r, g, b); + return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE); } } @@ -812,7 +813,7 @@ SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b, | (b >> format->Bloss) << format->Bshift | ((a >> format->Aloss) << format->Ashift & format->Amask); } else { - return SDL_FindColor(format->palette, r, g, b); + return SDL_FindColor(format->palette, r, g, b, a); } } @@ -858,7 +859,7 @@ SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format, *r = format->palette->colors[pixel].r; *g = format->palette->colors[pixel].g; *b = format->palette->colors[pixel].b; - *a = SDL_ALPHA_OPAQUE; + *a = format->palette->colors[pixel].unused; } else { *r = *g = *b = *a = 0; } @@ -894,7 +895,7 @@ Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) for (i = 0; i < src->ncolors; ++i) { map[i] = SDL_FindColor(dst, src->colors[i].r, src->colors[i].g, - src->colors[i].b); + src->colors[i].b, src->colors[i].unused); } return (map); } @@ -918,10 +919,10 @@ Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, /* We memory copy to the pixel map so the endianness is preserved */ for (i = 0; i < pal->ncolors; ++i) { - Uint8 A = Amod; Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255); Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255); Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255); + Uint8 A = (Uint8) ((pal->colors[i].unused * Amod) / 255); ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A); } return (map); diff --git a/src/video/SDL_pixels_c.h b/src/video/SDL_pixels_c.h index 46b086c45..0b5d9a006 100644 --- a/src/video/SDL_pixels_c.h +++ b/src/video/SDL_pixels_c.h @@ -36,6 +36,6 @@ extern void SDL_FreeBlitMap(SDL_BlitMap * map); /* Miscellaneous functions */ extern int SDL_CalculatePitch(SDL_Surface * surface); extern void SDL_DitherColors(SDL_Color * colors, int bpp); -extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b); +extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 710508ed3..b496a1b86 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -187,7 +187,13 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) if (flag) { surface->map->info.flags |= SDL_COPY_COLORKEY; surface->map->info.colorkey = key; + if (surface->format->palette) { + surface->format->palette->colors[surface->map->info.colorkey].unused = SDL_ALPHA_TRANSPARENT; + } } else { + if (surface->format->palette) { + surface->format->palette->colors[surface->map->info.colorkey].unused = SDL_ALPHA_OPAQUE; + } surface->map->info.flags &= ~SDL_COPY_COLORKEY; } if (surface->map->info.flags != flags) { @@ -843,14 +849,35 @@ SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format, SDL_COPY_RLE_ALPHAKEY)); surface->map->info.flags = copy_flags; if (copy_flags & SDL_COPY_COLORKEY) { - Uint8 keyR, keyG, keyB, keyA; + SDL_bool set_colorkey_by_color = SDL_FALSE; - SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR, - &keyG, &keyB, &keyA); - SDL_SetColorKey(convert, 1, - SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); - /* This is needed when converting for 3D texture upload */ - SDL_ConvertColorkeyToAlpha(convert); + if (surface->format->palette) { + if (format->palette && + surface->format->palette->ncolors <= format->palette->ncolors && + (SDL_memcmp(surface->format->palette->colors, format->palette->colors, + surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) { + /* The palette is identical, just set the same colorkey */ + SDL_SetColorKey(convert, 1, surface->map->info.colorkey); + } else if (format->Amask) { + /* The alpha was set in the destination from the palette */ + } else { + set_colorkey_by_color = SDL_TRUE; + } + } else { + set_colorkey_by_color = SDL_TRUE; + } + + if (set_colorkey_by_color) { + /* Set the colorkey by color, which needs to be unique */ + Uint8 keyR, keyG, keyB, keyA; + + SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR, + &keyG, &keyB, &keyA); + SDL_SetColorKey(convert, 1, + SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); + /* This is needed when converting for 3D texture upload */ + SDL_ConvertColorkeyToAlpha(convert); + } } SDL_SetClipRect(convert, &surface->clip_rect); From e09b99c523fb83410ed6c84e75f8c12bd0ba8640 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 24 Mar 2013 09:56:45 -0700 Subject: [PATCH 112/151] We're using the alpha component of the palette entries, let's name it appropriately. --- include/SDL_pixels.h | 2 +- src/video/SDL_bmp.c | 6 +++--- src/video/SDL_pixels.c | 10 +++++----- src/video/SDL_surface.c | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h index 14bac9bcb..e73215260 100644 --- a/include/SDL_pixels.h +++ b/include/SDL_pixels.h @@ -256,7 +256,7 @@ typedef struct SDL_Color Uint8 r; Uint8 g; Uint8 b; - Uint8 unused; + Uint8 a; } SDL_Color; #define SDL_Colour SDL_Color diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index bb69af6cd..a6341f4c8 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -252,14 +252,14 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) SDL_RWread(src, &palette->colors[i].b, 1, 1); SDL_RWread(src, &palette->colors[i].g, 1, 1); SDL_RWread(src, &palette->colors[i].r, 1, 1); - palette->colors[i].unused = SDL_ALPHA_OPAQUE; + palette->colors[i].a = SDL_ALPHA_OPAQUE; } } else { for (i = 0; i < (int) biClrUsed; ++i) { SDL_RWread(src, &palette->colors[i].b, 1, 1); SDL_RWread(src, &palette->colors[i].g, 1, 1); SDL_RWread(src, &palette->colors[i].r, 1, 1); - SDL_RWread(src, &palette->colors[i].unused, 1, 1); + SDL_RWread(src, &palette->colors[i].a, 1, 1); } } } @@ -510,7 +510,7 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst) SDL_RWwrite(dst, &colors[i].b, 1, 1); SDL_RWwrite(dst, &colors[i].g, 1, 1); SDL_RWwrite(dst, &colors[i].r, 1, 1); - SDL_RWwrite(dst, &colors[i].unused, 1, 1); + SDL_RWwrite(dst, &colors[i].a, 1, 1); } } diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index b27520832..c9d5bd262 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -730,7 +730,7 @@ SDL_DitherColors(SDL_Color * colors, int bpp) b |= b << 2; b |= b << 4; colors[i].b = b; - colors[i].unused = SDL_ALPHA_OPAQUE; + colors[i].a = SDL_ALPHA_OPAQUE; } } @@ -776,7 +776,7 @@ SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a) rd = pal->colors[i].r - r; gd = pal->colors[i].g - g; bd = pal->colors[i].b - b; - ad = pal->colors[i].unused - a; + ad = pal->colors[i].a - a; distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad); if (distance < smallest) { pixel = i; @@ -859,7 +859,7 @@ SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format, *r = format->palette->colors[pixel].r; *g = format->palette->colors[pixel].g; *b = format->palette->colors[pixel].b; - *a = format->palette->colors[pixel].unused; + *a = format->palette->colors[pixel].a; } else { *r = *g = *b = *a = 0; } @@ -895,7 +895,7 @@ Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) for (i = 0; i < src->ncolors; ++i) { map[i] = SDL_FindColor(dst, src->colors[i].r, src->colors[i].g, - src->colors[i].b, src->colors[i].unused); + src->colors[i].b, src->colors[i].a); } return (map); } @@ -922,7 +922,7 @@ Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255); Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255); Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255); - Uint8 A = (Uint8) ((pal->colors[i].unused * Amod) / 255); + Uint8 A = (Uint8) ((pal->colors[i].a * Amod) / 255); ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A); } return (map); diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index b496a1b86..93fbdc8d7 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -188,11 +188,11 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) surface->map->info.flags |= SDL_COPY_COLORKEY; surface->map->info.colorkey = key; if (surface->format->palette) { - surface->format->palette->colors[surface->map->info.colorkey].unused = SDL_ALPHA_TRANSPARENT; + surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT; } } else { if (surface->format->palette) { - surface->format->palette->colors[surface->map->info.colorkey].unused = SDL_ALPHA_OPAQUE; + surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_OPAQUE; } surface->map->info.flags &= ~SDL_COPY_COLORKEY; } From 8718681e490d3d93bed10661051a7a441a65cbb7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 24 Mar 2013 10:37:16 -0700 Subject: [PATCH 113/151] Make sure we bump the palette version when we modify it. --- src/video/SDL_surface.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 93fbdc8d7..4c67dc916 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -189,10 +189,18 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) surface->map->info.colorkey = key; if (surface->format->palette) { surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT; + ++surface->format->palette->version; + if (!surface->format->palette->version) { + surface->format->palette->version = 1; + } } } else { if (surface->format->palette) { surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_OPAQUE; + ++surface->format->palette->version; + if (!surface->format->palette->version) { + surface->format->palette->version = 1; + } } surface->map->info.flags &= ~SDL_COPY_COLORKEY; } From abfb78058f6b4a89ea50f7867558adeaa3e89d2e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 25 Mar 2013 11:38:30 -0700 Subject: [PATCH 114/151] Added GUIDs for Bluetooth devices, using the same algorithm as the Linux code. Reformatted the code so it was easier to step through using gdb. --- src/joystick/darwin/SDL_sysjoystick.c | 125 +++++++++++++------------- 1 file changed, 60 insertions(+), 65 deletions(-) diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index dbdd6d568..9e36a5679 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -463,98 +463,92 @@ HIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties, /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties */ - if ((KERN_SUCCESS == - IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1)) - && (KERN_SUCCESS == - IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) - && (KERN_SUCCESS == - IORegistryEntryCreateCFProperties(parent2, &usbProperties, - kCFAllocatorDefault, - kNilOptions))) { + if ((KERN_SUCCESS == IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1)) + && (KERN_SUCCESS == IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) + && (KERN_SUCCESS == IORegistryEntryCreateCFProperties(parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) { if (usbProperties) { CFTypeRef refCF = 0; /* get device info * try hid dictionary first, if fail then go to usb dictionary */ - /* get product name */ - refCF = - CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); - if (!refCF) - refCF = - CFDictionaryGetValue(usbProperties, - CFSTR("USB Product Name")); + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); + if (!refCF) { + refCF = CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name")); + } if (refCF) { - if (!CFStringGetCString - (refCF, pDevice->product, 256, - CFStringGetSystemEncoding())) - SDL_SetError - ("CFStringGetCString error retrieving pDevice->product."); + if (!CFStringGetCString(refCF, pDevice->product, 256, CFStringGetSystemEncoding())) { + SDL_SetError("CFStringGetCString error retrieving pDevice->product."); + } } /* get usage page and usage */ - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDPrimaryUsagePageKey)); + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) { - if (!CFNumberGetValue - (refCF, kCFNumberLongType, &pDevice->usagePage)) - SDL_SetError - ("CFNumberGetValue error retrieving pDevice->usagePage."); - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDPrimaryUsageKey)); - if (refCF) - if (!CFNumberGetValue - (refCF, kCFNumberLongType, &pDevice->usage)) - SDL_SetError - ("CFNumberGetValue error retrieving pDevice->usage."); + if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage)) { + SDL_SetError("CFNumberGetValue error retrieving pDevice->usagePage."); + } + + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); + if (refCF) { + if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage)) { + SDL_SetError("CFNumberGetValue error retrieving pDevice->usage."); + } + } } - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDVendorIDKey)); + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDVendorIDKey)); if (refCF) { - if (!CFNumberGetValue - (refCF, kCFNumberLongType, &pDevice->guid.data[0])) - SDL_SetError - ("CFNumberGetValue error retrieving pDevice->guid."); - } - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDProductIDKey)); - if (refCF) { - if (!CFNumberGetValue - (refCF, kCFNumberLongType, &pDevice->guid.data[8])) - SDL_SetError - ("CFNumberGetValue error retrieving pDevice->guid[8]."); + if (!CFNumberGetValue(refCF, kCFNumberLongType, &pDevice->guid.data[0])) { + SDL_SetError("CFNumberGetValue error retrieving pDevice->guid[0]"); + } } - - if (NULL == refCF) { /* get top level element HID usage page or usage */ + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductIDKey)); + if (refCF) { + if (!CFNumberGetValue(refCF, kCFNumberLongType, &pDevice->guid.data[8])) { + SDL_SetError("CFNumberGetValue error retrieving pDevice->guid[8]"); + } + } + + /* Check to make sure we have a vendor and product ID + If we don't, use the same algorithm as the Linux code for Bluetooth devices */ + { + Uint32 *guid32 = (Uint32*)pDevice->guid.data; + if (!guid32[0] && !guid32[1]) { + const Uint16 BUS_BLUETOOTH = 0x05; + Uint16 *guid16 = (Uint16 *)guid32; + *guid16++ = BUS_BLUETOOTH; + *guid16++ = 0; + SDL_strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4); + } + } + + /* If we don't have a vendor and product ID this is probably a Bluetooth device */ + + if (NULL == refCF) { /* get top level element HID usage page or usage */ /* use top level element instead */ CFTypeRef refCFTopElement = 0; - refCFTopElement = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDElementKey)); + refCFTopElement = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDElementKey)); { /* refCFTopElement points to an array of element dictionaries */ CFRange range = { 0, CFArrayGetCount(refCFTopElement) }; - CFArrayApplyFunction(refCFTopElement, range, - HIDTopLevelElementHandler, pDevice); + CFArrayApplyFunction(refCFTopElement, range, HIDTopLevelElementHandler, pDevice); } } CFRelease(usbProperties); - } else - SDL_SetError - ("IORegistryEntryCreateCFProperties failed to create usbProperties."); + } else { + SDL_SetError("IORegistryEntryCreateCFProperties failed to create usbProperties."); + } - if (kIOReturnSuccess != IOObjectRelease(parent2)) - SDL_SetError("IOObjectRelease error with parent2."); - if (kIOReturnSuccess != IOObjectRelease(parent1)) - SDL_SetError("IOObjectRelease error with parent1."); + if (kIOReturnSuccess != IOObjectRelease(parent2)) { + SDL_SetError("IOObjectRelease error with parent2"); + } + if (kIOReturnSuccess != IOObjectRelease(parent1)) { + SDL_SetError("IOObjectRelease error with parent1"); + } } } @@ -1100,4 +1094,5 @@ SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick) } #endif /* SDL_JOYSTICK_IOKIT */ + /* vi: set ts=4 sw=4 expandtab: */ From aff63d09c254c106b077ce10fd727120392e9ef3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 25 Mar 2013 12:04:16 -0700 Subject: [PATCH 115/151] Added support for the GameStop Gamepad --- src/joystick/SDL_gamecontroller.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index c6e5b10a7..8bb18b853 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -94,9 +94,11 @@ const char *s_ControllerMappings [] = "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7", "88880803000000000000504944564944,PS3,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12", "25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,x:b0,y:b3,start:b8,guide:,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5", + "ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", #elif defined(__MACOSX__) "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", + "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", #elif defined(__LINUX__) "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", "030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", @@ -106,6 +108,7 @@ const char *s_ControllerMappings [] = "030000006d04000019c2000011010000,Logitech F710 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // Guide button doesn't seem to be sent in DInput mode. "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", + "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", #endif NULL }; From 1e10688f01a98e25a11858d1e17c27d4966f1a21 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Mar 2013 04:57:29 -0700 Subject: [PATCH 116/151] SDL message box improvements from Dan Thompson --- src/video/windows/SDL_windowsmessagebox.c | 245 +++++++++++++++++++--- 1 file changed, 218 insertions(+), 27 deletions(-) diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 9865d7778..0ed50aff6 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -28,9 +28,39 @@ /* Display a Windows message box */ +#pragma pack(push, 1) + typedef struct { - LPDLGTEMPLATE lpDialog; + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x; + short y; + short cx; + short cy; +} DLGTEMPLATEEX; + +typedef struct +{ + DWORD helpID; + DWORD exStyle; + DWORD style; + short x; + short y; + short cx; + short cy; + DWORD id; +} DLGITEMTEMPLATEEX; + +#pragma pack(pop) + +typedef struct +{ + DLGTEMPLATEEX* lpDialog; Uint8 *data; size_t size; size_t used; @@ -70,7 +100,7 @@ static SDL_bool ExpandDialogSpace(WIN_DialogData *dialog, size_t space) } dialog->data = data; dialog->size = size; - dialog->lpDialog = (LPDLGTEMPLATE)dialog->data; + dialog->lpDialog = (DLGTEMPLATEEX*)dialog->data; } return SDL_TRUE; } @@ -128,21 +158,35 @@ static SDL_bool AddDialogString(WIN_DialogData *dialog, const char *string) return status; } +static int s_BaseUnitsX; +static int s_BaseUnitsY; +static void Vec2ToDLU(WORD* x, WORD* y) +{ + SDL_assert(s_BaseUnitsX != 0); // we init in WIN_ShowMessageBox(), which is the only public function... + + *x = MulDiv(*x, 4, s_BaseUnitsX); + *y = MulDiv(*y, 8, s_BaseUnitsY); +} + + static SDL_bool AddDialogControl(WIN_DialogData *dialog, WORD type, DWORD style, DWORD exStyle, int x, int y, int w, int h, int id, const char *caption) { - DLGITEMTEMPLATE item; + DLGITEMTEMPLATEEX item; WORD marker = 0xFFFF; WORD extraData = 0; SDL_zero(item); item.style = style; - item.dwExtendedStyle = exStyle; + item.exStyle = exStyle; item.x = x; item.y = y; item.cx = w; item.cy = h; item.id = id; + Vec2ToDLU(&item.x, &item.y); + Vec2ToDLU(&item.cx, &item.cy); + if (!AlignDialogData(dialog, sizeof(DWORD))) { return SDL_FALSE; } @@ -161,14 +205,14 @@ static SDL_bool AddDialogControl(WIN_DialogData *dialog, WORD type, DWORD style, if (!AddDialogData(dialog, &extraData, sizeof(extraData))) { return SDL_FALSE; } - ++dialog->lpDialog->cdit; + ++dialog->lpDialog->cDlgItems; return SDL_TRUE; } static SDL_bool AddDialogStatic(WIN_DialogData *dialog, int x, int y, int w, int h, const char *text) { - DWORD style = WS_VISIBLE | WS_CHILD | SS_LEFT | SS_NOPREFIX; + DWORD style = WS_VISIBLE | WS_CHILD | SS_LEFT | SS_NOPREFIX | SS_EDITCONTROL; return AddDialogControl(dialog, 0x0082, style, 0, x, y, w, h, -1, text); } @@ -194,14 +238,18 @@ static void FreeDialogData(WIN_DialogData *dialog) static WIN_DialogData *CreateDialogData(int w, int h, const char *caption) { WIN_DialogData *dialog; - DLGTEMPLATE dialogTemplate; + DLGTEMPLATEEX dialogTemplate; + WORD WordToPass; SDL_zero(dialogTemplate); - dialogTemplate.style = (WS_CAPTION | DS_CENTER); + dialogTemplate.dlgVer = 1; + dialogTemplate.signature = 0xffff; + dialogTemplate.style = (WS_CAPTION | DS_CENTER | DS_SHELLFONT); dialogTemplate.x = 0; dialogTemplate.y = 0; dialogTemplate.cx = w; dialogTemplate.cy = h; + Vec2ToDLU(&dialogTemplate.cx, &dialogTemplate.cy); dialog = (WIN_DialogData *)SDL_calloc(1, sizeof(*dialog)); if (!dialog) { @@ -213,17 +261,76 @@ static WIN_DialogData *CreateDialogData(int w, int h, const char *caption) return NULL; } - /* There is no menu or special class */ - if (!AddDialogString(dialog, "") || !AddDialogString(dialog, "")) { + // No menu + WordToPass = 0; + if (!AddDialogData(dialog, &WordToPass, 2)) { FreeDialogData(dialog); return NULL; } + // No custom class + if (!AddDialogData(dialog, &WordToPass, 2)) { + FreeDialogData(dialog); + return NULL; + } + + // title if (!AddDialogString(dialog, caption)) { FreeDialogData(dialog); return NULL; } + // Font stuff + { + // + // We want to use the system messagebox font. + // + BYTE ToPass; + + NONCLIENTMETRICSA NCM; + NCM.cbSize = sizeof(NCM); + SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0); + + // Font size - convert to logical font size for dialog parameter. + { + HDC ScreenDC = GetDC(0); + WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / GetDeviceCaps(ScreenDC, LOGPIXELSY)); + ReleaseDC(0, ScreenDC); + } + + if (!AddDialogData(dialog, &WordToPass, 2)) { + FreeDialogData(dialog); + return NULL; + } + + // Font weight + WordToPass = (WORD)NCM.lfMessageFont.lfWeight; + if (!AddDialogData(dialog, &WordToPass, 2)) { + FreeDialogData(dialog); + return NULL; + } + + // italic? + ToPass = NCM.lfMessageFont.lfItalic; + if (!AddDialogData(dialog, &ToPass, 1)) { + FreeDialogData(dialog); + return NULL; + } + + // charset? + ToPass = NCM.lfMessageFont.lfCharSet; + if (!AddDialogData(dialog, &ToPass, 1)) { + FreeDialogData(dialog); + return NULL; + } + + // font typeface. + if (!AddDialogString(dialog, NCM.lfMessageFont.lfFaceName)) { + FreeDialogData(dialog); + return NULL; + } + } + return dialog; } @@ -231,30 +338,114 @@ int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) { WIN_DialogData *dialog; - int i, x, y, w, h, gap; - INT_PTR which; + int i, x, y, which; const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; - - /* FIXME: Need a better algorithm for laying out the message box */ + HFONT DialogFont; + SIZE Size; + RECT TextSize; + wchar_t* wmessage; + TEXTMETRIC TM; - dialog = CreateDialogData(570, 260, messageboxdata->title); + + const int ButtonWidth = 88; + const int ButtonHeight = 26; + const int TextMargin = 16; + const int ButtonMargin = 12; + + + // Jan 25th, 2013 - dant@fleetsa.com + // + // + // I've tried to make this more reasonable, but I've run in to a lot + // of nonsense. + // + // The original issue is the code was written in pixels and not + // dialog units (DLUs). All DialogBox functions use DLUs, which + // vary based on the selected font (yay). + // + // According to MSDN, the most reliable way to convert is via + // MapDialogUnits, which requires an HWND, which we don't have + // at time of template creation. + // + // We do however have: + // The system font (DLU width 8 for me) + // The font we select for the dialog (DLU width 6 for me) + // + // Based on experimentation, *neither* of these return the value + // actually used. Stepping in to MapDialogUnits(), the conversion + // is fairly clear, and uses 7 for me. + // + // As a result, some of this is hacky to ensure the sizing is + // somewhat correct. + // + // Honestly, a long term solution is to use CreateWindow, not CreateDialog. + // + + // + // In order to get text dimensions we need to have a DC with the desired font. + // I'm assuming a dialog box in SDL is rare enough we can to the create. + // + HDC FontDC = CreateCompatibleDC(0); + + { + // Create a duplicate of the font used in system message boxes. + LOGFONT lf; + NONCLIENTMETRICS NCM; + NCM.cbSize = sizeof(NCM); + SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0); + lf = NCM.lfMessageFont; + DialogFont = CreateFontIndirect(&lf); + } + + // Select the font in to our DC + SelectObject(FontDC, DialogFont); + + { + // Get the metrics to try and figure our DLU conversion. + GetTextMetrics(FontDC, &TM); + s_BaseUnitsX = TM.tmAveCharWidth + 1; + s_BaseUnitsY = TM.tmHeight; + } + + // Measure the *pixel* size of the string. + wmessage = WIN_UTF8ToString(messageboxdata->message); + SDL_zero(TextSize); + Size.cx = DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT); + + // Add some padding for hangs, etc. + TextSize.right += 2; + TextSize.bottom += 2; + + // Done with the DC, and the string + DeleteDC(FontDC); + SDL_free(wmessage); + + // Increase the size of the dialog by some border spacing around the text. + Size.cx = TextSize.right - TextSize.left; + Size.cy = TextSize.bottom - TextSize.top; + Size.cx += TextMargin * 2; + Size.cy += TextMargin * 2; + + // Ensure the size is wide enough for all of the buttons. + if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin) + Size.cx = messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin; + + // Add vertical space for the buttons and border. + Size.cy += ButtonHeight + TextMargin; + + dialog = CreateDialogData(Size.cx, Size.cy, messageboxdata->title); if (!dialog) { return -1; } - w = 100; - h = 25; - gap = 10; - x = gap; - y = 50; - - if (!AddDialogStatic(dialog, x, y, 550, 100, messageboxdata->message)) { + if (!AddDialogStatic(dialog, TextMargin, TextMargin, TextSize.right - TextSize.left, TextSize.bottom - TextSize.top, messageboxdata->message)) { FreeDialogData(dialog); return -1; } - y += 110; - + // Align the buttons to the right/bottom. + x = Size.cx - ButtonWidth - ButtonMargin; + y = Size.cy - ButtonHeight - ButtonMargin; for (i = 0; i < messageboxdata->numbuttons; ++i) { SDL_bool isDefault; @@ -263,15 +454,15 @@ WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) } else { isDefault = SDL_FALSE; } - if (!AddDialogButton(dialog, x, y, w, h, buttons[i].text, i, isDefault)) { + if (!AddDialogButton(dialog, x, y, ButtonWidth, ButtonHeight, buttons[i].text, i, isDefault)) { FreeDialogData(dialog); return -1; } - x += w + gap; + x -= ButtonWidth + ButtonMargin; } /* FIXME: If we have a parent window, get the Instance and HWND for them */ - which = DialogBoxIndirect(NULL, dialog->lpDialog, NULL, (DLGPROC)MessageBoxDialogProc); + which = DialogBoxIndirect(NULL, (DLGTEMPLATE*)dialog->lpDialog, NULL, (DLGPROC)MessageBoxDialogProc); *buttonid = buttons[which].buttonid; FreeDialogData(dialog); From 607bf8a77c435d8ddbd5ab327606ea0daeff59b2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Mar 2013 05:08:57 -0700 Subject: [PATCH 117/151] Fixed compiler warning with Cygwin --- src/video/windows/SDL_windowsevents.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 03491a846..6a62df573 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -179,6 +179,8 @@ WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam ) return SDL_SCANCODE_KP_DIVIDE; case SDL_SCANCODE_CAPSLOCK: return SDL_SCANCODE_KP_PLUS; + default: + break; } } From 75a30e72a06081784d35e2f0127fdc453ae0509a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Mar 2013 05:09:09 -0700 Subject: [PATCH 118/151] Fixed compiler error with Cygwin --- src/video/windows/SDL_windowsmessagebox.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 0ed50aff6..562fc83ed 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -26,6 +26,10 @@ #include "SDL_windowsvideo.h" +#ifndef SS_EDITCONTROL +#define SS_EDITCONTROL 0x2000 +#endif + /* Display a Windows message box */ #pragma pack(push, 1) From f36b6b53efb0c1d3ae2e064a3655d53be09dc213 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Mar 2013 22:26:07 -0700 Subject: [PATCH 119/151] =?UTF-8?q?The=20Haiku=20port=20is=20being=20activ?= =?UTF-8?q?ely=20maintained=20by=20Axel=20D=C3=B6rfler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.Platforms | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.Platforms b/README.Platforms index 19a6e429a..1e0e7a6aa 100644 --- a/README.Platforms +++ b/README.Platforms @@ -24,9 +24,9 @@ Solaris Platforms supported by volunteers ================================= -Pandora - maintained by Scott Smith +Haiku - maintained by Axel Dörfler PSP - maintained by 527721088@qq.com +Pandora - maintained by Scott Smith Platforms that need maintainers =============================== -Haiku From b7b75855ecd5a2b5dc332071f224473d0efd2787 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 29 Mar 2013 21:13:16 -0400 Subject: [PATCH 120/151] Fixed compiler warnings with SDL_FORCE_INLINE on gcc2. (Thanks, Axel!) Fixes Bugzilla #1770. --- include/begin_code.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/begin_code.h b/include/begin_code.h index 61b8250d1..f0e111ad4 100644 --- a/include/begin_code.h +++ b/include/begin_code.h @@ -130,7 +130,7 @@ #if defined(_MSC_VER) #define SDL_FORCE_INLINE __forceinline -#elif defined(__GNUC__) || defined(__clang__) +#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) ) #define SDL_FORCE_INLINE __attribute__((always_inline)) static inline #else #define SDL_FORCE_INLINE static __inline__ From 6432ccda7f75ed30752e358a850fdf0d461204b0 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 29 Mar 2013 21:16:30 -0400 Subject: [PATCH 121/151] Don't use __builtin_clz() on gcc2. (thanks, Axel!) Fixes Bugzilla #1771. --- include/SDL_bits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL_bits.h b/include/SDL_bits.h index 4b35a77cf..d678b7822 100644 --- a/include/SDL_bits.h +++ b/include/SDL_bits.h @@ -52,7 +52,7 @@ extern "C" { SDL_FORCE_INLINE Sint8 SDL_MostSignificantBitIndex32(Uint32 x) { -#if defined(__GNUC__) +#if defined(__GNUC__) && __GNUC__ >= 4 /* Count Leading Zeroes builtin in GCC. * http://gcc.gnu.org/onlinedocs/gcc-4.3.4/gcc/Other-Builtins.html */ From f3d6be82af7900a614b475024932ada00da115c0 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 29 Mar 2013 21:21:48 -0400 Subject: [PATCH 122/151] Patched test apps to compile with C89 compilers (thanks, Axel!). Fixes Bugzilla #1772. --- test/testaudioinfo.c | 4 +++- test/testwm2.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/testaudioinfo.c b/test/testaudioinfo.c index ac3191a52..ff7c25b7f 100644 --- a/test/testaudioinfo.c +++ b/test/testaudioinfo.c @@ -36,6 +36,8 @@ print_devices(int iscapture) int main(int argc, char **argv) { + int n; + /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); @@ -43,7 +45,7 @@ main(int argc, char **argv) } /* Print available audio drivers */ - int n = SDL_GetNumAudioDrivers(); + n = SDL_GetNumAudioDrivers(); if (n == 0) { printf("No built-in audio drivers\n\n"); } else { diff --git a/test/testwm2.c b/test/testwm2.c index 8f1897403..bdc484ec3 100644 --- a/test/testwm2.c +++ b/test/testwm2.c @@ -42,13 +42,14 @@ main(int argc, char *argv[]) "NO", "hand", }; - SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS); int i, done; SDL_Event event; int system_cursor = -1; SDL_Cursor *cursor = NULL; + SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS); + /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { From d7b0215c79cec0cc0df5f6a5fb9dc035aa72fa3f Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 29 Mar 2013 21:25:02 -0400 Subject: [PATCH 123/151] Haiku no longer #defines __BEOS__, so check for it too (thanks, Axel!). Fixes Bugzilla #1773. --- src/main/beos/SDL_BeApp.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index ae5e9ad1c..78eb3fb0e 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -20,7 +20,7 @@ */ #include "SDL_config.h" -#ifdef __BEOS__ +#if defined(__BEOS__) || defined(__HAIKU__) /* Handle the BeApp specific portions of the application */ From 8c6b9f474350dc7513a2d88c31d4c389000e9461 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 29 Mar 2013 21:29:57 -0400 Subject: [PATCH 124/151] Corrected function signature on SDL_strtod_inline() (thanks, Axel!). Fixes Bugzilla #1774. --- include/SDL_stdinc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index bc400524b..f1e0edbca 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -592,7 +592,7 @@ SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int ba extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp); #ifdef HAVE_STRTOD -SDL_FORCE_INLINE Uint64 SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); } +SDL_FORCE_INLINE double SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); } #define SDL_strtod SDL_strtod_inline #endif From 4f438b70a2dd81a890f6eb42db70190d90d9576c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 31 Mar 2013 12:48:50 -0400 Subject: [PATCH 125/151] Make SDL_SetError and friends unconditionally return -1. This lets us change things like this... if (Failed) { SDL_SetError("We failed"); return -1; } ...into this... if (Failed) { return SDL_SetError("We failed"); } Fixes Bugzilla #1778. --- include/SDL_error.h | 6 +- src/SDL.c | 18 +-- src/SDL_error.c | 26 ++--- src/audio/SDL_audiocvt.c | 15 +-- src/audio/SDL_wave.c | 12 +- src/audio/directsound/SDL_directsound.c | 13 +-- src/audio/sun/SDL_sunaudio.c | 6 +- src/core/android/SDL_android.cpp | 12 +- src/core/windows/SDL_windows.c | 3 +- src/core/windows/SDL_windows.h | 4 +- src/events/SDL_events.c | 3 +- src/events/SDL_gesture.c | 9 +- src/events/SDL_mouse.c | 3 +- src/events/SDL_touch.c | 12 +- src/file/SDL_rwops.c | 27 ++--- src/haptic/SDL_haptic.c | 33 ++---- src/haptic/darwin/SDL_syshaptic.c | 86 +++++--------- src/haptic/linux/SDL_syshaptic.c | 57 ++++------ src/haptic/windows/SDL_syshaptic.c | 89 ++++++--------- src/joystick/SDL_gamecontroller.c | 3 +- src/joystick/SDL_joystick.c | 3 +- src/joystick/android/SDL_androidjoystick.c | 19 ++-- src/joystick/beos/SDL_bejoystick.cc | 9 +- src/joystick/bsd/SDL_sysjoystick.c | 14 +-- src/joystick/darwin/SDL_sysjoystick.c | 14 +-- src/joystick/dummy/SDL_sysjoystick.c | 3 +- src/joystick/iphoneos/SDL_sysjoystick.m | 3 - src/joystick/linux/SDL_sysjoystick.c | 18 +-- src/joystick/psp/SDL_sysjoystick.c | 6 +- src/joystick/windows/SDL_dxjoystick.c | 67 ++++------- src/joystick/windows/SDL_mmjoystick.c | 3 +- src/main/beos/SDL_BeApp.cc | 3 +- src/render/SDL_render.c | 71 ++++-------- src/render/SDL_yuv_sw.c | 11 +- src/render/direct3d/SDL_render_d3d.c | 88 +++++---------- src/render/opengl/SDL_render_gl.c | 20 ++-- src/render/opengles/SDL_render_gles.c | 40 +++---- src/render/opengles2/SDL_render_gles2.c | 89 +++++---------- src/render/psp/SDL_render_psp.c | 3 +- src/render/software/SDL_blendfillrect.c | 18 +-- src/render/software/SDL_blendline.c | 12 +- src/render/software/SDL_blendpoint.c | 18 +-- src/render/software/SDL_drawline.c | 12 +- src/render/software/SDL_drawpoint.c | 18 +-- src/render/software/SDL_render_sw.c | 15 +-- src/test/SDL_test_fuzzer.c | 4 +- src/thread/beos/SDL_syssem.c | 12 +- src/thread/beos/SDL_systhread.c | 3 +- src/thread/generic/SDL_syscond.c | 9 +- src/thread/generic/SDL_sysmutex.c | 12 +- src/thread/generic/SDL_syssem.c | 22 ++-- src/thread/generic/SDL_systhread.c | 3 +- src/thread/psp/SDL_syscond.c | 9 +- src/thread/psp/SDL_sysmutex.c | 9 +- src/thread/psp/SDL_syssem.c | 9 +- src/thread/psp/SDL_systhread.c | 3 +- src/thread/pthread/SDL_syscond.c | 34 ++---- src/thread/pthread/SDL_sysmutex.c | 36 ++---- src/thread/pthread/SDL_syssem.c | 14 +-- src/thread/pthread/SDL_systhread.c | 17 +-- src/thread/windows/SDL_sysmutex.c | 9 +- src/thread/windows/SDL_syssem.c | 12 +- src/thread/windows/SDL_systhread.c | 11 +- src/video/SDL_RLEaccel.c | 6 +- src/video/SDL_blit.c | 5 +- src/video/SDL_fillrect.c | 12 +- src/video/SDL_pixels.c | 6 +- src/video/SDL_stretch.c | 24 ++-- src/video/SDL_surface.c | 27 ++--- src/video/SDL_video.c | 123 +++++++-------------- src/video/android/SDL_androidgl.c | 3 +- src/video/android/SDL_androidwindow.c | 3 +- src/video/bwindow/SDL_bframebuffer.cc | 3 +- src/video/bwindow/SDL_bmodes.cc | 3 +- src/video/cocoa/SDL_cocoamodes.m | 4 +- src/video/cocoa/SDL_cocoamouse.m | 3 +- src/video/cocoa/SDL_cocoaopengl.m | 3 +- src/video/cocoa/SDL_cocoawindow.m | 9 +- src/video/directfb/SDL_DirectFB_opengl.c | 9 +- src/video/directfb/SDL_DirectFB_render.c | 15 +-- src/video/directfb/SDL_DirectFB_window.c | 6 +- src/video/dummy/SDL_nullframebuffer.c | 3 +- src/video/pandora/SDL_pandora.c | 36 ++---- src/video/psp/SDL_pspgl.c | 6 +- src/video/psp/SDL_pspvideo.c | 3 +- src/video/uikit/SDL_uikitmodes.m | 6 +- src/video/uikit/SDL_uikitopengles.m | 3 +- src/video/uikit/SDL_uikitvideo.m | 2 +- src/video/uikit/SDL_uikitwindow.m | 9 +- src/video/windows/SDL_windowsclipboard.c | 6 +- src/video/windows/SDL_windowsevents.c | 5 +- src/video/windows/SDL_windowsframebuffer.c | 3 +- src/video/windows/SDL_windowsmodes.c | 6 +- src/video/windows/SDL_windowsmouse.c | 3 +- src/video/windows/SDL_windowsopengl.c | 39 +++---- src/video/windows/SDL_windowsvideo.c | 2 +- src/video/windows/SDL_windowswindow.c | 15 +-- src/video/x11/SDL_x11clipboard.c | 3 +- src/video/x11/SDL_x11framebuffer.c | 15 +-- src/video/x11/SDL_x11messagebox.c | 24 ++-- src/video/x11/SDL_x11modes.c | 15 +-- src/video/x11/SDL_x11opengl.c | 22 ++-- src/video/x11/SDL_x11opengles.c | 44 +++----- src/video/x11/SDL_x11shape.c | 3 +- src/video/x11/SDL_x11video.c | 2 +- src/video/x11/SDL_x11window.c | 24 ++-- 106 files changed, 616 insertions(+), 1189 deletions(-) diff --git a/include/SDL_error.h b/include/SDL_error.h index fe7f762cd..81c64da66 100644 --- a/include/SDL_error.h +++ b/include/SDL_error.h @@ -39,7 +39,8 @@ extern "C" { #endif /* Public functions */ -extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...); +/* SDL_SetError() unconditionally returns -1. */ +extern DECLSPEC int SDLCALL SDL_SetError(const char *fmt, ...); extern DECLSPEC const char *SDLCALL SDL_GetError(void); extern DECLSPEC void SDLCALL SDL_ClearError(void); @@ -62,7 +63,8 @@ typedef enum SDL_UNSUPPORTED, SDL_LASTERROR } SDL_errorcode; -extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code); +/* SDL_Error() unconditionally returns -1. */ +extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code); /*@}*//*Internal error functions*/ /* Ends C function definitions when using C++ */ diff --git a/src/SDL.c b/src/SDL.c index aebc3fe36..829da1e7b 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -109,8 +109,7 @@ SDL_InitSubSystem(Uint32 flags) } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER); #else - SDL_SetError("SDL not built with timer support"); - return (-1); + return SDL_SetError("SDL not built with timer support"); #endif } @@ -124,8 +123,7 @@ SDL_InitSubSystem(Uint32 flags) } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO); #else - SDL_SetError("SDL not built with video support"); - return (-1); + return SDL_SetError("SDL not built with video support"); #endif } @@ -139,8 +137,7 @@ SDL_InitSubSystem(Uint32 flags) } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO); #else - SDL_SetError("SDL not built with audio support"); - return (-1); + return SDL_SetError("SDL not built with audio support"); #endif } @@ -159,8 +156,7 @@ SDL_InitSubSystem(Uint32 flags) } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK); #else - SDL_SetError("SDL not built with joystick support"); - return (-1); + return SDL_SetError("SDL not built with joystick support"); #endif } @@ -173,8 +169,7 @@ SDL_InitSubSystem(Uint32 flags) } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER); #else - SDL_SetError("SDL not built with joystick support"); - return (-1); + return SDL_SetError("SDL not built with joystick support"); #endif } @@ -188,8 +183,7 @@ SDL_InitSubSystem(Uint32 flags) } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC); #else - SDL_SetError("SDL not built with haptic (force feedback) support"); - return (-1); + return SDL_SetError("SDL not built with haptic (force feedback) support"); #endif } diff --git a/src/SDL_error.c b/src/SDL_error.c index a94b1827f..40388124b 100644 --- a/src/SDL_error.c +++ b/src/SDL_error.c @@ -49,14 +49,14 @@ SDL_LookupString(const char *key) /* Public functions */ -void +int SDL_SetError(const char *fmt, ...) { va_list ap; SDL_error *error; /* Ignore call if invalid format pointer was passed */ - if (fmt == NULL) return; + if (fmt == NULL) return -1; /* Copy in the key, mark error as valid */ error = SDL_GetErrBuf(); @@ -112,6 +112,8 @@ SDL_SetError(const char *fmt, ...) /* If we are in debug mode, print out an error message */ SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError()); + + return -1; } /* This function has a bit more overhead than most error functions @@ -216,28 +218,22 @@ SDL_ClearError(void) } /* Very common errors go here */ -void +int SDL_Error(SDL_errorcode code) { switch (code) { case SDL_ENOMEM: - SDL_SetError("Out of memory"); - break; + return SDL_SetError("Out of memory"); case SDL_EFREAD: - SDL_SetError("Error reading from datastream"); - break; + return SDL_SetError("Error reading from datastream"); case SDL_EFWRITE: - SDL_SetError("Error writing to datastream"); - break; + return SDL_SetError("Error writing to datastream"); case SDL_EFSEEK: - SDL_SetError("Error seeking in datastream"); - break; + return SDL_SetError("Error seeking in datastream"); case SDL_UNSUPPORTED: - SDL_SetError("That operation is not supported"); - break; + return SDL_SetError("That operation is not supported"); default: - SDL_SetError("Unknown SDL error"); - break; + return SDL_SetError("Unknown SDL error"); } } diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index 1c6b493bd..2d067e779 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -970,28 +970,23 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt, /* Sanity check target pointer */ if (cvt == NULL) { - SDL_InvalidParamError("cvt"); - return -1; + return SDL_InvalidParamError("cvt"); } /* there are no unsigned types over 16 bits, so catch this up front. */ if ((SDL_AUDIO_BITSIZE(src_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(src_fmt))) { - SDL_SetError("Invalid source format"); - return -1; + return SDL_SetError("Invalid source format"); } if ((SDL_AUDIO_BITSIZE(dst_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(dst_fmt))) { - SDL_SetError("Invalid destination format"); - return -1; + return SDL_SetError("Invalid destination format"); } /* prevent possible divisions by zero, etc. */ if ((src_channels == 0) || (dst_channels == 0)) { - SDL_SetError("Source or destination channels is zero"); - return -1; + return SDL_SetError("Source or destination channels is zero"); } if ((src_rate == 0) || (dst_rate == 0)) { - SDL_SetError("Source or destination rate is zero"); - return -1; + return SDL_SetError("Source or destination rate is zero"); } #ifdef DEBUG_CONVERT printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n", diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c index 7bcc59e9f..b1bd0538c 100644 --- a/src/audio/SDL_wave.c +++ b/src/audio/SDL_wave.c @@ -134,8 +134,7 @@ MS_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len) MS_ADPCM_state.wavefmt.channels * sizeof(Sint16); *audio_buf = (Uint8 *) SDL_malloc(*audio_len); if (*audio_buf == NULL) { - SDL_Error(SDL_ENOMEM); - return (-1); + return SDL_OutOfMemory(); } decoded = *audio_buf; @@ -359,8 +358,7 @@ IMA_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len) IMA_ADPCM_state.wavefmt.channels * sizeof(Sint16); *audio_buf = (Uint8 *) SDL_malloc(*audio_len); if (*audio_buf == NULL) { - SDL_Error(SDL_ENOMEM); - return (-1); + return SDL_OutOfMemory(); } decoded = *audio_buf; @@ -620,14 +618,12 @@ ReadChunk(SDL_RWops * src, Chunk * chunk) chunk->length = SDL_ReadLE32(src); chunk->data = (Uint8 *) SDL_malloc(chunk->length); if (chunk->data == NULL) { - SDL_Error(SDL_ENOMEM); - return (-1); + return SDL_OutOfMemory(); } if (SDL_RWread(src, chunk->data, chunk->length, 1) != 1) { - SDL_Error(SDL_EFREAD); SDL_free(chunk->data); chunk->data = NULL; - return (-1); + return SDL_Error(SDL_EFREAD); } return (chunk->length); } diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c index 24a599d54..a26fa7e0c 100644 --- a/src/audio/directsound/SDL_directsound.c +++ b/src/audio/directsound/SDL_directsound.c @@ -95,7 +95,7 @@ utf16_to_utf8(const WCHAR *S) (SDL_wcslen(S)+1)*sizeof(WCHAR)); } -static void +static int SetDSerror(const char *function, int code) { static const char *error; @@ -145,8 +145,7 @@ SetDSerror(const char *function, int code) SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); } - SDL_SetError("%s", errbuf); - return; + return SDL_SetError("%s", errbuf); } @@ -380,16 +379,14 @@ CreateSecondary(_THIS, HWND focus, WAVEFORMATEX * wavefmt) format.dwBufferBytes = numchunks * chunksize; if ((format.dwBufferBytes < DSBSIZE_MIN) || (format.dwBufferBytes > DSBSIZE_MAX)) { - SDL_SetError("Sound buffer size must be between %d and %d", - DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks); - return (-1); + return SDL_SetError("Sound buffer size must be between %d and %d", + DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks); } format.dwReserved = 0; format.lpwfxFormat = wavefmt; result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL); if (result != DS_OK) { - SetDSerror("DirectSound CreateSoundBuffer", result); - return (-1); + return SetDSerror("DirectSound CreateSoundBuffer", result); } IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt); diff --git a/src/audio/sun/SDL_sunaudio.c b/src/audio/sun/SDL_sunaudio.c index 2d643b503..c5a33d47f 100644 --- a/src/audio/sun/SDL_sunaudio.c +++ b/src/audio/sun/SDL_sunaudio.c @@ -332,8 +332,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->frequency = 8; this->hidden->ulaw_buf = (Uint8 *) SDL_malloc(this->hidden->fragsize); if (this->hidden->ulaw_buf == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } this->spec.channels = 1; } else { @@ -353,8 +352,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) /* Allocate mixing buffer */ this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size); if (this->hidden->mixbuf == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); diff --git a/src/core/android/SDL_android.cpp b/src/core/android/SDL_android.cpp index d87e724c2..9ca73d60a 100644 --- a/src/core/android/SDL_android.cpp +++ b/src/core/android/SDL_android.cpp @@ -811,8 +811,7 @@ static int Android_JNI_FileClose(SDL_RWops* ctx, bool release) JNIEnv *mEnv = Android_JNI_GetEnv(); if (!refs.init(mEnv)) { - SDL_SetError("Failed to allocate enough JVM local references"); - return -1; + return SDL_SetError("Failed to allocate enough JVM local references"); } if (ctx) { @@ -875,8 +874,7 @@ extern "C" Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence offset = ctx->hidden.androidio.offset + ctx->hidden.androidio.size + offset; break; default: - SDL_SetError("Unknown value for 'whence'"); - return -1; + return SDL_SetError("Unknown value for 'whence'"); } whence = SEEK_SET; @@ -897,14 +895,12 @@ extern "C" Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence newPosition = ctx->hidden.androidio.size + offset; break; default: - SDL_SetError("Unknown value for 'whence'"); - return -1; + return SDL_SetError("Unknown value for 'whence'"); } /* Validate the new position */ if (newPosition < 0) { - SDL_Error(SDL_EFSEEK); - return -1; + return SDL_Error(SDL_EFSEEK); } if (newPosition > ctx->hidden.androidio.size) { newPosition = ctx->hidden.androidio.size; diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index 0927832f0..e69d25793 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -29,7 +29,7 @@ #include /* for CoInitialize/CoUninitialize */ /* Sets an error message based on GetLastError() */ -void +int WIN_SetError(const char *prefix) { TCHAR buffer[1024]; @@ -39,6 +39,7 @@ WIN_SetError(const char *prefix) message = WIN_StringToUTF8(buffer); SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); SDL_free(message); + return -1; } HRESULT diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index c30fa9be6..440c387d3 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -43,8 +43,8 @@ #define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1) #endif -/* Sets an error message based on GetLastError() */ -extern void WIN_SetError(const char *prefix); +/* Sets an error message based on GetLastError(). Always return -1. */ +extern int WIN_SetError(const char *prefix); /* Wrap up the oddities of CoInitialize() into a common function. */ extern HRESULT WIN_CoInitialize(void); diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index b608590c4..ade28a697 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -244,8 +244,7 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action, } SDL_UnlockMutex(SDL_EventQ.lock); } else { - SDL_SetError("Couldn't lock event queue"); - used = -1; + return SDL_SetError("Couldn't lock event queue"); } return (used); } diff --git a/src/events/SDL_gesture.c b/src/events/SDL_gesture.c index bd7681e3a..a56aa3e55 100644 --- a/src/events/SDL_gesture.c +++ b/src/events/SDL_gesture.c @@ -158,8 +158,7 @@ int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) } } } - SDL_SetError("Unknown gestureId"); - return -1; + return SDL_SetError("Unknown gestureId"); } //path is an already sampled set of points @@ -176,8 +175,7 @@ static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* p (index + 1) * sizeof(SDL_DollarTemplate)); if (!dollarTemplate) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } inTouch->dollarTemplate = dollarTemplate; @@ -419,8 +417,7 @@ int SDL_GestureAddTouch(SDL_TouchID touchId) sizeof(SDL_GestureTouch)); if (!gestureTouch) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_gestureTouch = gestureTouch; diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index ba3eec2d1..d467d0791 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -413,8 +413,7 @@ SDL_SetRelativeMouseMode(SDL_bool enabled) } if (!mouse->SetRelativeMouseMode) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } if (mouse->SetRelativeMouseMode(enabled) < 0) { diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 4b41e2741..c2bb22ece 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -141,8 +141,7 @@ SDL_AddTouch(SDL_TouchID touchID, const char *name) touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices, (SDL_num_touch + 1) * sizeof(*touchDevices)); if (!touchDevices) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_touchDevices = touchDevices; @@ -150,8 +149,7 @@ SDL_AddTouch(SDL_TouchID touchID, const char *name) SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index])); if (!SDL_touchDevices[index]) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* we're setting the touch properties */ @@ -176,14 +174,12 @@ SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float p SDL_Finger **new_fingers; new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers)); if (!new_fingers) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } touch->fingers = new_fingers; touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger)); if (!touch->fingers[touch->max_fingers]) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } touch->max_fingers++; } diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 0b67978d6..ec4f5be8f 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -87,8 +87,7 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode) context->hidden.windowsio.buffer.data = (char *) SDL_malloc(READAHEAD_BUFFER_SIZE); if (!context->hidden.windowsio.buffer.data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Do not open a dialog box if failure */ old_error_mode = @@ -124,13 +123,11 @@ windows_file_size(SDL_RWops * context) LARGE_INTEGER size; if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) { - SDL_SetError("windows_file_size: invalid context/file not opened"); - return -1; + return SDL_SetError("windows_file_size: invalid context/file not opened"); } if (!GetFileSizeEx(context->hidden.windowsio.h, &size)) { - WIN_SetError("windows_file_size"); - return -1; + return WIN_SetError("windows_file_size"); } return size.QuadPart; @@ -143,8 +140,7 @@ windows_file_seek(SDL_RWops * context, Sint64 offset, int whence) LARGE_INTEGER windowsoffset; if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) { - SDL_SetError("windows_file_seek: invalid context/file not opened"); - return -1; + return SDL_SetError("windows_file_seek: invalid context/file not opened"); } /* FIXME: We may be able to satisfy the seek within buffered data */ @@ -164,14 +160,12 @@ windows_file_seek(SDL_RWops * context, Sint64 offset, int whence) windowswhence = FILE_END; break; default: - SDL_SetError("windows_file_seek: Unknown value for 'whence'"); - return -1; + return SDL_SetError("windows_file_seek: Unknown value for 'whence'"); } windowsoffset.QuadPart = offset; if (!SetFilePointerEx(context->hidden.windowsio.h, windowsoffset, &windowsoffset, windowswhence)) { - WIN_SetError("windows_file_seek"); - return -1; + return WIN_SetError("windows_file_seek"); } return windowsoffset.QuadPart; } @@ -325,8 +319,7 @@ stdio_seek(SDL_RWops * context, Sint64 offset, int whence) return (ftell(context->hidden.stdio.fp)); } #endif - SDL_Error(SDL_EFSEEK); - return (-1); + return SDL_Error(SDL_EFSEEK); } static size_t SDLCALL @@ -361,8 +354,7 @@ stdio_close(SDL_RWops * context) if (context->hidden.stdio.autoclose) { /* WARNING: Check the return value here! */ if (fclose(context->hidden.stdio.fp) != 0) { - SDL_Error(SDL_EFWRITE); - status = -1; + status = SDL_Error(SDL_EFWRITE); } } SDL_FreeRW(context); @@ -395,8 +387,7 @@ mem_seek(SDL_RWops * context, Sint64 offset, int whence) newpos = context->hidden.mem.stop + offset; break; default: - SDL_SetError("Unknown value for 'whence'"); - return (-1); + return SDL_SetError("Unknown value for 'whence'"); } if (newpos < context->hidden.mem.base) { newpos = context->hidden.mem.base; diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index d6b8a7b2e..5952a455d 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -447,8 +447,7 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect) /* Check to see if effect is supported */ if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) { - SDL_SetError("Haptic: Effect not supported by haptic device."); - return -1; + return SDL_SetError("Haptic: Effect not supported by haptic device."); } /* See if there's a free slot */ @@ -467,8 +466,7 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect) } } - SDL_SetError("Haptic: Device has no free space left."); - return -1; + return SDL_SetError("Haptic: Device has no free space left."); } /* @@ -497,8 +495,7 @@ SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, /* Can't change type dynamically. */ if (data->type != haptic->effects[effect].effect.type) { - SDL_SetError("Haptic: Updating effect type is illegal."); - return -1; + return SDL_SetError("Haptic: Updating effect type is illegal."); } /* Updates the effect */ @@ -579,8 +576,7 @@ SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect) } if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) { - SDL_SetError("Haptic: Device does not support status queries."); - return -1; + return SDL_SetError("Haptic: Device does not support status queries."); } return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]); @@ -600,13 +596,11 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain) } if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) { - SDL_SetError("Haptic: Device does not support setting gain."); - return -1; + return SDL_SetError("Haptic: Device does not support setting gain."); } if ((gain < 0) || (gain > 100)) { - SDL_SetError("Haptic: Gain must be between 0 and 100."); - return -1; + return SDL_SetError("Haptic: Gain must be between 0 and 100."); } /* We use the envvar to get the maximum gain. */ @@ -644,13 +638,11 @@ SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) } if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) { - SDL_SetError("Haptic: Device does not support setting autocenter."); - return -1; + return SDL_SetError("Haptic: Device does not support setting autocenter."); } if ((autocenter < 0) || (autocenter > 100)) { - SDL_SetError("Haptic: Autocenter must be between 0 and 100."); - return -1; + return SDL_SetError("Haptic: Autocenter must be between 0 and 100."); } if (SDL_SYS_HapticSetAutocenter(haptic, autocenter) < 0) { @@ -671,8 +663,7 @@ SDL_HapticPause(SDL_Haptic * haptic) } if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) { - SDL_SetError("Haptic: Device does not support setting pausing."); - return -1; + return SDL_SetError("Haptic: Device does not support setting pausing."); } return SDL_SYS_HapticPause(haptic); @@ -773,8 +764,7 @@ SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length) } if (haptic->rumble_id < 0) { - SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); - return -1; + return SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); } /* Clamp strength. */ @@ -805,8 +795,7 @@ SDL_HapticRumbleStop(SDL_Haptic * haptic) } if (haptic->rumble_id < 0) { - SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); - return -1; + return SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); } return SDL_HapticStopEffect(haptic, haptic->rumble_id); diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index 32548b373..1af86b8b1 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -160,15 +160,13 @@ SDL_SYS_HapticInit(void) /* Get HID devices. */ match = IOServiceMatching(kIOHIDDeviceKey); if (match == NULL) { - SDL_SetError("Haptic: Failed to get IOServiceMatching."); - return -1; + return SDL_SetError("Haptic: Failed to get IOServiceMatching."); } /* Now search I/O Registry for matching devices. */ result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter); if (result != kIOReturnSuccess) { - SDL_SetError("Haptic: Couldn't create a HID object iterator."); - return -1; + return SDL_SetError("Haptic: Couldn't create a HID object iterator."); } /* IOServiceGetMatchingServices consumes dictionary. */ @@ -257,8 +255,7 @@ HIDGetDeviceProduct(io_service_t dev, char *name) ret = IORegistryEntryCreateCFProperties(dev, &hidProperties, kCFAllocatorDefault, kNilOptions); if ((ret != KERN_SUCCESS) || !hidProperties) { - SDL_SetError("Haptic: Unable to create CFProperties."); - return -1; + return SDL_SetError("Haptic: Unable to create CFProperties."); } /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also @@ -289,17 +286,15 @@ HIDGetDeviceProduct(io_service_t dev, char *name) if (refCF) { if (!CFStringGetCString(refCF, name, 256, CFStringGetSystemEncoding())) { - SDL_SetError + return SDL_SetError ("Haptic: CFStringGetCString error retrieving pDevice->product."); - return -1; } } CFRelease(usbProperties); } else { - SDL_SetError + return SDL_SetError ("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties."); - return -1; } /* Release stuff. */ @@ -310,8 +305,7 @@ HIDGetDeviceProduct(io_service_t dev, char *name) SDL_SetError("Haptic: IOObjectRelease error with parent1."); } } else { - SDL_SetError("Haptic: Error getting registry entries."); - return -1; + return SDL_SetError("Haptic: Error getting registry entries."); } return 0; @@ -336,8 +330,7 @@ GetSupportedFeatures(SDL_Haptic * haptic) ret = FFDeviceGetForceFeedbackCapabilities(device, &features); if (ret != FF_OK) { - SDL_SetError("Haptic: Unable to get device's supported features."); - return -1; + return SDL_SetError("Haptic: Unable to get device's supported features."); } supported = 0; @@ -366,9 +359,8 @@ GetSupportedFeatures(SDL_Haptic * haptic) if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN; else if (ret != FFERR_UNSUPPORTED) { - SDL_SetError("Haptic: Unable to get if device supports gain: %s.", - FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Unable to get if device supports gain: %s.", + FFStrError(ret)); } /* Checks if supports autocenter. */ @@ -377,10 +369,9 @@ GetSupportedFeatures(SDL_Haptic * haptic) if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER; else if (ret != FFERR_UNSUPPORTED) { - SDL_SetError + return SDL_SetError ("Haptic: Unable to get if device supports autocenter: %s.", FFStrError(ret)); - return -1; } /* Check for axes, we have an artificial limit on axes */ @@ -625,8 +616,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes) /* Has axes. */ rglDir = SDL_malloc(sizeof(LONG) * naxes); if (rglDir == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(rglDir, 0, sizeof(LONG) * naxes); effect->rglDirection = rglDir; @@ -654,8 +644,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes) return 0; default: - SDL_SetError("Haptic: Unknown direction type."); - return -1; + return SDL_SetError("Haptic: Unknown direction type."); } } @@ -695,8 +684,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, /* Envelope. */ envelope = SDL_malloc(sizeof(FFENVELOPE)); if (envelope == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(envelope, 0, sizeof(FFENVELOPE)); dest->lpEnvelope = envelope; @@ -707,8 +695,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, if (dest->cAxes > 0) { axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); if (axes == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ if (dest->cAxes > 1) { @@ -727,8 +714,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_constant = &src->constant; constant = SDL_malloc(sizeof(FFCONSTANTFORCE)); if (constant == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE)); @@ -771,8 +757,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_periodic = &src->periodic; periodic = SDL_malloc(sizeof(FFPERIODIC)); if (periodic == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(periodic, 0, sizeof(FFPERIODIC)); @@ -817,8 +802,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_condition = &src->condition; condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes); if (condition == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(condition, 0, sizeof(FFCONDITION)); @@ -860,8 +844,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_ramp = &src->ramp; ramp = SDL_malloc(sizeof(FFRAMPFORCE)); if (ramp == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(ramp, 0, sizeof(FFRAMPFORCE)); @@ -899,8 +882,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_custom = &src->custom; custom = SDL_malloc(sizeof(FFCUSTOMFORCE)); if (custom == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE)); @@ -944,8 +926,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, default: - SDL_SetError("Haptic: Unknown effect type."); - return -1; + return SDL_SetError("Haptic: Unknown effect type."); } return 0; @@ -1150,9 +1131,8 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, /* Run the effect. */ ret = FFEffectStart(effect->hweffect->ref, iter, 0); if (ret != FF_OK) { - SDL_SetError("Haptic: Unable to run the effect: %s.", - FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Unable to run the effect: %s.", + FFStrError(ret)); } return 0; @@ -1169,9 +1149,8 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) ret = FFEffectStop(effect->hweffect->ref); if (ret != FF_OK) { - SDL_SetError("Haptic: Unable to stop the effect: %s.", - FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Unable to stop the effect: %s.", + FFStrError(ret)); } return 0; @@ -1236,8 +1215,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, FFPROP_FFGAIN, &val); if (ret != FF_OK) { - SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret)); } return 0; @@ -1262,9 +1240,8 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, FFPROP_AUTOCENTER, &val); if (ret != FF_OK) { - SDL_SetError("Haptic: Error setting autocenter: %s.", - FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error setting autocenter: %s.", + FFStrError(ret)); } return 0; @@ -1282,8 +1259,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic) ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_PAUSE); if (ret != FF_OK) { - SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); } return 0; @@ -1301,8 +1277,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic) ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_CONTINUE); if (ret != FF_OK) { - SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); } return 0; @@ -1320,8 +1295,7 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic) ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_STOPALL); if (ret != FF_OK) { - SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret)); } return 0; diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index 6f40cd775..e07c832f9 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -92,9 +92,8 @@ EV_IsHaptic(int fd) /* Ask device for what it has. */ ret = 0; if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) { - SDL_SetError("Haptic: Unable to get device's features: %s", - strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to get device's features: %s", + strerror(errno)); } /* Convert supported features to SDL_HAPTIC platform-neutral features. */ @@ -309,9 +308,8 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic) /* Open the character device */ fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0); if (fd < 0) { - SDL_SetError("Haptic: Unable to open %s: %s", - SDL_hapticlist[haptic->index], strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to open %s: %s", + SDL_hapticlist[haptic->index], strerror(errno)); } /* Try to create the haptic. */ @@ -340,9 +338,8 @@ SDL_SYS_HapticMouse(void) /* Open the device. */ fd = open(SDL_hapticlist[i].fname, O_RDWR, 0); if (fd < 0) { - SDL_SetError("Haptic: Unable to open %s: %s", - SDL_hapticlist[i], strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to open %s: %s", + SDL_hapticlist[i], strerror(errno)); } /* Is it a mouse? */ @@ -405,15 +402,13 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) } } if (i >= MAX_HAPTICS) { - SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities"); - return -1; + return SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities"); } fd = open(joystick->hwdata->fname, O_RDWR, 0); if (fd < 0) { - SDL_SetError("Haptic: Unable to open %s: %s", - joystick->hwdata->fname, strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to open %s: %s", + joystick->hwdata->fname, strerror(errno)); } ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */ if (ret < 0) { @@ -544,8 +539,7 @@ SDL_SYS_ToDirection(SDL_HapticDirection * dir) return (Uint16) tmp; default: - SDL_SetError("Haptic: Unsupported direction type."); - return (Uint16) - 1; + return (Uint16) SDL_SetError("Haptic: Unsupported direction type."); } return 0; @@ -733,8 +727,7 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) default: - SDL_SetError("Haptic: Unknown effect type."); - return -1; + return SDL_SetError("Haptic: Unknown effect type."); } return 0; @@ -754,8 +747,7 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, effect->hweffect = (struct haptic_hweffect *) SDL_malloc(sizeof(struct haptic_hweffect)); if (effect->hweffect == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Prepare the ff_effect */ @@ -802,9 +794,8 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, /* See if it can be uploaded. */ if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) { - SDL_SetError("Haptic: Error updating the effect: %s", - strerror(errno)); - return -1; + return SDL_SetError("Haptic: Error updating the effect: %s", + strerror(errno)); } /* Copy the new effect into memory. */ @@ -831,8 +822,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, run.value = (iterations > INT_MAX) ? INT_MAX : iterations; if (write(haptic->hwdata->fd, (const void *) &run, sizeof(run)) < 0) { - SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno)); } return 0; @@ -852,9 +842,8 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) stop.value = 0; if (write(haptic->hwdata->fd, (const void *) &stop, sizeof(stop)) < 0) { - SDL_SetError("Haptic: Unable to stop the effect: %s", - strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to stop the effect: %s", + strerror(errno)); } return 0; @@ -891,8 +880,7 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, ie.code = effect->hweffect->effect.id; if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { - SDL_SetError("Haptic: Error getting device status."); - return -1; + return SDL_SetError("Haptic: Error getting device status."); } return 0; @@ -915,8 +903,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) ie.value = (0xFFFFUL * gain) / 100; if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { - SDL_SetError("Haptic: Error setting gain: %s", strerror(errno)); - return -1; + return SDL_SetError("Haptic: Error setting gain: %s", strerror(errno)); } return 0; @@ -936,8 +923,7 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) ie.value = (0xFFFFUL * autocenter) / 100; if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { - SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno)); - return -1; + return SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno)); } return 0; @@ -977,9 +963,8 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic) if (haptic->effects[i].hweffect != NULL) { ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]); if (ret < 0) { - SDL_SetError + return SDL_SetError ("Haptic: Error while trying to stop all playing effects."); - return -1; } } } diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c index a4a2644a1..9446ce52a 100644 --- a/src/haptic/windows/SDL_syshaptic.c +++ b/src/haptic/windows/SDL_syshaptic.c @@ -87,7 +87,7 @@ extern HWND SDL_HelperWindow; /* * Prototypes. */ -static void DI_SetError(const char *str, HRESULT err); +static int DI_SetError(const char *str, HRESULT err); static int DI_GUIDIsSame(const GUID * a, const GUID * b); static int SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance); @@ -110,14 +110,14 @@ static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv); /* * Like SDL_SetError but for DX error codes. */ -static void +static int DI_SetError(const char *str, HRESULT err) { /* SDL_SetError("Haptic: %s - %s: %s", str, DXGetErrorString8A(err), DXGetErrorDescription8A(err)); */ - SDL_SetError("Haptic error %s", str); + return SDL_SetError("Haptic error %s", str); } @@ -142,8 +142,7 @@ SDL_SYS_HapticInit(void) HINSTANCE instance; if (dinput != NULL) { /* Already open. */ - SDL_SetError("Haptic: SubSystem already open."); - return -1; + return SDL_SetError("Haptic: SubSystem already open."); } /* Clear all the memory. */ @@ -153,8 +152,7 @@ SDL_SYS_HapticInit(void) ret = WIN_CoInitialize(); if (FAILED(ret)) { - DI_SetError("Coinitialize", ret); - return -1; + return DI_SetError("Coinitialize", ret); } coinitialized = SDL_TRUE; @@ -163,23 +161,20 @@ SDL_SYS_HapticInit(void) &IID_IDirectInput8, (LPVOID) & dinput); if (FAILED(ret)) { SDL_SYS_HapticQuit(); - DI_SetError("CoCreateInstance", ret); - return -1; + return DI_SetError("CoCreateInstance", ret); } /* Because we used CoCreateInstance, we need to Initialize it, first. */ instance = GetModuleHandle(NULL); if (instance == NULL) { SDL_SYS_HapticQuit(); - SDL_SetError("GetModuleHandle() failed with error code %d.", - GetLastError()); - return -1; + return SDL_SetError("GetModuleHandle() failed with error code %d.", + GetLastError()); } ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION); if (FAILED(ret)) { SDL_SYS_HapticQuit(); - DI_SetError("Initializing DirectInput device", ret); - return -1; + return DI_SetError("Initializing DirectInput device", ret); } /* Look for haptic devices. */ @@ -191,8 +186,7 @@ SDL_SYS_HapticInit(void) DIEDFL_ATTACHEDONLY); if (FAILED(ret)) { SDL_SYS_HapticQuit(); - DI_SetError("Enumerating DirectInput devices", ret); - return -1; + return DI_SetError("Enumerating DirectInput devices", ret); } if (!env || SDL_atoi(env)) { @@ -411,8 +405,7 @@ SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, Uint8 userid) haptic->effects = (struct haptic_effect *) SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); if (haptic->effects == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Clear the memory */ SDL_memset(haptic->effects, 0, @@ -422,8 +415,7 @@ SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, Uint8 userid) if (haptic->hwdata == NULL) { SDL_free(haptic->effects); haptic->effects = NULL; - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); @@ -690,8 +682,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) haptic->hwdata = (struct haptic_hwdata *) SDL_malloc(sizeof(*haptic->hwdata)); if (haptic->hwdata == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); @@ -809,8 +800,7 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes) /* Has axes. */ rglDir = SDL_malloc(sizeof(LONG) * naxes); if (rglDir == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(rglDir, 0, sizeof(LONG) * naxes); effect->rglDirection = rglDir; @@ -838,8 +828,7 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes) return 0; default: - SDL_SetError("Haptic: Unknown direction type."); - return -1; + return SDL_SetError("Haptic: Unknown direction type."); } } @@ -875,8 +864,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, /* Envelope. */ envelope = SDL_malloc(sizeof(DIENVELOPE)); if (envelope == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(envelope, 0, sizeof(DIENVELOPE)); dest->lpEnvelope = envelope; @@ -887,8 +875,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, if (dest->cAxes > 0) { axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); if (axes == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ if (dest->cAxes > 1) { @@ -907,8 +894,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_constant = &src->constant; constant = SDL_malloc(sizeof(DICONSTANTFORCE)); if (constant == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(constant, 0, sizeof(DICONSTANTFORCE)); @@ -951,8 +937,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_periodic = &src->periodic; periodic = SDL_malloc(sizeof(DIPERIODIC)); if (periodic == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(periodic, 0, sizeof(DIPERIODIC)); @@ -997,8 +982,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_condition = &src->condition; condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes); if (condition == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(condition, 0, sizeof(DICONDITION)); @@ -1040,8 +1024,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_ramp = &src->ramp; ramp = SDL_malloc(sizeof(DIRAMPFORCE)); if (ramp == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(ramp, 0, sizeof(DIRAMPFORCE)); @@ -1079,8 +1062,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_custom = &src->custom; custom = SDL_malloc(sizeof(DICUSTOMFORCE)); if (custom == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(custom, 0, sizeof(DICUSTOMFORCE)); @@ -1124,8 +1106,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, default: - SDL_SetError("Haptic: Unknown effect type."); - return -1; + return SDL_SetError("Haptic: Unknown effect type."); } return 0; @@ -1358,8 +1339,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, /* Run the effect. */ ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0); if (FAILED(ret)) { - DI_SetError("Running the effect", ret); - return -1; + return DI_SetError("Running the effect", ret); } return 0; @@ -1381,8 +1361,7 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) ret = IDirectInputEffect_Stop(effect->hweffect->ref); if (FAILED(ret)) { - DI_SetError("Unable to stop effect", ret); - return -1; + return DI_SetError("Unable to stop effect", ret); } return 0; @@ -1424,8 +1403,7 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status); if (FAILED(ret)) { - DI_SetError("Getting effect status", ret); - return -1; + return DI_SetError("Getting effect status", ret); } if (status == 0) @@ -1454,8 +1432,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device, DIPROP_FFGAIN, &dipdw.diph); if (FAILED(ret)) { - DI_SetError("Setting gain", ret); - return -1; + return DI_SetError("Setting gain", ret); } return 0; @@ -1483,8 +1460,7 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device, DIPROP_AUTOCENTER, &dipdw.diph); if (FAILED(ret)) { - DI_SetError("Setting autocenter", ret); - return -1; + return DI_SetError("Setting autocenter", ret); } return 0; @@ -1503,8 +1479,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic) ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, DISFFC_PAUSE); if (FAILED(ret)) { - DI_SetError("Pausing the device", ret); - return -1; + return DI_SetError("Pausing the device", ret); } return 0; @@ -1523,8 +1498,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic) ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, DISFFC_CONTINUE); if (FAILED(ret)) { - DI_SetError("Pausing the device", ret); - return -1; + return DI_SetError("Pausing the device", ret); } return 0; @@ -1548,8 +1522,7 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic) ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, DISFFC_STOPALL); if (FAILED(ret)) { - DI_SetError("Stopping the device", ret); - return -1; + return DI_SetError("Stopping the device", ret); } return 0; diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 8bb18b853..037f6b6a5 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -722,10 +722,9 @@ SDL_GameControllerAddMapping( const char *mappingString ) } else { pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); if (!pControllerMapping) { - SDL_OutOfMemory(); SDL_free( pchName ); SDL_free( pchMapping ); - return -1; + return SDL_OutOfMemory(); } #ifdef SDL_JOYSTICK_DINPUT if ( is_xinput_mapping ) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index e92536366..6099ed176 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -303,8 +303,7 @@ SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy) joystick->balls[ball].dx = 0; joystick->balls[ball].dy = 0; } else { - SDL_SetError("Joystick only has %d balls", joystick->nballs); - retval = -1; + return SDL_SetError("Joystick only has %d balls", joystick->nballs); } return (retval); } diff --git a/src/joystick/android/SDL_androidjoystick.c b/src/joystick/android/SDL_androidjoystick.c index 6bee7cbf7..41ccd2240 100644 --- a/src/joystick/android/SDL_androidjoystick.c +++ b/src/joystick/android/SDL_androidjoystick.c @@ -77,31 +77,26 @@ SDL_SYS_JoystickInit(void) { int i = 0; if (Android_JNI_JoystickInit() < 0) - return (-1); + return -1; SYS_numjoysticks = Android_JNI_GetNumJoysticks(); SYS_Joysticks = (SDL_Joystick **)SDL_malloc(SYS_numjoysticks*sizeof(SDL_Joystick *)); - if (SYS_Joysticks == NULL) - { - SDL_OutOfMemory(); - return (-1); + if (SYS_Joysticks == NULL) { + return SDL_OutOfMemory(); } SYS_JoystickNames = (char **)SDL_malloc(SYS_numjoysticks*sizeof(char *)); - if (SYS_JoystickNames == NULL) - { + if (SYS_JoystickNames == NULL) { SDL_free(SYS_Joysticks); SYS_Joysticks = NULL; - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(SYS_JoystickNames, 0, (SYS_numjoysticks*sizeof(char *))); SDL_memset(SYS_Joysticks, 0, (SYS_numjoysticks*sizeof(SDL_Joystick *))); - for (i = 0; i < SYS_numjoysticks; i++) - { + for (i = 0; i < SYS_numjoysticks; i++) { SYS_JoystickNames[i] = Android_JNI_GetJoystickName(i); } - return (SYS_numjoysticks); + return SYS_numjoysticks; } int SDL_SYS_NumJoysticks() diff --git a/src/joystick/beos/SDL_bejoystick.cc b/src/joystick/beos/SDL_bejoystick.cc index 5d41e58e3..f8a7f14a0 100644 --- a/src/joystick/beos/SDL_bejoystick.cc +++ b/src/joystick/beos/SDL_bejoystick.cc @@ -125,8 +125,7 @@ extern "C" joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); if (joystick->hwdata == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); stick = new BJoystick; @@ -134,9 +133,8 @@ extern "C" /* Open the requested joystick for use */ if (stick->Open(SDL_joyport[device_index]) == B_ERROR) { - SDL_SetError("Unable to open joystick"); SDL_SYS_JoystickClose(joystick); - return (-1); + return SDL_SetError("Unable to open joystick"); } /* Set the joystick to calibrated mode */ @@ -152,9 +150,8 @@ extern "C" joystick->hwdata->new_hats = (uint8 *) SDL_malloc(joystick->nhats * sizeof(uint8)); if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) { - SDL_OutOfMemory(); SDL_SYS_JoystickClose(joystick); - return (-1); + return SDL_OutOfMemory(); } /* We're done! */ diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c index ff1588764..bbdae328c 100644 --- a/src/joystick/bsd/SDL_sysjoystick.c +++ b/src/joystick/bsd/SDL_sysjoystick.c @@ -297,17 +297,15 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index) fd = open(path, O_RDONLY); if (fd == -1) { - SDL_SetError("%s: %s", path, strerror(errno)); - return (-1); + return SDL_SetError("%s: %s", path, strerror(errno)); } joy->instance_id = device_index; hw = (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata)); if (hw == NULL) { - SDL_OutOfMemory(); close(fd); - return (-1); + return SDL_OutOfMemory(); } joy->hwdata = hw; hw->fd = fd; @@ -634,8 +632,7 @@ report_alloc(struct report *r, struct report_desc *rd, int repind) #endif if (len < 0) { - SDL_SetError("Negative HID report size"); - return (-1); + return SDL_SetError("Negative HID report size"); } r->size = len; @@ -647,15 +644,14 @@ report_alloc(struct report *r, struct report_desc *rd, int repind) r->size); #endif if (r->buf == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } } else { r->buf = NULL; } r->status = SREPORT_CLEAN; - return (0); + return 0; } static void diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 9e36a5679..ee16028b2 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -169,7 +169,7 @@ HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice) &(pDevice->interface)); if (S_OK != plugInResult) HIDReportErrorNum - ("CouldnÕt query HID class device interface from plugInInterface", + ("Couldn't query HID class device interface from plugInInterface", plugInResult); (*ppPlugInInterface)->Release(ppPlugInInterface); } else @@ -724,14 +724,12 @@ SDL_SYS_JoystickInit(void) io_iterator_t portIterator = 0; if (gpDeviceList) { - SDL_SetError("Joystick: Device list already inited."); - return -1; + return SDL_SetError("Joystick: Device list already inited."); } result = IOMasterPort(bootstrap_port, &masterPort); if (kIOReturnSuccess != result) { - SDL_SetError("Joystick: IOMasterPort error with bootstrap_port."); - return -1; + return SDL_SetError("Joystick: IOMasterPort error with bootstrap_port."); } /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */ @@ -750,9 +748,8 @@ SDL_SYS_JoystickInit(void) CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage); */ } else { - SDL_SetError + return SDL_SetError ("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching."); - return -1; } /*/ Now search I/O Registry for matching devices. */ @@ -761,8 +758,7 @@ SDL_SYS_JoystickInit(void) &hidObjectIterator); /* Check for errors */ if (kIOReturnSuccess != result) { - SDL_SetError("Joystick: Couldn't create a HID object iterator."); - return -1; + return SDL_SetError("Joystick: Couldn't create a HID object iterator."); } if (!hidObjectIterator) { /* there are no joysticks */ gpDeviceList = NULL; diff --git a/src/joystick/dummy/SDL_sysjoystick.c b/src/joystick/dummy/SDL_sysjoystick.c index e20f38e9e..2f03e39c3 100644 --- a/src/joystick/dummy/SDL_sysjoystick.c +++ b/src/joystick/dummy/SDL_sysjoystick.c @@ -73,8 +73,7 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) { - SDL_SetError("Logic error: No joysticks available"); - return (-1); + return SDL_SetError("Logic error: No joysticks available"); } /* Function to determine is this joystick is attached to the system right now */ diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m index a275732f9..e93002576 100644 --- a/src/joystick/iphoneos/SDL_sysjoystick.m +++ b/src/joystick/iphoneos/SDL_sysjoystick.m @@ -122,15 +122,12 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick) [[SDLUIAccelerationDelegate sharedDelegate] shutdown]; } SDL_SetError("No joystick open with that index"); - - return; } /* Function to perform any system-specific joystick related cleanup */ void SDL_SYS_JoystickQuit(void) { - return; } SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index cf1afeb41..98e6c0ec0 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -387,8 +387,7 @@ JoystickInitWithUdev(void) SDL_assert(udev == NULL); udev = UDEV_udev_new(); if (udev == NULL) { - SDL_SetError("udev_new() failed"); - return -1; + return SDL_SetError("udev_new() failed"); } udev_mon = UDEV_udev_monitor_new_from_netlink(udev, "udev"); @@ -400,8 +399,7 @@ JoystickInitWithUdev(void) enumerate = UDEV_udev_enumerate_new(udev); if (enumerate == NULL) { - SDL_SetError("udev_enumerate_new() failed"); - return -1; + return SDL_SetError("udev_enumerate_new() failed"); } UDEV_udev_enumerate_add_match_subsystem(enumerate, "input"); @@ -725,15 +723,13 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) int fd = -1; if (item == NULL) { - SDL_SetError("No such device"); - return -1; + return SDL_SetError("No such device"); } fname = item->path; fd = open(fname, O_RDONLY, 0); if (fd < 0) { - SDL_SetError("Unable to open %s", fname); - return -1; + return SDL_SetError("Unable to open %s", fname); } joystick->instance_id = item->device_instance; @@ -741,8 +737,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) SDL_malloc(sizeof(*joystick->hwdata)); if (joystick->hwdata == NULL) { close(fd); - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); joystick->hwdata->item = item; @@ -753,8 +748,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) SDL_free(joystick->hwdata); joystick->hwdata = NULL; close(fd); - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_assert(item->hwdata == NULL); diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c index 69cab8402..a2c51a285 100644 --- a/src/joystick/psp/SDL_sysjoystick.c +++ b/src/joystick/psp/SDL_sysjoystick.c @@ -113,13 +113,11 @@ int SDL_SYS_JoystickInit(void) /* Start thread to read data */ if((pad_sem = SDL_CreateSemaphore(1)) == NULL) { - SDL_SetError("Can't create input semaphore\n"); - return -1; + return SDL_SetError("Can't create input semaphore"); } running = 1; if((thread = SDL_CreateThread(JoystickUpdate, "JoySitckThread",NULL)) == NULL) { - SDL_SetError("Can't create input thread\n"); - return -1; + return SDL_SetError("Can't create input thread"); } /* Create an accurate map from analog inputs (0 to 255) diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index aac20489f..6ac7f338d 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -159,7 +159,7 @@ typedef struct JoyStick_DeviceData_ JoyStick_DeviceData; static JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */ /* local prototypes */ -static void SetDIerror(const char *function, HRESULT code); +static int SetDIerror(const char *function, HRESULT code); static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext); static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, @@ -352,14 +352,14 @@ const DIDATAFORMAT c_dfDIJoystick2 = { /* Convert a DirectInput return code to a text message */ -static void +static int SetDIerror(const char *function, HRESULT code) { /* - SDL_SetError("%s() [%s]: %s", function, + return SDL_SetError("%s() [%s]: %s", function, DXGetErrorString9A(code), DXGetErrorDescription9A(code)); */ - SDL_SetError("%s() DirectX error %d", function, code); + return SDL_SetError("%s() DirectX error %d", function, code); } @@ -565,17 +565,13 @@ SDL_JoystickThread(void *_data) if (!RegisterClassEx (&wincl)) { - SDL_SetError("Failed to create register class for joystick autodetect.", - GetLastError()); - return -1; + return SDL_SetError("Failed to create register class for joystick autodetect.", GetLastError()); } messageWindow = (HWND)CreateWindowEx( 0, L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL ); if ( !messageWindow ) { - SDL_SetError("Failed to create message window for joystick autodetect.", - GetLastError()); - return -1; + return SDL_SetError("Failed to create message window for joystick autodetect.", GetLastError()); } SDL_memset(&dbh, 0x0, sizeof(dbh)); @@ -587,9 +583,7 @@ SDL_JoystickThread(void *_data) hNotify = RegisterDeviceNotification( messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE ); if ( !hNotify ) { - SDL_SetError("Failed to create notify device for joystick autodetect.", - GetLastError()); - return -1; + return SDL_SetError("Failed to create notify device for joystick autodetect.", GetLastError()); } SDL_LockMutex( s_mutexJoyStickEnum ); @@ -674,8 +668,7 @@ SDL_SYS_JoystickInit(void) result = WIN_CoInitialize(); if (FAILED(result)) { - SetDIerror("CoInitialize", result); - return (-1); + return SetDIerror("CoInitialize", result); } coinitialized = SDL_TRUE; @@ -685,24 +678,20 @@ SDL_SYS_JoystickInit(void) if (FAILED(result)) { SDL_SYS_JoystickQuit(); - SetDIerror("CoCreateInstance", result); - return (-1); + return SetDIerror("CoCreateInstance", result); } /* Because we used CoCreateInstance, we need to Initialize it, first. */ instance = GetModuleHandle(NULL); if (instance == NULL) { SDL_SYS_JoystickQuit(); - SDL_SetError("GetModuleHandle() failed with error code %d.", - GetLastError()); - return (-1); + return SDL_SetError("GetModuleHandle() failed with error code %d.", GetLastError()); } result = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION); if (FAILED(result)) { SDL_SYS_JoystickQuit(); - SetDIerror("IDirectInput::Initialize", result); - return (-1); + return SetDIerror("IDirectInput::Initialize", result); } s_mutexJoyStickEnum = SDL_CreateMutex(); @@ -967,8 +956,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata)); if (joystick->hwdata == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(joystick->hwdata, 0, sizeof(struct joystick_hwdata)); joystick->hwdata->buffered = 1; @@ -1040,8 +1028,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) IDirectInput8_CreateDevice(dinput, &(joystickdevice->dxdevice.guidInstance), &device, NULL); if (FAILED(result)) { - SetDIerror("IDirectInput::CreateDevice", result); - return (-1); + return SetDIerror("IDirectInput::CreateDevice", result); } /* Now get the IDirectInputDevice8 interface, instead. */ @@ -1053,8 +1040,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) IDirectInputDevice8_Release(device); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::QueryInterface", result); - return (-1); + return SetDIerror("IDirectInputDevice8::QueryInterface", result); } /* Aquire shared access. Exclusive access is required for forces, @@ -1065,8 +1051,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result); - return (-1); + return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result); } /* Use the extended data structure: DIJOYSTATE2. */ @@ -1074,8 +1059,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) IDirectInputDevice8_SetDataFormat(joystick->hwdata->InputDevice, &c_dfDIJoystick2); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SetDataFormat", result); - return (-1); + return SetDIerror("IDirectInputDevice8::SetDataFormat", result); } /* Get device capabilities */ @@ -1084,8 +1068,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) &joystick->hwdata->Capabilities); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::GetCapabilities", result); - return (-1); + return SetDIerror("IDirectInputDevice8::GetCapabilities", result); } /* Force capable? */ @@ -1094,8 +1077,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) result = IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::Acquire", result); - return (-1); + return SetDIerror("IDirectInputDevice8::Acquire", result); } /* reset all accuators. */ @@ -1106,17 +1088,14 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) /* Not necessarily supported, ignore if not supported. if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", - result); - return (-1); + return SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", result); } */ result = IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::Unacquire", result); - return (-1); + return SetDIerror("IDirectInputDevice8::Unacquire", result); } /* Turn on auto-centering for a ForceFeedback device (until told @@ -1131,8 +1110,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) /* Not necessarily supported, ignore if not supported. if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SetProperty", result); - return (-1); + return SetDIerror("IDirectInputDevice8::SetProperty", result); } */ } @@ -1160,8 +1138,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) * to use less reliable polling. */ joystick->hwdata->buffered = 0; } else if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SetProperty", result); - return (-1); + return SetDIerror("IDirectInputDevice8::SetProperty", result); } } return (0); diff --git a/src/joystick/windows/SDL_mmjoystick.c b/src/joystick/windows/SDL_mmjoystick.c index bf67c9579..73ad7fb95 100644 --- a/src/joystick/windows/SDL_mmjoystick.c +++ b/src/joystick/windows/SDL_mmjoystick.c @@ -244,8 +244,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); if (joystick->hwdata == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index 78eb3fb0e..fb622ab1d 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -64,8 +64,7 @@ SDL_InitBeApp(void) if (SDL_BeAppActive <= 0) { SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL); if (SDL_AppThread == NULL) { - SDL_SetError("Couldn't create BApplication thread"); - return (-1); + return SDL_SetError("Couldn't create BApplication thread"); } /* Change working to directory to that of executable */ diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index d007186e8..cab98d420 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -82,9 +82,8 @@ int SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info) { if (index < 0 || index >= SDL_GetNumRenderDrivers()) { - SDL_SetError("index must be in the range of 0 - %d", - SDL_GetNumRenderDrivers() - 1); - return -1; + return SDL_SetError("index must be in the range of 0 - %d", + SDL_GetNumRenderDrivers() - 1); } *info = render_drivers[index]->info; return 0; @@ -695,8 +694,7 @@ SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect, temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); @@ -732,8 +730,7 @@ SDL_UpdateTextureNative(SDL_Texture * texture, const SDL_Rect * rect, temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_ConvertPixels(rect->w, rect->h, texture->format, pixels, pitch, @@ -800,8 +797,7 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, CHECK_TEXTURE_MAGIC(texture, -1); if (texture->access != SDL_TEXTUREACCESS_STREAMING) { - SDL_SetError("SDL_LockTexture(): texture must be streaming"); - return -1; + return SDL_SetError("SDL_LockTexture(): texture must be streaming"); } if (!rect) { @@ -897,8 +893,7 @@ int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { if (!SDL_RenderTargetSupported(renderer)) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } if (texture == renderer->target) { /* Nothing to do! */ @@ -909,12 +904,10 @@ SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) if (texture) { CHECK_TEXTURE_MAGIC(texture, -1); if (renderer != texture->renderer) { - SDL_SetError("Texture was not created with this renderer"); - return -1; + return SDL_SetError("Texture was not created with this renderer"); } if (texture->access != SDL_TEXTUREACCESS_TARGET) { - SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET"); - return -1; + return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET"); } if (texture->native) { /* Always render to the native texture */ @@ -979,8 +972,7 @@ UpdateLogicalSize(SDL_Renderer *renderer) SDL_GetWindowSize(renderer->window, &w, &h); } else { /* FIXME */ - SDL_SetError("Internal error: No way to get output resolution"); - return -1; + return SDL_SetError("Internal error: No way to get output resolution"); } want_aspect = (float)renderer->logical_w / renderer->logical_h; @@ -1198,8 +1190,7 @@ RenderDrawPointsWithRects(SDL_Renderer * renderer, frects = SDL_stack_alloc(SDL_FRect, count); if (!frects) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { frects[i].x = points[i].x * renderer->scale.x; @@ -1226,8 +1217,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); if (!points) { - SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points"); - return -1; + return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points"); } if (count < 1) { return 0; @@ -1243,8 +1233,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, fpoints = SDL_stack_alloc(SDL_FPoint, count); if (!fpoints) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { fpoints[i].x = points[i].x * renderer->scale.x; @@ -1282,8 +1271,7 @@ RenderDrawLinesWithRects(SDL_Renderer * renderer, frects = SDL_stack_alloc(SDL_FRect, count-1); if (!frects) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } status = 0; @@ -1338,8 +1326,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); if (!points) { - SDL_SetError("SDL_RenderDrawLines(): Passed NULL points"); - return -1; + return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points"); } if (count < 2) { return 0; @@ -1355,8 +1342,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, fpoints = SDL_stack_alloc(SDL_FPoint, count); if (!fpoints) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { fpoints[i].x = points[i].x * renderer->scale.x; @@ -1408,8 +1394,7 @@ SDL_RenderDrawRects(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); if (!rects) { - SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects"); - return -1; + return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects"); } if (count < 1) { return 0; @@ -1455,8 +1440,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); if (!rects) { - SDL_SetError("SDL_RenderFillRects(): Passed NULL rects"); - return -1; + return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects"); } if (count < 1) { return 0; @@ -1468,8 +1452,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, frects = SDL_stack_alloc(SDL_FRect, count); if (!frects) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { frects[i].x = rects[i].x * renderer->scale.x; @@ -1497,8 +1480,7 @@ SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, CHECK_TEXTURE_MAGIC(texture, -1); if (renderer != texture->renderer) { - SDL_SetError("Texture was not created with this renderer"); - return -1; + return SDL_SetError("Texture was not created with this renderer"); } real_srcrect.x = 0; @@ -1566,12 +1548,10 @@ SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, CHECK_TEXTURE_MAGIC(texture, -1); if (renderer != texture->renderer) { - SDL_SetError("Texture was not created with this renderer"); - return -1; + return SDL_SetError("Texture was not created with this renderer"); } if (!renderer->RenderCopyEx) { - SDL_SetError("Renderer does not support RenderCopyEx"); - return -1; + return SDL_SetError("Renderer does not support RenderCopyEx"); } real_srcrect.x = 0; @@ -1623,8 +1603,7 @@ SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, CHECK_RENDERER_MAGIC(renderer, -1); if (!renderer->RenderReadPixels) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } if (!format) { @@ -1729,8 +1708,7 @@ int SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh) return renderer->GL_BindTexture(renderer, texture, texw, texh); } - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } int SDL_GL_UnbindTexture(SDL_Texture *texture) @@ -1743,8 +1721,7 @@ int SDL_GL_UnbindTexture(SDL_Texture *texture) return renderer->GL_UnbindTexture(renderer, texture); } - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c index 47de2aff2..9f04c21ca 100644 --- a/src/render/SDL_yuv_sw.c +++ b/src/render/SDL_yuv_sw.c @@ -896,8 +896,7 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format) if (!SDL_PixelFormatEnumToMasks (target_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask) || bpp < 15) { - SDL_SetError("Unsupported YUV destination format"); - return -1; + return SDL_SetError("Unsupported YUV destination format"); } swdata->target_format = target_format; @@ -1057,8 +1056,8 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int)); swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32)); if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) { - SDL_OutOfMemory(); SDL_SW_DestroyYUVTexture(swdata); + SDL_OutOfMemory(); return NULL; } @@ -1197,9 +1196,8 @@ SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, if (rect && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w || rect->h != swdata->h)) { - SDL_SetError + return SDL_SetError ("YV12 and IYUV textures only support full surface locks"); - return -1; } break; } @@ -1309,8 +1307,7 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, Cb = lum + 3; break; default: - SDL_SetError("Unsupported YUV format in copy"); - return (-1); + return SDL_SetError("Unsupported YUV format in copy"); } mod = (pitch / SDL_BYTESPERPIXEL(target_format)); diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index a2bd41346..f75d3a98e 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -246,7 +246,7 @@ typedef struct float u, v; } Vertex; -static void +static int D3D_SetError(const char *prefix, HRESULT result) { const char *error; @@ -322,7 +322,7 @@ D3D_SetError(const char *prefix, HRESULT result) error = "UNKNOWN"; break; } - SDL_SetError("%s: %s", prefix, error); + return SDL_SetError("%s: %s", prefix, error); } static D3DFORMAT @@ -373,8 +373,7 @@ D3D_Reset(SDL_Renderer * renderer) /* Don't worry about it, we'll reset later... */ return 0; } else { - D3D_SetError("Reset()", result); - return -1; + return D3D_SetError("Reset()", result); } } IDirect3DDevice9_SetVertexShader(data->device, NULL); @@ -422,8 +421,7 @@ D3D_ActivateRenderer(SDL_Renderer * renderer) result = IDirect3DDevice9_BeginScene(data->device); } if (FAILED(result)) { - D3D_SetError("BeginScene()", result); - return -1; + return D3D_SetError("BeginScene()", result); } data->beginScene = SDL_FALSE; } @@ -704,8 +702,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->scaleMode = GetScaleQuality(); @@ -732,8 +729,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) PixelFormatToD3DFMT(texture->format), pool, &data->texture, NULL); if (FAILED(result)) { - D3D_SetError("CreateTexture()", result); - return -1; + return D3D_SetError("CreateTexture()", result); } return 0; @@ -767,8 +763,7 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, } if (FAILED(result)) { - D3D_SetError("LockRect()", result); - return -1; + return D3D_SetError("LockRect()", result); } src = pixels; @@ -804,8 +799,7 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0); if (FAILED(result)) { - D3D_SetError("LockRect()", result); - return -1; + return D3D_SetError("LockRect()", result); } *pixels = locked.pBits; *pitch = locked.Pitch; @@ -881,13 +875,11 @@ D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) texturedata = (D3D_TextureData *) texture->driverdata; result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture, 0, &data->currentRenderTarget); if(FAILED(result)) { - D3D_SetError("GetSurfaceLevel()", result); - return -1; + return D3D_SetError("GetSurfaceLevel()", result); } result = IDirect3DDevice9_SetRenderTarget(data->device, 0, data->currentRenderTarget); if(FAILED(result)) { - D3D_SetError("SetRenderTarget()", result); - return -1; + return D3D_SetError("SetRenderTarget()", result); } return 0; @@ -936,8 +928,7 @@ D3D_RenderClear(SDL_Renderer * renderer) } if (FAILED(result)) { - D3D_SetError("Clear()", result); - return -1; + return D3D_SetError("Clear()", result); } return 0; } @@ -997,8 +988,7 @@ D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) 0); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); @@ -1017,8 +1007,7 @@ D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, vertices, sizeof(*vertices)); SDL_stack_free(vertices); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } return 0; } @@ -1043,8 +1032,7 @@ D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) 0); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); @@ -1073,8 +1061,7 @@ D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, SDL_stack_free(vertices); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } return 0; } @@ -1100,8 +1087,7 @@ D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) 0); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); @@ -1146,8 +1132,7 @@ D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, vertices, sizeof(*vertices)); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } } return 0; @@ -1224,28 +1209,24 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) texturedata->texture); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } if (shader) { result = IDirect3DDevice9_SetPixelShader(data->device, shader); if (FAILED(result)) { - D3D_SetError("SetShader()", result); - return -1; + return D3D_SetError("SetShader()", result); } } result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, vertices, sizeof(*vertices)); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } if (shader) { result = IDirect3DDevice9_SetPixelShader(data->device, NULL); if (FAILED(result)) { - D3D_SetError("SetShader()", result); - return -1; + return D3D_SetError("SetShader()", result); } } return 0; @@ -1348,28 +1329,24 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) texturedata->texture); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } if (shader) { result = IDirect3DDevice9_SetPixelShader(data->device, shader); if (FAILED(result)) { - D3D_SetError("SetShader()", result); - return -1; + return D3D_SetError("SetShader()", result); } } result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, vertices, sizeof(*vertices)); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } if (shader) { result = IDirect3DDevice9_SetPixelShader(data->device, NULL); if (FAILED(result)) { - D3D_SetError("SetShader()", result); - return -1; + return D3D_SetError("SetShader()", result); } } ID3DXMatrixStack_Pop(data->matrixStack); @@ -1394,30 +1371,26 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, result = IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); if (FAILED(result)) { - D3D_SetError("GetBackBuffer()", result); - return -1; + return D3D_SetError("GetBackBuffer()", result); } result = IDirect3DSurface9_GetDesc(backBuffer, &desc); if (FAILED(result)) { - D3D_SetError("GetDesc()", result); IDirect3DSurface9_Release(backBuffer); - return -1; + return D3D_SetError("GetDesc()", result); } result = IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL); if (FAILED(result)) { - D3D_SetError("CreateOffscreenPlainSurface()", result); IDirect3DSurface9_Release(backBuffer); - return -1; + return D3D_SetError("CreateOffscreenPlainSurface()", result); } result = IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, surface); if (FAILED(result)) { - D3D_SetError("GetRenderTargetData()", result); IDirect3DSurface9_Release(surface); IDirect3DSurface9_Release(backBuffer); - return -1; + return D3D_SetError("GetRenderTargetData()", result); } d3drect.left = rect->x; @@ -1427,10 +1400,9 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY); if (FAILED(result)) { - D3D_SetError("LockRect()", result); IDirect3DSurface9_Release(surface); IDirect3DSurface9_Release(backBuffer); - return -1; + return D3D_SetError("LockRect()", result); } SDL_ConvertPixels(rect->w, rect->h, diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index 5a0d72fb5..30d0716bb 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -208,8 +208,7 @@ GL_LoadFunctions(GL_RenderData * data) do { \ data->func = SDL_GL_GetProcAddress(#func); \ if ( ! data->func ) { \ - SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \ - return -1; \ + return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \ } \ } while ( 0 ); #endif /* __SDL_NOGETPROCADDR__ */ @@ -500,15 +499,13 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) if (!convert_format(renderdata, texture->format, &internalFormat, &format, &type)) { - SDL_SetError("Texture format %s not supported by OpenGL", - SDL_GetPixelFormatName(texture->format)); - return -1; + return SDL_SetError("Texture format %s not supported by OpenGL", + SDL_GetPixelFormatName(texture->format)); } data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { @@ -522,9 +519,8 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) } data->pixels = SDL_calloc(1, size); if (!data->pixels) { - SDL_OutOfMemory(); SDL_free(data); - return -1; + return SDL_OutOfMemory(); } } @@ -746,8 +742,7 @@ GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) /* Check FBO status */ status = data->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - SDL_SetError("glFramebufferTexture2DEXT() failed"); - return -1; + return SDL_SetError("glFramebufferTexture2DEXT() failed"); } return 0; } @@ -1157,8 +1152,7 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } convert_format(data, temp_format, &internalFormat, &format, &type); diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c index 17b7ee250..62b547b2c 100644 --- a/src/render/opengles/SDL_render_gles.c +++ b/src/render/opengles/SDL_render_gles.c @@ -135,7 +135,7 @@ typedef struct GLES_FBOList *fbo; } GLES_TextureData; -static void +static int GLES_SetError(const char *prefix, GLenum result) { const char *error; @@ -166,7 +166,7 @@ GLES_SetError(const char *prefix, GLenum result) error = "UNKNOWN"; break; } - SDL_SetError("%s: %s", prefix, error); + return SDL_SetError("%s: %s", prefix, error); } static int GLES_LoadFunctions(GLES_RenderData * data) @@ -186,8 +186,7 @@ static int GLES_LoadFunctions(GLES_RenderData * data) do { \ data->func = SDL_GL_GetProcAddress(#func); \ if ( ! data->func ) { \ - SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \ - return -1; \ + return SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \ } \ } while ( 0 ); #endif /* _SDL_NOGETPROCADDR_ */ @@ -442,23 +441,20 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) type = GL_UNSIGNED_BYTE; break; default: - SDL_SetError("Texture format not supported"); - return -1; + return SDL_SetError("Texture format not supported"); } data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); data->pixels = SDL_calloc(1, texture->h * data->pitch); if (!data->pixels) { - SDL_OutOfMemory(); SDL_free(data); - return -1; + return SDL_OutOfMemory(); } } @@ -495,8 +491,7 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) result = renderdata->glGetError(); if (result != GL_NO_ERROR) { - GLES_SetError("glTexImage2D()", result); - return -1; + return GLES_SetError("glTexImage2D()", result); } return 0; } @@ -521,17 +516,13 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, /* Reformat the texture data into a tightly packed array */ srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format); src = (Uint8 *)pixels; - if (pitch != srcPitch) - { + if (pitch != srcPitch) { blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); - if (!blob) - { - SDL_OutOfMemory(); - return -1; + if (!blob) { + return SDL_OutOfMemory(); } src = blob; - for (y = 0; y < rect->h; ++y) - { + for (y = 0; y < rect->h; ++y) { SDL_memcpy(src, pixels, srcPitch); src += srcPitch; pixels = (Uint8 *)pixels + pitch; @@ -559,8 +550,7 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, if (renderdata->glGetError() != GL_NO_ERROR) { - SDL_SetError("Failed to update texture"); - return -1; + return SDL_SetError("Failed to update texture"); } return 0; } @@ -613,8 +603,7 @@ GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) /* Check FBO status */ status = data->glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); if (status != GL_FRAMEBUFFER_COMPLETE_OES) { - SDL_SetError("glFramebufferTexture2DOES() failed"); - return -1; + return SDL_SetError("glFramebufferTexture2DOES() failed"); } return 0; } @@ -1006,8 +995,7 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_GetWindowSize(window, &w, &h); diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 14ee2a3c8..2877ef63f 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -189,8 +189,7 @@ static int GLES2_LoadFunctions(GLES2_DriverContext * data) do { \ data->func = SDL_GL_GetProcAddress(#func); \ if ( ! data->func ) { \ - SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \ - return -1; \ + return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \ } \ } while ( 0 ); #endif /* _SDL_NOGETPROCADDR_ */ @@ -372,16 +371,13 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) type = GL_UNSIGNED_BYTE; break; default: - SDL_SetError("Texture format not supported"); - return -1; + return SDL_SetError("Texture format not supported"); } /* Allocate a texture struct */ tdata = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData)); - if (!tdata) - { - SDL_OutOfMemory(); - return -1; + if (!tdata) { + return SDL_OutOfMemory(); } tdata->texture = 0; tdata->texture_type = GL_TEXTURE_2D; @@ -390,15 +386,12 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) scaleMode = GetScaleQuality(); /* Allocate a blob for image data */ - if (texture->access == SDL_TEXTUREACCESS_STREAMING) - { + if (texture->access == SDL_TEXTUREACCESS_STREAMING) { tdata->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); tdata->pixel_data = SDL_calloc(1, tdata->pitch * texture->h); - if (!tdata->pixel_data) - { - SDL_OutOfMemory(); + if (!tdata->pixel_data) { SDL_free(tdata); - return -1; + return SDL_OutOfMemory(); } } @@ -414,10 +407,9 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) rdata->glTexImage2D(tdata->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL); if (rdata->glGetError() != GL_NO_ERROR) { - SDL_SetError("Texture creation failed"); rdata->glDeleteTextures(1, &tdata->texture); SDL_free(tdata); - return -1; + return SDL_SetError("Texture creation failed"); } texture->driverdata = tdata; @@ -497,13 +489,10 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect /* Reformat the texture data into a tightly packed array */ srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format); src = (Uint8 *)pixels; - if (pitch != srcPitch) - { + if (pitch != srcPitch) { blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); - if (!blob) - { - SDL_OutOfMemory(); - return -1; + if (!blob) { + return SDL_OutOfMemory(); } src = blob; for (y = 0; y < rect->h; ++y) @@ -533,10 +522,8 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect SDL_free(blob); } - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to update texture"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to update texture"); } return 0; } @@ -558,8 +545,7 @@ GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) /* Check FBO status */ status = data->glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { - SDL_SetError("glFramebufferTexture2D() failed"); - return -1; + return SDL_SetError("glFramebufferTexture2D() failed"); } } return 0; @@ -636,9 +622,9 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex, rdata->glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful); if (rdata->glGetError() != GL_NO_ERROR || !linkSuccessful) { - SDL_SetError("Failed to link shader program"); rdata->glDeleteProgram(entry->id); SDL_free(entry); + SDL_SetError("Failed to link shader program"); return NULL; } @@ -930,10 +916,8 @@ GLES2_SetOrthographicProjection(SDL_Renderer *renderer) locProjection = rdata->current_program->uniform_locations[GLES2_UNIFORM_PROJECTION]; rdata->glGetError(); rdata->glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to set orthographic projection"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to set orthographic projection"); } return 0; } @@ -1066,8 +1050,7 @@ GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int cou /* Emit the specified vertices as points */ vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) - { + for (idx = 0; idx < count; ++idx) { GLfloat x = points[idx].x + 0.5f; GLfloat y = points[idx].y + 0.5f; @@ -1078,10 +1061,8 @@ GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int cou rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); rdata->glDrawArrays(GL_POINTS, 0, count); SDL_stack_free(vertices); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render lines"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render lines"); } return 0; } @@ -1099,8 +1080,7 @@ GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int coun /* Emit a line strip including the specified vertices */ vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) - { + for (idx = 0; idx < count; ++idx) { GLfloat x = points[idx].x + 0.5f; GLfloat y = points[idx].y + 0.5f; @@ -1117,10 +1097,8 @@ GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int coun rdata->glDrawArrays(GL_POINTS, count-1, 1); } SDL_stack_free(vertices); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render lines"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render lines"); } return 0; } @@ -1157,10 +1135,8 @@ GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count) rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); rdata->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render lines"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render lines"); } return 0; } @@ -1315,10 +1291,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords); rdata->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render texture"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render texture"); } return 0; } @@ -1499,10 +1473,8 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect rdata->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_CENTER); rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render texture"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render texture"); } return 0; } @@ -1525,8 +1497,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_GetWindowSize(window, &w, &h); diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c index fb4e2289a..3bcd87965 100644 --- a/src/render/psp/SDL_render_psp.c +++ b/src/render/psp/SDL_render_psp.c @@ -493,9 +493,8 @@ PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) if(!psp_texture->data) { - SDL_OutOfMemory(); SDL_free(psp_texture); - return -1; + return SDL_OutOfMemory(); } texture->driverdata = psp_texture; diff --git a/src/render/software/SDL_blendfillrect.c b/src/render/software/SDL_blendfillrect.c index 7d1172486..ea05ea64b 100644 --- a/src/render/software/SDL_blendfillrect.c +++ b/src/render/software/SDL_blendfillrect.c @@ -159,8 +159,7 @@ SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect, } return 0; default: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } @@ -189,8 +188,7 @@ SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect, } return 0; default: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } @@ -201,14 +199,12 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_Rect clipped; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendFillRect(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendFillRect(): Unsupported surface format"); } /* If 'rect' == NULL, then fill the whole surface */ @@ -274,14 +270,12 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, int status = 0; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendFillRects(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format"); } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { diff --git a/src/render/software/SDL_blendline.c b/src/render/software/SDL_blendline.c index f34e098de..2ab0231b5 100644 --- a/src/render/software/SDL_blendline.c +++ b/src/render/software/SDL_blendline.c @@ -711,14 +711,12 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, BlendLineFunc func; if (!dst) { - SDL_SetError("SDL_BlendLine(): Passed NULL destination surface"); - return -1; + return SDL_SetError("SDL_BlendLine(): Passed NULL destination surface"); } func = SDL_CalculateBlendLineFunc(dst->format); if (!func) { - SDL_SetError("SDL_BlendLine(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendLine(): Unsupported surface format"); } /* Perform clipping */ @@ -742,14 +740,12 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, BlendLineFunc func; if (!dst) { - SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); - return -1; + return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); } func = SDL_CalculateBlendLineFunc(dst->format); if (!func) { - SDL_SetError("SDL_BlendLines(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendLines(): Unsupported surface format"); } for (i = 1; i < count; ++i) { diff --git a/src/render/software/SDL_blendpoint.c b/src/render/software/SDL_blendpoint.c index 772a8efa8..e2fa66fd8 100644 --- a/src/render/software/SDL_blendpoint.c +++ b/src/render/software/SDL_blendpoint.c @@ -159,8 +159,7 @@ SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uin } return 0; default: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } @@ -189,8 +188,7 @@ SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Ui } return 0; default: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } @@ -199,14 +197,12 @@ SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r Uint8 g, Uint8 b, Uint8 a) { if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); } /* Perform clipping */ @@ -272,14 +268,12 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, int status = 0; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendPoints(): Unsupported surface format"); - return (-1); + return SDL_SetError("SDL_BlendPoints(): Unsupported surface format"); } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { diff --git a/src/render/software/SDL_drawline.c b/src/render/software/SDL_drawline.c index 510e7ffb5..9f5da0ab6 100644 --- a/src/render/software/SDL_drawline.c +++ b/src/render/software/SDL_drawline.c @@ -145,14 +145,12 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) DrawLineFunc func; if (!dst) { - SDL_SetError("SDL_DrawLine(): Passed NULL destination surface"); - return -1; + return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface"); } func = SDL_CalculateDrawLineFunc(dst->format); if (!func) { - SDL_SetError("SDL_DrawLine(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_DrawLine(): Unsupported surface format"); } /* Perform clipping */ @@ -176,14 +174,12 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, DrawLineFunc func; if (!dst) { - SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); - return -1; + return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); } func = SDL_CalculateDrawLineFunc(dst->format); if (!func) { - SDL_SetError("SDL_DrawLines(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_DrawLines(): Unsupported surface format"); } for (i = 1; i < count; ++i) { diff --git a/src/render/software/SDL_drawpoint.c b/src/render/software/SDL_drawpoint.c index a570deae8..1ae8419c1 100644 --- a/src/render/software/SDL_drawpoint.c +++ b/src/render/software/SDL_drawpoint.c @@ -30,14 +30,12 @@ int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) { if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); } /* Perform clipping */ @@ -55,8 +53,7 @@ SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) DRAW_FASTSETPIXELXY2(x, y); break; case 3: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); case 4: DRAW_FASTSETPIXELXY4(x, y); break; @@ -74,14 +71,12 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, int x, y; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); } minx = dst->clip_rect.x; @@ -105,8 +100,7 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, DRAW_FASTSETPIXELXY2(x, y); break; case 3: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); case 4: DRAW_FASTSETPIXELXY4(x, y); break; diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index bf9606ebd..21ff1a9ae 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -200,8 +200,7 @@ SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) if (!SDL_PixelFormatEnumToMasks (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { - SDL_SetError("Unknown texture format"); - return -1; + return SDL_SetError("Unknown texture format"); } texture->driverdata = @@ -357,8 +356,7 @@ SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, final_points = SDL_stack_alloc(SDL_Point, count); if (!final_points) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (renderer->viewport.x || renderer->viewport.y) { int x = renderer->viewport.x; @@ -407,8 +405,7 @@ SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, final_points = SDL_stack_alloc(SDL_Point, count); if (!final_points) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (renderer->viewport.x || renderer->viewport.y) { int x = renderer->viewport.x; @@ -456,8 +453,7 @@ SW_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count) final_rects = SDL_stack_alloc(SDL_Rect, count); if (!final_rects) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (renderer->viewport.x || renderer->viewport.y) { int x = renderer->viewport.x; @@ -647,8 +643,7 @@ SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, if (rect->x < 0 || rect->x+rect->w > surface->w || rect->y < 0 || rect->y+rect->h > surface->h) { - SDL_SetError("Tried to read outside of surface bounds"); - return -1; + return SDL_SetError("Tried to read outside of surface bounds"); } src_format = surface->format->format; diff --git a/src/test/SDL_test_fuzzer.c b/src/test/SDL_test_fuzzer.c index 885706355..89b669157 100644 --- a/src/test/SDL_test_fuzzer.c +++ b/src/test/SDL_test_fuzzer.c @@ -251,7 +251,7 @@ SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, if (index == 0) { /* There are no valid boundaries */ - SDL_Error(SDL_UNSUPPORTED); + SDL_Unsupported(); return 0; } @@ -379,7 +379,7 @@ SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValu if (index == 0) { /* There are no valid boundaries */ - SDL_Error(SDL_UNSUPPORTED); + SDL_Unsupported(); return minValue; } diff --git a/src/thread/beos/SDL_syssem.c b/src/thread/beos/SDL_syssem.c index 393e81d55..9661f9012 100644 --- a/src/thread/beos/SDL_syssem.c +++ b/src/thread/beos/SDL_syssem.c @@ -73,8 +73,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } tryagain: @@ -97,8 +96,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) retval = SDL_MUTEX_TIMEDOUT; break; default: - SDL_SetError("acquire_sem() failed"); - retval = -1; + retval = SDL_SetError("acquire_sem() failed"); break; } @@ -139,13 +137,11 @@ int SDL_SemPost(SDL_sem * sem) { if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } if (release_sem(sem->id) != B_NO_ERROR) { - SDL_SetError("release_sem() failed"); - return -1; + return SDL_SetError("release_sem() failed"); } return 0; } diff --git a/src/thread/beos/SDL_systhread.c b/src/thread/beos/SDL_systhread.c index 4c61bd302..11646f974 100644 --- a/src/thread/beos/SDL_systhread.c +++ b/src/thread/beos/SDL_systhread.c @@ -77,8 +77,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args); if ((thread->handle == B_NO_MORE_THREADS) || (thread->handle == B_NO_MEMORY)) { - SDL_SetError("Not enough resources to create thread"); - return (-1); + return SDL_SetError("Not enough resources to create thread"); } resume_thread(thread->handle); return (0); diff --git a/src/thread/generic/SDL_syscond.c b/src/thread/generic/SDL_syscond.c index ca281521e..f540cddb6 100644 --- a/src/thread/generic/SDL_syscond.c +++ b/src/thread/generic/SDL_syscond.c @@ -82,8 +82,7 @@ int SDL_CondSignal(SDL_cond * cond) { if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then @@ -107,8 +106,7 @@ int SDL_CondBroadcast(SDL_cond * cond) { if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then @@ -164,8 +162,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) int retval; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* Obtain the protection mutex, and increment the number of waiters. diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c index 4954f48e8..3e3c1fea9 100644 --- a/src/thread/generic/SDL_sysmutex.c +++ b/src/thread/generic/SDL_sysmutex.c @@ -78,8 +78,7 @@ SDL_LockMutex(SDL_mutex * mutex) SDL_threadID this_thread; if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } this_thread = SDL_ThreadID(); @@ -110,8 +109,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) SDL_threadID this_thread; if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } this_thread = SDL_ThreadID(); @@ -141,14 +139,12 @@ SDL_mutexV(SDL_mutex * mutex) return 0; #else if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } /* If we don't own the mutex, we can't unlock it */ if (SDL_ThreadID() != mutex->owner) { - SDL_SetError("mutex not owned by this thread"); - return -1; + return SDL_SetError("mutex not owned by this thread"); } if (mutex->recursive) { diff --git a/src/thread/generic/SDL_syssem.c b/src/thread/generic/SDL_syssem.c index 474c44662..fc4e1fcc7 100644 --- a/src/thread/generic/SDL_syssem.c +++ b/src/thread/generic/SDL_syssem.c @@ -39,28 +39,24 @@ SDL_CreateSemaphore(Uint32 initial_value) void SDL_DestroySemaphore(SDL_sem * sem) { - return; } int SDL_SemTryWait(SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + return SDL_SetError("SDL not configured with thread support"); } int SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { - SDL_SetError("SDL not configured with thread support"); - return -1; + return SDL_SetError("SDL not configured with thread support"); } int SDL_SemWait(SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + return SDL_SetError("SDL not configured with thread support"); } Uint32 @@ -72,8 +68,7 @@ SDL_SemValue(SDL_sem * sem) int SDL_SemPost(SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + return SDL_SetError("SDL not configured with thread support"); } #else @@ -137,8 +132,7 @@ SDL_SemTryWait(SDL_sem * sem) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } retval = SDL_MUTEX_TIMEDOUT; @@ -158,8 +152,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } /* A timeout of 0 is an easy case */ @@ -207,8 +200,7 @@ int SDL_SemPost(SDL_sem * sem) { if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } SDL_LockMutex(sem->count_lock); diff --git a/src/thread/generic/SDL_systhread.c b/src/thread/generic/SDL_systhread.c index d41643007..deebc64fb 100644 --- a/src/thread/generic/SDL_systhread.c +++ b/src/thread/generic/SDL_systhread.c @@ -28,8 +28,7 @@ int SDL_SYS_CreateThread(SDL_Thread * thread, void *args) { - SDL_SetError("Threads are not supported on this platform"); - return (-1); + return SDL_SetError("Threads are not supported on this platform"); } void diff --git a/src/thread/psp/SDL_syscond.c b/src/thread/psp/SDL_syscond.c index ca281521e..f540cddb6 100644 --- a/src/thread/psp/SDL_syscond.c +++ b/src/thread/psp/SDL_syscond.c @@ -82,8 +82,7 @@ int SDL_CondSignal(SDL_cond * cond) { if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then @@ -107,8 +106,7 @@ int SDL_CondBroadcast(SDL_cond * cond) { if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then @@ -164,8 +162,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) int retval; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* Obtain the protection mutex, and increment the number of waiters. diff --git a/src/thread/psp/SDL_sysmutex.c b/src/thread/psp/SDL_sysmutex.c index a68f238c7..6bb68a23d 100644 --- a/src/thread/psp/SDL_sysmutex.c +++ b/src/thread/psp/SDL_sysmutex.c @@ -78,8 +78,7 @@ SDL_mutexP(SDL_mutex * mutex) SDL_threadID this_thread; if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } this_thread = SDL_ThreadID(); @@ -107,14 +106,12 @@ SDL_mutexV(SDL_mutex * mutex) return 0; #else if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } /* If we don't own the mutex, we can't unlock it */ if (SDL_ThreadID() != mutex->owner) { - SDL_SetError("mutex not owned by this thread"); - return -1; + return SDL_SetError("mutex not owned by this thread"); } if (mutex->recursive) { diff --git a/src/thread/psp/SDL_syssem.c b/src/thread/psp/SDL_syssem.c index 56638ca42..22ecc5f6b 100644 --- a/src/thread/psp/SDL_syssem.c +++ b/src/thread/psp/SDL_syssem.c @@ -105,8 +105,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) case SCE_KERNEL_ERROR_WAIT_TIMEOUT: return SDL_MUTEX_TIMEDOUT; default: - SDL_SetError("WaitForSingleObject() failed"); - return -1; + return SDL_SetError("WaitForSingleObject() failed"); } } @@ -142,14 +141,12 @@ int SDL_SemPost(SDL_sem *sem) int res; if (sem == NULL) { - SDL_SetError("Passed a NULL sem"); - return -1; + return SDL_SetError("Passed a NULL sem"); } res = sceKernelSignalSema(sem->semid, 1); if (res < 0) { - SDL_SetError("sceKernelSignalSema() failed"); - return -1; + return SDL_SetError("sceKernelSignalSema() failed"); } return 0; diff --git a/src/thread/psp/SDL_systhread.c b/src/thread/psp/SDL_systhread.c index c786272b0..57b932084 100644 --- a/src/thread/psp/SDL_systhread.c +++ b/src/thread/psp/SDL_systhread.c @@ -54,8 +54,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) priority, 0x8000, PSP_THREAD_ATTR_VFPU, NULL); if (thread->handle < 0) { - SDL_SetError("sceKernelCreateThread() failed"); - return -1; + return SDL_SetError("sceKernelCreateThread() failed"); } sceKernelStartThread(thread->handle, 4, &args); diff --git a/src/thread/pthread/SDL_syscond.c b/src/thread/pthread/SDL_syscond.c index f07cdb20e..1eb4f29f9 100644 --- a/src/thread/pthread/SDL_syscond.c +++ b/src/thread/pthread/SDL_syscond.c @@ -67,14 +67,12 @@ SDL_CondSignal(SDL_cond * cond) int retval; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } retval = 0; if (pthread_cond_signal(&cond->cond) != 0) { - SDL_SetError("pthread_cond_signal() failed"); - retval = -1; + return SDL_SetError("pthread_cond_signal() failed"); } return retval; } @@ -86,14 +84,12 @@ SDL_CondBroadcast(SDL_cond * cond) int retval; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } retval = 0; if (pthread_cond_broadcast(&cond->cond) != 0) { - SDL_SetError("pthread_cond_broadcast() failed"); - retval = -1; + return SDL_SetError("pthread_cond_broadcast() failed"); } return retval; } @@ -106,8 +102,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) struct timespec abstime; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } gettimeofday(&delta, NULL); @@ -131,9 +126,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) case 0: break; default: - SDL_SetError("pthread_cond_timedwait() failed"); - retval = -1; - break; + retval = SDL_SetError("pthread_cond_timedwait() failed"); } return retval; } @@ -144,19 +137,12 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) int SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) { - int retval; - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); + } else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) { + return SDL_SetError("pthread_cond_wait() failed"); } - - retval = 0; - if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) { - SDL_SetError("pthread_cond_wait() failed"); - retval = -1; - } - return retval; + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index faf178771..bd238da36 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -81,17 +81,14 @@ SDL_DestroyMutex(SDL_mutex * mutex) int SDL_LockMutex(SDL_mutex * mutex) { - int retval; #if FAKE_RECURSIVE_MUTEX pthread_t this_thread; #endif if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } - retval = 0; #if FAKE_RECURSIVE_MUTEX this_thread = pthread_self(); if (mutex->owner == this_thread) { @@ -105,17 +102,15 @@ SDL_LockMutex(SDL_mutex * mutex) mutex->owner = this_thread; mutex->recursive = 0; } else { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; + return SDL_SetError("pthread_mutex_lock() failed"); } } #else if (pthread_mutex_lock(&mutex->id) < 0) { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; + return SDL_SetError("pthread_mutex_lock() failed"); } #endif - return retval; + return 0; } int @@ -127,8 +122,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) #endif if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } retval = 0; @@ -147,8 +141,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) } else if (errno == EBUSY) { retval = SDL_MUTEX_TIMEDOUT; } else { - SDL_SetError("pthread_mutex_trylock() failed"); - retval = -1; + retval = SDL_SetError("pthread_mutex_trylock() failed"); } } #else @@ -156,8 +149,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) if (errno == EBUSY) { retval = SDL_MUTEX_TIMEDOUT; } else { - SDL_SetError("pthread_mutex_trylock() failed"); - retval = -1; + retval = SDL_SetError("pthread_mutex_trylock() failed"); } } #endif @@ -167,14 +159,10 @@ SDL_TryLockMutex(SDL_mutex * mutex) int SDL_UnlockMutex(SDL_mutex * mutex) { - int retval; - if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } - retval = 0; #if FAKE_RECURSIVE_MUTEX /* We can only unlock the mutex if we own it */ if (pthread_self() == mutex->owner) { @@ -190,18 +178,16 @@ SDL_UnlockMutex(SDL_mutex * mutex) pthread_mutex_unlock(&mutex->id); } } else { - SDL_SetError("mutex not owned by this thread"); - retval = -1; + return SDL_SetError("mutex not owned by this thread"); } #else if (pthread_mutex_unlock(&mutex->id) < 0) { - SDL_SetError("pthread_mutex_unlock() failed"); - retval = -1; + return SDL_SetError("pthread_mutex_unlock() failed"); } #endif /* FAKE_RECURSIVE_MUTEX */ - return retval; + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index 5e461a7fc..4acd6bfb5 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -72,8 +72,7 @@ SDL_SemTryWait(SDL_sem * sem) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } retval = SDL_MUTEX_TIMEDOUT; if (sem_trywait(&sem->sem) == 0) { @@ -88,13 +87,12 @@ SDL_SemWait(SDL_sem * sem) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } retval = sem_wait(&sem->sem); if (retval < 0) { - SDL_SetError("sem_wait() failed"); + retval = SDL_SetError("sem_wait() failed"); } return retval; } @@ -111,8 +109,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) #endif if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } /* Try the easy cases first */ @@ -188,8 +185,7 @@ SDL_SemPost(SDL_sem * sem) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } retval = sem_post(&sem->sem); diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index e83e1f6c3..62436936e 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -97,18 +97,16 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) /* Set the thread attributes */ if (pthread_attr_init(&type) != 0) { - SDL_SetError("Couldn't initialize pthread attributes"); - return (-1); + return SDL_SetError("Couldn't initialize pthread attributes"); } pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); /* Create the thread and go! */ if (pthread_create(&thread->handle, &type, RunThread, args) != 0) { - SDL_SetError("Not enough resources to create thread"); - return (-1); + return SDL_SetError("Not enough resources to create thread"); } - return (0); + return 0; } void @@ -173,8 +171,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) /* Note that this fails if you're trying to set high priority and you don't have root permission. BUT DON'T RUN AS ROOT! */ - SDL_SetError("setpriority() failed"); - return -1; + return SDL_SetError("setpriority() failed"); } return 0; #else @@ -183,8 +180,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) pthread_t thread = pthread_self(); if (pthread_getschedparam(thread, &policy, &sched) < 0) { - SDL_SetError("pthread_getschedparam() failed"); - return -1; + return SDL_SetError("pthread_getschedparam() failed"); } if (priority == SDL_THREAD_PRIORITY_LOW) { sched.sched_priority = sched_get_priority_min(policy); @@ -196,8 +192,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) sched.sched_priority = (min_priority + (max_priority - min_priority) / 2); } if (pthread_setschedparam(thread, policy, &sched) < 0) { - SDL_SetError("pthread_setschedparam() failed"); - return -1; + return SDL_SetError("pthread_setschedparam() failed"); } return 0; #endif /* linux */ diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index 6455cbeab..60e9c6c87 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -67,8 +67,7 @@ int SDL_LockMutex(SDL_mutex * mutex) { if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } EnterCriticalSection(&mutex->cs); @@ -81,8 +80,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) { int retval = 0; if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } if (TryEnterCriticalSection(&mutex->cs) == 0) { @@ -96,8 +94,7 @@ int SDL_UnlockMutex(SDL_mutex * mutex) { if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } LeaveCriticalSection(&mutex->cs); diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 8c45e3827..8dc72bcb9 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -78,8 +78,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) DWORD dwMilliseconds; if (!sem) { - SDL_SetError("Passed a NULL sem"); - return -1; + return SDL_SetError("Passed a NULL sem"); } if (timeout == SDL_MUTEX_MAXWAIT) { @@ -96,8 +95,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) retval = SDL_MUTEX_TIMEDOUT; break; default: - SDL_SetError("WaitForSingleObject() failed"); - retval = -1; + retval = SDL_SetError("WaitForSingleObject() failed"); break; } return retval; @@ -130,8 +128,7 @@ int SDL_SemPost(SDL_sem * sem) { if (!sem) { - SDL_SetError("Passed a NULL sem"); - return -1; + return SDL_SetError("Passed a NULL sem"); } /* Increase the counter in the first place, because * after a successful release the semaphore may @@ -141,8 +138,7 @@ SDL_SemPost(SDL_sem * sem) InterlockedIncrement(&sem->count); if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) { InterlockedDecrement(&sem->count); /* restore */ - SDL_SetError("ReleaseSemaphore() failed"); - return -1; + return SDL_SetError("ReleaseSemaphore() failed"); } return 0; } diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c index 1a898e1a3..6ae9cdb8f 100644 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -116,8 +116,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) pThreadStartParms pThreadParms = (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms)); if (!pThreadParms) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } // Save the function which we will have to call to clear the RTL of calling app! pThreadParms->pfnCurrentEndThread = pfnEndThread; @@ -135,10 +134,9 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) pThreadParms, 0, &threadid); } if (thread->handle == NULL) { - SDL_SetError("Not enough resources to create thread"); - return (-1); + return SDL_SetError("Not enough resources to create thread"); } - return (0); + return 0; } #ifdef _MSC_VER @@ -198,8 +196,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) value = THREAD_PRIORITY_NORMAL; } if (!SetThreadPriority(GetCurrentThread(), value)) { - WIN_SetError("SetThreadPriority()"); - return -1; + return WIN_SetError("SetThreadPriority()"); } return 0; } diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index 07f5fd3c0..de61ccd47 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -1087,8 +1087,7 @@ RLEAlphaSurface(SDL_Surface * surface) maxsize += sizeof(RLEDestFormat); rlebuf = (Uint8 *) SDL_malloc(maxsize); if (!rlebuf) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } { /* save the destination format so we can undo the encoding later */ @@ -1299,8 +1298,7 @@ RLEColorkeySurface(SDL_Surface * surface) rlebuf = (Uint8 *) SDL_malloc(maxsize); if (rlebuf == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } /* Set up the conversion */ diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c index ed546c526..d7c258d4c 100644 --- a/src/video/SDL_blit.c +++ b/src/video/SDL_blit.c @@ -270,11 +270,10 @@ SDL_CalculateBlit(SDL_Surface * surface) /* Make sure we have a blit function */ if (blit == NULL) { SDL_InvalidateMap(map); - SDL_SetError("Blit combination not supported"); - return (-1); + return SDL_SetError("Blit combination not supported"); } - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_fillrect.c b/src/video/SDL_fillrect.c index 91f3feccf..a99371e05 100644 --- a/src/video/SDL_fillrect.c +++ b/src/video/SDL_fillrect.c @@ -315,14 +315,12 @@ SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color) Uint8 *pixels; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_FillRect(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_FillRect(): Unsupported surface format"); } /* If 'rect' == NULL, then fill the whole surface */ @@ -338,8 +336,7 @@ SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color) /* Perform software fill */ if (!dst->pixels) { - SDL_SetError("SDL_FillRect(): You must lock the surface"); - return (-1); + return SDL_SetError("SDL_FillRect(): You must lock the surface"); } pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch + @@ -423,8 +420,7 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, int status = 0; if (!rects) { - SDL_SetError("SDL_FillRects() passed NULL rects"); - return -1; + return SDL_SetError("SDL_FillRects() passed NULL rects"); } for (i = 0; i < count; ++i) { diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index c9d5bd262..84a75b8eb 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -638,13 +638,11 @@ int SDL_SetPixelFormatPalette(SDL_PixelFormat * format, SDL_Palette *palette) { if (!format) { - SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format"); - return -1; + return SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format"); } if (palette && palette->ncolors != (1 << format->BitsPerPixel)) { - SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format"); - return -1; + return SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format"); } if (format->palette == palette) { diff --git a/src/video/SDL_stretch.c b/src/video/SDL_stretch.c index 9d6588af9..e976d10f0 100644 --- a/src/video/SDL_stretch.c +++ b/src/video/SDL_stretch.c @@ -102,14 +102,12 @@ generate_rowbytes(int src_w, int dst_w, int bpp) store = STORE_WORD; break; default: - SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); - return (-1); + return SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); } #ifdef HAVE_MPROTECT /* Make the code writeable */ if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_WRITE) < 0) { - SDL_SetError("Couldn't make copy buffer writeable"); - return (-1); + return SDL_SetError("Couldn't make copy buffer writeable"); } #endif pos = 0x10000; @@ -141,8 +139,7 @@ generate_rowbytes(int src_w, int dst_w, int bpp) #ifdef HAVE_MPROTECT /* Make the code executable but not writeable */ if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) { - SDL_SetError("Couldn't make copy buffer executable"); - return (-1); + return SDL_SetError("Couldn't make copy buffer executable"); } #endif last.status = 0; @@ -224,8 +221,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, const int bpp = dst->format->BytesPerPixel; if (src->format->BitsPerPixel != dst->format->BitsPerPixel) { - SDL_SetError("Only works with same format surfaces"); - return (-1); + return SDL_SetError("Only works with same format surfaces"); } /* Verify the blit rectangles */ @@ -233,8 +229,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, if ((srcrect->x < 0) || (srcrect->y < 0) || ((srcrect->x + srcrect->w) > src->w) || ((srcrect->y + srcrect->h) > src->h)) { - SDL_SetError("Invalid source blit rectangle"); - return (-1); + return SDL_SetError("Invalid source blit rectangle"); } } else { full_src.x = 0; @@ -247,8 +242,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, if ((dstrect->x < 0) || (dstrect->y < 0) || ((dstrect->x + dstrect->w) > dst->w) || ((dstrect->y + dstrect->h) > dst->h)) { - SDL_SetError("Invalid destination blit rectangle"); - return (-1); + return SDL_SetError("Invalid destination blit rectangle"); } } else { full_dst.x = 0; @@ -262,8 +256,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, dst_locked = 0; if (SDL_MUSTLOCK(dst)) { if (SDL_LockSurface(dst) < 0) { - SDL_SetError("Unable to lock destination surface"); - return (-1); + return SDL_SetError("Unable to lock destination surface"); } dst_locked = 1; } @@ -274,8 +267,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, if (dst_locked) { SDL_UnlockSurface(dst); } - SDL_SetError("Unable to lock source surface"); - return (-1); + return SDL_SetError("Unable to lock source surface"); } src_locked = 1; } diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 4c67dc916..94ce6eacc 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -143,8 +143,7 @@ int SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette) { if (!surface) { - SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface"); - return -1; + return SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface"); } return SDL_SetPixelFormatPalette(surface->format, palette); } @@ -402,8 +401,7 @@ SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode) surface->map->info.flags |= SDL_COPY_MOD; break; default: - SDL_Unsupported(); - status = -1; + status = SDL_Unsupported(); break; } @@ -518,12 +516,10 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, /* Make sure the surfaces aren't locked */ if (!src || !dst) { - SDL_SetError("SDL_UpperBlit: passed a NULL surface"); - return (-1); + return SDL_SetError("SDL_UpperBlit: passed a NULL surface"); } if (src->locked || dst->locked) { - SDL_SetError("Surfaces must not be locked during blit"); - return (-1); + return SDL_SetError("Surfaces must not be locked during blit"); } /* If the destination rectangle is NULL, use the entire dest surface */ @@ -610,12 +606,10 @@ SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, /* Make sure the surfaces aren't locked */ if (!src || !dst) { - SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface"); - return (-1); + return SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface"); } if (src->locked || dst->locked) { - SDL_SetError("Surfaces must not be locked during blit"); - return (-1); + return SDL_SetError("Surfaces must not be locked during blit"); } /* If the destination rectangle is NULL, use the entire dest surface */ @@ -972,12 +966,10 @@ int SDL_ConvertPixels(int width, int height, /* Check to make sure we are bliting somewhere, so we don't crash */ if (!dst) { - SDL_InvalidParamError("dst"); - return -1; + return SDL_InvalidParamError("dst"); } if (!dst_pitch) { - SDL_InvalidParamError("dst_pitch"); - return -1; + return SDL_InvalidParamError("dst_pitch"); } /* Fast path for same format copy */ @@ -994,8 +986,7 @@ int SDL_ConvertPixels(int width, int height, bpp = 2; break; default: - SDL_SetError("Unknown FOURCC pixel format"); - return -1; + return SDL_SetError("Unknown FOURCC pixel format"); } } else { bpp = SDL_BYTESPERPIXEL(src_format); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index f04b13199..53da52693 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -242,16 +242,14 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix } } if (!renderer) { - SDL_SetError("No hardware accelerated renderers available"); - return -1; + return SDL_SetError("No hardware accelerated renderers available"); } /* Create the data after we successfully create the renderer (bug #1116) */ data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data)); if (!data) { SDL_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data); @@ -294,8 +292,7 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3); data->pixels = SDL_malloc(window->h * data->pitch); if (!data->pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } *pixels = data->pixels; @@ -316,8 +313,7 @@ SDL_UpdateWindowTexture(_THIS, SDL_Window * window, const SDL_Rect * rects, int data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA); if (!data || !data->texture) { - SDL_SetError("No window texture data"); - return -1; + return SDL_SetError("No window texture data"); } /* Update a single rect that contains subrects for best DMA performance */ @@ -384,10 +380,10 @@ cmpmodes(const void *A, const void *B) return 0; } -static void +static int SDL_UninitializedVideo() { - SDL_SetError("Video subsystem has not been initialized"); + return SDL_SetError("Video subsystem has not been initialized"); } int @@ -454,11 +450,9 @@ SDL_VideoInit(const char *driver_name) } if (video == NULL) { if (driver_name) { - SDL_SetError("%s not available", driver_name); - } else { - SDL_SetError("No available video device"); + return SDL_SetError("%s not available", driver_name); } - return -1; + return SDL_SetError("No available video device"); } _this = video; _this->name = bootstrap[i]->name; @@ -510,9 +504,8 @@ SDL_VideoInit(const char *driver_name) /* Make sure some displays were added */ if (_this->num_displays == 0) { - SDL_SetError("The video driver did not add any displays"); SDL_VideoQuit(); - return (-1); + return SDL_SetError("The video driver did not add any displays"); } /* Add the renderer framebuffer emulation if desired */ @@ -721,9 +714,8 @@ SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode) display = &_this->displays[displayIndex]; if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) { - SDL_SetError("index must be in the range of 0 - %d", - SDL_GetNumDisplayModesForDisplay(display) - 1); - return -1; + return SDL_SetError("index must be in the range of 0 - %d", + SDL_GetNumDisplayModesForDisplay(display) - 1); } if (mode) { *mode = display->display_modes[index]; @@ -904,9 +896,8 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * /* Get a good video mode, the closest one possible */ if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) { - SDL_SetError("No video mode large enough for %dx%d", - display_mode.w, display_mode.h); - return -1; + return SDL_SetError("No video mode large enough for %dx%d", + display_mode.w, display_mode.h); } } else { display_mode = display->desktop_mode; @@ -920,8 +911,7 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * /* Actually change the display mode */ if (!_this->SetDisplayMode) { - SDL_SetError("Video driver doesn't support changing display mode"); - return -1; + return SDL_SetError("Video driver doesn't support changing display mode"); } if (_this->SetDisplayMode(_this, display, &display_mode) < 0) { return -1; @@ -1021,8 +1011,7 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) SDL_VideoDisplay *display; if (!mode) { - SDL_InvalidParamError("mode"); - return -1; + return SDL_InvalidParamError("mode"); } CHECK_WINDOW_MAGIC(window, -1); @@ -1045,8 +1034,7 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window), &fullscreen_mode, &fullscreen_mode)) { - SDL_SetError("Couldn't find display mode match"); - return -1; + return SDL_SetError("Couldn't find display mode match"); } if (mode) { @@ -1299,8 +1287,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags) char *title = window->title; if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { - SDL_SetError("No OpenGL support in video driver"); - return -1; + return SDL_SetError("No OpenGL support in video driver"); } if (window->flags & SDL_WINDOW_FOREIGN) { @@ -1847,8 +1834,7 @@ SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects, CHECK_WINDOW_MAGIC(window, -1); if (!window->surface_valid) { - SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface"); - return -1; + return SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface"); } return _this->UpdateWindowFramebuffer(_this, window, rects, numrects); @@ -1886,8 +1872,7 @@ SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red, CHECK_WINDOW_MAGIC(window, -1); if (!_this->SetWindowGammaRamp) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } if (!window->gamma) { @@ -1924,8 +1909,7 @@ SDL_GetWindowGammaRamp(SDL_Window * window, Uint16 * red, window->gamma = (Uint16 *)SDL_malloc(256*6*sizeof(Uint16)); if (!window->gamma) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } window->saved_gamma = window->gamma + 3*256; @@ -2266,19 +2250,16 @@ SDL_GL_LoadLibrary(const char *path) int retval; if (!_this) { - SDL_UninitializedVideo(); - return -1; + return SDL_UninitializedVideo(); } if (_this->gl_config.driver_loaded) { if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) { - SDL_SetError("OpenGL library already loaded"); - return -1; + return SDL_SetError("OpenGL library already loaded"); } retval = 0; } else { if (!_this->GL_LoadLibrary) { - SDL_SetError("No dynamic GL support in video driver"); - return -1; + return SDL_SetError("No dynamic GL support in video driver"); } retval = _this->GL_LoadLibrary(_this, path); } @@ -2388,8 +2369,7 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) int retval; if (!_this) { - SDL_UninitializedVideo(); - return -1; + return SDL_UninitializedVideo(); } retval = 0; switch (attr) { @@ -2458,8 +2438,7 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG | SDL_GL_CONTEXT_RESET_ISOLATION_FLAG) ) { - SDL_SetError("Unknown OpenGL context flag %d", value); - retval = -1; + retval = SDL_SetError("Unknown OpenGL context flag %d", value); break; } _this->gl_config.flags = value; @@ -2469,8 +2448,7 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) value != SDL_GL_CONTEXT_PROFILE_CORE && value != SDL_GL_CONTEXT_PROFILE_COMPATIBILITY && value != SDL_GL_CONTEXT_PROFILE_ES ) { - SDL_SetError("Unknown OpenGL context profile %d", value); - retval = -1; + retval = SDL_SetError("Unknown OpenGL context profile %d", value); break; } _this->gl_config.profile_mask = value; @@ -2479,14 +2457,12 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) _this->gl_config.share_with_current_context = value; break; default: - SDL_SetError("Unknown OpenGL attribute"); - retval = -1; + retval = SDL_SetError("Unknown OpenGL attribute"); break; } return retval; #else - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); #endif /* SDL_VIDEO_OPENGL */ } @@ -2645,36 +2621,22 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) return 0; } default: - SDL_SetError("Unknown OpenGL attribute"); - return -1; + return SDL_SetError("Unknown OpenGL attribute"); } glGetIntegervFunc(attrib, (GLint *) value); error = glGetErrorFunc(); if (error != GL_NO_ERROR) { - switch (error) { - case GL_INVALID_ENUM: - { - SDL_SetError("OpenGL error: GL_INVALID_ENUM"); - } - break; - case GL_INVALID_VALUE: - { - SDL_SetError("OpenGL error: GL_INVALID_VALUE"); - } - break; - default: - { - SDL_SetError("OpenGL error: %08X", error); - } - break; + if (error == GL_INVALID_ENUM) { + return SDL_SetError("OpenGL error: GL_INVALID_ENUM"); + } else if (error == GL_INVALID_VALUE) { + return SDL_SetError("OpenGL error: GL_INVALID_VALUE"); } - return -1; + return SDL_SetError("OpenGL error: %08X", error); } return 0; #else - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); #endif /* SDL_VIDEO_OPENGL */ } @@ -2706,8 +2668,7 @@ SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx) CHECK_WINDOW_MAGIC(window, -1); if (!(window->flags & SDL_WINDOW_OPENGL)) { - SDL_SetError("The specified window isn't an OpenGL window"); - return -1; + return SDL_SetError("The specified window isn't an OpenGL window"); } if (!ctx) { window = NULL; @@ -2730,16 +2691,13 @@ int SDL_GL_SetSwapInterval(int interval) { if (!_this) { - SDL_UninitializedVideo(); - return -1; + return SDL_UninitializedVideo(); } else if (_this->current_glctx == NULL) { - SDL_SetError("No OpenGL context has been made current"); - return -1; + return SDL_SetError("No OpenGL context has been made current"); } else if (_this->GL_SetSwapInterval) { return _this->GL_SetSwapInterval(_this, interval); } else { - SDL_SetError("Setting the swap interval is not supported"); - return -1; + return SDL_SetError("Setting the swap interval is not supported"); } } @@ -3025,8 +2983,7 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_ShowCursor( show_cursor_prev ); SDL_SetRelativeMouseMode( relative_mode ); - if(retval == -1) - { + if(retval == -1) { SDL_SetError("No message system available"); } return retval; diff --git a/src/video/android/SDL_androidgl.c b/src/video/android/SDL_androidgl.c index 8cdaa46d6..1382b8878 100644 --- a/src/video/android/SDL_androidgl.c +++ b/src/video/android/SDL_androidgl.c @@ -42,8 +42,7 @@ Android_GL_LoadLibrary(_THIS, const char *path) if (!Android_GLHandle) { Android_GLHandle = dlopen("libGLESv1_CM.so",RTLD_GLOBAL); if (!Android_GLHandle) { - SDL_SetError("Could not initialize GL ES library\n"); - return -1; + return SDL_SetError("Could not initialize GL ES library\n"); } } return 0; diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index 88b124a01..7d13a26d3 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -31,8 +31,7 @@ int Android_CreateWindow(_THIS, SDL_Window * window) { if (Android_Window) { - SDL_SetError("Android only supports one window"); - return -1; + return SDL_SetError("Android only supports one window"); } Android_Window = window; Android_PauseSem = SDL_CreateSemaphore(0); diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 11e60bd5f..6e7f8c3f2 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -76,8 +76,7 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, true); /* Contiguous memory required */ if(bitmap->InitCheck() != B_OK) { - SDL_SetError("Could not initialize back buffer!\n"); - return -1; + return SDL_SetError("Could not initialize back buffer!\n"); } diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 5abdf8dde..2e8f4b577 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -310,8 +310,7 @@ int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ } if(bscreen.SetMode(bmode) != B_OK) { - SDL_SetError("Bad video mode\n"); - return -1; + return SDL_SetError("Bad video mode\n"); } free(bmode_list); diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index 4f6cf6555..563226c2a 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -84,7 +84,7 @@ IS_SNOW_LEOPARD_OR_LATER(_THIS) #endif } -static void +static int CG_SetError(const char *prefix, CGDisplayErr result) { const char *error; @@ -124,7 +124,7 @@ CG_SetError(const char *prefix, CGDisplayErr result) error = "Unknown Error"; break; } - SDL_SetError("%s: %s", prefix, error); + return SDL_SetError("%s: %s", prefix, error); } static SDL_bool diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 5b5981827..a12bde8dd 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -190,8 +190,7 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled) result = CGAssociateMouseAndMouseCursorPosition(YES); } if (result != kCGErrorSuccess) { - SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed"); - return -1; + return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed"); } return 0; } diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 7fa382a28..a1686219b 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -274,8 +274,7 @@ Cocoa_GL_SetSwapInterval(_THIS, int interval) [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval]; status = 0; } else { - SDL_SetError("No current OpenGL context"); - status = -1; + status = SDL_SetError("No current OpenGL context"); } [pool release]; diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 63894ee11..f2803dad3 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -501,8 +501,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created /* Allocate the window data */ data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->window = window; data->nswindow = nswindow; @@ -954,8 +953,7 @@ Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) if (CGSetDisplayTransferByTable(display_id, tableSize, redTable, greenTable, blueTable) != CGDisplayNoErr) { - SDL_SetError("CGSetDisplayTransferByTable()"); - return -1; + return SDL_SetError("CGSetDisplayTransferByTable()"); } return 0; } @@ -973,8 +971,7 @@ Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) if (CGGetDisplayTransferByTable(display_id, tableSize, redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) { - SDL_SetError("CGGetDisplayTransferByTable()"); - return -1; + return SDL_SetError("CGGetDisplayTransferByTable()"); } for (i = 0; i < tableCopied; i++) { diff --git a/src/video/directfb/SDL_DirectFB_opengl.c b/src/video/directfb/SDL_DirectFB_opengl.c index 09a3bddc2..c325f4231 100644 --- a/src/video/directfb/SDL_DirectFB_opengl.c +++ b/src/video/directfb/SDL_DirectFB_opengl.c @@ -72,8 +72,7 @@ DirectFB_GL_Initialize(_THIS) sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } _this->gl_data->initialized = 0; @@ -115,8 +114,7 @@ DirectFB_GL_LoadLibrary(_THIS, const char *path) SDL_DFB_DEBUG("Loadlibrary : %s\n", path); if (_this->gl_data->gl_active) { - SDL_SetError("OpenGL context already created"); - return -1; + return SDL_SetError("OpenGL context already created"); } @@ -243,8 +241,7 @@ DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) int DirectFB_GL_SetSwapInterval(_THIS, int interval) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } int diff --git a/src/video/directfb/SDL_DirectFB_render.c b/src/video/directfb/SDL_DirectFB_render.c index 09a9bdd9d..db69a5c44 100644 --- a/src/video/directfb/SDL_DirectFB_render.c +++ b/src/video/directfb/SDL_DirectFB_render.c @@ -657,8 +657,7 @@ DirectFB_SetTexturePalette(SDL_Renderer * renderer, palette->SetEntries(data->palette, entries, ncolors, firstcolor)); return 0; } else { - SDL_SetError("YUV textures don't have a palette"); - return -1; + return SDL_SetError("YUV textures don't have a palette"); } error: return -1; @@ -688,8 +687,7 @@ DirectFB_GetTexturePalette(SDL_Renderer * renderer, } return 0; } else { - SDL_SetError("YUV textures don't have a palette"); - return -1; + return SDL_SetError("YUV textures don't have a palette"); } error: return -1; @@ -718,9 +716,8 @@ DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) case SDL_BLENDMODE_MOD: return 0; default: - SDL_Unsupported(); texture->blendMode = SDL_BLENDMODE_NONE; - return -1; + return SDL_Unsupported(); } } @@ -735,9 +732,8 @@ DirectFB_SetDrawBlendMode(SDL_Renderer * renderer) case SDL_BLENDMODE_MOD: return 0; default: - SDL_Unsupported(); renderer->blendMode = SDL_BLENDMODE_NONE; - return -1; + return SDL_Unsupported(); } } @@ -762,10 +758,9 @@ DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE | DSRO_ANTIALIAS; break; default: - SDL_Unsupported(); data->render_options = DSRO_NONE; texture->scaleMode = SDL_SCALEMODE_NONE; - return -1; + return SDL_Unsupported(); } #endif return 0; diff --git a/src/video/directfb/SDL_DirectFB_window.c b/src/video/directfb/SDL_DirectFB_window.c index 6f052b844..1ba4cfe60 100644 --- a/src/video/directfb/SDL_DirectFB_window.c +++ b/src/video/directfb/SDL_DirectFB_window.c @@ -176,8 +176,7 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } void @@ -188,8 +187,9 @@ DirectFB_SetWindowTitle(_THIS, SDL_Window * window) if (windata->is_managed) { windata->wm_needs_redraw = 1; DirectFB_WM_RedrawLayout(_this, window); - } else + } else { SDL_Unsupported(); + } } void diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c index 242fb8209..f3904918a 100644 --- a/src/video/dummy/SDL_nullframebuffer.c +++ b/src/video/dummy/SDL_nullframebuffer.c @@ -65,8 +65,7 @@ int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE); if (!surface) { - SDL_SetError("Couldn't find dummy surface for window"); - return -1; + return SDL_SetError("Couldn't find dummy surface for window"); } /* Send the data to the display */ diff --git a/src/video/pandora/SDL_pandora.c b/src/video/pandora/SDL_pandora.c index 660648beb..77d12b79c 100644 --- a/src/video/pandora/SDL_pandora.c +++ b/src/video/pandora/SDL_pandora.c @@ -211,8 +211,7 @@ PND_createwindow(_THIS, SDL_Window * window) /* Allocate window internal data */ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); if (wdata == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Setup driver data for this window */ @@ -230,14 +229,12 @@ PND_createwindow(_THIS, SDL_Window * window) if (phdata->egl_display == EGL_NO_DISPLAY) { phdata->egl_display = eglGetDisplay((NativeDisplayType) 0); if (phdata->egl_display == EGL_NO_DISPLAY) { - SDL_SetError("PND: Can't get connection to OpenGL ES"); - return -1; + return SDL_SetError("PND: Can't get connection to OpenGL ES"); } initstatus = eglInitialize(phdata->egl_display, NULL, NULL); if (initstatus != EGL_TRUE) { - SDL_SetError("PND: Can't init OpenGL ES library"); - return -1; + return SDL_SetError("PND: Can't init OpenGL ES library"); } } @@ -356,8 +353,7 @@ PND_gl_loadlibrary(_THIS, const char *path) _this->gl_config.dll_handle = SDL_LoadObject(path); if (!_this->gl_config.dll_handle) { /* Failed to load new GL ES library */ - SDL_SetError("PND: Failed to locate OpenGL ES library"); - return -1; + return SDL_SetError("PND: Failed to locate OpenGL ES library"); } /* Store OpenGL ES library path and name */ @@ -726,8 +722,7 @@ PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context) EGLBoolean status; if (phdata->egl_initialized != SDL_TRUE) { - SDL_SetError("PND: GF initialization failed, no OpenGL ES support"); - return -1; + return SDL_SetError("PND: GF initialization failed, no OpenGL ES support"); } if ((window == NULL) && (context == NULL)) { @@ -736,33 +731,28 @@ PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context) EGL_NO_SURFACE, EGL_NO_CONTEXT); if (status != EGL_TRUE) { /* Failed to set current GL ES context */ - SDL_SetError("PND: Can't set OpenGL ES context"); - return -1; + return SDL_SetError("PND: Can't set OpenGL ES context"); } } else { wdata = (SDL_WindowData *) window->driverdata; if (wdata->gles_surface == EGL_NO_SURFACE) { - SDL_SetError + return SDL_SetError ("PND: OpenGL ES surface is not initialized for this window"); - return -1; } if (wdata->gles_context == EGL_NO_CONTEXT) { - SDL_SetError + return SDL_SetError ("PND: OpenGL ES context is not initialized for this window"); - return -1; } if (wdata->gles_context != context) { - SDL_SetError + return SDL_SetError ("PND: OpenGL ES context is not belong to this window"); - return -1; } status = eglMakeCurrent(phdata->egl_display, wdata->gles_surface, wdata->gles_surface, wdata->gles_context); if (status != EGL_TRUE) { /* Failed to set current GL ES context */ - SDL_SetError("PND: Can't set OpenGL ES context"); - return -1; + return SDL_SetError("PND: Can't set OpenGL ES context"); } } return 0; @@ -775,8 +765,7 @@ PND_gl_setswapinterval(_THIS, int interval) EGLBoolean status; if (phdata->egl_initialized != SDL_TRUE) { - SDL_SetError("PND: EGL initialization failed, no OpenGL ES support"); - return -1; + return SDL_SetError("PND: EGL initialization failed, no OpenGL ES support"); } /* Check if OpenGL ES connection has been initialized */ @@ -791,8 +780,7 @@ PND_gl_setswapinterval(_THIS, int interval) } /* Failed to set swap interval */ - SDL_SetError("PND: Cannot set swap interval"); - return -1; + return SDL_SetError("PND: Cannot set swap interval"); } int diff --git a/src/video/psp/SDL_pspgl.c b/src/video/psp/SDL_pspgl.c index 7a60b728d..247496d96 100644 --- a/src/video/psp/SDL_pspgl.c +++ b/src/video/psp/SDL_pspgl.c @@ -146,8 +146,7 @@ PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface, _this->gl_data->surface, _this->gl_data->context)) { - SDL_SetError("Unable to make EGL context current"); - return -1; + return SDL_SetError("Unable to make EGL context current"); } return 0; } @@ -163,8 +162,7 @@ PSP_GL_SetSwapInterval(_THIS, int interval) return 0; } /* Failed to set swap interval */ - SDL_SetError("Unable to set the EGL swap interval"); - return -1; + return SDL_SetError("Unable to set the EGL swap interval"); } int diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c index 67aed9d86..8ed637551 100644 --- a/src/video/psp/SDL_pspvideo.c +++ b/src/video/psp/SDL_pspvideo.c @@ -223,8 +223,7 @@ PSP_CreateWindow(_THIS, SDL_Window * window) /* Allocate window internal data */ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); if (wdata == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Setup driver data for this window */ diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m index 1f6b81025..87c3cc1e5 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -39,8 +39,7 @@ UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode, /* Allocate the display mode data */ data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->uiscreenmode = uiscreenmode; @@ -160,9 +159,8 @@ UIKit_AddDisplay(UIScreen *uiscreen) /* Allocate the display data */ SDL_DisplayData *data = (SDL_DisplayData *) SDL_malloc(sizeof(*data)); if (!data) { - SDL_OutOfMemory(); UIKit_FreeDisplayModeData(&display.desktop_mode); - return -1; + return SDL_OutOfMemory(); } [uiscreen retain]; diff --git a/src/video/uikit/SDL_uikitopengles.m b/src/video/uikit/SDL_uikitopengles.m index 63d8dbb7b..f3efab2a7 100644 --- a/src/video/uikit/SDL_uikitopengles.m +++ b/src/video/uikit/SDL_uikitopengles.m @@ -72,8 +72,7 @@ UIKit_GL_LoadLibrary(_THIS, const char *path) and because the SDK forbids loading an external SO */ if (path != NULL) { - SDL_SetError("iPhone GL Load Library just here for compatibility"); - return -1; + return SDL_SetError("iPhone GL Load Library just here for compatibility"); } return 0; } diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index 12ceb1a11..ff025067b 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -63,10 +63,10 @@ UIKit_CreateDevice(int devindex) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); if (device) { SDL_free(device); } + SDL_OutOfMemory(); return (0); } diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index e10f07efe..11ab119b3 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/src/video/uikit/SDL_uikitwindow.m @@ -54,8 +54,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo /* Allocate the window data */ data = (SDL_WindowData *)SDL_malloc(sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->uiwindow = uiwindow; data->viewcontroller = nil; @@ -133,8 +132,7 @@ UIKit_CreateWindow(_THIS, SDL_Window *window) /* We currently only handle a single window per display on iOS */ if (window->next != NULL) { - SDL_SetError("Only one window allowed per display."); - return -1; + return SDL_SetError("Only one window allowed per display."); } // If monitor has a resolution of 0x0 (hasn't been explicitly set by the @@ -315,8 +313,7 @@ SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callbac SDL_WindowData *data = window ? (SDL_WindowData *)window->driverdata : NULL; if (!data || !data->view) { - SDL_SetError("Invalid window or view not set"); - return -1; + return SDL_SetError("Invalid window or view not set"); } [data->view setAnimationCallback:interval callback:callback callbackParam:callbackParam]; diff --git a/src/video/windows/SDL_windowsclipboard.c b/src/video/windows/SDL_windowsclipboard.c index 5c1bf11fd..4f0c87a81 100644 --- a/src/video/windows/SDL_windowsclipboard.c +++ b/src/video/windows/SDL_windowsclipboard.c @@ -89,8 +89,7 @@ WIN_SetClipboardText(_THIS, const char *text) EmptyClipboard(); if (!SetClipboardData(TEXT_FORMAT, hMem)) { - WIN_SetError("Couldn't set clipboard data"); - result = -1; + result = WIN_SetError("Couldn't set clipboard data"); } data->clipboard_count = GetClipboardSequenceNumber(); } @@ -98,8 +97,7 @@ WIN_SetClipboardText(_THIS, const char *text) CloseClipboard(); } else { - WIN_SetError("Couldn't open clipboard"); - result = -1; + result = WIN_SetError("Couldn't open clipboard"); } return result; } diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 6a62df573..730e73766 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -809,12 +809,11 @@ SDL_RegisterApp(char *name, Uint32 style, void *hInst) class.cbWndExtra = 0; class.cbClsExtra = 0; if (!RegisterClass(&class)) { - SDL_SetError("Couldn't register application class"); - return (-1); + return SDL_SetError("Couldn't register application class"); } app_registered = 1; - return (0); + return 0; } /* Unregisters the windowclass registered in SDL_RegisterApp above. */ diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c index 5c22ff1f7..5a2a9ef00 100644 --- a/src/video/windows/SDL_windowsframebuffer.c +++ b/src/video/windows/SDL_windowsframebuffer.c @@ -85,8 +85,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi SDL_stack_free(info); if (!data->hbm) { - WIN_SetError("Unable to create DIB"); - return -1; + return WIN_SetError("Unable to create DIB"); } SelectObject(data->mdc, data->hbm); diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index 30922c803..97ddc736d 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -214,8 +214,7 @@ WIN_InitModes(_THIS) } } if (_this->num_displays == 0) { - SDL_SetError("No displays available"); - return -1; + return SDL_SetError("No displays available"); } return 0; } @@ -282,8 +281,7 @@ WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) reason = "DISP_CHANGE_FAILED"; break; } - SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason); - return -1; + return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason); } EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode); return 0; diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index 8306f6709..23f288b19 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -196,8 +196,7 @@ WIN_SetRelativeMouseMode(SDL_bool enabled) /* Only return an error when registering. If we unregister and fail, then it's probably that we unregistered twice. That's OK. */ if(enabled) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index e77b923e7..97cbaffc4 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -91,8 +91,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path) char message[1024]; SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")", path); - WIN_SetError(message); - return -1; + return WIN_SetError(message); } SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); @@ -103,8 +102,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path) sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Load function pointers */ @@ -124,9 +122,8 @@ WIN_GL_LoadLibrary(_THIS, const char *path) !_this->gl_data->wglCreateContext || !_this->gl_data->wglDeleteContext || !_this->gl_data->wglMakeCurrent) { - SDL_SetError("Could not retrieve OpenGL functions"); SDL_UnloadObject(handle); - return -1; + return SDL_SetError("Could not retrieve OpenGL functions"); } return 0; @@ -512,12 +509,10 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window) pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd); } if (!pixel_format) { - SDL_SetError("No matching GL pixel format available"); - return -1; + return SDL_SetError("No matching GL pixel format available"); } if (!SetPixelFormat(hdc, pixel_format, &pfd)) { - WIN_SetError("SetPixelFormat()"); - return (-1); + return WIN_SetError("SetPixelFormat()"); } return 0; } @@ -611,11 +606,9 @@ int WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { HDC hdc; - int status; if (!_this->gl_data) { - SDL_SetError("OpenGL not initialized"); - return -1; + return SDL_SetError("OpenGL not initialized"); } if (window) { @@ -624,30 +617,24 @@ WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) hdc = NULL; } if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) { - WIN_SetError("wglMakeCurrent()"); - status = -1; - } else { - status = 0; + return WIN_SetError("wglMakeCurrent()"); } - return status; + return 0; } int WIN_GL_SetSwapInterval(_THIS, int interval) { - int retval = -1; if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) { - SDL_SetError("Negative swap interval unsupported in this GL"); + return SDL_SetError("Negative swap interval unsupported in this GL"); } else if (_this->gl_data->wglSwapIntervalEXT) { - if (_this->gl_data->wglSwapIntervalEXT(interval) == TRUE) { - retval = 0; - } else { - WIN_SetError("wglSwapIntervalEXT()"); + if (_this->gl_data->wglSwapIntervalEXT(interval) != TRUE) { + return WIN_SetError("wglSwapIntervalEXT()"); } } else { - SDL_Unsupported(); + return SDL_Unsupported(); } - return retval; + return 0; } int diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 5d016e7c3..c64749f4f 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -75,10 +75,10 @@ WIN_CreateDevice(int devindex) data = NULL; } if (!data) { - SDL_OutOfMemory(); if (device) { SDL_free(device); } + SDL_OutOfMemory(); return NULL; } device->driverdata = data; diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 08894ecd6..800349235 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -82,8 +82,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) /* Allocate the window data */ data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->window = window; data->hwnd = hwnd; @@ -98,8 +97,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) { ReleaseDC(hwnd, data->hdc); SDL_free(data); - WIN_SetError("SetProp() failed"); - return -1; + return WIN_SetError("SetProp() failed"); } /* Set up the window proc function */ @@ -221,8 +219,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window) CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL, SDL_Instance, NULL); if (!hwnd) { - WIN_SetError("Couldn't create window"); - return -1; + return WIN_SetError("Couldn't create window"); } WIN_PumpEvents(_this); @@ -635,8 +632,7 @@ SDL_HelperWindowCreate(void) /* Register the class. */ SDL_HelperWindowClass = RegisterClass(&wce); if (SDL_HelperWindowClass == 0) { - WIN_SetError("Unable to create Helper Window Class"); - return -1; + return WIN_SetError("Unable to create Helper Window Class"); } /* Create the window. */ @@ -648,8 +644,7 @@ SDL_HelperWindowCreate(void) hInstance, NULL); if (SDL_HelperWindow == NULL) { UnregisterClass(SDL_HelperWindowClassName, hInstance); - WIN_SetError("Unable to create Helper Window"); - return -1; + return WIN_SetError("Unable to create Helper Window"); } return 0; diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c index 4ab18576b..0c3b000e0 100644 --- a/src/video/x11/SDL_x11clipboard.c +++ b/src/video/x11/SDL_x11clipboard.c @@ -59,8 +59,7 @@ X11_SetClipboardText(_THIS, const char *text) /* Get the SDL window that will own the selection */ window = GetWindow(_this); if (window == None) { - SDL_SetError("Couldn't find a window to own the selection"); - return -1; + return SDL_SetError("Couldn't find a window to own the selection"); } /* Save the selection on the root window */ diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c index 7f19ddd29..0c8febe4a 100644 --- a/src/video/x11/SDL_x11framebuffer.c +++ b/src/video/x11/SDL_x11framebuffer.c @@ -68,20 +68,17 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, gcv.graphics_exposures = False; data->gc = XCreateGC(display, data->xwindow, GCGraphicsExposures, &gcv); if (!data->gc) { - SDL_SetError("Couldn't create graphics context"); - return -1; + return SDL_SetError("Couldn't create graphics context"); } /* Find out the pixel format and depth */ if (X11_GetVisualInfoFromVisual(display, data->visual, &vinfo) < 0) { - SDL_SetError("Couldn't get window visual information"); - return -1; + return SDL_SetError("Couldn't get window visual information"); } *format = X11_GetPixelFormatFromVisualInfo(display, &vinfo); if (*format == SDL_PIXELFORMAT_UNKNOWN) { - SDL_SetError("Unknown window pixel format"); - return -1; + return SDL_SetError("Unknown window pixel format"); } /* Calculate pitch */ @@ -132,8 +129,7 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, *pixels = SDL_malloc(window->h*(*pitch)); if (*pixels == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->ximage = XCreateImage(display, data->visual, @@ -141,8 +137,7 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, window->w, window->h, 32, 0); if (!data->ximage) { SDL_free(*pixels); - SDL_SetError("Couldn't create XImage"); - return -1; + return SDL_SetError("Couldn't create XImage"); } return 0; } diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index 620194c6b..47cac1c66 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -168,8 +168,7 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess const SDL_MessageBoxColor *colorhints; if ( numbuttons > MAX_BUTTONS ) { - SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS); - return -1; + return SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS); } data->dialog_width = MIN_DIALOG_WIDTH; @@ -181,8 +180,7 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess data->display = XOpenDisplay( NULL ); if ( !data->display ) { - SDL_SetError("Couldn't open X11 display"); - return -1; + return SDL_SetError("Couldn't open X11 display"); } if (SDL_X11_HAVE_UTF8) { @@ -194,14 +192,12 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess XFreeStringList(missing); } if ( data->font_set == NULL ) { - SDL_SetError("Couldn't load font %s", g_MessageBoxFont); - return -1; + return SDL_SetError("Couldn't load font %s", g_MessageBoxFont); } } else { data->font_struct = XLoadQueryFont( data->display, g_MessageBoxFontLatin1 ); if ( data->font_struct == NULL ) { - SDL_SetError("Couldn't load font %s", g_MessageBoxFontLatin1); - return -1; + return SDL_SetError("Couldn't load font %s", g_MessageBoxFontLatin1); } } @@ -388,8 +384,7 @@ X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data ) 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &wnd_attr ); if ( data->window == None ) { - SDL_SetError("Couldn't create X window"); - return -1; + return SDL_SetError("Couldn't create X window"); } if ( windowdata ) { @@ -520,8 +515,7 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data ) ctx = XCreateGC( data->display, data->window, gcflags, &ctx_vals ); if ( ctx == None ) { - SDL_SetError("Couldn't create graphics context"); - return -1; + return SDL_SetError("Couldn't create graphics context"); } data->button_press_index = -1; /* Reset what button is currently depressed. */ @@ -660,8 +654,7 @@ X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid) if (origlocale != NULL) { origlocale = SDL_strdup(origlocale); if (origlocale == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } setlocale(LC_ALL, ""); } @@ -739,8 +732,7 @@ X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_assert(rc == pid); /* not sure what to do if this fails. */ if ((rc == -1) || (!WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) { - SDL_SetError("msgbox child process failed"); - return -1; + return SDL_SetError("msgbox child process failed"); } if (read(fds[0], &status, sizeof (int)) != sizeof (int)) diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index 347e7bbdf..60363b491 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -656,8 +656,7 @@ X11_InitModes(_THIS) #endif if (_this->num_displays == 0) { - SDL_SetError("No available displays"); - return -1; + return SDL_SetError("No available displays"); } return 0; } @@ -798,23 +797,20 @@ X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode res = XRRGetScreenResources (display, RootWindow(display, data->screen)); if (!res) { - SDL_SetError("Couldn't get XRandR screen resources"); - return -1; + return SDL_SetError("Couldn't get XRandR screen resources"); } output_info = XRRGetOutputInfo(display, res, data->xrandr_output); if (!output_info || output_info->connection == RR_Disconnected) { - SDL_SetError("Couldn't get XRandR output info"); XRRFreeScreenResources(res); - return -1; + return SDL_SetError("Couldn't get XRandR output info"); } crtc = XRRGetCrtcInfo(display, res, output_info->crtc); if (!crtc) { - SDL_SetError("Couldn't get XRandR crtc info"); XRRFreeOutputInfo(output_info); XRRFreeScreenResources(res); - return -1; + return SDL_SetError("Couldn't get XRandR crtc info"); } status = XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime, @@ -826,8 +822,7 @@ X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode XRRFreeScreenResources(res); if (status != Success) { - SDL_SetError("XRRSetCrtcConfig failed"); - return -1; + return SDL_SetError("XRRSetCrtcConfig failed"); } } #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 400ef84e9..8e6614bef 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -136,8 +136,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) void *handle; if (_this->gl_data) { - SDL_SetError("OpenGL context already created"); - return -1; + return SDL_SetError("OpenGL context already created"); } /* If SDL_GL_CONTEXT_EGL has been changed to 1, switch over to X11_GLES functions */ @@ -154,8 +153,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) _this->GL_DeleteContext = X11_GLES_DeleteContext; return X11_GLES_LoadLibrary(_this, path); #else - SDL_SetError("SDL not configured with OpenGL ES/EGL support"); - return -1; + return SDL_SetError("SDL not configured with OpenGL ES/EGL support"); #endif } @@ -183,8 +181,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Load function pointers */ @@ -216,8 +213,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) !_this->gl_data->glXDestroyContext || !_this->gl_data->glXMakeCurrent || !_this->gl_data->glXSwapBuffers) { - SDL_SetError("Could not retrieve OpenGL functions"); - return -1; + return SDL_SetError("Could not retrieve OpenGL functions"); } /* Initialize extensions */ @@ -656,20 +652,16 @@ X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) Window drawable = (context ? ((SDL_WindowData *) window->driverdata)->xwindow : None); GLXContext glx_context = (GLXContext) context; - int status; if (!_this->gl_data) { - SDL_SetError("OpenGL not initialized"); - return -1; + return SDL_SetError("OpenGL not initialized"); } - status = 0; if (!_this->gl_data->glXMakeCurrent(display, drawable, glx_context)) { - SDL_SetError("Unable to make GL context current"); - status = -1; + return SDL_SetError("Unable to make GL context current"); } - return (status); + return 0; } /* diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c index 3b8a97a94..279c58c34 100644 --- a/src/video/x11/SDL_x11opengles.c +++ b/src/video/x11/SDL_x11opengles.c @@ -35,8 +35,7 @@ *((void**)&_this->gles_data->NAME) = dlsym(handle, #NAME); \ if (!_this->gles_data->NAME) \ { \ - SDL_SetError("Could not retrieve EGL function " #NAME); \ - return -1; \ + return SDL_SetError("Could not retrieve EGL function " #NAME); \ } /* GLES implementation of SDL OpenGL support */ @@ -95,8 +94,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; if (_this->gles_data) { - SDL_SetError("OpenGL ES context already created"); - return -1; + return SDL_SetError("OpenGL ES context already created"); } /* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions */ @@ -113,8 +111,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) _this->GL_DeleteContext = X11_GL_DeleteContext; return X11_GL_LoadLibrary(_this, path); #else - SDL_SetError("SDL not configured with OpenGL/GLX support"); - return -1; + return SDL_SetError("SDL not configured with OpenGL/GLX support"); #endif } @@ -136,8 +133,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) } if (handle == NULL) { - SDL_SetError("Could not load OpenGL ES/EGL library"); - return -1; + return SDL_SetError("Could not load OpenGL ES/EGL library"); } /* Unload the old driver and reset the pointers */ @@ -145,8 +141,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) _this->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData)); if (!_this->gles_data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Load new function pointers */ @@ -168,15 +163,13 @@ X11_GLES_LoadLibrary(_THIS, const char *path) _this->gles_data->eglGetDisplay((NativeDisplayType) data->display); if (!_this->gles_data->egl_display) { - SDL_SetError("Could not get EGL display"); - return -1; + return SDL_SetError("Could not get EGL display"); } if (_this->gles_data-> eglInitialize(_this->gles_data->egl_display, NULL, NULL) != EGL_TRUE) { - SDL_SetError("Could not initialize EGL"); - return -1; + return SDL_SetError("Could not initialize EGL"); } _this->gles_data->egl_dll_handle = handle; @@ -198,8 +191,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) } if (handle == NULL) { - SDL_SetError("Could not initialize OpenGL ES library"); - return -1; + return SDL_SetError("Could not initialize OpenGL ES library"); } _this->gl_config.dll_handle = handle; @@ -353,40 +345,34 @@ X11_GLES_CreateContext(_THIS, SDL_Window * window) int X11_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { - int retval; - /* SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display = data->videodata->display; */ if (!_this->gles_data) { - SDL_SetError("OpenGL not initialized"); - return -1; + return SDL_SetError("OpenGL not initialized"); } - retval = 1; if (!_this->gles_data->eglMakeCurrent(_this->gles_data->egl_display, _this->gles_data->egl_surface, _this->gles_data->egl_surface, _this->gles_data->egl_context)) { - SDL_SetError("Unable to make EGL context current"); - retval = -1; + return SDL_SetError("Unable to make EGL context current"); } /* XSync(display, False); */ - return (retval); + return 1; } int X11_GLES_SetSwapInterval(_THIS, int interval) { if (_this->gles_data) { - SDL_SetError("OpenGL ES context not active"); - return -1; + return SDL_SetError("OpenGL ES context not active"); } EGLBoolean status; @@ -396,16 +382,14 @@ X11_GLES_SetSwapInterval(_THIS, int interval) return 0; } - SDL_SetError("Unable to set the EGL swap interval"); - return -1; + return SDL_SetError("Unable to set the EGL swap interval"); } int X11_GLES_GetSwapInterval(_THIS) { if (_this->gles_data) { - SDL_SetError("OpenGL ES context not active"); - return -1; + return SDL_SetError("OpenGL ES context not active"); } return _this->gles_data->egl_swapinterval; diff --git a/src/video/x11/SDL_x11shape.c b/src/video/x11/SDL_x11shape.c index 40cccc6ad..e1e68934e 100644 --- a/src/video/x11/SDL_x11shape.c +++ b/src/video/x11/SDL_x11shape.c @@ -72,8 +72,7 @@ X11_ResizeWindowShape(SDL_Window* window) { free(data->bitmap); data->bitmap = malloc(data->bitmapsize); if(data->bitmap == NULL) { - SDL_SetError("Could not allocate memory for shaped-window bitmap."); - return -1; + return SDL_SetError("Could not allocate memory for shaped-window bitmap."); } } memset(data->bitmap,0,data->bitmapsize); diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 5288e520f..4794241e9 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -305,8 +305,8 @@ X11_CreateDevice(int devindex) } data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); if (!data) { - SDL_OutOfMemory(); SDL_free(device); + SDL_OutOfMemory(); return NULL; } device->driverdata = data; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index cb932a2c7..6403ac4b4 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -214,8 +214,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) /* Allocate the window data */ data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->window = window; data->xwindow = w; @@ -242,9 +241,8 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) (numwindows + 1) * sizeof(*windowlist)); if (!windowlist) { - SDL_OutOfMemory(); SDL_free(data); - return -1; + return SDL_OutOfMemory(); } windowlist[numwindows] = data; videodata->numwindows++; @@ -392,15 +390,13 @@ X11_CreateWindow(_THIS, SDL_Window * window) /* If we can't create a colormap, then we must die */ if (!xattr.colormap) { - SDL_SetError("Could not create writable colormap"); - return -1; + return SDL_SetError("Could not create writable colormap"); } /* OK, we got a colormap, now fill it in as best as we can */ colorcells = SDL_malloc(visual->map_entries * sizeof(XColor)); if (!colorcells) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } ncolors = visual->map_entries; rmax = 0xffff; @@ -465,8 +461,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) (CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap), &xattr); if (!w) { - SDL_SetError("Couldn't create window"); - return -1; + return SDL_SetError("Couldn't create window"); } #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 if ((window->flags & SDL_WINDOW_OPENGL) && (_this->gl_config.use_egl == 1)) { @@ -483,9 +478,8 @@ X11_CreateWindow(_THIS, SDL_Window * window) (NativeWindowType) w, NULL); if (_this->gles_data->egl_surface == EGL_NO_SURFACE) { - SDL_SetError("Could not create GLES window surface"); XDestroyWindow(display, w); - return -1; + return SDL_SetError("Could not create GLES window surface"); } } #endif @@ -1209,15 +1203,13 @@ X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) int i; if (visual->class != DirectColor) { - SDL_SetError("Window doesn't have DirectColor visual"); - return -1; + return SDL_SetError("Window doesn't have DirectColor visual"); } ncolors = visual->map_entries; colorcells = SDL_malloc(ncolors * sizeof(XColor)); if (!colorcells) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } rshift = 0; From 2df4ed556e0aa13192f9243ce001dac2b4963f9b Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 31 Mar 2013 13:05:40 -0400 Subject: [PATCH 126/151] Changed audio subsystem's OpenDevice interface to return -1 on error. This lets us 'return SDL_SetError("whatever");' on one line. Fixes Bugzilla #1778. --- src/audio/SDL_audio.c | 4 +- src/audio/alsa/SDL_alsa_audio.c | 55 ++++++++++--------------- src/audio/android/SDL_androidaudio.c | 17 +++----- src/audio/arts/SDL_artsaudio.c | 22 ++++------ src/audio/baudio/SDL_beaudio.cc | 11 ++--- src/audio/bsd/SDL_bsdaudio.c | 20 ++++----- src/audio/coreaudio/SDL_coreaudio.c | 10 ++--- src/audio/directsound/SDL_directsound.c | 19 ++++----- src/audio/disk/SDL_diskaudio.c | 9 ++-- src/audio/dsp/SDL_dspaudio.c | 35 ++++++---------- src/audio/dummy/SDL_dummyaudio.c | 2 +- src/audio/esd/SDL_esdaudio.c | 14 +++---- src/audio/fusionsound/SDL_fsaudio.c | 17 +++----- src/audio/nas/SDL_nasaudio.c | 17 +++----- src/audio/paudio/SDL_paudio.c | 23 ++++------- src/audio/psp/SDL_pspaudio.c | 14 +++---- src/audio/pulseaudio/SDL_pulseaudio.c | 38 ++++++----------- src/audio/qsa/SDL_qsa_audio.c | 45 ++++++++------------ src/audio/sun/SDL_sunaudio.c | 24 ++++------- src/audio/winmm/SDL_winmm.c | 30 +++++--------- src/audio/xaudio2/SDL_xaudio2.c | 38 ++++++----------- 21 files changed, 169 insertions(+), 295 deletions(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 439e74d70..f6763f9b6 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -191,7 +191,7 @@ SDL_AudioDeinitialize_Default(void) static int SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture) { - return 0; + return -1; } static void @@ -940,7 +940,7 @@ open_audio_device(const char *devname, int iscapture, ((!iscapture) && (current_audio.outputDevices == NULL)) ) SDL_GetNumAudioDevices(iscapture); - if (!current_audio.impl.OpenDevice(device, devname, iscapture)) { + if (current_audio.impl.OpenDevice(device, devname, iscapture) < 0) { close_audio_device(device); return 0; } diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index 3e33d1692..9b5e75624 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -482,8 +482,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -495,9 +494,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't open audio device: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't open audio device: %s", + ALSA_snd_strerror(status)); } this->hidden->pcm_handle = pcm_handle; @@ -507,9 +505,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't get hardware config: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't get hardware config: %s", + ALSA_snd_strerror(status)); } /* SDL only uses interleaved sample output */ @@ -517,9 +514,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) SND_PCM_ACCESS_RW_INTERLEAVED); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't set interleaved access: %s", + return SDL_SetError("ALSA: Couldn't set interleaved access: %s", ALSA_snd_strerror(status)); - return 0; } /* Try for a closest match on audio format */ @@ -572,8 +568,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) } if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("ALSA: Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -585,8 +580,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't set audio channels"); - return 0; + return SDL_SetError("ALSA: Couldn't set audio channels"); } this->spec.channels = channels; } @@ -597,9 +591,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) &rate, NULL); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't set audio frequency: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't set audio frequency: %s", + ALSA_snd_strerror(status)); } this->spec.freq = rate; @@ -609,8 +602,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) /* Failed to set desired buffer size, do the best you can... */ if ( ALSA_set_period_size(this, hwparams, 1) < 0 ) { ALSA_CloseDevice(this); - SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status)); - return(-1); + return SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status)); } } /* Set the software parameters */ @@ -618,31 +610,27 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't get software config: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't get software config: %s", + ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("Couldn't set minimum available samples: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("Couldn't set minimum available samples: %s", + ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't set start threshold: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't set start threshold: %s", + ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params(pcm_handle, swparams); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("Couldn't set software audio parameters: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("Couldn't set software audio parameters: %s", + ALSA_snd_strerror(status)); } /* Calculate the final parameters for this audio specification */ @@ -653,8 +641,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { ALSA_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -662,7 +649,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) ALSA_snd_pcm_nonblock(pcm_handle, 0); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static void diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c index 0fe2e4e55..f82854385 100644 --- a/src/audio/android/SDL_androidaudio.c +++ b/src/audio/android/SDL_androidaudio.c @@ -42,21 +42,18 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture) if (iscapture) { //TODO: implement capture - SDL_SetError("Capture not supported on Android"); - return 0; + return SDL_SetError("Capture not supported on Android"); } if (audioDevice != NULL) { - SDL_SetError("Only one audio device at a time please!"); - return 0; + return SDL_SetError("Only one audio device at a time please!"); } audioDevice = this; this->hidden = SDL_malloc(sizeof(*(this->hidden))); if (!this->hidden) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -71,8 +68,7 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture) if (test_format == 0) { // Didn't find a compatible format :( - SDL_SetError("No compatible audio format!"); - return 0; + return SDL_SetError("No compatible audio format!"); } if (this->spec.channels > 1) { @@ -94,11 +90,10 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture) if (this->spec.samples == 0) { // Init failed? - SDL_SetError("Java-side initialization failed!"); - return 0; + return SDL_SetError("Java-side initialization failed!"); } - return 1; + return 0; } static void diff --git a/src/audio/arts/SDL_artsaudio.c b/src/audio/arts/SDL_artsaudio.c index b4a94bcb9..ac0bb9d5d 100644 --- a/src/audio/arts/SDL_artsaudio.c +++ b/src/audio/arts/SDL_artsaudio.c @@ -241,8 +241,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -271,22 +270,19 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) } if (format == 0) { ARTS_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; if ((rc = SDL_NAME(arts_init) ()) != 0) { ARTS_CloseDevice(this); - SDL_SetError("Unable to initialize ARTS: %s", - SDL_NAME(arts_error_text) (rc)); - return 0; + return SDL_SetError("Unable to initialize ARTS: %s", + SDL_NAME(arts_error_text) (rc)); } if (!ARTS_Suspend()) { ARTS_CloseDevice(this); - SDL_SetError("ARTS can not open audio device"); - return 0; + return SDL_SetError("ARTS can not open audio device"); } this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq, @@ -304,8 +300,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec); if ((0x01 << frag_spec) != this->spec.size) { ARTS_CloseDevice(this); - SDL_SetError("Fragment size must be a power of two"); - return 0; + return SDL_SetError("Fragment size must be a power of two"); } frag_spec |= 0x00020000; /* two fragments, for low latency */ @@ -326,8 +321,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { ARTS_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -335,7 +329,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->parent = getpid(); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } diff --git a/src/audio/baudio/SDL_beaudio.cc b/src/audio/baudio/SDL_beaudio.cc index 2a25cf0d2..e2edf85fb 100644 --- a/src/audio/baudio/SDL_beaudio.cc +++ b/src/audio/baudio/SDL_beaudio.cc @@ -95,8 +95,7 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) /* Initialize all variables that we clean on shutdown */ _this->hidden = new SDL_PrivateAudioData; if (_this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(_this->hidden, 0, (sizeof *_this->hidden)); @@ -153,8 +152,7 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_datatype) { /* shouldn't happen, but just in case... */ BEOSAUDIO_CloseDevice(_this); - SDL_SetError("Unsupported audio format"); - return 0; + return SDL_SetError("Unsupported audio format"); } /* Calculate the final parameters for this audio specification */ @@ -173,12 +171,11 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) _this->hidden->audio_obj->SetHasData(true); } else { BEOSAUDIO_CloseDevice(_this); - SDL_SetError("Unable to start Be audio"); - return 0; + return SDL_SetError("Unable to start Be audio"); } /* We're running! */ - return 1; + return 0; } static void diff --git a/src/audio/bsd/SDL_bsdaudio.c b/src/audio/bsd/SDL_bsdaudio.c index d080d666b..b63c838ad 100644 --- a/src/audio/bsd/SDL_bsdaudio.c +++ b/src/audio/bsd/SDL_bsdaudio.c @@ -239,8 +239,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (devname == NULL) { devname = SDL_GetAudioDeviceName(0, iscapture); if (devname == NULL) { - SDL_SetError("No such audio device"); - return 0; + return SDL_SetError("No such audio device"); } } @@ -248,16 +247,14 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); /* Open the audio device */ this->hidden->audio_fd = open(devname, flags, 0); if (this->hidden->audio_fd < 0) { - SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); - return 0; + return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); } AUDIO_INITINFO(&info); @@ -269,8 +266,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) info.mode = AUMODE_PLAY; if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) { BSDAUDIO_CloseDevice(this); - SDL_SetError("Couldn't put device into play mode"); - return 0; + return SDL_SetError("Couldn't put device into play mode"); } AUDIO_INITINFO(&info); @@ -312,8 +308,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (!format) { BSDAUDIO_CloseDevice(this); - SDL_SetError("No supported encoding for 0x%x", this->spec.format); - return 0; + return SDL_SetError("No supported encoding for 0x%x", this->spec.format); } this->spec.format = format; @@ -336,15 +331,14 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { BSDAUDIO_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); BSDAUDIO_Status(this); /* We're ready to rock and roll. :-) */ - return (0); + return 0; } static int diff --git a/src/audio/coreaudio/SDL_coreaudio.c b/src/audio/coreaudio/SDL_coreaudio.c index 31eb32615..8f83d0b39 100644 --- a/src/audio/coreaudio/SDL_coreaudio.c +++ b/src/audio/coreaudio/SDL_coreaudio.c @@ -469,8 +469,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return (0); + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -511,8 +510,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_datatype) { /* shouldn't happen, but just in case... */ COREAUDIO_CloseDevice(this); - SDL_SetError("Unsupported audio format"); - return 0; + return SDL_SetError("Unsupported audio format"); } strdesc.mBytesPerFrame = @@ -522,10 +520,10 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (!prepare_audiounit(this, devname, iscapture, &strdesc)) { COREAUDIO_CloseDevice(this); - return 0; /* prepare_audiounit() will call SDL_SetError()... */ + return -1; /* prepare_audiounit() will call SDL_SetError()... */ } - return 1; /* good to go. */ + return 0; /* good to go. */ } static int diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c index a26fa7e0c..e320056b5 100644 --- a/src/audio/directsound/SDL_directsound.c +++ b/src/audio/directsound/SDL_directsound.c @@ -363,8 +363,7 @@ CreateSecondary(_THIS, HWND focus, WAVEFORMATEX * wavefmt) DSSCL_NORMAL); } if (result != DS_OK) { - SetDSerror("DirectSound SetCooperativeLevel", result); - return (-1); + return SetDSerror("DirectSound SetCooperativeLevel", result); } /* Try to create the secondary buffer */ @@ -449,8 +448,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture) pDirectSoundEnumerateW(FindDevGUID, &devguid); if (!devguid.found) { - SDL_SetError("DirectSound: Requested device not found"); - return 0; + return SDL_SetError("DirectSound: Requested device not found"); } guid = &devguid.guid; } @@ -459,8 +457,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -478,8 +475,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_format) { DSOUND_CloseDevice(this); - SDL_SetError("DirectSound: Unsupported audio format"); - return 0; + return SDL_SetError("DirectSound: Unsupported audio format"); } SDL_memset(&waveformat, 0, sizeof(waveformat)); @@ -499,21 +495,20 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture) result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL); if (result != DS_OK) { DSOUND_CloseDevice(this); - SetDSerror("DirectSoundCreate", result); - return 0; + return SetDSerror("DirectSoundCreate", result); } /* Create the audio buffer to which we write */ this->hidden->num_buffers = CreateSecondary(this, NULL, &waveformat); if (this->hidden->num_buffers < 0) { DSOUND_CloseDevice(this); - return 0; + return -1; } /* The buffer will auto-start playing in DSOUND_WaitDevice() */ this->hidden->mixlen = this->spec.size; - return 1; /* good to go. */ + return 0; /* good to go. */ } diff --git a/src/audio/disk/SDL_diskaudio.c b/src/audio/disk/SDL_diskaudio.c index 3b5b7c9ff..89687ed18 100644 --- a/src/audio/disk/SDL_diskaudio.c +++ b/src/audio/disk/SDL_diskaudio.c @@ -110,8 +110,7 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc(sizeof(*this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, sizeof(*this->hidden)); @@ -119,14 +118,14 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->output = SDL_RWFromFile(fname, "wb"); if (this->hidden->output == NULL) { DISKAUD_CloseDevice(this); - return 0; + return -1; } /* Allocate mixing buffer */ this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { DISKAUD_CloseDevice(this); - return 0; + return -1; } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -141,7 +140,7 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture) #endif /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static int diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c index c0a5d5be3..f868e874a 100644 --- a/src/audio/dsp/SDL_dspaudio.c +++ b/src/audio/dsp/SDL_dspaudio.c @@ -89,8 +89,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) if (devname == NULL) { devname = SDL_GetAudioDeviceName(0, iscapture); if (devname == NULL) { - SDL_SetError("No such audio device"); - return 0; + return SDL_SetError("No such audio device"); } } @@ -107,8 +106,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -116,8 +114,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->audio_fd = open(devname, flags, 0); if (this->hidden->audio_fd < 0) { DSP_CloseDevice(this); - SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); - return 0; + return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); } this->hidden->mixbuf = NULL; @@ -128,8 +125,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) ctlflags &= ~O_NONBLOCK; if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) { DSP_CloseDevice(this); - SDL_SetError("Couldn't set audio blocking mode"); - return 0; + return SDL_SetError("Couldn't set audio blocking mode"); } } @@ -137,8 +133,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) { perror("SNDCTL_DSP_GETFMTS"); DSP_CloseDevice(this); - SDL_SetError("Couldn't get audio format list"); - return 0; + return SDL_SetError("Couldn't get audio format list"); } /* Try for a closest match on audio format */ @@ -195,8 +190,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) } if (format == 0) { DSP_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -206,8 +200,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) (value != format)) { perror("SNDCTL_DSP_SETFMT"); DSP_CloseDevice(this); - SDL_SetError("Couldn't set audio format"); - return 0; + return SDL_SetError("Couldn't set audio format"); } /* Set the number of channels of output */ @@ -215,8 +208,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) { perror("SNDCTL_DSP_CHANNELS"); DSP_CloseDevice(this); - SDL_SetError("Cannot set the number of channels"); - return 0; + return SDL_SetError("Cannot set the number of channels"); } this->spec.channels = value; @@ -225,8 +217,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) { perror("SNDCTL_DSP_SPEED"); DSP_CloseDevice(this); - SDL_SetError("Couldn't set audio frequency"); - return 0; + return SDL_SetError("Couldn't set audio frequency"); } this->spec.freq = value; @@ -237,8 +228,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec); if ((0x01U << frag_spec) != this->spec.size) { DSP_CloseDevice(this); - SDL_SetError("Fragment size must be a power of two"); - return 0; + return SDL_SetError("Fragment size must be a power of two"); } frag_spec |= 0x00020000; /* two fragments, for low latency */ @@ -266,13 +256,12 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { DSP_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } diff --git a/src/audio/dummy/SDL_dummyaudio.c b/src/audio/dummy/SDL_dummyaudio.c index 79106b91f..c3e8ea415 100644 --- a/src/audio/dummy/SDL_dummyaudio.c +++ b/src/audio/dummy/SDL_dummyaudio.c @@ -29,7 +29,7 @@ static int DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture) { - return 1; /* always succeeds. */ + return 0; /* always succeeds. */ } static int diff --git a/src/audio/esd/SDL_esdaudio.c b/src/audio/esd/SDL_esdaudio.c index 307bba911..cdc12120f 100644 --- a/src/audio/esd/SDL_esdaudio.c +++ b/src/audio/esd/SDL_esdaudio.c @@ -228,8 +228,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); this->hidden->audio_fd = -1; @@ -257,8 +256,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) if (!found) { ESD_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } if (this->spec.channels == 1) { @@ -277,8 +275,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) if (this->hidden->audio_fd < 0) { ESD_CloseDevice(this); - SDL_SetError("Couldn't open ESD connection"); - return 0; + return SDL_SetError("Couldn't open ESD connection"); } /* Calculate the final parameters for this audio specification */ @@ -292,8 +289,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { ESD_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -301,7 +297,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->parent = getpid(); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static void diff --git a/src/audio/fusionsound/SDL_fsaudio.c b/src/audio/fusionsound/SDL_fsaudio.c index 8af02ffe1..bc279fec6 100644 --- a/src/audio/fusionsound/SDL_fsaudio.c +++ b/src/audio/fusionsound/SDL_fsaudio.c @@ -200,8 +200,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -243,8 +242,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) if (format == 0) { SDL_FS_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -252,8 +250,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) ret = SDL_NAME(FusionSoundCreate) (&this->hidden->fs); if (ret) { SDL_FS_CloseDevice(this); - SDL_SetError("Unable to initialize FusionSound: %d", ret); - return 0; + return SDL_SetError("Unable to initialize FusionSound: %d", ret); } this->hidden->mixsamples = this->spec.size / bytes / this->spec.channels; @@ -272,8 +269,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) &this->hidden->stream); if (ret) { SDL_FS_CloseDevice(this); - SDL_SetError("Unable to create FusionSoundStream: %d", ret); - return 0; + return SDL_SetError("Unable to create FusionSoundStream: %d", ret); } /* See what we got */ @@ -294,13 +290,12 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { SDL_FS_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } diff --git a/src/audio/nas/SDL_nasaudio.c b/src/audio/nas/SDL_nasaudio.c index fac6ab396..4e3dc0a13 100644 --- a/src/audio/nas/SDL_nasaudio.c +++ b/src/audio/nas/SDL_nasaudio.c @@ -288,8 +288,7 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -304,24 +303,21 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture) } if (format == 0) { NAS_CloseDevice(this); - SDL_SetError("NAS: Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("NAS: Couldn't find any hardware audio formats"); } this->spec.format = test_format; this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL); if (this->hidden->aud == 0) { NAS_CloseDevice(this); - SDL_SetError("NAS: Couldn't open connection to NAS server"); - return 0; + return SDL_SetError("NAS: Couldn't open connection to NAS server"); } this->hidden->dev = find_device(this, this->spec.channels); if ((this->hidden->dev == AuNone) || (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, 0)))) { NAS_CloseDevice(this); - SDL_SetError("NAS: Couldn't find a fitting device on NAS server"); - return 0; + return SDL_SetError("NAS: Couldn't find a fitting device on NAS server"); } buffer_size = this->spec.freq; @@ -354,13 +350,12 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { NAS_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static void diff --git a/src/audio/paudio/SDL_paudio.c b/src/audio/paudio/SDL_paudio.c index 1cb77aa1c..3966d1e7a 100644 --- a/src/audio/paudio/SDL_paudio.c +++ b/src/audio/paudio/SDL_paudio.c @@ -264,8 +264,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -274,8 +273,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->audio_fd = fd; if (fd < 0) { PAUDIO_CloseDevice(this); - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return 0; + return SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); } /* @@ -284,8 +282,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) */ if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) { PAUDIO_CloseDevice(this); - SDL_SetError("Couldn't get audio buffer information"); - return 0; + return SDL_SetError("Couldn't get audio buffer information"); } if (this->spec.channels > 1) @@ -399,8 +396,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) fprintf(stderr, "Couldn't find any hardware audio formats\n"); #endif PAUDIO_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -458,8 +454,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (err != NULL) { PAUDIO_CloseDevice(this); - SDL_SetError("Paudio: %s", err); - return 0; + return SDL_SetError("Paudio: %s", err); } /* Allocate mixing buffer */ @@ -467,8 +462,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { PAUDIO_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -506,8 +500,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) #ifdef DEBUG_AUDIO fprintf(stderr, "Can't start audio play\n"); #endif - SDL_SetError("Can't start audio play"); - return 0; + return SDL_SetError("Can't start audio play"); } /* Check to see if we need to use select() workaround */ @@ -518,7 +511,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) } /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static int diff --git a/src/audio/psp/SDL_pspaudio.c b/src/audio/psp/SDL_pspaudio.c index fc277e60d..fc03a8754 100644 --- a/src/audio/psp/SDL_pspaudio.c +++ b/src/audio/psp/SDL_pspaudio.c @@ -46,8 +46,7 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc(sizeof(*this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, sizeof(*this->hidden)); switch (this->spec.format & 0xff) { @@ -56,8 +55,7 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture) this->spec.format = AUDIO_S16LSB; break; default: - SDL_SetError("Unsupported audio format"); - return 0; + return SDL_SetError("Unsupported audio format"); } /* The sample count must be a multiple of 64. */ @@ -86,8 +84,7 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture) mixlen = this->spec.size * NUM_BUFFERS; this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen); if (this->hidden->rawbuf == NULL) { - SDL_SetError("Couldn't allocate mixing buffer"); - return 0; + return SDL_SetError("Couldn't allocate mixing buffer"); } /* Setup the hardware channel. */ @@ -98,10 +95,9 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture) } this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format); if (this->hidden->channel < 0) { - SDL_SetError("Couldn't reserve hardware channel"); free(this->hidden->rawbuf); this->hidden->rawbuf = NULL; - return 0; + return SDL_SetError("Couldn't reserve hardware channel"); } memset(this->hidden->rawbuf, 0, mixlen); @@ -110,7 +106,7 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture) } this->hidden->next_buffer = 0; - return 1; + return 0; } static void PSPAUD_PlayDevice(_THIS) diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index cf3522b1b..12021e6de 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -337,8 +337,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); h = this->hidden; @@ -371,8 +370,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) } if (paspec.format == PA_SAMPLE_INVALID) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -387,8 +385,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) h->mixbuf = (Uint8 *) SDL_AllocAudioMem(h->mixlen); if (h->mixbuf == NULL) { PULSEAUDIO_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(h->mixbuf, this->spec.silence, this->spec.size); @@ -419,36 +416,31 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) /* Set up a new main loop */ if (!(h->mainloop = PULSEAUDIO_pa_mainloop_new())) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("pa_mainloop_new() failed"); - return 0; + return SDL_SetError("pa_mainloop_new() failed"); } h->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(h->mainloop); h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, NULL); if (!h->context) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("pa_context_new() failed"); - return 0; + return SDL_SetError("pa_context_new() failed"); } /* Connect to the PulseAudio server */ if (PULSEAUDIO_pa_context_connect(h->context, NULL, 0, NULL) < 0) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not setup connection to PulseAudio"); - return 0; + return SDL_SetError("Could not setup connection to PulseAudio"); } do { if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("pa_mainloop_iterate() failed"); - return 0; + return SDL_SetError("pa_mainloop_iterate() failed"); } state = PULSEAUDIO_pa_context_get_state(h->context); if (!PA_CONTEXT_IS_GOOD(state)) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not connect to PulseAudio"); - return 0; + return SDL_SetError("Could not connect to PulseAudio"); } } while (state != PA_CONTEXT_READY); @@ -461,33 +453,29 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (h->stream == NULL) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not set up PulseAudio stream"); - return 0; + return SDL_SetError("Could not set up PulseAudio stream"); } if (PULSEAUDIO_pa_stream_connect_playback(h->stream, NULL, &paattr, flags, NULL, NULL) < 0) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not connect PulseAudio stream"); - return 0; + return SDL_SetError("Could not connect PulseAudio stream"); } do { if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("pa_mainloop_iterate() failed"); - return 0; + return SDL_SetError("pa_mainloop_iterate() failed"); } state = PULSEAUDIO_pa_stream_get_state(h->stream); if (!PA_STREAM_IS_GOOD(state)) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not create to PulseAudio stream"); - return 0; + return SDL_SetError("Could not create to PulseAudio stream"); } } while (state != PA_STREAM_READY); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } diff --git a/src/audio/qsa/SDL_qsa_audio.c b/src/audio/qsa/SDL_qsa_audio.c index a72a19c6c..e3877b463 100644 --- a/src/audio/qsa/SDL_qsa_audio.c +++ b/src/audio/qsa/SDL_qsa_audio.c @@ -83,10 +83,10 @@ uint32_t qsa_playback_devices; QSA_Device qsa_capture_device[QSA_MAX_DEVICES]; uint32_t qsa_capture_devices; -static inline void +static inline int QSA_SetError(const char *fn, int status) { - SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status)); + return SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status)); } /* card names check to apply the workarounds */ @@ -183,13 +183,13 @@ QSA_WaitDevice(_THIS) switch (selectret) { case -1: { - SDL_SetError("QSA: select() failed: %s\n", strerror(errno)); + SDL_SetError("QSA: select() failed: %s", strerror(errno)); return; } break; case 0: { - SDL_SetError("QSA: timeout on buffer waiting occured\n"); + SDL_SetError("QSA: timeout on buffer waiting occured"); this->hidden->timeout_on_wait = 1; return; } @@ -237,7 +237,7 @@ QSA_PlayDevice(_THIS) /* the audio device driver */ if ((errno == EAGAIN) && (written == 0)) { if (this->hidden->timeout_on_wait != 0) { - SDL_SetError("QSA: buffer playback timeout\n"); + SDL_SetError("QSA: buffer playback timeout"); return; } } @@ -355,8 +355,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) (struct SDL_PrivateAudioData))); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData)); @@ -384,8 +383,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) device++; if (device >= qsa_playback_devices) { QSA_CloseDevice(this); - SDL_SetError("No such playback device"); - return 0; + return SDL_SetError("No such playback device"); } } while (1); } @@ -409,8 +407,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) device++; if (device >= qsa_capture_devices) { QSA_CloseDevice(this); - SDL_SetError("No such capture device"); - return 0; + return SDL_SetError("No such capture device"); } } while (1); } @@ -448,8 +445,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) if (status < 0) { this->hidden->audio_handle = NULL; QSA_CloseDevice(this); - QSA_SetError("snd_pcm_open", status); - return 0; + return QSA_SetError("snd_pcm_open", status); } if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) { @@ -459,8 +455,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) PLUGIN_DISABLE_MMAP); if (status < 0) { QSA_CloseDevice(this); - QSA_SetError("snd_pcm_plugin_set_disable", status); - return 0; + return QSA_SetError("snd_pcm_plugin_set_disable", status); } } @@ -546,8 +541,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) /* assumes test_format not 0 on success */ if (test_format == 0) { QSA_CloseDevice(this); - SDL_SetError("QSA: Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("QSA: Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -565,8 +559,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams); if (status < 0) { QSA_CloseDevice(this); - QSA_SetError("snd_pcm_channel_params", status); - return 0; + return QSA_SetError("snd_pcm_channel_params", status); } /* Make sure channel is setup right one last time */ @@ -580,8 +573,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) /* Setup an audio channel */ if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) { QSA_CloseDevice(this); - SDL_SetError("QSA: Unable to setup channel\n"); - return 0; + return SDL_SetError("QSA: Unable to setup channel"); } /* Calculate the final parameters for this audio specification */ @@ -604,8 +596,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len); if (this->hidden->pcm_buf == NULL) { QSA_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->pcm_buf, this->spec.silence, this->hidden->pcm_len); @@ -623,8 +614,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) if (this->hidden->audio_fd < 0) { QSA_CloseDevice(this); - QSA_SetError("snd_pcm_file_descriptor", status); - return 0; + return QSA_SetError("snd_pcm_file_descriptor", status); } /* Prepare an audio channel */ @@ -642,12 +632,11 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) if (status < 0) { QSA_CloseDevice(this); - QSA_SetError("snd_pcm_plugin_prepare", status); - return 0; + return QSA_SetError("snd_pcm_plugin_prepare", status); } /* We're really ready to rock and roll. :-) */ - return 1; + return 0; } static void diff --git a/src/audio/sun/SDL_sunaudio.c b/src/audio/sun/SDL_sunaudio.c index c5a33d47f..37e175e10 100644 --- a/src/audio/sun/SDL_sunaudio.c +++ b/src/audio/sun/SDL_sunaudio.c @@ -213,8 +213,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (devname == NULL) { devname = SDL_GetAudioDeviceName(0, iscapture); if (devname == NULL) { - SDL_SetError("No such audio device"); - return 0; + return SDL_SetError("No such audio device"); } } @@ -222,16 +221,14 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); /* Open the audio device */ this->hidden->audio_fd = open(devname, flags, 0); if (this->hidden->audio_fd < 0) { - SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); - return 0; + return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); } #ifdef AUDIO_SETINFO @@ -263,8 +260,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) default: { /* !!! FIXME: fallback to conversion on unsupported types! */ - SDL_SetError("Unsupported audio format"); - return (-1); + return SDL_SetError("Unsupported audio format"); } } this->hidden->audio_fmt = this->spec.format; @@ -285,9 +281,8 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) /* Check to be sure we got what we wanted */ if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) { - SDL_SetError("Error getting audio parameters: %s", - strerror(errno)); - return -1; + return SDL_SetError("Error getting audio parameters: %s", + strerror(errno)); } if (info.play.encoding == enc && info.play.precision == (this->spec.format & 0xff) @@ -316,9 +311,8 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) default: /* oh well... */ - SDL_SetError("Error setting audio parameters: %s", - strerror(errno)); - return -1; + return SDL_SetError("Error setting audio parameters: %s", + strerror(errno)); } } #endif /* AUDIO_SETINFO */ @@ -357,7 +351,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return (1); + return 0; } /************************************************************************/ diff --git a/src/audio/winmm/SDL_winmm.c b/src/audio/winmm/SDL_winmm.c index 990f4d11c..f52a3afb1 100644 --- a/src/audio/winmm/SDL_winmm.c +++ b/src/audio/winmm/SDL_winmm.c @@ -91,7 +91,7 @@ FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, ReleaseSemaphore(this->hidden->audio_sem, 1, NULL); } -static void +static int SetMMerror(char *function, MMRESULT code) { size_t len; @@ -105,7 +105,7 @@ SetMMerror(char *function, MMRESULT code) WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len, MAXERRORLENGTH - len, NULL, NULL); - SDL_SetError("%s", errbuf); + return SDL_SetError("%s", errbuf); } static void @@ -234,8 +234,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) } if (devId == WAVE_MAPPER) { - SDL_SetError("Requested device not found"); - return 0; + return SDL_SetError("Requested device not found"); } } @@ -243,8 +242,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -270,8 +268,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_datatype) { WINMM_CloseDevice(this); - SDL_SetError("Unsupported audio format"); - return 0; + return SDL_SetError("Unsupported audio format"); } /* Set basic WAVE format parameters */ @@ -309,8 +306,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) if (result != MMSYSERR_NOERROR) { WINMM_CloseDevice(this); - SetMMerror("waveOutOpen()", result); - return 0; + return SetMMerror("waveOutOpen()", result); } #ifdef SOUND_DEBUG /* Check the sound device we retrieved */ @@ -321,8 +317,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) &caps, sizeof(caps)); if (result != MMSYSERR_NOERROR) { WINMM_CloseDevice(this); - SetMMerror("waveOutGetDevCaps()", result); - return 0; + return SetMMerror("waveOutGetDevCaps()", result); } printf("Audio device: %s\n", caps.szPname); } @@ -333,8 +328,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL); if (this->hidden->audio_sem == NULL) { WINMM_CloseDevice(this); - SDL_SetError("Couldn't create semaphore"); - return 0; + return SDL_SetError("Couldn't create semaphore"); } /* Create the sound buffers */ @@ -342,8 +336,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size); if (this->hidden->mixbuf == NULL) { WINMM_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } for (i = 0; i < NUM_BUFFERS; ++i) { SDL_memset(&this->hidden->wavebuf[i], 0, @@ -357,12 +350,11 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) sizeof(this->hidden->wavebuf[i])); if (result != MMSYSERR_NOERROR) { WINMM_CloseDevice(this); - SetMMerror("waveOutPrepareHeader()", result); - return 0; + return SetMMerror("waveOutPrepareHeader()", result); } } - return 1; /* Ready to go! */ + return 0; /* Ready to go! */ } diff --git a/src/audio/xaudio2/SDL_xaudio2.c b/src/audio/xaudio2/SDL_xaudio2.c index 3f78db438..40d94086f 100644 --- a/src/audio/xaudio2/SDL_xaudio2.c +++ b/src/audio/xaudio2/SDL_xaudio2.c @@ -245,11 +245,9 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) static IXAudio2VoiceCallback callbacks = { &callbacks_vtable }; if (iscapture) { - SDL_SetError("XAudio2: capture devices unsupported."); - return 0; + return SDL_SetError("XAudio2: capture devices unsupported."); } else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) { - SDL_SetError("XAudio2: XAudio2Create() failed."); - return 0; + return SDL_SetError("XAudio2: XAudio2Create() failed."); } if (devname != NULL) { @@ -258,8 +256,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) { IXAudio2_Release(ixa2); - SDL_SetError("XAudio2: IXAudio2_GetDeviceCount() failed."); - return 0; + return SDL_SetError("XAudio2: IXAudio2_GetDeviceCount() failed."); } for (i = 0; i < devcount; i++) { XAUDIO2_DEVICE_DETAILS details; @@ -278,8 +275,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) if (i == devcount) { IXAudio2_Release(ixa2); - SDL_SetError("XAudio2: Requested device not found."); - return 0; + return SDL_SetError("XAudio2: Requested device not found."); } } @@ -288,8 +284,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { IXAudio2_Release(ixa2); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -297,8 +292,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->semaphore = CreateSemaphore(NULL, 1, 2, NULL); if (this->hidden->semaphore == NULL) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: CreateSemaphore() failed!"); - return 0; + return SDL_SetError("XAudio2: CreateSemaphore() failed!"); } while ((!valid_format) && (test_format)) { @@ -316,8 +310,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_format) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Unsupported audio format"); - return 0; + return SDL_SetError("XAudio2: Unsupported audio format"); } /* Update the fragment size as size in bytes */ @@ -328,8 +321,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_malloc(2 * this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { XAUDIO2_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } this->hidden->nextbuf = this->hidden->mixbuf; SDL_memset(this->hidden->mixbuf, 0, 2 * this->hidden->mixlen); @@ -345,8 +337,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) this->spec.freq, 0, devId, NULL); if (result != S_OK) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Couldn't create mastering voice"); - return 0; + return SDL_SetError("XAudio2: Couldn't create mastering voice"); } SDL_zero(waveformat); @@ -369,8 +360,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) 1.0f, &callbacks, NULL, NULL); if (result != S_OK) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Couldn't create source voice"); - return 0; + return SDL_SetError("XAudio2: Couldn't create source voice"); } this->hidden->source = source; @@ -378,18 +368,16 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) result = IXAudio2_StartEngine(ixa2); if (result != S_OK) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Couldn't start engine"); - return 0; + return SDL_SetError("XAudio2: Couldn't start engine"); } result = IXAudio2SourceVoice_Start(source, 0, XAUDIO2_COMMIT_NOW); if (result != S_OK) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Couldn't start source voice"); - return 0; + return SDL_SetError("XAudio2: Couldn't start source voice"); } - return 1; /* good to go. */ + return 0; /* good to go. */ } static void From 6fe4eabf3e7125328883b7729e0d073a4b0517bf Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Mon, 1 Apr 2013 13:20:22 -0300 Subject: [PATCH 127/151] Backed out changeset: 9cef1005df5f --- android-project/project.properties | 2 +- .../src/org/libsdl/app/SDLActivity.java | 159 ++---------------- src/core/android/SDL_android.cpp | 128 -------------- src/core/android/SDL_android.h | 12 -- 4 files changed, 15 insertions(+), 286 deletions(-) diff --git a/android-project/project.properties b/android-project/project.properties index 0f507e530..b7c2081d5 100644 --- a/android-project/project.properties +++ b/android-project/project.properties @@ -11,4 +11,4 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-12 +target=android-10 diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index 55ab5cb4b..e0a850f42 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -24,8 +24,6 @@ import android.hardware.*; import android.content.*; import java.lang.*; -import java.util.List; -import java.util.ArrayList; /** @@ -44,11 +42,6 @@ public class SDLActivity extends Activity { // This is what SDL runs in. It invokes SDL_main(), eventually private static Thread mSDLThread; - - // Joystick - private static List mJoyIdList; - // TODO: Have a (somewhat) more efficient way of storing these? - private static List> mJoyAxesLists; // Audio private static Thread mAudioThread; @@ -163,15 +156,12 @@ public class SDLActivity extends Activity { public static native void nativePause(); public static native void nativeResume(); public static native void onNativeResize(int x, int y, int format); - public static native void onNativePadDown(int padId, int keycode); - public static native void onNativePadUp(int padId, int keycode); - public static native void onNativeJoy(int joyId, int axisNum, float value); public static native void onNativeKeyDown(int keycode); public static native void onNativeKeyUp(int keycode); public static native void onNativeTouch(int touchDevId, int pointerFingerId, int action, float x, float y, float p); -// public static native void onNativeAccel(float x, float y, float z); + public static native void onNativeAccel(float x, float y, float z); public static native void nativeRunAudioThread(); @@ -190,74 +180,6 @@ public class SDLActivity extends Activity { mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title); } - // Call when initializing the joystick subsystem - public static void joystickInit() { - mJoyIdList = new ArrayList(); - mJoyAxesLists = new ArrayList>(); - - int[] deviceIds = InputDevice.getDeviceIds(); - for(int i=0; i axesList = new ArrayList(); - /* With API 12 and above we can get a list of all motion - * ranges, hence all axes. Some of them may be irrelevant - * (e.g. an embedded trackpad). We filter the desired axes. - */ - if(Build.VERSION.SDK_INT >= 12) { - List rangesList = InputDevice.getDevice(deviceIds[i]).getMotionRanges(); - for (InputDevice.MotionRange range : rangesList) { - // Skip any possibly unrelated axis - if ( (range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { - axesList.add(range.getAxis()); - } - } - } else { - // In older versions, we can assume a sane X-Y default configuration - axesList.add(MotionEvent.AXIS_X); - axesList.add(MotionEvent.AXIS_Y); - } - mJoyAxesLists.add(axesList); - } - } - } - - // Call when one clears joystick subsystem resources - public static void joystickQuit() { - mJoyIdList = null; - mJoyAxesLists = null; - } - - public static int getNumJoysticks() { - if (mJoyIdList == null) - return -1; - return mJoyIdList.size(); - } - - public static String getJoystickName(int joy) { - if (mJoyIdList == null) - return null; - return InputDevice.getDevice(mJoyIdList.get(joy)).getName(); - } - - public static List getJoystickAxesList(int joy) { - if (mJoyIdList == null) - return null; - return mJoyAxesLists.get(joy); - } - - public static int getJoystickNumOfAxes(int joy) { - if (mJoyIdList == null) - return -1; - return mJoyAxesLists.get(joy).size(); - } - - public static int getJoyId(int devId) { - if (mJoyIdList == null) - return -1; - return mJoyIdList.indexOf(devId); - } - public static void sendMessage(int command, int param) { mSingleton.sendCommand(command, Integer.valueOf(param)); } @@ -556,12 +478,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, setFocusableInTouchMode(true); requestFocus(); setOnKeyListener(this); - setOnTouchListener(this); - - // Listen to joystick motion events if supported - if (Build.VERSION.SDK_INT >= 12) { - setOnGenericMotionListener(new SDLOnGenericMotionListener()); - } + setOnTouchListener(this); mSensorManager = (SensorManager)context.getSystemService("sensor"); @@ -651,65 +568,18 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, - // Listen to joystick motion events if supported (API >= 12) - private static class SDLOnGenericMotionListener implements View.OnGenericMotionListener { - @Override - public boolean onGenericMotion(View view, MotionEvent event) { - int actionPointerIndex = event.getActionIndex(); - int action = event.getActionMasked(); - - if ( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { - switch(action) { - case MotionEvent.ACTION_MOVE: - int id = SDLActivity.getJoyId( event.getDeviceId() ); - // The joystick subsystem may be uninitialized, so ignore - if (id < 0) - return true; - // Update values for all joystick axes - List axes = SDLActivity.getJoystickAxesList(id); - for (int axisIndex = 0; axisIndex < axes.size(); axisIndex++) { - SDLActivity.onNativeJoy(id, axisIndex, event.getAxisValue(axes.get(axisIndex), actionPointerIndex)); - } - - return true; - } - } - return false; - } - } - // Key events public boolean onKey(View v, int keyCode, KeyEvent event) { - /* Dispatch the different events depending on where they come from: - * If the input device has some joystick source (probably differing - * from the source to which the given key belongs), assume it is a - * game controller button. Otherwise, assume a keyboard key. - * This should also take care of some kinds of manually toggled soft - * keyboards (i.e. not via the SDL text input API). - */ - if ( (event.getDevice().getSources() & 0x00000010 /* API 12: InputDevice.SOURCE_CLASS_JOYSTICK*/) != 0) { - int id = SDLActivity.getJoyId( event.getDeviceId() ); - // The joystick subsystem may be uninitialized, so ignore - if (id < 0) - return true; - if (event.getAction() == KeyEvent.ACTION_DOWN) { - SDLActivity.onNativePadDown(id, keyCode); - return true; - } else if (event.getAction() == KeyEvent.ACTION_UP) { - SDLActivity.onNativePadUp(id, keyCode); - return true; - } - } else { - if (event.getAction() == KeyEvent.ACTION_DOWN) { - //Log.v("SDL", "key down: " + keyCode); - SDLActivity.onNativeKeyDown(keyCode); - return true; - } - else if (event.getAction() == KeyEvent.ACTION_UP) { - //Log.v("SDL", "key up: " + keyCode); - SDLActivity.onNativeKeyUp(keyCode); - return true; - } + + if (event.getAction() == KeyEvent.ACTION_DOWN) { + //Log.v("SDL", "key down: " + keyCode); + SDLActivity.onNativeKeyDown(keyCode); + return true; + } + else if (event.getAction() == KeyEvent.ACTION_UP) { + //Log.v("SDL", "key up: " + keyCode); + SDLActivity.onNativeKeyUp(keyCode); + return true; } return false; @@ -744,7 +614,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, } } return true; - } + } // Sensor events public void enableSensor(int sensortype, boolean enabled) { @@ -764,14 +634,13 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, } public void onSensorChanged(SensorEvent event) { -/* if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH, event.values[1] / SensorManager.GRAVITY_EARTH, event.values[2] / SensorManager.GRAVITY_EARTH); } -*/ } + } /* This is a fake invisible editor view that receives the input and defines the diff --git a/src/core/android/SDL_android.cpp b/src/core/android/SDL_android.cpp index 9ca73d60a..457512a16 100644 --- a/src/core/android/SDL_android.cpp +++ b/src/core/android/SDL_android.cpp @@ -31,15 +31,11 @@ extern "C" { #include "../../events/SDL_events_c.h" -#include "../../joystick/android/SDL_androidjoystick.h" #include "../../video/android/SDL_androidkeyboard.h" #include "../../video/android/SDL_androidtouch.h" #include "../../video/android/SDL_androidvideo.h" #include -#if ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK -#include -#endif #include #include #include @@ -80,11 +76,9 @@ static jmethodID midAudioWriteShortBuffer; static jmethodID midAudioWriteByteBuffer; static jmethodID midAudioQuit; -#ifdef ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK // Accelerometer data storage static float fLastAccelerometer[3]; static bool bHasNewData; -#endif /******************************************************************************* Functions called by JNI @@ -136,9 +130,7 @@ extern "C" void SDL_Android_Init(JNIEnv* mEnv, jclass cls) midAudioQuit = mEnv->GetStaticMethodID(mActivityClass, "audioQuit", "()V"); -#ifdef ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK bHasNewData = false; -#endif if(!midCreateGLContext || !midFlipBuffers || !midAudioInit || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) { @@ -155,27 +147,6 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize( Android_SetScreenResolution(width, height, format); } -// Paddown -extern "C" void Java_org_libsdl_app_SDLActivity_onNativePadDown( - JNIEnv* env, jclass jcls, jint padId, jint keycode) -{ - Android_OnPadDown(padId, keycode); -} - -// Padup -extern "C" void Java_org_libsdl_app_SDLActivity_onNativePadUp( - JNIEnv* env, jclass jcls, jint padId, jint keycode) -{ - Android_OnPadUp(padId, keycode); -} - -// Joysticks -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeJoy( - JNIEnv* env, jclass jcls, jint joyId, jint axisNum, jfloat value) -{ - Android_OnJoy(joyId, axisNum, value); -} - // Keydown extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown( JNIEnv* env, jclass jcls, jint keycode) @@ -199,7 +170,6 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch( Android_OnTouch(touch_device_id_in, pointer_finger_id_in, action, x, y, p); } -#if ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK // Accelerometer extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel( JNIEnv* env, jclass jcls, @@ -210,7 +180,6 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel( fLastAccelerometer[2] = z; bHasNewData = true; } -#endif // Quit extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit( @@ -378,7 +347,6 @@ extern "C" void Android_JNI_SetActivityTitle(const char *title) } } -#if ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK extern "C" SDL_bool Android_JNI_GetAccelerometerValues(float values[3]) { int i; @@ -394,7 +362,6 @@ extern "C" SDL_bool Android_JNI_GetAccelerometerValues(float values[3]) return retval; } -#endif static void Android_JNI_ThreadDestroyed(void* value) { /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */ @@ -1111,101 +1078,6 @@ extern "C" int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery return 0; } -// Initialize the joystick subsystem on the Java side -int Android_JNI_JoystickInit() -{ - JNIEnv* env = Android_JNI_GetEnv(); - if (!env) { - return -1; - } - jmethodID mid = env->GetStaticMethodID(mActivityClass, "joystickInit", "()V"); - if (!mid) { - return -1; - } - env->CallStaticVoidMethod(mActivityClass, mid); - return 0; -} - -// Quit the joystick subsystem on the Java side -int Android_JNI_JoystickQuit() -{ - JNIEnv* env = Android_JNI_GetEnv(); - if (!env) { - return -1; - } - jmethodID mid = env->GetStaticMethodID(mActivityClass, "joystickQuit", "()V"); - if (!mid) { - return -1; - } - env->CallStaticVoidMethod(mActivityClass, mid); - return 0; -} - -// return the total number of plugged in joysticks -extern "C" int Android_JNI_GetNumJoysticks() -{ - JNIEnv* env = Android_JNI_GetEnv(); - if (!env) { - return -1; - } - jmethodID mid = env->GetStaticMethodID(mActivityClass, "getNumJoysticks", "()I"); - if (!mid) { - return -1; - } - - return env->CallStaticIntMethod(mActivityClass, mid); -} - -// Return the name of joystick number "index" -extern "C" char* Android_JNI_GetJoystickName(int index) -{ - JNIEnv* env = Android_JNI_GetEnv(); - if (!env) { - return SDL_strdup(""); - } - - jmethodID mid = env->GetStaticMethodID(mActivityClass, "getJoystickName", "(I)Ljava/lang/String;"); - if (!mid) { - return SDL_strdup(""); - } - jstring string = reinterpret_cast(env->CallStaticObjectMethod(mActivityClass, mid, index)); - const char* utf = env->GetStringUTFChars(string, 0); - if (!utf) { - return SDL_strdup(""); - } - - char* text = SDL_strdup(utf); - env->ReleaseStringUTFChars(string, utf); - return text; -} - -// return the number of axes in the given joystick -extern "C" int Android_JNI_GetJoystickNumOfAxes(int index) -{ - JNIEnv* env = Android_JNI_GetEnv(); - if (!env) { - return -1; - } - jmethodID mid = env->GetStaticMethodID(mActivityClass, "getJoystickNumOfAxes", "(I)I"); - if (!mid) { - return -1; - } - - return env->CallStaticIntMethod(mActivityClass, mid, index); -} - -#if ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK -// Return the name of the default accelerometer -// This is much easier to be done with NDK than with JNI -extern "C" char* Android_GetAccelName() -{ - ASensorManager* mSensorManager = ASensorManager_getInstance(); - ASensor const* mAccelerometer = ASensorManager_getDefaultSensor(mSensorManager, ASENSOR_TYPE_ACCELEROMETER); - - return SDL_strdup(ASensor_getName(mAccelerometer)); -} -#endif - // sends message to be handled on the UI event dispatch thread extern "C" int Android_JNI_SendMessage(int command, int param) { diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index f57728461..7eddcfac8 100644 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -33,9 +33,7 @@ extern "C" { extern SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion, int red, int green, int blue, int alpha, int buffer, int depth, int stencil, int buffers, int samples); extern void Android_JNI_SwapWindow(); extern void Android_JNI_SetActivityTitle(const char *title); -#ifdef ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]); -#endif extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect); extern void Android_JNI_HideTextInput(); @@ -62,16 +60,6 @@ SDL_bool Android_JNI_HasClipboardText(); /* Power support */ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent); -/* Joystick/accelerometer support */ -int Android_JNI_JoystickInit(); -int Android_JNI_JoystickQuit(); -int Android_JNI_GetNumJoysticks(); -char* Android_JNI_GetJoystickName(int i); -int Android_JNI_GetJoystickNumOfAxes(int index); -#ifdef ENABLE_ACCELOMETER_AS_EMULATED_JOYSTICK -char* Android_GetAccelName(); -#endif - // Threads #include static void Android_JNI_ThreadDestroyed(void*); From 0bc9621a7f59855c274e14878402b0cae6ce267d Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Mon, 1 Apr 2013 13:21:08 -0300 Subject: [PATCH 128/151] Backed out changeset: a713101e1d25 --- src/joystick/android/SDL_androidjoystick.c | 239 --------------------- src/joystick/android/SDL_androidjoystick.h | 27 --- 2 files changed, 266 deletions(-) delete mode 100644 src/joystick/android/SDL_androidjoystick.c delete mode 100644 src/joystick/android/SDL_androidjoystick.h diff --git a/src/joystick/android/SDL_androidjoystick.c b/src/joystick/android/SDL_androidjoystick.c deleted file mode 100644 index 41ccd2240..000000000 --- a/src/joystick/android/SDL_androidjoystick.c +++ /dev/null @@ -1,239 +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" - -#ifdef SDL_JOYSTICK_ANDROID - -/* This is the system specific header for the SDL joystick API */ -#include /* For the definition of NULL */ - -#include "SDL_error.h" -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" -#include "../../core/android/SDL_android.h" - -//HACK!! -static SDL_Joystick **SYS_Joysticks; -static char **SYS_JoystickNames; -static int SYS_numjoysticks; - -/* Function to convert Android keyCodes into SDL ones. - * This code manipulation is done to get a sequential list of codes. - */ -int -keycode_to_SDL(int keycode) -{ - /* D-Pad key codes (API 1): - * KEYCODE_DPAD_UP=19, KEYCODE_DPAD_DOWN - * KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT, KEYCODE_DPAD_CENTER - */ - if(keycode < 96) - return keycode-19; - /* Some gamepad buttons (API 9): - * KEYCODE_BUTTON_A=96, KEYCODE_BUTTON_B, KEYCODE_BUTTON_C, - * KEYCODE_BUTTON_X, KEYCODE_BUTTON_Y, KEYCODE_BUTTON_Z, - * KEYCODE_BUTTON_L1, KEYCODE_BUTTON_L2, - * KEYCODE_BUTTON_R1, KEYCODE_BUTTON_R2, - * KEYCODE_BUTTON_THUMBL, KEYCODE_BUTTON_THUMBR, - * KEYCODE_BUTTON_START, KEYCODE_BUTTON_SELECT, KEYCODE_BUTTON_MODE - */ - else if(keycode < 188) - return keycode-91; - /* More gamepad buttons (API 12): - * KEYCODE_BUTTON_1=188 to KEYCODE_BUTTON_16 - */ - else - return keycode-168; -} - -/* Function to scan the system for joysticks. - * This function should set SYS_numjoysticks to the number of available - * joysticks. Joystick 0 should be the system default joystick. - * It should return 0, or -1 on an unrecoverable fatal error. - */ -int -SDL_SYS_JoystickInit(void) -{ - int i = 0; - if (Android_JNI_JoystickInit() < 0) - return -1; - SYS_numjoysticks = Android_JNI_GetNumJoysticks(); - SYS_Joysticks = (SDL_Joystick **)SDL_malloc(SYS_numjoysticks*sizeof(SDL_Joystick *)); - if (SYS_Joysticks == NULL) { - return SDL_OutOfMemory(); - } - SYS_JoystickNames = (char **)SDL_malloc(SYS_numjoysticks*sizeof(char *)); - if (SYS_JoystickNames == NULL) { - SDL_free(SYS_Joysticks); - SYS_Joysticks = NULL; - return SDL_OutOfMemory(); - } - SDL_memset(SYS_JoystickNames, 0, (SYS_numjoysticks*sizeof(char *))); - SDL_memset(SYS_Joysticks, 0, (SYS_numjoysticks*sizeof(SDL_Joystick *))); - - for (i = 0; i < SYS_numjoysticks; i++) { - SYS_JoystickNames[i] = Android_JNI_GetJoystickName(i); - } - - return SYS_numjoysticks; -} - -int SDL_SYS_NumJoysticks() -{ - return SYS_numjoysticks; -} - -void SDL_SYS_JoystickDetect() -{ -} - -SDL_bool SDL_SYS_JoystickNeedsPolling() -{ - return SDL_FALSE; -} - -/* Function to get the device-dependent name of a joystick */ -const char * -SDL_SYS_JoystickNameForDeviceIndex(int device_index) -{ - return SYS_JoystickNames[device_index]; -} - -/* Function to perform the mapping from device index to the instance id for this index */ -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) -{ - return device_index; -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int -SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) -{ - if( device_index < SYS_numjoysticks ) - { - // TODO: How to get the rest of the info?? - // 36 is the maximum number of handled buttons - joystick->nbuttons = 36; - joystick->nhats = 0; - joystick->nballs = 0; - joystick->naxes = Android_JNI_GetJoystickNumOfAxes(device_index); - } - else - { - return -1; - } - - // Extremely hacky - SYS_Joysticks[device_index] = joystick; - - return 0; -} - - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) -{ -} - -/* Function to determine is this joystick is attached to the system right now */ -SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) -{ - return SDL_TRUE; -} - -/* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick * joystick) -{ -} - -/* Function to perform any system-specific joystick related cleanup */ -void -SDL_SYS_JoystickQuit(void) -{ - SDL_free(SYS_JoystickNames); - SDL_free(SYS_Joysticks); - SYS_JoystickNames = NULL; - SYS_Joysticks = NULL; - Android_JNI_JoystickQuit(); -} - -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) -{ - SDL_JoystickGUID guid; - // the GUID is just the first 16 chars of the name for now - const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) -{ - SDL_JoystickGUID guid; - // the GUID is just the first 16 chars of the name for now - const char *name = joystick->name; - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -int -Android_OnPadDown(int padId, int keycode) -{ - SDL_PrivateJoystickButton(SYS_Joysticks[padId], keycode_to_SDL(keycode), SDL_PRESSED); - - return 0; -} - -int -Android_OnPadUp(int padId, int keycode) -{ - SDL_PrivateJoystickButton(SYS_Joysticks[padId], keycode_to_SDL(keycode), SDL_RELEASED); - - return 0; -} - -int -Android_OnJoy(int joyId, int axisnum, float value) -{ - // Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0] - // TODO: Are the reported values right? - SDL_PrivateJoystickAxis(SYS_Joysticks[joyId], axisnum, (Sint16) (32767.*value) ); - - return 0; -} - -#endif /* SDL_JOYSTICK_ANDROID */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/android/SDL_androidjoystick.h b/src/joystick/android/SDL_androidjoystick.h deleted file mode 100644 index 01a970232..000000000 --- a/src/joystick/android/SDL_androidjoystick.h +++ /dev/null @@ -1,27 +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" - -extern int Android_OnPadDown(int padId, int keycode); -extern int Android_OnPadUp(int padId, int keycode); -extern int Android_OnJoy(int joyId, int axisnum, float value); - -/* vi: set ts=4 sw=4 expandtab: */ From b39dd8c4e3c9134fb5cf9af7b93aee4d6e02806e Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Mon, 1 Apr 2013 13:21:23 -0300 Subject: [PATCH 129/151] Backed out changeset: a500a9dbfb41 --- src/joystick/android/SDL_sysjoystick.c | 156 +++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/joystick/android/SDL_sysjoystick.c diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c new file mode 100644 index 000000000..2e2d98a02 --- /dev/null +++ b/src/joystick/android/SDL_sysjoystick.c @@ -0,0 +1,156 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 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" + +#ifdef SDL_JOYSTICK_ANDROID + +/* This is the system specific header for the SDL joystick API */ +#include /* For the definition of NULL */ + +#include "SDL_error.h" +#include "SDL_events.h" +#include "SDL_joystick.h" +#include "../SDL_sysjoystick.h" +#include "../SDL_joystick_c.h" +#include "../../core/android/SDL_android.h" + +static const char *accelerometerName = "Android accelerometer"; + +/* Function to scan the system for joysticks. + * This function should set SDL_numjoysticks to the number of available + * joysticks. Joystick 0 should be the system default joystick. + * It should return 0, or -1 on an unrecoverable fatal error. + */ +int +SDL_SYS_JoystickInit(void) +{ + return (1); +} + +int SDL_SYS_NumJoysticks() +{ + return 1; +} + +void SDL_SYS_JoystickDetect() +{ +} + +SDL_bool SDL_SYS_JoystickNeedsPolling() +{ + return SDL_FALSE; +} + +/* Function to get the device-dependent name of a joystick */ +const char * +SDL_SYS_JoystickNameForDeviceIndex(int device_index) +{ + return accelerometerName; +} + +/* Function to perform the mapping from device index to the instance id for this index */ +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) +{ + return device_index; +} + +/* Function to open a joystick for use. + The joystick to open is specified by the index field of the joystick. + This should fill the nbuttons and naxes fields of the joystick structure. + It returns 0, or -1 if there is an error. + */ +int +SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) +{ + if (device_index == 0) { + joystick->nbuttons = 0; + joystick->nhats = 0; + joystick->nballs = 0; + joystick->naxes = 3; + return 0; + } else { + SDL_SetError("No joystick available with that index"); + return (-1); + } +} + +/* Function to determine is this joystick is attached to the system right now */ +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) +{ + return SDL_TRUE; +} + +/* Function to update the state of a joystick - called as a device poll. + * This function shouldn't update the joystick structure directly, + * but instead should call SDL_PrivateJoystick*() to deliver events + * and update joystick device state. + */ +void +SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) +{ + int i; + Sint16 value; + float values[3]; + + if (Android_JNI_GetAccelerometerValues(values)) { + for ( i = 0; i < 3; i++ ) { + value = (Sint16)(values[i] * 32767.0f); + SDL_PrivateJoystickAxis(joystick, i, value); + } + } +} + +/* Function to close a joystick after use */ +void +SDL_SYS_JoystickClose(SDL_Joystick * joystick) +{ +} + +/* Function to perform any system-specific joystick related cleanup */ +void +SDL_SYS_JoystickQuit(void) +{ +} + +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) +{ + SDL_JoystickGUID guid; + // the GUID is just the first 16 chars of the name for now + const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) +{ + SDL_JoystickGUID guid; + // the GUID is just the first 16 chars of the name for now + const char *name = joystick->name; + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + +#endif /* SDL_JOYSTICK_ANDROID */ + +/* vi: set ts=4 sw=4 expandtab: */ From 888d367270a112e952d5689536266f98f4ffbd16 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 1 Apr 2013 23:15:21 -0700 Subject: [PATCH 130/151] Fixed bug 1782 - SDL_opengl.h header disabled on FreeBSD q66 The SDL_opengl.h header contains this: #ifdef __FreeBSD__ /* !!! FIXME: temp compiler warning fix... */ #define NO_SDL_GLEXT 1 #endif However, I can't seem to find what kind of compiler warning it was and it makes it unusable to use on FreeBSD. If I comment out these lines on my machine, everything works fine - I use FreeBSD 9-STABLE (x86_64, gcc and clang both, the same in a x86 chroot). All I could find is that this was causing an error on FreeBSD 8, but I can't test that on my machine (maybe if I set up some FreeBSD 8 chroot). I set up a 8.2 chroot and investigated the problem. Apparently this issue was fixed in Mesa 7.6 (and in Git, June 4 2009, but it didn't get into 7.5). By the time those lines were added, FreeBSD contained the libGL port version 7.4.4, which suffered from the issue, but on April 2012 the version was updated to 7.6, which is available for FreeBSD 8 and FreeBSD 9 alike, which means those three lines should be safe to remove (it'll work fine for everyone with sufficiently up to date ports). --- include/SDL_opengl.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/SDL_opengl.h b/include/SDL_opengl.h index 0e0394d2c..079ed74e1 100644 --- a/include/SDL_opengl.h +++ b/include/SDL_opengl.h @@ -44,10 +44,6 @@ #define NO_SDL_GLEXT 1 #endif -#ifdef __FreeBSD__ /* !!! FIXME: temp compiler warning fix... */ -#define NO_SDL_GLEXT 1 -#endif - #ifdef __glext_h_ /* Someone has already included glext.h */ #define NO_SDL_GLEXT From 3bdfec9df0e3b2fd2cd29a9059ccc61082098ea9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 2 Apr 2013 07:51:23 -0700 Subject: [PATCH 131/151] Fixed bug 1781 - SDL sets an error for the initial touch on Android. Philipp Wiesemann SDL sets an error to be queried with SDL_GetError() for the initial touch on Android. Android_OnTouch() in SDL_androidtouch.c uses SDL_GetTouch() to check if a touch device was already added. SDL_GetTouch() sets the error "Unknown touch device" for an out of range access because touch devices are added after initial touch. I think this error is confusing because it always happens by design. I attached a patch which removes the call to SDL_GetTouch() and only uses SDL_AddTouch() which does the check (if already added) again and does not set an error (if not added yet). --- src/video/android/SDL_androidtouch.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/video/android/SDL_androidtouch.c b/src/video/android/SDL_androidtouch.c index 4f4a8fdb2..c8d5ae6d5 100644 --- a/src/video/android/SDL_androidtouch.c +++ b/src/video/android/SDL_androidtouch.c @@ -63,10 +63,8 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio } touchDeviceId = (SDL_TouchID)touch_device_id_in; - if (!SDL_GetTouch(touchDeviceId)) { - if (SDL_AddTouch(touchDeviceId, "") < 0) { - SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); - } + if (SDL_AddTouch(touchDeviceId, "") < 0) { + SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } fingerId = (SDL_FingerID)pointer_finger_id_in; From 25cefc7ef67080be79957aa36df51d44139ebf0a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 2 Apr 2013 07:55:25 -0700 Subject: [PATCH 132/151] Fixed bug 1779 - SDL's Android project template has old default icons from Android. Philipp Wiesemann SDL's Android project template has old default icons from Android while iOS project template has custom icons with SDL's logo. There is a Wizard in the Android Developer Tools to create "Android Icon Sets". As an example I created icons from the iOS loading screen and attached them in a ZIP archive. They are named "ic_launcher.png" instead of "icon.png" because that is the new name used in Android projects. To use them the AndroidManifest.xml needs to be changed to have "@drawable/ic_launcher" instead of "@drawable/icon". I do not know why there was no icon created for ldpi. Maybe it is deprecated. --- android-project/AndroidManifest.xml | 2 +- .../res/drawable-hdpi/ic_launcher.png | Bin 0 -> 2683 bytes android-project/res/drawable-hdpi/icon.png | Bin 4147 -> 0 bytes android-project/res/drawable-ldpi/icon.png | Bin 1723 -> 0 bytes .../res/drawable-mdpi/ic_launcher.png | Bin 0 -> 1698 bytes android-project/res/drawable-mdpi/icon.png | Bin 2574 -> 0 bytes .../res/drawable-xhdpi/ic_launcher.png | Bin 0 -> 3872 bytes .../res/drawable-xxhdpi/ic_launcher.png | Bin 0 -> 6874 bytes 8 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 android-project/res/drawable-hdpi/ic_launcher.png delete mode 100644 android-project/res/drawable-hdpi/icon.png delete mode 100644 android-project/res/drawable-ldpi/icon.png create mode 100644 android-project/res/drawable-mdpi/ic_launcher.png delete mode 100644 android-project/res/drawable-mdpi/icon.png create mode 100644 android-project/res/drawable-xhdpi/ic_launcher.png create mode 100644 android-project/res/drawable-xxhdpi/ic_launcher.png diff --git a/android-project/AndroidManifest.xml b/android-project/AndroidManifest.xml index 7e6c43c34..ce7c056ae 100644 --- a/android-project/AndroidManifest.xml +++ b/android-project/AndroidManifest.xml @@ -18,7 +18,7 @@ An example Java class can be found in README.android --> diff --git a/android-project/res/drawable-hdpi/ic_launcher.png b/android-project/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..d50bdaae06ee5a8d3f39911f81715abd3bf7b24d GIT binary patch literal 2683 zcmV->3WW8EP)f5ia)v7o~R{NBhA5U9TS|y z#6;hys3;x?J}MJ`{(hg4#z_5C&8JGE%`?(Dh&7ZR;5Edpc?St%xW6qA@|?(P(S$9MfVM(#w*vFZ~ne7nXF-+jLy z3pO0UA{`?v-E_!bpo?j?Gb?HuKfY?*Y6jAmgpYBGQGoCzQqLE+m2$@j^psT86g0Dzxxz6?lr@v zAI>O+wDU;6_MNgvMsCp%K-&)W_v8M0`z(e*RJXOYci>rk5?WeXCkK$Nn;&K_*T<}t z2KZ+6UM${d1kW4cNJ`5^dR8Hx{G0@bD*;%$>!h$E?|^-0}z!=BRu5?hkP6@Ogv z4u+$90J*3OE&QwiAi**?dI2S+6$5};vE|@dY$Y+&O%nhl1@2!Gl2KRRpm{)AdPndd z0`#@Efv}=mcVnQ;(l{1*`G=#00IemfV=H1vEGa%o7aW(E27PifhQLW$2|q_UN6D*F%>lA;xrTo&-7&<9I2LiRp0{ovfjB1mq-N$10i;ct zje|BrT20xlvU+4dUIBLn2uT+9o&pfNrOw`d_hiU5bqx~+R7p3<_>40mA4ZR8MdJcg zN9k3vBE?uFWi%=6FVs1Rb51_!qWXgYE#G21nAtdZD+3fv^^qcs!{*LtYHl6ko(#FB zcH)2}Hwy>~K^3Kc&DB9<-lpfT2tYGOfyAlbiLw*}QcV9`Cn*EuAM$Vz1k2d+q5#CD z1!qQ)9mz^H1*oB+0Y29Qkdm6N`AWLFwq8`jW_DLamg0Cchaj=5ac#tqxOl9pt`{{D zTb|ZtV`z~zRVV?(>0biDvUc$$KrO=R*frS#8F00R0A2J9#BmFIM8`ax{JmJo>k6^$ zkRY)oF{t0DMq0G-pn%1ew3Jj)RXc2aJ5{*4hGzr>NgVte36NBsvjs9_O#tG!vx?@_ z*?kNV527XxsIjR9C(mCNE~Bh*`kqaJd(MEnF(?k$42p|NwxmULd>;^Btdqx00fHg0 z*n;XCngt-XI(AWpvqbkWsz)dj#?#WXa^QIB3hq&$o-iOzt$+S@qgc2*kAC-4(6ylZ{WpdHEg7&r z76Yy#7wsdcBWWz{PDCVZom>&0_(C&){xn+$f1S4pfB#MoUoF`#Dqdcksja&x@@8<* z9!UQjxLv)1#a?ReTEjt?V^9o^EsC?9WLfNjk{ceix`dvd-a*S;DU?;xa4w*pm=dCUbG||3d|jyT|-=ZzCz!A82iOMJRi@? z*2-4P)~gO6Bf2(T$NF8yaP#oiOdZ5`^rzrRQJ*lNzs=Jd28qQ%`1-8}gH<&Hnz=$> zSd>%_NF@PlAuV`=fho>8`ywr?V0bESY#9vv(imwDX-+ORX3|ZWp|w+NZB#Y?kVwo~ ztq(&JGo)u`YyN>*BW*_G5>mwjEUtcePZs_#j^ar%dVBkZJ%=f;sClQ#cj92nR;KDX z&Kv40Npbv;c`2@OZ0qYAJr1=|?6h@pqx5bKuj~FF|B-8NZ!bK53dY^Y7$m1=B0IN` z?piLT))-`D<eGMlqZD8Z*BCPwP1LACT^t3Hb zSUBLcwKMFTufpoWCG0(94r4mc53uYndf~LC1Kh6OfU)TXy2Dq+IX6##m|Hp0f*fIB zWClAY51Q)&-TB+1ue(nmtbV)<6Pm~9_&FNmDJ*WJrbD4&#ONnaCSdFrle(wV<(;G0Lec~;&WXDm0eFd*VFUvcLv@+SFhOX@$VT~`C^!f@uJqTv3Ewmtx&YLx2rW?eW>h6iOjLeVwUW_kFyo2iQ{wPrD>YIcsX6NSPW^gDjIQGIS#NHx3;!Y4bwd7VEFr<#61_=Am1B-@bL?Pf8cFAPx=jQYP!=$i$M*IO;j^A z(Xo+$wJCknI#x^d35=k$o-H7R-+O?dkTCcK1moxUM7%C7R~oFR^sDF2&Q824eS_-i z8dO$Rp|YwPk7++tU*ACWNQAD9BT%MP7UMMCL9wBUs`6^8Nh%0hX=xeKsdy|XdWnLG$1hoqF4ULrYyC&Ur^73*_XQ>2KTwII~rIL~omHLp^!%_(-FE0<%Stac7NPn23 p`a;b$d_J(|Pvw8BB{$8s{{bZLi_t)ny#xRN002ovPDHLkV1mMH1%3bk literal 0 HcmV?d00001 diff --git a/android-project/res/drawable-hdpi/icon.png b/android-project/res/drawable-hdpi/icon.png deleted file mode 100644 index 8074c4c571b8cd19e27f4ee5545df367420686d7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4147 zcmV-35X|q1P)OwvMs$Q8_8nISM!^>PxsujeDCl4&hPxrxkp%Qc^^|l zp6LqAcf3zf1H4aA1Gv-O6ha)ktct9Y+VA@N^9i;p0H%6v>ZJZYQ`zEa396z-gi{r_ zDz)D=vgRv62GCVeRjK{15j7V@v6|2nafFX6W7z2j1_T0a zLyT3pGTubf1lB5)32>bl0*BflrA!$|_(WD2)iJIfV}37=ZKAC zSe3boYtQ=;o0i>)RtBvsI#iT{0!oF1VFeW`jDjF2Q4aE?{pGCAd>o8Kg#neIh*AMY zLl{;F!vLiem7s*x0<9FKAd6LoPz3~G32P+F+cuGOJ5gcC@pU_?C2fmix7g2)SUaQO$NS07~H)#fn!Q<}KQWtX}wW`g2>cMld+`7Rxgq zChaey66SG560JhO66zA!;sK1cWa2AG$9k~VQY??6bOmJsw9@3uL*z;WWa7(Nm{^TA zilc?y#N9O3LcTo2c)6d}SQl-v-pE4^#wb=s(RxaE28f3FQW(yp$ulG9{KcQ7r>7mQ zE!HYxUYex~*7IinL+l*>HR*UaD;HkQhkL(5I@UwN%Wz504M^d!ylo>ANvKPF_TvA< zkugG5;F6x}$s~J8cnev->_(Ic7%lGQgUi3n#XVo36lUpcS9s z)ympRr7}@|6WF)Ae;D{owN1;aZSR50al9h~?-WhbtKK%bDd zhML131oi1Bu1&Qb$Cp199LJ#;j5d|FhW8_i4KO1OI>}J^p2DfreMSVGY9aFlr&90t zyI2FvxQiKMFviSQeP$Ixh#70qj5O%I+O_I2t2XHWqmh2!1~tHpN3kA4n=1iHj?`@c<~3q^X6_Q$AqTDjBU`|!y<&lkqL|m5tG(b z8a!z&j^m(|;?SW(l*?tZ*{m2H9d&3jqBtXh>O-5e4Qp-W*a5=2NL&Oi62BUM)>zE3 zbSHb>aU3d@3cGggA`C-PsT9^)oy}%dHCaO~nwOrm5E54=aDg(&HR4S23Oa#-a^=}w%g?ZP-1iq8PSjE8jYaGZu z$I)?YN8he?F9>)2d$G6a*zm0XB*Rf&gZAjq(8l@CUDSY1tB#!i> zW$VfG%#SYSiZ};)>pHA`qlfDTEYQEwN6>NNEp+uxuqx({Fgr zjI@!4xRc?vk^9+~eU|mzH__dCDI=xb{Cd}4bELS9xRaS!*FXMwtMR-RR%SLMh0Cjl zencr8#Su<4(%}$yGVBU-HX{18v=yPH*+%^Vtknc>2A;%-~DrYFx^3XfuVgvZ{#1tA== zm3>IzAM2{3Iv_d1XG{P6^tN3|PkJMnjs&CWN7%7_CmjoVakUhsa&dMv==2~^ri?&x zVdv*rnfVyM+I1^Kg*S=23mR@+0T9BWFZUu~@toA8d)fw6be=`Yb6DSX6D?jB%2YT~ z*aHjtIOozfMhA!Jd*?u5_n!SnX>vX`=Ti-1HA4RiE>eI3vTn zz+>Ccf0HX6Ans-ebOB>RJST-Cyr#4XAk+mAlJgdQnoE{^iIN)OcYFSpgJUmXtl@tT z-^ZuUeSj5hSFrQwqX>~EtZ*{>Gi8Bu9_|o06oNtaXP?E936!a@DsvS*tsB@fa6kEA z5GkjwmH?EgpiG&itsB_Tb1NxtFnvxh_s@9KYX1Sttf?AlI~)z zT=6Y7ulx=}<8Scr_UqU-_z)5gPo%050PsbM*ZLno;_-ow&k?FZJtYmb2hPA$LkP)8 z=^d0Q6PImh6Y|QT?{grxj)S=uBKvY2EQUbm@ns9^yKiP~$DcD)c$5Em`zDSScH%iH zVov&m=cMo`1tYwA=!a}vb_ef_{)Q2?FUqn>BR$6phXQRv^1%=YfyE-F$AR4Q?9D!f zCzB^^#td~4u&l~l#rp2QLfe3+_ub9@+|x+m;=2(sQ`s%gO|j$XBb>A7Q(UydipiMw%igcweV#Cr~SP);q>w`bxts_4} znKHg?X==JDkQl3Y>Ckt%`s{n?Nq-1Fw5~%Mq$CAsi-`yu_bKm zxs#QdE7&vgJD%M84f4SNzSDv)S|V?|$!d5a#lhT5>>YWE4NGqa9-fbmV$=)@k&32kdEYetna>=j@0>V8+wRsL;po!3ivVwh<9tn z2S<1u9DAAQ>x1Sn=fk`)At|quvleV($B|#Kap_lB-F^*yV=wZ{9baUu(uXfokr95^ zA*!*W=5a>$2Ps`-F^+qRQT^{*cN>vipT*4!r#p%{(#I7s z0NN94*q?ib$KJjfDI_sjHNdmEVp5wB&j54O#VoFqBwy)gfA$%)4d_X4q${L9Xom2R3xy&ZBSNgt4a1d7K^CDWa9r zVb-_52m}Vp)`9;ZSKd#|U4ZYj5}Gp49{4utST|=c`~(#>KHF6}CCov1iHYw zt{bWo)A@yF2$~c(nR$rSAaFQ$(Wh{vkG1AlutDMw=mM`C`T=X&|Ad9fb5Od}ROt1z zOpczHqrb4Jo^rSCiW#&o(m7jFamnrsTpQb;*h4o8r#$aZ}2RaT-x2u^^ z%u@YyIv$U^u~@9(XGbSwU@fk6SikH>j+D1jQrYTKGJpW%vUT{!d}7THI5&Sa?~MKy zS0-mvMl+BOcroEJ@hN!2H_?coTEJ5Q<;Nd?yx;eIj4{$$E2?YUO|NtNPJ-PdDf;s} zab;}Mz0kbOI}5*w@3gROcnl#5)wQnEhDBfn!Xhy`u>C}*E~vWpO^HS)FC>8^umI=+ z&H;LW6w#;EF`}vQd_9Muru`KnQVPI9U?(sD)&Dg-0j3#(!fNKVZ_GoYH{la~d*1Yh$TI-TL>mI4vpNb@sU2=IZ8vL%AXUx0 zz{K0|nK(yizLHaeW#ZhRfQXoK^}1$=$#1{Yn002ovPDHLkV1n#w+^+xt diff --git a/android-project/res/drawable-ldpi/icon.png b/android-project/res/drawable-ldpi/icon.png deleted file mode 100644 index 1095584ec21f71cd0afc9e0993aa2209671b590c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1723 zcmV;s21NOZP)AReP91Tc8>~sHP8V>Ys(CF=aT`Sk=;|pS}XrJPb~T1dys{sdO&0YpQBSz*~us zcN*3-J_EnE1cxrXiq*F~jZje~rkAe3vf3>;eR)3?Ox=jK*jEU7Do|T`2NqP{56w(* zBAf)rvPB_7rsfeKd0^!CaR%BHUC$tsP9m8a!i@4&TxxzagzsYHJvblx4rRUu#0Jlz zclZJwdC}7S3BvwaIMTiwb!98zRf|zoya>NudJkDGgEYs=q*HmC)>GExofw=92}s;l z_YgKLUT5`<1RBwq{f)K~I%M=gRE6d)b5BP`8{u9x0-wsG%H)w^ zRU7n9FwtlfsZSjiSB(k8~Y5+O>dyoSI477Ly?|FR?m))C!ci%BtY!2Sst8Uri#|SFX&)8{_Ou2 z9r5p3Vz9_GY#%D>%huqp_>U}K45YGy__TE!HZA@bMxX~@{;>cGYRgH~Ih*vd7EgV7h6Pg$#$lH+5=^lj{W80p{{l+;{7_t5cv3xVUy zl_BY4ht1JH*EEeRS{VwTC(QFIVu8zF&P8O$gJsMgsSO35SVvBrX`Vah$Yz2-5T>-`4DJNH;N zlSSY8-mfty+|1~*;BtTwLz_w5 z+lRv)J28~G%ouyvca(@|{2->WsPii&79&nju7ITE6hMX4AQc{|KqZN#)aAvemg3IZ zCr}Y+!r}JU&^>U1C2WyZC<=47itSYQ`?$5{VH?mtFMFFExfYTsfqK%*WzH@Onc#i` zI@a|rm-WbKk{5my{mF}H>Duc$bit&yLAgFfqo2vVbm~?FeG#0F?dSP*kxSo0Ff!o@ z(C}B;r&6pa-NY4;y~5lX8g&*MYQ>yLGd^tDWC4(sGy$Ow-*!eh%xt;>ve|J1q$*w< zh;B#cz!6l2=5bkX#nJ9PJQ`ew8t>7z$bxqf*QB=l2_UB$hK|1EIfloN-jQ=qcwChF zYAkkyp=;FwcnUB3v0=*tMYMA(Hdyf} zu>|cMov+-ZzrP>60ufVbMfI5GD8S3sHU={Wz|3(0Iuu=S@d?FG>uvDs20IvRa=`Mf zj#y>tjJ0O2%(P!fEH>}&wob%R&H}5 zCGc-u(!|no5r`_`6U@PeT^`tAbpUc=l=XIx5}}*~W|%4>j>`bH?(t?i92~9nn5b`P z0>7Y$mEeQ`zFlE~MQf~ZG9n(urD7;YrS#B=Xsowzhmqy}5da!J%3kbpKFSQ6?LES3 zdZV=$HtqI=cTl8G16xp14uP;#cL2|TbNJ?WbCv}PLC1o@ra$3vG#sKQRjdsy89E-; znY%&Wrg-Hc0ikisFjZMa4gT2a!LsFbJVGacax#gWk55EjU*EU@vs5pnGl{G3Su9*> z!N$T5Ypq5G^s>zk;1`v_^H>BcvDMq12|&jy4-O2w$V^iek#aL6kcJj+tOIn78@KP` zS-n&hVAi+*!y%P5Bk6V~t9LpJEg6Dv^9^HW=&|J{j%XbP;NW?ZWriBBlQv?_b{7Wf z?jNR;`Laq0%pJT@Bot{6Kx_D6R>6O6CaG({;-O4fxdg!7FN{sE1|%b@0J(*wY`Ud# zI&>PHo!wYrvX5kIA6$-v>I9%5)46v*2=WER+5@z;cjB`jH^as)5b4Y=@KwIY|49kMQ$Jq^Dh2W~kwk@+x$8bu&m>dOMx`k@;AF zOr8K4IfY0k8eSOHMN@M#{DV%Rsz#yu)%WM&qwuw)N1vUEpCDpjN&f6V0!P?RG^g3&|W3X}!VA~OOk&(lPv85w2vT{aGqiO+W zYf57uSx8hDv*9QfJwZunB_z+Jkkm>cDyt-0fLi3{6{B7%LtVWLLei#2QU@6+!TiD! zl#~5aZJiXd#%46Pyg>bP8Oyk8^pf6|Hpt);7>u(~G3pkw+3Eo1=sLZnrDub4ArZ+b z_Yo2ni^%f{c*H9}V)8v)O}c|CM3)n8BIWKwa4ud)++{A##l(Y`E5KFmU4(Pu+2747 z*`g5=8ISd54mcALP0FuJ-Bx1G8vz)-chNQaRj#2MI5{az9zPF9gF_IX$VE?2kEYGs z!~iB@Qrq`{%xpdkcQ_(EDwdRD`FQUG69b?RqFdY^GAOBDH)`vilR+PWYe_e7@oFLp zi%XzX_GHnL8)uWgCx#|Gs=@G!ZNq|X!w*jD3DxnY32q2fsp%2msAeBm? z57GqikytE-K8Si%3m_B sCR#xB$vdJ2L!RajdHnFb`QMJe0XP&@60ho4VgLXD07*qoM6N<$f_SqK!TQ`Og{P|8RRXpj5bgrSmEzSMfBn+{{vpNxw?;5UX;iv9sYxy_`IQHs$i<61a_iv^L>h8s-`D(`e@|IgS*Fj zNGM876Gf;3D8*1UX9a%v>yJKD*QkCwW2AirU(L{qNA)JghmGItc;(H<$!ABY&gBy1vJIEUj-b8%el*o|VkG)LqNx#TG>Jvj^jIte!!+RY z)T4j$7+PoF1AkRBf}R#^T=-q|PaK1$c<4UH)Hpq3$4WA|xtr!ZQLC=*vNE>O6E9kp+5X0eKB$6>C(lPwI@3#oY zhS_%x7e|j!$yG?ECXmh~EH~^OeuK}+sWoJse3Z3?ha3n`MM9KvA?uqpEnBg4Q46)7 zM$p%a$@l;+O}vfvx%XjH`}a{(-HHth9!JaUwV0*VqGR48^gWNYN<&~7x)y$e!X>e` zZ5!6KZoxbKuV9XUDI%#M1~IVh?pNSdeb~6@$y`v|yk=XK+fHxnDqnUK4&=QRNyIVf zYbDM*cI>~qIy*a7=z7uqkw@agd(<=y-Q7L!ty_23SGdXmahO<;N=wB+j;lNm%=OHC zy zU|>La6h%92y4IPufI$9>Xu!@y`TaNgtg&41@PwMwBdmSm7)xAWDLoqjZ==P2#*k7! z3o1)cVSI3KP_!?d8G^Lg0FtLXC~JYdxi|c%h~lXEixY=%VSFF@!*3&&9>(Rb|iK54Cx5;s~PY5iaV1het%w`dgQFBAJ;aFK zImQC}(|QaCFYUm1JVfzSc)ebv=)ObI)0jwJb``}Zj9J0n0Xgn*Zc(rFM9$xh_makZbm-at_v5^SW zM1y1SW@%+FuIy*WR)i3A2N_q;(YO`O!A|Ts^%z}9ZepCj3ytlw#x%N_fNrKKtPh`< z|1{UqF`4LxHaCQ79+E=uUXCOZ35jAMRz%R%0(P!0FMv=sk>Nr8%+OzY^c-M9@+fz=G`qa@v4sF5u-2289-#$**LWnyNNDwDf1( zkUiMnw|y$tn>pQP=Vn!#|17L^5AGrjtBkN$D@v)Z7LXc5EFhLB4<;7Wehh)CMqX|W zqsiZaO^benJ_hwa&V0ub$-_HUk**?g6fm9|!@kguU6*zhK)$qn-<3*kFrYPIaqR=V zUaUvk>@F_89b@tHs8R!*QKY;INJ<2_U+K6Ca3e9Gsl2{qY0%a7J?uICWgHuLfj+MB z=GkAN1&ifT#2u}B+2S#~$5jA(Qn^;H%CCmIae4AE-Dsng|Hl*Ov!z72k3ZnJs{pp| z+pW`DDueC#mEWOf=ucJ!dTL}hzOeiS-i?m2E;`EKz4<&Lu~NnW?peqVU^@<+T3KKu z{yrI%Qy-Z%HEvLUz}n^~m?7x`xuCtNR#L2En!T>dQtIKdS#V-Hzt3RtwTeYtmQ&dR z6qXZvac*oc@BUYEH%@Ylv_1&tSjkbzzU6*h1(3^C`;1z;g_SmOtclS?KWk2VYE zM*oS<=C483XckW?GN|1jfh3Ro(hDu9RL8!nQ!g@05e%% zOT#K?b}Prj3S-OHm$ooGQ+0x!`C3qaj7A3_T z8XB}T5*8fh493CSC339iT;-!bU_>Y&8E%UgHly- z5ERej|4ObiE;(84*Y-9`SU-VaN;)RrO)iOV5hhyg4*XLUbS1$t>Qs= zZ$-6GNXg6al(UhMk)sG1QbtAw{R){3vv77Mq6sOtLz|c8xH&iy8>;Hse)x*15`G4% z9zQ#ln++S(t{dkCy1#F*0yF?f9r$0P6n^^q1{i#QwIEHXJxw^GyDML}VG1t%Em@;qPEAUkT@@#v2<-IwV2 z)IC1;xbV+Yd)Q|BFRc(G?gqzcx!f>h%KJC_F&Y625pm0-lIN6Mc7ttzFK4cLVV={H z+p`l_Wh6`57^Vd6at+DP_Ci>}NLfOVvf86+{(al9cTn5yC7ll%I*PLatUo>F`)anC zT~FLgZ^gRe4;gG^Go|Vux=t{^tR%uYUK-KYrgR*zG$u|SF(*xpci_DbO#%e9IZlzXOCyG1~judS7eiqs=c!# zLzpB_jeSDWV0JB!?-8M)Tb%ox?f|J=cp5c)CXkYAzGLKBx>Nrmc7l~O<}1@%x^_#9 zji$h#%}jFJ7z{k^3mbCN$&>dMB%VE{R-^cdsyzWpq36lena%SU-Z}8TZT8aGFG6tS ziClpOAT4%_=!1ZXKzXhrX*7}5ljC&ezU62I5dimYo)VDDph{KvN{`7jgd7cxrgN+rh1O*%)6xsafex=5HJw$NlZqyEKl%E-$%a79w zm+R>ik`b$>t;gO2`+QJK9P?=?wZSR`A+OPDTL4CS%v9TPdN&c?^H>J9_a{cdDX^8750Kkox~>foJA$yg5cTM zKPUzaS`9eLtHsn}4N)NV;-fk$i75pgYlTXHZ^a&UO>0KK{Dz*m(Z#=w!x^=09$O42O* zoO!)Ml=vq{uqMo33d&j%ZBlT*3j3Ywg*p)M?)9HbpQD4mg-M$(YM%$32@zp6>%7oH zN0F*HJ&a>Hq{-g=%!rzO7%;Oa{icV+B0!B}(?y4<;wmRHUHaQpWpTIl_Kc5vj0B0z zbBlS_5XkFs3#`ALu zP=V04T6?YPmi|W*>n%5{D)?zw-#9Il=(D!kHS)jV!%_FUDmcm4h{-Dnz5~p7_=j$s zS-W}(KN^ue&}+<3Zb!>vFxH6#3oXN()QPp$pf|+XGUq}F$JJQ%z+i9h0w#n+tcc=^ z{lqsKa!iPo1FFE$bgc)Ej7L_1n~C};vTG9D#^(vX1GKWr-T6R-hjBoH)Xby%o_=D+ z-R1@sG5i>QGZj`CcnzukQd@#ICJvwaZR%~wFD9hAx(+p~0B4mFcK-XxkQ8HkMum?~ zk(goaOZL=?2Nd4)}_X!x6dLf@x;5M8puoBR(2ry3vFI5TO>ProDzr)Va z>5tR^SZ8!w+#Yh5d0il(ZWSmWt-&#z8VsWE(3+lJQ@$bi97C+I=C}Q#Iw^z~5Cb@R z``4l%US^SWbY{UDN;a=*5iv;$CIwgJ1rVj_uZeSJ#XRTGt-VHZM>D0w1S~pqEqS?TLCqsoV@yVZzLaP6wS=jHX1`Rh64# zU4McqvwdmQgL$+>^j7T2oy%aR!p}~OAye$wH+LiZGo?_5oivNb+tA*eu?#-H3J~l>Ip64`tex@1dL_O-Ca55$%--OpKT#rkHnPzm#h<}2m(jc{#Rp0vs$G2`H8e540jvCix#pUjbaZ;r?1&F{8826qCEJL zLLEG+|Ifx%J++edXB0YZlF=IHrIPm2uz^~$Zir}PzOvrgDIN1S-PCo8W5s?de#Cht zp((q99npFj-cWEqX`98~jj&YAkd%-$eT;nOl>dpEHM^UMQ~+h)Vo5vC=0U+m1ZTX$lP>mYJrmlW1Y2W)UTP2Ci&oWs$scAYc=6 z2H6c(`lMBJLYSy!YBjcap~P(847q)cE56)b09R%z@~5tjK8(Md7v5lQ z5jl@cHLtQS-|Spa5-%csdHj=&f3x;J(|+-h1B_5YYvvR}PhaWif^)yYJXf$NoBOVy zSB{)E-S`vrm)NrpmVCKx7f+5M5y?J_SaxN~7wXrQ8v$K0Z>zDs2gq1&)_Gn%Tb2mV z=~v7l%8#ZSPqABq)&AS&n|D{DPfNM%=0bdU&ZP4)m*!pE|Fj2yOV7McXudbCPMjdP zxxH)f^@H;XPR+NJ!=G9YcjGe;i;Bw|IWwxR@6Xsem?u57t_{_3uxl1+`-u4!C+TQx zL{f!0*r+8KdhfQ`R`WW4yG&1U>h}n9XWq{oHyX$Ov{kTE9+XV!PSlT(YA{FLR_e0M z^fb---0R=93`Z{l`*k+85J96sMjfH z%XKYp-oC+K+w2+5*#&jpI|*P-b_CVCrwA=R{MohJz%4L;->!P`EwX5t9Bv&p4>Gei z2+pEARQ|wOzqq;;d(x}o^L;ixM(EKhZG2EWeo4DGItZ8;v}(3=oa%dUcP%79bq!S( zK~v#9CEAANA=?M-?yAslk9kl$97C@?`aRy4`JGj3u!luR?Fr{_*d^0R*B@Q>SD~k6 zSK9W?DI_aVPmiZ-Gli@aS{hN2JBijdjcWoQB!i#(0~*g>G`@ZPOO-jMlLOwDb^~>0 zn%%pqx(`!SN~CQR|ki}V~K&D z^479oM|f2fTvvHJTq0CasrEV8=|c4UCs&KLE&(I485j^y)LPBa43CdO0h=DoCGZtV0$X0o!9cW9D{gc7fhU&UF9 zFK%?Ph9LkEfB~RF0J4+26|z}G5MB~6l13E#rdssqd_si)M0#nc3Tt^F7y2FmPUL#Y zgWpVxWK~sF*3p9g(tDt_^>rlrvP25;2v=VZ(~G#4vrbc3Ue2g_nl=J(FwsUI+{go2 z+1kSNB1U=D;qbfvKQI`Kx?aR%r7&Y|po)`|Q$sIeloOb!Y;(=-Jct)kjD0RM=85i{{eUbTP^?q literal 0 HcmV?d00001 diff --git a/android-project/res/drawable-xxhdpi/ic_launcher.png b/android-project/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..d423dac2624cf0b5dc90821a15362bc29e5a1e6b GIT binary patch literal 6874 zcmZXZXE59i*N6YRdSAVlAWEWyD64Ox6TNpqv_y+;l?@@QEux0#J%Zp?cS*5Gh!R=7 zghjMyu`AKvdEV#C{mwgcotf*)Idi_9ncqn^HP)r0=As4wfKFde%NziJ%>NW6IRF5g zI`}RC;40VGx@Q?NzgO&IX{nz#gnnF83s)yb7Y0Y=F?|2N^j&S~JKQGMNvhp$x}rL7 zqwm08DyJ(UB}Ia|LNFBx7AzB^r0hZOf5KrO-1q2%?;|1-nyA@yNtGCMDu*eop z?Ap9A@l@wK5_Gv(PKOKOdoMmRROx4n7!}I-O#UBf?354@`3ZA%6_BV#AQ1ip@VgJoY(SgM<1EHs z^zH40ZSC7G*04PjRZ>zCxOI#A?benzf#6&kb#}gM&?%J?bzHE-JO1*=Ou_NPt?Mp7 zIBN-kKq!0uob(+NGjqFnhxo!&DLT7cmaymU8#$P>R1{U*!vQybpf)p@^U-hd_Tl=* z23c)&^}TPow{4!|4yMcx8qPJ&PGmeC!XI(Nc{I<7mNoU)UQc)*oHi}_-QB?Kb`c&s3yX?Uyj@&$6gvpjxP5SH75?5P%YSYuw;=#-a$aP(lpF9sjV?wbxL7k3 z&9Q)5{OL(TIZ0lnkN7vju*rYHB;fNes50gL1*u-)zW@t^UIO~r|Kk6TCHc^IzORCb zI4UO9o8P@hAo!@1sKG@*FHd%+m#=6u_~h44k2gt31p1zG@hb>*ma#Afi67FZVd8|jh+!)O;mtFwf&JSWD4kF`qloEm==5{^0F9j7?>{kO%YPgYt;Z=XbC&{rg=jv0 zluHUjpL0rvh(!Mov)|ztVeYho3rY3jR&c4&)K=zh$@sfl%ub0i#0M6QC z2FW?n;d+wdSKz+;yt`wp06ochY~Ag8yVBWC7A&w@|x`*(ZE! zn{kutMHRQvkHO;)>rPw5&hPn=434(-S7~!6)v!qs-a(U+f0%hE)&r$f1%A4i;}p z|M18KE+>R%43;#b@sCy?E}uUIB|%irfU^kvQ;?Yr;t81+?L^(HhIUAcuAAu_K3pis z8(%@^cD_DPBnL&!JZa5+%{1od7r=(edcPkXDi9)_(GplLxVzFh!qy`1iB3x*$nCb2`WFHL#g zAqdQ|1dQV1TULLyGr=__#p3W##Xu&TqOT;Nmab;XS&v-+l{zT>Ze}+TCt&2B301KF z)a+1~MVC-TgX7W-@LQ~=nFxuuphJNf`sZzc`Zg?gcjV_UXmRr^MQ~X`8~f4B_)kj2 zbN0#YLGlc{H1Sm4%v=laL&Kn*kxZ<)-SHRJHbrv`q`!i!t_I{zc`M0?UyFHL{_HE6 zV=e8Wy}!(4+i{S%5QRSb-5>!8Ys4^JBhBO=*NSoVXIVdX={W?F%-MO^;Jx~mFYuFn zB*@0{7OEyVz2FAkDg@&e?rDa2BDQwM4I-Ru1{1^F7gwV3>GD^T?B9dmAt#T_){{Bd zE{ z7#EY9-RWcKJ|%0Gv-U7U=$PkM0#)NQbLf3|HS$B}&O+Y2c&9oLU$3Px0My~VK$fD)}$lhu)qfB2@I0a{3S?tiu=g;`QO z1|b{Y{bd^y7GAwb91*Gh!$#(fOPl&Tf}C55Dld0`&qx;}S&QtcnYQ6ObVEQj*N$$) zK+=oR^xb5GBv_*D_R8E;(H64SI^xO*gk0m1myzP?~m_4m6=C18A}Bq}vzt>0Uio32(rrp;x~=po8sX`H~5;1>9vV`{eKl zmmW$K^EI-^n9*9jv$CE_@i$=Sp;()4esmLgHiYnnP>Lf!y? z4|*|PJMW8b@$b#_jnWJcDRg;X(8sjuk_2_8r_V>$i)4&x zcuQvAH=jqS2jLaDKLWxuU~`&le}JkV= z?-Urjlmku&(;J4ATe3d}>m?sUxmCCr6Dx-*O`XkrVt}JUCx-VzpPb(GW|n{RaTnk+ zZf?s{N%1$NgNzr;z|K7Pbw?c^$-+iQGX|9Th!HQF!sqrwZD}BIWqG+24v8k+Rmoj2 zQc~!c>wdowgpDtG#AdRQL4d5H3u_3Df1g%x6WFQ0&Hcu!!#RAgWOJNP-FF($S{g-u zk=`7^L0bOarT8flS*9zQMrd}7mS5u@1-h+ByJ2Ig?2?YgD|OSgK{HOp5i)tOMt zGDm909Vb+*?efcF6aciaSlWzo);zLFf)%w|JSbu*4dWO>_## zWV&HGUbzc7P?&t{q8&#I$qR6P&#k|K$Cb{=-G%+i%^_;~B5g63gGS$hp3qwJ2u?C; zrx^KgUSn)6GUoRFl(+6DR&QGa+QHBk1w=%F@M<*IqT1z3oEYiVy&H8Hn@5*GeL|PW zj>zxS5eR1-pMx40s~;D>4wg~CF>5Ur$G{c>EK?!UHnojBZBtpbb1* zsw5FG82S1gjAc&%rwO)@=3|LsT~?k}fTZ1K(vLV*-neQ~uMt%5Z1^3$5T86?i$5yh z(}9YmX*eW84y8KeyPDpUu%&tSI(oZMuUn(!o#Vk%Tebjn>~WrcXiM&t>DtV~T5mYOd1^*uSk@Q(7*E60X%>Ctb(H-RiSzXLUYjIDy_8^$VB+Lbpq) zgq=m+j5CYNF!r-B76}6QZh3OOKTY)H$(^sjrapEXBia|_|2#a8-COY-=%x63U!H!z z9520pzgvBp6yh+E1#Qu}%uY63?HS=NIlstqv3h{dvr=V8^`ml z7;{{`B?tl+A{P3}>-CFD4iQz?0Q@YX_95=hR!X^^5xVJ;pBzbH#OjK}OA(mgq_%^w zY~dn|@aT({1-M37Few{6@MT7E zq7H%GeF{DFMEq^@&#OUT7w-DAtoWSYRgIiS4P`87k$(=dJ|jlU*pJnB`yV!%(EDGx zZNb>f^7|<}=KrP+xW;IKVx2$wwZwk5B<498k0VBmO}e5Y+|H#;cqpm&j!=#xppXWh zYa^%GfFz^o`vf#Y4Rruv;h}}raPP;^_gy3j0hg;RMeG>S8qXEe2uwi&-X~*Ur{Of$ z!cXQ%AD}BAH^{4D5MI4eGoO-%)NNFf!ha~*t)TCjGDn!o1)o~W+;4nLn;FINY{Xr> zrGR7obzf^+s)KkH$ViBI#Um~5bVxx^BO$oQie0G_k7BB(pvAYy?Z9Ev#y}gNnx$In_qF?d6RS+>{Lyr=1;U}CRV&Gt`aptIUb*ULm720ohx_;&`V%(gX^x%(e z6^%N1ewdw-w(Y^MR5~g3*>`>_9sYk1YpCMcUpuJQ-_*O{t@q2kqJZ0fZpB&u&|OlP zs(bS@udsZg=9vKgZQ6n2+N`cjA3EWn+lFFx>6r(mNDS<#V@_c~Oy|wMNbDQ7niNiQg*?WNje~1 zCw|S9z&~G|^Oz}vLH}q#Q|8@XdXxBP{D`?j)}WyLF#CI$qnw+_as{AP0eyBr1K&K3 z{LA{t{j5jULcooVvyB7A2lDngz4~oPj%>CLt*N0g4|mq5V+q*o@=$x^F=!lj2R3{s z-v8AZCS3}uX|*DD7#Kdvj_L;RM7;!^(V>7Yn=%^s?Cj~g;E+UgzBFHFhdn!N*pWT_ zu5Ja>05~LREkEa#jNTxOAUetadE;r|lY^ZXMLFc$!^;sh*8!ztA60}llN<6(as)#c z39^(f!owSX7Lh!TCU%(QvZH~PS>eS#xCv?DpuOE`4DD+Bl8fZD0gvWQGFoj%=}@)q zWyiSb1(&Y_Kh#Tw@E>>PqwX5HgnZ~11=c(*R2AcHPD7vcpGg|)jbl7RIN8YbX6zSA z1lOWK7x9%XPuprEC~;lgyGP<=b)_NX&C#Mmv<9Po3VUpShL88;{Y*+uY!x&_?<7nf zJusMZd1ESOXofQA)?Rn=PcG|1_0*zfqN8jVvcrOCojscCMvg+J>}nr0S`z!37)x*W zk)8XXBTM26a-tY_DGP`W#amOa{-HYu#~X3o+Ok0O9h3_UT14!WZ3HzyG@gzX$O!t> z*xd`FdbSqdUR3;ibJd1|U2)i%zrYe@1@iDm7v?5t>Q)BrM{|vdILUVLOP^$@O@)44 zyGpRfPITZ5IqMo9e>kf9zH}9r&bVaY?|cJqQoHiN%{PCKHP=c^Orm8rvfC+)-J#<^ z81Xuh!YyK287inULnu-nC7Z~2OUHNOR+{002(GsY{Dl?Q8n`J4RV6QpeZd$h3(Au5 z3Y5L#!CY!GhKrD$pwN);6V+%ER0@1ATiSUbsgcj^niqY^s3V{=ASx)LPPHnE4>}Aa z^=DiB#CLXnCaKc$X^gCV$UW!|6wD~&wc4&h`iMpGlq^w5W<%CbC4qJK^}7WXO5HlX z*k`MhHL{T`7sAha@`rsYrHZeAX#9m%7?-d@N~_j_VtVPH<9&b91*QG=Phy~zOzyUe zaCob}Lgr??58pcP`G8W*B(LyuV6g&Hfjahvc%svb{!qugBC?o-S+;`C@`A(UX@mFsNF2=h>ITc#pF)X1p)nn% z;3PH02y6fQj-&CnM%k}Ut$Zct4E;&4xouWN<3jJidF05ith`v>Fx;#^U#y!7TtPHS zql62UvHHOEK?zZktts#W&#g`4$eZ{&hoX)^`Dv9XSEi4xnIHN>Hn@^vWYT+PM`CyO6lrUo{_ zmN-YE#ZuLS*@g~Ion=ev{30)GbB59fe4j)Kqv}s1!J{ouwA*2%%1q3+6r+j_ zM4UbI3ncbmn@*4Sx^hA{Hp#+V0icJ@w@RB_HkO35-URacTs@mW~s z=f;rSyP=EaWeI-2M7lsHg}3Gzk2%*4A7B`jn=#?S904syUsf#9-Q8q<#kUzK;*ZoW zFg>s@Z>603ZUJ-r5D9E}=DrGq^xzVNFQ<%_wt=GuVgvU_L3)0BdwbqbqQzn@8!IcX zqi*&I<>zBARx7umT#@Fg1cAdtMpDuj$u9){Qt-0uolFUMT8tU^OeowNc} zVe|WRg`2!y9-GNGsV)p-RO8R_iA3@r7|ZIax8`!{8S25srw_?5a^8I|fIipNS>y1j zow@gmhVtHQiyn_!?0r?z>^QNFFWG$ugXeUx9ul9?(b2kC(}brzDGmEJ+4)g=HolVP zQZ8+U%Kq~$r9CyAfq#^qSLIk@2TSi+K2fbO9$dqIfyRrm4OO~97(-IcZg0G-66mcArIY5?HwG*R51!QgcIJQwa0H?W1=M-w-Lk88*Gp#q@d6DH(q5%ddMVtwAA4HN&)ik4G-Lp3|Wo9*>07cDb57J*jTG zbV(q(3$w(r49%F5>{QIfeU|(jN>ga+`YLjnuOSN{-mn$?Q2ijIO|Wk_x0l2V&SP;z z8Q>J77AcY*j=#xHm!9rjA=OY_op=(^pIvJ*a2*yRwX_xBDTRoY7)qk330g4x|7rJs za&&SQm_}CZ(+^+*^S_dFIjV`iioxKB&n;aBE8hEuCD%Xzb8puT^;5B zP8QS9;Qy~EDzg8tYz?M!XL3cza>JCAlp?aRF6t^O4mbo Date: Tue, 2 Apr 2013 07:57:37 -0700 Subject: [PATCH 133/151] Fixed bug 1780 - SDL_RWFromFile() sets an error on Android although a valid SDL_RWops pointer is returned. Philipp Wiesemann SDL_RWFromFile() sets an error to be queried with SDL_GetError() on Android although a valid SDL_RWops pointer is returned. This happens if the fallback implemented in SDL_android.cpp is used to load compressed assets (see README.android in section "Loading assets") and results in a message like "java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed". I think this is confusing and not needed because the loading works as expected. I attached a patch which changes SDL_android.cpp to not set an error if compressed assets are loaded. In this case also no Exception is queried and no additional string are created. --- src/core/android/SDL_android.cpp | 42 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/core/android/SDL_android.cpp b/src/core/android/SDL_android.cpp index 457512a16..5ae8f93a0 100644 --- a/src/core/android/SDL_android.cpp +++ b/src/core/android/SDL_android.cpp @@ -509,7 +509,8 @@ extern "C" void Android_JNI_CloseAudioDevice() } // Test for an exception and call SDL_SetError with its detail if one occurs -static bool Android_JNI_ExceptionOccurred() +// If optional parameter silent is truthy then SDL_SetError() is not called. +static bool Android_JNI_ExceptionOccurred(bool silent = false) { SDL_assert(LocalReferenceHolder::IsActive()); JNIEnv *mEnv = Android_JNI_GetEnv(); @@ -521,27 +522,28 @@ static bool Android_JNI_ExceptionOccurred() // Until this happens most JNI operations have undefined behaviour mEnv->ExceptionClear(); - jclass exceptionClass = mEnv->GetObjectClass(exception); - jclass classClass = mEnv->FindClass("java/lang/Class"); + if (!silent) { + jclass exceptionClass = mEnv->GetObjectClass(exception); + jclass classClass = mEnv->FindClass("java/lang/Class"); - mid = mEnv->GetMethodID(classClass, "getName", "()Ljava/lang/String;"); - jstring exceptionName = (jstring)mEnv->CallObjectMethod(exceptionClass, mid); - const char* exceptionNameUTF8 = mEnv->GetStringUTFChars(exceptionName, 0); + mid = mEnv->GetMethodID(classClass, "getName", "()Ljava/lang/String;"); + jstring exceptionName = (jstring)mEnv->CallObjectMethod(exceptionClass, mid); + const char* exceptionNameUTF8 = mEnv->GetStringUTFChars(exceptionName, 0); - mid = mEnv->GetMethodID(exceptionClass, "getMessage", "()Ljava/lang/String;"); - jstring exceptionMessage = (jstring)mEnv->CallObjectMethod(exception, mid); + mid = mEnv->GetMethodID(exceptionClass, "getMessage", "()Ljava/lang/String;"); + jstring exceptionMessage = (jstring)mEnv->CallObjectMethod(exception, mid); - if (exceptionMessage != NULL) { - const char* exceptionMessageUTF8 = mEnv->GetStringUTFChars( - exceptionMessage, 0); - SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8); - mEnv->ReleaseStringUTFChars(exceptionMessage, exceptionMessageUTF8); - } else { - SDL_SetError("%s", exceptionNameUTF8); + if (exceptionMessage != NULL) { + const char* exceptionMessageUTF8 = mEnv->GetStringUTFChars(exceptionMessage, 0); + SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8); + mEnv->ReleaseStringUTFChars(exceptionMessage, exceptionMessageUTF8); + } else { + SDL_SetError("%s", exceptionNameUTF8); + } + + mEnv->ReleaseStringUTFChars(exceptionName, exceptionNameUTF8); } - mEnv->ReleaseStringUTFChars(exceptionName, exceptionNameUTF8); - return true; } @@ -588,19 +590,19 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx) */ mid = mEnv->GetMethodID(mEnv->GetObjectClass(assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;"); inputStream = mEnv->CallObjectMethod(assetManager, mid, fileNameJString); - if (Android_JNI_ExceptionOccurred()) { + if (Android_JNI_ExceptionOccurred(true)) { goto fallback; } mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), "getStartOffset", "()J"); ctx->hidden.androidio.offset = mEnv->CallLongMethod(inputStream, mid); - if (Android_JNI_ExceptionOccurred()) { + if (Android_JNI_ExceptionOccurred(true)) { goto fallback; } mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), "getDeclaredLength", "()J"); ctx->hidden.androidio.size = mEnv->CallLongMethod(inputStream, mid); - if (Android_JNI_ExceptionOccurred()) { + if (Android_JNI_ExceptionOccurred(true)) { goto fallback; } From 2b26967375c02988aed724b110e8a3fc85322229 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Tue, 2 Apr 2013 08:38:52 -0700 Subject: [PATCH 134/151] Add input validation and null checking to SDL_Get/SetWindowData [reported by Joseph T.] --- src/video/SDL_video.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 53da52693..1e40ec2cf 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1425,11 +1425,17 @@ SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata) SDL_WindowUserData *prev, *data; CHECK_WINDOW_MAGIC(window, NULL); + + /* Input validation */ + if (name == NULL || SDL_strlen(name) == 0) { + SDL_InvalidParamError("name"); + return NULL; + } /* See if the named data already exists */ prev = NULL; for (data = window->data; data; prev = data, data = data->next) { - if (SDL_strcmp(data->name, name) == 0) { + if (data->name && SDL_strcmp(data->name, name) == 0) { void *last_value = data->data; if (userdata) { @@ -1467,8 +1473,14 @@ SDL_GetWindowData(SDL_Window * window, const char *name) CHECK_WINDOW_MAGIC(window, NULL); + /* Input validation */ + if (name == NULL || SDL_strlen(name) == 0) { + SDL_InvalidParamError("name"); + return NULL; + } + for (data = window->data; data; data = data->next) { - if (SDL_strcmp(data->name, name) == 0) { + if (data->name && SDL_strcmp(data->name, name) == 0) { return data->data; } } From 4926901d46f0094a1c7334975e9b7b8103245f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Tue, 2 Apr 2013 18:09:30 -0700 Subject: [PATCH 135/151] Add new controller mappings for Windows. --- .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes .../English.lproj/InfoPlist.strings | Bin 588 -> 588 bytes src/joystick/SDL_gamecontroller.c | 4 +++- 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Xcode/TemplatesForXcodeTiger/SDL Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL Application/English.lproj/InfoPlist.strings index e612457676d964a8021d20ec90290d5c6c3d88c1..38224b5a6dc9494230bdffbcad9c8bd915f478d9 100755 GIT binary patch delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC diff --git a/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/English.lproj/InfoPlist.strings index e612457676d964a8021d20ec90290d5c6c3d88c1..38224b5a6dc9494230bdffbcad9c8bd915f478d9 100755 GIT binary patch delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC diff --git a/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/English.lproj/InfoPlist.strings b/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/English.lproj/InfoPlist.strings index e612457676d964a8021d20ec90290d5c6c3d88c1..38224b5a6dc9494230bdffbcad9c8bd915f478d9 100755 GIT binary patch delta 13 UcmX@Za)yQJ|G$mQo=l7k04L%Epa1{> delta 12 TcmX@Za)yQZ-+zXUOrA^tB1QzC diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 037f6b6a5..1cb998a9f 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -92,9 +92,11 @@ const char *s_ControllerMappings [] = #ifdef SDL_JOYSTICK_DINPUT "xinput,X360 Controller,a:b10,b:b11,y:b13,x:b12,start:b4,guide:b14,back:b5,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftshoulder:b8,rightshoulder:b9,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5", "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7", - "88880803000000000000504944564944,PS3,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12", + "88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12", + "4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,", "25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,x:b0,y:b3,start:b8,guide:,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5", "ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", + "6d0416c2000000000000504944564944,Generic DirectInput Controller,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", #elif defined(__MACOSX__) "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", From 29399839e34e1cfb3056ccdbbe5613f9c30686aa Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 2 Apr 2013 23:17:33 -0400 Subject: [PATCH 136/151] Check for a NULL pointer dereference. --HG-- extra : rebase_source : 91c95190c0e39e48e79c1479e2c63bf096976867 From 6bcac2ad6788a5626b0b3efa77b3d6ea32a4d288 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 3 Apr 2013 10:36:15 -0400 Subject: [PATCH 137/151] Fixed infinite recursion (thanks, Rainer!). --- src/stdlib/SDL_string.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index a1bfe6105..da7290600 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -31,8 +31,8 @@ #undef SDL_atof char *SDL_itoa(int value, char *str, int radix) { return SDL_itoa_inline(value, str, radix); } char *SDL_uitoa(unsigned int value, char *str, int radix) { return SDL_uitoa_inline(value, str, radix); } -int SDL_atoi(const char *str) { return SDL_atoi(str); } -double SDL_atof(const char *str) { return SDL_atof(str); } +int SDL_atoi(const char *str) { return SDL_atoi_inline(str); } +double SDL_atof(const char *str) { return SDL_atof_inline(str); } From 7ffbc59786c48580dd99bdbd94854f4914a66e5a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 3 Apr 2013 11:34:21 -0400 Subject: [PATCH 138/151] Fixed compiler warnings. "leftFingerDown" doesn't need to be an SDL_FingerID. --- src/video/uikit/SDL_uikitview.h | 2 +- src/video/uikit/SDL_uikitview.m | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/video/uikit/SDL_uikitview.h b/src/video/uikit/SDL_uikitview.h index cd5aec450..ff8a7d2cf 100644 --- a/src/video/uikit/SDL_uikitview.h +++ b/src/video/uikit/SDL_uikitview.h @@ -37,7 +37,7 @@ #endif SDL_TouchID touchId; - SDL_FingerID leftFingerDown; + UITouch *leftFingerDown; #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS UITouch *finger[MAX_SIMULTANEOUS_TOUCHES]; #endif diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index a5eca6c9d..82cce3cbf 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -94,7 +94,7 @@ /* send mouse down event */ SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); - leftFingerDown = (SDL_FingerID)touch; + leftFingerDown = touch; } CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; @@ -102,7 +102,7 @@ // FIXME: TODO: Using touch as the fingerId is potentially dangerous // It is also much more efficient than storing the UITouch pointer // and comparing it to the incoming event. - SDL_SendTouch(touchId, (SDL_FingerID)touch, + SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch), SDL_TRUE, locationInView.x, locationInView.y, 1.0f); #else int i; @@ -125,10 +125,10 @@ UITouch *touch = (UITouch*)[enumerator nextObject]; while(touch) { - if ((SDL_FingerID)touch == leftFingerDown) { + if (touch == leftFingerDown) { /* send mouse up */ SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); - leftFingerDown = 0; + leftFingerDown = nil; } CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; @@ -166,7 +166,7 @@ UITouch *touch = (UITouch*)[enumerator nextObject]; while (touch) { - if ((SDL_FingerID)touch == leftFingerDown) { + if (touch == leftFingerDown) { CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO]; /* send moved event */ From 9baec7cd8be706838f3b2280fe87e79f4a83d045 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 3 Apr 2013 11:38:05 -0400 Subject: [PATCH 139/151] Possibly fix compiler warnings, simplify SDLTest_SurfaceImage_t definition. --- include/SDL_test_images.h | 6 +----- test/automated/common/common.h | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/SDL_test_images.h b/include/SDL_test_images.h index 5730cca88..7917b3abc 100644 --- a/include/SDL_test_images.h +++ b/include/SDL_test_images.h @@ -53,11 +53,7 @@ typedef struct SDLTest_SurfaceImage_s { int width; int height; unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ -#if (defined(__GNUC__) && (__GNUC__ <= 2)) - unsigned char pixel_data[0]; -#else - unsigned char pixel_data[]; -#endif + const unsigned char *pixel_data; } SDLTest_SurfaceImage_t; /* Test images */ diff --git a/test/automated/common/common.h b/test/automated/common/common.h index d80d8186e..d5e7324f5 100644 --- a/test/automated/common/common.h +++ b/test/automated/common/common.h @@ -22,7 +22,7 @@ typedef struct SurfaceImage_s { int width; int height; unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ - const unsigned char pixel_data[]; + const unsigned char *pixel_data; } SurfaceImage_t; #define ALLOWABLE_ERROR_OPAQUE 0 From b58d643086b96cccc9ae530d79e4a3163614e5cd Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 3 Apr 2013 11:48:03 -0400 Subject: [PATCH 140/151] Compiler warning fixes for Windows message box code. --- src/video/windows/SDL_windowsmessagebox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 562fc83ed..18504cb3c 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -164,7 +164,7 @@ static SDL_bool AddDialogString(WIN_DialogData *dialog, const char *string) static int s_BaseUnitsX; static int s_BaseUnitsY; -static void Vec2ToDLU(WORD* x, WORD* y) +static void Vec2ToDLU(short *x, short *y) { SDL_assert(s_BaseUnitsX != 0); // we init in WIN_ShowMessageBox(), which is the only public function... From 569de57dd71609738a0ed6644038b5d5f8fe960f Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 3 Apr 2013 11:49:25 -0400 Subject: [PATCH 141/151] Another attempt at fixing compiler warnings for SDLTest_SurfaceImage_t. --- include/SDL_test_images.h | 2 +- test/automated/common/common.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/SDL_test_images.h b/include/SDL_test_images.h index 7917b3abc..ea7222928 100644 --- a/include/SDL_test_images.h +++ b/include/SDL_test_images.h @@ -53,7 +53,7 @@ typedef struct SDLTest_SurfaceImage_s { int width; int height; unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ - const unsigned char *pixel_data; + const char *pixel_data; } SDLTest_SurfaceImage_t; /* Test images */ diff --git a/test/automated/common/common.h b/test/automated/common/common.h index d5e7324f5..25e7ecf74 100644 --- a/test/automated/common/common.h +++ b/test/automated/common/common.h @@ -22,7 +22,7 @@ typedef struct SurfaceImage_s { int width; int height; unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ - const unsigned char *pixel_data; + const char *pixel_data; } SurfaceImage_t; #define ALLOWABLE_ERROR_OPAQUE 0 From 7641f6840f9cfb4b3d47206dc0d747386d653748 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 3 Apr 2013 11:58:04 -0400 Subject: [PATCH 142/151] Fixed compiler warnings in Mac Xcode builds. --- include/begin_code.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/begin_code.h b/include/begin_code.h index f0e111ad4..4e613f94e 100644 --- a/include/begin_code.h +++ b/include/begin_code.h @@ -128,6 +128,7 @@ #define __inline__ #endif +#ifndef SDL_FORCE_INLINE #if defined(_MSC_VER) #define SDL_FORCE_INLINE __forceinline #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) ) @@ -135,6 +136,7 @@ #else #define SDL_FORCE_INLINE static __inline__ #endif +#endif /* Apparently this is needed by several Windows compilers */ #if !defined(__MACH__) From cbd1884115b25077a98a98ebaf239f3414c8435f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Wed, 3 Apr 2013 16:48:20 -0700 Subject: [PATCH 143/151] Add 3 Logitech gamecontroller mappings for Mac OS X. --- src/joystick/SDL_gamecontroller.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 1cb998a9f..a5e388f54 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -101,6 +101,9 @@ const char *s_ControllerMappings [] = "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", + "6d040000000000001fc2000000000000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "6d0400000000000016c2000000000000,Logitech F310 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // Guide button doesn't seem to be sent in DInput mode. + "6d0400000000000019c2000000000000,Logitech Wireless Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. #elif defined(__LINUX__) "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", "030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", From 50a23e30269e65dd4fd80b9ec41f36376db5e7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Wed, 3 Apr 2013 16:48:23 -0700 Subject: [PATCH 144/151] Improve testgamecontroller output & robustness. --- test/testgamecontroller.c | 90 +++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index 8a4413c57..2e9d98ad5 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -21,11 +21,11 @@ #ifndef SDL_JOYSTICK_DISABLED #ifdef __IPHONEOS__ -#define SCREEN_WIDTH 320 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 480 #else -#define SCREEN_WIDTH 640 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 #endif #define MAX_NUM_AXES 6 @@ -121,7 +121,7 @@ WatchGameController(SDL_GameController * gamecontroller) SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE); SDL_RenderClear(screen); SDL_RenderPresent(screen); - SDL_RaiseWindow(window); + SDL_RaiseWindow(window); /* Print info about the controller we are watching */ printf("Watching controller %s\n", name ? name : "Unknown Controller"); @@ -199,9 +199,9 @@ WatchGameController(SDL_GameController * gamecontroller) SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE); SDL_RenderPresent(screen); - - if ( !done ) - done = SDL_GameControllerGetAttached( gamecontroller ) == 0; + + if ( !done ) + done = SDL_GameControllerGetAttached( gamecontroller ) == 0; } SDL_DestroyRenderer(screen); @@ -211,54 +211,60 @@ WatchGameController(SDL_GameController * gamecontroller) int main(int argc, char *argv[]) { - const char *name; int i; - int nController = 0; + int nController = 0; + int retcode = 0; + char guid[64]; SDL_GameController *gamecontroller; - SDL_SetHint( SDL_HINT_GAMECONTROLLERCONFIG, "341a3608000000000000504944564944,Aferglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" ); /* Initialize SDL (Note: video is required to start event loop) */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); + return 1; } /* Print information about the controller */ for (i = 0; i < SDL_NumJoysticks(); ++i) { - if ( SDL_IsGameController(i) ) - { - nController++; - name = SDL_GameControllerNameForIndex(i); - printf("Game Controller %d: %s\n", i, name ? name : "Unknown Controller"); - } + const char *name; + const char *description = "Joystick (not recognized as game controller)"; + + SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i), + guid, sizeof (guid)); + + if ( SDL_IsGameController(i) ) + { + nController++; + name = SDL_GameControllerNameForIndex(i); + } else { + name = SDL_JoystickNameForIndex(i); + } + printf("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid); } - printf("There are %d game controllers attached\n", nController); + printf("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks()); if (argv[1]) { - int nreportederror = 0; - SDL_Event event; - gamecontroller = SDL_GameControllerOpen(atoi(argv[1])); - while ( s_ForceQuit == SDL_FALSE ) { - if (gamecontroller == NULL) { - if ( nreportederror == 0 ) { - printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError()); - nreportederror = 1; - } - } else { - nreportederror = 0; - WatchGameController(gamecontroller); - SDL_GameControllerClose(gamecontroller); - } - - gamecontroller = NULL; - SDL_WaitEvent( &event ); - if ( event.type == SDL_JOYDEVICEADDED ) - gamecontroller = SDL_GameControllerOpen(atoi(argv[1])); - } - } - SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ); + int device = atoi(argv[1]); + if (device >= SDL_NumJoysticks()) { + printf("%i is an invalid joystick index.\n", device); + retcode = 1; + } else { + SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device), + guid, sizeof (guid)); + printf("Attempting to open device %i, guid %s\n", device, guid); + gamecontroller = SDL_GameControllerOpen(device); + if (gamecontroller == NULL) { + printf("Couldn't open joystick %d: %s\n", device, SDL_GetError()); + retcode = 1; + } else { + WatchGameController(gamecontroller); + SDL_GameControllerClose(gamecontroller); + } + } + } - return (0); + SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); + + return retcode; } #else From 45592bbbee1e503dab9b4a9ee7aedbb9f6614a91 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 4 Apr 2013 11:35:22 -0400 Subject: [PATCH 145/151] Corrected some stdinc inline functions (thanks, Martin!). qsort() returns void, so remove the "return" keyword, plus some C++ const_casting magic. Fixes Bugzilla #1785. --- include/SDL_stdinc.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index f1e0edbca..746a39d44 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -30,7 +30,6 @@ #include "SDL_config.h" - #ifdef HAVE_SYS_TYPES_H #include #endif @@ -282,7 +281,7 @@ SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)); #ifdef HAVE_QSORT -SDL_FORCE_INLINE void SDL_qsort_inline(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { return qsort(base, nmemb, size, compare); } +SDL_FORCE_INLINE void SDL_qsort_inline(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { qsort(base, nmemb, size, compare); } #define SDL_qsort SDL_qsort_inline #endif @@ -512,10 +511,22 @@ SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index( extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c); #ifdef HAVE_STRRCHR -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return (char*)strrchr(str, c); } +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { +#ifdef __cplusplus +return const_cast(strrchr(str, c)); +#else +return (char*)strrchr(str, c); +#endif +} #define SDL_strrchr SDL_strrchr_inline #elif defined(HAVE_RINDEX) /* !!! FIXME: is there anywhere that has this but not strrchr? */ -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return (char*)rindex(str, c); } +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { +#ifdef __cplusplus +return const_cast(rindex(str, c)); +#else +return (char*)rindex(str, c); +#endif +} #define SDL_strrchr SDL_strrchr_inline #endif From 280675858c707d11492a3a2471aad3ae304da9b7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 5 Apr 2013 16:34:59 -0400 Subject: [PATCH 146/151] Fixed another infinite recursion accident in stdlib. --- src/stdlib/SDL_string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index da7290600..da02d8b09 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -923,7 +923,7 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen) #ifdef SDL_strcasecmp #undef SDL_strcasecmp -int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp(str1, str2); } +int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp_inline(str1, str2); } #else int SDL_strcasecmp(const char *str1, const char *str2) From 8d0b0c59bff6be8a12aa4d430d3470976ab1e80c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 8 Apr 2013 18:37:50 -0400 Subject: [PATCH 147/151] More const_cast fixes for C++ apps using the public headers (thanks, Martin!). --- include/SDL_stdinc.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 746a39d44..a19647729 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -502,7 +502,13 @@ SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); } extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c); #ifdef HAVE_STRCHR -SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return (char*)strchr(str, c); } +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { +#ifdef __cplusplus +return const_cast(strchr(str, c)); +#else +return (char*)strchr(str, c); +#endif +} #define SDL_strchr SDL_strchr_inline #elif defined(HAVE_INDEX) /* !!! FIXME: is there anywhere that has this but not strchr? */ SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); } @@ -532,7 +538,13 @@ return (char*)rindex(str, c); extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle); #ifdef HAVE_STRSTR -SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return (char*)strstr(haystack, needle); } +SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { +#ifdef __cplusplus +return const_cast(strstr(haystack, needle)); +#else +return (char*)strstr(haystack, needle); +#endif +} #define SDL_strstr SDL_strstr_inline #endif From 4bf8e7bd24ca49de217a4ee383f7d21538f7733e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Wed, 10 Apr 2013 14:11:26 -0700 Subject: [PATCH 148/151] Numlock & pause fix from Alfred. Fix numlock and pause keys not being pressable on win32, they both report under the same scancode, so use the VK to tell them apart --HG-- extra : histedit_source : ea129a468bd8ca3164b1aaea0fa143cf2e130b7b --- src/video/windows/SDL_windowsevents.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 730e73766..fc85e4493 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -73,7 +73,8 @@ WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam ) char bIsExtended; int nScanCode = ( lParam >> 16 ) & 0xFF; - if ( nScanCode == 0 ) + /* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */ + if ( nScanCode == 0 || nScanCode == 0x45 ) { switch( wParam ) { @@ -82,6 +83,8 @@ WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam ) case VK_SELECT: return SDL_SCANCODE_SELECT; case VK_EXECUTE: return SDL_SCANCODE_EXECUTE; case VK_HELP: return SDL_SCANCODE_HELP; + case VK_PAUSE: return SDL_SCANCODE_PAUSE; + case VK_NUMLOCK: return SDL_SCANCODE_NUMLOCKCLEAR; case VK_F13: return SDL_SCANCODE_F13; case VK_F14: return SDL_SCANCODE_F14; From 7c5943b1ee9b6ce5d42eb1ec8e8a51f709fb848c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 10 Apr 2013 22:18:10 -0400 Subject: [PATCH 149/151] Fixed a typo (thanks, Ethan!). --- include/SDL_gamecontroller.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h index 318e51aa1..b90c4009f 100644 --- a/include/SDL_gamecontroller.h +++ b/include/SDL_gamecontroller.h @@ -111,7 +111,7 @@ typedef struct SDL_GameControllerButtonBind * * \return 1 if mapping is added, 0 if updated, -1 on error */ -extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping( const char* mappingSring ); +extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping( const char* mappingString ); /** * Get a mapping string for a GUID From 619405f9a3632900c5140cb455f40e8bcfee4ce3 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Sat, 13 Apr 2013 09:45:39 -0700 Subject: [PATCH 150/151] Add test coverage for SDL_SetWindowData and SDL_GetWindowData to Video suite --- test/testautomation_video.c | 224 +++++++++++++++++++++++++++++++++++- 1 file changed, 222 insertions(+), 2 deletions(-) diff --git a/test/testautomation_video.c b/test/testautomation_video.c index be10baa70..1c0dac6c2 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -601,7 +601,7 @@ void _checkInvalidWindowError() const char *invalidWindowError = "Invalid window"; char *lastError; - lastError = (char *)SDL_GetError(); + lastError = (char *)SDL_GetError(); SDLTest_AssertPass("SDL_GetError()"); SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); if (lastError != NULL) { @@ -1486,6 +1486,223 @@ video_getSetWindowMaximumSize(void *arg) return TEST_COMPLETED; } + +/** + * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowData + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowData + */ +int +video_getSetWindowData(void *arg) +{ + int returnValue = TEST_COMPLETED; + const char* title = "video_setGetWindowData Test Window"; + SDL_Window* window; + const char *referenceName = "TestName"; + const char *name = "TestName"; + const char *referenceName2 = "TestName2"; + const char *name2 = "TestName2"; + int datasize; + char *referenceUserdata; + char *userdata; + char *referenceUserdata2; + char *userdata2; + char *result; + int iteration; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Create testdata */ + datasize = SDLTest_RandomIntegerInRange(1, 32); + referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize); + if (referenceUserdata == NULL) { + returnValue = TEST_ABORTED; + goto cleanup; + } + userdata = (char *)strdup(referenceUserdata); + if (userdata == NULL) { + returnValue = TEST_ABORTED; + goto cleanup; + } + datasize = SDLTest_RandomIntegerInRange(1, 32); + referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize); + if (referenceUserdata2 == NULL) { + returnValue = TEST_ABORTED; + goto cleanup; + } + userdata2 = (char *)strdup(referenceUserdata2); + if (userdata2 == NULL) { + returnValue = TEST_ABORTED; + goto cleanup; + } + + /* Get non-existent data */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Set data */ + result = SDL_SetWindowData(window, name, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + + /* Get data (twice) */ + for (iteration = 1; iteration <= 2; iteration++) { + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + } + + /* Set data again twice */ + for (iteration = 1; iteration <= 2; iteration++) { + result = SDL_SetWindowData(window, name, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + } + + /* Get data again */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Set data with new data */ + result = SDL_SetWindowData(window, name, userdata2); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); + + /* Set data with new data again */ + result = SDL_SetWindowData(window, name, userdata2); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); + + /* Get new data */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Set data with NULL to clear */ + result = SDL_SetWindowData(window, name, NULL); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); + + /* Set data with NULL to clear again */ + result = SDL_SetWindowData(window, name, NULL); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name, userdata); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); + + /* Get non-existent data */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Get non-existent data new name */ + result = (char *)SDL_GetWindowData(window, name2); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2); + + /* Set data (again) */ + result = SDL_SetWindowData(window, name, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + + /* Get data (again) */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Negative test */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + /* Set with invalid window */ + result = SDL_SetWindowData(NULL, name, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidWindowError(); + + /* Set data with NULL name, valid userdata */ + result = SDL_SetWindowData(window, NULL, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Set data with empty name, valid userdata */ + result = SDL_SetWindowData(window, "", userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(name='')"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Set data with NULL name, NULL userdata */ + result = SDL_SetWindowData(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Set data with empty name, NULL userdata */ + result = SDL_SetWindowData(window, "", NULL); + SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Get with invalid window */ + result = SDL_GetWindowData(NULL, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidWindowError(); + + /* Get data with NULL name */ + result = SDL_GetWindowData(window, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Get data with empty name */ + result = SDL_GetWindowData(window, ""); + SDLTest_AssertPass("Call to SDL_GetWindowData(name='')"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + cleanup: + if (referenceUserdata != NULL) SDL_free(referenceUserdata); + if (referenceUserdata2 != NULL) SDL_free(referenceUserdata2); + if (userdata != NULL) SDL_free(userdata); + if (userdata != NULL) SDL_free(userdata); + + return returnValue; +} + + /* ================= Test References ================== */ /* Video test cases */ @@ -1555,13 +1772,16 @@ static const SDLTest_TestCaseReference videoTest21 = static const SDLTest_TestCaseReference videoTest22 = { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED }; +static const SDLTest_TestCaseReference videoTest23 = + { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED }; + /* Sequence of Video test cases */ static const SDLTest_TestCaseReference *videoTests[] = { &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17, &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22, - NULL + &videoTest23, NULL }; /* Video test suite (global) */ From c865461ef8c54d7825f1a8907942461840a626c5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 13 Apr 2013 20:43:32 -0400 Subject: [PATCH 151/151] Added a data2 field to the SDL_RWops::hidden::unknown. This shouldn't change the ABI, since this struct had space left in the union. --HG-- extra : rebase_source : 773ba0aa2ed9242d2259ed63384d23b98c33376a --- include/SDL_rwops.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/SDL_rwops.h b/include/SDL_rwops.h index 61c30920e..acc499ffb 100644 --- a/include/SDL_rwops.h +++ b/include/SDL_rwops.h @@ -138,6 +138,7 @@ typedef struct SDL_RWops struct { void *data1; + int data2; } unknown; } hidden;