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

Latest commit

 

History

History
662 lines (573 loc) · 18.4 KB

SDL_vglvideo.c

File metadata and controls

662 lines (573 loc) · 18.4 KB
 
Jun 19, 2001
Jun 19, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Jun 19, 2001
Jun 19, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Jun 19, 2001
Jun 19, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Jun 19, 2001
Jun 19, 2001
9
10
11
12
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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Jun 19, 2001
Jun 19, 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
Jun 19, 2001
Jun 19, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Jun 19, 2001
Jun 19, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Jun 19, 2001
Jun 19, 2001
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* libvga based SDL video driver implementation.
*/
#include <err.h>
#include <osreldate.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/fbio.h>
#include <sys/consio.h>
#include <sys/kbio.h>
#include <vgl.h>
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
39
40
41
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Jun 19, 2001
Jun 19, 2001
42
43
44
45
46
47
#include "SDL_vglvideo.h"
#include "SDL_vglevents_c.h"
#include "SDL_vglmouse_c.h"
/* Initialization/Query functions */
May 29, 2006
May 29, 2006
48
49
50
51
52
53
54
55
static int VGL_VideoInit(_THIS, SDL_PixelFormat * vformat);
static SDL_Rect **VGL_ListModes(_THIS, SDL_PixelFormat * format,
Uint32 flags);
static SDL_Surface *VGL_SetVideoMode(_THIS, SDL_Surface * current, int width,
int height, int bpp, Uint32 flags);
static int VGL_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color * colors);
static void VGL_VideoQuit(_THIS);
Jun 19, 2001
Jun 19, 2001
56
57
/* Hardware surface functions */
May 29, 2006
May 29, 2006
58
59
60
61
62
static int VGL_AllocHWSurface(_THIS, SDL_Surface * surface);
static int VGL_LockHWSurface(_THIS, SDL_Surface * surface);
static int VGL_FlipHWSurface(_THIS, SDL_Surface * surface);
static void VGL_UnlockHWSurface(_THIS, SDL_Surface * surface);
static void VGL_FreeHWSurface(_THIS, SDL_Surface * surface);
Jun 19, 2001
Jun 19, 2001
63
64
/* Misc function */
May 29, 2006
May 29, 2006
65
66
static VGLMode **VGLListModes(int depth, int mem_model);
static void VGLWaitRetrace(void);
Jun 19, 2001
Jun 19, 2001
67
68
69
/* VGL driver bootstrap functions */
May 28, 2006
May 28, 2006
70
static int
May 29, 2006
May 29, 2006
71
VGL_Available(void)
Jun 19, 2001
Jun 19, 2001
72
{
May 28, 2006
May 28, 2006
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Check to see if we are root and stdin is a
* virtual console. Also try to ensure that
* modes other than 320x200 are available
*/
int console, hires_available, i;
VGLMode **modes;
console = STDIN_FILENO;
if (console >= 0) {
struct stat sb;
struct vt_mode dummy;
May 29, 2006
May 29, 2006
86
87
if ((fstat(console, &sb) < 0) ||
(ioctl(console, VT_GETMODE, &dummy) < 0)) {
May 28, 2006
May 28, 2006
88
89
90
console = -1;
}
}
May 29, 2006
May 29, 2006
91
if (geteuid() != 0 && console == -1)
May 28, 2006
May 28, 2006
92
93
return 0;
May 29, 2006
May 29, 2006
94
modes = VGLListModes(8, V_INFO_MM_DIRECT | V_INFO_MM_PACKED);
May 28, 2006
May 28, 2006
95
96
97
98
99
100
101
102
103
104
105
106
hires_available = 0;
for (i = 0; modes[i] != NULL; i++) {
if ((modes[i]->ModeInfo.Xsize > 320) &&
(modes[i]->ModeInfo.Ysize > 200) &&
((modes[i]->ModeInfo.Type == VIDBUF8) ||
(modes[i]->ModeInfo.Type == VIDBUF16) ||
(modes[i]->ModeInfo.Type == VIDBUF32))) {
hires_available = 1;
break;
}
}
return hires_available;
Jun 19, 2001
Jun 19, 2001
107
108
}
May 28, 2006
May 28, 2006
109
static void
May 29, 2006
May 29, 2006
110
VGL_DeleteDevice(SDL_VideoDevice * device)
Jun 19, 2001
Jun 19, 2001
111
{
May 29, 2006
May 29, 2006
112
113
SDL_free(device->hidden);
SDL_free(device);
Jun 19, 2001
Jun 19, 2001
114
115
}
May 28, 2006
May 28, 2006
116
static SDL_VideoDevice *
May 29, 2006
May 29, 2006
117
VGL_CreateDevice(int devindex)
Jun 19, 2001
Jun 19, 2001
118
{
May 28, 2006
May 28, 2006
119
120
121
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
May 29, 2006
May 29, 2006
122
device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
May 28, 2006
May 28, 2006
123
if (device) {
May 29, 2006
May 29, 2006
124
SDL_memset(device, 0, (sizeof *device));
May 28, 2006
May 28, 2006
125
device->hidden = (struct SDL_PrivateVideoData *)
May 29, 2006
May 29, 2006
126
SDL_malloc((sizeof *device->hidden));
May 28, 2006
May 28, 2006
127
128
}
if ((device == NULL) || (device->hidden == NULL)) {
May 29, 2006
May 29, 2006
129
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
130
if (device) {
May 29, 2006
May 29, 2006
131
SDL_free(device);
May 28, 2006
May 28, 2006
132
133
134
}
return (0);
}
May 29, 2006
May 29, 2006
135
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
May 28, 2006
May 28, 2006
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* Set the function pointers */
device->VideoInit = VGL_VideoInit;
device->ListModes = VGL_ListModes;
device->SetVideoMode = VGL_SetVideoMode;
device->SetColors = VGL_SetColors;
device->UpdateRects = NULL;
device->VideoQuit = VGL_VideoQuit;
device->AllocHWSurface = VGL_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = VGL_LockHWSurface;
device->UnlockHWSurface = VGL_UnlockHWSurface;
device->FlipHWSurface = VGL_FlipHWSurface;
device->FreeHWSurface = VGL_FreeHWSurface;
device->SetIcon = NULL;
device->SetCaption = NULL;
device->GetWMInfo = NULL;
device->FreeWMCursor = VGL_FreeWMCursor;
device->CreateWMCursor = VGL_CreateWMCursor;
device->ShowWMCursor = VGL_ShowWMCursor;
device->WarpWMCursor = VGL_WarpWMCursor;
device->InitOSKeymap = VGL_InitOSKeymap;
device->PumpEvents = VGL_PumpEvents;
device->free = VGL_DeleteDevice;
return device;
Jun 19, 2001
Jun 19, 2001
166
167
168
}
VideoBootStrap VGL_bootstrap = {
May 28, 2006
May 28, 2006
169
170
"vgl", "FreeBSD libVGL",
VGL_Available, VGL_CreateDevice
Jun 19, 2001
Jun 19, 2001
171
172
};
May 28, 2006
May 28, 2006
173
static int
May 29, 2006
May 29, 2006
174
VGL_AddMode(_THIS, VGLMode * inmode)
Jun 19, 2001
Jun 19, 2001
175
{
May 28, 2006
May 28, 2006
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
SDL_Rect *mode;
int i, index;
int next_mode;
/* Check to see if we already have this mode */
if (inmode->Depth < 8) { /* Not supported */
return 0;
}
index = ((inmode->Depth + 7) / 8) - 1;
for (i = 0; i < SDL_nummodes[index]; ++i) {
mode = SDL_modelist[index][i];
if ((mode->w == inmode->ModeInfo.Xsize) &&
(mode->h == inmode->ModeInfo.Ysize))
return 0;
}
/* Set up the new video mode rectangle */
May 29, 2006
May 29, 2006
194
mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
May 28, 2006
May 28, 2006
195
if (mode == NULL) {
May 29, 2006
May 29, 2006
196
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
197
198
199
200
201
202
203
204
205
206
return -1;
}
mode->x = 0;
mode->y = 0;
mode->w = inmode->ModeInfo.Xsize;
mode->h = inmode->ModeInfo.Ysize;
/* Allocate the new list of modes, and fill in the new mode */
next_mode = SDL_nummodes[index];
SDL_modelist[index] = (SDL_Rect **)
May 29, 2006
May 29, 2006
207
208
SDL_realloc(SDL_modelist[index],
(1 + next_mode + 1) * sizeof(SDL_Rect *));
May 28, 2006
May 28, 2006
209
if (SDL_modelist[index] == NULL) {
May 29, 2006
May 29, 2006
210
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
211
SDL_nummodes[index] = 0;
May 29, 2006
May 29, 2006
212
SDL_free(mode);
May 28, 2006
May 28, 2006
213
214
215
216
217
218
219
return -1;
}
SDL_modelist[index][next_mode] = mode;
SDL_modelist[index][next_mode + 1] = NULL;
SDL_nummodes[index]++;
return 0;
Jun 19, 2001
Jun 19, 2001
220
221
}
May 28, 2006
May 28, 2006
222
static void
May 29, 2006
May 29, 2006
223
VGL_UpdateVideoInfo(_THIS)
Jun 19, 2001
Jun 19, 2001
224
{
May 28, 2006
May 28, 2006
225
226
227
228
229
230
231
232
233
234
this->info.wm_available = 0;
this->info.hw_available = 1;
this->info.video_mem = 0;
if (VGLCurMode == NULL) {
return;
}
if (VGLCurMode->ModeInfo.PixelBytes > 0) {
this->info.video_mem = VGLCurMode->ModeInfo.PixelBytes *
VGLCurMode->ModeInfo.Xsize * VGLCurMode->ModeInfo.Ysize;
}
Jun 19, 2001
Jun 19, 2001
235
236
}
May 28, 2006
May 28, 2006
237
int
May 29, 2006
May 29, 2006
238
VGL_VideoInit(_THIS, SDL_PixelFormat * vformat)
Jun 19, 2001
Jun 19, 2001
239
{
May 28, 2006
May 28, 2006
240
241
242
243
244
245
246
247
248
249
250
int i;
int total_modes;
VGLMode **modes;
/* Initialize all variables that we clean on shutdown */
for (i = 0; i < NUM_MODELISTS; ++i) {
SDL_nummodes[i] = 0;
SDL_modelist[i] = NULL;
}
/* Enable mouse and keyboard support */
May 29, 2006
May 29, 2006
251
252
253
if (SDL_getenv("SDL_NO_RAWKBD") == NULL) {
if (VGLKeyboardInit(VGL_CODEKEYS) != 0) {
SDL_SetError("Unable to initialize keyboard");
May 28, 2006
May 28, 2006
254
255
256
return -1;
}
} else {
May 29, 2006
May 29, 2006
257
warnx("Requiest to put keyboard into a raw mode ignored");
May 28, 2006
May 28, 2006
258
}
May 29, 2006
May 29, 2006
259
260
if (VGL_initkeymaps(STDIN_FILENO) != 0) {
SDL_SetError("Unable to initialize keymap");
May 28, 2006
May 28, 2006
261
262
return -1;
}
May 29, 2006
May 29, 2006
263
264
if (VGL_initmouse(STDIN_FILENO) != 0) {
SDL_SetError("Unable to initialize mouse");
May 28, 2006
May 28, 2006
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
return -1;
}
/* Determine the current screen size */
if (VGLCurMode != NULL) {
this->info.current_w = VGLCurMode->ModeInfo.Xsize;
this->info.current_h = VGLCurMode->ModeInfo.Ysize;
}
/* Determine the screen depth */
if (VGLCurMode != NULL)
vformat->BitsPerPixel = VGLCurMode->Depth;
else
vformat->BitsPerPixel = 16; /* Good default */
/* Query for the list of available video modes */
total_modes = 0;
May 29, 2006
May 29, 2006
282
modes = VGLListModes(-1, V_INFO_MM_DIRECT | V_INFO_MM_PACKED);
May 28, 2006
May 28, 2006
283
284
285
286
for (i = 0; modes[i] != NULL; i++) {
if ((modes[i]->ModeInfo.Type == VIDBUF8) ||
(modes[i]->ModeInfo.Type == VIDBUF16) ||
(modes[i]->ModeInfo.Type == VIDBUF32)) {
May 29, 2006
May 29, 2006
287
VGL_AddMode(this, modes[i]);
May 28, 2006
May 28, 2006
288
289
290
291
total_modes++;
}
}
if (total_modes == 0) {
May 29, 2006
May 29, 2006
292
SDL_SetError("No linear video modes available");
May 28, 2006
May 28, 2006
293
294
295
296
return -1;
}
/* Fill in our hardware acceleration capabilities */
May 29, 2006
May 29, 2006
297
VGL_UpdateVideoInfo(this);
May 28, 2006
May 28, 2006
298
299
/* Create the hardware surface lock mutex */
May 29, 2006
May 29, 2006
300
hw_lock = SDL_CreateMutex();
May 28, 2006
May 28, 2006
301
if (hw_lock == NULL) {
May 29, 2006
May 29, 2006
302
303
SDL_SetError("Unable to create lock mutex");
VGL_VideoQuit(this);
May 28, 2006
May 28, 2006
304
305
306
307
308
return -1;
}
/* We're done! */
return 0;
Jun 19, 2001
Jun 19, 2001
309
310
}
May 28, 2006
May 28, 2006
311
SDL_Rect **
May 29, 2006
May 29, 2006
312
VGL_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
Jun 19, 2001
Jun 19, 2001
313
{
May 28, 2006
May 28, 2006
314
return SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
Jun 19, 2001
Jun 19, 2001
315
316
317
}
/* Various screen update functions available */
May 29, 2006
May 29, 2006
318
319
static void VGL_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
static void VGL_BankedUpdate(_THIS, int numrects, SDL_Rect * rects);
Jun 19, 2001
Jun 19, 2001
320
May 28, 2006
May 28, 2006
321
SDL_Surface *
May 29, 2006
May 29, 2006
322
323
VGL_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp, Uint32 flags)
Jun 19, 2001
Jun 19, 2001
324
{
May 28, 2006
May 28, 2006
325
326
327
328
int mode_found;
int i;
VGLMode **modes;
May 29, 2006
May 29, 2006
329
modes = VGLListModes(bpp, V_INFO_MM_DIRECT | V_INFO_MM_PACKED);
May 28, 2006
May 28, 2006
330
331
332
333
334
335
336
337
338
339
340
341
mode_found = 0;
for (i = 0; modes[i] != NULL; i++) {
if ((modes[i]->ModeInfo.Xsize == width) &&
(modes[i]->ModeInfo.Ysize == height) &&
((modes[i]->ModeInfo.Type == VIDBUF8) ||
(modes[i]->ModeInfo.Type == VIDBUF16) ||
(modes[i]->ModeInfo.Type == VIDBUF32))) {
mode_found = 1;
break;
}
}
if (mode_found == 0) {
May 29, 2006
May 29, 2006
342
SDL_SetError("No matching video mode found");
May 28, 2006
May 28, 2006
343
344
345
346
347
return NULL;
}
/* Shutdown previous videomode (if any) */
if (VGLCurMode != NULL)
May 29, 2006
May 29, 2006
348
VGLEnd();
May 28, 2006
May 28, 2006
349
350
/* Try to set the requested linear video mode */
May 29, 2006
May 29, 2006
351
352
if (VGLInit(modes[i]->ModeId) != 0) {
SDL_SetError("Unable to switch to requested mode");
May 28, 2006
May 28, 2006
353
354
355
return NULL;
}
May 29, 2006
May 29, 2006
356
VGLCurMode = SDL_realloc(VGLCurMode, sizeof(VGLMode));
May 28, 2006
May 28, 2006
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
VGLCurMode->ModeInfo = *VGLDisplay;
VGLCurMode->Depth = modes[i]->Depth;
VGLCurMode->ModeId = modes[i]->ModeId;
VGLCurMode->Rmask = modes[i]->Rmask;
VGLCurMode->Gmask = modes[i]->Gmask;
VGLCurMode->Bmask = modes[i]->Bmask;
/* Workaround a bug in libvgl */
if (VGLCurMode->ModeInfo.PixelBytes == 0)
(VGLCurMode->ModeInfo.PixelBytes = 1);
current->w = VGLCurMode->ModeInfo.Xsize;
current->h = VGLCurMode->ModeInfo.Ysize;
current->pixels = VGLCurMode->ModeInfo.Bitmap;
current->pitch = VGLCurMode->ModeInfo.Xsize *
VGLCurMode->ModeInfo.PixelBytes;
current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE);
/* Check if we are in a pseudo-color mode */
if (VGLCurMode->ModeInfo.Type == VIDBUF8)
current->flags |= SDL_HWPALETTE;
/* Check if we can do doublebuffering */
if (flags & SDL_DOUBLEBUF) {
if (VGLCurMode->ModeInfo.Xsize * 2 <= VGLCurMode->ModeInfo.VYsize) {
current->flags |= SDL_DOUBLEBUF;
flip_page = 0;
flip_address[0] = (byte *) current->pixels;
flip_address[1] = (byte *) current->pixels +
current->h * current->pitch;
May 29, 2006
May 29, 2006
387
VGL_FlipHWSurface(this, current);
May 28, 2006
May 28, 2006
388
389
390
}
}
May 29, 2006
May 29, 2006
391
392
if (!SDL_ReallocFormat(current, modes[i]->Depth, VGLCurMode->Rmask,
VGLCurMode->Gmask, VGLCurMode->Bmask, 0)) {
May 28, 2006
May 28, 2006
393
394
395
396
return NULL;
}
/* Update hardware acceleration info */
May 29, 2006
May 29, 2006
397
VGL_UpdateVideoInfo(this);
May 28, 2006
May 28, 2006
398
399
400
401
402
403
/* Set the blit function */
this->UpdateRects = VGL_DirectUpdate;
/* We're done */
return current;
Jun 19, 2001
Jun 19, 2001
404
405
406
}
/* We don't actually allow hardware surfaces other than the main one */
May 28, 2006
May 28, 2006
407
static int
May 29, 2006
May 29, 2006
408
VGL_AllocHWSurface(_THIS, SDL_Surface * surface)
Jun 19, 2001
Jun 19, 2001
409
{
May 28, 2006
May 28, 2006
410
return -1;
Jun 19, 2001
Jun 19, 2001
411
}
May 28, 2006
May 28, 2006
412
static void
May 29, 2006
May 29, 2006
413
VGL_FreeHWSurface(_THIS, SDL_Surface * surface)
Jun 19, 2001
Jun 19, 2001
414
{
May 28, 2006
May 28, 2006
415
return;
Jun 19, 2001
Jun 19, 2001
416
417
418
}
/* We need to wait for vertical retrace on page flipped displays */
May 28, 2006
May 28, 2006
419
static int
May 29, 2006
May 29, 2006
420
VGL_LockHWSurface(_THIS, SDL_Surface * surface)
Jun 19, 2001
Jun 19, 2001
421
{
May 28, 2006
May 28, 2006
422
if (surface == SDL_VideoSurface) {
May 29, 2006
May 29, 2006
423
SDL_mutexP(hw_lock);
May 28, 2006
May 28, 2006
424
425
}
return 0;
Jun 19, 2001
Jun 19, 2001
426
}
May 28, 2006
May 28, 2006
427
static void
May 29, 2006
May 29, 2006
428
VGL_UnlockHWSurface(_THIS, SDL_Surface * surface)
Jun 19, 2001
Jun 19, 2001
429
{
May 28, 2006
May 28, 2006
430
if (surface == SDL_VideoSurface) {
May 29, 2006
May 29, 2006
431
SDL_mutexV(hw_lock);
May 28, 2006
May 28, 2006
432
}
Jun 19, 2001
Jun 19, 2001
433
434
}
May 28, 2006
May 28, 2006
435
static int
May 29, 2006
May 29, 2006
436
VGL_FlipHWSurface(_THIS, SDL_Surface * surface)
Jun 19, 2001
Jun 19, 2001
437
{
May 28, 2006
May 28, 2006
438
// VGLWaitRetrace();
May 29, 2006
May 29, 2006
439
440
if (VGLPanScreen(VGLDisplay, 0, flip_page * surface->h) < 0) {
SDL_SetError("VGLPanSreen() failed");
May 28, 2006
May 28, 2006
441
442
return -1;
}
Jun 19, 2001
Jun 19, 2001
443
May 28, 2006
May 28, 2006
444
445
flip_page = !flip_page;
surface->pixels = flip_address[flip_page];
Jun 19, 2001
Jun 19, 2001
446
May 28, 2006
May 28, 2006
447
return 0;
Jun 19, 2001
Jun 19, 2001
448
449
}
May 28, 2006
May 28, 2006
450
static void
May 29, 2006
May 29, 2006
451
VGL_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
Jun 19, 2001
Jun 19, 2001
452
{
May 28, 2006
May 28, 2006
453
return;
Jun 19, 2001
Jun 19, 2001
454
455
}
May 28, 2006
May 28, 2006
456
static void
May 29, 2006
May 29, 2006
457
VGL_BankedUpdate(_THIS, int numrects, SDL_Rect * rects)
Jun 19, 2001
Jun 19, 2001
458
{
May 28, 2006
May 28, 2006
459
return;
Jun 19, 2001
Jun 19, 2001
460
461
}
May 28, 2006
May 28, 2006
462
int
May 29, 2006
May 29, 2006
463
VGL_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
Jun 19, 2001
Jun 19, 2001
464
{
May 28, 2006
May 28, 2006
465
466
467
int i;
for (i = 0; i < ncolors; i++) {
May 29, 2006
May 29, 2006
468
469
470
VGLSetPaletteIndex(firstcolor + i,
colors[i].r >> 2,
colors[i].g >> 2, colors[i].b >> 2);
May 28, 2006
May 28, 2006
471
472
}
return 1;
Jun 19, 2001
Jun 19, 2001
473
474
475
476
477
}
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
May 28, 2006
May 28, 2006
478
void
May 29, 2006
May 29, 2006
479
VGL_VideoQuit(_THIS)
Jun 19, 2001
Jun 19, 2001
480
{
May 28, 2006
May 28, 2006
481
482
483
int i, j;
/* Return the keyboard to the normal state */
May 29, 2006
May 29, 2006
484
VGLKeyboardEnd();
May 28, 2006
May 28, 2006
485
486
487
/* Reset the console video mode if we actually initialised one */
if (VGLCurMode != NULL) {
May 29, 2006
May 29, 2006
488
489
VGLEnd();
SDL_free(VGLCurMode);
May 28, 2006
May 28, 2006
490
491
492
493
494
VGLCurMode = NULL;
}
/* Clear the lock mutex */
if (hw_lock != NULL) {
May 29, 2006
May 29, 2006
495
SDL_DestroyMutex(hw_lock);
May 28, 2006
May 28, 2006
496
497
498
499
500
501
502
hw_lock = NULL;
}
/* Free video mode lists */
for (i = 0; i < NUM_MODELISTS; i++) {
if (SDL_modelist[i] != NULL) {
for (j = 0; SDL_modelist[i][j] != NULL; ++j) {
May 29, 2006
May 29, 2006
503
SDL_free(SDL_modelist[i][j]);
May 28, 2006
May 28, 2006
504
}
May 29, 2006
May 29, 2006
505
SDL_free(SDL_modelist[i]);
May 28, 2006
May 28, 2006
506
507
508
509
510
511
512
513
SDL_modelist[i] = NULL;
}
}
if (this->screen && (this->screen->flags & SDL_HWSURFACE)) {
/* Direct screen access, not a memory buffer */
this->screen->pixels = NULL;
}
Jun 19, 2001
Jun 19, 2001
514
515
516
517
518
519
520
}
#define VGL_RED_INDEX 0
#define VGL_GREEN_INDEX 1
#define VGL_BLUE_INDEX 2
static VGLMode **
May 29, 2006
May 29, 2006
521
VGLListModes(int depth, int mem_model)
Jun 19, 2001
Jun 19, 2001
522
{
May 28, 2006
May 28, 2006
523
524
525
526
527
528
529
530
static VGLMode **modes = NULL;
VGLBitmap *vminfop;
VGLMode **modesp, *modescp;
video_info_t minfo;
int adptype, i, modenum;
if (modes == NULL) {
May 29, 2006
May 29, 2006
531
532
modes = SDL_malloc(sizeof(VGLMode *) * M_VESA_MODE_MAX);
bzero(modes, sizeof(VGLMode *) * M_VESA_MODE_MAX);
May 28, 2006
May 28, 2006
533
534
535
536
537
}
modesp = modes;
for (modenum = 0; modenum < M_VESA_MODE_MAX; modenum++) {
minfo.vi_mode = modenum;
May 29, 2006
May 29, 2006
538
539
if (ioctl(0, CONS_MODEINFO, &minfo)
|| ioctl(0, CONS_CURRENT, &adptype))
May 28, 2006
May 28, 2006
540
541
542
543
544
545
546
547
548
549
550
continue;
if (minfo.vi_mode != modenum)
continue;
if ((minfo.vi_flags & V_INFO_GRAPHICS) == 0)
continue;
if ((mem_model != -1) && ((minfo.vi_mem_model & mem_model) == 0))
continue;
if ((depth > 1) && (minfo.vi_depth != depth))
continue;
/* reallocf can fail */
May 29, 2006
May 29, 2006
551
if ((*modesp = reallocf(*modesp, sizeof(VGLMode))) == NULL)
May 28, 2006
May 28, 2006
552
553
554
555
return NULL;
modescp = *modesp;
vminfop = &(modescp->ModeInfo);
May 29, 2006
May 29, 2006
556
bzero(vminfop, sizeof(VGLBitmap));
May 28, 2006
May 28, 2006
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
vminfop->Type = NOBUF;
vminfop->PixelBytes = 1; /* Good default value */
switch (minfo.vi_mem_model) {
case V_INFO_MM_PLANAR:
/* we can handle EGA/VGA planar modes only */
if (!(minfo.vi_depth != 4 || minfo.vi_planes != 4
|| (adptype != KD_EGA && adptype != KD_VGA)))
vminfop->Type = VIDBUF4;
break;
case V_INFO_MM_PACKED:
/* we can do only 256 color packed modes */
if (minfo.vi_depth == 8)
vminfop->Type = VIDBUF8;
break;
case V_INFO_MM_VGAX:
vminfop->Type = VIDBUF8X;
break;
Mar 21, 2006
Mar 21, 2006
576
#if defined(__FREEBSD__) && (defined(__DragonFly__) || __FreeBSD_version >= 500000)
May 28, 2006
May 28, 2006
577
578
579
580
581
582
case V_INFO_MM_DIRECT:
vminfop->PixelBytes = minfo.vi_pixel_size;
switch (vminfop->PixelBytes) {
case 2:
vminfop->Type = VIDBUF16;
break;
Jun 19, 2001
Jun 19, 2001
583
#if notyet
May 28, 2006
May 28, 2006
584
585
586
case 3:
vminfop->Type = VIDBUF24;
break;
Jun 19, 2001
Jun 19, 2001
587
#endif
May 28, 2006
May 28, 2006
588
589
590
591
592
593
case 4:
vminfop->Type = VIDBUF32;
break;
default:
break;
}
Jun 19, 2001
Jun 19, 2001
594
#endif
May 28, 2006
May 28, 2006
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
default:
break;
}
if (vminfop->Type == NOBUF)
continue;
switch (vminfop->Type) {
case VIDBUF16:
case VIDBUF32:
modescp->Rmask =
((1 << minfo.vi_pixel_fsizes[VGL_RED_INDEX]) -
1) << minfo.vi_pixel_fields[VGL_RED_INDEX];
modescp->Gmask =
((1 << minfo.vi_pixel_fsizes[VGL_GREEN_INDEX]) -
1) << minfo.vi_pixel_fields[VGL_GREEN_INDEX];
modescp->Bmask =
((1 << minfo.vi_pixel_fsizes[VGL_BLUE_INDEX]) -
1) << minfo.vi_pixel_fields[VGL_BLUE_INDEX];
break;
default:
break;
}
vminfop->Xsize = minfo.vi_width;
vminfop->Ysize = minfo.vi_height;
modescp->Depth = minfo.vi_depth;
/* XXX */
if (minfo.vi_mode >= M_VESA_BASE)
May 29, 2006
May 29, 2006
625
modescp->ModeId = _IO('V', minfo.vi_mode - M_VESA_BASE);
May 28, 2006
May 28, 2006
626
else
May 29, 2006
May 29, 2006
627
modescp->ModeId = _IO('S', minfo.vi_mode);
May 28, 2006
May 28, 2006
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/* Sort list */
for (i = 0; modes + i < modesp; i++) {
if (modes[i]->ModeInfo.Xsize * modes[i]->ModeInfo.Ysize >
vminfop->Xsize * modes[i]->ModeInfo.Ysize)
continue;
if ((modes[i]->ModeInfo.Xsize * modes[i]->ModeInfo.Ysize ==
vminfop->Xsize * vminfop->Ysize) &&
(modes[i]->Depth >= modescp->Depth))
continue;
*modesp = modes[i];
modes[i] = modescp;
modescp = *modesp;
vminfop = &(modescp->ModeInfo);
}
modesp++;
}
if (*modesp != NULL) {
May 29, 2006
May 29, 2006
648
SDL_free(*modesp);
May 28, 2006
May 28, 2006
649
650
651
652
*modesp = NULL;
}
return modes;
Jun 19, 2001
Jun 19, 2001
653
654
655
}
static void
May 29, 2006
May 29, 2006
656
VGLWaitRetrace(void)
Jun 19, 2001
Jun 19, 2001
657
{
May 29, 2006
May 29, 2006
658
659
while (!(inb(0x3DA) & 8));
while (inb(0x3DA) & 8);
Jun 19, 2001
Jun 19, 2001
660
661
}
May 28, 2006
May 28, 2006
662
/* vi: set ts=4 sw=4 expandtab: */