Skip to content

Commit

Permalink
WinRT: code cleanup wrt. display mode(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLudwig committed Aug 27, 2013
1 parent f860141 commit 17ca1d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
24 changes: 2 additions & 22 deletions src/core/winrt/SDL_winrtapp.cpp
Expand Up @@ -41,6 +41,7 @@ extern "C" {

extern SDL_Window * WINRT_GlobalSDLWindow;
extern SDL_VideoDevice * WINRT_GlobalSDLVideoDevice;
extern SDL_DisplayMode WINRT_CalcDisplayModeUsingNativeWindow();


// Compile-time debugging options:
Expand Down Expand Up @@ -305,7 +306,7 @@ void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEven
// window-resize event as it appeared the SDL window didn't change
// size, and the Direct3D 11.1 renderer wouldn't resize its swap
// chain.
SDL_DisplayMode resizedDisplayMode = CalcCurrentDisplayMode();
SDL_DisplayMode resizedDisplayMode = WINRT_CalcDisplayModeUsingNativeWindow();
WINRT_GlobalSDLVideoDevice->displays[0].current_mode = resizedDisplayMode;
WINRT_GlobalSDLVideoDevice->displays[0].desktop_mode = resizedDisplayMode;
WINRT_GlobalSDLVideoDevice->displays[0].display_modes[0] = resizedDisplayMode;
Expand Down Expand Up @@ -466,24 +467,3 @@ void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
}
}

SDL_DisplayMode SDL_WinRTApp::CalcCurrentDisplayMode()
{
// Create an empty, zeroed-out display mode:
SDL_DisplayMode mode;
SDL_zero(mode);

// Fill in most fields:
mode.format = SDL_PIXELFORMAT_RGB888;
mode.refresh_rate = 0; // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
mode.driverdata = NULL;

// Calculate the display size given the window size, taking into account
// the current display's DPI:
const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
const float dipsPerInch = 96.0f;
mode.w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
mode.h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);

return mode;
}
1 change: 0 additions & 1 deletion src/core/winrt/SDL_winrtapp.h
Expand Up @@ -14,7 +14,6 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo

internal:
// SDL-specific methods
SDL_DisplayMode CalcCurrentDisplayMode();
void PumpEvents();
Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);

Expand Down
25 changes: 24 additions & 1 deletion src/video/winrt/SDL_winrtvideo.cpp
Expand Up @@ -147,10 +147,33 @@ WINRT_VideoInit(_THIS)
return 0;
}

SDL_DisplayMode
WINRT_CalcDisplayModeUsingNativeWindow()
{
// Create an empty, zeroed-out display mode:
SDL_DisplayMode mode;
SDL_zero(mode);

// Fill in most fields:
mode.format = SDL_PIXELFORMAT_RGB888;
mode.refresh_rate = 0; // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
mode.driverdata = NULL;

// Calculate the display size given the window size, taking into account
// the current display's DPI:
const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
const float dipsPerInch = 96.0f;
mode.w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
mode.h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);

return mode;
}


static int
WINRT_InitModes(_THIS)
{
SDL_DisplayMode mode = SDL_WinRTGlobalApp->CalcCurrentDisplayMode();
SDL_DisplayMode mode = WINRT_CalcDisplayModeUsingNativeWindow();
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}
Expand Down

0 comments on commit 17ca1d0

Please sign in to comment.