Fixed broken rotation detection routines on WinRT
authorDavid Ludwig
Sat, 15 Mar 2014 14:54:23 -0400
changeset 86215252788cb448
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
     1.1 --- a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj	Sat Mar 15 13:27:18 2014 -0400
     1.2 +++ b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj	Sat Mar 15 14:54:23 2014 -0400
     1.3 @@ -320,7 +320,12 @@
     1.4      <ClCompile Include="..\..\src\power\SDL_power.c" />
     1.5      <ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
     1.6      <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
     1.7 -    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp" />
     1.8 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp">
     1.9 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.10 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.11 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.12 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.13 +    </ClCompile>
    1.14      <ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
    1.15      <ClCompile Include="..\..\src\render\SDL_render.c" />
    1.16      <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
     2.1 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Sat Mar 15 13:27:18 2014 -0400
     2.2 +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Sat Mar 15 14:54:23 2014 -0400
     2.3 @@ -100,7 +100,14 @@
     2.4      <ClCompile Include="..\..\src\power\SDL_power.c" />
     2.5      <ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
     2.6      <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
     2.7 -    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp" />
     2.8 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp">
     2.9 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    2.10 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    2.11 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    2.12 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    2.13 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    2.14 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    2.15 +    </ClCompile>
    2.16      <ClCompile Include="..\..\src\render\opengles2\SDL_render_gles2.c" />
    2.17      <ClCompile Include="..\..\src\render\opengles2\SDL_shaders_gles2.c" />
    2.18      <ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
     3.1 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp	Sat Mar 15 13:27:18 2014 -0400
     3.2 +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp	Sat Mar 15 14:54:23 2014 -0400
     3.3 @@ -163,7 +163,11 @@
     3.4      // for details.  Microsoft's "Display orientation sample" also gives an
     3.5      // outline of how Windows treats device rotation
     3.6      // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
     3.7 +#if NTDDI_VERSION > NTDDI_WIN8
     3.8 +    DisplayInformation::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
     3.9 +#else
    3.10      DisplayProperties::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
    3.11 +#endif
    3.12  }
    3.13  
    3.14  static void
    3.15 @@ -283,20 +287,13 @@
    3.16  
    3.17      CoreApplication::Exiting +=
    3.18          ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnExiting);
    3.19 -
    3.20 -    DisplayProperties::OrientationChanged +=
    3.21 -        ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
    3.22 -
    3.23 -    // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.  This needs to be
    3.24 -    // done before the hint's callback is registered (as of Feb 22, 2013),
    3.25 -    // otherwise the hint callback won't get registered.
    3.26 -    //
    3.27 -    // 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.
    3.28 -    //SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown");   // DavidL: this is no longer needed (for SDL_AddHintCallback)
    3.29 -    SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
    3.30  }
    3.31  
    3.32 +#if NTDDI_VERSION > NTDDI_WIN8
    3.33 +void SDL_WinRTApp::OnOrientationChanged(DisplayInformation^ sender, Object^ args)
    3.34 +#else
    3.35  void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
    3.36 +#endif
    3.37  {
    3.38  #if LOG_ORIENTATION_EVENTS==1
    3.39      CoreWindow^ window = CoreWindow::GetForCurrentThread();
    3.40 @@ -379,6 +376,18 @@
    3.41          ref new EventHandler<BackPressedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
    3.42  #endif
    3.43  
    3.44 +#if NTDDI_VERSION > NTDDI_WIN8
    3.45 +    DisplayInformation::GetForCurrentView()->OrientationChanged +=
    3.46 +        ref new TypedEventHandler<Windows::Graphics::Display::DisplayInformation^, Object^>(this, &SDL_WinRTApp::OnOrientationChanged);
    3.47 +#else
    3.48 +    DisplayProperties::OrientationChanged +=
    3.49 +        ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
    3.50 +#endif
    3.51 +
    3.52 +    // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.
    3.53 +    // 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.
    3.54 +    SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
    3.55 +
    3.56  #if WINAPI_FAMILY == WINAPI_FAMILY_APP  // for Windows 8/8.1/RT apps... (and not Phone apps)
    3.57      // Make sure we know when a user has opened the app's settings pane.
    3.58      // This is needed in order to display a privacy policy, which needs
     4.1 --- a/src/core/winrt/SDL_winrtapp_direct3d.h	Sat Mar 15 13:27:18 2014 -0400
     4.2 +++ b/src/core/winrt/SDL_winrtapp_direct3d.h	Sat Mar 15 14:54:23 2014 -0400
     4.3 @@ -47,7 +47,11 @@
     4.4          Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args);
     4.5  #endif // if WINAPI_FAMILY == WINAPI_FAMILY_APP
     4.6  
     4.7 +#if NTDDI_VERSION > NTDDI_WIN8
     4.8 +    void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
     4.9 +#else
    4.10      void OnOrientationChanged(Platform::Object^ sender);
    4.11 +#endif
    4.12      void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
    4.13      void OnLogicalDpiChanged(Platform::Object^ sender);
    4.14      void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
     5.1 --- a/src/render/direct3d11/SDL_render_winrt.cpp	Sat Mar 15 13:27:18 2014 -0400
     5.2 +++ b/src/render/direct3d11/SDL_render_winrt.cpp	Sat Mar 15 14:54:23 2014 -0400
     5.3 @@ -34,7 +34,6 @@
     5.4  #include <windows.ui.xaml.media.dxinterop.h>
     5.5  #endif
     5.6  
     5.7 -using namespace ABI;
     5.8  using namespace Windows::UI::Core;
     5.9  using namespace Windows::Graphics::Display;
    5.10  
    5.11 @@ -80,8 +79,14 @@
    5.12  extern "C" DXGI_MODE_ROTATION
    5.13  D3D11_GetCurrentRotation()
    5.14  {
    5.15 -#if 0 /* FIXME: This doesn't compile on Visual Studio 2013 */
    5.16 -    switch (DisplayProperties::CurrentOrientation) {
    5.17 +#if NTDDI_VERSION > NTDDI_WIN8
    5.18 +    const DisplayOrientations currentOrientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
    5.19 +#else
    5.20 +    const DisplayOrientations currentOrientation = DisplayProperties::CurrentOrientation;
    5.21 +#endif
    5.22 +
    5.23 +    switch (currentOrientation) {
    5.24 +
    5.25  #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    5.26      /* Windows Phone rotations */
    5.27      case DisplayOrientations::Landscape:
    5.28 @@ -104,7 +109,7 @@
    5.29          return DXGI_MODE_ROTATION_ROTATE90;
    5.30  #endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
    5.31      }
    5.32 -#endif
    5.33 +
    5.34      return DXGI_MODE_ROTATION_IDENTITY;
    5.35  }
    5.36  
     6.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Sat Mar 15 13:27:18 2014 -0400
     6.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Sat Mar 15 14:54:23 2014 -0400
     6.3 @@ -163,7 +163,11 @@
     6.4  
     6.5      // Calculate the display size given the window size, taking into account
     6.6      // the current display's DPI:
     6.7 -    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; 
     6.8 +#if NTDDI_VERSION > NTDDI_WIN8
     6.9 +    const float currentDPI = DisplayInformation::GetForCurrentView()->LogicalDpi;
    6.10 +#else
    6.11 +    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
    6.12 +#endif
    6.13      const float dipsPerInch = 96.0f;
    6.14      const int w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
    6.15      const int h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
    6.16 @@ -185,7 +189,11 @@
    6.17      mode->w = w;
    6.18      mode->h = h;
    6.19      mode->driverdata = driverdata;
    6.20 +#if NTDDI_VERSION > NTDDI_WIN8
    6.21 +    driverdata->currentOrientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
    6.22 +#else
    6.23      driverdata->currentOrientation = DisplayProperties::CurrentOrientation;
    6.24 +#endif
    6.25  
    6.26  #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    6.27      // On Windows Phone, the native window's size is always in portrait,