src/video/winrt/SDL_winrtvideo.cpp
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Thu, 10 Mar 2016 21:00:44 +0100
changeset 10112 f3c18811079d
parent 9998 f67cf37e9cd4
child 10163 0f89301aae00
permissions -rw-r--r--
WinRT: Removed dead code and fixed memory leak if allocation for driver failed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     1
/*
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9993
diff changeset
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     4
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     7
  arising from the use of this software.
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     8
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    12
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    16
     appreciated but is not required.
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    18
     misrepresented as being the original software.
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    20
*/
8600
092802455aed build fixes for most WinRT-related files
David Ludwig <dludwig@pobox.com>
parents: 8582
diff changeset
    21
#include "../../SDL_internal.h"
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    22
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    23
#if SDL_VIDEO_DRIVER_WINRT
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    24
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    25
/* WinRT SDL video driver implementation
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    26
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    27
   Initial work on this was done by David Ludwig (dludwig@pobox.com), and
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    28
   was based off of SDL's "dummy" video driver.
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    29
 */
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    30
8494
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
    31
/* Windows includes */
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
    32
#include <agile.h>
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    33
#include <windows.graphics.display.h>
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    34
#include <dxgi.h>
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    35
#include <dxgi1_2.h>
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    36
using namespace Windows::ApplicationModel::Core;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    37
using namespace Windows::Foundation;
9925
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
    38
using namespace Windows::Graphics::Display;
8494
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
    39
using namespace Windows::UI::Core;
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    40
using namespace Windows::UI::ViewManagement;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    41
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    42
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    43
/* [re]declare Windows GUIDs locally, to limit the amount of external lib(s) SDL has to link to */
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    44
static const GUID IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48,{ 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
8494
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
    45
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
    46
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
    47
/* SDL includes */
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8328
diff changeset
    48
extern "C" {
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    49
#include "SDL_video.h"
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    50
#include "SDL_mouse.h"
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    51
#include "../SDL_sysvideo.h"
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    52
#include "../SDL_pixels_c.h"
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    53
#include "../../events/SDL_events_c.h"
8400
1315402d9028 WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
David Ludwig <dludwig@pobox.com>
parents: 8374
diff changeset
    54
#include "../../render/SDL_sysrender.h"
8411
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    55
#include "SDL_syswm.h"
8541
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
    56
#include "SDL_winrtopengles.h"
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
    57
#include "../../core/windows/SDL_windows.h"
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8328
diff changeset
    58
}
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    59
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
    60
#include "../../core/winrt/SDL_winrtapp_direct3d.h"
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
    61
#include "../../core/winrt/SDL_winrtapp_xaml.h"
8512
5b345a756965 WinRT: corrected SDL_MOUSE* coordinates in non-Portrait modes
David Ludwig <dludwig@pobox.com>
parents: 8510
diff changeset
    62
#include "SDL_winrtvideo_cpp.h"
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    63
#include "SDL_winrtevents_c.h"
8516
f3e0e381bdcd WinRT: renamed a mouse-related header file for naming-consistency's sake
David Ludwig <dludwig@pobox.com>
parents: 8515
diff changeset
    64
#include "SDL_winrtmouse_c.h"
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8503
diff changeset
    65
#include "SDL_main.h"
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8503
diff changeset
    66
#include "SDL_system.h"
8755
f2fc45874b9c Fixed rendering-alignment issues on WinPhone 8.1, when the device was rotated
David Ludwig <dludwig@pobox.com>
parents: 8747
diff changeset
    67
//#include "SDL_log.h"
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    68
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    69
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    70
/* Initialization/Query functions */
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    71
static int WINRT_VideoInit(_THIS);
8374
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
    72
static int WINRT_InitModes(_THIS);
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    73
static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    74
static void WINRT_VideoQuit(_THIS);
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    75
8494
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
    76
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
    77
/* Window functions */
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
    78
static int WINRT_CreateWindow(_THIS, SDL_Window * window);
9931
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
    79
static void WINRT_SetWindowSize(_THIS, SDL_Window * window);
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
    80
static void WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
    81
static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
8411
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
    82
static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
    83
8494
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
    84
8515
bc6cf9201dab WinRT: misc code cleanups regarding touch and mouse events, and also SDL-internal globals
David Ludwig <dludwig@pobox.com>
parents: 8512
diff changeset
    85
/* SDL-internal globals: */
8497
103bb054aa7d WinRT: moved the pointer to the global SDL_Window to a separate variable
David Ludwig <dludwig@pobox.com>
parents: 8496
diff changeset
    86
SDL_Window * WINRT_GlobalSDLWindow = NULL;
8498
333ae9a0f411 WinRT: moved the WinRT SDL_VideoDevice out of SDL_WinRTApp
David Ludwig <dludwig@pobox.com>
parents: 8497
diff changeset
    87
333ae9a0f411 WinRT: moved the WinRT SDL_VideoDevice out of SDL_WinRTApp
David Ludwig <dludwig@pobox.com>
parents: 8497
diff changeset
    88
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    89
/* WinRT driver bootstrap functions */
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    90
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    91
static int
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    92
WINRT_Available(void)
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    93
{
8328
88b08ad81bf7 WinRT: made the WinRT video driver always be initialize-able
David Ludwig <dludwig@pobox.com>
parents: 8327
diff changeset
    94
    return (1);
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    95
}
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    96
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    97
static void
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    98
WINRT_DeleteDevice(SDL_VideoDevice * device)
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    99
{
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   100
    if (device->driverdata) {
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   101
        SDL_VideoData * video_data = (SDL_VideoData *)device->driverdata;
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   102
        if (video_data->winrtEglWindow) {
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   103
            video_data->winrtEglWindow->Release();
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   104
        }
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   105
        SDL_free(video_data);
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   106
    }
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   107
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   108
    SDL_free(device);
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   109
}
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   110
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   111
static SDL_VideoDevice *
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   112
WINRT_CreateDevice(int devindex)
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   113
{
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   114
    SDL_VideoDevice *device;
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   115
    SDL_VideoData *data;
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   116
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   117
    /* Initialize all variables that we clean on shutdown */
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   118
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   119
    if (!device) {
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   120
        SDL_OutOfMemory();
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   121
        return (0);
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   122
    }
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   123
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   124
    data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   125
    if (!data) {
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   126
        SDL_OutOfMemory();
10112
f3c18811079d WinRT: Removed dead code and fixed memory leak if allocation for driver failed.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9998
diff changeset
   127
        SDL_free(device);
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   128
        return (0);
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   129
    }
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   130
    SDL_zerop(data);
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   131
    device->driverdata = data;
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   132
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   133
    /* Set the function pointers */
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   134
    device->VideoInit = WINRT_VideoInit;
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   135
    device->VideoQuit = WINRT_VideoQuit;
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   136
    device->CreateWindow = WINRT_CreateWindow;
9931
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   137
    device->SetWindowSize = WINRT_SetWindowSize;
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   138
    device->SetWindowFullscreen = WINRT_SetWindowFullscreen;
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   139
    device->DestroyWindow = WINRT_DestroyWindow;
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   140
    device->SetDisplayMode = WINRT_SetDisplayMode;
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   141
    device->PumpEvents = WINRT_PumpEvents;
8411
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   142
    device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
8541
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   143
#ifdef SDL_VIDEO_OPENGL_EGL
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8579
diff changeset
   144
    device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8579
diff changeset
   145
    device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8579
diff changeset
   146
    device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8579
diff changeset
   147
    device->GL_CreateContext = WINRT_GLES_CreateContext;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8579
diff changeset
   148
    device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8579
diff changeset
   149
    device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8579
diff changeset
   150
    device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8579
diff changeset
   151
    device->GL_SwapWindow = WINRT_GLES_SwapWindow;
8541
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   152
    device->GL_DeleteContext = WINRT_GLES_DeleteContext;
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   153
#endif
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8424
diff changeset
   154
    device->free = WINRT_DeleteDevice;
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   155
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   156
    return device;
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   157
}
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   158
8494
5d165785918d WinRT: misc code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8492
diff changeset
   159
#define WINRTVID_DRIVER_NAME "winrt"
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   160
VideoBootStrap WINRT_bootstrap = {
8500
f25ef28d61e8 WinRT: more "Windows RT" to "WinRT" renaming
David Ludwig <dludwig@pobox.com>
parents: 8499
diff changeset
   161
    WINRTVID_DRIVER_NAME, "SDL WinRT video driver",
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   162
    WINRT_Available, WINRT_CreateDevice
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   163
};
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   164
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   165
int
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   166
WINRT_VideoInit(_THIS)
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   167
{
8374
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   168
    if (WINRT_InitModes(_this) < 0) {
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   169
        return -1;
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   170
    }
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   171
    WINRT_InitMouse(_this);
8515
bc6cf9201dab WinRT: misc code cleanups regarding touch and mouse events, and also SDL-internal globals
David Ludwig <dludwig@pobox.com>
parents: 8512
diff changeset
   172
    WINRT_InitTouch(_this);
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   173
8374
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   174
    return 0;
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   175
}
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   176
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   177
extern "C"
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   178
Uint32 D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   179
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   180
static void
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   181
WINRT_DXGIModeToSDLDisplayMode(const DXGI_MODE_DESC * dxgiMode, SDL_DisplayMode * sdlMode)
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   182
{
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   183
    SDL_zerop(sdlMode);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   184
    sdlMode->w = dxgiMode->Width;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   185
    sdlMode->h = dxgiMode->Height;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   186
    sdlMode->refresh_rate = dxgiMode->RefreshRate.Numerator / dxgiMode->RefreshRate.Denominator;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   187
    sdlMode->format = D3D11_DXGIFormatToSDLPixelFormat(dxgiMode->Format);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   188
}
8578
6517b6aca713 WinRT: fixed a crash in SDL_Quit
David Ludwig <dludwig@pobox.com>
parents: 8574
diff changeset
   189
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   190
static int
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   191
WINRT_AddDisplaysForOutput (_THIS, IDXGIAdapter1 * dxgiAdapter1, int outputIndex)
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   192
{
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   193
    HRESULT hr;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   194
    IDXGIOutput * dxgiOutput = NULL;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   195
    DXGI_OUTPUT_DESC dxgiOutputDesc;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   196
    SDL_VideoDisplay display;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   197
    char * displayName = NULL;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   198
    UINT numModes;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   199
    DXGI_MODE_DESC * dxgiModes = NULL;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   200
    int functionResult = -1;        /* -1 for failure, 0 for success */
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   201
    DXGI_MODE_DESC modeToMatch, closestMatch;
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   202
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   203
    SDL_zero(display);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   204
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   205
    hr = dxgiAdapter1->EnumOutputs(outputIndex, &dxgiOutput);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   206
    if (FAILED(hr)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   207
        if (hr != DXGI_ERROR_NOT_FOUND) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   208
            WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIAdapter1::EnumOutputs failed", hr);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   209
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   210
        goto done;
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   211
    }
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   212
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   213
    hr = dxgiOutput->GetDesc(&dxgiOutputDesc);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   214
    if (FAILED(hr)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   215
        WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDesc failed", hr);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   216
        goto done;
8579
ee7126c459d0 WinRT: cleaned up some hard-to-read SDL_DisplayMode management code
David Ludwig <dludwig@pobox.com>
parents: 8578
diff changeset
   217
    }
ee7126c459d0 WinRT: cleaned up some hard-to-read SDL_DisplayMode management code
David Ludwig <dludwig@pobox.com>
parents: 8578
diff changeset
   218
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   219
    SDL_zero(modeToMatch);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   220
    modeToMatch.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   221
    modeToMatch.Width = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   222
    modeToMatch.Height = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   223
    hr = dxgiOutput->FindClosestMatchingMode(&modeToMatch, &closestMatch, NULL);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   224
    if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   225
        /* DXGI_ERROR_NOT_CURRENTLY_AVAILABLE gets returned by IDXGIOutput::FindClosestMatchingMode
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   226
           when running under the Windows Simulator, which uses Remote Desktop (formerly known as Terminal
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   227
           Services) under the hood.  According to the MSDN docs for the similar function,
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   228
           IDXGIOutput::GetDisplayModeList, DXGI_ERROR_NOT_CURRENTLY_AVAILABLE is returned if and
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   229
           when an app is run under a Terminal Services session, hence the assumption.
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   230
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   231
           In this case, just add an SDL display mode, with approximated values.
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   232
        */
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   233
        SDL_DisplayMode mode;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   234
        SDL_zero(mode);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   235
        display.name = "Windows Simulator / Terminal Services Display";
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   236
        mode.w = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   237
        mode.h = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   238
        mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   239
        mode.refresh_rate = 0;  /* Display mode is unknown, so just fill in zero, as specified by SDL's header files */
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   240
        display.desktop_mode = mode;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   241
        display.current_mode = mode;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   242
        if ( ! SDL_AddDisplayMode(&display, &mode)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   243
            goto done;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   244
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   245
    } else if (FAILED(hr)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   246
        WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::FindClosestMatchingMode failed", hr);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   247
        goto done;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   248
    } else {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   249
        displayName = WIN_StringToUTF8(dxgiOutputDesc.DeviceName);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   250
        display.name = displayName;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   251
        WINRT_DXGIModeToSDLDisplayMode(&closestMatch, &display.desktop_mode);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   252
        display.current_mode = display.desktop_mode;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   253
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   254
        hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_B8G8R8A8_UNORM, 0, &numModes, NULL);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   255
        if (FAILED(hr)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   256
            if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   257
                // TODO, WinRT: make sure display mode(s) are added when using Terminal Services / Windows Simulator
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   258
            }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   259
            WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDisplayModeList [get mode list size] failed", hr);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   260
            goto done;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   261
        }
8578
6517b6aca713 WinRT: fixed a crash in SDL_Quit
David Ludwig <dludwig@pobox.com>
parents: 8574
diff changeset
   262
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   263
        dxgiModes = (DXGI_MODE_DESC *)SDL_calloc(numModes, sizeof(DXGI_MODE_DESC));
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   264
        if ( ! dxgiModes) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   265
            SDL_OutOfMemory();
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   266
            goto done;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   267
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   268
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   269
        hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_B8G8R8A8_UNORM, 0, &numModes, dxgiModes);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   270
        if (FAILED(hr)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   271
            WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDisplayModeList [get mode contents] failed", hr);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   272
            goto done;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   273
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   274
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   275
        for (UINT i = 0; i < numModes; ++i) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   276
            SDL_DisplayMode sdlMode;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   277
            WINRT_DXGIModeToSDLDisplayMode(&dxgiModes[i], &sdlMode);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   278
            SDL_AddDisplayMode(&display, &sdlMode);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   279
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   280
    }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   281
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   282
    if (SDL_AddVideoDisplay(&display) < 0) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   283
        goto done;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   284
    }
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   285
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   286
    functionResult = 0;     /* 0 for Success! */
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   287
done:
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   288
    if (dxgiModes) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   289
        SDL_free(dxgiModes);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   290
    }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   291
    if (dxgiOutput) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   292
        dxgiOutput->Release();
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   293
    }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   294
    if (displayName) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   295
        SDL_free(displayName);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   296
    }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   297
    return functionResult;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   298
}
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   299
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   300
static int
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   301
WINRT_AddDisplaysForAdapter (_THIS, IDXGIFactory2 * dxgiFactory2, int adapterIndex)
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   302
{
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   303
    HRESULT hr;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   304
    IDXGIAdapter1 * dxgiAdapter1;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   305
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   306
    hr = dxgiFactory2->EnumAdapters1(adapterIndex, &dxgiAdapter1);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   307
    if (FAILED(hr)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   308
        if (hr != DXGI_ERROR_NOT_FOUND) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   309
            WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory1::EnumAdapters1() failed", hr);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   310
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   311
        return -1;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   312
    }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   313
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   314
    for (int outputIndex = 0; ; ++outputIndex) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   315
        if (WINRT_AddDisplaysForOutput(_this, dxgiAdapter1, outputIndex) < 0) {
9947
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   316
            /* HACK: The Windows App Certification Kit 10.0 can fail, when
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   317
               running the Store Apps' test, "Direct3D Feature Test".  The
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   318
               certification kit's error is:
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   319
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   320
               "Application App was not running at the end of the test. It likely crashed or was terminated for having become unresponsive."
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   321
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   322
               This was caused by SDL/WinRT's DXGI failing to report any
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   323
               outputs.  Attempts to get the 1st display-output from the
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   324
               1st display-adapter can fail, with IDXGIAdapter::EnumOutputs
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   325
               returning DXGI_ERROR_NOT_FOUND.  This could be a bug in Windows,
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   326
               the Windows App Certification Kit, or possibly in SDL/WinRT's
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   327
               display detection code.  Either way, try to detect when this
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   328
               happens, and use a hackish means to create a reasonable-as-possible
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   329
               'display mode'.  -- DavidL
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   330
            */
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   331
            if (adapterIndex == 0 && outputIndex == 0) {
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   332
                SDL_VideoDisplay display;
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   333
                SDL_DisplayMode mode;
9952
54b2eeb48c7d WinRT: build fix for Windows Phone 8.0
David Ludwig <dludwig@pobox.com>
parents: 9951
diff changeset
   334
#if SDL_WINRT_USE_APPLICATIONVIEW
9947
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   335
                ApplicationView ^ appView = ApplicationView::GetForCurrentView();
9952
54b2eeb48c7d WinRT: build fix for Windows Phone 8.0
David Ludwig <dludwig@pobox.com>
parents: 9951
diff changeset
   336
#endif
9950
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   337
                CoreWindow ^ coreWin = CoreWindow::GetForCurrentThread();
9947
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   338
                SDL_zero(display);
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   339
                SDL_zero(mode);
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   340
                display.name = "DXGI Display-detection Workaround";
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   341
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   342
                /* HACK: ApplicationView's VisibleBounds property, appeared, via testing, to
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   343
                   give a better approximation of display-size, than did CoreWindow's
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   344
                   Bounds property, insofar that ApplicationView::VisibleBounds seems like
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   345
                   it will, at least some of the time, give the full display size (during the
9950
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   346
                   failing test), whereas CoreWindow might not.  -- DavidL
9947
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   347
                */
9950
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   348
9952
54b2eeb48c7d WinRT: build fix for Windows Phone 8.0
David Ludwig <dludwig@pobox.com>
parents: 9951
diff changeset
   349
#if (NTDDI_VERSION >= NTDDI_WIN10) || (SDL_WINRT_USE_APPLICATIONVIEW && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
9947
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   350
                mode.w = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Width);
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   351
                mode.h = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Height);
9950
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   352
#else
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   353
                /* On platform(s) that do not support VisibleBounds, such as Windows 8.1,
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   354
                   fall back to CoreWindow's Bounds property.
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   355
                */
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   356
                mode.w = WINRT_DIPS_TO_PHYSICAL_PIXELS(coreWin->Bounds.Width);
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   357
                mode.h = WINRT_DIPS_TO_PHYSICAL_PIXELS(coreWin->Bounds.Height);
6cc7e0682758 WinRT: enabled the Win10-Store Cert Kit bug-workaround, for Windows 8.1 apps
David Ludwig <dludwig@pobox.com>
parents: 9949
diff changeset
   358
#endif
9947
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   359
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   360
                mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   361
                mode.refresh_rate = 0;  /* Display mode is unknown, so just fill in zero, as specified by SDL's header files */
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   362
                display.desktop_mode = mode;
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   363
                display.current_mode = mode;
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   364
                if ((SDL_AddDisplayMode(&display, &mode) < 0) ||
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   365
                    (SDL_AddVideoDisplay(&display) < 0))
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   366
                {
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   367
                    return SDL_SetError("Failed to apply DXGI Display-detection workaround");
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   368
                }
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   369
            }
3b68fd2503df WinRT: workaround for a possible bug in the Win10 Store's Certification Kit
David Ludwig <dludwig@pobox.com>
parents: 9931
diff changeset
   370
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   371
            break;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   372
        }
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   373
    }
8578
6517b6aca713 WinRT: fixed a crash in SDL_Quit
David Ludwig <dludwig@pobox.com>
parents: 8574
diff changeset
   374
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   375
    dxgiAdapter1->Release();
8578
6517b6aca713 WinRT: fixed a crash in SDL_Quit
David Ludwig <dludwig@pobox.com>
parents: 8574
diff changeset
   376
    return 0;
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   377
}
8503
90b33b6c6ab9 WinRT: code cleanup wrt. display mode(s)
David Ludwig <dludwig@pobox.com>
parents: 8501
diff changeset
   378
8505
a76a3842c9eb WinRT: experimental and preliminary support for XAML-based overlays on Windows 8/RT
David Ludwig <dludwig@pobox.com>
parents: 8503
diff changeset
   379
int
8374
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   380
WINRT_InitModes(_THIS)
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   381
{
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   382
    /* HACK: Initialize a single display, for whatever screen the app's
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   383
         CoreApplicationView is on.
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   384
       TODO, WinRT: Try initializing multiple displays, one for each monitor.
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   385
         Appropriate WinRT APIs for this seem elusive, though.  -- DavidL
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   386
    */
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   387
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   388
    HRESULT hr;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   389
    IDXGIFactory2 * dxgiFactory2 = NULL;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   390
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   391
    hr = CreateDXGIFactory1(IID_IDXGIFactory2, (void **)&dxgiFactory2);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   392
    if (FAILED(hr)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   393
        WIN_SetErrorFromHRESULT(__FUNCTION__ ", CreateDXGIFactory1() failed", hr);
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   394
        return -1;
8374
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   395
    }
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   396
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   397
    for (int adapterIndex = 0; ; ++adapterIndex) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   398
        if (WINRT_AddDisplaysForAdapter(_this, dxgiFactory2, adapterIndex) < 0) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   399
            break;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   400
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   401
    }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   402
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   403
    return 0;
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   404
}
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   405
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   406
static int
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   407
WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   408
{
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   409
    return 0;
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   410
}
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   411
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   412
void
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   413
WINRT_VideoQuit(_THIS)
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   414
{
8374
0294dc45d39d WinRT: added cursor visibility toggling, and system cursor creation
David Ludwig <dludwig@pobox.com>
parents: 8368
diff changeset
   415
    WINRT_QuitMouse(_this);
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   416
}
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   417
9926
277db103ed10 WinRT: bug-fix, OpenGLES2 was failing to init, after recent windowing fixes
David Ludwig <dludwig@pobox.com>
parents: 9925
diff changeset
   418
static const Uint32 WINRT_DetectableFlags =
277db103ed10 WinRT: bug-fix, OpenGLES2 was failing to init, after recent windowing fixes
David Ludwig <dludwig@pobox.com>
parents: 9925
diff changeset
   419
    SDL_WINDOW_MAXIMIZED |
277db103ed10 WinRT: bug-fix, OpenGLES2 was failing to init, after recent windowing fixes
David Ludwig <dludwig@pobox.com>
parents: 9925
diff changeset
   420
    SDL_WINDOW_FULLSCREEN_DESKTOP |
277db103ed10 WinRT: bug-fix, OpenGLES2 was failing to init, after recent windowing fixes
David Ludwig <dludwig@pobox.com>
parents: 9925
diff changeset
   421
    SDL_WINDOW_SHOWN |
277db103ed10 WinRT: bug-fix, OpenGLES2 was failing to init, after recent windowing fixes
David Ludwig <dludwig@pobox.com>
parents: 9925
diff changeset
   422
    SDL_WINDOW_HIDDEN |
277db103ed10 WinRT: bug-fix, OpenGLES2 was failing to init, after recent windowing fixes
David Ludwig <dludwig@pobox.com>
parents: 9925
diff changeset
   423
    SDL_WINDOW_MOUSE_FOCUS;
277db103ed10 WinRT: bug-fix, OpenGLES2 was failing to init, after recent windowing fixes
David Ludwig <dludwig@pobox.com>
parents: 9925
diff changeset
   424
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   425
extern "C" Uint32
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   426
WINRT_DetectWindowFlags(SDL_Window * window)
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   427
{
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   428
    Uint32 latestFlags = 0;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   429
    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   430
    bool is_fullscreen = false;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   431
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   432
#if SDL_WINRT_USE_APPLICATIONVIEW
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   433
    if (data->appView) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   434
        is_fullscreen = data->appView->IsFullScreen;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   435
    }
9927
16d2f1997733 WinRT: bug-fix, fullscreen mode wasn't getting reported in Windows 8.0 apps
David Ludwig <dludwig@pobox.com>
parents: 9926
diff changeset
   436
#elif (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION == NTDDI_WIN8)
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   437
    is_fullscreen = true;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   438
#endif
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   439
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   440
    if (data->coreWindow.Get()) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   441
        if (is_fullscreen) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   442
            SDL_VideoDisplay * display = SDL_GetDisplayForWindow(window);
9925
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   443
            int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   444
            int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   445
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   446
#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION > NTDDI_WIN8)
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   447
            // On all WinRT platforms, except for WinPhone 8.0, rotate the
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   448
            // window size.  This is needed to properly calculate
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   449
            // fullscreen vs. maximized.
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   450
            const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   451
            switch (currentOrientation) {
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   452
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   453
                case DisplayOrientations::Landscape:
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   454
                case DisplayOrientations::LandscapeFlipped:
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   455
#else
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   456
                case DisplayOrientations::Portrait:
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   457
                case DisplayOrientations::PortraitFlipped:
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   458
#endif
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   459
                {
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   460
                    int tmp = w;
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   461
                    w = h;
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   462
                    h = tmp;
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   463
                } break;
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   464
            }
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   465
#endif
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   466
2be74843315c WinRT: bug-fix, fullscreen window flags weren't set if device was rotated 90 degrees
David Ludwig <dludwig@pobox.com>
parents: 9924
diff changeset
   467
            if (display->desktop_mode.w != w || display->desktop_mode.h != h) {
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   468
                latestFlags |= SDL_WINDOW_MAXIMIZED;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   469
            } else {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   470
                latestFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   471
            }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   472
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   473
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   474
        if (data->coreWindow->Visible) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   475
            latestFlags |= SDL_WINDOW_SHOWN;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   476
        } else {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   477
            latestFlags |= SDL_WINDOW_HIDDEN;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   478
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   479
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   480
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION < NTDDI_WINBLUE)
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   481
        // data->coreWindow->PointerPosition is not supported on WinPhone 8.0
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   482
        latestFlags |= SDL_WINDOW_MOUSE_FOCUS;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   483
#else
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   484
        if (data->coreWindow->Bounds.Contains(data->coreWindow->PointerPosition)) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   485
            latestFlags |= SDL_WINDOW_MOUSE_FOCUS;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   486
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   487
#endif
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   488
    }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   489
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   490
    return latestFlags;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   491
}
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   492
9993
e05d46c27ce3 WinRT: minor code-comment cleanups
David Ludwig <dludwig@pobox.com>
parents: 9964
diff changeset
   493
// TODO, WinRT: consider removing WINRT_UpdateWindowFlags, and just calling WINRT_DetectWindowFlags as-appropriate (with appropriate calls to SDL_SendWindowEvent)
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   494
void
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   495
WINRT_UpdateWindowFlags(SDL_Window * window, Uint32 mask)
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   496
{
9926
277db103ed10 WinRT: bug-fix, OpenGLES2 was failing to init, after recent windowing fixes
David Ludwig <dludwig@pobox.com>
parents: 9925
diff changeset
   497
    mask &= WINRT_DetectableFlags;
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   498
    if (window) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   499
        Uint32 apply = WINRT_DetectWindowFlags(window);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   500
        if ((apply & mask) & SDL_WINDOW_FULLSCREEN) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   501
            window->last_fullscreen_flags = window->flags;  // seems necessary to programmatically un-fullscreen, via SDL APIs
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   502
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   503
        window->flags = (window->flags & ~mask) | (apply & mask);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   504
    }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   505
}
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   506
9964
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   507
static bool
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   508
WINRT_IsCoreWindowActive(CoreWindow ^ coreWindow)
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   509
{
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   510
    /* WinRT does not appear to offer API(s) to determine window-activation state,
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   511
       at least not that I am aware of in Win8 - Win10.  As such, SDL tracks this
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   512
       itself, via window-activation events.
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   513
       
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   514
       If there *is* an API to track this, it should probably get used instead
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   515
       of the following hack (that uses "SDLHelperWindowActivationState").
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   516
         -- DavidL.
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   517
    */
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   518
    if (coreWindow->CustomProperties->HasKey("SDLHelperWindowActivationState")) {
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   519
        CoreWindowActivationState activationState = \
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   520
            safe_cast<CoreWindowActivationState>(coreWindow->CustomProperties->Lookup("SDLHelperWindowActivationState"));
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   521
        return (activationState != CoreWindowActivationState::Deactivated);
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   522
    }
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   523
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   524
    /* Assume that non-SDL tracked windows are active, although this should
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   525
       probably be avoided, if possible.
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   526
       
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   527
       This might not even be possible, in normal SDL use, at least as of
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   528
       this writing (Dec 22, 2015; via latest hg.libsdl.org/SDL clone)  -- DavidL
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   529
    */
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   530
    return true;
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   531
}
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   532
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   533
int
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   534
WINRT_CreateWindow(_THIS, SDL_Window * window)
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   535
{
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   536
    // Make sure that only one window gets created, at least until multimonitor
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   537
    // support is added.
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   538
    if (WINRT_GlobalSDLWindow != NULL) {
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   539
        SDL_SetError("WinRT only supports one window");
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   540
        return -1;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   541
    }
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   542
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   543
    SDL_WindowData *data = new SDL_WindowData;  /* use 'new' here as SDL_WindowData may use WinRT/C++ types */
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   544
    if (!data) {
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   545
        SDL_OutOfMemory();
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   546
        return -1;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   547
    }
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   548
    window->driverdata = data;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   549
    data->sdlWindow = window;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   550
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   551
    /* To note, when XAML support is enabled, access to the CoreWindow will not
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   552
       be possible, at least not via the SDL/XAML thread.  Attempts to access it
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   553
       from there will throw exceptions.  As such, the SDL_WindowData's
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   554
       'coreWindow' field will only be set (to a non-null value) if XAML isn't
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   555
       enabled.
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   556
    */
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   557
    if (!WINRT_XAMLWasEnabled) {
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   558
        data->coreWindow = CoreWindow::GetForCurrentThread();
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   559
#if SDL_WINRT_USE_APPLICATIONVIEW
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   560
        data->appView = ApplicationView::GetForCurrentView();
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   561
#endif
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   562
    }
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   563
9931
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   564
    /* Make note of the requested window flags, before they start getting changed. */
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   565
    const Uint32 requestedFlags = window->flags;
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   566
8541
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   567
#if SDL_VIDEO_OPENGL_EGL
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   568
    /* Setup the EGL surface, but only if OpenGL ES 2 was requested. */
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   569
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   570
        /* OpenGL ES 2 wasn't requested.  Don't set up an EGL surface. */
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   571
        data->egl_surface = EGL_NO_SURFACE;
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   572
    } else {
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   573
        /* OpenGL ES 2 was reuqested.  Set up an EGL surface. */
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   574
        SDL_VideoData * video_data = (SDL_VideoData *)_this->driverdata;
8572
f8a89aa53309 WinRT: fixed crash on ARM and x64 during OpenGL window init
David Ludwig <dludwig@pobox.com>
parents: 8551
diff changeset
   575
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   576
        /* Call SDL_EGL_ChooseConfig and eglCreateWindowSurface directly,
9212
6b9794bae8ed WinRT: updated an OpenGL-related code-comment
David Ludwig <dludwig@pobox.com>
parents: 9211
diff changeset
   577
         * rather than via SDL_EGL_CreateSurface, as older versions of
6b9794bae8ed WinRT: updated an OpenGL-related code-comment
David Ludwig <dludwig@pobox.com>
parents: 9211
diff changeset
   578
         * ANGLE/WinRT may require that a C++ object, ComPtr<IUnknown>,
6b9794bae8ed WinRT: updated an OpenGL-related code-comment
David Ludwig <dludwig@pobox.com>
parents: 9211
diff changeset
   579
         * be passed into eglCreateWindowSurface.
8572
f8a89aa53309 WinRT: fixed crash on ARM and x64 during OpenGL window init
David Ludwig <dludwig@pobox.com>
parents: 8551
diff changeset
   580
         */
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   581
        if (SDL_EGL_ChooseConfig(_this) != 0) {
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   582
            char buf[512];
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   583
            SDL_snprintf(buf, sizeof(buf), "SDL_EGL_ChooseConfig failed: %s", SDL_GetError());
9557
e05c7ad6ec57 WinRT: Fixed format string for error message.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9214
diff changeset
   584
            return SDL_SetError("%s", buf);
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   585
        }
8572
f8a89aa53309 WinRT: fixed crash on ARM and x64 during OpenGL window init
David Ludwig <dludwig@pobox.com>
parents: 8551
diff changeset
   586
9211
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   587
        if (video_data->winrtEglWindow) {   /* ... is the 'old' version of ANGLE/WinRT being used? */
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   588
            /* Attempt to create a window surface using older versions of
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   589
             * ANGLE/WinRT:
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   590
             */
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   591
            Microsoft::WRL::ComPtr<IUnknown> cpp_winrtEglWindow = video_data->winrtEglWindow;
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   592
            data->egl_surface = ((eglCreateWindowSurface_Old_Function)_this->egl_data->eglCreateWindowSurface)(
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   593
                _this->egl_data->egl_display,
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   594
                _this->egl_data->egl_config,
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   595
                cpp_winrtEglWindow, NULL);
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   596
            if (data->egl_surface == NULL) {
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   597
                return SDL_SetError("eglCreateWindowSurface failed");
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   598
            }
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   599
        } else if (data->coreWindow.Get() != nullptr) {
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   600
            /* Attempt to create a window surface using newer versions of
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   601
             * ANGLE/WinRT:
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   602
             */
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   603
            IInspectable * coreWindowAsIInspectable = reinterpret_cast<IInspectable *>(data->coreWindow.Get());
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   604
            data->egl_surface = _this->egl_data->eglCreateWindowSurface(
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   605
                _this->egl_data->egl_display,
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   606
                _this->egl_data->egl_config,
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   607
                coreWindowAsIInspectable,
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   608
                NULL);
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   609
            if (data->egl_surface == NULL) {
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   610
                return SDL_SetError("eglCreateWindowSurface failed");
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   611
            }
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   612
        } else {
04c7e1220a65 WinRT: expanded OpenGL ES 2 support to enable recent updates to ANGLE/WinRT
David Ludwig <dludwig@pobox.com>
parents: 8757
diff changeset
   613
            return SDL_SetError("No supported means to create an EGL window surface are available");
8541
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   614
        }
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   615
    }
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   616
#endif
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   617
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   618
    /* Determine as many flags dynamically, as possible. */
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   619
    window->flags =
9928
639be75bbc84 WinRT: native windows are inherently resizable (in WinRT 8.x)
David Ludwig <dludwig@pobox.com>
parents: 9927
diff changeset
   620
        SDL_WINDOW_BORDERLESS |
639be75bbc84 WinRT: native windows are inherently resizable (in WinRT 8.x)
David Ludwig <dludwig@pobox.com>
parents: 9927
diff changeset
   621
        SDL_WINDOW_RESIZABLE;
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   622
8541
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   623
#if SDL_VIDEO_OPENGL_EGL
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   624
    if (data->egl_surface) {
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   625
        window->flags |= SDL_WINDOW_OPENGL;
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   626
    }
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   627
#endif
0041edb891f3 WinRT: added experimental OpenGL ES 2.0 support
David Ludwig <dludwig@pobox.com>
parents: 8527
diff changeset
   628
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   629
    if (WINRT_XAMLWasEnabled) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   630
        /* TODO, WinRT: set SDL_Window size, maybe position too, from XAML control */
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   631
        window->x = 0;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   632
        window->y = 0;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   633
        window->flags |= SDL_WINDOW_SHOWN;
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   634
        SDL_SetMouseFocus(NULL);        // TODO: detect this
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   635
        SDL_SetKeyboardFocus(NULL);     // TODO: detect this
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   636
    } else {
9931
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   637
        /* WinRT 8.x apps seem to live in an environment where the OS controls the
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   638
           app's window size, with some apps being fullscreen, depending on
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   639
           user choice of various things.  For now, just adapt the SDL_Window to
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   640
           whatever Windows set-up as the native-window's geometry.
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   641
        */
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   642
        window->x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   643
        window->y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
9931
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   644
#if NTDDI_VERSION < NTDDI_WIN10
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   645
        /* On WinRT 8.x / pre-Win10, just use the size we were given. */
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   646
        window->w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   647
        window->h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
9931
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   648
#else
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   649
        /* On Windows 10, we occasionally get control over window size.  For windowed
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   650
           mode apps, try this.
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   651
        */
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   652
        bool didSetSize = false;
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   653
        if (!(requestedFlags & SDL_WINDOW_FULLSCREEN)) {
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   654
            const Windows::Foundation::Size size(WINRT_PHYSICAL_PIXELS_TO_DIPS(window->w),
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   655
                                                 WINRT_PHYSICAL_PIXELS_TO_DIPS(window->h));
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   656
            didSetSize = data->appView->TryResizeView(size);
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   657
        }
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   658
        if (!didSetSize) {
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   659
            /* We either weren't able to set the window size, or a request for
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   660
               fullscreen was made.  Get window-size info from the OS.
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   661
            */
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   662
            window->w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   663
            window->h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   664
        }
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   665
#endif
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   666
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   667
        WINRT_UpdateWindowFlags(
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   668
            window,
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   669
            0xffffffff      /* Update any window flag(s) that WINRT_UpdateWindow can handle */
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   670
        );
8551
666f05b079ea WinRT: bug fix: game-controller/joystick button-down events weren't getting sent
David Ludwig <dludwig@pobox.com>
parents: 8541
diff changeset
   671
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   672
        /* Try detecting if the window is active */
9964
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   673
        bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
9924
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   674
        if (isWindowActive) {
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   675
            SDL_SetKeyboardFocus(window);
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   676
        }
355cccccc7dc WinRT: lots of display and windowing related fixes
David Ludwig <dludwig@pobox.com>
parents: 9619
diff changeset
   677
    }
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   678
 
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   679
    /* Make sure the WinRT app's IFramworkView can post events on
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   680
       behalf of SDL:
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   681
    */
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   682
    WINRT_GlobalSDLWindow = window;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   683
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   684
    /* All done! */
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   685
    return 0;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   686
}
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   687
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   688
void
9931
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   689
WINRT_SetWindowSize(_THIS, SDL_Window * window)
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   690
{
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   691
#if NTDDI_VERSION >= NTDDI_WIN10
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   692
    SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   693
    const Windows::Foundation::Size size(WINRT_PHYSICAL_PIXELS_TO_DIPS(window->w),
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   694
                                         WINRT_PHYSICAL_PIXELS_TO_DIPS(window->h));
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   695
    data->appView->TryResizeView(size); // TODO, WinRT: return failure (to caller?) from TryResizeView()
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   696
#endif
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   697
}
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   698
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   699
void
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   700
WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   701
{
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   702
#if NTDDI_VERSION >= NTDDI_WIN10
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   703
    SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
9964
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   704
    bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   705
    if (isWindowActive) {
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   706
        if (fullscreen) {
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   707
            if (!data->appView->IsFullScreenMode) {
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   708
                data->appView->TryEnterFullScreenMode();    // TODO, WinRT: return failure (to caller?) from TryEnterFullScreenMode()
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   709
            }
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   710
        } else {
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   711
            if (data->appView->IsFullScreenMode) {
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   712
                data->appView->ExitFullScreenMode();
bcb6bd590d03 WinRT: Fixed bug 3210, "alt-tab doesn't work correctly with full-screened, UWP (Win10 Store) apps"
David Ludwig <dludwig@pobox.com>
parents: 9952
diff changeset
   713
            }
9931
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   714
        }
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   715
    }
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   716
#endif
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   717
}
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   718
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   719
0bb3dd1c95f2 WinRT: added Win10/UWP (Universal Windows Platform) support
David Ludwig <dludwig@pobox.com>
parents: 9929
diff changeset
   720
