hardcoredaniel
2016-10-02 09:20:22 UTC
Hi,
I have experimented with WinRT a little and want to publish my changes.
Below is the diff.
These are the changes:
1) Added a hint to enable saving the fullscreen preference of an app.
Default is disabled.
2) Use triple-buffering instead of double-buffering. We discussed this
before, not sure whether and how to apply it.
3) Experimental code to query display densities. Because I have no idea what
to do with the "diagonal DPI" value, I tried to put the scaling factor in.
Any feedback is welcome!
Regards,
Daniel
-------------------------
diff -Naur SDL_snapshot/include/SDL_hints.h SDL_merged/include/SDL_hints.h
--- SDL_snapshot/include/SDL_hints.h   2016-10-02 09:27:31.000000000 +0200
+++ SDL_merged/include/SDL_hints.h   2016-10-02 09:41:18.000000000 +0200
@@ -689,6 +689,20 @@
 #define SDL_HINT_BMP_SAVE_LEGACY_FORMAT "SDL_BMP_SAVE_LEGACY_FORMAT"
Â
 /**
+ * \brief A hint to control whether the system shall remember the preferred
fullscreen mode.
+ *
+ * This hint will work for WinRT only.
+ *
+ * The variable can be set to the following values:
+ *Â Â Â "0"Â Â Â Â Â Â - No action. System does not remember whether the app wants
to run in fullscreen.
+ *Â Â Â "1"Â Â Â Â Â Â - Remember preferred app setting (fullscreen or windowed).
+ *
+ * The default is "0".
+ *
+ */
+#define SDL_HINT_WINRT_REMEMBER_WINDOW_FULLSCREEN_PREFERENCE "SDL_WINRT_
REMEMBER_WINDOW_FULLSCREEN_PREFERENCE"
+
+/**
 * \brief An enumeration of hint priorities
 */
 typedef enum
diff -Naur SDL_snapshot/src/render/direct3d11/SDL_render_d3d11.c SDL_merged/
src/render/direct3d11/SDL_render_d3d11.c
--- SDL_snapshot/src/render/direct3d11/SDL_render_d3d11.c   2016-10-02 09:
27:31.000000000 +0200
+++ SDL_merged/src/render/direct3d11/SDL_render_d3d11.c   2016-10-02 09:58:
08.000000000 +0200
@@ -1437,7 +1437,7 @@
    swapChainDesc.SampleDesc.Count = 1; /* Don't use multi-sampling. */
    swapChainDesc.SampleDesc.Quality = 0;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
-Â Â Â swapChainDesc.BufferCount = 2; /* Use double-buffering to minimize
latency. */
+Â Â Â swapChainDesc.BufferCount = 3; /* Use triple-buffering to minimize
latency. */
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    swapChainDesc.Scaling = DXGI_SCALING_STRETCH; /* On phone, only stretch
and aspect-ratio stretch scaling are allowed. */
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; /* On phone, no
swap effects are supported. */
diff -Naur SDL_snapshot/src/video/winrt/SDL_winrtvideo.cpp SDL_merged/src/
video/winrt/SDL_winrtvideo.cpp
--- SDL_snapshot/src/video/winrt/SDL_winrtvideo.cpp   2016-10-02 09:27:
31.000000000 +0200
+++ SDL_merged/src/video/winrt/SDL_winrtvideo.cpp   2016-10-02 10:10:
31.000000000 +0200
@@ -67,7 +67,8 @@
 #include "SDL_winrtmouse_c.h"
 #include "SDL_main.h"
 #include "SDL_system.h"
-//#include "SDL_log.h"
+#include "SDL_hints.h"
+#include "SDL_log.h"
Â
Â
 /* Initialization/Query functions */
@@ -83,6 +84,7 @@
 static void WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_
VideoDisplay * display, SDL_bool fullscreen);
 static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
 static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_
SysWMinfo * info);
+static int WINRT_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float
* ddpi, float * hdpi, float * vdpi);
Â
Â
 /* Misc functions */
@@ -148,6 +150,7 @@
    device->PumpEvents = WINRT_PumpEvents;
    device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
    device->SuspendScreenSaver = WINRT_SuspendScreenSaver;
+Â Â Â device->GetDisplayDPI = WINRT_GetDisplayDPI;
Â
 #if NTDDI_VERSION >= NTDDI_WIN10
    device->HasScreenKeyboardSupport = WINRT_HasScreenKeyboardSupport;
