Atlas - SDL_offscreenvideo.c

Home / ext / SDL / src / video / offscreen Lines: 1 | Size: 4952 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 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#ifdef SDL_VIDEO_DRIVER_OFFSCREEN 24 25/* Offscreen video driver is similar to dummy driver, however its purpose 26 * is enabling applications to use some of the SDL video functionality 27 * (notably context creation) while not requiring a display output. 28 * 29 * An example would be running a graphical program on a headless box 30 * for automated testing. 31 */ 32 33#include "SDL_offscreenvideo.h" 34#include "SDL_offscreenevents_c.h" 35#include "SDL_offscreenframebuffer_c.h" 36#include "SDL_offscreenopengles.h" 37#include "SDL_offscreenvulkan.h" 38#include "SDL_offscreenwindow.h" 39 40#define OFFSCREENVID_DRIVER_NAME "offscreen" 41 42// Initialization/Query functions 43static bool OFFSCREEN_VideoInit(SDL_VideoDevice *_this); 44static bool OFFSCREEN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); 45static void OFFSCREEN_VideoQuit(SDL_VideoDevice *_this); 46 47// OFFSCREEN driver bootstrap functions 48 49static void OFFSCREEN_DeleteDevice(SDL_VideoDevice *device) 50{ 51 SDL_free(device); 52} 53 54static bool OFFSCREEN_Available(const char *drivername) 55{ 56 const char *hint = SDL_GetHint(SDL_HINT_VIDEO_DRIVER); 57 if (hint && SDL_strstr(hint, drivername) != NULL) { 58 return true; 59 } 60 return false; 61} 62 63static SDL_VideoDevice *OFFSCREEN_CreateDevice(void) 64{ 65 SDL_VideoDevice *device; 66 67 if (!OFFSCREEN_Available(OFFSCREENVID_DRIVER_NAME)) { 68 return NULL; 69 } 70 71 // Initialize all variables that we clean on shutdown 72 device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); 73 if (!device) { 74 return NULL; 75 } 76 77 // General video 78 device->VideoInit = OFFSCREEN_VideoInit; 79 device->VideoQuit = OFFSCREEN_VideoQuit; 80 device->SetDisplayMode = OFFSCREEN_SetDisplayMode; 81 device->PumpEvents = OFFSCREEN_PumpEvents; 82 device->CreateWindowFramebuffer = SDL_OFFSCREEN_CreateWindowFramebuffer; 83 device->UpdateWindowFramebuffer = SDL_OFFSCREEN_UpdateWindowFramebuffer; 84 device->DestroyWindowFramebuffer = SDL_OFFSCREEN_DestroyWindowFramebuffer; 85 device->free = OFFSCREEN_DeleteDevice; 86 87#ifdef SDL_VIDEO_OPENGL_EGL 88 // GL context 89 device->GL_SwapWindow = OFFSCREEN_GLES_SwapWindow; 90 device->GL_MakeCurrent = OFFSCREEN_GLES_MakeCurrent; 91 device->GL_CreateContext = OFFSCREEN_GLES_CreateContext; 92 device->GL_DestroyContext = OFFSCREEN_GLES_DestroyContext; 93 device->GL_LoadLibrary = OFFSCREEN_GLES_LoadLibrary; 94 device->GL_UnloadLibrary = OFFSCREEN_GLES_UnloadLibrary; 95 device->GL_GetProcAddress = OFFSCREEN_GLES_GetProcAddress; 96 device->GL_GetSwapInterval = OFFSCREEN_GLES_GetSwapInterval; 97 device->GL_SetSwapInterval = OFFSCREEN_GLES_SetSwapInterval; 98#endif 99 100#ifdef SDL_VIDEO_VULKAN 101 device->Vulkan_LoadLibrary = OFFSCREEN_Vulkan_LoadLibrary; 102 device->Vulkan_UnloadLibrary = OFFSCREEN_Vulkan_UnloadLibrary; 103 device->Vulkan_GetInstanceExtensions = OFFSCREEN_Vulkan_GetInstanceExtensions; 104 device->Vulkan_CreateSurface = OFFSCREEN_Vulkan_CreateSurface; 105 device->Vulkan_DestroySurface = OFFSCREEN_Vulkan_DestroySurface; 106#endif 107 108 // "Window" 109 device->CreateSDLWindow = OFFSCREEN_CreateWindow; 110 device->DestroyWindow = OFFSCREEN_DestroyWindow; 111 device->SetWindowSize = OFFSCREEN_SetWindowSize; 112 113 return device; 114} 115 116VideoBootStrap OFFSCREEN_bootstrap = { 117 OFFSCREENVID_DRIVER_NAME, "SDL offscreen video driver", 118 OFFSCREEN_CreateDevice, 119 NULL, // no ShowMessageBox implementation 120 false 121}; 122 123static bool OFFSCREEN_VideoInit(SDL_VideoDevice *_this) 124{ 125 SDL_DisplayMode mode; 126 127 // Use a fake 32-bpp desktop mode 128 SDL_zero(mode); 129 mode.format = SDL_PIXELFORMAT_XRGB8888; 130 mode.w = 1024; 131 mode.h = 768; 132 if (SDL_AddBasicVideoDisplay(&mode) == 0) { 133 return false; 134 } 135 136 // We're done! 137 return true; 138} 139 140static bool OFFSCREEN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) 141{ 142 return true; 143} 144 145void OFFSCREEN_VideoQuit(SDL_VideoDevice *_this) 146{ 147} 148 149#endif // SDL_VIDEO_DRIVER_OFFSCREEN 150
[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.