Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreW…
Browse files Browse the repository at this point in the history
…indow
  • Loading branch information
DavidLudwig committed Feb 9, 2013
1 parent 7e7e3ff commit 44af168
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
7 changes: 6 additions & 1 deletion VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj
Expand Up @@ -299,7 +299,12 @@
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\SDL_joystick.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_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
Expand Down
9 changes: 8 additions & 1 deletion VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
Expand Up @@ -78,7 +78,14 @@
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\SDL_joystick.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_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
Expand Down
7 changes: 7 additions & 0 deletions include/SDL_syswm.h
Expand Up @@ -103,6 +103,7 @@ typedef enum
{
SDL_SYSWM_UNKNOWN,
SDL_SYSWM_WINDOWS,
SDL_SYSWM_WINDOWSRT,
SDL_SYSWM_X11,
SDL_SYSWM_DIRECTFB,
SDL_SYSWM_COCOA,
Expand Down Expand Up @@ -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
{
Expand Down
45 changes: 42 additions & 3 deletions src/video/windowsrt/SDL_winrtvideo.cpp
Expand Up @@ -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"
Expand All @@ -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 */

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -234,13 +241,45 @@ 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)
{
SDL_WinRTGlobalApp->SetSDLWindowData(NULL);
}
}

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 */

Expand Down
7 changes: 1 addition & 6 deletions src/video/windowsrt/SDL_winrtvideo.h
Expand Up @@ -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 */
Expand Down

0 comments on commit 44af168

Please sign in to comment.