comparison src/video/win32/SDL_win32video.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents
children 36d52b1f0504
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 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 /* WIN32 driver bootstrap functions */
39
40 static int
41 WIN_Available(void)
42 {
43 return (1);
44 }
45
46 static void
47 WIN_DeleteDevice(SDL_VideoDevice * device)
48 {
49 SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
50
51 SDL_UnregisterApp();
52 #if SDL_VIDEO_RENDER_D3D
53 if (data->d3d) {
54 IDirect3D9_Release(data->d3d);
55 FreeLibrary(data->d3dDLL);
56 }
57 #endif
58 SDL_free(device->driverdata);
59 SDL_free(device);
60 }
61
62 static SDL_VideoDevice *
63 WIN_CreateDevice(int devindex)
64 {
65 SDL_VideoDevice *device;
66 SDL_VideoData *data;
67
68 SDL_RegisterApp(NULL, 0, NULL);
69
70 /* Initialize all variables that we clean on shutdown */
71 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
72 if (device) {
73 data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
74 }
75 if (!device || !data) {
76 SDL_OutOfMemory();
77 if (device) {
78 SDL_free(device);
79 }
80 return NULL;
81 }
82 device->driverdata = data;
83
84 #if SDL_VIDEO_RENDER_D3D
85 data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
86 if (data->d3dDLL) {
87 IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
88
89 D3DCreate =
90 (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
91 "Direct3DCreate9");
92 if (D3DCreate) {
93 data->d3d = D3DCreate(D3D_SDK_VERSION);
94 }
95 if (!data->d3d) {
96 FreeLibrary(data->d3dDLL);
97 data->d3dDLL = NULL;
98 }
99 }
100 #endif /* SDL_VIDEO_RENDER_D3D */
101
102 /* Set the function pointers */
103 device->VideoInit = WIN_VideoInit;
104 device->GetDisplayModes = WIN_GetDisplayModes;
105 device->SetDisplayMode = WIN_SetDisplayMode;
106 device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
107 device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
108 device->VideoQuit = WIN_VideoQuit;
109 device->PumpEvents = WIN_PumpEvents;
110
111 #undef CreateWindow
112 device->CreateWindow = WIN_CreateWindow;
113 device->CreateWindowFrom = WIN_CreateWindowFrom;
114 device->SetWindowTitle = WIN_SetWindowTitle;
115 device->SetWindowPosition = WIN_SetWindowPosition;
116 device->SetWindowSize = WIN_SetWindowSize;
117 device->ShowWindow = WIN_ShowWindow;
118 device->HideWindow = WIN_HideWindow;
119 device->RaiseWindow = WIN_RaiseWindow;
120 device->MaximizeWindow = WIN_MaximizeWindow;
121 device->MinimizeWindow = WIN_MinimizeWindow;
122 device->RestoreWindow = WIN_RestoreWindow;
123 device->SetWindowGrab = WIN_SetWindowGrab;
124 device->DestroyWindow = WIN_DestroyWindow;
125 device->GetWindowWMInfo = WIN_GetWindowWMInfo;
126
127 device->free = WIN_DeleteDevice;
128
129 return device;
130 }
131
132 VideoBootStrap WIN32_bootstrap = {
133 "win32", "SDL Win32/64 video driver",
134 WIN_Available, WIN_CreateDevice
135 };
136
137
138 int
139 WIN_VideoInit(_THIS)
140 {
141 WIN_InitModes(_this);
142
143 #if SDL_VIDEO_RENDER_GDI
144 GDI_AddRenderDriver(_this);
145 #endif
146 #if SDL_VIDEO_RENDER_D3D
147 D3D_AddRenderDriver(_this);
148 #endif
149
150 WIN_InitKeyboard(_this);
151 WIN_InitMouse(_this);
152
153 return 0;
154 }
155
156 void
157 WIN_VideoQuit(_THIS)
158 {
159 WIN_QuitModes(_this);
160 WIN_QuitKeyboard(_this);
161 WIN_QuitMouse(_this);
162 }
163
164 /* vim: set ts=4 sw=4 expandtab: */