Added SDL_DXGIGetOutputInfo which returns the adapter and output indices that are used to create DX10 and DX11 devices and swap chains on a particular display.
authorSam Lantinga <slouken@libsdl.org>
Thu, 13 Feb 2014 11:05:30 -0800
changeset 8213c08568651ebb
parent 8212 d278747da408
child 8214 c6006ec834fa
Added SDL_DXGIGetOutputInfo which returns the adapter and output indices that are used to create DX10 and DX11 devices and swap chains on a particular display.

CR: SamL
include/SDL_system.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/test/SDL_test_common.c
src/video/windows/SDL_windowsvideo.c
     1.1 --- a/include/SDL_system.h	Thu Feb 13 11:05:28 2014 -0800
     1.2 +++ b/include/SDL_system.h	Thu Feb 13 11:05:30 2014 -0800
     1.3 @@ -55,6 +55,12 @@
     1.4  typedef struct IDirect3DDevice9 IDirect3DDevice9;
     1.5  extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
     1.6  
     1.7 +/* Returns the DXGI Adapter and Output indices for the specified display index. 
     1.8 +   These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
     1.9 +   required to create a DX10 or DX11 device and swap chain.
    1.10 + */
    1.11 +extern DECLSPEC void SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
    1.12 +
    1.13  #endif /* __WIN32__ */
    1.14  
    1.15  
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Thu Feb 13 11:05:28 2014 -0800
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Thu Feb 13 11:05:30 2014 -0800
     2.3 @@ -574,3 +574,4 @@
     2.4  #define SDL_HasAVX SDL_HasAVX_REAL
     2.5  #define SDL_GetDefaultAssertionHandler SDL_GetDefaultAssertionHandler_REAL
     2.6  #define SDL_GetAssertionHandler SDL_GetAssertionHandler_REAL
     2.7 +#define SDL_DXGIGetOutputInfo SDL_DXGIGetOutputInfo_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Thu Feb 13 11:05:28 2014 -0800
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Thu Feb 13 11:05:30 2014 -0800
     3.3 @@ -70,6 +70,7 @@
     3.4  SDL_DYNAPI_PROC(int,SDL_RegisterApp,(char *a, Uint32 b, void *c),(a,b,c),return)
     3.5  SDL_DYNAPI_PROC(void,SDL_UnregisterApp,(void),(),)
     3.6  SDL_DYNAPI_PROC(int,SDL_Direct3D9GetAdapterIndex,(int a),(a),return)
     3.7 +SDL_DYNAPI_PROC(void,SDL_DXGIGetOutputInfo,(int a,int *b, int *c),(a,b,c),)
     3.8  SDL_DYNAPI_PROC(IDirect3DDevice9*,SDL_RenderGetD3D9Device,(SDL_Renderer *a),(a),return)
     3.9  #endif
    3.10  
     4.1 --- a/src/test/SDL_test_common.c	Thu Feb 13 11:05:28 2014 -0800
     4.2 +++ b/src/test/SDL_test_common.c	Thu Feb 13 11:05:30 2014 -0800
     4.3 @@ -706,6 +706,7 @@
     4.4              Uint32 Rmask, Gmask, Bmask, Amask;
     4.5  #if SDL_VIDEO_DRIVER_WINDOWS
     4.6  			int adapterIndex = 0;
     4.7 +			int outputIndex = 0;
     4.8  #endif
     4.9              n = SDL_GetNumVideoDisplays();
    4.10              fprintf(stderr, "Number of displays: %d\n", n);
    4.11 @@ -761,9 +762,13 @@
    4.12                  }
    4.13  
    4.14  #if SDL_VIDEO_DRIVER_WINDOWS
    4.15 -				/* Print the adapter index */
    4.16 +				/* Print the D3D9 adapter index */
    4.17  				adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
    4.18 -				fprintf( stderr, "Adapter Index: %d", adapterIndex );
    4.19 +				fprintf( stderr, "D3D9 Adapter Index: %d", adapterIndex );
    4.20 +
    4.21 +				/* Print the DXGI adapter and output indices */
    4.22 +				SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
    4.23 +				fprintf( stderr, "DXGI Adapter Index: %d  Output Index: %d", adapterIndex, outputIndex );
    4.24  #endif
    4.25              }
    4.26          }
     5.1 --- a/src/video/windows/SDL_windowsvideo.c	Thu Feb 13 11:05:28 2014 -0800
     5.2 +++ b/src/video/windows/SDL_windowsvideo.c	Thu Feb 13 11:05:30 2014 -0800
     5.3 @@ -245,6 +245,91 @@
     5.4  	}
     5.5  }
     5.6  
     5.7 +#define CINTERFACE
     5.8 +#define COBJMACROS
     5.9 +#include <DXGI.h>
    5.10 +
    5.11 +SDL_bool 
    5.12 +DXGI_LoadDLL( void **pDXGIDLL , IDXGIFactory **pDXGIFactory )
    5.13 +{
    5.14 +	*pDXGIDLL = SDL_LoadObject("DXGI.DLL");
    5.15 +	if (*pDXGIDLL ) {
    5.16 +		HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory );
    5.17 +
    5.18 +		CreateDXGI =
    5.19 +			(HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
    5.20 +			"CreateDXGIFactory");
    5.21 +		if (CreateDXGI) {
    5.22 +			GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
    5.23 +			if( !SUCCEEDED( CreateDXGI( &dxgiGUID, pDXGIFactory ))) {
    5.24 +				*pDXGIFactory = NULL;
    5.25 +			}
    5.26 +		}
    5.27 +		if (!*pDXGIFactory) {
    5.28 +			SDL_UnloadObject(*pDXGIDLL);
    5.29 +			*pDXGIDLL = NULL;
    5.30 +			return SDL_FALSE;
    5.31 +		}
    5.32 +
    5.33 +		return SDL_TRUE;
    5.34 +	} else {
    5.35 +		*pDXGIFactory = NULL;
    5.36 +		return SDL_FALSE;
    5.37 +	}
    5.38 +}
    5.39 +
    5.40 +
    5.41 +void
    5.42 +SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex )
    5.43 +{
    5.44 +	void *pDXGIDLL;
    5.45 +	IDXGIFactory *pDXGIFactory;
    5.46 +
    5.47 +	*adapterIndex = -1;
    5.48 +	*outputIndex = -1;
    5.49 +
    5.50 +	if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) {
    5.51 +		SDL_SetError("Unable to create DXGI interface");
    5.52 +	} else {
    5.53 +		SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
    5.54 +
    5.55 +		if (!pData) {
    5.56 +			SDL_SetError("Invalid display index");
    5.57 +		} else {
    5.58 +			char *displayName = WIN_StringToUTF8(pData->DeviceName);
    5.59 +			int nAdapter = 0, nOutput = 0;
    5.60 +			IDXGIAdapter* pDXGIAdapter;
    5.61 +			while ( *adapterIndex == -1 && IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter) != DXGI_ERROR_NOT_FOUND ) {
    5.62 +				IDXGIOutput* pDXGIOutput;
    5.63 +				while ( *adapterIndex == -1 && IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput) != DXGI_ERROR_NOT_FOUND ) {
    5.64 +					DXGI_OUTPUT_DESC outputDesc;
    5.65 +					if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) {
    5.66 +						char *outputName = WIN_StringToUTF8(outputDesc.DeviceName);
    5.67 +
    5.68 +						if(!SDL_strcmp(outputName, displayName)) {
    5.69 +							*adapterIndex = nAdapter;
    5.70 +							*outputIndex = nOutput;
    5.71 +						}
    5.72 +
    5.73 +						SDL_free( outputName );
    5.74 +					}
    5.75 +
    5.76 +					IDXGIOutput_Release( pDXGIOutput );
    5.77 +					nOutput++;
    5.78 +				}
    5.79 +
    5.80 +				IDXGIAdapter_Release( pDXGIAdapter );
    5.81 +				nAdapter++;
    5.82 +			}
    5.83 +			SDL_free(displayName);
    5.84 +		}
    5.85 +
    5.86 +		/* free up the D3D stuff we inited */
    5.87 +		IDXGIFactory_AddRef( pDXGIFactory );
    5.88 +		SDL_UnloadObject(pDXGIDLL);
    5.89 +	}
    5.90 +}
    5.91 +
    5.92  #endif /* SDL_VIDEO_DRIVER_WINDOWS */
    5.93  
    5.94  /* vim: set ts=4 sw=4 expandtab: */