@@ -729,14 +732,33 @@
 #if NTDDI_VERSION >= NTDDI_WIN10
    SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
    bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
+Â Â Â bool rememberMode = false;
+
+Â Â Â const char *hint = SDL_GetHint(SDL_HINT_WINRT_REMEMBER_WINDOW_
FULLSCREEN_PREFERENCE);
+Â Â Â if (hint) {
+Â Â Â Â Â Â if (*hint == '1') {
+Â Â Â Â Â Â Â Â Â rememberMode = true;
+Â Â Â Â Â Â }
+Â Â Â }
+
    if (isWindowActive) {
        if (fullscreen) {
-Â Â Â Â Â Â Â Â Â Â Â if (!data->appView->IsFullScreenMode) {
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â data->appView->TryEnterFullScreenMode();Â Â Â // TODO, WinRT:
return failure (to caller?) from TryEnterFullScreenMode()
-Â Â Â Â Â Â Â Â Â Â Â }
+Â Â Â Â Â Â Â Â Â if (!data->appView->IsFullScreenMode) {
+Â Â Â Â Â Â Â Â Â Â Â Â if (data->appView->TryEnterFullScreenMode() == true) {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (rememberMode == true) {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â data->appView->PreferredLaunchWindowingMode =
ApplicationViewWindowingMode::FullScreen;
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
+Â Â Â Â Â Â Â Â Â Â Â Â } else {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // TODO, WinRT: return failure (to caller?) from
TryEnterFullScreenMode()
+Â Â Â Â Â Â Â Â Â Â Â Â }
+Â Â Â Â Â Â Â Â Â }
        } else {
            if (data->appView->IsFullScreenMode) {
                data->appView->ExitFullScreenMode();
+
+Â Â Â Â Â Â Â Â Â Â Â Â if (rememberMode == true) {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â data->appView->PreferredLaunchWindowingMode =
ApplicationViewWindowingMode::Auto;
+Â Â Â Â Â Â Â Â Â Â Â Â }
            }
        }
    }
@@ -837,6 +859,90 @@
    }
 }
Â
+int
+WINRT_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi,
float * hdpi, float * vdpi)
+{
+Â Â Â DisplayInformation ^ inf = DisplayInformation::GetForCurrentView();
+
+Â Â Â *hdpi = inf->RawDpiX;
+Â Â Â *vdpi = inf->RawDpiY;
+Â Â Â switch (inf->ResolutionScale)
+Â Â Â {
+Â Â Â case ResolutionScale::Scale100Percent:
+Â Â Â Â Â Â *ddpi = 100;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale120Percent:
+Â Â Â Â Â Â *ddpi = 120;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale125Percent:
+Â Â Â Â Â Â *ddpi = 125;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale140Percent:
+Â Â Â Â Â Â *ddpi = 140;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale150Percent:
+Â Â Â Â Â Â *ddpi = 150;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale160Percent:
+Â Â Â Â Â Â *ddpi = 160;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale175Percent:
+Â Â Â Â Â Â *ddpi = 175;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale180Percent:
+Â Â Â Â Â Â *ddpi = 180;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale200Percent:
+Â Â Â Â Â Â *ddpi = 200;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale225Percent:
+Â Â Â Â Â Â *ddpi = 225;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale250Percent:
+Â Â Â Â Â Â *ddpi = 250;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale300Percent:
+Â Â Â Â Â Â *ddpi = 300;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale350Percent:
+Â Â Â Â Â Â *ddpi = 350;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale400Percent:
+Â Â Â Â Â Â *ddpi = 400;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale450Percent:
+Â Â Â Â Â Â *ddpi = 450;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale500Percent:
+Â Â Â Â Â Â *ddpi = 500;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Invalid:
+Â Â Â default:
+Â Â Â Â Â Â *ddpi = 0;
+Â Â Â }
+Â Â Â //Â Â Â *ddpi = inf->ResolutionScale;
+
+Â Â Â SDL_Log("Densities: H=%.1f V=%.1f D=%.1f\n", *hdpi, *vdpi, *ddpi);
+
+Â Â Â return 0;
+}
+
 #endif /* SDL_VIDEO_DRIVER_WINRT */
Â
 /* vi: set ts=4 sw=4 expandtab: */
