Fixed compiler errors in the D3D11 renderer when building for WinRT
authorDavid Ludwig <dludwig@pobox.com>
Tue, 11 Mar 2014 12:40:31 -0400
changeset 8608 c5d603f7094e
parent 8607 ef23c9d08eed
child 8609 d59f0f12bf07
child 8611 a762dfc67e1a
Fixed compiler errors in the D3D11 renderer when building for WinRT Still TODO: fix other build errors, especially linker errors, when building SDL/WinRT, then fix any runtime errors that pop up.
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters
src/render/direct3d11/SDL_render_d3d11.c
src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp
src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h
--- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Mon Mar 10 22:53:03 2014 -0400
+++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Tue Mar 11 12:40:31 2014 -0400
@@ -97,6 +97,14 @@
     <ClCompile Include="..\..\src\joystick\winrt\SDL_xinputjoystick.c" />
     <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
     <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers.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\opengles2\SDL_render_gles2.c" />
     <ClCompile Include="..\..\src\render\opengles2\SDL_shaders_gles2.c" />
     <ClCompile Include="..\..\src\render\SDL_render.c" />
@@ -277,6 +285,7 @@
     <ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
     <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
     <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
+    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers_cpp.h" />
     <ClInclude Include="..\..\src\render\mmx.h" />
     <ClInclude Include="..\..\src\render\opengles2\SDL_gles2funcs.h" />
     <ClInclude Include="..\..\src\render\opengles2\SDL_shaders_gles2.h" />
--- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters	Mon Mar 10 22:53:03 2014 -0400
+++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters	Tue Mar 11 12:40:31 2014 -0400
@@ -280,6 +280,9 @@
     <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\include\begin_code.h">
@@ -636,6 +639,9 @@
     <ClInclude Include="..\..\src\SDL_internal.h">
       <Filter>Source Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers_cpp.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Header Files">
--- a/src/render/direct3d11/SDL_render_d3d11.c	Mon Mar 10 22:53:03 2014 -0400
+++ b/src/render/direct3d11/SDL_render_d3d11.c	Tue Mar 11 12:40:31 2014 -0400
@@ -22,18 +22,6 @@
 
 #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
 
-#ifdef __WINRT__
-#include <windows.ui.core.h>
-#include <windows.foundation.h>
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_APP
-#include <windows.ui.xaml.media.dxinterop.h>
-#endif
-
-using namespace Windows::UI::Core;
-using namespace Windows::Graphics::Display;
-#endif  /* __WINRT__ */
-
 #define COBJMACROS
 #include "../../core/windows/SDL_windows.h"
 #include "SDL_hints.h"
@@ -45,6 +33,19 @@
 #include <d3d11_1.h>
 
 
+#ifdef __WINRT__
+
+#include "SDL_render_d3d11_winrthelpers_cpp.h"
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+#include <windows.ui.xaml.media.dxinterop.h>
+/* TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var */
+extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative;
+#endif  /* WINAPI_FAMILY == WINAPI_FAMILY_APP */
+
+#endif  /* __WINRT__ */
+
+
 #define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; }
 
 
@@ -960,10 +961,11 @@
     D3D11_SAMPLER_DESC samplerDesc;
     D3D11_RASTERIZER_DESC rasterDesc;
 
-#ifdef __WINRT__
-    CreateDXGIFactoryFunc = CreateDXGIFactory;
-    D3D11CreateDeviceFunc = D3D11CreateDevice;
-#else
+    // TODO, WinRT, Mar 11, 2014: once SDL/WinRT is back up and running, see if D3D11 init functions are loadable (via LoadPackagedLibrary/SDL_LoadObject, etc.)
+//#ifdef __WINRT__
+//    CreateDXGIFactoryFunc = CreateDXGIFactory;
+//    D3D11CreateDeviceFunc = D3D11CreateDevice;
+//#else
     data->hDXGIMod = SDL_LoadObject("dxgi.dll");
     if (!data->hDXGIMod) {
         result = E_FAIL;
@@ -987,7 +989,7 @@
         result = E_FAIL;
         goto done;
     }
-#endif /* __WINRT__ */
+//#endif /* __WINRT__ */
 
     result = CreateDXGIFactoryFunc(&IID_IDXGIFactory2, &data->dxgiFactory);
     if (FAILED(result)) {
@@ -1269,79 +1271,7 @@
     return result;
 }
 
-#ifdef __WINRT__
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_APP
-/* TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var */
-extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative;
-#endif
-
-static IUnknown *
-D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
-{
-    SDL_Window * sdlWindow = renderer->window;
-    if (!renderer->window) {
-        return NULL;
-    }
-
-    SDL_SysWMinfo sdlWindowInfo;
-    SDL_VERSION(&sdlWindowInfo.version);
-    if (!SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo)) {
-        return NULL;
-    }
-
-    if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
-        return NULL;
-    }
-
-    if (!sdlWindowInfo.info.winrt.window) {
-        return NULL;
-    }
-
-    ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
-    if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
-        return NULL;
-    }
-
-    IUnknown *coreWindowAsIUnknown = NULL;
-    coreWindow->QueryInterface(&coreWindowAsIUnknown);
-    coreWindow->Release();
-
-    return coreWindowAsIUnknown;
-}
-
-static DXGI_MODE_ROTATION
-D3D11_GetCurrentRotation()
-{
-    switch (DisplayProperties::CurrentOrientation) {
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
-        /* Windows Phone rotations */
-    case DisplayOrientations::Landscape:
-        return DXGI_MODE_ROTATION_ROTATE90;
-    case DisplayOrientations::Portrait:
-        return DXGI_MODE_ROTATION_IDENTITY;
-    case DisplayOrientations::LandscapeFlipped:
-        return DXGI_MODE_ROTATION_ROTATE270;
-    case DisplayOrientations::PortraitFlipped:
-        return DXGI_MODE_ROTATION_ROTATE180;
-#else
-        /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
-    case DisplayOrientations::Landscape:
-        return DXGI_MODE_ROTATION_IDENTITY;
-    case DisplayOrientations::Portrait:
-        return DXGI_MODE_ROTATION_ROTATE270;
-    case DisplayOrientations::LandscapeFlipped:
-        return DXGI_MODE_ROTATION_ROTATE180;
-    case DisplayOrientations::PortraitFlipped:
-        return DXGI_MODE_ROTATION_ROTATE90;
-#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
-
-    default:
-        return DXGI_MODE_ROTATION_UNSPECIFIED;
-    }
-}
-
-#else
+#ifdef __WIN32__
 
 static DXGI_MODE_ROTATION
 D3D11_GetCurrentRotation()
