WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
authorDavid Ludwig <dludwig@pobox.com>
Sat, 09 Feb 2013 14:35:06 -0500
changeset 8411aca0591bc58f
parent 8410 ba725b3a0c87
child 8412 59f1191a5cca
WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
include/SDL_syswm.h
src/video/windowsrt/SDL_winrtvideo.cpp
src/video/windowsrt/SDL_winrtvideo.h
     1.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Sat Feb 09 11:42:17 2013 -0500
     1.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Sat Feb 09 14:35:06 2013 -0500
     1.3 @@ -299,7 +299,12 @@
     1.4      <ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
     1.5      <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
     1.6      <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
     1.7 -    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp" />
     1.8 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
     1.9 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.10 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.11 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.12 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.13 +    </ClCompile>
    1.14      <ClCompile Include="..\..\src\render\SDL_render.c" />
    1.15      <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
    1.16      <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
     2.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Sat Feb 09 11:42:17 2013 -0500
     2.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Sat Feb 09 14:35:06 2013 -0500
     2.3 @@ -78,7 +78,14 @@
     2.4      <ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
     2.5      <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
     2.6      <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
     2.7 -    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp" />
     2.8 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
     2.9 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    2.10 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    2.11 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    2.12 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    2.13 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    2.14 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    2.15 +    </ClCompile>
    2.16      <ClCompile Include="..\..\src\render\SDL_render.c" />
    2.17      <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
    2.18      <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
     3.1 --- a/include/SDL_syswm.h	Sat Feb 09 11:42:17 2013 -0500
     3.2 +++ b/include/SDL_syswm.h	Sat Feb 09 14:35:06 2013 -0500
     3.3 @@ -103,6 +103,7 @@
     3.4  {
     3.5      SDL_SYSWM_UNKNOWN,
     3.6      SDL_SYSWM_WINDOWS,
     3.7 +    SDL_SYSWM_WINDOWSRT,
     3.8      SDL_SYSWM_X11,
     3.9      SDL_SYSWM_DIRECTFB,
    3.10      SDL_SYSWM_COCOA,
    3.11 @@ -171,6 +172,12 @@
    3.12              HWND window;                /**< The window handle */
    3.13          } win;
    3.14  #endif
    3.15 +#if defined(SDL_VIDEO_DRIVER_WINRT)
    3.16 +        struct
    3.17 +        {
    3.18 +            void * window;          /**< The Windows RT CoreWindow, casted from 'CoreWindow ^*' to 'void *' */
    3.19 +        } winrt;
    3.20 +#endif
    3.21  #if defined(SDL_VIDEO_DRIVER_X11)
    3.22          struct
    3.23          {
     4.1 --- a/src/video/windowsrt/SDL_winrtvideo.cpp	Sat Feb 09 11:42:17 2013 -0500
     4.2 +++ b/src/video/windowsrt/SDL_winrtvideo.cpp	Sat Feb 09 14:35:06 2013 -0500
     4.3 @@ -35,6 +35,7 @@
     4.4  #include "../SDL_pixels_c.h"
     4.5  #include "../../events/SDL_events_c.h"
     4.6  #include "../../render/SDL_sysrender.h"
     4.7 +#include "SDL_syswm.h"
     4.8  }
     4.9  
    4.10  #include "SDL_WinRTApp.h"
    4.11 @@ -61,6 +62,7 @@
    4.12  /* Window functions */
    4.13  static int WINRT_CreateWindow(_THIS, SDL_Window * window);
    4.14  static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
    4.15 +static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
    4.16  
    4.17  /* WinRT driver bootstrap functions */
    4.18  
    4.19 @@ -101,6 +103,7 @@
    4.20      device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
    4.21      device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer;
    4.22      device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer;
    4.23 +    device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
    4.24  
    4.25      device->free = WINRT_DeleteDevice;
    4.26  
    4.27 @@ -159,14 +162,13 @@
    4.28          return -1;
    4.29      }
    4.30  
    4.31 -    SDL_WindowData *data;
    4.32 -    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
    4.33 +    SDL_WindowData *data = new SDL_WindowData;
    4.34      if (!data) {
    4.35          SDL_OutOfMemory();
    4.36          return -1;
    4.37      }
    4.38 -    SDL_zerop(data);
    4.39      data->sdlWindow = window;
    4.40 +    data->coreWindow = new CoreWindow^(CoreWindow::GetForCurrentThread());
    4.41  
    4.42      /* Make sure the window is considered to be positioned at {0,0},
    4.43         and is considered fullscreen, shown, and the like.
    4.44 @@ -222,6 +224,11 @@
    4.45      // resources first.
    4.46      //
    4.47      // TODO, WinRT: either make WINRT_CreateWindow not call SDL_CreateRenderer, or have it do error checking if it does call it
    4.48 +
    4.49 +    // HACK: make sure the SDL window references SDL_WindowData data now, in
    4.50 +    // order to allow the SDL_Renderer to be created in WINRT_CreateWindow
    4.51 +    window->driverdata = data;
    4.52 +
    4.53      SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
    4.54      SDL_WinRTGlobalApp->m_renderer->m_sdlRenderer = renderer;
    4.55      SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata;
    4.56 @@ -234,6 +241,21 @@
    4.57  void
    4.58  WINRT_DestroyWindow(_THIS, SDL_Window * window)
    4.59  {
    4.60 +    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
    4.61 +
    4.62 +    if (data) {
    4.63 +        // Delete the reference to the WinRT CoreWindow:
    4.64 +        CoreWindow ^* windowPointer = ((SDL_WindowData *) window->driverdata)->coreWindow;
    4.65 +        if (windowPointer) {
    4.66 +            *windowPointer = nullptr;   // Clear the C++/CX reference to the CoreWindow
    4.67 +            delete windowPointer;       // Delete the C++/CX reference itself
    4.68 +        }
    4.69 +
    4.70 +        // Delete the internal window data:
    4.71 +        delete data;
    4.72 +        data = NULL;
    4.73 +    }
    4.74 +
    4.75      if (SDL_WinRTGlobalApp->HasSDLWindowData() &&
    4.76          SDL_WinRTGlobalApp->GetSDLWindowData()->sdlWindow == window)
    4.77      {
    4.78 @@ -241,6 +263,23 @@
    4.79      }
    4.80  }
    4.81  
    4.82 +SDL_bool
    4.83 +WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
    4.84 +{
    4.85 +    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
    4.86 +    CoreWindow ^* windowPointer = data->coreWindow;
    4.87 +
    4.88 +    if (info->version.major <= SDL_MAJOR_VERSION) {
    4.89 +        info->subsystem = SDL_SYSWM_WINDOWSRT;
    4.90 +        info->info.winrt.window = windowPointer;
    4.91 +        return SDL_TRUE;
    4.92 +    } else {
    4.93 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
    4.94 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
    4.95 +        return SDL_FALSE;
    4.96 +    }
    4.97 +    return SDL_FALSE;
    4.98 +}
    4.99  
   4.100  #endif /* SDL_VIDEO_DRIVER_WINRT */
   4.101  
     5.1 --- a/src/video/windowsrt/SDL_winrtvideo.h	Sat Feb 09 11:42:17 2013 -0500
     5.2 +++ b/src/video/windowsrt/SDL_winrtvideo.h	Sat Feb 09 14:35:06 2013 -0500
     5.3 @@ -23,19 +23,14 @@
     5.4  #ifndef _SDL_winrtvideo_h
     5.5  #define _SDL_winrtvideo_h
     5.6  
     5.7 -#ifdef __cplusplus
     5.8  extern "C" {
     5.9 -#endif
    5.10 -
    5.11  #include "../SDL_sysvideo.h"
    5.12 -
    5.13 -#ifdef __cplusplus
    5.14  }
    5.15 -#endif
    5.16  
    5.17  struct SDL_WindowData
    5.18  {
    5.19      SDL_Window *sdlWindow;
    5.20 +    Windows::UI::Core::CoreWindow ^* coreWindow;
    5.21  };
    5.22  
    5.23  #endif /* _SDL_winrtvideo_h */