WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
authorDavid Ludwig
Sun, 06 Dec 2015 17:06:40 -0500
changeset 99473b68fd2503df
parent 9946 6f852b334192
child 9948 46ba1492b14b
WinRT: workaround for a possible bug in the Win10 Store's Certification Kit

DXGI fails to report any displays in at least one of the
"Windows App Certification Kit 10.0"'s tests for Store Apps. This was
causing SDL's video initialization code to fail, when the suspect test
("Direct3D Feature Test") was run, as DXGI was unable to report a
display-output at adapter-index 0, output-index 0.

The workaround that is applied here attempts to detect this case, then
use a hopefully-reasonable alternative means to calculate at least one
display output.
src/video/winrt/SDL_winrtvideo.cpp
     1.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Sun Dec 06 17:51:11 2015 +0100
     1.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Sun Dec 06 17:06:40 2015 -0500
     1.3 @@ -315,6 +315,51 @@
     1.4  
     1.5      for (int outputIndex = 0; ; ++outputIndex) {
     1.6          if (WINRT_AddDisplaysForOutput(_this, dxgiAdapter1, outputIndex) < 0) {
     1.7 +            /* HACK: The Windows App Certification Kit 10.0 can fail, when
     1.8 +               running the Store Apps' test, "Direct3D Feature Test".  The
     1.9 +               certification kit's error is:
    1.10 +
    1.11 +               "Application App was not running at the end of the test. It likely crashed or was terminated for having become unresponsive."
    1.12 +
    1.13 +               This was caused by SDL/WinRT's DXGI failing to report any
    1.14 +               outputs.  Attempts to get the 1st display-output from the
    1.15 +               1st display-adapter can fail, with IDXGIAdapter::EnumOutputs
    1.16 +               returning DXGI_ERROR_NOT_FOUND.  This could be a bug in Windows,
    1.17 +               the Windows App Certification Kit, or possibly in SDL/WinRT's
    1.18 +               display detection code.  Either way, try to detect when this
    1.19 +               happens, and use a hackish means to create a reasonable-as-possible
    1.20 +               'display mode'.  -- DavidL
    1.21 +            */
    1.22 +#if SDL_WINRT_USE_APPLICATIONVIEW
    1.23 +            if (adapterIndex == 0 && outputIndex == 0) {
    1.24 +                SDL_VideoDisplay display;
    1.25 +                SDL_DisplayMode mode;
    1.26 +                ApplicationView ^ appView = ApplicationView::GetForCurrentView();
    1.27 +                SDL_zero(display);
    1.28 +                SDL_zero(mode);
    1.29 +                display.name = "DXGI Display-detection Workaround";
    1.30 +
    1.31 +                /* HACK: ApplicationView's VisibleBounds property, appeared, via testing, to
    1.32 +                   give a better approximation of display-size, than did CoreWindow's
    1.33 +                   Bounds property, insofar that ApplicationView::VisibleBounds seems like
    1.34 +                   it will, at least some of the time, give the full display size (during the
    1.35 +                   failing test), whereas CoreWindow will not.  -- DavidL
    1.36 +                */
    1.37 +                mode.w = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Width);
    1.38 +                mode.h = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Height);
    1.39 +
    1.40 +                mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
    1.41 +                mode.refresh_rate = 0;  /* Display mode is unknown, so just fill in zero, as specified by SDL's header files */
    1.42 +                display.desktop_mode = mode;
    1.43 +                display.current_mode = mode;
    1.44 +                if ((SDL_AddDisplayMode(&display, &mode) < 0) ||
    1.45 +                    (SDL_AddVideoDisplay(&display) < 0))
    1.46 +                {
    1.47 +                    return SDL_SetError("Failed to apply DXGI Display-detection workaround");
    1.48 +                }
    1.49 +            }
    1.50 +#endif  // SDL_WINRT_USE_APPLICATIONVIEW
    1.51 +
    1.52              break;
    1.53          }
    1.54      }