From 44af1681c014b5a95ef8502cc0291d34d873e9ce Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Sat, 9 Feb 2013 14:35:06 -0500 Subject: [PATCH] WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow --- .../SDL/SDL_VS2012-WinPhone.vcxproj | 7 ++- VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj | 9 +++- include/SDL_syswm.h | 7 +++ src/video/windowsrt/SDL_winrtvideo.cpp | 45 +++++++++++++++++-- src/video/windowsrt/SDL_winrtvideo.h | 7 +-- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj index f2850a547..4ddc0a112 100644 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj @@ -299,7 +299,12 @@ - + + true + true + true + true + diff --git a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj index 9e5306e39..c5a803fbc 100644 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj @@ -78,7 +78,14 @@ - + + true + true + true + true + true + true + diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h index a96f42e2d..69a08e19e 100644 --- a/include/SDL_syswm.h +++ b/include/SDL_syswm.h @@ -103,6 +103,7 @@ typedef enum { SDL_SYSWM_UNKNOWN, SDL_SYSWM_WINDOWS, + SDL_SYSWM_WINDOWSRT, SDL_SYSWM_X11, SDL_SYSWM_DIRECTFB, SDL_SYSWM_COCOA, @@ -171,6 +172,12 @@ struct SDL_SysWMinfo HWND window; /**< The window handle */ } win; #endif +#if defined(SDL_VIDEO_DRIVER_WINRT) + struct + { + void * window; /**< The Windows RT CoreWindow, casted from 'CoreWindow ^*' to 'void *' */ + } winrt; +#endif #if defined(SDL_VIDEO_DRIVER_X11) struct { diff --git a/src/video/windowsrt/SDL_winrtvideo.cpp b/src/video/windowsrt/SDL_winrtvideo.cpp index 6c9098847..fb067f843 100644 --- a/src/video/windowsrt/SDL_winrtvideo.cpp +++ b/src/video/windowsrt/SDL_winrtvideo.cpp @@ -35,6 +35,7 @@ extern "C" { #include "../SDL_pixels_c.h" #include "../../events/SDL_events_c.h" #include "../../render/SDL_sysrender.h" +#include "SDL_syswm.h" } #include "SDL_WinRTApp.h" @@ -61,6 +62,7 @@ static void WINRT_VideoQuit(_THIS); /* Window functions */ 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); /* WinRT driver bootstrap functions */ @@ -101,6 +103,7 @@ WINRT_CreateDevice(int devindex) device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer; device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer; device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer; + device->GetWindowWMInfo = WINRT_GetWindowWMInfo; device->free = WINRT_DeleteDevice; @@ -159,14 +162,13 @@ WINRT_CreateWindow(_THIS, SDL_Window * window) return -1; } - SDL_WindowData *data; - data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); + SDL_WindowData *data = new SDL_WindowData; if (!data) { SDL_OutOfMemory(); return -1; } - SDL_zerop(data); data->sdlWindow = window; + data->coreWindow = new CoreWindow^(CoreWindow::GetForCurrentThread()); /* Make sure the window is considered to be positioned at {0,0}, and is considered fullscreen, shown, and the like. @@ -222,6 +224,11 @@ WINRT_CreateWindow(_THIS, SDL_Window * window) // resources first. // // TODO, WinRT: either make WINRT_CreateWindow not call SDL_CreateRenderer, or have it do error checking if it does call it + + // HACK: make sure the SDL window references SDL_WindowData data now, in + // order to allow the SDL_Renderer to be created in WINRT_CreateWindow + window->driverdata = data; + SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE); SDL_WinRTGlobalApp->m_renderer->m_sdlRenderer = renderer; SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata; @@ -234,6 +241,21 @@ WINRT_CreateWindow(_THIS, SDL_Window * window) void WINRT_DestroyWindow(_THIS, SDL_Window * window) { + SDL_WindowData * data = (SDL_WindowData *) window->driverdata; + + if (data) { + // Delete the reference to the WinRT CoreWindow: + CoreWindow ^* windowPointer = ((SDL_WindowData *) window->driverdata)->coreWindow; + if (windowPointer) { + *windowPointer = nullptr; // Clear the C++/CX reference to the CoreWindow + delete windowPointer; // Delete the C++/CX reference itself + } + + // Delete the internal window data: + delete data; + data = NULL; + } + if (SDL_WinRTGlobalApp->HasSDLWindowData() && SDL_WinRTGlobalApp->GetSDLWindowData()->sdlWindow == window) { @@ -241,6 +263,23 @@ WINRT_DestroyWindow(_THIS, SDL_Window * window) } } +SDL_bool +WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) +{ + SDL_WindowData * data = (SDL_WindowData *) window->driverdata; + CoreWindow ^* windowPointer = data->coreWindow; + + if (info->version.major <= SDL_MAJOR_VERSION) { + info->subsystem = SDL_SYSWM_WINDOWSRT; + info->info.winrt.window = windowPointer; + 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 */ diff --git a/src/video/windowsrt/SDL_winrtvideo.h b/src/video/windowsrt/SDL_winrtvideo.h index fe8063f53..83eb78733 100644 --- a/src/video/windowsrt/SDL_winrtvideo.h +++ b/src/video/windowsrt/SDL_winrtvideo.h @@ -23,19 +23,14 @@ #ifndef _SDL_winrtvideo_h #define _SDL_winrtvideo_h -#ifdef __cplusplus extern "C" { -#endif - #include "../SDL_sysvideo.h" - -#ifdef __cplusplus } -#endif struct SDL_WindowData { SDL_Window *sdlWindow; + Windows::UI::Core::CoreWindow ^* coreWindow; }; #endif /* _SDL_winrtvideo_h */