WinRT changes for review

hardcoredaniel <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <V}[email protected]>
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: */

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.