Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
400 lines (332 loc) · 10.1 KB

SDL_ggivideo.c

File metadata and controls

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