WinRT: minor rotation/orientation code cleanup in the d3d11 renderer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/src/render/direct3d11/SDL_render_d3d11.cpp b/src/render/direct3d11/SDL_render_d3d11.cpp
index fd5d662..4942a67 100644
--- a/src/render/direct3d11/SDL_render_d3d11.cpp
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp
@@ -1062,6 +1062,18 @@ D3D11_GetRotationForOrientation(Windows::Graphics::Display::DisplayOrientations
}
}
+static bool
+D3D11_IsDisplayRotated90Degrees(Windows::Graphics::Display::DisplayOrientations orientation)
+{
+ switch (D3D11_GetRotationForOrientation(orientation)) {
+ case DXGI_MODE_ROTATION_ROTATE90:
+ case DXGI_MODE_ROTATION_ROTATE270:
+ return true;
+ default:
+ return false;
+ }
+}
+
// Initialize all resources that change when the window's size changes.
// TODO, WinRT: get D3D11_CreateWindowSizeDependentResources working on Win32
HRESULT
@@ -1108,9 +1120,7 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
const bool swapDimensions = false;
#else
- const bool swapDimensions =
- data->orientation == DisplayOrientations::Portrait ||
- data->orientation == DisplayOrientations::PortraitFlipped;
+ const bool swapDimensions = D3D11_IsDisplayRotated90Degrees(data->orientation);
#endif
data->renderTargetSize.x = swapDimensions ? windowHeight : windowWidth;
data->renderTargetSize.y = swapDimensions ? windowWidth : windowHeight;
@@ -1687,16 +1697,7 @@ D3D11_UpdateViewport(SDL_Renderer * renderer)
// for Windows Phone devices.
//
SDL_FRect orientationAlignedViewport;
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
- const bool swapDimensions =
- data->orientation == DisplayOrientations::Landscape ||
- data->orientation == DisplayOrientations::LandscapeFlipped;
-#else
- const bool swapDimensions =
- data->orientation == DisplayOrientations::Portrait ||
- data->orientation == DisplayOrientations::PortraitFlipped;
-#endif
+ const bool swapDimensions = D3D11_IsDisplayRotated90Degrees(data->orientation);
if (swapDimensions) {
orientationAlignedViewport.x = (float) renderer->viewport.y;
orientationAlignedViewport.y = (float) renderer->viewport.x;