src/video/winrt/SDL_winrtvideo.cpp
author Ryan C. Gordon <icculus@icculus.org>
Mon, 06 Apr 2015 00:10:54 -0400
changeset 9458 543298b36b28
parent 9214 dad92c567585
child 9557 e05c7ad6ec57
permissions -rw-r--r--
This function can be static.
dludwig@8327
     1
/*
dludwig@8327
     2
  Simple DirectMedia Layer
slouken@8615
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
dludwig@8327
     4
dludwig@8327
     5
  This software is provided 'as-is', without any express or implied
dludwig@8327
     6
  warranty.  In no event will the authors be held liable for any damages
dludwig@8327
     7
  arising from the use of this software.
dludwig@8327
     8
dludwig@8327
     9
  Permission is granted to anyone to use this software for any purpose,
dludwig@8327
    10
  including commercial applications, and to alter it and redistribute it
dludwig@8327
    11
  freely, subject to the following restrictions:
dludwig@8327
    12
dludwig@8327
    13
  1. The origin of this software must not be misrepresented; you must not
dludwig@8327
    14
     claim that you wrote the original software. If you use this software
dludwig@8327
    15
     in a product, an acknowledgment in the product documentation would be
dludwig@8327
    16
     appreciated but is not required.
dludwig@8327
    17
  2. Altered source versions must be plainly marked as such, and must not be
dludwig@8327
    18
     misrepresented as being the original software.
dludwig@8327
    19
  3. This notice may not be removed or altered from any source distribution.
dludwig@8327
    20
*/
dludwig@8600
    21
#include "../../SDL_internal.h"
dludwig@8327
    22
dludwig@8327
    23
#if SDL_VIDEO_DRIVER_WINRT
dludwig@8327
    24
dludwig@8327
    25
/* WinRT SDL video driver implementation
dludwig@8327
    26
dludwig@8327
    27
   Initial work on this was done by David Ludwig (dludwig@pobox.com), and
dludwig@8327
    28
   was based off of SDL's "dummy" video driver.
dludwig@8327
    29
 */
dludwig@8327
    30
dludwig@8494
    31
/* Windows includes */
dludwig@8494
    32
#include <agile.h>
dludwig@8663
    33
#include <wrl/client.h>
dludwig@8494
    34
using namespace Windows::UI::Core;
dludwig@8494
    35
dludwig@8494
    36
dludwig@8494
    37
/* SDL includes */
dludwig@8329
    38
extern "C" {
dludwig@8327
    39
#include "SDL_video.h"
dludwig@8327
    40
#include "SDL_mouse.h"
dludwig@8327
    41
#include "../SDL_sysvideo.h"
dludwig@8327
    42
#include "../SDL_pixels_c.h"
dludwig@8327
    43
#include "../../events/SDL_events_c.h"
dludwig@8400
    44
#include "../../render/SDL_sysrender.h"
dludwig@8411
    45
#include "SDL_syswm.h"
dludwig@8541
    46
#include "SDL_winrtopengles.h"
dludwig@8329
    47
}
dludwig@8327
    48
dludwig@8522
    49
#include "../../core/winrt/SDL_winrtapp_direct3d.h"
dludwig@8522
    50
#include "../../core/winrt/SDL_winrtapp_xaml.h"
dludwig@8512
    51
#include "SDL_winrtvideo_cpp.h"
dludwig@8327
    52
#include "SDL_winrtevents_c.h"
dludwig@8516
    53
#include "SDL_winrtmouse_c.h"
dludwig@8505
    54
#include "SDL_main.h"
dludwig@8505
    55
#include "SDL_system.h"
dludwig@8755
    56
//#include "SDL_log.h"
dludwig@8327
    57
dludwig@8327
    58
dludwig@8327
    59
/* Initialization/Query functions */
dludwig@8327
    60
static int WINRT_VideoInit(_THIS);
dludwig@8374
    61
static int WINRT_InitModes(_THIS);
dludwig@8327
    62
static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
dludwig@8327
    63
static void WINRT_VideoQuit(_THIS);
dludwig@8327
    64
dludwig@8494
    65
dludwig@8333
    66
/* Window functions */
dludwig@8522
    67
static int WINRT_CreateWindow(_THIS, SDL_Window * window);
dludwig@8333
    68
static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
dludwig@8411
    69
static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
dludwig@8333
    70
dludwig@8494
    71
dludwig@8515
    72
