📄 i_video_xshm.c
字号:
// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: i_video_xshm.c,v 1.27 2001/04/27 13:32:14 bpereira Exp $//// Copyright (C) 1993-1996 by id Software, Inc.// Portions Copyright (C) 1998-2000 by DooM Legacy Team.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program 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 General Public License for more details.////// $Log: i_video_xshm.c,v $// Revision 1.27 2001/04/27 13:32:14 bpereira// no message//// Revision 1.26 2001/04/14 14:17:52 metzgermeister// clean up//// Revision 1.25 2001/03/30 17:12:52 bpereira// no message//// Revision 1.24 2001/03/12 21:03:10 metzgermeister// * new symbols for rendererlib added in SDL// * console printout fixed for Linux&SDL// * Crash fixed in Linux SW renderer initialization//// Revision 1.23 2001/02/24 13:35:22 bpereira// no message//// Revision 1.22 2001/02/19 23:55:26 hurdler// Update to match win32 source code//// Revision 1.21 2001/02/13 20:37:27 metzgermeister// *** empty log message ***//// Revision 1.20 2001/01/25 22:15:45 bpereira// added heretic support//// Revision 1.19 2000/11/04 16:23:45 bpereira// no message//// Revision 1.18 2000/11/02 19:49:40 bpereira// no message//// Revision 1.17 2000/10/08 13:30:02 bpereira// no message//// Revision 1.16 2000/09/10 10:51:02 metzgermeister// added vid_wait//// Revision 1.15 2000/08/21 21:14:31 metzgermeister// Voodoo3/Banshee fix//// Revision 1.14 2000/08/11 19:11:07 metzgermeister// *** empty log message ***//// Revision 1.12 2000/05/13 19:53:54 metzgermeister// voodoo fullscreen & remote display//// Revision 1.11 2000/05/07 08:29:03 metzgermeister// added windowed voodoo mode//// Revision 1.10 2000/04/22 20:27:35 metzgermeister// support for immediate fullscreen switching//// Revision 1.9 2000/04/18 23:47:00 metzgermeister// bugfixes//// Revision 1.8 2000/04/16 20:10:51 metzgermeister// screensaver handling//// Revision 1.7 2000/04/12 19:32:50 metzgermeister// new Voodoo and fullscreen support//// Revision 1.6 2000/04/07 23:10:15 metzgermeister// fullscreen support under X in Linux//// Revision 1.5 2000/03/23 22:40:49 metzgermeister// added support for automatic 3dfx fullscreen//// Revision 1.4 2000/03/07 03:30:49 hurdler// fix linux compilation//// Revision 1.3 2000/03/06 15:19:58 hurdler// Add Bell Kin's changes//// Revision 1.2 2000/02/27 00:42:12 hurdler// fix CR+LF problem//// Revision 1.1.1.1 2000/02/22 20:32:33 hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION:// DOOM graphics stuff for X11, UNIX.////-----------------------------------------------------------------------------#include <stdlib.h>#include <unistd.h>#include <sys/ipc.h>#include <sys/shm.h>#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/keysym.h>#include <X11/extensions/XShm.h>#include <X11/extensions/xf86vmode.h>// Had to dig up XShm.c for this one.// It is in the libXext, but not in the X headers.//#if defined(LINUX)int XShmGetEventBase( Display* dpy );//#endif#include <stdarg.h>#include <sys/time.h>#include <sys/types.h>#include <dlfcn.h> // added 19990831 by Kin#include <sys/socket.h>#include <netinet/in.h>#include <errno.h>#include <signal.h>#if defined(SCOOS5) || defined(SCOUW2) || defined(SCOUW7)#include "strcmp.h"#endif// it must be here 19990117 by Kin#include "doomdef.h"#define DONTDEFINEBOOL#include "doomstat.h"#include "i_system.h"#include "v_video.h"#include "m_argv.h"#include "m_menu.h"#include "d_main.h"#include "s_sound.h"// added for 1.27 19990220 by Kin#include "g_input.h"#include "st_stuff.h"#include "g_game.h"#include "i_video.h"#include "hardware/hw_main.h"#include "hardware/hw_drv.h"#include "hardware/hw_glob.h"#include "console.h"#include "command.h"void VID_PrepareModeList(void);// maximum number of windowed modes for X11 (see windowedModes[][])#define MAXWINMODES (6) #define NUM_VOODOOMODES (3)// resolution threshold for hires mode#define HIRES_HORIZ (640)#define HIRES_VERT (400) static boolean haveVoodoo = false;extern consvar_t cv_fullscreen; // for fullscreen support under X and GLXextern short color8to16[];static boolean showkey=false; // force to no 19990118 by Kinstatic boolean verbose=false; // enable/disable some printoutsstatic boolean vidmode_ext; // Are videmode extensions available?static boolean vidmode_active;static int num_fullvidmodes;static int num_vidmodes = 0;static int lowest_vidmode;static XF86VidModeModeInfo **vidmodes;static char vidModeName[33][32]; // allow 33 different modesstatic int vidmap[33];// added for 1.27 19990220 by Kinrendermode_t rendermode=render_soft;boolean highcolor = false;// synchronize page flipping with screen refresh// unused and for compatibilityy reason consvar_t cv_vidwait = {"vid_wait","1",CV_SAVE,CV_OnOff};byte graphics_started = 0;// To disable fullscreen at startup; is set in VID_PrepareModeListboolean allow_fullscreen = false;static Display* X_display=NULL;static Window X_mainWindow=0;static Colormap X_cmap;static Visual* X_visual;static GC X_gc;static XEvent X_event;static int X_screen;static XVisualInfo X_visualinfo;static XSizeHints X_size;static XWMHints X_wm;static XClassHint X_class;static Atom X_wm_delwin;static int X_width;static int X_height;static XImage* image = NULL;static Window dummy;static int dont_care;static boolean localDisplay = true;// MIT SHared Memory extension.boolean doShm;XShmSegmentInfo X_shminfo;int X_shmeventtype;// Mouse handling.boolean Mousegrabbed = false;event_t event;// X visual modestatic int x_depth=1;static int x_bpp=1;static int x_pseudo=1;static unsigned short* x_colormap2 = 0;static unsigned char* x_colormap3 = 0;static unsigned long* x_colormap4 = 0;static unsigned long x_red_mask = 0;static unsigned long x_green_mask = 0;static unsigned long x_blue_mask = 0;static unsigned char x_red_offset = 0;static unsigned char x_green_offset = 0;static unsigned char x_blue_offset = 0;// X11 video modes from which to choose from.static int windowedModes[MAXWINMODES][2] = { {1024, 768}, {800, 600}, {640, 480}, {512, 384}, {400, 300}, {320, 200}};// These are modes for 3dfx voodoo graphics (loopthrough) cardsstatic int voodooModes[NUM_VOODOOMODES][2] = { {800, 600}, {640, 480}, {512, 384}};static void determineVidModes(void){ int i, firstEntry; boolean finished; int lowest_vidmode; if(vidmode_ext) { // get fullscreen modes XF86VidModeGetAllModeLines(X_display, X_screen, &num_fullvidmodes, &vidmodes); num_vidmodes = num_fullvidmodes; // initialize mapping for(i=0; i<num_vidmodes; i++) vidmap[i] = i; // bubble sort modes do { int temp; finished = true; for(i=0; i<num_vidmodes-1; i++) { if(vidmodes[vidmap[i ]]->hdisplay * vidmodes[vidmap[i ]]->vdisplay < vidmodes[vidmap[i+1]]->hdisplay * vidmodes[vidmap[i+1]]->vdisplay) { temp = vidmap[i]; vidmap[i] = vidmap[i+1]; vidmap[i+1] = temp; finished = false; } } } while(!finished); // exclude modes which are too large (to prevent X-Server problems) firstEntry = num_vidmodes; for(i=0; i<num_vidmodes; i++) { if(vidmodes[vidmap[i]]->hdisplay <= windowedModes[0][0] && vidmodes[vidmap[i]]->vdisplay <= windowedModes[0][1]) { firstEntry = i; break; } } // copy modes for(i=0; i<num_vidmodes-firstEntry; i++) { vidmap[i] = vidmap[i+firstEntry]; } num_vidmodes -= firstEntry; lowest_vidmode = num_vidmodes - 1; } else { num_vidmodes = 0; } return;}static void checkVidModeExtension(void) { int MajorVersion, MinorVersion; MajorVersion = MinorVersion = 0; // disable extensions for non-local displays if(!localDisplay){ vidmode_ext = false; return; } if (!XF86VidModeQueryVersion(X_display, &MajorVersion, &MinorVersion)) { vidmode_ext = false; } else { CONS_Printf("Using XFree86-VidModeExtension Version %d.%d\n", MajorVersion, MinorVersion); vidmode_ext = true; } return;}static void findVisual(void) { X_screen = DefaultScreen(X_display); if (XMatchVisualInfo(X_display, X_screen, 8, PseudoColor, &X_visualinfo)) { x_depth = 1; x_pseudo = 1; } else if (XMatchVisualInfo(X_display, X_screen, 16, TrueColor, &X_visualinfo)) { x_depth = 2; x_pseudo = 0; } else if (XMatchVisualInfo(X_display, X_screen, 24, TrueColor, &X_visualinfo)) { x_depth = 3; x_pseudo = 0; } else I_Error("no supported visual found"); X_visual = X_visualinfo.visual; return;}static void determineColorMask(void) { x_red_mask = X_visual->red_mask; x_green_mask = X_visual->green_mask; x_blue_mask = X_visual->blue_mask; if (x_depth==3) { switch (x_red_mask) {#ifdef BIGEND case 0x000000ff: x_red_offset = 3; break; case 0x0000ff00: x_red_offset = 2; break; case 0x00ff0000: x_red_offset = 1; break; case 0xff000000: x_red_offset = 0; break;#else case 0x000000ff: x_red_offset = 0; break; case 0x0000ff00: x_red_offset = 1; break; case 0x00ff0000: x_red_offset = 2; break; case 0xff000000: x_red_offset = 3; break;#endif } switch (x_green_mask) {#ifdef BIGEND case 0x000000ff: x_green_offset = 3; break; case 0x0000ff00: x_green_offset = 2; break; case 0x00ff0000: x_green_offset = 1; break; case 0xff000000: x_green_offset = 0; break;#else case 0x000000ff: x_green_offset = 0; break; case 0x0000ff00: x_green_offset = 1; break; case 0x00ff0000: x_green_offset = 2; break; case 0xff000000: x_green_offset = 3; break;#endif } switch (x_blue_mask) {#ifdef BIGEND case 0x000000ff: x_blue_offset = 3; break; case 0x0000ff00: x_blue_offset = 2; break; case 0x00ff0000: x_blue_offset = 1; break; case 0xff000000: x_blue_offset = 0; break;#else case 0x000000ff: x_blue_offset = 0; break; case 0x0000ff00: x_blue_offset = 1; break; case 0x00ff0000: x_blue_offset = 2; break; case 0xff000000: x_blue_offset = 3; break;#endif } } if (x_depth==2) { // for 16bpp, x_*_offset specifies the number of bits to shift unsigned long mask; mask = x_red_mask; x_red_offset = 0; while (!(mask&1)) { x_red_offset++; mask >>= 1; } x_red_mask = 8; while (mask&1) { x_red_mask--; mask >>= 1; } mask = x_green_mask; x_green_offset = 0; while (!(mask&1)) { x_green_offset++; mask >>= 1; } x_green_mask = 8; while (mask&1) { x_green_mask--; mask >>= 1; } mask = x_blue_mask; x_blue_offset = 0; while (!(mask&1)) { x_blue_offset++; mask >>= 1; } x_blue_mask = 8; while (mask&1) { x_blue_mask--; mask >>= 1; } } return;}static void determineBPP(void) { int count; XPixmapFormatValues* X_pixmapformats; X_pixmapformats = XListPixmapFormats(X_display,&count); if (X_pixmapformats) { int i; x_bpp=0; for (i=0;i<count;i++) { if (X_pixmapformats[i].depth == x_depth*8) { x_bpp = X_pixmapformats[i].bits_per_pixel/8; break; } } if (x_bpp==0) I_Error("Could not determine bits_per_pixel"); XFree(X_pixmapformats); } else I_Error("Could not get list of pixmap formats"); return;}static char *initDisplay(void){ int pnum; char *displayname, *d, displaycopy[256]; // check for command-line display name if((pnum = M_CheckParm("-display")) && (pnum < myargc-1)) displayname = myargv[pnum+1]; else displayname = NULL; // open the display X_display = XOpenDisplay(displayname); if (!X_display) { if (displayname) I_Error("Could not open display [%s]", displayname); else I_Error("Could not open display (DISPLAY=[%s])", getenv("DISPLAY")); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -