Atlas - SDL_vivantevideo.c
Home / ext / SDL2 / src / video / vivante Lines: 1 | Size: 11390 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2018 Sam Lantinga <[email protected]> 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 42static int 43VIVANTE_Available(void) 44{ 45 return 1; 46} 47 48static void 49VIVANTE_Destroy(SDL_VideoDevice * device) 50{ 51 if (device->driverdata != NULL) { 52 SDL_free(device->driverdata); 53 device->driverdata = NULL; 54 } 55} 56 57static SDL_VideoDevice * 58VIVANTE_Create() 59{ 60 SDL_VideoDevice *device; 61 SDL_VideoData *data; 62 63 /* Initialize SDL_VideoDevice structure */ 64 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); 65 if (device == NULL) { 66 SDL_OutOfMemory(); 67 return NULL; 68 } 69 70 /* Initialize internal data */ 71 data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); 72 if (data == NULL) { 73 SDL_OutOfMemory(); 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; 89 device->GetDisplayModes = VIVANTE_GetDisplayModes; 90 device->SetDisplayMode = VIVANTE_SetDisplayMode; 91 device->CreateSDLWindow = 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; 99 100#if SDL_VIDEO_OPENGL_EGL 101 device->GL_LoadLibrary = VIVANTE_GLES_LoadLibrary; 102 device->GL_GetProcAddress = VIVANTE_GLES_GetProcAddress; 103 device->GL_UnloadLibrary = VIVANTE_GLES_UnloadLibrary; 104 device->GL_CreateContext = VIVANTE_GLES_CreateContext; 105 device->GL_MakeCurrent = VIVANTE_GLES_MakeCurrent; 106 device->GL_SetSwapInterval = VIVANTE_GLES_SetSwapInterval; 107 device->GL_GetSwapInterval = VIVANTE_GLES_GetSwapInterval; 108 device->GL_SwapWindow = VIVANTE_GLES_SwapWindow; 109 device->GL_DeleteContext = VIVANTE_GLES_DeleteContext; 110#endif 111 112 device->PumpEvents = VIVANTE_PumpEvents; 113 114 return device; 115} 116 117VideoBootStrap VIVANTE_bootstrap = { 118 "vivante", 119 "Vivante EGL Video Driver", 120 VIVANTE_Available, 121 VIVANTE_Create 122}; 123 124/*****************************************************************************/ 125/* SDL Video and Display initialization/handling functions */ 126/*****************************************************************************/ 127 128static int 129VIVANTE_AddVideoDisplays(_THIS) 130{ 131 SDL_VideoData *videodata = _this->driverdata; 132 SDL_VideoDisplay display; 133 SDL_DisplayMode current_mode; 134 SDL_DisplayData *data; 135 int pitch = 0, bpp = 0; 136 unsigned long pixels = 0; 137 138 data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); 139 if (data == NULL) { 140 return SDL_OutOfMemory(); 141 } 142 143 SDL_zero(current_mode); 144#if SDL_VIDEO_DRIVER_VIVANTE_VDK 145 data->native_display = vdkGetDisplay(videodata->vdk_private); 146 147 vdkGetDisplayInfo(data->native_display, ¤t_mode.w, ¤t_mode.h, &pixels, &pitch, &bpp); 148#else 149 data->native_display = videodata->fbGetDisplayByIndex(0); 150 151 videodata->fbGetDisplayInfo(data->native_display, ¤t_mode.w, ¤t_mode.h, &pixels, &pitch, &bpp); 152#endif /* SDL_VIDEO_DRIVER_VIVANTE_VDK */ 153 154 switch (bpp) 155 { 156 default: /* Is another format used? */ 157 case 32: 158 current_mode.format = SDL_PIXELFORMAT_ARGB8888; 159 break; 160 case 16: 161 current_mode.format = SDL_PIXELFORMAT_RGB565; 162 break; 163 } 164 /* FIXME: How do we query refresh rate? */ 165 current_mode.refresh_rate = 60; 166 167 SDL_zero(display); 168 display.name = VIVANTE_GetDisplayName(_this); 169 display.desktop_mode = current_mode; 170 display.current_mode = current_mode; 171 display.driverdata = data; 172 SDL_AddVideoDisplay(&display); 173 return 0; 174} 175 176int 177VIVANTE_VideoInit(_THIS) 178{ 179 SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; 180 181#if SDL_VIDEO_DRIVER_VIVANTE_VDK 182 videodata->vdk_private = vdkInitialize(); 183 if (!videodata->vdk_private) { 184 return SDL_SetError("vdkInitialize() failed"); 185 } 186#else 187 videodata->egl_handle = SDL_LoadObject("libEGL.so.1"); 188 if (!videodata->egl_handle) { 189 videodata->egl_handle = SDL_LoadObject("libEGL.so"); 190 if (!videodata->egl_handle) { 191 return -1; 192 } 193 } 194#define LOAD_FUNC(NAME) \ 195 videodata->NAME = SDL_LoadFunction(videodata->egl_handle, #NAME); \ 196 if (!videodata->NAME) return -1; 197 198 LOAD_FUNC(fbGetDisplay); 199 LOAD_FUNC(fbGetDisplayByIndex); 200 LOAD_FUNC(fbGetDisplayGeometry); 201 LOAD_FUNC(fbGetDisplayInfo); 202 LOAD_FUNC(fbDestroyDisplay); 203 LOAD_FUNC(fbCreateWindow); 204 LOAD_FUNC(fbGetWindowGeometry); 205 LOAD_FUNC(fbGetWindowInfo); 206 LOAD_FUNC(fbDestroyWindow); 207#endif 208 209 if (VIVANTE_SetupPlatform(_this) < 0) { 210 return -1; 211 } 212 213 if (VIVANTE_AddVideoDisplays(_this) < 0) { 214 return -1; 215 } 216 217 VIVANTE_UpdateDisplayScale(_this); 218 219#ifdef SDL_INPUT_LINUXEV 220 if (SDL_EVDEV_Init() < 0) { 221 return -1; 222 } 223#endif 224 225 return 0; 226} 227 228void 229VIVANTE_VideoQuit(_THIS) 230{ 231 SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; 232 233#ifdef SDL_INPUT_LINUXEV 234 SDL_EVDEV_Quit(); 235#endif 236 237 VIVANTE_CleanupPlatform(_this); 238 239#if SDL_VIDEO_DRIVER_VIVANTE_VDK 240 if (videodata->vdk_private) { 241 vdkExit(videodata->vdk_private); 242 videodata->vdk_private = NULL; 243 } 244#else 245 if (videodata->egl_handle) { 246 SDL_UnloadObject(videodata->egl_handle); 247 videodata->egl_handle = NULL; 248 } 249#endif 250} 251 252void 253VIVANTE_GetDisplayModes(_THIS, SDL_VideoDisplay * display) 254{ 255 /* Only one display mode available, the current one */ 256 SDL_AddDisplayMode(display, &display->current_mode); 257} 258 259int 260VIVANTE_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) 261{ 262 return 0; 263} 264 265int 266VIVANTE_CreateWindow(_THIS, SDL_Window * window) 267{ 268 SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; 269 SDL_DisplayData *displaydata; 270 SDL_WindowData *data; 271 272 displaydata = SDL_GetDisplayDriverData(0); 273 274 /* Allocate window internal data */ 275 data = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); 276 if (data == NULL) { 277 return SDL_OutOfMemory(); 278 } 279 280 /* Setup driver data for this window */ 281 window->driverdata = data; 282 283#if SDL_VIDEO_DRIVER_VIVANTE_VDK 284 data->native_window = vdkCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h); 285#else 286 data->native_window = videodata->fbCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h); 287#endif 288 if (!data->native_window) { 289 return SDL_SetError("VIVANTE: Can't create native window"); 290 } 291 292#if SDL_VIDEO_OPENGL_EGL 293 if (window->flags & SDL_WINDOW_OPENGL) { 294 data->egl_surface = SDL_EGL_CreateSurface(_this, data->native_window); 295 if (data->egl_surface == EGL_NO_SURFACE) { 296 return SDL_SetError("VIVANTE: Can't create EGL surface"); 297 } 298 } else { 299 data->egl_surface = EGL_NO_SURFACE; 300 } 301#endif 302 303 /* Window has been successfully created */ 304 return 0; 305} 306 307void 308VIVANTE_DestroyWindow(_THIS, SDL_Window * window) 309{ 310 SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; 311 SDL_WindowData *data; 312 313 data = window->driverdata; 314 if (data) { 315#if SDL_VIDEO_OPENGL_EGL 316 if (data->egl_surface != EGL_NO_SURFACE) { 317 SDL_EGL_DestroySurface(_this, data->egl_surface); 318 } 319#endif 320 321 if (data->native_window) { 322#if SDL_VIDEO_DRIVER_VIVANTE_VDK 323 vdkDestroyWindow(data->native_window); 324#else 325 videodata->fbDestroyWindow(data->native_window); 326#endif 327 } 328 329 SDL_free(data); 330 } 331 window->driverdata = NULL; 332} 333 334void 335VIVANTE_SetWindowTitle(_THIS, SDL_Window * window) 336{ 337#if SDL_VIDEO_DRIVER_VIVANTE_VDK 338 SDL_WindowData *data = window->driverdata; 339 vdkSetWindowTitle(data->native_window, window->title); 340#endif 341} 342 343void 344VIVANTE_SetWindowPosition(_THIS, SDL_Window * window) 345{ 346 /* FIXME */ 347} 348 349void 350VIVANTE_SetWindowSize(_THIS, SDL_Window * window) 351{ 352 /* FIXME */ 353} 354 355void 356VIVANTE_ShowWindow(_THIS, SDL_Window * window) 357{ 358#if SDL_VIDEO_DRIVER_VIVANTE_VDK 359 SDL_WindowData *data = window->driverdata; 360 vdkShowWindow(data->native_window); 361#endif 362 SDL_SetMouseFocus(window); 363 SDL_SetKeyboardFocus(window); 364} 365 366void 367VIVANTE_HideWindow(_THIS, SDL_Window * window) 368{ 369#if SDL_VIDEO_DRIVER_VIVANTE_VDK 370 SDL_WindowData *data = window->driverdata; 371 vdkHideWindow(data->native_window); 372#endif 373} 374 375/*****************************************************************************/ 376/* SDL Window Manager function */ 377/*****************************************************************************/ 378SDL_bool 379VIVANTE_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info) 380{ 381 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 382 SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(0); 383 384 if (info->version.major == SDL_MAJOR_VERSION && 385 info->version.minor == SDL_MINOR_VERSION) { 386 info->subsystem = SDL_SYSWM_VIVANTE; 387 info->info.vivante.display = displaydata->native_display; 388 info->info.vivante.window = data->native_window; 389 return SDL_TRUE; 390 } else { 391 SDL_SetError("Application not compiled with SDL %d.%d", 392 SDL_MAJOR_VERSION, SDL_MINOR_VERSION); 393 return SDL_FALSE; 394 } 395} 396 397/*****************************************************************************/ 398/* SDL event functions */ 399/*****************************************************************************/ 400void VIVANTE_PumpEvents(_THIS) 401{ 402#ifdef SDL_INPUT_LINUXEV 403 SDL_EVDEV_Poll(); 404#endif 405} 406 407#endif /* SDL_VIDEO_DRIVER_VIVANTE */ 408 409/* vi: set ts=4 sw=4 expandtab: */ 410[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.