Fixed broken rotation detection routines on WinRT
authorDavid Ludwig <dludwig@pobox.com>
Sat, 15 Mar 2014 14:54:23 -0400
changeset 8621 5252788cb448
parent 8620 a27695b26b57
child 8622 957fbefc8556
Fixed broken rotation detection routines on WinRT Rotation detection and handling should now work across all, publicly-released, WinRT-based platforms (Windows 8.0, Windows 8.1, and Windows Phone 8.0).
VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
src/core/winrt/SDL_winrtapp_direct3d.cpp
src/core/winrt/SDL_winrtapp_direct3d.h
src/render/direct3d11/SDL_render_winrt.cpp
src/video/winrt/SDL_winrtvideo.cpp
--- a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj	Sat Mar 15 13:27:18 2014 -0400
+++ b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj	Sat Mar 15 14:54:23 2014 -0400
@@ -320,7 +320,12 @@
     <ClCompile Include="..\..\src\power\SDL_power.c" />
     <ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
     <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
-    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp" />
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp">
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+    </ClCompile>
     <ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
     <ClCompile Include="..\..\src\render\SDL_render.c" />
     <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
--- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Sat Mar 15 13:27:18 2014 -0400
+++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Sat Mar 15 14:54:23 2014 -0400
@@ -100,7 +100,14 @@
     <ClCompile Include="..\..\src\power\SDL_power.c" />
     <ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
     <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
-    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp" />
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp">
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
+    </ClCompile>
     <ClCompile Include="..\..\src\render\opengles2\SDL_render_gles2.c" />
     <ClCompile Include="..\..\src\render\opengles2\SDL_shaders_gles2.c" />
     <ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
--- a/src/core/winrt/SDL_winrtapp_direct3d.cpp	Sat Mar 15 13:27:18 2014 -0400
+++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp	Sat Mar 15 14:54:23 2014 -0400
@@ -163,7 +163,11 @@
     // for details.  Microsoft's "Display orientation sample" also gives an
     // outline of how Windows treats device rotation
     // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
+#if NTDDI_VERSION > NTDDI_WIN8
+    DisplayInformation::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
+#else
     DisplayProperties::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
+#endif
 }
 
 static void
@@ -283,20 +287,13 @@
 
     CoreApplication::Exiting +=
         ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnExiting);
-
-    DisplayProperties::OrientationChanged +=
-        ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
-
-    // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.  This needs to be
-    // done before the hint's callback is registered (as of Feb 22, 2013),
-    // otherwise the hint callback won't get registered.
-    //
-    // TODO, WinRT: 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");   // DavidL: this is no longer needed (for SDL_AddHintCallback)
-    SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
 }
 
+#if NTDDI_VERSION > NTDDI_WIN8
+void SDL_WinRTApp::OnOrientationChanged(DisplayInformation^ sender, Object^ args)
+#else
 void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
+#endif
 {
 #if LOG_ORIENTATION_EVENTS==1
     CoreWindow^ window = CoreWindow::GetForCurrentThread();
@@ -379,6 +376,18 @@
         ref new EventHandler<BackPressedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
 #endif
 
+#if NTDDI_VERSION > NTDDI_WIN8
+    DisplayInformation::GetForCurrentView()->OrientationChanged +=
+        ref new TypedEventHandler<Windows::Graphics::Display::DisplayInformation^, Object^>(this, &SDL_WinRTApp::OnOrientationChanged);
+#else
+    DisplayProperties::OrientationChanged +=
+        ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
+#endif
+
+    // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.
+    // TODO, WinRT: 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_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
+
 #if WINAPI_FAMILY == WINAPI_FAMILY_APP  // for Windows 8/8.1/RT apps... (and not Phone apps)
     // Make sure we know when a user has opened the app's settings pane.
     // This is needed in order to display a privacy policy, which needs
--- a/src/core/winrt/SDL_winrtapp_direct3d.h	Sat Mar 15 13:27:18 2014 -0400
+++ b/src/core/winrt/SDL_winrtapp_direct3d.h	Sat Mar 15 14:54:23 2014 -0400
@@ -47,7 +47,11 @@
         Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args);
 #endif // if WINAPI_FAMILY == WINAPI_FAMILY_APP
 
+#if NTDDI_VERSION > NTDDI_WIN8
+    void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
+#else
     void OnOrientationChanged(Platform::Object^ sender);
+#endif
     void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
     void OnLogicalDpiChanged(Platform::Object^ sender);
     void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
--- a/src/render/direct3d11/SDL_render_winrt.cpp	Sat Mar 15 13:27:18 2014 -0400
+++ b/src/render/direct3d11/SDL_render_winrt.cpp	Sat Mar 15 14:54:23 2014 -0400
@@ -34,7 +34,6 @@
 #include <windows.ui.xaml.media.dxinterop.h>
 #endif
 
-using namespace ABI;
 using namespace Windows::UI::Core;
 using namespace Windows::Graphics::Display;
 
@@ -80,8 +79,14 @@
 extern "C" DXGI_MODE_ROTATION
 D3D11_GetCurrentRotation()
 {
-#if 0 /* FIXME: This doesn't compile on Visual Studio 2013 */
-    switch (DisplayProperties::CurrentOrientation) {
+#if NTDDI_VERSION > NTDDI_WIN8
+    const DisplayOrientations currentOrientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
+#else
+    const DisplayOrientations currentOrientation = DisplayProperties::CurrentOrientation;
+#endif
+
+    switch (currentOrientation) {
+
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     /* Windows Phone rotations */
     case DisplayOrientations::Landscape:
@@ -104,7 +109,7 @@
         return DXGI_MODE_ROTATION_ROTATE90;
 #endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
     }
-#endif
+
     return DXGI_MODE_ROTATION_IDENTITY;
 }
 
--- a/src/video/winrt/SDL_winrtvideo.cpp	Sat Mar 15 13:27:18 2014 -0400
+++ b/src/video/winrt/SDL_winrtvideo.cpp	Sat Mar 15 14:54:23 2014 -0400
@@ -163,7 +163,11 @@
 
     // Calculate the display size given the window size, taking into account
     // the current display's DPI:
-    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; 
+#if NTDDI_VERSION > NTDDI_WIN8
+    const float currentDPI = DisplayInformation::GetForCurrentView()->LogicalDpi;
+#else
+    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
+#endif
     const float dipsPerInch = 96.0f;
     const int w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
     const int h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
@@ -185,7 +189,11 @@
     mode->w = w;
     mode->h = h;
     mode->driverdata = driverdata;
+#if NTDDI_VERSION > NTDDI_WIN8
+    driverdata->currentOrientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
+#else
     driverdata->currentOrientation = DisplayProperties::CurrentOrientation;
+#endif
 
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     // On Windows Phone, the native window's size is always in portrait,