dludwig@8327
|
1 |
/*
|
dludwig@8327
|
2 |
Simple DirectMedia Layer
|
dludwig@8327
|
3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
dludwig@8327
|
4 |
|
dludwig@8327
|
5 |
This software is provided 'as-is', without any express or implied
|
dludwig@8327
|
6 |
warranty. In no event will the authors be held liable for any damages
|
dludwig@8327
|
7 |
arising from the use of this software.
|
dludwig@8327
|
8 |
|
dludwig@8327
|
9 |
Permission is granted to anyone to use this software for any purpose,
|
dludwig@8327
|
10 |
including commercial applications, and to alter it and redistribute it
|
dludwig@8327
|
11 |
freely, subject to the following restrictions:
|
dludwig@8327
|
12 |
|
dludwig@8327
|
13 |
1. The origin of this software must not be misrepresented; you must not
|
dludwig@8327
|
14 |
claim that you wrote the original software. If you use this software
|
dludwig@8327
|
15 |
in a product, an acknowledgment in the product documentation would be
|
dludwig@8327
|
16 |
appreciated but is not required.
|
dludwig@8327
|
17 |
2. Altered source versions must be plainly marked as such, and must not be
|
dludwig@8327
|
18 |
misrepresented as being the original software.
|
dludwig@8327
|
19 |
3. This notice may not be removed or altered from any source distribution.
|
dludwig@8327
|
20 |
*/
|
dludwig@8327
|
21 |
#include "SDL_config.h"
|
dludwig@8327
|
22 |
|
dludwig@8327
|
23 |
#if SDL_VIDEO_DRIVER_WINRT
|
dludwig@8327
|
24 |
|
dludwig@8327
|
25 |
/* WinRT SDL video driver implementation
|
dludwig@8327
|
26 |
|
dludwig@8327
|
27 |
Initial work on this was done by David Ludwig (dludwig@pobox.com), and
|
dludwig@8327
|
28 |
was based off of SDL's "dummy" video driver.
|
dludwig@8327
|
29 |
*/
|
dludwig@8327
|
30 |
|
dludwig@8329
|
31 |
extern "C" {
|
dludwig@8327
|
32 |
#include "SDL_video.h"
|
dludwig@8327
|
33 |
#include "SDL_mouse.h"
|
dludwig@8327
|
34 |
#include "../SDL_sysvideo.h"
|
dludwig@8327
|
35 |
#include "../SDL_pixels_c.h"
|
dludwig@8327
|
36 |
#include "../../events/SDL_events_c.h"
|
dludwig@8329
|
37 |
}
|
dludwig@8327
|
38 |
|
dludwig@8329
|
39 |
#include "SDL_WinRTApp.h"
|
dludwig@8327
|
40 |
#include "SDL_winrtvideo.h"
|
dludwig@8327
|
41 |
#include "SDL_winrtevents_c.h"
|
dludwig@8327
|
42 |
#include "SDL_winrtframebuffer_c.h"
|
dludwig@8374
|
43 |
#include "SDL_winrtmouse.h"
|
dludwig@8327
|
44 |
|
dludwig@8333
|
45 |
/* On Windows, windows.h defines CreateWindow */
|
dludwig@8333
|
46 |
#ifdef CreateWindow
|
dludwig@8333
|
47 |
#undef CreateWindow
|
dludwig@8333
|
48 |
#endif
|
dludwig@8333
|
49 |
|
dludwig@8332
|
50 |
extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
|
dludwig@8332
|
51 |
|
dludwig@8368
|
52 |
#define WINRTVID_DRIVER_NAME "winrt"
|
dludwig@8327
|
53 |
|
dludwig@8327
|
54 |
/* Initialization/Query functions */
|
dludwig@8327
|
55 |
static int WINRT_VideoInit(_THIS);
|
dludwig@8374
|
56 |
static int WINRT_InitModes(_THIS);
|
dludwig@8327
|
57 |
static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
dludwig@8327
|
58 |
static void WINRT_VideoQuit(_THIS);
|
dludwig@8327
|
59 |
|
dludwig@8333
|
60 |
/* Window functions */
|
dludwig@8333
|
61 |
static int WINRT_CreateWindow(_THIS, SDL_Window * window);
|
dludwig@8333
|
62 |
static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
|
dludwig@8333
|
63 |
|
dludwig@8327
|
64 |
/* WinRT driver bootstrap functions */
|
dludwig@8327
|
65 |
|
dludwig@8327
|
66 |
static int
|
dludwig@8327
|
67 |
WINRT_Available(void)
|
dludwig@8327
|
68 |
{
|
dludwig@8328
|
69 |
return (1);
|
dludwig@8327
|
70 |
}
|
dludwig@8327
|
71 |
|
dludwig@8327
|
72 |
static void
|
dludwig@8327
|
73 |
WINRT_DeleteDevice(SDL_VideoDevice * device)
|
dludwig@8327
|
74 |
{
|
dludwig@8327
|
75 |
SDL_free(device);
|
dludwig@8327
|
76 |
}
|
dludwig@8327
|
77 |
|
dludwig@8327
|
78 |
static SDL_VideoDevice *
|
dludwig@8327
|
79 |
WINRT_CreateDevice(int devindex)
|
dludwig@8327
|
80 |
{
|
dludwig@8327
|
81 |
SDL_VideoDevice *device;
|
dludwig@8327
|
82 |
|
dludwig@8327
|
83 |
/* Initialize all variables that we clean on shutdown */
|
dludwig@8327
|
84 |
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
dludwig@8327
|
85 |
if (!device) {
|
dludwig@8327
|
86 |
SDL_OutOfMemory();
|
dludwig@8327
|
87 |
if (device) {
|
dludwig@8327
|
88 |
SDL_free(device);
|
dludwig@8327
|
89 |
}
|
dludwig@8327
|
90 |
return (0);
|
dludwig@8327
|
91 |
}
|
dludwig@8327
|
92 |
|
dludwig@8327
|
93 |
/* Set the function pointers */
|
dludwig@8327
|
94 |
device->VideoInit = WINRT_VideoInit;
|
dludwig@8327
|
95 |
device->VideoQuit = WINRT_VideoQuit;
|
dludwig@8333
|
96 |
device->CreateWindow = WINRT_CreateWindow;
|
dludwig@8333
|
97 |
device->DestroyWindow = WINRT_DestroyWindow;
|
dludwig@8327
|
98 |
device->SetDisplayMode = WINRT_SetDisplayMode;
|
dludwig@8327
|
99 |
device->PumpEvents = WINRT_PumpEvents;
|
dludwig@8327
|
100 |
device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
|
dludwig@8327
|
101 |
device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer;
|
dludwig@8327
|
102 |
device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer;
|
dludwig@8327
|
103 |
|
dludwig@8327
|
104 |
device->free = WINRT_DeleteDevice;
|
dludwig@8327
|
105 |
|
dludwig@8327
|
106 |
return device;
|
dludwig@8327
|
107 |
}
|
dludwig@8327
|
108 |
|
dludwig@8327
|
109 |
VideoBootStrap WINRT_bootstrap = {
|
dludwig@8327
|
110 |
WINRTVID_DRIVER_NAME, "SDL Windows RT video driver",
|
dludwig@8327
|
111 |
WINRT_Available, WINRT_CreateDevice
|
dludwig@8327
|
112 |
};
|
dludwig@8327
|
113 |
|
dludwig@8327
|
114 |
int
|
dludwig@8327
|
115 |
WINRT_VideoInit(_THIS)
|
dludwig@8327
|
116 |
{
|
dludwig@8374
|
117 |
if (WINRT_InitModes(_this) < 0) {
|
dludwig@8374
|
118 |
return -1;
|
dludwig@8374
|
119 |
}
|
dludwig@8374
|
120 |
|
dludwig@8374
|
121 |
WINRT_InitMouse(_this);
|
dludwig@8374
|
122 |
|
dludwig@8374
|
123 |
return 0;
|
dludwig@8374
|
124 |
}
|
dludwig@8374
|
125 |
|
dludwig@8374
|
126 |
static int
|
dludwig@8374
|
127 |
WINRT_InitModes(_THIS)
|
dludwig@8374
|
128 |
{
|
dludwig@8329
|
129 |
SDL_DisplayMode mode = SDL_WinRTGlobalApp->GetMainDisplayMode();
|
dludwig@8329
|
130 |
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
dludwig@8329
|
131 |
return -1;
|
dludwig@8374
|
132 |
}
|
dludwig@8374
|
133 |
|
dludwig@8374
|
134 |
SDL_AddDisplayMode(&_this->displays[0], &mode);
|
dludwig@8327
|
135 |
return 0;
|
dludwig@8327
|
136 |
}
|
dludwig@8327
|
137 |
|
dludwig@8327
|
138 |
static int
|
dludwig@8327
|
139 |
WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
dludwig@8327
|
140 |
{
|
dludwig@8327
|
141 |
return 0;
|
dludwig@8327
|
142 |
}
|
dludwig@8327
|
143 |
|
dludwig@8327
|
144 |
void
|
dludwig@8327
|
145 |
WINRT_VideoQuit(_THIS)
|
dludwig@8327
|
146 |
{
|
dludwig@8374
|
147 |
WINRT_QuitMouse(_this);
|
dludwig@8327
|
148 |
}
|
dludwig@8327
|
149 |
|
dludwig@8333
|
150 |
int
|
dludwig@8333
|
151 |
WINRT_CreateWindow(_THIS, SDL_Window * window)
|
dludwig@8333
|
152 |
{
|
dludwig@8334
|
153 |
// Make sure that only one window gets created, at least until multimonitor
|
dludwig@8334
|
154 |
// support is added.
|
dludwig@8334
|
155 |
if (SDL_WinRTGlobalApp->HasSDLWindowData())
|
dludwig@8334
|
156 |
{
|
dludwig@8334
|
157 |
SDL_SetError("WinRT only supports one window");
|
dludwig@8334
|
158 |
return -1;
|
dludwig@8334
|
159 |
}
|
dludwig@8333
|
160 |
|
dludwig@8333
|
161 |
SDL_WindowData *data;
|
dludwig@8333
|
162 |
data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
|
dludwig@8333
|
163 |
if (!data) {
|
dludwig@8333
|
164 |
SDL_OutOfMemory();
|
dludwig@8333
|
165 |
return -1;
|
dludwig@8333
|
166 |
}
|
dludwig@8333
|
167 |
SDL_zerop(data);
|
dludwig@8333
|
168 |
data->sdlWindow = window;
|
dludwig@8333
|
169 |
|
dludwig@8367
|
170 |
/* Make sure the window is considered to be positioned at {0,0},
|
dludwig@8367
|
171 |
and is considered fullscreen, shown, and the like.
|
dludwig@8367
|
172 |
*/
|
dludwig@8333
|
173 |
window->x = 0;
|
dludwig@8333
|
174 |
window->y = 0;
|
dludwig@8367
|
175 |
window->flags =
|
dludwig@8367
|
176 |
SDL_WINDOW_FULLSCREEN |
|
dludwig@8367
|
177 |
SDL_WINDOW_SHOWN |
|
dludwig@8367
|
178 |
SDL_WINDOW_BORDERLESS |
|
dludwig@8367
|
179 |
SDL_WINDOW_MAXIMIZED |
|
dludwig@8367
|
180 |
SDL_WINDOW_INPUT_GRABBED;
|
dludwig@8333
|
181 |
|
dludwig@8367
|
182 |
/* HACK from DLudwig: The following line of code prevents
|
dludwig@8367
|
183 |
SDL_CreateWindow and SDL_UpdateFullscreenMode from trying to resize
|
dludwig@8367
|
184 |
the window after the call to WINRT_CreateWindow returns.
|
dludwig@8367
|
185 |
|
dludwig@8367
|
186 |
This hack should allow a window to be created in virtually any size,
|
dludwig@8367
|
187 |
and more importantly, it allows a window's framebuffer, as created and
|
dludwig@8367
|
188 |
retrieved via SDL_GetWindowSurface, to be in any size. This can be
|
dludwig@8367
|
189 |
utilized by apps centered around software rendering, such as ports
|
dludwig@8367
|
190 |
of older apps. The app can have SDL create a framebuffer in any size
|
dludwig@8367
|
191 |
it chooses. SDL will scale the framebuffer to the native
|
dludwig@8367
|
192 |
screen size on the GPU (via SDL_UpdateWindowSurface).
|
dludwig@8367
|
193 |
*/
|
dludwig@8367
|
194 |
_this->displays[0].fullscreen_window = window;
|
dludwig@8367
|
195 |
|
dludwig@8367
|
196 |
/* Further prevent any display resizing, and make sure SDL_GetWindowDisplayMode
|
dludwig@8367
|
197 |
can report the correct size of windows, by creating a new display
|
dludwig@8367
|
198 |
mode in the requested size. To note, if the window is being created in
|
dludwig@8367
|
199 |
the device's native screen size, SDL_AddDisplayMode will do nothing.
|
dludwig@8367
|
200 |
*/
|
dludwig@8367
|
201 |
window->fullscreen_mode = SDL_WinRTGlobalApp->GetMainDisplayMode();
|
dludwig@8367
|
202 |
window->fullscreen_mode.w = window->w;
|
dludwig@8367
|
203 |
window->fullscreen_mode.h = window->h;
|
dludwig@8367
|
204 |
SDL_AddDisplayMode(&_this->displays[0], &window->fullscreen_mode);
|
dludwig@8367
|
205 |
|
dludwig@8367
|
206 |
/* TODO: Consider removing custom display modes in WINRT_DestroyWindow. */
|
dludwig@8367
|
207 |
|
dludwig@8367
|
208 |
/* Make sure the WinRT app's IFramworkView can post events on
|
dludwig@8367
|
209 |
behalf of SDL:
|
dludwig@8367
|
210 |
*/
|
dludwig@8333
|
211 |
SDL_WinRTGlobalApp->SetSDLWindowData(data);
|
dludwig@8333
|
212 |
|
dludwig@8367
|
213 |
/* All done! */
|
dludwig@8333
|
214 |
return 0;
|
dludwig@8333
|
215 |
}
|
dludwig@8333
|
216 |
|
dludwig@8333
|
217 |
void
|
dludwig@8333
|
218 |
WINRT_DestroyWindow(_THIS, SDL_Window * window)
|
dludwig@8333
|
219 |
{
|
dludwig@8335
|
220 |
if (SDL_WinRTGlobalApp->HasSDLWindowData() &&
|
dludwig@8335
|
221 |
SDL_WinRTGlobalApp->GetSDLWindowData()->sdlWindow == window)
|
dludwig@8334
|
222 |
{
|
dludwig@8334
|
223 |
SDL_WinRTGlobalApp->SetSDLWindowData(NULL);
|
dludwig@8334
|
224 |
}
|
dludwig@8333
|
225 |
}
|
dludwig@8333
|
226 |
|
dludwig@8333
|
227 |
|
dludwig@8327
|
228 |
#endif /* SDL_VIDEO_DRIVER_WINRT */
|
dludwig@8327
|
229 |
|
dludwig@8327
|
230 |
/* vi: set ts=4 sw=4 expandtab: */
|