Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Include windows.h in a single point in the source, so we can be consi…

…stent 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
  • Loading branch information
slouken committed Jan 25, 2011
1 parent cc33ffa commit 6b41c2c5262f2c5c5310c9854df501a6210af023
Showing with 273 additions and 272 deletions.
  1. +12 −11 Android.mk
  2. +16 −8 VisualC/SDL/SDL_VS2008.vcproj
  3. +3 −1 VisualC/SDL/SDL_VS2010.vcxproj
  4. +8 −0 VisualCE/SDL/SDL.vcproj
  5. +1 −2 src/SDL.c
  6. +1 −8 src/SDL_assert.c
  7. +2 −9 src/atomic/SDL_spinlock.c
  8. +1 −1 src/audio/android/SDL_androidaudio.c
  9. +1 −9 src/audio/windib/SDL_dibaudio.c
  10. +9 −9 src/audio/windx5/SDL_dx5audio.c
  11. +1 −2 src/audio/windx5/directx.h
  12. 0 src/{ → core/android}/SDL_android.cpp
  13. 0 src/{ → core/android}/SDL_android.h
  14. +41 −0 src/core/windows/SDL_windows.c
  15. +53 −0 src/core/windows/SDL_windows.h
  16. +1 −2 src/cpuinfo/SDL_cpuinfo.c
  17. +13 −20 src/file/SDL_rwops.c
  18. +14 −1 src/haptic/windows/SDL_syshaptic.c
  19. +1 −1 src/joystick/android/SDL_sysjoystick.c
  20. +12 −2 src/joystick/windows/SDL_dxjoystick.c
  21. +1 −2 src/joystick/windows/SDL_dxjoystick_c.h
  22. +1 −2 src/joystick/windows/SDL_mmjoystick.c
  23. +20 −85 src/loadso/windows/SDL_sysloadso.c
  24. +1 −2 src/power/windows/SDL_syspower.c
  25. +5 −6 src/stdlib/SDL_getenv.c
  26. +1 −2 src/thread/windows/SDL_sysmutex.c
  27. +1 −2 src/thread/windows/SDL_syssem.c
  28. +1 −2 src/thread/windows/SDL_systhread_c.h
  29. +1 −2 src/thread/windows/win_ce_semaphore.c
  30. +1 −2 src/timer/wince/SDL_systimer.c
  31. +1 −2 src/timer/windows/SDL_systimer.c
  32. +1 −1 src/video/android/SDL_androidgl.c
  33. +13 −13 src/video/windows/SDL_gapirender.c
  34. +10 −10 src/video/windows/SDL_windowskeyboard.c
  35. +1 −1 src/video/windows/SDL_windowsopengl.c
  36. +17 −30 src/video/windows/SDL_windowsvideo.c
  37. +7 −22 src/video/windows/SDL_windowsvideo.h
@@ -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

@@ -1150,6 +1150,22 @@
RelativePath="..\..\src\audio\SDL_wave.h"
>
</File>
<File
RelativePath="..\..\src\events\SDL_windowevents.c"
>
</File>
<File
RelativePath="..\..\src\events\SDL_windowevents_c.h"
>
</File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.c"
>
</File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.h"
>
</File>
<File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
>
@@ -1230,14 +1246,6 @@
RelativePath="..\..\src\video\windows\SDL_windowswindow.h"
>
</File>
<File
RelativePath="..\..\src\events\SDL_windowevents.c"
>
</File>
<File
RelativePath="..\..\src\events\SDL_windowevents_c.h"
>
</File>
<File
RelativePath="..\..\src\video\SDL_yuv_mmx.c"
>
@@ -272,6 +272,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClInclude Include="..\..\include\SDL_types.h" />
<ClInclude Include="..\..\include\SDL_version.h" />
<ClInclude Include="..\..\include\SDL_video.h" />
<ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
<ClInclude Include="..\..\src\events\blank_cursor.h" />
<ClInclude Include="..\..\src\events\default_cursor.h" />
<ClInclude Include="..\..\src\audio\windx5\directx.h" />
@@ -345,6 +346,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClInclude Include="..\..\src\video\windows\wmmsg.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
<ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
<ClCompile Include="..\..\src\events\SDL_gesture.c" />
<ClCompile Include="..\..\src\events\SDL_touch.c" />
@@ -460,4 +462,4 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
@@ -1053,6 +1053,10 @@
RelativePath="..\..\src\events\SDL_windowevents.c"
>
</File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.c"
>
</File>
<File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
>
@@ -1358,6 +1362,10 @@
RelativePath="..\..\src\events\SDL_windowevents_c.h"
>
</File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.h"
>
</File>
<File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.h"
>
@@ -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 <windows.h>
#include "core/windows/SDL_windows.h"

BOOL APIENTRY
_DllMainCRTStartup(HANDLE hModule,
@@ -27,18 +27,11 @@
#include "video/SDL_sysvideo.h"

#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#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 <stdio.h>
#include <stdlib.h>
@@ -25,22 +25,15 @@
#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 <windows.h>
#else
#include <intrin.h>
#endif
#endif /* _MSC_VER */
#include "../core/windows/SDL_windows.h"

/* This function is where all the magic happens... */
SDL_bool
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);
@@ -27,7 +27,7 @@
#include "../SDL_audio_c.h"
#include "SDL_androidaudio.h"

#include "../../SDL_android.h"
#include "../../core/android/SDL_android.h"

#include <android/log.h>

@@ -23,8 +23,7 @@

/* Allow access to a raw mixing buffer */

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "../../core/windows/SDL_windows.h"
#include <mmsystem.h>

#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);
}
@@ -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)
{
DSoundCreate = NULL;

if (DSoundDLL != NULL) {
FreeLibrary(DSoundDLL);
SDL_UnloadObject(DSoundDLL);
DSoundDLL = NULL;
}

DSoundCreate = NULL;
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) {
@@ -4,8 +4,7 @@

/* Include all of the DirectX 5.0 headers and adds any necessary tweaks */

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "../../core/windows/SDL_windows.h"
#include <mmsystem.h>
#ifndef WIN32
#define WIN32
File renamed without changes.
File renamed without changes.
@@ -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: */
@@ -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 <windows.h>


/* 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: */
@@ -39,8 +39,7 @@
#include <setjmp.h>
#endif
#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "../core/windows/SDL_windows.h"
#endif

#define CPU_HAS_RDTSC 0x00000001

0 comments on commit 6b41c2c

Please sign in to comment.