2 Simple DirectMedia Layer
3 Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_VIVANTE
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"
33 #ifdef SDL_INPUT_LINUXEV
34 #include "../../core/linux/SDL_evdev.h"
37 #include "SDL_vivantevideo.h"
38 #include "SDL_vivanteplatform.h"
39 #include "SDL_vivanteopengles.h"
43 VIVANTE_Available(void)
49 VIVANTE_Destroy(SDL_VideoDevice * device)
51 if (device->driverdata != NULL) {
52 SDL_free(device->driverdata);
53 device->driverdata = NULL;
57 static SDL_VideoDevice *
60 SDL_VideoDevice *device;
63 /* Initialize SDL_VideoDevice structure */
64 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
70 /* Initialize internal data */
71 data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
78 device->driverdata = data;
80 /* Setup amount of available displays */
81 device->num_displays = 0;
83 /* Set device free function */
84 device->free = VIVANTE_Destroy;
86 /* Setup all functions which we can handle */
87 device->VideoInit = VIVANTE_VideoInit;
88 device->VideoQuit = VIVANTE_VideoQuit;
89 device->GetDisplayModes = VIVANTE_GetDisplayModes;
90 device->SetDisplayMode = VIVANTE_SetDisplayMode;
91 device->CreateWindow = VIVANTE_CreateWindow;
92 device->SetWindowTitle = VIVANTE_SetWindowTitle;
93 device->SetWindowPosition = VIVANTE_SetWindowPosition;
94 device->SetWindowSize = VIVANTE_SetWindowSize;
95 device->ShowWindow = VIVANTE_ShowWindow;
96 device->HideWindow = VIVANTE_HideWindow;
97 device->DestroyWindow = VIVANTE_DestroyWindow;
98 device->GetWindowWMInfo = VIVANTE_GetWindowWMInfo;
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;
110 device->PumpEvents = VIVANTE_PumpEvents;
115 VideoBootStrap VIVANTE_bootstrap = {
117 "Vivante EGL Video Driver",
122 /*****************************************************************************/
123 /* SDL Video and Display initialization/handling functions */
124 /*****************************************************************************/
127 VIVANTE_AddVideoDisplays(_THIS)
129 SDL_VideoData *videodata = _this->driverdata;
130 SDL_VideoDisplay display;
131 SDL_DisplayMode current_mode;
132 SDL_DisplayData *data;
133 int pitch = 0, bpp = 0;
134 unsigned long pixels = 0;
136 data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
138 return SDL_OutOfMemory();
141 SDL_zero(current_mode);
142 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
143 data->native_display = vdkGetDisplay(videodata->vdk_private);
145 vdkGetDisplayInfo(data->native_display, ¤t_mode.w, ¤t_mode.h, &pixels, &pitch, &bpp);
147 data->native_display = videodata->fbGetDisplayByIndex(0);
149 videodata->fbGetDisplayInfo(data->native_display, ¤t_mode.w, ¤t_mode.h, &pixels, &pitch, &bpp);
150 #endif /* SDL_VIDEO_DRIVER_VIVANTE_VDK */
154 default: /* Is another format used? */
156 current_mode.format = SDL_PIXELFORMAT_RGB565;
159 /* FIXME: How do we query refresh rate? */
160 current_mode.refresh_rate = 60;
163 display.desktop_mode = current_mode;
164 display.current_mode = current_mode;
165 display.driverdata = data;
166 SDL_AddVideoDisplay(&display);
171 VIVANTE_VideoInit(_THIS)
173 SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
175 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
176 videodata->vdk_private = vdkInitialize();
177 if (!videodata->vdk_private) {
178 return SDL_SetError("vdkInitialize() failed");
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) {
188 #define LOAD_FUNC(NAME) \
189 videodata->NAME = SDL_LoadFunction(videodata->egl_handle, #NAME); \
190 if (!videodata->NAME) return -1;
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);
203 if (VIVANTE_SetupPlatform(_this) < 0) {
207 if (VIVANTE_AddVideoDisplays(_this) < 0) {
211 #ifdef SDL_INPUT_LINUXEV
212 if (SDL_EVDEV_Init() < 0) {
221 VIVANTE_VideoQuit(_THIS)
223 SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
225 #ifdef SDL_INPUT_LINUXEV
229 VIVANTE_CleanupPlatform(_this);
231 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
232 if (videodata->vdk_private) {
233 vdkExit(videodata->vdk_private);
234 videodata->vdk_private = NULL;
237 if (videodata->egl_handle) {
238 SDL_UnloadObject(videodata->egl_handle);
239 videodata->egl_handle = NULL;
245 VIVANTE_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
247 /* Only one display mode available, the current one */
248 SDL_AddDisplayMode(display, &display->current_mode);
252 VIVANTE_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
258 VIVANTE_CreateWindow(_THIS, SDL_Window * window)
260 SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
261 SDL_DisplayData *displaydata;
262 SDL_WindowData *data;
264 displaydata = SDL_GetDisplayDriverData(0);
266 /* Allocate window internal data */
267 data = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
269 return SDL_OutOfMemory();
272 /* Setup driver data for this window */
273 window->driverdata = data;
275 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
276 data->native_window = vdkCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
278 data->native_window = videodata->fbCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
280 if (!data->native_window) {
281 return SDL_SetError("VIVANTE: Can't create native window");
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");
290 data->egl_surface = EGL_NO_SURFACE;
293 /* Window has been successfully created */
298 VIVANTE_DestroyWindow(_THIS, SDL_Window * window)
300 SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
301 SDL_WindowData *data;
303 data = window->driverdata;
305 if (data->egl_surface != EGL_NO_SURFACE) {
306 SDL_EGL_DestroySurface(_this, data->egl_surface);
309 if (data->native_window) {
310 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
311 vdkDestroyWindow(data->native_window);
313 videodata->fbDestroyWindow(data->native_window);
319 window->driverdata = NULL;
323 VIVANTE_SetWindowTitle(_THIS, SDL_Window * window)
325 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
326 SDL_WindowData *data = window->driverdata;
327 vdkSetWindowTitle(data->native_window, window->title);
332 VIVANTE_SetWindowPosition(_THIS, SDL_Window * window)
338 VIVANTE_SetWindowSize(_THIS, SDL_Window * window)
344 VIVANTE_ShowWindow(_THIS, SDL_Window * window)
346 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
347 SDL_WindowData *data = window->driverdata;
348 vdkShowWindow(data->native_window);
350 SDL_SetMouseFocus(window);
351 SDL_SetKeyboardFocus(window);
355 VIVANTE_HideWindow(_THIS, SDL_Window * window)
357 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
358 SDL_WindowData *data = window->driverdata;
359 vdkHideWindow(data->native_window);
363 /*****************************************************************************/
364 /* SDL Window Manager function */
365 /*****************************************************************************/
367 VIVANTE_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
369 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
370 SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(0);
372 if (info->version.major == SDL_MAJOR_VERSION &&
373 info->version.minor == SDL_MINOR_VERSION) {
374 info->subsystem = SDL_SYSWM_VIVANTE;
375 info->info.vivante.display = displaydata->native_display;
376 info->info.vivante.window = data->native_window;
379 SDL_SetError("Application not compiled with SDL %d.%d\n",
380 SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
385 /*****************************************************************************/
386 /* SDL event functions */
387 /*****************************************************************************/
388 void VIVANTE_PumpEvents(_THIS)
390 #ifdef SDL_INPUT_LINUXEV
395 #endif /* SDL_VIDEO_DRIVER_VIVANTE */
397 /* vi: set ts=4 sw=4 expandtab: */