src/video/windows/SDL_windowsvideo.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 18 May 2018 13:09:30 -0700
changeset 11983 3a50eb90e4b2
parent 11872 e917e911dab6
child 12070 1d65571b57dd
permissions -rw-r--r--
Merged latest changes from Steam Link app
slouken@1895
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
slouken@1895
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1895
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1895
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1895
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@1895
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@6044
    24
slouken@1895
    25
#include "SDL_main.h"
slouken@1895
    26
#include "SDL_video.h"
slouken@8813
    27
#include "SDL_hints.h"
slouken@1895
    28
#include "SDL_mouse.h"
slouken@7762
    29
#include "SDL_system.h"
slouken@1895
    30
#include "../SDL_sysvideo.h"
slouken@1895
    31
#include "../SDL_pixels_c.h"
slouken@1895
    32
slouken@5062
    33
#include "SDL_windowsvideo.h"
slouken@5175
    34
#include "SDL_windowsframebuffer.h"
slouken@5062
    35
#include "SDL_windowsshape.h"
icculus@11365
    36
#include "SDL_windowsvulkan.h"
slouken@1895
    37
slouken@1895
    38
/* Initialization/Query functions */
slouken@1895
    39
static int WIN_VideoInit(_THIS);
slouken@1895
    40
static void WIN_VideoQuit(_THIS);
slouken@1895
    41
slouken@8813
    42
/* Hints */
slouken@8814
    43
SDL_bool g_WindowsEnableMessageLoop = SDL_TRUE;
slouken@8813
    44
SDL_bool g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
slouken@8813
    45
slouken@11284
    46
static void SDLCALL
slouken@11284
    47
UpdateWindowsEnableMessageLoop(void *userdata, const char *name, const char *oldValue, const char *newValue)
slouken@8814
    48
{
slouken@8814
    49
    if (newValue && *newValue == '0') {
slouken@8814
    50
        g_WindowsEnableMessageLoop = SDL_FALSE;
slouken@8814
    51
    } else {
slouken@8814
    52
        g_WindowsEnableMessageLoop = SDL_TRUE;
slouken@8814
    53
    }
slouken@8814
    54
}
slouken@8814
    55
slouken@11284
    56
static void SDLCALL
slouken@11284
    57
UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const char *oldValue, const char *newValue)
slouken@8813
    58
{
slouken@8813
    59
    if (newValue && *newValue == '0') {
slouken@8813
    60
        g_WindowFrameUsableWhileCursorHidden = SDL_FALSE;
slouken@8813
    61
    } else {
slouken@8813
    62
        g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
slouken@8813
    63
    }
slouken@8813
    64
}
slouken@8813
    65
slouken@2710
    66
slouken@5062
    67
/* Windows driver bootstrap functions */
slouken@1895
    68
slouken@1895
    69
static int
slouken@1895
    70
WIN_Available(void)
slouken@1895
    71
{
slouken@1895
    72
    return (1);
slouken@1895
    73
}
slouken@1895
    74
slouken@1895
    75
static void
slouken@1895
    76
WIN_DeleteDevice(SDL_VideoDevice * device)
slouken@1895
    77
{
slouken@1895
    78
    SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
slouken@1895
    79
slouken@1895
    80
    SDL_UnregisterApp();
slouken@7191
    81
    if (data->userDLL) {
slouken@7191
    82
        SDL_UnloadObject(data->userDLL);
slouken@7191
    83
    }
alfred@9813
    84
    if (data->shcoreDLL) {
alfred@9813
    85
        SDL_UnloadObject(data->shcoreDLL);
alfred@9813
    86
    }
slouken@4919
    87
slouken@1895
    88
    SDL_free(device->driverdata);
slouken@1895
    89
    SDL_free(device);
slouken@1895
    90
}
slouken@1895
    91
slouken@1895
    92
static SDL_VideoDevice *
slouken@1895
    93
WIN_CreateDevice(int devindex)
slouken@1895
    94
{
slouken@1895
    95
    SDL_VideoDevice *device;
slouken@1895
    96
    SDL_VideoData *data;
slouken@1895
    97
slouken@1895
    98
    SDL_RegisterApp(NULL, 0, NULL);
slouken@1895
    99
slouken@1895
   100
    /* Initialize all variables that we clean on shutdown */
slouken@1895
   101
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1895
   102
    if (device) {
slouken@1895
   103
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
slouken@4761
   104
    } else {
slouken@4761
   105
        data = NULL;
slouken@1895
   106
    }
slouken@4761
   107
    if (!data) {
slouken@7719
   108
        SDL_free(device);
icculus@7037
   109
        SDL_OutOfMemory();
slouken@1895
   110
        return NULL;
slouken@1895
   111
    }
slouken@1895
   112
    device->driverdata = data;
slouken@1895
   113
slouken@7191
   114
    data->userDLL = SDL_LoadObject("USER32.DLL");
slouken@7191
   115
    if (data->userDLL) {
sezero@11872
   116
        data->CloseTouchInputHandle = (BOOL (WINAPI *)(HTOUCHINPUT)) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
sezero@11872
   117
        data->GetTouchInputInfo = (BOOL (WINAPI *)(HTOUCHINPUT, UINT, PTOUCHINPUT, int)) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
sezero@11872
   118
        data->RegisterTouchWindow = (BOOL (WINAPI *)(HWND, ULONG)) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
slouken@11219
   119
    } else {
slouken@11219
   120
        SDL_ClearError();
slouken@7191
   121
    }
slouken@4919
   122
alfred@9813
   123
    data->shcoreDLL = SDL_LoadObject("SHCORE.DLL");
alfred@9813
   124
    if (data->shcoreDLL) {
sezero@11872
   125
        data->GetDpiForMonitor = (HRESULT (WINAPI *)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *)) SDL_LoadFunction(data->shcoreDLL, "GetDpiForMonitor");
slouken@11219
   126
    } else {
slouken@11219
   127
        SDL_ClearError();
alfred@9813
   128
    }
alfred@9813
   129
slouken@1895
   130
    /* Set the function pointers */
slouken@1895
   131
    device->VideoInit = WIN_VideoInit;
slouken@1913
   132
    device->VideoQuit = WIN_VideoQuit;
slouken@3528
   133
    device->GetDisplayBounds = WIN_GetDisplayBounds;
icculus@10019
   134
    device->GetDisplayUsableBounds = WIN_GetDisplayUsableBounds;
alfred@9813
   135
    device->GetDisplayDPI = WIN_GetDisplayDPI;
slouken@1895
   136
    device->GetDisplayModes = WIN_GetDisplayModes;
slouken@1895
   137
    device->SetDisplayMode = WIN_SetDisplayMode;
slouken@1895
   138
    device->PumpEvents = WIN_PumpEvents;
slouken@1895
   139
slouken@11383
   140
    device->CreateSDLWindow = WIN_CreateWindow;
slouken@11383
   141
    device->CreateSDLWindowFrom = WIN_CreateWindowFrom;
slouken@1895
   142
    device->SetWindowTitle = WIN_SetWindowTitle;
slouken@2970
   143
    device->SetWindowIcon = WIN_SetWindowIcon;
slouken@1895
   144
    device->SetWindowPosition = WIN_SetWindowPosition;
slouken@1895
   145
    device->SetWindowSize = WIN_SetWindowSize;
slouken@11815
   146
    device->GetWindowBordersSize = WIN_GetWindowBordersSize;
icculus@10025
   147
    device->SetWindowOpacity = WIN_SetWindowOpacity;
slouken@1895
   148
    device->ShowWindow = WIN_ShowWindow;
slouken@1895
   149
    device->HideWindow = WIN_HideWindow;
slouken@1895
   150
    device->RaiseWindow = WIN_RaiseWindow;
slouken@1895
   151
    device->MaximizeWindow = WIN_MaximizeWindow;
slouken@1895
   152
    device->MinimizeWindow = WIN_MinimizeWindow;
slouken@1895
   153
    device->RestoreWindow = WIN_RestoreWindow;
icculus@6422
   154
    device->SetWindowBordered = WIN_SetWindowBordered;
icculus@10385
   155
    device->SetWindowResizable = WIN_SetWindowResizable;
slouken@5305
   156
    device->SetWindowFullscreen = WIN_SetWindowFullscreen;
slouken@5466
   157
    device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
slouken@5466
   158
    device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
