comparison src/video/ggi/SDL_ggivideo.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
47 }; 47 };
48 48
49 ggi_visual_t VIS; 49 ggi_visual_t VIS;
50 50
51 /* Initialization/Query functions */ 51 /* Initialization/Query functions */
52 static int GGI_VideoInit (_THIS, SDL_PixelFormat * vformat); 52 static int GGI_VideoInit(_THIS, SDL_PixelFormat * vformat);
53 static SDL_Rect **GGI_ListModes (_THIS, SDL_PixelFormat * format, 53 static SDL_Rect **GGI_ListModes(_THIS, SDL_PixelFormat * format,
54 Uint32 flags); 54 Uint32 flags);
55 static SDL_Surface *GGI_SetVideoMode (_THIS, SDL_Surface * current, int width, 55 static SDL_Surface *GGI_SetVideoMode(_THIS, SDL_Surface * current, int width,
56 int height, int bpp, Uint32 flags); 56 int height, int bpp, Uint32 flags);
57 static int GGI_SetColors (_THIS, int firstcolor, int ncolors, 57 static int GGI_SetColors(_THIS, int firstcolor, int ncolors,
58 SDL_Color * colors); 58 SDL_Color * colors);
59 static void GGI_VideoQuit (_THIS); 59 static void GGI_VideoQuit(_THIS);
60 60
61 /* Hardware surface functions */ 61 /* Hardware surface functions */
62 static int GGI_AllocHWSurface (_THIS, SDL_Surface * surface); 62 static int GGI_AllocHWSurface(_THIS, SDL_Surface * surface);
63 static int GGI_LockHWSurface (_THIS, SDL_Surface * surface); 63 static int GGI_LockHWSurface(_THIS, SDL_Surface * surface);
64 static void GGI_UnlockHWSurface (_THIS, SDL_Surface * surface); 64 static void GGI_UnlockHWSurface(_THIS, SDL_Surface * surface);
65 static void GGI_FreeHWSurface (_THIS, SDL_Surface * surface); 65 static void GGI_FreeHWSurface(_THIS, SDL_Surface * surface);
66 66
67 /* GGI driver bootstrap functions */ 67 /* GGI driver bootstrap functions */
68 68
69 static int 69 static int
70 GGI_Available (void) 70 GGI_Available(void)
71 { 71 {
72 ggi_visual_t *vis; 72 ggi_visual_t *vis;
73 73
74 vis = NULL; 74 vis = NULL;
75 if (ggiInit () == 0) { 75 if (ggiInit() == 0) {
76 vis = ggiOpen (NULL); 76 vis = ggiOpen(NULL);
77 if (vis != NULL) { 77 if (vis != NULL) {
78 ggiClose (vis); 78 ggiClose(vis);
79 } 79 }
80 } 80 }
81 return (vis != NULL); 81 return (vis != NULL);
82 } 82 }
83 83
84 static void 84 static void
85 GGI_DeleteDevice (SDL_VideoDevice * device) 85 GGI_DeleteDevice(SDL_VideoDevice * device)
86 { 86 {
87 SDL_free (device->hidden); 87 SDL_free(device->hidden);
88 SDL_free (device); 88 SDL_free(device);
89 } 89 }
90 90
91 static SDL_VideoDevice * 91 static SDL_VideoDevice *
92 GGI_CreateDevice (int devindex) 92 GGI_CreateDevice(int devindex)
93 { 93 {
94 SDL_VideoDevice *device; 94 SDL_VideoDevice *device;
95 95
96 /* Initialize all variables that we clean on shutdown */ 96 /* Initialize all variables that we clean on shutdown */
97 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 97 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
98 if (device) { 98 if (device) {
99 SDL_memset (device, 0, (sizeof *device)); 99 SDL_memset(device, 0, (sizeof *device));
100 device->hidden = (struct SDL_PrivateVideoData *) 100 device->hidden = (struct SDL_PrivateVideoData *)
101 SDL_malloc ((sizeof *device->hidden)); 101 SDL_malloc((sizeof *device->hidden));
102 } 102 }
103 if ((device == NULL) || (device->hidden == NULL)) { 103 if ((device == NULL) || (device->hidden == NULL)) {
104 SDL_OutOfMemory (); 104 SDL_OutOfMemory();
105 if (device) { 105 if (device) {
106 SDL_free (device); 106 SDL_free(device);
107 } 107 }
108 return (0); 108 return (0);
109 } 109 }
110 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 110 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
111 111
112 /* Set the function pointers */ 112 /* Set the function pointers */
113 device->VideoInit = GGI_VideoInit; 113 device->VideoInit = GGI_VideoInit;
114 device->ListModes = GGI_ListModes; 114 device->ListModes = GGI_ListModes;
115 device->SetVideoMode = GGI_SetVideoMode; 115 device->SetVideoMode = GGI_SetVideoMode;
146 146
147 static SDL_Rect video_mode; 147 static SDL_Rect video_mode;
148 static SDL_Rect *SDL_modelist[4] = { NULL, NULL, NULL, NULL }; 148 static SDL_Rect *SDL_modelist[4] = { NULL, NULL, NULL, NULL };
149 149
150 int 150 int
151 GGI_VideoInit (_THIS, SDL_PixelFormat * vformat) 151 GGI_VideoInit(_THIS, SDL_PixelFormat * vformat)
152 { 152 {
153 ggi_mode mode = { 153 ggi_mode mode = {
154 1, 154 1,
155 {GGI_AUTO, GGI_AUTO}, 155 {GGI_AUTO, GGI_AUTO},
156 {GGI_AUTO, GGI_AUTO}, 156 {GGI_AUTO, GGI_AUTO},
162 ggi_color pal[256], map[256]; 162 ggi_color pal[256], map[256];
163 const ggi_directbuffer *db; 163 const ggi_directbuffer *db;
164 int err, num_bufs; 164 int err, num_bufs;
165 ggi_pixel white, black; 165 ggi_pixel white, black;
166 166
167 priv = SDL_malloc (sizeof (struct private_hwdata)); 167 priv = SDL_malloc(sizeof(struct private_hwdata));
168 if (priv == NULL) { 168 if (priv == NULL) {
169 SDL_SetError ("Unhandled GGI mode type!\n"); 169 SDL_SetError("Unhandled GGI mode type!\n");
170 GGI_VideoQuit (NULL); 170 GGI_VideoQuit(NULL);
171 } 171 }
172 172
173 if (ggiInit () != 0) { 173 if (ggiInit() != 0) {
174 SDL_SetError ("Unable to initialize GGI!\n"); 174 SDL_SetError("Unable to initialize GGI!\n");
175 GGI_VideoQuit (NULL); 175 GGI_VideoQuit(NULL);
176 } 176 }
177 177
178 VIS = ggiOpen (NULL); 178 VIS = ggiOpen(NULL);
179 if (VIS == NULL) { 179 if (VIS == NULL) {
180 SDL_SetError ("Unable to open default GGI visual!\n"); 180 SDL_SetError("Unable to open default GGI visual!\n");
181 ggiExit (); 181 ggiExit();
182 GGI_VideoQuit (NULL); 182 GGI_VideoQuit(NULL);
183 } 183 }
184 184
185 ggiSetFlags (VIS, GGIFLAG_ASYNC); 185 ggiSetFlags(VIS, GGIFLAG_ASYNC);
186 186
187 /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ 187 /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */
188 ggiCheckMode (VIS, &mode); 188 ggiCheckMode(VIS, &mode);
189 189
190 /* At this point we should have a valid mode - try to set it */ 190 /* At this point we should have a valid mode - try to set it */
191 err = ggiSetMode (VIS, &mode); 191 err = ggiSetMode(VIS, &mode);
192 192
193 /* If we couldn't set _any_ modes, something is very wrong */ 193 /* If we couldn't set _any_ modes, something is very wrong */
194 if (err) { 194 if (err) {
195 SDL_SetError ("Can't set a mode!\n"); 195 SDL_SetError("Can't set a mode!\n");
196 ggiClose (VIS); 196 ggiClose(VIS);
197 ggiExit (); 197 ggiExit();
198 GGI_VideoQuit (NULL); 198 GGI_VideoQuit(NULL);
199 } 199 }
200 200
201 /* Determine the current screen size */ 201 /* Determine the current screen size */
202 this->info.current_w = mode.virt.x; 202 this->info.current_w = mode.virt.x;
203 this->info.current_h = mode.virt.y; 203 this->info.current_h = mode.virt.y;
204 204
205 /* Set a palette for palletized modes */ 205 /* Set a palette for palletized modes */
206 if (GT_SCHEME (mode.graphtype) == GT_PALETTE) { 206 if (GT_SCHEME(mode.graphtype) == GT_PALETTE) {
207 ggiSetColorfulPalette (VIS); 207 ggiSetColorfulPalette(VIS);
208 ggiGetPalette (VIS, 0, 1 << vformat->BitsPerPixel, pal); 208 ggiGetPalette(VIS, 0, 1 << vformat->BitsPerPixel, pal);
209 } 209 }
210 210
211 /* Now we try to get the DirectBuffer info, which determines whether 211 /* Now we try to get the DirectBuffer info, which determines whether
212 * SDL can access hardware surfaces directly. */ 212 * SDL can access hardware surfaces directly. */
213 213
214 num_bufs = ggiDBGetNumBuffers (VIS); 214 num_bufs = ggiDBGetNumBuffers(VIS);
215 215
216 if (num_bufs > 0) { 216 if (num_bufs > 0) {
217 db = ggiDBGetBuffer (VIS, 0); /* Only handle one DB for now */ 217 db = ggiDBGetBuffer(VIS, 0); /* Only handle one DB for now */
218 218
219 vformat->BitsPerPixel = db->buffer.plb.pixelformat->depth; 219 vformat->BitsPerPixel = db->buffer.plb.pixelformat->depth;
220 220
221 vformat->Rmask = db->buffer.plb.pixelformat->red_mask; 221 vformat->Rmask = db->buffer.plb.pixelformat->red_mask;
222 vformat->Gmask = db->buffer.plb.pixelformat->green_mask; 222 vformat->Gmask = db->buffer.plb.pixelformat->green_mask;
238 /* We're done! */ 238 /* We're done! */
239 return (0); 239 return (0);
240 } 240 }
241 241
242 static SDL_Rect ** 242 static SDL_Rect **
243 GGI_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 243 GGI_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
244 { 244 {
245 return (&SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]); 245 return (&SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
246 } 246 }
247 247
248 /* Various screen update functions available */ 248 /* Various screen update functions available */
249 static void GGI_DirectUpdate (_THIS, int numrects, SDL_Rect * rects); 249 static void GGI_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
250 250
251 SDL_Surface * 251 SDL_Surface *
252 GGI_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, 252 GGI_SetVideoMode(_THIS, SDL_Surface * current, int width, int height,
253 int bpp, Uint32 flags) 253 int bpp, Uint32 flags)
254 { 254 {
255 ggi_mode mode = { 255 ggi_mode mode = {
256 1, 256 1,
257 {GGI_AUTO, GGI_AUTO}, 257 {GGI_AUTO, GGI_AUTO},
258 {GGI_AUTO, GGI_AUTO}, 258 {GGI_AUTO, GGI_AUTO},
262 }; 262 };
263 const ggi_directbuffer *db; 263 const ggi_directbuffer *db;
264 ggi_color pal[256]; 264 ggi_color pal[256];
265 int err; 265 int err;
266 266
267 fprintf (stderr, "GGI_SetVideoMode()\n"); 267 fprintf(stderr, "GGI_SetVideoMode()\n");
268 268
269 mode.visible.x = mode.virt.x = width; 269 mode.visible.x = mode.virt.x = width;
270 mode.visible.y = mode.virt.y = height; 270 mode.visible.y = mode.virt.y = height;
271 271
272 /* Translate requested SDL bit depth into a GGI mode */ 272 /* Translate requested SDL bit depth into a GGI mode */
294 break; 294 break;
295 case 32: 295 case 32:
296 mode.graphtype = GT_32BIT; 296 mode.graphtype = GT_32BIT;
297 break; 297 break;
298 default: 298 default:
299 SDL_SetError ("Unknown SDL bit depth, using GT_AUTO....\n"); 299 SDL_SetError("Unknown SDL bit depth, using GT_AUTO....\n");
300 mode.graphtype = GT_AUTO; 300 mode.graphtype = GT_AUTO;
301 } 301 }
302 302
303 /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ 303 /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */
304 ggiCheckMode (VIS, &mode); 304 ggiCheckMode(VIS, &mode);
305 305
306 /* At this point we should have a valid mode - try to set it */ 306 /* At this point we should have a valid mode - try to set it */
307 err = ggiSetMode (VIS, &mode); 307 err = ggiSetMode(VIS, &mode);
308 308
309 /* If we couldn't set _any_ modes, something is very wrong */ 309 /* If we couldn't set _any_ modes, something is very wrong */
310 if (err) { 310 if (err) {
311 SDL_SetError ("Can't set a mode!\n"); 311 SDL_SetError("Can't set a mode!\n");
312 ggiClose (VIS); 312 ggiClose(VIS);
313 ggiExit (); 313 ggiExit();
314 GGI_VideoQuit (NULL); 314 GGI_VideoQuit(NULL);
315 } 315 }
316 316
317 /* Set a palette for palletized modes */ 317 /* Set a palette for palletized modes */
318 if (GT_SCHEME (mode.graphtype) == GT_PALETTE) { 318 if (GT_SCHEME(mode.graphtype) == GT_PALETTE) {
319 ggiSetColorfulPalette (VIS); 319 ggiSetColorfulPalette(VIS);
320 ggiGetPalette (VIS, 0, 1 << bpp, pal); 320 ggiGetPalette(VIS, 0, 1 << bpp, pal);
321 } 321 }
322 322
323 db = ggiDBGetBuffer (VIS, 0); 323 db = ggiDBGetBuffer(VIS, 0);
324 324
325 /* Set up the new mode framebuffer */ 325 /* Set up the new mode framebuffer */
326 current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); 326 current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE);
327 current->w = mode.virt.x; 327 current->w = mode.virt.x;
328 current->h = mode.virt.y; 328 current->h = mode.virt.y;
335 /* We're done */ 335 /* We're done */
336 return (current); 336 return (current);
337 } 337 }
338 338
339 static int 339 static int
340 GGI_AllocHWSurface (_THIS, SDL_Surface * surface) 340 GGI_AllocHWSurface(_THIS, SDL_Surface * surface)
341 { 341 {
342 return (-1); 342 return (-1);
343 } 343 }
344 static void 344 static void
345 GGI_FreeHWSurface (_THIS, SDL_Surface * surface) 345 GGI_FreeHWSurface(_THIS, SDL_Surface * surface)
346 { 346 {
347 return; 347 return;
348 } 348 }
349 static int 349 static int
350 GGI_LockHWSurface (_THIS, SDL_Surface * surface) 350 GGI_LockHWSurface(_THIS, SDL_Surface * surface)
351 { 351 {
352 return (0); 352 return (0);
353 } 353 }
354 static void 354 static void
355 GGI_UnlockHWSurface (_THIS, SDL_Surface * surface) 355 GGI_UnlockHWSurface(_THIS, SDL_Surface * surface)
356 { 356 {
357 return; 357 return;
358 } 358 }
359 359
360 static void 360 static void
361 GGI_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) 361 GGI_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
362 { 362 {
363 int i; 363 int i;
364 364
365 /* ggiFlush(VIS); */ 365 /* ggiFlush(VIS); */
366 366
367 for (i = 0; i < numrects; i++) { 367 for (i = 0; i < numrects; i++) {
368 ggiFlushRegion (VIS, rects[i].x, rects[i].y, rects[i].w, rects[i].h); 368 ggiFlushRegion(VIS, rects[i].x, rects[i].y, rects[i].w, rects[i].h);
369 } 369 }
370 return; 370 return;
371 } 371 }
372 372
373 int 373 int
374 GGI_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 374 GGI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
375 { 375 {
376 int i; 376 int i;
377 ggi_color pal[256]; 377 ggi_color pal[256];
378 378
379 /* Set up the colormap */ 379 /* Set up the colormap */
381 pal[i].r = (colors[i].r << 8) | colors[i].r; 381 pal[i].r = (colors[i].r << 8) | colors[i].r;
382 pal[i].g = (colors[i].g << 8) | colors[i].g; 382 pal[i].g = (colors[i].g << 8) | colors[i].g;
383 pal[i].b = (colors[i].b << 8) | colors[i].b; 383 pal[i].b = (colors[i].b << 8) | colors[i].b;
384 } 384 }
385 385
386 ggiSetPalette (VIS, firstcolor, ncolors, pal); 386 ggiSetPalette(VIS, firstcolor, ncolors, pal);
387 387
388 return 1; 388 return 1;
389 } 389 }
390 390
391 void 391 void
392 GGI_VideoQuit (_THIS) 392 GGI_VideoQuit(_THIS)
393 { 393 {
394 } 394 }
395 void 395 void
396 GGI_FinalQuit (void) 396 GGI_FinalQuit(void)
397 { 397 {
398 } 398 }
399 399
400 /* vi: set ts=4 sw=4 expandtab: */ 400 /* vi: set ts=4 sw=4 expandtab: */