1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
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_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 (icculus@icculus.org). 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_video.h"
41 #include "SDL_mouse.h"
42 #include "../SDL_sysvideo.h"
43 #include "../SDL_pixels_c.h"
44 #include "../../events/SDL_events_c.h"
45
46 #include "SDL_nullvideo.h"
47 #include "SDL_nullevents_c.h"
48 #include "SDL_nullframebuffer_c.h"
49
50 #define DUMMYVID_DRIVER_NAME "dummy"
51
52 /* Initialization/Query functions */
53 static int DUMMY_VideoInit(_THIS);
54 static int DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
55 static void DUMMY_VideoQuit(_THIS);
56
57 /* DUMMY driver bootstrap functions */
58
59 static int
DUMMY_Available(void)60 DUMMY_Available(void)
61 {
62 const char *envr = SDL_getenv("SDL_VIDEODRIVER");
63 if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
64 return (1);
65 }
66
67 return (0);
68 }
69
70 static void
DUMMY_DeleteDevice(SDL_VideoDevice * device)71 DUMMY_DeleteDevice(SDL_VideoDevice * device)
72 {
73 SDL_free(device);
74 }
75
76 static SDL_VideoDevice *
DUMMY_CreateDevice(int devindex)77 DUMMY_CreateDevice(int devindex)
78 {
79 SDL_VideoDevice *device;
80
81 /* Initialize all variables that we clean on shutdown */
82 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
83 if (!device) {
84 SDL_OutOfMemory();
85 return (0);
86 }
87
88 /* Set the function pointers */
89 device->VideoInit = DUMMY_VideoInit;
90 device->VideoQuit = DUMMY_VideoQuit;
91 device->SetDisplayMode = DUMMY_SetDisplayMode;
92 device->PumpEvents = DUMMY_PumpEvents;
93 device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer;
94 device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer;
95 device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer;
96
97 device->free = DUMMY_DeleteDevice;
98
99 return device;
100 }
101
102 VideoBootStrap DUMMY_bootstrap = {
103 DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
104 DUMMY_Available, DUMMY_CreateDevice
105 };
106
107
108 int
DUMMY_VideoInit(_THIS)109 DUMMY_VideoInit(_THIS)
110 {
111 SDL_DisplayMode mode;
112
113 /* Use a fake 32-bpp desktop mode */
114 mode.format = SDL_PIXELFORMAT_RGB888;
115 mode.w = 1024;
116 mode.h = 768;
117 mode.refresh_rate = 0;
118 mode.driverdata = NULL;
119 if (SDL_AddBasicVideoDisplay(&mode) < 0) {
120 return -1;
121 }
122
123 SDL_zero(mode);
124 SDL_AddDisplayMode(&_this->displays[0], &mode);
125
126 /* We're done! */
127 return 0;
128 }
129
130 static int
DUMMY_SetDisplayMode(_THIS,SDL_VideoDisplay * display,SDL_DisplayMode * mode)131 DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
132 {
133 return 0;
134 }
135
136 void
DUMMY_VideoQuit(_THIS)137 DUMMY_VideoQuit(_THIS)
138 {
139 }
140
141 #endif /* SDL_VIDEO_DRIVER_DUMMY */
142
143 /* vi: set ts=4 sw=4 expandtab: */
144