From 34722465d1de9b1f86dfb94dfeefbe7c09d55eb8 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Fri, 6 Sep 2013 21:13:15 -0400 Subject: [PATCH] WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML) --- .../SDL/SDL_VS2012-WinPhone.vcxproj | 10 +- .../SDL/SDL_VS2012-WinPhone.vcxproj.filters | 22 +- VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj | 10 +- .../SDL/SDL_VS2012-WinRT.vcxproj.filters | 20 +- ...winrtapp.cpp => SDL_winrtapp_direct3d.cpp} | 2 +- ...SDL_winrtapp.h => SDL_winrtapp_direct3d.h} | 0 ...DL_winrtxaml.cpp => SDL_winrtapp_xaml.cpp} | 36 +-- ...DL_winrtxaml_cpp.h => SDL_winrtapp_xaml.h} | 6 +- src/video/winrt/SDL_winrtevents.cpp | 4 +- src/video/winrt/SDL_winrtmouse.cpp | 2 +- src/video/winrt/SDL_winrtvideo.cpp | 276 +++++++++--------- 11 files changed, 194 insertions(+), 194 deletions(-) rename src/core/winrt/{SDL_winrtapp.cpp => SDL_winrtapp_direct3d.cpp} (97%) rename src/core/winrt/{SDL_winrtapp.h => SDL_winrtapp_direct3d.h} (100%) rename src/core/winrt/{SDL_winrtxaml.cpp => SDL_winrtapp_xaml.cpp} (99%) rename src/core/winrt/{SDL_winrtxaml_cpp.h => SDL_winrtapp_xaml.h} (92%) diff --git a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj index 474039e856298..fce026f16d62e 100644 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj @@ -197,8 +197,8 @@ - - + + @@ -269,19 +269,19 @@ true - + true true true true - + true true true true - + true true true diff --git a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters index 2b5524e9ccffc..9e2d8ee273c2c 100644 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters @@ -321,24 +321,24 @@ Source Files - - Source Files - Source Files Source Files - - Source Files - Source Files Header Files + + Source Files + + + Source Files + @@ -581,9 +581,6 @@ Source Files - - Source Files - Source Files @@ -599,10 +596,13 @@ Source Files - + Source Files - + + Source Files + + Source Files diff --git a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj index 66bdee538f5c3..c383a26150a67 100644 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj @@ -47,7 +47,7 @@ true - + true true true @@ -55,7 +55,7 @@ true true - + true true true @@ -63,7 +63,7 @@ true true - + true true true @@ -244,8 +244,8 @@ - - + + diff --git a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters index 4c22c3f8182d1..fad8ce82bae84 100644 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters @@ -258,9 +258,6 @@ Source Files - - Source Files - Source Files @@ -273,7 +270,10 @@ Source Files - + + Source Files + + Source Files @@ -593,21 +593,21 @@ Source Files - - Source Files - Source Files - - Source Files - Source Files Header Files + + Source Files + + + Source Files + diff --git a/src/core/winrt/SDL_winrtapp.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp similarity index 97% rename from src/core/winrt/SDL_winrtapp.cpp rename to src/core/winrt/SDL_winrtapp_direct3d.cpp index f421ea45efbb0..7bcd528d7ea6a 100644 --- a/src/core/winrt/SDL_winrtapp.cpp +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp @@ -38,7 +38,7 @@ extern "C" { #include "../../video/winrt/SDL_winrtevents_c.h" #include "../../video/winrt/SDL_winrtvideo_cpp.h" -#include "SDL_winrtapp.h" +#include "SDL_winrtapp_direct3d.h" // Compile-time debugging options: diff --git a/src/core/winrt/SDL_winrtapp.h b/src/core/winrt/SDL_winrtapp_direct3d.h similarity index 100% rename from src/core/winrt/SDL_winrtapp.h rename to src/core/winrt/SDL_winrtapp_direct3d.h diff --git a/src/core/winrt/SDL_winrtxaml.cpp b/src/core/winrt/SDL_winrtapp_xaml.cpp similarity index 99% rename from src/core/winrt/SDL_winrtxaml.cpp rename to src/core/winrt/SDL_winrtapp_xaml.cpp index 42500c3b5d4d6..055569377ce72 100644 --- a/src/core/winrt/SDL_winrtxaml.cpp +++ b/src/core/winrt/SDL_winrtapp_xaml.cpp @@ -32,7 +32,7 @@ #include "SDL.h" #include "../../video/winrt/SDL_winrtevents_c.h" #include "../../video/winrt/SDL_winrtvideo_cpp.h" -#include "SDL_winrtxaml_cpp.h" +#include "SDL_winrtapp_xaml.h" @@ -51,28 +51,28 @@ static Windows::Foundation::EventRegistrationToken WINRT_XAMLAppEventToken; */ #if WINAPI_FAMILY == WINAPI_FAMILY_APP -static void -WINRT_OnPointerPressedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args) -{ - WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr)); +static void +WINRT_OnPointerPressedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args) +{ + WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr)); } -static void -WINRT_OnPointerMovedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args) -{ - WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr)); +static void +WINRT_OnPointerMovedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args) +{ + WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr)); } -static void -WINRT_OnPointerReleasedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args) -{ - WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr)); +static void +WINRT_OnPointerReleasedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args) +{ + WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr)); } -static void -WINRT_OnPointerWheelChangedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args) -{ - WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr)); +static void +WINRT_OnPointerWheelChangedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args) +{ + WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr)); } #endif // WINAPI_FAMILY == WINAPI_FAMILY_APP @@ -128,7 +128,7 @@ SDL_WinRTInitXAMLApp(Platform::Object ^backgroundPanel, int (*mainFunction)(int, swapChainBackgroundPanel->PointerMoved += ref new PointerEventHandler(WINRT_OnPointerMovedViaXAML); // Setup for rendering: - IInspectable *panelInspectable = (IInspectable*) reinterpret_cast(swapChainBackgroundPanel); + IInspectable *panelInspectable = (IInspectable*) reinterpret_cast(swapChainBackgroundPanel); panelInspectable->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void **)&WINRT_GlobalSwapChainBackgroundPanelNative); WINRT_XAMLAppEventToken = CompositionTarget::Rendering::add(ref new EventHandler(WINRT_OnRenderViaXAML)); diff --git a/src/core/winrt/SDL_winrtxaml_cpp.h b/src/core/winrt/SDL_winrtapp_xaml.h similarity index 92% rename from src/core/winrt/SDL_winrtxaml_cpp.h rename to src/core/winrt/SDL_winrtapp_xaml.h index e0997beccd9f5..2beaad8072de7 100644 --- a/src/core/winrt/SDL_winrtxaml_cpp.h +++ b/src/core/winrt/SDL_winrtapp_xaml.h @@ -20,8 +20,8 @@ */ #include "SDL_config.h" -#ifndef _SDL_winrtxaml_h -#define _SDL_winrtxaml_h +#ifndef _SDL_winrtapp_xaml_h +#define _SDL_winrtapp_xaml_h #include "SDL_types.h" @@ -30,4 +30,4 @@ extern SDL_bool WINRT_XAMLWasEnabled; extern int (*WINRT_XAMLAppMainFunction)(int, char **); #endif // ifdef __cplusplus -#endif // ifndef _SDL_winrtxaml_h +#endif // ifndef _SDL_winrtapp_xaml_h diff --git a/src/video/winrt/SDL_winrtevents.cpp b/src/video/winrt/SDL_winrtevents.cpp index 94d71590a3ed3..b766177831a29 100644 --- a/src/video/winrt/SDL_winrtevents.cpp +++ b/src/video/winrt/SDL_winrtevents.cpp @@ -33,8 +33,8 @@ using Windows::UI::Core::CoreCursor; * SDL includes: */ #include "SDL_winrtevents_c.h" -#include "../../core/winrt/SDL_winrtapp.h" -#include "../../core/winrt/SDL_winrtxaml_cpp.h" +#include "../../core/winrt/SDL_winrtapp_direct3d.h" +#include "../../core/winrt/SDL_winrtapp_xaml.h" #include "SDL_assert.h" #include "SDL_system.h" diff --git a/src/video/winrt/SDL_winrtmouse.cpp b/src/video/winrt/SDL_winrtmouse.cpp index 8f07f4302875d..c2605e47f1328 100644 --- a/src/video/winrt/SDL_winrtmouse.cpp +++ b/src/video/winrt/SDL_winrtmouse.cpp @@ -42,7 +42,7 @@ extern "C" { #include "SDL_log.h" } -#include "../../core/winrt/SDL_winrtapp.h" +#include "../../core/winrt/SDL_winrtapp_direct3d.h" #include "SDL_winrtvideo_cpp.h" #include "SDL_winrtmouse_c.h" diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index d7de493e70023..2bd4444718757 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -44,8 +44,8 @@ extern "C" { #include "SDL_syswm.h" } -#include "../../core/winrt/SDL_winrtapp.h" -#include "../../core/winrt/SDL_winrtxaml_cpp.h" +#include "../../core/winrt/SDL_winrtapp_direct3d.h" +#include "../../core/winrt/SDL_winrtapp_xaml.h" #include "SDL_winrtvideo_cpp.h" #include "SDL_winrtevents_c.h" #include "SDL_winrtmouse_c.h" @@ -61,7 +61,7 @@ static void WINRT_VideoQuit(_THIS); /* Window functions */ -static int WINRT_CreateWindow(_THIS, SDL_Window * window); +static int WINRT_CreateWindow(_THIS, SDL_Window * window); static void WINRT_DestroyWindow(_THIS, SDL_Window * window); static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info); @@ -131,76 +131,76 @@ WINRT_VideoInit(_THIS) } WINRT_InitMouse(_this); WINRT_InitTouch(_this); - + return 0; } -SDL_DisplayMode -WINRT_CalcDisplayModeUsingNativeWindow() -{ - using namespace Windows::Graphics::Display; - - // Create an empty, zeroed-out display mode: - SDL_DisplayMode mode; - SDL_zero(mode); - - // Go no further if a native window cannot be accessed. This can happen, - // for example, if this function is called from certain threads, such as - // the SDL/XAML thread. - if (!CoreWindow::GetForCurrentThread()) { - return 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 = (void *) DisplayProperties::CurrentOrientation; - - // 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); - -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - // On Windows Phone, the native window's size is always in portrait, - // regardless of the device's orientation. This is in contrast to - // Windows 8/RT, which will resize the native window as the device's - // orientation changes. In order to compensate for this behavior, - // on Windows Phone, the mode's width and height will be swapped when - // the device is in a landscape (non-portrait) mode. - switch (DisplayProperties::CurrentOrientation) { - case DisplayOrientations::Landscape: - case DisplayOrientations::LandscapeFlipped: - { - const int tmp = mode.h; - mode.h = mode.w; - mode.w = tmp; - break; - } - - default: - break; - } - - // Attach the mode to te -#endif - - return mode; -} +SDL_DisplayMode +WINRT_CalcDisplayModeUsingNativeWindow() +{ + using namespace Windows::Graphics::Display; + + // Create an empty, zeroed-out display mode: + SDL_DisplayMode mode; + SDL_zero(mode); + + // Go no further if a native window cannot be accessed. This can happen, + // for example, if this function is called from certain threads, such as + // the SDL/XAML thread. + if (!CoreWindow::GetForCurrentThread()) { + return 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 = (void *) DisplayProperties::CurrentOrientation; + + // 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); + +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP + // On Windows Phone, the native window's size is always in portrait, + // regardless of the device's orientation. This is in contrast to + // Windows 8/RT, which will resize the native window as the device's + // orientation changes. In order to compensate for this behavior, + // on Windows Phone, the mode's width and height will be swapped when + // the device is in a landscape (non-portrait) mode. + switch (DisplayProperties::CurrentOrientation) { + case DisplayOrientations::Landscape: + case DisplayOrientations::LandscapeFlipped: + { + const int tmp = mode.h; + mode.h = mode.w; + mode.w = tmp; + break; + } + + default: + break; + } + + // Attach the mode to te +#endif + + return mode; +} int WINRT_InitModes(_THIS) { // Retrieve the display mode: - SDL_DisplayMode mode = WINRT_CalcDisplayModeUsingNativeWindow(); - if (mode.w == 0 || mode.h == 0) { - return SDL_SetError("Unable to calculate the WinRT window/display's size"); - } - - if (SDL_AddBasicVideoDisplay(&mode) < 0) { - return -1; + SDL_DisplayMode mode = WINRT_CalcDisplayModeUsingNativeWindow(); + if (mode.w == 0 || mode.h == 0) { + return SDL_SetError("Unable to calculate the WinRT window/display's size"); + } + + if (SDL_AddBasicVideoDisplay(&mode) < 0) { + return -1; } SDL_AddDisplayMode(&_this->displays[0], &mode); @@ -219,64 +219,64 @@ WINRT_VideoQuit(_THIS) WINRT_QuitMouse(_this); } -int -WINRT_CreateWindow(_THIS, SDL_Window * window) -{ - // Make sure that only one window gets created, at least until multimonitor - // support is added. - if (WINRT_GlobalSDLWindow != NULL) { - SDL_SetError("WinRT only supports one window"); - return -1; - } - - SDL_WindowData *data = new SDL_WindowData; - if (!data) { - SDL_OutOfMemory(); - return -1; - } - window->driverdata = data; - data->sdlWindow = window; - - /* To note, when XAML support is enabled, access to the CoreWindow will not - be possible, at least not via the SDL/XAML thread. Attempts to access it - from there will throw exceptions. As such, the SDL_WindowData's - 'coreWindow' field will only be set (to a non-null value) if XAML isn't - enabled. - */ - if (!WINRT_XAMLWasEnabled) { - data->coreWindow = CoreWindow::GetForCurrentThread(); - } - - /* Make sure the window is considered to be positioned at {0,0}, - and is considered fullscreen, shown, and the like. - */ - window->x = 0; - window->y = 0; - window->flags = - SDL_WINDOW_FULLSCREEN | - SDL_WINDOW_SHOWN | - SDL_WINDOW_BORDERLESS | - SDL_WINDOW_MAXIMIZED | - SDL_WINDOW_INPUT_GRABBED; - - /* WinRT does not, as of this writing, appear to support app-adjustable - window sizes. Set the window size to whatever the native WinRT - CoreWindow is set at. - - TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces. - */ - window->w = _this->displays[0].current_mode.w; - window->h = _this->displays[0].current_mode.h; - - /* Make sure the WinRT app's IFramworkView can post events on - behalf of SDL: - */ - WINRT_GlobalSDLWindow = window; - - /* All done! */ - return 0; -} - +int +WINRT_CreateWindow(_THIS, SDL_Window * window) +{ + // Make sure that only one window gets created, at least until multimonitor + // support is added. + if (WINRT_GlobalSDLWindow != NULL) { + SDL_SetError("WinRT only supports one window"); + return -1; + } + + SDL_WindowData *data = new SDL_WindowData; + if (!data) { + SDL_OutOfMemory(); + return -1; + } + window->driverdata = data; + data->sdlWindow = window; + + /* To note, when XAML support is enabled, access to the CoreWindow will not + be possible, at least not via the SDL/XAML thread. Attempts to access it + from there will throw exceptions. As such, the SDL_WindowData's + 'coreWindow' field will only be set (to a non-null value) if XAML isn't + enabled. + */ + if (!WINRT_XAMLWasEnabled) { + data->coreWindow = CoreWindow::GetForCurrentThread(); + } + + /* Make sure the window is considered to be positioned at {0,0}, + and is considered fullscreen, shown, and the like. + */ + window->x = 0; + window->y = 0; + window->flags = + SDL_WINDOW_FULLSCREEN | + SDL_WINDOW_SHOWN | + SDL_WINDOW_BORDERLESS | + SDL_WINDOW_MAXIMIZED | + SDL_WINDOW_INPUT_GRABBED; + + /* WinRT does not, as of this writing, appear to support app-adjustable + window sizes. Set the window size to whatever the native WinRT + CoreWindow is set at. + + TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces. + */ + window->w = _this->displays[0].current_mode.w; + window->h = _this->displays[0].current_mode.h; + + /* Make sure the WinRT app's IFramworkView can post events on + behalf of SDL: + */ + WINRT_GlobalSDLWindow = window; + + /* All done! */ + return 0; +} + void WINRT_DestroyWindow(_THIS, SDL_Window * window) { @@ -293,21 +293,21 @@ WINRT_DestroyWindow(_THIS, SDL_Window * window) } } -SDL_bool -WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) -{ - SDL_WindowData * data = (SDL_WindowData *) window->driverdata; - - if (info->version.major <= SDL_MAJOR_VERSION) { - info->subsystem = SDL_SYSWM_WINRT; - info->info.winrt.window = reinterpret_cast(data->coreWindow.Get()); - return SDL_TRUE; - } else { - SDL_SetError("Application not compiled with SDL %d.%d\n", - SDL_MAJOR_VERSION, SDL_MINOR_VERSION); - return SDL_FALSE; - } - return SDL_FALSE; +SDL_bool +WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) +{ + SDL_WindowData * data = (SDL_WindowData *) window->driverdata; + + if (info->version.major <= SDL_MAJOR_VERSION) { + info->subsystem = SDL_SYSWM_WINRT; + info->info.winrt.window = reinterpret_cast(data->coreWindow.Get()); + return SDL_TRUE; + } else { + SDL_SetError("Application not compiled with SDL %d.%d\n", + SDL_MAJOR_VERSION, SDL_MINOR_VERSION); + return SDL_FALSE; + } + return SDL_FALSE; } #endif /* SDL_VIDEO_DRIVER_WINRT */