Moved SDL_Direct3D9GetAdapterIndex() to SDL_windowsvideo.c since it doesn't belong in the window code.
authorSam Lantinga <slouken@libsdl.org>
Sat, 28 Sep 2013 14:06:59 -0700
changeset 776251abf7664304
parent 7761 bddbfca922cd
child 7763 fc802d707136
Moved SDL_Direct3D9GetAdapterIndex() to SDL_windowsvideo.c since it doesn't belong in the window code.
src/render/direct3d/SDL_render_d3d.c
src/video/windows/SDL_windowsvideo.c
src/video/windows/SDL_windowsvideo.h
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
     1.1 --- a/src/render/direct3d/SDL_render_d3d.c	Sat Sep 28 14:06:55 2013 -0700
     1.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Sat Sep 28 14:06:59 2013 -0700
     1.3 @@ -30,10 +30,7 @@
     1.4  #include "SDL_syswm.h"
     1.5  #include "SDL_system.h"
     1.6  #include "../SDL_sysrender.h"
     1.7 -#include <stdio.h>
     1.8 -
     1.9 -#include "../../video/SDL_sysvideo.h"
    1.10 -#include "../../video/windows/SDL_windowswindow.h"
    1.11 +#include "../../video/windows/SDL_windowsvideo.h"
    1.12  
    1.13  #if SDL_VIDEO_RENDER_D3D
    1.14  #define D3D_DEBUG_INFO
     2.1 --- a/src/video/windows/SDL_windowsvideo.c	Sat Sep 28 14:06:55 2013 -0700
     2.2 +++ b/src/video/windows/SDL_windowsvideo.c	Sat Sep 28 14:06:59 2013 -0700
     2.3 @@ -25,6 +25,7 @@
     2.4  #include "SDL_main.h"
     2.5  #include "SDL_video.h"
     2.6  #include "SDL_mouse.h"
     2.7 +#include "SDL_system.h"
     2.8  #include "../SDL_sysvideo.h"
     2.9  #include "../SDL_pixels_c.h"
    2.10  
    2.11 @@ -174,6 +175,76 @@
    2.12      WIN_QuitMouse(_this);
    2.13  }
    2.14  
    2.15 +
    2.16 +#define D3D_DEBUG_INFO
    2.17 +#include <d3d9.h>
    2.18 +
    2.19 +SDL_bool 
    2.20 +D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
    2.21 +{
    2.22 +	*pD3DDLL = SDL_LoadObject("D3D9.DLL");
    2.23 +	if (*pD3DDLL) {
    2.24 +		IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
    2.25 +
    2.26 +		D3DCreate =
    2.27 +			(IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
    2.28 +			"Direct3DCreate9");
    2.29 +		if (D3DCreate) {
    2.30 +			*pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
    2.31 +		}
    2.32 +		if (!*pDirect3D9Interface) {
    2.33 +			SDL_UnloadObject(*pD3DDLL);
    2.34 +			*pD3DDLL = NULL;
    2.35 +			return SDL_FALSE;
    2.36 +		}
    2.37 +
    2.38 +		return SDL_TRUE;
    2.39 +	} else {
    2.40 +		*pDirect3D9Interface = NULL;
    2.41 +		return SDL_FALSE;
    2.42 +	}
    2.43 +}
    2.44 +
    2.45 +
    2.46 +int
    2.47 +SDL_Direct3D9GetAdapterIndex( int displayIndex )
    2.48 +{
    2.49 +	void *pD3DDLL;
    2.50 +	IDirect3D9 *pD3D;
    2.51 +	if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
    2.52 +		SDL_SetError("Unable to create Direct3D interface");
    2.53 +		return D3DADAPTER_DEFAULT;
    2.54 +	} else {
    2.55 +		SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
    2.56 +		int adapterIndex = D3DADAPTER_DEFAULT;
    2.57 +
    2.58 +		if (!pData) {
    2.59 +			SDL_SetError("Invalid display index");
    2.60 +			adapterIndex = -1; /* make sure we return something invalid */
    2.61 +		} else {
    2.62 +			char *displayName = WIN_StringToUTF8(pData->DeviceName);
    2.63 +			unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
    2.64 +			unsigned int i;
    2.65 +			for (i=0; i<count; i++) {
    2.66 +				D3DADAPTER_IDENTIFIER9 id;
    2.67 +				IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
    2.68 +
    2.69 +				if (SDL_strcmp(id.DeviceName, displayName) == 0) {
    2.70 +					adapterIndex = i;
    2.71 +					break;
    2.72 +				}
    2.73 +			}
    2.74 +			SDL_free(displayName);
    2.75 +		}
    2.76 +
    2.77 +		/* free up the D3D stuff we inited */
    2.78 +		IDirect3D9_Release(pD3D);
    2.79 +		SDL_UnloadObject(pD3DDLL);
    2.80 +
    2.81 +		return adapterIndex;
    2.82 +	}
    2.83 +}
    2.84 +
    2.85  #endif /* SDL_VIDEO_DRIVER_WINDOWS */
    2.86  
    2.87  /* vim: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/video/windows/SDL_windowsvideo.h	Sat Sep 28 14:06:55 2013 -0700
     3.2 +++ b/src/video/windows/SDL_windowsvideo.h	Sat Sep 28 14:06:59 2013 -0700
     3.3 @@ -170,6 +170,10 @@
     3.4      TSFSink *ime_ippasink;
     3.5  } SDL_VideoData;
     3.6  
     3.7 +
     3.8 +typedef struct IDirect3D9 IDirect3D9;
     3.9 +extern SDL_bool D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface );
    3.10 +
    3.11  #endif /* _SDL_windowsvideo_h */
    3.12  
    3.13  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/windows/SDL_windowswindow.c	Sat Sep 28 14:06:55 2013 -0700
     4.2 +++ b/src/video/windows/SDL_windowswindow.c	Sat Sep 28 14:06:59 2013 -0700
     4.3 @@ -22,15 +22,10 @@
     4.4  
     4.5  #if SDL_VIDEO_DRIVER_WINDOWS
     4.6  
     4.7 -#include "../../core/windows/SDL_windows.h"
     4.8 -
     4.9  #include "SDL_assert.h"
    4.10 -#include "SDL_system.h"
    4.11  #include "../SDL_sysvideo.h"
    4.12  #include "../SDL_pixels_c.h"
    4.13  #include "../../events/SDL_keyboard_c.h"
    4.14 -#include "../../video/SDL_sysvideo.h"
    4.15 -#include "../../video/windows/SDL_windowsmodes.h"
    4.16  
    4.17  #include "SDL_windowsvideo.h"
    4.18  #include "SDL_windowswindow.h"
    4.19 @@ -41,9 +36,6 @@
    4.20  /* This is included after SDL_windowsvideo.h, which includes windows.h */
    4.21  #include "SDL_syswm.h"
    4.22  
    4.23 -#define D3D_DEBUG_INFO
    4.24 -#include <d3d9.h>
    4.25 -
    4.26  /* Windows CE compatibility */
    4.27  #ifndef SWP_NOCOPYBITS
    4.28  #define SWP_NOCOPYBITS 0
    4.29 @@ -691,74 +683,6 @@
    4.30  #endif /* WM_MOUSELEAVE */
    4.31  }
    4.32  
    4.33 -SDL_bool 
    4.34 -D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
    4.35 -{
    4.36 -	*pD3DDLL = SDL_LoadObject("D3D9.DLL");
    4.37 -	if (*pD3DDLL) {
    4.38 -		IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
    4.39 -
    4.40 -		D3DCreate =
    4.41 -			(IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
    4.42 -			"Direct3DCreate9");
    4.43 -		if (D3DCreate) {
    4.44 -			*pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
    4.45 -		}
    4.46 -		if (!*pDirect3D9Interface) {
    4.47 -			SDL_UnloadObject(*pD3DDLL);
    4.48 -			*pD3DDLL = NULL;
    4.49 -			return SDL_FALSE;
    4.50 -		}
    4.51 -
    4.52 -		return SDL_TRUE;
    4.53 -	} else {
    4.54 -		*pDirect3D9Interface = NULL;
    4.55 -		return SDL_FALSE;
    4.56 -	}
    4.57 -}
    4.58 -
    4.59 -
    4.60 -int 
    4.61 -SDL_Direct3D9GetAdapterIndex( int displayIndex )
    4.62 -{
    4.63 -	void *pD3DDLL;
    4.64 -	IDirect3D9 *pD3D;
    4.65 -	if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
    4.66 -		SDL_SetError("Unable to create Direct3D interface");
    4.67 -		return D3DADAPTER_DEFAULT;
    4.68 -	} else {
    4.69 -		SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
    4.70 -		int adapterIndex = D3DADAPTER_DEFAULT;
    4.71 -
    4.72 -		if (!pData) {
    4.73 -			SDL_SetError("Invalid display index");
    4.74 -			adapterIndex = -1; /* make sure we return something invalid */
    4.75 -		} else {
    4.76 -			char *displayName = WIN_StringToUTF8(pData->DeviceName);
    4.77 -			unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
    4.78 -			unsigned int i;
    4.79 -			for (i=0; i<count; i++) {
    4.80 -				D3DADAPTER_IDENTIFIER9 id;
    4.81 -				IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
    4.82 -
    4.83 -				if (SDL_strcmp(id.DeviceName, displayName) == 0) {
    4.84 -					adapterIndex = i;
    4.85 -					break;
    4.86 -				}
    4.87 -			}
    4.88 -			SDL_free(displayName);
    4.89 -		}
    4.90 -
    4.91 -		/* free up the D3D stuff we inited */
    4.92 -		IDirect3D9_Release(pD3D);
    4.93 -		SDL_UnloadObject(pD3DDLL);
    4.94 -
    4.95 -		return adapterIndex;
    4.96 -	}
    4.97 -}
    4.98 -
    4.99 -
   4.100 -
   4.101  #endif /* SDL_VIDEO_DRIVER_WINDOWS */
   4.102  
   4.103  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/video/windows/SDL_windowswindow.h	Sat Sep 28 14:06:55 2013 -0700
     5.2 +++ b/src/video/windows/SDL_windowswindow.h	Sat Sep 28 14:06:59 2013 -0700
     5.3 @@ -36,8 +36,6 @@
     5.4      struct SDL_VideoData *videodata;
     5.5  } SDL_WindowData;
     5.6  
     5.7 -typedef struct IDirect3D9 IDirect3D9;
     5.8 -
     5.9  extern int WIN_CreateWindow(_THIS, SDL_Window * window);
    5.10  extern int WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
    5.11  extern void WIN_SetWindowTitle(_THIS, SDL_Window * window);
    5.12 @@ -59,7 +57,6 @@
    5.13  extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
    5.14                                      struct SDL_SysWMinfo *info);
    5.15  extern void WIN_OnWindowEnter(_THIS, SDL_Window * window);
    5.16 -extern SDL_bool D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface );
    5.17  
    5.18  #endif /* _SDL_windowswindow_h */
    5.19