2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
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.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 /* Dummy SDL video driver implementation; this is just enough to make an
25 * SDL-based application THINK it's got a working video driver, for
26 * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
27 * and also for use as a collection of stubs when porting SDL to a new
28 * platform for which you haven't yet written a valid video driver.
30 * This is also a great way to determine bottlenecks: if you think that SDL
31 * is a performance problem for a given platform, enable this driver, and
32 * then see if your application runs faster without video overhead.
34 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
35 * of this was cut-and-pasted from Stephane Peter's work in the AAlib
36 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
39 #include "SDL_video.h"
40 #include "SDL_mouse.h"
41 #include "../SDL_sysvideo.h"
42 #include "../SDL_pixels_c.h"
43 #include "../../events/SDL_events_c.h"
45 #include "SDL_nullvideo.h"
46 #include "SDL_nullevents_c.h"
47 #include "SDL_nullmouse_c.h"
49 #define DUMMYVID_DRIVER_NAME "dummy"
51 /* Initialization/Query functions */
52 static int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat);
53 static SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
54 static SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
55 static int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
56 static void DUMMY_VideoQuit(_THIS);
58 /* Hardware surface functions */
59 static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface);
60 static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface);
61 static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface);
62 static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface);
65 static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
67 /* DUMMY driver bootstrap functions */
69 static int DUMMY_Available(void)
71 const char *envr = SDL_getenv("SDL_VIDEODRIVER");
72 if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
79 static void DUMMY_DeleteDevice(SDL_VideoDevice *device)
81 SDL_free(device->hidden);
85 static SDL_VideoDevice *DUMMY_CreateDevice(int devindex)
87 SDL_VideoDevice *device;
89 /* Initialize all variables that we clean on shutdown */
90 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
92 SDL_memset(device, 0, (sizeof *device));
93 device->hidden = (struct SDL_PrivateVideoData *)
94 SDL_malloc((sizeof *device->hidden));
96 if ( (device == NULL) || (device->hidden == NULL) ) {
103 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
105 /* Set the function pointers */
106 device->VideoInit = DUMMY_VideoInit;
107 device->ListModes = DUMMY_ListModes;
108 device->SetVideoMode = DUMMY_SetVideoMode;
109 device->CreateYUVOverlay = NULL;
110 device->SetColors = DUMMY_SetColors;
111 device->UpdateRects = DUMMY_UpdateRects;
112 device->VideoQuit = DUMMY_VideoQuit;
113 device->AllocHWSurface = DUMMY_AllocHWSurface;
114 device->CheckHWBlit = NULL;
115 device->FillHWRect = NULL;
116 device->SetHWColorKey = NULL;
117 device->SetHWAlpha = NULL;
118 device->LockHWSurface = DUMMY_LockHWSurface;
119 device->UnlockHWSurface = DUMMY_UnlockHWSurface;
120 device->FlipHWSurface = NULL;
121 device->FreeHWSurface = DUMMY_FreeHWSurface;
122 device->SetCaption = NULL;
123 device->SetIcon = NULL;
124 device->IconifyWindow = NULL;
125 device->GrabInput = NULL;
126 device->GetWMInfo = NULL;
127 device->InitOSKeymap = DUMMY_InitOSKeymap;
128 device->PumpEvents = DUMMY_PumpEvents;
130 device->free = DUMMY_DeleteDevice;
135 VideoBootStrap DUMMY_bootstrap = {
136 DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
137 DUMMY_Available, DUMMY_CreateDevice
141 int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat)
144 fprintf(stderr, "WARNING: You are using the SDL dummy video driver!\n");
147 /* Determine the screen depth (use default 8-bit depth) */
148 /* we change this during the SDL_SetVideoMode implementation... */
149 vformat->BitsPerPixel = 8;
150 vformat->BytesPerPixel = 1;
156 SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
158 return (SDL_Rect **) -1;
161 SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current,
162 int width, int height, int bpp, Uint32 flags)
164 if ( this->hidden->buffer ) {
165 SDL_free( this->hidden->buffer );
168 this->hidden->buffer = SDL_malloc(width * height * (bpp / 8));
169 if ( ! this->hidden->buffer ) {
170 SDL_SetError("Couldn't allocate buffer for requested mode");
174 /* printf("Setting mode %dx%d\n", width, height); */
176 SDL_memset(this->hidden->buffer, 0, width * height * (bpp / 8));
178 /* Allocate the new pixel format for the screen */
179 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
180 SDL_free(this->hidden->buffer);
181 this->hidden->buffer = NULL;
182 SDL_SetError("Couldn't allocate new pixel format for requested mode");
186 /* Set up the new mode framebuffer */
187 current->flags = flags & SDL_FULLSCREEN;
188 this->hidden->w = current->w = width;
189 this->hidden->h = current->h = height;
190 current->pitch = current->w * (bpp / 8);
191 current->pixels = this->hidden->buffer;
197 /* We don't actually allow hardware surfaces other than the main one */
198 static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface)
202 static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface)
207 /* We need to wait for vertical retrace on page flipped displays */
208 static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface)
213 static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface)
218 static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
223 int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
225 /* do nothing of note. */
229 /* Note: If we are terminated, this could be called in the middle of
230 another SDL video routine -- notably UpdateRects.
232 void DUMMY_VideoQuit(_THIS)
234 if (this->screen->pixels != NULL)
236 SDL_free(this->screen->pixels);
237 this->screen->pixels = NULL;