slouken@1895
   159
    device->SetWindowGrab = WIN_SetWindowGrab;
slouken@1895
   160
    device->DestroyWindow = WIN_DestroyWindow;
slouken@1895
   161
    device->GetWindowWMInfo = WIN_GetWindowWMInfo;
slouken@5175
   162
    device->CreateWindowFramebuffer = WIN_CreateWindowFramebuffer;
slouken@5175
   163
    device->UpdateWindowFramebuffer = WIN_UpdateWindowFramebuffer;
slouken@5175
   164
    device->DestroyWindowFramebuffer = WIN_DestroyWindowFramebuffer;
jorgen@7089
   165
    device->OnWindowEnter = WIN_OnWindowEnter;
icculus@8938
   166
    device->SetWindowHitTest = WIN_SetWindowHitTest;
slouken@7191
   167
eligottlieb@4788
   168
    device->shape_driver.CreateShaper = Win32_CreateShaper;
eligottlieb@4788
   169
    device->shape_driver.SetWindowShape = Win32_SetWindowShape;
eligottlieb@4788
   170
    device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
slouken@7191
   171
slouken@5088
   172
#if SDL_VIDEO_OPENGL_WGL
slouken@1913
   173
    device->GL_LoadLibrary = WIN_GL_LoadLibrary;
slouken@1913
   174
    device->GL_GetProcAddress = WIN_GL_GetProcAddress;
slouken@3057
   175
    device->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
slouken@1913
   176
    device->GL_CreateContext = WIN_GL_CreateContext;
slouken@1913
   177
    device->GL_MakeCurrent = WIN_GL_MakeCurrent;
slouken@1913
   178
    device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
slouken@1913
   179
    device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
slouken@1913
   180
    device->GL_SwapWindow = WIN_GL_SwapWindow;
slouken@1913
   181
    device->GL_DeleteContext = WIN_GL_DeleteContext;
slouken@8908
   182
#elif SDL_VIDEO_OPENGL_EGL        
slouken@8908
   183
    /* Use EGL based functions */
slouken@8908
   184
    device->GL_LoadLibrary = WIN_GLES_LoadLibrary;
slouken@8908
   185
    device->GL_GetProcAddress = WIN_GLES_GetProcAddress;
slouken@8908
   186
    device->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
slouken@8908
   187
    device->GL_CreateContext = WIN_GLES_CreateContext;
slouken@8908
   188
    device->GL_MakeCurrent = WIN_GLES_MakeCurrent;
slouken@8908
   189
    device->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
slouken@8908
   190
    device->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
slouken@8908
   191
    device->GL_SwapWindow = WIN_GLES_SwapWindow;
slouken@8908
   192
    device->GL_DeleteContext = WIN_GLES_DeleteContext;
slouken@1913
   193
#endif
slouken@11381
   194
#if SDL_VIDEO_VULKAN
icculus@11365
   195
    device->Vulkan_LoadLibrary = WIN_Vulkan_LoadLibrary;
icculus@11365
   196
    device->Vulkan_UnloadLibrary = WIN_Vulkan_UnloadLibrary;
icculus@11365
   197
    device->Vulkan_GetInstanceExtensions = WIN_Vulkan_GetInstanceExtensions;
icculus@11365
   198
    device->Vulkan_CreateSurface = WIN_Vulkan_CreateSurface;
icculus@11365
   199
#endif
icculus@11365
   200
slouken@4761
   201
    device->StartTextInput = WIN_StartTextInput;
slouken@4761
   202
    device->StopTextInput = WIN_StopTextInput;
slouken@4761
   203
    device->SetTextInputRect = WIN_SetTextInputRect;
slouken@4761
   204
slouken@4761
   205
    device->SetClipboardText = WIN_SetClipboardText;
slouken@4761
   206
    device->GetClipboardText = WIN_GetClipboardText;
slouken@4761
   207
    device->HasClipboardText = WIN_HasClipboardText;
slouken@1895
   208
slouken@1895
   209
    device->free = WIN_DeleteDevice;
slouken@1895
   210
slouken@1895
   211
    return device;
slouken@1895
   212
}
slouken@1895
   213
slouken@8813
   214
slouken@5062
   215
