src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp
changeset 8608 c5d603f7094e
child 8611 a762dfc67e1a
equal deleted inserted replaced
8607:ef23c9d08eed 8608:c5d603f7094e
       
     1 /*
       
     2   Simple DirectMedia Layer
       
     3   Copyright (C) 1997-2012 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 extern "C" {
       
    27 #include "../SDL_sysrender.h"
       
    28 }
       
    29 
       
    30 #include <windows.ui.core.h>
       
    31 #include <windows.foundation.h>
       
    32 
       
    33 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
       
    34 #include <windows.ui.xaml.media.dxinterop.h>
       
    35 #endif
       
    36 
       
    37 using namespace Windows::UI::Core;
       
    38 using namespace Windows::Graphics::Display;
       
    39 
       
    40 
       
    41 extern "C" void *
       
    42 D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
       
    43 {
       
    44     SDL_Window * sdlWindow = renderer->window;
       
    45     if ( ! renderer->window ) {
       
    46         return NULL;
       
    47     }
       
    48 
       
    49     SDL_SysWMinfo sdlWindowInfo;
       
    50     SDL_VERSION(&sdlWindowInfo.version);
       
    51     if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) {
       
    52         return NULL;
       
    53     }
       
    54 
       
    55     if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
       
    56         return NULL;
       
    57     }
       
    58 
       
    59     if (!sdlWindowInfo.info.winrt.window) {
       
    60         return NULL;
       
    61     }
       
    62 
       
    63     ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
       
    64     if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
       
    65         return NULL;
       
    66     }
       
    67 
       
    68     IUnknown *coreWindowAsIUnknown = NULL;
       
    69     coreWindow->QueryInterface(&coreWindowAsIUnknown);
       
    70     coreWindow->Release();
       
    71 
       
    72     return coreWindowAsIUnknown;
       
    73 }
       
    74 
       
    75 extern "C" DXGI_MODE_ROTATION
       
    76 D3D11_GetCurrentRotation()
       
    77 {
       
    78     switch (DisplayProperties::CurrentOrientation) {
       
    79 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
       
    80         /* Windows Phone rotations */
       
    81         case DisplayOrientations::Landscape:
       
    82             return DXGI_MODE_ROTATION_ROTATE90;
       
    83         case DisplayOrientations::Portrait:
       
    84             return DXGI_MODE_ROTATION_IDENTITY;
       
    85         case DisplayOrientations::LandscapeFlipped:
       
    86             return DXGI_MODE_ROTATION_ROTATE270;
       
    87         case DisplayOrientations::PortraitFlipped:
       
    88             return DXGI_MODE_ROTATION_ROTATE180;
       
    89 #else
       
    90         /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
       
    91         case DisplayOrientations::Landscape:
       
    92             return DXGI_MODE_ROTATION_IDENTITY;
       
    93         case DisplayOrientations::Portrait:
       
    94             return DXGI_MODE_ROTATION_ROTATE270;
       
    95         case DisplayOrientations::LandscapeFlipped:
       
    96             return DXGI_MODE_ROTATION_ROTATE180;
       
    97         case DisplayOrientations::PortraitFlipped:
       
    98             return DXGI_MODE_ROTATION_ROTATE90;
       
    99 #endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
       
   100 
       
   101     default:
       
   102         return DXGI_MODE_ROTATION_UNSPECIFIED;
       
   103     }
       
   104 }
       
   105 
       
   106 
       
   107 #endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
       
   108 
       
   109 /* vi: set ts=4 sw=4 expandtab: */