I have experimented with WinRT a little and want to publish my changes.
Below is the diff.
These are the changes:
1) Added a hint to enable saving the fullscreen preference of an app.
Default is disabled.
2) Use triple-buffering instead of double-buffering. We discussed this
before, not sure whether and how to apply it.
3) Experimental code to query display densities. Because I have no idea what
to do with the "diagonal DPI" value, I tried to put the scaling factor in.
Any feedback is welcome!
Regards,
Daniel
-------------------------
diff -Naur SDL_snapshot/include/SDL_hints.h SDL_merged/include/SDL_hints.h
--- SDL_snapshot/include/SDL_hints.h   2016-10-02 09:27:31.000000000 +0200
+++ SDL_merged/include/SDL_hints.h   2016-10-02 09:41:18.000000000 +0200
@@ -689,6 +689,20 @@
 #define SDL_HINT_BMP_SAVE_LEGACY_FORMAT "SDL_BMP_SAVE_LEGACY_FORMAT"
Â
 /**
+ * \brief A hint to control whether the system shall remember the preferred
fullscreen mode.
+ *
+ * This hint will work for WinRT only.
+ *
+ * The variable can be set to the following values:
+ *Â Â Â "0"Â Â Â Â Â Â - No action. System does not remember whether the app wants
to run in fullscreen.
+ *Â Â Â "1"Â Â Â Â Â Â - Remember preferred app setting (fullscreen or windowed).
+ *
+ * The default is "0".
+ *
+ */
+#define SDL_HINT_WINRT_REMEMBER_WINDOW_FULLSCREEN_PREFERENCE "SDL_WINRT_
REMEMBER_WINDOW_FULLSCREEN_PREFERENCE"
+
+/**
 * \brief An enumeration of hint priorities
 */
 typedef enum
diff -Naur SDL_snapshot/src/render/direct3d11/SDL_render_d3d11.c SDL_merged/
src/render/direct3d11/SDL_render_d3d11.c
--- SDL_snapshot/src/render/direct3d11/SDL_render_d3d11.c   2016-10-02 09:
27:31.000000000 +0200
+++ SDL_merged/src/render/direct3d11/SDL_render_d3d11.c   2016-10-02 09:58:
08.000000000 +0200
@@ -1437,7 +1437,7 @@
    swapChainDesc.SampleDesc.Count = 1; /* Don't use multi-sampling. */
    swapChainDesc.SampleDesc.Quality = 0;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
-Â Â Â swapChainDesc.BufferCount = 2; /* Use double-buffering to minimize
latency. */
+Â Â Â swapChainDesc.BufferCount = 3; /* Use triple-buffering to minimize
latency. */
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    swapChainDesc.Scaling = DXGI_SCALING_STRETCH; /* On phone, only stretch
and aspect-ratio stretch scaling are allowed. */
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; /* On phone, no
swap effects are supported. */
diff -Naur SDL_snapshot/src/video/winrt/SDL_winrtvideo.cpp SDL_merged/src/
video/winrt/SDL_winrtvideo.cpp
--- SDL_snapshot/src/video/winrt/SDL_winrtvideo.cpp   2016-10-02 09:27:
31.000000000 +0200
+++ SDL_merged/src/video/winrt/SDL_winrtvideo.cpp   2016-10-02 10:10:
31.000000000 +0200
@@ -67,7 +67,8 @@
 #include "SDL_winrtmouse_c.h"
 #include "SDL_main.h"
 #include "SDL_system.h"
-//#include "SDL_log.h"
+#include "SDL_hints.h"
+#include "SDL_log.h"
Â
Â
 /* Initialization/Query functions */
@@ -83,6 +84,7 @@
 static void WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_
VideoDisplay * display, SDL_bool fullscreen);
 static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
 static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_
SysWMinfo * info);
+static int WINRT_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float
* ddpi, float * hdpi, float * vdpi);
Â
Â
 /* Misc functions */
@@ -148,6 +150,7 @@
    device->PumpEvents = WINRT_PumpEvents;
    device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
    device->SuspendScreenSaver = WINRT_SuspendScreenSaver;
+Â Â Â device->GetDisplayDPI = WINRT_GetDisplayDPI;
Â
 #if NTDDI_VERSION >= NTDDI_WIN10
    device->HasScreenKeyboardSupport = WINRT_HasScreenKeyboardSupport;
