comparison src/video/windows/SDL_windowsvideo.c @ 5062:e8916fe9cfc8

Fixed bug #925 Changed "win32" to "windows"
author Sam Lantinga <slouken@libsdl.org>
date Thu, 20 Jan 2011 18:04:05 -0800
parents src/video/win32/SDL_win32video.c@716b2cbf4c9e
children c2539ff054c8
comparison
equal deleted inserted replaced
5061:9e9940eae455 5062:e8916fe9cfc8
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_windowsvideo.h"
31 #include "SDL_windowsshape.h"
32 #include "SDL_d3drender.h"
33 #include "SDL_gdirender.h"
34 #include "SDL_gapirender.h"
35
36 /* Initialization/Query functions */
37 static int WIN_VideoInit(_THIS);
38 static void WIN_VideoQuit(_THIS);
39
40 /* Sets an error message based on GetLastError() */
41 void
42 WIN_SetError(const char *prefix)
43 {
44 TCHAR buffer[1024];
45 char *message;
46 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
47 buffer, SDL_arraysize(buffer), NULL);
48 message = WIN_StringToUTF8(buffer);
49 SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message);
50 SDL_free(message);
51 }
52
53
54 /* Windows driver bootstrap functions */
55
56 static int
57 WIN_Available(void)
58 {
59 return (1);
60 }
61
62 static void
63 WIN_DeleteDevice(SDL_VideoDevice * device)
64 {
65 SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
66
67 SDL_UnregisterApp();
68 #if SDL_VIDEO_RENDER_D3D
69 if (data->d3d) {
70 IDirect3D9_Release(data->d3d);
71 FreeLibrary(data->d3dDLL);
72 }
73 #endif
74 #if SDL_VIDEO_RENDER_DDRAW
75 if (data->ddraw) {
76 data->ddraw->lpVtbl->Release(data->ddraw);
77 FreeLibrary(data->ddrawDLL);
78 }
79 #endif
80 #ifdef _WIN32_WCE
81 if(data->hAygShell) {
82 FreeLibrary(data->hAygShell);
83 }
84 #endif
85 if (data->userDLL) {
86 FreeLibrary(data->userDLL);
87 }
88
89 SDL_free(device->driverdata);
90 SDL_free(device);
91 }
92
93 static SDL_VideoDevice *
94 WIN_CreateDevice(int devindex)
95 {
96 SDL_VideoDevice *device;
97 SDL_VideoData *data;
98
99 SDL_RegisterApp(NULL, 0, NULL);
100
101 /* Initialize all variables that we clean on shutdown */
102 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
103 if (device) {
104 data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
105 } else {
106 data = NULL;
107 }
108 if (!data) {
109 SDL_OutOfMemory();
110 if (device) {
111 SDL_free(device);
112 }
113 return NULL;
114 }
115 device->driverdata = data;
116
117 #if SDL_VIDEO_RENDER_D3D
118 data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
119 if (data->d3dDLL) {
120 IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
121
122 D3DCreate =
123 (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
124 "Direct3DCreate9");
125 if (D3DCreate) {
126 data->d3d = D3DCreate(D3D_SDK_VERSION);
127 }
128 if (!data->d3d) {
129 FreeLibrary(data->d3dDLL);
130 data->d3dDLL = NULL;
131 }
132 }
133 #endif /* SDL_VIDEO_RENDER_D3D */
134 #if SDL_VIDEO_RENDER_DDRAW
135 data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll"));
136 if (data->ddrawDLL) {
137 IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID,
138 LPDIRECTDRAW FAR * lplpDD,
139 IUnknown FAR * pUnkOuter);
140
141 DDCreate =
142 (IDirectDraw *
143 (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *))
144 GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate"));
145 if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) {
146 FreeLibrary(data->ddrawDLL);
147 data->ddrawDLL = NULL;
148 data->ddraw = NULL;
149 }
150 }
151 #endif /* SDL_VIDEO_RENDER_DDRAW */
152
153 #ifdef _WIN32_WCE
154 data->hAygShell = LoadLibrary(TEXT("\\windows\\aygshell.dll"));
155 if(0 == data->hAygShell)
156 data->hAygShell = LoadLibrary(TEXT("aygshell.dll"));
157 data->SHFullScreen = (0 != data->hAygShell ?
158 (PFNSHFullScreen) GetProcAddress(data->hAygShell, TEXT("SHFullScreen")) : 0);
159 data->CoordTransform = NULL;
160 #endif
161
162 data->userDLL = LoadLibrary(TEXT("USER32.DLL"));
163 if (data->userDLL) {
164 data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(data->userDLL, "CloseTouchInputHandle");
165 data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(data->userDLL, "GetTouchInputInfo");
166 data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(data->userDLL, "RegisterTouchWindow");
167 }
168
169 /* Set the function pointers */
170 device->VideoInit = WIN_VideoInit;
171 device->VideoQuit = WIN_VideoQuit;
172 device->GetDisplayBounds = WIN_GetDisplayBounds;
173 device->GetDisplayModes = WIN_GetDisplayModes;
174 device->SetDisplayMode = WIN_SetDisplayMode;
175 device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
176 device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
177 device->PumpEvents = WIN_PumpEvents;
178
179 #undef CreateWindow
180 device->CreateWindow = WIN_CreateWindow;
181 device->CreateWindowFrom = WIN_CreateWindowFrom;
182 device->SetWindowTitle = WIN_SetWindowTitle;
183 device->SetWindowIcon = WIN_SetWindowIcon;
184 device->SetWindowPosition = WIN_SetWindowPosition;
185 device->SetWindowSize = WIN_SetWindowSize;
186 device->ShowWindow = WIN_ShowWindow;
187 device->HideWindow = WIN_HideWindow;
188 device->RaiseWindow = WIN_RaiseWindow;
189 device->MaximizeWindow = WIN_MaximizeWindow;
190 device->MinimizeWindow = WIN_MinimizeWindow;
191 device->RestoreWindow = WIN_RestoreWindow;
192 device->SetWindowGrab = WIN_SetWindowGrab;
193 device->DestroyWindow = WIN_DestroyWindow;
194 device->GetWindowWMInfo = WIN_GetWindowWMInfo;
195
196 device->shape_driver.CreateShaper = Win32_CreateShaper;
197 device->shape_driver.SetWindowShape = Win32_SetWindowShape;
198 device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
199
200 #ifdef SDL_VIDEO_OPENGL_WGL
201 device->GL_LoadLibrary = WIN_GL_LoadLibrary;
202 device->GL_GetProcAddress = WIN_GL_GetProcAddress;
203 device->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
204 device->GL_CreateContext = WIN_GL_CreateContext;
205 device->GL_MakeCurrent = WIN_GL_MakeCurrent;
206 device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
207 device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
208 device->GL_SwapWindow = WIN_GL_SwapWindow;
209 device->GL_DeleteContext = WIN_GL_DeleteContext;
210 #endif
211 device->StartTextInput = WIN_StartTextInput;
212 device->StopTextInput = WIN_StopTextInput;
213 device->SetTextInputRect = WIN_SetTextInputRect;
214
215 device->SetClipboardText = WIN_SetClipboardText;
216 device->GetClipboardText = WIN_GetClipboardText;
217 device->HasClipboardText = WIN_HasClipboardText;
218
219 device->free = WIN_DeleteDevice;
220
221 return device;
222 }
223
224 VideoBootStrap WINDOWS_bootstrap = {
225 #ifdef _WIN32_WCE
226 "wince", "SDL WinCE video driver", WINCE_Available, WIN_CreateDevice
227 #else
228 "windows", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice
229 #endif
230 };
231
232 int
233 WIN_VideoInit(_THIS)
234 {
235 if (WIN_InitModes(_this) < 0) {
236 return -1;
237 }
238
239 #if SDL_VIDEO_RENDER_D3D
240 D3D_AddRenderDriver(_this);
241 #endif
242 #if SDL_VIDEO_RENDER_DDRAW
243 DDRAW_AddRenderDriver(_this);
244 #endif
245 #if SDL_VIDEO_RENDER_GDI
246 GDI_AddRenderDriver(_this);
247 #endif
248 #if SDL_VIDEO_RENDER_GAPI
249 WINCE_AddRenderDriver(_this);
250 #endif
251
252 WIN_InitKeyboard(_this);
253 WIN_InitMouse(_this);
254
255 return 0;
256 }
257
258 void
259 WIN_VideoQuit(_THIS)
260 {
261 WIN_QuitModes(_this);
262 WIN_QuitKeyboard(_this);
263 WIN_QuitMouse(_this);
264 }
265
266 /* vim: set ts=4 sw=4 expandtab: */