src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp
author David Ludwig <dludwig@pobox.com>
Wed, 12 Mar 2014 11:57:15 -0400
changeset 8611 a762dfc67e1a
parent 8608 c5d603f7094e
permissions -rw-r--r--
Fixed various build and runtime errors when using WinRT with VS2012.
     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 #include <DXGI.h>
    41 
    42 
    43 extern "C" void *
    44 D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
    45 {
    46     SDL_Window * sdlWindow = renderer->window;
    47     if ( ! renderer->window ) {
    48         return NULL;
    49     }
    50 
    51     SDL_SysWMinfo sdlWindowInfo;
    52     SDL_VERSION(&sdlWindowInfo.version);
    53     if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) {
    54         return NULL;
    55     }
    56 
    57     if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
    58         return NULL;
    59     }
    60 
    61     if (!sdlWindowInfo.info.winrt.window) {
    62         return NULL;
    63     }
    64 
    65     ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
    66     if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
    67         return NULL;
    68     }
    69 
    70     IUnknown *coreWindowAsIUnknown = NULL;
    71     coreWindow->QueryInterface(&coreWindowAsIUnknown);
    72     coreWindow->Release();
    73 
    74     return coreWindowAsIUnknown;
    75 }
    76 
    77 extern "C" DXGI_MODE_ROTATION
    78 D3D11_GetCurrentRotation()
    79 {
    80     switch (DisplayProperties::CurrentOrientation) {
    81 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    82         /* Windows Phone rotations */
    83         case DisplayOrientations::Landscape:
    84             return DXGI_MODE_ROTATION_ROTATE90;
    85         case DisplayOrientations::Portrait:
    86             return DXGI_MODE_ROTATION_IDENTITY;
    87         case DisplayOrientations::LandscapeFlipped:
    88             return DXGI_MODE_ROTATION_ROTATE270;
    89         case DisplayOrientations::PortraitFlipped:
    90             return DXGI_MODE_ROTATION_ROTATE180;
    91 #else
    92         /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
    93         case DisplayOrientations::Landscape:
    94             return DXGI_MODE_ROTATION_IDENTITY;
    95         case DisplayOrientations::Portrait:
    96             return DXGI_MODE_ROTATION_ROTATE270;
    97         case DisplayOrientations::LandscapeFlipped:
    98             return DXGI_MODE_ROTATION_ROTATE180;
    99         case DisplayOrientations::PortraitFlipped:
   100             return DXGI_MODE_ROTATION_ROTATE90;
   101 #endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
   102 
   103     default:
   104         return DXGI_MODE_ROTATION_UNSPECIFIED;
   105     }
   106 }
   107 
   108 
   109 #endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
   110 
   111 /* vi: set ts=4 sw=4 expandtab: */