SDL_render_winrt.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 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 defined(SDL_VIDEO_RENDER_D3D11) && !defined(SDL_RENDER_DISABLED)
  20. #include "../../video/winrt/SDL_winrtvideo_cpp.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 Windows::UI::Core;
  30. using namespace Windows::Graphics::Display;
  31. #include <DXGI.h>
  32. #include "SDL_render_winrt.h"
  33. extern "C" void *
  34. D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer *renderer)
  35. {
  36. IInspectable *window = (IInspectable *)SDL_GetProperty(SDL_GetWindowProperties(renderer->window), SDL_PROP_WINDOW_WINRT_WINDOW_POINTER, NULL);
  37. ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
  38. if (!window || FAILED(window->QueryInterface(&coreWindow))) {
  39. return NULL;
  40. }
  41. IUnknown *coreWindowAsIUnknown = NULL;
  42. coreWindow->QueryInterface(&coreWindowAsIUnknown);
  43. coreWindow->Release();
  44. return coreWindowAsIUnknown;
  45. }
  46. extern "C" DXGI_MODE_ROTATION
  47. D3D11_GetCurrentRotation()
  48. {
  49. const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
  50. switch (currentOrientation) {
  51. #if SDL_WINAPI_FAMILY_PHONE
  52. /* Windows Phone rotations */
  53. case DisplayOrientations::Landscape:
  54. return DXGI_MODE_ROTATION_ROTATE90;
  55. case DisplayOrientations::Portrait:
  56. return DXGI_MODE_ROTATION_IDENTITY;
  57. case DisplayOrientations::LandscapeFlipped:
  58. return DXGI_MODE_ROTATION_ROTATE270;
  59. case DisplayOrientations::PortraitFlipped:
  60. return DXGI_MODE_ROTATION_ROTATE180;
  61. #else
  62. /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
  63. case DisplayOrientations::Landscape:
  64. return DXGI_MODE_ROTATION_IDENTITY;
  65. case DisplayOrientations::Portrait:
  66. return DXGI_MODE_ROTATION_ROTATE270;
  67. case DisplayOrientations::LandscapeFlipped:
  68. return DXGI_MODE_ROTATION_ROTATE180;
  69. case DisplayOrientations::PortraitFlipped:
  70. return DXGI_MODE_ROTATION_ROTATE90;
  71. #endif /* SDL_WINAPI_FAMILY_PHONE */
  72. }
  73. return DXGI_MODE_ROTATION_IDENTITY;
  74. }
  75. #endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */