Mercurial > sdl-ios-xcode
annotate src/video/ggi/SDL_ggivideo.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | c9b51268668f |
children | 604d73db6802 |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
19 Sam Lantinga |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
20 slouken@libsdl.org |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
21 */ |
0 | 22 |
23 /* GGI-based SDL video driver implementation. | |
24 */ | |
25 | |
26 #include <stdlib.h> | |
27 #include <stdio.h> | |
28 #include <fcntl.h> | |
29 #include <unistd.h> | |
30 #include <sys/mman.h> | |
31 | |
32 #include <ggi/ggi.h> | |
33 #include <ggi/gii.h> | |
34 | |
35 #include "SDL.h" | |
36 #include "SDL_error.h" | |
37 #include "SDL_video.h" | |
38 #include "SDL_mouse.h" | |
39 #include "SDL_sysvideo.h" | |
40 #include "SDL_pixels_c.h" | |
41 #include "SDL_events_c.h" | |
42 #include "SDL_ggivideo.h" | |
43 #include "SDL_ggimouse_c.h" | |
44 #include "SDL_ggievents_c.h" | |
45 | |
46 | |
47 struct private_hwdata | |
48 { | |
49 ggi_visual_t vis; | |
50 }; | |
51 | |
52 ggi_visual_t VIS; | |
53 | |
54 /* Initialization/Query functions */ | |
55 static int GGI_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
56 static SDL_Rect **GGI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
57 static SDL_Surface *GGI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
58 static int GGI_SetColors(_THIS, int firstcolor, int ncolors, | |
59 SDL_Color *colors); | |
60 static void GGI_VideoQuit(_THIS); | |
61 | |
62 /* Hardware surface functions */ | |
63 static int GGI_AllocHWSurface(_THIS, SDL_Surface *surface); | |
64 static int GGI_LockHWSurface(_THIS, SDL_Surface *surface); | |
65 static void GGI_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
66 static void GGI_FreeHWSurface(_THIS, SDL_Surface *surface); | |
67 | |
68 /* GGI driver bootstrap functions */ | |
69 | |
70 static int GGI_Available(void) | |
71 { | |
72 ggi_visual_t *vis; | |
17
4f22a992f5e9
Fixed crash in GGI detection
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
73 |
4f22a992f5e9
Fixed crash in GGI detection
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
74 vis = NULL; |
4f22a992f5e9
Fixed crash in GGI detection
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
75 if (ggiInit() == 0) { |
4f22a992f5e9
Fixed crash in GGI detection
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
76 vis = ggiOpen(NULL); |
4f22a992f5e9
Fixed crash in GGI detection
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
77 if (vis != NULL) { |
4f22a992f5e9
Fixed crash in GGI detection
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
78 ggiClose(vis); |
4f22a992f5e9
Fixed crash in GGI detection
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
79 } |
0 | 80 } |
81 return (vis != NULL); | |
82 } | |
83 | |
84 static void GGI_DeleteDevice(SDL_VideoDevice *device) | |
85 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
86 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
87 SDL_free(device); |
0 | 88 } |
89 | |
90 static SDL_VideoDevice *GGI_CreateDevice(int devindex) | |
91 { | |
92 SDL_VideoDevice *device; | |
93 | |
94 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
95 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
0 | 96 if ( device ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
97 SDL_memset(device, 0, (sizeof *device)); |
0 | 98 device->hidden = (struct SDL_PrivateVideoData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
99 SDL_malloc((sizeof *device->hidden)); |
0 | 100 } |
101 if ( (device == NULL) || (device->hidden == NULL) ) { | |
102 SDL_OutOfMemory(); | |
103 if ( device ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
104 SDL_free(device); |
0 | 105 } |
106 return(0); | |
107 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
108 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
0 | 109 |
110 /* Set the function pointers */ | |
111 device->VideoInit = GGI_VideoInit; | |
112 device->ListModes = GGI_ListModes; | |
113 device->SetVideoMode = GGI_SetVideoMode; | |
114 device->SetColors = GGI_SetColors; | |
115 device->UpdateRects = NULL; | |
116 device->VideoQuit = GGI_VideoQuit; | |
117 device->AllocHWSurface = GGI_AllocHWSurface; | |
118 device->CheckHWBlit = NULL; | |
119 device->FillHWRect = NULL; | |
120 device->SetHWColorKey = NULL; | |
121 device->SetHWAlpha = NULL; | |
122 device->LockHWSurface = GGI_LockHWSurface; | |
123 device->UnlockHWSurface = GGI_UnlockHWSurface; | |
124 device->FlipHWSurface = NULL; | |
125 device->FreeHWSurface = GGI_FreeHWSurface; | |
126 device->SetCaption = NULL; | |
127 device->SetIcon = NULL; | |
128 device->IconifyWindow = NULL; | |
129 device->GrabInput = NULL; | |
130 device->GetWMInfo = NULL; | |
131 device->InitOSKeymap = GGI_InitOSKeymap; | |
132 device->PumpEvents = GGI_PumpEvents; | |
133 | |
134 device->free = GGI_DeleteDevice; | |
135 | |
136 return device; | |
137 } | |
138 | |
139 VideoBootStrap GGI_bootstrap = { | |
140 "ggi", "General Graphics Interface (GGI)", | |
141 GGI_Available, GGI_CreateDevice | |
142 }; | |
143 | |
144 | |
145 static SDL_Rect video_mode; | |
146 static SDL_Rect *SDL_modelist[4] = { NULL, NULL, NULL, NULL }; | |
147 | |
148 int GGI_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
149 { | |
150 ggi_mode mode = | |
151 { | |
152 1, | |
153 { GGI_AUTO, GGI_AUTO }, | |
154 { GGI_AUTO, GGI_AUTO }, | |
155 { 0, 0 }, | |
156 GT_AUTO, | |
157 { GGI_AUTO, GGI_AUTO } | |
158 }; | |
159 struct private_hwdata *priv; | |
160 ggi_color pal[256], map[256]; | |
161 const ggi_directbuffer *db; | |
162 int err, num_bufs; | |
163 ggi_pixel white, black; | |
164 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
165 priv = SDL_malloc(sizeof(struct private_hwdata)); |
0 | 166 if (priv == NULL) |
167 { | |
168 SDL_SetError("Unhandled GGI mode type!\n"); | |
169 GGI_VideoQuit(NULL); | |
170 } | |
171 | |
172 if (ggiInit() != 0) | |
173 { | |
174 SDL_SetError("Unable to initialize GGI!\n"); | |
175 GGI_VideoQuit(NULL); | |
176 } | |
177 | |
178 VIS = ggiOpen(NULL); | |
179 if (VIS == NULL) | |
180 { | |
181 SDL_SetError("Unable to open default GGI visual!\n"); | |
182 ggiExit(); | |
183 GGI_VideoQuit(NULL); | |
184 } | |
185 | |
186 ggiSetFlags(VIS, GGIFLAG_ASYNC); | |
187 | |
188 /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ | |
189 ggiCheckMode(VIS, &mode); | |
190 | |
191 /* At this point we should have a valid mode - try to set it */ | |
192 err = ggiSetMode(VIS, &mode); | |
193 | |
194 /* If we couldn't set _any_ modes, something is very wrong */ | |
195 if (err) | |
196 { | |
197 SDL_SetError("Can't set a mode!\n"); | |
198 ggiClose(VIS); | |
199 ggiExit(); | |
200 GGI_VideoQuit(NULL); | |
201 } | |
202 | |
203 /* Set a palette for palletized modes */ | |
204 if (GT_SCHEME(mode.graphtype) == GT_PALETTE) | |
205 { | |
206 ggiSetColorfulPalette(VIS); | |
207 ggiGetPalette(VIS, 0, 1 << vformat->BitsPerPixel, pal); | |
208 } | |
209 | |
210 /* Now we try to get the DirectBuffer info, which determines whether | |
211 * SDL can access hardware surfaces directly. */ | |
212 | |
213 num_bufs = ggiDBGetNumBuffers(VIS); | |
214 | |
215 if (num_bufs > 0) | |
216 { | |
217 db = ggiDBGetBuffer(VIS, 0); /* Only handle one DB for now */ | |
218 | |
219 vformat->BitsPerPixel = db->buffer.plb.pixelformat->depth; | |
220 | |
221 vformat->Rmask = db->buffer.plb.pixelformat->red_mask; | |
222 vformat->Gmask = db->buffer.plb.pixelformat->green_mask; | |
223 vformat->Bmask = db->buffer.plb.pixelformat->blue_mask; | |
224 | |
225 /* Fill in our hardware acceleration capabilities */ | |
226 | |
227 this->info.wm_available = 0; | |
228 this->info.hw_available = 1; | |
229 this->info.video_mem = db->buffer.plb.stride * mode.virt.y; | |
230 } | |
231 | |
232 video_mode.x = 0; | |
233 video_mode.y = 0; | |
234 video_mode.w = mode.virt.x; | |
235 video_mode.h = mode.virt.y; | |
236 SDL_modelist[((vformat->BitsPerPixel + 7) / 8) - 1] = &video_mode; | |
237 | |
238 /* We're done! */ | |
239 return(0); | |
240 } | |
241 | |
242 static SDL_Rect **GGI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
243 { | |
244 return(&SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]); | |
245 } | |
246 | |
247 /* Various screen update functions available */ | |
248 static void GGI_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | |
249 | |
250 SDL_Surface *GGI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) | |
251 { | |
252 ggi_mode mode = | |
253 { | |
254 1, | |
255 { GGI_AUTO, GGI_AUTO }, | |
256 { GGI_AUTO, GGI_AUTO }, | |
257 { 0, 0 }, | |
258 GT_AUTO, | |
259 { GGI_AUTO, GGI_AUTO } | |
260 }; | |
261 const ggi_directbuffer *db; | |
262 ggi_color pal[256]; | |
263 int err; | |
264 | |
265 fprintf(stderr, "GGI_SetVideoMode()\n"); | |
266 | |
267 mode.visible.x = mode.virt.x = width; | |
268 mode.visible.y = mode.virt.y = height; | |
269 | |
270 /* Translate requested SDL bit depth into a GGI mode */ | |
271 switch (bpp) | |
272 { | |
273 case 1: mode.graphtype = GT_1BIT; break; | |
274 case 2: mode.graphtype = GT_2BIT; break; | |
275 case 4: mode.graphtype = GT_4BIT; break; | |
276 case 8: mode.graphtype = GT_8BIT; break; | |
277 case 15: mode.graphtype = GT_15BIT; break; | |
278 case 16: mode.graphtype = GT_16BIT; break; | |
279 case 24: mode.graphtype = GT_24BIT; break; | |
280 case 32: mode.graphtype = GT_32BIT; break; | |
281 default: | |
282 SDL_SetError("Unknown SDL bit depth, using GT_AUTO....\n"); | |
283 mode.graphtype = GT_AUTO; | |
284 } | |
285 | |
286 /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ | |
287 ggiCheckMode(VIS, &mode); | |
288 | |
289 /* At this point we should have a valid mode - try to set it */ | |
290 err = ggiSetMode(VIS, &mode); | |
291 | |
292 /* If we couldn't set _any_ modes, something is very wrong */ | |
293 if (err) | |
294 { | |
295 SDL_SetError("Can't set a mode!\n"); | |
296 ggiClose(VIS); | |
297 ggiExit(); | |
298 GGI_VideoQuit(NULL); | |
299 } | |
300 | |
301 /* Set a palette for palletized modes */ | |
302 if (GT_SCHEME(mode.graphtype) == GT_PALETTE) | |
303 { | |
304 ggiSetColorfulPalette(VIS); | |
305 ggiGetPalette(VIS, 0, 1 << bpp, pal); | |
306 } | |
307 | |
308 db = ggiDBGetBuffer(VIS, 0); | |
309 | |
310 /* Set up the new mode framebuffer */ | |
311 current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); | |
312 current->w = mode.virt.x; | |
313 current->h = mode.virt.y; | |
314 current->pitch = db->buffer.plb.stride; | |
315 current->pixels = db->read; | |
316 | |
317 /* Set the blit function */ | |
318 this->UpdateRects = GGI_DirectUpdate; | |
319 | |
320 /* We're done */ | |
321 return(current); | |
322 } | |
323 | |
324 static int GGI_AllocHWSurface(_THIS, SDL_Surface *surface) | |
325 { | |
326 return(-1); | |
327 } | |
328 static void GGI_FreeHWSurface(_THIS, SDL_Surface *surface) | |
329 { | |
330 return; | |
331 } | |
332 static int GGI_LockHWSurface(_THIS, SDL_Surface *surface) | |
333 { | |
334 return(0); | |
335 } | |
336 static void GGI_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
337 { | |
338 return; | |
339 } | |
340 | |
341 static void GGI_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | |
342 { | |
343 int i; | |
344 | |
345 /* ggiFlush(VIS); */ | |
346 | |
347 for (i = 0; i < numrects; i++) | |
348 { | |
349 ggiFlushRegion(VIS, rects[i].x, rects[i].y, rects[i].w, rects[i].h); | |
350 } | |
351 return; | |
352 } | |
353 | |
354 int GGI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
355 { | |
356 int i; | |
357 ggi_color pal[256]; | |
358 | |
359 /* Set up the colormap */ | |
360 for (i = 0; i < ncolors; i++) | |
361 { | |
362 pal[i].r = (colors[i].r << 8) | colors[i].r; | |
363 pal[i].g = (colors[i].g << 8) | colors[i].g; | |
364 pal[i].b = (colors[i].b << 8) | colors[i].b; | |
365 } | |
366 | |
367 ggiSetPalette(VIS, firstcolor, ncolors, pal); | |
368 | |
369 return 1; | |
370 } | |
371 | |
372 void GGI_VideoQuit(_THIS) | |
373 { | |
374 } | |
375 void GGI_FinalQuit(void) | |
376 { | |
377 } |