@@ -1350,7 +1280,7 @@
     return DXGI_MODE_ROTATION_IDENTITY;
 }
 
-#endif /* __WINRT__ */
+#endif /* __WIN32__ */
 
 static BOOL
 D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation)
@@ -1460,7 +1390,7 @@
         }
 
 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
-        result = WINRT_GlobalSwapChainBackgroundPanelNative->SetSwapChain(data->swapChain);
+        result = ISwapChainBackgroundPanelNative_SetSwapChain(WINRT_GlobalSwapChainBackgroundPanelNative, (IDXGISwapChain *) data->swapChain);
         if (FAILED(result)) {
             WIN_SetErrorFromHRESULT(__FUNCTION__ ", ISwapChainBackgroundPanelNative::SetSwapChain", result);
             goto done;
@@ -1471,6 +1401,7 @@
         goto done;
 #endif
     } else {
+#ifdef __WIN32__
         SDL_SysWMinfo windowinfo;
         SDL_VERSION(&windowinfo.version);
         SDL_GetWindowWMInfo(renderer->window, &windowinfo);
@@ -1487,6 +1418,10 @@
             WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory2::CreateSwapChainForHwnd", result);
             goto done;
         }
+#else
+        SDL_SetError(__FUNCTION__", Unable to find something to attach a swap chain to");
+        goto done;
+#endif  /* ifdef __WIN32__ / else */
     }
     data->swapEffect = swapChainDesc.SwapEffect;
 
@@ -2379,7 +2314,7 @@
 D3D11_RenderSetBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
 {
     D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
-    ID3D11BlendState *blendState;
+    ID3D11BlendState *blendState = NULL;
     switch (blendMode) {
     case SDL_BLENDMODE_BLEND:
         blendState = rendererData->blendModeBlend;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp	Tue Mar 11 12:40:31 2014 -0400
@@ -0,0 +1,109 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+#include "SDL_syswm.h"
+extern "C" {
+#include "../SDL_sysrender.h"
+}
+
+#include <windows.ui.core.h>
+#include <windows.foundation.h>
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+#include <windows.ui.xaml.media.dxinterop.h>
+#endif
+
+using namespace Windows::UI::Core;
+using namespace Windows::Graphics::Display;
+
+
+extern "C" void *
+D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
+{
+    SDL_Window * sdlWindow = renderer->window;
+    if ( ! renderer->window ) {
+        return NULL;
+    }
+
+    SDL_SysWMinfo sdlWindowInfo;
+    SDL_VERSION(&sdlWindowInfo.version);
+    if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) {
+        return NULL;
+    }
+
+    if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
+        return NULL;
+    }
+
+    if (!sdlWindowInfo.info.winrt.window) {
+        return NULL;
+    }
+
+    ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
+    if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
+        return NULL;
+    }
+
+    IUnknown *coreWindowAsIUnknown = NULL;
+    coreWindow->QueryInterface(&coreWindowAsIUnknown);
+    coreWindow->Release();
+
+    return coreWindowAsIUnknown;
+}
+
+extern "C" DXGI_MODE_ROTATION
+D3D11_GetCurrentRotation()
+{
+    switch (DisplayProperties::CurrentOrientation) {
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+        /* Windows Phone rotations */
+        case DisplayOrientations::Landscape:
+            return DXGI_MODE_ROTATION_ROTATE90;
+        case DisplayOrientations::Portrait:
+            return DXGI_MODE_ROTATION_IDENTITY;
+        case DisplayOrientations::LandscapeFlipped:
+            return DXGI_MODE_ROTATION_ROTATE270;
+        case DisplayOrientations::PortraitFlipped:
+            return DXGI_MODE_ROTATION_ROTATE180;
+#else
+        /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
+        case DisplayOrientations::Landscape:
+            return DXGI_MODE_ROTATION_IDENTITY;
+        case DisplayOrientations::Portrait:
+            return DXGI_MODE_ROTATION_ROTATE270;
+        case DisplayOrientations::LandscapeFlipped:
+            return DXGI_MODE_ROTATION_ROTATE180;
+        case DisplayOrientations::PortraitFlipped:
+            return DXGI_MODE_ROTATION_ROTATE90;
+#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
+
+    default:
+        return DXGI_MODE_ROTATION_UNSPECIFIED;
+    }
+}
+
+
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h	Tue Mar 11 12:40:31 2014 -0400
@@ -0,0 +1,40 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+#include "SDL_render.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void * D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer);
+DXGI_MODE_ROTATION D3D11_GetCurrentRotation();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */