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