src/video/winrt/SDL_winrtvideo.cpp
changeset 8579 ee7126c459d0
parent 8578 6517b6aca713
child 8582 c3e9a2b93517
     1.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Sat Mar 01 16:08:16 2014 -0500
     1.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Sat Mar 01 16:37:30 2014 -0500
     1.3 @@ -154,9 +154,6 @@
     1.4  
     1.5      using namespace Windows::Graphics::Display;
     1.6  
     1.7 -    // Initialize the mode to all zeros:
     1.8 -    SDL_zerop(mode);
     1.9 -
    1.10      // Go no further if a native window cannot be accessed.  This can happen,
    1.11      // for example, if this function is called from certain threads, such as
    1.12      // the SDL/XAML thread.
    1.13 @@ -164,6 +161,16 @@
    1.14          return SDL_SetError("SDL/WinRT display modes cannot be calculated outside of the main thread, such as in SDL's XAML thread");
    1.15      }
    1.16  
    1.17 +    // Calculate the display size given the window size, taking into account
    1.18 +    // the current display's DPI:
    1.19 +    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; 
    1.20 +    const float dipsPerInch = 96.0f;
    1.21 +    const int w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
    1.22 +    const int h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
    1.23 +    if (w == 0 || w == h) {
    1.24 +        return SDL_SetError("Unable to calculate the WinRT window/display's size");
    1.25 +    }
    1.26 +
    1.27      // Create a driverdata field:
    1.28      driverdata = (SDL_DisplayModeData *) SDL_malloc(sizeof(*driverdata));
    1.29      if (!driverdata) {
    1.30 @@ -172,18 +179,14 @@
    1.31      SDL_zerop(driverdata);
    1.32  
    1.33      // Fill in most fields:
    1.34 +    SDL_zerop(mode);
    1.35      mode->format = SDL_PIXELFORMAT_RGB888;
    1.36      mode->refresh_rate = 0;  // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
    1.37 +    mode->w = w;
    1.38 +    mode->h = h;
    1.39      mode->driverdata = driverdata;
    1.40      driverdata->currentOrientation = DisplayProperties::CurrentOrientation;
    1.41  
    1.42 -    // Calculate the display size given the window size, taking into account
    1.43 -    // the current display's DPI:
    1.44 -    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; 
    1.45 -    const float dipsPerInch = 96.0f;
    1.46 -    mode->w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
    1.47 -    mode->h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
    1.48 -
    1.49  #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.50      // On Windows Phone, the native window's size is always in portrait,
    1.51      // regardless of the device's orientation.  This is in contrast to
    1.52 @@ -231,11 +234,6 @@
    1.53      if (WINRT_CalcDisplayModeUsingNativeWindow(&mode) != 0) {
    1.54          return -1;	// If WINRT_CalcDisplayModeUsingNativeWindow fails, it'll already have set the SDL error
    1.55      }
    1.56 -    
    1.57 -    if (mode.w == 0 || mode.h == 0) {
    1.58 -        SDL_free(mode.driverdata);
    1.59 -        return SDL_SetError("Unable to calculate the WinRT window/display's size");
    1.60 -    }
    1.61  
    1.62      if (WINRT_DuplicateDisplayMode(&desktop_mode, &mode) != 0) {
    1.63          return -1;