2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
vid_x11.c
|
|
|
|
|
|
|
|
general x11 video driver
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999-2000 contributors of the QuakeForge project
|
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define _BSD
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#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 "qendian.h"
|
|
|
|
#include "qargs.h"
|
|
|
|
#include "d_local.h"
|
|
|
|
#include "keys.h"
|
|
|
|
#include "cvar.h"
|
|
|
|
#include "sys.h"
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "console.h"
|
|
|
|
#include "va.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "context_x11.h"
|
|
|
|
#include "host.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_VIDMODE
|
|
|
|
# include <X11/extensions/xf86vmode.h>
|
|
|
|
#endif
|
|
|
|
#include "dga_check.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
extern viddef_t vid; // global video state
|
|
|
|
unsigned short d_8to16table[256];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static Colormap x_cmap;
|
|
|
|
static GC x_gc;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int XShmQueryExtension (Display *);
|
|
|
|
int XShmGetEventBase (Display *);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean doShm;
|
|
|
|
static XShmSegmentInfo x_shminfo[2];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int current_framebuffer;
|
|
|
|
static XImage *x_framebuffer[2] = { 0, 0 };
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int verbose = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int VID_options_items = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
static byte current_palette[768];
|
|
|
|
|
|
|
|
typedef unsigned short PIXEL16;
|
|
|
|
typedef unsigned long PIXEL24;
|
|
|
|
static PIXEL16 st2d_8to16table[256];
|
|
|
|
static PIXEL24 st2d_8to24table[256];
|
2001-02-26 06:48:02 +00:00
|
|
|
static int shiftmask_fl = 0;
|
|
|
|
static long r_shift, g_shift, b_shift;
|
|
|
|
static unsigned long r_mask, g_mask, b_mask;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *vid_width;
|
|
|
|
cvar_t *vid_height;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
shiftmask_init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
unsigned int x;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
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 <<= 1)
|
|
|
|
r_shift++;
|
|
|
|
for (g_shift = -8, x = 1; x < g_mask; x <<= 1)
|
|
|
|
g_shift++;
|
|
|
|
for (b_shift = -8, x = 1; x < b_mask; x <<= 1)
|
|
|
|
b_shift++;
|
|
|
|
shiftmask_fl = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static PIXEL16
|
|
|
|
xlib_rgb16 (int r, int g, int b)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL16 p = 0;
|
|
|
|
|
|
|
|
if (shiftmask_fl == 0)
|
|
|
|
shiftmask_init ();
|
|
|
|
|
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static PIXEL24
|
|
|
|
xlib_rgb24 (int r, int g, int b)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL24 p = 0;
|
|
|
|
|
|
|
|
if (shiftmask_fl == 0)
|
|
|
|
shiftmask_init ();
|
|
|
|
|
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
st2_fixup (XImage * framebuf, int x, int y, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int xi, yi;
|
2001-02-19 21:15:25 +00:00
|
|
|
unsigned char *src;
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL16 *dest;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x < 0 || y < 0)
|
|
|
|
return;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (yi = y; yi < (y + height); yi++) {
|
|
|
|
src = &framebuf->data[yi * framebuf->bytes_per_line];
|
|
|
|
dest = (PIXEL16 *) src;
|
|
|
|
for (xi = (x + width - 1); xi >= x; xi--) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dest[xi] = st2d_8to16table[src[xi]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
st3_fixup (XImage * framebuf, int x, int y, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int yi;
|
2001-02-19 21:15:25 +00:00
|
|
|
unsigned char *src;
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL24 *dest;
|
2001-02-19 21:15:25 +00:00
|
|
|
register int count, n;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x < 0 || y < 0)
|
|
|
|
return;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (yi = y; yi < (y + height); yi++) {
|
|
|
|
src = &framebuf->data[yi * framebuf->bytes_per_line];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Duff's Device
|
|
|
|
count = width;
|
|
|
|
n = (count + 7) / 8;
|
2001-02-26 06:48:02 +00:00
|
|
|
dest = ((PIXEL24 *) src) + x + width - 1;
|
|
|
|
src += x + width - 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
switch (count % 8) {
|
2001-02-26 06:48:02 +00:00
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// for(xi = (x+width-1); xi >= x; xi--) {
|
|
|
|
// dest[xi] = st2d_8to16table[src[xi]];
|
|
|
|
// }
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
D_BeginDirectRect
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// direct drawing of the "accessing disk" icon isn't supported
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
D_EndDirectRect
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
D_EndDirectRect (int x, int y, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// direct drawing of the "accessing disk" icon isn't supported
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_Gamma_f
|
|
|
|
|
|
|
|
Keybinding command
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
byte vid_gamma[256];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Gamma_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
float g, f, inf;
|
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (Cmd_Argc () == 2) {
|
2001-02-26 06:48:02 +00:00
|
|
|
g = 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;
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_gamma[i] = inf;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_SetPalette (current_palette);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
ResetFrameBuffer (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int tbuffersize, tcachesize;
|
|
|
|
|
|
|
|
void *vid_surfcache;
|
|
|
|
int mem, pwidth;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Calculate the sizes we want first
|
|
|
|
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
|
2001-02-26 06:48:02 +00:00
|
|
|
tcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (x_framebuffer[0]) {
|
2001-02-26 06:48:02 +00:00
|
|
|
XDestroyImage (x_framebuffer[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// Free the old z-buffer
|
|
|
|
if (d_pzbuffer) {
|
|
|
|
free (d_pzbuffer);
|
|
|
|
d_pzbuffer = NULL;
|
|
|
|
}
|
|
|
|
// Free the old surface cache
|
|
|
|
vid_surfcache = D_SurfaceCacheAddress ();
|
|
|
|
if (vid_surfcache) {
|
|
|
|
D_FlushCaches ();
|
|
|
|
free (vid_surfcache);
|
|
|
|
vid_surfcache = NULL;
|
|
|
|
}
|
|
|
|
// Allocate the new z-buffer
|
|
|
|
d_pzbuffer = calloc (tbuffersize, 1);
|
|
|
|
if (!d_pzbuffer) {
|
|
|
|
Sys_Error ("Not enough memory for video mode\n");
|
|
|
|
}
|
|
|
|
// Allocate the new surface cache; free the z-buffer if we fail
|
|
|
|
vid_surfcache = calloc (tcachesize, 1);
|
|
|
|
if (!vid_surfcache) {
|
|
|
|
free (d_pzbuffer);
|
|
|
|
d_pzbuffer = NULL;
|
|
|
|
Sys_Error ("Not enough memory for video mode\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
D_InitCaches (vid_surfcache, tcachesize);
|
|
|
|
|
|
|
|
pwidth = x_visinfo->depth / 8;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (pwidth == 3)
|
|
|
|
pwidth = 4;
|
|
|
|
mem = ((vid.width * pwidth + 7) & ~7) * vid.height;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
x_framebuffer[0] = XCreateImage (x_disp, x_vis, x_visinfo->depth,
|
|
|
|
ZPixmap, 0,
|
|
|
|
malloc (mem),
|
|
|
|
vid.width, vid.height, 32, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!x_framebuffer[0]) {
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: XCreateImage failed\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
ResetSharedFrameBuffers (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int tbuffersize, tcachesize;
|
|
|
|
void *vid_surfcache;
|
|
|
|
|
|
|
|
int size;
|
|
|
|
int key;
|
|
|
|
int minsize = getpagesize ();
|
|
|
|
int frm;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Calculate the sizes we want first
|
|
|
|
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
|
2001-02-26 06:48:02 +00:00
|
|
|
tcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Free the old z-buffer
|
|
|
|
if (d_pzbuffer) {
|
|
|
|
free (d_pzbuffer);
|
|
|
|
d_pzbuffer = NULL;
|
|
|
|
}
|
|
|
|
// Free the old surface cache
|
|
|
|
vid_surfcache = D_SurfaceCacheAddress ();
|
|
|
|
if (vid_surfcache) {
|
|
|
|
D_FlushCaches ();
|
|
|
|
free (vid_surfcache);
|
|
|
|
vid_surfcache = NULL;
|
|
|
|
}
|
|
|
|
// Allocate the new z-buffer
|
|
|
|
d_pzbuffer = calloc (tbuffersize, 1);
|
|
|
|
if (!d_pzbuffer) {
|
|
|
|
Sys_Error ("Not enough memory for video mode\n");
|
|
|
|
}
|
|
|
|
// Allocate the new surface cache; free the z-buffer if we fail
|
|
|
|
vid_surfcache = calloc (tcachesize, 1);
|
|
|
|
if (!vid_surfcache) {
|
|
|
|
free (d_pzbuffer);
|
|
|
|
d_pzbuffer = NULL;
|
|
|
|
Sys_Error ("Not enough memory for video mode\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
D_InitCaches (vid_surfcache, tcachesize);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (frm = 0; frm < 2; frm++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// free up old frame buffer memory
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x_framebuffer[frm]) {
|
|
|
|
XShmDetach (x_disp, &x_shminfo[frm]);
|
|
|
|
free (x_framebuffer[frm]);
|
|
|
|
shmdt (x_shminfo[frm].shmaddr);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// create the image
|
|
|
|
x_framebuffer[frm] = XShmCreateImage (x_disp,
|
2001-02-26 06:48:02 +00:00
|
|
|
x_vis,
|
|
|
|
x_visinfo->depth,
|
|
|
|
ZPixmap,
|
|
|
|
0,
|
|
|
|
&x_shminfo[frm],
|
|
|
|
vid.width, vid.height);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// grab shared memory
|
2001-02-26 06:48:02 +00:00
|
|
|
size = x_framebuffer[frm]->bytes_per_line * x_framebuffer[frm]->height;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (size < minsize)
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: Window must use at least %d bytes\n", minsize);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
key = random ();
|
|
|
|
x_shminfo[frm].shmid = shmget ((key_t) key, size, IPC_CREAT | 0777);
|
|
|
|
if (x_shminfo[frm].shmid == -1)
|
|
|
|
Sys_Error ("VID: Could not get any shared memory\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// attach to the shared memory segment
|
2001-02-26 06:48:02 +00:00
|
|
|
x_shminfo[frm].shmaddr = (void *) shmat (x_shminfo[frm].shmid, 0, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
printf ("VID: shared memory id=%d, addr=0x%lx\n", x_shminfo[frm].shmid,
|
|
|
|
(long) x_shminfo[frm].shmaddr);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
|
|
|
|
|
|
|
|
// get the X server to attach to it
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!XShmAttach (x_disp, &x_shminfo[frm]))
|
|
|
|
Sys_Error ("VID: XShmAttach() failed\n");
|
|
|
|
XSync (x_disp, 0);
|
|
|
|
shmctl (x_shminfo[frm].shmid, IPC_RMID, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
event_shm (XEvent * event)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
if (doShm)
|
2001-02-19 21:15:25 +00:00
|
|
|
oktodraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called at startup to set up translation tables, takes 256 8 bit RGB values
|
|
|
|
// the palette data will go away after the call, so it must be copied off if
|
|
|
|
// the video driver will need it again
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Init (unsigned char *palette)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int pnum, i;
|
2001-02-19 21:15:25 +00:00
|
|
|
XVisualInfo template;
|
2001-02-26 06:48:02 +00:00
|
|
|
int num_visuals;
|
|
|
|
int template_mask;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VID_GetWindowSize (320, 200);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// plugin_load("in_x11.so");
|
|
|
|
// Cmd_AddCommand("gamma", VID_Gamma_f, "No Description");
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
vid_gamma[i] = i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid.width = vid_width->int_val;
|
|
|
|
vid.height = vid_height->int_val;
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.numpages = 2;
|
|
|
|
vid.colormap = host_colormap;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
srandom (getpid ());
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
verbose = COM_CheckParm ("-verbose");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// open the display
|
2001-02-26 06:48:02 +00:00
|
|
|
x11_open_display ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// check for command-line window size
|
|
|
|
|
|
|
|
template_mask = 0;
|
|
|
|
|
|
|
|
// specify a visual id
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((pnum = COM_CheckParm ("-visualid"))) {
|
|
|
|
if (pnum >= com_argc - 1)
|
|
|
|
Sys_Error ("VID: -visualid <id#>\n");
|
|
|
|
template.visualid = atoi (com_argv[pnum + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
template_mask = VisualIDMask;
|
|
|
|
}
|
|
|
|
// If not specified, use default visual
|
2001-02-26 06:48:02 +00:00
|
|
|
else {
|
2001-02-19 21:15:25 +00:00
|
|
|
template.visualid =
|
2001-02-26 06:48:02 +00:00
|
|
|
XVisualIDFromVisual (XDefaultVisual (x_disp, x_screen));
|
2001-02-19 21:15:25 +00:00
|
|
|
template_mask = VisualIDMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pick a visual- warn if more than one was available
|
2001-02-26 06:48:02 +00:00
|
|
|
x_visinfo = XGetVisualInfo (x_disp, template_mask, &template, &num_visuals);
|
2001-02-19 21:15:25 +00:00
|
|
|
x_vis = x_visinfo->visual;
|
|
|
|
|
|
|
|
if (num_visuals > 1) {
|
2001-02-26 06:48:02 +00:00
|
|
|
printf ("Found more than one visual id at depth %d:\n", template.depth);
|
|
|
|
for (i = 0; i < num_visuals; i++)
|
|
|
|
printf (" -visualid %d\n", (int) (x_visinfo[i].visualid));
|
2001-02-19 21:15:25 +00:00
|
|
|
} else if (num_visuals == 0) {
|
|
|
|
if (template_mask == VisualIDMask) {
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: Bad visual id %ld\n", template.visualid);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: No visuals at depth %d\n", template.depth);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose) {
|
2001-02-26 06:48:02 +00:00
|
|
|
printf ("Using visualid %d:\n", (int) (x_visinfo->visualid));
|
|
|
|
printf (" class %d\n", x_visinfo->class);
|
|
|
|
printf (" screen %d\n", x_visinfo->screen);
|
|
|
|
printf (" depth %d\n", x_visinfo->depth);
|
|
|
|
printf (" red_mask 0x%x\n", (int) (x_visinfo->red_mask));
|
|
|
|
printf (" green_mask 0x%x\n", (int) (x_visinfo->green_mask));
|
|
|
|
printf (" blue_mask 0x%x\n", (int) (x_visinfo->blue_mask));
|
|
|
|
printf (" colormap_size %d\n", x_visinfo->colormap_size);
|
|
|
|
printf (" bits_per_rgb %d\n", x_visinfo->bits_per_rgb);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup attributes for main window */
|
2001-02-26 06:48:02 +00:00
|
|
|
x11_set_vidmode (vid.width, vid.height);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/* Create the main window */
|
2001-02-26 06:48:02 +00:00
|
|
|
x11_create_window (vid.width, vid.height);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/* Invisible cursor */
|
2001-02-26 06:48:02 +00:00
|
|
|
x11_create_null_cursor ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (x_visinfo->depth == 8) {
|
|
|
|
/* Create and upload the palette */
|
|
|
|
if (x_visinfo->class == PseudoColor) {
|
2001-02-26 06:48:02 +00:00
|
|
|
x_cmap = XCreateColormap (x_disp, x_win, x_vis, AllocAll);
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
XSetWindowColormap (x_disp, x_win, x_cmap);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// create the GC
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
XGCValues xgcvalues;
|
|
|
|
int valuemask = GCGraphicsExposures;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
xgcvalues.graphics_exposures = False;
|
2001-02-26 06:48:02 +00:00
|
|
|
x_gc = XCreateGC (x_disp, x_win, valuemask, &xgcvalues);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
x11_grab_keyboard ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// wait for first exposure event
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
XEvent event;
|
|
|
|
|
|
|
|
do {
|
|
|
|
XNextEvent (x_disp, &event);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (event.type == Expose && !event.xexpose.count)
|
|
|
|
oktodraw = true;
|
|
|
|
} while (!oktodraw);
|
|
|
|
}
|
|
|
|
// now safe to draw
|
|
|
|
|
|
|
|
// even if MITSHM is available, make sure it's a local connection
|
2001-02-26 06:48:02 +00:00
|
|
|
if (XShmQueryExtension (x_disp))
|
|
|
|
// if (0)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
char *displayname;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
doShm = true;
|
2001-02-26 06:48:02 +00:00
|
|
|
displayname = (char *) getenv ("DISPLAY");
|
|
|
|
if (displayname) {
|
|
|
|
char *d = displayname;
|
|
|
|
|
|
|
|
while (*d && (*d != ':'))
|
|
|
|
d++;
|
|
|
|
if (*d)
|
|
|
|
*d = 0;
|
|
|
|
if (!(!strcasecmp (displayname, "unix") || !*displayname))
|
2001-02-19 21:15:25 +00:00
|
|
|
doShm = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (doShm) {
|
|
|
|
x_shmeventtype = XShmGetEventBase (x_disp) + ShmCompletion;
|
|
|
|
ResetSharedFrameBuffers ();
|
|
|
|
} else
|
|
|
|
ResetFrameBuffer ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
current_framebuffer = 0;
|
|
|
|
vid.rowbytes = x_framebuffer[0]->bytes_per_line;
|
|
|
|
vid.buffer = x_framebuffer[0]->data;
|
|
|
|
vid.direct = 0;
|
|
|
|
vid.conbuffer = x_framebuffer[0]->data;
|
|
|
|
vid.conrowbytes = vid.rowbytes;
|
|
|
|
vid.conwidth = vid.width;
|
|
|
|
vid.conheight = vid.height;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// XSynchronize(x_disp, False);
|
|
|
|
x11_add_event (x_shmeventtype, event_shm);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Init_Cvars ()
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
x11_Init_Cvars ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_ShiftPalette (unsigned char *p)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_SetPalette (p);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_SetPalette (unsigned char *palette)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
XColor colors[256];
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
st2d_8to16table[i] = xlib_rgb16 (palette[i * 3], palette[i * 3 + 1],
|
|
|
|
palette[i * 3 + 2]);
|
|
|
|
st2d_8to24table[i] = xlib_rgb24 (palette[i * 3], palette[i * 3 + 1],
|
|
|
|
palette[i * 3 + 2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) {
|
|
|
|
if (palette != current_palette) {
|
2001-02-26 06:48:02 +00:00
|
|
|
memcpy (current_palette, palette, 768);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
colors[i].pixel = i;
|
|
|
|
colors[i].flags = DoRed | DoGreen | DoBlue;
|
|
|
|
colors[i].red = vid_gamma[palette[i * 3]] * 256;
|
|
|
|
colors[i].green = vid_gamma[palette[i * 3 + 1]] * 256;
|
|
|
|
colors[i].blue = vid_gamma[palette[i * 3 + 2]] * 256;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
XStoreColors (x_disp, x_cmap, colors, 256);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Called at shutdown
|
|
|
|
*/
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Printf ("VID_Shutdown\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
if (x_disp) {
|
2001-02-26 06:48:02 +00:00
|
|
|
x11_restore_vidmode ();
|
|
|
|
x11_close_display ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int config_notify = 0;
|
|
|
|
static int config_notify_width;
|
|
|
|
static int config_notify_height;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Flushes the given rectangles from the view buffer to the screen.
|
|
|
|
*/
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_Update (vrect_t *rects)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
/* If the window changes dimension, skip this frame. */
|
|
|
|
if (config_notify) {
|
2001-02-26 06:48:02 +00:00
|
|
|
fprintf (stderr, "config notify\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
config_notify = 0;
|
|
|
|
vid.width = config_notify_width & ~7;
|
|
|
|
vid.height = config_notify_height;
|
|
|
|
if (doShm)
|
2001-02-26 06:48:02 +00:00
|
|
|
ResetSharedFrameBuffers ();
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
ResetFrameBuffer ();
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.rowbytes = x_framebuffer[0]->bytes_per_line;
|
|
|
|
vid.buffer = x_framebuffer[current_framebuffer]->data;
|
|
|
|
vid.conbuffer = vid.buffer;
|
|
|
|
vid.conwidth = vid.width;
|
|
|
|
vid.conheight = vid.height;
|
|
|
|
vid.conrowbytes = vid.rowbytes;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.recalc_refdef = 1; /* force a surface cache flush */
|
|
|
|
Con_CheckResize ();
|
|
|
|
Con_Clear_f ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doShm) {
|
|
|
|
while (rects) {
|
|
|
|
if (x_visinfo->depth == 16) {
|
2001-02-26 06:48:02 +00:00
|
|
|
st2_fixup (x_framebuffer[current_framebuffer],
|
|
|
|
rects->x, rects->y, rects->width, rects->height);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else if (x_visinfo->depth == 24) {
|
2001-02-26 06:48:02 +00:00
|
|
|
st3_fixup (x_framebuffer[current_framebuffer],
|
|
|
|
rects->x, rects->y, rects->width, rects->height);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!XShmPutImage (x_disp, x_win, x_gc,
|
|
|
|
x_framebuffer[current_framebuffer],
|
|
|
|
rects->x, rects->y,
|
|
|
|
rects->x, rects->y,
|
|
|
|
rects->width, rects->height, True)) {
|
|
|
|
Sys_Error ("VID_Update: XShmPutImage failed\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
oktodraw = false;
|
2001-02-26 06:48:02 +00:00
|
|
|
while (!oktodraw)
|
|
|
|
x11_process_event ();
|
2001-02-19 21:15:25 +00:00
|
|
|
rects = rects->pnext;
|
|
|
|
}
|
|
|
|
current_framebuffer = !current_framebuffer;
|
|
|
|
vid.buffer = x_framebuffer[current_framebuffer]->data;
|
|
|
|
vid.conbuffer = vid.buffer;
|
2001-02-26 06:48:02 +00:00
|
|
|
XSync (x_disp, False);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
|
|
|
while (rects) {
|
|
|
|
if (x_visinfo->depth == 16) {
|
2001-02-26 06:48:02 +00:00
|
|
|
st2_fixup (x_framebuffer[current_framebuffer],
|
|
|
|
rects->x, rects->y, rects->width, rects->height);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else if (x_visinfo->depth == 24) {
|
2001-02-26 06:48:02 +00:00
|
|
|
st3_fixup (x_framebuffer[current_framebuffer],
|
|
|
|
rects->x, rects->y, rects->width, rects->height);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
XPutImage (x_disp, x_win, x_gc, x_framebuffer[0],
|
|
|
|
rects->x, rects->y, rects->x, rects->y,
|
|
|
|
rects->width, rects->height);
|
2001-02-19 21:15:25 +00:00
|
|
|
rects = rects->pnext;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
XSync (x_disp, False);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int dither;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_DitherOn (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (dither == 0) {
|
|
|
|
vid.recalc_refdef = 1;
|
|
|
|
dither = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_DitherOff (void)
|
|
|
|
{
|
|
|
|
if (dither) {
|
|
|
|
vid.recalc_refdef = 1;
|
|
|
|
dither = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_LockBuffer (void)
|
|
|
|
{
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_UnlockBuffer (void)
|
|
|
|
{
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
VID_SetCaption (char *text)
|
|
|
|
{
|
|
|
|
if (text && *text) {
|
2001-02-26 06:48:02 +00:00
|
|
|
char *temp = strdup (text);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
|
|
|
|
free (temp);
|
|
|
|
} else {
|
|
|
|
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_HandlePause (qboolean paused)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|