/* SDL-internal globals: */
dludwig@8497
    73
SDL_Window * WINRT_GlobalSDLWindow = NULL;
dludwig@8498
    74
dludwig@8498
    75
dludwig@8327
    76
/* WinRT driver bootstrap functions */
dludwig@8327
    77
dludwig@8327
    78
static int
dludwig@8327
    79
WINRT_Available(void)
dludwig@8327
    80
{
dludwig@8328
    81
    return (1);
dludwig@8327
    82
}
dludwig@8327
    83
dludwig@8327
    84
static void
dludwig@8327
    85
WINRT_DeleteDevice(SDL_VideoDevice * device)
dludwig@8327
    86
{
dludwig@8663
    87
    if (device->driverdata) {
dludwig@8663
    88
        SDL_VideoData * video_data = (SDL_VideoData *)device->driverdata;
dludwig@8663
    89
        if (video_data->winrtEglWindow) {
dludwig@8663
    90
            video_data->winrtEglWindow->Release();
dludwig@8663
    91
        }
dludwig@8663
    92
        SDL_free(video_data);
dludwig@8663
    93
    }
dludwig@8663
    94
dludwig@8327
    95
    SDL_free(device);
dludwig@8327
    96
}
dludwig@8327
    97
dludwig@8327
    98
static SDL_VideoDevice *
dludwig@8327
    99
WINRT_CreateDevice(int devindex)
dludwig@8327
   100
{
dludwig@8327
   101
    SDL_VideoDevice *device;
dludwig@8663
   102
    SDL_VideoData *data;
dludwig@8327
   103
dludwig@8327
   104
    /* Initialize all variables that we clean on shutdown */
dludwig@8327
   105
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
dludwig@8327
   106
    if (!device) {
dludwig@8327
   107
        SDL_OutOfMemory();
dludwig@8327
   108
        if (device) {
dludwig@8327
   109
            SDL_free(device);
dludwig@8327
   110
        }
dludwig@8327
   111
        return (0);
dludwig@8327
   112
    }
dludwig@8327
   113
dludwig@8663
   114
    data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
dludwig@8663
   115
    if (!data) {
dludwig@8663
   116
        SDL_OutOfMemory();
dludwig@8663
   117
        return (0);
dludwig@8663
   118
    }
dludwig@8663
   119
    SDL_zerop(data);
dludwig@8663
   120
    device->driverdata = data;
dludwig@8663
   121
dludwig@8327
   122
    /* Set the function pointers */
dludwig@8327
   123
    device->VideoInit = WINRT_VideoInit;
dludwig@8327
   124
    device->VideoQuit = WINRT_VideoQuit;
dludwig@8333
   125
    device->CreateWindow = WINRT_CreateWindow;
dludwig@8333
   126
    device->DestroyWindow = WINRT_DestroyWindow;
dludwig@8327
   127
    device->SetDisplayMode = WINRT_SetDisplayMode;
dludwig@8327
   128
    device->PumpEvents = WINRT_PumpEvents;
dludwig@8411
   129
    device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
dludwig@8541
   130
#ifdef SDL_VIDEO_OPENGL_EGL
slouken@8582
   131
    device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
slouken@8582
   132
    device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
slouken@8582
   133
    device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
slouken@8582
   134
    device->GL_CreateContext = WINRT_GLES_CreateContext;
slouken@8582
   135
    device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
slouken@8582
   136
    device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
slouken@8582
   137
    device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
slouken@8582
   138
    device->GL_SwapWindow = WINRT_GLES_SwapWindow;
dludwig@8541
   139
    device->GL_DeleteContext = WINRT_GLES_DeleteContext;
dludwig@8541
   140
#endif
dludwig@8433
   141
    device->free = WINRT_DeleteDevice;
dludwig@8327
   142
dludwig@8327
   143
    return device;
dludwig@8327
   144
}
dludwig@8327
   145
dludwig@8494
   146
#define WINRTVID_DRIVER_NAME "winrt"
dludwig@8327
   147
VideoBootStrap WINRT_bootstrap = {
dludwig@8500
   148
    WINRTVID_DRIVER_NAME, "SDL WinRT video driver",
dludwig@8327
   149
    WINRT_Available, WINRT_CreateDevice
dludwig@8327
   150
};
dludwig@8327
   151
dludwig@8327
   152
int
dludwig@8327
   153
