comparison src/video/dummy/SDL_nullvideo.c @ 1:cf2af46e9e2a

Changes since SDL 1.2.0 release
author Sam Lantinga <slouken@lokigames.com>
date Thu, 26 Apr 2001 16:50:19 +0000
parents
children 13e4c612098d
comparison
equal deleted inserted replaced
0:74212992fb08 1:cf2af46e9e2a
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
27
28 /* Dummy SDL video driver implementation; this is just enough to make an
29 * SDL-based application THINK it's got a working video driver, for
30 * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
31 * and also for use as a collection of stubs when porting SDL to a new
32 * platform for which you haven't yet written a valid video driver.
33 *
34 * This is also a great way to determine bottlenecks: if you think that SDL
35 * is a performance problem for a given platform, enable this driver, and
36 * then see if your application runs faster without video overhead.
37 *
38 * Initial work by Ryan C. Gordon (icculus@linuxgames.com). A good portion
39 * of this was cut-and-pasted from Stephane Peter's work in the AAlib
40 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
41 */
42
43 #include <stdio.h>
44 #include <stdlib.h>
45
46 #include "SDL.h"
47 #include "SDL_error.h"
48 #include "SDL_video.h"
49 #include "SDL_mouse.h"
50 #include "SDL_sysvideo.h"
51 #include "SDL_pixels_c.h"
52 #include "SDL_events_c.h"
53
54 #include "SDL_nullvideo.h"
55 #include "SDL_nullevents_c.h"
56 #include "SDL_nullmouse_c.h"
57
58 /* Initialization/Query functions */
59 static int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat);
60 static SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
61 static SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
62 static int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
63 static void DUMMY_VideoQuit(_THIS);
64
65 /* Hardware surface functions */
66 static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface);
67 static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface);
68 static int DUMMY_FlipHWSurface(_THIS, SDL_Surface *surface);
69 static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface);
70 static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface);
71
72 /* etc. */
73 static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
74
75 /* DUMMY driver bootstrap functions */
76
77 static int DUMMY_Available(void)
78 {
79 return 1; /* Always available ! */
80 }
81
82 static void DUMMY_DeleteDevice(SDL_VideoDevice *device)
83 {
84 free(device->hidden);
85 free(device);
86 }
87
88 static SDL_VideoDevice *DUMMY_CreateDevice(int devindex)
89 {
90 SDL_VideoDevice *device;
91
92 /* Initialize all variables that we clean on shutdown */
93 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
94 if ( device ) {
95 memset(device, 0, (sizeof *device));
96 device->hidden = (struct SDL_PrivateVideoData *)
97 malloc((sizeof *device->hidden));
98 }
99 if ( (device == NULL) || (device->hidden == NULL) ) {
100 SDL_OutOfMemory();
101 if ( device ) {
102 free(device);
103 }
104 return(0);
105 }
106 memset(device->hidden, 0, (sizeof *device->hidden));
107
108 /* Set the function pointers */
109 device->VideoInit = DUMMY_VideoInit;
110 device->ListModes = DUMMY_ListModes;
111 device->SetVideoMode = DUMMY_SetVideoMode;
112 device->CreateYUVOverlay = NULL;
113 device->SetColors = DUMMY_SetColors;
114 device->UpdateRects = DUMMY_UpdateRects;
115 device->VideoQuit = DUMMY_VideoQuit;
116 device->AllocHWSurface = DUMMY_AllocHWSurface;
117 device->CheckHWBlit = NULL;
118 device->FillHWRect = NULL;
119 device->SetHWColorKey = NULL;
120 device->SetHWAlpha = NULL;
121 device->LockHWSurface = DUMMY_LockHWSurface;
122 device->UnlockHWSurface = DUMMY_UnlockHWSurface;
123 device->FlipHWSurface = NULL;
124 device->FreeHWSurface = DUMMY_FreeHWSurface;
125 device->SetCaption = NULL;
126 device->SetIcon = NULL;
127 device->IconifyWindow = NULL;
128 device->GrabInput = NULL;
129 device->GetWMInfo = NULL;
130 device->InitOSKeymap = DUMMY_InitOSKeymap;
131 device->PumpEvents = DUMMY_PumpEvents;
132
133 device->free = DUMMY_DeleteDevice;
134
135 return device;
136 }
137
138 VideoBootStrap DUMMY_bootstrap = {
139 "dummy", "SDL dummy video driver",
140 DUMMY_Available, DUMMY_CreateDevice
141 };
142
143
144 int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat)
145 {
146 fprintf(stderr, "WARNING: You are using the SDL dummy video driver!\n");
147
148 /* Determine the screen depth (use default 8-bit depth) */
149 /* we change this during the SDL_SetVideoMode implementation... */
150 vformat->BitsPerPixel = 8;
151 vformat->BytesPerPixel = 1;
152
153 /* We're done! */
154 return(0);
155 }
156
157 SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
158 {
159 return (SDL_Rect **) -1;
160 }
161
162 SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current,
163 int width, int height, int bpp, Uint32 flags)
164 {
165 if ( this->hidden->buffer ) {
166 free( this->hidden->buffer );
167 }
168
169 this->hidden->buffer = malloc(width * height * (bpp / 8));
170 if ( ! this->hidden->buffer ) {
171 SDL_SetError("Couldn't allocate buffer for requested mode");
172 return(NULL);
173 }
174
175 /* printf("Setting mode %dx%d\n", width, height); */
176
177 memset(this->hidden->buffer, 0, width * height * (bpp / 8));
178
179 /* Allocate the new pixel format for the screen */
180 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
181 free(this->hidden->buffer);
182 this->hidden->buffer = NULL;
183 SDL_SetError("Couldn't allocate new pixel format for requested mode");
184 return(NULL);
185 }
186
187 /* Set up the new mode framebuffer */
188 current->flags = flags & SDL_FULLSCREEN;
189 this->hidden->w = current->w = width;
190 this->hidden->h = current->h = height;
191 current->pitch = current->w * (bpp / 8);
192 current->pixels = this->hidden->buffer;
193
194 /* We're done */
195 return(current);
196 }
197
198 /* We don't actually allow hardware surfaces other than the main one */
199 static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface)
200 {
201 return(-1);
202 }
203 static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface)
204 {
205 return;
206 }
207
208 /* We need to wait for vertical retrace on page flipped displays */
209 static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface)
210 {
211 return(0);
212 }
213
214 static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface)
215 {
216 return;
217 }
218
219 static int DUMMY_FlipHWSurface(_THIS, SDL_Surface *surface)
220 {
221 return(0);
222 }
223
224 static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
225 {
226 /* do nothing. */
227 }
228
229 int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
230 {
231 /* do nothing of note. */
232 return(1);
233 }
234
235 /* Note: If we are terminated, this could be called in the middle of
236 another SDL video routine -- notably UpdateRects.
237 */
238 void DUMMY_VideoQuit(_THIS)
239 {
240 if (this->screen->pixels != NULL)
241 {
242 free(this->screen->pixels);
243 this->screen->pixels = NULL;
244 }
245 }