@@ -729,14 +732,33 @@
 #if NTDDI_VERSION >= NTDDI_WIN10
    SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
    bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
+Â Â Â bool rememberMode = false;
+
+Â Â Â const char *hint = SDL_GetHint(SDL_HINT_WINRT_REMEMBER_WINDOW_
FULLSCREEN_PREFERENCE);
+Â Â Â if (hint) {
+Â Â Â Â Â Â if (*hint == '1') {
+Â Â Â Â Â Â Â Â Â rememberMode = true;
+Â Â Â Â Â Â }
+Â Â Â }
+
    if (isWindowActive) {
        if (fullscreen) {
-Â Â Â Â Â Â Â Â Â Â Â if (!data->appView->IsFullScreenMode) {
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â data->appView->TryEnterFullScreenMode();Â Â Â // TODO, WinRT:
return failure (to caller?) from TryEnterFullScreenMode()
-Â Â Â Â Â Â Â Â Â Â Â }
+Â Â Â Â Â Â Â Â Â if (!data->appView->IsFullScreenMode) {
+Â Â Â Â Â Â Â Â Â Â Â Â if (data->appView->TryEnterFullScreenMode() == true) {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (rememberMode == true) {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â data->appView->PreferredLaunchWindowingMode =
ApplicationViewWindowingMode::FullScreen;
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
+Â Â Â Â Â Â Â Â Â Â Â Â } else {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // TODO, WinRT: return failure (to caller?) from
TryEnterFullScreenMode()
+Â Â Â Â Â Â Â Â Â Â Â Â }
+Â Â Â Â Â Â Â Â Â }
        } else {
            if (data->appView->IsFullScreenMode) {
                data->appView->ExitFullScreenMode();
+
+Â Â Â Â Â Â Â Â Â Â Â Â if (rememberMode == true) {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â data->appView->PreferredLaunchWindowingMode =
ApplicationViewWindowingMode::Auto;
+Â Â Â Â Â Â Â Â Â Â Â Â }
            }
        }
    }
@@ -837,6 +859,90 @@
    }
 }
Â
+int
+WINRT_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi,
float * hdpi, float * vdpi)
+{
+Â Â Â DisplayInformation ^ inf = DisplayInformation::GetForCurrentView();
+
+Â Â Â *hdpi = inf->RawDpiX;
+Â Â Â *vdpi = inf->RawDpiY;
+Â Â Â switch (inf->ResolutionScale)
+Â Â Â {
+Â Â Â case ResolutionScale::Scale100Percent:
+Â Â Â Â Â Â *ddpi = 100;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale120Percent:
+Â Â Â Â Â Â *ddpi = 120;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale125Percent:
+Â Â Â Â Â Â *ddpi = 125;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale140Percent:
+Â Â Â Â Â Â *ddpi = 140;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale150Percent:
+Â Â Â Â Â Â *ddpi = 150;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale160Percent:
+Â Â Â Â Â Â *ddpi = 160;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale175Percent:
+Â Â Â Â Â Â *ddpi = 175;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale180Percent:
+Â Â Â Â Â Â *ddpi = 180;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale200Percent:
+Â Â Â Â Â Â *ddpi = 200;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale225Percent:
+Â Â Â Â Â Â *ddpi = 225;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale250Percent:
+Â Â Â Â Â Â *ddpi = 250;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale300Percent:
+Â Â Â Â Â Â *ddpi = 300;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale350Percent:
+Â Â Â Â Â Â *ddpi = 350;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale400Percent:
+Â Â Â Â Â Â *ddpi = 400;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale450Percent:
+Â Â Â Â Â Â *ddpi = 450;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Scale500Percent:
+Â Â Â Â Â Â *ddpi = 500;
+Â Â Â Â Â Â break;
+
+Â Â Â case ResolutionScale::Invalid:
+Â Â Â default:
+Â Â Â Â Â Â *ddpi = 0;
+Â Â Â }
+Â Â Â //Â Â Â *ddpi = inf->ResolutionScale;
+
+Â Â Â SDL_Log("Densities: H=%.1f V=%.1f D=%.1f\n", *hdpi, *vdpi, *ddpi);
+
+Â Â Â return 0;
+}
+
 #endif /* SDL_VIDEO_DRIVER_WINRT */
Â
 /* vi: set ts=4 sw=4 expandtab: */