Discussion:
[SDL] Some WinRT strangeness with reported window size
hardcoredaniel
2016-10-08 13:44:03 UTC
Permalink
Hi,

I found some strangeness with WinRT when looking at app resume and the SDL
events "window resized" and "window size changed":

1) On the desktop, I'm changing the app from fullscreen to windowed mode.
After changing the window size to make the window a little smaller, I
minimize the window, then restore it again.

The issue I see is that the window events report the width and height of the
window as if it still was fullscreen. Somehow SDL did not "fully realize"
that the window is no longer fullscreen. Which is strange because all the
events that are fired during resizing the window are correct (e.g. when the
issue occurs, resizing the window again corrects the coordinates
immediately).

2) On the phone, the coordinates reported by the 2 events seem to be
inconsistent (at least for an app that is declared to support landscape
only). Sometimes the corrdinates are reported with width < height, sometimes
the other way 'round. There seem to be a number of notifications coming, and
the "last" one after initial app start is different to the "last" one after
resume, so that my app becomes confused.

I can help reproducing the issues if this proves to be difficult. Any help
is appreciated :-)

Regards,

Daniel
DLudwig
2016-10-10 20:27:37 UTC
Permalink
1) On the desktop, I'm changing the app from fullscreen to windowed mode. After changing the window size to make the window a little smaller, I minimize the window, then restore it again.
The issue I see is that the window events report the width and height of the window as if it still was fullscreen. Somehow SDL did not "fully realize" that the window is no longer fullscreen. Which is strange because all the events that are fired during resizing the window are correct (e.g. when the issue occurs, resizing the window again corrects the coordinates immediately).
I am unable to reproduce this. Can you provide a set of steps-to-reproduce, along with expected and observed results?

Also, which version/revision of SDL are you using?

-- David L.
hardcoredaniel
2016-10-15 10:26:56 UTC
Permalink
Hi David,

can you check out this app:

https://www.microsoft.com/en-us/store/p/wmelite-engine/9nblggh4wb5z

It will launch in fullscreen. When you resize it to windowed mode, change it
to say 50% of its fullscreen size, minimize it, and then restore, it will
display in invalid size. If you start resizing the window again, it'll
immediately use the proper size.

The SDL version from this app is the state of trunk from around mid of june.
The behaviour does not change if I use SDL trunk from around 2 weeks ago.

Regards,

Daniel



---------- Původní zpráva ----------
Od: DLudwig <***@pobox.com>
Komu: ***@lists.libsdl.org
Datum: 10. 10. 2016 22:27:52
Předmět: Re: [SDL] Some WinRT strangeness with reported window size

"











hardcoredaniel wrote:
1) On the desktop, I'm changing the app from fullscreen to windowed mode.
After changing the window size to make the window a little smaller, I
minimize the window, then restore it again.

The issue I see is that the window events report the width and height of the
window as if it still was fullscreen. Somehow SDL did not "fully realize"
that the window is no longer fullscreen. Which is strange because all the
events that are fired during resizing the window are correct (e.g. when the
issue occurs, resizing the window again corrects the coordinates
immediately).





I am unable to reproduce this. Can you provide a set of steps-to-reproduce,
along with expected and observed results?

Also, which version/revision of SDL are you using?

-- David L.
DLudwig
2016-10-15 18:07:39 UTC
Permalink
It will launch in fullscreen. When you resize it to windowed mode, change it to say 50% of its fullscreen size, minimize it, and then restore, it will display in invalid size. If you start resizing the window again, it'll immediately use the proper size.
I see the bug reproduce in that app, but not in my own code. I've tried checking various SDL outputs as well (window size, renderer output size, viewport, and a few other things), and am not yet seeing any discrepencies.

Do you have sample code that I could try building + testing against, preferably something dependency-free and single-file?

-- David L.
hardcoredaniel
2016-10-18 15:15:01 UTC
Permalink
Hi David,

I'm sorry for having you bothered with an issue that you could not have
reproduced due to missing information. After thinking about your
observations it occurred to me that some time ago I tried to implement some
workaround for the issue that the SDL app will not reliably start (resp
change to) fullscreen mode on PCs.

What I did was to add some code in my app to react on the window event "SDL_
WINDOWEVENT_SHOWN" and to call "SDL_SetWindowFullscreen" with SDL_TRUE as 2
nd parameter.

