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