This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_nullvideo.c
144 lines (117 loc) · 4.08 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
Sam Lantinga
20
slouken@libsdl.org
21
*/
22
#include "SDL_config.h"
23
24
25
26
27
28
29
30
31
32
33
/* 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.
*
34
* Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
35
36
37
38
39
40
* 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"
41
42
43
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
44
45
46
47
48
#include "SDL_nullvideo.h"
#include "SDL_nullevents_c.h"
#include "SDL_nullmouse_c.h"
49
50
#define DUMMYVID_DRIVER_NAME "dummy"
51
/* Initialization/Query functions */
52
53
54
55
static int DUMMY_VideoInit(_THIS);
static int DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
static void DUMMY_CreateWindowSurface(_THIS, SDL_Window * window,
Uint32 flags);
56
57
static void DUMMY_UpdateWindowSurface(_THIS, SDL_Window * window,
int numrects, SDL_Rect * rects);
58
static void DUMMY_VideoQuit(_THIS);
59
60
61
/* DUMMY driver bootstrap functions */
62
static int
63
DUMMY_Available(void)
64
{
65
66
const char *envr = SDL_getenv("SDL_VIDEODRIVER");
if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
67
68
return (1);
}
69
70
return (0);
71
72
}
73
static void
74
DUMMY_DeleteDevice(SDL_VideoDevice * device)
75
{
76
77
SDL_free(device->hidden);
SDL_free(device);
78
79
}
80
static SDL_VideoDevice *
81
DUMMY_CreateDevice(int devindex)
82
{
83
84
85
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
86
device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
87
if (device) {
88
SDL_memset(device, 0, (sizeof *device));
89
device->hidden = (struct SDL_PrivateVideoData *)
90
SDL_malloc((sizeof *device->hidden));
91
92
}
if ((device == NULL) || (device->hidden == NULL)) {
93
SDL_OutOfMemory();
94
if (device) {
95
SDL_free(device);
96
97
98
}
return (0);
}
99
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
100
101
102
103
104
105
106
107
108
109
/* Set the function pointers */
device->VideoInit = DUMMY_VideoInit;
device->SetDisplayMode = DUMMY_SetDisplayMode;
device->VideoQuit = DUMMY_VideoQuit;
device->PumpEvents = DUMMY_PumpEvents;
device->free = DUMMY_DeleteDevice;
return device;
110
111
112
}
VideoBootStrap DUMMY_bootstrap = {
113
114
DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
DUMMY_Available, DUMMY_CreateDevice
115
116
117
};
118
int
119
DUMMY_VideoInit(_THIS)
120
{
121
122
SDL_DisplayMode mode;
123
SDL_AddBasicVideoDisplay(NULL);
124
125
126
127
SDL_zero(mode);
SDL_AddDisplayMode(0, &mode);
128
129
/* We're done! */
return 0;
130
131
}
132
static int
133
DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode)
134
{
135
SDL_CurrentDisplay.current_mode = *mode;
136
return 0;
137
138
}
139
void
140
DUMMY_VideoQuit(_THIS)
141
142
{
}
143
144
/* vi: set ts=4 sw=4 expandtab: */