Mercurial > sdl-ios-xcode
comparison src/video/picogui/SDL_pgvideo.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 "SDL_pgevents_c.h" | 34 #include "SDL_pgevents_c.h" |
35 | 35 |
36 #define PGVID_DRIVER_NAME "picogui" | 36 #define PGVID_DRIVER_NAME "picogui" |
37 | 37 |
38 /* Initialization/Query functions */ | 38 /* Initialization/Query functions */ |
39 static int PG_VideoInit (_THIS, SDL_PixelFormat * vformat); | 39 static int PG_VideoInit(_THIS, SDL_PixelFormat * vformat); |
40 static SDL_Rect **PG_ListModes (_THIS, SDL_PixelFormat * format, | 40 static SDL_Rect **PG_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags); |
41 Uint32 flags); | 41 static SDL_Surface *PG_SetVideoMode(_THIS, SDL_Surface * current, int width, |
42 static SDL_Surface *PG_SetVideoMode (_THIS, SDL_Surface * current, int width, | 42 int height, int bpp, Uint32 flags); |
43 int height, int bpp, Uint32 flags); | 43 static int PG_SetColors(_THIS, int firstcolor, int ncolors, |
44 static int PG_SetColors (_THIS, int firstcolor, int ncolors, | 44 SDL_Color * colors); |
45 SDL_Color * colors); | 45 static void PG_VideoQuit(_THIS); |
46 static void PG_VideoQuit (_THIS); | |
47 | 46 |
48 /* Hardware surface functions */ | 47 /* Hardware surface functions */ |
49 static int PG_AllocHWSurface (_THIS, SDL_Surface * surface); | 48 static int PG_AllocHWSurface(_THIS, SDL_Surface * surface); |
50 static int PG_LockHWSurface (_THIS, SDL_Surface * surface); | 49 static int PG_LockHWSurface(_THIS, SDL_Surface * surface); |
51 static void PG_UnlockHWSurface (_THIS, SDL_Surface * surface); | 50 static void PG_UnlockHWSurface(_THIS, SDL_Surface * surface); |
52 static void PG_FreeHWSurface (_THIS, SDL_Surface * surface); | 51 static void PG_FreeHWSurface(_THIS, SDL_Surface * surface); |
53 | 52 |
54 /* etc. */ | 53 /* etc. */ |
55 static void PG_UpdateRects (_THIS, int numrects, SDL_Rect * rects); | 54 static void PG_UpdateRects(_THIS, int numrects, SDL_Rect * rects); |
56 | 55 |
57 // The implementation dependent data for the window manager cursor | 56 // The implementation dependent data for the window manager cursor |
58 struct WMcursor | 57 struct WMcursor |
59 { | 58 { |
60 /* Our cursor is a PicoGUI theme */ | 59 /* Our cursor is a PicoGUI theme */ |
61 pghandle theme; | 60 pghandle theme; |
62 }; | 61 }; |
63 | 62 |
64 /* WM functions */ | 63 /* WM functions */ |
65 void PG_SetCaption (_THIS, const char *title, const char *icon); | 64 void PG_SetCaption(_THIS, const char *title, const char *icon); |
66 WMcursor *PG_CreateWMCursor (_THIS, Uint8 * data, Uint8 * mask, | 65 WMcursor *PG_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask, |
67 int w, int h, int hot_x, int hot_y); | 66 int w, int h, int hot_x, int hot_y); |
68 void PG_FreeWMCursor (_THIS, WMcursor * cursor); | 67 void PG_FreeWMCursor(_THIS, WMcursor * cursor); |
69 void PG_WarpWMCursor (_THIS, Uint16 x, Uint16 y); | 68 void PG_WarpWMCursor(_THIS, Uint16 x, Uint16 y); |
70 int PG_ShowWMCursor (_THIS, WMcursor * cursor); | 69 int PG_ShowWMCursor(_THIS, WMcursor * cursor); |
71 | 70 |
72 /* PicoGUI driver bootstrap functions */ | 71 /* PicoGUI driver bootstrap functions */ |
73 | 72 |
74 static int | 73 static int |
75 PG_Available (void) | 74 PG_Available(void) |
76 { | 75 { |
77 /* FIXME: The current client lib doesn't give a way to see if the picogui | 76 /* FIXME: The current client lib doesn't give a way to see if the picogui |
78 * server is reachable without causing a fatal error if it isn't. | 77 * server is reachable without causing a fatal error if it isn't. |
79 * This should be fixed in cli_c2, but until then assume we can | 78 * This should be fixed in cli_c2, but until then assume we can |
80 * connect. Since more common drivers like X11 are probed first anyway, | 79 * connect. Since more common drivers like X11 are probed first anyway, |
82 */ | 81 */ |
83 return (1); | 82 return (1); |
84 } | 83 } |
85 | 84 |
86 static void | 85 static void |
87 PG_DeleteDevice (SDL_VideoDevice * device) | 86 PG_DeleteDevice(SDL_VideoDevice * device) |
88 { | 87 { |
89 SDL_free (device->hidden); | 88 SDL_free(device->hidden); |
90 SDL_free (device); | 89 SDL_free(device); |
91 } | 90 } |
92 | 91 |
93 static SDL_VideoDevice * | 92 static SDL_VideoDevice * |
94 PG_CreateDevice (int devindex) | 93 PG_CreateDevice(int devindex) |
95 { | 94 { |
96 SDL_VideoDevice *device; | 95 SDL_VideoDevice *device; |
97 | 96 |
98 /* Initialize all variables that we clean on shutdown */ | 97 /* Initialize all variables that we clean on shutdown */ |
99 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); | 98 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice)); |
100 if (device) { | 99 if (device) { |
101 SDL_memset (device, 0, (sizeof *device)); | 100 SDL_memset(device, 0, (sizeof *device)); |
102 device->hidden = (struct SDL_PrivateVideoData *) | 101 device->hidden = (struct SDL_PrivateVideoData *) |
103 SDL_malloc ((sizeof *device->hidden)); | 102 SDL_malloc((sizeof *device->hidden)); |
104 } | 103 } |
105 if ((device == NULL) || (device->hidden == NULL)) { | 104 if ((device == NULL) || (device->hidden == NULL)) { |
106 SDL_OutOfMemory (); | 105 SDL_OutOfMemory(); |
107 if (device) { | 106 if (device) { |
108 SDL_free (device); | 107 SDL_free(device); |
109 } | 108 } |
110 return (0); | 109 return (0); |
111 } | 110 } |
112 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); | 111 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
113 | 112 |
114 /* Set the function pointers */ | 113 /* Set the function pointers */ |
115 device->VideoInit = PG_VideoInit; | 114 device->VideoInit = PG_VideoInit; |
116 device->ListModes = PG_ListModes; | 115 device->ListModes = PG_ListModes; |
117 device->SetVideoMode = PG_SetVideoMode; | 116 device->SetVideoMode = PG_SetVideoMode; |
151 PG_Available, PG_CreateDevice | 150 PG_Available, PG_CreateDevice |
152 }; | 151 }; |
153 | 152 |
154 | 153 |
155 int | 154 int |
156 PG_VideoInit (_THIS, SDL_PixelFormat * vformat) | 155 PG_VideoInit(_THIS, SDL_PixelFormat * vformat) |
157 { | 156 { |
158 /* Connect to the PicoGUI server. No way to process command line args yet, | 157 /* Connect to the PicoGUI server. No way to process command line args yet, |
159 * but since this is based on SHM it's not important to be able to specify | 158 * but since this is based on SHM it's not important to be able to specify |
160 * a remote PicoGUI server. | 159 * a remote PicoGUI server. |
161 * | 160 * |
162 * FIXME: Another nitpick about the current client lib is there's no | 161 * FIXME: Another nitpick about the current client lib is there's no |
163 * clean way to indicate that command line args are not available. | 162 * clean way to indicate that command line args are not available. |
164 */ | 163 */ |
165 pgInit (0, (char **) ""); | 164 pgInit(0, (char **) ""); |
166 this->hidden->mi = *pgGetVideoMode (); | 165 this->hidden->mi = *pgGetVideoMode(); |
167 | 166 |
168 /* Create a picogui application and canvas. We'll populate the canvas later. */ | 167 /* Create a picogui application and canvas. We'll populate the canvas later. */ |
169 this->hidden->wApp = pgRegisterApp (PG_APP_NORMAL, "SDL", 0); | 168 this->hidden->wApp = pgRegisterApp(PG_APP_NORMAL, "SDL", 0); |
170 this->hidden->wCanvas = pgNewWidget (PG_WIDGET_CANVAS, 0, 0); | 169 this->hidden->wCanvas = pgNewWidget(PG_WIDGET_CANVAS, 0, 0); |
171 pgSetWidget (PGDEFAULT, PG_WP_SIDE, PG_S_ALL, 0); | 170 pgSetWidget(PGDEFAULT, PG_WP_SIDE, PG_S_ALL, 0); |
172 | 171 |
173 PG_InitEvents (this); | 172 PG_InitEvents(this); |
174 | 173 |
175 /* Determine the current screen size */ | 174 /* Determine the current screen size */ |
176 this->info.current_w = this->hidden->mi.lxres; | 175 this->info.current_w = this->hidden->mi.lxres; |
177 this->info.current_h = this->hidden->mi.lyres; | 176 this->info.current_h = this->hidden->mi.lyres; |
178 | 177 |
188 /* We're done! */ | 187 /* We're done! */ |
189 return (0); | 188 return (0); |
190 } | 189 } |
191 | 190 |
192 SDL_Rect ** | 191 SDL_Rect ** |
193 PG_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) | 192 PG_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) |
194 { | 193 { |
195 return (SDL_Rect **) - 1; | 194 return (SDL_Rect **) - 1; |
196 } | 195 } |
197 | 196 |
198 SDL_Surface * | 197 SDL_Surface * |
199 PG_SetVideoMode (_THIS, SDL_Surface * current, | 198 PG_SetVideoMode(_THIS, SDL_Surface * current, |
200 int width, int height, int bpp, Uint32 flags) | 199 int width, int height, int bpp, Uint32 flags) |
201 { | 200 { |
202 if (this->hidden->bitmap) { | 201 if (this->hidden->bitmap) { |
203 /* Free old bitmap */ | 202 /* Free old bitmap */ |
204 if (current->pixels) { | 203 if (current->pixels) { |
205 shmdt (current->pixels); | 204 shmdt(current->pixels); |
206 current->pixels = NULL; | 205 current->pixels = NULL; |
207 } | 206 } |
208 pgDelete (this->hidden->bitmap); | 207 pgDelete(this->hidden->bitmap); |
209 } | 208 } |
210 | 209 |
211 /* Allocate the new pixel format for the screen */ | 210 /* Allocate the new pixel format for the screen */ |
212 if (!SDL_ReallocFormat (current, bpp, 0, 0, 0, 0)) { | 211 if (!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) { |
213 SDL_SetError | 212 SDL_SetError("Couldn't allocate new pixel format for requested mode"); |
214 ("Couldn't allocate new pixel format for requested mode"); | |
215 return (NULL); | 213 return (NULL); |
216 } | 214 } |
217 | 215 |
218 /* Create a new picogui bitmap */ | 216 /* Create a new picogui bitmap */ |
219 this->hidden->bitmap = pgCreateBitmap (width, height); | 217 this->hidden->bitmap = pgCreateBitmap(width, height); |
220 this->hidden->shm = *pgMakeSHMBitmap (this->hidden->bitmap); | 218 this->hidden->shm = *pgMakeSHMBitmap(this->hidden->bitmap); |
221 current->pixels = shmat (shmget (this->hidden->shm.shm_key, | 219 current->pixels = shmat(shmget(this->hidden->shm.shm_key, |
222 this->hidden->shm.shm_length, 0), NULL, | 220 this->hidden->shm.shm_length, 0), NULL, 0); |
223 0); | |
224 | 221 |
225 /* Reset the canvas, and draw persistent and incremental grops. | 222 /* Reset the canvas, and draw persistent and incremental grops. |
226 * Use mapping and offsets to center it. | 223 * Use mapping and offsets to center it. |
227 */ | 224 */ |
228 | 225 |
229 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_NUKE, 0); | 226 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_NUKE, 0); |
230 | 227 |
231 /* 0. Set the source position during incremental rendering | 228 /* 0. Set the source position during incremental rendering |
232 */ | 229 */ |
233 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_GROP, 5, PG_GROP_SETSRC, 0, 0, | 230 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 5, PG_GROP_SETSRC, 0, 0, |
234 0, 0); | 231 0, 0); |
235 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1, | 232 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1, |
236 PG_GROPF_INCREMENTAL); | 233 PG_GROPF_INCREMENTAL); |
237 | 234 |
238 /* 1. Incremental bitmap rendering | 235 /* 1. Incremental bitmap rendering |
239 */ | 236 */ |
240 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP, | 237 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP, |
241 0, 0, 0, 0, this->hidden->bitmap); | 238 0, 0, 0, 0, this->hidden->bitmap); |
242 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1, | 239 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1, |
243 PG_GROPF_INCREMENTAL); | 240 PG_GROPF_INCREMENTAL); |
244 | 241 |
245 /* 2. Normal bitmap rendering | 242 /* 2. Normal bitmap rendering |
246 */ | 243 */ |
247 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP, | 244 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP, |
248 0, 0, this->hidden->shm.width, this->hidden->shm.height, | 245 0, 0, this->hidden->shm.width, this->hidden->shm.height, |
249 this->hidden->bitmap); | 246 this->hidden->bitmap); |
250 | 247 |
251 /* Set up the new mode framebuffer */ | 248 /* Set up the new mode framebuffer */ |
252 current->flags = 0; | 249 current->flags = 0; |
253 current->w = this->hidden->shm.width; | 250 current->w = this->hidden->shm.width; |
254 current->h = this->hidden->shm.height; | 251 current->h = this->hidden->shm.height; |
272 current->format->Gloss = 8 - this->hidden->shm.green_length; | 269 current->format->Gloss = 8 - this->hidden->shm.green_length; |
273 current->format->Bloss = 8 - this->hidden->shm.blue_length; | 270 current->format->Bloss = 8 - this->hidden->shm.blue_length; |
274 current->format->Aloss = 8 - this->hidden->shm.alpha_length; | 271 current->format->Aloss = 8 - this->hidden->shm.alpha_length; |
275 | 272 |
276 /* Draw the app */ | 273 /* Draw the app */ |
277 pgUpdate (); | 274 pgUpdate(); |
278 | 275 |
279 /* We're done */ | 276 /* We're done */ |
280 return (current); | 277 return (current); |
281 } | 278 } |
282 | 279 |
283 /* We don't actually allow hardware surfaces other than the main one */ | 280 /* We don't actually allow hardware surfaces other than the main one */ |
284 static int | 281 static int |
285 PG_AllocHWSurface (_THIS, SDL_Surface * surface) | 282 PG_AllocHWSurface(_THIS, SDL_Surface * surface) |
286 { | 283 { |
287 return (-1); | 284 return (-1); |
288 } | 285 } |
289 static void | 286 static void |
290 PG_FreeHWSurface (_THIS, SDL_Surface * surface) | 287 PG_FreeHWSurface(_THIS, SDL_Surface * surface) |
291 { | 288 { |
292 return; | 289 return; |
293 } | 290 } |
294 | 291 |
295 /* We need to wait for vertical retrace on page flipped displays */ | 292 /* We need to wait for vertical retrace on page flipped displays */ |
296 static int | 293 static int |
297 PG_LockHWSurface (_THIS, SDL_Surface * surface) | 294 PG_LockHWSurface(_THIS, SDL_Surface * surface) |
298 { | 295 { |
299 return (0); | 296 return (0); |
300 } | 297 } |
301 | 298 |
302 static void | 299 static void |
303 PG_UnlockHWSurface (_THIS, SDL_Surface * surface) | 300 PG_UnlockHWSurface(_THIS, SDL_Surface * surface) |
304 { | 301 { |
305 return; | 302 return; |
306 } | 303 } |
307 | 304 |
308 static void | 305 static void |
309 PG_UpdateRects (_THIS, int numrects, SDL_Rect * rects) | 306 PG_UpdateRects(_THIS, int numrects, SDL_Rect * rects) |
310 { | 307 { |
311 int i; | 308 int i; |
312 | 309 |
313 for (i = 0; i < numrects; i++) { | 310 for (i = 0; i < numrects; i++) { |
314 if (rects[i].w <= 0 || rects[i].h <= 0) | 311 if (rects[i].w <= 0 || rects[i].h <= 0) |
315 continue; | 312 continue; |
316 | 313 |
317 /* Schedule an incremental update for this rectangle, using | 314 /* Schedule an incremental update for this rectangle, using |
318 * the canvas gropnodes we've loaded beforehand. | 315 * the canvas gropnodes we've loaded beforehand. |
319 */ | 316 */ |
320 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_FINDGROP, 1, 0); | 317 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_FINDGROP, 1, 0); |
321 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_MOVEGROP, 4, | 318 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_MOVEGROP, 4, |
322 rects[i].x, rects[i].y, rects[i].w, rects[i].h); | 319 rects[i].x, rects[i].y, rects[i].w, rects[i].h); |
323 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_FINDGROP, 1, 1); | 320 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_FINDGROP, 1, 1); |
324 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_MOVEGROP, 4, | 321 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_MOVEGROP, 4, |
325 rects[i].x, rects[i].y, rects[i].w, rects[i].h); | 322 rects[i].x, rects[i].y, rects[i].w, rects[i].h); |
326 | 323 |
327 /* Go perform the update */ | 324 /* Go perform the update */ |
328 pgWriteCmd (this->hidden->wCanvas, PGCANVAS_INCREMENTAL, 0); | 325 pgWriteCmd(this->hidden->wCanvas, PGCANVAS_INCREMENTAL, 0); |
329 pgSubUpdate (this->hidden->wCanvas); | 326 pgSubUpdate(this->hidden->wCanvas); |
330 } | 327 } |
331 } | 328 } |
332 | 329 |
333 int | 330 int |
334 PG_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) | 331 PG_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) |
335 { | 332 { |
336 /* do nothing of note. */ | 333 /* do nothing of note. */ |
337 return (1); | 334 return (1); |
338 } | 335 } |
339 | 336 |
340 /* Note: If we are terminated, this could be called in the middle of | 337 /* Note: If we are terminated, this could be called in the middle of |
341 another SDL video routine -- notably UpdateRects. | 338 another SDL video routine -- notably UpdateRects. |
342 */ | 339 */ |
343 void | 340 void |
344 PG_VideoQuit (_THIS) | 341 PG_VideoQuit(_THIS) |
345 { | 342 { |
346 if (this->screen->pixels != NULL) { | 343 if (this->screen->pixels != NULL) { |
347 shmdt (this->screen->pixels); | 344 shmdt(this->screen->pixels); |
348 this->screen->pixels = NULL; | 345 this->screen->pixels = NULL; |
349 pgDelete (this->hidden->bitmap); | 346 pgDelete(this->hidden->bitmap); |
350 } | 347 } |
351 pgDelete (this->hidden->wCanvas); | 348 pgDelete(this->hidden->wCanvas); |
352 pgDelete (this->hidden->wApp); | 349 pgDelete(this->hidden->wApp); |
353 } | 350 } |
354 | 351 |
355 void | 352 void |
356 PG_SetCaption (_THIS, const char *title, const char *icon) | 353 PG_SetCaption(_THIS, const char *title, const char *icon) |
357 { | 354 { |
358 if (title != NULL) | 355 if (title != NULL) |
359 pgReplaceText (this->hidden->wApp, title); | 356 pgReplaceText(this->hidden->wApp, title); |
360 pgUpdate (); | 357 pgUpdate(); |
361 } | 358 } |
362 | 359 |
363 /* FIXME: The cursor stuff isn't implemented yet! */ | 360 /* FIXME: The cursor stuff isn't implemented yet! */ |
364 | 361 |
365 WMcursor * | 362 WMcursor * |
366 PG_CreateWMCursor (_THIS, Uint8 * data, Uint8 * mask, | 363 PG_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask, |
367 int w, int h, int hot_x, int hot_y) | 364 int w, int h, int hot_x, int hot_y) |
368 { | 365 { |
369 static WMcursor dummy; | 366 static WMcursor dummy; |
370 return &dummy; | 367 return &dummy; |
371 } | 368 } |
372 | 369 |
373 void | 370 void |
374 PG_FreeWMCursor (_THIS, WMcursor * cursor) | 371 PG_FreeWMCursor(_THIS, WMcursor * cursor) |
375 { | 372 { |
376 } | 373 } |
377 | 374 |
378 void | 375 void |
379 PG_WarpWMCursor (_THIS, Uint16 x, Uint16 y) | 376 PG_WarpWMCursor(_THIS, Uint16 x, Uint16 y) |
380 { | 377 { |
381 } | 378 } |
382 | 379 |
383 int | 380 int |
384 PG_ShowWMCursor (_THIS, WMcursor * cursor) | 381 PG_ShowWMCursor(_THIS, WMcursor * cursor) |
385 { | 382 { |
386 return 1; | 383 return 1; |
387 } | 384 } |
388 | 385 |
389 /* vi: set ts=4 sw=4 expandtab: */ | 386 /* vi: set ts=4 sw=4 expandtab: */ |