Skip to content

Latest commit

 

History

History
301 lines (254 loc) · 7.55 KB

SDL_mx6video.c

File metadata and controls

301 lines (254 loc) · 7.55 KB
 
Sep 10, 2014
Sep 10, 2014
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_MX6
/* SDL internals */
#include "../SDL_sysvideo.h"
#include "SDL_version.h"
#include "SDL_syswm.h"
#include "SDL_loadso.h"
#include "SDL_events.h"
#ifdef SDL_INPUT_LINUXEV
#include "../../core/linux/SDL_evdev.h"
#endif
#include "SDL_mx6video.h"
#include "SDL_mx6events_c.h"
#include "SDL_mx6opengles.h"
static int
MX6_Available(void)
{
return 1;
}
static void
MX6_Destroy(SDL_VideoDevice * device)
{
if (device->driverdata != NULL) {
device->driverdata = NULL;
}
}
static SDL_VideoDevice *
MX6_Create()
{
SDL_VideoDevice *device;
SDL_VideoData *phdata;
/* Initialize SDL_VideoDevice structure */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device == NULL) {
SDL_OutOfMemory();
return NULL;
}
/* Initialize internal data */
phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
if (phdata == NULL) {
SDL_OutOfMemory();
SDL_free(device);
return NULL;
}
device->driverdata = phdata;
/* Setup amount of available displays and current display */
device->num_displays = 0;
/* Set device free function */
device->free = MX6_Destroy;
/* Setup all functions which we can handle */
device->VideoInit = MX6_VideoInit;
device->VideoQuit = MX6_VideoQuit;
device->GetDisplayModes = MX6_GetDisplayModes;
device->SetDisplayMode = MX6_SetDisplayMode;
device->CreateWindow = MX6_CreateWindow;
device->CreateWindowFrom = MX6_CreateWindowFrom;
device->SetWindowTitle = MX6_SetWindowTitle;
device->SetWindowIcon = MX6_SetWindowIcon;
device->SetWindowPosition = MX6_SetWindowPosition;
device->SetWindowSize = MX6_SetWindowSize;
device->ShowWindow = MX6_ShowWindow;
device->HideWindow = MX6_HideWindow;
device->RaiseWindow = MX6_RaiseWindow;
device->MaximizeWindow = MX6_MaximizeWindow;
device->MinimizeWindow = MX6_MinimizeWindow;
device->RestoreWindow = MX6_RestoreWindow;
device->SetWindowGrab = MX6_SetWindowGrab;
device->DestroyWindow = MX6_DestroyWindow;
device->GetWindowWMInfo = MX6_GetWindowWMInfo;
device->GL_LoadLibrary = MX6_GLES_LoadLibrary;
device->GL_GetProcAddress = MX6_GLES_GetProcAddress;
device->GL_UnloadLibrary = MX6_GLES_UnloadLibrary;
device->GL_CreateContext = MX6_GLES_CreateContext;
device->GL_MakeCurrent = MX6_GLES_MakeCurrent;
device->GL_SetSwapInterval = MX6_GLES_SetSwapInterval;
device->GL_GetSwapInterval = MX6_GLES_GetSwapInterval;
device->GL_SwapWindow = MX6_GLES_SwapWindow;
device->GL_DeleteContext = MX6_GLES_DeleteContext;
device->PumpEvents = MX6_PumpEvents;
return device;
}
VideoBootStrap MX6_bootstrap = {
"MX6",
"Freescale i.MX6 Video Driver",
MX6_Available,
MX6_Create
};
/*****************************************************************************/
/* SDL Video and Display initialization/handling functions */
/*****************************************************************************/
int
MX6_VideoInit(_THIS)
{
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayData *data;
data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (data == NULL) {
return SDL_OutOfMemory();
}
/* Actual data will be set in SDL_GL_LoadLibrary call below */
SDL_zero(current_mode);
current_mode.w = 0;
current_mode.h = 0;
current_mode.refresh_rate = 60;
current_mode.format = SDL_PIXELFORMAT_RGB565;
current_mode.driverdata = NULL;
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
display.driverdata = data;
SDL_AddVideoDisplay(&display);
if (SDL_GL_LoadLibrary(NULL) < 0) {
return -1;
}
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Init();
#endif
return 1;
}
void
MX6_VideoQuit(_THIS)
{
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Quit();
#endif
}
void
MX6_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
/* Only one display mode available, the current one */
SDL_AddDisplayMode(display, &display->current_mode);
}
int
MX6_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
return 0;
}
int
MX6_CreateWindow(_THIS, SDL_Window * window)
{
SDL_DisplayData *displaydata;
SDL_WindowData *wdata;
displaydata = SDL_GetDisplayDriverData(0);
/* Allocate window internal data */
wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
if (wdata == NULL) {
return SDL_OutOfMemory();
}
/* Setup driver data for this window */
window->driverdata = wdata;
window->flags |= SDL_WINDOW_OPENGL;
if (!_this->egl_data) {
return -1;
}
wdata->native_window = egl_viv_data->fbCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
if (!wdata->native_window) {
return SDL_SetError("MX6: Can't create native window");
}
wdata->egl_surface = SDL_EGL_CreateSurface(_this, wdata->native_window);
if (wdata->egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("MX6: Can't create EGL surface");
}
/* Window has been successfully created */
return 0;
}
void
MX6_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_WindowData *wdata;
wdata = window->driverdata;
if (wdata) {
SDL_EGL_DestroySurface(_this, wdata->egl_surface);
}
if (egl_viv_data) {
egl_viv_data->fbDestroyWindow(wdata->native_window);
}
}
int
MX6_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{
return -1;
}
void
MX6_SetWindowTitle(_THIS, SDL_Window * window)
{
}
void
MX6_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{
}
void
MX6_SetWindowPosition(_THIS, SDL_Window * window)
{
}
void
MX6_SetWindowSize(_THIS, SDL_Window * window)
{
}
void
MX6_ShowWindow(_THIS, SDL_Window * window)
{
}
void
MX6_HideWindow(_THIS, SDL_Window * window)
{
}
void
MX6_RaiseWindow(_THIS, SDL_Window * window)
{
}
void
MX6_MaximizeWindow(_THIS, SDL_Window * window)
{
}
void
MX6_MinimizeWindow(_THIS, SDL_Window * window)
{
}
void
MX6_RestoreWindow(_THIS, SDL_Window * window)
{
}
void
MX6_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{
}
/*****************************************************************************/
/* SDL Window Manager function */
/*****************************************************************************/
SDL_bool
MX6_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
{
return SDL_TRUE;
}
#endif /* SDL_VIDEO_DRIVER_MX6 */
/* vi: set ts=4 sw=4 expandtab: */