void
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   721
WINRT_DestroyWindow(_THIS, SDL_Window * window)
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   722
{
8411
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   723
    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   724
8497
103bb054aa7d WinRT: moved the pointer to the global SDL_Window to a separate variable
David Ludwig <dludwig@pobox.com>
parents: 8496
diff changeset
   725
    if (WINRT_GlobalSDLWindow == window) {
103bb054aa7d WinRT: moved the pointer to the global SDL_Window to a separate variable
David Ludwig <dludwig@pobox.com>
parents: 8496
diff changeset
   726
        WINRT_GlobalSDLWindow = NULL;
8424
3cf9501008f1 WinRT: fixed bug: SDL_CreateWindow wouldn't work after an initial window was created + destroyed
David Ludwig <dludwig@pobox.com>
parents: 8417
diff changeset
   727
    }
3cf9501008f1 WinRT: fixed bug: SDL_CreateWindow wouldn't work after an initial window was created + destroyed
David Ludwig <dludwig@pobox.com>
parents: 8417
diff changeset
   728
8411
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   729
    if (data) {
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   730
        // Delete the internal window data:
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   731
        delete data;
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   732
        data = NULL;
9214
dad92c567585 WinRT: fixed crash when trying, and failing, to load the opengles2 renderer
David Ludwig <dludwig@pobox.com>
parents: 9212
diff changeset
   733
        window->driverdata = NULL;
8411
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   734
    }
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   735
}
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   736
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   737
SDL_bool
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   738
WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   739
{
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   740
    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   741
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   742
    if (info->version.major <= SDL_MAJOR_VERSION) {
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   743
        info->subsystem = SDL_SYSWM_WINRT;
8527
e3807733fad5 WinRT: made SDL_GetWindowWMInfo return window data in a slightly easier-to-use format
David Ludwig <dludwig@pobox.com>
parents: 8522
diff changeset
   744
        info->info.winrt.window = reinterpret_cast<IInspectable *>(data->coreWindow.Get());
8522
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   745
        return SDL_TRUE;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   746
    } else {
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   747
        SDL_SetError("Application not compiled with SDL %d.%d\n",
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   748
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   749
        return SDL_FALSE;
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   750
    }
3ae9dc9c439f WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
David Ludwig <dludwig@pobox.com>
parents: 8516
diff changeset
   751
    return SDL_FALSE;
8411
aca0591bc58f WinRT: provided access, via SDL_GetWindowWMInfo, to SDL's WinRT CoreWindow
David Ludwig <dludwig@pobox.com>
parents: 8401
diff changeset
   752
}
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   753
8327
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   754
#endif /* SDL_VIDEO_DRIVER_WINRT */
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   755
bc51589f33dc WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   756
/* vi: set ts=4 sw=4 expandtab: */