From 50c5b0720f6253810fc77abd983c684e07f0bd1b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 23 Jan 2011 21:55:04 -0800 Subject: [PATCH 01/44] Fixed bug #1011 Daniel Ellis 2010-06-25 15:20:31 PDT SDL based applications sometimes display the wrong application name in the Sound Preferences dialog when using pulseaudio. I can see from the code that the SDL pulse module is initiating a new pulse audio context and passing an application name using the function get_progname(). The get_progname() function returns the name of the current process. However, the process name is often not a suitable name to use. For example, the OpenShot video editor is a python application, and so "python" is displayed in the Sound Preferences window (see Bug #596504), when it should be displaying "OpenShot". PulseAudio allows applications to specify the application name, either at the time the context is created (as SDL does currently), or by special environment variables (see http://www.pulseaudio.org/wiki/ApplicationProperties). If no name is specified, then pulseaudio will determine the name based on the process. If you specify the application name when initiating the pulseaudio context, then that will override any application name specified using an environment variable. As libsdl is a library, I believe the solution is for libsdl to not specify any application name when initiating a pulseaudio context, which will enable applications to specify the application name using environment variables. In the case that the applications do not specify anything, pulseaudio will fall back to using the process name anyway. The attached patch removes the get_progname() function and passes NULL as the application name when creating the pulseaudio context, which fixes the issue. --- src/audio/pulseaudio/SDL_pulseaudio.c | 34 +-------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index 63bd030d7..a0406c941 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -304,38 +304,6 @@ PULSEAUDIO_CloseDevice(_THIS) } -/* !!! FIXME: this could probably be expanded. */ -/* Try to get the name of the program */ -static char * -get_progname(void) -{ -#ifdef __LINUX__ - char *progname = NULL; - FILE *fp; - static char temp[BUFSIZ]; - - SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid()); - fp = fopen(temp, "r"); - if (fp != NULL) { - if (fgets(temp, sizeof(temp) - 1, fp)) { - progname = SDL_strrchr(temp, '/'); - if (progname == NULL) { - progname = temp; - } else { - progname = progname + 1; - } - } - fclose(fp); - } - return(progname); -#elif defined(__NetBSD__) - return getprogname(); -#else - return("unknown"); -#endif -} - - static int PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) { @@ -438,7 +406,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) } h->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(h->mainloop); - h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, get_progname()); + h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, NULL); if (!h->context) { PULSEAUDIO_CloseDevice(this); SDL_SetError("pa_context_new() failed"); From d35de7167f5cb621fef8c942ac22d7fde596cbe3 Mon Sep 17 00:00:00 2001 From: krogoway Date: Mon, 24 Jan 2011 13:47:35 -0600 Subject: [PATCH 02/44] Renamed SDL_keysym to SDL_KeySym Renamed SDL_scancode to SDL_ScanCode Added #defines to SDL_compat.h --- Xcode-iPhoneOS/Demos/src/keyboard.c | 8 ++++---- include/SDL_compat.h | 3 +++ include/SDL_events.h | 2 +- include/SDL_keyboard.h | 18 +++++++++--------- include/SDL_scancode.h | 4 ++-- src/events/SDL_keyboard.c | 16 ++++++++-------- src/events/SDL_keyboard_c.h | 4 ++-- src/events/scancodes_darwin.h | 2 +- src/events/scancodes_linux.h | 2 +- src/events/scancodes_windows.h | 2 +- src/events/scancodes_xfree86.h | 4 ++-- src/video/android/SDL_androidkeyboard.c | 6 +++--- src/video/bwindow/SDL_BWin.h | 4 ++-- src/video/cocoa/SDL_cocoakeyboard.m | 20 ++++++++++---------- src/video/directfb/SDL_DirectFB_events.c | 22 +++++++++++----------- src/video/photon/SDL_photon.c | 2 +- src/video/photon/SDL_photon_input.c | 4 ++-- src/video/photon/SDL_photon_input.h | 2 +- src/video/riscos/SDL_riscosevents.c | 8 ++++---- src/video/uikit/SDL_uikitview.m | 4 ++-- src/video/uikit/keyinfotable.h | 4 ++-- src/video/windows/SDL_windowskeyboard.c | 2 +- src/video/windows/SDL_windowsvideo.h | 2 +- src/video/x11/SDL_x11events.c | 2 +- src/video/x11/SDL_x11keyboard.c | 10 +++++----- src/video/x11/SDL_x11video.h | 2 +- test/checkkeys.c | 2 +- test/testkeys.c | 2 +- test/testwm.c | 2 +- 29 files changed, 84 insertions(+), 81 deletions(-) diff --git a/Xcode-iPhoneOS/Demos/src/keyboard.c b/Xcode-iPhoneOS/Demos/src/keyboard.c index ccbc25473..b2f774f42 100644 --- a/Xcode-iPhoneOS/Demos/src/keyboard.c +++ b/Xcode-iPhoneOS/Demos/src/keyboard.c @@ -34,7 +34,7 @@ static SDL_Color bg_color = { 50, 50, 100, 255 }; /* color of background * */ typedef struct { - SDL_scancode scancode; /* scancode of the key we want to map */ + SDL_ScanCode scancode; /* scancode of the key we want to map */ int allow_no_mod; /* is the map valid if the key has no modifiers? */ SDLMod mod; /* what modifiers are allowed for the mapping */ int index; /* what index in the font does the scancode map to */ @@ -103,7 +103,7 @@ fontMapping map[TABLE_SIZE] = { }; /* - This function maps an SDL_keysym to an index in the bitmap font. + This function maps an SDL_KeySym to an index in the bitmap font. It does so by scanning through the font mapping table one entry at a time. @@ -113,7 +113,7 @@ fontMapping map[TABLE_SIZE] = { If there is no entry for the key, -1 is returned */ int -keyToIndex(SDL_keysym key) +keyToIndex(SDL_KeySym key) { int i, index = -1; for (i = 0; i < TABLE_SIZE; i++) { @@ -240,7 +240,7 @@ main(int argc, char *argv[]) SDL_Window *window; SDL_Event event; /* last event received */ SDLMod mod; /* key modifiers of last key we pushed */ - SDL_scancode scancode; /* scancode of last key we pushed */ + SDL_ScanCode scancode; /* scancode of last key we pushed */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Error initializing SDL: %s", SDL_GetError()); diff --git a/include/SDL_compat.h b/include/SDL_compat.h index 96a5f4220..069df66e0 100644 --- a/include/SDL_compat.h +++ b/include/SDL_compat.h @@ -223,6 +223,9 @@ struct SDL_SysWMinfo; */ /*@{*/ +#define SDL_keysym SDL_KeySym +#define SDL_scancode SDL_ScanCode + /** * \name Renamed keys * diff --git a/include/SDL_events.h b/include/SDL_events.h index 40e76e8a2..dba6c2c1d 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -151,7 +151,7 @@ typedef struct SDL_KeyboardEvent Uint8 repeat; /**< Non-zero if this is a key repeat */ Uint8 padding2; Uint8 padding3; - SDL_keysym keysym; /**< The key that was pressed or released */ + SDL_KeySym keysym; /**< The key that was pressed or released */ } SDL_KeyboardEvent; #define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32) diff --git a/include/SDL_keyboard.h b/include/SDL_keyboard.h index 4482ac028..7d90a7071 100644 --- a/include/SDL_keyboard.h +++ b/include/SDL_keyboard.h @@ -45,13 +45,13 @@ extern "C" { /** * \brief The SDL keysym structure, used in key events. */ -typedef struct SDL_keysym +typedef struct SDL_KeySym { - SDL_scancode scancode; /**< SDL physical key code - see ::SDL_scancode for details */ + SDL_ScanCode scancode; /**< SDL physical key code - see ::SDL_ScanCode for details */ SDLKey sym; /**< SDL virtual key code - see ::SDLKey for details */ Uint16 mod; /**< current key modifiers */ Uint32 unicode; /**< \deprecated use SDL_TextInputEvent instead */ -} SDL_keysym; +} SDL_KeySym; /* Function prototypes */ @@ -65,7 +65,7 @@ extern DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void); * * \param numkeys if non-NULL, receives the length of the returned array. * - * \return An array of key states. Indexes into this array are obtained by using ::SDL_scancode values. + * \return An array of key states. Indexes into this array are obtained by using ::SDL_ScanCode values. * * \b Example: * \code @@ -97,17 +97,17 @@ extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate); * * \sa SDL_GetKeyName() */ -extern DECLSPEC SDLKey SDLCALL SDL_GetKeyFromScancode(SDL_scancode scancode); +extern DECLSPEC SDLKey SDLCALL SDL_GetKeyFromScancode(SDL_ScanCode scancode); /** * \brief Get the scancode corresponding to the given key code according to the * current keyboard layout. * - * See ::SDL_scancode for details. + * See ::SDL_ScanCode for details. * * \sa SDL_GetScancodeName() */ -extern DECLSPEC SDL_scancode SDLCALL SDL_GetScancodeFromKey(SDLKey key); +extern DECLSPEC SDL_ScanCode SDLCALL SDL_GetScancodeFromKey(SDLKey key); /** * \brief Get a human-readable name for a scancode. @@ -117,9 +117,9 @@ extern DECLSPEC SDL_scancode SDLCALL SDL_GetScancodeFromKey(SDLKey key); * copy it. If the scancode doesn't have a name, this function returns * an empty string (""). * - * \sa SDL_scancode + * \sa SDL_ScanCode */ -extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_scancode +extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_ScanCode scancode); /** diff --git a/include/SDL_scancode.h b/include/SDL_scancode.h index 0efaf8850..a4e273845 100644 --- a/include/SDL_scancode.h +++ b/include/SDL_scancode.h @@ -35,7 +35,7 @@ * \brief The SDL keyboard scancode representation. * * Values of this type are used to represent keyboard keys, among other places - * in the \link SDL_keysym::scancode key.keysym.scancode \endlink field of the + * in the \link SDL_KeySym::scancode key.keysym.scancode \endlink field of the * SDL_Event structure. * * The values in this enumeration are based on the USB usage page standard: @@ -392,7 +392,7 @@ typedef enum SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes for array bounds */ -} SDL_scancode; +} SDL_ScanCode; #endif /* _SDL_scancode_h */ diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index b75aea3d7..49948d77c 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -562,7 +562,7 @@ void SDL_ResetKeyboard(void) { SDL_Keyboard *keyboard = &SDL_keyboard; - SDL_scancode scancode; + SDL_ScanCode scancode; for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) { if (keyboard->keystate[scancode] == SDL_PRESSED) { @@ -590,7 +590,7 @@ SDL_SetKeymap(int start, SDLKey * keys, int length) } void -SDL_SetScancodeName(SDL_scancode scancode, const char *name) +SDL_SetScancodeName(SDL_ScanCode scancode, const char *name) { SDL_scancode_names[scancode] = name; } @@ -638,7 +638,7 @@ SDL_SetKeyboardFocus(SDL_Window * window) } int -SDL_SendKeyboardKey(Uint8 state, SDL_scancode scancode) +SDL_SendKeyboardKey(Uint8 state, SDL_ScanCode scancode) { SDL_Keyboard *keyboard = &SDL_keyboard; int posted; @@ -849,18 +849,18 @@ SDL_SetModState(SDLMod modstate) } SDLKey -SDL_GetKeyFromScancode(SDL_scancode scancode) +SDL_GetKeyFromScancode(SDL_ScanCode scancode) { SDL_Keyboard *keyboard = &SDL_keyboard; return keyboard->keymap[scancode]; } -SDL_scancode +SDL_ScanCode SDL_GetScancodeFromKey(SDLKey key) { SDL_Keyboard *keyboard = &SDL_keyboard; - SDL_scancode scancode; + SDL_ScanCode scancode; for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) { @@ -872,7 +872,7 @@ SDL_GetScancodeFromKey(SDLKey key) } const char * -SDL_GetScancodeName(SDL_scancode scancode) +SDL_GetScancodeName(SDL_ScanCode scancode) { const char *name = SDL_scancode_names[scancode]; @@ -890,7 +890,7 @@ SDL_GetKeyName(SDLKey key) if (key & SDLK_SCANCODE_MASK) { return - SDL_GetScancodeName((SDL_scancode) (key & ~SDLK_SCANCODE_MASK)); + SDL_GetScancodeName((SDL_ScanCode) (key & ~SDLK_SCANCODE_MASK)); } switch (key) { diff --git a/src/events/SDL_keyboard_c.h b/src/events/SDL_keyboard_c.h index 1eeb9718c..51e7cb00b 100644 --- a/src/events/SDL_keyboard_c.h +++ b/src/events/SDL_keyboard_c.h @@ -43,13 +43,13 @@ extern void SDL_SetKeymap(int start, SDLKey * keys, int length); name. Encoded as UTF-8. The string is not copied, thus the pointer given to this function must stay valid forever (or at least until the call to VideoQuit()). */ -extern void SDL_SetScancodeName(SDL_scancode scancode, const char *name); +extern void SDL_SetScancodeName(SDL_ScanCode scancode, const char *name); /* Set the keyboard focus window */ extern void SDL_SetKeyboardFocus(SDL_Window * window); /* Send a keyboard key event */ -extern int SDL_SendKeyboardKey(Uint8 state, SDL_scancode scancode); +extern int SDL_SendKeyboardKey(Uint8 state, SDL_ScanCode scancode); /* Send keyboard text input */ extern int SDL_SendKeyboardText(const char *text); diff --git a/src/events/scancodes_darwin.h b/src/events/scancodes_darwin.h index f328cba44..79496c10f 100644 --- a/src/events/scancodes_darwin.h +++ b/src/events/scancodes_darwin.h @@ -27,7 +27,7 @@ - experimentation on various ADB and USB ISO keyboards and one ADB ANSI keyboard */ /* *INDENT-OFF* */ -static const SDL_scancode darwin_scancode_table[] = { +static const SDL_ScanCode darwin_scancode_table[] = { /* 0 */ SDL_SCANCODE_A, /* 1 */ SDL_SCANCODE_S, /* 2 */ SDL_SCANCODE_D, diff --git a/src/events/scancodes_linux.h b/src/events/scancodes_linux.h index c4b9419bd..5c7f96d8c 100644 --- a/src/events/scancodes_linux.h +++ b/src/events/scancodes_linux.h @@ -26,7 +26,7 @@ - Linux kernel source input.h */ /* *INDENT-OFF* */ -static SDL_scancode const linux_scancode_table[] = { +static SDL_ScanCode const linux_scancode_table[] = { /* 0 */ SDL_SCANCODE_UNKNOWN, /* 1 */ SDL_SCANCODE_ESCAPE, /* 2 */ SDL_SCANCODE_1, diff --git a/src/events/scancodes_windows.h b/src/events/scancodes_windows.h index 2718d37c3..47199ce3b 100644 --- a/src/events/scancodes_windows.h +++ b/src/events/scancodes_windows.h @@ -26,7 +26,7 @@ - msdn.microsoft.com */ /* *INDENT-OFF* */ -static const SDL_scancode windows_scancode_table[] = { +static const SDL_ScanCode windows_scancode_table[] = { /* 0, 0x00 */ SDL_SCANCODE_UNKNOWN, /* 1, 0x01 */ SDL_SCANCODE_UNKNOWN, /* 2, 0x02 */ SDL_SCANCODE_UNKNOWN, diff --git a/src/events/scancodes_xfree86.h b/src/events/scancodes_xfree86.h index 6d9f4e61c..faa3afc17 100644 --- a/src/events/scancodes_xfree86.h +++ b/src/events/scancodes_xfree86.h @@ -26,7 +26,7 @@ - atKeyNames.h from XFree86 source code */ /* *INDENT-OFF* */ -static const SDL_scancode xfree86_scancode_table[] = { +static const SDL_ScanCode xfree86_scancode_table[] = { /* 0 */ SDL_SCANCODE_UNKNOWN, /* 1 */ SDL_SCANCODE_ESCAPE, /* 2 */ SDL_SCANCODE_1, @@ -177,7 +177,7 @@ static const SDL_scancode xfree86_scancode_table[] = { }; /* for wireless usb keyboard (manufacturer TRUST) without numpad. */ -static const SDL_scancode xfree86_scancode_table2[] = { +static const SDL_ScanCode xfree86_scancode_table2[] = { /* 0 */ SDL_SCANCODE_UNKNOWN, /* 1 */ SDL_SCANCODE_ESCAPE, /* 2 */ SDL_SCANCODE_1, diff --git a/src/video/android/SDL_androidkeyboard.c b/src/video/android/SDL_androidkeyboard.c index b94db5ba2..251eea7c2 100644 --- a/src/video/android/SDL_androidkeyboard.c +++ b/src/video/android/SDL_androidkeyboard.c @@ -37,7 +37,7 @@ void Android_InitKeyboard() SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); } -static SDL_scancode Android_Keycodes[] = { +static SDL_ScanCode Android_Keycodes[] = { SDL_SCANCODE_UNKNOWN, /* AKEYCODE_UNKNOWN */ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_LEFT */ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_RIGHT */ @@ -151,10 +151,10 @@ static SDL_scancode Android_Keycodes[] = { SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_MODE */ }; -static SDL_scancode +static SDL_ScanCode TranslateKeycode(int keycode) { - SDL_scancode scancode = SDL_SCANCODE_UNKNOWN; + SDL_ScanCode scancode = SDL_SCANCODE_UNKNOWN; if (keycode < SDL_arraysize(Android_Keycodes)) { scancode = Android_Keycodes[keycode]; diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index d0bf1b4ba..94ddd3417 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -509,7 +509,7 @@ class SDL_BWin:public BDirectWindow if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) { - SDL_keysym keysym; + SDL_KeySym keysym; keysym.scancode = key; if ((key > 0) && (key < 128)) { keysym.sym = keymap[key]; @@ -543,7 +543,7 @@ class SDL_BWin:public BDirectWindow int32 modifiers; if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) { - SDL_keysym keysym; + SDL_KeySym keysym; keysym.scancode = key; if ((key > 0) && (key < 128)) { keysym.sym = keymap[key]; diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index 0d7c400ad..da11d7711 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -246,7 +246,7 @@ static void HandleNonDeviceModifier(unsigned int device_independent_mask, unsigned int oldMods, unsigned int newMods, - SDL_scancode scancode) + SDL_ScanCode scancode) { unsigned int oldMask, newMask; @@ -268,7 +268,7 @@ HandleNonDeviceModifier(unsigned int device_independent_mask, */ static void HandleModifierOneSide(unsigned int oldMods, unsigned int newMods, - SDL_scancode scancode, + SDL_ScanCode scancode, unsigned int sided_device_dependent_mask) { unsigned int old_dep_mask, new_dep_mask; @@ -297,8 +297,8 @@ HandleModifierOneSide(unsigned int oldMods, unsigned int newMods, static void HandleModifierSide(int device_independent_mask, unsigned int oldMods, unsigned int newMods, - SDL_scancode left_scancode, - SDL_scancode right_scancode, + SDL_ScanCode left_scancode, + SDL_ScanCode right_scancode, unsigned int left_device_dependent_mask, unsigned int right_device_dependent_mask) { @@ -341,8 +341,8 @@ HandleModifierSide(int device_independent_mask, static void ReleaseModifierSide(unsigned int device_independent_mask, unsigned int oldMods, unsigned int newMods, - SDL_scancode left_scancode, - SDL_scancode right_scancode, + SDL_ScanCode left_scancode, + SDL_ScanCode right_scancode, unsigned int left_device_dependent_mask, unsigned int right_device_dependent_mask) { @@ -409,13 +409,13 @@ DoSidedModifiers(unsigned short scancode, unsigned int oldMods, unsigned int newMods) { /* Set up arrays for the key syms for the left and right side. */ - const SDL_scancode left_mapping[] = { + const SDL_ScanCode left_mapping[] = { SDL_SCANCODE_LSHIFT, SDL_SCANCODE_LCTRL, SDL_SCANCODE_LALT, SDL_SCANCODE_LGUI }; - const SDL_scancode right_mapping[] = { + const SDL_ScanCode right_mapping[] = { SDL_SCANCODE_RSHIFT, SDL_SCANCODE_RCTRL, SDL_SCANCODE_RALT, @@ -489,7 +489,7 @@ UpdateKeymap(SDL_VideoData *data) #endif const void *chr_data; int i; - SDL_scancode scancode; + SDL_ScanCode scancode; SDLKey keymap[SDL_NUM_SCANCODES]; /* See if the keymap needs to be updated */ @@ -675,7 +675,7 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; unsigned short scancode = [event keyCode]; - SDL_scancode code; + SDL_ScanCode code; #if 0 const char *text; #endif diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c index 8fe8db78b..97a821515 100644 --- a/src/video/directfb/SDL_DirectFB_events.c +++ b/src/video/directfb/SDL_DirectFB_events.c @@ -56,11 +56,11 @@ struct _cb_data static SDLKey oskeymap[256]; -static SDL_keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, - SDL_keysym * keysym); -static SDL_keysym *DirectFB_TranslateKeyInputEvent(_THIS, int index, +static SDL_KeySym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, + SDL_KeySym * keysym); +static SDL_KeySym *DirectFB_TranslateKeyInputEvent(_THIS, int index, DFBInputEvent * evt, - SDL_keysym * keysym); + SDL_KeySym * keysym); static void DirectFB_InitOSKeymap(_THIS, SDLKey * keypmap, int numkeys); static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button); @@ -168,7 +168,7 @@ ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags, DFBWindowEvent * evt) { SDL_DFB_DEVICEDATA(_this); - SDL_keysym keysym; + SDL_KeySym keysym; char text[5]; if (evt->clazz == DFEC_WINDOW) { @@ -300,7 +300,7 @@ static void ProcessInputEvent(_THIS, DFBInputEvent * ievt) { SDL_DFB_DEVICEDATA(_this); - SDL_keysym keysym; + SDL_KeySym keysym; int kbd_idx; char text[5]; @@ -549,8 +549,8 @@ DirectFB_InitOSKeymap(_THIS, SDLKey * keymap, int numkeys) } -static SDL_keysym * -DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym) +static SDL_KeySym * +DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_KeySym * keysym) { SDL_DFB_DEVICEDATA(_this); @@ -577,9 +577,9 @@ DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym) return keysym; } -static SDL_keysym * +static SDL_KeySym * DirectFB_TranslateKeyInputEvent(_THIS, int index, DFBInputEvent * evt, - SDL_keysym * keysym) + SDL_KeySym * keysym) { SDL_DFB_DEVICEDATA(_this); @@ -719,7 +719,7 @@ DirectFB_PumpEvents(_THIS) while (devdata->eventbuffer->GetEvent(devdata->eventbuffer, DFB_EVENT(&evt)) == DFB_OK) { - SDL_keysym keysym; + SDL_KeySym keysym; DFBInputDeviceModifierMask mod; if (evt.clazz = DFEC_INPUT) { diff --git a/src/video/photon/SDL_photon.c b/src/video/photon/SDL_photon.c index add29c876..724c1abe4 100644 --- a/src/video/photon/SDL_photon.c +++ b/src/video/photon/SDL_photon.c @@ -2488,7 +2488,7 @@ photon_pumpevents(_THIS) case Ph_EV_KEY: { PhKeyEvent_t *keyevent = NULL; - SDL_scancode scancode = SDL_SCANCODE_UNKNOWN; + SDL_ScanCode scancode = SDL_SCANCODE_UNKNOWN; SDL_bool pressed = SDL_FALSE; keyevent = PhGetData(event); diff --git a/src/video/photon/SDL_photon_input.c b/src/video/photon/SDL_photon_input.c index b12012935..4d739f72b 100644 --- a/src/video/photon/SDL_photon_input.c +++ b/src/video/photon/SDL_photon_input.c @@ -460,10 +460,10 @@ photon_freemouse(SDL_Mouse * mouse) return; } -SDL_scancode +SDL_ScanCode photon_to_sdl_keymap(uint32_t key) { - SDL_scancode scancode = SDL_SCANCODE_UNKNOWN; + SDL_ScanCode scancode = SDL_SCANCODE_UNKNOWN; switch (key & 0x0000007F) { case PHOTON_SCANCODE_ESCAPE: diff --git a/src/video/photon/SDL_photon_input.h b/src/video/photon/SDL_photon_input.h index cc1be32c5..589028c0e 100644 --- a/src/video/photon/SDL_photon_input.h +++ b/src/video/photon/SDL_photon_input.h @@ -45,6 +45,6 @@ int32_t photon_delinputdevices(_THIS); #define SDL_PHOTON_MOUSE_COLOR_WHITE 0xFFFFFFFF #define SDL_PHOTON_MOUSE_COLOR_TRANS 0x00000000 -SDL_scancode photon_to_sdl_keymap(uint32_t key); +SDL_ScanCode photon_to_sdl_keymap(uint32_t key); #endif /* __SDL_GF_INPUT_H__ */ diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c index fc4e4c6a1..8755aca11 100644 --- a/src/video/riscos/SDL_riscosevents.c +++ b/src/video/riscos/SDL_riscosevents.c @@ -69,7 +69,7 @@ static SDLKey RO_keymap[SDLK_LAST]; static char RO_pressed[ROKEYBD_ARRAYSIZE]; -static SDL_keysym *TranslateKey(int intkey, SDL_keysym * keysym, int pressed); +static SDL_KeySym *TranslateKey(int intkey, SDL_KeySym * keysym, int pressed); void RISCOS_PollMouse(_THIS); void RISCOS_PollKeyboard(); @@ -366,7 +366,7 @@ RISCOS_PollKeyboard() int which_key = ROKEY_LEFT_SHIFT; int j; int min_key, max_key; - SDL_keysym key; + SDL_KeySym key; /* Scan the keyboard to see what is pressed */ while (which_key <= ROKEY_LAST_KEY) { @@ -428,8 +428,8 @@ RISCOS_PollKeyboard() } } -static SDL_keysym * -TranslateKey(int intkey, SDL_keysym * keysym, int pressed) +static SDL_KeySym * +TranslateKey(int intkey, SDL_KeySym * keysym, int pressed) { /* Set the keysym information */ keysym->scancode = (unsigned char) intkey; diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index ff27b0fb9..9a012052c 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -267,10 +267,10 @@ unichar c = [string characterAtIndex: i]; Uint16 mod = 0; - SDL_scancode code; + SDL_ScanCode code; if (c < 127) { - /* figure out the SDL_scancode and SDL_keymod for this unichar */ + /* figure out the SDL_ScanCode and SDL_keymod for this unichar */ code = unicharToUIKeyInfoTable[c].code; mod = unicharToUIKeyInfoTable[c].mod; } diff --git a/src/video/uikit/keyinfotable.h b/src/video/uikit/keyinfotable.h index 3bece3e5e..0e1e37b39 100644 --- a/src/video/uikit/keyinfotable.h +++ b/src/video/uikit/keyinfotable.h @@ -27,14 +27,14 @@ /* This file is used by the keyboard code in SDL_uikitview.m to convert between characters - passed in from the iPhone's virtual keyboard, and tuples of SDL_scancodes and SDL_keymods. + passed in from the iPhone's virtual keyboard, and tuples of SDL_ScanCodes and SDL_keymods. For example unicharToUIKeyInfoTable['a'] would give you the scan code and keymod for lower case a. */ typedef struct { - SDL_scancode code; + SDL_ScanCode code; Uint16 mod; } UIKitKeyInfo; diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index 3e765ff36..4f442f2e1 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -145,7 +145,7 @@ void WIN_UpdateKeymap() { int i; - SDL_scancode scancode; + SDL_ScanCode scancode; SDLKey keymap[SDL_NUM_SCANCODES]; SDL_GetDefaultKeymap(keymap); diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index f96abb8c4..9051b11b9 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -160,7 +160,7 @@ typedef struct SDL_VideoData PFCoordTransform CoordTransform; #endif - const SDL_scancode *key_layout; + const SDL_ScanCode *key_layout; DWORD clipboard_count; /* Touch input functions */ diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index a45ea7925..ec3d8322c 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -202,7 +202,7 @@ X11_DispatchEvent(_THIS) case KeyPress:{ KeyCode keycode = xevent.xkey.keycode; KeySym keysym = NoSymbol; - SDL_scancode scancode; + SDL_ScanCode scancode; char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; Status status = 0; diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c index d6d5b7f8d..5dc479f5b 100644 --- a/src/video/x11/SDL_x11keyboard.c +++ b/src/video/x11/SDL_x11keyboard.c @@ -134,7 +134,7 @@ static const struct { static const struct { - const SDL_scancode const *table; + const SDL_ScanCode const *table; int table_size; } scancode_set[] = { { darwin_scancode_table, SDL_arraysize(darwin_scancode_table) }, @@ -175,7 +175,7 @@ X11_InitKeyboard(_THIS) int i, j; int min_keycode, max_keycode; struct { - SDL_scancode scancode; + SDL_ScanCode scancode; KeySym keysym; int value; } fingerprint[] = { @@ -215,7 +215,7 @@ X11_InitKeyboard(_THIS) printf("Using scancode set %d, min_keycode = %d, max_keycode = %d, table_size = %d\n", i, min_keycode, max_keycode, scancode_set[i].table_size); #endif SDL_memcpy(&data->key_layout[min_keycode], scancode_set[i].table, - sizeof(SDL_scancode) * scancode_set[i].table_size); + sizeof(SDL_ScanCode) * scancode_set[i].table_size); fingerprint_detected = SDL_TRUE; break; } @@ -239,7 +239,7 @@ X11_InitKeyboard(_THIS) key = X11_KeyCodeToSDLKey(data->display, i); for (j = 0; j < SDL_arraysize(keymap); ++j) { if (keymap[j] == key) { - data->key_layout[i] = (SDL_scancode) j; + data->key_layout[i] = (SDL_ScanCode) j; break; } } @@ -264,7 +264,7 @@ X11_UpdateKeymap(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; int i; - SDL_scancode scancode; + SDL_ScanCode scancode; SDLKey keymap[SDL_NUM_SCANCODES]; SDL_zero(keymap); diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index 5b936edca..2a8e547f6 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -96,7 +96,7 @@ typedef struct SDL_VideoData Atom _NET_WM_ICON; Atom UTF8_STRING; - SDL_scancode key_layout[256]; + SDL_ScanCode key_layout[256]; SDL_bool selection_waiting; } SDL_VideoData; diff --git a/test/checkkeys.c b/test/checkkeys.c index cec489f1e..909f43113 100644 --- a/test/checkkeys.c +++ b/test/checkkeys.c @@ -53,7 +53,7 @@ print_modifiers(void) } static void -PrintKey(SDL_keysym * sym, SDL_bool pressed, SDL_bool repeat) +PrintKey(SDL_KeySym * sym, SDL_bool pressed, SDL_bool repeat) { /* Print the keycode, name and state */ if (sym->sym) { diff --git a/test/testkeys.c b/test/testkeys.c index 8ec7665f8..9891e689a 100644 --- a/test/testkeys.c +++ b/test/testkeys.c @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) { - SDL_scancode scancode; + SDL_ScanCode scancode; if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); diff --git a/test/testwm.c b/test/testwm.c index 79ffa4091..68ae51ccf 100644 --- a/test/testwm.c +++ b/test/testwm.c @@ -210,7 +210,7 @@ print_modifiers(void) printf(" MODE"); } -static void PrintKey(const SDL_keysym *sym, int pressed) +static void PrintKey(const SDL_KeySym *sym, int pressed) { /* Print the keycode, name and state */ if ( sym->sym ) { From 294c77d54e42698f5c1010737740a101cb8da762 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 14:36:12 -0800 Subject: [PATCH 03/44] Fixed bug #1080 Markus Rathgeb 2011-01-23 14:34:23 PST With kernel 2.6.31 the struct input_absinfo defined in linux/input.h changed. A field "__s32 resolution" was added at the end of the struct. Because the macro EVIOCGABS(abs) is using the struct input_absinfo, it would be better (IMHO) to change the declaration of variable values to "int values[sizeof(struct input_absinfo) / sizeof(int)];" or using "struct input_absinfo" directly. --- src/joystick/linux/SDL_sysjoystick.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 57ab0a3d0..1d5302d1a 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -701,25 +701,26 @@ EV_ConfigJoystick(SDL_Joystick * joystick, int fd) continue; } if (test_bit(i, absbit)) { - int values[6]; + struct input_absinfo absinfo; if (ioctl(fd, EVIOCGABS(i), values) < 0) continue; #ifdef DEBUG_INPUT_EVENTS printf("Joystick has absolute axis: %x\n", i); printf("Values = { %d, %d, %d, %d, %d }\n", - values[0], values[1], values[2], values[3], values[4]); + absinfo.value, absinfo.minimum, absinfo.maximum, + absinfo.fuzz, absinfo.flat); #endif /* DEBUG_INPUT_EVENTS */ joystick->hwdata->abs_map[i] = joystick->naxes; - if (values[1] == values[2]) { + if (absinfo.minimum == absinfo.maximum) { joystick->hwdata->abs_correct[i].used = 0; } else { joystick->hwdata->abs_correct[i].used = 1; joystick->hwdata->abs_correct[i].coef[0] = - (values[2] + values[1]) / 2 - values[4]; + (absinfo.maximum + absinfo.minimum) / 2 - absinfo.flat; joystick->hwdata->abs_correct[i].coef[1] = - (values[2] + values[1]) / 2 + values[4]; - t = ((values[2] - values[1]) / 2 - 2 * values[4]); + (absinfo.maximum + absinfo.minimum) / 2 + absinfo.flat; + t = ((absinfo.maximum - absinfo.minimum) / 2 - 2 * absinfo.flat); if (t != 0) { joystick->hwdata->abs_correct[i].coef[2] = (1 << 29) / t; From 5bb95359094cc6013eb131ea6f6e01d7b37f314e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 15:10:16 -0800 Subject: [PATCH 04/44] Fixed compile error --- src/joystick/linux/SDL_sysjoystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 1d5302d1a..ee9ffb5f6 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -703,7 +703,7 @@ EV_ConfigJoystick(SDL_Joystick * joystick, int fd) if (test_bit(i, absbit)) { struct input_absinfo absinfo; - if (ioctl(fd, EVIOCGABS(i), values) < 0) + if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) continue; #ifdef DEBUG_INPUT_EVENTS printf("Joystick has absolute axis: %x\n", i); From ec39fffe84e48953255d0ee41d6ec16c4a40d841 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 15:46:11 -0800 Subject: [PATCH 05/44] Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008 --- VisualCE/SDL.sln | 4 +- VisualCE/SDL/SDL.vcproj | 3179 +++-------------------- VisualCE/SDLMain/SDLmain.vcproj | 77 +- VisualCE/loopwave/loopwave.vcproj | 25 +- VisualCE/testalpha/testalpha.vcproj | 33 +- VisualCE/testtimer/testtimer.vcproj | 25 +- VisualCE/testwin/testwin.vcproj | 33 +- include/SDL_assert.h | 2 +- include/SDL_atomic.h | 2 +- include/SDL_compat.h | 2 +- include/SDL_config_windows.h | 10 +- include/SDL_main.h | 4 +- include/SDL_opengl.h | 2 +- include/SDL_platform.h | 4 +- include/SDL_rwops.h | 2 +- include/SDL_thread.h | 2 +- include/begin_code.h | 4 +- src/SDL.c | 12 +- src/SDL_assert.c | 50 +- src/atomic/SDL_spinlock.c | 5 + src/audio/SDL_audio.c | 2 +- src/cpuinfo/SDL_cpuinfo.c | 4 +- src/events/SDL_events.c | 2 +- src/events/SDL_sysevents.h | 2 +- src/file/SDL_rwops.c | 6 +- src/libm/math_private.h | 2 +- src/loadso/windows/SDL_sysloadso.c | 2 +- src/power/windows/SDL_syspower.c | 11 +- src/stdlib/SDL_getenv.c | 4 +- src/stdlib/SDL_stdlib.c | 4 +- src/thread/windows/SDL_syssem.c | 2 +- src/thread/windows/SDL_systhread.c | 4 +- src/video/SDL_renderer_gl.c | 4 +- src/video/windows/SDL_gapirender.c | 928 +++---- src/video/windows/SDL_gdirender.c | 2 + src/video/windows/SDL_windowsevents.c | 39 +- src/video/windows/SDL_windowskeyboard.c | 29 + src/video/windows/SDL_windowsmodes.c | 6 + src/video/windows/SDL_windowsvideo.c | 12 +- src/video/windows/SDL_windowsvideo.h | 2 +- src/video/windows/SDL_windowswindow.c | 26 +- test/testgesture.c | 4 +- 42 files changed, 1137 insertions(+), 3437 deletions(-) diff --git a/VisualCE/SDL.sln b/VisualCE/SDL.sln index aaf906f4e..8e17b70a8 100644 --- a/VisualCE/SDL.sln +++ b/VisualCE/SDL.sln @@ -1,6 +1,6 @@  -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL", "SDL\SDL.vcproj", "{C598024D-8030-4F9C-AB76-69BF4CA0645F}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDLmain", "SDLmain\SDLmain.vcproj", "{5AC88B84-5EAA-4C1E-948D-332DA34227F6}" diff --git a/VisualCE/SDL/SDL.vcproj b/VisualCE/SDL/SDL.vcproj index 54ffdd82d..ca83d77ac 100644 --- a/VisualCE/SDL/SDL.vcproj +++ b/VisualCE/SDL/SDL.vcproj @@ -1,10 +1,11 @@ + @@ -195,6 +201,8 @@ StackCommitSize="4096" EntryPointSymbol="_DllMainCRTStartup" BaseAddress="0x00100000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" ImportLibrary="$(PlatformName)\$(ConfigurationName)/SDL.lib" /> + @@ -296,6 +307,8 @@ StackCommitSize="4096" EntryPointSymbol="_DllMainCRTStartup" BaseAddress="0x00100000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" ImportLibrary="$(PlatformName)\$(ConfigurationName)/SDL.lib" /> + @@ -396,6 +412,8 @@ StackCommitSize="4096" EntryPointSymbol="_DllMainCRTStartup" BaseAddress="0x00100000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" ImportLibrary="$(PlatformName)\$(ConfigurationName)/SDL.lib" /> + @@ -500,6 +521,8 @@ StackCommitSize="4096" EntryPointSymbol="_DllMainCRTStartup" BaseAddress="0x00100000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" ImportLibrary="$(PlatformName)\$(ConfigurationName)/SDL.lib" /> + @@ -606,6 +632,8 @@ LinkTimeCodeGeneration="1" EntryPointSymbol="_DllMainCRTStartup" BaseAddress="0x00100000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" ImportLibrary="$(PlatformName)\$(ConfigurationName)/SDL.lib" /> + @@ -643,937 +674,193 @@ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" > - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + @@ -1581,355 +868,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - + + @@ -1941,60 +916,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - + + - - - - - - @@ -3670,11 +1223,23 @@ > + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - diff --git a/VisualCE/SDLMain/SDLmain.vcproj b/VisualCE/SDLMain/SDLmain.vcproj index 95526d296..4876aae67 100644 --- a/VisualCE/SDLMain/SDLmain.vcproj +++ b/VisualCE/SDLMain/SDLmain.vcproj @@ -1,10 +1,11 @@ + @@ -171,6 +175,9 @@ SuppressStartupBanner="true" OutputFile="$(PlatformName)\$(ConfigurationName)/SDLmain.bsc" /> + @@ -254,6 +261,9 @@ SuppressStartupBanner="true" OutputFile="$(PlatformName)\$(ConfigurationName)/SDLmain.bsc" /> + @@ -337,6 +347,9 @@ SuppressStartupBanner="true" OutputFile="$(PlatformName)\$(ConfigurationName)/SDLmain.bsc" /> + @@ -420,6 +433,9 @@ SuppressStartupBanner="true" OutputFile="$(PlatformName)\$(ConfigurationName)/SDLmain.bsc" /> + @@ -506,6 +522,9 @@ SuppressStartupBanner="true" OutputFile="$(PlatformName)\$(ConfigurationName)/SDLmain.bsc" /> + @@ -530,62 +549,8 @@ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" > - - - - - - - - - - - - - - - - - - + @@ -125,7 +131,7 @@ Name="VCCLCompilerTool" ExecutionBucket="7" Optimization="0" - AdditionalIncludeDirectories="..\..\nclude" + AdditionalIncludeDirectories="..\..\include" PreprocessorDefinitions="_DEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;DEBUG;_WINDOWS;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;UNICODE" MinimalRebuild="true" RuntimeLibrary="1" @@ -154,6 +160,8 @@ GenerateDebugInformation="true" ProgramDatabaseFile="$(OutDir)/loopwave.pdb" SubSystem="0" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -236,6 +247,8 @@ SubSystem="0" OptimizeReferences="2" EnableCOMDATFolding="2" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -317,6 +333,8 @@ SubSystem="0" OptimizeReferences="2" EnableCOMDATFolding="2" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + diff --git a/VisualCE/testalpha/testalpha.vcproj b/VisualCE/testalpha/testalpha.vcproj index 5e4d62349..3db0bd3a2 100644 --- a/VisualCE/testalpha/testalpha.vcproj +++ b/VisualCE/testalpha/testalpha.vcproj @@ -1,10 +1,11 @@ + @@ -195,6 +201,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -300,6 +311,8 @@ LinkTimeCodeGeneration="1" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -400,6 +416,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -500,6 +521,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -600,6 +626,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + diff --git a/VisualCE/testtimer/testtimer.vcproj b/VisualCE/testtimer/testtimer.vcproj index 6c84ea6ee..cce6a01ca 100644 --- a/VisualCE/testtimer/testtimer.vcproj +++ b/VisualCE/testtimer/testtimer.vcproj @@ -1,11 +1,12 @@ + @@ -125,6 +131,7 @@ Name="VCCLCompilerTool" ExecutionBucket="7" Optimization="0" + AdditionalIncludeDirectories="..\..\include" PreprocessorDefinitions="_DEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;DEBUG;_WINDOWS;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;UNICODE" MinimalRebuild="true" RuntimeLibrary="1" @@ -153,6 +160,8 @@ GenerateDebugInformation="true" ProgramDatabaseFile="$(OutDir)/testtimer.pdb" SubSystem="0" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -235,6 +247,8 @@ SubSystem="0" OptimizeReferences="2" EnableCOMDATFolding="2" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -286,6 +303,7 @@ Name="VCCLCompilerTool" ExecutionBucket="7" Optimization="2" + AdditionalIncludeDirectories="..\..\include" PreprocessorDefinitions="NDEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;_WINDOWS;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;UNICODE" RuntimeLibrary="0" UsePrecompiledHeader="0" @@ -315,6 +333,8 @@ SubSystem="0" OptimizeReferences="2" EnableCOMDATFolding="2" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + diff --git a/VisualCE/testwin/testwin.vcproj b/VisualCE/testwin/testwin.vcproj index e95b02e60..8dac65eba 100644 --- a/VisualCE/testwin/testwin.vcproj +++ b/VisualCE/testwin/testwin.vcproj @@ -1,10 +1,11 @@ + @@ -194,6 +200,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -295,6 +306,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -395,6 +411,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -495,6 +516,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + @@ -595,6 +621,8 @@ StackCommitSize="4096" EntryPointSymbol="WinMainCRTStartup" BaseAddress="0x00010000" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" /> + diff --git a/include/SDL_assert.h b/include/SDL_assert.h index d822303d6..74eb465e9 100644 --- a/include/SDL_assert.h +++ b/include/SDL_assert.h @@ -50,7 +50,7 @@ on the assertion line and not in some random guts of SDL, and so each assert can have unique static variables associated with it. */ -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(_WIN32_WCE) #include #define SDL_TriggerBreakpoint() __debugbreak() #elif (defined(__GNUC__) && ((__i386__) || (__x86_64__))) diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index c2dfd045e..9f339c7cb 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -58,7 +58,7 @@ /* Need to do this here because intrin.h has C++ code in it */ /* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */ -#if defined(_MSC_VER) && (_MSC_VER >= 1500) +#if defined(_MSC_VER) && (_MSC_VER >= 1500) && !defined(_WIN32_WCE) #include #define HAVE_MSC_ATOMICS #endif diff --git a/include/SDL_compat.h b/include/SDL_compat.h index 069df66e0..92f622be8 100644 --- a/include/SDL_compat.h +++ b/include/SDL_compat.h @@ -65,7 +65,7 @@ extern "C" { /*@{*/ /* Platform */ -#ifdef __WINDOWS__ +#ifdef __WIN32__ #undef __WIN32__ #define __WIN32__ 1 #endif diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index 489d4b9aa..f02d18f0b 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -20,8 +20,8 @@ slouken@libsdl.org */ -#ifndef _SDL_config_windows2_h -#define _SDL_config_windows2_h +#ifndef _SDL_config_windows_h +#define _SDL_config_windows_h #include "SDL_platform.h" @@ -178,7 +178,11 @@ typedef unsigned int uintptr_t; #define SDL_VIDEO_DRIVER_DUMMY 1 #define SDL_VIDEO_DRIVER_WINDOWS 1 +#ifdef _WIN32_WCE +#define SDL_VIDEO_RENDER_GAPI 1 +#else #define SDL_VIDEO_RENDER_D3D 1 +#endif #define SDL_VIDEO_RENDER_GDI 1 /* Enable OpenGL support */ @@ -196,4 +200,4 @@ typedef unsigned int uintptr_t; #define SDL_ASSEMBLY_ROUTINES 1 #endif -#endif /* _SDL_config_windows2_h */ +#endif /* _SDL_config_windows_h */ diff --git a/include/SDL_main.h b/include/SDL_main.h index fe9f45986..df75a2f63 100644 --- a/include/SDL_main.h +++ b/include/SDL_main.h @@ -31,7 +31,7 @@ * Redefine main() on some platforms so that it is called by SDL. */ -#if defined(__WINDOWS__) || \ +#if defined(__WIN32__) || \ (defined(__MWERKS__) && !defined(__BEOS__)) || \ defined(__SYMBIAN32__) || defined(__IPHONEOS__) || \ defined(__ANDROID__) @@ -66,7 +66,7 @@ extern C_LINKAGE int SDL_main(int argc, char *argv[]); /* From the SDL library code -- needed for registering the app on Win32 */ -#ifdef __WINDOWS__ +#ifdef __WIN32__ #include "begin_code.h" #ifdef __cplusplus diff --git a/include/SDL_opengl.h b/include/SDL_opengl.h index 5a391c034..8402e72c9 100644 --- a/include/SDL_opengl.h +++ b/include/SDL_opengl.h @@ -31,7 +31,7 @@ #include "SDL_config.h" -#ifdef __WINDOWS__ +#ifdef __WIN32__ #define WIN32_LEAN_AND_MEAN #ifndef NOMINMAX #define NOMINMAX /* Don't defined min() and max() */ diff --git a/include/SDL_platform.h b/include/SDL_platform.h index 583c6a81a..13bdc0d74 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -125,8 +125,8 @@ #define __SOLARIS__ 1 #endif #if defined(WIN32) || defined(_WIN32) -#undef __WINDOWS__ -#define __WINDOWS__ 1 +#undef __WIN32__ +#define __WIN32__ 1 #endif #if defined(__NDS__) diff --git a/include/SDL_rwops.h b/include/SDL_rwops.h index 1bbac964e..ab6f26878 100644 --- a/include/SDL_rwops.h +++ b/include/SDL_rwops.h @@ -83,7 +83,7 @@ typedef struct SDL_RWops Uint32 type; union { -#ifdef __WINDOWS__ +#ifdef __WIN32__ struct { SDL_bool append; diff --git a/include/SDL_thread.h b/include/SDL_thread.h index dd94bd714..1c8a76a25 100644 --- a/include/SDL_thread.h +++ b/include/SDL_thread.h @@ -55,7 +55,7 @@ typedef unsigned long SDL_threadID; */ typedef int (SDLCALL * SDL_ThreadFunction) (void *data); -#if defined(__WINDOWS__) && !defined(HAVE_LIBC) +#if defined(__WIN32__) && !defined(HAVE_LIBC) /** * \file SDL_thread.h * diff --git a/include/begin_code.h b/include/begin_code.h index ccdcea612..395dc7c6a 100644 --- a/include/begin_code.h +++ b/include/begin_code.h @@ -42,7 +42,7 @@ # else # define DECLSPEC __declspec(export) # endif -# elif defined(__WINDOWS__) +# elif defined(__WIN32__) # ifdef __BORLANDC__ # ifdef BUILD_SDL # define DECLSPEC @@ -63,7 +63,7 @@ /* By default SDL uses the C calling convention */ #ifndef SDLCALL -#if defined(__WINDOWS__) && !defined(__GNUC__) +#if defined(__WIN32__) && !defined(__GNUC__) #define SDLCALL __cdecl #else #define SDLCALL diff --git a/src/SDL.c b/src/SDL.c index 9913dbdad..49620a8e1 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -39,7 +39,7 @@ extern void SDL_StartTicks(void); extern int SDL_TimerInit(void); extern void SDL_TimerQuit(void); #endif -#if defined(__WINDOWS__) +#if defined(__WIN32__) extern int SDL_HelperWindowCreate(void); extern int SDL_HelperWindowDestroy(void); #endif @@ -147,7 +147,7 @@ SDL_Init(Uint32 flags) /* Clear the error message */ SDL_ClearError(); -#if defined(__WINDOWS__) +#if defined(__WIN32__) if (SDL_HelperWindowCreate() < 0) { return -1; } @@ -220,7 +220,7 @@ SDL_Quit(void) fflush(stdout); #endif -#if defined(__WINDOWS__) +#if defined(__WIN32__) SDL_HelperWindowDestroy(); #endif SDL_QuitSubSystem(SDL_INIT_EVERYTHING); @@ -312,7 +312,7 @@ SDL_GetPlatform() return "RISC OS"; #elif __SOLARIS__ return "Solaris"; -#elif __WINDOWS__ +#elif __WIN32__ #ifdef _WIN32_WCE return "Windows CE"; #else @@ -325,7 +325,7 @@ SDL_GetPlatform() #endif } -#if defined(__WINDOWS__) +#if defined(__WIN32__) #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL)) /* Need to include DllMain() on Watcom C for some reason.. */ @@ -347,6 +347,6 @@ _DllMainCRTStartup(HANDLE hModule, } #endif /* building DLL with Watcom C */ -#endif /* __WINDOWS__ */ +#endif /* __WIN32__ */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL_assert.c b/src/SDL_assert.c index 9c4a73eec..38ee92560 100644 --- a/src/SDL_assert.c +++ b/src/SDL_assert.c @@ -26,9 +26,19 @@ #include "SDL_assert_c.h" #include "video/SDL_sysvideo.h" -#ifdef __WINDOWS__ +#ifdef __WIN32__ #define WIN32_LEAN_AND_MEAN #include + +#ifndef WS_OVERLAPPEDWINDOW +#define WS_OVERLAPPEDWINDOW 0 +#endif + +#ifdef UNICODE +#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1) +#else +#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1) +#endif #else /* fprintf, _exit(), etc. */ #include #include @@ -57,11 +67,12 @@ debug_print(const char *fmt, ...) __attribute__((format (printf, 1, 2))); static void debug_print(const char *fmt, ...) { -#ifdef __WINDOWS__ +#ifdef __WIN32__ /* Format into a buffer for OutputDebugStringA(). */ char buf[1024]; char *startptr; char *ptr; + LPTSTR tstr; int len; va_list ap; va_start(ap, fmt); @@ -78,15 +89,19 @@ debug_print(const char *fmt, ...) for (ptr = startptr; *ptr; ptr++) { if (*ptr == '\n') { *ptr = '\0'; - OutputDebugStringA(startptr); - OutputDebugStringA("\r\n"); + tstr = WIN_UTF8ToString(startptr); + OutputDebugString(tstr); + SDL_free(tstr); + OutputDebugString(TEXT("\r\n")); startptr = ptr+1; } } /* catch that last piece if it didn't have a newline... */ if (startptr != ptr) { - OutputDebugStringA(startptr); + tstr = WIN_UTF8ToString(startptr); + OutputDebugString(tstr); + SDL_free(tstr); } #else /* Unix has it easy. Just dump it to stderr. */ @@ -99,7 +114,7 @@ debug_print(const char *fmt, ...) } -#ifdef __WINDOWS__ +#ifdef __WIN32__ static SDL_assert_state SDL_Windows_AssertChoice = SDL_ASSERTION_ABORT; static const SDL_assert_data *SDL_Windows_AssertData = NULL; @@ -113,6 +128,7 @@ SDL_Assertion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) /* !!! FIXME: all this code stinks. */ const SDL_assert_data *data = SDL_Windows_AssertData; char buf[1024]; + LPTSTR tstr; const int w = 100; const int h = 25; const int gap = 10; @@ -121,14 +137,14 @@ SDL_Assertion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) int len; int i; static const struct { - const char *name; + LPCTSTR name; SDL_assert_state state; } buttons[] = { - {"Abort", SDL_ASSERTION_ABORT }, - {"Break", SDL_ASSERTION_BREAK }, - {"Retry", SDL_ASSERTION_RETRY }, - {"Ignore", SDL_ASSERTION_IGNORE }, - {"Always Ignore", SDL_ASSERTION_ALWAYS_IGNORE }, + {TEXT("Abort"), SDL_ASSERTION_ABORT }, + {TEXT("Break"), SDL_ASSERTION_BREAK }, + {TEXT("Retry"), SDL_ASSERTION_RETRY }, + {TEXT("Ignore"), SDL_ASSERTION_IGNORE }, + {TEXT("Always Ignore"), SDL_ASSERTION_ALWAYS_IGNORE }, }; len = (int) SDL_snprintf(buf, sizeof (buf), @@ -140,14 +156,16 @@ SDL_Assertion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) buf[sizeof (buf) - 1] = '\0'; } - CreateWindowA("STATIC", buf, + tstr = WIN_UTF8ToString(buf); + CreateWindow(TEXT("STATIC"), tstr, WS_VISIBLE | WS_CHILD | SS_LEFT, x, y, 550, 100, hwnd, (HMENU) 1, NULL, NULL); + SDL_free(tstr); y += 110; for (i = 0; i < (sizeof (buttons) / sizeof (buttons[0])); i++) { - CreateWindowA("BUTTON", buttons[i].name, + CreateWindow(TEXT("BUTTON"), buttons[i].name, WS_VISIBLE | WS_CHILD, x, y, w, h, hwnd, (HMENU) buttons[i].state, NULL, NULL); @@ -248,7 +266,7 @@ static void SDL_GenerateAssertionReport(void) static void SDL_ExitProcess(int exitcode) { -#ifdef __WINDOWS__ +#ifdef __WIN32__ ExitProcess(42); #else _exit(42); @@ -311,7 +329,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata) /* platform-specific UI... */ -#ifdef __WINDOWS__ +#ifdef __WIN32__ state = SDL_PromptAssertion_windows(data); #elif __MACOSX__ diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index 19efbfca8..9d9a136d9 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -26,8 +26,13 @@ /* Don't do the check for Visual Studio 2005, it's safe here */ #if defined(_MSC_VER) +#ifdef _WIN32_WCE +#define WIN32_LEAN_AND_MEAN +#include +#else #include #endif +#endif /* _MSC_VER */ /* This function is where all the magic happens... */ SDL_bool diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index d4b72a7d3..b55fee325 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -971,7 +971,7 @@ open_audio_device(const char *devname, int iscapture, if (!current_audio.impl.ProvidesOwnCallbackThread) { /* Start the audio thread */ /* !!! FIXME: this is nasty. */ -#if (defined(__WINDOWS__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) +#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) #undef SDL_CreateThread device->thread = SDL_CreateThread(SDL_RunAudio, device, NULL, NULL); #else diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index b79f02bb0..7fa382818 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -38,7 +38,7 @@ #include #include #endif -#ifdef __WINDOWS__ +#ifdef __WIN32__ #define WIN32_LEAN_AND_MEAN #include #endif @@ -319,7 +319,7 @@ SDL_GetCPUCount() sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0); } #endif -#ifdef __WINDOWS__ +#ifdef __WIN32__ if (SDL_CPUCount <= 0) { SYSTEM_INFO info; GetSystemInfo(&info); diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index ad19c09e4..06f533cd2 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -170,7 +170,7 @@ SDL_StartEventThread(Uint32 flags) /* The event thread will handle timers too */ SDL_SetTimerThreaded(2); -#if (defined(__WINDOWS__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) +#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) #undef SDL_CreateThread SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL); diff --git a/src/events/SDL_sysevents.h b/src/events/SDL_sysevents.h index 98440eaaf..994477733 100644 --- a/src/events/SDL_sysevents.h +++ b/src/events/SDL_sysevents.h @@ -29,7 +29,7 @@ #define MUST_THREAD_EVENTS #endif -#ifdef __WINDOWS__ /* Windows doesn't allow a separate event thread */ +#ifdef __WIN32__ /* Windows doesn't allow a separate event thread */ #define CANT_THREAD_EVENTS #endif diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 2710872ca..6548403f0 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -37,7 +37,7 @@ #include #endif /* __NDS__ */ -#ifdef __WINDOWS__ +#ifdef __WIN32__ /* Functions to read/write Win32 API file pointers */ /* Will not use it on WinCE because stdio is buffered, it means @@ -295,7 +295,7 @@ windows_file_close(SDL_RWops * context) } return (0); } -#endif /* __WINDOWS__ */ +#endif /* __WIN32__ */ #ifdef HAVE_STDIO_H @@ -449,7 +449,7 @@ SDL_RWFromFile(const char *file, const char *mode) SDL_SetError("SDL_RWFromFile(): No file or no mode specified"); return NULL; } -#if defined(__WINDOWS__) +#if defined(__WIN32__) rwops = SDL_AllocRW(); if (!rwops) return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ diff --git a/src/libm/math_private.h b/src/libm/math_private.h index 63c98bf61..500e7da96 100644 --- a/src/libm/math_private.h +++ b/src/libm/math_private.h @@ -19,7 +19,7 @@ /*#include */ #include "SDL_endian.h" -#include +/*#include */ #define attribute_hidden #define libm_hidden_proto(x) diff --git a/src/loadso/windows/SDL_sysloadso.c b/src/loadso/windows/SDL_sysloadso.c index c6706be71..061243429 100644 --- a/src/loadso/windows/SDL_sysloadso.c +++ b/src/loadso/windows/SDL_sysloadso.c @@ -61,7 +61,7 @@ SDL_LoadObject(const char *sofile) SDL_free(sofile_t); SDL_free(errbuf_t); -#else /*if defined(__WINDOWS__) */ +#else /*if defined(__WIN32__) */ char errbuf[512]; handle = (void *) LoadLibrary(sofile); diff --git a/src/power/windows/SDL_syspower.c b/src/power/windows/SDL_syspower.c index af007d4d8..a5e23e7fa 100644 --- a/src/power/windows/SDL_syspower.c +++ b/src/power/windows/SDL_syspower.c @@ -32,11 +32,20 @@ SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState * state, int *seconds, int *percent) { +#ifdef _WIN32_WCE + SYSTEM_POWER_STATUS_EX status; +#else SYSTEM_POWER_STATUS status; +#endif SDL_bool need_details = SDL_FALSE; /* This API should exist back to Win95 and Windows CE. */ - if (!GetSystemPowerStatus(&status)) { +#ifdef _WIN32_WCE + if (!GetSystemPowerStatusEx(&status, FALSE)) +#else + if (!GetSystemPowerStatus(&status)) +#endif + { /* !!! FIXME: push GetLastError() into SDL_GetError() */ *state = SDL_POWERSTATE_UNKNOWN; } else if (status.BatteryFlag == 0xFF) { /* unknown state */ diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index 5d0502f8e..387531a88 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -25,7 +25,7 @@ #ifndef HAVE_GETENV -#if defined(__WINDOWS__) && !defined(_WIN32_WCE) +#if defined(__WIN32__) && !defined(_WIN32_WCE) #define WIN32_LEAN_AND_MEAN #include @@ -163,7 +163,7 @@ SDL_getenv(const char *name) return value; } -#endif /* __WINDOWS__ */ +#endif /* __WIN32__ */ #endif /* !HAVE_GETENV */ diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 93e13b3cc..39e70f6ff 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -35,9 +35,7 @@ __declspec(selectany) int _fltused = 1; #endif -#ifdef _WIN64 - -#else +#ifdef _M_IX86 void __declspec(naked) diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 4fcb8c6e1..9673ee898 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -39,7 +39,7 @@ struct SDL_semaphore #else HANDLE id; #endif - LONG volatile count; + LONG count; }; diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c index 71313c3be..5a00e9723 100644 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -23,12 +23,10 @@ /* Win32 thread management routines for SDL */ -#define WIN32_LEAN_AND_MEAN -#include - #include "SDL_thread.h" #include "../SDL_thread_c.h" #include "../SDL_systhread.h" +#include "SDL_systhread_c.h" #ifndef SDL_PASSED_BEGINTHREAD_ENDTHREAD #ifndef _WIN32_WCE diff --git a/src/video/SDL_renderer_gl.c b/src/video/SDL_renderer_gl.c index b9155fa62..e3938b1af 100644 --- a/src/video/SDL_renderer_gl.c +++ b/src/video/SDL_renderer_gl.c @@ -1181,7 +1181,7 @@ GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, } data->glEnd(); } else { -#if defined(__APPLE__) || defined(__WINDOWS__) +#if defined(__APPLE__) || defined(__WIN32__) #else int x1, y1, x2, y2; #endif @@ -1200,7 +1200,7 @@ GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, * least it would be pixel perfect. */ data->glBegin(GL_POINTS); -#if defined(__APPLE__) || defined(__WINDOWS__) +#if defined(__APPLE__) || defined(__WIN32__) /* Mac OS X and Windows seem to always leave the second point open */ data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y); #else diff --git a/src/video/windows/SDL_gapirender.c b/src/video/windows/SDL_gapirender.c index d8d1dd6f2..a0485aea6 100644 --- a/src/video/windows/SDL_gapirender.c +++ b/src/video/windows/SDL_gapirender.c @@ -92,19 +92,19 @@ typedef struct //#define DM_DISPLAYORIENTATION 0x00800000L //#endif -#define FORMAT_565 1 -#define FORMAT_555 2 -#define FORMAT_OTHER 3 +#define FORMAT_565 1 +#define FORMAT_555 2 +#define FORMAT_OTHER 3 -#define GETRAWFRAMEBUFFER 0x00020001 -#define GETGXINFO 0x00020000 +#define GETRAWFRAMEBUFFER 0x00020001 +#define GETGXINFO 0x00020000 -#define kfPalette 0x10 -#define kfDirect 0x20 -#define kfDirect555 0x40 -#define kfDirect565 0x80 +#define kfPalette 0x10 +#define kfDirect 0x20 +#define kfDirect555 0x40 +#define kfDirect565 0x80 -#define GX_FULLSCREEN 0x01 +#define GX_FULLSCREEN 0x01 enum ScreenOrientation { ORIENTATION_UNKNOWN = -1, ORIENTATION_UP = DMDO_0, ORIENTATION_DOWN = DMDO_180, ORIENTATION_LEFT = DMDO_270, ORIENTATION_RIGHT = DMDO_90 }; enum ScreenGeometry { GEOMETRY_UNKNOWN, GEOMETRY_PORTRAIT, GEOMETRY_LANDSCAPE, GEOMETRY_SQUARE }; @@ -123,15 +123,15 @@ typedef struct // private display data typedef struct { - unsigned char* pixels; // video memory - int format; // video format - FrameBufferInfo fb; // framebuffer geometry - GapiInfo* gapi; // GAPI module + unsigned char* pixels; // video memory + int format; // video format + FrameBufferInfo fb; // framebuffer geometry + GapiInfo* gapi; // GAPI module int userOrientation; int systemOrientation; int hardwareGeometry; - int flags; // fb flags - float scale; // scale pointer position + int flags; // fb flags + float scale; // scale pointer position int debug; } WINCE_RenderData; @@ -147,110 +147,111 @@ typedef struct // system func -SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags); -void WINCE_DestroyRenderer(SDL_Renderer* renderer); +SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags); +void WINCE_DestroyRenderer(SDL_Renderer* renderer); -int WINCE_CreateTexture(SDL_Renderer* renderer, SDL_Texture* texture); -void WINCE_DestroyTexture(SDL_Renderer* renderer, SDL_Texture* texture); -int WINCE_QueryTexturePixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch); -int WINCE_UpdateTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch); -int WINCE_LockTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int dirty, void** pixels, int* pitch); -void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture); +int WINCE_CreateTexture(SDL_Renderer* renderer, SDL_Texture* texture); +void WINCE_DestroyTexture(SDL_Renderer* renderer, SDL_Texture* texture); +int WINCE_QueryTexturePixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch); +int WINCE_UpdateTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch); +int WINCE_LockTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int dirty, void** pixels, int* pitch); +void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture); -int WINCE_Available(void); -void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height); +int WINCE_Available(void); +void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height); -int WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srect, const SDL_Rect* drect); -void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible); +int WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srect, const SDL_Rect* drect); +void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible); -void WINCE_RenderPresent(SDL_Renderer* renderer); -int WINCE_RenderDrawPoints(SDL_Renderer* renderer, const SDL_Point* points, int count); -int WINCE_RenderDrawLines(SDL_Renderer* renderer, const SDL_Point* points, int count); -int WINCE_RenderDrawRects(SDL_Renderer* renderer, const SDL_Rect ** rects, int count); -int WINCE_RenderFillRects(SDL_Renderer* renderer, const SDL_Rect** rects, int count); +void WINCE_RenderPresent(SDL_Renderer* renderer); +int WINCE_RenderDrawPoints(SDL_Renderer* renderer, const SDL_Point* points, int count); +int WINCE_RenderDrawLines(SDL_Renderer* renderer, const SDL_Point* points, int count); +int WINCE_RenderDrawRects(SDL_Renderer* renderer, const SDL_Rect ** rects, int count); +int WINCE_RenderFillRects(SDL_Renderer* renderer, const SDL_Rect** rects, int count); -void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt); -void WINCE_DumpVideoInfo(WINCE_RenderData* data); -void WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height); -void WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height); -void WINCE_SquareTransform(WINCE_RenderData* data, int width, int height); -int WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug); -int WINCE_GetDMOrientation(void); -int WINCE_SetDMOrientation(int orientation); -void WINCE_UpdateYUVTextureData(SDL_Texture* texture); +void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt); +void WINCE_DumpVideoInfo(WINCE_RenderData* data); +void WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height); +void WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height); +void WINCE_SquareTransform(WINCE_RenderData* data, int width, int height); +int WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug); +int WINCE_GetDMOrientation(void); +int WINCE_SetDMOrientation(int orientation); +void WINCE_UpdateYUVTextureData(SDL_Texture* texture); // gapi engine specific -int GAPI_Init(WINCE_RenderData* data, HWND hwnd); -void GAPI_Quit(WINCE_RenderData* data); +int GAPI_Init(WINCE_RenderData* data, HWND hwnd); +void GAPI_Quit(WINCE_RenderData* data); // raw engine specific -int RAW_Init(WINCE_RenderData* data); -void RAW_Quit(WINCE_RenderData* data); +int RAW_Init(WINCE_RenderData* data); +void RAW_Quit(WINCE_RenderData* data); // tools -void FrameBufferRotate(FrameBufferInfo* src, int orientation); -int GetFrameBufferOrientation(const FrameBufferInfo* src); -void PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation); -void FrameBufferInitialize(FrameBufferInfo* fb); -void FrameBufferDumpInfo(const FrameBufferInfo* fb, const char*); -const char* GetOrientationName(int orientation); -void UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, Uint16 width); +void FrameBufferRotate(FrameBufferInfo* src, int orientation); +int GetFrameBufferOrientation(const FrameBufferInfo* src); +void PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation); +void FrameBufferInitialize(FrameBufferInfo* fb); +void FrameBufferDumpInfo(const FrameBufferInfo* fb, const char*); +const char* GetOrientationName(int orientation); +void UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, Uint16 width); // stdlib -inline int __abs(int x){ return x < 0 ? -x : x; }; -inline void __swap(int* a, int* b){ int t = *a; *a = *b; *b = t; }; +static __inline__ int __abs(int x){ return x < 0 ? -x : x; }; +static __inline__ void __swap(int* a, int* b){ int t = *a; *a = *b; *b = t; }; -#define GAPI_RENDER_NAME "gapi" -#define RAW_RENDER_NAME "raw" +#define GAPI_RENDER_NAME "gapi" +#define RAW_RENDER_NAME "raw" // SDL_RenderDriver GAPI_RenderDriver = { WINCE_CreateRenderer, { - GAPI_RENDER_NAME, - (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD), - (SDL_TEXTUREMODULATE_NONE), - (SDL_BLENDMODE_NONE), - (SDL_SCALEMODE_NONE), - 7, - { - SDL_PIXELFORMAT_RGB555, - SDL_PIXELFORMAT_RGB565, - SDL_PIXELFORMAT_YV12, - SDL_PIXELFORMAT_IYUV, - SDL_PIXELFORMAT_YUY2, - SDL_PIXELFORMAT_UYVY, - SDL_PIXELFORMAT_YVYU - }, - 0, - 0 + GAPI_RENDER_NAME, + (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD), + (SDL_TEXTUREMODULATE_NONE), + (SDL_BLENDMODE_NONE), + (SDL_SCALEMODE_NONE), + 7, + { + SDL_PIXELFORMAT_RGB555, + SDL_PIXELFORMAT_RGB565, + SDL_PIXELFORMAT_YV12, + SDL_PIXELFORMAT_IYUV, + SDL_PIXELFORMAT_YUY2, + SDL_PIXELFORMAT_UYVY, + SDL_PIXELFORMAT_YVYU + }, + 0, + 0 } }; SDL_RenderDriver RAW_RenderDriver = { WINCE_CreateRenderer, { - RAW_RENDER_NAME, - (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD), - (SDL_TEXTUREMODULATE_NONE), - (SDL_BLENDMODE_NONE), - (SDL_SCALEMODE_NONE), - 7, - { - SDL_PIXELFORMAT_RGB555, - SDL_PIXELFORMAT_RGB565, - SDL_PIXELFORMAT_YV12, - SDL_PIXELFORMAT_IYUV, - SDL_PIXELFORMAT_YUY2, - SDL_PIXELFORMAT_UYVY, - SDL_PIXELFORMAT_YVYU - }, - 0, - 0 + RAW_RENDER_NAME, + (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD), + (SDL_TEXTUREMODULATE_NONE), + (SDL_BLENDMODE_NONE), + (SDL_SCALEMODE_NONE), + 7, + { + SDL_PIXELFORMAT_RGB555, + SDL_PIXELFORMAT_RGB565, + SDL_PIXELFORMAT_YV12, + SDL_PIXELFORMAT_IYUV, + SDL_PIXELFORMAT_YUY2, + SDL_PIXELFORMAT_UYVY, + SDL_PIXELFORMAT_YVYU + }, + 0, + 0 } }; int WINCE_Available(void) { + HMODULE render_gapi; const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); // raw check @@ -260,13 +261,13 @@ int WINCE_Available(void) ReleaseDC(NULL, hdc); if(render_raw != 0 && rfbi.cxPixels != 0 && rfbi.cyPixels != 0 && - rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0) - render_raw = 1; + rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0) + render_raw = 1; if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw; // gapi check - HMODULE render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); + render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); if(0 == render_gapi) render_gapi = LoadLibrary(TEXT("gx.dll")); FreeLibrary(render_gapi); @@ -290,8 +291,8 @@ void WINCE_AddRenderDriver(_THIS) ReleaseDC(NULL, hdc); if(render_raw != 0 && rfbi.cxPixels != 0 && rfbi.cyPixels != 0 && - rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0) - render_raw = 1; + rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0) + render_raw = 1; // gapi check render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); @@ -299,25 +300,25 @@ void WINCE_AddRenderDriver(_THIS) render_gapi = LoadLibrary(TEXT("gx.dll")); if(render_gapi) - FreeLibrary(render_gapi); + FreeLibrary(render_gapi); for(ii = 0; ii < _this->num_displays; ++ii) { - if(preferably) - { - if(0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME) && render_raw) - SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver); - else - if(0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME) && render_gapi) - SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver); - } - else - { - if(render_raw) - SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver); - if(render_gapi) - SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver); - } + if(preferably) + { + if(0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME) && render_raw) + SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver); + else + if(0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME) && render_gapi) + SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver); + } + else + { + if(render_raw) + SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver); + if(render_gapi) + SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver); + } } } @@ -332,7 +333,7 @@ SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags) Uint32 Rmask, Gmask, Bmask, Amask; if(!(window->flags & SDL_WINDOW_FULLSCREEN)) - window->flags |= SDL_WINDOW_FULLSCREEN; + window->flags |= SDL_WINDOW_FULLSCREEN; if(!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { @@ -342,13 +343,13 @@ SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags) switch(window->fullscreen_mode.format) { - case SDL_PIXELFORMAT_RGB555: - case SDL_PIXELFORMAT_RGB565: - break; + case SDL_PIXELFORMAT_RGB555: + case SDL_PIXELFORMAT_RGB565: + break; - default: - SDL_SetError("Support only 16 or 15 bpp"); - return NULL; + default: + SDL_SetError("Support only 16 or 15 bpp"); + return NULL; } renderer = (SDL_Renderer*) SDL_calloc(1, sizeof(SDL_Renderer)); @@ -375,9 +376,9 @@ SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags) // set debug - data->debug = SDL_getenv("DEBUG_VIDEO_GAPI") || SDL_getenv("GAPI_RENDERER_DEBUG") ? 1 : 0; + data->debug = SDL_getenv("DEBUG_VIDEO_GAPI") || SDL_getenv("GAPI_RENDERER_DEBUG") ? 1 : 0; #if defined(DEBUG_VIDEO_GAPI) || defined(GAPI_RENDERER_DEBUG) - data->debug = 1; + data->debug = 1; #endif windowdata->videodata->render = data->gapi ? RENDER_GAPI : RENDER_RAW; @@ -418,10 +419,10 @@ void WINCE_DestroyRenderer(SDL_Renderer* renderer) if(renderdata) { - if(renderdata->gapi) - GAPI_Quit(renderdata); - else - RAW_Quit(renderdata); + if(renderdata->gapi) + GAPI_Quit(renderdata); + else + RAW_Quit(renderdata); SDL_free(renderdata); } @@ -448,20 +449,21 @@ int WINCE_CreateTexture(SDL_Renderer* renderer, SDL_Texture* texture) if(SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - texturedata->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h); + SDL_Window* window = renderer->window; + SDL_VideoDisplay* display = window->display; + + texturedata->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h); if(NULL == texturedata->yuv) - { - SDL_OutOfMemory(); + { + SDL_OutOfMemory(); return -1; } - SDL_Window* window = renderer->window; - SDL_VideoDisplay* display = window->display; - texturedata->format = display->current_mode.format; + texturedata->format = display->current_mode.format; } else { - texturedata->yuv = NULL; - texturedata->format = texture->format; + texturedata->yuv = NULL; + texturedata->format = texture->format; } texture->driverdata = texturedata; @@ -475,10 +477,10 @@ void WINCE_DestroyTexture(SDL_Renderer* renderer, SDL_Texture* texture) if(texturedata) { - if(texturedata->yuv) SDL_SW_DestroyYUVTexture(texturedata->yuv); - if(texturedata->pixels) SDL_free(texturedata->pixels); - SDL_free(texturedata); - texture->driverdata = NULL; + if(texturedata->yuv) SDL_SW_DestroyYUVTexture(texturedata->yuv); + if(texturedata->pixels) SDL_free(texturedata->pixels); + SDL_free(texturedata); + texture->driverdata = NULL; } } @@ -509,19 +511,19 @@ int WINCE_UpdateTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_ if(0 < rect->w && 0 < rect->h) { - const unsigned char *src = ((const unsigned char*) pixels); - unsigned char *dst = ((unsigned char*) texturedata->pixels) + - rect->y * texturedata->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format); + const unsigned char *src = ((const unsigned char*) pixels); + unsigned char *dst = ((unsigned char*) texturedata->pixels) + + rect->y * texturedata->pitch + + rect->x * SDL_BYTESPERPIXEL(texture->format); int length = rect->w * SDL_BYTESPERPIXEL(texture->format); - int height = rect->h; + int height = rect->h; - while(height--) - { - SDL_memcpy(dst, src, length); - dst += texturedata->pitch; - src += pitch; - } + while(height--) + { + SDL_memcpy(dst, src, length); + dst += texturedata->pitch; + src += pitch; + } } return 0; @@ -535,9 +537,10 @@ int WINCE_LockTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Re return SDL_SW_LockYUVTexture(texturedata->yuv, rect, dirty, pixels, pitch); *pixels = (void *) ((unsigned char*) texturedata->pixels + - rect->y * texturedata->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); + rect->y * texturedata->pitch + + rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = texturedata->pitch; + return 0; } void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture) @@ -547,7 +550,7 @@ void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture) if(texturedata->yuv) { SDL_SW_UnlockYUVTexture(texturedata->yuv); - WINCE_UpdateYUVTextureData(texture); + WINCE_UpdateYUVTextureData(texture); } } @@ -555,41 +558,43 @@ int WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rec { WINCE_RenderData* dstdata = (WINCE_RenderData*) renderer->driverdata; WINCE_TextureData* srcdata = (WINCE_TextureData*) texture->driverdata; + const unsigned char *src; + unsigned char *dst; if((dstdata->flags & FB_SUSPENDED) || - 0 >= srect->w || 0 >= srect->h) return; + 0 >= srect->w || 0 >= srect->h) return 0; // lock gapi if(dstdata->gapi) dstdata->gapi->GXBeginDraw(); - const unsigned char *src = ((const unsigned char*) srcdata->pixels); - unsigned char *dst = dstdata->pixels + (dstdata->flags & FB_SKIP_OFFSET ? 0 : dstdata->fb.offset) + - drect->y * dstdata->fb.ypitch + - drect->x * dstdata->fb.xpitch; + src = ((const unsigned char*) srcdata->pixels); + dst = dstdata->pixels + (dstdata->flags & FB_SKIP_OFFSET ? 0 : dstdata->fb.offset) + + drect->y * dstdata->fb.ypitch + + drect->x * dstdata->fb.xpitch; if(srcdata->yuv) { - return SDL_SW_CopyYUVToRGB(srcdata->yuv, + return SDL_SW_CopyYUVToRGB(srcdata->yuv, srect, srcdata->format, drect->w, drect->h, dst, dstdata->fb.ypitch); } else { - int height = drect->h; - int length = drect->w * SDL_BYTESPERPIXEL(texture->format); // in bytes + int height = drect->h; + int length = drect->w * SDL_BYTESPERPIXEL(texture->format); // in bytes - while(height--) - { - switch(SDL_BYTESPERPIXEL(texture->format)) - { - case 2: UpdateLine16to16(&dstdata->fb, (Uint16*) src, (Uint16*) dst, length >> 1); break; + while(height--) + { + switch(SDL_BYTESPERPIXEL(texture->format)) + { + case 2: UpdateLine16to16(&dstdata->fb, (Uint16*) src, (Uint16*) dst, length >> 1); break; - default: break; - } + default: break; + } - dst += dstdata->fb.ypitch; - src += srcdata->pitch; - } + dst += dstdata->fb.ypitch; + src += srcdata->pitch; + } } // unlock gapi @@ -630,8 +635,8 @@ int WINCE_RenderFillRects(SDL_Renderer* renderer, const SDL_Rect** rects, int co void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height) { - const float maxW1 = GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN) ? GetSystemMetrics(SM_CXSCREEN) : GetSystemMetrics(SM_CYSCREEN); - const float maxW2 = data->fb.width > data->fb.height ? data->fb.width : data->fb.height; + const float maxW1 = (float)(GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN) ? GetSystemMetrics(SM_CXSCREEN) : GetSystemMetrics(SM_CYSCREEN)); + const float maxW2 = (float)(data->fb.width > data->fb.height ? data->fb.width : data->fb.height); // scale define data->scale = maxW2 / maxW1; @@ -643,31 +648,31 @@ void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height) data->userOrientation = ORIENTATION_UP; data->systemOrientation = WINCE_GetDMOrientation(); data->hardwareGeometry = data->fb.width == data->fb.height ? GEOMETRY_SQUARE : - (data->fb.width < data->fb.height ? GEOMETRY_PORTRAIT : GEOMETRY_LANDSCAPE); + (data->fb.width < data->fb.height ? GEOMETRY_PORTRAIT : GEOMETRY_LANDSCAPE); if(data->debug) - WINCE_DumpVideoInfo(data); + WINCE_DumpVideoInfo(data); if(data->systemOrientation == ORIENTATION_UNKNOWN) - data->systemOrientation == ORIENTATION_UP; + data->systemOrientation = ORIENTATION_UP; data->userOrientation = ORIENTATION_UP; switch(data->hardwareGeometry) { - case GEOMETRY_PORTRAIT: WINCE_PortraitTransform(data, width, height); break; - case GEOMETRY_LANDSCAPE: WINCE_LandscapeTransform(data, width, height); break; - case GEOMETRY_SQUARE: WINCE_SquareTransform(data, width, height); break; - default: break; + case GEOMETRY_PORTRAIT: WINCE_PortraitTransform(data, width, height); break; + case GEOMETRY_LANDSCAPE: WINCE_LandscapeTransform(data, width, height); break; + case GEOMETRY_SQUARE: WINCE_SquareTransform(data, width, height); break; + default: break; } // debug if(data->debug) { - printf("\n"); - printf("user video width: %d\n", width); - printf("user video height: %d\n", height); - FrameBufferDumpInfo(&data->fb, "user"); + printf("\n"); + printf("user video width: %d\n", width); + printf("user video height: %d\n", height); + FrameBufferDumpInfo(&data->fb, "user"); } } @@ -705,42 +710,42 @@ void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible) if(visible) { - if(window->flags & SDL_WINDOW_FULLSCREEN) - { - if(videodata->SHFullScreen) - videodata->SHFullScreen(windowdata->hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON); - ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_HIDE); - } + if(window->flags & SDL_WINDOW_FULLSCREEN) + { + if(videodata->SHFullScreen) + videodata->SHFullScreen(windowdata->hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON); + ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_HIDE); + } - ShowWindow(windowdata->hwnd, SW_SHOW); + ShowWindow(windowdata->hwnd, SW_SHOW); SetForegroundWindow(windowdata->hwnd); - if(renderer && - (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) - { - WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata; - renderdata->flags &= ~FB_SUSPENDED; - if(renderdata->gapi) renderdata->gapi->GXResume(); - } + if(renderer && + (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) + { + WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata; + renderdata->flags &= ~FB_SUSPENDED; + if(renderdata->gapi) renderdata->gapi->GXResume(); + } } else { - if(renderer && - (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) - { - WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata; - if(renderdata->gapi) renderdata->gapi->GXSuspend(); - renderdata->flags |= FB_SUSPENDED; - } + if(renderer && + (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) + { + WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata; + if(renderdata->gapi) renderdata->gapi->GXSuspend(); + renderdata->flags |= FB_SUSPENDED; + } - ShowWindow(windowdata->hwnd, SW_HIDE); + ShowWindow(windowdata->hwnd, SW_HIDE); - if(window->flags & SDL_WINDOW_FULLSCREEN) - { - if(videodata->SHFullScreen) - videodata->SHFullScreen(windowdata->hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); - ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_SHOW); - } + if(window->flags & SDL_WINDOW_FULLSCREEN) + { + if(videodata->SHFullScreen) + videodata->SHFullScreen(windowdata->hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); + ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_SHOW); + } } } @@ -749,8 +754,8 @@ void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt) { WINCE_RenderData* data = (WINCE_RenderData*) window->renderer->driverdata; - pt->x *= data->scale; - pt->y *= data->scale; + pt->x = (LONG)(pt->x * data->scale); + pt->y = (LONG)(pt->y * data->scale); PointerRotate(pt, &data->fb, data->userOrientation); } @@ -758,44 +763,45 @@ void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt) void WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height) { if(data->systemOrientation != ORIENTATION_UP) - FrameBufferRotate(&data->fb, data->systemOrientation); + FrameBufferRotate(&data->fb, data->systemOrientation); - if(data->fb.width != width || data->fb.height != height) - switch(data->systemOrientation) - { - case ORIENTATION_UP: - case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break; - case ORIENTATION_RIGHT: - case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break; - default: break; + if(data->fb.width != width || data->fb.height != height) { + switch(data->systemOrientation) + { + case ORIENTATION_UP: + case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break; + case ORIENTATION_RIGHT: + case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break; + default: break; + } } if(data->userOrientation != ORIENTATION_UP) - FrameBufferRotate(&data->fb, data->userOrientation); + FrameBufferRotate(&data->fb, data->userOrientation); } void WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height) { switch(data->systemOrientation) { - case ORIENTATION_UP: FrameBufferRotate(&data->fb, ORIENTATION_LEFT); break; - case ORIENTATION_LEFT:FrameBufferRotate(&data->fb, ORIENTATION_DOWN); break; - case ORIENTATION_DOWN:FrameBufferRotate(&data->fb, ORIENTATION_RIGHT); break; - default: break; + case ORIENTATION_UP: FrameBufferRotate(&data->fb, ORIENTATION_LEFT); break; + case ORIENTATION_LEFT:FrameBufferRotate(&data->fb, ORIENTATION_DOWN); break; + case ORIENTATION_DOWN:FrameBufferRotate(&data->fb, ORIENTATION_RIGHT); break; + default: break; } if(data->fb.width != width || data->fb.height != height) switch(data->systemOrientation) { - case ORIENTATION_UP: - case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break; - case ORIENTATION_RIGHT: - case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break; - default: break; + case ORIENTATION_UP: + case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break; + case ORIENTATION_RIGHT: + case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break; + default: break; } if(data->userOrientation != ORIENTATION_UP) - FrameBufferRotate(&data->fb, data->userOrientation); + FrameBufferRotate(&data->fb, data->userOrientation); } void WINCE_SquareTransform(WINCE_RenderData* data, int width, int height) @@ -807,43 +813,43 @@ int WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug) { // check square if(GetSystemMetrics(SM_CXSCREEN) == GetSystemMetrics(SM_CYSCREEN) && - fb->width != fb->height) + fb->width != fb->height) { - if(fb->width < fb->height) - fb->height = fb->width; - else - if(fb->height < fb->width) - fb->width = fb->height; + if(fb->width < fb->height) + fb->height = fb->width; + else + if(fb->height < fb->width) + fb->width = fb->height; } // check width if(__abs(fb->xpitch) == bpp && - fb->width != __abs(fb->ypitch) / bpp) + fb->width != __abs(fb->ypitch) / bpp) { - if(fb->height == __abs(fb->ypitch) / bpp) - { - __swap(&fb->width, &fb->height); + if(fb->height == __abs(fb->ypitch) / bpp) + { + __swap(&fb->width, &fb->height); - if(debug) - printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height); - } - else - return -1; + if(debug) + printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height); + } + else + return -1; } else // check height if(__abs(fb->ypitch) == bpp && - fb->height != __abs(fb->xpitch) / bpp) + fb->height != __abs(fb->xpitch) / bpp) { - if(fb->width == __abs(fb->xpitch) / bpp) - { - __swap(&fb->width, &fb->height); + if(fb->width == __abs(fb->xpitch) / bpp) + { + __swap(&fb->width, &fb->height); - if(debug) - printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height); - } - else - return -1; + if(debug) + printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height); + } + else + return -1; } return 0; @@ -865,8 +871,12 @@ int GAPI_Init(WINCE_RenderData* data, HWND hwnd) { if(NULL == data->gapi) { - const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); - if(preferably && 0 != SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0; + struct GXDisplayProperties gxProperties; + GXDeviceInfo gxInfo = { 0 }; + HDC hdc; + int enable, result; + const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); + if(preferably && 0 != SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0; data->gapi = (GapiInfo *) SDL_calloc(1, sizeof(GapiInfo)); if(NULL == data->gapi) @@ -875,116 +885,116 @@ int GAPI_Init(WINCE_RenderData* data, HWND hwnd) return 0; } - data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll")); - if(0 == data->gapi->hGapiLib) - { - data->gapi->hGapiLib = LoadLibrary(TEXT("gx.dll")); - if(0 == data->gapi->hGapiLib) return 0; - } + data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll")); + if(0 == data->gapi->hGapiLib) + { + data->gapi->hGapiLib = LoadLibrary(TEXT("gx.dll")); + if(0 == data->gapi->hGapiLib) return 0; + } - // load gapi library + // load gapi library #define LINK(type,name,import) name=(PFN##type)GetProcAddress(data->gapi->hGapiLib,TEXT(import)) - LINK(GXOpenDisplay, data->gapi->GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z"); - LINK(GXCloseDisplay, data->gapi->GXCloseDisplay, "?GXCloseDisplay@@YAHXZ"); - LINK(GXBeginDraw, data->gapi->GXBeginDraw, "?GXBeginDraw@@YAPAXXZ"); - LINK(GXEndDraw, data->gapi->GXEndDraw, "?GXEndDraw@@YAHXZ"); - LINK(GXGetDisplayProperties,data->gapi->GXGetDisplayProperties,"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ"); - LINK(GXSuspend, data->gapi->GXSuspend, "?GXSuspend@@YAHXZ"); - LINK(GXResume, data->gapi->GXResume, "?GXResume@@YAHXZ"); + LINK(GXOpenDisplay, data->gapi->GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z"); + LINK(GXCloseDisplay, data->gapi->GXCloseDisplay, "?GXCloseDisplay@@YAHXZ"); + LINK(GXBeginDraw, data->gapi->GXBeginDraw, "?GXBeginDraw@@YAPAXXZ"); + LINK(GXEndDraw, data->gapi->GXEndDraw, "?GXEndDraw@@YAHXZ"); + LINK(GXGetDisplayProperties,data->gapi->GXGetDisplayProperties,"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ"); + LINK(GXSuspend, data->gapi->GXSuspend, "?GXSuspend@@YAHXZ"); + LINK(GXResume, data->gapi->GXResume, "?GXResume@@YAHXZ"); #undef LINK - int enable = data->gapi->GXGetDisplayProperties && data->gapi->GXCloseDisplay && data->gapi->GXOpenDisplay && - data->gapi->GXBeginDraw && data->gapi->GXEndDraw && data->gapi->GXSuspend && data->gapi->GXResume; + enable = data->gapi->GXGetDisplayProperties && data->gapi->GXCloseDisplay && data->gapi->GXOpenDisplay && + data->gapi->GXBeginDraw && data->gapi->GXEndDraw && data->gapi->GXSuspend && data->gapi->GXResume; - if(!enable) - { - SDL_SetError("GAPI_Init: error gx.dll: internal error"); - GAPI_Quit(data); - return 0; - } + if(!enable) + { + SDL_SetError("GAPI_Init: error gx.dll: internal error"); + GAPI_Quit(data); + return 0; + } - if(0 == data->gapi->GXOpenDisplay(hwnd, GX_FULLSCREEN)) - { - SDL_SetError("GAPI_Init: couldn't initialize GAPI"); - GAPI_Quit(data); - return 0; - } + if(0 == data->gapi->GXOpenDisplay(hwnd, GX_FULLSCREEN)) + { + SDL_SetError("GAPI_Init: couldn't initialize GAPI"); + GAPI_Quit(data); + return 0; + } - struct GXDisplayProperties gxProperties = data->gapi->GXGetDisplayProperties(); + gxProperties = data->gapi->GXGetDisplayProperties(); - // fill FrameBufferInfo - data->fb.xpitch = gxProperties.cbxPitch; - data->fb.ypitch = gxProperties.cbyPitch; - data->fb.width = gxProperties.cxWidth; - data->fb.height = gxProperties.cyHeight; - data->fb.offset = 0; + // fill FrameBufferInfo + data->fb.xpitch = gxProperties.cbxPitch; + data->fb.ypitch = gxProperties.cbyPitch; + data->fb.width = gxProperties.cxWidth; + data->fb.height = gxProperties.cyHeight; + data->fb.offset = 0; if((gxProperties.ffFormat & kfDirect565) || 16 == gxProperties.cBPP) - data->format = SDL_PIXELFORMAT_RGB565; - else - if((gxProperties.ffFormat & kfDirect555) || 15 == gxProperties.cBPP) - data->format = SDL_PIXELFORMAT_RGB555; - else - data->format = 0; + data->format = SDL_PIXELFORMAT_RGB565; + else + if((gxProperties.ffFormat & kfDirect555) || 15 == gxProperties.cBPP) + data->format = SDL_PIXELFORMAT_RGB555; + else + data->format = 0; - // get pixels - GXDeviceInfo gxInfo = { 0 }; - HDC hdc = GetDC(NULL); + // get pixels + hdc = GetDC(NULL); - gxInfo.Version = 100; - int result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *) &gxInfo); - ReleaseDC(NULL, hdc); + gxInfo.Version = 100; + result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *) &gxInfo); + ReleaseDC(NULL, hdc); - if(result > 0) - { - // more debug - if(data->debug) - { - printf("GXDeviceInfo.pvFrameBuffer: %p\n", gxInfo.pvFrameBuffer); - printf("GXDeviceInfo.cxWidth: %d\n", gxInfo.cxWidth); - printf("GXDeviceInfo.cyHeight: %d\n", gxInfo.cyHeight); - printf("GXDeviceInfo.cbStride: %d\n", gxInfo.cbStride); - printf("GXDeviceInfo.cBPP: %d\n", gxInfo.cBPP); - printf("GXDeviceInfo.ffFormat: 0x%x\n", gxInfo.ffFormat); + if(result > 0) + { + // more debug + if(data->debug) + { + int i; - printf("GXDeviceInfo.unk:\n"); - int ii; for(ii = 0; ii < sizeof(gxInfo.unknown); ++ii) - printf("0x%02hhX,", gxInfo.unknown[ii]); - printf("\n"); - } + printf("GXDeviceInfo.pvFrameBuffer: %p\n", gxInfo.pvFrameBuffer); + printf("GXDeviceInfo.cxWidth: %d\n", gxInfo.cxWidth); + printf("GXDeviceInfo.cyHeight: %d\n", gxInfo.cyHeight); + printf("GXDeviceInfo.cbStride: %d\n", gxInfo.cbStride); + printf("GXDeviceInfo.cBPP: %d\n", gxInfo.cBPP); + printf("GXDeviceInfo.ffFormat: 0x%x\n", gxInfo.ffFormat); - if(gxInfo.ffFormat && gxInfo.ffFormat != gxProperties.ffFormat) - { - if((gxInfo.ffFormat & kfDirect565) || 16 == gxInfo.cBPP) - data->format = SDL_PIXELFORMAT_RGB565; - else - if((gxInfo.ffFormat & kfDirect555) || 15 == gxInfo.cBPP) - data->format = SDL_PIXELFORMAT_RGB555; - } + printf("GXDeviceInfo.unk:\n"); + for(i = 0; i < sizeof(gxInfo.unknown); ++i) + printf("0x%02hhX,", gxInfo.unknown[i]); + printf("\n"); + } - data->pixels = gxInfo.pvFrameBuffer; + if(gxInfo.ffFormat && gxInfo.ffFormat != gxProperties.ffFormat) { + if((gxInfo.ffFormat & kfDirect565) || 16 == gxInfo.cBPP) + data->format = SDL_PIXELFORMAT_RGB565; + else + if((gxInfo.ffFormat & kfDirect555) || 15 == gxInfo.cBPP) + data->format = SDL_PIXELFORMAT_RGB555; + } + + data->pixels = gxInfo.pvFrameBuffer; } - else - { - data->flags |= FB_SKIP_OFFSET; - data->pixels = data->gapi->GXBeginDraw(); - data->gapi->GXEndDraw(); + else + { + data->flags |= FB_SKIP_OFFSET; + data->pixels = data->gapi->GXBeginDraw(); + data->gapi->GXEndDraw(); - if(data->debug) - { - printf("GAPI_Init\n"); - printf("use GXBeginDraw: %p\n", data->pixels); - printf("use skip offset\n"); - } - } + if(data->debug) + { + printf("GAPI_Init\n"); + printf("use GXBeginDraw: %p\n", data->pixels); + printf("use skip offset\n"); + } + } - if(0 == data->format || - 0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug)) - { - SDL_SetError("GAPI_Init: unknown hardware"); - GAPI_Quit(data); - return 0; - } + if(0 == data->format || + 0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug)) + { + SDL_SetError("GAPI_Init: unknown hardware"); + GAPI_Quit(data); + return 0; + } } return data->gapi && data->pixels ? 1 : 0; @@ -994,28 +1004,30 @@ void GAPI_Quit(WINCE_RenderData* data) { if(data->gapi) { - if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); - if(data->gapi->hGapiLib) FreeLibrary(data->gapi->hGapiLib); + if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); + if(data->gapi->hGapiLib) FreeLibrary(data->gapi->hGapiLib); - SDL_free(data->gapi); + SDL_free(data->gapi); data->gapi = NULL; } } int RAW_Init(WINCE_RenderData* data) { + RawFrameBufferInfo rfbi = { 0 }; + HDC hdc; + int result; const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); if(preferably && 0 != SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0; - RawFrameBufferInfo rfbi = { 0 }; - HDC hdc = GetDC(NULL); - int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); + hdc = GetDC(NULL); + result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); ReleaseDC(NULL, hdc); //disable if(result == 0 || rfbi.pFramePointer == 0 || - rfbi.cxPixels == 0 || rfbi.cyPixels == 0 || - rfbi.cxStride == 0 || rfbi.cyStride == 0) return 0; + rfbi.cxPixels == 0 || rfbi.cyPixels == 0 || + rfbi.cxStride == 0 || rfbi.cyStride == 0) return 0; data->flags = FB_RAW_MODE; @@ -1029,19 +1041,19 @@ int RAW_Init(WINCE_RenderData* data) data->fb.offset = 0; if((FORMAT_565 & rfbi.wFormat) || 16 == rfbi.wBPP) - data->format = SDL_PIXELFORMAT_RGB565; + data->format = SDL_PIXELFORMAT_RGB565; else if((FORMAT_555 & rfbi.wFormat) || 15 == rfbi.wBPP) - data->format = SDL_PIXELFORMAT_RGB555; + data->format = SDL_PIXELFORMAT_RGB555; else - data->format = 0; + data->format = 0; if(0 == data->format || - 0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug)) + 0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug)) { - SDL_SetError("RAW_Init: unknown hardware"); - RAW_Quit(data); - return 0; + SDL_SetError("RAW_Init: unknown hardware"); + RAW_Quit(data); + return 0; } data->pixels = rfbi.pFramePointer; @@ -1060,50 +1072,50 @@ void FrameBufferInitialize(FrameBufferInfo* fb) // set correct start offset switch(orientation) { - case ORIENTATION_UP: - fb->offset = 0; - break; + case ORIENTATION_UP: + fb->offset = 0; + break; - case ORIENTATION_LEFT: - fb->offset = __abs(fb->ypitch * (fb->height - 1)); - break; + case ORIENTATION_LEFT: + fb->offset = __abs(fb->ypitch * (fb->height - 1)); + break; - case ORIENTATION_RIGHT: - fb->offset = __abs(fb->xpitch * (fb->width - 1)); - break; + case ORIENTATION_RIGHT: + fb->offset = __abs(fb->xpitch * (fb->width - 1)); + break; - case ORIENTATION_DOWN: - fb->offset = __abs(fb->xpitch * (fb->width - 1) + - fb->ypitch * (fb->height - 1)); - break; + case ORIENTATION_DOWN: + fb->offset = __abs(fb->xpitch * (fb->width - 1) + + fb->ypitch * (fb->height - 1)); + break; - default: break; + default: break; } //if(orientation != ORIENTATION_UP) switch(orientation) { - case ORIENTATION_LEFT: FrameBufferRotate(fb, ORIENTATION_RIGHT); break; - case ORIENTATION_RIGHT:FrameBufferRotate(fb, ORIENTATION_LEFT); break; - case ORIENTATION_DOWN: FrameBufferRotate(fb, ORIENTATION_DOWN); break; + case ORIENTATION_LEFT: FrameBufferRotate(fb, ORIENTATION_RIGHT); break; + case ORIENTATION_RIGHT:FrameBufferRotate(fb, ORIENTATION_LEFT); break; + case ORIENTATION_DOWN: FrameBufferRotate(fb, ORIENTATION_DOWN); break; - default: break; + default: break; } } int GetFrameBufferOrientation(const FrameBufferInfo* src) { if(src->xpitch > 0 && src->ypitch > 0) - return ORIENTATION_UP; + return ORIENTATION_UP; else if(src->xpitch > 0 && src->ypitch < 0) - return ORIENTATION_LEFT; + return ORIENTATION_LEFT; else if(src->xpitch < 0 && src->ypitch > 0) - return ORIENTATION_RIGHT; + return ORIENTATION_RIGHT; else if(src->xpitch < 0 && src->ypitch < 0) - return ORIENTATION_DOWN; + return ORIENTATION_DOWN; return ORIENTATION_UNKNOWN; } @@ -1117,28 +1129,28 @@ void FrameBufferRotate(FrameBufferInfo* dst, int orientation) switch(orientation) { case ORIENTATION_LEFT: - dst->width = src.height; - dst->height = src.width; - dst->xpitch = src.ypitch; - dst->ypitch = -src.xpitch; - dst->offset = src.offset + src.xpitch * (src.width - 1); - break; + dst->width = src.height; + dst->height = src.width; + dst->xpitch = src.ypitch; + dst->ypitch = -src.xpitch; + dst->offset = src.offset + src.xpitch * (src.width - 1); + break; case ORIENTATION_RIGHT: - dst->width = src.height; - dst->height = src.width; - dst->xpitch = -src.ypitch; - dst->ypitch = src.xpitch; - dst->offset = src.offset + src.ypitch * (src.height - 1); - break; + dst->width = src.height; + dst->height = src.width; + dst->xpitch = -src.ypitch; + dst->ypitch = src.xpitch; + dst->offset = src.offset + src.ypitch * (src.height - 1); + break; case ORIENTATION_DOWN: - FrameBufferRotate(dst, ORIENTATION_LEFT); - FrameBufferRotate(dst, ORIENTATION_LEFT); - break; + FrameBufferRotate(dst, ORIENTATION_LEFT); + FrameBufferRotate(dst, ORIENTATION_LEFT); + break; default: - break; + break; } } @@ -1146,31 +1158,31 @@ void PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation) { switch(orientation) { - case ORIENTATION_UP: - break; + case ORIENTATION_UP: + break; - case ORIENTATION_LEFT: - { - int temp = pt->y; - pt->y = fb->height - pt->x; - pt->x = temp; - } - break; + case ORIENTATION_LEFT: + { + int temp = pt->y; + pt->y = fb->height - pt->x; + pt->x = temp; + } + break; - case ORIENTATION_RIGHT: - { - int temp = pt->x; - pt->x = fb->width - pt->y; - pt->y = temp; - } - break; + case ORIENTATION_RIGHT: + { + int temp = pt->x; + pt->x = fb->width - pt->y; + pt->y = temp; + } + break; - case ORIENTATION_DOWN: - pt->x = fb->width - pt->x; - pt->y = fb->height - pt->y; - break; + case ORIENTATION_DOWN: + pt->x = fb->width - pt->x; + pt->y = fb->height - pt->y; + break; - default: break; + default: break; } } @@ -1196,14 +1208,14 @@ int WINCE_GetDMOrientation(void) // DMDO_0, DMDO_90, DMDO_180, DMDO_270 if(DISP_CHANGE_BADMODE != ChangeDisplaySettingsEx(NULL, &sDevMode, 0, CDS_TEST, NULL)) - switch(sDevMode.dmDisplayOrientation) - { - case DMDO_0: return DMDO_0; - case DMDO_90: return DMDO_90; - case DMDO_180: return DMDO_180; - case DMDO_270: return DMDO_270; - default: break; - } + switch(sDevMode.dmDisplayOrientation) + { + case DMDO_0: return DMDO_0; + case DMDO_90: return DMDO_90; + case DMDO_180: return DMDO_180; + case DMDO_270: return DMDO_270; + default: break; + } SDL_SetError("WINCE_GetDMOrientation: ChangeDisplaySettingsEx return BADMODE"); return -1; @@ -1217,15 +1229,15 @@ int WINCE_SetDMOrientation(int orientation) switch(orientation) { - case DMDO_0: sDevMode.dmDisplayOrientation = DMDO_0; break; - case DMDO_90: sDevMode.dmDisplayOrientation = DMDO_90; break; - case DMDO_180: sDevMode.dmDisplayOrientation = DMDO_180; break; - case DMDO_270: sDevMode.dmDisplayOrientation = DMDO_270; break; - default: return 0; + case DMDO_0: sDevMode.dmDisplayOrientation = DMDO_0; break; + case DMDO_90: sDevMode.dmDisplayOrientation = DMDO_90; break; + case DMDO_180: sDevMode.dmDisplayOrientation = DMDO_180; break; + case DMDO_270: sDevMode.dmDisplayOrientation = DMDO_270; break; + default: return 0; } if(DISP_CHANGE_BADMODE != ChangeDisplaySettingsEx(NULL, &sDevMode, 0, CDS_RESET, NULL)) - return 1; + return 1; SDL_SetError("WINCE_SetDMOrientation: ChangeDisplaySettingsEx return BADMODE"); return -1; @@ -1233,13 +1245,15 @@ int WINCE_SetDMOrientation(int orientation) void FrameBufferDumpInfo(const FrameBufferInfo* fb, const char* name) { + int orientation; + printf("%s fb.width: %d\n", name, fb->width); printf("%s fb.height: %d\n", name, fb->height); printf("%s fb.xpitch: %d\n", name, fb->xpitch); printf("%s fb.ypitch: %d\n", name, fb->ypitch); printf("%s fb.offset: %d\n", name, fb->offset); - int orientation = GetFrameBufferOrientation(fb); + orientation = GetFrameBufferOrientation(fb); printf("%s fb.orientation: %d, %s\n", name, orientation, GetOrientationName(orientation)); } @@ -1247,34 +1261,34 @@ void UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, { if(2 == fb->xpitch) { - switch(width) - { - case 1: - *dst = *src; - break; + switch(width) + { + case 1: + *dst = *src; + break; - case 2: - *((Uint32*) dst) = *((Uint32*) src); - break; + case 2: + *((Uint32*) dst) = *((Uint32*) src); + break; - default: - SDL_memcpy(dst, src, width * 2); - break; - } + default: + SDL_memcpy(dst, src, width * 2); + break; + } } else if(-2 == fb->xpitch) { - while(width--) - *dst-- = *src++; + while(width--) + *dst-- = *src++; } else { - while(width--) - { - *dst = *src++; - dst += fb->xpitch / 2; - } + while(width--) + { + *dst = *src++; + dst += fb->xpitch / 2; + } } } diff --git a/src/video/windows/SDL_gdirender.c b/src/video/windows/SDL_gdirender.c index c52366117..06ab8686f 100644 --- a/src/video/windows/SDL_gdirender.c +++ b/src/video/windows/SDL_gdirender.c @@ -167,8 +167,10 @@ GDI_CreateRenderer(SDL_Window * window, Uint32 flags) SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; SDL_Renderer *renderer; GDI_RenderData *data; +#ifndef NO_GETDIBBITS int bmi_size; HBITMAP hbm; +#endif int i, n; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 563d5d7bd..89e9d2804 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -192,20 +192,20 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: #ifdef _WIN32_WCE - /* transform coords for VGA, WVGA... */ - { - SDL_VideoData *videodata = data->videodata; - if(videodata->CoordTransform && - (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) - { - POINT pt; - pt.x = LOWORD(lParam); - pt.y = HIWORD(lParam); - videodata->CoordTransform(data->window, &pt); - SDL_SendMouseMotion(data->window, 0, pt.x, pt.y); - break; - } - } + /* transform coords for VGA, WVGA... */ + { + SDL_VideoData *videodata = data->videodata; + if(videodata->CoordTransform && + (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) + { + POINT pt; + pt.x = LOWORD(lParam); + pt.y = HIWORD(lParam); + videodata->CoordTransform(data->window, &pt); + SDL_SendMouseMotion(data->window, 0, pt.x, pt.y); + break; + } + } #endif SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam)); break; @@ -252,12 +252,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) break; } +#ifdef WM_MOUSELEAVE + /* FIXME: Do we need the SDL 1.2 hack to generate WM_MOUSELEAVE now? */ case WM_MOUSELEAVE: if (SDL_GetMouseFocus() == data->window) { SDL_SetMouseFocus(NULL); } returnCode = 0; break; +#endif /* WM_MOUSELEAVE */ case WM_SYSKEYDOWN: case WM_KEYDOWN: @@ -382,13 +385,16 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) returnCode = 0; break; +#ifdef WM_INPUTLANGCHANGE case WM_INPUTLANGCHANGE: { WIN_UpdateKeymap(); } returnCode = 1; break; +#endif /* WM_INPUTLANGCHANGE */ +#ifdef WM_GETMINMAXINFO case WM_GETMINMAXINFO: { MINMAXINFO *info; @@ -447,6 +453,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } returnCode = 0; break; +#endif /* WM_GETMINMAXINFO */ case WM_WINDOWPOSCHANGED: { @@ -534,6 +541,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } return (1); +#if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER) case WM_SYSCOMMAND: { /* Don't start the screensaver or blank the monitor in fullscreen apps */ @@ -545,6 +553,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } } break; +#endif /* System has screensaver support */ case WM_CLOSE: { @@ -656,7 +665,9 @@ SDL_RegisterApp(char *name, Uint32 style, void *hInst) } if (!name && !SDL_Appname) { name = "SDL_app"; +#if defined(CS_BYTEALIGNCLIENT) || defined(CS_OWNDC) SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC); +#endif SDL_Instance = hInst ? hInst : GetModuleHandle(NULL); } diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index 4f442f2e1..45fd8284e 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -21,6 +21,10 @@ */ #include "SDL_config.h" +#ifdef _WIN32_WCE +#define SDL_DISABLE_WINDOWS_IME +#endif + #include "SDL_windowsvideo.h" #include "../../events/SDL_keyboard_c.h" @@ -29,10 +33,12 @@ #include #include +#ifndef SDL_DISABLE_WINDOWS_IME static void IME_Init(SDL_VideoData *videodata, HWND hwnd); static void IME_Enable(SDL_VideoData *videodata, HWND hwnd); static void IME_Disable(SDL_VideoData *videodata, HWND hwnd); static void IME_Quit(SDL_VideoData *videodata); +#endif /* !SDL_DISABLE_WINDOWS_IME */ #ifndef MAPVK_VK_TO_VSC #define MAPVK_VK_TO_VSC 0 @@ -172,12 +178,15 @@ WIN_UpdateKeymap() void WIN_QuitKeyboard(_THIS) { +#ifndef SDL_DISABLE_WINDOWS_IME IME_Quit((SDL_VideoData *)_this->driverdata); +#endif } void WIN_StartTextInput(_THIS) { +#ifndef SDL_DISABLE_WINDOWS_IME SDL_Window *window = SDL_GetKeyboardFocus(); if (window) { HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; @@ -186,11 +195,13 @@ WIN_StartTextInput(_THIS) IME_Init(videodata, hwnd); IME_Enable(videodata, hwnd); } +#endif /* !SDL_DISABLE_WINDOWS_IME */ } void WIN_StopTextInput(_THIS) { +#ifndef SDL_DISABLE_WINDOWS_IME SDL_Window *window = SDL_GetKeyboardFocus(); if (window) { HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; @@ -198,6 +209,7 @@ WIN_StopTextInput(_THIS) IME_Init(videodata, hwnd); IME_Disable(videodata, hwnd); } +#endif /* !SDL_DISABLE_WINDOWS_IME */ } void @@ -207,6 +219,21 @@ WIN_SetTextInputRect(_THIS, SDL_Rect *rect) videodata->ime_rect = *rect; } +#ifdef SDL_DISABLE_WINDOWS_IME + + +SDL_bool +IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoData *videodata) +{ + return SDL_FALSE; +} + +void IME_Present(SDL_VideoData *videodata) +{ +} + +#else + #ifdef __GNUC__ #undef DEFINE_GUID #define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) static const GUID n = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} @@ -1552,4 +1579,6 @@ void IME_Present(SDL_VideoData *videodata) SDL_RenderCopy(videodata->ime_candtex, NULL, &videodata->ime_candlistrect); } +#endif /* SDL_DISABLE_WINDOWS_IME */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index bd6bbf276..62ff9553c 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -23,13 +23,19 @@ #include "SDL_windowsvideo.h" +/* Windows CE compatibility */ +#ifndef CDS_FULLSCREEN +#define CDS_FULLSCREEN 0 +#endif static SDL_bool WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode) { SDL_DisplayModeData *data; DEVMODE devmode; +#ifndef _WIN32_WCE HDC hdc; +#endif devmode.dmSize = sizeof(devmode); devmode.dmDriverExtra = 0; diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 38f0a071e..3d053fd44 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -161,9 +161,9 @@ WIN_CreateDevice(int devindex) data->userDLL = LoadLibrary(TEXT("USER32.DLL")); if (data->userDLL) { - data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(data->userDLL, "CloseTouchInputHandle"); - data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(data->userDLL, "GetTouchInputInfo"); - data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(data->userDLL, "RegisterTouchWindow"); + data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(data->userDLL, TEXT("CloseTouchInputHandle")); + data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(data->userDLL, TEXT("GetTouchInputInfo")); + data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(data->userDLL, TEXT("RegisterTouchWindow")); } /* Set the function pointers */ @@ -222,11 +222,7 @@ WIN_CreateDevice(int devindex) } VideoBootStrap WINDOWS_bootstrap = { -#ifdef _WIN32_WCE - "wince", "SDL WinCE video driver", WINCE_Available, WIN_CreateDevice -#else - "windows", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice -#endif + "windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice }; int diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index 9051b11b9..895aa08c0 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -36,7 +36,7 @@ #include -#ifndef __GNUC__ +#if defined(_MSC_VER) && !defined(_WIN32_WCE) #include #else #include "SDL_msctf.h" diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 9a2ec5a63..2302a33f5 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -32,6 +32,10 @@ #include "SDL_syswm.h" #include "SDL_gapirender.h" +/* Windows CE compatibility */ +#ifndef SWP_NOCOPYBITS +#define SWP_NOCOPYBITS 0 +#endif /* Fake window to help with DirectInput events. */ HWND SDL_HelperWindow = NULL; @@ -68,13 +72,21 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) } /* Set up the window proc function */ +#ifdef GWLP_WNDPROC data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC); if (data->wndproc == WIN_WindowProc) { data->wndproc = NULL; - } - else { + } else { SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc); } +#else + data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC); + if (data->wndproc == WIN_WindowProc) { + data->wndproc = NULL; + } else { + SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc); + } +#endif /* Fill in the SDL window with the window data */ { @@ -112,14 +124,20 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) } else { window->flags &= ~SDL_WINDOW_RESIZABLE; } +#ifdef WS_MAXIMIZE if (style & WS_MAXIMIZE) { window->flags |= SDL_WINDOW_MAXIMIZED; - } else { + } else +#endif + { window->flags &= ~SDL_WINDOW_MAXIMIZED; } +#ifdef WS_MINIMIZE if (style & WS_MINIMIZE) { window->flags |= SDL_WINDOW_MINIMIZED; - } else { + } else +#endif + { window->flags &= ~SDL_WINDOW_MINIMIZED; } } diff --git a/test/testgesture.c b/test/testgesture.c index 29f7106f0..0667c539e 100644 --- a/test/testgesture.c +++ b/test/testgesture.c @@ -19,14 +19,14 @@ #define PRIu32 "u" #endif #ifndef PRIs64 -#ifdef __WINDOWS__ +#ifdef __WIN32__ #define PRIs64 "I64" #else #define PRIs64 "lld" #endif #endif #ifndef PRIu64 -#ifdef __WINDOWS__ +#ifdef __WIN32__ #define PRIu64 "I64u" #else #define PRIu64 "llu" From eec2c075f84bcf2b701125c44c5a872f15575ec0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 16:10:13 -0800 Subject: [PATCH 06/44] Fixed bug #1103 The SDL_blendmode.h and SDL_scalemode.h headers needed to be added to the Public Headers and all the public headers need to have the "Public" role set. --- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 168660b9c..11df392d2 100755 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -123,6 +123,10 @@ 00D8DA2A1195093100638393 /* testsdl.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA1A1195093100638393 /* testsdl.c */; }; 044E5F8511E6051C0076F181 /* SDL_clipboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 044E5F8411E6051C0076F181 /* SDL_clipboard.h */; settings = {ATTRIBUTES = (Public, ); }; }; 044E5F8611E6051C0076F181 /* SDL_clipboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 044E5F8411E6051C0076F181 /* SDL_clipboard.h */; }; + 0469A10B12EE4BF100B846D6 /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469A10912EE4BF100B846D6 /* SDL_blendmode.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 0469A10C12EE4BF100B846D6 /* SDL_scalemode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469A10A12EE4BF100B846D6 /* SDL_scalemode.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 0469A10D12EE4BF100B846D6 /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469A10912EE4BF100B846D6 /* SDL_blendmode.h */; }; + 0469A10E12EE4BF100B846D6 /* SDL_scalemode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469A10A12EE4BF100B846D6 /* SDL_scalemode.h */; }; 04BD000812E6671800899322 /* SDL_diskaudio.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFD8812E6671700899322 /* SDL_diskaudio.c */; }; 04BD000912E6671800899322 /* SDL_diskaudio.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFD8912E6671700899322 /* SDL_diskaudio.h */; }; 04BD001012E6671800899322 /* SDL_dummyaudio.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFD9412E6671700899322 /* SDL_dummyaudio.c */; }; @@ -578,7 +582,7 @@ 04DEA57311E6006A00386CAC /* SDL_input.h in Headers */ = {isa = PBXBuildFile; fileRef = 04DEA56F11E6006A00386CAC /* SDL_input.h */; }; 04F2AF691104AC4500D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF681104AC4500D6DDF7 /* SDL_assert.h */; settings = {ATTRIBUTES = (Public, ); }; }; 04F2AF6A1104AC4500D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF681104AC4500D6DDF7 /* SDL_assert.h */; }; - 453773821207C518002F0F45 /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 453773811207C518002F0F45 /* SDL_shape.h */; }; + 453773821207C518002F0F45 /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 453773811207C518002F0F45 /* SDL_shape.h */; settings = {ATTRIBUTES = (Public, ); }; }; 8CB0A77811F6A87F00CBA2DE /* SDL_gesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CB0A77611F6A87F00CBA2DE /* SDL_gesture.h */; settings = {ATTRIBUTES = (Public, ); }; }; 8CB0A77911F6A87F00CBA2DE /* SDL_touch.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CB0A77711F6A87F00CBA2DE /* SDL_touch.h */; settings = {ATTRIBUTES = (Public, ); }; }; BECDF6760761BA81005FE872 /* SDL_cpuinfo.h in Headers */ = {isa = PBXBuildFile; fileRef = B2CF8DC405C444E400E5DC7F /* SDL_cpuinfo.h */; }; @@ -711,6 +715,8 @@ 00D8DA1A1195093100638393 /* testsdl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testsdl.c; path = ../../test/automated/testsdl.c; sourceTree = SOURCE_ROOT; }; 00F5D79E0990CA0D0051C449 /* UniversalBinaryNotes.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = UniversalBinaryNotes.rtf; sourceTree = ""; }; 044E5F8411E6051C0076F181 /* SDL_clipboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_clipboard.h; path = ../../include/SDL_clipboard.h; sourceTree = SOURCE_ROOT; }; + 0469A10912EE4BF100B846D6 /* SDL_blendmode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_blendmode.h; path = ../../include/SDL_blendmode.h; sourceTree = SOURCE_ROOT; }; + 0469A10A12EE4BF100B846D6 /* SDL_scalemode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_scalemode.h; path = ../../include/SDL_scalemode.h; sourceTree = SOURCE_ROOT; }; 04BDFD7412E6671700899322 /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = ""; }; 04BDFD7512E6671700899322 /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = ""; }; 04BDFD8812E6671700899322 /* SDL_diskaudio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_diskaudio.c; sourceTree = ""; }; @@ -1141,14 +1147,13 @@ 0153844A006D81B07F000001 /* Public Headers */ = { isa = PBXGroup; children = ( - 8CB0A77611F6A87F00CBA2DE /* SDL_gesture.h */, - 8CB0A77711F6A87F00CBA2DE /* SDL_touch.h */, 0C5AF5E501191D2B7F000001 /* begin_code.h */, 0C5AF5E601191D2B7F000001 /* close_code.h */, 0C5AF5FF01191D2B7F000001 /* SDL.h */, 04F2AF681104AC4500D6DDF7 /* SDL_assert.h */, 00CFA67A106B44CE00758660 /* SDL_atomic.h */, 0C5AF5E801191D2B7F000001 /* SDL_audio.h */, + 0469A10912EE4BF100B846D6 /* SDL_blendmode.h */, 044E5F8411E6051C0076F181 /* SDL_clipboard.h */, 00CFA67B106B44CE00758660 /* SDL_compat.h */, 00162D3709BD1FA90037C8D0 /* SDL_config.h */, @@ -1158,6 +1163,7 @@ 0C5AF5EC01191D2B7F000001 /* SDL_endian.h */, 0C5AF5ED01191D2B7F000001 /* SDL_error.h */, 0C5AF5EE01191D2B7F000001 /* SDL_events.h */, + 8CB0A77611F6A87F00CBA2DE /* SDL_gesture.h */, 00CFA67C106B44CE00758660 /* SDL_haptic.h */, 04DEA56F11E6006A00386CAC /* SDL_input.h */, 0C5AF5F001191D2B7F000001 /* SDL_joystick.h */, @@ -1176,6 +1182,7 @@ 00CFA67F106B44CE00758660 /* SDL_rect.h */, 00A6EBD91078D569001EEA06 /* SDL_revision.h */, 0C5AF5F801191D2B7F000001 /* SDL_rwops.h */, + 0469A10A12EE4BF100B846D6 /* SDL_scalemode.h */, 00CFA680106B44CE00758660 /* SDL_scancode.h */, 453773811207C518002F0F45 /* SDL_shape.h */, 00162D3909BD1FA90037C8D0 /* SDL_stdinc.h */, @@ -1183,6 +1190,7 @@ 0C5AF5F901191D2B7F000001 /* SDL_syswm.h */, 0C5AF5FA01191D2B7F000001 /* SDL_thread.h */, 0C5AF5FB01191D2B7F000001 /* SDL_timer.h */, + 8CB0A77711F6A87F00CBA2DE /* SDL_touch.h */, 0C5AF5FC01191D2B7F000001 /* SDL_types.h */, 0C5AF5FD01191D2B7F000001 /* SDL_version.h */, 0C5AF5FE01191D2B7F000001 /* SDL_video.h */, @@ -1952,6 +1960,8 @@ 04BD020712E6671800899322 /* Xvlib.h in Headers */, 04BD020812E6671800899322 /* Xvproto.h in Headers */, 04BD021512E6671800899322 /* Xvlibint.h in Headers */, + 0469A10B12EE4BF100B846D6 /* SDL_blendmode.h in Headers */, + 0469A10C12EE4BF100B846D6 /* SDL_scalemode.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2080,6 +2090,8 @@ 04BD041F12E6671800899322 /* Xvlib.h in Headers */, 04BD042012E6671800899322 /* Xvproto.h in Headers */, 04BD042C12E6671800899322 /* Xvlibint.h in Headers */, + 0469A10D12EE4BF100B846D6 /* SDL_blendmode.h in Headers */, + 0469A10E12EE4BF100B846D6 /* SDL_scalemode.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; From 57ac355cb5b712ccd722290e63b7a67eec6e3de0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 17:38:18 -0800 Subject: [PATCH 07/44] Fixed bug #1100 Test the video features with #if instead of #ifdef --- include/SDL_config_macosx.h | 10 ++++++++++ include/SDL_config_windows.h | 12 ++++++++++++ src/video/cocoa/SDL_cocoavideo.m | 2 +- src/video/windows/SDL_windowsvideo.c | 2 +- src/video/windows/SDL_windowswindow.c | 2 +- src/video/x11/SDL_x11video.c | 2 +- src/video/x11/SDL_x11window.c | 2 +- 7 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h index 4a9f1862a..d070a36b5 100644 --- a/include/SDL_config_macosx.h +++ b/include/SDL_config_macosx.h @@ -148,13 +148,23 @@ #define SDL_VIDEO_DRIVER_X11_XV 1 #define SDL_VIDEO_DRIVER_X11_XSHAPE 1 +#ifndef SDL_VIDEO_RENDER_OGL #define SDL_VIDEO_RENDER_OGL 1 +#endif +#ifndef SDL_VIDEO_RENDER_X11 #define SDL_VIDEO_RENDER_X11 1 +#endif /* Enable OpenGL support */ +#ifndef SDL_VIDEO_OPENGL #define SDL_VIDEO_OPENGL 1 +#endif +#ifndef SDL_VIDEO_OPENGL_CGL #define SDL_VIDEO_OPENGL_CGL 1 +#endif +#ifndef SDL_VIDEO_OPENGL_GLX #define SDL_VIDEO_OPENGL_GLX 1 +#endif /* Enable system power support */ #define SDL_POWER_MACOSX 1 diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index f02d18f0b..698765727 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -179,18 +179,30 @@ typedef unsigned int uintptr_t; #define SDL_VIDEO_DRIVER_WINDOWS 1 #ifdef _WIN32_WCE +#ifndef SDL_VIDEO_RENDER_GAPI #define SDL_VIDEO_RENDER_GAPI 1 +#endif #else +#ifndef SDL_VIDEO_RENDER_D3D #define SDL_VIDEO_RENDER_D3D 1 #endif +#endif +#ifndef SDL_VIDEO_RENDER_GDI #define SDL_VIDEO_RENDER_GDI 1 +#endif /* Enable OpenGL support */ #ifndef _WIN32_WCE +#ifndef SDL_VIDEO_OPENGL #define SDL_VIDEO_OPENGL 1 +#endif +#ifndef SDL_VIDEO_OPENGL_WGL #define SDL_VIDEO_OPENGL_WGL 1 +#endif +#ifndef SDL_VIDEO_RENDER_OGL #define SDL_VIDEO_RENDER_OGL 1 #endif +#endif /* Enable system power support */ #define SDL_POWER_WINDOWS 1 diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index f1bb64f2d..78b1d7ee3 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -98,7 +98,7 @@ Cocoa_CreateDevice(int devindex) device->shape_driver.SetWindowShape = Cocoa_SetWindowShape; device->shape_driver.ResizeWindowShape = Cocoa_ResizeWindowShape; -#ifdef SDL_VIDEO_OPENGL_CGL +#if SDL_VIDEO_OPENGL_CGL device->GL_LoadLibrary = Cocoa_GL_LoadLibrary; device->GL_GetProcAddress = Cocoa_GL_GetProcAddress; device->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary; diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 3d053fd44..193f2d166 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -197,7 +197,7 @@ WIN_CreateDevice(int devindex) device->shape_driver.SetWindowShape = Win32_SetWindowShape; device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape; -#ifdef SDL_VIDEO_OPENGL_WGL +#if SDL_VIDEO_OPENGL_WGL device->GL_LoadLibrary = WIN_GL_LoadLibrary; device->GL_GetProcAddress = WIN_GL_GetProcAddress; device->GL_UnloadLibrary = WIN_GL_UnloadLibrary; diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 2302a33f5..00402c119 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -243,7 +243,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window) DestroyWindow(hwnd); return -1; } -#ifdef SDL_VIDEO_OPENGL_WGL +#if SDL_VIDEO_OPENGL_WGL if (window->flags & SDL_WINDOW_OPENGL) { if (WIN_GL_SetupWindow(_this, window) < 0) { WIN_DestroyWindow(_this, window); diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index ef6d8c4a9..09a3a666f 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -209,7 +209,7 @@ X11_CreateDevice(int devindex) device->shape_driver.CreateShaper = X11_CreateShaper; device->shape_driver.SetWindowShape = X11_SetWindowShape; device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape; -#ifdef SDL_VIDEO_OPENGL_GLX +#if SDL_VIDEO_OPENGL_GLX device->GL_LoadLibrary = X11_GL_LoadLibrary; device->GL_GetProcAddress = X11_GL_GetProcAddress; device->GL_UnloadLibrary = X11_GL_UnloadLibrary; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 9decd08db..0c5be5334 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -288,7 +288,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) } */ #endif -#ifdef SDL_VIDEO_OPENGL_GLX +#if SDL_VIDEO_OPENGL_GLX if (window->flags & SDL_WINDOW_OPENGL) { XVisualInfo *vinfo; From e1e1122ee038c1c34733970ef7c328dd430ddb54 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 17:47:18 -0800 Subject: [PATCH 08/44] Fixed bug #1102 Check /usr/local/bin for hg before sourcing the user's bash settings --- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 11df392d2..76f5c4137 100755 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -2292,7 +2292,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "# The underlying scripts require calling hg to get revision info.\n# Since hg may not be in the standard Xcode path, I am sourcing .bashrc\n# But I don't know what to do if people are using other shells.\nif test -f ~/.bash_profile; then source ~/.bash_profile; fi\nif test -f ~/.bashrc; then source ~/.bashrc; fi\nsh ../../build-scripts/updaterev.sh\n"; + shellScript = "# The official HG installer puts the binary in /usr/local/bin, so add that\n# to Xcode's path and see if the hg executable is found. Otherwise, source\n# the user's bash settings file as a last resort.\nPATH=$PATH:/usr/local/bin\nif ! which -s hg ; then\n if test -f ~/.bash_profile; then source ~/.bash_profile; fi\nfi\nsh ../../build-scripts/updaterev.sh\n"; }; 0083103E1072EA5700A531F1 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; From 01fa14dc420aef91b62097cdfb7a559098ceb311 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 21:20:30 -0800 Subject: [PATCH 09/44] Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share. I think this also fixes the bug relating to non-latin characters in filenames, since UNICODE wasn't defined in SDL_rwops.c --- Android.mk | 23 +++--- VisualC/SDL/SDL_VS2008.vcproj | 24 ++++-- VisualC/SDL/SDL_VS2010.vcxproj | 4 +- VisualCE/SDL/SDL.vcproj | 8 ++ src/SDL.c | 3 +- src/SDL_assert.c | 9 +- src/atomic/SDL_spinlock.c | 11 +-- src/audio/android/SDL_androidaudio.c | 2 +- src/audio/windib/SDL_dibaudio.c | 10 +-- src/audio/windx5/SDL_dx5audio.c | 20 ++--- src/audio/windx5/directx.h | 3 +- src/{ => core/android}/SDL_android.cpp | 0 src/{ => core/android}/SDL_android.h | 0 src/core/windows/SDL_windows.c | 41 +++++++++ src/core/windows/SDL_windows.h | 53 ++++++++++++ src/cpuinfo/SDL_cpuinfo.c | 3 +- src/file/SDL_rwops.c | 33 +++----- src/haptic/windows/SDL_syshaptic.c | 15 +++- src/joystick/android/SDL_sysjoystick.c | 2 +- src/joystick/windows/SDL_dxjoystick.c | 14 +++- src/joystick/windows/SDL_dxjoystick_c.h | 3 +- src/joystick/windows/SDL_mmjoystick.c | 3 +- src/loadso/windows/SDL_sysloadso.c | 105 +++++------------------- src/power/windows/SDL_syspower.c | 3 +- src/stdlib/SDL_getenv.c | 11 ++- src/thread/windows/SDL_sysmutex.c | 3 +- src/thread/windows/SDL_syssem.c | 3 +- src/thread/windows/SDL_systhread_c.h | 3 +- src/thread/windows/win_ce_semaphore.c | 3 +- src/timer/wince/SDL_systimer.c | 3 +- src/timer/windows/SDL_systimer.c | 3 +- src/video/android/SDL_androidgl.c | 2 +- src/video/windows/SDL_gapirender.c | 26 +++--- src/video/windows/SDL_windowskeyboard.c | 20 ++--- src/video/windows/SDL_windowsopengl.c | 2 +- src/video/windows/SDL_windowsvideo.c | 47 ++++------- src/video/windows/SDL_windowsvideo.h | 29 ++----- 37 files changed, 274 insertions(+), 273 deletions(-) rename src/{ => core/android}/SDL_android.cpp (100%) rename src/{ => core/android}/SDL_android.h (100%) create mode 100644 src/core/windows/SDL_windows.c create mode 100644 src/core/windows/SDL_windows.h diff --git a/Android.mk b/Android.mk index 12f683b3d..984050699 100755 --- a/Android.mk +++ b/Android.mk @@ -12,30 +12,31 @@ LOCAL_MODULE := SDL LOCAL_C_INCLUDES := $(LOCAL_PATH)/include -LOCAL_SRC_FILES := src/SDL_android.cpp \ +LOCAL_SRC_FILES := \ $(subst $(LOCAL_PATH)/,, \ $(wildcard $(LOCAL_PATH)/src/*.c) \ $(wildcard $(LOCAL_PATH)/src/audio/*.c) \ + $(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \ + $(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \ $(LOCAL_PATH)/src/atomic/SDL_atomic.c \ $(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \ + $(wildcard $(LOCAL_PATH)/src/core/android/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \ $(wildcard $(LOCAL_PATH)/src/events/*.c) \ $(wildcard $(LOCAL_PATH)/src/file/*.c) \ - $(wildcard $(LOCAL_PATH)/src/joystick/*.c) \ $(wildcard $(LOCAL_PATH)/src/haptic/*.c) \ + $(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \ + $(wildcard $(LOCAL_PATH)/src/joystick/*.c) \ + $(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \ + $(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c)) \ + $(wildcard $(LOCAL_PATH)/src/power/*.c) \ $(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \ $(wildcard $(LOCAL_PATH)/src/thread/*.c) \ - $(wildcard $(LOCAL_PATH)/src/timer/*.c) \ - $(wildcard $(LOCAL_PATH)/src/video/*.c) \ - $(wildcard $(LOCAL_PATH)/src/power/*.c) \ - $(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \ - $(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \ - $(wildcard $(LOCAL_PATH)/src/video/android/*.c) \ - $(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \ - $(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \ $(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \ + $(wildcard $(LOCAL_PATH)/src/timer/*.c) \ $(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \ - $(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c)) + $(wildcard $(LOCAL_PATH)/src/video/*.c) \ + $(wildcard $(LOCAL_PATH)/src/video/android/*.c) LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog diff --git a/VisualC/SDL/SDL_VS2008.vcproj b/VisualC/SDL/SDL_VS2008.vcproj index 35fdbc306..71608ed98 100644 --- a/VisualC/SDL/SDL_VS2008.vcproj +++ b/VisualC/SDL/SDL_VS2008.vcproj @@ -1150,6 +1150,22 @@ RelativePath="..\..\src\audio\SDL_wave.h" > + + + + + + + + @@ -1230,14 +1246,6 @@ RelativePath="..\..\src\video\windows\SDL_windowswindow.h" > - - - - diff --git a/VisualC/SDL/SDL_VS2010.vcxproj b/VisualC/SDL/SDL_VS2010.vcxproj index cf3a604cc..d0bd7263f 100644 --- a/VisualC/SDL/SDL_VS2010.vcxproj +++ b/VisualC/SDL/SDL_VS2010.vcxproj @@ -272,6 +272,7 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" + @@ -345,6 +346,7 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" + @@ -460,4 +462,4 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" - + \ No newline at end of file diff --git a/VisualCE/SDL/SDL.vcproj b/VisualCE/SDL/SDL.vcproj index ca83d77ac..3e6c09e2d 100644 --- a/VisualCE/SDL/SDL.vcproj +++ b/VisualCE/SDL/SDL.vcproj @@ -1053,6 +1053,10 @@ RelativePath="..\..\src\events\SDL_windowevents.c" > + + @@ -1358,6 +1362,10 @@ RelativePath="..\..\src\events\SDL_windowevents_c.h" > + + diff --git a/src/SDL.c b/src/SDL.c index 49620a8e1..cfd73f792 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -329,8 +329,7 @@ SDL_GetPlatform() #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL)) /* Need to include DllMain() on Watcom C for some reason.. */ -#define WIN32_LEAN_AND_MEAN -#include +#include "core/windows/SDL_windows.h" BOOL APIENTRY _DllMainCRTStartup(HANDLE hModule, diff --git a/src/SDL_assert.c b/src/SDL_assert.c index 38ee92560..4af552908 100644 --- a/src/SDL_assert.c +++ b/src/SDL_assert.c @@ -27,18 +27,11 @@ #include "video/SDL_sysvideo.h" #ifdef __WIN32__ -#define WIN32_LEAN_AND_MEAN -#include +#include "core/windows/SDL_windows.h" #ifndef WS_OVERLAPPEDWINDOW #define WS_OVERLAPPEDWINDOW 0 #endif - -#ifdef UNICODE -#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1) -#else -#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1) -#endif #else /* fprintf, _exit(), etc. */ #include #include diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index 9d9a136d9..b28b696ae 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -25,14 +25,7 @@ #include "SDL_timer.h" /* Don't do the check for Visual Studio 2005, it's safe here */ -#if defined(_MSC_VER) -#ifdef _WIN32_WCE -#define WIN32_LEAN_AND_MEAN -#include -#else -#include -#endif -#endif /* _MSC_VER */ +#include "../core/windows/SDL_windows.h" /* This function is where all the magic happens... */ SDL_bool @@ -40,7 +33,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) { #if defined(_MSC_VER) SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); - return (_InterlockedExchange((long*)lock, 1) == 0); + return (InterlockedExchange((long*)lock, 1) == 0); #elif defined(__MACOSX__) return OSAtomicCompareAndSwap32Barrier(0, 1, lock); diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c index 5f62339da..cdb39eb0d 100644 --- a/src/audio/android/SDL_androidaudio.c +++ b/src/audio/android/SDL_androidaudio.c @@ -27,7 +27,7 @@ #include "../SDL_audio_c.h" #include "SDL_androidaudio.h" -#include "../../SDL_android.h" +#include "../../core/android/SDL_android.h" #include diff --git a/src/audio/windib/SDL_dibaudio.c b/src/audio/windib/SDL_dibaudio.c index 7640c5eee..aee271213 100644 --- a/src/audio/windib/SDL_dibaudio.c +++ b/src/audio/windib/SDL_dibaudio.c @@ -23,8 +23,7 @@ /* Allow access to a raw mixing buffer */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #include "SDL_timer.h" @@ -67,21 +66,14 @@ SetMMerror(char *function, MMRESULT code) { size_t len; char errbuf[MAXERRORLENGTH]; -#ifdef _WIN32_WCE wchar_t werrbuf[MAXERRORLENGTH]; -#endif SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function); len = SDL_strlen(errbuf); -#ifdef _WIN32_WCE - /* UNICODE version */ waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len); WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len, MAXERRORLENGTH - len, NULL, NULL); -#else - waveOutGetErrorText(code, errbuf + len, (UINT) (MAXERRORLENGTH - len)); -#endif SDL_SetError("%s", errbuf); } diff --git a/src/audio/windx5/SDL_dx5audio.c b/src/audio/windx5/SDL_dx5audio.c index c583b3e63..7066d82eb 100644 --- a/src/audio/windx5/SDL_dx5audio.c +++ b/src/audio/windx5/SDL_dx5audio.c @@ -24,6 +24,7 @@ /* Allow access to a raw mixing buffer */ #include "SDL_timer.h" +#include "SDL_loadso.h" #include "SDL_audio.h" #include "../SDL_audio_c.h" #include "SDL_dx5audio.h" @@ -38,19 +39,19 @@ #endif /* DirectX function pointers for audio */ -static HINSTANCE DSoundDLL = NULL; +static void* DSoundDLL = NULL; static HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN) = NULL; static void DSOUND_Unload(void) { - if (DSoundDLL != NULL) { - FreeLibrary(DSoundDLL); - } - DSoundCreate = NULL; - DSoundDLL = NULL; + + if (DSoundDLL != NULL) { + SDL_UnloadObject(DSoundDLL); + DSoundDLL = NULL; + } } @@ -61,17 +62,16 @@ DSOUND_Load(void) DSOUND_Unload(); - DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL")); + DSoundDLL = SDL_LoadObject("DSOUND.DLL"); if (DSoundDLL == NULL) { SDL_SetError("DirectSound: failed to load DSOUND.DLL"); } else { /* Now make sure we have DirectX 5 or better... */ /* (DirectSoundCaptureCreate was added in DX5) */ - if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) { + if (!SDL_LoadFunction(DSoundDLL, "DirectSoundCaptureCreate")) { SDL_SetError("DirectSound: System doesn't appear to have DX5."); } else { - DSoundCreate = (void *) GetProcAddress(DSoundDLL, - TEXT("DirectSoundCreate")); + DSoundCreate = SDL_LoadFunction(DSoundDLL, "DirectSoundCreate"); } if (!DSoundCreate) { diff --git a/src/audio/windx5/directx.h b/src/audio/windx5/directx.h index c283f6bc4..1c371f953 100644 --- a/src/audio/windx5/directx.h +++ b/src/audio/windx5/directx.h @@ -4,8 +4,7 @@ /* Include all of the DirectX 5.0 headers and adds any necessary tweaks */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #ifndef WIN32 #define WIN32 diff --git a/src/SDL_android.cpp b/src/core/android/SDL_android.cpp similarity index 100% rename from src/SDL_android.cpp rename to src/core/android/SDL_android.cpp diff --git a/src/SDL_android.h b/src/core/android/SDL_android.h similarity index 100% rename from src/SDL_android.h rename to src/core/android/SDL_android.h diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c new file mode 100644 index 000000000..cadf9ce97 --- /dev/null +++ b/src/core/windows/SDL_windows.c @@ -0,0 +1,41 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_error.h" +#include "SDL_windows.h" + + +/* Sets an error message based on GetLastError() */ +void +WIN_SetError(const char *prefix) +{ + TCHAR buffer[1024]; + char *message; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, + buffer, SDL_arraysize(buffer), NULL); + message = WIN_StringToUTF8(buffer); + SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); + SDL_free(message); +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h new file mode 100644 index 000000000..601fc5b11 --- /dev/null +++ b/src/core/windows/SDL_windows.h @@ -0,0 +1,53 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This is an include file for windows.h with the SDL build settings */ + +#ifndef _INCLUDED_WINDOWS_H +#define _INCLUDED_WINDOWS_H + +#define WIN32_LEAN_AND_MEAN +#define STRICT +#ifndef UNICODE +#define UNICODE 1 +#endif +#undef WINVER +#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */ + +#include + + +/* Routines to convert from UTF8 to native Windows text */ +#if UNICODE +#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UCS-2", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR)) +#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)(S), SDL_strlen(S)+1) +#else +#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1)) +#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); + +#endif /* _INCLUDED_WINDOWS_H */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index 7fa382818..3444f2fad 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -39,8 +39,7 @@ #include #endif #ifdef __WIN32__ -#define WIN32_LEAN_AND_MEAN -#include +#include "../core/windows/SDL_windows.h" #endif #define CPU_HAS_RDTSC 0x00000001 diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 6548403f0..5ea6bc753 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -44,8 +44,7 @@ faster, and all stdio functions anyway are embedded in coredll.dll - the main wince dll*/ -#define WINDOWS_LEAN_AND_MEAN -#include +#include "../core/windows/SDL_windows.h" #ifndef INVALID_SET_FILE_POINTER #define INVALID_SET_FILE_POINTER 0xFFFFFFFF @@ -98,34 +97,28 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode) } #ifdef _WIN32_WCE { - size_t size = SDL_strlen(filename) + 1; - wchar_t *filenameW = SDL_stack_alloc(wchar_t, size); - - if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == - 0) { - SDL_stack_free(filenameW); - SDL_free(context->hidden.windowsio.buffer.data); - context->hidden.windowsio.buffer.data = NULL; - SDL_SetError("Unable to convert filename to Unicode"); - return -1; - } - h = CreateFile(filenameW, (w_right | r_right), + LPTSTR tstr = WIN_UTF8ToString(filename); + h = CreateFile(tstr, (w_right | r_right), (w_right) ? 0 : FILE_SHARE_READ, NULL, (must_exist | truncate | a_mode), FILE_ATTRIBUTE_NORMAL, NULL); - SDL_stack_free(filenameW); + SDL_free(tstr); } #else /* Do not open a dialog box if failure */ old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); - h = CreateFile(filename, (w_right | r_right), - (w_right) ? 0 : FILE_SHARE_READ, NULL, - (must_exist | truncate | a_mode), FILE_ATTRIBUTE_NORMAL, - NULL); + { + LPTSTR tstr = WIN_UTF8ToString(filename); + h = CreateFile(tstr, (w_right | r_right), + (w_right) ? 0 : FILE_SHARE_READ, NULL, + (must_exist | truncate | a_mode), + FILE_ATTRIBUTE_NORMAL, NULL); + SDL_free(tstr); + } - /* restore old behaviour */ + /* restore old behavior */ SetErrorMode(old_error_mode); #endif /* _WIN32_WCE */ diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c index 504479acf..a41f684b2 100644 --- a/src/haptic/windows/SDL_syshaptic.c +++ b/src/haptic/windows/SDL_syshaptic.c @@ -39,6 +39,7 @@ static struct { DIDEVICEINSTANCE instance; + char *name; SDL_Haptic *haptic; DIDEVCAPS capabilities; } SDL_hapticlist[MAX_HAPTICS]; @@ -220,6 +221,9 @@ EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) return DIENUM_CONTINUE; } + /* Copy the name */ + SDL_hapticlist[SDL_numhaptics].name = WIN_StringToUTF8(SDL_hapticlist[SDL_numhaptics].instance.tszProductName); + /* Close up device and count it. */ IDirectInputDevice_Release(device); SDL_numhaptics++; @@ -238,7 +242,7 @@ EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) const char * SDL_SYS_HapticName(int index) { - return SDL_hapticlist[index].instance.tszProductName; + return SDL_hapticlist[index].name; } @@ -630,6 +634,15 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic) void SDL_SYS_HapticQuit(void) { + int i; + + for (i = 0; i < SDL_arraysize(SDL_hapticlist); ++i) { + if (SDL_hapticlist[i].name) { + SDL_free(SDL_hapticlist[i].name); + SDL_hapticlist[i].name = NULL; + } + } + IDirectInput_Release(dinput); dinput = NULL; } diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index 58d346243..578449286 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -32,7 +32,7 @@ #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" #include "../SDL_joystick_c.h" -#include "../../SDL_android.h" +#include "../../core/android/SDL_android.h" static const char *accelerometerName = "Android accelerometer"; diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index d9ddaa3b2..995fb6e2d 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -63,6 +63,7 @@ extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * ppDI, LPUNKNOWN punkOuter); static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS]; /* array to hold joystick ID values */ +static char *SYS_JoystickNames[MAX_JOYSTICKS]; static int SYS_NumJoysticks; static HINSTANCE DInputDLL = NULL; @@ -326,6 +327,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) { SDL_memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance, sizeof(DIDEVICEINSTANCE)); + SYS_JoystickNames[SYS_NumJoysticks] = WIN_StringToUTF8(pdidInstance->tszProductName); SYS_NumJoysticks++; if (SYS_NumJoysticks >= MAX_JOYSTICKS) @@ -338,8 +340,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) const char * SDL_SYS_JoystickName(int index) { - /***-> test for invalid index ? */ - return (SYS_Joystick[index].tszProductName); + return SYS_JoystickNames[index]; } /* Function to open a joystick for use. @@ -793,6 +794,15 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick) void SDL_SYS_JoystickQuit(void) { + int i; + + for (i = 0; i < SDL_arraysize(SYS_JoystickNames); ++i) { + if (SYS_JoystickNames[i]) { + SDL_free(SYS_JoystickNames[i]); + SYS_JoystickNames[i] = NULL; + } + } + IDirectInput_Release(dinput); dinput = NULL; } diff --git a/src/joystick/windows/SDL_dxjoystick_c.h b/src/joystick/windows/SDL_dxjoystick_c.h index 847b168b6..039cf825d 100644 --- a/src/joystick/windows/SDL_dxjoystick_c.h +++ b/src/joystick/windows/SDL_dxjoystick_c.h @@ -33,8 +33,7 @@ * with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and * let it return 0 events. */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #define DIRECTINPUT_VERSION 0x0700 /* Need version 7 for force feedback. */ #include diff --git a/src/joystick/windows/SDL_mmjoystick.c b/src/joystick/windows/SDL_mmjoystick.c index bcfc83f69..570e91ada 100644 --- a/src/joystick/windows/SDL_mmjoystick.c +++ b/src/joystick/windows/SDL_mmjoystick.c @@ -25,8 +25,7 @@ /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #include diff --git a/src/loadso/windows/SDL_sysloadso.c b/src/loadso/windows/SDL_sysloadso.c index 061243429..e8ec3337e 100644 --- a/src/loadso/windows/SDL_sysloadso.c +++ b/src/loadso/windows/SDL_sysloadso.c @@ -26,110 +26,45 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* System dependent library loading routines */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "SDL_loadso.h" void * SDL_LoadObject(const char *sofile) { - void *handle = NULL; - const char *loaderror = "Unknown error"; - -#if defined(_WIN32_WCE) - char errbuf[512]; - - wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); - wchar_t *sofile_t = SDL_malloc((MAX_PATH + 1) * sizeof(wchar_t)); - - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, - MAX_PATH); - handle = (void *) LoadLibrary(sofile_t); + LPTSTR tstr = WIN_UTF8ToString(sofile); + void *handle = (void *) LoadLibrary(tstr); + SDL_free(tstr); /* Generate an error message if all loads failed */ if (handle == NULL) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf_t, SDL_arraysize(errbuf), NULL); - WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); - loaderror = errbuf; + char errbuf[512]; + SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf)); + SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf)); + WIN_SetError(errbuf); } - - SDL_free(sofile_t); - SDL_free(errbuf_t); - -#else /*if defined(__WIN32__) */ - char errbuf[512]; - - handle = (void *) LoadLibrary(sofile); - - /* Generate an error message if all loads failed */ - if (handle == NULL) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf, SDL_arraysize(errbuf), NULL); - loaderror = errbuf; - } -#endif - - if (handle == NULL) { - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - } - return (handle); + return handle; } void * SDL_LoadFunction(void *handle, const char *name) { - void *symbol = NULL; - const char *loaderror = "Unknown error"; - -#if defined(_WIN32_WCE) - char errbuf[512]; - int length = SDL_strlen(name); - - wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t)); - wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); - - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length + 1); - - symbol = (void *) GetProcAddress((HMODULE) handle, name_t); - if (symbol == NULL) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf_t, SDL_arraysize(errbuf), NULL); - WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); - loaderror = errbuf; - } - - SDL_free(name_t); - SDL_free(errbuf_t); - -#else /*if defined(WIN32) */ - char errbuf[512]; - - symbol = (void *) GetProcAddress((HMODULE) handle, name); - if (symbol == NULL) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf, SDL_arraysize(errbuf), NULL); - loaderror = errbuf; - } +#ifdef _WIN32_WCE + LPTSTR tstr = WIN_UTF8ToString(name); + void *symbol = (void *) GetProcAddress((HMODULE) handle, tstr); + SDL_free(tstr); +#else + void *symbol = (void *) GetProcAddress((HMODULE) handle, name); #endif if (symbol == NULL) { - SDL_SetError("Failed loading %s: %s", name, loaderror); + char errbuf[512]; + SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf)); + SDL_strlcat(errbuf, name, SDL_arraysize(errbuf)); + WIN_SetError(errbuf); } - return (symbol); + return symbol; } void diff --git a/src/power/windows/SDL_syspower.c b/src/power/windows/SDL_syspower.c index a5e23e7fa..e85243522 100644 --- a/src/power/windows/SDL_syspower.c +++ b/src/power/windows/SDL_syspower.c @@ -24,8 +24,7 @@ #ifndef SDL_POWER_DISABLED #ifdef SDL_POWER_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "SDL_power.h" diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index 387531a88..851673032 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -27,8 +27,7 @@ #if defined(__WIN32__) && !defined(_WIN32_WCE) -#define WIN32_LEAN_AND_MEAN -#include +#include "../core/windows/SDL_windows.h" /* Note this isn't thread-safe! */ @@ -41,12 +40,12 @@ SDL_setenv(const char *name, const char *value, int overwrite) { if (!overwrite) { char ch = 0; - const size_t len = GetEnvironmentVariable(name, &ch, sizeof (ch)); + const size_t len = GetEnvironmentVariableA(name, &ch, sizeof (ch)); if (len > 0) { return 0; /* asked not to overwrite existing value. */ } } - if (!SetEnvironmentVariable(name, *value ? value : NULL)) { + if (!SetEnvironmentVariableA(name, *value ? value : NULL)) { return -1; } return 0; @@ -59,7 +58,7 @@ SDL_getenv(const char *name) size_t bufferlen; bufferlen = - GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen); + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); if (bufferlen == 0) { return NULL; } @@ -70,7 +69,7 @@ SDL_getenv(const char *name) } SDL_envmem = newmem; SDL_envmemlen = bufferlen; - GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen); + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); } return SDL_envmem; } diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index d0f1c8556..820390359 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -23,8 +23,7 @@ /* Mutex functions using the Win32 API */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "SDL_mutex.h" diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 9673ee898..799dac04b 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -23,8 +23,7 @@ /* Semaphore functions using the Win32 API */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "SDL_thread.h" #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) diff --git a/src/thread/windows/SDL_systhread_c.h b/src/thread/windows/SDL_systhread_c.h index 675e821c9..1a9a554a2 100644 --- a/src/thread/windows/SDL_systhread_c.h +++ b/src/thread/windows/SDL_systhread_c.h @@ -21,8 +21,7 @@ */ #include "SDL_config.h" -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" typedef HANDLE SYS_ThreadHandle; diff --git a/src/thread/windows/win_ce_semaphore.c b/src/thread/windows/win_ce_semaphore.c index a44fc34f5..62072f562 100644 --- a/src/thread/windows/win_ce_semaphore.c +++ b/src/thread/windows/win_ce_semaphore.c @@ -28,8 +28,7 @@ and it is not clear how to handle a mixture of WCE semaphores and normal events and mutexes. */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "win_ce_semaphore.h" diff --git a/src/timer/wince/SDL_systimer.c b/src/timer/wince/SDL_systimer.c index 8ecb71416..5abbaa587 100644 --- a/src/timer/wince/SDL_systimer.c +++ b/src/timer/wince/SDL_systimer.c @@ -23,8 +23,7 @@ #ifdef SDL_TIMER_WINCE -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #include "SDL_thread.h" diff --git a/src/timer/windows/SDL_systimer.c b/src/timer/windows/SDL_systimer.c index 083a88040..0ae01da10 100644 --- a/src/timer/windows/SDL_systimer.c +++ b/src/timer/windows/SDL_systimer.c @@ -23,8 +23,7 @@ #ifdef SDL_TIMER_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #include "SDL_timer.h" diff --git a/src/video/android/SDL_androidgl.c b/src/video/android/SDL_androidgl.c index 27f1665d5..715d12123 100644 --- a/src/video/android/SDL_androidgl.c +++ b/src/video/android/SDL_androidgl.c @@ -26,7 +26,7 @@ #include "SDL_video.h" #include "SDL_androidvideo.h" -#include "../../SDL_android.h" +#include "../../core/android/SDL_android.h" #include diff --git a/src/video/windows/SDL_gapirender.c b/src/video/windows/SDL_gapirender.c index a0485aea6..456f3e37f 100644 --- a/src/video/windows/SDL_gapirender.c +++ b/src/video/windows/SDL_gapirender.c @@ -78,7 +78,7 @@ typedef int (*PFNGXResume)(); typedef struct { // gx.dll - HMODULE hGapiLib; + void* hGapiLib; PFNGXOpenDisplay GXOpenDisplay; PFNGXCloseDisplay GXCloseDisplay; PFNGXBeginDraw GXBeginDraw; @@ -251,7 +251,7 @@ SDL_RenderDriver RAW_RenderDriver = { int WINCE_Available(void) { - HMODULE render_gapi; + void* render_gapi; const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); // raw check @@ -267,10 +267,10 @@ int WINCE_Available(void) if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw; // gapi check - render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); + render_gapi = SDL_LoadObject("\\Windows\\gx.dll"); if(0 == render_gapi) - render_gapi = LoadLibrary(TEXT("gx.dll")); - FreeLibrary(render_gapi); + render_gapi = SDL_LoadObject("gx.dll"); + SDL_UnloadObject(render_gapi); if(preferably && 0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0 != render_gapi; @@ -280,7 +280,7 @@ int WINCE_Available(void) void WINCE_AddRenderDriver(_THIS) { HDC hdc; - HMODULE render_gapi; + void* render_gapi; int render_raw, ii; const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); @@ -295,12 +295,12 @@ void WINCE_AddRenderDriver(_THIS) render_raw = 1; // gapi check - render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); + render_gapi = SDL_LoadObject("\\Windows\\gx.dll"); if(0 == render_gapi) - render_gapi = LoadLibrary(TEXT("gx.dll")); + render_gapi = SDL_LoadObject("gx.dll"); if(render_gapi) - FreeLibrary(render_gapi); + SDL_UnloadObject(render_gapi); for(ii = 0; ii < _this->num_displays; ++ii) { @@ -885,15 +885,15 @@ int GAPI_Init(WINCE_RenderData* data, HWND hwnd) return 0; } - data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll")); + data->gapi->hGapiLib = SDL_LoadObject("\\Windows\\gx.dll"); if(0 == data->gapi->hGapiLib) { - data->gapi->hGapiLib = LoadLibrary(TEXT("gx.dll")); + data->gapi->hGapiLib = SDL_LoadObject("gx.dll"); if(0 == data->gapi->hGapiLib) return 0; } // load gapi library -#define LINK(type,name,import) name=(PFN##type)GetProcAddress(data->gapi->hGapiLib,TEXT(import)) +#define LINK(type,name,import) name=(PFN##type)SDL_LoadFunction(data->gapi->hGapiLib,import) LINK(GXOpenDisplay, data->gapi->GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z"); LINK(GXCloseDisplay, data->gapi->GXCloseDisplay, "?GXCloseDisplay@@YAHXZ"); LINK(GXBeginDraw, data->gapi->GXBeginDraw, "?GXBeginDraw@@YAPAXXZ"); @@ -1005,7 +1005,7 @@ void GAPI_Quit(WINCE_RenderData* data) if(data->gapi) { if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); - if(data->gapi->hGapiLib) FreeLibrary(data->gapi->hGapiLib); + if(data->gapi->hGapiLib) SDL_UnloadObject(data->gapi->hGapiLib); SDL_free(data->gapi); data->gapi = NULL; diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index 45fd8284e..d82696520 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -312,15 +312,15 @@ IME_Init(SDL_VideoData *videodata, HWND hwnd) CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (LPVOID *)&videodata->ime_threadmgr); } videodata->ime_initialized = SDL_TRUE; - videodata->ime_himm32 = LoadLibraryA("imm32.dll"); + videodata->ime_himm32 = SDL_LoadObject("imm32.dll"); if (!videodata->ime_himm32) { videodata->ime_available = SDL_FALSE; return; } - videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmLockIMC"); - videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMC"); - videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmLockIMCC"); - videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMCC"); + videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC"); + videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMC"); + videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMCC"); + videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMCC"); IME_SetWindow(videodata, hwnd); videodata->ime_himc = ImmGetContext(hwnd); @@ -383,7 +383,7 @@ IME_Quit(SDL_VideoData *videodata) videodata->ime_hwnd_main = 0; videodata->ime_himc = 0; if (videodata->ime_himm32) { - FreeLibrary(videodata->ime_himm32); + SDL_UnloadObject(videodata->ime_himm32); videodata->ime_himm32 = 0; } if (videodata->ime_threadmgr) { @@ -606,7 +606,7 @@ static void IME_SetupAPI(SDL_VideoData *videodata) { char ime_file[MAX_PATH + 1]; - HMODULE hime = 0; + void* hime = 0; HKL hkl = 0; videodata->GetReadingString = 0; videodata->ShowReadingWindow = 0; @@ -617,14 +617,14 @@ IME_SetupAPI(SDL_VideoData *videodata) if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0) return; - hime = LoadLibraryA(ime_file); + hime = SDL_LoadObject(ime_file); if (!hime) return; videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT)) - GetProcAddress(hime, "GetReadingString"); + SDL_LoadFunction(hime, "GetReadingString"); videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL)) - GetProcAddress(hime, "ShowReadingWindow"); + SDL_LoadFunction(hime, "ShowReadingWindow"); if (videodata->ShowReadingWindow) { HIMC himc = ImmGetContext(videodata->ime_hwnd_current); diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index 0de7414be..950c35a4b 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -101,7 +101,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path) !_this->gl_data->wglDeleteContext || !_this->gl_data->wglMakeCurrent) { SDL_SetError("Could not retrieve OpenGL functions"); - FreeLibrary(handle); + SDL_UnloadObject(handle); return -1; } diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 193f2d166..0cc2fc8bc 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -37,19 +37,6 @@ static int WIN_VideoInit(_THIS); static void WIN_VideoQuit(_THIS); -/* Sets an error message based on GetLastError() */ -void -WIN_SetError(const char *prefix) -{ - TCHAR buffer[1024]; - char *message; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, - buffer, SDL_arraysize(buffer), NULL); - message = WIN_StringToUTF8(buffer); - SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); - SDL_free(message); -} - /* Windows driver bootstrap functions */ @@ -68,22 +55,22 @@ WIN_DeleteDevice(SDL_VideoDevice * device) #if SDL_VIDEO_RENDER_D3D if (data->d3d) { IDirect3D9_Release(data->d3d); - FreeLibrary(data->d3dDLL); + SDL_UnloadObject(data->d3dDLL); } #endif #if SDL_VIDEO_RENDER_DDRAW if (data->ddraw) { data->ddraw->lpVtbl->Release(data->ddraw); - FreeLibrary(data->ddrawDLL); + SDL_UnloadObject(data->ddrawDLL); } #endif #ifdef _WIN32_WCE if(data->hAygShell) { - FreeLibrary(data->hAygShell); + SDL_UnloadObject(data->hAygShell); } #endif if (data->userDLL) { - FreeLibrary(data->userDLL); + SDL_UnloadObject(data->userDLL); } SDL_free(device->driverdata); @@ -115,24 +102,24 @@ WIN_CreateDevice(int devindex) device->driverdata = data; #if SDL_VIDEO_RENDER_D3D - data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL")); + data->d3dDLL = SDL_LoadObject("D3D9.DLL"); if (data->d3dDLL) { IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion); D3DCreate = - (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL, + (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL, "Direct3DCreate9"); if (D3DCreate) { data->d3d = D3DCreate(D3D_SDK_VERSION); } if (!data->d3d) { - FreeLibrary(data->d3dDLL); + SDL_UnloadObject(data->d3dDLL); data->d3dDLL = NULL; } } #endif /* SDL_VIDEO_RENDER_D3D */ #if SDL_VIDEO_RENDER_DDRAW - data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll")); + data->ddrawDLL = SDL_LoadObject("ddraw.dll"); if (data->ddrawDLL) { IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID, LPDIRECTDRAW FAR * lplpDD, @@ -141,9 +128,9 @@ WIN_CreateDevice(int devindex) DDCreate = (IDirectDraw * (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *)) - GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate")); + SDL_LoadFunction(data->ddrawDLL, "DirectDrawCreate"); if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) { - FreeLibrary(data->ddrawDLL); + SDL_UnloadObject(data->ddrawDLL); data->ddrawDLL = NULL; data->ddraw = NULL; } @@ -151,19 +138,19 @@ WIN_CreateDevice(int devindex) #endif /* SDL_VIDEO_RENDER_DDRAW */ #ifdef _WIN32_WCE - data->hAygShell = LoadLibrary(TEXT("\\windows\\aygshell.dll")); + data->hAygShell = SDL_LoadObject("\\windows\\aygshell.dll"); if(0 == data->hAygShell) - data->hAygShell = LoadLibrary(TEXT("aygshell.dll")); + data->hAygShell = SDL_LoadObject("aygshell.dll"); data->SHFullScreen = (0 != data->hAygShell ? - (PFNSHFullScreen) GetProcAddress(data->hAygShell, TEXT("SHFullScreen")) : 0); + (PFNSHFullScreen) SDL_LoadFunction(data->hAygShell, "SHFullScreen") : 0); data->CoordTransform = NULL; #endif - data->userDLL = LoadLibrary(TEXT("USER32.DLL")); + data->userDLL = SDL_LoadObject("USER32.DLL"); if (data->userDLL) { - data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(data->userDLL, TEXT("CloseTouchInputHandle")); - data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(data->userDLL, TEXT("GetTouchInputInfo")); - data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(data->userDLL, TEXT("RegisterTouchWindow")); + data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle"); + data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo"); + data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow"); } /* Set the function pointers */ diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index 895aa08c0..c43776f97 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -26,15 +26,7 @@ #include "../SDL_sysvideo.h" -#define WIN32_LEAN_AND_MEAN -#define STRICT -#ifndef UNICODE -#define UNICODE -#endif -#undef WINVER -#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */ - -#include +#include "../../core/windows/SDL_windows.h" #if defined(_MSC_VER) && !defined(_WIN32_WCE) #include @@ -68,15 +60,8 @@ #include "SDL_windowsopengl.h" #include "SDL_windowswindow.h" #include "SDL_events.h" +#include "SDL_loadso.h" -#ifdef UNICODE -#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UCS-2", (char *)S, (SDL_wcslen(S)+1)*sizeof(WCHAR)) -#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1) -#else -#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)S, (SDL_strlen(S)+1)) -#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1) -#endif -extern void WIN_SetError(const char *prefix); enum { RENDER_NONE, RENDER_D3D, RENDER_DDRAW, RENDER_GDI, RENDER_GAPI, RENDER_RAW }; @@ -147,15 +132,15 @@ typedef struct SDL_VideoData int render; #if SDL_VIDEO_RENDER_D3D - HANDLE d3dDLL; + void* d3dDLL; IDirect3D9 *d3d; #endif #if SDL_VIDEO_RENDER_DDRAW - HANDLE ddrawDLL; + void* ddrawDLL; IDirectDraw *ddraw; #endif #ifdef _WIN32_WCE - HMODULE hAygShell; + void* hAygShell; PFNSHFullScreen SHFullScreen; PFCoordTransform CoordTransform; #endif @@ -164,7 +149,7 @@ typedef struct SDL_VideoData DWORD clipboard_count; /* Touch input functions */ - HANDLE userDLL; + void* userDLL; BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT ); BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int ); BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG ); @@ -199,7 +184,7 @@ typedef struct SDL_VideoData int ime_winheight; HKL ime_hkl; - HMODULE ime_himm32; + void* ime_himm32; UINT (WINAPI *GetReadingString)(HIMC himc, UINT uReadingBufLen, LPWSTR lpwReadingBuf, PINT pnErrorIndex, BOOL *pfIsVertical, PUINT puMaxReadingLen); BOOL (WINAPI *ShowReadingWindow)(HIMC himc, BOOL bShow); LPINPUTCONTEXT2 (WINAPI *ImmLockIMC)(HIMC himc); From 35a4f38472591a0435433a25895cbe2ace27393d Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 21:22:00 -0800 Subject: [PATCH 10/44] Only include windows.h on Windows. :) --- src/atomic/SDL_spinlock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index b28b696ae..25fdca27a 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -25,7 +25,9 @@ #include "SDL_timer.h" /* Don't do the check for Visual Studio 2005, it's safe here */ +#ifdef __WIN32__ #include "../core/windows/SDL_windows.h" +#endif /* This function is where all the magic happens... */ SDL_bool From 0709487572319dea0859c30c8e5a5b9f915d9267 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 21:31:32 -0800 Subject: [PATCH 11/44] Fixed Android build --- Android.mk | 4 ++-- src/core/android/SDL_android.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Android.mk b/Android.mk index 984050699..2c3893c30 100755 --- a/Android.mk +++ b/Android.mk @@ -28,7 +28,7 @@ LOCAL_SRC_FILES := \ $(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \ $(wildcard $(LOCAL_PATH)/src/joystick/*.c) \ $(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \ - $(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c)) \ + $(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \ $(wildcard $(LOCAL_PATH)/src/power/*.c) \ $(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \ $(wildcard $(LOCAL_PATH)/src/thread/*.c) \ @@ -36,7 +36,7 @@ LOCAL_SRC_FILES := \ $(wildcard $(LOCAL_PATH)/src/timer/*.c) \ $(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \ $(wildcard $(LOCAL_PATH)/src/video/*.c) \ - $(wildcard $(LOCAL_PATH)/src/video/android/*.c) + $(wildcard $(LOCAL_PATH)/src/video/android/*.c)) LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog diff --git a/src/core/android/SDL_android.cpp b/src/core/android/SDL_android.cpp index 4f5f8f5ae..0351007e3 100644 --- a/src/core/android/SDL_android.cpp +++ b/src/core/android/SDL_android.cpp @@ -24,10 +24,10 @@ #include "SDL_android.h" extern "C" { -#include "events/SDL_events_c.h" -#include "video/android/SDL_androidkeyboard.h" -#include "video/android/SDL_androidtouch.h" -#include "video/android/SDL_androidvideo.h" +#include "../../events/SDL_events_c.h" +#include "../../video/android/SDL_androidkeyboard.h" +#include "../../video/android/SDL_androidtouch.h" +#include "../../video/android/SDL_androidvideo.h" /* Impelemented in audio/android/SDL_androidaudio.c */ extern void Android_RunAudioThread(); From 37df0221d45c78765caee426ee365f78b90e37b9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 21:41:36 -0800 Subject: [PATCH 12/44] Fixed cross-compiling for Windows --- configure.in | 4 ++++ include/SDL_config.h.in | 2 +- src/thread/windows/SDL_systhread_c.h | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 631a8958d..98bb7b166 100644 --- a/configure.in +++ b/configure.in @@ -2446,6 +2446,10 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau CheckWINDOWS CheckWINDOWSGL CheckDIRECTX + + # Set up the core platform files + SOURCES="$SOURCES $srcdir/src/core/windows/*.c" + # Set up files for the video library if test x$enable_video = xyes; then AC_DEFINE(SDL_VIDEO_DRIVER_WINDOWS) diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index c0500f0ee..625608532 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -90,7 +90,7 @@ #undef HAVE_REALLOC #undef HAVE_FREE #undef HAVE_ALLOCA -#ifndef __WINDOWS__ /* Don't use C runtime versions of these on Windows */ +#ifndef __WIN32__ /* Don't use C runtime versions of these on Windows */ #undef HAVE_GETENV #undef HAVE_SETENV #undef HAVE_PUTENV diff --git a/src/thread/windows/SDL_systhread_c.h b/src/thread/windows/SDL_systhread_c.h index 1a9a554a2..cabbed046 100644 --- a/src/thread/windows/SDL_systhread_c.h +++ b/src/thread/windows/SDL_systhread_c.h @@ -21,8 +21,13 @@ */ #include "SDL_config.h" +#ifndef _SDL_systhread_c_h +#define _SDL_systhread_c_h + #include "../../core/windows/SDL_windows.h" typedef HANDLE SYS_ThreadHandle; +#endif /* _SDL_systhread_c_h */ + /* vi: set ts=4 sw=4 expandtab: */ From 86dd80b24b40eb461ab4e1fe2bd212266c165ab1 Mon Sep 17 00:00:00 2001 From: krogoway Date: Mon, 24 Jan 2011 23:54:21 -0600 Subject: [PATCH 13/44] Added SDL_window.* to the project. --- VisualC/SDL/SDL_VS2005.vcproj | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/VisualC/SDL/SDL_VS2005.vcproj b/VisualC/SDL/SDL_VS2005.vcproj index bce129fd3..6f8979f69 100644 --- a/VisualC/SDL/SDL_VS2005.vcproj +++ b/VisualC/SDL/SDL_VS2005.vcproj @@ -647,10 +647,6 @@ RelativePath="..\..\src\atomic\SDL_atomic.c" > - - @@ -1047,6 +1043,10 @@ RelativePath="..\..\src\video\SDL_shape_internals.h" > + + @@ -1163,6 +1163,22 @@ RelativePath="..\..\src\audio\SDL_wave.h" > + + + + + + + + @@ -1243,14 +1259,6 @@ RelativePath="..\..\src\video\windows\SDL_windowswindow.h" > - - - - From 3dc100972366961acec97b22167ed4513384c97b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Jan 2011 17:40:06 -0800 Subject: [PATCH 14/44] Improvements based on feedback from Anthony Williams --- configure.in | 2 + include/SDL_atomic.h | 120 ++++++++++++++++++++++++-------------- src/atomic/SDL_atomic.c | 79 +------------------------ src/atomic/SDL_spinlock.c | 18 ++++-- 4 files changed, 93 insertions(+), 126 deletions(-) diff --git a/configure.in b/configure.in index 98bb7b166..2bbff60d7 100644 --- a/configure.in +++ b/configure.in @@ -301,6 +301,7 @@ if test x$enable_gcc_atomics = xyes; then int a; void *x, *y, *z; __sync_lock_test_and_set(&a, 4); + __sync_lock_test_and_set(&x, y); __sync_fetch_and_add(&a, 1); __sync_bool_compare_and_swap(&a, 5, 10); __sync_bool_compare_and_swap(&x, y, z); @@ -317,6 +318,7 @@ if test x$enable_gcc_atomics = xyes; then ],[ int a; __sync_lock_test_and_set(&a, 1); + __sync_lock_release(&a); ],[ have_gcc_sync_lock_test_and_set=yes ]) diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index 9f339c7cb..8342489d0 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -38,8 +38,13 @@ * SDL_AtomicDecRef() * * Seriously, here be dragons! + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ * - * These operations may, or may not, actually be implemented using + * You can find out a little more about lockless programming and the + * subtle issues that can arise here: + * http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx + * + * These operations may or may not actually be implemented using * processor specific atomic operations. When possible they are * implemented as true processor specific atomic operations. When that * is not possible the are implemented using locks that *do* use the @@ -114,66 +119,54 @@ extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock); /*@}*//*SDL AtomicLock*/ + +/* The compiler barrier prevents the compiler from reordering + reads and writes to globally visible variables across the call. +*/ +#ifdef _MSC_VER +void _ReadWriteBarrier(void); +#pragma intrinsic(_ReadWriteBarrier) +#define SDL_CompilerBarrier() _ReadWriteBarrier() +#elif __GNUC__ +#define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory") +#else +#define SDL_CompilerBarrier() \ +({ SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }) +#endif + /* Platform specific optimized versions of the atomic functions, * you can disable these by defining SDL_DISABLE_ATOMIC_INLINE */ #ifndef SDL_DISABLE_ATOMIC_INLINE -#if defined(HAVE_MSC_ATOMICS) +#if HAVE_MSC_ATOMICS #define SDL_AtomicSet(a, v) _InterlockedExchange((long*)&(a)->value, (v)) -#define SDL_AtomicGet(a) ((a)->value) #define SDL_AtomicAdd(a, v) _InterlockedExchangeAdd((long*)&(a)->value, (v)) #define SDL_AtomicCAS(a, oldval, newval) (_InterlockedCompareExchange((long*)&(a)->value, (newval), (oldval)) == (oldval)) -#define SDL_AtomicSetPtr(a, v) (void)_InterlockedExchangePointer((a), (v)) -#define SDL_AtomicGetPtr(a) (*(a)) +#define SDL_AtomicSetPtr(a, v) _InterlockedExchangePointer((a), (v)) #if _M_IX86 #define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchange((long*)(a), (long)(newval), (long)(oldval)) == (long)(oldval)) #else #define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchangePointer((a), (newval), (oldval)) == (oldval)) #endif -#elif defined(__MACOSX__) +#elif __MACOSX__ #include -#define SDL_AtomicSet(a, v) \ -({ \ - int oldvalue; \ - \ - do { \ - oldvalue = (a)->value; \ - } while (!OSAtomicCompareAndSwap32Barrier(oldvalue, v, &(a)->value)); \ - \ - oldvalue; \ -}) -#define SDL_AtomicGet(a) ((a)->value) -#define SDL_AtomicAdd(a, v) \ -({ \ - int oldvalue; \ - \ - do { \ - oldvalue = (a)->value; \ - } while (!OSAtomicCompareAndSwap32Barrier(oldvalue, oldvalue+v, &(a)->value)); \ - \ - oldvalue; \ -}) -#define SDL_AtomicCAS(a, oldval, newval) OSAtomicCompareAndSwap32Barrier(oldval, newval, &(a)->value) -#define SDL_AtomicSetPtr(a, v) (*(a) = v, OSMemoryBarrier()) -#define SDL_AtomicGetPtr(a) (*(a)) +#define SDL_AtomicCAS(a, oldval, newval) OSAtomicCompareAndSwap32Barrier((oldval), (newval), &(a)->value) #if SIZEOF_VOIDP == 4 #define SDL_AtomicCASPtr(a, oldval, newval) OSAtomicCompareAndSwap32Barrier((int32_t)(oldval), (int32_t)(newval), (int32_t*)(a)) #elif SIZEOF_VOIDP == 8 #define SDL_AtomicCASPtr(a, oldval, newval) OSAtomicCompareAndSwap64Barrier((int64_t)(oldval), (int64_t)(newval), (int64_t*)(a)) #endif -#elif defined(HAVE_GCC_ATOMICS) +#elif HAVE_GCC_ATOMICS #define SDL_AtomicSet(a, v) __sync_lock_test_and_set(&(a)->value, v) -#define SDL_AtomicGet(a) ((a)->value) #define SDL_AtomicAdd(a, v) __sync_fetch_and_add(&(a)->value, v) +#define SDL_AtomicSetPtr(a, v) __sync_lock_test_and_set(a, v) #define SDL_AtomicCAS(a, oldval, newval) __sync_bool_compare_and_swap(&(a)->value, oldval, newval) -#define SDL_AtomicSetPtr(a, v) (*(a) = v, __sync_synchronize()) -#define SDL_AtomicGetPtr(a) (*(a)) #define SDL_AtomicCASPtr(a, oldval, newval) __sync_bool_compare_and_swap(a, oldval, newval) #endif @@ -195,40 +188,61 @@ typedef struct { int value; } SDL_atomic_t; * \return The previous value of the atomic variable. */ #ifndef SDL_AtomicSet -extern DECLSPEC int SDLCALL SDL_AtomicSet(SDL_atomic_t *a, int value); +#define SDL_AtomicSet(a, v) \ +({ \ + int _value; \ + do { \ + _value = (a)->value; \ + } while (!SDL_AtomicCAS(a, _value, (v))); \ + _value; \ +}) #endif /** * \brief Get the value of an atomic variable */ #ifndef SDL_AtomicGet -extern DECLSPEC int SDLCALL SDL_AtomicGet(SDL_atomic_t *a); +#define SDL_AtomicGet(a) \ +({ \ + int _value = (a)->value; \ + SDL_CompilerBarrier(); \ + _value; \ +}) #endif /** - * \brief Add to an atomic variable. + * \brief Add to an atomic variable. * * \return The previous value of the atomic variable. + * + * \note This same style can be used for any number operation */ #ifndef SDL_AtomicAdd -extern DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_atomic_t *a, int value); +#define SDL_AtomicAdd(a, v) \ +({ \ + int _value; \ + do { \ + _value = (a)->value; \ + } while (!SDL_AtomicCAS(a, _value, (_value + (v)))); \ + _value; \ +}) #endif /** * \brief Increment an atomic variable used as a reference count. */ #ifndef SDL_AtomicIncRef -extern DECLSPEC void SDLCALL SDL_AtomicIncRef(SDL_atomic_t *a); +#define SDL_AtomicIncRef(a) SDL_AtomicAdd(a, 1) #endif /** * \brief Decrement an atomic variable used as a reference count. * - * \return SDL_TRUE if the variable has reached zero after decrementing, + * \return SDL_TRUE if the variable reached zero after decrementing, * SDL_FALSE otherwise */ #ifndef SDL_AtomicDecRef -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicDecRef(SDL_atomic_t *a); +#define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1) #endif /** @@ -239,21 +253,36 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicDecRef(SDL_atomic_t *a); * \note If you don't know what this function is for, you shouldn't use it! */ #ifndef SDL_AtomicCAS -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval); +#define SDL_AtomicCAS SDL_AtomicCAS_ #endif +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval); /** * \brief Set a pointer to a value atomically. + * + * \return The previous value of the pointer. */ #ifndef SDL_AtomicSetPtr -extern DECLSPEC void SDLCALL SDL_AtomicSetPtr(void** a, void* value); +#define SDL_AtomicSetPtr(a, v) \ +({ \ + void* _value; \ + do { \ + _value = *(a); \ + } while (!SDL_AtomicCASPtr(a, _value, (v))); \ + _value; \ +}) #endif /** * \brief Get the value of a pointer atomically. */ #ifndef SDL_AtomicGetPtr -extern DECLSPEC void* SDLCALL SDL_AtomicGetPtr(void** a); +#define SDL_AtomicGetPtr(a) \ +({ \ + void* _value = *(a); \ + SDL_CompilerBarrier(); \ + _value; \ +}) #endif /** @@ -264,8 +293,9 @@ extern DECLSPEC void* SDLCALL SDL_AtomicGetPtr(void** a); * \note If you don't know what this function is for, you shouldn't use it! */ #ifndef SDL_AtomicCASPtr -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void **a, void *oldval, void *newval); +#define SDL_AtomicCASPtr SDL_AtomicCASPtr_ #endif +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr_(void **a, void *oldval, void *newval); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/atomic/SDL_atomic.c b/src/atomic/SDL_atomic.c index 50cc7da36..7790823ed 100644 --- a/src/atomic/SDL_atomic.c +++ b/src/atomic/SDL_atomic.c @@ -70,61 +70,8 @@ leaveLock(void *a) SDL_AtomicUnlock(&locks[index]); } -#undef SDL_AtomicSet -int -SDL_AtomicSet(SDL_atomic_t *a, int value) -{ - int oldvalue; - - enterLock(a); - oldvalue = a->value; - a->value = value; - leaveLock(a); - - return oldvalue; -} - -#undef SDL_AtomicGet -int -SDL_AtomicGet(SDL_atomic_t *a) -{ - /* Assuming integral reads on this platform, we're safe here since the - functions that set the variable have the necessary memory barriers. - */ - return a->value; -} - -#undef SDL_AtomicAdd -int -SDL_AtomicAdd(SDL_atomic_t *a, int value) -{ - int oldvalue; - - enterLock(a); - oldvalue = a->value; - a->value += value; - leaveLock(a); - - return oldvalue; -} - -#undef SDL_AtomicIncRef -void -SDL_AtomicIncRef(SDL_atomic_t *a) -{ - SDL_AtomicAdd(a, 1); -} - -#undef SDL_AtomicDecRef SDL_bool -SDL_AtomicDecRef(SDL_atomic_t *a) -{ - return SDL_AtomicAdd(a, -1) == 1; -} - -#undef SDL_AtomicCAS -SDL_bool -SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval) +SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval) { SDL_bool retval = SDL_FALSE; @@ -138,28 +85,8 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval) return retval; } -#undef SDL_AtomicSetPtr -void -SDL_AtomicSetPtr(void** a, void* value) -{ - void *prevval; - do { - prevval = *a; - } while (!SDL_AtomicCASPtr(a, prevval, value)); -} - -#undef SDL_AtomicGetPtr -void* -SDL_AtomicGetPtr(void** a) -{ - /* Assuming integral reads on this platform, we're safe here since the - functions that set the pointer have the necessary memory barriers. - */ - return *a; -} - -#undef SDL_AtomicCASPtr -SDL_bool SDL_AtomicCASPtr(void **a, void *oldval, void *newval) +SDL_bool +SDL_AtomicCASPtr_(void **a, void *oldval, void *newval) { SDL_bool retval = SDL_FALSE; diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index 25fdca27a..3580455ba 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -37,20 +37,20 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); return (InterlockedExchange((long*)lock, 1) == 0); -#elif defined(__MACOSX__) +#elif __MACOSX__ return OSAtomicCompareAndSwap32Barrier(0, 1, lock); -#elif defined(HAVE_GCC_ATOMICS) || defined(HAVE_GCC_SYNC_LOCK_TEST_AND_SET) +#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET return (__sync_lock_test_and_set(lock, 1) == 0); -#elif defined(__GNUC__) && defined(__arm__) && defined(__ARM_ARCH_5__) +#elif __GNUC__ && __arm__ && __ARM_ARCH_5__ int result; __asm__ __volatile__ ( "swp %0, %1, [%2]\n" : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory"); return (result == 0); -#elif defined(__GNUC__) && defined(__arm__) +#elif __GNUC__ && __arm__ int result; __asm__ __volatile__ ( "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" @@ -75,8 +75,16 @@ SDL_AtomicLock(SDL_SpinLock *lock) void SDL_AtomicUnlock(SDL_SpinLock *lock) { - /* Assuming atomic assignment operation and full memory barrier in lock */ +#if defined(_MSC_VER) + _ReadWriteBarrier(); *lock = 0; + +#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET + __sync_lock_release(lock); + +#else + *lock = 0; +#endif } /* vi: set ts=4 sw=4 expandtab: */ From 7dba2ad5da5deb642d9a43d375b78055443592a7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Jan 2011 17:44:17 -0800 Subject: [PATCH 15/44] Fixed compile error on Visual C++ --- include/SDL_atomic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index 8342489d0..872aa1254 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -65,7 +65,7 @@ /* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */ #if defined(_MSC_VER) && (_MSC_VER >= 1500) && !defined(_WIN32_WCE) #include -#define HAVE_MSC_ATOMICS +#define HAVE_MSC_ATOMICS 1 #endif /* Set up for C function definitions, even when using C++ */ From 94cfb29bb198161072ecbaaf72106efc2aaf5f8e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Jan 2011 18:02:41 -0800 Subject: [PATCH 16/44] More fixes for compilation on Visual Studio --- include/SDL_atomic.h | 133 +++++++++++++++++++------------------- src/atomic/SDL_spinlock.c | 6 +- 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index 872aa1254..d45a78ce8 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -127,7 +127,7 @@ extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock); void _ReadWriteBarrier(void); #pragma intrinsic(_ReadWriteBarrier) #define SDL_CompilerBarrier() _ReadWriteBarrier() -#elif __GNUC__ +#elif defined(__GNUC__) #define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory") #else #define SDL_CompilerBarrier() \ @@ -139,7 +139,7 @@ void _ReadWriteBarrier(void); */ #ifndef SDL_DISABLE_ATOMIC_INLINE -#if HAVE_MSC_ATOMICS +#ifdef HAVE_MSC_ATOMICS #define SDL_AtomicSet(a, v) _InterlockedExchange((long*)&(a)->value, (v)) #define SDL_AtomicAdd(a, v) _InterlockedExchangeAdd((long*)&(a)->value, (v)) @@ -151,7 +151,7 @@ void _ReadWriteBarrier(void); #define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchangePointer((a), (newval), (oldval)) == (oldval)) #endif -#elif __MACOSX__ +#elif defined(__MACOSX__) #include #define SDL_AtomicCAS(a, oldval, newval) OSAtomicCompareAndSwap32Barrier((oldval), (newval), &(a)->value) @@ -161,7 +161,7 @@ void _ReadWriteBarrier(void); #define SDL_AtomicCASPtr(a, oldval, newval) OSAtomicCompareAndSwap64Barrier((int64_t)(oldval), (int64_t)(newval), (int64_t*)(a)) #endif -#elif HAVE_GCC_ATOMICS +#elif defined(HAVE_GCC_ATOMICS) #define SDL_AtomicSet(a, v) __sync_lock_test_and_set(&(a)->value, v) #define SDL_AtomicAdd(a, v) __sync_fetch_and_add(&(a)->value, v) @@ -182,32 +182,44 @@ void _ReadWriteBarrier(void); typedef struct { int value; } SDL_atomic_t; #endif +/** + * \brief Set an atomic variable to a new value if it is currently an old value. + * + * \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise. + * + * \note If you don't know what this function is for, you shouldn't use it! +*/ +#ifndef SDL_AtomicCAS +#define SDL_AtomicCAS SDL_AtomicCAS_ +#endif +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval); + /** * \brief Set an atomic variable to a value. * * \return The previous value of the atomic variable. */ #ifndef SDL_AtomicSet -#define SDL_AtomicSet(a, v) \ -({ \ - int _value; \ - do { \ - _value = (a)->value; \ - } while (!SDL_AtomicCAS(a, _value, (v))); \ - _value; \ -}) +static __inline__ int SDL_AtomicSet(SDL_atomic_t *a, int v) +{ + int value; + do { + value = a->value; + } while (!SDL_AtomicCAS(a, value, v)); + return value; +} #endif /** * \brief Get the value of an atomic variable */ #ifndef SDL_AtomicGet -#define SDL_AtomicGet(a) \ -({ \ - int _value = (a)->value; \ - SDL_CompilerBarrier(); \ - _value; \ -}) +static __inline__ int SDL_AtomicGet(SDL_atomic_t *a) +{ + int value = a->value; + SDL_CompilerBarrier(); + return value; +} #endif /** @@ -218,14 +230,14 @@ typedef struct { int value; } SDL_atomic_t; * \note This same style can be used for any number operation */ #ifndef SDL_AtomicAdd -#define SDL_AtomicAdd(a, v) \ -({ \ - int _value; \ - do { \ - _value = (a)->value; \ - } while (!SDL_AtomicCAS(a, _value, (_value + (v)))); \ - _value; \ -}) +static __inline__ int SDL_AtomicAdd(SDL_atomic_t *a, int v) +{ + int value; + do { + value = a->value; + } while (!SDL_AtomicCAS(a, value, (value + v))); + return value; +} #endif /** @@ -245,46 +257,6 @@ typedef struct { int value; } SDL_atomic_t; #define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1) #endif -/** - * \brief Set an atomic variable to a new value if it is currently an old value. - * - * \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise. - * - * \note If you don't know what this function is for, you shouldn't use it! -*/ -#ifndef SDL_AtomicCAS -#define SDL_AtomicCAS SDL_AtomicCAS_ -#endif -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval); - -/** - * \brief Set a pointer to a value atomically. - * - * \return The previous value of the pointer. - */ -#ifndef SDL_AtomicSetPtr -#define SDL_AtomicSetPtr(a, v) \ -({ \ - void* _value; \ - do { \ - _value = *(a); \ - } while (!SDL_AtomicCASPtr(a, _value, (v))); \ - _value; \ -}) -#endif - -/** - * \brief Get the value of a pointer atomically. - */ -#ifndef SDL_AtomicGetPtr -#define SDL_AtomicGetPtr(a) \ -({ \ - void* _value = *(a); \ - SDL_CompilerBarrier(); \ - _value; \ -}) -#endif - /** * \brief Set a pointer to a new value if it is currently an old value. * @@ -297,6 +269,35 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int #endif extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr_(void **a, void *oldval, void *newval); +/** + * \brief Set a pointer to a value atomically. + * + * \return The previous value of the pointer. + */ +#ifndef SDL_AtomicSetPtr +static __inline__ void* SDL_AtomicSetPtr(void* *a, void* v) +{ + void* value; + do { + value = *a; + } while (!SDL_AtomicCASPtr(a, value, v)); + return value; +} +#endif + +/** + * \brief Get the value of a pointer atomically. + */ +#ifndef SDL_AtomicGetPtr +static __inline__ void* SDL_AtomicGetPtr(void* *a) +{ + void* value = *a; + SDL_CompilerBarrier(); + return value; +} +#endif + + /* Ends C function definitions when using C++ */ #ifdef __cplusplus /* *INDENT-OFF* */ diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index 3580455ba..83ba93727 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -37,20 +37,20 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); return (InterlockedExchange((long*)lock, 1) == 0); -#elif __MACOSX__ +#elif defined(__MACOSX__) return OSAtomicCompareAndSwap32Barrier(0, 1, lock); #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET return (__sync_lock_test_and_set(lock, 1) == 0); -#elif __GNUC__ && __arm__ && __ARM_ARCH_5__ +#elif defined(__GNUC__) && defined(__arm__) && defined(__ARM_ARCH_5__) int result; __asm__ __volatile__ ( "swp %0, %1, [%2]\n" : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory"); return (result == 0); -#elif __GNUC__ && __arm__ +#elif defined(__GNUC__) && defined(__arm__) int result; __asm__ __volatile__ ( "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" From c382f9501386e80a878efe94f2be9954635646c3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Jan 2011 23:23:52 -0800 Subject: [PATCH 17/44] Added a FIFO test to the atomic test suite. This is really useful because we might be able to use something like this for the SDL event queue. --- include/SDL_atomic.h | 3 + test/testatomic.c | 393 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 396 insertions(+) diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index d45a78ce8..7259f7c44 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -44,6 +44,9 @@ * subtle issues that can arise here: * http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx * + * There's also lots of good information here: + * http://www.1024cores.net/home/lock-free-algorithms + * * These operations may or may not actually be implemented using * processor specific atomic operations. When possible they are * implemented as true processor specific atomic operations. When that diff --git a/test/testatomic.c b/test/testatomic.c index cce12aefa..065b1d2c6 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -231,10 +231,403 @@ void RunEpicTest() /* End atomic operation test */ /**************************************************************************/ +/**************************************************************************/ +/* Lock-free FIFO test */ + +#define NUM_READERS 4 +#define NUM_WRITERS 4 +#define EVENTS_PER_WRITER 1000000 + +/* A decent guess for the size of a cache line on this architecture */ +#define CACHELINE 64 + +/* The number of entries must be a power of 2 */ +#define MAX_ENTRIES 256 +#define WRAP_MASK (MAX_ENTRIES-1) + +typedef struct +{ + SDL_atomic_t sequence; + SDL_Event event; +} SDL_EventQueueEntry; + +typedef struct +{ + SDL_EventQueueEntry entries[MAX_ENTRIES]; + + char cache_pad1[CACHELINE-((sizeof(SDL_EventQueueEntry)*MAX_ENTRIES)%CACHELINE)]; + + SDL_atomic_t enqueue_pos; + + char cache_pad2[CACHELINE-sizeof(SDL_atomic_t)]; + + SDL_atomic_t dequeue_pos; + + char cache_pad3[CACHELINE-sizeof(SDL_atomic_t)]; + + SDL_bool active; + + /* Only needed for the mutex test */ + SDL_mutex *mutex; + +} SDL_EventQueue; + +static void InitEventQueue(SDL_EventQueue *queue) +{ + int i; + + for (i = 0; i < MAX_ENTRIES; ++i) { + SDL_AtomicSet(&queue->entries[i].sequence, i); + } + SDL_AtomicSet(&queue->enqueue_pos, 0); + SDL_AtomicSet(&queue->dequeue_pos, 0); + queue->active = SDL_TRUE; +} + +static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *event) +{ + SDL_EventQueueEntry *entry; + unsigned queue_pos; + unsigned entry_seq; + int delta; + + queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos); + for ( ; ; ) { + entry = &queue->entries[queue_pos & WRAP_MASK]; + entry_seq = (unsigned)SDL_AtomicGet(&entry->sequence); + + delta = (int)(entry_seq - queue_pos); + if (delta == 0) { + /* The entry and the queue position match, try to increment the queue position */ + if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos+1))) { + break; + } + } else if (delta < 0) { + /* We ran into an old queue entry, which means it still needs to be dequeued */ + return SDL_FALSE; + } else { + /* We ran into a new queue entry, get the new queue position */ + queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos); + } + } + + /* We own the object, fill it! */ + entry->event = *event; + SDL_AtomicSet(&entry->sequence, (int)(queue_pos + 1)); + + return SDL_TRUE; +} + +static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event) +{ + SDL_EventQueueEntry *entry; + unsigned queue_pos; + unsigned entry_seq; + int delta; + + queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos); + for ( ; ; ) { + entry = &queue->entries[queue_pos & WRAP_MASK]; + entry_seq = (unsigned)SDL_AtomicGet(&entry->sequence); + + delta = (int)(entry_seq - (queue_pos + 1)); + if (delta == 0) { + /* The entry and the queue position match, try to increment the queue position */ + if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos+1))) { + break; + } + } else if (delta < 0) { + /* We ran into an old queue entry, which means we've hit empty */ + return SDL_FALSE; + } else { + /* We ran into a new queue entry, get the new queue position */ + queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos); + } + } + + /* We own the object, fill it! */ + *event = entry->event; + SDL_AtomicSet(&entry->sequence, (int)(queue_pos+MAX_ENTRIES)); + + return SDL_TRUE; +} + +static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event) +{ + SDL_EventQueueEntry *entry; + unsigned queue_pos; + unsigned entry_seq; + int delta; + + SDL_mutexP(queue->mutex); + + queue_pos = (unsigned)queue->enqueue_pos.value; + entry = &queue->entries[queue_pos & WRAP_MASK]; + entry_seq = (unsigned)entry->sequence.value; + + delta = (int)(entry_seq - queue_pos); + if (delta == 0) { + ++queue->enqueue_pos.value; + } else if (delta < 0) { + /* We ran into an old queue entry, which means it still needs to be dequeued */ + SDL_mutexV(queue->mutex); + return SDL_FALSE; + } else { + printf("ERROR: mutex failed!\n"); + } + + /* We own the object, fill it! */ + entry->event = *event; + entry->sequence.value = (int)(queue_pos + 1); + + SDL_mutexV(queue->mutex); + + return SDL_TRUE; +} + +static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) +{ + SDL_EventQueueEntry *entry; + unsigned queue_pos; + unsigned entry_seq; + int delta; + + SDL_mutexP(queue->mutex); + + queue_pos = (unsigned)queue->dequeue_pos.value; + entry = &queue->entries[queue_pos & WRAP_MASK]; + entry_seq = (unsigned)entry->sequence.value; + + delta = (int)(entry_seq - (queue_pos + 1)); + if (delta == 0) { + ++queue->dequeue_pos.value; + } else if (delta < 0) { + /* We ran into an old queue entry, which means we've hit empty */ + SDL_mutexV(queue->mutex); + return SDL_FALSE; + } else { + printf("ERROR: mutex failed!\n"); + } + + /* We own the object, fill it! */ + *event = entry->event; + entry->sequence.value = (int)(queue_pos + MAX_ENTRIES); + + SDL_mutexV(queue->mutex); + + return SDL_TRUE; +} + +static SDL_sem *writersDone; +static SDL_sem *readersDone; +static SDL_atomic_t writersRunning; +static SDL_atomic_t readersRunning; + +typedef struct +{ + SDL_EventQueue *queue; + int index; + char padding1[CACHELINE-(sizeof(SDL_EventQueue*)+sizeof(int))%CACHELINE]; + int waits; + SDL_bool lock_free; + char padding2[CACHELINE-sizeof(int)-sizeof(SDL_bool)]; +} WriterData; + +typedef struct +{ + SDL_EventQueue *queue; + int counters[NUM_WRITERS]; + int waits; + SDL_bool lock_free; + char padding[CACHELINE-(sizeof(SDL_EventQueue*)+sizeof(int)*NUM_WRITERS+sizeof(int)+sizeof(SDL_bool))%CACHELINE]; +} ReaderData; + +static int FIFO_Writer(void* _data) +{ + WriterData *data = (WriterData *)_data; + SDL_EventQueue *queue = data->queue; + int index = data->index; + int i; + SDL_Event event; + + event.type = SDL_USEREVENT; + event.user.windowID = 0; + event.user.code = 0; + event.user.data1 = data; + event.user.data2 = NULL; + + if (data->lock_free) { + for (i = 0; i < EVENTS_PER_WRITER; ++i) { + event.user.code = i; + while (!EnqueueEvent_LockFree(queue, &event)) { + ++data->waits; + SDL_Delay(0); + } + } + } else { + for (i = 0; i < EVENTS_PER_WRITER; ++i) { + event.user.code = i; + while (!EnqueueEvent_Mutex(queue, &event)) { + ++data->waits; + SDL_Delay(0); + } + } + } + SDL_AtomicAdd(&writersRunning, -1); + SDL_SemPost(writersDone); + return 0; +} + +static int FIFO_Reader(void* _data) +{ + ReaderData *data = (ReaderData *)_data; + SDL_EventQueue *queue = data->queue; + SDL_Event event; + int index; + + if (data->lock_free) { + for ( ; ; ) { + if (DequeueEvent_LockFree(queue, &event)) { + WriterData *writer = (WriterData*)event.user.data1; + ++data->counters[writer->index]; + } else if (queue->active) { + ++data->waits; + SDL_Delay(0); + } else { + /* We drained the queue, we're done! */ + break; + } + } + } else { + for ( ; ; ) { + if (DequeueEvent_Mutex(queue, &event)) { + WriterData *writer = (WriterData*)event.user.data1; + ++data->counters[writer->index]; + } else if (queue->active) { + ++data->waits; + SDL_Delay(0); + } else { + /* We drained the queue, we're done! */ + break; + } + } + } + SDL_AtomicAdd(&readersRunning, -1); + SDL_SemPost(readersDone); + return 0; +} + +static void RunFIFOTest(SDL_bool lock_free) +{ + SDL_EventQueue queue; + WriterData writerData[NUM_WRITERS]; + ReaderData readerData[NUM_READERS]; + Uint32 start, end; + int i, j; + int grand_total; + + printf("\nFIFO test---------------------------------------\n\n"); + printf("Mode: %s\n", lock_free ? "LockFree" : "Mutex"); + + readersDone = SDL_CreateSemaphore(0); + writersDone = SDL_CreateSemaphore(0); + + SDL_memset(&queue, 0xff, sizeof(queue)); + + InitEventQueue(&queue); + if (!lock_free) { + queue.mutex = SDL_CreateMutex(); + } + + start = SDL_GetTicks(); + + /* Start the readers first */ + printf("Starting %d readers\n", NUM_READERS); + SDL_zero(readerData); + SDL_AtomicSet(&readersRunning, NUM_READERS); + for (i = 0; i < NUM_READERS; ++i) { + readerData[i].queue = &queue; + readerData[i].lock_free = lock_free; + SDL_CreateThread(FIFO_Reader, &readerData[i]); + } + + /* Start up the writers */ + printf("Starting %d writers\n", NUM_WRITERS); + SDL_zero(writerData); + SDL_AtomicSet(&writersRunning, NUM_WRITERS); + for (i = 0; i < NUM_WRITERS; ++i) { + writerData[i].queue = &queue; + writerData[i].index = i; + writerData[i].lock_free = lock_free; + SDL_CreateThread(FIFO_Writer, &writerData[i]); + } + + /* Wait for the writers */ + while (SDL_AtomicGet(&writersRunning) > 0) { + SDL_SemWait(writersDone); + } + + /* Shut down the queue so readers exit */ + queue.active = SDL_FALSE; + + /* Wait for the readers */ + while (SDL_AtomicGet(&readersRunning) > 0) { + SDL_SemWait(readersDone); + } + + end = SDL_GetTicks(); + + SDL_DestroySemaphore(readersDone); + SDL_DestroySemaphore(writersDone); + + if (!lock_free) { + SDL_DestroyMutex(queue.mutex); + } + + printf("Finished in %f sec\n", (end - start) / 1000.f); + + printf("\n"); + for (i = 0; i < NUM_WRITERS; ++i) { + printf("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits); + } + printf("Writers wrote %d total events\n", NUM_WRITERS*EVENTS_PER_WRITER); + + /* Print a breakdown of which readers read messages from which writer */ + printf("\n"); + grand_total = 0; + for (i = 0; i < NUM_READERS; ++i) { + int total = 0; + for (j = 0; j < NUM_WRITERS; ++j) { + total += readerData[i].counters[j]; + } + grand_total += total; + printf("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits); + printf(" { "); + for (j = 0; j < NUM_WRITERS; ++j) { + if (j > 0) { + printf(", "); + } + printf("%d", readerData[i].counters[j]); + } + printf(" }\n"); + } + printf("Readers read %d total events\n", grand_total); +} + +/* End FIFO test */ +/**************************************************************************/ + int main(int argc, char *argv[]) { RunBasicTest(); RunEpicTest(); +/* This test is really slow, so don't run it by default */ +#if 0 + RunFIFOTest(SDL_FALSE); +#endif + RunFIFOTest(SDL_TRUE); return 0; } + +/* vi: set ts=4 sw=4 expandtab: */ From 45a109abad724e02517f4bb2628435668f63c219 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 26 Jan 2011 00:03:34 -0800 Subject: [PATCH 18/44] Added a test to measure the impact of a separate thread periodically locking the queue entirely. --- test/testatomic.c | 125 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 99 insertions(+), 26 deletions(-) diff --git a/test/testatomic.c b/test/testatomic.c index 065b1d2c6..c034bd6de 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -234,6 +234,11 @@ void RunEpicTest() /**************************************************************************/ /* Lock-free FIFO test */ +/* This is useful to test the impact of another thread locking the queue + entirely for heavy-weight manipulation. + */ +#define TEST_SPINLOCK_FIFO + #define NUM_READERS 4 #define NUM_WRITERS 4 #define EVENTS_PER_WRITER 1000000 @@ -265,6 +270,14 @@ typedef struct char cache_pad3[CACHELINE-sizeof(SDL_atomic_t)]; +#ifdef TEST_SPINLOCK_FIFO + SDL_SpinLock lock; + SDL_atomic_t rwcount; + SDL_atomic_t watcher; + + char cache_pad4[CACHELINE-sizeof(SDL_SpinLock)-2*sizeof(SDL_atomic_t)]; +#endif + SDL_bool active; /* Only needed for the mutex test */ @@ -281,6 +294,10 @@ static void InitEventQueue(SDL_EventQueue *queue) } SDL_AtomicSet(&queue->enqueue_pos, 0); SDL_AtomicSet(&queue->dequeue_pos, 0); +#ifdef TEST_SPINLOCK_FIFO + queue->lock = 0; + SDL_AtomicSet(&queue->rwcount, 0); +#endif queue->active = SDL_TRUE; } @@ -290,6 +307,15 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev unsigned queue_pos; unsigned entry_seq; int delta; + SDL_bool status; + +#ifdef TEST_SPINLOCK_FIFO + /* This is a gate so an external thread can lock the queue */ + SDL_AtomicLock(&queue->lock); + SDL_assert(SDL_AtomicGet(&queue->watcher) == 0); + SDL_AtomicIncRef(&queue->rwcount); + SDL_AtomicUnlock(&queue->lock); +#endif queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos); for ( ; ; ) { @@ -300,22 +326,26 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev if (delta == 0) { /* The entry and the queue position match, try to increment the queue position */ if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos+1))) { + /* We own the object, fill it! */ + entry->event = *event; + SDL_AtomicSet(&entry->sequence, (int)(queue_pos + 1)); + status = SDL_TRUE; break; } } else if (delta < 0) { /* We ran into an old queue entry, which means it still needs to be dequeued */ - return SDL_FALSE; + status = SDL_FALSE; + break; } else { /* We ran into a new queue entry, get the new queue position */ queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos); } } - /* We own the object, fill it! */ - entry->event = *event; - SDL_AtomicSet(&entry->sequence, (int)(queue_pos + 1)); - - return SDL_TRUE; +#ifdef TEST_SPINLOCK_FIFO + SDL_AtomicDecRef(&queue->rwcount); +#endif + return status; } static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event) @@ -324,6 +354,15 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event) unsigned queue_pos; unsigned entry_seq; int delta; + SDL_bool status; + +#ifdef TEST_SPINLOCK_FIFO + /* This is a gate so an external thread can lock the queue */ + SDL_AtomicLock(&queue->lock); + SDL_assert(SDL_AtomicGet(&queue->watcher) == 0); + SDL_AtomicIncRef(&queue->rwcount); + SDL_AtomicUnlock(&queue->lock); +#endif queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos); for ( ; ; ) { @@ -334,22 +373,26 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event) if (delta == 0) { /* The entry and the queue position match, try to increment the queue position */ if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos+1))) { + /* We own the object, fill it! */ + *event = entry->event; + SDL_AtomicSet(&entry->sequence, (int)(queue_pos+MAX_ENTRIES)); + status = SDL_TRUE; break; } } else if (delta < 0) { /* We ran into an old queue entry, which means we've hit empty */ - return SDL_FALSE; + status = SDL_FALSE; + break; } else { /* We ran into a new queue entry, get the new queue position */ queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos); } } - /* We own the object, fill it! */ - *event = entry->event; - SDL_AtomicSet(&entry->sequence, (int)(queue_pos+MAX_ENTRIES)); - - return SDL_TRUE; +#ifdef TEST_SPINLOCK_FIFO + SDL_AtomicDecRef(&queue->rwcount); +#endif + return status; } static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event) @@ -358,6 +401,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event unsigned queue_pos; unsigned entry_seq; int delta; + SDL_bool status = SDL_FALSE; SDL_mutexP(queue->mutex); @@ -368,21 +412,20 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event delta = (int)(entry_seq - queue_pos); if (delta == 0) { ++queue->enqueue_pos.value; + + /* We own the object, fill it! */ + entry->event = *event; + entry->sequence.value = (int)(queue_pos + 1); + status = SDL_TRUE; } else if (delta < 0) { /* We ran into an old queue entry, which means it still needs to be dequeued */ - SDL_mutexV(queue->mutex); - return SDL_FALSE; } else { printf("ERROR: mutex failed!\n"); } - /* We own the object, fill it! */ - entry->event = *event; - entry->sequence.value = (int)(queue_pos + 1); - SDL_mutexV(queue->mutex); - return SDL_TRUE; + return status; } static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) @@ -391,6 +434,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) unsigned queue_pos; unsigned entry_seq; int delta; + SDL_bool status = SDL_FALSE; SDL_mutexP(queue->mutex); @@ -401,21 +445,20 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) delta = (int)(entry_seq - (queue_pos + 1)); if (delta == 0) { ++queue->dequeue_pos.value; + + /* We own the object, fill it! */ + *event = entry->event; + entry->sequence.value = (int)(queue_pos + MAX_ENTRIES); + status = SDL_TRUE; } else if (delta < 0) { /* We ran into an old queue entry, which means we've hit empty */ - SDL_mutexV(queue->mutex); - return SDL_FALSE; } else { printf("ERROR: mutex failed!\n"); } - /* We own the object, fill it! */ - *event = entry->event; - entry->sequence.value = (int)(queue_pos + MAX_ENTRIES); - SDL_mutexV(queue->mutex); - return SDL_TRUE; + return status; } static SDL_sem *writersDone; @@ -517,6 +560,29 @@ static int FIFO_Reader(void* _data) return 0; } +#ifdef TEST_SPINLOCK_FIFO +/* This thread periodically locks the queue for no particular reason */ +static int FIFO_Watcher(void* _data) +{ + SDL_EventQueue *queue = (SDL_EventQueue *)_data; + + while (queue->active) { + SDL_AtomicLock(&queue->lock); + SDL_AtomicIncRef(&queue->watcher); + while (SDL_AtomicGet(&queue->rwcount) > 0) { + SDL_Delay(0); + } + /* Do queue manipulation here... */ + SDL_AtomicDecRef(&queue->watcher); + SDL_AtomicUnlock(&queue->lock); + + /* Wait a bit... */ + SDL_Delay(1); + } + return 0; +} +#endif /* TEST_SPINLOCK_FIFO */ + static void RunFIFOTest(SDL_bool lock_free) { SDL_EventQueue queue; @@ -541,6 +607,13 @@ static void RunFIFOTest(SDL_bool lock_free) start = SDL_GetTicks(); +#ifdef TEST_SPINLOCK_FIFO + /* Start a monitoring thread */ + if (lock_free) { + SDL_CreateThread(FIFO_Watcher, &queue); + } +#endif + /* Start the readers first */ printf("Starting %d readers\n", NUM_READERS); SDL_zero(readerData); From 46fea0e925cb2140b2b4d554e2ad621ec8977b0b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 26 Jan 2011 12:23:32 -0800 Subject: [PATCH 19/44] Ozkan Sezer to slouken The attached small patch updates SDL's libtoolized files for pe-x86_64 magic, ie win/x64. --- acinclude/libtool.m4 | 2 +- build-scripts/ltmain.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/acinclude/libtool.m4 b/acinclude/libtool.m4 index 6894db826..b64223e2e 100644 --- a/acinclude/libtool.m4 +++ b/acinclude/libtool.m4 @@ -3014,7 +3014,7 @@ mingw* | pw32*) lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' else - lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' lt_cv_file_magic_cmd='$OBJDUMP -f' fi lt_cv_deplibs_check_method=pass_all diff --git a/build-scripts/ltmain.sh b/build-scripts/ltmain.sh index d2b860f42..5e04f0862 100644 --- a/build-scripts/ltmain.sh +++ b/build-scripts/ltmain.sh @@ -2560,7 +2560,7 @@ func_win32_libid () ;; *ar\ archive*) # could be an import, or static if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | - $EGREP 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then + $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null ; then win32_nmres=`eval $NM -f posix -A $1 | $SED -n -e ' 1,100{ From 647b5a4fa1e0b06acf8d7524c534c43ca5af9438 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 26 Jan 2011 19:20:16 -0800 Subject: [PATCH 20/44] Since we're directly reading and writing 'active' from different threads, it needs to be flagged volatile. --- test/testatomic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testatomic.c b/test/testatomic.c index c034bd6de..98a6a7824 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -278,7 +278,7 @@ typedef struct char cache_pad4[CACHELINE-sizeof(SDL_SpinLock)-2*sizeof(SDL_atomic_t)]; #endif - SDL_bool active; + volatile SDL_bool active; /* Only needed for the mutex test */ SDL_mutex *mutex; From 9195b9f9229ee81f057ac39ff6d7240533817d2a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 00:06:36 -0800 Subject: [PATCH 21/44] Nobody is maintaining RISC OS code, so I'm removing it for now. --- README | 9 +- README.RISCOS | 129 --- configure.in | 26 - include/SDL_config.h.in | 3 - src/joystick/riscos/SDL_sysjoystick.c | 180 ----- src/thread/pthread/SDL_systhread.c | 14 - src/thread/riscos/SDL_syscond.c | 167 ---- src/thread/riscos/SDL_sysmutex.c | 159 ---- src/thread/riscos/SDL_sysmutex_c.h | 36 - src/thread/riscos/SDL_syssem.c | 216 ----- src/thread/riscos/SDL_systhread.c | 141 ---- src/thread/riscos/SDL_systhread_c.h | 36 - src/timer/riscos/SDL_systimer.c | 248 ------ src/video/SDL_sysvideo.h | 3 - src/video/SDL_video.c | 3 - src/video/riscos/SDL_riscosASM.S | 116 --- src/video/riscos/SDL_riscosFullScreenVideo.c | 802 ------------------- src/video/riscos/SDL_riscosevents.c | 598 -------------- src/video/riscos/SDL_riscosevents_c.h | 34 - src/video/riscos/SDL_riscosmouse.c | 380 --------- src/video/riscos/SDL_riscosmouse_c.h | 46 -- src/video/riscos/SDL_riscossprite.c | 263 ------ src/video/riscos/SDL_riscostask.c | 367 --------- src/video/riscos/SDL_riscostask.h | 41 - src/video/riscos/SDL_riscosvideo.c | 337 -------- src/video/riscos/SDL_riscosvideo.h | 64 -- src/video/riscos/SDL_wimppoll.c | 334 -------- src/video/riscos/SDL_wimpvideo.c | 511 ------------ 28 files changed, 4 insertions(+), 5259 deletions(-) delete mode 100644 README.RISCOS delete mode 100644 src/joystick/riscos/SDL_sysjoystick.c delete mode 100644 src/thread/riscos/SDL_syscond.c delete mode 100644 src/thread/riscos/SDL_sysmutex.c delete mode 100644 src/thread/riscos/SDL_sysmutex_c.h delete mode 100644 src/thread/riscos/SDL_syssem.c delete mode 100644 src/thread/riscos/SDL_systhread.c delete mode 100644 src/thread/riscos/SDL_systhread_c.h delete mode 100644 src/timer/riscos/SDL_systimer.c delete mode 100644 src/video/riscos/SDL_riscosASM.S delete mode 100644 src/video/riscos/SDL_riscosFullScreenVideo.c delete mode 100644 src/video/riscos/SDL_riscosevents.c delete mode 100644 src/video/riscos/SDL_riscosevents_c.h delete mode 100644 src/video/riscos/SDL_riscosmouse.c delete mode 100644 src/video/riscos/SDL_riscosmouse_c.h delete mode 100644 src/video/riscos/SDL_riscossprite.c delete mode 100644 src/video/riscos/SDL_riscostask.c delete mode 100644 src/video/riscos/SDL_riscostask.h delete mode 100644 src/video/riscos/SDL_riscosvideo.c delete mode 100644 src/video/riscos/SDL_riscosvideo.h delete mode 100644 src/video/riscos/SDL_wimppoll.c delete mode 100644 src/video/riscos/SDL_wimpvideo.c diff --git a/README b/README index f2667e95c..6098a9133 100644 --- a/README +++ b/README @@ -3,7 +3,7 @@ (SDL) - Version 1.2 + Version 1.3 --- http://www.libsdl.org/ @@ -12,10 +12,9 @@ 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 Linux, Windows, Windows CE, BeOS, MacOS, -Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. -The code contains support for AIX, OSF/Tru64, RISC OS, and SymbianOS, -but these are not officially supported. +The current version supports Windows, Windows CE, Mac OS X, Linux, FreeBSD, +NetBSD, OpenBSD, BSD/OS, Solaris, QNX, iOS, and Android. The code contains +support for other operating systems but those are not officially supported. SDL is written in C, but works with C++ natively, and has bindings to several other languages, including Ada, C#, Eiffel, Erlang, Euphoria, diff --git a/README.RISCOS b/README.RISCOS deleted file mode 100644 index 3a526b11b..000000000 --- a/README.RISCOS +++ /dev/null @@ -1,129 +0,0 @@ -Readme for RISC OS port of SDL -============================== - -This document last updated on 2nd Februrary 2006 - -This is a RISC OS port of the Simple Direct Media Layer (SDL) by Alan Buckley with contributions from Peter Naulls. - -Details of the SDL can be found at http://www.libsdl.org. - -The source code including the RISC OS version can be obtained from: - -http://www.libsdl.org. - -Pre built libraries and many games and applications compiled for RISC OS using this library can be downloaded from The Unix Porting Project at http://www.riscos.info/unix/. - -This is released under the LGPL see the file COPYING for details. - - -Compiling applications under RISC OS -==================================== - -Add -ISDL: for the C compiler flags if you include the files in the SDL directory. e.g. #include "SDL/SDL.h" -Add -ISDL:SDL for the C compiler flags if you include the files directly. e.g. #include "SDL/SDL.h" - -Add -LSDL: -lSDL to the link stage of compilation. - -For example, to compile the testbitmap.c sample you could use: - -gcc -ISDL:SDL -LSDL: -lSDL testbitmap.c -otestbitmap - - -RISC OS port of SDL runtime information -======================================= - -Runtime requirements --------------------- - -This library currently needs a minimum of RISC OS 3.6. The source code for the library (and a lot of the programs built with it) also need long file names. - -To use the audio you also need 16 bit sound and to have installed the DigitalRender module by Andreas Dehmel version 0.51 available from his -web site: http://home.t-online.de/~zarquon -This is loaded when needed by UnixLib. - -Note: As most programs ported from other OSes use high resolution graphics and a memory back buffer a machine with a StrongARM processor and 1 or 2MB of VRAM (or a better machine) is recomended. - - -RISC OS runtime parameters --------------------------- - -Several environmental variables have been defined to make porting programs easier (i.e. By setting these variable you do not need to have source code differences between OSes). - -They are all defined on an application basis. - -The used below is found as follows: -1. Use the name of the program unless it is !RunImage -2. Check the folder specification for the folder !RunImage is run from. If it is a folder name use that name, otherwise if it is an environmental variable of the form use the value of XXX. - -The variables are: - -SDL$$TaskName - -The name of the task for RISC OS. If omitted then is used for the task name, - -SDL$$BackBuffer - -Set to 1 to use a system memory back buffer for the screen in full screen mode. Some programs on other systems assume their is always a back buffer even though the SDL specification specifies this is not the case. The current RISC OS implementation uses direct writes to the screen if a hardware fullscreen is requested. - -Set to 2 to use an ARM code full word copy. This is faster than the standard back buffer, but uses aligned words only so it is possible (but unlikely) for it to corrupt the screen for 8bpp and 16bpp modes. - -Set to 3 to use a RISC OS sprite as the back buffer. This is usually the slowest for most SDL applications, however it may be useful in the future as Sprite acceleration is added to various hardware that runs RISC OS. - -SDL$$CloseAction - set the action for the close icon. Again as programs don't match the specification you can set this to 0 to remove the close icon from the main window for applications where this does not affect the program. - - -RISC OS SDL port API notes -========================== - -Current level of implementation -------------------------------- - -The following list is an overview of how much of the SDL is implemented. The areas match the main areas of the SDL. - -video - Mostly done. Doesn't cover gamma, YUV-overlay or OpenGL. -Window Manager - Mostly done. SetIcon/IconifyWindow not implemented. -Events - Mostly done. Resize and some joystick events missing. -Joystick - Currently assumes a single joystick with 4 buttons. -Audio - Done -Threads - Done -Timers - Done - -Thread support can be removed by defining DISABLE_THREADS and recompiling the library. - -SDL API notes -------------- - -This section contains additional notes on some specific commands. - -SDL_SetVideoMode - On RISC OS a fullscreen mode directly accesses the screen. This can be modified by the environmental variable (SDL$$BackBuffer) or by using the SDL_SWSURFACE flag to write to an offscreen buffer that is updated using SDL_UpdateRects. - Open GL is not supported so SDL_OPENGL and SDL_OPENGLBLIT flags fail. - SDL_RESIZEABLE and SDL_NOFRAME flags are not supported. - -SDL_SetColors - In a wimp mode the screen colours are not changed for a hardware palette instead the RISC OS sprite colour mapping is used to get the best matching colours. - -SDL_CreateCursor - Inverted colour is not supported. - -SDL_WM_ToggleFullScreen - Currently this won't work if the application starts up in Fullscreen mode. - Toggling to fullscreen will only work if the monitor is set up to support the exact screen size requested. - -SDL_EnableUNICODE - Unicode translation used here is only really accurate for 7 bit characters. - -SDL_NumJoysticks/JoystickName etc. - Hardcoded to expect only 1 joystick with 4 buttons if the Joystick module is loaded. - -SDL_GetTicks - Timer used has only a centisecond accuracy. This applies to other time related functions. - -SDL_Delay - Modified to poll keyboard/mouse during the delay on the event thread. - - -Notes on current implementation -------------------------------- - -Keyboard and mouse are polled so if too long a time is spent between a call to SDL_PumpEvents, functions that use it, or SDL_Delay events can be missed. diff --git a/configure.in b/configure.in index 2bbff60d7..dde39bb08 100644 --- a/configure.in +++ b/configure.in @@ -2668,32 +2668,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit" fi ;; - *-riscos) - ARCH=riscos - CheckOSS - CheckPTHREAD - # Set up files for the video library - if test x$enable_video = xyes; then - AC_DEFINE(SDL_VIDEO_DRIVER_RISCOS) - SOURCES="$SOURCES $srcdir/src/video/riscos/*.c" - SOURCES="$SOURCES $srcdir/src/video/riscos/*.S" - have_video=yes - fi - # Set up files for the joystick library - if test x$enable_joystick = xyes; then - AC_DEFINE(SDL_JOYSTICK_RISCOS) - SOURCES="$SOURCES $srcdir/src/joystick/riscos/*.c" - have_joystick=yes - fi - # Set up files for the timer library - if test x$enable_timers = xyes; then - AC_DEFINE(SDL_TIMER_RISCOS) - SOURCES="$SOURCES $srcdir/src/timer/riscos/*.c" - have_timers=yes - fi - # The RISC OS platform requires special setup. - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ljpeg -ltiff -lpng -lz" - ;; *) AC_MSG_ERROR([ *** Unsupported host: Please add to configure.in diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 625608532..cfa2ae8c1 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -221,7 +221,6 @@ #undef SDL_JOYSTICK_IOKIT #undef SDL_JOYSTICK_LINUX #undef SDL_JOYSTICK_NDS -#undef SDL_JOYSTICK_RISCOS #undef SDL_JOYSTICK_WINMM #undef SDL_JOYSTICK_USBHID #undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H @@ -251,7 +250,6 @@ #undef SDL_TIMER_BEOS #undef SDL_TIMER_DUMMY #undef SDL_TIMER_NDS -#undef SDL_TIMER_RISCOS #undef SDL_TIMER_UNIX #undef SDL_TIMER_WINDOWS #undef SDL_TIMER_WINCE @@ -265,7 +263,6 @@ #undef SDL_VIDEO_DRIVER_NDS #undef SDL_VIDEO_DRIVER_PHOTON #undef SDL_VIDEO_DRIVER_QNXGF -#undef SDL_VIDEO_DRIVER_RISCOS #undef SDL_VIDEO_DRIVER_WINDOWS #undef SDL_VIDEO_DRIVER_X11 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC diff --git a/src/joystick/riscos/SDL_sysjoystick.c b/src/joystick/riscos/SDL_sysjoystick.c deleted file mode 100644 index 441ce8997..000000000 --- a/src/joystick/riscos/SDL_sysjoystick.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_RISCOS - -/* - RISC OS - Joystick support by Alan Buckley (alan_baa@hotmail.com) - 10 April 2003 - - Note: Currently assumes joystick is present if joystick module is loaded - and that there is one joystick with four buttons. -*/ - -/* This is the system specific header for the SDL joystick API */ - -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#include "kernel.h" - -#define JOYSTICK_READ 0x43F40 - -struct joystick_hwdata -{ - int joystate; -}; - - -/* 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) -{ - _kernel_swi_regs regs; - - /* Try to read joystick 0 */ - regs.r[0] = 0; - if (_kernel_swi(JOYSTICK_READ, ®s, ®s) == NULL) { - /* Switch works so assume we've got a joystick */ - return 1; - } - /* Switch fails so it looks like there's no joystick here */ - - return (0); -} - -/* Function to get the device-dependent name of a joystick */ -const char * -SDL_SYS_JoystickName(int index) -{ - if (index == 0) { - return "RISC OS Joystick 0"; - } - - 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) -{ - _kernel_swi_regs regs; - - if (!(joystick->hwdata = SDL_malloc(sizeof(struct joystick_hwdata)))) - return -1; - - regs.r[0] = joystick->index; - - /* Don't know how to get exact count of buttons so assume max of 4 for now */ - joystick->nbuttons = 4; - - joystick->nhats = 0; - joystick->nballs = 0; - joystick->naxes = 2; - joystick->hwdata->joystate = 0; - - 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) -{ - _kernel_swi_regs regs; - regs.r[0] = joystick->index; - - if (_kernel_swi(JOYSTICK_READ, ®s, ®s) == NULL) { - int newstate = regs.r[0]; - int oldstate = joystick->hwdata->joystate; - if (newstate != oldstate) { - if ((newstate & 0xFF) != (oldstate & 0xFF)) { - int y = regs.r[0] & 0xFF; - /* Convert to signed values */ - if (y >= 128) - y -= 256; - SDL_PrivateJoystickAxis(joystick, 1, -y * 256); /* Up and down opposite to result in SDL */ - } - if ((newstate & 0xFF00) != (oldstate & 0xFF00)) { - int x = (regs.r[0] & 0xFF00) >> 8; - if (x >= 128) - x -= 256; - SDL_PrivateJoystickAxis(joystick, 0, x * 256); - } - - if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) { - int buttons = (regs.r[0] & 0xFF0000) >> 16; - int oldbuttons = (oldstate & 0xFF0000) >> 16; - int i; - for (i = 0; i < joystick->nbuttons; i++) { - if ((buttons & (1 << i)) != (oldbuttons & (1 << i))) { - if (buttons & (1 << i)) - SDL_PrivateJoystickButton(joystick, i, - SDL_PRESSED); - else - SDL_PrivateJoystickButton(joystick, i, - SDL_RELEASED); - } - } - } - joystick->hwdata->joystate = newstate; - } - } - - return; -} - -/* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick * joystick) -{ - if (joystick->hwdata) - SDL_free(joystick->hwdata); - return; -} - -/* Function to perform any system-specific joystick related cleanup */ -void -SDL_SYS_JoystickQuit(void) -{ - SDL_numjoysticks = 0; - - return; -} - -#endif /* SDL_JOYSTICK_RISCOS */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index c4f694fbe..89ca1c4eb 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -34,14 +34,6 @@ static const int sig_list[] = { SIGVTALRM, SIGPROF, 0 }; -#ifdef __RISCOS__ -/* RISC OS needs to know the main thread for - * it's timer and event processing. */ -int riscos_using_threads = 0; -SDL_threadID riscos_main_thread = 0; /* Thread running events */ -#endif - - static void * RunThread(void *data) { @@ -67,12 +59,6 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) SDL_SetError("Not enough resources to create thread"); return (-1); } -#ifdef __RISCOS__ - if (riscos_using_threads == 0) { - riscos_using_threads = 1; - riscos_main_thread = SDL_ThreadID(); - } -#endif return (0); } diff --git a/src/thread/riscos/SDL_syscond.c b/src/thread/riscos/SDL_syscond.c deleted file mode 100644 index 4182fa3ca..000000000 --- a/src/thread/riscos/SDL_syscond.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* RISC OS implementations uses pthreads based on linux code */ - -#if SDL_THREADS_DISABLED -#include "../generic/SDL_syscond.c" -#else -#include -#include -#include - -#include "SDL_thread.h" -#include "SDL_sysmutex_c.h" - -struct SDL_cond -{ - pthread_cond_t cond; -}; - -/* Create a condition variable */ -SDL_cond * -SDL_CreateCond(void) -{ - SDL_cond *cond; - - cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); - if (cond) { - if (pthread_cond_init(&cond->cond, NULL) < 0) { - SDL_SetError("pthread_cond_init() failed"); - SDL_free(cond); - cond = NULL; - } - } - return (cond); -} - -/* Destroy a condition variable */ -void -SDL_DestroyCond(SDL_cond * cond) -{ - if (cond) { - pthread_cond_destroy(&cond->cond); - SDL_free(cond); - } -} - -/* Restart one of the threads that are waiting on the condition variable */ -int -SDL_CondSignal(SDL_cond * cond) -{ - int retval; - - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if (pthread_cond_signal(&cond->cond) != 0) { - SDL_SetError("pthread_cond_signal() failed"); - retval = -1; - } - return retval; -} - -/* Restart all threads that are waiting on the condition variable */ -int -SDL_CondBroadcast(SDL_cond * cond) -{ - int retval; - - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if (pthread_cond_broadcast(&cond->cond) != 0) { - SDL_SetError("pthread_cond_broadcast() failed"); - retval = -1; - } - return retval; -} - -int -SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) -{ - int retval; - struct timeval delta; - struct timespec abstime; - - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - gettimeofday(&delta, NULL); - - abstime.tv_sec = delta.tv_sec + (ms / 1000); - abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000; - if (abstime.tv_nsec > 1000000000) { - abstime.tv_sec += 1; - abstime.tv_nsec -= 1000000000; - } - - tryagain: - retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime); - switch (retval) { - case EINTR: - goto tryagain; - break; - case ETIMEDOUT: - retval = SDL_MUTEX_TIMEDOUT; - break; - case 0: - break; - default: - SDL_SetError("pthread_cond_timedwait() failed"); - retval = -1; - break; - } - return retval; -} - -/* Wait on the condition variable, unlocking the provided mutex. - The mutex must be locked before entering this function! - */ -int -SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) -{ - int retval; - - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) { - SDL_SetError("pthread_cond_wait() failed"); - retval = -1; - } - return retval; -} -#endif -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_sysmutex.c b/src/thread/riscos/SDL_sysmutex.c deleted file mode 100644 index c4d842b94..000000000 --- a/src/thread/riscos/SDL_sysmutex.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* RISC OS implementations uses pthreads based on linux code */ - -#include "SDL_thread.h" - -#if SDL_THREADS_DISABLED -#include "../generic/SDL_sysmutex.c" -#else - -#include - -struct SDL_mutex -{ - pthread_mutex_t id; -#if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - int recursive; - pthread_t owner; -#endif -}; - -SDL_mutex * -SDL_CreateMutex(void) -{ - SDL_mutex *mutex; - pthread_mutexattr_t attr; - - /* Allocate the structure */ - mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex)); - if (mutex) { - pthread_mutexattr_init(&attr); -#if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - /* No extra attributes necessary */ -#else - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); -#endif /* SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX */ - if (pthread_mutex_init(&mutex->id, &attr) != 0) { - SDL_SetError("pthread_mutex_init() failed"); - SDL_free(mutex); - mutex = NULL; - } - } else { - SDL_OutOfMemory(); - } - return (mutex); -} - -void -SDL_DestroyMutex(SDL_mutex * mutex) -{ - if (mutex) { - pthread_mutex_destroy(&mutex->id); - SDL_free(mutex); - } -} - -/* Lock the mutex */ -int -SDL_mutexP(SDL_mutex * mutex) -{ - int retval; -#if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - pthread_t this_thread; -#endif - - if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - retval = 0; -#if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - this_thread = pthread_self(); - 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. - */ - if (pthread_mutex_lock(&mutex->id) == 0) { - mutex->owner = this_thread; - mutex->recursive = 0; - } else { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; - } - } -#else - if (pthread_mutex_lock(&mutex->id) < 0) { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; - } -#endif - return retval; -} - -int -SDL_mutexV(SDL_mutex * mutex) -{ - int retval; - - if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - retval = 0; -#if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - /* We can only unlock the mutex if we own it */ - if (pthread_self() == mutex->owner) { - 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; - pthread_mutex_unlock(&mutex->id); - } - } else { - SDL_SetError("mutex not owned by this thread"); - retval = -1; - } - -#else - if (pthread_mutex_unlock(&mutex->id) < 0) { - SDL_SetError("pthread_mutex_unlock() failed"); - retval = -1; - } -#endif /* SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX */ - - return retval; -} -#endif -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_sysmutex_c.h b/src/thread/riscos/SDL_sysmutex_c.h deleted file mode 100644 index 25d8e2cfb..000000000 --- a/src/thread/riscos/SDL_sysmutex_c.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifndef _SDL_mutex_c_h -#define _SDL_mutex_c_h - -#if !SDL_THREADS_DISABLED -struct SDL_mutex -{ - pthread_mutex_t id; -}; -#endif - - -#endif /* _SDL_mutex_c_h */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_syssem.c b/src/thread/riscos/SDL_syssem.c deleted file mode 100644 index ab481776d..000000000 --- a/src/thread/riscos/SDL_syssem.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* RISC OS semiphores based on linux code */ - - -#include "SDL_timer.h" -#include "SDL_thread.h" -#include "SDL_systhread_c.h" - -#if !SDL_THREADS_DISABLED - -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 - - -#include /* For getpid() */ -#include -#include - -struct SDL_semaphore -{ - sem_t *sem; - sem_t sem_data; -}; - -/* Create a semaphore, initialized with value */ -SDL_sem * -SDL_CreateSemaphore(Uint32 initial_value) -{ - SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem)); - if (sem) { - if (sem_init(&sem->sem_data, 0, initial_value) < 0) { - SDL_SetError("sem_init() failed"); - SDL_free(sem); - sem = NULL; - } else { - sem->sem = &sem->sem_data; - } - } else { - SDL_OutOfMemory(); - } - return sem; -} - -void -SDL_DestroySemaphore(SDL_sem * sem) -{ - if (sem) { - sem_destroy(sem->sem); - SDL_free(sem); - } -} - -int -SDL_SemTryWait(SDL_sem * sem) -{ - int retval; - - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - retval = SDL_MUTEX_TIMEDOUT; - if (sem_trywait(sem->sem) == 0) { - retval = 0; - } - return retval; -} - -int -SDL_SemWait(SDL_sem * sem) -{ - int retval; - - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = sem_wait(sem->sem); - if (retval < 0) { - SDL_SetError("sem_wait() failed"); - } - return retval; -} - -int -SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) -{ - int retval; - - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - /* Try the easy cases first */ - if (timeout == 0) { - return SDL_SemTryWait(sem); - } - if (timeout == SDL_MUTEX_MAXWAIT) { - return SDL_SemWait(sem); - } - - /* Ack! We have to busy wait... */ - timeout += SDL_GetTicks(); - do { - retval = SDL_SemTryWait(sem); - if (retval == 0) { - break; - } - SDL_Delay(1); - } while (SDL_GetTicks() < timeout); - - return retval; -} - -Uint32 -SDL_SemValue(SDL_sem * sem) -{ - int ret = 0; - if (sem) { - sem_getvalue(sem->sem, &ret); - if (ret < 0) { - ret = 0; - } - } - return (Uint32) ret; -} - -int -SDL_SemPost(SDL_sem * sem) -{ - int retval; - - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = sem_post(sem->sem); - if (retval < 0) { - SDL_SetError("sem_post() failed"); - } - return retval; -} - -#endif /* !SDL_THREADS_DISABLED */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_systhread.c b/src/thread/riscos/SDL_systhread.c deleted file mode 100644 index 8940f2286..000000000 --- a/src/thread/riscos/SDL_systhread.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* RISC OS version based on pthreads linux source */ - -#include "SDL_thread.h" -#include "../SDL_systhread.h" - -#if SDL_THREADS_DISABLED - -int -SDL_SYS_CreateThread(SDL_Thread * thread, void *args) -{ - SDL_SetError - ("Threads have not been compiled into this version of the library"); - return (-1); -} - -void -SDL_SYS_SetupThread(void) -{ - return; -} - -SDL_threadID -SDL_ThreadID(void) -{ - return (0); -} - -void -SDL_SYS_WaitThread(SDL_Thread * thread) -{ - return; -} - -#else - -#include - -/* List of signals to mask in the subthreads */ -static int sig_list[] = { - SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, - SIGVTALRM, SIGPROF, 0 -}; - -#include - -int riscos_using_threads = 0; -Uint32 riscos_main_thread = 0; /* Thread running events */ - -static void * -RunThread(void *data) -{ - SDL_RunThread(data); - pthread_exit((void *) 0); - return ((void *) 0); /* Prevent compiler warning */ -} - -int -SDL_SYS_CreateThread(SDL_Thread * thread, void *args) -{ - pthread_attr_t type; - - /* Set the thread attributes */ - if (pthread_attr_init(&type) != 0) { - SDL_SetError("Couldn't initialize pthread attributes"); - return (-1); - } - 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); - } - - if (riscos_using_threads == 0) { - riscos_using_threads = 1; - riscos_main_thread = SDL_ThreadID(); - } - - return (0); -} - -void -SDL_SYS_SetupThread(void) -{ - int i; - sigset_t mask; - - /* Mask asynchronous signals for this thread */ - sigemptyset(&mask); - for (i = 0; sig_list[i]; ++i) { - sigaddset(&mask, sig_list[i]); - } - pthread_sigmask(SIG_BLOCK, &mask, 0); - -#ifdef PTHREAD_CANCEL_ASYNCHRONOUS - /* Allow ourselves to be asynchronously cancelled */ - { - int oldstate; - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); - } -#endif -} - -Uint32 -SDL_ThreadID(void) -{ - return ((Uint32) pthread_self()); -} - -void -SDL_SYS_WaitThread(SDL_Thread * thread) -{ - pthread_join(thread->handle, 0); -} - -#endif -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_systhread_c.h b/src/thread/riscos/SDL_systhread_c.h deleted file mode 100644 index 752af0f05..000000000 --- a/src/thread/riscos/SDL_systhread_c.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#if SDL_THREADS_DISABLED - -typedef int SYS_ThreadHandle; - -#else - -#include - -typedef pthread_t SYS_ThreadHandle; - -#endif - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/riscos/SDL_systimer.c b/src/timer/riscos/SDL_systimer.c deleted file mode 100644 index 5b25160f6..000000000 --- a/src/timer/riscos/SDL_systimer.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_TIMER_RISCOS - -#include -#include -#include -#include -#include -#include - -#include "SDL_timer.h" -#include "../SDL_timer_c.h" - -#if SDL_THREADS_DISABLED -/* Timer SDL_arraysize(Timer ),start/reset time */ -static Uint32 timerStart; -/* Timer running function */ -void RISCOS_CheckTimer(); -#else -#include -extern SDL_threadID riscos_main_thread; -extern int riscos_using_threads; -extern SDL_threadID SDL_ThreadID(); -extern SDL_threadID SDL_EventThreadID(void); -#endif - - -extern void RISCOS_BackgroundTasks(void); - -/* The first ticks value of the application */ -clock_t start; - -void -SDL_StartTicks(void) -{ - /* Set first ticks value */ - start = clock(); -} - -Uint32 -SDL_GetTicks(void) -{ - clock_t ticks; - - ticks = clock() - start; - - -#if CLOCKS_PER_SEC == 1000 - - return (ticks); - -#elif CLOCKS_PER_SEC == 100 - - return (ticks * 10); - -#else - - return ticks * (1000 / CLOCKS_PER_SEC); - -#endif - -} - -void -SDL_Delay(Uint32 ms) -{ - Uint32 now, then, elapsed; -#if !SDL_THREADS_DISABLED - int is_event_thread; - if (riscos_using_threads) { - is_event_thread = 0; - if (SDL_EventThreadID()) { - if (SDL_EventThreadID() == SDL_ThreadID()) - is_event_thread = 1; - } else if (SDL_ThreadID() == riscos_main_thread) - is_event_thread = 1; - } else - is_event_thread = 1; -#endif - - /*TODO: Next version of Unixlib may allow us to use usleep here */ - /* for non event threads */ - - /* Set the timeout interval - Linux only needs to do this once */ - then = SDL_GetTicks(); - - do { - /* Do background tasks required while sleeping as we are not multithreaded */ -#if SDL_THREADS_DISABLED - RISCOS_BackgroundTasks(); -#else - /* For threaded build only run background tasks in event thread */ - if (is_event_thread) - RISCOS_BackgroundTasks(); -#endif - - /* Calculate the time interval left (in case of interrupt) */ - now = SDL_GetTicks(); - elapsed = (now - then); - then = now; - if (elapsed >= ms) { - break; - } - ms -= elapsed; -#if !SDL_THREADS_DISABLED - /* Need to yield to let other threads have a go */ - if (riscos_using_threads) - pthread_yield(); -#endif - - } while (1); -} - -#if SDL_THREADS_DISABLED - -/* Non-threaded version of timer */ - -int -SDL_SYS_TimerInit(void) -{ - return (0); -} - -void -SDL_SYS_TimerQuit(void) -{ - SDL_SetTimer(0, NULL); -} - -int -SDL_SYS_StartTimer(void) -{ - timerStart = SDL_GetTicks(); - - return (0); -} - -void -SDL_SYS_StopTimer(void) -{ - /* Don't need to do anything as we use SDL_timer_running - to detect if we need to check the timer */ -} - - -void -RISCOS_CheckTimer() -{ - if (SDL_timer_running - && SDL_GetTicks() - timerStart >= SDL_alarm_interval) { - Uint32 ms; - - ms = SDL_alarm_callback(SDL_alarm_interval); - if (ms != SDL_alarm_interval) { - if (ms) { - SDL_alarm_interval = ROUND_RESOLUTION(ms); - } else { - SDL_alarm_interval = 0; - SDL_timer_running = 0; - } - } - if (SDL_alarm_interval) - timerStart = SDL_GetTicks(); - } -} - -#else - -/* Threaded version of timer - based on code for linux */ - -#include "SDL_thread.h" - -/* Data to handle a single periodic alarm */ -static int timer_alive = 0; -static SDL_Thread *timer = NULL; - -static int -RunTimer(void *unused) -{ - while (timer_alive) { - if (SDL_timer_running) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(1); - } - return (0); -} - -/* This is only called if the event thread is not running */ -int -SDL_SYS_TimerInit(void) -{ - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if (timer == NULL) - return (-1); - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - timer_alive = 0; - if (timer) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } -} - -int -SDL_SYS_StartTimer(void) -{ - SDL_SetError("Internal logic error: RISC OS uses threaded timer"); - return (-1); -} - -void -SDL_SYS_StopTimer(void) -{ - return; -} - -#endif /* SDL_THREADS_DISABLED */ - -#endif /* SDL_TIMER_RISCOS */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 55ef1e907..260dfedab 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -426,9 +426,6 @@ extern VideoBootStrap qnxgf_bootstrap; #if SDL_VIDEO_DRIVER_EPOC extern VideoBootStrap EPOC_bootstrap; #endif -#if SDL_VIDEO_DRIVER_RISCOS -extern VideoBootStrap RISCOS_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 99da176a9..9d1f85b23 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -80,9 +80,6 @@ static VideoBootStrap *bootstrap[] = { #if SDL_VIDEO_DRIVER_EPOC &EPOC_bootstrap, #endif -#if SDL_VIDEO_DRIVER_RISCOS - &RISCOS_bootstrap, -#endif #if SDL_VIDEO_DRIVER_NDS &NDS_bootstrap, #endif diff --git a/src/video/riscos/SDL_riscosASM.S b/src/video/riscos/SDL_riscosASM.S deleted file mode 100644 index 12b9e5e13..000000000 --- a/src/video/riscos/SDL_riscosASM.S +++ /dev/null @@ -1,116 +0,0 @@ -; -; SDL - Simple DirectMedia Layer -; Copyright (C) 1997-2009 Sam Lantinga -; -; This library is free software; you can redistribute it and/or -; modify it under the terms of the GNU Library General Public -; License as published by the Free Software Foundation; either -; version 2 of the License, or (at your option) any later version. -; -; This library is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -; Library General Public License for more details. -; -; You should have received a copy of the GNU Library General Public -; License along with this library; if not, write to the Free -; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -; -; Sam Lantinga -; slouken@libsdl.org -; -; Assembler routines for RISC OS display -; - - AREA |C$$CODE| - - EXPORT |RISCOS_Put32| - -; Display 32bpp to 32bpp, 1:1 -; -; Code provided by Adrain Lees -; -; entry a1 -> destination -; a2 = dest width in pixels -; a3 = dest line length in bytes -; a4 = dest height in scanlines -; arg5 -> source -; arg6 = byte offset from end of source line to start of next - -Arg5 * 10*4 -Arg6 * Arg5+4 - -RISCOS_Put32 ROUT - STMFD sp!,{a2,v1-v6,sl,fp,lr} - LDR ip,[sp,#Arg5] - MOV lr,a1 - B ucp64lp - -00 ;tail strip of 1-15 pixels - - LDR v1,[ip],#4 -01 SUBS a2,a2,#1 - STR v1,[lr],#4 - LDRHI v1,[ip],#4 - BHI %01 - B %02 - -ucp64end ADDS a2,a2,#16 - BNE %00 - -02 SUBS a4,a4,#1 ;height-- - LDRHI v1,[sp,#Arg6] - LDRHI a2,[sp] ;reload width - BLS %03 - - ;move to start of next scanline - - ADD lr,a1,a3 - ADD a1,a1,a3 - ADD ip,ip,v1 - -ucp64lp SUBS a2,a2,#16 - BLO ucp64end - - PLD [ip,#64] - - LDR v1,[ip],#4 - LDR v2,[ip],#4 - LDR v3,[ip],#4 - LDR v4,[ip],#4 - LDR v5,[ip],#4 - LDR v6,[ip],#4 - LDR sl,[ip],#4 - LDR fp,[ip],#4 - STR v1,[lr],#4 - STR v2,[lr],#4 - STR v3,[lr],#4 - STR v4,[lr],#4 - STR v5,[lr],#4 - STR v6,[lr],#4 - STR sl,[lr],#4 - STR fp,[lr],#4 - - PLD [ip,#64] - - LDR v1,[ip],#4 - LDR v2,[ip],#4 - LDR v3,[ip],#4 - LDR v4,[ip],#4 - LDR v5,[ip],#4 - LDR v6,[ip],#4 - LDR sl,[ip],#4 - LDR fp,[ip],#4 - STR v1,[lr],#4 - STR v2,[lr],#4 - STR v3,[lr],#4 - STR v4,[lr],#4 - STR v5,[lr],#4 - STR v6,[lr],#4 - STR sl,[lr],#4 - STR fp,[lr],#4 - - B ucp64lp - -03 LDMFD sp!,{a2,v1-v6,sl,fp,pc} - diff --git a/src/video/riscos/SDL_riscosFullScreenVideo.c b/src/video/riscos/SDL_riscosFullScreenVideo.c deleted file mode 100644 index 687321470..000000000 --- a/src/video/riscos/SDL_riscosFullScreenVideo.c +++ /dev/null @@ -1,802 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability - 27 March 2003 - - Implements RISC OS full screen display. -*/ - -#include "SDL_video.h" -#include "SDL_mouse.h" -#include "../SDL_sysvideo.h" -#include "../SDL_pixels_c.h" -#include "../../events/SDL_events_c.h" - -#include "SDL_riscostask.h" -#include "SDL_riscosvideo.h" -#include "SDL_riscosevents_c.h" -#include "SDL_riscosmouse_c.h" - -#include "kernel.h" -#include "swis.h" -#include "unixlib/os.h" -#include "unixlib/local.h" - -/* Private structures */ -typedef struct tagScreenModeBlock -{ - int flags; // mode selector flags, bit 0 = 1, bit 1-7 format specifier, 8-31 reserved - int x_pixels; - int y_pixels; - int pixel_depth; // 2^pixel_depth = bpp,i.e. 0 = 1, 1 = 2, 4 = 16, 5 = 32 - int frame_rate; // -1 use first match - int mode_vars[5]; // array of index, value pairs terminated by -1 -} SCREENMODEBLOCK; - - -/* Helper functions */ -void FULLSCREEN_SetDeviceMode(_THIS); -int FULLSCREEN_SetMode(int width, int height, int bpp); -void FULLSCREEN_SetupBanks(_THIS); - -/* SDL video device functions for fullscreen mode */ -static int FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, - SDL_Color * colors); -static int FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface * surface); -void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon); -extern int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info); - -/* UpdateRects variants */ -static void FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect * rects); -static void FULLSCREEN_UpdateRectsMemCpy(_THIS, int numrects, - SDL_Rect * rects); -static void FULLSCREEN_UpdateRects8bpp(_THIS, int numrects, SDL_Rect * rects); -static void FULLSCREEN_UpdateRects16bpp(_THIS, int numrects, - SDL_Rect * rects); -static void FULLSCREEN_UpdateRects32bpp(_THIS, int numrects, - SDL_Rect * rects); -static void FULLSCREEN_UpdateRectsOS(_THIS, int numrects, SDL_Rect * rects); - -/* Local helper functions */ -static int cmpmodes(const void *va, const void *vb); -static int FULLSCREEN_AddMode(_THIS, int bpp, int w, int h); -void FULLSCREEN_SetWriteBank(int bank); -void FULLSCREEN_SetDisplayBank(int bank); -static void FULLSCREEN_DisableEscape(); -static void FULLSCREEN_EnableEscape(); -void FULLSCREEN_BuildModeList(_THIS); - -/* Following variable is set up in riskosTask.c */ -extern int riscos_backbuffer; /* Create a back buffer in system memory for full screen mode */ - -/* Following is used to create a sprite back buffer */ -extern unsigned char *WIMP_CreateBuffer(int width, int height, int bpp); - -/* Fast assembler copy */ -extern void RISCOS_Put32(void *to, int pixels, int pitch, int rows, - void *from, int src_skip_bytes); - -SDL_Surface * -FULLSCREEN_SetVideoMode(_THIS, SDL_Surface * current, - int width, int height, int bpp, Uint32 flags) -{ - _kernel_swi_regs regs; - Uint32 Rmask = 0; - Uint32 Gmask = 0; - Uint32 Bmask = 0; - int create_back_buffer = riscos_backbuffer; - - switch (bpp) { - case 8: - flags |= SDL_HWPALETTE; - break; - - case 15: - case 16: - Bmask = 0x00007c00; - Gmask = 0x000003e0; - Rmask = 0x0000001f; - break; - - case 32: - Bmask = 0x00ff0000; - Gmask = 0x0000ff00; - Rmask = 0x000000ff; - break; - - default: - SDL_SetError("Pixel depth not supported"); - return NULL; - break; - } - - if (FULLSCREEN_SetMode(width, height, bpp) == 0) { - SDL_SetError("Couldn't set requested mode"); - return (NULL); - } - -/* printf("Setting mode %dx%d\n", width, height); */ - - /* Allocate the new pixel format for the screen */ - if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0)) { - RISCOS_RestoreWimpMode(); - SDL_SetError("Couldn't allocate new pixel format for requested mode"); - return (NULL); - } - - /* Set up the new mode framebuffer */ - current->w = width; - this->hidden->height = current->h = height; - - regs.r[0] = -1; /* -1 for current screen mode */ - - /* Get screen width in bytes */ - regs.r[1] = 6; // Screen Width in bytes - _kernel_swi(OS_ReadModeVariable, ®s, ®s); - - current->pitch = regs.r[2]; - - if (flags & SDL_DOUBLEBUF) { - regs.r[0] = 2; /* Screen area */ - _kernel_swi(OS_ReadDynamicArea, ®s, ®s); - - /* Reg 1 has amount of memory currently used for display */ - regs.r[0] = 2; /* Screen area */ - regs.r[1] = (current->pitch * height * 2) - regs.r[1]; - if (_kernel_swi(OS_ChangeDynamicArea, ®s, ®s) != NULL) { - /* Can't allocate enough screen memory for double buffer */ - flags &= ~SDL_DOUBLEBUF; - } - } - - current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | SDL_PREALLOC; - - - /* Need to set display banks here for double buffering */ - if (flags & SDL_DOUBLEBUF) { - FULLSCREEN_SetWriteBank(0); - FULLSCREEN_SetDisplayBank(1); - - create_back_buffer = 0; /* Don't need a back buffer for a double buffered display */ - } - - FULLSCREEN_SetupBanks(this); - - if (create_back_buffer) { - /* If not double buffered we may need to create a memory - ** back buffer to simulate processing on other OSes. - ** This is turned on by setting the enviromental variable - ** SDL$$BackBuffer >= 1 - */ - if (riscos_backbuffer == 3) - this->hidden->bank[0] = WIMP_CreateBuffer(width, height, bpp); - else - this->hidden->bank[0] = SDL_malloc(height * current->pitch); - if (this->hidden->bank[0] == 0) { - RISCOS_RestoreWimpMode(); - SDL_SetError("Couldnt allocate memory for back buffer"); - return (NULL); - } - /* Surface updated in programs is now a software surface */ - current->flags &= ~SDL_HWSURFACE; - } - - /* Store address of allocated screen bank to be freed later */ - if (this->hidden->alloc_bank) - SDL_free(this->hidden->alloc_bank); - if (create_back_buffer) { - this->hidden->alloc_bank = this->hidden->bank[0]; - if (riscos_backbuffer == 3) { - this->hidden->bank[0] += 60; /* Start of sprite data */ - if (bpp == 8) - this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ - } - } else - this->hidden->alloc_bank = 0; - - // Clear both banks to black - SDL_memset(this->hidden->bank[0], 0, height * current->pitch); - SDL_memset(this->hidden->bank[1], 0, height * current->pitch); - - this->hidden->current_bank = 0; - current->pixels = this->hidden->bank[0]; - - /* Have to set the screen here, so SetDeviceMode will pick it up */ - this->screen = current; - - /* Reset device functions for the wimp */ - FULLSCREEN_SetDeviceMode(this); - -/* FULLSCREEN_DisableEscape(); */ - - /* We're done */ - return (current); -} - -/* Reset any device functions that have been changed because we have run in WIMP mode */ -void -FULLSCREEN_SetDeviceMode(_THIS) -{ - /* Update rects is different if we have a backbuffer */ - - if (riscos_backbuffer && (this->screen->flags & SDL_DOUBLEBUF) == 0) { - switch (riscos_backbuffer) { - case 2: /* ARM code full word copy */ - switch (this->screen->format->BytesPerPixel) { - case 1: /* 8bpp modes */ - this->UpdateRects = FULLSCREEN_UpdateRects8bpp; - break; - case 2: /* 15/16bpp modes */ - this->UpdateRects = FULLSCREEN_UpdateRects16bpp; - break; - case 4: /* 32 bpp modes */ - this->UpdateRects = FULLSCREEN_UpdateRects32bpp; - break; - - default: /* Just default to the memcpy routine */ - this->UpdateRects = FULLSCREEN_UpdateRectsMemCpy; - break; - } - break; - - case 3: /* Use OS sprite plot routine */ - this->UpdateRects = FULLSCREEN_UpdateRectsOS; - break; - - default: /* Old but safe memcpy */ - this->UpdateRects = FULLSCREEN_UpdateRectsMemCpy; - break; - } - } else - this->UpdateRects = FULLSCREEN_UpdateRects; /* Default do nothing implementation */ - - this->SetColors = FULLSCREEN_SetColors; - - this->FlipHWSurface = FULLSCREEN_FlipHWSurface; - - this->SetCaption = FULLSCREEN_SetWMCaption; - this->SetIcon = NULL; - this->IconifyWindow = NULL; - - this->ShowWMCursor = RISCOS_ShowWMCursor; - this->WarpWMCursor = FULLSCREEN_WarpWMCursor; - - this->PumpEvents = FULLSCREEN_PumpEvents; -} - -/* Query for the list of available video modes */ -void -FULLSCREEN_BuildModeList(_THIS) -{ - _kernel_swi_regs regs; - char *enumInfo = NULL; - char *enum_ptr; - int *blockInfo; - int j; - int num_modes; - - /* Find out how much space we need */ - regs.r[0] = 2; /* Reason code */ - regs.r[2] = 0; /* Number of modes to skip */ - regs.r[6] = 0; /* pointer to block or 0 for count */ - regs.r[7] = 0; /* Size of block in bytes */ - _kernel_swi(OS_ScreenMode, ®s, ®s); - - num_modes = -regs.r[2]; - - /* Video memory should be in r[5] */ - this->info.video_mem = regs.r[5] / 1024; - - enumInfo = (unsigned char *) SDL_malloc(-regs.r[7]); - if (enumInfo == NULL) { - SDL_OutOfMemory(); - return; - } - /* Read mode information into block */ - regs.r[2] = 0; - regs.r[6] = (int) enumInfo; - regs.r[7] = -regs.r[7]; - _kernel_swi(OS_ScreenMode, ®s, ®s); - - enum_ptr = enumInfo; - - for (j = 0; j < num_modes; j++) { - blockInfo = (int *) enum_ptr; - if ((blockInfo[1] & 255) == 1) { /* We understand this format */ - switch (blockInfo[4]) { - case 3: /* 8 bits per pixel */ - FULLSCREEN_AddMode(this, 8, blockInfo[2], blockInfo[3]); - break; - case 4: /* 15 bits per pixel */ - FULLSCREEN_AddMode(this, 15, blockInfo[2], blockInfo[3]); - break; - case 5: /* 32 bits per pixel */ - FULLSCREEN_AddMode(this, 32, blockInfo[2], blockInfo[3]); - break; - } - } - - enum_ptr += blockInfo[0]; - } - - SDL_free(enumInfo); - - /* Sort the mode lists */ - for (j = 0; j < NUM_MODELISTS; ++j) { - if (SDL_nummodes[j] > 0) { - SDL_qsort(SDL_modelist[j], SDL_nummodes[j], - sizeof *SDL_modelist[j], cmpmodes); - } - } -} - -static int -FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface * surface) -{ - _kernel_swi_regs regs; - regs.r[0] = 19; - - FULLSCREEN_SetDisplayBank(this->hidden->current_bank); - this->hidden->current_bank ^= 1; - FULLSCREEN_SetWriteBank(this->hidden->current_bank); - surface->pixels = this->hidden->bank[this->hidden->current_bank]; - - /* Wait for Vsync */ - _kernel_swi(OS_Byte, ®s, ®s); - - return (0); -} - -/* Nothing to do if we are writing direct to hardware */ -static void -FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect * rects) -{ -} - -/* Safe but slower Memory copy from our allocated back buffer */ -static void -FULLSCREEN_UpdateRectsMemCpy(_THIS, int numrects, SDL_Rect * rects) -{ - int j; - char *to, *from; - int pitch = this->screen->pitch; - int row; - int xmult = this->screen->format->BytesPerPixel; - for (j = 0; j < numrects; j++) { - from = this->hidden->bank[0] + rects->x * xmult + rects->y * pitch; - to = this->hidden->bank[1] + rects->x * xmult + rects->y * pitch; - for (row = 0; row < rects->h; row++) { - SDL_memcpy(to, from, rects->w * xmult); - from += pitch; - to += pitch; - } - rects++; - } -} - -/* Use optimized assembler memory copy. Deliberately copies extra columns if - necessary to ensure the rectangle is word aligned. */ -static void -FULLSCREEN_UpdateRects8bpp(_THIS, int numrects, SDL_Rect * rects) -{ - int j; - char *to, *from; - int pitch = this->screen->pitch; - int width_bytes; - int src_skip_bytes; - - for (j = 0; j < numrects; j++) { - from = this->hidden->bank[0] + rects->x + rects->y * pitch; - to = this->hidden->bank[1] + rects->x + rects->y * pitch; - width_bytes = rects->w; - if ((int) from & 3) { - int extra = ((int) from & 3); - from -= extra; - to -= extra; - width_bytes += extra; - } - if (width_bytes & 3) - width_bytes += 4 - (width_bytes & 3); - src_skip_bytes = pitch - width_bytes; - - RISCOS_Put32(to, (width_bytes >> 2), pitch, (int) rects->h, from, - src_skip_bytes); - rects++; - } -} - -/* Use optimized assembler memory copy. Deliberately copies extra columns if - necessary to ensure the rectangle is word aligned. */ -static void -FULLSCREEN_UpdateRects16bpp(_THIS, int numrects, SDL_Rect * rects) -{ - int j; - char *to, *from; - int pitch = this->screen->pitch; - int width_bytes; - int src_skip_bytes; - - for (j = 0; j < numrects; j++) { - from = this->hidden->bank[0] + (rects->x << 1) + rects->y * pitch; - to = this->hidden->bank[1] + (rects->x << 1) + rects->y * pitch; - width_bytes = (((int) rects->w) << 1); - if ((int) from & 3) { - from -= 2; - to -= 2; - width_bytes += 2; - } - if (width_bytes & 3) - width_bytes += 2; - src_skip_bytes = pitch - width_bytes; - - RISCOS_Put32(to, (width_bytes >> 2), pitch, (int) rects->h, from, - src_skip_bytes); - rects++; - } -} - -/* Use optimized assembler memory copy. 32 bpp modes are always word aligned */ -static void -FULLSCREEN_UpdateRects32bpp(_THIS, int numrects, SDL_Rect * rects) -{ - int j; - char *to, *from; - int pitch = this->screen->pitch; - int width; - - for (j = 0; j < numrects; j++) { - from = this->hidden->bank[0] + (rects->x << 2) + rects->y * pitch; - to = this->hidden->bank[1] + (rects->x << 2) + rects->y * pitch; - width = (int) rects->w; - - RISCOS_Put32(to, width, pitch, (int) rects->h, from, - pitch - (width << 2)); - rects++; - } -} - -/* Use operating system sprite plots. Currently this is much slower than the - other variants however accelerated sprite plotting can be seen on the horizon - so this prepares for it. */ -static void -FULLSCREEN_UpdateRectsOS(_THIS, int numrects, SDL_Rect * rects) -{ - _kernel_swi_regs regs; - _kernel_oserror *err; - int j; - int y; - - regs.r[0] = 28 + 512; - regs.r[1] = (unsigned int) this->hidden->alloc_bank; - regs.r[2] = (unsigned int) this->hidden->alloc_bank + 16; - regs.r[5] = 0; - - for (j = 0; j < numrects; j++) { - y = this->screen->h - rects->y; /* top of clipping region */ - _kernel_oswrch(24); /* Set graphics clip region */ - _kernel_oswrch((rects->x << this->hidden->xeig) & 0xFF); /* left */ - _kernel_oswrch(((rects->x << this->hidden->xeig) >> 8) & 0xFF); - _kernel_oswrch(((y - rects->h) << this->hidden->yeig) & 0xFF); /* bottom */ - _kernel_oswrch((((y - rects->h) << this->hidden->yeig) >> 8) & 0xFF); - _kernel_oswrch(((rects->x + rects->w - 1) << this->hidden->xeig) & 0xFF); /* right */ - _kernel_oswrch((((rects->x + rects->w - - 1) << this->hidden->xeig) >> 8) & 0xFF); - _kernel_oswrch(((y - 1) << this->hidden->yeig) & 0xFF); /* top */ - _kernel_oswrch((((y - 1) << this->hidden->yeig) >> 8) & 0xFF); - - regs.r[3] = 0; - regs.r[4] = 0; - - if ((err = _kernel_swi(OS_SpriteOp, ®s, ®s)) != 0) { - printf("OS_SpriteOp failed \n%s\n", err->errmess); - } - - rects++; - - /* Reset to full screen clipping */ - _kernel_oswrch(24); /* Set graphics clip region */ - _kernel_oswrch(0); /* left */ - _kernel_oswrch(0); - _kernel_oswrch(0); /* bottom */ - _kernel_oswrch(0); - _kernel_oswrch(((this->screen->w - 1) << this->hidden->xeig) & 0xFF); /* right */ - _kernel_oswrch((((this->screen->w - - 1) << this->hidden->xeig) >> 8) & 0xFF); - _kernel_oswrch(((this->screen->h - 1) << this->hidden->yeig) & 0xFF); /* top */ - _kernel_oswrch((((this->screen->h - - 1) << this->hidden->yeig) >> 8) & 0xFF); - } -} - - -int -FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) -{ - _kernel_swi_regs regs; - int palette[256]; - - regs.r[0] = -1; - regs.r[1] = -1; - regs.r[2] = (int) palette; - regs.r[3] = 1024; - regs.r[4] = 0; - _kernel_swi(ColourTrans_ReadPalette, ®s, ®s); - - while (ncolors--) { - palette[firstcolor] = - ((colors->b) << 24) | ((colors->g) << 16) | ((colors->r) << 8); - firstcolor++; - colors++; - } - - regs.r[0] = -1; - regs.r[1] = -1; - regs.r[2] = (int) palette; - regs.r[3] = 0; - regs.r[4] = 0; - _kernel_swi(ColourTrans_WritePalette, ®s, ®s); - - return (1); -} - - -static int -cmpmodes(const void *va, const void *vb) -{ - SDL_Rect *a = *(SDL_Rect **) va; - SDL_Rect *b = *(SDL_Rect **) vb; - if (a->w == b->w) - return b->h - a->h; - else - return b->w - a->w; -} - -static int -FULLSCREEN_AddMode(_THIS, int bpp, int w, int h) -{ - SDL_Rect *mode; - int i, index; - int next_mode; - - /* Check to see if we already have this mode */ - if (bpp < 8) { /* Not supported */ - return (0); - } - index = ((bpp + 7) / 8) - 1; - for (i = 0; i < SDL_nummodes[index]; ++i) { - mode = SDL_modelist[index][i]; - if ((mode->w == w) && (mode->h == h)) { - return (0); - } - } - - /* Set up the new video mode rectangle */ - mode = (SDL_Rect *) SDL_malloc(sizeof *mode); - if (mode == NULL) { - SDL_OutOfMemory(); - return (-1); - } - mode->x = 0; - mode->y = 0; - mode->w = w; - mode->h = h; - - /* Allocate the new list of modes, and fill in the new mode */ - next_mode = SDL_nummodes[index]; - SDL_modelist[index] = (SDL_Rect **) - SDL_realloc(SDL_modelist[index], - (1 + next_mode + 1) * sizeof(SDL_Rect *)); - if (SDL_modelist[index] == NULL) { - SDL_OutOfMemory(); - SDL_nummodes[index] = 0; - SDL_free(mode); - return (-1); - } - SDL_modelist[index][next_mode] = mode; - SDL_modelist[index][next_mode + 1] = NULL; - SDL_nummodes[index]++; - - return (0); -} - -void -FULLSCREEN_SetWriteBank(int bank) -{ - _kernel_swi_regs regs; - regs.r[0] = 112; - regs.r[1] = bank + 1; - _kernel_swi(OS_Byte, ®s, ®s); -} - -void -FULLSCREEN_SetDisplayBank(int bank) -{ - _kernel_swi_regs regs; - regs.r[0] = 113; - regs.r[1] = bank + 1; - _kernel_swi(OS_Byte, ®s, ®s); -} - - -/** Disable special escape key processing */ -static void -FULLSCREEN_DisableEscape() -{ - _kernel_swi_regs regs; - regs.r[0] = 229; - regs.r[1] = 1; - regs.r[2] = 0; - _kernel_swi(OS_Byte, ®s, ®s); - -} - -/** Enable special escape key processing */ -static void -FULLSCREEN_EnableEscape() -{ - _kernel_swi_regs regs; - regs.r[0] = 229; - regs.r[1] = 0; - regs.r[2] = 0; - _kernel_swi(OS_Byte, ®s, ®s); - -} - -/** Store caption in case this is called before we create a window */ -void -FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon) -{ - SDL_strlcpy(this->hidden->title, title, - SDL_arraysize(this->hidden->title)); -} - -/* Set screen mode -* -* Returns 1 if mode is set ok, otherwise 0 -*/ - -int -FULLSCREEN_SetMode(int width, int height, int bpp) -{ - SCREENMODEBLOCK smb; - _kernel_swi_regs regs; - - smb.flags = 1; - smb.x_pixels = width; - smb.y_pixels = height; - smb.mode_vars[0] = -1; - - switch (bpp) { - case 8: - smb.pixel_depth = 3; - /* Note: Need to set ModeFlags to 128 and NColour variables to 255 get full 8 bit palette */ - smb.mode_vars[0] = 0; - smb.mode_vars[1] = 128; /* Mode flags */ - smb.mode_vars[2] = 3; - smb.mode_vars[3] = 255; /* NColour (number of colours -1) */ - smb.mode_vars[4] = -1; /* End of list */ - break; - - case 15: - case 16: - smb.pixel_depth = 4; - break; - - case 32: - smb.pixel_depth = 5; - break; - - default: - SDL_SetError("Pixel depth not supported"); - return 0; - break; - } - - smb.frame_rate = -1; - - regs.r[0] = 0; - regs.r[1] = (int) &smb; - - if (_kernel_swi(OS_ScreenMode, ®s, ®s) != 0) { - SDL_SetError("Couldn't set requested mode"); - return 0; - } - - /* Turn cursor off */ - _kernel_oswrch(23); - _kernel_oswrch(1); - _kernel_oswrch(0); - _kernel_oswrch(0); - _kernel_oswrch(0); - _kernel_oswrch(0); - _kernel_oswrch(0); - _kernel_oswrch(0); - _kernel_oswrch(0); - _kernel_oswrch(0); - _kernel_oswrch(0); - - return 1; -} - -/* Get Start addresses for the screen banks */ -void -FULLSCREEN_SetupBanks(_THIS) -{ - _kernel_swi_regs regs; - int block[5]; - block[0] = 148; /* Write screen start */ - block[1] = 149; /* Display screen start */ - block[2] = 4; /* X eig factor */ - block[3] = 5; /* Y eig factor */ - block[4] = -1; /* End of list of variables to request */ - - regs.r[0] = (int) block; - regs.r[1] = (int) block; - _kernel_swi(OS_ReadVduVariables, ®s, ®s); - - this->hidden->bank[0] = (void *) block[0]; - this->hidden->bank[1] = (void *) block[1]; - this->hidden->xeig = block[2]; - this->hidden->yeig = block[3]; -} - -/* Toggle to full screen mode from the WIMP */ - -int -FULLSCREEN_ToggleFromWimp(_THIS) -{ - int width = this->screen->w; - int height = this->screen->h; - int bpp = this->screen->format->BitsPerPixel; - - RISCOS_StoreWimpMode(); - if (FULLSCREEN_SetMode(width, height, bpp)) { - char *buffer = this->hidden->alloc_bank; /* This is start of sprite data */ - /* Support back buffer mode only */ - if (riscos_backbuffer == 0) - riscos_backbuffer = 1; - - FULLSCREEN_SetupBanks(this); - - this->hidden->bank[0] = buffer + 60; /* Start of sprite data */ - if (bpp == 8) - this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ - - this->hidden->current_bank = 0; - this->screen->pixels = this->hidden->bank[0]; - - /* Copy back buffer to screen memory */ - SDL_memcpy(this->hidden->bank[1], this->hidden->bank[0], - width * height * this->screen->format->BytesPerPixel); - - FULLSCREEN_SetDeviceMode(this); - return 1; - } else - RISCOS_RestoreWimpMode(); - - return 0; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c deleted file mode 100644 index 8755aca11..000000000 --- a/src/video/riscos/SDL_riscosevents.c +++ /dev/null @@ -1,598 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability - 27 March 2003 - - Implements keyboard setup, event pump and keyboard and mouse polling -*/ - - -#include "../../timer/SDL_timer_c.h" -#include "../../events/SDL_sysevents.h" -#include "../../events/SDL_events_c.h" -#include "../SDL_cursor_c.h" -#include "SDL_riscosvideo.h" -#include "SDL_riscosevents_c.h" - -#include "memory.h" -#include "stdlib.h" -#include "ctype.h" - -#include "kernel.h" -#include "swis.h" - -/* The translation table from a RISC OS internal key numbers to a SDL keysym */ -static SDLKey RO_keymap[SDLK_LAST]; - -/* RISC OS Key codes */ -#define ROKEY_SHIFT 0 -#define ROKEY_CTRL 1 -#define ROKEY_ALT 2 -/* Left shift is first key we will check for */ -#define ROKEY_LEFT_SHIFT 3 - -/* Need to ignore mouse buttons as they are processed separately */ -#define ROKEY_LEFT_MOUSE 9 -#define ROKEY_CENTRE_MOUSE 10 -#define ROKEY_RIGHT_MOUSE 11 - -/* No key has been pressed return value*/ -#define ROKEY_NONE 255 - -/* Id of last key in keyboard */ -#define ROKEY_LAST_KEY 124 - -/* Size of array for all keys */ -#define ROKEYBD_ARRAYSIZE 125 - -static char RO_pressed[ROKEYBD_ARRAYSIZE]; - -static SDL_KeySym *TranslateKey(int intkey, SDL_KeySym * keysym, int pressed); - -void RISCOS_PollMouse(_THIS); -void RISCOS_PollKeyboard(); - -void RISCOS_PollMouseHelper(_THIS, int fullscreen); - -#if SDL_THREADS_DISABLED -extern void DRenderer_FillBuffers(); - -/* Timer running function */ -extern void RISCOS_CheckTimer(); - -#endif - -void -FULLSCREEN_PumpEvents(_THIS) -{ - /* Current implementation requires keyboard and mouse polling */ - RISCOS_PollKeyboard(); - RISCOS_PollMouse(this); -#if SDL_THREADS_DISABLED -// DRenderer_FillBuffers(); - if (SDL_timer_running) - RISCOS_CheckTimer(); -#endif -} - - -void -RISCOS_InitOSKeymap(_THIS) -{ - int i; - - /* Map the VK keysyms */ - for (i = 0; i < SDL_arraysize(RO_keymap); ++i) - RO_keymap[i] = SDLK_UNKNOWN; - - RO_keymap[3] = SDLK_LSHIFT; - RO_keymap[4] = SDLK_LCTRL; - RO_keymap[5] = SDLK_LALT; - RO_keymap[6] = SDLK_RSHIFT; - RO_keymap[7] = SDLK_RCTRL; - RO_keymap[8] = SDLK_RALT; - RO_keymap[16] = SDLK_q; - RO_keymap[17] = SDLK_3; - RO_keymap[18] = SDLK_4; - RO_keymap[19] = SDLK_5; - RO_keymap[20] = SDLK_F4; - RO_keymap[21] = SDLK_8; - RO_keymap[22] = SDLK_F7; - RO_keymap[23] = SDLK_MINUS, RO_keymap[25] = SDLK_LEFT; - RO_keymap[26] = SDLK_KP6; - RO_keymap[27] = SDLK_KP7; - RO_keymap[28] = SDLK_F11; - RO_keymap[29] = SDLK_F12; - RO_keymap[30] = SDLK_F10; - RO_keymap[31] = SDLK_SCROLLOCK; - RO_keymap[32] = SDLK_PRINT; - RO_keymap[33] = SDLK_w; - RO_keymap[34] = SDLK_e; - RO_keymap[35] = SDLK_t; - RO_keymap[36] = SDLK_7; - RO_keymap[37] = SDLK_i; - RO_keymap[38] = SDLK_9; - RO_keymap[39] = SDLK_0; - RO_keymap[41] = SDLK_DOWN; - RO_keymap[42] = SDLK_KP8; - RO_keymap[43] = SDLK_KP9; - RO_keymap[44] = SDLK_BREAK; - RO_keymap[45] = SDLK_BACKQUOTE; -/* RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */ - RO_keymap[47] = SDLK_BACKSPACE; - RO_keymap[48] = SDLK_1; - RO_keymap[49] = SDLK_2; - RO_keymap[50] = SDLK_d; - RO_keymap[51] = SDLK_r; - RO_keymap[52] = SDLK_6; - RO_keymap[53] = SDLK_u; - RO_keymap[54] = SDLK_o; - RO_keymap[55] = SDLK_p; - RO_keymap[56] = SDLK_LEFTBRACKET; - RO_keymap[57] = SDLK_UP; - RO_keymap[58] = SDLK_KP_PLUS; - RO_keymap[59] = SDLK_KP_MINUS; - RO_keymap[60] = SDLK_KP_ENTER; - RO_keymap[61] = SDLK_INSERT; - RO_keymap[62] = SDLK_HOME; - RO_keymap[63] = SDLK_PAGEUP; - RO_keymap[64] = SDLK_CAPSLOCK; - RO_keymap[65] = SDLK_a; - RO_keymap[66] = SDLK_x; - RO_keymap[67] = SDLK_f; - RO_keymap[68] = SDLK_y; - RO_keymap[69] = SDLK_j; - RO_keymap[70] = SDLK_k; - RO_keymap[72] = SDLK_SEMICOLON; - RO_keymap[73] = SDLK_RETURN; - RO_keymap[74] = SDLK_KP_DIVIDE; - RO_keymap[76] = SDLK_KP_PERIOD; - RO_keymap[77] = SDLK_NUMLOCK; - RO_keymap[78] = SDLK_PAGEDOWN; - RO_keymap[79] = SDLK_QUOTE; - RO_keymap[81] = SDLK_s; - RO_keymap[82] = SDLK_c; - RO_keymap[83] = SDLK_g; - RO_keymap[84] = SDLK_h; - RO_keymap[85] = SDLK_n; - RO_keymap[86] = SDLK_l; - RO_keymap[87] = SDLK_SEMICOLON; - RO_keymap[88] = SDLK_RIGHTBRACKET; - RO_keymap[89] = SDLK_DELETE; - RO_keymap[90] = SDLK_KP_MINUS; - RO_keymap[91] = SDLK_KP_MULTIPLY; - RO_keymap[93] = SDLK_EQUALS; - RO_keymap[94] = SDLK_BACKSLASH; - RO_keymap[96] = SDLK_TAB; - RO_keymap[97] = SDLK_z; - RO_keymap[98] = SDLK_SPACE; - RO_keymap[99] = SDLK_v; - RO_keymap[100] = SDLK_b; - RO_keymap[101] = SDLK_m; - RO_keymap[102] = SDLK_COMMA; - RO_keymap[103] = SDLK_PERIOD; - RO_keymap[104] = SDLK_SLASH; - RO_keymap[105] = SDLK_END; - RO_keymap[106] = SDLK_KP0; - RO_keymap[107] = SDLK_KP1; - RO_keymap[108] = SDLK_KP3; - RO_keymap[112] = SDLK_ESCAPE; - RO_keymap[113] = SDLK_F1; - RO_keymap[114] = SDLK_F2; - RO_keymap[115] = SDLK_F3; - RO_keymap[116] = SDLK_F5; - RO_keymap[117] = SDLK_F6; - RO_keymap[118] = SDLK_F8; - RO_keymap[119] = SDLK_F9; - RO_keymap[120] = SDLK_HASH; - RO_keymap[121] = SDLK_RIGHT; - RO_keymap[122] = SDLK_KP4; - RO_keymap[123] = SDLK_KP5; - RO_keymap[124] = SDLK_KP2; - - SDL_memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE); -} - - -/* Variable for mouse relative processing */ -int mouse_relative = 0; - -/* Check to see if we need to enter or leave mouse relative mode */ - -void -RISCOS_CheckMouseMode(_THIS) -{ - /* If the mouse is hidden and input is grabbed, we use relative mode */ - if (!(SDL_cursorstate & CURSOR_VISIBLE) && - (this->input_grab != SDL_GRAB_OFF)) { - mouse_relative = 1; - } else { - mouse_relative = 0; - } -} - - -void -RISCOS_PollMouse(_THIS) -{ - RISCOS_PollMouseHelper(this, 1); -} - -extern int mouseInWindow; - -void -WIMP_PollMouse(_THIS) -{ - /* Only poll when mouse is over the window */ - if (!mouseInWindow) - return; - - RISCOS_PollMouseHelper(this, 0); -} - -/* Static variables so only changes are reported */ -static Sint16 last_x = -1, last_y = -1; -static int last_buttons = 0; - -/* Share routine between WIMP and FULLSCREEN for polling mouse and - passing on events */ -void -RISCOS_PollMouseHelper(_THIS, int fullscreen) -{ - _kernel_swi_regs regs; - static int starting = 1; - - if (_kernel_swi(OS_Mouse, ®s, ®s) == NULL) { - Sint16 new_x = regs.r[0]; /* Initialy get as OS units */ - Sint16 new_y = regs.r[1]; - - /* Discard mouse events until they let go of the mouse after starting */ - if (starting && regs.r[2] != 0) - return; - else - starting = 0; - - if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2]) { - /* Something changed so generate appropriate events */ - int topLeftX, topLeftY; /* Top left OS units */ - int x, y; /* Mouse position in SDL pixels */ - - if (fullscreen) { - topLeftX = 0; - topLeftY = (this->hidden->height << this->hidden->yeig) - 1; - } else { - int window_state[9]; - - /* Get current window state */ - window_state[0] = this->hidden->window_handle; - regs.r[1] = (unsigned int) window_state; - _kernel_swi(Wimp_GetWindowState, ®s, ®s); - - topLeftX = window_state[1]; - topLeftY = window_state[4]; - } - - /* Convert co-ordinates to workspace */ - x = new_x - topLeftX; - y = topLeftY - new_y; /* Y goes from top of window/screen */ - - /* Convert OS units to pixels */ - x >>= this->hidden->xeig; - y >>= this->hidden->yeig; - - if (last_x != new_x || last_y != new_y) { - if (mouse_relative) { - int centre_x = SDL_VideoSurface->w / 2; - int centre_y = SDL_VideoSurface->h / 2; - - if (centre_x != x || centre_y != y) { - if (SDL_VideoSurface) - SDL_PrivateMouseMotion(0, 1, - x - centre_x, - y - centre_y); - last_x = topLeftX + (centre_x << this->hidden->xeig); - last_y = topLeftY - (centre_y << this->hidden->yeig); - - /* Re-centre the mouse pointer, so we still get relative - movement when the mouse is at the edge of the window - or screen. - */ - { - unsigned char block[5]; - - block[0] = 3; /* OSWORD move pointer sub-reason code */ - block[1] = last_x & 0xFF; - block[2] = (last_x >> 8) & 0xFF; - block[3] = last_y & 0xFF; - block[4] = (last_y >> 8) & 0xFF; - - regs.r[0] = 21; /* OSWORD pointer stuff code */ - regs.r[1] = (int) block; - _kernel_swi(OS_Word, ®s, ®s); - } - } - } else { - last_x = new_x; - last_y = new_y; - SDL_PrivateMouseMotion(0, 0, x, y); - } - } - - if (last_buttons != regs.r[2]) { - int changed = last_buttons ^ regs.r[2]; - last_buttons = regs.r[2]; - if (changed & 4) - SDL_PrivateMouseButton((last_buttons & 4) ? - SDL_PRESSED : SDL_RELEASED, - SDL_BUTTON_LEFT, 0, 0); - if (changed & 2) - SDL_PrivateMouseButton((last_buttons & 2) ? - SDL_PRESSED : SDL_RELEASED, - SDL_BUTTON_MIDDLE, 0, 0); - if (changed & 1) - SDL_PrivateMouseButton((last_buttons & 1) ? - SDL_PRESSED : SDL_RELEASED, - SDL_BUTTON_RIGHT, 0, 0); - } - } - } -} - -void -RISCOS_PollKeyboard() -{ - int which_key = ROKEY_LEFT_SHIFT; - int j; - int min_key, max_key; - SDL_KeySym key; - - /* Scan the keyboard to see what is pressed */ - while (which_key <= ROKEY_LAST_KEY) { - which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF); - if (which_key != ROKEY_NONE) { - switch (which_key) { - /* Skip over mouse keys */ - case ROKEY_LEFT_MOUSE: - case ROKEY_CENTRE_MOUSE: - case ROKEY_RIGHT_MOUSE: - which_key = ROKEY_RIGHT_MOUSE; - break; - - /* Ignore keys that cause 2 internal number to be generated */ - case 71: - case 24: - case 87: - case 40: - break; - - /* Ignore break as it can be latched on */ - case 44: - break; - - default: - RO_pressed[which_key] += 2; - break; - } - which_key++; - } - } - - /* Generate key released messages */ - min_key = ROKEY_LAST_KEY + 1; - max_key = ROKEY_LEFT_SHIFT; - - for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++) { - if (RO_pressed[j]) { - if (RO_pressed[j] == 1) { - RO_pressed[j] = 0; - SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j, &key, 0)); - } else { - if (j < min_key) - min_key = j; - if (j > max_key) - max_key = j; - } - } - } - - /* Generate key pressed messages */ - for (j = min_key; j <= max_key; j++) { - if (RO_pressed[j]) { - if (RO_pressed[j] == 2) { - SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(j, &key, 1)); - } - RO_pressed[j] = 1; - } - } -} - -static SDL_KeySym * -TranslateKey(int intkey, SDL_KeySym * keysym, int pressed) -{ - /* Set the keysym information */ - keysym->scancode = (unsigned char) intkey; - keysym->sym = RO_keymap[intkey]; - keysym->mod = KMOD_NONE; - keysym->unicode = 0; - if (pressed && SDL_TranslateUNICODE) { - int state; - int ch; - - state = (_kernel_osbyte(202, 0, 255) & 0xFF); - - /*TODO: Take into account other keyboard layouts */ - - ch = keysym->sym; /* This should handle most unshifted keys */ - - if (intkey < 9 || ch == SDLK_UNKNOWN) { - ch = 0; - - } else if (state & 64) { /* Control on */ - ch = ch & 31; - - } else { - int topOfKey = 0; - if (state & 8) { /* Shift on */ - topOfKey = 1; - } - - if ((state & 16) == 0) { /* Caps lock is on */ - if (ch >= SDLK_a && ch <= SDLK_z) { - if ((state & 128) == 0) { /* Shift Enable off */ - /* All letter become upper case */ - topOfKey = 1; - } else { - /* Shift+Letters gives lower case */ - topOfKey = 1 - topOfKey; - } - } - } - - if (topOfKey) { - /* Key produced with shift held down */ - - /* Letters just give upper case version */ - if (ch >= SDLK_a && ch <= SDLK_z) - ch = toupper(ch); - else { - switch (ch) { - case SDLK_HASH: - ch = '~'; - break; - case SDLK_QUOTE: - ch = '@'; - break; - case SDLK_COMMA: - ch = '<'; - break; - case SDLK_MINUS: - ch = '_'; - break; - case SDLK_PERIOD: - ch = '>'; - break; - case SDLK_SLASH: - ch = '?'; - break; - - case SDLK_0: - ch = ')'; - break; - case SDLK_1: - ch = '!'; - break; - case SDLK_2: - ch = '"'; - break; - case SDLK_3: - ch = '£'; - break; - case SDLK_4: - ch = '$'; - break; - case SDLK_5: - ch = '%'; - break; - case SDLK_6: - ch = '^'; - break; - case SDLK_7: - ch = '&'; - break; - case SDLK_8: - ch = '*'; - break; - case SDLK_9: - ch = '('; - break; - - case SDLK_SEMICOLON: - ch = ':'; - break; - case SDLK_EQUALS: - ch = '+'; - break; - case SDLK_LEFTBRACKET: - ch = '{'; - break; - case SDLK_BACKSLASH: - ch = '|'; - break; - case SDLK_RIGHTBRACKET: - ch = '}'; - break; - case SDLK_BACKQUOTE: - ch = '¬'; - break; - - default: - ch = 0; /* Map to zero character if we don't understand it */ - break; - } - } - - } else if (ch > 126) { - /* SDL key code < 126 map directly onto their Unicode equivalents */ - /* Keypad 0 to 9 maps to numeric equivalent */ - if (ch >= SDLK_KP0 && ch <= SDLK_KP9) - ch = ch - SDLK_KP0 + '0'; - else { - /* Following switch maps other keys that produce an Ascii value */ - switch (ch) { - case SDLK_KP_PERIOD: - ch = '.'; - break; - case SDLK_KP_DIVIDE: - ch = '/'; - break; - case SDLK_KP_MULTIPLY: - ch = '*'; - break; - case SDLK_KP_MINUS: - ch = '-'; - break; - case SDLK_KP_PLUS: - ch = '+'; - break; - case SDLK_KP_EQUALS: - ch = '='; - break; - - default: - /* If we don't know what it is set the Unicode to 0 */ - ch = 0; - break; - } - } - } - } - - keysym->unicode = ch; - } - return (keysym); -} - -/* end of SDL_riscosevents.c ... */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscosevents_c.h b/src/video/riscos/SDL_riscosevents_c.h deleted file mode 100644 index e0da64d78..000000000 --- a/src/video/riscos/SDL_riscosevents_c.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_riscosvideo.h" - -/* Variables and functions exported by SDL_sysevents.c to other parts - of the native video subsystem (SDL_sysvideo.c) -*/ -extern void RISCOS_InitOSKeymap(_THIS); -extern void FULLSCREEN_PumpEvents(_THIS); -extern void WIMP_PumpEvents(_THIS); - -/* end of SDL_nullevents_c.h ... */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscosmouse.c b/src/video/riscos/SDL_riscosmouse.c deleted file mode 100644 index f18939d10..000000000 --- a/src/video/riscos/SDL_riscosmouse.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability - 27 March 2003 - - Implements mouse cursor shape definitions and positioning -*/ - -#include "SDL_mouse.h" -#include "../../events/SDL_events_c.h" - -#include "SDL_riscosmouse_c.h" - -#include "kernel.h" -#include "swis.h" - -static WMcursor *current_cursor = NULL; -static WMcursor *defined_cursor = NULL; - -extern int mouseInWindow; - -/* Area to save cursor palette colours changed by SDL. - Actual values will be read before we change to the SDL cursor */ -static Uint8 wimp_cursor_palette[2][5] = { - {1, 25, 255, 255, 255}, - {3, 25, 255, 255, 255} -}; - -static int cursor_palette_saved = 0; - -void WIMP_SaveCursorPalette(); -void WIMP_RestoreWimpCursor(); -void WIMP_SetSDLCursorPalette(); - - -void -RISCOS_FreeWMCursor(_THIS, WMcursor * cursor) -{ - SDL_free(cursor->data); - SDL_free(cursor); -} - -WMcursor * -RISCOS_CreateWMCursor(_THIS, - Uint8 * data, Uint8 * mask, int w, int h, int hot_x, - int hot_y) -{ - WMcursor *cursor; - Uint8 *cursor_data; - Uint8 *ptr; - int i, j, k; - int data_byte, mask_byte; - - /* Check to make sure the cursor size is okay */ - if ((w > 32) || (h > 32)) { - SDL_SetError("Only with width and height <= 32 pixels are allowed"); - return (NULL); - } - - /* Allocate the cursor */ - cursor = (WMcursor *) SDL_malloc(sizeof(*cursor)); - if (cursor == NULL) { - SDL_SetError("Out of memory"); - return (NULL); - } - - /* Note: SDL says width must be a multiple of 8 */ - cursor_data = SDL_malloc(w / 4 * h); - if (cursor_data == NULL) { - SDL_free(cursor); - SDL_SetError("Out of memory"); - return (NULL); - } - - cursor->w = w; - cursor->h = h; - cursor->hot_x = hot_x; - cursor->hot_y = hot_y; - cursor->data = cursor_data; - - -/* Data / Mask Resulting pixel on screen - 0 / 1 White - 1 / 1 Black - 0 / 0 Transparent - 1 / 0 Inverted color if possible, black if not. -*/ - ptr = cursor_data; - - for (i = 0; i < h; ++i) { - for (j = 0; j < w / 8; ++j) { - data_byte = *data; - mask_byte = *mask; - *ptr++ = 0; /* Sets whole byte transparent */ - *ptr = 0; - for (k = 0; k < 8; k++) { - (*ptr) <<= 2; - if (data_byte & 1) - *ptr |= 3; /* Black or inverted */ - else if (mask_byte & 1) - *ptr |= 1; /* White */ - if ((k & 3) == 3) - ptr--; - data_byte >>= 1; - mask_byte >>= 1; - } - - ptr += 3; - data++; - mask++; - } - } - - return (cursor); -} - -int -RISCOS_ShowWMCursor(_THIS, WMcursor * cursor) -{ - current_cursor = cursor; - - if (cursor == NULL) { - _kernel_osbyte(106, 0, 0); - defined_cursor = NULL; - } else { - WMcursor *old_cursor = defined_cursor; - - if (cursor != defined_cursor) { - Uint8 cursor_def[10]; - - cursor_def[0] = 0; - cursor_def[1] = 2; /* Use shape number 2 */ - cursor_def[2] = cursor->w / 4; /* Width in bytes */ - cursor_def[3] = cursor->h; /* Height (h) in pixels */ - cursor_def[4] = cursor->hot_x; /* ActiveX in pixels from left */ - cursor_def[5] = cursor->hot_y; /* ActiveY in pixels from top */ - cursor_def[6] = ((int) (cursor->data) & 0xFF); /* Least significant byte of pointer to data */ - cursor_def[7] = ((int) (cursor->data) >> 8) & 0xFF; /* ... */ - cursor_def[8] = ((int) (cursor->data) >> 16) & 0xFF; /* ... */ - cursor_def[9] = ((int) (cursor->data) >> 24) & 0xFF; /* Most significant byte of pointer to data */ - - if (_kernel_osword(21, (int *) cursor_def) != 0) { - SDL_SetError("RISCOS couldn't create the cursor to show"); - return (0); - } - defined_cursor = cursor; - } - - if (old_cursor == NULL) { - /* First time or reshow in window, so save/setup palette */ - if (!cursor_palette_saved) { - WIMP_SaveCursorPalette(); - } - WIMP_SetSDLCursorPalette(); - } - - _kernel_osbyte(106, 2, 0); - } - - return (1); -} - -void -FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y) -{ - Uint8 move_block[5]; - int eig_block[3]; - _kernel_swi_regs regs; - int os_x, os_y; - - eig_block[0] = 4; /* X eig factor */ - eig_block[1] = 5; /* Y eig factor */ - eig_block[2] = -1; /* End of list of variables to request */ - - regs.r[0] = (int) eig_block; - regs.r[1] = (int) eig_block; - _kernel_swi(OS_ReadVduVariables, ®s, ®s); - - os_x = x << eig_block[0]; - os_y = y << eig_block[1]; - - move_block[0] = 3; /* Move cursor */ - move_block[1] = os_x & 0xFF; - move_block[2] = (os_x >> 8) & 0xFF; - move_block[3] = os_y & 0xFF; - move_block[4] = (os_y >> 8) & 0xFF; - - _kernel_osword(21, (int *) move_block); - SDL_PrivateMouseMotion(0, 0, x, y); -} - - -/* Reshow cursor when mouse re-enters the window */ -void -WIMP_ReshowCursor(_THIS) -{ - defined_cursor = NULL; - cursor_palette_saved = 0; - RISCOS_ShowWMCursor(this, current_cursor); -} - -void -WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y) -{ - _kernel_swi_regs regs; - int window_state[9]; - char block[5]; - int osX, osY; - - window_state[0] = this->hidden->window_handle; - regs.r[1] = (unsigned int) window_state; - _kernel_swi(Wimp_GetWindowState, ®s, ®s); - - osX = (x << this->hidden->xeig) + window_state[1]; - osY = window_state[4] - (y << this->hidden->yeig); - - block[0] = 3; - block[1] = osX & 0xFF; - block[2] = (osX >> 8) & 0xFF; - block[3] = osY & 0xFF; - block[4] = (osY >> 8) & 0xFF; - - regs.r[0] = 21; - regs.r[1] = (int) block; - _kernel_swi(OS_Word, ®s, ®s); - SDL_PrivateMouseMotion(0, 0, x, y); -} - -int -WIMP_ShowWMCursor(_THIS, WMcursor * cursor) -{ - if (mouseInWindow) - return RISCOS_ShowWMCursor(this, cursor); - else - current_cursor = cursor; - - return 1; -} - -SDL_GrabMode -RISCOS_GrabInput(_THIS, SDL_GrabMode mode) -{ - /* In fullscreen mode we don't need to do anything */ - if (mode < SDL_GRAB_FULLSCREEN) { - _kernel_swi_regs regs; - unsigned char block[9]; - block[0] = 1; /* Define mouse cursor bounding block */ - - if (mode == SDL_GRAB_OFF) { - /* Clip to whole screen */ - - int r = (this->hidden->screen_width << this->hidden->xeig) - 1; - int t = (this->hidden->screen_height << this->hidden->yeig) - 1; - - block[1] = 0; - block[2] = 0; /* Left */ - block[3] = 0; - block[4] = 0; /* Bottom */ - block[5] = r & 0xFF; - block[6] = (r >> 8) & 0xFF; /* Right */ - block[7] = t & 0xFF; - block[8] = (t >> 8) & 0xFF; /* Top */ - } else { - /* Clip to window */ - unsigned char window_state[36]; - - *((int *) window_state) = this->hidden->window_handle; - regs.r[1] = (unsigned int) window_state; - _kernel_swi(Wimp_GetWindowState, ®s, ®s); - - block[1] = window_state[4]; - block[2] = window_state[5]; - block[3] = window_state[8]; - block[4] = window_state[9]; - block[5] = window_state[12]; - block[6] = window_state[13]; - block[7] = window_state[16]; - block[8] = window_state[17]; - - } - - regs.r[0] = 21; /* OS word code */ - regs.r[1] = (int) block; - _kernel_swi(OS_Word, ®s, ®s); - } - - return mode; -} - -/* Save mouse cursor palette to be restore when we are no longer - defining a cursor */ - -void -WIMP_SaveCursorPalette() -{ - _kernel_swi_regs regs; - int colour; - - for (colour = 0; colour < 2; colour++) { - regs.r[0] = (int) wimp_cursor_palette[colour][0]; - regs.r[1] = 25; - /* Read settings with OS_ReadPalette */ - if (_kernel_swi(0x2f, ®s, ®s) == NULL) { - wimp_cursor_palette[colour][2] = - (unsigned char) ((regs.r[2] >> 8) & 0xFF); - wimp_cursor_palette[colour][3] = - (unsigned char) ((regs.r[2] >> 16) & 0xFF); - wimp_cursor_palette[colour][4] = - (unsigned char) ((regs.r[2] >> 24) & 0xFF); - } - } - - cursor_palette_saved = 1; -} - -/* Restore the WIMP's cursor when we leave the SDL window */ -void -WIMP_RestoreWimpCursor() -{ - int colour; - - /* Reset to pointer shape 1 */ - _kernel_osbyte(106, 1, 0); - - /* Reset pointer colours */ - if (cursor_palette_saved) { - for (colour = 0; colour < 2; colour++) { - _kernel_osword(12, (int *) wimp_cursor_palette[colour]); - } - } - cursor_palette_saved = 0; -} - -/* Set palette used for SDL mouse cursors */ -void -WIMP_SetSDLCursorPalette() -{ - /* First time set up the mouse colours */ - Uint8 block[5]; - - /* Set up colour 1 as white */ - block[0] = 1; /* Colour to change 1 - 3 */ - block[1] = 25; /* Set pointer colour */ - block[2] = 255; /* red component */ - block[3] = 255; /* green component */ - block[4] = 255; /* blue component */ - _kernel_osword(12, (int *) block); - - /* Set colour 3 to back */ - block[0] = 3; /* Colour to change 1 - 3 */ - block[1] = 25; /* Set pointer colour */ - block[2] = 0; /* red component */ - block[3] = 0; /* green component */ - block[4] = 0; /* blue component */ - _kernel_osword(12, (int *) block); -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscosmouse_c.h b/src/video/riscos/SDL_riscosmouse_c.h deleted file mode 100644 index 0ba7ea6cb..000000000 --- a/src/video/riscos/SDL_riscosmouse_c.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_riscosvideo.h" - -/* The implementation dependent data for the window manager cursor */ -struct WMcursor -{ - int w; - int h; - int hot_x; - int hot_y; - Uint8 *data; -}; - -/* Functions to be exported */ -void RISCOS_FreeWMCursor(_THIS, WMcursor * cursor); -WMcursor *RISCOS_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask, int w, - int h, int hot_x, int hot_y); - -int RISCOS_ShowWMCursor(_THIS, WMcursor * cursor); -void FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y); - -int WIMP_ShowWMCursor(_THIS, WMcursor * cursor); -void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y); -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscossprite.c b/src/video/riscos/SDL_riscossprite.c deleted file mode 100644 index f542cc2ff..000000000 --- a/src/video/riscos/SDL_riscossprite.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability - 27 March 2003 - - Implements Sprite plotting code for wimp display.window -*/ - -#include "kernel.h" -#include "swis.h" - -#include "SDL_stdinc.h" -#include "SDL_riscosvideo.h" - -extern void WIMP_ReadModeInfo(_THIS); - -void WIMP_PaletteChanged(_THIS); - - -/* Create sprite buffer for screen */ - -unsigned char * -WIMP_CreateBuffer(int width, int height, int bpp) -{ - int size; - char sprite_name[12] = "display"; - unsigned char *buffer; - _kernel_swi_regs regs; - int bytesPerPixel; - int bytesPerRow; - int offsetToSpriteData = 60; - - switch (bpp) { - case 32: - bytesPerPixel = 4; - break; - case 16: - bytesPerPixel = 2; - break; - case 8: - bytesPerPixel = 1; - offsetToSpriteData += 2048; /* Add in size of palette */ - break; - default: - return NULL; - break; - } - - bytesPerRow = bytesPerPixel * width; - - if ((bytesPerRow & 3) != 0) { - bytesPerRow += 4 - (bytesPerRow & 3); - } - size = bytesPerRow * height; - - buffer = SDL_malloc((size_t) size + offsetToSpriteData); - if (!buffer) - return NULL; - - /* Initialise a sprite area */ - - *(unsigned int *) buffer = size + offsetToSpriteData; - *(unsigned int *) (buffer + 8) = 16; - - regs.r[0] = 256 + 9; - regs.r[1] = (unsigned int) buffer; - _kernel_swi(OS_SpriteOp, ®s, ®s); - - regs.r[0] = 256 + 15; - regs.r[1] = (unsigned int) buffer; - regs.r[2] = (unsigned int) &sprite_name; - regs.r[3] = 0; /* Palette flag: 0 = no palette */ - regs.r[4] = width; - regs.r[5] = height; - if (bpp == 8) { - /* Use old style mode number */ - regs.r[6] = 28; /* 8bpp 90x90dpi */ - } else { - regs.r[6] = (((bpp == 16) ? 5 : 6) << 27) /* Type 6 = 32bpp sprite, 5 = 16bpp sprite */ - |(90 << 14) /* Vertical dpi */ - |(90 << 1) /* Horizontal dpi */ - |1; /* Marker to distinguish between mode selectors and sprite modes */ - } - if (_kernel_swi(OS_SpriteOp, ®s, ®s) == NULL) { - if (bpp == 8) { - /* Modify sprite to take into account 256 colour palette */ - int *sprite = (int *) (buffer + 16); - /* Adjust sprite offsets */ - sprite[0] += 2048; - sprite[8] += 2048; - sprite[9] += 2048; - /* Adjust sprite area next free pointer */ - (*(int *) (buffer + 12)) += 2048; - - /* Don't need to set up palette as SDL sets up the default - 256 colour palette */ -/* { - int *pal = sprite + 11; - unsigned int j; - unsigned int entry; - for (j = 0; j < 255; j++) - { - entry = (j << 24) | (j << 16) | (j << 8); - *pal++ = entry; - *pal++ = entry; - } - } -*/ - } - } else { - SDL_free(buffer); - buffer = NULL; - } - - return buffer; -} - - -/* Setup translation buffers for the sprite plotting */ - -void -WIMP_SetupPlotInfo(_THIS) -{ - _kernel_swi_regs regs; - int *sprite = ((int *) this->hidden->bank[1]) + 4; - - regs.r[0] = (unsigned int) this->hidden->bank[1]; - regs.r[1] = (unsigned int) sprite; - regs.r[2] = -1; /* Current mode */ - regs.r[3] = -1; /* Current palette */ - regs.r[4] = 0; /* Get size of buffer */ - regs.r[5] = 1 | 2 | 16; /* R1 - pointer to sprite and can use full palette words */ - regs.r[6] = 0; - regs.r[7] = 0; - - if (this->hidden->pixtrans) - SDL_free(this->hidden->pixtrans); - this->hidden->pixtrans = 0; - - /* Get the size required for the buffer */ - _kernel_swi(ColourTrans_GenerateTable, ®s, ®s); - if (regs.r[4]) { - this->hidden->pixtrans = SDL_malloc(regs.r[4]); - - regs.r[4] = (unsigned int) this->hidden->pixtrans; - /* Actually read the buffer */ - _kernel_swi(ColourTrans_GenerateTable, ®s, ®s); - } -} - -/* Plot the sprite in the given context */ -void -WIMP_PlotSprite(_THIS, int x, int y) -{ - _kernel_swi_regs regs; - _kernel_oserror *err; - - regs.r[0] = 52 + 512; - regs.r[1] = (unsigned int) this->hidden->bank[1]; - regs.r[2] = (unsigned int) this->hidden->bank[1] + 16; - regs.r[3] = x; - regs.r[4] = y; - regs.r[5] = 0 | 32; /* Overwrite screen and pixtrans contains wide colour entries */ - regs.r[6] = 0; /* No scale factors i.e. 1:1 */ - regs.r[7] = (int) this->hidden->pixtrans; - - if ((err = _kernel_swi(OS_SpriteOp, ®s, ®s)) != 0) { - int *p = (int *) this->hidden->pixtrans; - printf("OS_SpriteOp failed \n%s\n", err->errmess); - printf("pixtrans %d\n", (int) this->hidden->pixtrans); - printf("%x %x %x\n", p[0], p[1], p[2]); - } -} - - -/* Wimp mode has changes so update colour mapping and pixel sizes - of windows and the sprites they plot */ - -void -WIMP_ModeChanged(_THIS) -{ - int oldXeig = this->hidden->xeig; - int oldYeig = this->hidden->yeig; - - WIMP_ReadModeInfo(this); - - if (oldXeig == this->hidden->xeig && oldYeig == this->hidden->yeig) { - /* Only need to update the palette */ - WIMP_PaletteChanged(this); - } else { - _kernel_swi_regs regs; - int window_state[9]; - int extent[4]; - int currWidth, currHeight; - int newWidth, newHeight; - - /* Need to resize windows and update the palette */ - WIMP_SetupPlotInfo(this); - - - window_state[0] = this->hidden->window_handle; - regs.r[1] = (unsigned int) window_state; - _kernel_swi(Wimp_GetWindowState, ®s, ®s); - - currWidth = window_state[3] - window_state[1]; - currHeight = window_state[4] - window_state[2]; - - newWidth = (currWidth >> oldXeig) << this->hidden->xeig; - newHeight = (currHeight >> oldYeig) << this->hidden->yeig; - /* Need to avoid extent getting too small for visible part - of window */ - extent[0] = 0; - if (currHeight <= newHeight) { - extent[1] = -newHeight; - } else { - extent[1] = -currHeight; - } - if (currWidth <= newWidth) { - extent[2] = newWidth; - } else { - extent[2] = currWidth; - } - extent[3] = 0; - - regs.r[0] = this->hidden->window_handle; - regs.r[1] = (int) extent; - _kernel_swi(Wimp_SetExtent, ®s, ®s); - - /*TODO: May need to set flag to resize window on next open */ - } -} - -/* Palette has changed so update palettes used for windows sprites */ - -void -WIMP_PaletteChanged(_THIS) -{ - WIMP_SetupPlotInfo(this); -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscostask.c b/src/video/riscos/SDL_riscostask.c deleted file mode 100644 index 960bfdd89..000000000 --- a/src/video/riscos/SDL_riscostask.c +++ /dev/null @@ -1,367 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - This file added by Alan Buckley (alan_baa@hotmail.com) to support RISC OS - 26 March 2003 - - File includes routines for: - Setting up as a WIMP Task - Reading information about the current desktop - Storing information before a switch to full screen - Restoring desktop after switching to full screen -*/ - -#include "kernel.h" -#include "swis.h" - -#include "SDL_stdinc.h" -#include "SDL_riscostask.h" - -#if !SDL_THREADS_DISABLED -#include -pthread_t main_thread; -#endif - -/* RISC OS variables */ - -static int task_handle = 0; -static int wimp_version = 0; - -/* RISC OS variables to help compatability with certain programs */ -int riscos_backbuffer = 0; /* Create a back buffer in system memory for full screen mode */ -int riscos_closeaction = 1; /* Close icon action */ - -static int stored_mode = -1; /* -1 when in desktop, mode number or pointer when full screen */ - -extern int mouseInWindow; /* Mouse is in WIMP window */ - -/* Local function */ - -static int RISCOS_GetTaskName(char *task_name, size_t maxlen); - -/* Uncomment next line to copy mode changes/restores to stderr */ -/* #define DUMP_MODE */ -#ifdef DUMP_MODE -#include "stdio.h" -static void -dump_mode() -{ - fprintf(stderr, "mode %d\n", stored_mode); - if (stored_mode < -1 || stored_mode >= 256) { - int blockSize = 0; - int *storeBlock = (int *) stored_mode; - - while (blockSize < 5 || storeBlock[blockSize] != -1) { - fprintf(stderr, " %d\n", storeBlock[blockSize++]); - } - } -} -#endif - -/****************************************************************** - - Initialise as RISC OS Wimp task - -*******************************************************************/ - -int -RISCOS_InitTask() -{ - char task_name[32]; - _kernel_swi_regs regs; - int messages[4]; - - if (RISCOS_GetTaskName(task_name, SDL_arraysize(task_name)) == 0) - return 0; - - messages[0] = 9; /* Palette changed */ - messages[1] = 0x400c1; /* Mode changed */ - messages[2] = 8; /* Pre quit */ - messages[2] = 0; - - regs.r[0] = (unsigned int) 360; /* Minimum version 3.6 */ - regs.r[1] = (unsigned int) 0x4b534154; - regs.r[2] = (unsigned int) task_name; - regs.r[3] = (unsigned int) messages; - - if (_kernel_swi(Wimp_Initialise, ®s, ®s) == 0) { - wimp_version = regs.r[0]; - task_handle = regs.r[1]; - return 1; - } -#if !SDL_THREADS_DISABLED - main_thread = pthread_self(); -#endif - - return 0; -} - -/********************************************************************* - - Close down application on exit. - -**********************************************************************/ - -void -RISCOS_ExitTask() -{ - _kernel_swi_regs regs; - - if (stored_mode == -1) { - /* Ensure cursor is put back to standard pointer shape if - we have been running in a window */ - _kernel_osbyte(106, 1, 0); - } - - /* Ensure we end up back in the wimp */ - RISCOS_RestoreWimpMode(); - - /* Neatly exit the task */ - regs.r[0] = task_handle; - regs.r[1] = (unsigned int) 0x4b534154; - _kernel_swi(Wimp_CloseDown, ®s, ®s); - task_handle = 0; -} - -/************************************************************************** - - Get the name of the task for the desktop. - - Param: task_name - name of task 32 characters. - - Returns: 1 is successful, otherwise 0 - - Notes: Works by getting using OS_GetEnv to get the command line - used to run the program and then parsing a name from it - as follows. - - 1. Use name after final period if not !RunImage - 2. If name is !RunImage then process item before the period - in front of !RunImage. - 3. If directory name use that - 4. if in form use the XXX. - - Finally once this value has been retrieved use it unless - there is a variable set up in the form SDL$$TaskName - in which case the value of this variable will be used. - - Now also gets other RISC OS configuration varibles - SDL$$BackBuffer - set to 1 to use a system memory backbuffer in fullscreen mode - so updates wait until a call to SDL_UpdateRects. (default 0) - This is required for programmes where they have assumed this is - always the case which is contrary to the documentation. - SDL$$CloseAction - 0 Don't show close icon - 1 Show close icon - -***************************************************************************/ - -int -RISCOS_GetTaskName(char *task_name, size_t maxlen) -{ - _kernel_swi_regs regs; - - task_name[0] = 0; - - /* Figure out a sensible task name */ - if (_kernel_swi(OS_GetEnv, ®s, ®s) == 0) { - char *command_line = (char *) regs.r[0]; - size_t len = SDL_strlen(command_line) + 1; - char *buffer = SDL_stack_alloc(char, len); - char *env_var; - char *p; - - SDL_strlcpy(buffer, command_line, len); - p = SDL_strchr(buffer, ' '); - if (p) - *p = 0; - p = SDL_strrchr(buffer, '.'); - if (p == 0) - p = buffer; - if (stricmp(p + 1, "!RunImage") == 0) { - *p = 0; - p = SDL_strrchr(buffer, '.'); - if (p == 0) - p = buffer; - } - if (*p == '.') - p++; - if (*p == '!') - p++; /* Skip "!" at beginning of application directories */ - - if (*p == '<') { - // Probably in the form - char *q = SDL_strchr(p, '$'); - if (q == 0) - q = SDL_strchr(p, '>'); /* Use variable name if not */ - if (q) - *q = 0; - p++; /* Move over the < */ - } - - if (*p) { - /* Read variables that effect the RISC OS SDL engine for this task */ - len = SDL_strlen(p) + 18; /* 18 is larger than the biggest variable name */ - env_var = SDL_stack_alloc(char, len); - if (env_var) { - char *env_val; - - /* See if a variable of form SDL$$TaskName exists */ - - SDL_strlcpy(env_var, "SDL$", len); - SDL_strlcat(env_var, p, len); - SDL_strlcat(env_var, "$TaskName", len); - - env_val = SDL_getenv(env_var); - if (env_val) - SDL_strlcpy(task_name, env_val, maxlen); - - SDL_strlcpy(env_var, "SDL$", len); - SDL_strlcat(env_var, p, len); - SDL_strlcat(env_var, "$BackBuffer", len); - - env_val = SDL_getenv(env_var); - if (env_val) - riscos_backbuffer = atoi(env_val); - - SDL_strlcpy(env_var, "SDL$", len); - SDL_strlcat(env_var, p, len); - SDL_strlcat(env_var, "$CloseAction", len); - - env_val = SDL_getenv(env_var); - if (env_val && SDL_strcmp(env_val, "0") == 0) - riscos_closeaction = 0; - - SDL_stack_free(env_var); - } - - if (!*task_name) - SDL_strlcpy(task_name, p, maxlen); - } - - SDL_stack_free(buffer); - } - - if (task_name[0] == 0) - SDL_strlcpy(task_name, "SDL Task", maxlen); - - return 1; -} - -/***************************************************************** - - Store the current desktop screen mode if we are in the desktop. - -******************************************************************/ - -void -RISCOS_StoreWimpMode() -{ - _kernel_swi_regs regs; - - /* Don't store if in full screen mode */ - if (stored_mode != -1) - return; - - regs.r[0] = 1; - _kernel_swi(OS_ScreenMode, ®s, ®s); - if (regs.r[1] >= 0 && regs.r[1] < 256) - stored_mode = regs.r[1]; - else { - int blockSize = 0; - int *retBlock = (int *) regs.r[1]; - int *storeBlock; - int j; - - while (blockSize < 5 || retBlock[blockSize] != -1) - blockSize++; - blockSize++; - storeBlock = (int *) SDL_malloc(blockSize * sizeof(int)); - retBlock = (int *) regs.r[1]; - for (j = 0; j < blockSize; j++) - storeBlock[j] = retBlock[j]; - - stored_mode = (int) storeBlock; - } -#if DUMP_MODE - fprintf(stderr, "Stored "); - dump_mode(); -#endif -} - -/***************************************************************** - - Restore desktop screen mode if we are in full screen mode. - -*****************************************************************/ - -void -RISCOS_RestoreWimpMode() -{ - _kernel_swi_regs regs; - - /* Only need to restore if we are in full screen mode */ - if (stored_mode == -1) - return; - -#if DUMP_MODE - fprintf(stderr, "Restored"); - dump_mode(); -#endif - - regs.r[0] = stored_mode; - _kernel_swi(Wimp_SetMode, ®s, ®s); - if (stored_mode < 0 || stored_mode > 256) { - SDL_free((int *) stored_mode); - } - stored_mode = -1; - - /* Flush keyboard buffer to dump the keystrokes we've already polled */ - regs.r[0] = 21; - regs.r[1] = 0; /* Keyboard buffer number */ - _kernel_swi(OS_Byte, ®s, ®s); - - mouseInWindow = 0; - -} - -/********************************************************************* - - Get version of Wimp running when task was initialised. - -*********************************************************************/ - -int -RISCOS_GetWimpVersion() -{ - return wimp_version; -} - -int -RISCOS_GetTaskHandle() -{ - return task_handle; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscostask.h b/src/video/riscos/SDL_riscostask.h deleted file mode 100644 index 8eadb87b4..000000000 --- a/src/video/riscos/SDL_riscostask.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - This file added by Alan Buckley (alan_baa@hotmail.com) to support RISC OS - 26 March 2003 -*/ - -/* Task initialisation/Clean up */ - -extern int RISCOS_InitTask(); -extern void RISCOS_ExitTask(); -extern int RISCOS_GetWimpVersion(); -extern int RISCOS_GetTaskHandle(); - - -/* Wimp mode saveing/restoring */ -extern void RISCOS_StoreWimpMode(); -extern void RISCOS_RestoreWimpMode(); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscosvideo.c b/src/video/riscos/SDL_riscosvideo.c deleted file mode 100644 index c36c3d542..000000000 --- a/src/video/riscos/SDL_riscosvideo.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability - 23 March 2003 - - Implements RISC OS display device management. - Routines for full screen and wimp modes are split - into other source files. -*/ - -#include "SDL_video.h" -#include "SDL_mouse.h" -#include "SDL_syswm.h" -#include "../SDL_sysvideo.h" -#include "../SDL_pixels_c.h" -#include "../../events/SDL_events_c.h" - -#include "SDL_riscostask.h" -#include "SDL_riscosvideo.h" -#include "SDL_riscosevents_c.h" -#include "SDL_riscosmouse_c.h" - -#include "kernel.h" -#include "swis.h" - -#define RISCOSVID_DRIVER_NAME "riscos" - -/* Initialization/Query functions */ -static int RISCOS_VideoInit(_THIS, SDL_PixelFormat * vformat); -static void RISCOS_VideoQuit(_THIS); - -static SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat * format, - Uint32 flags); -static SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface * current, - int width, int height, int bpp, - Uint32 flags); - -int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info); - -int RISCOS_ToggleFullScreen(_THIS, int fullscreen); -/* Mouse checking */ -void RISCOS_CheckMouseMode(_THIS); -extern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode); - -/* Fullscreen mode functions */ -extern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface * current, - int width, int height, int bpp, - Uint32 flags); -extern void FULLSCREEN_BuildModeList(_THIS); -extern void FULLSCREEN_SetDeviceMode(_THIS); -extern int FULLSCREEN_ToggleFromWimp(_THIS); - -/* Wimp mode functions */ -extern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface * current, - int width, int height, int bpp, - Uint32 flags); -extern void WIMP_DeleteWindow(_THIS); -extern int WIMP_ToggleFromFullScreen(_THIS); - -/* Hardware surface functions - common to WIMP and FULLSCREEN */ -static int RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface); -static int RISCOS_LockHWSurface(_THIS, SDL_Surface * surface); -static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface * surface); -static void RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface); - -/* RISC OS driver bootstrap functions */ - -static int -RISCOS_Available(void) -{ - return (1); -} - -static void -RISCOS_DeleteDevice(SDL_VideoDevice * device) -{ - SDL_free(device->hidden); - SDL_free(device); -} - -static SDL_VideoDevice * -RISCOS_CreateDevice(int devindex) -{ - SDL_VideoDevice *device; - - /* Initialize all variables that we clean on shutdown */ - device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice)); - if (device) { - SDL_memset(device, 0, (sizeof *device)); - device->hidden = (struct SDL_PrivateVideoData *) - SDL_malloc((sizeof *device->hidden)); - } - if ((device == NULL) || (device->hidden == NULL)) { - SDL_OutOfMemory(); - if (device) { - SDL_free(device); - } - return (0); - } - SDL_memset(device->hidden, 0, (sizeof *device->hidden)); - - /* Set the function pointers */ - device->VideoInit = RISCOS_VideoInit; - device->VideoQuit = RISCOS_VideoQuit; - - device->ListModes = RISCOS_ListModes; - device->SetVideoMode = RISCOS_SetVideoMode; - device->CreateYUVOverlay = NULL; - device->AllocHWSurface = RISCOS_AllocHWSurface; - device->CheckHWBlit = NULL; - device->FillHWRect = NULL; - device->SetHWColorKey = NULL; - device->SetHWAlpha = NULL; - device->LockHWSurface = RISCOS_LockHWSurface; - device->UnlockHWSurface = RISCOS_UnlockHWSurface; - device->FreeHWSurface = RISCOS_FreeHWSurface; - - device->FreeWMCursor = RISCOS_FreeWMCursor; - device->CreateWMCursor = RISCOS_CreateWMCursor; - device->CheckMouseMode = RISCOS_CheckMouseMode; - device->GrabInput = RISCOS_GrabInput; - - device->InitOSKeymap = RISCOS_InitOSKeymap; - - device->GetWMInfo = RISCOS_GetWmInfo; - - device->free = RISCOS_DeleteDevice; - -/* Can't get Toggle screen to work if program starts up in Full screen mode so - disable it here and re-enable it when a wimp screen is chosen */ - device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen; */ - - /* Set other entries for fullscreen mode */ - FULLSCREEN_SetDeviceMode(device); - - /* Mouse pointer needs to use the WIMP ShowCursor version so - that it doesn't modify the pointer until the SDL Window is - entered or the application goes full screen */ - device->ShowWMCursor = WIMP_ShowWMCursor; - - return device; -} - -VideoBootStrap RISCOS_bootstrap = { - RISCOSVID_DRIVER_NAME, "RISC OS video driver", - RISCOS_Available, RISCOS_CreateDevice -}; - - -int -RISCOS_VideoInit(_THIS, SDL_PixelFormat * vformat) -{ - _kernel_swi_regs regs; - int vars[4], vals[3]; - - if (RISCOS_InitTask() == 0) { - SDL_SetError("Unable to start task"); - return 0; - } - - vars[0] = 9; /* Log base 2 bpp */ - vars[1] = 11; /* XWndLimit - num x pixels -1 */ - vars[2] = 12; /* YWndLimit - num y pixels -1 */ - vars[3] = -1; /* Terminate list */ - regs.r[0] = (int) vars; - regs.r[1] = (int) vals; - - _kernel_swi(OS_ReadVduVariables, ®s, ®s); - vformat->BitsPerPixel = (1 << vals[0]); - - /* Determine the current screen size */ - this->info.current_w = vals[1] + 1; - this->info.current_h = vals[2] + 1; - - /* Minimum bpp for SDL is 8 */ - if (vformat->BitsPerPixel < 8) - vformat->BitsPerPixel = 8; - - - switch (vformat->BitsPerPixel) { - case 15: - case 16: - vformat->Bmask = 0x00007c00; - vformat->Gmask = 0x000003e0; - vformat->Rmask = 0x0000001f; - vformat->BitsPerPixel = 16; /* SDL wants actual number of bits used */ - vformat->BytesPerPixel = 2; - break; - - case 24: - case 32: - vformat->Bmask = 0x00ff0000; - vformat->Gmask = 0x0000ff00; - vformat->Rmask = 0x000000ff; - vformat->BytesPerPixel = 4; - break; - - default: - vformat->Bmask = 0; - vformat->Gmask = 0; - vformat->Rmask = 0; - vformat->BytesPerPixel = 1; - break; - } - - /* Fill in some window manager capabilities */ - this->info.wm_available = 1; - - /* We're done! */ - return (0); -} - -/* Note: If we are terminated, this could be called in the middle of - another SDL video routine -- notably UpdateRects. -*/ -void -RISCOS_VideoQuit(_THIS) -{ - RISCOS_ExitTask(); - - if (this->hidden->alloc_bank) - SDL_free(this->hidden->alloc_bank); - this->hidden->alloc_bank = 0; -} - - -SDL_Rect ** -RISCOS_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) -{ - if (flags & SDL_FULLSCREEN) { - /* Build mode list when first required. */ - if (SDL_nummodes[0] == 0) - FULLSCREEN_BuildModeList(this); - - return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]); - } else - return (SDL_Rect **) - 1; -} - - -/* Set up video mode */ -SDL_Surface * -RISCOS_SetVideoMode(_THIS, SDL_Surface * current, - int width, int height, int bpp, Uint32 flags) -{ - if (flags & SDL_FULLSCREEN) { - RISCOS_StoreWimpMode(); - /* Dump wimp window on switch to full screen */ - if (this->hidden->window_handle) - WIMP_DeleteWindow(this); - - return FULLSCREEN_SetVideoMode(this, current, width, height, bpp, - flags); - } else { - RISCOS_RestoreWimpMode(); - return WIMP_SetVideoMode(this, current, width, height, bpp, flags); - } -} - - -/* We don't actually allow hardware surfaces other than the main one */ -static int -RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface) -{ - return (-1); -} - -static void -RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface) -{ - return; -} - -/* We need to wait for vertical retrace on page flipped displays */ -static int -RISCOS_LockHWSurface(_THIS, SDL_Surface * surface) -{ - return (0); -} - -static void -RISCOS_UnlockHWSurface(_THIS, SDL_Surface * surface) -{ - return; -} - - -int -RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info) -{ - SDL_VERSION(&(info->version)); - info->wimpVersion = RISCOS_GetWimpVersion(); - info->taskHandle = RISCOS_GetTaskHandle(); - info->window = this->hidden->window_handle; - - return 1; -} - -/* Toggle full screen mode. - Returns 1 if successful otherwise 0 -*/ - -int -RISCOS_ToggleFullScreen(_THIS, int fullscreen) -{ - if (fullscreen) { - return FULLSCREEN_ToggleFromWimp(this); - } else { - return WIMP_ToggleFromFullScreen(this); - } - - return 0; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_riscosvideo.h b/src/video/riscos/SDL_riscosvideo.h deleted file mode 100644 index 5858a99ba..000000000 --- a/src/video/riscos/SDL_riscosvideo.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifndef _SDL_riscosvideo_h -#define _SDL_riscosvideo_h - -#include "SDL_mouse.h" -#include "SDL_mutex.h" -#include "../SDL_sysvideo.h" - -/* Hidden "this" pointer for the video functions */ -#define _THIS SDL_VideoDevice *this - - -/* Private display data */ - -struct SDL_PrivateVideoData -{ - unsigned char *bank[2]; - int current_bank; - unsigned char *alloc_bank; - int height; - int xeig; - int yeig; - int screen_bpp; - int screen_width; - int screen_height; - char *pixtrans; - - /* Wimp variables */ - unsigned int window_handle; - char title[256]; - -#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */ - int SDL_nummodes[NUM_MODELISTS]; - SDL_Rect **SDL_modelist[NUM_MODELISTS]; -}; - -/* Old variable names */ -#define SDL_nummodes (this->hidden->SDL_nummodes) -#define SDL_modelist (this->hidden->SDL_modelist) - -#endif /* _SDL_risosvideo_h */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_wimppoll.c b/src/video/riscos/SDL_wimppoll.c deleted file mode 100644 index 31d0fda58..000000000 --- a/src/video/riscos/SDL_wimppoll.c +++ /dev/null @@ -1,334 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability - 27 March 2003 - - Implements Pumping of events and WIMP polling -*/ - -#include "SDL_syswm.h" -#include "../../events/SDL_sysevents.h" -#include "../../events/SDL_events_c.h" -#include "SDL_riscosvideo.h" -#include "SDL_riscosevents_c.h" -#include "SDL_riscosmouse_c.h" -#include "../../timer/SDL_timer_c.h" - -#include "memory.h" -#include "stdlib.h" -#include "ctype.h" - -#include "kernel.h" -#include "swis.h" -#include "unixlib/os.h" - -#if !SDL_THREADS_DISABLED -#include -#endif - -/* Local functions */ -void WIMP_Poll(_THIS, int waitTime); -void WIMP_SetFocus(int win); - -/* SDL_riscossprite functions */ -void WIMP_PlotSprite(_THIS, int x, int y); -void WIMP_ModeChanged(_THIS); -void WIMP_PaletteChanged(_THIS); - - -extern void WIMP_PollMouse(_THIS); -extern void RISCOS_PollKeyboard(); - -#if SDL_THREADS_DISABLED -/* Timer running function */ -extern void RISCOS_CheckTimer(); -#else -extern int riscos_using_threads; -#endif - -/* Mouse cursor handling */ -extern void WIMP_ReshowCursor(_THIS); -extern void WIMP_RestoreWimpCursor(); - -int hasFocus = 0; -int mouseInWindow = 0; - -/* Flag to ensure window is correct size after a mode change */ -static int resizeOnOpen = 0; - -void -WIMP_PumpEvents(_THIS) -{ - WIMP_Poll(this, 0); - if (hasFocus) - RISCOS_PollKeyboard(); - if (mouseInWindow) - WIMP_PollMouse(this); -#if SDL_THREADS_DISABLED - if (SDL_timer_running) - RISCOS_CheckTimer(); -#endif -} - - -void -WIMP_Poll(_THIS, int waitTime) -{ - _kernel_swi_regs regs; - int message[64]; - unsigned int code; - int pollMask = 0; - int doPoll = 1; - int sysEvent; - int sdlWindow = this->hidden->window_handle; - - if (this->PumpEvents != WIMP_PumpEvents) - return; - - if (waitTime > 0) { - _kernel_swi(OS_ReadMonotonicTime, ®s, ®s); - waitTime += regs.r[0]; - } - - while (doPoll) { -#if !SDL_THREADS_DISABLED - /* Stop thread callbacks while program is paged out */ - if (riscos_using_threads) - __pthread_stop_ticker(); -#endif - - if (waitTime <= 0) { - regs.r[0] = pollMask; /* Poll Mask */ - /* For no wait time mask out null event so we wait until something happens */ - if (waitTime < 0) - regs.r[0] |= 1; - regs.r[1] = (int) message; - _kernel_swi(Wimp_Poll, ®s, ®s); - } else { - regs.r[0] = pollMask; - regs.r[1] = (int) message; - regs.r[2] = waitTime; - _kernel_swi(Wimp_PollIdle, ®s, ®s); - } - - /* Flag to specify if we post a SDL_SysWMEvent */ - sysEvent = 0; - - code = (unsigned int) regs.r[0]; - - switch (code) { - case 0: /* Null Event - drop out for standard processing */ - doPoll = 0; - break; - - case 1: /* Redraw window */ - _kernel_swi(Wimp_RedrawWindow, ®s, ®s); - if (message[0] == sdlWindow) { - while (regs.r[0]) { - WIMP_PlotSprite(this, message[1], message[2]); - _kernel_swi(Wimp_GetRectangle, ®s, ®s); - } - } else { - /* TODO: Currently we just eat them - we may need to pass them on */ - while (regs.r[0]) { - _kernel_swi(Wimp_GetRectangle, ®s, ®s); - } - } - break; - - case 2: /* Open window */ - if (resizeOnOpen && message[0] == sdlWindow) { - /* Ensure window is correct size */ - resizeOnOpen = 0; - message[3] = - message[1] + (this->screen->w << this->hidden->xeig); - message[4] = - message[2] + (this->screen->h << this->hidden->yeig); - } - _kernel_swi(Wimp_OpenWindow, ®s, ®s); - break; - - case 3: /* Close window */ - if (message[0] == sdlWindow) { - /* Documentation makes it looks as if the following line is correct: - ** if (SDL_PrivateQuit() == 1) _kernel_swi(Wimp_CloseWindow, ®s, ®s); - ** However some programs don't process this message and so sit there invisibly - ** in the background so I just post the quit message and hope the application - ** does the correct thing. - */ - SDL_PrivateQuit(); - } else - sysEvent = 1; - doPoll = 0; - break; - - case 4: /* Pointer_Leaving_Window */ - if (message[0] == sdlWindow) { - mouseInWindow = 0; - //TODO: Lose buttons / dragging - /* Reset to default pointer */ - WIMP_RestoreWimpCursor(); - SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); - } else - sysEvent = 1; - break; - - case 5: /* Pointer_Entering_Window */ - if (message[0] == sdlWindow) { - mouseInWindow = 1; - WIMP_ReshowCursor(this); - SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); - } else - sysEvent = 1; - break; - - case 6: /* Mouse_Click */ - if (hasFocus == 0) { - /* First click gives focus if it's not a menu */ - /* we only count non-menu clicks on a window that has the focus */ - WIMP_SetFocus(message[3]); - } else - doPoll = 0; // So PollMouse gets a chance to pick it up - break; - - case 7: /* User_Drag_Box - Used for mouse release */ - //TODO: May need to implement this in the future - sysEvent = 1; - break; - - case 8: /* Keypressed */ - doPoll = 0; /* PollKeyboard should pick it up */ - if (message[0] != sdlWindow) - sysEvent = 1; - /*TODO: May want to always pass F12 etc to the wimp - { - regs.r[0] = message[6]; - _kernel_swi(Wimp_ProcessKey, ®s, ®s); - } - */ - break; - - case 11: /* Lose Caret */ - hasFocus = 0; - if (message[0] == sdlWindow) - SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); - else - sysEvent = 1; - break; - - case 12: /* Gain Caret */ - hasFocus = 1; - if (message[0] == sdlWindow) - SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); - else - sysEvent = 1; - break; - - case 17: - case 18: - sysEvent = 1; /* All messages are passed on */ - - switch (message[4]) { - case 0: /* Quit Event */ - /* No choice - have to quit */ - SDL_Quit(); - exit(0); - break; - - case 8: /* Pre Quit */ - SDL_PrivateQuit(); - break; - - case 0x400c1: /* Mode change */ - WIMP_ModeChanged(this); - resizeOnOpen = 1; - break; - - case 9: /* Palette changed */ - WIMP_PaletteChanged(this); - break; - } - break; - - default: - /* Pass unknown events on */ - sysEvent = 1; - break; - } - - if (sysEvent) { - SDL_SysWMmsg wmmsg; - - SDL_VERSION(&wmmsg.version); - wmmsg.eventCode = code; - SDL_memcpy(wmmsg.pollBlock, message, 64 * sizeof(int)); - - /* Fall out of polling loop if message is successfully posted */ - if (SDL_PrivateSysWMEvent(&wmmsg)) - doPoll = 0; - } -#if !SDL_THREADS_DISABLED - if (riscos_using_threads) { - /* Restart ticker here so other thread can not interfere - with the Redraw processing */ - if (riscos_using_threads) - __pthread_start_ticker(); - /* Give other threads a better chance of running */ - pthread_yield(); - } -#endif - } -} - -/* Set focus to specified window */ -void -WIMP_SetFocus(int win) -{ - _kernel_swi_regs regs; - - regs.r[0] = win; - regs.r[1] = -1; /* Icon handle */ - regs.r[2] = 0; /* X-offset we just put it at position 0 */ - regs.r[3] = 0; /* Y-offset as above */ - regs.r[4] = 1 << 25; /* Caret is invisible */ - regs.r[5] = 0; /* index into string */ - - _kernel_swi(Wimp_SetCaretPosition, ®s, ®s); -} - -/** Run background task while in a sleep command */ -void -RISCOS_BackgroundTasks(void) -{ - if (current_video && current_video->hidden->window_handle) { - WIMP_Poll(current_video, 0); - } -#if SDL_THREADS_DISABLED - if (SDL_timer_running) - RISCOS_CheckTimer(); -#endif -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/riscos/SDL_wimpvideo.c b/src/video/riscos/SDL_wimpvideo.c deleted file mode 100644 index 3b6104f56..000000000 --- a/src/video/riscos/SDL_wimpvideo.c +++ /dev/null @@ -1,511 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* - File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability - 27 March 2003 - - Implements RISC OS Wimp display. -*/ - -#include "SDL_video.h" -#include "SDL_mouse.h" -#include "../SDL_sysvideo.h" -#include "../SDL_pixels_c.h" -#include "../../events/SDL_events_c.h" - -#include "SDL_riscostask.h" -#include "SDL_riscosvideo.h" -#include "SDL_riscosevents_c.h" -#include "SDL_riscosmouse_c.h" - -#include "kernel.h" -#include "swis.h" - -/* Initialization/Query functions */ -SDL_Rect **WIMP_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags); -SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface * current, int width, - int height, int bpp, Uint32 flags); -int WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors); -void WIMP_SetWMCaption(_THIS, const char *title, const char *icon); - - -extern unsigned char *WIMP_CreateBuffer(int width, int height, int bpp); -extern void WIMP_PumpEvents(_THIS); -extern void WIMP_PlotSprite(_THIS, int x, int y); -extern void WIMP_SetupPlotInfo(_THIS); -extern void WIMP_SetFocus(int win); - -/* etc. */ -static void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect * rects); - -/* RISC OS Wimp handling helpers */ -void WIMP_ReadModeInfo(_THIS); -unsigned int WIMP_SetupWindow(_THIS, SDL_Surface * surface); -void WIMP_SetDeviceMode(_THIS); -void WIMP_DeleteWindow(_THIS); - -/* FULLSCREEN function required for wimp/fullscreen toggling */ -extern int FULLSCREEN_SetMode(int width, int height, int bpp); - -/* Currently need to set this up here as it only works if you - start up in a Wimp mode */ -extern int RISCOS_ToggleFullScreen(_THIS, int fullscreen); - -extern int riscos_backbuffer; -extern int mouseInWindow; -extern int riscos_closeaction; - -/* Following needed to ensure window is shown immediately */ -extern int hasFocus; -extern void WIMP_Poll(_THIS, int waitTime); - -SDL_Surface * -WIMP_SetVideoMode(_THIS, SDL_Surface * current, - int width, int height, int bpp, Uint32 flags) -{ - Uint32 Rmask = 0; - Uint32 Gmask = 0; - Uint32 Bmask = 0; - char *buffer = NULL; - int bytesPerPixel = 1; - - /* Don't support double buffering in Wimp mode */ - flags &= ~SDL_DOUBLEBUF; - flags &= ~SDL_HWSURFACE; - - switch (bpp) { - case 8: - /* Emulated palette using ColourTrans */ - flags |= SDL_HWPALETTE; - break; - - case 15: - case 16: - Bmask = 0x00007c00; - Gmask = 0x000003e0; - Rmask = 0x0000001f; - bytesPerPixel = 2; - break; - - case 32: - Bmask = 0x00ff0000; - Gmask = 0x0000ff00; - Rmask = 0x000000ff; - bytesPerPixel = 4; - break; - - default: - SDL_SetError("Pixel depth not supported"); - return NULL; - break; - } - -/* printf("Setting mode %dx%d\n", width, height);*/ - - /* Allocate the new pixel format for the screen */ - if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0)) { - SDL_SetError("Couldn't allocate new pixel format for requested mode"); - return (NULL); - } - - /* Set up the new mode framebuffer */ - current->w = width; - this->hidden->height = current->h = height; - - if (bpp == 15) - bpp = 16; - buffer = WIMP_CreateBuffer(width, height, bpp); - if (buffer == NULL) { - SDL_SetError("Couldn't create sprite for video memory"); - return (NULL); - } - - this->hidden->bank[0] = buffer + 60; /* Start of sprite data */ - if (bpp == 8) - this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ - - this->hidden->bank[1] = buffer; /* Start of buffer */ - - /* Remember sprite buffer so it can be freed later */ - if (this->hidden->alloc_bank) - SDL_free(this->hidden->alloc_bank); - this->hidden->alloc_bank = buffer; - - current->pitch = width * bytesPerPixel; - if ((current->pitch & 3)) { - /* Sprites are 32bit word aligned */ - current->pitch += (4 - (current->pitch & 3)); - } - - current->flags = flags | SDL_PREALLOC; - - WIMP_ReadModeInfo(this); - - SDL_memset(this->hidden->bank[0], 0, height * current->pitch); - - this->hidden->current_bank = 0; - current->pixels = this->hidden->bank[0]; - - - if (WIMP_SetupWindow(this, current) == 0) { - SDL_SetError("Unable to create window to display surface"); - return NULL; - } - - /* Reset device functions for the wimp */ - WIMP_SetDeviceMode(this); - - /* Needs to set up plot info after window has been created */ - /* Not sure why, but plots don't work if I do it earlier */ - WIMP_SetupPlotInfo(this); - - /* Poll until window is shown */ - { - /* We wait until it gets the focus, but give up after 5 seconds - in case the focus is prevented in any way. - */ - Uint32 now = SDL_GetTicks(); - while (!hasFocus && SDL_GetTicks() - now < 5000) { - WIMP_Poll(this, 0); - } - } - - /* We're done */ - return (current); -} - - -void -WIMP_ReadModeInfo(_THIS) -{ - _kernel_swi_regs regs; - int vars[6]; - int vals[5]; - - vars[0] = 4; /* XEig */ - vars[1] = 5; /* YEig */ - vars[2] = 9; /* Log base 2 bpp */ - vars[3] = 11; /* Screen Width - 1 */ - vars[4] = 12; /* Screen Depth - 1 */ - vars[5] = -1; /* Terminate list */ - - regs.r[0] = (int) vars; - regs.r[1] = (int) vals; - _kernel_swi(OS_ReadVduVariables, ®s, ®s); - this->hidden->xeig = vals[0]; - this->hidden->yeig = vals[1]; - this->hidden->screen_bpp = 1 << vals[2]; - this->hidden->screen_width = vals[3] + 1; - this->hidden->screen_height = vals[4] + 1; -} - -/* Set device function to call the correct versions for running - in a wimp window */ - -void -WIMP_SetDeviceMode(_THIS) -{ - if (this->UpdateRects == WIMP_UpdateRects) - return; /* Already set up */ - - this->SetColors = WIMP_SetColors; - this->UpdateRects = WIMP_UpdateRects; - - this->FlipHWSurface = NULL; - - this->SetCaption = WIMP_SetWMCaption; - this->SetIcon = NULL; - this->IconifyWindow = NULL; - - this->ShowWMCursor = WIMP_ShowWMCursor; - this->WarpWMCursor = WIMP_WarpWMCursor; - - this->ToggleFullScreen = RISCOS_ToggleFullScreen; - - this->PumpEvents = WIMP_PumpEvents; -} - -/* Setup the Window to display the surface */ -unsigned int -WIMP_SetupWindow(_THIS, SDL_Surface * surface) -{ - _kernel_swi_regs regs; - int window_data[23]; - int *window_block = window_data + 1; - int x = (this->hidden->screen_width - surface->w) / 2; - int y = (this->hidden->screen_height - surface->h) / 2; - int xeig = this->hidden->xeig; - int yeig = this->hidden->yeig; - - mouseInWindow = 0; - - /* Always delete the window and recreate on a change */ - if (this->hidden->window_handle) - WIMP_DeleteWindow(this); - - /* Setup window co-ordinates */ - window_block[0] = x << xeig; - window_block[1] = y << yeig; - window_block[2] = window_block[0] + (surface->w << xeig); - window_block[3] = window_block[1] + (surface->h << yeig); - - - window_block[4] = 0; /* Scroll offsets */ - window_block[5] = 0; - window_block[6] = -1; /* Open on top of window stack */ - - window_block[7] = 0x85040042; /* Window flags */ - if (riscos_closeaction != 0) - window_block[7] |= 0x2000000; - - /* TODO: Take into account surface->flags */ - - window_block[8] = 0xff070207; /* Window colours */ - window_block[9] = 0x000c0103; - window_block[10] = 0; /* Work area minimum */ - window_block[11] = -surface->h << yeig; - window_block[12] = surface->w << xeig; /* Work area maximum */ - window_block[13] = 0; - window_block[14] = 0x2700013d; /* Title icon flags */ - window_block[15] = 0x00003000; /* Work area flags - Mouse click down reported */ - window_block[16] = 1; /* Sprite area control block pointer */ - window_block[17] = 0x00100010; /* Minimum window size (width & height) (16x16) */ - window_block[18] = (int) this->hidden->title; /* Title data */ - window_block[19] = -1; - window_block[20] = 256; - window_block[21] = 0; /* Number of icons */ - - regs.r[1] = (unsigned int) (window_block); - - /* Create the window */ - if (_kernel_swi(Wimp_CreateWindow, ®s, ®s) == NULL) { - this->hidden->window_handle = window_data[0] = regs.r[0]; - - /* Show the window on the screen */ - regs.r[1] = (unsigned int) window_data; - if (_kernel_swi(Wimp_OpenWindow, ®s, ®s) == NULL) { - WIMP_SetFocus(this->hidden->window_handle); - } else { - WIMP_DeleteWindow(this); - } - } - - return this->hidden->window_handle; -} - -/* Destroy the Window */ - -void -WIMP_DeleteWindow(_THIS) -{ - _kernel_swi_regs regs; - regs.r[1] = (unsigned int) &(this->hidden->window_handle); - _kernel_swi(Wimp_DeleteWindow, ®s, ®s); - this->hidden->window_handle = 0; -} - - -void -WIMP_UpdateRects(_THIS, int numrects, SDL_Rect * rects) -{ - _kernel_swi_regs regs; - int update_block[12]; - int xeig = this->hidden->xeig; - int yeig = this->hidden->yeig; - int j; - update_block[0] = this->hidden->window_handle; - - for (j = 0; j < numrects; j++) { - update_block[1] = rects[j].x << xeig; /* Min X */ - update_block[4] = -(rects[j].y << yeig); - update_block[3] = update_block[1] + (rects[j].w << xeig); - update_block[2] = update_block[4] - (rects[j].h << yeig); - - regs.r[1] = (int) update_block; - /* Update window can fail if called before first poll */ - if (_kernel_swi(Wimp_UpdateWindow, ®s, ®s) == 0) { - while (regs.r[0]) { - WIMP_PlotSprite(this, update_block[1], update_block[2]); - _kernel_swi(Wimp_GetRectangle, ®s, ®s); - } - } - } -} - - -int -WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) -{ - unsigned int *pal = (unsigned int *) (this->hidden->bank[1] + 60); - int j; - SDL_Rect update; - - pal += firstcolor * 2; - for (j = 0; j < ncolors; j++) { - *pal = (((unsigned int) colors->r) << 8) - + (((unsigned int) colors->g) << 16) - + (((unsigned int) colors->b) << 24); - pal[1] = *pal; - pal += 2; - colors++; - } - - WIMP_SetupPlotInfo(this); - - /* Need to refresh the window */ - update.x = 0; - update.y = 0; - update.w = SDL_VideoSurface->w; - update.h = SDL_VideoSurface->h; - WIMP_UpdateRects(this, 1, &update); - - return 1; -} - -void -WIMP_SetWMCaption(_THIS, const char *title, const char *icon) -{ - _kernel_swi_regs regs; - - SDL_strlcpy(this->hidden->title, title, - SDL_arraysize(this->hidden->title)); - - if (RISCOS_GetWimpVersion() < 380) { - int block[6]; - - regs.r[1] = (int) block; - _kernel_swi(Wimp_GetCaretPosition, ®s, ®s); - if (block[0] == (int) this->hidden->window_handle) { - regs.r[0] = -1; - _kernel_swi(Wimp_SetCaretPosition, ®s, ®s); - } else { - regs.r[0] = this->hidden->window_handle; - regs.r[1] = -1; - regs.r[2] = -1; - regs.r[3] = -1; - _kernel_swi(Wimp_SetCaretPosition, ®s, ®s); - } - regs.r[0] = block[0]; - regs.r[1] = block[1]; - regs.r[2] = block[2]; - regs.r[3] = block[3]; - regs.r[4] = block[4]; - regs.r[5] = block[5]; - _kernel_swi(Wimp_SetCaretPosition, ®s, ®s); - } else { - regs.r[0] = this->hidden->window_handle; - regs.r[1] = 0x4b534154; /* "TASK" */ - regs.r[2] = 3; /* Redraw title */ - _kernel_swi(Wimp_ForceRedraw, ®s, ®s); - } -} - -void -WIMP_RefreshDesktop(_THIS) -{ - int width = this->hidden->screen_width << this->hidden->xeig; - int height = this->hidden->screen_height << this->hidden->yeig; - _kernel_swi_regs regs; - regs.r[0] = -1; /* Whole screen */ - regs.r[1] = 0; - regs.r[2] = 0; - regs.r[3] = width; - regs.r[4] = height; - _kernel_swi(Wimp_ForceRedraw, ®s, ®s); -} - -/* Toggle to window from full screen */ -int -WIMP_ToggleFromFullScreen(_THIS) -{ - int width = this->screen->w; - int height = this->screen->h; - int bpp = this->screen->format->BitsPerPixel; - char *buffer = NULL; - char *old_bank[2]; - char *old_alloc_bank; - - /* Ensure flags are OK */ - this->screen->flags &= ~(SDL_DOUBLEBUF | SDL_HWSURFACE); - - if (this->hidden->bank[0] == this->hidden->alloc_bank - || riscos_backbuffer == 0) { - /* Need to create a sprite for the screen and copy the data to it */ - char *data; - buffer = WIMP_CreateBuffer(width, height, bpp); - data = buffer + 60; /* Start of sprite data */ - if (bpp == 8) - data += 2048; /* 8bpp sprite have palette first */ - - if (buffer == NULL) - return 0; - SDL_memcpy(data, this->hidden->bank[0], - width * height * this->screen->format->BytesPerPixel); - } - /* else We've switch to full screen before so we already have a sprite */ - - old_bank[0] = this->hidden->bank[0]; - old_bank[1] = this->hidden->bank[1]; - old_alloc_bank = this->hidden->alloc_bank; - - if (buffer != NULL) - this->hidden->alloc_bank = buffer; - - this->hidden->bank[1] = this->hidden->alloc_bank; - this->hidden->bank[0] = this->hidden->bank[1] + 60; /* Start of sprite data */ - if (bpp == 8) - this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ - - this->hidden->current_bank = 0; - this->screen->pixels = this->hidden->bank[0]; - - RISCOS_RestoreWimpMode(); - WIMP_ReadModeInfo(this); - if (WIMP_SetupWindow(this, this->screen)) { - WIMP_SetDeviceMode(this); - WIMP_SetupPlotInfo(this); - - if (riscos_backbuffer == 0) - riscos_backbuffer = 1; - - if (buffer && old_alloc_bank) - SDL_free(old_alloc_bank); - - return 1; - } else { - /* Drop back to full screen mode on failure */ - this->hidden->bank[0] = old_bank[0]; - this->hidden->bank[1] = old_bank[1]; - this->hidden->alloc_bank = old_alloc_bank; - if (buffer) - SDL_free(buffer); - - RISCOS_StoreWimpMode(); - FULLSCREEN_SetMode(width, height, bpp); - } - - return 0; -} - -/* vi: set ts=4 sw=4 expandtab: */ From 4bdd736397161a61804320774895ad7a91543dfa Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 00:19:46 -0800 Subject: [PATCH 22/44] Added a list of platforms, for my own sanity. :) --- README.Platforms | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 README.Platforms diff --git a/README.Platforms b/README.Platforms new file mode 100644 index 000000000..6bf4de12b --- /dev/null +++ b/README.Platforms @@ -0,0 +1,34 @@ + +This is a list of the platforms SDL supports, and who maintains them. + +Officially supported platforms +============================== +(code compiles, and thoroughly tested for release) +============================== +Windows XP +Windows Vista +Windows 7 +Mac OS X 10.4+ +Linux 2.6+ +iOS 3.2+ +Android 1.6+ + +Unofficially supported platforms +================================ +(code compiles, but not thoroughly tested) +================================ +Windows CE +FreeBSD +NetBSD +OpenBSD +Solaris + +Platforms supported by volunteers +================================= + +Platforms that need maintainers +=============================== +Nintendo DS +Pandora +QNX +Haiku From b3eae36a254b37055f339fea8848317b6e41fc7f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 00:34:12 -0800 Subject: [PATCH 23/44] Colin Leroy 2011-01-26 04:24:20 PST the pthread implementation of SDL_SemWaitTimeout() uses busy waiting, while pthread's sem_timedwait() does work. Attached are patches that make use of it --- src/thread/pthread/SDL_syssem.c | 39 +++++++++++++++++++++++++-------- test/testsem.c | 26 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index 0e0feaf40..7328eafb8 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -21,6 +21,7 @@ */ #include "SDL_config.h" +#include #include #include @@ -102,6 +103,8 @@ int SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { int retval; + struct timeval now; + struct timespec ts_timeout; if (!sem) { SDL_SetError("Passed a NULL semaphore"); @@ -116,16 +119,34 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) return SDL_SemWait(sem); } - /* Ack! We have to busy wait... */ - /* FIXME: Use sem_timedwait()? */ - timeout += SDL_GetTicks(); + /* Setup the timeout. sem_timedwait doesn't wait for + * a lapse of time, but until we reach a certain time. + * This time is now plus the timeout. + */ + gettimeofday(&now, NULL); + + /* Add our timeout to current time */ + now.tv_usec += (timeout % 1000) * 1000; + now.tv_sec += timeout / 1000; + + /* Wrap the second if needed */ + if ( now.tv_usec >= 1000000 ) { + now.tv_usec -= 1000000; + now.tv_sec ++; + } + + /* Convert to timespec */ + ts_timeout.tv_sec = now.tv_sec; + ts_timeout.tv_nsec = now.tv_usec * 1000; + + /* Wait. */ do { - retval = SDL_SemTryWait(sem); - if (retval == 0) { - break; - } - SDL_Delay(1); - } while (SDL_GetTicks() < timeout); + retval = sem_timedwait(&sem->sem, &ts_timeout); + } while (retval < 0 && errno == EINTR); + + if (retval < 0) { + SDL_SetError("sem_timedwait() failed"); + } return retval; } diff --git a/test/testsem.c b/test/testsem.c index 6d9622867..c4787e9b8 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -39,6 +39,29 @@ killed(int sig) alive = 0; } +static void +TestWaitTimeout(void) +{ + Uint32 start_ticks; + Uint32 end_ticks; + Uint32 duration; + + sem = SDL_CreateSemaphore(0); + printf("Waiting 2 seconds on semaphore\n"); + + start_ticks = SDL_GetTicks(); + SDL_SemWaitTimeout(sem, 2000); + end_ticks = SDL_GetTicks(); + + duration = end_ticks - start_ticks; + + /* Accept a little offset in the effective wait */ + if (duration > 1900 && duration < 2050) + printf("Wait done.\n"); + else + fprintf(stderr, "Wait took %d milliseconds\n", duration); +} + int main(int argc, char **argv) { @@ -81,6 +104,9 @@ main(int argc, char **argv) printf("Finished waiting for threads\n"); SDL_DestroySemaphore(sem); + + TestWaitTimeout(); + SDL_Quit(); return (0); } From 0ffe05f55fcfc99cc0947a13af97c2442d0173b8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 07:05:13 -0800 Subject: [PATCH 24/44] Only document the public API, not the whole source tree. --- include/doxyfile | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/include/doxyfile b/include/doxyfile index 5a8118c42..103475527 100644 --- a/include/doxyfile +++ b/include/doxyfile @@ -124,10 +124,7 @@ FULL_PATH_NAMES = YES # If left blank the directory from which doxygen is run is used as the # path to strip. -STRIP_FROM_PATH = ../ \ - C:/source/svn.libsdl.org/trunk/ \ - C:\source\svn.libsdl.org\trunk\ \ - ..\ +STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of # the path mentioned in the documentation of a class, which tells @@ -572,7 +569,7 @@ WARN_LOGFILE = ./doxygen_warn.txt # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = .. +INPUT = . # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is @@ -652,10 +649,7 @@ EXCLUDE_SYMLINKS = NO # against the file with absolute path, so to exclude all test directories # for example use the pattern */test/* -EXCLUDE_PATTERNS = */.svn/* \ - */bin/* \ - */lib/* \ - */obj/* +EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the @@ -669,9 +663,7 @@ EXCLUDE_SYMBOLS = # directories that contain example code fragments that are included (see # the \include command). -EXAMPLE_PATH = ../test \ - ../Xcode \ - ../Xcode-iPhoneOS +EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp From a83b9bdf4b975b219157dc0471eb8ad9b6556443 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 08:40:06 -0800 Subject: [PATCH 25/44] Fixed bug #1109 Ozkan Sezer 2011-01-26 12:33:42 PST I got warnings from SDL_windowskeyboard.c when I compiled for win64. --- src/video/windows/SDL_windowskeyboard.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index d82696520..af43c9e53 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -534,7 +534,7 @@ IME_GetId(SDL_VideoData *videodata, UINT uIndex) return dwRet[uIndex]; hklprev = hkl; - dwLang = ((DWORD)hkl & 0xffff); + dwLang = ((DWORD_PTR)hkl & 0xffff); if (videodata->ime_uiless && LANG() == LANG_CHT) { dwRet[0] = IMEID_CHT_VER_VISTA; dwRet[1] = 0; @@ -781,7 +781,7 @@ IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata) UINT cchars = 0; for (; i < videodata->ime_candcount; ++i) { - UINT len = SDL_wcslen((LPWSTR)((DWORD)cand_list + cand_list->dwOffset[i])) + 1; + UINT len = SDL_wcslen((LPWSTR)((DWORD_PTR)cand_list + cand_list->dwOffset[i])) + 1; if (len + cchars > maxcandchar) { if (i > cand_list->dwSelection) break; @@ -801,7 +801,7 @@ IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata) } SDL_memset(&videodata->ime_candidates, 0, sizeof(videodata->ime_candidates)); for (i = page_start, j = 0; (DWORD)i < cand_list->dwCount && j < (int)videodata->ime_candpgsize; i++, j++) { - LPCWSTR candidate = (LPCWSTR)((DWORD)cand_list + cand_list->dwOffset[i]); + LPCWSTR candidate = (LPCWSTR)((DWORD_PTR)cand_list + cand_list->dwOffset[i]); IME_AddCandidate(videodata, j, candidate); } if (PRIMLANG() == LANG_KOREAN || (PRIMLANG() == LANG_CHT && !IME_GetId(videodata, 0))) From 96fd668ed6b7af8e758af27e8c381b07443ccee2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 10:07:14 -0800 Subject: [PATCH 26/44] Scott Smith volunteered to maintain the Pandora port. --- README.Platforms | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.Platforms b/README.Platforms index 6bf4de12b..586133f2d 100644 --- a/README.Platforms +++ b/README.Platforms @@ -25,10 +25,10 @@ Solaris Platforms supported by volunteers ================================= +Pandora - maintained by Scott Smith Platforms that need maintainers =============================== Nintendo DS -Pandora QNX Haiku From 98d356be1b3a7a1d24f27f0f008b4b99bff215fc Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 10:40:17 -0800 Subject: [PATCH 27/44] Improved condition variable documentation --- include/SDL_mutex.h | 26 ++++++++++++++++++++++++++ src/thread/generic/SDL_syscond.c | 21 +++++++++++---------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/include/SDL_mutex.h b/include/SDL_mutex.h index e066f944b..c117bdbcc 100644 --- a/include/SDL_mutex.h +++ b/include/SDL_mutex.h @@ -164,6 +164,31 @@ typedef struct SDL_cond SDL_cond; /** * Create a condition variable. + * + * Typical use of condition variables: + * + * 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); + * + * There is some discussion whether to signal the condition variable + * with the mutex locked or not. There is some potential performance + * benefit to unlocking first on some platforms, but there are some + * potential race conditions depending on how your code is structured. + * + * In general it's safer to signal the condition variable while the + * mutex is locked. */ extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void); @@ -181,6 +206,7 @@ extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond); /** * Restart all threads that are waiting on the condition variable. + * * \return 0 or -1 on error. */ extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond); diff --git a/src/thread/generic/SDL_syscond.c b/src/thread/generic/SDL_syscond.c index d2db76949..97383bef3 100644 --- a/src/thread/generic/SDL_syscond.c +++ b/src/thread/generic/SDL_syscond.c @@ -145,18 +145,19 @@ SDL_CondBroadcast(SDL_cond * cond) Typical use: Thread A: - SDL_LockMutex(lock); - while ( ! condition ) { - SDL_CondWait(cond); - } - SDL_UnlockMutex(lock); + SDL_LockMutex(lock); + while ( ! condition ) { + SDL_CondWait(cond, lock); + } + SDL_UnlockMutex(lock); Thread B: - SDL_LockMutex(lock); - ... - condition = true; - ... - SDL_UnlockMutex(lock); + SDL_LockMutex(lock); + ... + condition = true; + ... + SDL_CondSignal(cond); + SDL_UnlockMutex(lock); */ int SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) From 9b5a15bc30d88992b9ac703fc715124315f1b18b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 14:45:06 -0800 Subject: [PATCH 28/44] Improved timer implementation The new timer model is formalized as using a separate thread to handle timer callbacks. This was the case on almost every platform before, but it's now a requirement, and simplifies the implementation and makes it perform consistently across platforms. Goals: * Minimize timer thread blocking * Dispatch timers as accurately as possible * SDL_AddTimer() and SDL_RemoveTimer() are completely threadsafe * SDL_RemoveTimer() doesn't crash with a timer that's expired or removed --- include/SDL_compat.h | 7 + include/SDL_timer.h | 86 +---- src/SDL_compat.c | 25 ++ src/events/SDL_events.c | 6 - src/timer/SDL_systimer.h | 42 --- src/timer/SDL_timer.c | 539 +++++++++++++++++-------------- src/timer/SDL_timer_c.h | 14 - src/timer/beos/SDL_systimer.c | 53 +-- src/timer/dummy/SDL_systimer.c | 54 +--- src/timer/nds/SDL_systimer.c | 79 +---- src/timer/unix/SDL_systimer.c | 122 +------ src/timer/wince/SDL_systimer.c | 129 +------- src/timer/windows/SDL_systimer.c | 56 ---- 13 files changed, 379 insertions(+), 833 deletions(-) delete mode 100644 src/timer/SDL_systimer.h diff --git a/include/SDL_compat.h b/include/SDL_compat.h index 92f622be8..1e2a53917 100644 --- a/include/SDL_compat.h +++ b/include/SDL_compat.h @@ -344,6 +344,13 @@ typedef SDL_Window* SDL_WindowID; #define SDL_RenderFill(X) (X) ? SDL_RenderFillRect(X) : SDL_RenderClear() #define SDL_KillThread(X) +/* The timeslice and timer resolution are no longer relevant */ +#define SDL_TIMESLICE 10 +#define TIMER_RESOLUTION 10 + +typedef Uint32 (SDLCALL * SDL_OldTimerCallback) (Uint32 interval); +extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_OldTimerCallback callback); + extern DECLSPEC int SDLCALL SDL_putenv(const char *variable); /*@}*//*Compatibility*/ diff --git a/include/SDL_timer.h b/include/SDL_timer.h index 91160f6f9..2d38a0689 100644 --- a/include/SDL_timer.h +++ b/include/SDL_timer.h @@ -41,104 +41,50 @@ extern "C" { #endif /** - * This is the OS scheduler timeslice, in milliseconds. - */ -#define SDL_TIMESLICE 10 - -/** - * This is the maximum resolution of the SDL timer on all platforms. - */ -#define TIMER_RESOLUTION 10 /**< Experimentally determined */ - -/** - * Get the number of milliseconds since the SDL library initialization. + * \brief Get the number of milliseconds since the SDL library initialization. * - * Note that this value wraps if the program runs for more than ~49 days. + * \note This value wraps if the program runs for more than ~49 days. */ extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void); /** - * Wait a specified number of milliseconds before returning. + * \brief Wait a specified number of milliseconds before returning. */ extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms); /** * Function prototype for the timer callback function. - */ -typedef Uint32(SDLCALL * SDL_TimerCallback) (Uint32 interval); - -/** - * Set a callback to run after the specified number of milliseconds has - * elapsed. The callback function is passed the current timer interval - * and returns the next timer interval. If the returned value is the - * same as the one passed in, the periodic alarm continues, otherwise a - * new alarm is scheduled. If the callback returns 0, the periodic alarm - * is cancelled. - * - * To cancel a currently running timer, call - * \code SDL_SetTimer(0, NULL); \endcode - * - * The timer callback function may run in a different thread than your - * main code, and so shouldn't call any functions from within itself. - * - * The maximum resolution of this timer is 10 ms, which means that if - * you request a 16 ms timer, your callback will run approximately 20 ms - * later on an unloaded system. If you wanted to set a flag signaling - * a frame update at 30 frames per second (every 33 ms), you might set a - * timer for 30 ms: - * \code - * SDL_SetTimer((33/10)*10, flag_update); - * \endcode - * - * If you use this function, you need to pass ::SDL_INIT_TIMER to SDL_Init(). - * - * Under UNIX, you should not use raise or use SIGALRM and this function - * in the same program, as it is implemented using setitimer(). You also - * should not use this function in multi-threaded applications as signals - * to multi-threaded apps have undefined behavior in some implementations. - * - * \return 0 if successful, or -1 if there was an error. - */ -extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, - SDL_TimerCallback callback); - -/** - * \name Peter timers - * New timer API, supports multiple timers - * Written by Stephane Peter - */ -/*@{*/ - -/** - * Function prototype for the new timer callback function. * * The callback function is passed the current timer interval and returns * the next timer interval. If the returned value is the same as the one * passed in, the periodic alarm continues, otherwise a new alarm is * scheduled. If the callback returns 0, the periodic alarm is cancelled. */ -typedef Uint32(SDLCALL * SDL_NewTimerCallback) (Uint32 interval, void *param); +typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval, void *param); /** - * Definition of the timer ID type. + * Definition of the timer ID type. */ -typedef struct _SDL_TimerID *SDL_TimerID; +typedef int SDL_TimerID; /** - * Add a new timer to the pool of timers already running. - * \return A timer ID, or NULL when an error occurs. + * \brief Add a new timer to the pool of timers already running. + * + * \return A timer ID, or NULL when an error occurs. */ extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, - SDL_NewTimerCallback - callback, void *param); + SDL_TimerCallback callback, + void *param); /** - * Remove one of the multiple timers knowing its ID. - * \return A boolean value indicating success or failure. + * \brief Remove a timer knowing its ID. + * + * \return A boolean value indicating success or failure. + * + * \warning It is not safe to remove a timer multiple times. */ extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t); -/*@}*//*Peter timers*/ /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/SDL_compat.c b/src/SDL_compat.c index c35dfbb66..fedd84520 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -1760,6 +1760,31 @@ SDL_EnableUNICODE(int enable) return previous; } +static Uint32 +SDL_SetTimerCallback(Uint32 interval, void* param) +{ + return ((SDL_OldTimerCallback)param)(interval); +} + +int +SDL_SetTimer(Uint32 interval, SDL_OldTimerCallback callback) +{ + static SDL_TimerID compat_timer; + + if (compat_timer) { + SDL_RemoveTimer(compat_timer); + compat_timer = 0; + } + + if (interval && callback) { + compat_timer = SDL_AddTimer(interval, SDL_SetTimerCallback, callback); + if (!compat_timer) { + return -1; + } + } + return 0; +} + int SDL_putenv(const char *_var) { diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 06f533cd2..b3c2ad818 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -123,9 +123,6 @@ SDL_GobbleEvents(void *unused) /* Give up the CPU for the rest of our timeslice */ SDL_EventLock.safe = 1; - if (SDL_timer_running) { - SDL_ThreadedTimerCheck(); - } SDL_Delay(1); /* Check for event locking. @@ -140,7 +137,6 @@ SDL_GobbleEvents(void *unused) SDL_EventLock.safe = 0; SDL_mutexV(SDL_EventLock.lock); } - SDL_SetTimerThreaded(0); event_thread = 0; return (0); } @@ -168,8 +164,6 @@ SDL_StartEventThread(Uint32 flags) } SDL_EventLock.safe = 0; - /* The event thread will handle timers too */ - SDL_SetTimerThreaded(2); #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) #undef SDL_CreateThread SDL_EventThread = diff --git a/src/timer/SDL_systimer.h b/src/timer/SDL_systimer.h deleted file mode 100644 index d0cfd25db..000000000 --- a/src/timer/SDL_systimer.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* The system dependent timer handling functions */ - -#include "SDL_timer.h" -#include "SDL_timer_c.h" - - -/* Initialize the system dependent timer subsystem */ -extern int SDL_SYS_TimerInit(void); - -/* Quit the system dependent timer subsystem */ -extern void SDL_SYS_TimerQuit(void); - -/* Start a timer set up by SDL_SetTimer() */ -extern int SDL_SYS_StartTimer(void); - -/* Stop a previously started timer */ -extern void SDL_SYS_StopTimer(void); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 684a20ff7..593add64d 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -23,289 +23,360 @@ #include "SDL_timer.h" #include "SDL_timer_c.h" -#include "SDL_mutex.h" -#include "SDL_systimer.h" +#include "SDL_atomic.h" +#include "SDL_thread.h" /* #define DEBUG_TIMERS */ -int SDL_timer_started = 0; -int SDL_timer_running = 0; - -/* Data to handle a single periodic alarm */ -Uint32 SDL_alarm_interval = 0; -SDL_TimerCallback SDL_alarm_callback; - -/* Data used for a thread-based timer */ -static int SDL_timer_threaded = 0; - -struct _SDL_TimerID +typedef struct _SDL_Timer { - Uint32 interval; - SDL_NewTimerCallback cb; + int timerID; + SDL_TimerCallback callback; void *param; - Uint32 last_alarm; - struct _SDL_TimerID *next; -}; + Uint32 interval; + Uint32 scheduled; + volatile SDL_bool canceled; + struct _SDL_Timer *next; +} SDL_Timer; -static SDL_TimerID SDL_timers = NULL; -static SDL_mutex *SDL_timer_mutex; -static volatile SDL_bool list_changed = SDL_FALSE; - -/* Set whether or not the timer should use a thread. - This should not be called while the timer subsystem is running. -*/ -int -SDL_SetTimerThreaded(int value) +typedef struct _SDL_TimerMap { - int retval; + int timerID; + SDL_Timer *timer; + struct _SDL_TimerMap *next; +} SDL_TimerMap; - if (SDL_timer_started) { - SDL_SetError("Timer already initialized"); - retval = -1; - } else { - retval = 0; - SDL_timer_threaded = value; +/* A reasonable guess */ +#define CACHELINE_SIZE 128 + +/* The timers are kept in a sorted list */ +typedef struct { + /* Data used by the main thread */ + SDL_Thread *thread; + SDL_atomic_t nextID; + SDL_TimerMap *timermap; + SDL_mutex *timermap_lock; + + /* Padding to separate cache lines between threads */ + char pad[CACHELINE_SIZE]; + + /* Data used to communicate with the timer thread */ + SDL_SpinLock lock; + SDL_sem *sem; + SDL_Timer * volatile pending; + SDL_Timer * volatile freelist; + volatile SDL_bool active; + + /* List of timers - this is only touched by the timer thread */ + SDL_Timer *timers; +} SDL_TimerData; + +static SDL_TimerData SDL_timer_data; + + +/* The idea here is that any thread might add a timer, but a single + * thread manages the active timer queue, sorted by scheduling time. + * + * Timers are removed by simply setting a canceled flag + */ + +static void +SDL_AddTimerInternal(SDL_TimerData *data, SDL_Timer *timer) +{ + SDL_Timer *prev, *curr; + + prev = NULL; + for (curr = data->timers; curr; prev = curr, curr = curr->next) { + if ((Sint32)(timer->scheduled-curr->scheduled) < 0) { + break; + } } - return retval; + + /* Insert the timer here! */ + if (prev) { + prev->next = timer; + } else { + data->timers = timer; + } + timer->next = curr; +} + +static int +SDL_TimerThread(void *_data) +{ + SDL_TimerData *data = (SDL_TimerData *)_data; + SDL_Timer *pending; + SDL_Timer *current; + SDL_Timer *freelist_head = NULL; + SDL_Timer *freelist_tail = NULL; + Uint32 tick, now, interval, delay; + + /* Threaded timer loop: + * 1. Queue timers added by other threads + * 2. Handle any timers that should dispatch this cycle + * 3. Wait until next dispatch time or new timer arrives + */ + for ( ; ; ) { + /* Pending and freelist maintenance */ + SDL_AtomicLock(&data->lock); + { + /* Get any timers ready to be queued */ + pending = data->pending; + data->pending = NULL; + + /* Make any unused timer structures available */ + if (freelist_head) { + freelist_tail->next = data->freelist; + data->freelist = freelist_head; + } + } + SDL_AtomicUnlock(&data->lock); + + /* Sort the pending timers into our list */ + while (pending) { + current = pending; + pending = pending->next; + SDL_AddTimerInternal(data, current); + } + freelist_head = NULL; + freelist_tail = NULL; + + /* Check to see if we're still running, after maintenance */ + if (!data->active) { + break; + } + + /* Initial delay if there are no timers */ + delay = SDL_MUTEX_MAXWAIT; + + tick = SDL_GetTicks(); + + /* Process all the pending timers for this tick */ + while (data->timers) { + current = data->timers; + + if ((Sint32)(tick-current->scheduled) < 0) { + /* Scheduled for the future, wait a bit */ + delay = (current->scheduled - tick); + break; + } + + /* We're going to do something with this timer */ + data->timers = current->next; + + if (current->canceled) { + interval = 0; + } else { + interval = current->callback(current->interval, current->param); + } + + if (interval > 0) { + /* Reschedule this timer */ + current->scheduled = tick + interval; + SDL_AddTimerInternal(data, current); + } else { + if (!freelist_head) { + freelist_head = current; + } + if (freelist_tail) { + freelist_tail->next = current; + } + freelist_tail = current; + + current->canceled = SDL_TRUE; + } + } + + /* Adjust the delay based on processing time */ + now = SDL_GetTicks(); + interval = (now - tick); + if (interval > delay) { + delay = 0; + } else { + delay -= interval; + } + + /* Note that each time a timer is added, this will return + immediately, but we process the timers added all at once. + That's okay, it just means we run through the loop a few + extra times. + */ + SDL_SemWaitTimeout(data->sem, delay); + } + return 0; } int SDL_TimerInit(void) { - int retval; + SDL_TimerData *data = &SDL_timer_data; - retval = 0; - if (SDL_timer_started) { - SDL_TimerQuit(); + if (!data->active) { + data->timermap_lock = SDL_CreateMutex(); + if (!data->timermap_lock) { + return -1; + } + + data->sem = SDL_CreateSemaphore(0); + if (!data->sem) { + SDL_DestroyMutex(data->timermap_lock); + return -1; + } + + data->active = SDL_TRUE; + data->thread = SDL_CreateThread(SDL_TimerThread, data); + if (!data->thread) { + SDL_TimerQuit(); + return -1; + } + + SDL_AtomicSet(&data->nextID, 1); } - if (!SDL_timer_threaded) { - retval = SDL_SYS_TimerInit(); - } - if (SDL_timer_threaded) { - SDL_timer_mutex = SDL_CreateMutex(); - } - if (retval == 0) { - SDL_timer_started = 1; - } - return (retval); + return 0; } void SDL_TimerQuit(void) { - SDL_SetTimer(0, NULL); - if (SDL_timer_threaded < 2) { - SDL_SYS_TimerQuit(); - } - if (SDL_timer_threaded) { - SDL_DestroyMutex(SDL_timer_mutex); - SDL_timer_mutex = NULL; - } - SDL_timer_started = 0; - SDL_timer_threaded = 0; -} + SDL_TimerData *data = &SDL_timer_data; + SDL_Timer *timer; + SDL_TimerMap *entry; -void -SDL_ThreadedTimerCheck(void) -{ - Uint32 now, ms; - SDL_TimerID t, prev, next; - SDL_bool removed; + if (data->active) { + data->active = SDL_FALSE; - SDL_mutexP(SDL_timer_mutex); - - now = SDL_GetTicks(); - do { - list_changed = SDL_FALSE; - for (prev = NULL, t = SDL_timers; t; t = next) { - removed = SDL_FALSE; - ms = t->interval - SDL_TIMESLICE; - next = t->next; - if ((int) (now - t->last_alarm) > (int) ms) { - struct _SDL_TimerID timer; - - if ((now - t->last_alarm) < t->interval) { - t->last_alarm += t->interval; - } else { - t->last_alarm = now; - } -#ifdef DEBUG_TIMERS - printf("Executing timer %p (thread = %lu)\n", - t, SDL_ThreadID()); -#endif - timer = *t; - SDL_mutexV(SDL_timer_mutex); - ms = timer.cb(timer.interval, timer.param); - SDL_mutexP(SDL_timer_mutex); - if (list_changed) { - next = t->next; - for (prev = SDL_timers; prev; prev = prev->next) { - if (prev->next == t) - break; - } - } - if (ms != t->interval) { - if (ms) { - t->interval = ROUND_RESOLUTION(ms); - } else { - /* Remove timer from the list */ -#ifdef DEBUG_TIMERS - printf("SDL: Removing timer %p\n", t); -#endif - if (prev) { - prev->next = next; - } else { - SDL_timers = next; - } - SDL_free(t); - --SDL_timer_running; - removed = SDL_TRUE; - } - } - if (list_changed) { - /* Abort, list of timers modified */ - break; - } - } - /* Don't update prev if the timer has disappeared */ - if (!removed) { - prev = t; - } + /* Shutdown the timer thread */ + if (data->thread) { + SDL_SemPost(data->sem); + SDL_WaitThread(data->thread, NULL); + data->thread = NULL; } - } while (list_changed); - SDL_mutexV(SDL_timer_mutex); -} + SDL_DestroySemaphore(data->sem); + data->sem = NULL; -static SDL_TimerID -SDL_AddTimerInternal(Uint32 interval, SDL_NewTimerCallback callback, - void *param) -{ - SDL_TimerID t; - t = (SDL_TimerID) SDL_malloc(sizeof(struct _SDL_TimerID)); - if (t) { - t->interval = ROUND_RESOLUTION(interval); - t->cb = callback; - t->param = param; - t->last_alarm = SDL_GetTicks(); - t->next = SDL_timers; - SDL_timers = t; - ++SDL_timer_running; - list_changed = SDL_TRUE; + /* Clean up the timer entries */ + while (data->timers) { + timer = data->timers; + data->timers = timer->next; + SDL_free(timer); + } + while (data->freelist) { + timer = data->freelist; + data->freelist = timer->next; + SDL_free(timer); + } + while (data->timermap) { + entry = data->timermap; + data->timermap = entry->next; + SDL_free(entry); + } + + SDL_DestroyMutex(data->timermap_lock); + data->timermap_lock = NULL; } -#ifdef DEBUG_TIMERS - printf("SDL_AddTimer(%d) = %08x num_timers = %d\n", interval, (Uint32) t, - SDL_timer_running); -#endif - return t; } SDL_TimerID -SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param) +SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param) { - SDL_TimerID t; - if (!SDL_timer_mutex) { - if (SDL_timer_started) { - SDL_SetError("This platform doesn't support multiple timers"); - } else { - SDL_SetError("You must call SDL_Init(SDL_INIT_TIMER) first"); + SDL_TimerData *data = &SDL_timer_data; + SDL_Timer *timer; + SDL_TimerMap *entry; + + if (!data->active) { + int status = 0; + + SDL_AtomicLock(&data->lock); + if (!data->active) { + status = SDL_TimerInit(); + } + SDL_AtomicUnlock(&data->lock); + + if (status < 0) { + return 0; } - return NULL; } - if (!SDL_timer_threaded) { - SDL_SetError("Multiple timers require threaded events!"); - return NULL; + + SDL_AtomicLock(&data->lock); + timer = data->freelist; + if (timer) { + data->freelist = timer->next; } - SDL_mutexP(SDL_timer_mutex); - t = SDL_AddTimerInternal(interval, callback, param); - SDL_mutexV(SDL_timer_mutex); - return t; + SDL_AtomicUnlock(&data->lock); + + if (timer) { + SDL_RemoveTimer(timer->timerID); + } else { + timer = (SDL_Timer *)SDL_malloc(sizeof(*timer)); + if (!timer) { + SDL_OutOfMemory(); + return 0; + } + } + timer->timerID = SDL_AtomicIncRef(&data->nextID); + timer->callback = callback; + timer->param = param; + timer->interval = interval; + timer->scheduled = SDL_GetTicks() + interval; + timer->canceled = SDL_FALSE; + + entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry)); + if (!entry) { + SDL_free(timer); + SDL_OutOfMemory(); + return 0; + } + entry->timer = timer; + entry->timerID = timer->timerID; + + SDL_mutexP(data->timermap_lock); + entry->next = data->timermap; + data->timermap = entry; + SDL_mutexV(data->timermap_lock); + + /* Add the timer to the pending list for the timer thread */ + SDL_AtomicLock(&data->lock); + timer->next = data->pending; + data->pending = timer; + SDL_AtomicUnlock(&data->lock); + + /* Wake up the timer thread if necessary */ + SDL_SemPost(data->sem); + + return entry->timerID; } SDL_bool SDL_RemoveTimer(SDL_TimerID id) { - SDL_TimerID t, prev = NULL; - SDL_bool removed; + SDL_TimerData *data = &SDL_timer_data; + SDL_TimerMap *prev, *entry; + SDL_bool canceled = SDL_FALSE; - removed = SDL_FALSE; - SDL_mutexP(SDL_timer_mutex); - /* Look for id in the linked list of timers */ - for (t = SDL_timers; t; prev = t, t = t->next) { - if (t == id) { + /* Find the timer */ + SDL_mutexP(data->timermap_lock); + prev = NULL; + for (entry = data->timermap; entry; prev = entry, entry = entry->next) { + if (entry->timerID == id) { if (prev) { - prev->next = t->next; + prev->next = entry->next; } else { - SDL_timers = t->next; + data->timermap = entry->next; } - SDL_free(t); - --SDL_timer_running; - removed = SDL_TRUE; - list_changed = SDL_TRUE; break; } } -#ifdef DEBUG_TIMERS - printf("SDL_RemoveTimer(%08x) = %d num_timers = %d thread = %lu\n", - (Uint32) id, removed, SDL_timer_running, SDL_ThreadID()); -#endif - SDL_mutexV(SDL_timer_mutex); - return removed; -} + SDL_mutexV(data->timermap_lock); -/* Old style callback functions are wrapped through this */ -static Uint32 SDLCALL -callback_wrapper(Uint32 ms, void *param) -{ - SDL_TimerCallback func = (SDL_TimerCallback) param; - return (*func) (ms); -} - -int -SDL_SetTimer(Uint32 ms, SDL_TimerCallback callback) -{ - int retval; - -#ifdef DEBUG_TIMERS - printf("SDL_SetTimer(%d)\n", ms); -#endif - retval = 0; - - if (SDL_timer_threaded) { - SDL_mutexP(SDL_timer_mutex); - } - if (SDL_timer_running) { /* Stop any currently running timer */ - if (SDL_timer_threaded) { - while (SDL_timers) { - SDL_TimerID freeme = SDL_timers; - SDL_timers = SDL_timers->next; - SDL_free(freeme); - } - SDL_timer_running = 0; - list_changed = SDL_TRUE; - } else { - SDL_SYS_StopTimer(); - SDL_timer_running = 0; + if (entry) { + if (!entry->timer->canceled) { + entry->timer->canceled = SDL_TRUE; + canceled = SDL_TRUE; } + SDL_free(entry); } - if (ms) { - if (SDL_timer_threaded) { - if (SDL_AddTimerInternal - (ms, callback_wrapper, (void *) callback) == NULL) { - retval = -1; - } - } else { - SDL_timer_running = 1; - SDL_alarm_interval = ms; - SDL_alarm_callback = callback; - retval = SDL_SYS_StartTimer(); - } - } - if (SDL_timer_threaded) { - SDL_mutexV(SDL_timer_mutex); - } - - return retval; + return canceled; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/SDL_timer_c.h b/src/timer/SDL_timer_c.h index 3e7d3ebd7..c99ccef72 100644 --- a/src/timer/SDL_timer_c.h +++ b/src/timer/SDL_timer_c.h @@ -27,21 +27,7 @@ #define ROUND_RESOLUTION(X) \ (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION) -extern int SDL_timer_started; -extern int SDL_timer_running; - -/* Data to handle a single periodic alarm */ -extern Uint32 SDL_alarm_interval; -extern SDL_TimerCallback SDL_alarm_callback; - -/* Set whether or not the timer should use a thread. - This should be called while the timer subsystem is running. -*/ -extern int SDL_SetTimerThreaded(int value); - extern int SDL_TimerInit(void); extern void SDL_TimerQuit(void); -/* This function is called from the SDL event thread if it is available */ -extern void SDL_ThreadedTimerCheck(void); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/beos/SDL_systimer.c b/src/timer/beos/SDL_systimer.c index e31bdebea..cec78deb0 100644 --- a/src/timer/beos/SDL_systimer.c +++ b/src/timer/beos/SDL_systimer.c @@ -25,9 +25,7 @@ #include -#include "SDL_thread.h" #include "SDL_timer.h" -#include "../SDL_timer_c.h" static bigtime_t start; @@ -50,55 +48,6 @@ SDL_Delay(Uint32 ms) snooze(ms * 1000); } -/* Data to handle a single periodic alarm */ -static int timer_alive = 0; -static SDL_Thread *timer = NULL; - -static int -RunTimer(void *unused) -{ - while (timer_alive) { - if (SDL_timer_running) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(10); - } - return (0); -} - -/* This is only called if the event thread is not running */ -int -SDL_SYS_TimerInit(void) -{ - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if (timer == NULL) - return (-1); - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - timer_alive = 0; - if (timer) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } -} - -int -SDL_SYS_StartTimer(void) -{ - SDL_SetError("Internal logic error: BeOS uses threaded timer"); - return (-1); -} - -void -SDL_SYS_StopTimer(void) -{ - return; -} - #endif /* SDL_TIMER_BEOS */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/dummy/SDL_systimer.c b/src/timer/dummy/SDL_systimer.c index f13f0d566..77f69c395 100644 --- a/src/timer/dummy/SDL_systimer.c +++ b/src/timer/dummy/SDL_systimer.c @@ -24,7 +24,6 @@ #if defined(SDL_TIMER_DUMMY) || defined(SDL_TIMERS_DISABLED) #include "SDL_timer.h" -#include "../SDL_timer_c.h" void SDL_StartTicks(void) @@ -44,57 +43,6 @@ SDL_Delay(Uint32 ms) SDL_Unsupported(); } -#include "SDL_thread.h" - -/* Data to handle a single periodic alarm */ -static int timer_alive = 0; -static SDL_Thread *timer = NULL; - -static int -RunTimer(void *unused) -{ - while (timer_alive) { - if (SDL_timer_running) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(1); - } - return (0); -} - -/* This is only called if the event thread is not running */ -int -SDL_SYS_TimerInit(void) -{ - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if (timer == NULL) - return (-1); - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - timer_alive = 0; - if (timer) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } -} - -int -SDL_SYS_StartTimer(void) -{ - SDL_SetError("Internal logic error: threaded timer in use"); - return (-1); -} - -void -SDL_SYS_StopTimer(void) -{ - return; -} - #endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/nds/SDL_systimer.c b/src/timer/nds/SDL_systimer.c index 50791f887..75abf2d65 100644 --- a/src/timer/nds/SDL_systimer.c +++ b/src/timer/nds/SDL_systimer.c @@ -27,22 +27,25 @@ #include #include "SDL_timer.h" -#include "../SDL_timer_c.h" -#include "../SDL_systimer.h" -/* Data to handle a single periodic alarm */ -static int timer_alive = 0; -static Uint32 timer_ticks; + +static volatile Uint32 timer_ticks; + +static void +NDS_TimerInterrupt(void) +{ + timer_ticks++; +} void SDL_StartTicks(void) { - if (!timer_alive) { - SDL_SYS_TimerInit(); - SDL_SYS_StartTimer(); - } - timer_ticks = 0; + + TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ; + TIMER_DATA(3) = TIMER_FREQ_1024(1000); + irqSet(IRQ_TIMER3, NDS_TimerInterrupt); + irqEnable(IRQ_TIMER3); } Uint32 @@ -61,60 +64,6 @@ SDL_Delay(Uint32 ms) } } -static int -RunTimer(void *unused) -{ - while (timer_alive) { - if (SDL_timer_running) { - } - SDL_Delay(1); - } - return (0); -} - -void -NDS_TimerInterrupt(void) -{ - timer_ticks++; -} - -/* This is only called if the event thread is not running */ -int -SDL_SYS_TimerInit(void) -{ - timer_alive = 1; - timer_ticks = 0; - TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ; - TIMER_DATA(3) = TIMER_FREQ_1024(1000); - irqSet(IRQ_TIMER3, NDS_TimerInterrupt); - irqEnable(IRQ_TIMER3); - return 0; -} - -void -SDL_SYS_TimerQuit(void) -{ - if (timer_alive) { - TIMER_CR(3) = 0; - } - timer_alive = 0; - irqDisable(IRQ_TIMER3); -} - -int -SDL_SYS_StartTimer(void) -{ - TIMER_CR(3) |= TIMER_ENABLE; - return 0; -} - -void -SDL_SYS_StopTimer(void) -{ - TIMER_CR(3) &= ~TIMER_ENABLE; - return; -} - - #endif /* SDL_TIMER_NDS */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/unix/SDL_systimer.c b/src/timer/unix/SDL_systimer.c index 2a933eea2..ca7f45a8d 100644 --- a/src/timer/unix/SDL_systimer.c +++ b/src/timer/unix/SDL_systimer.c @@ -25,14 +25,10 @@ #include #include -#include #include -#include #include #include "SDL_timer.h" -#include "../SDL_systimer.h" -#include "../SDL_timer_c.h" /* The clock_gettime provides monotonous time, so we should use it if it's available. The clock_gettime function is behind ifdef @@ -43,10 +39,6 @@ #include #endif -#if SDL_THREADS_DISABLED -#define USE_ITIMER -#endif - /* The first ticks value of the application */ #ifdef HAVE_CLOCK_GETTIME static struct timespec start; @@ -131,118 +123,6 @@ SDL_Delay(Uint32 ms) } while (was_error && (errno == EINTR)); } -#ifdef USE_ITIMER - -static void -HandleAlarm(int sig) -{ - Uint32 ms; - - if (SDL_alarm_callback) { - ms = (*SDL_alarm_callback) (SDL_alarm_interval); - if (ms != SDL_alarm_interval) { - SDL_SetTimer(ms, SDL_alarm_callback); - } - } -} - -int -SDL_SYS_TimerInit(void) -{ - struct sigaction action; - - /* Set the alarm handler (Linux specific) */ - SDL_memset(&action, 0, sizeof(action)); - action.sa_handler = HandleAlarm; - action.sa_flags = SA_RESTART; - sigemptyset(&action.sa_mask); - sigaction(SIGALRM, &action, NULL); - return (0); -} - -void -SDL_SYS_TimerQuit(void) -{ - SDL_SetTimer(0, NULL); -} - -int -SDL_SYS_StartTimer(void) -{ - struct itimerval timer; - - timer.it_value.tv_sec = (SDL_alarm_interval / 1000); - timer.it_value.tv_usec = (SDL_alarm_interval % 1000) * 1000; - timer.it_interval.tv_sec = (SDL_alarm_interval / 1000); - timer.it_interval.tv_usec = (SDL_alarm_interval % 1000) * 1000; - setitimer(ITIMER_REAL, &timer, NULL); - return (0); -} - -void -SDL_SYS_StopTimer(void) -{ - struct itimerval timer; - - SDL_memset(&timer, 0, (sizeof timer)); - setitimer(ITIMER_REAL, &timer, NULL); -} - -#else /* USE_ITIMER */ - -#include "SDL_thread.h" - -/* Data to handle a single periodic alarm */ -static int timer_alive = 0; -static SDL_Thread *timer = NULL; - -static int -RunTimer(void *unused) -{ - while (timer_alive) { - if (SDL_timer_running) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(1); - } - return (0); -} - -/* This is only called if the event thread is not running */ -int -SDL_SYS_TimerInit(void) -{ - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if (timer == NULL) - return (-1); - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - timer_alive = 0; - if (timer) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } -} - -int -SDL_SYS_StartTimer(void) -{ - SDL_SetError("Internal logic error: Linux uses threaded timer"); - return (-1); -} - -void -SDL_SYS_StopTimer(void) -{ - return; -} - -#endif /* USE_ITIMER */ - #endif /* SDL_TIMER_UNIX */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/wince/SDL_systimer.c b/src/timer/wince/SDL_systimer.c index 5abbaa587..8a2ced4e3 100644 --- a/src/timer/wince/SDL_systimer.c +++ b/src/timer/wince/SDL_systimer.c @@ -24,11 +24,8 @@ #ifdef SDL_TIMER_WINCE #include "../../core/windows/SDL_windows.h" -#include -#include "SDL_thread.h" #include "SDL_timer.h" -#include "../SDL_timer_c.h" static Uint64 start_date; static Uint64 start_ticks; @@ -69,6 +66,14 @@ wce_rel_date(void) return ((Sint32) (wce_date() - start_date)); } +/* Recard start-time of application for reference */ +void +SDL_StartTicks(void) +{ + start_date = wce_date(); + start_ticks = wce_ticks(); +} + /* Return time in ms relative to when SDL was started */ Uint32 SDL_GetTicks() @@ -89,122 +94,6 @@ SDL_Delay(Uint32 ms) Sleep(ms); } -/* Recard start-time of application for reference */ -void -SDL_StartTicks(void) -{ - start_date = wce_date(); - start_ticks = wce_ticks(); -} - -static UINT WIN_timer; - -#if ( _WIN32_WCE <= 420 ) - -static HANDLE timersThread = 0; -static HANDLE timersQuitEvent = 0; - -DWORD -TimersThreadProc(void *data) -{ - while (WaitForSingleObject(timersQuitEvent, 10) == WAIT_TIMEOUT) { - SDL_ThreadedTimerCheck(); - } - return 0; -} - -int -SDL_SYS_TimerInit(void) -{ - // create a thread to process a threaded timers - // SetTimer does not suit the needs because - // TimerCallbackProc will be called only when WM_TIMER occured - - timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0); - if (!timersQuitEvent) { - SDL_SetError("Cannot create event for timers thread"); - return -1; - } - timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0); - if (!timersThread) { - SDL_SetError - ("Cannot create timers thread, check amount of RAM available"); - return -1; - } - SetThreadPriority(timersThread, THREAD_PRIORITY_HIGHEST); - - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - SetEvent(timersQuitEvent); - if (WaitForSingleObject(timersThread, 2000) == WAIT_TIMEOUT) - TerminateThread(timersThread, 0); - CloseHandle(timersThread); - CloseHandle(timersQuitEvent); - return; -} - -#else - -#pragma comment(lib, "mmtimer.lib") - -/* Data to handle a single periodic alarm */ -static UINT timerID = 0; - -static void CALLBACK -HandleAlarm(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) -{ - SDL_ThreadedTimerCheck(); -} - - -int -SDL_SYS_TimerInit(void) -{ - MMRESULT result; - - /* Set timer resolution */ - result = timeBeginPeriod(TIMER_RESOLUTION); - if (result != TIMERR_NOERROR) { - SDL_SetError("Warning: Can't set %d ms timer resolution", - TIMER_RESOLUTION); - } - /* Allow 10 ms of drift so we don't chew on CPU */ - timerID = - timeSetEvent(TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC); - if (!timerID) { - SDL_SetError("timeSetEvent() failed"); - return (-1); - } - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - if (timerID) { - timeKillEvent(timerID); - } - timeEndPeriod(TIMER_RESOLUTION); -} - -#endif - -int -SDL_SYS_StartTimer(void) -{ - SDL_SetError("Internal logic error: WinCE uses threaded timer"); - return (-1); -} - -void -SDL_SYS_StopTimer(void) -{ - return; -} - #endif /* SDL_TIMER_WINCE */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/windows/SDL_systimer.c b/src/timer/windows/SDL_systimer.c index 0ae01da10..2674e2200 100644 --- a/src/timer/windows/SDL_systimer.c +++ b/src/timer/windows/SDL_systimer.c @@ -24,10 +24,8 @@ #ifdef SDL_TIMER_WINDOWS #include "../../core/windows/SDL_windows.h" -#include #include "SDL_timer.h" -#include "../SDL_timer_c.h" #ifdef _WIN32_WCE #error This is WinCE. Please use src/timer/wince/SDL_systimer.c instead. @@ -106,60 +104,6 @@ SDL_Delay(Uint32 ms) Sleep(ms); } -/* Data to handle a single periodic alarm */ -static UINT timerID = 0; - -static void CALLBACK -HandleAlarm(UINT uID, UINT uMsg, DWORD_PTR dwUser, - DWORD_PTR dw1, DWORD_PTR dw2) -{ - SDL_ThreadedTimerCheck(); -} - - -int -SDL_SYS_TimerInit(void) -{ - MMRESULT result; - - /* Set timer resolution */ - result = timeBeginPeriod(TIMER_RESOLUTION); - if (result != TIMERR_NOERROR) { - SDL_SetError("Warning: Can't set %d ms timer resolution", - TIMER_RESOLUTION); - } - /* Allow 10 ms of drift so we don't chew on CPU */ - timerID = - timeSetEvent(TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC); - if (!timerID) { - SDL_SetError("timeSetEvent() failed"); - return (-1); - } - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - if (timerID) { - timeKillEvent(timerID); - } - timeEndPeriod(TIMER_RESOLUTION); -} - -int -SDL_SYS_StartTimer(void) -{ - SDL_SetError("Internal logic error: Win32 uses threaded timer"); - return (-1); -} - -void -SDL_SYS_StopTimer(void) -{ - return; -} - #endif /* SDL_TIMER_WINDOWS */ /* vi: set ts=4 sw=4 expandtab: */ From 8a17c426476dc814f73fec5e2e317522871147fc Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 14:54:20 -0800 Subject: [PATCH 29/44] This patch fixes the issue of configure generating broken Makefile when .cc files are used due to bad sed substitution on multiple passes: $(objects)/SDL_BeApp.lo: $(objects)/SDL_BeApp.lo: ./src/main/beos/SDL_BeApp.c $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@c $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: François Revol --- configure.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index dde39bb08..fd592de45 100644 --- a/configure.in +++ b/configure.in @@ -2712,10 +2712,10 @@ if test x$SDLMAIN_SOURCES = x; then fi OBJECTS=`echo $SOURCES` -DEPENDS=`echo $SOURCES` +DEPENDS=`echo $SOURCES | tr ' ' '\n'` for EXT in asm cc m c S; do OBJECTS=`echo "$OBJECTS" | sed 's,[[^ ]]*/\([[^ ]]*\)\.'$EXT',$(objects)/\1.lo,g'` - DEPENDS=`echo "$DEPENDS" | sed "s,\\([[^ ]]*\\)/\\([[^ ]]*\\)\\.$EXT,\\\\ + DEPENDS=`echo "$DEPENDS" | sed "s,^\\([[^ ]]*\\)/\\([[^ ]]*\\)\\.$EXT\\$,\\\\ \\$(objects)/\\2.lo: \\1/\\2.$EXT\\\\ \\$(LIBTOOL) --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@,g"` done From 16881d932ea396651ac40c820b029979c0a983f0 Mon Sep 17 00:00:00 2001 From: krogoway Date: Thu, 27 Jan 2011 15:58:30 -0600 Subject: [PATCH 30/44] When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event. Common.c now destroys the SDL_Window upon a SDL_WINDOWEVENT_CLOSE event to ensure that all windows get closed properly and the new code to handle the last window closes gets executed. --- src/events/SDL_windowevents.c | 8 ++++++++ test/common.c | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index ff92e82dd..fa34034a2 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -176,6 +176,14 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1, posted = (SDL_PushEvent(&event) > 0); } + + if (windowevent == SDL_WINDOWEVENT_CLOSE) { + if ( !window->prev && !window->next ) { + // This is the last window in the list so send the SDL_QUIT event + SDL_SendQuit(); + } + } + return (posted); } diff --git a/test/common.c b/test/common.c index 167694420..7b48a644f 100644 --- a/test/common.c +++ b/test/common.c @@ -1038,7 +1038,12 @@ CommonEvent(CommonState * state, SDL_Event * event, int *done) case SDL_WINDOWEVENT: switch (event->window.event) { case SDL_WINDOWEVENT_CLOSE: - *done = 1; + { + SDL_Window *pWindow = SDL_GetWindowFromID(event->window.windowID); + if ( pWindow ) { + SDL_DestroyWindow( pWindow ); + } + } break; } break; From 050fce366dd718eaf0e4d09215eda58d1676f160 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 15:31:00 -0800 Subject: [PATCH 31/44] Fixed compiling under Visual Studio --- src/timer/SDL_timer.c | 6 ++++++ src/timer/windows/SDL_systimer.c | 1 + test/testatomic.c | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 593add64d..2ad2e4e23 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -224,7 +224,13 @@ SDL_TimerInit(void) } data->active = SDL_TRUE; + /* !!! FIXME: this is nasty. */ +#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) +#undef SDL_CreateThread + data->thread = SDL_CreateThread(SDL_TimerThread, data, NULL, NULL); +#else data->thread = SDL_CreateThread(SDL_TimerThread, data); +#endif if (!data->thread) { SDL_TimerQuit(); return -1; diff --git a/src/timer/windows/SDL_systimer.c b/src/timer/windows/SDL_systimer.c index 2674e2200..6b3581c1b 100644 --- a/src/timer/windows/SDL_systimer.c +++ b/src/timer/windows/SDL_systimer.c @@ -24,6 +24,7 @@ #ifdef SDL_TIMER_WINDOWS #include "../../core/windows/SDL_windows.h" +#include #include "SDL_timer.h" diff --git a/test/testatomic.c b/test/testatomic.c index 98a6a7824..ecf134a2a 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -526,7 +526,6 @@ static int FIFO_Reader(void* _data) ReaderData *data = (ReaderData *)_data; SDL_EventQueue *queue = data->queue; SDL_Event event; - int index; if (data->lock_free) { for ( ; ; ) { From d6a650353798620fcf96f4f56354cfd94edbc0ea Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 16:46:15 -0800 Subject: [PATCH 32/44] Added cache line size info in SDL_cpuinfo.h I also added an implementation to dynamically query it, but didn't expose it since most x86 CPUs have an L1 cache line size of 64 bytes. --- include/SDL_cpuinfo.h | 5 ++ src/cpuinfo/SDL_cpuinfo.c | 160 +++++++++++++++++++++++++------------- src/timer/SDL_timer.c | 6 +- test/testatomic.c | 17 ++-- 4 files changed, 121 insertions(+), 67 deletions(-) diff --git a/include/SDL_cpuinfo.h b/include/SDL_cpuinfo.h index 0cc4998e6..ea29df9da 100644 --- a/include/SDL_cpuinfo.h +++ b/include/SDL_cpuinfo.h @@ -39,6 +39,11 @@ extern "C" { /* *INDENT-ON* */ #endif +/* This is a guess for the cacheline size used for padding, and is correct + * for most x86 processors at this point. + */ +#define SDL_CACHELINE_SIZE 64 + /** * This function returns the number of CPU cores available. */ diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index 3444f2fad..443d5c188 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -337,73 +337,125 @@ SDL_GetCPUCount() static const char * SDL_GetCPUType() { - static char SDL_CPUType[48]; + static char SDL_CPUType[13]; if (!SDL_CPUType[0]) { int i = 0; int a, b, c, d; + if (CPU_haveCPUID()) { + cpuid(0x00000000, a, b, c, d); + SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; + } + if (!SDL_CPUType[0]) { + SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType)); + } + } + return SDL_CPUType; +} + +static const char * +SDL_GetCPUName() +{ + static char SDL_CPUName[48]; + + if (!SDL_CPUName[0]) { + int i = 0; + int a, b, c, d; + if (CPU_haveCPUID()) { cpuid(0x80000000, a, b, c, d); if (a >= 0x80000004) { cpuid(0x80000002, a, b, c, d); - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; cpuid(0x80000003, a, b, c, d); - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; cpuid(0x80000004, a, b, c, d); - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; - SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; + SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8; } } - if (!SDL_CPUType[0]) { - SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType)); + if (!SDL_CPUName[0]) { + SDL_strlcpy(SDL_CPUName, "Unknown", sizeof(SDL_CPUName)); } } - return SDL_CPUType; + return SDL_CPUName; +} + +static int +SDL_GetCPUCacheLineSize() +{ + const char *cpuType = SDL_GetCPUType(); + + if (SDL_strcmp(cpuType, "GenuineIntel") == 0) { + int a, b, c, d; + + cpuid(0x00000001, a, b, c, d); + return (((b >> 8) & 0xff) * 8); + } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) { + int a, b, c, d; + + cpuid(0x80000005, a, b, c, d); + return (c & 0xff); + } else { + /* Just make a guess here... */ + return SDL_CACHELINE_SIZE; + } } static Uint32 SDL_CPUFeatures = 0xFFFFFFFF; @@ -521,7 +573,9 @@ int main() { printf("CPU count: %d\n", SDL_GetCPUCount()); - printf("CPU name: %s\n", SDL_GetCPUType()); + printf("CPU type: %s\n", SDL_GetCPUType()); + printf("CPU name: %s\n", SDL_GetCPUName()); + printf("CacheLine size: %d\n", SDL_GetCPUCacheLineSize()); printf("RDTSC: %d\n", SDL_HasRDTSC()); printf("MMX: %d\n", SDL_HasMMX()); printf("MMXExt: %d\n", SDL_HasMMXExt()); diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 2ad2e4e23..2efea24c3 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -24,6 +24,7 @@ #include "SDL_timer.h" #include "SDL_timer_c.h" #include "SDL_atomic.h" +#include "SDL_cpuinfo.h" #include "SDL_thread.h" /* #define DEBUG_TIMERS */ @@ -46,9 +47,6 @@ typedef struct _SDL_TimerMap struct _SDL_TimerMap *next; } SDL_TimerMap; -/* A reasonable guess */ -#define CACHELINE_SIZE 128 - /* The timers are kept in a sorted list */ typedef struct { /* Data used by the main thread */ @@ -58,7 +56,7 @@ typedef struct { SDL_mutex *timermap_lock; /* Padding to separate cache lines between threads */ - char pad[CACHELINE_SIZE]; + char cache_pad[SDL_CACHELINE_SIZE]; /* Data used to communicate with the timer thread */ SDL_SpinLock lock; diff --git a/test/testatomic.c b/test/testatomic.c index ecf134a2a..0c9b13a27 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -243,9 +243,6 @@ void RunEpicTest() #define NUM_WRITERS 4 #define EVENTS_PER_WRITER 1000000 -/* A decent guess for the size of a cache line on this architecture */ -#define CACHELINE 64 - /* The number of entries must be a power of 2 */ #define MAX_ENTRIES 256 #define WRAP_MASK (MAX_ENTRIES-1) @@ -260,22 +257,22 @@ typedef struct { SDL_EventQueueEntry entries[MAX_ENTRIES]; - char cache_pad1[CACHELINE-((sizeof(SDL_EventQueueEntry)*MAX_ENTRIES)%CACHELINE)]; + char cache_pad1[SDL_CACHELINE_SIZE-((sizeof(SDL_EventQueueEntry)*MAX_ENTRIES)%SDL_CACHELINE_SIZE)]; SDL_atomic_t enqueue_pos; - char cache_pad2[CACHELINE-sizeof(SDL_atomic_t)]; + char cache_pad2[SDL_CACHELINE_SIZE-sizeof(SDL_atomic_t)]; SDL_atomic_t dequeue_pos; - char cache_pad3[CACHELINE-sizeof(SDL_atomic_t)]; + char cache_pad3[SDL_CACHELINE_SIZE-sizeof(SDL_atomic_t)]; #ifdef TEST_SPINLOCK_FIFO SDL_SpinLock lock; SDL_atomic_t rwcount; SDL_atomic_t watcher; - char cache_pad4[CACHELINE-sizeof(SDL_SpinLock)-2*sizeof(SDL_atomic_t)]; + char cache_pad4[SDL_CACHELINE_SIZE-sizeof(SDL_SpinLock)-2*sizeof(SDL_atomic_t)]; #endif volatile SDL_bool active; @@ -470,10 +467,10 @@ typedef struct { SDL_EventQueue *queue; int index; - char padding1[CACHELINE-(sizeof(SDL_EventQueue*)+sizeof(int))%CACHELINE]; + char padding1[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int))%SDL_CACHELINE_SIZE]; int waits; SDL_bool lock_free; - char padding2[CACHELINE-sizeof(int)-sizeof(SDL_bool)]; + char padding2[SDL_CACHELINE_SIZE-sizeof(int)-sizeof(SDL_bool)]; } WriterData; typedef struct @@ -482,7 +479,7 @@ typedef struct int counters[NUM_WRITERS]; int waits; SDL_bool lock_free; - char padding[CACHELINE-(sizeof(SDL_EventQueue*)+sizeof(int)*NUM_WRITERS+sizeof(int)+sizeof(SDL_bool))%CACHELINE]; + char padding[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int)*NUM_WRITERS+sizeof(int)+sizeof(SDL_bool))%SDL_CACHELINE_SIZE]; } ReaderData; static int FIFO_Writer(void* _data) From c5035c553b5c09996bf8ecff1090554b20189142 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 16:51:47 -0800 Subject: [PATCH 33/44] Bump up the default cache line size. --- include/SDL_cpuinfo.h | 8 +++++--- test/testatomic.c | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/SDL_cpuinfo.h b/include/SDL_cpuinfo.h index ea29df9da..f63140688 100644 --- a/include/SDL_cpuinfo.h +++ b/include/SDL_cpuinfo.h @@ -39,10 +39,12 @@ extern "C" { /* *INDENT-ON* */ #endif -/* This is a guess for the cacheline size used for padding, and is correct - * for most x86 processors at this point. +/* This is a guess for the cacheline size used for padding. + * Most x86 processors have a 64 byte cache line. + * The 64-bit PowerPC processors have a 128 byte cache line. + * We'll use the larger value to be generally safe. */ -#define SDL_CACHELINE_SIZE 64 +#define SDL_CACHELINE_SIZE 128 /** * This function returns the number of CPU cores available. diff --git a/test/testatomic.c b/test/testatomic.c index 0c9b13a27..89bf09fc0 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -3,6 +3,7 @@ #include "SDL.h" #include "SDL_atomic.h" #include "SDL_assert.h" +#include "SDL_cpuinfo.h" /* Absolutely basic tests just to see if we get the expected value From ece000dbf14a0f450340872523c85362af638ee7 Mon Sep 17 00:00:00 2001 From: krogoway Date: Thu, 27 Jan 2011 20:30:39 -0600 Subject: [PATCH 34/44] Always copy the SDL_config_windows.h to SDL_config.h for VisualC 2005, 2008 and 2010 projects. --- VisualC/SDL/SDL_VS2005.vcproj | 4 ++-- VisualC/SDL/SDL_VS2008.vcproj | 4 ++-- VisualC/SDL/SDL_VS2010.vcxproj | 12 ++++-------- VisualC/SDLmain/SDLmain_VS2005.vcproj | 6 +++--- VisualC/SDLmain/SDLmain_VS2008.vcproj | 6 +++--- VisualC/SDLmain/SDLmain_VS2010.vcxproj | 20 +++++++------------- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/VisualC/SDL/SDL_VS2005.vcproj b/VisualC/SDL/SDL_VS2005.vcproj index 6f8979f69..7f689ffef 100644 --- a/VisualC/SDL/SDL_VS2005.vcproj +++ b/VisualC/SDL/SDL_VS2005.vcproj @@ -29,7 +29,7 @@ Making sure basic SDL headers are in place... - if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY -echo Copying SDL_config_windows.h to SDL_config.h... -copy "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" -:SDLCONFIGOKAY + echo Copying SDL_config_windows.h to SDL_config.h... +copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY echo Creating stub SDL_revision.h file... @@ -154,10 +152,8 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" Making sure basic SDL headers are in place... - if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY -echo Copying SDL_config_windows.h to SDL_config.h... -copy "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" -:SDLCONFIGOKAY + echo Copying SDL_config_windows.h to SDL_config.h... +copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY echo Creating stub SDL_revision.h file... diff --git a/VisualC/SDLmain/SDLmain_VS2005.vcproj b/VisualC/SDLmain/SDLmain_VS2005.vcproj index 276747f29..6c9ff8aef 100644 --- a/VisualC/SDLmain/SDLmain_VS2005.vcproj +++ b/VisualC/SDLmain/SDLmain_VS2005.vcproj @@ -29,7 +29,7 @@ Making sure basic SDL headers are in place... - if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY -echo Copying SDL_config_windows.h to SDL_config.h... -copy "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" -:SDLCONFIGOKAY + echo Copying SDL_config_windows.h to SDL_config.h... +copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY echo Creating stub SDL_revision.h file... @@ -154,10 +152,8 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" Making sure basic SDL headers are in place... - if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY -echo Copying SDL_config_windows.h to SDL_config.h... -copy "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" -:SDLCONFIGOKAY + echo Copying SDL_config_windows.h to SDL_config.h... +copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY echo Creating stub SDL_revision.h file... @@ -207,10 +203,8 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" Making sure basic SDL headers are in place... - if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY -echo Copying SDL_config_windows.h to SDL_config.h... -copy "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" -:SDLCONFIGOKAY + echo Copying SDL_config_windows.h to SDL_config.h... +copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h" if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY echo Creating stub SDL_revision.h file... @@ -261,4 +255,4 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" - + \ No newline at end of file From 8903c6651b4376d7fd760372ed73ee4594fd2a8f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 20:14:10 -0800 Subject: [PATCH 35/44] 0 isn't a valid Mercurial revision --- VisualC/SDL/SDL_VS2005.vcproj | 4 ++-- VisualC/SDL/SDL_VS2008.vcproj | 4 ++-- VisualC/SDL/SDL_VS2010.vcxproj | 6 +++--- VisualC/SDLmain/SDLmain_VS2005.vcproj | 6 +++--- VisualC/SDLmain/SDLmain_VS2008.vcproj | 6 +++--- VisualC/SDLmain/SDLmain_VS2010.vcxproj | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/VisualC/SDL/SDL_VS2005.vcproj b/VisualC/SDL/SDL_VS2005.vcproj index 7f689ffef..973a4a7d6 100644 --- a/VisualC/SDL/SDL_VS2005.vcproj +++ b/VisualC/SDL/SDL_VS2005.vcproj @@ -29,7 +29,7 @@ @@ -157,7 +157,7 @@ copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\ if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY echo Creating stub SDL_revision.h file... -echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" +echo #define SDL_REVISION "hg-0:baadf00d" >"$(ProjectDir)\..\..\include\SDL_revision.h" :SDLREVISIONOKAY @@ -458,4 +458,4 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" - \ No newline at end of file + diff --git a/VisualC/SDLmain/SDLmain_VS2005.vcproj b/VisualC/SDLmain/SDLmain_VS2005.vcproj index 6c9ff8aef..0b1f3ab12 100644 --- a/VisualC/SDLmain/SDLmain_VS2005.vcproj +++ b/VisualC/SDLmain/SDLmain_VS2005.vcproj @@ -29,7 +29,7 @@ @@ -157,7 +157,7 @@ copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\ if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY echo Creating stub SDL_revision.h file... -echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" +echo #define SDL_REVISION "hg-0:baadf00d" >"$(ProjectDir)\..\..\include\SDL_revision.h" :SDLREVISIONOKAY @@ -208,7 +208,7 @@ copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\ if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY echo Creating stub SDL_revision.h file... -echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" +echo #define SDL_REVISION "hg-0:baadf00d" >"$(ProjectDir)\..\..\include\SDL_revision.h" :SDLREVISIONOKAY @@ -255,4 +255,4 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" - \ No newline at end of file + From cff0c4846bb86b75041fcdd018db6bd414a99bcc Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 20:37:54 -0800 Subject: [PATCH 36/44] Fixed quotes around Mercurial revision text --- VisualC/SDL/SDL_VS2005.vcproj | 4 ++-- VisualC/SDL/SDL_VS2008.vcproj | 4 ++-- VisualC/SDLmain/SDLmain_VS2005.vcproj | 6 +++--- VisualC/SDLmain/SDLmain_VS2008.vcproj | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/VisualC/SDL/SDL_VS2005.vcproj b/VisualC/SDL/SDL_VS2005.vcproj index 973a4a7d6..cab82386f 100644 --- a/VisualC/SDL/SDL_VS2005.vcproj +++ b/VisualC/SDL/SDL_VS2005.vcproj @@ -29,7 +29,7 @@ Date: Thu, 27 Jan 2011 20:46:45 -0800 Subject: [PATCH 37/44] Added API function to get CPU cache line size. --- include/SDL_cpuinfo.h | 8 ++++++++ src/cpuinfo/SDL_cpuinfo.c | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/SDL_cpuinfo.h b/include/SDL_cpuinfo.h index f63140688..b15393834 100644 --- a/include/SDL_cpuinfo.h +++ b/include/SDL_cpuinfo.h @@ -51,6 +51,14 @@ extern "C" { */ extern DECLSPEC int SDLCALL SDL_GetCPUCount(void); +/** + * This function returns the L1 cache line size of the CPU + * + * This is useful for determining multi-threaded structure padding + * or SIMD prefetch sizes. + */ +extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void); + /** * This function returns true if the CPU has the RDTSC instruction. */ diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index 443d5c188..e365ad76f 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -304,7 +304,7 @@ CPU_haveAltiVec(void) static int SDL_CPUCount = 0; int -SDL_GetCPUCount() +SDL_GetCPUCount(void) { if (!SDL_CPUCount) { #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) @@ -335,7 +335,7 @@ SDL_GetCPUCount() /* Oh, such a sweet sweet trick, just not very useful. :) */ static const char * -SDL_GetCPUType() +SDL_GetCPUType(void) { static char SDL_CPUType[13]; @@ -366,7 +366,7 @@ SDL_GetCPUType() } static const char * -SDL_GetCPUName() +SDL_GetCPUName(void) { static char SDL_CPUName[48]; @@ -437,8 +437,8 @@ SDL_GetCPUName() return SDL_CPUName; } -static int -SDL_GetCPUCacheLineSize() +int +SDL_GetCPUCacheLineSize(void) { const char *cpuType = SDL_GetCPUType(); From 473652316aaf3b57f8a57fbdf5052ce6a35ccfec Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 20:49:07 -0800 Subject: [PATCH 38/44] Added CPU cache line size to the test output. --- test/testplatform.c | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testplatform.c b/test/testplatform.c index 74a70e1b3..59e762317 100644 --- a/test/testplatform.c +++ b/test/testplatform.c @@ -140,6 +140,7 @@ TestCPUInfo(SDL_bool verbose) { if (verbose) { printf("CPU count: %d\n", SDL_GetCPUCount()); + printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineCount()); printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected"); printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected"); printf("MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected"); From 6935f227c715b399b67059e0ee91afac01a9a7c7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 20:51:54 -0800 Subject: [PATCH 39/44] Fixed test --- test/testplatform.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/testplatform.c b/test/testplatform.c index 59e762317..75e538ec8 100644 --- a/test/testplatform.c +++ b/test/testplatform.c @@ -140,7 +140,7 @@ TestCPUInfo(SDL_bool verbose) { if (verbose) { printf("CPU count: %d\n", SDL_GetCPUCount()); - printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineCount()); + printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize()); printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected"); printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected"); printf("MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected"); @@ -169,7 +169,6 @@ TestAssertions(SDL_bool verbose) SDL_assert_release(5 < 4); SDL_assert_release(0 && "This is a test"); #endif - SDL_assert_release(0 && "This is a test"); return (0); } From 74a3510cf205281c3e4c70775bbabc76d7413438 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jan 2011 22:44:08 -0800 Subject: [PATCH 40/44] Removed completely non-portable event thread hack. Next I'll be working on generalizing the event sources and making the event queue lock-free. :) --- include/SDL.h | 1 - include/SDL_video.h | 5 +- src/SDL.c | 2 +- src/events/SDL_events.c | 187 +++-------------------- src/events/SDL_events_c.h | 7 +- src/events/SDL_keyboard.c | 2 +- src/joystick/SDL_joystick.c | 16 -- src/video/SDL_video.c | 26 ++-- src/video/directfb/SDL_DirectFB_events.c | 1 - src/video/dummy/SDL_nullevents.c | 1 - src/video/nds/SDL_ndsevents.c | 1 - src/video/pandora/SDL_pandora_events.c | 1 - src/video/uikit/SDL_uikitevents.m | 1 - test/common.c | 2 +- test/testshape.c | 2 +- test/threadwin.c | 16 +- 16 files changed, 44 insertions(+), 227 deletions(-) diff --git a/include/SDL.h b/include/SDL.h index 0f4eb35b0..88af953cc 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -116,7 +116,6 @@ extern "C" { #define SDL_INIT_JOYSTICK 0x00000200 #define SDL_INIT_HAPTIC 0x00001000 #define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */ -#define SDL_INIT_EVENTTHREAD 0x01000000 /**< Not supported on all OS's */ #define SDL_INIT_EVERYTHING 0x0000FFFF /*@}*/ diff --git a/include/SDL_video.h b/include/SDL_video.h index 12227fc36..a992a4cac 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -278,8 +278,6 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index); * \param driver_name Initialize a specific driver by name, or NULL for the * default video driver. * - * \param flags FIXME: Still needed? - * * \return 0 on success, -1 on error * * This function initializes the video subsystem; setting up a connection @@ -288,8 +286,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index); * * \sa SDL_VideoQuit() */ -extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, - Uint32 flags); +extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name); /** * \brief Shuts down the video subsystem. diff --git a/src/SDL.c b/src/SDL.c index cfd73f792..53a1b8a1d 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -59,7 +59,7 @@ SDL_InitSubSystem(Uint32 flags) #if !SDL_VIDEO_DISABLED /* Initialize the video/event subsystem */ if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) { - if (SDL_VideoInit(NULL, (flags & SDL_INIT_EVENTTHREAD)) < 0) { + if (SDL_VideoInit(NULL) < 0) { return (-1); } SDL_initialized |= SDL_INIT_VIDEO; diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index b3c2ad818..af4af7588 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -27,12 +27,12 @@ #include "SDL_events.h" #include "SDL_syswm.h" #include "SDL_thread.h" -#include "SDL_sysevents.h" #include "SDL_events_c.h" #include "../timer/SDL_timer_c.h" #if !SDL_JOYSTICK_DISABLED #include "../joystick/SDL_joystick_c.h" #endif +#include "../video/SDL_sysvideo.h" /* Public data -- the event filter */ SDL_EventFilter SDL_EventOK = NULL; @@ -58,36 +58,6 @@ static struct struct SDL_SysWMmsg wmmsg[MAXEVENTS]; } SDL_EventQ; -/* Private data -- event locking structure */ -static struct -{ - SDL_mutex *lock; - int safe; -} SDL_EventLock; - -/* Thread functions */ -static SDL_Thread *SDL_EventThread = NULL; /* Thread handle */ -static SDL_threadID event_thread; /* The event thread id */ - -void -SDL_Lock_EventThread(void) -{ - if (SDL_EventThread && (SDL_ThreadID() != event_thread)) { - /* Grab lock and spin until we're sure event thread stopped */ - SDL_mutexP(SDL_EventLock.lock); - while (!SDL_EventLock.safe) { - SDL_Delay(1); - } - } -} - -void -SDL_Unlock_EventThread(void) -{ - if (SDL_EventThread && (SDL_ThreadID() != event_thread)) { - SDL_mutexV(SDL_EventLock.lock); - } -} static __inline__ SDL_bool SDL_ShouldPollJoystick() @@ -102,106 +72,6 @@ SDL_ShouldPollJoystick() return SDL_FALSE; } -static int SDLCALL -SDL_GobbleEvents(void *unused) -{ - event_thread = SDL_ThreadID(); - - while (SDL_EventQ.active) { - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - - /* Get events from the video subsystem */ - if (_this) { - _this->PumpEvents(_this); - } -#if !SDL_JOYSTICK_DISABLED - /* Check for joystick state change */ - if (SDL_ShouldPollJoystick()) { - SDL_JoystickUpdate(); - } -#endif - - /* Give up the CPU for the rest of our timeslice */ - SDL_EventLock.safe = 1; - SDL_Delay(1); - - /* Check for event locking. - On the P of the lock mutex, if the lock is held, this thread - will wait until the lock is released before continuing. The - safe flag will be set, meaning that the other thread can go - about it's business. The safe flag is reset before the V, - so as soon as the mutex is free, other threads can see that - it's not safe to interfere with the event thread. - */ - SDL_mutexP(SDL_EventLock.lock); - SDL_EventLock.safe = 0; - SDL_mutexV(SDL_EventLock.lock); - } - event_thread = 0; - return (0); -} - -static int -SDL_StartEventThread(Uint32 flags) -{ - /* Reset everything to zero */ - SDL_EventThread = NULL; - SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock)); - - /* Create the lock and set ourselves active */ -#if !SDL_THREADS_DISABLED - SDL_EventQ.lock = SDL_CreateMutex(); - if (SDL_EventQ.lock == NULL) { - return (-1); - } -#endif /* !SDL_THREADS_DISABLED */ - SDL_EventQ.active = 1; - - if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { - SDL_EventLock.lock = SDL_CreateMutex(); - if (SDL_EventLock.lock == NULL) { - return (-1); - } - SDL_EventLock.safe = 0; - -#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) -#undef SDL_CreateThread - SDL_EventThread = - SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL); -#else - SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL); -#endif - if (SDL_EventThread == NULL) { - return (-1); - } - } else { - event_thread = 0; - } - return (0); -} - -static void -SDL_StopEventThread(void) -{ - SDL_EventQ.active = 0; - if (SDL_EventThread) { - SDL_WaitThread(SDL_EventThread, NULL); - SDL_EventThread = NULL; - SDL_DestroyMutex(SDL_EventLock.lock); - SDL_EventLock.lock = NULL; - } - if (SDL_EventQ.lock) { - SDL_DestroyMutex(SDL_EventQ.lock); - SDL_EventQ.lock = NULL; - } -} - -SDL_threadID -SDL_EventThreadID(void) -{ - return (event_thread); -} - /* Public functions */ void @@ -209,13 +79,10 @@ SDL_StopEventLoop(void) { int i; - /* Halt the event thread, if running */ - SDL_StopEventThread(); - - /* Shutdown event handlers */ - SDL_KeyboardQuit(); - SDL_MouseQuit(); - SDL_QuitQuit(); + if (SDL_EventQ.lock) { + SDL_DestroyMutex(SDL_EventQ.lock); + SDL_EventQ.lock = NULL; + } /* Clean out EventQ */ SDL_EventQ.head = 0; @@ -233,12 +100,11 @@ SDL_StopEventLoop(void) /* This function (and associated calls) may be called more than once */ int -SDL_StartEventLoop(Uint32 flags) +SDL_StartEventLoop(void) { int retcode; /* Clean out the event queue */ - SDL_EventThread = NULL; SDL_EventQ.lock = NULL; SDL_StopEventLoop(); @@ -246,22 +112,15 @@ SDL_StartEventLoop(Uint32 flags) SDL_EventOK = NULL; SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE); - /* Initialize event handlers */ - retcode = 0; - retcode += SDL_KeyboardInit(); - retcode += SDL_MouseInit(); - retcode += SDL_TouchInit(); - retcode += SDL_QuitInit(); - if (retcode < 0) { - /* We don't expect them to fail, but... */ + /* Create the lock and set ourselves active */ +#if !SDL_THREADS_DISABLED + SDL_EventQ.lock = SDL_CreateMutex(); + if (SDL_EventQ.lock == NULL) { return (-1); } +#endif /* !SDL_THREADS_DISABLED */ + SDL_EventQ.active = 1; - /* Create the lock and event thread */ - if (SDL_StartEventThread(flags) < 0) { - SDL_StopEventLoop(); - return (-1); - } return (0); } @@ -420,20 +279,18 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType) void SDL_PumpEvents(void) { - if (!SDL_EventThread) { - SDL_VideoDevice *_this = SDL_GetVideoDevice(); + SDL_VideoDevice *_this = SDL_GetVideoDevice(); - /* Get events from the video subsystem */ - if (_this) { - _this->PumpEvents(_this); - } -#if !SDL_JOYSTICK_DISABLED - /* Check for joystick state change */ - if (SDL_ShouldPollJoystick()) { - SDL_JoystickUpdate(); - } -#endif + /* Get events from the video subsystem */ + if (_this) { + _this->PumpEvents(_this); } +#if !SDL_JOYSTICK_DISABLED + /* Check for joystick state change */ + if (SDL_ShouldPollJoystick()) { + SDL_JoystickUpdate(); + } +#endif } /* Public functions */ diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h index ccf29b3da..569e9daea 100644 --- a/src/events/SDL_events_c.h +++ b/src/events/SDL_events_c.h @@ -29,15 +29,12 @@ #include "SDL_touch_c.h" #include "SDL_windowevents_c.h" #include "SDL_gesture_c.h" + /* Start and stop the event processing loop */ -extern int SDL_StartEventLoop(Uint32 flags); +extern int SDL_StartEventLoop(void); extern void SDL_StopEventLoop(void); extern void SDL_QuitInterrupt(void); -extern void SDL_Lock_EventThread(void); -extern void SDL_Unlock_EventThread(void); -extern SDL_threadID SDL_EventThreadID(void); - extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message); extern int SDL_QuitInit(void); diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index 49948d77c..307dc5386 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -26,7 +26,7 @@ #include "SDL_timer.h" #include "SDL_events.h" #include "SDL_events_c.h" -#include "SDL_sysevents.h" +#include "../video/SDL_sysvideo.h" /* Global keyboard information */ diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 6a99c4bf9..1ed0d41f3 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -30,12 +30,6 @@ #include "../events/SDL_events_c.h" #endif -/* This is used for Quake III Arena */ -#if SDL_EVENTS_DISABLED -#define SDL_Lock_EventThread() -#define SDL_Unlock_EventThread() -#endif - Uint8 SDL_numjoysticks = 0; SDL_Joystick **SDL_joysticks = NULL; static SDL_Joystick *default_joystick = NULL; @@ -165,11 +159,9 @@ SDL_JoystickOpen(int device_index) /* Add joystick to list */ ++joystick->ref_count; - SDL_Lock_EventThread(); for (i = 0; SDL_joysticks[i]; ++i) /* Skip to next joystick */ ; SDL_joysticks[i] = joystick; - SDL_Unlock_EventThread(); return (joystick); } @@ -379,9 +371,6 @@ SDL_JoystickClose(SDL_Joystick * joystick) return; } - /* Lock the event queue - prevent joystick polling */ - SDL_Lock_EventThread(); - if (joystick == default_joystick) { default_joystick = NULL; } @@ -396,9 +385,6 @@ SDL_JoystickClose(SDL_Joystick * joystick) } } - /* Let the event thread keep running */ - SDL_Unlock_EventThread(); - /* Free the data associated with this joystick */ if (joystick->axes) { SDL_free(joystick->axes); @@ -419,9 +405,7 @@ void SDL_JoystickQuit(void) { /* Stop the event polling */ - SDL_Lock_EventThread(); SDL_numjoysticks = 0; - SDL_Unlock_EventThread(); /* Quit the joystick setup */ SDL_SYS_JoystickQuit(); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 9d1f85b23..0e4ec105b 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -31,7 +31,6 @@ #include "SDL_renderer_gl.h" #include "SDL_renderer_gles.h" #include "SDL_renderer_sw.h" -#include "../events/SDL_sysevents.h" #include "../events/SDL_events_c.h" #if SDL_VIDEO_DRIVER_WINDOWS @@ -172,7 +171,7 @@ SDL_GetVideoDriver(int index) * Initialize the video and event subsystems -- determine native pixel format */ int -SDL_VideoInit(const char *driver_name, Uint32 flags) +SDL_VideoInit(const char *driver_name) { SDL_VideoDevice *video; int index; @@ -183,18 +182,12 @@ SDL_VideoInit(const char *driver_name, Uint32 flags) SDL_VideoQuit(); } - /* Toggle the event thread flags, based on OS requirements */ -#if defined(MUST_THREAD_EVENTS) - flags |= SDL_INIT_EVENTTHREAD; -#elif defined(CANT_THREAD_EVENTS) - if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { - SDL_SetError("OS doesn't support threaded events"); - return -1; - } -#endif - /* Start the event loop */ - if (SDL_StartEventLoop(flags) < 0) { + if (SDL_StartEventLoop() < 0 || + SDL_KeyboardInit() < 0 || + SDL_MouseInit() < 0 || + SDL_TouchInit() < 0 || + SDL_QuitInit() < 0) { return -1; } @@ -887,7 +880,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) if (!_this) { /* Initialize the video system if needed */ - if (SDL_VideoInit(NULL, 0) < 0) { + if (SDL_VideoInit(NULL) < 0) { return NULL; } } @@ -2807,8 +2800,13 @@ SDL_VideoQuit(void) if (!_this) { return; } + /* Halt event processing before doing anything else */ + SDL_QuitQuit(); + SDL_MouseQuit(); + SDL_KeyboardQuit(); SDL_StopEventLoop(); + SDL_EnableScreenSaver(); /* Clean up the system video */ diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c index 97a821515..e994249bc 100644 --- a/src/video/directfb/SDL_DirectFB_events.c +++ b/src/video/directfb/SDL_DirectFB_events.c @@ -26,7 +26,6 @@ #include #include "../SDL_sysvideo.h" -#include "../../events/SDL_sysevents.h" #include "../../events/SDL_events_c.h" #include "../../events/SDL_keyboard_c.h" #include "../../events/scancodes_linux.h" diff --git a/src/video/dummy/SDL_nullevents.c b/src/video/dummy/SDL_nullevents.c index 195b8fc69..e164f8439 100644 --- a/src/video/dummy/SDL_nullevents.c +++ b/src/video/dummy/SDL_nullevents.c @@ -24,7 +24,6 @@ /* Being a null driver, there's no event stream. We just define stubs for most of the API. */ -#include "../../events/SDL_sysevents.h" #include "../../events/SDL_events_c.h" #include "SDL_nullvideo.h" diff --git a/src/video/nds/SDL_ndsevents.c b/src/video/nds/SDL_ndsevents.c index 94db798c8..5dc06d9ae 100644 --- a/src/video/nds/SDL_ndsevents.c +++ b/src/video/nds/SDL_ndsevents.c @@ -28,7 +28,6 @@ #include #include -#include "../../events/SDL_sysevents.h" #include "../../events/SDL_events_c.h" #include "SDL_ndsvideo.h" diff --git a/src/video/pandora/SDL_pandora_events.c b/src/video/pandora/SDL_pandora_events.c index e44899776..eb3aa8566 100644 --- a/src/video/pandora/SDL_pandora_events.c +++ b/src/video/pandora/SDL_pandora_events.c @@ -24,7 +24,6 @@ /* Being a null driver, there's no event stream. We just define stubs for most of the API. */ -#include "../../events/SDL_sysevents.h" #include "../../events/SDL_events_c.h" void diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m index 12b1e281b..e59a043a7 100644 --- a/src/video/uikit/SDL_uikitevents.m +++ b/src/video/uikit/SDL_uikitevents.m @@ -21,7 +21,6 @@ */ #include "SDL_config.h" -#include "../../events/SDL_sysevents.h" #include "../../events/SDL_events_c.h" #include "SDL_uikitvideo.h" diff --git a/test/common.c b/test/common.c index 7b48a644f..968efb0b5 100644 --- a/test/common.c +++ b/test/common.c @@ -616,7 +616,7 @@ CommonInit(CommonState * state) fprintf(stderr, "\n"); } } - if (SDL_VideoInit(state->videodriver, 0) < 0) { + if (SDL_VideoInit(state->videodriver) < 0) { fprintf(stderr, "Couldn't initialize video driver: %s\n", SDL_GetError()); return SDL_FALSE; diff --git a/test/testshape.c b/test/testshape.c index ba14dae99..495944aad 100644 --- a/test/testshape.c +++ b/test/testshape.c @@ -60,7 +60,7 @@ int main(int argc,char** argv) { exit(-1); } - if(SDL_VideoInit(NULL,0) == -1) { + if(SDL_VideoInit(NULL) == -1) { printf("Could not initialize SDL video.\n"); exit(-2); } diff --git a/test/threadwin.c b/test/threadwin.c index dfd1c3c9c..08c149f92 100644 --- a/test/threadwin.c +++ b/test/threadwin.c @@ -241,16 +241,7 @@ main(int argc, char *argv[]) video_flags = SDL_SWSURFACE; parsed = 1; while (parsed) { - /* If the threaded option is enabled, and the SDL library hasn't - been compiled with threaded events enabled, then the mouse and - keyboard won't respond. - */ - if ((argc >= 2) && (strcmp(argv[1], "-threaded") == 0)) { - init_flags |= SDL_INIT_EVENTTHREAD; - argc -= 1; - argv += 1; - printf("Running with threaded events\n"); - } else if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) { + if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) { video_flags |= SDL_FULLSCREEN; argc -= 1; argv += 1; @@ -320,9 +311,8 @@ main(int argc, char *argv[]) /* Loop, waiting for QUIT */ while (!done) { - if (!(init_flags & SDL_INIT_EVENTTHREAD)) { - SDL_PumpEvents(); /* Needed when event thread is off */ - } + SDL_PumpEvents(); + if (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT)) { done = 1; } From 177d309b34762e1d4cab9528a92b999960dc94cc Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Jan 2011 10:21:58 -0800 Subject: [PATCH 41/44] Fixed bug #1056 (Frequent crashes in Touch events by simply touching the screen) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Joseba García Echebarria 2010-12-15 01:55:22 PST I believe the crash is caused by a check not being performed on wether an SDL_Touch element is NULL before using it in the SDL_SendTouchMotion function in src/events/SDL_touch.c around line 400. Judging from the rest of the code, there's a missing if (!touch) { return 0; } before using "touch" as SDL_GetFinger(), SDL_GetFingerIndexId() use touch->num_fingers without checking. I can attach a patch if you like. It seems pretty straightforward, though. I have yet to discover why touch is being returned as NULL as this error is only triggered when an actual gesture has been performed, maybe something related to SDL_AddTouch()? --- src/events/SDL_touch.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index c6bde97ba..07f0bfe11 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -397,15 +397,16 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, float xin, float yin, float pressurein) { int index = SDL_GetTouchIndexId(id); - SDL_Touch *touch = SDL_GetTouch(id); - SDL_Finger *finger = SDL_GetFinger(touch,fingerid); + SDL_Touch *touch; + SDL_Finger *finger; int posted; Sint16 xrel, yrel; float x_max = 0, y_max = 0; - Uint16 x; - Uint16 y; - Uint16 pressure; + Uint16 x; + Uint16 y; + Uint16 pressure; + touch = SDL_GetTouch(id); if (!touch) { return SDL_TouchNotFoundError(id); } @@ -418,6 +419,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, return 0; } + finger = SDL_GetFinger(touch,fingerid); if(finger == NULL || !finger->down) { return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein); } else { @@ -496,14 +498,16 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, return posted; } } + int SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button) { - SDL_Touch *touch = SDL_GetTouch(id); + SDL_Touch *touch; int posted; Uint32 type; + touch = SDL_GetTouch(id); if (!touch) { return SDL_TouchNotFoundError(id); } From 2bf744413967c678fe3bf82033eeecf858fc6183 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Jan 2011 10:37:36 -0800 Subject: [PATCH 42/44] Updated main.c for API changes Kees Bakker to sdl The main.c for the template is still targeting SDL1.2. Here is the patch to make it work for SDL1.3 (I'm hoping the mailing lists accepts attachments.) In this patch I have also changed the shell script that assembles the Template. Since there is now only one lib target (same name for "device" and "simulator" version) I copy the simulator library to the destination with the name libSDLSimulator.a. This is not a satisfactory solution, because both libraries are included in the project while only one is needed (depending on the selected environment). However, I'm not fluent with Xcode to say what a better solution would be. Kind regards, Kees Bakker --- Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj | 2 +- Xcode-iPhoneOS/Template/SDL Application/main.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj index cf1f37235..06043549d 100755 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj @@ -1352,7 +1352,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "# clean up the framework, remove headers, extra files\n\ntemp=$BUILD_DIR/$BUILD_STYLE-template\ndest=\"/Developer/Platforms/iPhoneOS.platform/Developer/Library/XCode/Project Templates/SDL\"\ntemplate_dir_name=\"SDL Application\"\n\nrsync_flags=\"--exclude *.svn --links -r\"\n\n# mkdir -p $dest\nmkdir -p $temp\nmkdir -p \"$temp/$template_dir_name/lib/\"\nmkdir -p \"$temp/$template_dir_name/include\"\n\n#copy template\nrsync $rsync_flags \"../template/$template_dir_name\" $temp/\n\n#copy iPhone OS library\nrsync $rsync_flags -r $BUILD_DIR/$BUILD_STYLE-iphoneos/libSDLiPhoneOS.a \"$temp/$template_dir_name/lib/\"\n\n#copy iPhone Simulator Lib\nrsync $rsync_flags -r $BUILD_DIR/$BUILD_STYLE-iphonesimulator/libSDLSimulator.a \"$temp/$template_dir_name/lib/\"\n\n#copy headers\nrsync $rsync_flags ../../include/ \"$temp/$template_dir_name/include\"\n\n#install (nah, don't install)\n# cp -fr \"$temp/$template_dir_name\" \"$dest\""; + shellScript = "# clean up the framework, remove headers, extra files\n\ntemp=$BUILD_DIR/$BUILD_STYLE-template\ndest=\"/Developer/Platforms/iPhoneOS.platform/Developer/Library/XCode/Project Templates/SDL\"\ntemplate_dir_name=\"SDL Application\"\n\nrsync_flags=\"--exclude *.svn --links -r\"\n\n# mkdir -p $dest\nmkdir -p $temp\nmkdir -p \"$temp/$template_dir_name/lib/\"\nmkdir -p \"$temp/$template_dir_name/include\"\n\n#copy template\nrsync $rsync_flags \"../template/$template_dir_name\" $temp/\n\n#copy iPhone OS library\nrsync $rsync_flags -r $BUILD_DIR/$BUILD_STYLE-iphoneos/libSDLiPhoneOS.a \"$temp/$template_dir_name/lib/\"\n\n#copy iPhone Simulator Lib. Can't use the same name.\nrsync $rsync_flags -r $BUILD_DIR/$BUILD_STYLE-iphonesimulator/libSDLiPhoneOS.a \"$temp/$template_dir_name/lib/libSDLSimulator.a\"\n\n#copy headers\nrsync $rsync_flags ../../include/. \"$temp/$template_dir_name/include\"\n\n#install (nah, don't install)\n# cp -fr \"$temp/$template_dir_name\" \"$dest\""; }; /* End PBXShellScriptBuildPhase section */ diff --git a/Xcode-iPhoneOS/Template/SDL Application/main.c b/Xcode-iPhoneOS/Template/SDL Application/main.c index 168fb48c9..8b20954b7 100644 --- a/Xcode-iPhoneOS/Template/SDL Application/main.c +++ b/Xcode-iPhoneOS/Template/SDL Application/main.c @@ -32,9 +32,10 @@ render(void) r = randomInt(50, 255); g = randomInt(50, 255); b = randomInt(50, 255); + SDL_SetRenderDrawColor(r, g, b, 255); /* Fill the rectangle in the color */ - SDL_RenderFill(r, g, b, 255, &rect); + SDL_RenderFillRect(&rect); /* update screen */ SDL_RenderPresent(); @@ -69,7 +70,7 @@ main(int argc, char *argv[]) } /* Fill screen with black */ - SDL_RenderFill(0, 0, 0, 0, NULL); + SDL_RenderClear(); /* Enter render loop, waiting for user to quit */ done = 0; From a961fbabfe0098aef42cef9a079c02ddb5873335 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Jan 2011 12:09:25 -0800 Subject: [PATCH 43/44] Added Edgar's blog to the haptic documentation --- include/SDL_haptic.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index 52f33f152..f4e1578cb 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -81,6 +81,10 @@ * return 0; // Success * } * \endcode + * + * You can also find out more information on my blog: + * http://bobbens.dyndns.org/journal/2010/sdl_haptic/ + * * \author Edgar Simo Serra */ From 741f1ec0c44df610e37df8b59c591b66ad3efa8e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 30 Jan 2011 13:42:05 -0800 Subject: [PATCH 44/44] Fixed bug #1111 kwm@rainbow-runner.nl 2011-01-30 06:28:27 PST Created attachment 562 [details] Build fix with clang. When building sdl 1.2.14 with the Clang compiler http://clang.llvm.org . The build fails in src/video/mmx.h with the following error: -------------------------------------------------- ./src/video/SDL_RLEaccel.c:831:5: error: invalid operand for instruction CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt); ^ ./src/video/SDL_RLEaccel.c:831:17: note: instantiated from: CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt); ^ ./src/video/SDL_RLEaccel.c:831:5: note: instantiated from: CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt); ^ ./src/video/SDL_RLEaccel.c:647:23: note: instantiated from: blitter(2, Uint8, ALPHA_BLIT16_565MMX); \ ^ ./src/video/SDL_RLEaccel.c:282:4: note: instantiated from: movq_r2m(mm3, *dstp); \ ^ In file included from ./src/video/SDL_RLEaccel.c:99: ./src/video/mmx.h:379:28: note: instantiated from: #define movq_r2m(reg, var) mmx_r2m(movq, reg, var) ^ :192:1: note: instantiated from: "movq" ^ :1:2: note: instantiated into assembly here movq %mm3, %dx ^ -------------------------------------------------- According to the clang developers this is a invalid inline assembly. Using the attached patch from the last commit in the below bug report fixes the compile. More details from: http://llvm.org/bugs/show_bug.cgi?id=6730 --- src/video/mmx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/mmx.h b/src/video/mmx.h index 86190d473..3bd00ac23 100644 --- a/src/video/mmx.h +++ b/src/video/mmx.h @@ -293,7 +293,7 @@ mmx_ok(void) #define mmx_r2m(op, reg, mem) \ __asm__ __volatile__ (#op " %%" #reg ", %0" \ - : "=X" (mem) \ + : "=m" (mem) \ : /* nothing */ ) #define mmx_r2r(op, regs, regd) \