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