This worked well at app start, so that I forgot about this trick.
However, when restoring a minimized app that I changed to windowed mode
before, the system is not going to fullscreen despite that call (I'm not
sure whether or whom to blame, because I intentionally left fullscreen mode
before minimizing the window).
As the call to "SetWindowFullscreen" cannot return success/failure, SDL
doesn't know about this and so probably assumes fullscreen was ok and sends
the SDL_WINDOWEVENT_RESIZED with the fullscreen coords.

So maybe I will have to modify the SDL sources myself to add a return code
to SetWindowFullscreen, return hard-coded success for all other platforms,
and success/failure for WinRT only. I remember your comment about such a
change not suiting all platforms where the success/failure of such operation
is reported asynchronously. Yet I have no other idea how to handle it.

BTW: Can you reproduce the width/height parameter inconsistency on the
mobile platform? Or is there a relation to my workaround as well?

Regards,

Daniel


---------- Původní zpráva ----------
Od: DLudwig <***@pobox.com>
Komu: ***@lists.libsdl.org
Datum: 15. 10. 2016 20:07:53
Předmět: Re: [SDL] Some WinRT strangeness with reported window size

"











hardcoredaniel wrote:
It will launch in fullscreen. When you resize it to windowed mode, change it
to say 50% of its fullscreen size, minimize it, and then restore, it will
display in invalid size. If you start resizing the window again, it'll
immediately use the proper size.




I see the bug reproduce in that app, but not in my own code. I've tried
checking various SDL outputs as well (window size, renderer output size,
viewport, and a few other things), and am not yet seeing any discrepencies.

Do you have sample code that I could try building + testing against,
preferably something dependency-free and single-file?

-- David L.
hardcoredaniel
2016-10-23 13:28:47 UTC
Permalink
Hi David,

I found that modifying SDL as described fixes the issue. FYI the (pretty
ugly) patch is below. Modifying the behaviour in SDL_video.c's "update
fullscreen" depending on the result of the TryEnterFullscreen() mode fixes
all screen size issues for me.

Regards,

Daniel


--- SDL_snapshot/src/video/SDL_sysvideo.h       2016-10-02 08:22:
14.323265900 +0200
+++ SDL_merged/src/video/SDL_sysvideo.h 2016-10-22 16:08:43.340540400 +0200
@@ -220,7 +220,11 @@
     void (*RestoreWindow) (_THIS, SDL_Window * window);
     void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool
bordered);
     void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool
resizable);
+#ifdef __WINRT__
+    int (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_
VideoDisplay * display, SDL_bool fullscreen);
+#else
     void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_
VideoDisplay * display, SDL_bool fullscreen);
+#endif
     int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 *
ramp);
     int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
     void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
diff -bBur SDL_snapshot/src/video/SDL_video.c SDL_merged/src/video/SDL_
video.c
--- SDL_snapshot/src/video/SDL_video.c  2016-10-08 10:16:43.377628700 +0200
+++ SDL_merged/src/video/SDL_video.c    2016-10-22 17:26:58.402858000 +0200
@@ -1265,7 +1265,14 @@
                 }

                 if (_this->SetWindowFullscreen) {
+#ifdef __WINRT__
+                       if (_this->SetWindowFullscreen(_this, other,
display, SDL_TRUE) != 0)
+                       {
+                               resized = SDL_FALSE;
+                       }
+#else
                     _this->SetWindowFullscreen(_this, other, display, SDL_
TRUE);
+#endif
                 }
                 display->fullscreen_window = other;
diff -bBur 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 08:22:
18.423455500 +0200
+++ SDL_merged/src/video/winrt/SDL_winrtvideo.cpp       2016-10-22 17:27:
36.208419200 +0200
@@ -80,9 +81,10 @@
 /* Window functions */
 static int WINRT_CreateWindow(_THIS, SDL_Window * window);
 static void WINRT_SetWindowSize(_THIS, SDL_Window * window);
-static void WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_
VideoDisplay * display, SDL_bool fullscreen);
+static int 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 */
@@ -723,23 +726,49 @@
 #endif
 }

-void
+int
 WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay *
display, SDL_bool fullscreen)
 {
 #if NTDDI_VERSION >= NTDDI_WIN10
     SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
     bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
+       bool rememberMode = false;
+       int successVal = 0;
+
+       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->TryEnterFullScreenMode()
== true) {
+                                       if (rememberMode == true) {
+                                               data->appView->
PreferredLaunchWindowingMode = ApplicationViewWindowingMode::FullScreen;
+                                       }
+                               } else {
+                                       successVal = -1;
+                               }
             }
         } else {
             if (data->appView->IsFullScreenMode) {
                 data->appView->ExitFullScreenMode();
+
+                               if (rememberMode == true) {
+                                       data->appView->
PreferredLaunchWindowingMode = ApplicationViewWindowingMode::Auto;
+                               }
             }
         }
     }