WINRT_VideoInit(_THIS)
dludwig@8327
   154
{
dludwig@8374
   155
    if (WINRT_InitModes(_this) < 0) {
dludwig@8374
   156
        return -1;
dludwig@8374
   157
    }
dludwig@8374
   158
    WINRT_InitMouse(_this);
dludwig@8515
   159
    WINRT_InitTouch(_this);
dludwig@8522
   160
dludwig@8374
   161
    return 0;
dludwig@8374
   162
}
dludwig@8374
   163
dludwig@8578
   164
int
dludwig@8578
   165
WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode)
dludwig@8522
   166
{
dludwig@8578
   167
    SDL_DisplayModeData * driverdata;
dludwig@8578
   168
dludwig@8522
   169
    using namespace Windows::Graphics::Display;
dludwig@8522
   170
dludwig@8522
   171
    // Go no further if a native window cannot be accessed.  This can happen,
dludwig@8522
   172
    // for example, if this function is called from certain threads, such as
dludwig@8522
   173
    // the SDL/XAML thread.
dludwig@8522
   174
    if (!CoreWindow::GetForCurrentThread()) {
dludwig@8578
   175
        return SDL_SetError("SDL/WinRT display modes cannot be calculated outside of the main thread, such as in SDL's XAML thread");
dludwig@8522
   176
    }
dludwig@8522
   177
dludwig@8755
   178
    //SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, DPI = %f\n",
dludwig@8755
   179
    //    __FUNCTION__,
dludwig@8755
   180
    //    CoreWindow::GetForCurrentThread()->Bounds.Width, CoreWindow::GetForCurrentThread()->Bounds.Height,
dludwig@8755
   181
    //    WINRT_DISPLAY_PROPERTY(CurrentOrientation),
dludwig@8755
   182
    //    WINRT_DISPLAY_PROPERTY(NativeOrientation),
dludwig@8755
   183
    //    WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
dludwig@8755
   184
    //    WINRT_DISPLAY_PROPERTY(LogicalDpi));
dludwig@8755
   185
dludwig@8579
   186
    // Calculate the display size given the window size, taking into account
dludwig@8579
   187
    // the current display's DPI:
dludwig@8757
   188
    const float currentDPI = WINRT_DISPLAY_PROPERTY(LogicalDpi);
dludwig@8579
   189
    const float dipsPerInch = 96.0f;
dludwig@8579
   190
    const int w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
dludwig@8579
   191
    const int h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
dludwig@8579
   192
    if (w == 0 || w == h) {
dludwig@8579
   193
        return SDL_SetError("Unable to calculate the WinRT window/display's size");
dludwig@8579
   194
    }
dludwig@8579
   195
dludwig@8578
   196
    // Create a driverdata field:
dludwig@8578
   197
    driverdata = (SDL_DisplayModeData *) SDL_malloc(sizeof(*driverdata));
dludwig@8578
   198
    if (!driverdata) {
dludwig@8578
   199
        return SDL_OutOfMemory();
dludwig@8578
   200
    }
dludwig@8578
   201
    SDL_zerop(driverdata);
dludwig@8578
   202
dludwig@8522
   203
    // Fill in most fields:
dludwig@8579
   204
    SDL_zerop(mode);
dludwig@8578
   205
    mode->format = SDL_PIXELFORMAT_RGB888;
dludwig@8578
   206
    mode->refresh_rate = 0;  // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
dludwig@8579
   207
    mode->w = w;
dludwig@8579
   208
    mode->h = h;
dludwig@8578
   209
    mode->driverdata = driverdata;
dludwig@8757
   210
    driverdata->currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
dludwig@8522
   211
dludwig@8755
   212
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
dludwig@8755
   213
    // On Windows Phone 8.0, the native window's size is always in portrait,
dludwig@8522
   214
    // regardless of the device's orientation.  This is in contrast to
dludwig@8755
   215
    // Windows 8.x/RT and Windows Phone 8.1, which will resize the native window as the device's
dludwig@8522
   216
    // orientation changes.  In order to compensate for this behavior,
dludwig@8522
   217
    // on Windows Phone, the mode's width and height will be swapped when
dludwig@8522
   218
    // the device is in a landscape (non-portrait) mode.
dludwig@8747
   219
    switch (driverdata->currentOrientation) {
dludwig@8522
   220
        case DisplayOrientations::Landscape:
dludwig@8522
   221
        case DisplayOrientations::LandscapeFlipped:
dludwig@8522
   222
        {
dludwig@8578
   223
            const int tmp = mode->h;
dludwig@8578
   224
            mode->h = mode->w;
dludwig@8578
   225
            mode->w = tmp;
dludwig@8522
   226
            break;
dludwig@8522
   227
        }
dludwig@8522
   228
dludwig@8522
   229
        default:
dludwig@8522
   230
            break;
dludwig@8522
   231
    }
dludwig@8522
   232
#endif
dludwig@8522
   233
dludwig@8578
   234
    return 0;
dludwig@8578
   235
}
dludwig@8578
   236