VideoBootStrap WINDOWS_bootstrap = {
slouken@5086
   216
    "windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice
slouken@1895
   217
};
slouken@1895
   218
slouken@1895
   219
int
slouken@1895
   220
WIN_VideoInit(_THIS)
slouken@1895
   221
{
slouken@3521
   222
    if (WIN_InitModes(_this) < 0) {
slouken@3521
   223
        return -1;
slouken@3521
   224
    }
slouken@1895
   225
slouken@1895
   226
    WIN_InitKeyboard(_this);
slouken@1895
   227
    WIN_InitMouse(_this);
slouken@1895
   228
slouken@8814
   229
    SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
slouken@8814
   230
    SDL_AddHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);
slouken@8813
   231
slouken@1895
   232
    return 0;
slouken@1895
   233
}
slouken@1895
   234
slouken@1895
   235
void
slouken@1895
   236
WIN_VideoQuit(_THIS)
slouken@1895
   237
{
slouken@1895
   238
    WIN_QuitModes(_this);
slouken@1895
   239
    WIN_QuitKeyboard(_this);
slouken@1895
   240
    WIN_QuitMouse(_this);
slouken@1895
   241
}
slouken@1895
   242
slouken@7762
   243
slouken@7762
   244
#define D3D_DEBUG_INFO
slouken@7762
   245
#include <d3d9.h>
slouken@7762
   246
slouken@7762
   247
SDL_bool 
slouken@8814
   248
D3D_LoadDLL(void **pD3DDLL, IDirect3D9 **pDirect3D9Interface)
slouken@7762
   249
{
slouken@8719
   250
    *pD3DDLL = SDL_LoadObject("D3D9.DLL");
slouken@8719
   251
    if (*pD3DDLL) {
slouken@8792
   252
        typedef IDirect3D9 *(WINAPI *Direct3DCreate9_t) (UINT SDKVersion);
slouken@8797
   253
        Direct3DCreate9_t Direct3DCreate9Func;
slouken@7762
   254
slouken@8797
   255
#ifdef USE_D3D9EX
slouken@8794
   256
        typedef HRESULT (WINAPI *Direct3DCreate9Ex_t)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
slouken@8792
   257
        Direct3DCreate9Ex_t Direct3DCreate9ExFunc;
icculus@8751
   258
sezero@11872
   259
        Direct3DCreate9ExFunc = (Direct3DCreate9Ex_t)SDL_LoadFunction(*pD3DDLL, "Direct3DCreate9Ex");
slouken@8792
   260
        if (Direct3DCreate9ExFunc) {
slouken@8792
   261
            IDirect3D9Ex *pDirect3D9ExInterface;
slouken@8792
   262
            HRESULT hr = Direct3DCreate9ExFunc(D3D_SDK_VERSION, &pDirect3D9ExInterface);
slouken@8792
   263
            if (SUCCEEDED(hr)) {
slouken@8792
   264
                const GUID IDirect3D9_GUID = { 0x81bdcbca, 0x64d4, 0x426d, { 0xae, 0x8d, 0xad, 0x1, 0x47, 0xf4, 0x27, 0x5c } };
slouken@8793
   265
                hr = IDirect3D9Ex_QueryInterface(pDirect3D9ExInterface, &IDirect3D9_GUID, (void**)pDirect3D9Interface);
slouken@8792
   266
                IDirect3D9Ex_Release(pDirect3D9ExInterface);
slouken@8792
   267
                if (SUCCEEDED(hr)) {
slouken@8792
   268
                    return SDL_TRUE;
slouken@8792
   269
                }
slouken@8792
   270
            }
slouken@8719
   271
        }
slouken@8797
   272
#endif /* USE_D3D9EX */
icculus@8751
   273
sezero@11872
   274
        Direct3DCreate9Func = (Direct3DCreate9_t)SDL_LoadFunction(*pD3DDLL, "Direct3DCreate9");
slouken@8792
   275
        if (Direct3DCreate9Func) {
slouken@8792
   276
            *pDirect3D9Interface = Direct3DCreate9Func(D3D_SDK_VERSION);
slouken@8792
   277
            if (*pDirect3D9Interface) {
slouken@8792
   278
                return SDL_TRUE;
slouken@8792
   279
            }
slouken@8719
   280
        }
slouken@7762
   281
slouken@8792
   282
        SDL_UnloadObject(*pD3DDLL);
slouken@8792
   283
        *pD3DDLL = NULL;
slouken@8719
   284
    }
slouken@8792
   285
    *pDirect3D9Interface = NULL;
slouken@8792
   286
    return SDL_FALSE;
slouken@7762
   287
}
slouken@7762
   288
