SDL_nullvideo.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_DUMMY
/* Dummy SDL video driver implementation; this is just enough to make an
* SDL-based application THINK it's got a working video driver, for
* applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
* and also for use as a collection of stubs when porting SDL to a new
* platform for which you haven't yet written a valid video driver.
*
* This is also a great way to determine bottlenecks: if you think that SDL
* is a performance problem for a given platform, enable this driver, and
* then see if your application runs faster without video overhead.
*
* Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
* of this was cut-and-pasted from Stephane Peter's work in the AAlib
* SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
*/
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
#include "SDL_nullvideo.h"
#include "SDL_nullevents_c.h"
#include "SDL_nullframebuffer_c.h"
#define DUMMYVID_DRIVER_NAME "dummy"
/* Initialization/Query functions */
static int DUMMY_VideoInit(_THIS);
static int DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
static void DUMMY_VideoQuit(_THIS);
/* DUMMY driver bootstrap functions */
static int
DUMMY_Available(void)
{
const char *envr = SDL_getenv("SDL_VIDEODRIVER");
if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
return (1);
}
return (0);
}
static void
DUMMY_DeleteDevice(SDL_VideoDevice * device)
{
SDL_free(device);
}
static SDL_VideoDevice *
DUMMY_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
SDL_OutOfMemory();
return (0);
}
device->is_dummy = SDL_TRUE;
/* Set the function pointers */
device->VideoInit = DUMMY_VideoInit;
device->VideoQuit = DUMMY_VideoQuit;
device->SetDisplayMode = DUMMY_SetDisplayMode;
device->PumpEvents = DUMMY_PumpEvents;
device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer;
device->free = DUMMY_DeleteDevice;
return device;
}
VideoBootStrap DUMMY_bootstrap = {
DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
DUMMY_Available, DUMMY_CreateDevice
};
int
DUMMY_VideoInit(_THIS)
{
SDL_DisplayMode mode;
/* Use a fake 32-bpp desktop mode */
mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = 1024;
mode.h = 768;
mode.refresh_rate = 0;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}
SDL_zero(mode);
SDL_AddDisplayMode(&_this->displays[0], &mode);
/* We're done! */
return 0;
}
static int
DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
return 0;
}
void
DUMMY_VideoQuit(_THIS)
{
}
#endif /* SDL_VIDEO_DRIVER_DUMMY */
/* vi: set ts=4 sw=4 expandtab: */
SDL_TRUE
Definition: SDL_stdinc.h:142
SDL_DisplayMode::w
int w
Definition: SDL_video.h:56
SDL_VideoDevice::free
void(* free)(_THIS)
Definition: SDL_sysvideo.h:390
SDL_AddBasicVideoDisplay
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
Definition: SDL_video.c:592
SDL_DisplayMode
The structure that defines a display mode.
Definition: SDL_video.h:53
SDL_DisplayMode::refresh_rate
int refresh_rate
Definition: SDL_video.h:58
SDL_VideoDevice::is_dummy
SDL_bool is_dummy
Definition: SDL_sysvideo.h:309
SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:236
SDL_VideoDevice::SetDisplayMode
int(* SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
Definition: SDL_sysvideo.h:204
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
device
static SDL_AudioDeviceID device
Definition: loopwave.c:37
SDL_nullframebuffer_c.h
SDL_video.h
SDL_DUMMY_DestroyWindowFramebuffer
void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
SDL_DUMMY_UpdateWindowFramebuffer
int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_DisplayMode::driverdata
void * driverdata
Definition: SDL_video.h:59
SDL_mouse.h
VideoBootStrap
Definition: SDL_sysvideo.h:393
mode
GLenum mode
Definition: SDL_opengl_glext.h:1122
SDL_VideoDevice::displays
SDL_VideoDisplay * displays
Definition: SDL_sysvideo.h:312
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
SDL_DisplayMode::h
int h
Definition: SDL_video.h:57
DUMMY_PumpEvents
void DUMMY_PumpEvents(_THIS)
SDL_nullvideo.h
SDL_nullevents_c.h
SDL_VideoDisplay
Definition: SDL_sysvideo.h:125
SDL_getenv
#define SDL_getenv
Definition: SDL_dynapi_overrides.h:378
SDL_VideoDevice::DestroyWindowFramebuffer
void(* DestroyWindowFramebuffer)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:237
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_VideoDevice::VideoQuit
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:166
DUMMY_bootstrap
VideoBootStrap DUMMY_bootstrap
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
SDL_VideoDevice
Definition: SDL_sysvideo.h:147
SDL_AddDisplayMode
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:743
SDL_VideoDevice::VideoInit
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:160
SDL_VideoDevice::UpdateWindowFramebuffer
int(* UpdateWindowFramebuffer)(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
Definition: SDL_sysvideo.h:236
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:417
SDL_DisplayMode::format
Uint32 format
Definition: SDL_video.h:55
SDL_VideoDevice::CreateWindowFramebuffer
int(* CreateWindowFramebuffer)(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
Definition: SDL_sysvideo.h:235
SDL_DUMMY_CreateWindowFramebuffer
int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
SDL_VideoDevice::PumpEvents
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:280