4755
|
1 /*
|
|
2 SDL - Simple DirectMedia Layer
|
|
3 Copyright (C) 1997-2010 Sam Lantinga
|
|
4
|
|
5 This library is free software; you can redistribute it and/or
|
|
6 modify it under the terms of the GNU Lesser General Public
|
|
7 License as published by the Free Software Foundation; either
|
|
8 version 2.1 of the License, or (at your option) any later version.
|
|
9
|
|
10 This library is distributed in the hope that it will be useful,
|
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 Lesser General Public License for more details.
|
|
14
|
|
15 You should have received a copy of the GNU Lesser General Public
|
|
16 License along with this library; if not, write to the Free Software
|
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18
|
|
19 Sam Lantinga
|
|
20 slouken@libsdl.org
|
|
21 */
|
|
22 #include "SDL_config.h"
|
|
23
|
|
24 #include "SDL_main.h"
|
|
25 #include "SDL_video.h"
|
|
26 #include "SDL_mouse.h"
|
|
27 #include "../SDL_sysvideo.h"
|
|
28 #include "../SDL_pixels_c.h"
|
|
29
|
|
30 #include "SDL_win32video.h"
|
|
31 #include "SDL_d3drender.h"
|
|
32 #include "SDL_gdirender.h"
|
|
33
|
|
34 /* Initialization/Query functions */
|
|
35 static int WIN_VideoInit(_THIS);
|
|
36 static void WIN_VideoQuit(_THIS);
|
|
37
|
|
38 /* Sets an error message based on GetLastError() */
|
|
39 void
|
|
40 WIN_SetError(const char *prefix)
|
|
41 {
|
|
42 TCHAR buffer[1024];
|
|
43 char *message;
|
|
44 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
|
|
45 buffer, SDL_arraysize(buffer), NULL);
|
|
46 message = WIN_StringToUTF8(buffer);
|
|
47 SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message);
|
|
48 SDL_free(message);
|
|
49 }
|
|
50
|
|
51 /* WIN32 driver bootstrap functions */
|
|
52
|
|
53 static int
|
|
54 WIN_Available(void)
|
|
55 {
|
|
56 return (1);
|
|
57 }
|
|
58
|
|
59 static void
|
|
60 WIN_DeleteDevice(SDL_VideoDevice * device)
|
|
61 {
|
|
62 SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
|
|
63
|
|
64 SDL_UnregisterApp();
|
|
65 #if SDL_VIDEO_RENDER_D3D
|
|
66 if (data->d3d) {
|
|
67 IDirect3D9_Release(data->d3d);
|
|
68 FreeLibrary(data->d3dDLL);
|
|
69 }
|
|
70 #endif
|
|
71 #if SDL_VIDEO_RENDER_DDRAW
|
|
72 if (data->ddraw) {
|
|
73 data->ddraw->lpVtbl->Release(data->ddraw);
|
|
74 FreeLibrary(data->ddrawDLL);
|
|
75 }
|
|
76 #endif
|
|
77 SDL_free(device->driverdata);
|
|
78 SDL_free(device);
|
|
79 }
|
|
80
|
|
81 static SDL_VideoDevice *
|
|
82 WIN_CreateDevice(int devindex)
|
|
83 {
|
|
84 SDL_VideoDevice *device;
|
|
85 SDL_VideoData *data;
|
|
86
|
|
87 SDL_RegisterApp(NULL, 0, NULL);
|
|
88
|
|
89 /* Initialize all variables that we clean on shutdown */
|
|
90 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
|
91 if (device) {
|
|
92 data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
|
|
93 } else {
|
|
94 data = NULL;
|
|
95 }
|
|
96 if (!data) {
|
|
97 SDL_OutOfMemory();
|
|
98 if (device) {
|
|
99 SDL_free(device);
|
|
100 }
|
|
101 return NULL;
|
|
102 }
|
|
103 device->driverdata = data;
|
|
104
|
|
105 #if SDL_VIDEO_RENDER_D3D
|
|
106 data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
|
|
107 if (data->d3dDLL) {
|
|
108 IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
|
|
109
|
|
110 D3DCreate =
|
|
111 (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
|
|
112 "Direct3DCreate9");
|
|
113 if (D3DCreate) {
|
|
114 data->d3d = D3DCreate(D3D_SDK_VERSION);
|
|
115 }
|
|
116 if (!data->d3d) {
|
|
117 FreeLibrary(data->d3dDLL);
|
|
118 data->d3dDLL = NULL;
|
|
119 }
|
|
120 }
|
|
121 #endif /* SDL_VIDEO_RENDER_D3D */
|
|
122 #if SDL_VIDEO_RENDER_DDRAW
|
|
123 data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll"));
|
|
124 if (data->ddrawDLL) {
|
|
125 IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID,
|
|
126 LPDIRECTDRAW FAR * lplpDD,
|
|
127 IUnknown FAR * pUnkOuter);
|
|
128
|
|
129 DDCreate =
|
|
130 (IDirectDraw *
|
|
131 (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *))
|
|
132 GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate"));
|
|
133 if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) {
|
|
134 FreeLibrary(data->ddrawDLL);
|
|
135 data->ddrawDLL = NULL;
|
|
136 data->ddraw = NULL;
|
|
137 }
|
|
138 }
|
|
139 #endif /* SDL_VIDEO_RENDER_DDRAW */
|
|
140
|
|
141 /* Set the function pointers */
|
|
142 device->VideoInit = WIN_VideoInit;
|
|
143 device->VideoQuit = WIN_VideoQuit;
|
|
144 device->GetDisplayBounds = WIN_GetDisplayBounds;
|
|
145 device->GetDisplayModes = WIN_GetDisplayModes;
|
|
146 device->SetDisplayMode = WIN_SetDisplayMode;
|
|
147 device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
|
|
148 device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
|
|
149 device->PumpEvents = WIN_PumpEvents;
|
|
150
|
|
151 #undef CreateWindow
|
|
152 device->CreateWindow = WIN_CreateWindow;
|
|
153 device->CreateWindowFrom = WIN_CreateWindowFrom;
|
|
154 device->SetWindowTitle = WIN_SetWindowTitle;
|
|
155 device->SetWindowIcon = WIN_SetWindowIcon;
|
|
156 device->SetWindowPosition = WIN_SetWindowPosition;
|
|
157 device->SetWindowSize = WIN_SetWindowSize;
|
|
158 device->ShowWindow = WIN_ShowWindow;
|
|
159 device->HideWindow = WIN_HideWindow;
|
|
160 device->RaiseWindow = WIN_RaiseWindow;
|
|
161 device->MaximizeWindow = WIN_MaximizeWindow;
|
|
162 device->MinimizeWindow = WIN_MinimizeWindow;
|
|
163 device->RestoreWindow = WIN_RestoreWindow;
|
|
164 device->SetWindowGrab = WIN_SetWindowGrab;
|
|
165 device->DestroyWindow = WIN_DestroyWindow;
|
|
166 device->GetWindowWMInfo = WIN_GetWindowWMInfo;
|
|
167 #ifdef SDL_VIDEO_OPENGL_WGL
|
|
168 device->GL_LoadLibrary = WIN_GL_LoadLibrary;
|
|
169 device->GL_GetProcAddress = WIN_GL_GetProcAddress;
|
|
170 device->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
|
|
171 device->GL_CreateContext = WIN_GL_CreateContext;
|
|
172 device->GL_MakeCurrent = WIN_GL_MakeCurrent;
|
|
173 device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
|
|
174 device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
|
|
175 device->GL_SwapWindow = WIN_GL_SwapWindow;
|
|
176 device->GL_DeleteContext = WIN_GL_DeleteContext;
|
|
177 #endif
|
|
178 device->StartTextInput = WIN_StartTextInput;
|
|
179 device->StopTextInput = WIN_StopTextInput;
|
|
180 device->SetTextInputRect = WIN_SetTextInputRect;
|
|
181
|
|
182 device->SetClipboardText = WIN_SetClipboardText;
|
|
183 device->GetClipboardText = WIN_GetClipboardText;
|
|
184 device->HasClipboardText = WIN_HasClipboardText;
|
|
185
|
|
186 device->free = WIN_DeleteDevice;
|
|
187
|
|
188 return device;
|
|
189 }
|
|
190
|
|
191 VideoBootStrap WIN32_bootstrap = {
|
|
192 "win32", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice
|
|
193 };
|
|
194
|
|
195
|
|
196 int
|
|
197 WIN_VideoInit(_THIS)
|
|
198 {
|
|
199 if (WIN_InitModes(_this) < 0) {
|
|
200 return -1;
|
|
201 }
|
|
202
|
|
203 #if SDL_VIDEO_RENDER_D3D
|
|
204 D3D_AddRenderDriver(_this);
|
|
205 #endif
|
|
206 #if SDL_VIDEO_RENDER_DDRAW
|
|
207 DDRAW_AddRenderDriver(_this);
|
|
208 #endif
|
|
209 #if SDL_VIDEO_RENDER_GDI
|
|
210 GDI_AddRenderDriver(_this);
|
|
211 #endif
|
|
212 #if SDL_VIDEO_RENDER_GAPI
|
|
213 GAPI_AddRenderDriver(_this);
|
|
214 #endif
|
|
215
|
|
216 WIN_InitKeyboard(_this);
|
|
217 WIN_InitMouse(_this);
|
|
218
|
|
219 return 0;
|
|
220 }
|
|
221
|
|
222 void
|
|
223 WIN_VideoQuit(_THIS)
|
|
224 {
|
|
225 WIN_QuitModes(_this);
|
|
226 WIN_QuitKeyboard(_this);
|
|
227 WIN_QuitMouse(_this);
|
|
228 }
|
|
229
|
|
230 /* vim: set ts=4 sw=4 expandtab: */
|