SDL_DXGIGetOutputInfo() checks input parameters and returns a boolean value whether or not it succeeded.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
diff --git a/include/SDL_system.h b/include/SDL_system.h
index fd929f7..cf3937a 100644
--- a/include/SDL_system.h
+++ b/include/SDL_system.h
@@ -59,7 +59,7 @@ extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer *
These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
required to create a DX10 or DX11 device and swap chain.
*/
-extern DECLSPEC void SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
+extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
#endif /* __WIN32__ */
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 301aff3..ed0ea86 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -604,5 +604,5 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_HasAVX,(void),(),return)
SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetDefaultAssertionHandler,(void),(),return)
SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return)
#ifdef __WIN32__
-SDL_DYNAPI_PROC(void,SDL_DXGIGetOutputInfo,(int a,int *b, int *c),(a,b,c),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_DXGIGetOutputInfo,(int a,int *b, int *c),(a,b,c),return)
#endif
diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c
index 503653b..c94d7b7 100644
--- a/src/video/windows/SDL_windowsvideo.c
+++ b/src/video/windows/SDL_windowsvideo.c
@@ -182,67 +182,67 @@ WIN_VideoQuit(_THIS)
SDL_bool
D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
{
- *pD3DDLL = SDL_LoadObject("D3D9.DLL");
- if (*pD3DDLL) {
- IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
-
- D3DCreate =
- (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
- "Direct3DCreate9");
- if (D3DCreate) {
- *pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
- }
- if (!*pDirect3D9Interface) {
- SDL_UnloadObject(*pD3DDLL);
- *pD3DDLL = NULL;
- return SDL_FALSE;
- }
-
- return SDL_TRUE;
- } else {
- *pDirect3D9Interface = NULL;
- return SDL_FALSE;
- }
+ *pD3DDLL = SDL_LoadObject("D3D9.DLL");
+ if (*pD3DDLL) {
+ IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
+
+ D3DCreate =
+ (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
+ "Direct3DCreate9");
+ if (D3DCreate) {
+ *pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
+ }
+ if (!*pDirect3D9Interface) {
+ SDL_UnloadObject(*pD3DDLL);
+ *pD3DDLL = NULL;
+ return SDL_FALSE;
+ }
+
+ return SDL_TRUE;
+ } else {
+ *pDirect3D9Interface = NULL;
+ return SDL_FALSE;
+ }
}
int
SDL_Direct3D9GetAdapterIndex( int displayIndex )
{
- void *pD3DDLL;
- IDirect3D9 *pD3D;
- if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
- SDL_SetError("Unable to create Direct3D interface");
- return D3DADAPTER_DEFAULT;
- } else {
- SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
- int adapterIndex = D3DADAPTER_DEFAULT;
-
- if (!pData) {
- SDL_SetError("Invalid display index");
- adapterIndex = -1; /* make sure we return something invalid */
- } else {
- char *displayName = WIN_StringToUTF8(pData->DeviceName);
- unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
- unsigned int i;
- for (i=0; i<count; i++) {
- D3DADAPTER_IDENTIFIER9 id;
- IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
-
- if (SDL_strcmp(id.DeviceName, displayName) == 0) {
- adapterIndex = i;
- break;
- }
- }
- SDL_free(displayName);
- }
-
- /* free up the D3D stuff we inited */
- IDirect3D9_Release(pD3D);
- SDL_UnloadObject(pD3DDLL);
-
- return adapterIndex;
- }
+ void *pD3DDLL;
+ IDirect3D9 *pD3D;
+ if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
+ SDL_SetError("Unable to create Direct3D interface");
+ return D3DADAPTER_DEFAULT;
+ } else {
+ SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
+ int adapterIndex = D3DADAPTER_DEFAULT;
+
+ if (!pData) {
+ SDL_SetError("Invalid display index");
+ adapterIndex = -1; /* make sure we return something invalid */
+ } else {
+ char *displayName = WIN_StringToUTF8(pData->DeviceName);
+ unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
+ unsigned int i;
+ for (i=0; i<count; i++) {
+ D3DADAPTER_IDENTIFIER9 id;
+ IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
+
+ if (SDL_strcmp(id.DeviceName, displayName) == 0) {
+ adapterIndex = i;
+ break;
+ }
+ }
+ SDL_free(displayName);
+ }
+
+ /* free up the D3D stuff we inited */
+ IDirect3D9_Release(pD3D);
+ SDL_UnloadObject(pD3DDLL);
+
+ return adapterIndex;
+ }
}
#define CINTERFACE
@@ -250,84 +250,98 @@ SDL_Direct3D9GetAdapterIndex( int displayIndex )
#include <dxgi.h>
SDL_bool
-DXGI_LoadDLL( void **pDXGIDLL , IDXGIFactory **pDXGIFactory )
+DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
{
- *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
- if (*pDXGIDLL ) {
- HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory );
-
- CreateDXGI =
- (HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
- "CreateDXGIFactory");
- if (CreateDXGI) {
- GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
- if( !SUCCEEDED( CreateDXGI( &dxgiGUID, (void**)pDXGIFactory ))) {
- *pDXGIFactory = NULL;
- }
- }
- if (!*pDXGIFactory) {
- SDL_UnloadObject(*pDXGIDLL);
- *pDXGIDLL = NULL;
- return SDL_FALSE;
- }
-
- return SDL_TRUE;
- } else {
- *pDXGIFactory = NULL;
- return SDL_FALSE;
- }
+ *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
+ if (!*pDXGIDLL) {
+ HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory );
+
+ CreateDXGI =
+ (HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
+ "CreateDXGIFactory");
+ if (CreateDXGI) {
+ GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
+ if (!SUCCEEDED(CreateDXGI(&dxgiGUID, (void**)pDXGIFactory))) {
+ *pDXGIFactory = NULL;
+ }
+ }
+ if (!*pDXGIFactory) {
+ SDL_UnloadObject(*pDXGIDLL);
+ *pDXGIDLL = NULL;
+ return SDL_FALSE;
+ }
+
+ return SDL_TRUE;
+ } else {
+ *pDXGIFactory = NULL;
+ return SDL_FALSE;
+ }
}
-void
-SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex )
+SDL_bool
+SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
{
- void *pDXGIDLL;
- IDXGIFactory *pDXGIFactory;
-
- *adapterIndex = -1;
- *outputIndex = -1;
-
- if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) {
- SDL_SetError("Unable to create DXGI interface");
- } else {
- SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
-
- if (!pData) {
- SDL_SetError("Invalid display index");
- } else {
- char *displayName = WIN_StringToUTF8(pData->DeviceName);
- int nAdapter = 0, nOutput = 0;
- IDXGIAdapter* pDXGIAdapter;
- while ( *adapterIndex == -1 && IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter) != DXGI_ERROR_NOT_FOUND ) {
- IDXGIOutput* pDXGIOutput;
- while ( *adapterIndex == -1 && IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput) != DXGI_ERROR_NOT_FOUND ) {
- DXGI_OUTPUT_DESC outputDesc;
- if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) {
- char *outputName = WIN_StringToUTF8(outputDesc.DeviceName);
-
- if(!SDL_strcmp(outputName, displayName)) {
- *adapterIndex = nAdapter;
- *outputIndex = nOutput;
- }
-
- SDL_free( outputName );
- }
-
- IDXGIOutput_Release( pDXGIOutput );
- nOutput++;
- }
-
- IDXGIAdapter_Release( pDXGIAdapter );
- nAdapter++;
- }
- SDL_free(displayName);
- }
-
- /* free up the D3D stuff we inited */
- IDXGIFactory_AddRef( pDXGIFactory );
- SDL_UnloadObject(pDXGIDLL);
- }
+ SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
+ void *pDXGIDLL;
+ IDXGIFactory *pDXGIFactory;
+ IDXGIAdapter *pDXGIAdapter;
+ IDXGIOutput* pDXGIOutput;
+ int nAdapter = 0, nOutput = 0;
+ char *displayName;
+
+ if (!adapterIndex) {
+ SDL_InvalidParamError("adapterIndex");
+ return SDL_FALSE;
+ }
+
+ if (!outputIndex) {
+ SDL_InvalidParamError("outputIndex");
+ return SDL_FALSE;
+ }
+
+ *adapterIndex = -1;
+ *outputIndex = -1;
+
+ if (!pData) {
+ SDL_SetError("Invalid display index");
+ return SDL_FALSE;
+ }
+
+ if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) {
+ SDL_SetError("Unable to create DXGI interface");
+ return SDL_FALSE;
+ }
+
+ displayName = WIN_StringToUTF8(pData->DeviceName);
+ while (*adapterIndex == -1 && SUCCEEDED(IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter))) {
+ while (*adapterIndex == -1 && SUCCEEDED(IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput))) {
+ DXGI_OUTPUT_DESC outputDesc;
+ if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) {
+ char *outputName = WIN_StringToUTF8(outputDesc.DeviceName);
+ if (SDL_strcmp(outputName, displayName) == 0) {
+ *adapterIndex = nAdapter;
+ *outputIndex = nOutput;
+ }
+ SDL_free( outputName );
+ }
+ IDXGIOutput_Release(pDXGIOutput);
+ nOutput++;
+ }
+ IDXGIAdapter_Release(pDXGIAdapter);
+ nAdapter++;
+ }
+ SDL_free(displayName);
+
+ /* free up the DXGI factory */
+ IDXGIFactory_Release(pDXGIFactory);
+ SDL_UnloadObject(pDXGIDLL);
+
+ if (*adapterIndex == -1) {
+ return SDL_FALSE;
+ } else {
+ return SDL_TRUE;
+ }
}
#endif /* SDL_VIDEO_DRIVER_WINDOWS */