📄 vid_sunx.c
字号:
/*
Copyright (C) 1996-1997 Id Software, Inc.
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// vid_x.c -- general x video driver
#define _BSD
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/XShm.h>
#include "quakedef.h"
#include "d_local.h"
cvar_t *m_filter;
qboolean mouse_avail;
int mouse_buttons=3;
int mouse_oldbuttonstate;
int mouse_buttonstate;
float mouse_x, mouse_y;
float old_mouse_x, old_mouse_y;
int p_mouse_x;
int p_mouse_y;
qboolean mouse_grabbed = false; // we grab it when console is up
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar;
byte *VGA_pagebase;
// The following X property format is defined in Motif 1.1's
// Xm/MwmUtils.h, but QUAKE should not depend on that header
// file. Note: Motif 1.2 expanded this structure with
// uninteresting fields (to QUAKE) so just stick with the
// smaller Motif 1.1 structure.
#define MWM_HINTS_DECORATIONS 2
typedef struct
{
long flags;
long functions;
long decorations;
long input_mode;
} MotifWmHints;
#define MAX_COLUMN_SIZE 11
#define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
typedef struct
{
int modenum;
int iscur;
char desc[256];
} modedesc_t;
extern void M_Menu_Options_f (void);
extern void M_Print (int cx, int cy, char *str);
extern void M_PrintWhite (int cx, int cy, char *str);
extern void M_DrawCharacter (int cx, int line, int num);
extern void M_DrawTransPic (int x, int y, qpic_t *pic);
extern void M_DrawPic (int x, int y, qpic_t *pic);
extern int sb_updates;
extern int x_root, y_root; // root window relative mouse coords
typedef struct
{
int input;
int output;
} keymap_t;
viddef_t vid; // global video state
unsigned short d_8to16table[256];
int num_shades=32;
int d_con_indirect = 0;
int vid_buffersize;
#define STD_EVENT_MASK \
( KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | \
PointerMotionMask | EnterWindowMask | LeaveWindowMask | VisibilityChangeMask | \
ExposureMask | StructureNotifyMask )
qboolean x_fullscreen = true;
Display *x_disp = NULL;
int x_screen, x_screen_width, x_screen_height;
int x_center_width, x_center_height;
int x_std_event_mask = STD_EVENT_MASK;
Window x_win, x_root_win;
qboolean mouse_in_window = false;
int global_dx, global_dy;
static qboolean doShm;
static Colormap x_cmap;
static GC x_gc;
static Visual *x_vis;
static XVisualInfo *x_visinfo;
static Atom aHints = 0;
static Atom aWMDelete = 0;
static int x_shmeventtype;
//static XShmSegmentInfo x_shminfo;
static qboolean oktodraw = false;
int XShmQueryExtension(Display *);
int XShmGetEventBase(Display *);
int current_framebuffer;
static XImage *x_framebuffer[2] = { 0, 0 };
static XShmSegmentInfo x_shminfo[2];
static int verbose=1;
static byte current_palette[768];
typedef unsigned short PIXEL16;
typedef unsigned long PIXEL24;
static PIXEL16 st2d_8to16table[256];
static PIXEL24 st2d_8to24table[256];
static int shiftmask_fl=0;
static long r_shift,g_shift,b_shift;
static unsigned long r_mask,g_mask,b_mask;
void shiftmask_init()
{
unsigned int x;
r_mask=x_vis->red_mask;
g_mask=x_vis->green_mask;
b_mask=x_vis->blue_mask;
for(r_shift=-8,x=1;x<r_mask;x=x<<1)r_shift++;
for(g_shift=-8,x=1;x<g_mask;x=x<<1)g_shift++;
for(b_shift=-8,x=1;x<b_mask;x=x<<1)b_shift++;
shiftmask_fl=1;
}
PIXEL16 xlib_rgb16(int r,int g,int b)
{
PIXEL16 p;
if(shiftmask_fl==0) shiftmask_init();
p=0;
if(r_shift>0) {
p=(r<<(r_shift))&r_mask;
} else if(r_shift<0) {
p=(r>>(-r_shift))&r_mask;
} else p|=(r&r_mask);
if(g_shift>0) {
p|=(g<<(g_shift))&g_mask;
} else if(g_shift<0) {
p|=(g>>(-g_shift))&g_mask;
} else p|=(g&g_mask);
if(b_shift>0) {
p|=(b<<(b_shift))&b_mask;
} else if(b_shift<0) {
p|=(b>>(-b_shift))&b_mask;
} else p|=(b&b_mask);
return p;
}
PIXEL24 xlib_rgb24(int r,int g,int b)
{
PIXEL24 p;
if(shiftmask_fl==0) shiftmask_init();
p=0;
if(r_shift>0) {
p=(r<<(r_shift))&r_mask;
} else if(r_shift<0) {
p=(r>>(-r_shift))&r_mask;
} else p|=(r&r_mask);
if(g_shift>0) {
p|=(g<<(g_shift))&g_mask;
} else if(g_shift<0) {
p|=(g>>(-g_shift))&g_mask;
} else p|=(g&g_mask);
if(b_shift>0) {
p|=(b<<(b_shift))&b_mask;
} else if(b_shift<0) {
p|=(b>>(-b_shift))&b_mask;
} else p|=(b&b_mask);
return p;
}
void st2_fixup( XImage *framebuf, int x, int y, int width, int height)
{
int xi,yi;
unsigned char *src;
PIXEL16 *dest;
register int count, n;
if( (x<0)||(y<0) )return;
for (yi = y; yi < (y+height); yi++) {
src = &framebuf->data [yi * framebuf->bytes_per_line];
// Duff's Device
count = width;
n = (count + 7) / 8;
dest = ((PIXEL16 *)src) + x+width - 1;
src += x+width - 1;
switch (count % 8) {
case 0: do { *dest-- = st2d_8to16table[*src--];
case 7: *dest-- = st2d_8to16table[*src--];
case 6: *dest-- = st2d_8to16table[*src--];
case 5: *dest-- = st2d_8to16table[*src--];
case 4: *dest-- = st2d_8to16table[*src--];
case 3: *dest-- = st2d_8to16table[*src--];
case 2: *dest-- = st2d_8to16table[*src--];
case 1: *dest-- = st2d_8to16table[*src--];
} while (--n > 0);
}
// for(xi = (x+width-1); xi >= x; xi--) {
// dest[xi] = st2d_8to16table[src[xi]];
// }
}
}
void st3_fixup( XImage *framebuf, int x, int y, int width, int height)
{
int xi,yi;
unsigned char *src;
PIXEL24 *dest;
register int count, n;
if( (x<0)||(y<0) )return;
for (yi = y; yi < (y+height); yi++) {
src = &framebuf->data [yi * framebuf->bytes_per_line];
// Duff's Device
count = width;
n = (count + 7) / 8;
dest = ((PIXEL24 *)src) + x+width - 1;
src += x+width - 1;
switch (count % 8) {
case 0: do { *dest-- = st2d_8to24table[*src--];
case 7: *dest-- = st2d_8to24table[*src--];
case 6: *dest-- = st2d_8to24table[*src--];
case 5: *dest-- = st2d_8to24table[*src--];
case 4: *dest-- = st2d_8to24table[*src--];
case 3: *dest-- = st2d_8to24table[*src--];
case 2: *dest-- = st2d_8to24table[*src--];
case 1: *dest-- = st2d_8to24table[*src--];
} while (--n > 0);
}
// for(xi = (x+width-1); xi >= x; xi--) {
// dest[xi] = st2d_8to16table[src[xi]];
// }
}
}
/*
================
D_BeginDirectRect
================
*/
void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{
// direct drawing of the "accessing disk" icon isn't supported under Nextstep
}
/*
================
D_EndDirectRect
================
*/
void D_EndDirectRect (int x, int y, int width, int height)
{
// direct drawing of the "accessing disk" icon isn't supported under Nextstep
}
/*
=================
VID_Gamma_f
Keybinding command
=================
*/
byte vid_gamma[256];
void VID_Gamma_f (void)
{
float g, f, inf;
int i;
if (Cmd_Argc () == 2)
{
g = Q_atof (Cmd_Argv(1));
for (i=0 ; i<255 ; i++)
{
f = pow ((i+1)/256.0, g);
inf = f*255 + 0.5;
if (inf < 0)
inf = 0;
if (inf > 255)
inf = 255;
vid_gamma[i] = inf;
}
VID_SetPalette (current_palette);
vid.recalc_refdef = 1; // force a surface cache flush
}
}
// ========================================================================
// Tragic death handler
// ========================================================================
void TragicDeath(int signal_num)
{
//XAutoRepeatOn(x_disp);
VID_Shutdown();
Sys_Error("This death brought to you by the number %d\n", signal_num);
}
// ========================================================================
// makes a null cursor
// ========================================================================
static Cursor CreateNullCursor(Display *display, Window root)
{
Pixmap cursormask;
XGCValues xgc;
GC gc;
XColor dummycolour;
Cursor cursor;
cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
xgc.function = GXclear;
gc = XCreateGC(display, cursormask, GCFunction, &xgc);
XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
dummycolour.pixel = 0;
dummycolour.red = 0;
dummycolour.flags = 04;
cursor = XCreatePixmapCursor(display, cursormask, cursormask,
&dummycolour,&dummycolour, 0,0);
XFreePixmap(display,cursormask);
XFreeGC(display,gc);
return cursor;
}
void ResetFrameBuffer(void)
{
int mem;
int pwidth;
if (x_framebuffer[0])
{
Z_Free(mainzone, x_framebuffer[0]->data); // 2001-09-20 Enhanced zone handling by Maddes
// Z_Free(mainzone, d_pzbuffer); // 2001-09-20 Enhanced zone handling by Maddes
free(x_framebuffer[0]);
}
pwidth = x_visinfo->depth / 8;
if (pwidth == 3) pwidth = 4;
mem = ((vid.width*pwidth+3)&~3) * vid.height;
// d_pzbuffer = (unsigned short *) Z_Malloc(mainzone, vid.width*vid.height* // 2001-09-20 Enhanced zone handling by Maddes
// sizeof(*d_pzbuffer));
d_pzbuffer = (short *) Hunk_HighAllocName(vid.width*vid.height*
sizeof(*d_pzbuffer), "zbuff");
x_framebuffer[0] = XCreateImage( x_disp,
x_vis,
x_visinfo->depth,
ZPixmap,
0,
Z_Malloc(mainzone, mem), // 2001-09-20 Enhanced zone handling by Maddes
vid.width, vid.height,
32,
0);
if (!x_framebuffer[0])
Sys_Error("VID: XCreateImage failed\n");
}
void ResetSharedFrameBuffers(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -