SDL_render_winrt.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../../SDL_internal.h"
  19. #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
  20. #include "SDL_syswm.h"
  21. extern "C" {
  22. #include "../SDL_sysrender.h"
  23. }
  24. #include <windows.ui.core.h>
  25. #include <windows.graphics.display.h>
  26. #if WINAPI_FAMILY == WINAPI_FAMILY_APP
  27. #include <windows.ui.xaml.media.dxinterop.h>
  28. #endif
  29. using namespace ABI;
  30. using namespace Windows::UI::Core;
  31. using namespace Windows::Graphics::Display;
  32. #include <DXGI.h>
  33. #include "SDL_render_winrt.h"
  34. extern "C" void *
  35. D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
  36. {
  37. SDL_Window * sdlWindow = renderer->window;
  38. if ( ! renderer->window ) {
  39. return NULL;
  40. }
  41. SDL_SysWMinfo sdlWindowInfo;
  42. SDL_VERSION(&sdlWindowInfo.version);
  43. if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) {
  44. return NULL;
  45. }
  46. if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
  47. return NULL;
  48. }
  49. if (!sdlWindowInfo.info.winrt.window) {
  50. return NULL;
  51. }
  52. ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
  53. if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
  54. return NULL;
  55. }
  56. IUnknown *coreWindowAsIUnknown = NULL;
  57. coreWindow->QueryInterface(&coreWindowAsIUnknown);
  58. coreWindow->Release();
  59. return coreWindowAsIUnknown;
  60. }
  61. extern "C" DXGI_MODE_ROTATION
  62. D3D11_GetCurrentRotation()
  63. {
  64. #if 0 /* FIXME: This doesn't compile on Visual Studio 2013 */
  65. switch (DisplayProperties::CurrentOrientation) {
  66. #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  67. /* Windows Phone rotations */
  68. case DisplayOrientations::Landscape:
  69. return DXGI_MODE_ROTATION_ROTATE90;
  70. case DisplayOrientations::Portrait:
  71. return DXGI_MODE_ROTATION_IDENTITY;
  72. case DisplayOrientations::LandscapeFlipped:
  73. return DXGI_MODE_ROTATION_ROTATE270;
  74. case DisplayOrientations::PortraitFlipped:
  75. return DXGI_MODE_ROTATION_ROTATE180;
  76. #else
  77. /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
  78. case DisplayOrientations::Landscape:
  79. return DXGI_MODE_ROTATION_IDENTITY;
  80. case DisplayOrientations::Portrait:
  81. return DXGI_MODE_ROTATION_ROTATE270;
  82. case DisplayOrientations::LandscapeFlipped:
  83. return DXGI_MODE_ROTATION_ROTATE180;
  84. case DisplayOrientations::PortraitFlipped:
  85. return DXGI_MODE_ROTATION_ROTATE90;
  86. #endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
  87. }
  88. #endif
  89. return DXGI_MODE_ROTATION_IDENTITY;
  90. }
  91. #endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
  92. /* vi: set ts=4 sw=4 expandtab: */