Moved D3D_LoadDLL and SDL_Direct3D9GetAdapterIndex to SDL_windowswindow.c at Jorgen's insistence. That file is wrapped in a more appropriate define check so it will work if somebody builds a binary without D3D support. Added a reference to SDL_Direct3D9GetAdapterIndex to SDL_test_common.c so SDL will fail to compile if the new symbol isn't included properly. CR: Jorgen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index d99057e..0248b21 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -28,11 +28,13 @@
#include "SDL_hints.h"
#include "SDL_loadso.h"
#include "SDL_syswm.h"
+#include "SDL_system.h"
#include "../SDL_sysrender.h"
-#include "../../video/SDL_sysvideo.h"
-#include "../../video/windows/SDL_windowsmodes.h"
#include <stdio.h>
+#include "../../video/SDL_sysvideo.h"
+#include "../../video/windows/SDL_windowswindow.h"
+
#if SDL_VIDEO_RENDER_D3D
#define D3D_DEBUG_INFO
#include <d3d9.h>
@@ -533,72 +535,6 @@ D3D_ActivateRenderer(SDL_Renderer * renderer)
return 0;
}
-SDL_bool
-D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
-{
- *pD3DDLL = SDL_LoadObject("D3D9.DLL");
- if (*pD3DDLL) {
- IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
-
- D3DCreate =
- (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
- "Direct3DCreate9");
- if (D3DCreate) {
- *pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
- }
- if (!*pDirect3D9Interface) {
- SDL_UnloadObject(*pD3DDLL);
- *pD3DDLL = NULL;
- return SDL_FALSE;
- }
-
- return SDL_TRUE;
- } else {
- *pDirect3D9Interface = NULL;
- return SDL_FALSE;
- }
-}
-
-
-int
-SDL_Direct3D9GetAdapterIndex( int displayIndex )
-{
- void *pD3DDLL;
- IDirect3D9 *pD3D;
- if (!D3D_LoadDLL( &pD3DDLL, &pD3D)) {
- SDL_SetError("Unable to create Direct3D interface");
- return D3DADAPTER_DEFAULT;
- } else {
- SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData( displayIndex );
- int adapterIndex = D3DADAPTER_DEFAULT;
-
- if (!pData) {
- SDL_SetError( "Invalid display index" );
- } else {
- char *displayName = WIN_StringToUTF8( pData->DeviceName );
- unsigned int count = IDirect3D9_GetAdapterCount( pD3D );
- unsigned int i;
- for (i=0; i<count; i++) {
- D3DADAPTER_IDENTIFIER9 id;
- IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
-
- if (SDL_strcmp(id.DeviceName, displayName) == 0) {
- adapterIndex = i;
- break;
- }
- }
- SDL_free( displayName );
- }
-
- /* free up the D3D stuff we inited */
- IDirect3D9_Release(pD3D);
- SDL_UnloadObject(pD3DDLL);
-
- return adapterIndex;
- }
-}
-
-
SDL_Renderer *
D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
{
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index e0ff376..05d72a2 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -701,7 +701,9 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
SDL_DisplayMode mode;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
-
+#if SDL_VIDEO_DRIVER_WINDOWS
+ int adapterIndex = 0;
+#endif
n = SDL_GetNumVideoDisplays();
fprintf(stderr, "Number of displays: %d\n", n);
for (i = 0; i < n; ++i) {
@@ -754,6 +756,12 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
}
}
}
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+ /* Print the adapter index */
+ adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
+ fprintf( stderr, "Adapter Index: %d", adapterIndex );
+#endif
}
}
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index c28da52..f7e1b37 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -22,10 +22,15 @@
#if SDL_VIDEO_DRIVER_WINDOWS
+#include "../../core/windows/SDL_windows.h"
+
#include "SDL_assert.h"
+#include "SDL_system.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_keyboard_c.h"
+#include "../../video/SDL_sysvideo.h"
+#include "../../video/windows/SDL_windowsmodes.h"
#include "SDL_windowsvideo.h"
#include "SDL_windowswindow.h"
@@ -36,6 +41,9 @@
/* This is included after SDL_windowsvideo.h, which includes windows.h */
#include "SDL_syswm.h"
+#define D3D_DEBUG_INFO
+#include <d3d9.h>
+
/* Windows CE compatibility */
#ifndef SWP_NOCOPYBITS
#define SWP_NOCOPYBITS 0
@@ -683,6 +691,74 @@ void WIN_OnWindowEnter(_THIS, SDL_Window * window)
#endif /* WM_MOUSELEAVE */
}
+SDL_bool
+D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
+{
+ *pD3DDLL = SDL_LoadObject("D3D9.DLL");
+ if (*pD3DDLL) {
+ IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
+
+ D3DCreate =
+ (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
+ "Direct3DCreate9");
+ if (D3DCreate) {
+ *pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
+ }
+ if (!*pDirect3D9Interface) {
+ SDL_UnloadObject(*pD3DDLL);
+ *pD3DDLL = NULL;
+ return SDL_FALSE;
+ }
+
+ return SDL_TRUE;
+ } else {
+ *pDirect3D9Interface = NULL;
+ return SDL_FALSE;
+ }
+}
+
+
+int
+SDL_Direct3D9GetAdapterIndex( int displayIndex )
+{
+ void *pD3DDLL;
+ IDirect3D9 *pD3D;
+ if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
+ SDL_SetError("Unable to create Direct3D interface");
+ return D3DADAPTER_DEFAULT;
+ } else {
+ SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
+ int adapterIndex = D3DADAPTER_DEFAULT;
+
+ if (!pData) {
+ SDL_SetError("Invalid display index");
+ adapterIndex = -1; /* make sure we return something invalid */
+ } else {
+ char *displayName = WIN_StringToUTF8(pData->DeviceName);
+ unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
+ unsigned int i;
+ for (i=0; i<count; i++) {
+ D3DADAPTER_IDENTIFIER9 id;
+ IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
+
+ if (SDL_strcmp(id.DeviceName, displayName) == 0) {
+ adapterIndex = i;
+ break;
+ }
+ }
+ SDL_free(displayName);
+ }
+
+ /* free up the D3D stuff we inited */
+ IDirect3D9_Release(pD3D);
+ SDL_UnloadObject(pD3DDLL);
+
+ return adapterIndex;
+ }
+}
+
+
+
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h
index e85c201..08e6186 100644
--- a/src/video/windows/SDL_windowswindow.h
+++ b/src/video/windows/SDL_windowswindow.h
@@ -36,6 +36,8 @@ typedef struct
struct SDL_VideoData *videodata;
} SDL_WindowData;
+typedef struct IDirect3D9 IDirect3D9;
+
extern int WIN_CreateWindow(_THIS, SDL_Window * window);
extern int WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
extern void WIN_SetWindowTitle(_THIS, SDL_Window * window);
@@ -57,6 +59,7 @@ extern void WIN_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);
extern void WIN_OnWindowEnter(_THIS, SDL_Window * window);
+extern SDL_bool D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface );
#endif /* _SDL_windowswindow_h */