SDL_DXGIGetOutputInfo() checks input parameters and returns a boolean value whether or not it succeeded.

This commit is contained in:
Sam Lantinga 2014-04-18 12:43:04 -07:00
parent fc9e3a69b7
commit 03afd0de40
3 changed files with 128 additions and 114 deletions

View File

@ -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 These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
required to create a DX10 or DX11 device and swap chain. 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__ */ #endif /* __WIN32__ */

View File

@ -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_GetDefaultAssertionHandler,(void),(),return)
SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return) SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return)
#ifdef __WIN32__ #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 #endif

View File

@ -250,10 +250,10 @@ SDL_Direct3D9GetAdapterIndex( int displayIndex )
#include <dxgi.h> #include <dxgi.h>
SDL_bool SDL_bool
DXGI_LoadDLL( void **pDXGIDLL , IDXGIFactory **pDXGIFactory ) DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
{ {
*pDXGIDLL = SDL_LoadObject("DXGI.DLL"); *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
if (*pDXGIDLL ) { if (!*pDXGIDLL) {
HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory ); HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory );
CreateDXGI = CreateDXGI =
@ -261,7 +261,7 @@ DXGI_LoadDLL( void **pDXGIDLL , IDXGIFactory **pDXGIFactory )
"CreateDXGIFactory"); "CreateDXGIFactory");
if (CreateDXGI) { if (CreateDXGI) {
GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}}; GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
if( !SUCCEEDED( CreateDXGI( &dxgiGUID, (void**)pDXGIFactory ))) { if (!SUCCEEDED(CreateDXGI(&dxgiGUID, (void**)pDXGIFactory))) {
*pDXGIFactory = NULL; *pDXGIFactory = NULL;
} }
} }
@ -279,54 +279,68 @@ DXGI_LoadDLL( void **pDXGIDLL , IDXGIFactory **pDXGIFactory )
} }
void SDL_bool
SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex ) SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
{ {
SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
void *pDXGIDLL; void *pDXGIDLL;
IDXGIFactory *pDXGIFactory; 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; *adapterIndex = -1;
*outputIndex = -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) { if (!pData) {
SDL_SetError("Invalid display index"); SDL_SetError("Invalid display index");
} else { return SDL_FALSE;
char *displayName = WIN_StringToUTF8(pData->DeviceName); }
int nAdapter = 0, nOutput = 0;
IDXGIAdapter* pDXGIAdapter; if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) {
while ( *adapterIndex == -1 && IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter) != DXGI_ERROR_NOT_FOUND ) { SDL_SetError("Unable to create DXGI interface");
IDXGIOutput* pDXGIOutput; return SDL_FALSE;
while ( *adapterIndex == -1 && IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput) != DXGI_ERROR_NOT_FOUND ) { }
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; DXGI_OUTPUT_DESC outputDesc;
if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) { if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) {
char *outputName = WIN_StringToUTF8(outputDesc.DeviceName); char *outputName = WIN_StringToUTF8(outputDesc.DeviceName);
if (SDL_strcmp(outputName, displayName) == 0) {
if(!SDL_strcmp(outputName, displayName)) {
*adapterIndex = nAdapter; *adapterIndex = nAdapter;
*outputIndex = nOutput; *outputIndex = nOutput;
} }
SDL_free( outputName ); SDL_free( outputName );
} }
IDXGIOutput_Release(pDXGIOutput);
IDXGIOutput_Release( pDXGIOutput );
nOutput++; nOutput++;
} }
IDXGIAdapter_Release(pDXGIAdapter);
IDXGIAdapter_Release( pDXGIAdapter );
nAdapter++; nAdapter++;
} }
SDL_free(displayName); SDL_free(displayName);
}
/* free up the D3D stuff we inited */ /* free up the DXGI factory */
IDXGIFactory_AddRef( pDXGIFactory ); IDXGIFactory_Release(pDXGIFactory);
SDL_UnloadObject(pDXGIDLL); SDL_UnloadObject(pDXGIDLL);
if (*adapterIndex == -1) {
return SDL_FALSE;
} else {
return SDL_TRUE;
} }
} }