winrt: Don't register orientation hint callback in startup code. SDL_AddHintCallback() uses SDL_malloc(), which means this would run before main(), so the app wouldn't be able to supply its own replacement SDL_malloc() implementation in time. This code was moved to under SDL_Init. Since the hint callback already makes efforts to not override the app manifest's orientation settings, this is safe to move until after pre-main() startup. Fixes #4449.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp
index 9c115c6..4ed6f36 100644
--- a/src/core/winrt/SDL_winrtapp_direct3d.cpp
+++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp
@@ -119,68 +119,6 @@ int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **))
return 0;
}
-static void SDLCALL
-WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
-{
- SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
-
- /* HACK: prevent SDL from altering an app's .appxmanifest-set orientation
- * from being changed on startup, by detecting when SDL_HINT_ORIENTATIONS
- * is getting registered.
- *
- * TODO, WinRT: consider reading in an app's .appxmanifest file, and apply its orientation when 'newValue == NULL'.
- */
- if ((oldValue == NULL) && (newValue == NULL)) {
- return;
- }
-
- // Start with no orientation flags, then add each in as they're parsed
- // from newValue.
- unsigned int orientationFlags = 0;
- if (newValue) {
- std::istringstream tokenizer(newValue);
- while (!tokenizer.eof()) {
- std::string orientationName;
- std::getline(tokenizer, orientationName, ' ');
- if (orientationName == "LandscapeLeft") {
- orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
- } else if (orientationName == "LandscapeRight") {
- orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
- } else if (orientationName == "Portrait") {
- orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
- } else if (orientationName == "PortraitUpsideDown") {
- orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
- }
- }
- }
-
- // If no valid orientation flags were specified, use a reasonable set of defaults:
- if (!orientationFlags) {
- // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
- orientationFlags = (unsigned int) ( \
- DisplayOrientations::Landscape |
- DisplayOrientations::LandscapeFlipped |
- DisplayOrientations::Portrait |
- DisplayOrientations::PortraitFlipped);
- }
-
- // Set the orientation/rotation preferences. Please note that this does
- // not constitute a 100%-certain lock of a given set of possible
- // orientations. According to Microsoft's documentation on WinRT [1]
- // when a device is not capable of being rotated, Windows may ignore
- // the orientation preferences, and stick to what the device is capable of
- // displaying.
- //
- // [1] Documentation on the 'InitialRotationPreference' setting for a
- // Windows app's manifest file describes how some orientation/rotation
- // preferences may be ignored. See
- // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
- // 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).
- WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations) orientationFlags;
-}
-
static void
WINRT_ProcessWindowSizeChange() // TODO: Pass an SDL_Window-identifying thing into WINRT_ProcessWindowSizeChange()
{
@@ -397,10 +335,6 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window)
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) && (NTDDI_VERSION < NTDDI_WIN10) // 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
diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp
index 019f4b6..90a3ab4 100644
--- a/src/video/winrt/SDL_winrtvideo.cpp
+++ b/src/video/winrt/SDL_winrtvideo.cpp
@@ -28,6 +28,12 @@
was based off of SDL's "dummy" video driver.
*/
+/* Standard C++11 includes */
+#include <functional>
+#include <string>
+#include <sstream>
+using namespace std;
+
/* Windows includes */
#include <agile.h>
#include <windows.graphics.display.h>
@@ -67,6 +73,7 @@ extern "C" {
#include "SDL_winrtmouse_c.h"
#include "SDL_main.h"
#include "SDL_system.h"
+#include "SDL_hints.h"
/* Initialization/Query functions */
@@ -171,6 +178,68 @@ VideoBootStrap WINRT_bootstrap = {
WINRT_CreateDevice
};
+static void SDLCALL
+WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
+{
+ SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
+
+ /* HACK: prevent SDL from altering an app's .appxmanifest-set orientation
+ * from being changed on startup, by detecting when SDL_HINT_ORIENTATIONS
+ * is getting registered.
+ *
+ * TODO, WinRT: consider reading in an app's .appxmanifest file, and apply its orientation when 'newValue == NULL'.
+ */
+ if ((oldValue == NULL) && (newValue == NULL)) {
+ return;
+ }
+
+ // Start with no orientation flags, then add each in as they're parsed
+ // from newValue.
+ unsigned int orientationFlags = 0;
+ if (newValue) {
+ std::istringstream tokenizer(newValue);
+ while (!tokenizer.eof()) {
+ std::string orientationName;
+ std::getline(tokenizer, orientationName, ' ');
+ if (orientationName == "LandscapeLeft") {
+ orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
+ } else if (orientationName == "LandscapeRight") {
+ orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
+ } else if (orientationName == "Portrait") {
+ orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
+ } else if (orientationName == "PortraitUpsideDown") {
+ orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
+ }
+ }
+ }
+
+ // If no valid orientation flags were specified, use a reasonable set of defaults:
+ if (!orientationFlags) {
+ // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
+ orientationFlags = (unsigned int) ( \
+ DisplayOrientations::Landscape |
+ DisplayOrientations::LandscapeFlipped |
+ DisplayOrientations::Portrait |
+ DisplayOrientations::PortraitFlipped);
+ }
+
+ // Set the orientation/rotation preferences. Please note that this does
+ // not constitute a 100%-certain lock of a given set of possible
+ // orientations. According to Microsoft's documentation on WinRT [1]
+ // when a device is not capable of being rotated, Windows may ignore
+ // the orientation preferences, and stick to what the device is capable of
+ // displaying.
+ //
+ // [1] Documentation on the 'InitialRotationPreference' setting for a
+ // Windows app's manifest file describes how some orientation/rotation
+ // preferences may be ignored. See
+ // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
+ // 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).
+ WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations) orientationFlags;
+}
+
int
WINRT_VideoInit(_THIS)
{
@@ -178,6 +247,11 @@ WINRT_VideoInit(_THIS)
if (WINRT_InitModes(_this) < 0) {
return -1;
}
+
+ // 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);
+
WINRT_InitMouse(_this);
WINRT_InitTouch(_this);
WINRT_InitGameBar(_this);