comparison src/video/vgl/SDL_vglvideo.c @ 1662:782fd950bd46 SDL-1.3

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