comparison src/video/dga/SDL_dgavideo.c @ 1575:3ba88cb7eb1b

Updated dynamic X11 code. See details in Bugzilla #170.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 22 Mar 2006 05:00:59 +0000
parents 8d9bb0cf2c2a
children 14717b52abc0 45669d4efd02
comparison
equal deleted inserted replaced
1574:0fd72308659e 1575:3ba88cb7eb1b
71 71
72 /* The driver is available is available if the display is local 72 /* The driver is available is available if the display is local
73 and the DGA 2.0+ extension is available, and we can map mem. 73 and the DGA 2.0+ extension is available, and we can map mem.
74 */ 74 */
75 if ( SDL_X11_LoadSymbols() ) { 75 if ( SDL_X11_LoadSymbols() ) {
76 if ( (SDL_strncmp(pXDisplayName(display), ":", 1) == 0) || 76 if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
77 (SDL_strncmp(pXDisplayName(display), "unix:", 5) == 0) ) { 77 (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
78 dpy = pXOpenDisplay(display); 78 dpy = XOpenDisplay(display);
79 if ( dpy ) { 79 if ( dpy ) {
80 int events, errors, major, minor; 80 int events, errors, major, minor;
81 81
82 if ( SDL_NAME(XDGAQueryExtension)(dpy, &events, &errors) && 82 if ( SDL_NAME(XDGAQueryExtension)(dpy, &events, &errors) &&
83 SDL_NAME(XDGAQueryVersion)(dpy, &major, &minor) ) { 83 SDL_NAME(XDGAQueryVersion)(dpy, &major, &minor) ) {
88 SDL_NAME(XDGAOpenFramebuffer)(dpy, screen) ) { 88 SDL_NAME(XDGAOpenFramebuffer)(dpy, screen) ) {
89 available = 1; 89 available = 1;
90 SDL_NAME(XDGACloseFramebuffer)(dpy, screen); 90 SDL_NAME(XDGACloseFramebuffer)(dpy, screen);
91 } 91 }
92 } 92 }
93 pXCloseDisplay(dpy); 93 XCloseDisplay(dpy);
94 } 94 }
95 } 95 }
96 SDL_X11_UnloadSymbols(); 96 SDL_X11_UnloadSymbols();
97 } 97 }
98 return(available); 98 return(available);
327 int i, num_modes; 327 int i, num_modes;
328 328
329 /* Open the X11 display */ 329 /* Open the X11 display */
330 display = NULL; /* Get it from DISPLAY environment variable */ 330 display = NULL; /* Get it from DISPLAY environment variable */
331 331
332 DGA_Display = pXOpenDisplay(display); 332 DGA_Display = XOpenDisplay(display);
333 if ( DGA_Display == NULL ) { 333 if ( DGA_Display == NULL ) {
334 SDL_SetError("Couldn't open X11 display"); 334 SDL_SetError("Couldn't open X11 display");
335 return(-1); 335 return(-1);
336 } 336 }
337 337
338 /* Check for the DGA extension */ 338 /* Check for the DGA extension */
339 if ( ! SDL_NAME(XDGAQueryExtension)(DGA_Display, &event_base, &error_base) || 339 if ( ! SDL_NAME(XDGAQueryExtension)(DGA_Display, &event_base, &error_base) ||
340 ! SDL_NAME(XDGAQueryVersion)(DGA_Display, &major_version, &minor_version) ) { 340 ! SDL_NAME(XDGAQueryVersion)(DGA_Display, &major_version, &minor_version) ) {
341 SDL_SetError("DGA extension not available"); 341 SDL_SetError("DGA extension not available");
342 pXCloseDisplay(DGA_Display); 342 XCloseDisplay(DGA_Display);
343 return(-1); 343 return(-1);
344 } 344 }
345 if ( major_version < 2 ) { 345 if ( major_version < 2 ) {
346 SDL_SetError("DGA driver requires DGA 2.0 or newer"); 346 SDL_SetError("DGA driver requires DGA 2.0 or newer");
347 pXCloseDisplay(DGA_Display); 347 XCloseDisplay(DGA_Display);
348 return(-1); 348 return(-1);
349 } 349 }
350 DGA_event_base = event_base; 350 DGA_event_base = event_base;
351 351
352 /* Determine the current screen size */ 352 /* Determine the current screen size */
358 { 358 {
359 XPixmapFormatValues *pix_format; 359 XPixmapFormatValues *pix_format;
360 int i, num_formats; 360 int i, num_formats;
361 361
362 vformat->BitsPerPixel = DefaultDepth(DGA_Display, DGA_Screen); 362 vformat->BitsPerPixel = DefaultDepth(DGA_Display, DGA_Screen);
363 pix_format = pXListPixmapFormats(DGA_Display, &num_formats); 363 pix_format = XListPixmapFormats(DGA_Display, &num_formats);
364 if ( pix_format == NULL ) { 364 if ( pix_format == NULL ) {
365 SDL_SetError("Couldn't determine screen formats"); 365 SDL_SetError("Couldn't determine screen formats");
366 pXCloseDisplay(DGA_Display); 366 XCloseDisplay(DGA_Display);
367 return(-1); 367 return(-1);
368 } 368 }
369 for ( i=0; i<num_formats; ++i ) { 369 for ( i=0; i<num_formats; ++i ) {
370 if ( vformat->BitsPerPixel == pix_format[i].depth ) 370 if ( vformat->BitsPerPixel == pix_format[i].depth )
371 break; 371 break;
372 } 372 }
373 if ( i != num_formats ) 373 if ( i != num_formats )
374 vformat->BitsPerPixel = pix_format[i].bits_per_pixel; 374 vformat->BitsPerPixel = pix_format[i].bits_per_pixel;
375 pXFree((char *)pix_format); 375 XFree((char *)pix_format);
376 } 376 }
377 if ( vformat->BitsPerPixel > 8 ) { 377 if ( vformat->BitsPerPixel > 8 ) {
378 vformat->Rmask = visual->red_mask; 378 vformat->Rmask = visual->red_mask;
379 vformat->Gmask = visual->green_mask; 379 vformat->Gmask = visual->green_mask;
380 vformat->Bmask = visual->blue_mask; 380 vformat->Bmask = visual->blue_mask;
381 } 381 }
382 382
383 /* Open access to the framebuffer */ 383 /* Open access to the framebuffer */
384 if ( ! SDL_NAME(XDGAOpenFramebuffer)(DGA_Display, DGA_Screen) ) { 384 if ( ! SDL_NAME(XDGAOpenFramebuffer)(DGA_Display, DGA_Screen) ) {
385 SDL_SetError("Unable to map the video memory"); 385 SDL_SetError("Unable to map the video memory");
386 pXCloseDisplay(DGA_Display); 386 XCloseDisplay(DGA_Display);
387 return(-1); 387 return(-1);
388 } 388 }
389 389
390 /* Query for the list of available video modes */ 390 /* Query for the list of available video modes */
391 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes); 391 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
401 modes[i].viewportWidth, 401 modes[i].viewportWidth,
402 modes[i].viewportHeight); 402 modes[i].viewportHeight);
403 } 403 }
404 } 404 }
405 UpdateHWInfo(this, modes); 405 UpdateHWInfo(this, modes);
406 pXFree(modes); 406 XFree(modes);
407 407
408 /* Create the hardware surface lock mutex */ 408 /* Create the hardware surface lock mutex */
409 hw_lock = SDL_CreateMutex(); 409 hw_lock = SDL_CreateMutex();
410 if ( hw_lock == NULL ) { 410 if ( hw_lock == NULL ) {
411 SDL_SetError("Unable to create lock mutex"); 411 SDL_SetError("Unable to create lock mutex");
440 Uint8 *surfaces_mem; 440 Uint8 *surfaces_mem;
441 int surfaces_len; 441 int surfaces_len;
442 442
443 /* Free any previous colormap */ 443 /* Free any previous colormap */
444 if ( DGA_colormap ) { 444 if ( DGA_colormap ) {
445 pXFreeColormap(DGA_Display, DGA_colormap); 445 XFreeColormap(DGA_Display, DGA_colormap);
446 DGA_colormap = 0; 446 DGA_colormap = 0;
447 } 447 }
448 448
449 /* Search for a matching video mode */ 449 /* Search for a matching video mode */
450 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes); 450 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
471 return(NULL); 471 return(NULL);
472 } 472 }
473 473
474 /* Set the video mode */ 474 /* Set the video mode */
475 mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num); 475 mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num);
476 pXFree(modes); 476 XFree(modes);
477 if ( mode == NULL ) { 477 if ( mode == NULL ) {
478 SDL_SetError("Unable to switch to requested mode"); 478 SDL_SetError("Unable to switch to requested mode");
479 return(NULL); 479 return(NULL);
480 } 480 }
481 DGA_visualClass = mode->mode.visualClass; 481 DGA_visualClass = mode->mode.visualClass;
819 #if 0 819 #if 0
820 printf("Hardware accelerated rectangle fill: %dx%d at %d,%d\n", w, h, x, y); 820 printf("Hardware accelerated rectangle fill: %dx%d at %d,%d\n", w, h, x, y);
821 #endif 821 #endif
822 SDL_NAME(XDGAFillRectangle)(DGA_Display, DGA_Screen, x, y, w, h, color); 822 SDL_NAME(XDGAFillRectangle)(DGA_Display, DGA_Screen, x, y, w, h, color);
823 if ( !(this->screen->flags & SDL_DOUBLEBUF) ) { 823 if ( !(this->screen->flags & SDL_DOUBLEBUF) ) {
824 pXFlush(DGA_Display); 824 XFlush(DGA_Display);
825 } 825 }
826 DGA_AddBusySurface(dst); 826 DGA_AddBusySurface(dst);
827 UNLOCK_DISPLAY(); 827 UNLOCK_DISPLAY();
828 return(0); 828 return(0);
829 } 829 }
861 } else { 861 } else {
862 SDL_NAME(XDGACopyArea)(DGA_Display, DGA_Screen, 862 SDL_NAME(XDGACopyArea)(DGA_Display, DGA_Screen,
863 srcx, srcy, w, h, dstx, dsty); 863 srcx, srcy, w, h, dstx, dsty);
864 } 864 }
865 if ( !(this->screen->flags & SDL_DOUBLEBUF) ) { 865 if ( !(this->screen->flags & SDL_DOUBLEBUF) ) {
866 pXFlush(DGA_Display); 866 XFlush(DGA_Display);
867 } 867 }
868 DGA_AddBusySurface(src); 868 DGA_AddBusySurface(src);
869 DGA_AddBusySurface(dst); 869 DGA_AddBusySurface(dst);
870 UNLOCK_DISPLAY(); 870 UNLOCK_DISPLAY();
871 return(0); 871 return(0);
941 DGA_WaitBusySurfaces(this); 941 DGA_WaitBusySurfaces(this);
942 } 942 }
943 DGA_WaitFlip(this); 943 DGA_WaitFlip(this);
944 SDL_NAME(XDGASetViewport)(DGA_Display, DGA_Screen, 944 SDL_NAME(XDGASetViewport)(DGA_Display, DGA_Screen,
945 0, flip_yoffset[flip_page], XDGAFlipRetrace); 945 0, flip_yoffset[flip_page], XDGAFlipRetrace);
946 pXFlush(DGA_Display); 946 XFlush(DGA_Display);
947 UNLOCK_DISPLAY(); 947 UNLOCK_DISPLAY();
948 was_flipped = 1; 948 was_flipped = 1;
949 flip_page = !flip_page; 949 flip_page = !flip_page;
950 950
951 surface->pixels = flip_address[flip_page]; 951 surface->pixels = flip_address[flip_page];
974 xcmap[i].green = (colors[i].g<<8)|colors[i].g; 974 xcmap[i].green = (colors[i].g<<8)|colors[i].g;
975 xcmap[i].blue = (colors[i].b<<8)|colors[i].b; 975 xcmap[i].blue = (colors[i].b<<8)|colors[i].b;
976 xcmap[i].flags = (DoRed|DoGreen|DoBlue); 976 xcmap[i].flags = (DoRed|DoGreen|DoBlue);
977 } 977 }
978 LOCK_DISPLAY(); 978 LOCK_DISPLAY();
979 pXStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors); 979 XStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
980 pXSync(DGA_Display, False); 980 XSync(DGA_Display, False);
981 UNLOCK_DISPLAY(); 981 UNLOCK_DISPLAY();
982 SDL_stack_free(xcmap); 982 SDL_stack_free(xcmap);
983 983
984 /* That was easy. :) */ 984 /* That was easy. :) */
985 return(1); 985 return(1);
1009 xcmap[i].green = ramp[1*256+c]; 1009 xcmap[i].green = ramp[1*256+c];
1010 xcmap[i].blue = ramp[2*256+c]; 1010 xcmap[i].blue = ramp[2*256+c];
1011 xcmap[i].flags = (DoRed|DoGreen|DoBlue); 1011 xcmap[i].flags = (DoRed|DoGreen|DoBlue);
1012 } 1012 }
1013 LOCK_DISPLAY(); 1013 LOCK_DISPLAY();
1014 pXStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors); 1014 XStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
1015 pXSync(DGA_Display, False); 1015 XSync(DGA_Display, False);
1016 UNLOCK_DISPLAY(); 1016 UNLOCK_DISPLAY();
1017 return(0); 1017 return(0);
1018 } 1018 }
1019 1019
1020 void DGA_VideoQuit(_THIS) 1020 void DGA_VideoQuit(_THIS)
1022 int i, j; 1022 int i, j;
1023 1023
1024 if ( DGA_Display ) { 1024 if ( DGA_Display ) {
1025 /* Free colormap, if necessary */ 1025 /* Free colormap, if necessary */
1026 if ( DGA_colormap ) { 1026 if ( DGA_colormap ) {
1027 pXFreeColormap(DGA_Display, DGA_colormap); 1027 XFreeColormap(DGA_Display, DGA_colormap);
1028 DGA_colormap = 0; 1028 DGA_colormap = 0;
1029 } 1029 }
1030 1030
1031 /* Unmap memory and reset video mode */ 1031 /* Unmap memory and reset video mode */
1032 SDL_NAME(XDGACloseFramebuffer)(DGA_Display, DGA_Screen); 1032 SDL_NAME(XDGACloseFramebuffer)(DGA_Display, DGA_Screen);
1062 1062
1063 /* Clean up the memory bucket list */ 1063 /* Clean up the memory bucket list */
1064 DGA_FreeHWSurfaces(this); 1064 DGA_FreeHWSurfaces(this);
1065 1065
1066 /* Close up the display */ 1066 /* Close up the display */
1067 pXCloseDisplay(DGA_Display); 1067 XCloseDisplay(DGA_Display);
1068 } 1068 }
1069 } 1069 }