slouken@7762
   289
slouken@7762
   290
int
slouken@8814
   291
SDL_Direct3D9GetAdapterIndex(int displayIndex)
slouken@7762
   292
{
slouken@8719
   293
    void *pD3DDLL;
slouken@8719
   294
    IDirect3D9 *pD3D;
slouken@8719
   295
    if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
slouken@8719
   296
        SDL_SetError("Unable to create Direct3D interface");
slouken@8719
   297
        return D3DADAPTER_DEFAULT;
slouken@8719
   298
    } else {
slouken@8719
   299
        SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
slouken@8719
   300
        int adapterIndex = D3DADAPTER_DEFAULT;
slouken@7762
   301
slouken@8719
   302
        if (!pData) {
slouken@8719
   303
            SDL_SetError("Invalid display index");
slouken@8719
   304
            adapterIndex = -1; /* make sure we return something invalid */
slouken@8719
   305
        } else {
slouken@8719
   306
            char *displayName = WIN_StringToUTF8(pData->DeviceName);
slouken@8719
   307
            unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
slouken@8719
   308
            unsigned int i;
slouken@8719
   309
            for (i=0; i<count; i++) {
slouken@8719
   310
                D3DADAPTER_IDENTIFIER9 id;
slouken@8719
   311
                IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
slouken@7762
   312
slouken@8719
   313
                if (SDL_strcmp(id.DeviceName, displayName) == 0) {
slouken@8719
   314
                    adapterIndex = i;
slouken@8719
   315
                    break;
slouken@8719
   316
                }
slouken@8719
   317
            }
slouken@8719
   318
            SDL_free(displayName);
slouken@8719
   319
        }
slouken@7762
   320
slouken@8719
   321
        /* free up the D3D stuff we inited */
slouken@8719
   322
        IDirect3D9_Release(pD3D);
slouken@8719
   323
        SDL_UnloadObject(pD3DDLL);
slouken@7762
   324
slouken@8719
   325
        return adapterIndex;
slouken@8719
   326
    }
slouken@7762
   327
}
slouken@7762
   328
icculus@8751
   329
#if HAVE_DXGI_H
slouken@8213
   330
#define CINTERFACE
slouken@8213
   331
#define COBJMACROS
icculus@8301
   332
#include <dxgi.h>
slouken@8213
   333
icculus@8751
   334
static SDL_bool
slouken@8719
   335
DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
slouken@8213
   336
{
slouken@8719
   337
    *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
slouken@8720
   338
    if (*pDXGIDLL) {
slouken@8814
   339
        HRESULT (WINAPI *CreateDXGI)(REFIID riid, void **ppFactory);
slouken@8213
   340
sezero@11872
   341
        CreateDXGI =
sezero@11872
   342
            (HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
sezero@11872
   343
            "CreateDXGIFactory");
slouken@8719
   344
        if (CreateDXGI) {
slouken@8719
   345
            GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
slouken@8719
   346
            if (!SUCCEEDED(CreateDXGI(&dxgiGUID, (void**)pDXGIFactory))) {
slouken@8719
   347
                *pDXGIFactory = NULL;
slouken@8719
   348
            }
slouken@8719
   349
        }
slouken@8719
   350
        if (!*pDXGIFactory) {
slouken@8719
   351
            SDL_UnloadObject(*pDXGIDLL);
slouken@8719
   352
            *pDXGIDLL = NULL;
slouken@8719
   353
            return SDL_FALSE;
slouken@8719
   354
        }
slouken@8213
   355
slouken@8719
   356
        return SDL_TRUE;
slouken@8719
   357
    } else {
slouken@8719
   358
        *pDXGIFactory = NULL;
slouken@8719
   359
        return SDL_FALSE;
slouken@8719
   360
    }
slouken@8213
   361
}
icculus@8751
   362
#endif
slouken@8213
   363
