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@8327
|
43 |
|
dludwig@8333
|
44 |
/* On Windows, windows.h defines CreateWindow */
|
dludwig@8333
|
45 |
#ifdef CreateWindow
|
dludwig@8333
|
46 |
#undef CreateWindow
|
dludwig@8333
|
47 |
#endif
|
dludwig@8333
|
48 |
|
dludwig@8332
|
49 |
extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
|
dludwig@8332
|
50 |
|
dludwig@8327
|
51 |
#define WINRTVID_DRIVER_NAME "dummy"
|
dludwig@8327
|
52 |
|
dludwig@8327
|
53 |
/* Initialization/Query functions */
|
dludwig@8327
|
54 |
static int WINRT_VideoInit(_THIS);
|
dludwig@8327
|
55 |
static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
dludwig@8327
|
56 |
static void WINRT_VideoQuit(_THIS);
|
dludwig@8327
|
57 |
|
dludwig@8333
|
58 |
/* Window functions */
|
dludwig@8333
|
59 |
static int WINRT_CreateWindow(_THIS, SDL_Window * window);
|
dludwig@8333
|
60 |
static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
|
dludwig@8333
|
61 |
|
dludwig@8327
|
62 |
/* WinRT driver bootstrap functions */
|
dludwig@8327
|
63 |
|
dludwig@8327
|
64 |
static int
|
dludwig@8327
|
65 |
WINRT_Available(void)
|
dludwig@8327
|
66 |
{
|
dludwig@8328
|
67 |
return (1);
|
dludwig@8327
|
68 |
}
|
dludwig@8327
|
69 |
|
dludwig@8327
|
70 |
static void
|
dludwig@8327
|
71 |
WINRT_DeleteDevice(SDL_VideoDevice * device)
|
dludwig@8327
|
72 |
{
|
dludwig@8327
|
73 |
SDL_free(device);
|
dludwig@8327
|
74 |
}
|
dludwig@8327
|
75 |
|
dludwig@8327
|
76 |
static SDL_VideoDevice *
|
dludwig@8327
|
77 |
WINRT_CreateDevice(int devindex)
|
dludwig@8327
|
78 |
{
|
dludwig@8327
|
79 |
SDL_VideoDevice *device;
|
dludwig@8327
|
80 |
|
dludwig@8327
|
81 |
/* Initialize all variables that we clean on shutdown */
|
dludwig@8327
|
82 |
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
dludwig@8327
|
83 |
if (!device) {
|
dludwig@8327
|
84 |
SDL_OutOfMemory();
|
dludwig@8327
|
85 |
if (device) {
|
dludwig@8327
|
86 |
SDL_free(device);
|
dludwig@8327
|
87 |
}
|
dludwig@8327
|
88 |
return (0);
|
dludwig@8327
|
89 |
}
|
dludwig@8327
|
90 |
|
dludwig@8327
|
91 |
/* Set the function pointers */
|
dludwig@8327
|
92 |
device->VideoInit = WINRT_VideoInit;
|
dludwig@8327
|
93 |
device->VideoQuit = WINRT_VideoQuit;
|
dludwig@8333
|
94 |
device->CreateWindow = WINRT_CreateWindow;
|
dludwig@8333
|
95 |
device->DestroyWindow = WINRT_DestroyWindow;
|
dludwig@8327
|
96 |
device->SetDisplayMode = WINRT_SetDisplayMode;
|
dludwig@8327
|
97 |
device->PumpEvents = WINRT_PumpEvents;
|
dludwig@8327
|
98 |
device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
|
dludwig@8327
|
99 |
device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer;
|
dludwig@8327
|
100 |
device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer;
|
dludwig@8327
|
101 |
|
dludwig@8327
|
102 |
device->free = WINRT_DeleteDevice;
|
dludwig@8327
|
103 |
|
dludwig@8327
|
104 |
return device;
|
dludwig@8327
|
105 |
}
|
dludwig@8327
|
106 |
|
dludwig@8327
|
107 |
VideoBootStrap WINRT_bootstrap = {
|
dludwig@8327
|
108 |
WINRTVID_DRIVER_NAME, "SDL Windows RT video driver",
|
dludwig@8327
|
109 |
WINRT_Available, WINRT_CreateDevice
|
dludwig@8327
|
110 |
};
|
dludwig@8327
|
111 |
|
dludwig@8327
|
112 |
int
|
dludwig@8327
|
113 |
WINRT_VideoInit(_THIS)
|
dludwig@8327
|
114 |
{
|
dludwig@8329
|
115 |
SDL_DisplayMode mode = SDL_WinRTGlobalApp->GetMainDisplayMode();
|
dludwig@8329
|
116 |
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
dludwig@8329
|
117 |
return -1;
|
dludwig@8329
|
118 |
}
|
dludwig@8329
|
119 |
|
dludwig@8329
|
120 |
SDL_AddDisplayMode(&_this->displays[0], &mode);
|
dludwig@8329
|
121 |
|
dludwig@8329
|
122 |
/* We're done! */
|
dludwig@8327
|
123 |
return 0;
|
dludwig@8327
|
124 |
}
|
dludwig@8327
|
125 |
|
dludwig@8327
|
126 |
static int
|
dludwig@8327
|
127 |
WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
dludwig@8327
|
128 |
{
|
dludwig@8327
|
129 |
return 0;
|
dludwig@8327
|
130 |
}
|
dludwig@8327
|
131 |
|
dludwig@8327
|
132 |
void
|
dludwig@8327
|
133 |
WINRT_VideoQuit(_THIS)
|
dludwig@8327
|
134 |
{
|
dludwig@8327
|
135 |
}
|
dludwig@8327
|
136 |
|
dludwig@8333
|
137 |
int
|
dludwig@8333
|
138 |
WINRT_CreateWindow(_THIS, SDL_Window * window)
|
dludwig@8333
|
139 |
{
|
dludwig@8333
|
140 |
// TODO, WinRT: modify WINRT_Createwindow to ensure that, for now, only one window gets created
|
dludwig@8333
|
141 |
// (until multimonitor support is added to the WinRT port).
|
dludwig@8333
|
142 |
|
dludwig@8333
|
143 |
SDL_WindowData *data;
|
dludwig@8333
|
144 |
data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
|
dludwig@8333
|
145 |
if (!data) {
|
dludwig@8333
|
146 |
SDL_OutOfMemory();
|
dludwig@8333
|
147 |
return -1;
|
dludwig@8333
|
148 |
}
|
dludwig@8333
|
149 |
SDL_zerop(data);
|
dludwig@8333
|
150 |
data->sdlWindow = window;
|
dludwig@8333
|
151 |
|
dludwig@8333
|
152 |
/* Adjust the window data to match the screen */
|
dludwig@8333
|
153 |
window->x = 0;
|
dludwig@8333
|
154 |
window->y = 0;
|
dludwig@8333
|
155 |
window->w = _this->displays->desktop_mode.w;
|
dludwig@8333
|
156 |
window->h = _this->displays->desktop_mode.h;
|
dludwig@8333
|
157 |
|
dludwig@8333
|
158 |
SDL_WinRTGlobalApp->SetSDLWindowData(data);
|
dludwig@8333
|
159 |
|
dludwig@8333
|
160 |
return 0;
|
dludwig@8333
|
161 |
}
|
dludwig@8333
|
162 |
|
dludwig@8333
|
163 |
void
|
dludwig@8333
|
164 |
WINRT_DestroyWindow(_THIS, SDL_Window * window)
|
dludwig@8333
|
165 |
{
|
dludwig@8333
|
166 |
SDL_WinRTGlobalApp->SetSDLWindowData(NULL);
|
dludwig@8333
|
167 |
}
|
dludwig@8333
|
168 |
|
dludwig@8333
|
169 |
|
dludwig@8327
|
170 |
#endif /* SDL_VIDEO_DRIVER_WINRT */
|
dludwig@8327
|
171 |
|
dludwig@8327
|
172 |
/* vi: set ts=4 sw=4 expandtab: */
|