WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow

This commit is contained in:
David Ludwig 2013-02-09 14:35:06 -05:00
parent 0bc7f7eac8
commit 4b6b1755fe
5 changed files with 64 additions and 11 deletions

View file

@ -299,7 +299,12 @@
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" /> <ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\SDL_joystick.c" /> <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" /> <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp" /> <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
</ClCompile>
<ClCompile Include="..\..\src\render\SDL_render.c" /> <ClCompile Include="..\..\src\render\SDL_render.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" /> <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" /> <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />

View file

@ -78,7 +78,14 @@
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" /> <ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\SDL_joystick.c" /> <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" /> <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp" /> <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
<ClCompile Include="..\..\src\render\SDL_render.c" /> <ClCompile Include="..\..\src\render\SDL_render.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" /> <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" /> <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />

View file

@ -103,6 +103,7 @@ typedef enum
{ {
SDL_SYSWM_UNKNOWN, SDL_SYSWM_UNKNOWN,
SDL_SYSWM_WINDOWS, SDL_SYSWM_WINDOWS,
SDL_SYSWM_WINDOWSRT,
SDL_SYSWM_X11, SDL_SYSWM_X11,
SDL_SYSWM_DIRECTFB, SDL_SYSWM_DIRECTFB,
SDL_SYSWM_COCOA, SDL_SYSWM_COCOA,
@ -171,6 +172,12 @@ struct SDL_SysWMinfo
HWND window; /**< The window handle */ HWND window; /**< The window handle */
} win; } win;
#endif #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) #if defined(SDL_VIDEO_DRIVER_X11)
struct struct
{ {

View file

@ -35,6 +35,7 @@ extern "C" {
#include "../SDL_pixels_c.h" #include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#include "../../render/SDL_sysrender.h" #include "../../render/SDL_sysrender.h"
#include "SDL_syswm.h"
} }
#include "SDL_WinRTApp.h" #include "SDL_WinRTApp.h"
@ -61,6 +62,7 @@ static void WINRT_VideoQuit(_THIS);
/* Window functions */ /* 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 void WINRT_DestroyWindow(_THIS, SDL_Window * window);
static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
/* WinRT driver bootstrap functions */ /* WinRT driver bootstrap functions */
@ -101,6 +103,7 @@ WINRT_CreateDevice(int devindex)
device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer; device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer; device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer; device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer;
device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
device->free = WINRT_DeleteDevice; device->free = WINRT_DeleteDevice;
@ -159,14 +162,13 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
return -1; return -1;
} }
SDL_WindowData *data; SDL_WindowData *data = new SDL_WindowData;
data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
if (!data) { if (!data) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
SDL_zerop(data);
data->sdlWindow = window; data->sdlWindow = window;
data->coreWindow = new CoreWindow^(CoreWindow::GetForCurrentThread());
/* Make sure the window is considered to be positioned at {0,0}, /* Make sure the window is considered to be positioned at {0,0},
and is considered fullscreen, shown, and the like. and is considered fullscreen, shown, and the like.
@ -222,6 +224,11 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
// resources first. // resources first.
// //
// TODO, WinRT: either make WINRT_CreateWindow not call SDL_CreateRenderer, or have it do error checking if it does call it // 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_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_sdlRenderer = renderer;
SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata; SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata;
@ -234,6 +241,21 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
void void
WINRT_DestroyWindow(_THIS, SDL_Window * window) 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() && if (SDL_WinRTGlobalApp->HasSDLWindowData() &&
SDL_WinRTGlobalApp->GetSDLWindowData()->sdlWindow == window) 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 */ #endif /* SDL_VIDEO_DRIVER_WINRT */

View file

@ -23,19 +23,14 @@
#ifndef _SDL_winrtvideo_h #ifndef _SDL_winrtvideo_h
#define _SDL_winrtvideo_h #define _SDL_winrtvideo_h
#ifdef __cplusplus
extern "C" { extern "C" {
#endif
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#ifdef __cplusplus
} }
#endif
struct SDL_WindowData struct SDL_WindowData
{ {
SDL_Window *sdlWindow; SDL_Window *sdlWindow;
Windows::UI::Core::CoreWindow ^* coreWindow;
}; };
#endif /* _SDL_winrtvideo_h */ #endif /* _SDL_winrtvideo_h */