src/render/direct3d11/SDL_render_winrt.cpp
author Sam Lantinga <slouken@libsdl.org>
Thu, 13 Mar 2014 00:40:08 -0700
changeset 8615 097646deaef2
parent 8612 24d36bb9c7af
child 8621 5252788cb448
permissions -rw-r--r--
Fixed the copyright date on files contributed by David Ludwig
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2014 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.graphics.display.h>
    32 
    33 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
    34 #include <windows.ui.xaml.media.dxinterop.h>
    35 #endif
    36 
    37 using namespace ABI;
    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 #if 0 /* FIXME: This doesn't compile on Visual Studio 2013 */
    84     switch (DisplayProperties::CurrentOrientation) {
    85 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    86     /* Windows Phone rotations */
    87     case DisplayOrientations::Landscape:
    88         return DXGI_MODE_ROTATION_ROTATE90;
    89     case DisplayOrientations::Portrait:
    90         return DXGI_MODE_ROTATION_IDENTITY;
    91     case DisplayOrientations::LandscapeFlipped:
    92         return DXGI_MODE_ROTATION_ROTATE270;
    93     case DisplayOrientations::PortraitFlipped:
    94         return DXGI_MODE_ROTATION_ROTATE180;
    95 #else
    96     /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
    97     case DisplayOrientations::Landscape:
    98         return DXGI_MODE_ROTATION_IDENTITY;
    99     case DisplayOrientations::Portrait:
   100         return DXGI_MODE_ROTATION_ROTATE270;
   101     case DisplayOrientations::LandscapeFlipped:
   102         return DXGI_MODE_ROTATION_ROTATE180;
   103     case DisplayOrientations::PortraitFlipped:
   104         return DXGI_MODE_ROTATION_ROTATE90;
   105 #endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
   106     }
   107 #endif
   108     return DXGI_MODE_ROTATION_IDENTITY;
   109 }
   110 
   111 
   112 #endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
   113 
   114 /* vi: set ts=4 sw=4 expandtab: */