comparison src/video/dummy/SDL_nullvideo.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents c439dad53df8
children 7577fd11cee4
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
42 #include "../SDL_pixels_c.h" 42 #include "../SDL_pixels_c.h"
43 #include "../../events/SDL_events_c.h" 43 #include "../../events/SDL_events_c.h"
44 44
45 #include "SDL_nullvideo.h" 45 #include "SDL_nullvideo.h"
46 #include "SDL_nullevents_c.h" 46 #include "SDL_nullevents_c.h"
47 #include "SDL_nullmouse_c.h" 47 #include "SDL_nullrender_c.h"
48 48
49 #define DUMMYVID_DRIVER_NAME "dummy" 49 #define DUMMYVID_DRIVER_NAME "dummy"
50 50
51 /* Initialization/Query functions */ 51 /* Initialization/Query functions */
52 static int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat); 52 static int DUMMY_VideoInit(_THIS);
53 static SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 53 static int DUMMY_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
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); 54 static void DUMMY_VideoQuit(_THIS);
57
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);
63
64 /* etc. */
65 static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
66 55
67 /* DUMMY driver bootstrap functions */ 56 /* DUMMY driver bootstrap functions */
68 57
69 static int DUMMY_Available(void) 58 static int
59 DUMMY_Available(void)
70 { 60 {
71 const char *envr = SDL_getenv("SDL_VIDEODRIVER"); 61 const char *envr = SDL_getenv("SDL_VIDEODRIVER");
72 if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) { 62 if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
73 return(1); 63 return (1);
74 } 64 }
75 65
76 return(0); 66 return (0);
77 } 67 }
78 68
79 static void DUMMY_DeleteDevice(SDL_VideoDevice *device) 69 static void
70 DUMMY_DeleteDevice(SDL_VideoDevice * device)
80 { 71 {
81 SDL_free(device->hidden); 72 SDL_free(device);
82 SDL_free(device);
83 } 73 }
84 74
85 static SDL_VideoDevice *DUMMY_CreateDevice(int devindex) 75 static SDL_VideoDevice *
76 DUMMY_CreateDevice(int devindex)
86 { 77 {
87 SDL_VideoDevice *device; 78 SDL_VideoDevice *device;
88 79
89 /* Initialize all variables that we clean on shutdown */ 80 /* Initialize all variables that we clean on shutdown */
90 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 81 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
91 if ( device ) { 82 if (!device) {
92 SDL_memset(device, 0, (sizeof *device)); 83 SDL_OutOfMemory();
93 device->hidden = (struct SDL_PrivateVideoData *) 84 if (device) {
94 SDL_malloc((sizeof *device->hidden)); 85 SDL_free(device);
95 } 86 }
96 if ( (device == NULL) || (device->hidden == NULL) ) { 87 return (0);
97 SDL_OutOfMemory(); 88 }
98 if ( device ) {
99 SDL_free(device);
100 }
101 return(0);
102 }
103 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
104 89
105 /* Set the function pointers */ 90 /* Set the function pointers */
106 device->VideoInit = DUMMY_VideoInit; 91 device->VideoInit = DUMMY_VideoInit;
107 device->ListModes = DUMMY_ListModes; 92 device->SetDisplayMode = DUMMY_SetDisplayMode;
108 device->SetVideoMode = DUMMY_SetVideoMode; 93 device->VideoQuit = DUMMY_VideoQuit;
109 device->CreateYUVOverlay = NULL; 94 device->PumpEvents = DUMMY_PumpEvents;
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;
129 95
130 device->free = DUMMY_DeleteDevice; 96 device->free = DUMMY_DeleteDevice;
131 97
132 return device; 98 return device;
133 } 99 }
134 100
135 VideoBootStrap DUMMY_bootstrap = { 101 VideoBootStrap DUMMY_bootstrap = {
136 DUMMYVID_DRIVER_NAME, "SDL dummy video driver", 102 DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
137 DUMMY_Available, DUMMY_CreateDevice 103 DUMMY_Available, DUMMY_CreateDevice
138 }; 104 };
139 105
140 106
141 int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat) 107 int
108 DUMMY_VideoInit(_THIS)
142 { 109 {
143 /* 110 SDL_DisplayMode mode;
144 fprintf(stderr, "WARNING: You are using the SDL dummy video driver!\n");
145 */
146 111
147 /* Determine the screen depth (use default 8-bit depth) */ 112 SDL_AddBasicVideoDisplay(NULL);
148 /* we change this during the SDL_SetVideoMode implementation... */ 113 SDL_AddRenderDriver(0, &SDL_DUMMY_RenderDriver);
149 vformat->BitsPerPixel = 8;
150 vformat->BytesPerPixel = 1;
151 114
152 /* We're done! */ 115 SDL_zero(mode);
153 return(0); 116 SDL_AddDisplayMode(0, &mode);
117
118 /* We're done! */
119 return 0;
154 } 120 }
155 121
156 SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 122 static int
123 DUMMY_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
157 { 124 {
158 return (SDL_Rect **) -1; 125 return 0;
159 } 126 }
160 127
161 SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, 128 void
162 int width, int height, int bpp, Uint32 flags) 129 DUMMY_VideoQuit(_THIS)
163 { 130 {
164 if ( this->hidden->buffer ) {
165 SDL_free( this->hidden->buffer );
166 }
167
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");
171 return(NULL);
172 }
173
174 /* printf("Setting mode %dx%d\n", width, height); */
175
176 SDL_memset(this->hidden->buffer, 0, width * height * (bpp / 8));
177
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");
183 return(NULL);
184 }
185
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;
192
193 /* We're done */
194 return(current);
195 } 131 }
196 132
197 /* We don't actually allow hardware surfaces other than the main one */ 133 /* vi: set ts=4 sw=4 expandtab: */
198 static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface)
199 {
200 return(-1);
201 }
202 static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface)
203 {
204 return;
205 }
206
207 /* We need to wait for vertical retrace on page flipped displays */
208 static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface)
209 {
210 return(0);
211 }
212
213 static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface)
214 {
215 return;
216 }
217
218 static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
219 {
220 /* do nothing. */
221 }
222
223 int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
224 {
225 /* do nothing of note. */
226 return(1);
227 }
228
229 /* Note: If we are terminated, this could be called in the middle of
230 another SDL video routine -- notably UpdateRects.
231 */
232 void DUMMY_VideoQuit(_THIS)
233 {
234 if (this->screen->pixels != NULL)
235 {
236 SDL_free(this->screen->pixels);
237 this->screen->pixels = NULL;
238 }
239 }