SDL_DXGIGetOutputInfo() checks input parameters and returns a boolean value whether or not it succeeded.
authorSam Lantinga <slouken@libsdl.org>
Fri, 18 Apr 2014 12:43:04 -0700
changeset 8719135b8fef4adb
parent 8718 61ae7b328789
child 8720 97d23eef62fd
SDL_DXGIGetOutputInfo() checks input parameters and returns a boolean value whether or not it succeeded.
include/SDL_system.h
src/dynapi/SDL_dynapi_procs.h
src/video/windows/SDL_windowsvideo.c
     1.1 --- a/include/SDL_system.h	Tue Apr 15 13:53:07 2014 -0700
     1.2 +++ b/include/SDL_system.h	Fri Apr 18 12:43:04 2014 -0700
     1.3 @@ -59,7 +59,7 @@
     1.4     These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
     1.5     required to create a DX10 or DX11 device and swap chain.
     1.6   */
     1.7 -extern DECLSPEC void SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
     1.8 +extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
     1.9  
    1.10  #endif /* __WIN32__ */
    1.11  
     2.1 --- a/src/dynapi/SDL_dynapi_procs.h	Tue Apr 15 13:53:07 2014 -0700
     2.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Fri Apr 18 12:43:04 2014 -0700
     2.3 @@ -604,5 +604,5 @@
     2.4  SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetDefaultAssertionHandler,(void),(),return)
     2.5  SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return)
     2.6  #ifdef __WIN32__
     2.7 -SDL_DYNAPI_PROC(void,SDL_DXGIGetOutputInfo,(int a,int *b, int *c),(a,b,c),)
     2.8 +SDL_DYNAPI_PROC(SDL_bool,SDL_DXGIGetOutputInfo,(int a,int *b, int *c),(a,b,c),return)
     2.9  #endif
     3.1 --- a/src/video/windows/SDL_windowsvideo.c	Tue Apr 15 13:53:07 2014 -0700
     3.2 +++ b/src/video/windows/SDL_windowsvideo.c	Fri Apr 18 12:43:04 2014 -0700
     3.3 @@ -182,67 +182,67 @@
     3.4  SDL_bool 
     3.5  D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
     3.6  {
     3.7 -	*pD3DDLL = SDL_LoadObject("D3D9.DLL");
     3.8 -	if (*pD3DDLL) {
     3.9 -		IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
    3.10 +    *pD3DDLL = SDL_LoadObject("D3D9.DLL");
    3.11 +    if (*pD3DDLL) {
    3.12 +        IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
    3.13  
    3.14 -		D3DCreate =
    3.15 -			(IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
    3.16 -			"Direct3DCreate9");
    3.17 -		if (D3DCreate) {
    3.18 -			*pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
    3.19 -		}
    3.20 -		if (!*pDirect3D9Interface) {
    3.21 -			SDL_UnloadObject(*pD3DDLL);
    3.22 -			*pD3DDLL = NULL;
    3.23 -			return SDL_FALSE;
    3.24 -		}
    3.25 +        D3DCreate =
    3.26 +            (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
    3.27 +            "Direct3DCreate9");
    3.28 +        if (D3DCreate) {
    3.29 +            *pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
    3.30 +        }
    3.31 +        if (!*pDirect3D9Interface) {
    3.32 +            SDL_UnloadObject(*pD3DDLL);
    3.33 +            *pD3DDLL = NULL;
    3.34 +            return SDL_FALSE;
    3.35 +        }
    3.36  
    3.37 -		return SDL_TRUE;
    3.38 -	} else {
    3.39 -		*pDirect3D9Interface = NULL;
    3.40 -		return SDL_FALSE;
    3.41 -	}
    3.42 +        return SDL_TRUE;
    3.43 +    } else {
    3.44 +        *pDirect3D9Interface = NULL;
    3.45 +        return SDL_FALSE;
    3.46 +    }
    3.47  }
    3.48  
    3.49  
    3.50  int
    3.51  SDL_Direct3D9GetAdapterIndex( int displayIndex )
    3.52  {
    3.53 -	void *pD3DDLL;
    3.54 -	IDirect3D9 *pD3D;
    3.55 -	if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
    3.56 -		SDL_SetError("Unable to create Direct3D interface");
    3.57 -		return D3DADAPTER_DEFAULT;
    3.58 -	} else {
    3.59 -		SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
    3.60 -		int adapterIndex = D3DADAPTER_DEFAULT;
    3.61 +    void *pD3DDLL;
    3.62 +    IDirect3D9 *pD3D;
    3.63 +    if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
    3.64 +        SDL_SetError("Unable to create Direct3D interface");
    3.65 +        return D3DADAPTER_DEFAULT;
    3.66 +    } else {
    3.67 +        SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
    3.68 +        int adapterIndex = D3DADAPTER_DEFAULT;
    3.69  
    3.70 -		if (!pData) {
    3.71 -			SDL_SetError("Invalid display index");
    3.72 -			adapterIndex = -1; /* make sure we return something invalid */
    3.73 -		} else {
    3.74 -			char *displayName = WIN_StringToUTF8(pData->DeviceName);
    3.75 -			unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
    3.76 -			unsigned int i;
    3.77 -			for (i=0; i<count; i++) {
    3.78 -				D3DADAPTER_IDENTIFIER9 id;
    3.79 -				IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
    3.80 +        if (!pData) {
    3.81 +            SDL_SetError("Invalid display index");
    3.82 +            adapterIndex = -1; /* make sure we return something invalid */
    3.83 +        } else {
    3.84 +            char *displayName = WIN_StringToUTF8(pData->DeviceName);
    3.85 +            unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
    3.86 +            unsigned int i;
    3.87 +            for (i=0; i<count; i++) {
    3.88 +                D3DADAPTER_IDENTIFIER9 id;
    3.89 +                IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
    3.90  
    3.91 -				if (SDL_strcmp(id.DeviceName, displayName) == 0) {
    3.92 -					adapterIndex = i;
    3.93 -					break;
    3.94 -				}
    3.95 -			}
    3.96 -			SDL_free(displayName);
    3.97 -		}
    3.98 +                if (SDL_strcmp(id.DeviceName, displayName) == 0) {
    3.99 +                    adapterIndex = i;
   3.100 +                    break;
   3.101 +                }
   3.102 +            }
   3.103 +            SDL_free(displayName);
   3.104 +        }
   3.105  
   3.106 -		/* free up the D3D stuff we inited */
   3.107 -		IDirect3D9_Release(pD3D);
   3.108 -		SDL_UnloadObject(pD3DDLL);
   3.109 +        /* free up the D3D stuff we inited */
   3.110 +        IDirect3D9_Release(pD3D);
   3.111 +        SDL_UnloadObject(pD3DDLL);
   3.112  
   3.113 -		return adapterIndex;
   3.114 -	}
   3.115 +        return adapterIndex;
   3.116 +    }
   3.117  }
   3.118  
   3.119  #define CINTERFACE
   3.120 @@ -250,84 +250,98 @@
   3.121  #include <dxgi.h>
   3.122  
   3.123  SDL_bool 
   3.124 -DXGI_LoadDLL( void **pDXGIDLL , IDXGIFactory **pDXGIFactory )
   3.125 +DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
   3.126  {
   3.127 -	*pDXGIDLL = SDL_LoadObject("DXGI.DLL");
   3.128 -	if (*pDXGIDLL ) {
   3.129 -		HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory );
   3.130 +    *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
   3.131 +    if (!*pDXGIDLL) {
   3.132 +        HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory );
   3.133  
   3.134 -		CreateDXGI =
   3.135 -			(HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
   3.136 -			"CreateDXGIFactory");
   3.137 -		if (CreateDXGI) {
   3.138 -			GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
   3.139 -			if( !SUCCEEDED( CreateDXGI( &dxgiGUID, (void**)pDXGIFactory ))) {
   3.140 -				*pDXGIFactory = NULL;
   3.141 -			}
   3.142 -		}
   3.143 -		if (!*pDXGIFactory) {
   3.144 -			SDL_UnloadObject(*pDXGIDLL);
   3.145 -			*pDXGIDLL = NULL;
   3.146 -			return SDL_FALSE;
   3.147 -		}
   3.148 +        CreateDXGI =
   3.149 +            (HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
   3.150 +            "CreateDXGIFactory");
   3.151 +        if (CreateDXGI) {
   3.152 +            GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
   3.153 +            if (!SUCCEEDED(CreateDXGI(&dxgiGUID, (void**)pDXGIFactory))) {
   3.154 +                *pDXGIFactory = NULL;
   3.155 +            }
   3.156 +        }
   3.157 +        if (!*pDXGIFactory) {
   3.158 +            SDL_UnloadObject(*pDXGIDLL);
   3.159 +            *pDXGIDLL = NULL;
   3.160 +            return SDL_FALSE;
   3.161 +        }
   3.162  
   3.163 -		return SDL_TRUE;
   3.164 -	} else {
   3.165 -		*pDXGIFactory = NULL;
   3.166 -		return SDL_FALSE;
   3.167 -	}
   3.168 +        return SDL_TRUE;
   3.169 +    } else {
   3.170 +        *pDXGIFactory = NULL;
   3.171 +        return SDL_FALSE;
   3.172 +    }
   3.173  }
   3.174  
   3.175  
   3.176 -void
   3.177 -SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex )
   3.178 +SDL_bool
   3.179 +SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
   3.180  {
   3.181 -	void *pDXGIDLL;
   3.182 -	IDXGIFactory *pDXGIFactory;
   3.183 +    SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
   3.184 +    void *pDXGIDLL;
   3.185 +    IDXGIFactory *pDXGIFactory;
   3.186 +    IDXGIAdapter *pDXGIAdapter;
   3.187 +    IDXGIOutput* pDXGIOutput;
   3.188 +    int nAdapter = 0, nOutput = 0;
   3.189 +    char *displayName;
   3.190  
   3.191 -	*adapterIndex = -1;
   3.192 -	*outputIndex = -1;
   3.193 +    if (!adapterIndex) {
   3.194 +        SDL_InvalidParamError("adapterIndex");
   3.195 +        return SDL_FALSE;
   3.196 +    }
   3.197  
   3.198 -	if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) {
   3.199 -		SDL_SetError("Unable to create DXGI interface");
   3.200 -	} else {
   3.201 -		SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
   3.202 +    if (!outputIndex) {
   3.203 +        SDL_InvalidParamError("outputIndex");
   3.204 +        return SDL_FALSE;
   3.205 +    }
   3.206  
   3.207 -		if (!pData) {
   3.208 -			SDL_SetError("Invalid display index");
   3.209 -		} else {
   3.210 -			char *displayName = WIN_StringToUTF8(pData->DeviceName);
   3.211 -			int nAdapter = 0, nOutput = 0;
   3.212 -			IDXGIAdapter* pDXGIAdapter;
   3.213 -			while ( *adapterIndex == -1 && IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter) != DXGI_ERROR_NOT_FOUND ) {
   3.214 -				IDXGIOutput* pDXGIOutput;
   3.215 -				while ( *adapterIndex == -1 && IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput) != DXGI_ERROR_NOT_FOUND ) {
   3.216 -					DXGI_OUTPUT_DESC outputDesc;
   3.217 -					if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) {
   3.218 -						char *outputName = WIN_StringToUTF8(outputDesc.DeviceName);
   3.219 +    *adapterIndex = -1;
   3.220 +    *outputIndex = -1;
   3.221  
   3.222 -						if(!SDL_strcmp(outputName, displayName)) {
   3.223 -							*adapterIndex = nAdapter;
   3.224 -							*outputIndex = nOutput;
   3.225 -						}
   3.226 +    if (!pData) {
   3.227 +        SDL_SetError("Invalid display index");
   3.228 +        return SDL_FALSE;
   3.229 +    }
   3.230  
   3.231 -						SDL_free( outputName );
   3.232 -					}
   3.233 +    if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) {
   3.234 +        SDL_SetError("Unable to create DXGI interface");
   3.235 +        return SDL_FALSE;
   3.236 +    }
   3.237  
   3.238 -					IDXGIOutput_Release( pDXGIOutput );
   3.239 -					nOutput++;
   3.240 -				}
   3.241 +    displayName = WIN_StringToUTF8(pData->DeviceName);
   3.242 +    while (*adapterIndex == -1 && SUCCEEDED(IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter))) {
   3.243 +        while (*adapterIndex == -1 && SUCCEEDED(IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput))) {
   3.244 +            DXGI_OUTPUT_DESC outputDesc;
   3.245 +            if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) {
   3.246 +                char *outputName = WIN_StringToUTF8(outputDesc.DeviceName);
   3.247 +                if (SDL_strcmp(outputName, displayName) == 0) {
   3.248 +                    *adapterIndex = nAdapter;
   3.249 +                    *outputIndex = nOutput;
   3.250 +                }
   3.251 +                SDL_free( outputName );
   3.252 +            }
   3.253 +            IDXGIOutput_Release(pDXGIOutput);
   3.254 +            nOutput++;
   3.255 +        }
   3.256 +        IDXGIAdapter_Release(pDXGIAdapter);
   3.257 +        nAdapter++;
   3.258 +    }
   3.259 +    SDL_free(displayName);
   3.260  
   3.261 -				IDXGIAdapter_Release( pDXGIAdapter );
   3.262 -				nAdapter++;
   3.263 -			}
   3.264 -			SDL_free(displayName);
   3.265 -		}
   3.266 +    /* free up the DXGI factory */
   3.267 +    IDXGIFactory_Release(pDXGIFactory);
   3.268 +    SDL_UnloadObject(pDXGIDLL);
   3.269  
   3.270 -		/* free up the D3D stuff we inited */
   3.271 -		IDXGIFactory_AddRef( pDXGIFactory );
   3.272 -		SDL_UnloadObject(pDXGIDLL);
   3.273 -	}
   3.274 +    if (*adapterIndex == -1) {
   3.275 +        return SDL_FALSE;
   3.276 +    } else {
   3.277 +        return SDL_TRUE;
   3.278 +    }
   3.279  }
   3.280  
   3.281  #endif /* SDL_VIDEO_DRIVER_WINDOWS */