WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
authorDavid Ludwig <dludwig@pobox.com>
Tue, 13 Aug 2013 20:09:52 -0400
changeset 8478 337b5dc0797b
parent 8477 ad08f0d710f3
child 8479 f92a250b4a3f
WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
include/SDL_config_windowsrt.h
include/SDL_platform.h
include/SDL_stdinc.h
src/SDL_log.c
src/audio/xaudio2/SDL_xaudio2.c
src/joystick/SDL_gamecontrollerdb.h
src/render/SDL_render.c
src/stdlib/SDL_stdlib.c
src/thread/stdcpp/SDL_systhread.cpp
src/timer/windows/SDL_systimer.c
src/video/windowsrt/SDL_WinRTApp.cpp
--- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Mon Aug 12 22:29:55 2013 -0400
+++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Tue Aug 13 20:09:52 2013 -0400
@@ -100,11 +100,11 @@
     <ClCompile Include="..\..\src\SDL.c" />
     <ClCompile Include="..\..\src\SDL_assert.c" />
     <ClCompile Include="..\..\src\SDL_error.c" />
-    <ClCompile Include="..\..\src\SDL_fatal.c" />
     <ClCompile Include="..\..\src\SDL_hints.c" />
     <ClCompile Include="..\..\src\SDL_log.c" />
     <ClCompile Include="..\..\src\stdlib\SDL_getenv.c" />
     <ClCompile Include="..\..\src\stdlib\SDL_iconv.c" />
+    <ClCompile Include="..\..\src\stdlib\SDL_malloc.c" />
     <ClCompile Include="..\..\src\stdlib\SDL_qsort.c" />
     <ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" />
     <ClCompile Include="..\..\src\stdlib\SDL_string.c" />
@@ -239,6 +239,7 @@
     <ClInclude Include="..\..\src\events\SDL_windowevents_c.h" />
     <ClInclude Include="..\..\src\haptic\SDL_haptic_c.h" />
     <ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
+    <ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
     <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
     <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
     <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h" />
--- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Mon Aug 12 22:29:55 2013 -0400
+++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Tue Aug 13 20:09:52 2013 -0400
@@ -96,9 +96,6 @@
     <ClCompile Include="..\..\src\events\SDL_events.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\src\SDL_fatal.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\src\video\SDL_fillrect.c">
       <Filter>Source Files</Filter>
     </ClCompile>
@@ -267,6 +264,9 @@
     <ClCompile Include="..\..\src\joystick\windowsrt\SDL_xinputjoystick.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\stdlib\SDL_malloc.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\include\begin_code.h">
@@ -593,6 +593,9 @@
     <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h">
       <Filter>Source Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Header Files">
--- a/include/SDL_config_windowsrt.h	Mon Aug 12 22:29:55 2013 -0400
+++ b/include/SDL_config_windowsrt.h	Tue Aug 13 20:09:52 2013 -0400
@@ -83,6 +83,7 @@
 #define HAVE_STRING_H 1
 #define HAVE_CTYPE_H 1
 #define HAVE_MATH_H 1
+#define HAVE_FLOAT_H 1
 #define HAVE_SIGNAL_H 1
 
 /* C library functions */
@@ -123,7 +124,7 @@
 #define HAVE_ATAN 1
 #define HAVE_ATAN2 1
 #define HAVE_CEIL 1
-//#define HAVE_COPYSIGN 1   // TODO, WinRT: consider using _copysign instead
+#define HAVE__COPYSIGN 1
 #define HAVE_COS 1
 #define HAVE_COSF 1
 #define HAVE_FABS 1
@@ -131,6 +132,7 @@
 #define HAVE_LOG 1
 #define HAVE_POW 1
 //#define HAVE_SCALBN 1
+#define HAVE__SCALB 1
 #define HAVE_SIN 1
 #define HAVE_SINF 1
 #define HAVE_SQRT 1
--- a/include/SDL_platform.h	Mon Aug 12 22:29:55 2013 -0400
+++ b/include/SDL_platform.h	Tue Aug 13 20:09:52 2013 -0400
@@ -120,10 +120,27 @@
 #undef __SOLARIS__
 #define __SOLARIS__ 1
 #endif
