From 36e7c8d92d5ab46f09ef456067cfce0d1871429e Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Tue, 11 Mar 2014 12:40:31 -0400 Subject: [PATCH] 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 | 9 ++ .../SDL/SDL-WinRT_VS2012.vcxproj.filters | 6 + src/render/direct3d11/SDL_render_d3d11.c | 121 ++++-------------- .../SDL_render_d3d11_winrthelpers.cpp | 109 ++++++++++++++++ .../SDL_render_d3d11_winrthelpers_cpp.h | 40 ++++++ 5 files changed, 192 insertions(+), 93 deletions(-) create mode 100644 src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp create mode 100644 src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h diff --git a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj index 53171dbd411a4..cc5fddd7b3946 100644 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj @@ -97,6 +97,14 @@ + + true + true + true + true + true + true + @@ -277,6 +285,7 @@ + diff --git a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters index f24a448d333be..fb3195f913000 100644 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters @@ -280,6 +280,9 @@ Source Files + + Source Files + @@ -636,6 +639,9 @@ Source Files + + Source Files + diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c index caa875599a818..58673d465445e 100644 --- a/src/render/direct3d11/SDL_render_d3d11.c +++ b/src/render/direct3d11/SDL_render_d3d11.c @@ -22,18 +22,6 @@ #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED -#ifdef __WINRT__ -#include -#include - -#if WINAPI_FAMILY == WINAPI_FAMILY_APP -#include -#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 @@ using namespace Windows::Graphics::Display; #include +#ifdef __WINRT__ + +#include "SDL_render_d3d11_winrthelpers_cpp.h" + +#if WINAPI_FAMILY == WINAPI_FAMILY_APP +#include +/* 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_CreateDeviceResources(SDL_Renderer * renderer) 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 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer) result = E_FAIL; goto done; } -#endif /* __WINRT__ */ +//#endif /* __WINRT__ */ result = CreateDXGIFactoryFunc(&IID_IDXGIFactory2, &data->dxgiFactory); if (FAILED(result)) { @@ -1269,79 +1271,7 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer) 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 @@ D3D11_GetCurrentRotation() return DXGI_MODE_ROTATION_IDENTITY; } -#endif /* __WINRT__ */ +#endif /* __WIN32__ */ static BOOL D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation) @@ -1460,7 +1390,7 @@ D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h) } #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 @@ D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h) goto done; #endif } else { +#ifdef __WIN32__ SDL_SysWMinfo windowinfo; SDL_VERSION(&windowinfo.version); SDL_GetWindowWMInfo(renderer->window, &windowinfo); @@ -1487,6 +1418,10 @@ D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h) 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 @@ static void 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; diff --git a/src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp b/src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp new file mode 100644 index 0000000000000..25e6765e92a1a --- /dev/null +++ b/src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp @@ -0,0 +1,109 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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 +#include + +#if WINAPI_FAMILY == WINAPI_FAMILY_APP +#include +#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: */ diff --git a/src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h b/src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h new file mode 100644 index 0000000000000..19df2a20cc7e8 --- /dev/null +++ b/src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h @@ -0,0 +1,40 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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: */