Added SDL_Direct3D9GetAdapterIndex(), which returns the adapter index you would pass into CreateDevice to get your device on the right monitor in full screen mode. This fixes the default adapter in SDL_render_d3d.c, which means that tests will work fullscreen off the main monitor now.
authorSam Lantinga <slouken@libsdl.org>
Fri, 13 Sep 2013 17:42:46 -0700
changeset 774284e32c3d415c
parent 7741 199d77d7bf1c
child 7743 360acf8c1526
Added SDL_Direct3D9GetAdapterIndex(), which returns the adapter index you would pass into CreateDevice to get your device on the right monitor in full screen mode. This fixes the default adapter in SDL_render_d3d.c, which means that tests will work fullscreen off the main monitor now.

CR: Sam
include/SDL_system.h
src/render/direct3d/SDL_render_d3d.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
     1.1 --- a/include/SDL_system.h	Fri Sep 13 17:42:38 2013 -0700
     1.2 +++ b/include/SDL_system.h	Fri Sep 13 17:42:46 2013 -0700
     1.3 @@ -41,6 +41,19 @@
     1.4  extern "C" {
     1.5  #endif
     1.6  
     1.7 +
     1.8 +/* Platform specific functions for Windows */
     1.9 +#ifdef __WIN32__
    1.10 +
    1.11 +/* Returns the D3D9 adapter index that matches the specified display index.
    1.12 +   This adapter index can be passed to IDirect3D9::CreateDevice and controls
    1.13 +   on which monitor a full screen application will appear.
    1.14 +*/
    1.15 +extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
    1.16 +
    1.17 +#endif /* __WIN32__ */
    1.18 +
    1.19 +
    1.20  /* Platform specific functions for iOS */
    1.21  #if defined(__IPHONEOS__) && __IPHONEOS__
    1.22  
    1.23 @@ -93,7 +106,6 @@
    1.24  
    1.25  #endif /* __ANDROID__ */
    1.26  
    1.27 -
    1.28  /* Ends C function definitions when using C++ */
    1.29  #ifdef __cplusplus
    1.30  }
     2.1 --- a/src/render/direct3d/SDL_render_d3d.c	Fri Sep 13 17:42:38 2013 -0700
     2.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Fri Sep 13 17:42:46 2013 -0700
     2.3 @@ -29,6 +29,8 @@
     2.4  #include "SDL_loadso.h"
     2.5  #include "SDL_syswm.h"
     2.6  #include "../SDL_sysrender.h"
     2.7 +#include "../../video/SDL_sysvideo.h"
     2.8 +#include "../../video/windows/SDL_windowsmodes.h"
     2.9  #include <stdio.h>
    2.10  
    2.11  #if SDL_VIDEO_RENDER_D3D
    2.12 @@ -531,6 +533,72 @@
    2.13      return 0;
    2.14  }
    2.15  
    2.16 +SDL_bool 
    2.17 +D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
    2.18 +{
    2.19 +	*pD3DDLL = SDL_LoadObject("D3D9.DLL");
    2.20 +	if (*pD3DDLL) {
    2.21 +		IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
    2.22 +
    2.23 +		D3DCreate =
    2.24 +			(IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
    2.25 +			"Direct3DCreate9");
    2.26 +		if (D3DCreate) {
    2.27 +			*pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
    2.28 +		}
    2.29 +		if (!*pDirect3D9Interface) {
    2.30 +			SDL_UnloadObject(*pD3DDLL);
    2.31 +			*pD3DDLL = NULL;
    2.32 +			return SDL_FALSE;
    2.33 +		}
    2.34 +
    2.35 +		return SDL_TRUE;
    2.36 +	} else {
    2.37 +		*pDirect3D9Interface = NULL;
    2.38 +		return SDL_FALSE;
    2.39 +	}
    2.40 +}
    2.41 +
    2.42 +
    2.43 +int 
    2.44 +SDL_Direct3D9GetAdapterIndex( int displayIndex )
    2.45 +{
    2.46 +	void *pD3DDLL;
    2.47 +	IDirect3D9 *pD3D;
    2.48 +	if (!D3D_LoadDLL( &pD3DDLL, &pD3D)) {
    2.49 +		SDL_SetError("Unable to create Direct3D interface");
    2.50 +		return D3DADAPTER_DEFAULT;
    2.51 +	} else {
    2.52 +		SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData( displayIndex );
    2.53 +		int adapterIndex = D3DADAPTER_DEFAULT;
    2.54 +
    2.55 +		if (!pData) {
    2.56 +			SDL_SetError( "Invalid display index" );
    2.57 +		} else {
    2.58 +			char *displayName = WIN_StringToUTF8( pData->DeviceName );
    2.59 +			unsigned int count = IDirect3D9_GetAdapterCount( pD3D );
    2.60 +			unsigned int i;
    2.61 +			for (i=0; i<count; i++) {
    2.62 +				D3DADAPTER_IDENTIFIER9 id;
    2.63 +				IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
    2.64 +
    2.65 +				if (SDL_strcmp(id.DeviceName, displayName) == 0) {
    2.66 +					adapterIndex = i;
    2.67 +					break;
    2.68 +				}
    2.69 +			}
    2.70 +			SDL_free( displayName );
    2.71 +		}
    2.72 +
    2.73 +		/* free up the D3D stuff we inited */
    2.74 +		IDirect3D9_Release(pD3D);
    2.75 +		SDL_UnloadObject(pD3DDLL);
    2.76 +
    2.77 +		return adapterIndex;
    2.78 +	}
    2.79 +}
    2.80 +
    2.81 +
    2.82  SDL_Renderer *
    2.83  D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
    2.84  {
    2.85 @@ -546,6 +614,7 @@
    2.86      SDL_DisplayMode fullscreen_mode;
    2.87      int d3dxVersion;
    2.88      char d3dxDLLFile[50];
    2.89 +	int displayIndex;
    2.90  
    2.91      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
    2.92      if (!renderer) {
    2.93 @@ -560,21 +629,7 @@
    2.94          return NULL;
    2.95      }
    2.96  
    2.97 -    data->d3dDLL = SDL_LoadObject("D3D9.DLL");
    2.98 -    if (data->d3dDLL) {
    2.99 -        IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
   2.100 -
   2.101 -        D3DCreate =
   2.102 -            (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL,
   2.103 -                                                            "Direct3DCreate9");
   2.104 -        if (D3DCreate) {
   2.105 -            data->d3d = D3DCreate(D3D_SDK_VERSION);
   2.106 -        }
   2.107 -        if (!data->d3d) {
   2.108 -            SDL_UnloadObject(data->d3dDLL);
   2.109 -            data->d3dDLL = NULL;
   2.110 -        }
   2.111 -
   2.112 +	if( D3D_LoadDLL( &data->d3dDLL, &data->d3d ) ) {
   2.113          for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) {
   2.114              LPTSTR dllName;
   2.115              SDL_snprintf(d3dxDLLFile, sizeof(d3dxDLLFile), "D3DX9_%02d.dll", d3dxVersion);
   2.116 @@ -667,8 +722,10 @@
   2.117          pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
   2.118      }
   2.119  
   2.120 -    /* FIXME: Which adapter? */
   2.121 -    data->adapter = D3DADAPTER_DEFAULT;
   2.122 +    /* Get the adapter for the display that the window is on */
   2.123 +	displayIndex = SDL_GetWindowDisplayIndex( window );
   2.124 +    data->adapter = SDL_Direct3D9GetAdapterIndex( displayIndex );
   2.125 +
   2.126      IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
   2.127  
   2.128      result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
     3.1 --- a/src/video/SDL_sysvideo.h	Fri Sep 13 17:42:38 2013 -0700
     3.2 +++ b/src/video/SDL_sysvideo.h	Fri Sep 13 17:42:46 2013 -0700
     3.3 @@ -371,6 +371,7 @@
     3.4  extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
     3.5  extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
     3.6  extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
     3.7 +extern void *SDL_GetDisplayDriverData( int displayIndex );
     3.8  
     3.9  extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
    3.10  
     4.1 --- a/src/video/SDL_video.c	Fri Sep 13 17:42:38 2013 -0700
     4.2 +++ b/src/video/SDL_video.c	Fri Sep 13 17:42:46 2013 -0700
     4.3 @@ -615,6 +615,14 @@
     4.4      return 0;
     4.5  }
     4.6  
     4.7 +void *
     4.8 +SDL_GetDisplayDriverData( int displayIndex )
     4.9 +{
    4.10 +	CHECK_DISPLAY_INDEX( displayIndex, NULL );
    4.11 +
    4.12 +	return _this->displays[displayIndex].driverdata;
    4.13 +}
    4.14 +
    4.15  const char *
    4.16  SDL_GetDisplayName(int displayIndex)
    4.17  {