dludwig@8578
   237
int
dludwig@8578
   238
WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src)
dludwig@8578
   239
{
dludwig@8578
   240
    SDL_DisplayModeData * driverdata;
dludwig@8578
   241
    driverdata = (SDL_DisplayModeData *) SDL_malloc(sizeof(*driverdata));
dludwig@8578
   242
    if (!driverdata) {
dludwig@8578
   243
        return SDL_OutOfMemory();
dludwig@8578
   244
    }
dludwig@8578
   245
    SDL_memcpy(driverdata, src->driverdata, sizeof(SDL_DisplayModeData));
dludwig@8578
   246
    SDL_memcpy(dest, src, sizeof(SDL_DisplayMode));
dludwig@8578
   247
    dest->driverdata = driverdata;
dludwig@8578
   248
    return 0;
dludwig@8522
   249
}
dludwig@8503
   250
dludwig@8505
   251
int
dludwig@8374
   252
WINRT_InitModes(_THIS)
dludwig@8374
   253
{
dludwig@8505
   254
    // Retrieve the display mode:
dludwig@8578
   255
    SDL_DisplayMode mode, desktop_mode;
dludwig@8578
   256
    if (WINRT_CalcDisplayModeUsingNativeWindow(&mode) != 0) {
dludwig@8578
   257
        return -1;	// If WINRT_CalcDisplayModeUsingNativeWindow fails, it'll already have set the SDL error
dludwig@8578
   258
    }
dludwig@8522
   259
dludwig@8578
   260
    if (WINRT_DuplicateDisplayMode(&desktop_mode, &mode) != 0) {
dludwig@8578
   261
        return -1;
dludwig@8578
   262
    }
dludwig@8578
   263
    if (SDL_AddBasicVideoDisplay(&desktop_mode) < 0) {
dludwig@8522
   264
        return -1;
dludwig@8374
   265
    }
dludwig@8374
   266
dludwig@8374
   267
    SDL_AddDisplayMode(&_this->displays[0], &mode);
dludwig@8327
   268
    return 0;
dludwig@8327
   269
}
dludwig@8327
   270
dludwig@8327
   271
static int
dludwig@8327
   272
WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
dludwig@8327
   273
{
dludwig@8327
   274
    return 0;
dludwig@8327
   275
}
dludwig@8327
   276
dludwig@8327
   277
void
dludwig@8327
   278
WINRT_VideoQuit(_THIS)
dludwig@8327
   279
{
dludwig@8374
   280
    WINRT_QuitMouse(_this);
dludwig@8327
   281
}
dludwig@8327
   282
dludwig@8522
   283
int
dludwig@8522
   284
