Mercurial > sdl-ios-xcode
comparison src/video/dc/SDL_dcvideo.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 |
---|---|
34 #include <dc/video.h> | 34 #include <dc/video.h> |
35 #include <dc/pvr.h> | 35 #include <dc/pvr.h> |
36 | 36 |
37 | 37 |
38 /* Initialization/Query functions */ | 38 /* Initialization/Query functions */ |
39 static int DC_VideoInit (_THIS, SDL_PixelFormat * vformat); | 39 static int DC_VideoInit(_THIS, SDL_PixelFormat * vformat); |
40 static SDL_Rect **DC_ListModes (_THIS, SDL_PixelFormat * format, | 40 static SDL_Rect **DC_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags); |
41 Uint32 flags); | 41 static SDL_Surface *DC_SetVideoMode(_THIS, SDL_Surface * current, int width, |
42 static SDL_Surface *DC_SetVideoMode (_THIS, SDL_Surface * current, int width, | 42 int height, int bpp, Uint32 flags); |
43 int height, int bpp, Uint32 flags); | 43 static int DC_SetColors(_THIS, int firstcolor, int ncolors, |
44 static int DC_SetColors (_THIS, int firstcolor, int ncolors, | 44 SDL_Color * colors); |
45 SDL_Color * colors); | 45 static void DC_VideoQuit(_THIS); |
46 static void DC_VideoQuit (_THIS); | |
47 | 46 |
48 /* Hardware surface functions */ | 47 /* Hardware surface functions */ |
49 static int DC_AllocHWSurface (_THIS, SDL_Surface * surface); | 48 static int DC_AllocHWSurface(_THIS, SDL_Surface * surface); |
50 static int DC_LockHWSurface (_THIS, SDL_Surface * surface); | 49 static int DC_LockHWSurface(_THIS, SDL_Surface * surface); |
51 static void DC_UnlockHWSurface (_THIS, SDL_Surface * surface); | 50 static void DC_UnlockHWSurface(_THIS, SDL_Surface * surface); |
52 static void DC_FreeHWSurface (_THIS, SDL_Surface * surface); | 51 static void DC_FreeHWSurface(_THIS, SDL_Surface * surface); |
53 static int DC_FlipHWSurface (_THIS, SDL_Surface * surface); | 52 static int DC_FlipHWSurface(_THIS, SDL_Surface * surface); |
54 | 53 |
55 /* etc. */ | 54 /* etc. */ |
56 static void DC_UpdateRects (_THIS, int numrects, SDL_Rect * rects); | 55 static void DC_UpdateRects(_THIS, int numrects, SDL_Rect * rects); |
57 | 56 |
58 /* OpenGL */ | 57 /* OpenGL */ |
59 #if SDL_VIDEO_OPENGL | 58 #if SDL_VIDEO_OPENGL |
60 static void *DC_GL_GetProcAddress (_THIS, const char *proc); | 59 static void *DC_GL_GetProcAddress(_THIS, const char *proc); |
61 static int DC_GL_LoadLibrary (_THIS, const char *path); | 60 static int DC_GL_LoadLibrary(_THIS, const char *path); |
62 static int DC_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value); | 61 static int DC_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value); |
63 static void DC_GL_SwapBuffers (_THIS); | 62 static void DC_GL_SwapBuffers(_THIS); |
64 #endif | 63 #endif |
65 | 64 |
66 /* DC driver bootstrap functions */ | 65 /* DC driver bootstrap functions */ |
67 | 66 |
68 static int | 67 static int |
69 DC_Available (void) | 68 DC_Available(void) |
70 { | 69 { |
71 return 1; | 70 return 1; |
72 } | 71 } |
73 | 72 |
74 static void | 73 static void |
75 DC_DeleteDevice (SDL_VideoDevice * device) | 74 DC_DeleteDevice(SDL_VideoDevice * device) |
76 { | 75 { |
77 SDL_free (device->hidden); | 76 SDL_free(device->hidden); |
78 SDL_free (device); | 77 SDL_free(device); |
79 } | 78 } |
80 | 79 |
81 static SDL_VideoDevice * | 80 static SDL_VideoDevice * |
82 DC_CreateDevice (int devindex) | 81 DC_CreateDevice(int devindex) |
83 { | 82 { |
84 SDL_VideoDevice *device; | 83 SDL_VideoDevice *device; |
85 | 84 |
86 /* Initialize all variables that we clean on shutdown */ | 85 /* Initialize all variables that we clean on shutdown */ |
87 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); | 86 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice)); |
88 if (device) { | 87 if (device) { |
89 SDL_memset (device, 0, (sizeof *device)); | 88 SDL_memset(device, 0, (sizeof *device)); |
90 device->hidden = (struct SDL_PrivateVideoData *) | 89 device->hidden = (struct SDL_PrivateVideoData *) |
91 SDL_malloc ((sizeof *device->hidden)); | 90 SDL_malloc((sizeof *device->hidden)); |
92 } | 91 } |
93 if ((device == NULL) || (device->hidden == NULL)) { | 92 if ((device == NULL) || (device->hidden == NULL)) { |
94 SDL_OutOfMemory (); | 93 SDL_OutOfMemory(); |
95 if (device) { | 94 if (device) { |
96 SDL_free (device); | 95 SDL_free(device); |
97 } | 96 } |
98 return (0); | 97 return (0); |
99 } | 98 } |
100 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); | 99 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
101 | 100 |
102 /* Set the function pointers */ | 101 /* Set the function pointers */ |
103 device->VideoInit = DC_VideoInit; | 102 device->VideoInit = DC_VideoInit; |
104 device->ListModes = DC_ListModes; | 103 device->ListModes = DC_ListModes; |
105 device->SetVideoMode = DC_SetVideoMode; | 104 device->SetVideoMode = DC_SetVideoMode; |
141 DC_Available, DC_CreateDevice | 140 DC_Available, DC_CreateDevice |
142 }; | 141 }; |
143 | 142 |
144 | 143 |
145 int | 144 int |
146 DC_VideoInit (_THIS, SDL_PixelFormat * vformat) | 145 DC_VideoInit(_THIS, SDL_PixelFormat * vformat) |
147 { | 146 { |
148 /* Determine the screen depth (use default 16-bit depth) */ | 147 /* Determine the screen depth (use default 16-bit depth) */ |
149 /* we change this during the SDL_SetVideoMode implementation... */ | 148 /* we change this during the SDL_SetVideoMode implementation... */ |
150 vformat->BitsPerPixel = 16; | 149 vformat->BitsPerPixel = 16; |
151 vformat->Rmask = 0x0000f800; | 150 vformat->Rmask = 0x0000f800; |
165 &RECT_320x240, | 164 &RECT_320x240, |
166 NULL | 165 NULL |
167 }; | 166 }; |
168 | 167 |
169 SDL_Rect ** | 168 SDL_Rect ** |
170 DC_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) | 169 DC_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) |
171 { | 170 { |
172 switch (format->BitsPerPixel) { | 171 switch (format->BitsPerPixel) { |
173 case 15: | 172 case 15: |
174 case 16: | 173 case 16: |
175 return &vid_modes; | 174 return &vid_modes; |
195 #if SDL_VIDEO_OPENGL | 194 #if SDL_VIDEO_OPENGL |
196 static int pvr_inited; | 195 static int pvr_inited; |
197 #endif | 196 #endif |
198 | 197 |
199 SDL_Surface * | 198 SDL_Surface * |
200 DC_SetVideoMode (_THIS, SDL_Surface * current, | 199 DC_SetVideoMode(_THIS, SDL_Surface * current, |
201 int width, int height, int bpp, Uint32 flags) | 200 int width, int height, int bpp, Uint32 flags) |
202 { | 201 { |
203 int disp_mode, pixel_mode, pitch; | 202 int disp_mode, pixel_mode, pitch; |
204 Uint32 Rmask, Gmask, Bmask; | 203 Uint32 Rmask, Gmask, Bmask; |
205 | 204 |
206 if (width == 320 && height == 240) | 205 if (width == 320 && height == 240) |
208 else if (width == 640 && height == 480) | 207 else if (width == 640 && height == 480) |
209 disp_mode = DM_640x480; | 208 disp_mode = DM_640x480; |
210 else if (width == 800 && height == 600) | 209 else if (width == 800 && height == 600) |
211 disp_mode = DM_800x608; | 210 disp_mode = DM_800x608; |
212 else { | 211 else { |
213 SDL_SetError ("Couldn't find requested mode in list"); | 212 SDL_SetError("Couldn't find requested mode in list"); |
214 return (NULL); | 213 return (NULL); |
215 } | 214 } |
216 | 215 |
217 switch (bpp) { | 216 switch (bpp) { |
218 case 15: | 217 case 15: |
242 #if SDL_VIDEO_OPENGL | 241 #if SDL_VIDEO_OPENGL |
243 if (!(flags & SDL_INTERNALOPENGL)) | 242 if (!(flags & SDL_INTERNALOPENGL)) |
244 #endif | 243 #endif |
245 break; | 244 break; |
246 default: | 245 default: |
247 SDL_SetError ("Couldn't find requested mode in list"); | 246 SDL_SetError("Couldn't find requested mode in list"); |
248 return (NULL); | 247 return (NULL); |
249 } | 248 } |
250 | 249 |
251 // if ( bpp != current->format->BitsPerPixel ) { | 250 // if ( bpp != current->format->BitsPerPixel ) { |
252 if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, 0)) { | 251 if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0)) { |
253 return (NULL); | 252 return (NULL); |
254 } | 253 } |
255 // } | 254 // } |
256 | 255 |
257 /* Set up the new mode framebuffer */ | 256 /* Set up the new mode framebuffer */ |
261 current->pitch = pitch; | 260 current->pitch = pitch; |
262 | 261 |
263 #if SDL_VIDEO_OPENGL | 262 #if SDL_VIDEO_OPENGL |
264 if (pvr_inited) { | 263 if (pvr_inited) { |
265 pvr_inited = 0; | 264 pvr_inited = 0; |
266 pvr_shutdown (); | 265 pvr_shutdown(); |
267 } | 266 } |
268 #endif | 267 #endif |
269 | 268 |
270 vid_set_mode (disp_mode, pixel_mode); | 269 vid_set_mode(disp_mode, pixel_mode); |
271 | 270 |
272 current->pixels = vram_s; | 271 current->pixels = vram_s; |
273 | 272 |
274 #if SDL_VIDEO_OPENGL | 273 #if SDL_VIDEO_OPENGL |
275 if (flags & SDL_INTERNALOPENGL) { | 274 if (flags & SDL_INTERNALOPENGL) { |
276 this->gl_config.driver_loaded = 1; | 275 this->gl_config.driver_loaded = 1; |
277 current->flags = SDL_FULLSCREEN | SDL_INTERNALOPENGL; | 276 current->flags = SDL_FULLSCREEN | SDL_INTERNALOPENGL; |
278 current->pixels = NULL; | 277 current->pixels = NULL; |
279 pvr_inited = 1; | 278 pvr_inited = 1; |
280 pvr_init (¶ms); | 279 pvr_init(¶ms); |
281 glKosInit (); | 280 glKosInit(); |
282 glKosBeginFrame (); | 281 glKosBeginFrame(); |
283 } else | 282 } else |
284 #endif | 283 #endif |
285 if (flags | SDL_DOUBLEBUF) { | 284 if (flags | SDL_DOUBLEBUF) { |
286 current->flags |= SDL_DOUBLEBUF; | 285 current->flags |= SDL_DOUBLEBUF; |
287 current->pixels = (void *) ((int) current->pixels | 0x400000); | 286 current->pixels = (void *) ((int) current->pixels | 0x400000); |
291 return (current); | 290 return (current); |
292 } | 291 } |
293 | 292 |
294 /* We don't actually allow hardware surfaces other than the main one */ | 293 /* We don't actually allow hardware surfaces other than the main one */ |
295 static int | 294 static int |
296 DC_AllocHWSurface (_THIS, SDL_Surface * surface) | 295 DC_AllocHWSurface(_THIS, SDL_Surface * surface) |
297 { | 296 { |
298 return (-1); | 297 return (-1); |
299 } | 298 } |
300 static void | 299 static void |
301 DC_FreeHWSurface (_THIS, SDL_Surface * surface) | 300 DC_FreeHWSurface(_THIS, SDL_Surface * surface) |
302 { | 301 { |
303 return; | 302 return; |
304 } | 303 } |
305 | 304 |
306 /* We need to wait for vertical retrace on page flipped displays */ | 305 /* We need to wait for vertical retrace on page flipped displays */ |
307 static int | 306 static int |
308 DC_LockHWSurface (_THIS, SDL_Surface * surface) | 307 DC_LockHWSurface(_THIS, SDL_Surface * surface) |
309 { | 308 { |
310 return (0); | 309 return (0); |
311 } | 310 } |
312 | 311 |
313 static void | 312 static void |
314 DC_UnlockHWSurface (_THIS, SDL_Surface * surface) | 313 DC_UnlockHWSurface(_THIS, SDL_Surface * surface) |
315 { | 314 { |
316 return; | 315 return; |
317 } | 316 } |
318 | 317 |
319 static int | 318 static int |
320 DC_FlipHWSurface (_THIS, SDL_Surface * surface) | 319 DC_FlipHWSurface(_THIS, SDL_Surface * surface) |
321 { | 320 { |
322 if (surface->flags & SDL_DOUBLEBUF) { | 321 if (surface->flags & SDL_DOUBLEBUF) { |
323 vid_set_start ((int) surface->pixels & 0xffffff); | 322 vid_set_start((int) surface->pixels & 0xffffff); |
324 surface->pixels = (void *) ((int) surface->pixels ^ 0x400000); | 323 surface->pixels = (void *) ((int) surface->pixels ^ 0x400000); |
325 } | 324 } |
326 return (0); | 325 return (0); |
327 } | 326 } |
328 | 327 |
329 static void | 328 static void |
330 DC_UpdateRects (_THIS, int numrects, SDL_Rect * rects) | 329 DC_UpdateRects(_THIS, int numrects, SDL_Rect * rects) |
331 { | 330 { |
332 /* do nothing. */ | 331 /* do nothing. */ |
333 } | 332 } |
334 | 333 |
335 static int | 334 static int |
336 DC_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) | 335 DC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) |
337 { | 336 { |
338 /* do nothing of note. */ | 337 /* do nothing of note. */ |
339 return (1); | 338 return (1); |
340 } | 339 } |
341 | 340 |
342 /* Note: If we are terminated, this could be called in the middle of | 341 /* Note: If we are terminated, this could be called in the middle of |
343 another SDL video routine -- notably UpdateRects. | 342 another SDL video routine -- notably UpdateRects. |
344 */ | 343 */ |
345 static void | 344 static void |
346 DC_VideoQuit (_THIS) | 345 DC_VideoQuit(_THIS) |
347 { | 346 { |
348 #if SDL_VIDEO_OPENGL | 347 #if SDL_VIDEO_OPENGL |
349 if (pvr_inited) { | 348 if (pvr_inited) { |
350 pvr_inited = 0; | 349 pvr_inited = 0; |
351 pvr_shutdown (); | 350 pvr_shutdown(); |
352 } | 351 } |
353 #endif | 352 #endif |
354 } | 353 } |
355 | 354 |
356 #if SDL_VIDEO_OPENGL | 355 #if SDL_VIDEO_OPENGL |
357 | 356 |
358 void | 357 void |
359 dmyfunc (void) | 358 dmyfunc(void) |
360 { | 359 { |
361 } | 360 } |
362 | 361 |
363 typedef void (*funcptr) (); | 362 typedef void (*funcptr) (); |
364 const static struct | 363 const static struct |
365 { | 364 { |
366 char *name; | 365 char *name; |
367 funcptr addr; | 366 funcptr addr; |
368 } glfuncs[] = { | 367 } glfuncs[] = { |
369 #define DEF(func) {#func,&func} | 368 #define DEF(func) {#func,&func} |
370 DEF (glBegin), DEF (glBindTexture), DEF (glBlendFunc), DEF (glColor4f), | 369 DEF(glBegin), DEF(glBindTexture), DEF(glBlendFunc), DEF(glColor4f), |
371 // DEF(glCopyImageID), | 370 // DEF(glCopyImageID), |
372 DEF (glDisable), | 371 DEF(glDisable), |
373 DEF (glEnable), | 372 DEF(glEnable), |
374 DEF (glEnd), | 373 DEF(glEnd), |
375 DEF (glFlush), | 374 DEF(glFlush), |
376 DEF (glGenTextures), | 375 DEF(glGenTextures), |
377 DEF (glGetString), | 376 DEF(glGetString), |
378 DEF (glLoadIdentity), | 377 DEF(glLoadIdentity), |
379 DEF (glMatrixMode), DEF (glOrtho), DEF (glPixelStorei), | 378 DEF(glMatrixMode), DEF(glOrtho), DEF(glPixelStorei), |
380 // DEF(glPopAttrib), | 379 // DEF(glPopAttrib), |
381 // DEF(glPopClientAttrib), | 380 // DEF(glPopClientAttrib), |
382 { | 381 { |
383 "glPopAttrib", &dmyfunc}, { | 382 "glPopAttrib", &dmyfunc}, { |
384 "glPopClientAttrib", &dmyfunc}, DEF (glPopMatrix), | 383 "glPopClientAttrib", &dmyfunc}, DEF(glPopMatrix), |
385 // DEF(glPushAttrib), | 384 // DEF(glPushAttrib), |
386 // DEF(glPushClientAttrib), | 385 // DEF(glPushClientAttrib), |
387 { | 386 { |
388 "glPushAttrib", &dmyfunc}, { | 387 "glPushAttrib", &dmyfunc}, { |
389 "glPushClientAttrib", &dmyfunc}, | 388 "glPushClientAttrib", &dmyfunc}, |
390 DEF (glPushMatrix), | 389 DEF(glPushMatrix), |
391 DEF (glTexCoord2f), | 390 DEF(glTexCoord2f), |
392 DEF (glTexEnvf), | 391 DEF(glTexEnvf), |
393 DEF (glTexImage2D), | 392 DEF(glTexImage2D), |
394 DEF (glTexParameteri), | 393 DEF(glTexParameteri), |
395 DEF (glTexSubImage2D), DEF (glVertex2i), DEF (glViewport), | 394 DEF(glTexSubImage2D), DEF(glVertex2i), DEF(glViewport), |
396 #undef DEF | 395 #undef DEF |
397 }; | 396 }; |
398 | 397 |
399 static void * | 398 static void * |
400 DC_GL_GetProcAddress (_THIS, const char *proc) | 399 DC_GL_GetProcAddress(_THIS, const char *proc) |
401 { | 400 { |
402 void *ret; | 401 void *ret; |
403 int i; | 402 int i; |
404 | 403 |
405 ret = glKosGetProcAddress (proc); | 404 ret = glKosGetProcAddress(proc); |
406 if (ret) | 405 if (ret) |
407 return ret; | 406 return ret; |
408 | 407 |
409 for (i = 0; i < sizeof (glfuncs) / sizeof (glfuncs[0]); i++) { | 408 for (i = 0; i < sizeof(glfuncs) / sizeof(glfuncs[0]); i++) { |
410 if (SDL_strcmp (proc, glfuncs[i].name) == 0) | 409 if (SDL_strcmp(proc, glfuncs[i].name) == 0) |
411 return glfuncs[i].addr; | 410 return glfuncs[i].addr; |
412 } | 411 } |
413 | 412 |
414 return NULL; | 413 return NULL; |
415 } | 414 } |
416 | 415 |
417 static int | 416 static int |
418 DC_GL_LoadLibrary (_THIS, const char *path) | 417 DC_GL_LoadLibrary(_THIS, const char *path) |
419 { | 418 { |
420 this->gl_config.driver_loaded = 1; | 419 this->gl_config.driver_loaded = 1; |
421 | 420 |
422 return 0; | 421 return 0; |
423 } | 422 } |
424 | 423 |
425 static int | 424 static int |
426 DC_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value) | 425 DC_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value) |
427 { | 426 { |
428 GLenum mesa_attrib; | 427 GLenum mesa_attrib; |
429 int val; | 428 int val; |
430 | 429 |
431 switch (attrib) { | 430 switch (attrib) { |
467 *value = val; | 466 *value = val; |
468 return 0; | 467 return 0; |
469 } | 468 } |
470 | 469 |
471 static void | 470 static void |
472 DC_GL_SwapBuffers (_THIS) | 471 DC_GL_SwapBuffers(_THIS) |
473 { | 472 { |
474 glKosFinishFrame (); | 473 glKosFinishFrame(); |
475 glKosBeginFrame (); | 474 glKosBeginFrame(); |
476 } | 475 } |
477 #endif | 476 #endif |
478 /* vi: set ts=4 sw=4 expandtab: */ | 477 /* vi: set ts=4 sw=4 expandtab: */ |