Skip to content
Permalink
Browse files

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).
  • Loading branch information
DavidLudwig committed Mar 15, 2014
1 parent 5281f9f commit f25ee50b036b59953cd1e7ce894486f0b6e4df64
@@ -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" />
@@ -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" />
@@ -163,7 +163,11 @@ static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *n
// 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 @@ void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)

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 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window)
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
@@ -47,7 +47,11 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo
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);
@@ -34,7 +34,6 @@ extern "C" {
#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 @@ D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
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 @@ D3D11_GetCurrentRotation()
return DXGI_MODE_ROTATION_ROTATE90;
#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
}
#endif

return DXGI_MODE_ROTATION_IDENTITY;
}

@@ -163,7 +163,11 @@ WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode)

// 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 @@ WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode)
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,

0 comments on commit f25ee50

Please sign in to comment.