+       else {
+               successVal = -1;
+       }
+    return successVal;
+#else
+    return 0;
 #endif
 }









---------- Původní zpráva ----------
Od: hardcoredaniel <***@seznam.cz>
Komu: ***@lists.libsdl.org
Datum: 18. 10. 2016 17:15:17
Předmět: Re: [SDL] Some WinRT strangeness with reported window size

"
Hi David,

I'm sorry for having you bothered with an issue that you could not have
reproduced due to missing information. After thinking about your
observations it occurred to me that some time ago I tried to implement some
workaround for the issue that the SDL app will not reliably start (resp
change to) fullscreen mode on PCs.

What I did was to add some code in my app to react on the window event "SDL_
WINDOWEVENT_SHOWN" and to call "SDL_SetWindowFullscreen" with SDL_TRUE as 2
nd parameter.

This worked well at app start, so that I forgot about this trick.
However, when restoring a minimized app that I changed to windowed mode
before, the system is not going to fullscreen despite that call (I'm not
sure whether or whom to blame, because I intentionally left fullscreen mode
before minimizing the window).
As the call to "SetWindowFullscreen" cannot return success/failure, SDL
doesn't know about this and so probably assumes fullscreen was ok and sends
the SDL_WINDOWEVENT_RESIZED with the fullscreen coords.

So maybe I will have to modify the SDL sources myself to add a return code
to SetWindowFullscreen, return hard-coded success for all other platforms,
and success/failure for WinRT only. I remember your comment about such a
change not suiting all platforms where the success/failure of such operation
is reported asynchronously. Yet I have no other idea how to handle it.

BTW: Can you reproduce the width/height parameter inconsistency on the
mobile platform? Or is there a relation to my workaround as well?

Regards,

Daniel


---------- Původní zpráva ----------
Od: DLudwig <***@pobox.com>
Komu: ***@lists.libsdl.org
Datum: 15. 10. 2016 20:07:53
Předmět: Re: [SDL] Some WinRT strangeness with reported window size

"











hardcoredaniel wrote:
It will launch in fullscreen. When you resize it to windowed mode, change it
to say 50% of its fullscreen size, minimize it, and then restore, it will
display in invalid size. If you start resizing the window again, it'll
immediately use the proper size.




I see the bug reproduce in that app, but not in my own code. I've tried
checking various SDL outputs as well (window size, renderer output size,
viewport, and a few other things), and am not yet seeing any discrepencies.

Do you have sample code that I could try building + testing against,
preferably something dependency-free and single-file?

-- David L.
DLudwig
2016-10-23 16:25:32 UTC
Permalink
Hi Daniel,

Any chance that you could provide some sample code, maybe some project file(s), with which one could use to reliably reproduce the bug you were initially seeing?

-- David L.
hardcoredaniel
2016-11-09 10:35:59 UTC
Permalink
Hi David,

sorry for the long delay for my reply.

I do not have a small project, mine is rather big (repo size ~3G). But I
hope you have some scratch disk space :-)

Please check out these 2 repos next to each other (e.g. into the same root
dir) from bitbucket:

https://***@bitbucket.org/hcdaniel/wmelite-dependencies-for-linux-and-
android
https://***@bitbucket.org/hcdaniel/wmelite-rapaki-edition

The names of the repos must be kept because the project references go across
the repos.

Then you can open this project:

 wmelite-rapaki-edition/vs2015_uwp/wmelite_sdl_mixer/wmelite_sdl_mixer.sln

And compilation/running should work.

The SDL fork that the project references to has the change for fullscreen
already implemented. I hope that you can easily remove this reference and
point it to SDL trunk instead, to see the difference.

Regards,

Daniel



---------- Původní zpráva ----------
Od: DLudwig <***@pobox.com>
Komu: ***@lists.libsdl.org
Datum: 23. 10. 2016 18:25:44
Předmět: Re: [SDL] Some WinRT strangeness with reported window size

"

Hi Daniel,

Any chance that you could provide some sample code, maybe some project file
(s), with which one could use to reliably reproduce the bug you were
initially seeing?

-- David L.

Loading...