static int dga_available (void) { #ifdef USE_DGA_EXTENSION int MajorVersion, MinorVersion; int EventBase, ErrorBase; if (! XF86DGAQueryVersion (display, &MajorVersion, &MinorVersion)) { write_log ("Unable to query video extension version\n"); return 0; } if (! XF86DGAQueryExtension (display, &EventBase, &ErrorBase)) { write_log ("Unable to query video extension information\n"); return 0; } /* Fail if the extension version in the server is too old */ if (MajorVersion < DGA_MINMAJOR || (MajorVersion == DGA_MINMAJOR && MinorVersion < DGA_MINMINOR)) { write_log ( "Xserver is running an old XFree86-DGA version" " (%d.%d)\n", MajorVersion, MinorVersion); write_log ("Minimum required version is %d.%d\n", DGA_MINMAJOR, DGA_MINMINOR); return 0; } if (geteuid () != 0) { write_log ("UAE is not running as root, DGA extension disabled.\n"); return 0; } if (! XF86DGAGetVideo (display, screen, &fb_addr, &fb_width, &fb_bank, &fb_mem) || fb_bank < fb_mem) { write_log ("Problems with DGA - disabling DGA extension.\n"); return 0; } write_log ("DGA extension: addr:%X, width %d, bank size %d mem size %d\n", fb_addr, fb_width, fb_bank, fb_mem); return 1; #else return 0; #endif }
void I_InitGraphics(void) { const char* displayname = NULL; int n; int pnum; int x=0; int y=0; { static int firsttime=1; if (!firsttime) { return; } firsttime = 0; } { // Check for screen enlargement char str[3] = { '-', 0, 0 }; for (n=1; n<4; n++) { str[1] = n + '0'; if (M_CheckParm(str)) multiply = n; } } X_width = SCREENWIDTH * multiply; X_height = SCREENHEIGHT * multiply; // check for command-line geometry if ( (pnum=M_CheckParm("-geom")) ? 1 : (pnum=M_CheckParm("-geometry"))) if (pnum+1 < myargc) { // check parm given // warning: char format, different type arg char xsign=' '; char ysign=' '; const char* pg = myargv[pnum+1]; pg += strcspn(pg, "+-"); // warning: char format, different type arg 3,5 n = sscanf(pg, "%c%d%c%d", &xsign, &x, &ysign, &y); if (n==2) x = y = 0; else if (n==4) { if (xsign == '-') x = -x; if (ysign == '-') y = -y; } else fprintf(stderr, "I_InitGraphics: bad -geom offsets \"%s\"\n", pg); } // check for command-line display name if ( (pnum=M_CheckParm("-disp")) ) // suggest parentheses around assignment displayname = myargv[pnum+1]; // CPhipps - support more standard -display param if ( (pnum=M_CheckParm("-display")) ) // ditto displayname = myargv[pnum+1]; // CPhipps - and -displayname as for xterm if ( (pnum=M_CheckParm("-displayname")) ) // ditto displayname = myargv[pnum+1]; // open the display if (!(X_display = XOpenDisplay(displayname))) { if (displayname) I_Error("Could not open display [%s]", displayname); else I_Error("Could not open display (DISPLAY=[%s])", getenv("DISPLAY")); } // use the default visual X_screen = DefaultScreen(X_display); X_deletewin = XInternAtom(X_display, "WM_DELETE_WINDOW", False); // check for the MITSHM extension // even if it's available, make sure it's a local connection lprintf(LO_INFO,"I_InitGraphics:"); #ifdef HAVE_LIBXXF86DGA if ((doDga = (M_CheckParm("-dga") && XF86DGAQueryExtension(X_display, &n, &n)) )) { lprintf(LO_INFO,"I_InitGraphics: found DGA extension\n"); if (M_CheckParm("-noaccel") || (X_opt & 1)) doDga = false; else lprintf(LO_INFO, "(using DGA)"); } else #endif #ifdef HAVE_LIBXEXT if ((doShm = XShmQueryExtension(X_display))) { if (!displayname) displayname = getenv("DISPLAY"); if (displayname) { // CPhipps - don't modify the original string, please. // - oops my code here was totally wrong // I have no idea exactly what should go here. if (M_CheckParm("-noaccel") || (X_opt & 1)) doShm = false; else lprintf(LO_INFO, "(using MITShm)"); } } else #endif if (devparm) fprintf(stderr, "No MITShm extension in server"); if (devparm) fputc('\n', stderr); if ((X_visual = I_FindMode(X_screen)) == NULL) I_Error("Unsupported visual"); // create the colormap X_cmap = XCreateColormap(X_display, RootWindow(X_display, X_screen), X_visual, true_color ? AllocNone : AllocAll); #ifdef HAVE_LIBXXF86DGA /* setup for DGA */ if(doDga) { char *fb; X_mainWindow=RootWindow(X_display, X_screen); XF86DGAGetViewPortSize(X_display, X_screen, &DGA_width, &DGA_height); XF86DGAGetVideo(X_display, X_screen, &fb, &DGA_real_width, &DGA_pagelen, &DGA_memlen); fprintf(stderr, "I_InitGraphics: DGA reports %dx%d scan=%d page=%d mem=%d\n", DGA_width,DGA_height,DGA_real_width,DGA_pagelen,DGA_memlen); out_buffer=(void*)fb; XF86DGADirectVideo(X_display, X_screen, XF86DGADirectGraphics); XF86DGASetVidPage(X_display, X_screen, 0); XF86DGAForkApp(X_screen); XSelectInput(X_display, X_mainWindow, KeyPressMask | KeyReleaseMask); fprintf(stderr,"DGA framebuffer @%p\n",fb); memset(fb,0,102400); } #endif #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif { // setup attributes for main window unsigned long attribmask; XSetWindowAttributes attribs; attribmask = CWEventMask | CWColormap | CWBorderPixel; attribs.event_mask = KeyPressMask | KeyReleaseMask #ifdef MONITOR_VISIBILITY | VisibilityChangeMask #endif | ExposureMask; attribs.colormap = X_cmap; attribs.border_pixel = 0; // create the main window X_mainWindow = XCreateWindow( X_display, RootWindow(X_display, X_screen), x, y, X_width, X_height, 0, // borderwidth X_bpp, // depth InputOutput, X_visual, attribmask, &attribs ); } #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif { XClassHint c_hint; XTextProperty x_name; XSizeHints s_hint; XWMHints wm_hint; char lcase_buf[10], ucase_buf[10]; char* str; strcpy(str = lcase_buf, lcase_lxdoom); XStringListToTextProperty(&str, 1, &x_name); s_hint.flags = PSize | PMinSize | PMaxSize; s_hint.min_width = s_hint.max_width = s_hint.base_width = X_width; s_hint.min_height = s_hint.max_height = s_hint.base_height = X_height; wm_hint.input = True; wm_hint.window_group = X_mainWindow; wm_hint.flags = InputHint | WindowGroupHint; strcpy(c_hint.res_name = lcase_buf, lcase_lxdoom); strcpy(c_hint.res_class = ucase_buf, ucase_lxdoom); XSetWMProtocols(X_display, X_mainWindow, &X_deletewin, 1); XSetWMProperties(X_display, X_mainWindow, &x_name, &x_name, (char**)myargv, myargc, &s_hint, &wm_hint, &c_hint); XFlush(X_display); } #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif // Hide pointer while over this window XDefineCursor(X_display, X_mainWindow, I_XCreateNullCursor( X_display, X_mainWindow ) ); { // create the GC XGCValues xgcvalues; int valuemask; valuemask = GCGraphicsExposures; xgcvalues.graphics_exposures = False; X_gc = XCreateGC(X_display, X_mainWindow, valuemask, &xgcvalues); } #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif { // name the window XStoreName(X_display, X_mainWindow, "lxdoom"); // map the window XMapWindow(X_display, X_mainWindow); } // wait until it is OK to draw #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif do { XNextEvent(X_display, &X_event); } while (!(X_event.type == Expose && !X_event.xexpose.count)); #ifdef HAVE_LIBXXF86DGA if(doDga) {} else #endif #ifdef HAVE_LIBXEXT if (doShm) { X_shmeventtype = XShmGetEventBase(X_display) + ShmCompletion; // create the image image = XShmCreateImage( X_display, X_visual, X_bpp, ZPixmap, 0, &X_shminfo, X_width, X_height ); I_XShmGrabSharedMemory(image->bytes_per_line * image->height); if (!(out_buffer = (pval*)image->data)) { perror(""); I_Error("shmat() failed in I_InitGraphics()"); } // get the X server to attach to it if (!XShmAttach(X_display, &X_shminfo)) I_Error("XShmAttach() failed in InitGraphics()"); if (!expand_buffer) { // Render directly into MitSHM memory Z_Free(screens[0]); screens[0] = (unsigned char *) (image->data); } } else #endif { if (!expand_buffer) { // Very efficient, render directly into image out_buffer = (pval*)screens[0]; } else { // Will have to enlarge from rendering buffer // into image buffer out_buffer = (pval*)malloc (X_width * X_height * BYTESPP); } { /* hack to enable 15 bpp usage */ int bpp=X_bpp; if(bpp==15)bpp=16; image=XCreateImage( X_display, X_visual, X_bpp, ZPixmap, 0, (char*)out_buffer, X_width, X_height, bpp, 0); #ifdef NOT_NOW image=XCreateImage( X_display, X_visual, X_bpp, ZPixmap, 0, (char*)out_buffer, X_width, X_height, X_bpp, 0); #endif } if (!image) I_Error("XCreateImage: failed to create image %dx%d %d bpp", X_width, X_height, X_bpp); } atexit(I_ShutdownGraphics); I_XInitInputs(); }