-#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
-#undef __WIN32__
-#define __WIN32__   1
-#endif
+
+#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
+/* Try to find out what version of Windows we are compiling for */
+#if defined(_MSC_VER) && (_MSC_VER >= 1700)	/* _MSC_VER==1700 for MSVC 2012 */
+#include <winapifamily.h>
+#endif
+/* Default to classic, Win32 / Desktop compilation either if:
+     1. the version of Windows is explicity set to a 'Desktop' (non-Metro) app
+     2. the version of Windows cannot be determined via winapifamily.h
+   If neither is true, see if we're compiling for WinRT.
+ */
+#if ! defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#undef __WIN32__
+#define __WIN32__   1
+/* See if we're compiling for WinRT: */
+#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
+#undef __WINRT__
+#define __WINRT__ 1
+#endif /* ! defined(WINAPI_FAMILY_PARTITION) */
+#endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */
+
 #if defined(__PSP__)
 #undef __PSP__
 #define __PSP__ 1
--- a/include/SDL_stdinc.h	Mon Aug 12 22:29:55 2013 -0400
+++ b/include/SDL_stdinc.h	Tue Aug 13 20:09:52 2013 -0400
@@ -80,6 +80,9 @@
 # endif
 # include <math.h>
 #endif
+#ifdef HAVE_FLOAT_H
+# include <float.h>
+#endif
 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
 # include <iconv.h>
 #endif
--- a/src/SDL_log.c	Mon Aug 12 22:29:55 2013 -0400
+++ b/src/SDL_log.c	Tue Aug 13 20:09:52 2013 -0400
@@ -322,6 +322,8 @@
         char *output;
         size_t length;
         LPTSTR tstr;
+
+#ifndef __WINRT__
         BOOL attachResult;
         DWORD attachError;
         unsigned long charsWritten; 
@@ -353,6 +355,7 @@
                         stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
                 }
         }
+#endif /* ifndef __WINRT__ */
 
         length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1;
         output = SDL_stack_alloc(char, length);
@@ -362,6 +365,7 @@
         /* Output to debugger */
         OutputDebugString(tstr);
        
+#ifndef __WINRT__
         /* Screen output to stderr, if console was attached. */
         if (consoleAttached == 1) {
                 if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
@@ -371,6 +375,7 @@
                     OutputDebugString(TEXT("Insufficient heap memory to write message"));
                 }
         }
+#endif /* ifndef __WINRT__ */
 
         SDL_free(tstr);
         SDL_stack_free(output);
--- a/src/audio/xaudio2/SDL_xaudio2.c	Mon Aug 12 22:29:55 2013 -0400
+++ b/src/audio/xaudio2/SDL_xaudio2.c	Tue Aug 13 20:09:52 2013 -0400
@@ -91,15 +91,11 @@
 }
 #endif
 
-#if defined(__WINRT__)
-#  define SDL_XAUDIO2_HAS_SDK 1
-#endif
-#if defined(__WIN32__)
 #ifdef __GNUC__
 /* The configure script already did any necessary checking */
 #  define SDL_XAUDIO2_HAS_SDK 1
 #elif defined(__WINRT__)
-/* WinRT always has access to the .the XAudio 2 SD
+/* WinRT always has access to the .the XAudio 2 SDK */
 #  define SDL_XAUDIO2_HAS_SDK
 #else
 #include <dxsdkver.h> /* XAudio2 exists as of the March 2008 DirectX SDK */
--- a/src/joystick/SDL_gamecontrollerdb.h	Mon Aug 12 22:29:55 2013 -0400
+++ b/src/joystick/SDL_gamecontrollerdb.h	Tue Aug 13 20:09:52 2013 -0400
@@ -38,6 +38,8 @@
     "4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
     "25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,",
     "xinput,X360 Controller,a:b10,b:b11,back:b5,dpdown:b1,dpleft:b2,dpright:b3,dpup:b0,guide:b14,leftshoulder:b8,leftstick:b6,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,rightstick:b7,righttrigger:a5,rightx:a2,righty:a3,start:b4,x:b12,y:b13,",