WINRT_CreateWindow(_THIS, SDL_Window * window)
dludwig@8522
   285
{
dludwig@8522
   286
    // Make sure that only one window gets created, at least until multimonitor
dludwig@8522
   287
    // support is added.
dludwig@8522
   288
    if (WINRT_GlobalSDLWindow != NULL) {
dludwig@8522
   289
        SDL_SetError("WinRT only supports one window");
dludwig@8522
   290
        return -1;
dludwig@8522
   291
    }
dludwig@8522
   292
dludwig@8522
   293
    SDL_WindowData *data = new SDL_WindowData;
dludwig@8522
   294
    if (!data) {
dludwig@8522
   295
        SDL_OutOfMemory();
dludwig@8522
   296
        return -1;
dludwig@8522
   297
    }
dludwig@8522
   298
    window->driverdata = data;
dludwig@8522
   299
    data->sdlWindow = window;
dludwig@8522
   300
dludwig@8522
   301
    /* To note, when XAML support is enabled, access to the CoreWindow will not
dludwig@8522
   302
       be possible, at least not via the SDL/XAML thread.  Attempts to access it
dludwig@8522
   303
       from there will throw exceptions.  As such, the SDL_WindowData's
dludwig@8522
   304
       'coreWindow' field will only be set (to a non-null value) if XAML isn't
dludwig@8522
   305
       enabled.
dludwig@8522
   306
    */
dludwig@8522
   307
    if (!WINRT_XAMLWasEnabled) {
dludwig@8522
   308
        data->coreWindow = CoreWindow::GetForCurrentThread();
dludwig@8522
   309
    }
dludwig@8522
   310
dludwig@8541
   311
#if SDL_VIDEO_OPENGL_EGL
dludwig@8541
   312
    /* Setup the EGL surface, but only if OpenGL ES 2 was requested. */
dludwig@8541
   313
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
dludwig@8541
   314
        /* OpenGL ES 2 wasn't requested.  Don't set up an EGL surface. */
dludwig@8541
   315
        data->egl_surface = EGL_NO_SURFACE;
dludwig@8541
   316
    } else {
dludwig@8541
   317
        /* OpenGL ES 2 was reuqested.  Set up an EGL surface. */
dludwig@8663
   318
        SDL_VideoData * video_data = (SDL_VideoData *)_this->driverdata;
dludwig@8572
   319
dludwig@8663
   320
        /* Call SDL_EGL_ChooseConfig and eglCreateWindowSurface directly,
dludwig@9212
   321
         * rather than via SDL_EGL_CreateSurface, as older versions of
dludwig@9212
   322
         * ANGLE/WinRT may require that a C++ object, ComPtr<IUnknown>,
dludwig@9212
   323
         * be passed into eglCreateWindowSurface.
dludwig@8572
   324
         */
dludwig@8663
   325
        if (SDL_EGL_ChooseConfig(_this) != 0) {
dludwig@8663
   326
            char buf[512];
dludwig@8663
   327
            SDL_snprintf(buf, sizeof(buf), "SDL_EGL_ChooseConfig failed: %s", SDL_GetError());
dludwig@8663
   328
            return SDL_SetError(buf);
dludwig@8663
   329
        }
dludwig@8572
   330
dludwig@9211
   331
        if (video_data->winrtEglWindow) {   /* ... is the 'old' version of ANGLE/WinRT being used? */
dludwig@9211
   332
            /* Attempt to create a window surface using older versions of
dludwig@9211
   333
             * ANGLE/WinRT:
dludwig@9211
   334
             */
dludwig@9211
   335
            Microsoft::WRL::ComPtr<IUnknown> cpp_winrtEglWindow = video_data->winrtEglWindow;
dludwig@9211
   336
            data->egl_surface = ((eglCreateWindowSurface_Old_Function)_this->egl_data->eglCreateWindowSurface)(
dludwig@9211
   337
                _this->egl_data->egl_display,
dludwig@9211
   338
                _this->egl_data->egl_config,
dludwig@9211
   339
                cpp_winrtEglWindow, NULL);
dludwig@9211
   340
            if (data->egl_surface == NULL) {
dludwig@9211
   341
                return SDL_SetError("eglCreateWindowSurface failed");
dludwig@9211
   342
            }
dludwig@9211
   343
        } else if (data->coreWindow.Get() != nullptr) {
dludwig@9211
   344
            /* Attempt to create a window surface using newer versions of
dludwig@9211
   345
             * ANGLE/WinRT:
dludwig@9211
   346
             */
dludwig@9211
   347
            IInspectable * coreWindowAsIInspectable = reinterpret_cast<IInspectable *>(data->coreWindow.Get());
dludwig@9211
   348
            data->egl_surface = _this->egl_data->eglCreateWindowSurface(
dludwig@9211
   349
                _this->egl_data->egl_display,
dludwig@9211
   350
                _this->egl_data->egl_config,
dludwig@9211
   351
                coreWindowAsIInspectable,
dludwig@9211
   352
                NULL);
dludwig@9211
   353
            if (data->egl_surface == NULL) {
dludwig@9211
   354
                return SDL_SetError("eglCreateWindowSurface failed");
dludwig@9211
   355
            }
dludwig@9211
   356
        } else {
dludwig@9211
   357
            return SDL_SetError("No supported means to create an EGL window surface are available");
dludwig@8541
   358
        }
dludwig@8541
   359
    }
dludwig@8541
   360
#endif
dludwig@8541
   361
