Atlas - SDL_nullvideo.c

Home / ext / SDL / src / video / dummy Lines: 1 | Size: 5477 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_DUMMY 24 25/* Dummy SDL video driver implementation; this is just enough to make an 26 * SDL-based application THINK it's got a working video driver, for 27 * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it, 28 * and also for use as a collection of stubs when porting SDL to a new 29 * platform for which you haven't yet written a valid video driver. 30 * 31 * This is also a great way to determine bottlenecks: if you think that SDL 32 * is a performance problem for a given platform, enable this driver, and 33 * then see if your application runs faster without video overhead. 34 * 35 * Initial work by Ryan C. Gordon ([email protected]). A good portion 36 * of this was cut-and-pasted from Stephane Peter's work in the AAlib 37 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga. 38 */ 39 40#include "../SDL_sysvideo.h" 41#include "../SDL_pixels_c.h" 42#include "../../events/SDL_events_c.h" 43#ifdef SDL_INPUT_LINUXEV 44#include "../../core/linux/SDL_evdev.h" 45#endif 46 47#include "SDL_nullvideo.h" 48#include "SDL_nullevents_c.h" 49#include "SDL_nullframebuffer_c.h" 50 51#define DUMMYVID_DRIVER_NAME "dummy" 52#define DUMMYVID_DRIVER_EVDEV_NAME "evdev" 53 54// Initialization/Query functions 55static bool DUMMY_VideoInit(SDL_VideoDevice *_this); 56static void DUMMY_VideoQuit(SDL_VideoDevice *_this); 57 58static bool DUMMY_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) 59{ 60 SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, window->pending.x, window->pending.y); 61 return true; 62} 63 64static void DUMMY_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) 65{ 66 SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->pending.w, window->pending.h); 67} 68 69// DUMMY driver bootstrap functions 70 71static bool DUMMY_Available(const char *drivername) 72{ 73 const char *hint = SDL_GetHint(SDL_HINT_VIDEO_DRIVER); 74 if (hint && SDL_strstr(hint, drivername) != NULL) { 75 return true; 76 } 77 return false; 78} 79 80static void DUMMY_DeleteDevice(SDL_VideoDevice *device) 81{ 82 SDL_free(device); 83} 84 85static SDL_VideoDevice *DUMMY_InternalCreateDevice(const char *enable_hint) 86{ 87 SDL_VideoDevice *device; 88 89 if (!DUMMY_Available(enable_hint)) { 90 return NULL; 91 } 92 93 // Initialize all variables that we clean on shutdown 94 device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); 95 if (!device) { 96 return NULL; 97 } 98 device->is_dummy = true; 99 100 // Set the function pointers 101 device->VideoInit = DUMMY_VideoInit; 102 device->VideoQuit = DUMMY_VideoQuit; 103 device->PumpEvents = DUMMY_PumpEvents; 104 device->SetWindowSize = DUMMY_SetWindowSize; 105 device->SetWindowPosition = DUMMY_SetWindowPosition; 106 device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer; 107 device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer; 108 device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer; 109 device->free = DUMMY_DeleteDevice; 110 111 return device; 112} 113 114static SDL_VideoDevice *DUMMY_CreateDevice(void) 115{ 116 return DUMMY_InternalCreateDevice(DUMMYVID_DRIVER_NAME); 117} 118 119VideoBootStrap DUMMY_bootstrap = { 120 DUMMYVID_DRIVER_NAME, "SDL dummy video driver", 121 DUMMY_CreateDevice, 122 NULL, // no ShowMessageBox implementation 123 false 124}; 125 126#ifdef SDL_INPUT_LINUXEV 127 128static void DUMMY_EVDEV_Poll(SDL_VideoDevice *_this) 129{ 130 (void)_this; 131 SDL_EVDEV_Poll(); 132} 133 134static SDL_VideoDevice *DUMMY_EVDEV_CreateDevice(void) 135{ 136 SDL_VideoDevice *device = DUMMY_InternalCreateDevice(DUMMYVID_DRIVER_EVDEV_NAME); 137 if (device) { 138 device->PumpEvents = DUMMY_EVDEV_Poll; 139 } 140 return device; 141} 142 143VideoBootStrap DUMMY_evdev_bootstrap = { 144 DUMMYVID_DRIVER_EVDEV_NAME, "SDL dummy video driver with evdev", 145 DUMMY_EVDEV_CreateDevice, 146 NULL, // no ShowMessageBox implementation 147 false 148}; 149 150#else 151 152static bool DUMMY_SetRelativeMouseMode(bool enabled) 153{ 154 return true; 155} 156 157#endif // SDL_INPUT_LINUXEV 158 159bool DUMMY_VideoInit(SDL_VideoDevice *_this) 160{ 161 SDL_DisplayMode mode; 162 163 // Use a fake 32-bpp desktop mode 164 SDL_zero(mode); 165 mode.format = SDL_PIXELFORMAT_XRGB8888; 166 mode.w = 1024; 167 mode.h = 768; 168 if (SDL_AddBasicVideoDisplay(&mode) == 0) { 169 return false; 170 } 171 172#ifdef SDL_INPUT_LINUXEV 173 SDL_EVDEV_Init(); 174#else 175 SDL_GetMouse()->SetRelativeMouseMode = DUMMY_SetRelativeMouseMode; 176#endif 177 178 // We're done! 179 return true; 180} 181 182void DUMMY_VideoQuit(SDL_VideoDevice *_this) 183{ 184#ifdef SDL_INPUT_LINUXEV 185 SDL_EVDEV_Quit(); 186#endif 187} 188 189#endif // SDL_VIDEO_DRIVER_DUMMY 190
[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.