slouken@8213
   364
slouken@8719
   365
SDL_bool
slouken@8719
   366
SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
slouken@8213
   367
{
icculus@8751
   368
#if !HAVE_DXGI_H
icculus@8751
   369
    if (adapterIndex) *adapterIndex = -1;
icculus@8751
   370
    if (outputIndex) *outputIndex = -1;
icculus@8751
   371
    SDL_SetError("SDL was compiled without DXGI support due to missing dxgi.h header");
icculus@8751
   372
    return SDL_FALSE;
icculus@8751
   373
#else
slouken@8719
   374
    SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
slouken@8719
   375
    void *pDXGIDLL;
icculus@8751
   376
    char *displayName;
icculus@8751
   377
    int nAdapter, nOutput;
slouken@8719
   378
    IDXGIFactory *pDXGIFactory;
slouken@8719
   379
    IDXGIAdapter *pDXGIAdapter;
slouken@8719
   380
    IDXGIOutput* pDXGIOutput;
slouken@8213
   381
slouken@8719
   382
    if (!adapterIndex) {
slouken@8719
   383
        SDL_InvalidParamError("adapterIndex");
slouken@8719
   384
        return SDL_FALSE;
slouken@8719
   385
    }
slouken@8213
   386
slouken@8719
   387
    if (!outputIndex) {
slouken@8719
   388
        SDL_InvalidParamError("outputIndex");
slouken@8719
   389
        return SDL_FALSE;
slouken@8719
   390
    }
slouken@8213
   391
slouken@8719
   392
    *adapterIndex = -1;
slouken@8719
   393
    *outputIndex = -1;
slouken@8213
   394
slouken@8719
   395
    if (!pData) {
slouken@8719
   396
        SDL_SetError("Invalid display index");
slouken@8719
   397
        return SDL_FALSE;
slouken@8719
   398
    }
slouken@8213
   399
slouken@8719
   400
    if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) {
slouken@8719
   401
        SDL_SetError("Unable to create DXGI interface");
slouken@8719
   402
        return SDL_FALSE;
slouken@8719
   403
    }
slouken@8213
   404
slouken@8719
   405
    displayName = WIN_StringToUTF8(pData->DeviceName);
slouken@8736
   406
    nAdapter = 0;
slouken@8719
   407
    while (*adapterIndex == -1 && SUCCEEDED(IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter))) {
slouken@8736
   408
        nOutput = 0;
slouken@8719
   409
        while (*adapterIndex == -1 && SUCCEEDED(IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput))) {
slouken@8719
   410
            DXGI_OUTPUT_DESC outputDesc;
slouken@8719
   411
            if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) {
slouken@8719
   412
                char *outputName = WIN_StringToUTF8(outputDesc.DeviceName);
slouken@8719
   413
                if (SDL_strcmp(outputName, displayName) == 0) {
slouken@8719
   414
                    *adapterIndex = nAdapter;
slouken@8719
   415
                    *outputIndex = nOutput;
slouken@8719
   416
                }
slouken@8814
   417
                SDL_free(outputName);
slouken@8719
   418
            }
slouken@8719
   419
            IDXGIOutput_Release(pDXGIOutput);
slouken@8719
   420
            nOutput++;
slouken@8719
   421
        }
slouken@8719
   422
        IDXGIAdapter_Release(pDXGIAdapter);
slouken@8719
   423
        nAdapter++;
slouken@8719
   424
    }
slouken@8719
   425
    SDL_free(displayName);
slouken@8213
   426
slouken@8719
   427
    /* free up the DXGI factory */
slouken@8719
   428
    IDXGIFactory_Release(pDXGIFactory);
slouken@8719
   429
    SDL_UnloadObject(pDXGIDLL);
slouken@8213
   430
slouken@8719
   431
    if (*adapterIndex == -1) {
slouken@8719
   432
        return SDL_FALSE;
slouken@8719
   433
    } else {
slouken@8719
   434
        return SDL_TRUE;
slouken@8719
   435
    }
icculus@8751
   436
#endif
slouken@8213
   437
}
slouken@8213
   438
slouken@6044
   439
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
slouken@6044
   440
slouken@1895
   441
/* vim: set ts=4 sw=4 expandtab: */