Atlas - SDL_nullvideo.c

Home / ext / SDL / src / video / dummy Lines: 1 | Size: 6018 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 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_VideoInitCommon(SDL_VideoDevice *_this); 56static bool DUMMY_VideoInit(SDL_VideoDevice *_this); 57static void DUMMY_VideoQuit(SDL_VideoDevice *_this); 58#ifdef SDL_INPUT_LINUXEV 59static bool DUMMY_EVDEV_VideoInit(SDL_VideoDevice *_this); 60static void DUMMY_EVDEV_VideoQuit(SDL_VideoDevice *_this); 61#endif 62 63static bool DUMMY_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) 64{ 65 SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, window->pending.x, window->pending.y); 66 return true; 67} 68 69static void DUMMY_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) 70{ 71 SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->pending.w, window->pending.h); 72} 73 74// DUMMY driver bootstrap functions 75 76static bool DUMMY_Available(const char *drivername) 77{ 78 const char *hint = SDL_GetHint(SDL_HINT_VIDEO_DRIVER); 79 if (hint && SDL_strstr(hint, drivername) != NULL) { 80 return true; 81 } 82 return false; 83} 84 85static void DUMMY_DeleteDevice(SDL_VideoDevice *device) 86{ 87 SDL_free(device); 88} 89 90static SDL_VideoDevice *DUMMY_InternalCreateDevice(const char *enable_hint) 91{ 92 SDL_VideoDevice *device; 93 94 if (!DUMMY_Available(enable_hint)) { 95 return NULL; 96 } 97 98 // Initialize all variables that we clean on shutdown 99 device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); 100 if (!device) { 101 return NULL; 102 } 103 104 // Set the function pointers 105 device->VideoInit = DUMMY_VideoInit; 106 device->VideoQuit = DUMMY_VideoQuit; 107 device->PumpEvents = DUMMY_PumpEvents; 108 device->SetWindowSize = DUMMY_SetWindowSize; 109 device->SetWindowPosition = DUMMY_SetWindowPosition; 110 device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer; 111 device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer; 112 device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer; 113 device->free = DUMMY_DeleteDevice; 114 115 return device; 116} 117 118static SDL_VideoDevice *DUMMY_CreateDevice(void) 119{ 120 return DUMMY_InternalCreateDevice(DUMMYVID_DRIVER_NAME); 121} 122 123VideoBootStrap DUMMY_bootstrap = { 124 DUMMYVID_DRIVER_NAME, "SDL dummy video driver", 125 DUMMY_CreateDevice, 126 NULL, // no ShowMessageBox implementation 127 false 128}; 129 130#ifdef SDL_INPUT_LINUXEV 131 132static bool DUMMY_EVDEV_VideoInit(SDL_VideoDevice *_this) 133{ 134 if (!DUMMY_VideoInitCommon(_this)) { 135 return false; 136 } 137 138 SDL_EVDEV_Init(); 139 return true; 140} 141 142static void DUMMY_EVDEV_VideoQuit(SDL_VideoDevice *_this) 143{ 144 SDL_EVDEV_Quit(); 145} 146 147static void DUMMY_EVDEV_Poll(SDL_VideoDevice *_this) 148{ 149 (void)_this; 150 SDL_EVDEV_Poll(); 151} 152 153static SDL_VideoDevice *DUMMY_EVDEV_CreateDevice(void) 154{ 155 SDL_VideoDevice *device = DUMMY_InternalCreateDevice(DUMMYVID_DRIVER_EVDEV_NAME); 156 if (device) { 157 device->VideoInit = DUMMY_EVDEV_VideoInit; 158 device->VideoQuit = DUMMY_EVDEV_VideoQuit; 159 device->PumpEvents = DUMMY_EVDEV_Poll; 160 } 161 return device; 162} 163 164VideoBootStrap DUMMY_evdev_bootstrap = { 165 DUMMYVID_DRIVER_EVDEV_NAME, "SDL dummy video driver with evdev", 166 DUMMY_EVDEV_CreateDevice, 167 NULL, // no ShowMessageBox implementation 168 false 169}; 170 171#endif // SDL_INPUT_LINUXEV 172 173static bool DUMMY_SetRelativeMouseMode(bool enabled) 174{ 175 return true; 176} 177 178bool DUMMY_VideoInitCommon(SDL_VideoDevice *_this) 179{ 180 SDL_DisplayMode mode; 181 182 // Use a fake 32-bpp desktop mode 183 SDL_zero(mode); 184 mode.format = SDL_PIXELFORMAT_XRGB8888; 185 mode.w = 1024; 186 mode.h = 768; 187 if (SDL_AddBasicVideoDisplay(&mode) == 0) { 188 return false; 189 } 190 191 return true; 192} 193 194bool DUMMY_VideoInit(SDL_VideoDevice *_this) 195{ 196 if (!DUMMY_VideoInitCommon(_this)) { 197 return false; 198 } 199 200 SDL_GetMouse()->SetRelativeMouseMode = DUMMY_SetRelativeMouseMode; 201 return true; 202} 203 204void DUMMY_VideoQuit(SDL_VideoDevice *_this) 205{ 206} 207 208#endif // SDL_VIDEO_DRIVER_DUMMY 209
[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.