+#elif defined(SDL_JOYSTICK_XINPUT)
+    "xinput,X360 Controller,a:b10,b:b11,back:b5,dpdown:b1,dpleft:b2,dpright:b3,dpup:b0,guide:b14,leftshoulder:b8,leftstick:b6,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,rightstick:b7,righttrigger:a5,rightx:a2,righty:a3,start:b4,x:b12,y:b13,",
 #elif defined(__MACOSX__)
     "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
     "6d0400000000000016c2000000000000,Logitech F310 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
--- a/src/render/SDL_render.c	Mon Aug 12 22:29:55 2013 -0400
+++ b/src/render/SDL_render.c	Tue Aug 13 20:09:52 2013 -0400
@@ -49,6 +49,9 @@
 #if SDL_VIDEO_RENDER_D3D
     &D3D_RenderDriver,
 #endif
+#if SDL_VIDEO_RENDER_D3D11
+    &D3D11_RenderDriver,
+#endif
 #if SDL_VIDEO_RENDER_OGL
     &GL_RenderDriver,
 #endif
--- a/src/stdlib/SDL_stdlib.c	Mon Aug 12 22:29:55 2013 -0400
+++ b/src/stdlib/SDL_stdlib.c	Tue Aug 13 20:09:52 2013 -0400
@@ -61,6 +61,8 @@
 {
 #if defined(HAVE_COPYSIGN)
     return copysign(x, y);
+#elif defined(HAVE__COPYSIGN)
+    return _copysign(x, y);
 #else
     return SDL_uclibc_copysign(x, y);
 #endif /* HAVE_COPYSIGN */
@@ -131,6 +133,8 @@
 {
 #if defined(HAVE_SCALBN)
     return scalbn(x, n);
+#elif defined(HAVE__SCALB)
+    return _scalb(x, n);
 #else
     return SDL_uclibc_scalbn(x, n);
 #endif /* HAVE_SCALBN */
--- a/src/thread/stdcpp/SDL_systhread.cpp	Mon Aug 12 22:29:55 2013 -0400
+++ b/src/thread/stdcpp/SDL_systhread.cpp	Tue Aug 13 20:09:52 2013 -0400
@@ -24,8 +24,8 @@
 
 extern "C" {
 #include "SDL_thread.h"
+#include "../SDL_thread_c.h"
 #include "../SDL_systhread.h"
-#include "../SDL_thread_c.h"
 #include "SDL_log.h"
 }
 
@@ -121,4 +121,18 @@
     }
 }
 
+extern "C"
+SDL_TLSData *
+SDL_SYS_GetTLSData()
+{
+    return SDL_Generic_GetTLSData();
+}
+
+extern "C"
+int
+SDL_SYS_SetTLSData(SDL_TLSData *data)
+{
+    return SDL_Generic_SetTLSData(data);
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/timer/windows/SDL_systimer.c	Mon Aug 12 22:29:55 2013 -0400
+++ b/src/timer/windows/SDL_systimer.c	Tue Aug 13 20:09:52 2013 -0400
@@ -41,6 +41,7 @@
 static LARGE_INTEGER hires_ticks_per_second;
 #endif
 
+#ifndef __WINRT__
 static void
 timeSetPeriod(UINT uPeriod)
 {
@@ -74,6 +75,7 @@
         timeSetPeriod(uPeriod);
     }
 }
+#endif /* ifndef __WINRT__ */
 
 void
 SDL_StartTicks(void)
@@ -90,13 +92,19 @@
         QueryPerformanceCounter(&hires_start_ticks);
     } else {
         hires_timer_available = FALSE;
+#ifdef __WINRT__
+        start = 0;            /* the timer failed to start! */
+#else
         timeSetPeriod(1);     /* use 1 ms timer precision */
         start = timeGetTime();
+#endif /* ifdef __WINRT__ */
     }
 #endif
 
