SDL  2.0
SDL_malivideo.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2014 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_MALI
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_malivideo.h"
38 #include "SDL_maliopengles.h"
39 
40 
41 static int
42 MALI_Available(void)
43 {
44  return 1;
45 }
46 
47 static void
48 MALI_Destroy(SDL_VideoDevice * device)
49 {
50  if (device->driverdata != NULL) {
51  SDL_free(device->driverdata);
52  device->driverdata = NULL;
53  }
54 }
55 
56 static SDL_VideoDevice *
57 MALI_Create()
58 {
60 
61  /* Initialize SDL_VideoDevice structure */
63  if (device == NULL) {
65  return NULL;
66  }
67 
68  device->driverdata = NULL;
69 
70  /* Setup amount of available displays and current display */
71  device->num_displays = 0;
72 
73  /* Set device free function */
74  device->free = MALI_Destroy;
75 
76  /* Setup all functions which we can handle */
77  device->VideoInit = MALI_VideoInit;
78  device->VideoQuit = MALI_VideoQuit;
79  device->GetDisplayModes = MALI_GetDisplayModes;
80  device->SetDisplayMode = MALI_SetDisplayMode;
81  device->CreateSDLWindow = MALI_CreateWindow;
82  device->SetWindowTitle = MALI_SetWindowTitle;
83  device->SetWindowPosition = MALI_SetWindowPosition;
84  device->SetWindowSize = MALI_SetWindowSize;
85  device->ShowWindow = MALI_ShowWindow;
86  device->HideWindow = MALI_HideWindow;
87  device->DestroyWindow = MALI_DestroyWindow;
88  device->GetWindowWMInfo = MALI_GetWindowWMInfo;
89 
90  device->GL_LoadLibrary = MALI_GLES_LoadLibrary;
91  device->GL_GetProcAddress = MALI_GLES_GetProcAddress;
92  device->GL_UnloadLibrary = MALI_GLES_UnloadLibrary;
93  device->GL_CreateContext = MALI_GLES_CreateContext;
94  device->GL_MakeCurrent = MALI_GLES_MakeCurrent;
95  device->GL_SetSwapInterval = MALI_GLES_SetSwapInterval;
96  device->GL_GetSwapInterval = MALI_GLES_GetSwapInterval;
97  device->GL_SwapWindow = MALI_GLES_SwapWindow;
98  device->GL_DeleteContext = MALI_GLES_DeleteContext;
99 
100  device->PumpEvents = MALI_PumpEvents;
101 
102  return device;
103 }
104 
106  "mali",
107  "Mali EGL Video Driver",
108  MALI_Available,
109  MALI_Create
110 };
111 
112 /*****************************************************************************/
113 /* SDL Video and Display initialization/handling functions */
114 /*****************************************************************************/
115 
116 int
118 {
119  SDL_VideoDisplay display;
120  SDL_DisplayMode current_mode;
122  struct fb_var_screeninfo vinfo;
123  int fd;
124 
126  if (data == NULL) {
127  return SDL_OutOfMemory();
128  }
129 
130  fd = open("/dev/fb0", O_RDWR, 0);
131  if (fd < 0) {
132  return SDL_SetError("mali-fbdev: Could not open framebuffer device");
133  }
134 
135  if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
137  return SDL_SetError("mali-fbdev: Could not get framebuffer information");
138  }
139  /* Enable triple buffering */
140  /*
141  vinfo.yres_virtual = vinfo.yres * 3;
142  if (ioctl(fd, FBIOPUT_VSCREENINFO, vinfo) == -1) {
143  printf("mali-fbdev: Error setting VSCREENINFO\n");
144  }
145  */
146  close(fd);
147  system("setterm -cursor off");
148 
149  data->native_display.width = vinfo.xres;
150  data->native_display.height = vinfo.yres;
151 
152  SDL_zero(current_mode);
153  current_mode.w = vinfo.xres;
154  current_mode.h = vinfo.yres;
155  /* FIXME: Is there a way to tell the actual refresh rate? */
156  current_mode.refresh_rate = 60;
157  /* 32 bpp for default */
158  //current_mode.format = SDL_PIXELFORMAT_ABGR8888;
159  current_mode.format = SDL_PIXELFORMAT_RGBX8888;
160 
161  current_mode.driverdata = NULL;
162 
163  SDL_zero(display);
164  display.desktop_mode = current_mode;
165  display.current_mode = current_mode;
166  display.driverdata = data;
167 
168  SDL_AddVideoDisplay(&display);
169 
170 #ifdef SDL_INPUT_LINUXEV
171  if (SDL_EVDEV_Init() < 0) {
172  return -1;
173  }
174 #endif
175 
176  return 0;
177 }
178 
179 void
181 {
182  /* Clear the framebuffer and ser cursor on again */
183  int fd = open("/dev/tty", O_RDWR);
184  ioctl(fd, VT_ACTIVATE, 5);
185  ioctl(fd, VT_ACTIVATE, 1);
186  close(fd);
187  system("setterm -cursor on");
188 
189 #ifdef SDL_INPUT_LINUXEV
190  SDL_EVDEV_Quit();
191 #endif
192 
193 }
194 
195 void
197 {
198  /* Only one display mode available, the current one */
199  SDL_AddDisplayMode(display, &display->current_mode);
200 }
201 
202 int
204 {
205  return 0;
206 }
207 
208 int
210 {
211  SDL_WindowData *windowdata;
212  SDL_DisplayData *displaydata;
213 
214  displaydata = SDL_GetDisplayDriverData(0);
215 
216  /* Allocate window internal data */
217  windowdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
218  if (windowdata == NULL) {
219  return SDL_OutOfMemory();
220  }
221 
222  /* Windows have one size for now */
223  window->w = displaydata->native_display.width;
224  window->h = displaydata->native_display.height;
225 
226  /* OpenGL ES is the law here */
227  window->flags |= SDL_WINDOW_OPENGL;
228 
229  if (!_this->egl_data) {
230  if (SDL_GL_LoadLibrary(NULL) < 0) {
231  return -1;
232  }
233  }
234  windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) &displaydata->native_display);
235 
236  if (windowdata->egl_surface == EGL_NO_SURFACE) {
238  return SDL_SetError("mali-fbdev: Can't create EGL window surface");
239  }
240 
241  /* Setup driver data for this window */
242  window->driverdata = windowdata;
243 
244  /* One window, it always has focus */
247 
248  /* Window has been successfully created */
249  return 0;
250 }
251 
252 void
254 {
256 
257  data = window->driverdata;
258  if (data) {
259  if (data->egl_surface != EGL_NO_SURFACE) {
260  SDL_EGL_DestroySurface(_this, data->egl_surface);
261  data->egl_surface = EGL_NO_SURFACE;
262  }
263  SDL_free(data);
264  }
265  window->driverdata = NULL;
266 }
267 
268 void
270 {
271 }
272 
273 void
275 {
276 }
277 
278 void
280 {
281 }
282 
283 void
285 {
286 }
287 
288 void
290 {
291 }
292 
293 /*****************************************************************************/
294 /* SDL Window Manager function */
295 /*****************************************************************************/
296 SDL_bool
298 {
299  if (info->version.major <= SDL_MAJOR_VERSION) {
300  return SDL_TRUE;
301  } else {
302  SDL_SetError("application not compiled with SDL %d.%d\n",
304  }
305 
306  /* Failed to get window manager information */
307  return SDL_FALSE;
308 }
309 
310 /*****************************************************************************/
311 /* SDL event functions */
312 /*****************************************************************************/
314 {
315 #ifdef SDL_INPUT_LINUXEV
316  SDL_EVDEV_Poll();
317 #endif
318 }
319 
320 #endif /* SDL_VIDEO_DRIVER_MALI */
321 
322 /* vi: set ts=4 sw=4 expandtab: */
323 
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
MALI_VideoInit
int MALI_VideoInit(_THIS)
SDL_DisplayMode::format
Uint32 format
Definition: SDL_video.h:55
SDL_events.h
MALI_SetWindowTitle
void MALI_SetWindowTitle(_THIS, SDL_Window *window)
SDL_malivideo.h
SDL_PIXELFORMAT_RGBX8888
@ SDL_PIXELFORMAT_RGBX8888
Definition: SDL_pixels.h:239
NULL
#define NULL
Definition: begin_code.h:167
mode
GLenum mode
Definition: SDL_opengl_glext.h:1122
NativeWindowType
EGLNativeWindowType NativeWindowType
Definition: eglplatform.h:112
SDL_SysWMinfo
Definition: SDL_syswm.h:197
SDL_WindowData
Definition: SDL_androidwindow.h:38
SDL_WINDOW_OPENGL
@ SDL_WINDOW_OPENGL
Definition: SDL_video.h:101
MALI_DestroyWindow
void MALI_DestroyWindow(_THIS, SDL_Window *window)
SDL_GL_LoadLibrary
#define SDL_GL_LoadLibrary
Definition: SDL_dynapi_overrides.h:553
SDL_SetKeyboardFocus
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:630
SDL_VideoDisplay::desktop_mode
SDL_DisplayMode desktop_mode
Definition: SDL_sysvideo.h:131
SDL_GetDisplayDriverData
void * SDL_GetDisplayDriverData(int displayIndex)
Definition: SDL_video.c:660
SDL_SetMouseFocus
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:211
MALI_PumpEvents
void MALI_PumpEvents(_THIS)
SDL_maliopengles.h
SDL_DisplayMode::h
int h
Definition: SDL_video.h:57
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
SDL_DisplayMode
The structure that defines a display mode.
Definition: SDL_video.h:53
SDL_AddDisplayMode
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:754
MALI_SetWindowSize
void MALI_SetWindowSize(_THIS, SDL_Window *window)
MALI_SetDisplayMode
int MALI_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
MALI_GetDisplayModes
void MALI_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
SDL_MINOR_VERSION
#define SDL_MINOR_VERSION
Definition: SDL_version.h:61
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
EGL_NO_SURFACE
#define EGL_NO_SURFACE
Definition: egl.h:100
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
MALI_ShowWindow
void MALI_ShowWindow(_THIS, SDL_Window *window)
SDL_DisplayData::native_display
struct SDL_DisplayData::@262 native_display
SDL_DisplayMode::refresh_rate
int refresh_rate
Definition: SDL_video.h:58
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_DisplayData::height
unsigned short height
Definition: SDL_malivideo.h:44
SDL_DisplayMode::w
int w
Definition: SDL_video.h:56
SDL_AddVideoDisplay
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display)
Definition: SDL_video.c:606
SDL_VideoDisplay::driverdata
void * driverdata
Definition: SDL_sysvideo.h:139
SDL_DisplayData
Definition: SDL_cocoamodes.h:26
MALI_GetWindowWMInfo
SDL_bool MALI_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
SDL_VideoDevice
Definition: SDL_sysvideo.h:148
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_SysWMinfo::version
SDL_version version
Definition: SDL_syswm.h:199
SDL_VideoDisplay
Definition: SDL_sysvideo.h:125
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
MALI_VideoQuit
void MALI_VideoQuit(_THIS)
MALI_CreateWindow
int MALI_CreateWindow(_THIS, SDL_Window *window)
MALI_SetWindowPosition
void MALI_SetWindowPosition(_THIS, SDL_Window *window)
SDL_DisplayMode::driverdata
void * driverdata
Definition: SDL_video.h:59
SDL_version.h
SDL_VideoDisplay::current_mode
SDL_DisplayMode current_mode
Definition: SDL_sysvideo.h:132
fd
GLuint64 GLenum GLint fd
Definition: gl2ext.h:1508
SDL_version::major
Uint8 major
Definition: SDL_version.h:53
MALI_HideWindow
void MALI_HideWindow(_THIS, SDL_Window *window)
VideoBootStrap
Definition: SDL_sysvideo.h:397
SDL_MAJOR_VERSION
#define SDL_MAJOR_VERSION
Definition: SDL_version.h:60
device
static SDL_AudioDeviceID device
Definition: loopwave.c:37
SDL_WindowData::egl_surface
EGLSurface egl_surface
Definition: SDL_androidwindow.h:40
SDL_loadso.h
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161
SDL_syswm.h
SDL_DisplayData::width
unsigned short width
Definition: SDL_malivideo.h:43
MALI_bootstrap
VideoBootStrap MALI_bootstrap