comparison src/video/dga/SDL_dgavideo.c @ 292:eadc0746dfaf

Added SDL_LockRect() and SDL_UnlockRect() Incorporated XFree86 extension libraries into the source
author Sam Lantinga <slouken@libsdl.org>
date Tue, 05 Mar 2002 19:55:32 +0000
parents e8157fcb3114
children f6ffac90895c
comparison
equal deleted inserted replaced
291:68a8a8237c09 292:eadc0746dfaf
29 */ 29 */
30 30
31 #include <stdlib.h> 31 #include <stdlib.h>
32 #include <string.h> 32 #include <string.h>
33 #include <X11/Xlib.h> 33 #include <X11/Xlib.h>
34 #include <X11/extensions/xf86dga.h> 34 #include <XFree86/extensions/xf86dga.h>
35 35
36 #ifdef HAVE_ALLOCA_H 36 #ifdef HAVE_ALLOCA_H
37 #include <alloca.h> 37 #include <alloca.h>
38 #endif 38 #endif
39 39
85 (strncmp(XDisplayName(display), "unix:", 5) == 0) ) { 85 (strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
86 dpy = XOpenDisplay(display); 86 dpy = XOpenDisplay(display);
87 if ( dpy ) { 87 if ( dpy ) {
88 int events, errors, major, minor; 88 int events, errors, major, minor;
89 89
90 if ( XDGAQueryExtension(dpy, &events, &errors) && 90 if ( SDL_NAME(XDGAQueryExtension)(dpy, &events, &errors) &&
91 XDGAQueryVersion(dpy, &major, &minor) ) { 91 SDL_NAME(XDGAQueryVersion)(dpy, &major, &minor) ) {
92 int screen; 92 int screen;
93 93
94 screen = DefaultScreen(dpy); 94 screen = DefaultScreen(dpy);
95 if ( (major >= 2) && 95 if ( (major >= 2) &&
96 XDGAOpenFramebuffer(dpy, screen) ) { 96 SDL_NAME(XDGAOpenFramebuffer)(dpy, screen) ) {
97 available = 1; 97 available = 1;
98 XDGACloseFramebuffer(dpy, screen); 98 SDL_NAME(XDGACloseFramebuffer)(dpy, screen);
99 } 99 }
100 } 100 }
101 XCloseDisplay(dpy); 101 XCloseDisplay(dpy);
102 } 102 }
103 } 103 }
214 214
215 /* This whole function is a hack. :) */ 215 /* This whole function is a hack. :) */
216 static Uint32 get_video_size(_THIS) 216 static Uint32 get_video_size(_THIS)
217 { 217 {
218 /* This is a non-exported function from libXxf86dga.a */ 218 /* This is a non-exported function from libXxf86dga.a */
219 extern unsigned char *XDGAGetMappedMemory(int screen); 219 extern unsigned char *SDL_NAME(XDGAGetMappedMemory)(int screen);
220 FILE *proc; 220 FILE *proc;
221 unsigned long mem; 221 unsigned long mem;
222 unsigned start, stop; 222 unsigned start, stop;
223 char line[BUFSIZ]; 223 char line[BUFSIZ];
224 Uint32 size; 224 Uint32 size;
225 225
226 mem = (unsigned long)XDGAGetMappedMemory(DGA_Screen); 226 mem = (unsigned long)SDL_NAME(XDGAGetMappedMemory)(DGA_Screen);
227 size = 0; 227 size = 0;
228 proc = fopen("/proc/self/maps", "r"); 228 proc = fopen("/proc/self/maps", "r");
229 if ( proc ) { 229 if ( proc ) {
230 while ( fgets(line, sizeof(line)-1, proc) ) { 230 while ( fgets(line, sizeof(line)-1, proc) ) {
231 sscanf(line, "%x-%x", &start, &stop); 231 sscanf(line, "%x-%x", &start, &stop);
238 } 238 }
239 return(size); 239 return(size);
240 } 240 }
241 241
242 #ifdef DGA_DEBUG 242 #ifdef DGA_DEBUG
243 static void PrintMode(XDGAMode *mode) 243 static void PrintMode(SDL_NAME(XDGAMode) *mode)
244 { 244 {
245 printf("Mode: %s (%dx%d) at %d bpp (%f refresh, %d pitch) num: %d\n", 245 printf("Mode: %s (%dx%d) at %d bpp (%f refresh, %d pitch) num: %d\n",
246 mode->name, 246 mode->name,
247 mode->viewportWidth, mode->viewportHeight, 247 mode->viewportWidth, mode->viewportHeight,
248 mode->depth == 24 ? mode->bitsPerPixel : mode->depth, 248 mode->depth == 24 ? mode->bitsPerPixel : mode->depth,
276 } 276 }
277 #endif /* DGA_DEBUG */ 277 #endif /* DGA_DEBUG */
278 278
279 static int cmpmodes(const void *va, const void *vb) 279 static int cmpmodes(const void *va, const void *vb)
280 { 280 {
281 const XDGAMode *a = (const XDGAMode *)va; 281 const SDL_NAME(XDGAMode) *a = (const SDL_NAME(XDGAMode) *)va;
282 const XDGAMode *b = (const XDGAMode *)vb; 282 const SDL_NAME(XDGAMode) *b = (const SDL_NAME(XDGAMode) *)vb;
283 283
284 /* Prefer DirectColor visuals for otherwise equal modes */ 284 /* Prefer DirectColor visuals for otherwise equal modes */
285 if ( (a->viewportWidth == b->viewportWidth) && 285 if ( (a->viewportWidth == b->viewportWidth) &&
286 (b->viewportHeight == a->viewportHeight) ) { 286 (b->viewportHeight == a->viewportHeight) ) {
287 if ( a->visualClass == DirectColor ) 287 if ( a->visualClass == DirectColor )
293 if(a->viewportWidth > b->viewportWidth) 293 if(a->viewportWidth > b->viewportWidth)
294 return -1; 294 return -1;
295 return b->viewportHeight - a->viewportHeight; 295 return b->viewportHeight - a->viewportHeight;
296 } 296 }
297 } 297 }
298 static void UpdateHWInfo(_THIS, XDGAMode *mode) 298 static void UpdateHWInfo(_THIS, SDL_NAME(XDGAMode) *mode)
299 { 299 {
300 this->info.wm_available = 0; 300 this->info.wm_available = 0;
301 this->info.hw_available = 1; 301 this->info.hw_available = 1;
302 if ( mode->flags & XDGABlitRect ) { 302 if ( mode->flags & XDGABlitRect ) {
303 this->info.blit_hw = 1; 303 this->info.blit_hw = 1;
321 { 321 {
322 const char *display; 322 const char *display;
323 int event_base, error_base; 323 int event_base, error_base;
324 int major_version, minor_version; 324 int major_version, minor_version;
325 Visual *visual; 325 Visual *visual;
326 XDGAMode *modes; 326 SDL_NAME(XDGAMode) *modes;
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
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 ( ! XDGAQueryExtension(DGA_Display, &event_base, &error_base) || 339 if ( ! SDL_NAME(XDGAQueryExtension)(DGA_Display, &event_base, &error_base) ||
340 ! 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 XCloseDisplay(DGA_Display); 342 XCloseDisplay(DGA_Display);
343 return(-1); 343 return(-1);
344 } 344 }
345 if ( major_version < 2 ) { 345 if ( major_version < 2 ) {
375 vformat->Gmask = visual->green_mask; 375 vformat->Gmask = visual->green_mask;
376 vformat->Bmask = visual->blue_mask; 376 vformat->Bmask = visual->blue_mask;
377 } 377 }
378 378
379 /* Open access to the framebuffer */ 379 /* Open access to the framebuffer */
380 if ( ! XDGAOpenFramebuffer(DGA_Display, DGA_Screen) ) { 380 if ( ! SDL_NAME(XDGAOpenFramebuffer)(DGA_Display, DGA_Screen) ) {
381 SDL_SetError("Unable to map the video memory"); 381 SDL_SetError("Unable to map the video memory");
382 XCloseDisplay(DGA_Display); 382 XCloseDisplay(DGA_Display);
383 return(-1); 383 return(-1);
384 } 384 }
385 385
386 /* Query for the list of available video modes */ 386 /* Query for the list of available video modes */
387 modes = XDGAQueryModes(DGA_Display, DGA_Screen, &num_modes); 387 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
388 qsort(modes, num_modes, sizeof *modes, cmpmodes); 388 qsort(modes, num_modes, sizeof *modes, cmpmodes);
389 for ( i=0; i<num_modes; ++i ) { 389 for ( i=0; i<num_modes; ++i ) {
390 #ifdef DGA_DEBUG 390 #ifdef DGA_DEBUG
391 PrintMode(&modes[i]); 391 PrintMode(&modes[i]);
392 #endif 392 #endif
427 static void DGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); 427 static void DGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
428 428
429 SDL_Surface *DGA_SetVideoMode(_THIS, SDL_Surface *current, 429 SDL_Surface *DGA_SetVideoMode(_THIS, SDL_Surface *current,
430 int width, int height, int bpp, Uint32 flags) 430 int width, int height, int bpp, Uint32 flags)
431 { 431 {
432 XDGAMode *modes; 432 SDL_NAME(XDGAMode) *modes;
433 int i, num_modes; 433 int i, num_modes;
434 XDGADevice *mode; 434 SDL_NAME(XDGADevice) *mode;
435 int screen_len; 435 int screen_len;
436 Uint8 *surfaces_mem; 436 Uint8 *surfaces_mem;
437 int surfaces_len; 437 int surfaces_len;
438 438
439 /* Free any previous colormap */ 439 /* Free any previous colormap */
441 XFreeColormap(DGA_Display, DGA_colormap); 441 XFreeColormap(DGA_Display, DGA_colormap);
442 DGA_colormap = 0; 442 DGA_colormap = 0;
443 } 443 }
444 444
445 /* Search for a matching video mode */ 445 /* Search for a matching video mode */
446 modes = XDGAQueryModes(DGA_Display, DGA_Screen, &num_modes); 446 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
447 qsort(modes, num_modes, sizeof *modes, cmpmodes); 447 qsort(modes, num_modes, sizeof *modes, cmpmodes);
448 for ( i=0; i<num_modes; ++i ) { 448 for ( i=0; i<num_modes; ++i ) {
449 int depth; 449 int depth;
450 450
451 451
466 SDL_SetError("No matching video mode found"); 466 SDL_SetError("No matching video mode found");
467 return(NULL); 467 return(NULL);
468 } 468 }
469 469
470 /* Set the video mode */ 470 /* Set the video mode */
471 mode = XDGASetMode(DGA_Display, DGA_Screen, modes[i].num); 471 mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num);
472 XFree(modes); 472 XFree(modes);
473 if ( mode == NULL ) { 473 if ( mode == NULL ) {
474 SDL_SetError("Unable to switch to requested mode"); 474 SDL_SetError("Unable to switch to requested mode");
475 return(NULL); 475 return(NULL);
476 } 476 }
493 screen_len = current->h*current->pitch; 493 screen_len = current->h*current->pitch;
494 494
495 /* Create a colormap if necessary */ 495 /* Create a colormap if necessary */
496 if ( (DGA_visualClass == PseudoColor) || 496 if ( (DGA_visualClass == PseudoColor) ||
497 (DGA_visualClass == DirectColor) ) { 497 (DGA_visualClass == DirectColor) ) {
498 DGA_colormap = XDGACreateColormap(DGA_Display, DGA_Screen, 498 DGA_colormap = SDL_NAME(XDGACreateColormap)(DGA_Display, DGA_Screen,
499 mode, AllocAll); 499 mode, AllocAll);
500 if ( DGA_visualClass == PseudoColor ) { 500 if ( DGA_visualClass == PseudoColor ) {
501 current->flags |= SDL_HWPALETTE; 501 current->flags |= SDL_HWPALETTE;
502 } else { 502 } else {
503 /* Initialize the colormap to the identity mapping */ 503 /* Initialize the colormap to the identity mapping */
505 this->screen = current; 505 this->screen = current;
506 DGA_SetGammaRamp(this, this->gamma); 506 DGA_SetGammaRamp(this, this->gamma);
507 this->screen = NULL; 507 this->screen = NULL;
508 } 508 }
509 } else { 509 } else {
510 DGA_colormap = XDGACreateColormap(DGA_Display, DGA_Screen, 510 DGA_colormap = SDL_NAME(XDGACreateColormap)(DGA_Display, DGA_Screen,
511 mode, AllocNone); 511 mode, AllocNone);
512 } 512 }
513 XDGAInstallColormap(DGA_Display, DGA_Screen, DGA_colormap); 513 SDL_NAME(XDGAInstallColormap)(DGA_Display, DGA_Screen, DGA_colormap);
514 514
515 /* Update the hardware capabilities */ 515 /* Update the hardware capabilities */
516 UpdateHWInfo(this, &mode->mode); 516 UpdateHWInfo(this, &mode->mode);
517 517
518 /* Set up the information for hardware surfaces */ 518 /* Set up the information for hardware surfaces */
519 surfaces_mem = (Uint8 *)current->pixels + screen_len; 519 surfaces_mem = (Uint8 *)current->pixels + screen_len;
520 surfaces_len = (mode->mode.imageHeight*current->pitch - screen_len); 520 surfaces_len = (mode->mode.imageHeight*current->pitch - screen_len);
521 521
522 /* Update for double-buffering, if we can */ 522 /* Update for double-buffering, if we can */
523 XDGASetViewport(DGA_Display, DGA_Screen, 0, 0, XDGAFlipRetrace); 523 SDL_NAME(XDGASetViewport)(DGA_Display, DGA_Screen, 0, 0, XDGAFlipRetrace);
524 if ( flags & SDL_DOUBLEBUF ) { 524 if ( flags & SDL_DOUBLEBUF ) {
525 if ( mode->mode.imageHeight >= (current->h*2) ) { 525 if ( mode->mode.imageHeight >= (current->h*2) ) {
526 current->flags |= SDL_DOUBLEBUF; 526 current->flags |= SDL_DOUBLEBUF;
527 flip_page = 0; 527 flip_page = 0;
528 flip_yoffset[0] = 0; 528 flip_yoffset[0] = 0;
554 /* Enable mouse and keyboard support */ 554 /* Enable mouse and keyboard support */
555 { long input_mask; 555 { long input_mask;
556 input_mask = (KeyPressMask | KeyReleaseMask); 556 input_mask = (KeyPressMask | KeyReleaseMask);
557 input_mask |= (ButtonPressMask | ButtonReleaseMask); 557 input_mask |= (ButtonPressMask | ButtonReleaseMask);
558 input_mask |= PointerMotionMask; 558 input_mask |= PointerMotionMask;
559 XDGASelectInput(DGA_Display, DGA_Screen, input_mask); 559 SDL_NAME(XDGASelectInput)(DGA_Display, DGA_Screen, input_mask);
560 } 560 }
561 561
562 /* We're done */ 562 /* We're done */
563 return(current); 563 return(current);
564 } 564 }
650 static __inline__ void DGA_WaitBusySurfaces(_THIS) 650 static __inline__ void DGA_WaitBusySurfaces(_THIS)
651 { 651 {
652 vidmem_bucket *bucket; 652 vidmem_bucket *bucket;
653 653
654 /* Wait for graphic operations to complete */ 654 /* Wait for graphic operations to complete */
655 XDGASync(DGA_Display, DGA_Screen); 655 SDL_NAME(XDGASync)(DGA_Display, DGA_Screen);
656 656
657 /* Clear all surface dirty bits */ 657 /* Clear all surface dirty bits */
658 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { 658 for ( bucket=&surfaces; bucket; bucket=bucket->next ) {
659 bucket->dirty = 0; 659 bucket->dirty = 0;
660 } 660 }
805 unsigned int w, h; 805 unsigned int w, h;
806 806
807 /* Don't fill the visible part of the screen, wait until flipped */ 807 /* Don't fill the visible part of the screen, wait until flipped */
808 LOCK_DISPLAY(); 808 LOCK_DISPLAY();
809 if ( was_flipped && (dst == this->screen) ) { 809 if ( was_flipped && (dst == this->screen) ) {
810 while ( XDGAGetViewportStatus(DGA_Display, DGA_Screen) ) 810 while ( SDL_NAME(XDGAGetViewportStatus)(DGA_Display, DGA_Screen) )
811 /* Keep waiting for the hardware ... */ ; 811 /* Keep waiting for the hardware ... */ ;
812 was_flipped = 0; 812 was_flipped = 0;
813 } 813 }
814 DGA_dst_to_xy(this, dst, &x, &y); 814 DGA_dst_to_xy(this, dst, &x, &y);
815 x += rect->x; 815 x += rect->x;
817 w = rect->w; 817 w = rect->w;
818 h = rect->h; 818 h = rect->h;
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 XDGAFillRectangle(DGA_Display, DGA_Screen, x, y, w, h, color); 822 SDL_NAME(XDGAFillRectangle)(DGA_Display, DGA_Screen, x, y, w, h, color);
823 XFlush(DGA_Display); 823 XFlush(DGA_Display);
824 DGA_AddBusySurface(dst); 824 DGA_AddBusySurface(dst);
825 UNLOCK_DISPLAY(); 825 UNLOCK_DISPLAY();
826 return(0); 826 return(0);
827 } 827 }
836 836
837 this = current_video; 837 this = current_video;
838 /* Don't blit to the visible part of the screen, wait until flipped */ 838 /* Don't blit to the visible part of the screen, wait until flipped */
839 LOCK_DISPLAY(); 839 LOCK_DISPLAY();
840 if ( was_flipped && (dst == this->screen) ) { 840 if ( was_flipped && (dst == this->screen) ) {
841 while ( XDGAGetViewportStatus(DGA_Display, DGA_Screen) ) 841 while ( SDL_NAME(XDGAGetViewportStatus)(DGA_Display, DGA_Screen) )
842 /* Keep waiting for the hardware ... */ ; 842 /* Keep waiting for the hardware ... */ ;
843 was_flipped = 0; 843 was_flipped = 0;
844 } 844 }
845 DGA_dst_to_xy(this, src, &srcx, &srcy); 845 DGA_dst_to_xy(this, src, &srcx, &srcy);
846 srcx += srcrect->x; 846 srcx += srcrect->x;
852 h = srcrect->h; 852 h = srcrect->h;
853 #if 0 853 #if 0
854 printf("Blitting %dx%d from %d,%d to %d,%d\n", w, h, srcx, srcy, dstx, dsty); 854 printf("Blitting %dx%d from %d,%d to %d,%d\n", w, h, srcx, srcy, dstx, dsty);
855 #endif 855 #endif
856 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { 856 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
857 XDGACopyTransparentArea(DGA_Display, DGA_Screen, 857 SDL_NAME(XDGACopyTransparentArea)(DGA_Display, DGA_Screen,
858 srcx, srcy, w, h, dstx, dsty, src->format->colorkey); 858 srcx, srcy, w, h, dstx, dsty, src->format->colorkey);
859 } else { 859 } else {
860 XDGACopyArea(DGA_Display, DGA_Screen, 860 SDL_NAME(XDGACopyArea)(DGA_Display, DGA_Screen,
861 srcx, srcy, w, h, dstx, dsty); 861 srcx, srcy, w, h, dstx, dsty);
862 } 862 }
863 XFlush(DGA_Display); 863 XFlush(DGA_Display);
864 DGA_AddBusySurface(src); 864 DGA_AddBusySurface(src);
865 DGA_AddBusySurface(dst); 865 DGA_AddBusySurface(dst);
895 } 895 }
896 896
897 static __inline__ void DGA_WaitFlip(_THIS) 897 static __inline__ void DGA_WaitFlip(_THIS)
898 { 898 {
899 if ( was_flipped ) { 899 if ( was_flipped ) {
900 while ( XDGAGetViewportStatus(DGA_Display, DGA_Screen) ) 900 while ( SDL_NAME(XDGAGetViewportStatus)(DGA_Display, DGA_Screen) )
901 /* Keep waiting for the hardware ... */ ; 901 /* Keep waiting for the hardware ... */ ;
902 was_flipped = 0; 902 was_flipped = 0;
903 } 903 }
904 } 904 }
905 905
935 LOCK_DISPLAY(); 935 LOCK_DISPLAY();
936 if ( DGA_IsSurfaceBusy(this->screen) ) { 936 if ( DGA_IsSurfaceBusy(this->screen) ) {
937 DGA_WaitBusySurfaces(this); 937 DGA_WaitBusySurfaces(this);
938 } 938 }
939 DGA_WaitFlip(this); 939 DGA_WaitFlip(this);
940 XDGASetViewport(DGA_Display, DGA_Screen, 940 SDL_NAME(XDGASetViewport)(DGA_Display, DGA_Screen,
941 0, flip_yoffset[flip_page], XDGAFlipRetrace); 941 0, flip_yoffset[flip_page], XDGAFlipRetrace);
942 XFlush(DGA_Display); 942 XFlush(DGA_Display);
943 UNLOCK_DISPLAY(); 943 UNLOCK_DISPLAY();
944 was_flipped = 1; 944 was_flipped = 1;
945 flip_page = !flip_page; 945 flip_page = !flip_page;
1022 XFreeColormap(DGA_Display, DGA_colormap); 1022 XFreeColormap(DGA_Display, DGA_colormap);
1023 DGA_colormap = 0; 1023 DGA_colormap = 0;
1024 } 1024 }
1025 1025
1026 /* Unmap memory and reset video mode */ 1026 /* Unmap memory and reset video mode */
1027 XDGACloseFramebuffer(DGA_Display, DGA_Screen); 1027 SDL_NAME(XDGACloseFramebuffer)(DGA_Display, DGA_Screen);
1028 if ( this->screen ) { 1028 if ( this->screen ) {
1029 /* Tell SDL not to free the pixels */ 1029 /* Tell SDL not to free the pixels */
1030 this->screen->pixels = NULL; 1030 this->screen->pixels = NULL;
1031 } 1031 }
1032 XDGASetMode(DGA_Display, DGA_Screen, 0); 1032 SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, 0);
1033 1033
1034 /* Clear the lock mutex */ 1034 /* Clear the lock mutex */
1035 if ( hw_lock != NULL ) { 1035 if ( hw_lock != NULL ) {
1036 SDL_DestroyMutex(hw_lock); 1036 SDL_DestroyMutex(hw_lock);
1037 hw_lock = NULL; 1037 hw_lock = NULL;