+#ifndef __WINRT__
     SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
                         SDL_TimerResolutionChanged, NULL);
+#endif
 }
 
 Uint32
@@ -119,7 +127,11 @@
 
         return (DWORD) hires_now.QuadPart;
     } else {
+#ifdef __WINRT__
+        now = 0;
+#else
         now = timeGetTime();
+#endif // ifdef __WINRT__
     }
 #endif
 
@@ -148,6 +160,19 @@
     return frequency.QuadPart;
 }
 
+#ifdef __WINRT__
+static void
+Sleep(DWORD timeout)
+{
+    static HANDLE mutex = 0;
+    if ( ! mutex )
+    {
+        mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
+    }
+    WaitForSingleObjectEx(mutex, timeout, FALSE);
+}
+#endif
+
 void
 SDL_Delay(Uint32 ms)
 {
--- a/src/video/windowsrt/SDL_WinRTApp.cpp	Mon Aug 12 22:29:55 2013 -0400
+++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Tue Aug 13 20:09:52 2013 -0400
@@ -13,7 +13,7 @@
 #include "SDL_stdinc.h"
 #include "SDL_render.h"
 #include "../SDL_sysvideo.h"
-#include "../../SDL_hints_c.h"
+//#include "../../SDL_hints_c.h"
 #include "../../events/scancodes_windows.h"
 #include "../../events/SDL_mouse_c.h"
 #include "../../events/SDL_keyboard_c.h"
@@ -86,7 +86,7 @@
     return 0;
 }
 
-static void WINRT_SetDisplayOrientationsPreference(const char *name, const char *oldValue, const char *newValue)
+static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
 {
     SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
 
@@ -163,8 +163,8 @@
     // otherwise the hint callback won't get registered.
     //
     // WinRT, TODO: see if an app's default orientation can be found out via WinRT API(s), then set the initial value of SDL_HINT_ORIENTATIONS accordingly.
-    SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown");
-    SDL_RegisterHintChangedCb(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference);
+    //SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown");   // DavidL: this is no longer needed (for SDL_AddHintCallback)
+    SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
 }
 
 void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
@@ -316,15 +316,19 @@
         // Windows device.
         //
         // Commencing hack in 3... 2... 1...
-        SDL_Renderer * rendererForMainWindow = SDL_GetRenderer(m_sdlWindowData->sdlWindow);
+        //
+        // UPDATE, SDL 2.0.0 update: the 'resized' flag is now gone.  This
+        // hack might not be necessary any more.
+        //
+        //SDL_Renderer * rendererForMainWindow = SDL_GetRenderer(m_sdlWindowData->sdlWindow);
         // For now, limit the hack to when the Direct3D 11.1 is getting used:
-        const bool usingD3D11Renderer = \
-            (rendererForMainWindow != NULL) &&
-            (SDL_strcmp(rendererForMainWindow->info.name, "direct3d 11.1") == 0);
-        SDL_bool wasD3D11RendererResized = SDL_FALSE;
-        if (usingD3D11Renderer) {
-            wasD3D11RendererResized = rendererForMainWindow->resized;
-        }
+        //const bool usingD3D11Renderer = \
+        //    (rendererForMainWindow != NULL) &&
+        //    (SDL_strcmp(rendererForMainWindow->info.name, "direct3d 11.1") == 0);
+        //SDL_bool wasD3D11RendererResized = SDL_FALSE;
+        //if (usingD3D11Renderer) {
+        //    wasD3D11RendererResized = rendererForMainWindow->resized;
+        //}
 
         // Send the window-resize event to the rest of SDL, and to apps:
         const int windowWidth = (int) ceil(args->Size.Width);
@@ -335,10 +339,10 @@
             windowWidth,
             windowHeight);
 
-        // Viewport hack, part two:
-        if (usingD3D11Renderer) {
-            rendererForMainWindow->resized = wasD3D11RendererResized;
-        }
+        //// Viewport hack, part two:
+        //if (usingD3D11Renderer) {
+        //    rendererForMainWindow->resized = wasD3D11RendererResized;
+        //}
     }
 }