SDL  2.0
SDL_vivantevideo.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #if SDL_VIDEO_DRIVER_VIVANTE
24 
25 /* SDL internals */
26 #include "../SDL_sysvideo.h"
27 #include "SDL_version.h"
28 #include "SDL_syswm.h"
29 #include "SDL_loadso.h"
30 #include "SDL_events.h"
31 #include "../../events/SDL_events_c.h"
32 
33 #ifdef SDL_INPUT_LINUXEV
34 #include "../../core/linux/SDL_evdev.h"
35 #endif
36 
37 #include "SDL_vivantevideo.h"
38 #include "SDL_vivanteplatform.h"
39 #include "SDL_vivanteopengles.h"
40 
41 
42 static int
43 VIVANTE_Available(void)
44 {
45  return 1;
46 }
47 
48 static void
49 VIVANTE_Destroy(SDL_VideoDevice * device)
50 {
51  if (device->driverdata != NULL) {
52  SDL_free(device->driverdata);
53  device->driverdata = NULL;
54  }
55 }
56 
57 static SDL_VideoDevice *
58 VIVANTE_Create()
59 {
60  SDL_VideoDevice *device;
62 
63  /* Initialize SDL_VideoDevice structure */
64  device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
65  if (device == NULL) {
67  return NULL;
68  }
69 
70  /* Initialize internal data */
71  data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
72  if (data == NULL) {
74  SDL_free(device);
75  return NULL;
76  }
77 
78  device->driverdata = data;
79 
80  /* Setup amount of available displays */
81  device->num_displays = 0;
82 
83  /* Set device free function */
84  device->free = VIVANTE_Destroy;
85 
86  /* Setup all functions which we can handle */
87  device->VideoInit = VIVANTE_VideoInit;
88  device->VideoQuit = VIVANTE_VideoQuit;
99 
100  device->GL_LoadLibrary = VIVANTE_GLES_LoadLibrary;
101  device->GL_GetProcAddress = VIVANTE_GLES_GetProcAddress;
102  device->GL_UnloadLibrary = VIVANTE_GLES_UnloadLibrary;
103  device->GL_CreateContext = VIVANTE_GLES_CreateContext;
104  device->GL_MakeCurrent = VIVANTE_GLES_MakeCurrent;
105  device->GL_SetSwapInterval = VIVANTE_GLES_SetSwapInterval;
106  device->GL_GetSwapInterval = VIVANTE_GLES_GetSwapInterval;
107  device->GL_SwapWindow = VIVANTE_GLES_SwapWindow;
108  device->GL_DeleteContext = VIVANTE_GLES_DeleteContext;
109 
110  device->PumpEvents = VIVANTE_PumpEvents;
111 
112  return device;
113 }
114 
115 VideoBootStrap VIVANTE_bootstrap = {
116  "vivante",
117  "Vivante EGL Video Driver",
118  VIVANTE_Available,
119  VIVANTE_Create
120 };
121 
122 /*****************************************************************************/
123 /* SDL Video and Display initialization/handling functions */
124 /*****************************************************************************/
125 
126 static int
127 VIVANTE_AddVideoDisplays(_THIS)
128 {
129  SDL_VideoData *videodata = _this->driverdata;
130  SDL_VideoDisplay display;
131  SDL_DisplayMode current_mode;
133  int pitch = 0, bpp = 0;
134  unsigned long pixels = 0;
135 
136  data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
137  if (data == NULL) {
138  return SDL_OutOfMemory();
139  }
140 
141  SDL_zero(current_mode);
142 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
143  data->native_display = vdkGetDisplay(videodata->vdk_private);
144 
145  vdkGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
146 #else
147  data->native_display = videodata->fbGetDisplayByIndex(0);
148 
149  videodata->fbGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
150 #endif /* SDL_VIDEO_DRIVER_VIVANTE_VDK */
151 
152  switch (bpp)
153  {
154  default: /* Is another format used? */
155  case 16:
156  current_mode.format = SDL_PIXELFORMAT_RGB565;
157  break;
158  }
159  /* FIXME: How do we query refresh rate? */
160  current_mode.refresh_rate = 60;
161 
162  SDL_zero(display);
163  display.desktop_mode = current_mode;
164  display.current_mode = current_mode;
165  display.driverdata = data;
166  SDL_AddVideoDisplay(&display);
167  return 0;
168 }
169 
170 int
172 {
173  SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
174 
175 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
176  videodata->vdk_private = vdkInitialize();
177  if (!videodata->vdk_private) {
178  return SDL_SetError("vdkInitialize() failed");
179  }
180 #else
181  videodata->egl_handle = SDL_LoadObject("libEGL.so.1");
182  if (!videodata->egl_handle) {
183  videodata->egl_handle = SDL_LoadObject("libEGL.so");
184  if (!videodata->egl_handle) {
185  return -1;
186  }
187  }
188 #define LOAD_FUNC(NAME) \
189  videodata->NAME = SDL_LoadFunction(videodata->egl_handle, #NAME); \
190  if (!videodata->NAME) return -1;
191 
192  LOAD_FUNC(fbGetDisplay);
193  LOAD_FUNC(fbGetDisplayByIndex);
194  LOAD_FUNC(fbGetDisplayGeometry);
195  LOAD_FUNC(fbGetDisplayInfo);
196  LOAD_FUNC(fbDestroyDisplay);
197  LOAD_FUNC(fbCreateWindow);
198  LOAD_FUNC(fbGetWindowGeometry);
199  LOAD_FUNC(fbGetWindowInfo);
200  LOAD_FUNC(fbDestroyWindow);
201 #endif
202 
203  if (VIVANTE_SetupPlatform(_this) < 0) {
204  return -1;
205  }
206 
207  if (VIVANTE_AddVideoDisplays(_this) < 0) {
208  return -1;
209  }
210 
211 #ifdef SDL_INPUT_LINUXEV
212  if (SDL_EVDEV_Init() < 0) {
213  return -1;
214  }
215 #endif
216 
217  return 0;
218 }
219 
220 void
222 {
223  SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
224 
225 #ifdef SDL_INPUT_LINUXEV
226  SDL_EVDEV_Quit();
227 #endif
228 
229  VIVANTE_CleanupPlatform(_this);
230 
231 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
232  if (videodata->vdk_private) {
233  vdkExit(videodata->vdk_private);
234  videodata->vdk_private = NULL;
235  }
236 #else
237  if (videodata->egl_handle) {
238  SDL_UnloadObject(videodata->egl_handle);
239  videodata->egl_handle = NULL;
240  }
241 #endif
242 }
243 
244 void
246 {
247  /* Only one display mode available, the current one */
248  SDL_AddDisplayMode(display, &display->current_mode);
249 }
250 
251 int
253 {
254  return 0;
255 }
256 
257 int
259 {
260  SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
261  SDL_DisplayData *displaydata;
262  SDL_WindowData *data;
263 
264  displaydata = SDL_GetDisplayDriverData(0);
265 
266  /* Allocate window internal data */
267  data = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
268  if (data == NULL) {
269  return SDL_OutOfMemory();
270  }
271 
272  /* Setup driver data for this window */
273  window->driverdata = data;
274 
275 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
276  data->native_window = vdkCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
277 #else
278  data->native_window = videodata->fbCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
279 #endif
280  if (!data->native_window) {
281  return SDL_SetError("VIVANTE: Can't create native window");
282  }
283 
284  if (window->flags & SDL_WINDOW_OPENGL) {
285  data->egl_surface = SDL_EGL_CreateSurface(_this, data->native_window);
286  if (data->egl_surface == EGL_NO_SURFACE) {
287  return SDL_SetError("VIVANTE: Can't create EGL surface");
288  }
289  } else {
290  data->egl_surface = EGL_NO_SURFACE;
291  }
292 
293  /* Window has been successfully created */
294  return 0;
295 }
296 
297 void
299 {
300  SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
301  SDL_WindowData *data;
302 
303  data = window->driverdata;
304  if (data) {
305  if (data->egl_surface != EGL_NO_SURFACE) {
306  SDL_EGL_DestroySurface(_this, data->egl_surface);
307  }
308 
309  if (data->native_window) {
310 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
311  vdkDestroyWindow(data->native_window);
312 #else
313  videodata->fbDestroyWindow(data->native_window);
314 #endif
315  }
316 
317  SDL_free(data);
318  }
319  window->driverdata = NULL;
320 }
321 
322 void
324 {
325 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
326  SDL_WindowData *data = window->driverdata;
327  vdkSetWindowTitle(data->native_window, window->title);
328 #endif
329 }
330 
331 void
333 {
334  /* FIXME */
335 }
336 
337 void
339 {
340  /* FIXME */
341 }
342 
343 void
345 {
346 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
347  SDL_WindowData *data = window->driverdata;
348  vdkShowWindow(data->native_window);
349 #endif
350  SDL_SetMouseFocus(window);
351  SDL_SetKeyboardFocus(window);
352 }
353 
354 void
356 {
357 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
358  SDL_WindowData *data = window->driverdata;
359  vdkHideWindow(data->native_window);
360 #endif
361 }
362 
363 /*****************************************************************************/
364 /* SDL Window Manager function */
365 /*****************************************************************************/
366 SDL_bool
367 VIVANTE_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
368 {
369  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
370  SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(0);
371 
372  if (info->version.major == SDL_MAJOR_VERSION &&
373  info->version.minor == SDL_MINOR_VERSION) {
375  info->info.vivante.display = displaydata->native_display;
376  info->info.vivante.window = data->native_window;
377  return SDL_TRUE;
378  } else {
379  SDL_SetError("Application not compiled with SDL %d.%d\n",
381  return SDL_FALSE;
382  }
383 }
384 
385 /*****************************************************************************/
386 /* SDL event functions */
387 /*****************************************************************************/
389 {
390 #ifdef SDL_INPUT_LINUXEV
391  SDL_EVDEV_Poll();
392 #endif
393 }
394 
395 #endif /* SDL_VIDEO_DRIVER_VIVANTE */
396 
397 /* vi: set ts=4 sw=4 expandtab: */
#define SDL_MINOR_VERSION
Definition: SDL_version.h:61
void VIVANTE_SetWindowTitle(_THIS, SDL_Window *window)
void VIVANTE_SetWindowPosition(_THIS, SDL_Window *window)
int VIVANTE_VideoInit(_THIS)
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:612
Display * display
Definition: SDL_syswm.h:215
#define SDL_MAJOR_VERSION
Definition: SDL_version.h:60
static SDL_Window * window
void VIVANTE_ShowWindow(_THIS, SDL_Window *window)
void(* free)(_THIS)
Definition: SDL_sysvideo.h:358
void VIVANTE_PumpEvents(_THIS)
int(* GL_SetSwapInterval)(_THIS, int interval)
Definition: SDL_sysvideo.h:253
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
void(* ShowWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:215
The structure that defines a display mode.
Definition: SDL_video.h:53
int VIVANTE_CreateWindow(_THIS, SDL_Window *window)
SDL_version version
Definition: SDL_syswm.h:195
Uint8 major
Definition: SDL_version.h:53
void(* SetWindowSize)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:208
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
SDL_SYSWM_TYPE subsystem
Definition: SDL_syswm.h:196
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:103
void(* GL_SwapWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:255
#define SDL_LoadObject
#define SDL_UnloadObject
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display)
Definition: SDL_video.c:591
int(* GL_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:247
int(* SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
Definition: SDL_sysvideo.h:197
void * SDL_GetDisplayDriverData(int displayIndex)
Definition: SDL_video.c:645
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
void(* HideWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:216
void * SDL_calloc(size_t nmemb, size_t size)
#define SDL_INPUT_LINUXEV
Definition: SDL_config.h:236
SDL_bool(* GetWindowWMInfo)(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
Definition: SDL_sysvideo.h:240
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:250
#define _THIS
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: SDL_sysvideo.h:251
void SDL_free(void *mem)
int VIVANTE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
SDL_DisplayMode current_mode
Definition: SDL_sysvideo.h:130
GLenum mode
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:227
Uint8 minor
Definition: SDL_version.h:54
#define SDL_zero(x)
Definition: SDL_stdinc.h:359
char * title
Definition: SDL_sysvideo.h:75
SDL_bool VIVANTE_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void(* GL_UnloadLibrary)(_THIS)
Definition: SDL_sysvideo.h:249
void(* GetDisplayModes)(_THIS, SDL_VideoDisplay *display)
Definition: SDL_sysvideo.h:189
Window window
Definition: SDL_syswm.h:216
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
Definition: SDL_stdinc.h:130
SDL_DisplayMode desktop_mode
Definition: SDL_sysvideo.h:129
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:164
#define SDL_SetError
void(* SetWindowPosition)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:207
void VIVANTE_SetWindowSize(_THIS, SDL_Window *window)
void VIVANTE_DestroyWindow(_THIS, SDL_Window *window)
int(* CreateWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:203
The type used to identify a window.
Definition: SDL_sysvideo.h:71
void VIVANTE_VideoQuit(_THIS)
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:728
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:158
union SDL_SysWMinfo::@18 info
void * driverdata
Definition: SDL_sysvideo.h:109
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:256
Uint32 format
Definition: SDL_video.h:55
void(* SetWindowTitle)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:205
int(* GL_GetSwapInterval)(_THIS)
Definition: SDL_sysvideo.h:254
ANativeWindow * native_window
Uint32 flags
Definition: SDL_sysvideo.h:81
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:248
EGLNativeDisplayType native_display
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:262
void VIVANTE_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
void VIVANTE_HideWindow(_THIS, SDL_Window *window)