SDL  2.0
SDL_vivantevideo.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 #include "SDL_vivantevulkan.h"
41 
42 
43 static void
44 VIVANTE_Destroy(SDL_VideoDevice * device)
45 {
46  if (device->driverdata != NULL) {
47  SDL_free(device->driverdata);
48  device->driverdata = NULL;
49  }
50 }
51 
52 static SDL_VideoDevice *
53 VIVANTE_Create()
54 {
57 
58  /* Initialize SDL_VideoDevice structure */
60  if (device == NULL) {
62  return NULL;
63  }
64 
65  /* Initialize internal data */
66  data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
67  if (data == NULL) {
70  return NULL;
71  }
72 
73  device->driverdata = data;
74 
75  /* Setup amount of available displays */
76  device->num_displays = 0;
77 
78  /* Set device free function */
79  device->free = VIVANTE_Destroy;
80 
81  /* Setup all functions which we can handle */
82  device->VideoInit = VIVANTE_VideoInit;
83  device->VideoQuit = VIVANTE_VideoQuit;
84  device->GetDisplayModes = VIVANTE_GetDisplayModes;
85  device->SetDisplayMode = VIVANTE_SetDisplayMode;
86  device->CreateSDLWindow = VIVANTE_CreateWindow;
87  device->SetWindowTitle = VIVANTE_SetWindowTitle;
88  device->SetWindowPosition = VIVANTE_SetWindowPosition;
89  device->SetWindowSize = VIVANTE_SetWindowSize;
90  device->ShowWindow = VIVANTE_ShowWindow;
91  device->HideWindow = VIVANTE_HideWindow;
92  device->DestroyWindow = VIVANTE_DestroyWindow;
93  device->GetWindowWMInfo = VIVANTE_GetWindowWMInfo;
94 
95 #if SDL_VIDEO_OPENGL_EGL
96  device->GL_LoadLibrary = VIVANTE_GLES_LoadLibrary;
97  device->GL_GetProcAddress = VIVANTE_GLES_GetProcAddress;
98  device->GL_UnloadLibrary = VIVANTE_GLES_UnloadLibrary;
99  device->GL_CreateContext = VIVANTE_GLES_CreateContext;
100  device->GL_MakeCurrent = VIVANTE_GLES_MakeCurrent;
101  device->GL_SetSwapInterval = VIVANTE_GLES_SetSwapInterval;
102  device->GL_GetSwapInterval = VIVANTE_GLES_GetSwapInterval;
103  device->GL_SwapWindow = VIVANTE_GLES_SwapWindow;
104  device->GL_DeleteContext = VIVANTE_GLES_DeleteContext;
105 #endif
106 
107 #if SDL_VIDEO_VULKAN
108  device->Vulkan_LoadLibrary = VIVANTE_Vulkan_LoadLibrary;
109  device->Vulkan_UnloadLibrary = VIVANTE_Vulkan_UnloadLibrary;
110  device->Vulkan_GetInstanceExtensions = VIVANTE_Vulkan_GetInstanceExtensions;
111  device->Vulkan_CreateSurface = VIVANTE_Vulkan_CreateSurface;
112 #endif
113 
114  device->PumpEvents = VIVANTE_PumpEvents;
115 
116  return device;
117 }
118 
120  "vivante",
121  "Vivante EGL Video Driver",
122  VIVANTE_Create
123 };
124 
125 /*****************************************************************************/
126 /* SDL Video and Display initialization/handling functions */
127 /*****************************************************************************/
128 
129 static int
130 VIVANTE_AddVideoDisplays(_THIS)
131 {
132  SDL_VideoData *videodata = _this->driverdata;
133  SDL_VideoDisplay display;
134  SDL_DisplayMode current_mode;
136  int pitch = 0, bpp = 0;
137  unsigned long pixels = 0;
138 
140  if (data == NULL) {
141  return SDL_OutOfMemory();
142  }
143 
144  SDL_zero(current_mode);
145 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
146  data->native_display = vdkGetDisplay(videodata->vdk_private);
147 
148  vdkGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
149 #else
150  data->native_display = videodata->fbGetDisplayByIndex(0);
151 
152  videodata->fbGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
153 #endif /* SDL_VIDEO_DRIVER_VIVANTE_VDK */
154 
155  switch (bpp)
156  {
157  default: /* Is another format used? */
158  case 32:
159  current_mode.format = SDL_PIXELFORMAT_ARGB8888;
160  break;
161  case 16:
162  current_mode.format = SDL_PIXELFORMAT_RGB565;
163  break;
164  }
165  /* FIXME: How do we query refresh rate? */
166  current_mode.refresh_rate = 60;
167 
168  SDL_zero(display);
169  display.name = VIVANTE_GetDisplayName(_this);
170  display.desktop_mode = current_mode;
171  display.current_mode = current_mode;
172  display.driverdata = data;
173  SDL_AddVideoDisplay(&display, SDL_FALSE);
174  return 0;
175 }
176 
177 int
179 {
180  SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
181 
182 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
183  videodata->vdk_private = vdkInitialize();
184  if (!videodata->vdk_private) {
185  return SDL_SetError("vdkInitialize() failed");
186  }
187 #else
188  videodata->egl_handle = SDL_LoadObject("libEGL.so.1");
189  if (!videodata->egl_handle) {
190  videodata->egl_handle = SDL_LoadObject("libEGL.so");
191  if (!videodata->egl_handle) {
192  return -1;
193  }
194  }
195 #define LOAD_FUNC(NAME) \
196  videodata->NAME = SDL_LoadFunction(videodata->egl_handle, #NAME); \
197  if (!videodata->NAME) return -1;
198 
199  LOAD_FUNC(fbGetDisplay);
200  LOAD_FUNC(fbGetDisplayByIndex);
201  LOAD_FUNC(fbGetDisplayGeometry);
202  LOAD_FUNC(fbGetDisplayInfo);
203  LOAD_FUNC(fbDestroyDisplay);
204  LOAD_FUNC(fbCreateWindow);
205  LOAD_FUNC(fbGetWindowGeometry);
206  LOAD_FUNC(fbGetWindowInfo);
207  LOAD_FUNC(fbDestroyWindow);
208 #endif
209 
210  if (VIVANTE_SetupPlatform(_this) < 0) {
211  return -1;
212  }
213 
214  if (VIVANTE_AddVideoDisplays(_this) < 0) {
215  return -1;
216  }
217 
218  VIVANTE_UpdateDisplayScale(_this);
219 
220 #ifdef SDL_INPUT_LINUXEV
221  if (SDL_EVDEV_Init() < 0) {
222  return -1;
223  }
224 #endif
225 
226  return 0;
227 }
228 
229 void
231 {
232  SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
233 
234 #ifdef SDL_INPUT_LINUXEV
235  SDL_EVDEV_Quit();
236 #endif
237 
238  VIVANTE_CleanupPlatform(_this);
239 
240 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
241  if (videodata->vdk_private) {
242  vdkExit(videodata->vdk_private);
243  videodata->vdk_private = NULL;
244  }
245 #else
246  if (videodata->egl_handle) {
247  SDL_UnloadObject(videodata->egl_handle);
248  videodata->egl_handle = NULL;
249  }
250 #endif
251 }
252 
253 void
255 {
256  /* Only one display mode available, the current one */
257  SDL_AddDisplayMode(display, &display->current_mode);
258 }
259 
260 int
262 {
263  return 0;
264 }
265 
266 int
268 {
269  SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
270  SDL_DisplayData *displaydata;
272 
273  displaydata = SDL_GetDisplayDriverData(0);
274 
275  /* Allocate window internal data */
276  data = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
277  if (data == NULL) {
278  return SDL_OutOfMemory();
279  }
280 
281  /* Setup driver data for this window */
282  window->driverdata = data;
283 
284 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
285  data->native_window = vdkCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
286 #else
287  data->native_window = videodata->fbCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
288 #endif
289  if (!data->native_window) {
290  return SDL_SetError("VIVANTE: Can't create native window");
291  }
292 
293 #if SDL_VIDEO_OPENGL_EGL
294  if (window->flags & SDL_WINDOW_OPENGL) {
295  data->egl_surface = SDL_EGL_CreateSurface(_this, data->native_window);
296  if (data->egl_surface == EGL_NO_SURFACE) {
297  return SDL_SetError("VIVANTE: Can't create EGL surface");
298  }
299  } else {
300  data->egl_surface = EGL_NO_SURFACE;
301  }
302 #endif
303 
304  /* Window has been successfully created */
305  return 0;
306 }
307 
308 void
310 {
311  SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
313 
314  data = window->driverdata;
315  if (data) {
316 #if SDL_VIDEO_OPENGL_EGL
317  if (data->egl_surface != EGL_NO_SURFACE) {
318  SDL_EGL_DestroySurface(_this, data->egl_surface);
319  }
320 #endif
321 
322  if (data->native_window) {
323 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
324  vdkDestroyWindow(data->native_window);
325 #else
326  videodata->fbDestroyWindow(data->native_window);
327 #endif
328  }
329 
330  SDL_free(data);
331  }
332  window->driverdata = NULL;
333 }
334 
335 void
337 {
338 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
339  SDL_WindowData *data = window->driverdata;
340  vdkSetWindowTitle(data->native_window, window->title);
341 #endif
342 }
343 
344 void
346 {
347  /* FIXME */
348 }
349 
350 void
352 {
353  /* FIXME */
354 }
355 
356 void
358 {
359 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
360  SDL_WindowData *data = window->driverdata;
361  vdkShowWindow(data->native_window);
362 #endif
365 }
366 
367 void
369 {
370 #if SDL_VIDEO_DRIVER_VIVANTE_VDK
371  SDL_WindowData *data = window->driverdata;
372  vdkHideWindow(data->native_window);
373 #endif
374 }
375 
376 /*****************************************************************************/
377 /* SDL Window Manager function */
378 /*****************************************************************************/
379 SDL_bool
381 {
382  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
383  SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(0);
384 
385  if (info->version.major == SDL_MAJOR_VERSION &&
386  info->version.minor == SDL_MINOR_VERSION) {
388  info->info.vivante.display = displaydata->native_display;
389  info->info.vivante.window = data->native_window;
390  return SDL_TRUE;
391  } else {
392  SDL_SetError("Application not compiled with SDL %d.%d",
394  return SDL_FALSE;
395  }
396 }
397 
398 /*****************************************************************************/
399 /* SDL event functions */
400 /*****************************************************************************/
402 {
403 #ifdef SDL_INPUT_LINUXEV
404  SDL_EVDEV_Poll();
405 #endif
406 }
407 
408 #endif /* SDL_VIDEO_DRIVER_VIVANTE */
409 
410 /* vi: set ts=4 sw=4 expandtab: */
#define _THIS
#define SDL_SetError
#define SDL_LoadObject
#define SDL_UnloadObject
#define SDL_free
#define SDL_calloc
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:634
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:208
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLenum mode
@ SDL_PIXELFORMAT_ARGB8888
Definition: SDL_pixels.h:257
@ SDL_PIXELFORMAT_RGB565
Definition: SDL_pixels.h:231
#define SDL_zero(x)
Definition: SDL_stdinc.h:426
SDL_bool
Definition: SDL_stdinc.h:168
@ SDL_TRUE
Definition: SDL_stdinc.h:170
@ SDL_FALSE
Definition: SDL_stdinc.h:169
void * SDL_GetDisplayDriverData(int displayIndex)
Definition: SDL_video.c:680
VideoBootStrap VIVANTE_bootstrap
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event)
Definition: SDL_video.c:607
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:792
@ SDL_SYSWM_VIVANTE
Definition: SDL_syswm.h:139
#define SDL_MINOR_VERSION
Definition: SDL_version.h:61
#define SDL_MAJOR_VERSION
Definition: SDL_version.h:60
static SDL_VideoDevice * _this
Definition: SDL_video.c:126
@ SDL_WINDOW_OPENGL
Definition: SDL_video.h:100
void VIVANTE_PumpEvents(_THIS)
void VIVANTE_VideoQuit(_THIS)
void VIVANTE_SetWindowPosition(_THIS, SDL_Window *window)
void VIVANTE_SetWindowSize(_THIS, SDL_Window *window)
int VIVANTE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
int VIVANTE_VideoInit(_THIS)
void VIVANTE_ShowWindow(_THIS, SDL_Window *window)
SDL_bool VIVANTE_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void VIVANTE_SetWindowTitle(_THIS, SDL_Window *window)
void VIVANTE_HideWindow(_THIS, SDL_Window *window)
int VIVANTE_CreateWindow(_THIS, SDL_Window *window)
void VIVANTE_DestroyWindow(_THIS, SDL_Window *window)
void VIVANTE_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
#define NULL
Definition: begin_code.h:163
#define EGL_NO_SURFACE
Definition: egl.h:100
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
#define SDL_INPUT_LINUXEV
Definition: SDL_config.h:293
static SDL_AudioDeviceID device
Definition: loopwave.c:37
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
The structure that defines a display mode.
Definition: SDL_video.h:54
Uint32 format
Definition: SDL_video.h:55
union SDL_SysWMinfo::@10 info
SDL_SYSWM_TYPE subsystem
Definition: SDL_syswm.h:219
Display * display
Definition: SDL_syswm.h:239
Window window
Definition: SDL_syswm.h:240
SDL_version version
Definition: SDL_syswm.h:218
SDL_DisplayMode desktop_mode
Definition: SDL_sysvideo.h:132
SDL_DisplayMode current_mode
Definition: SDL_sysvideo.h:133
The type used to identify a window.
Definition: SDL_sysvideo.h:75
Uint8 minor
Definition: SDL_version.h:54
Uint8 major
Definition: SDL_version.h:53