dludwig@8522
   362
    /* Make sure the window is considered to be positioned at {0,0},
dludwig@8522
   363
       and is considered fullscreen, shown, and the like.
dludwig@8522
   364
    */
dludwig@8522
   365
    window->x = 0;
dludwig@8522
   366
    window->y = 0;
dludwig@8522
   367
    window->flags =
dludwig@8522
   368
        SDL_WINDOW_FULLSCREEN |
dludwig@8522
   369
        SDL_WINDOW_SHOWN |
dludwig@8522
   370
        SDL_WINDOW_BORDERLESS |
dludwig@8522
   371
        SDL_WINDOW_MAXIMIZED |
dludwig@8522
   372
        SDL_WINDOW_INPUT_GRABBED;
dludwig@8522
   373
dludwig@8541
   374
#if SDL_VIDEO_OPENGL_EGL
dludwig@8541
   375
    if (data->egl_surface) {
dludwig@8541
   376
        window->flags |= SDL_WINDOW_OPENGL;
dludwig@8541
   377
    }
dludwig@8541
   378
#endif
dludwig@8541
   379
dludwig@8522
   380
    /* WinRT does not, as of this writing, appear to support app-adjustable
dludwig@8522
   381
       window sizes.  Set the window size to whatever the native WinRT
dludwig@8522
   382
       CoreWindow is set at.
dludwig@8522
   383
dludwig@8522
   384
       TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces.
dludwig@8522
   385
    */
dludwig@8522
   386
    window->w = _this->displays[0].current_mode.w;
dludwig@8522
   387
    window->h = _this->displays[0].current_mode.h;
dludwig@8551
   388
dludwig@8551
   389
    /* For now, treat WinRT apps as if they always have focus.
dludwig@8551
   390
       TODO, WinRT: try tracking keyboard and mouse focus state with respect to snapped apps
dludwig@8551
   391
     */
slouken@8582
   392
    SDL_SetMouseFocus(window);
dludwig@8551
   393
    SDL_SetKeyboardFocus(window);
dludwig@8522
   394
 
dludwig@8522
   395
    /* Make sure the WinRT app's IFramworkView can post events on
dludwig@8522
   396
       behalf of SDL:
dludwig@8522
   397
    */
dludwig@8522
   398
    WINRT_GlobalSDLWindow = window;
dludwig@8522
   399
dludwig@8522
   400
    /* All done! */
dludwig@8522
   401
    return 0;
dludwig@8522
   402
}
dludwig@8522
   403
dludwig@8333
   404
void
dludwig@8333
   405
WINRT_DestroyWindow(_THIS, SDL_Window * window)
dludwig@8333
   406
{
dludwig@8411
   407
    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
dludwig@8411
   408
dludwig@8497
   409
    if (WINRT_GlobalSDLWindow == window) {
dludwig@8497
   410
        WINRT_GlobalSDLWindow = NULL;
dludwig@8424
   411
    }
dludwig@8424
   412
dludwig@8411
   413
    if (data) {
dludwig@8411
   414
        // Delete the internal window data:
dludwig@8411
   415
        delete data;
dludwig@8411
   416
        data = NULL;
dludwig@9214
   417
        window->driverdata = NULL;
dludwig@8411
   418
    }
dludwig@8333
   419
}
dludwig@8333
   420
dludwig@8522
   421
SDL_bool
dludwig@8522
   422
WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
dludwig@8522
   423
{
dludwig@8522
   424
    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
dludwig@8522
   425
dludwig@8522
   426
    if (info->version.major <= SDL_MAJOR_VERSION) {
dludwig@8522
   427
        info->subsystem = SDL_SYSWM_WINRT;
dludwig@8527
   428
        info->info.winrt.window = reinterpret_cast<IInspectable *>(data->coreWindow.Get());
dludwig@8522
   429
        return SDL_TRUE;
dludwig@8522
   430
    } else {
dludwig@8522
   431
        SDL_SetError("Application not compiled with SDL %d.%d\n",
dludwig@8522
   432
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
dludwig@8522
   433
        return SDL_FALSE;
dludwig@8522
   434
    }
dludwig@8522
   435
    return SDL_FALSE;
dludwig@8411
   436
}
dludwig@8333
   437
dludwig@8327
   438
#endif /* SDL_VIDEO_DRIVER_WINRT */
dludwig@8327
   439
dludwig@8327
   440
/* vi: set ts=4 sw=4 expandtab: */