Whitespace, optimizations to VID_Update()

This commit is contained in:
Jeff Teunissen 2000-11-21 07:42:23 +00:00
parent 979a5b7e47
commit ded66b1bde

View file

@ -1,7 +1,7 @@
/* /*
vid_x11.c vid_x11.c
general x11 video driver General X11 video driver
Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1999-2000 contributors of the QuakeForge project Copyright (C) 1999-2000 contributors of the QuakeForge project
@ -31,51 +31,53 @@
*/ */
#define _BSD #define _BSD
#include <config.h>
#include <config.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <sys/ipc.h>
#include <sys/shm.h> #ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <X11/Xatom.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/XShm.h> #include <X11/extensions/XShm.h>
#include "qendian.h"
#include "qargs.h"
#include "quakedef.h"
#include "d_local.h"
#include "keys.h"
#include "cvar.h"
#include "menu.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"
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h> # include <X11/extensions/xf86vmode.h>
#endif #endif
#include "dga_check.h"
#ifdef HAVE_STRINGS_H #include "client.h"
#include <strings.h> #include "cmd.h"
#endif #include "console.h"
#include "context_x11.h"
#include "cvar.h"
#include "d_local.h"
#include "dga_check.h"
#include "draw.h"
#include "input.h"
#include "input.h"
#include "keys.h"
#include "menu.h"
#include "qargs.h"
#include "qendian.h"
#include "quakedef.h"
#include "sys.h"
#include "va.h"
extern viddef_t vid; // global video state extern viddef_t vid; // global video state
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
@ -83,10 +85,10 @@ unsigned short d_8to16table[256];
static Colormap x_cmap; static Colormap x_cmap;
static GC x_gc; static GC x_gc;
int XShmQueryExtension(Display *); int XShmQueryExtension (Display *);
int XShmGetEventBase(Display *); int XShmGetEventBase (Display *);
qboolean doShm; static qboolean doShm;
static XShmSegmentInfo x_shminfo[2]; static XShmSegmentInfo x_shminfo[2];
static int current_framebuffer; static int current_framebuffer;
@ -100,101 +102,131 @@ static byte current_palette[768];
typedef unsigned short PIXEL16; typedef unsigned short PIXEL16;
typedef unsigned long PIXEL24; typedef unsigned long PIXEL24;
static PIXEL16 st2d_8to16table[256]; static PIXEL16 st2d_8to16table[256];
static PIXEL24 st2d_8to24table[256]; static PIXEL24 st2d_8to24table[256];
static int shiftmask_fl=0; static int shiftmask_fl = 0;
static long r_shift,g_shift,b_shift; static long r_shift, g_shift, b_shift;
static unsigned long r_mask,g_mask,b_mask; static unsigned long r_mask, g_mask, b_mask;
cvar_t *vid_width; cvar_t *vid_width;
cvar_t *vid_height; cvar_t *vid_height;
static void static void
shiftmask_init( void ) shiftmask_init (void)
{ {
unsigned int x; unsigned int x;
r_mask=x_vis->red_mask; r_mask = x_vis->red_mask;
g_mask=x_vis->green_mask; g_mask = x_vis->green_mask;
b_mask=x_vis->blue_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;
}
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;
}
static PIXEL16 static PIXEL16
xlib_rgb16(int r, int g, int b) xlib_rgb16(int r, int g, int b)
{ {
PIXEL16 p = 0; PIXEL16 p = 0;
if (shiftmask_fl==0) shiftmask_init(); if (!shiftmask_fl)
shiftmask_init ();
if (r_shift>0) { if (r_shift > 0) {
p=(r<<(r_shift))&r_mask; p=(r << (r_shift)) & r_mask;
} else if (r_shift<0) { } else {
p=(r>>(-r_shift))&r_mask; if (r_shift < 0) {
} else p|=(r&r_mask); p =(r >> (-r_shift)) & r_mask;
} else {
p |= (r & r_mask);
}
}
if (g_shift>0) { if (g_shift > 0) {
p|=(g<<(g_shift))&g_mask; p |= (g << (g_shift)) & g_mask;
} else if (g_shift<0) { } else {
p|=(g>>(-g_shift))&g_mask; if (g_shift < 0) {
} else p|=(g&g_mask); p |= (g >> (-g_shift)) & g_mask;
} else {
p |= (g & g_mask);
}
}
if (b_shift>0) { if (b_shift > 0) {
p|=(b<<(b_shift))&b_mask; p |= (b << (b_shift)) & b_mask;
} else if (b_shift<0) { } else {
p|=(b>>(-b_shift))&b_mask; if (b_shift < 0) {
} else p|=(b&b_mask); p |= (b >> (-b_shift)) & b_mask;
} else {
p |= (b & b_mask);
}
}
return p; return p;
} }
static PIXEL24 static PIXEL24
xlib_rgb24(int r,int g,int b) xlib_rgb24 (int r, int g, int b)
{ {
PIXEL24 p = 0; PIXEL24 p = 0;
if (shiftmask_fl==0) shiftmask_init(); if (!shiftmask_fl)
shiftmask_init ();
if (r_shift>0) { if (r_shift > 0) {
p=(r<<(r_shift))&r_mask; p = (r << (r_shift)) & r_mask;
} else if (r_shift<0) { } else {
p=(r>>(-r_shift))&r_mask; if (r_shift < 0) {
} else p|=(r&r_mask); p = (r >> (-r_shift)) & r_mask;
} else {
p |= (r & r_mask);
}
}
if (g_shift>0) { if (g_shift > 0) {
p|=(g<<(g_shift))&g_mask; p |= (g << (g_shift)) & g_mask;
} else if (g_shift<0) { } else {
p|=(g>>(-g_shift))&g_mask; if (g_shift < 0) {
} else p|=(g&g_mask); p |= (g >> (-g_shift)) & g_mask;
} else {
p |= (g & g_mask);
}
}
if (b_shift>0) { if (b_shift > 0) {
p|=(b<<(b_shift))&b_mask; p |= (b << (b_shift)) & b_mask;
} else if (b_shift<0) { } else {
p|=(b>>(-b_shift))&b_mask; if (b_shift < 0) {
} else p|=(b&b_mask); p |= (b >> (-b_shift)) & b_mask;
} else {
p |= (b & b_mask);
}
}
return p; return p;
} }
static void static void
st2_fixup(XImage *framebuf, int x, int y, int width, int height) st2_fixup (XImage *framebuf, int x, int y, int width, int height)
{ {
int xi,yi; int xi, yi;
unsigned char *src; unsigned char *src;
PIXEL16 *dest; PIXEL16 *dest;
if (x < 0 || y < 0) return; if (x < 0 || y < 0)
return;
for (yi = y; yi < (y+height); yi++) { for (yi = y; yi < (y + height); yi++) {
src = &framebuf->data [yi * framebuf->bytes_per_line]; src = &framebuf->data[yi * framebuf->bytes_per_line];
dest = (PIXEL16*)src; dest = (PIXEL16 *) src;
for(xi = (x+width-1); xi >= x; xi--) { for(xi = (x + width - 1); xi >= x; xi--) {
dest[xi] = st2d_8to16table[src[xi]]; dest[xi] = st2d_8to16table[src[xi]];
} }
} }
@ -202,7 +234,7 @@ st2_fixup(XImage *framebuf, int x, int y, int width, int height)
static void static void
st3_fixup(XImage *framebuf, int x, int y, int width, int height) st3_fixup (XImage *framebuf, int x, int y, int width, int height)
{ {
int yi; int yi;
unsigned char *src; unsigned char *src;
@ -243,7 +275,8 @@ st3_fixup(XImage *framebuf, int x, int y, int width, int height)
D_BeginDirectRect D_BeginDirectRect
================ ================
*/ */
void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) void
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{ {
// direct drawing of the "accessing disk" icon isn't supported // direct drawing of the "accessing disk" icon isn't supported
} }
@ -254,7 +287,8 @@ void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
D_EndDirectRect D_EndDirectRect
================ ================
*/ */
void D_EndDirectRect (int x, int y, int width, int height) void
D_EndDirectRect (int x, int y, int width, int height)
{ {
// direct drawing of the "accessing disk" icon isn't supported // direct drawing of the "accessing disk" icon isn't supported
} }
@ -270,24 +304,24 @@ Keybinding command
byte vid_gamma[256]; byte vid_gamma[256];
void VID_Gamma_f (void) void
VID_Gamma_f (void)
{ {
float g, f, inf; float g, f, inf;
int i; int i;
if (Cmd_Argc () == 2) { if (Cmd_Argc () == 2) {
g = atof (Cmd_Argv(1)); g = atof (Cmd_Argv (1));
for (i=0 ; i<255 ; i++) { for (i = 0; i < 255; i++) {
f = pow ((i+1)/256.0, g); f = pow ((i + 1) / 256.0, g);
inf = f*255 + 0.5; inf = f*255 + 0.5;
if (inf < 0) inf = 0; inf = bound (0, inf, 255);
if (inf > 255) inf = 255;
vid_gamma[i] = inf; vid_gamma[i] = inf;
} }
VID_SetPalette(current_palette); VID_SetPalette (current_palette);
vid.recalc_refdef = 1; // force a surface cache flush vid.recalc_refdef = 1; // force a surface cache flush
} }
@ -295,7 +329,7 @@ void VID_Gamma_f (void)
static void static void
ResetFrameBuffer(void) ResetFrameBuffer (void)
{ {
int tbuffersize, tcachesize; int tbuffersize, tcachesize;
@ -304,10 +338,10 @@ ResetFrameBuffer(void)
// Calculate the sizes we want first // Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer); tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes(vid.width, vid.height); tcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
if (x_framebuffer[0]) { if (x_framebuffer[0]) {
XDestroyImage(x_framebuffer[0]); XDestroyImage (x_framebuffer[0]);
} }
// Free the old z-buffer // Free the old z-buffer
@ -341,35 +375,34 @@ ResetFrameBuffer(void)
D_InitCaches (vid_surfcache, tcachesize); D_InitCaches (vid_surfcache, tcachesize);
pwidth = x_visinfo->depth / 8; pwidth = x_visinfo->depth / 8;
if (pwidth == 3) pwidth = 4;
mem = ((vid.width*pwidth+7)&~7) * vid.height;
x_framebuffer[0] = XCreateImage(x_disp, x_vis, x_visinfo->depth, if (pwidth == 3)
ZPixmap, 0, pwidth = 4;
malloc(mem), mem = ((vid.width * pwidth + 7) &~ 7) * vid.height;
vid.width, vid.height,
32, 0); x_framebuffer[0] = XCreateImage (x_disp, x_vis, x_visinfo->depth,
ZPixmap, 0, malloc (mem), vid.width,
vid.height, 32, 0);
if (!x_framebuffer[0]) { if (!x_framebuffer[0]) {
Sys_Error("VID: XCreateImage failed\n"); Sys_Error ("VID: XCreateImage failed\n");
} }
} }
static void static void
ResetSharedFrameBuffers(void) ResetSharedFrameBuffers (void)
{ {
int tbuffersize, tcachesize; int tbuffersize, tcachesize;
void *vid_surfcache; void *vid_surfcache;
int size; int size;
int key; int key;
int minsize = getpagesize(); int minsize = getpagesize ();
int frm; int frm;
// Calculate the sizes we want first // Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer); tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes(vid.width, vid.height); tcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
// Free the old z-buffer // Free the old z-buffer
if (d_pzbuffer) { if (d_pzbuffer) {
@ -401,67 +434,65 @@ ResetSharedFrameBuffers(void)
D_InitCaches (vid_surfcache, tcachesize); D_InitCaches (vid_surfcache, tcachesize);
for (frm=0 ; frm<2 ; frm++) { for (frm = 0; frm < 2; frm++) {
// free up old frame buffer memory // free up old frame buffer memory
if (x_framebuffer[frm]) { if (x_framebuffer[frm]) {
XShmDetach(x_disp, &x_shminfo[frm]); XShmDetach (x_disp, &x_shminfo[frm]);
free(x_framebuffer[frm]); free (x_framebuffer[frm]);
shmdt(x_shminfo[frm].shmaddr); shmdt (x_shminfo[frm].shmaddr);
} }
// create the image // create the image
x_framebuffer[frm] = XShmCreateImage (x_disp, x_framebuffer[frm] = XShmCreateImage (x_disp, x_vis, x_visinfo->depth,
x_vis, ZPixmap, 0, &x_shminfo[frm],
x_visinfo->depth, vid.width, vid.height );
ZPixmap,
0,
&x_shminfo[frm],
vid.width,
vid.height );
// grab shared memory // grab shared memory
size = x_framebuffer[frm]->bytes_per_line size = x_framebuffer[frm]->bytes_per_line * x_framebuffer[frm]->height;
* x_framebuffer[frm]->height;
if (size < minsize) if (size < minsize)
Sys_Error("VID: Window must use at least %d bytes\n", minsize); Sys_Error ("VID: Window must use at least %d bytes\n", minsize);
key = random(); key = random();
x_shminfo[frm].shmid = shmget((key_t)key, size, IPC_CREAT|0777); x_shminfo[frm].shmid = shmget((key_t)key, size, IPC_CREAT|0777);
if (x_shminfo[frm].shmid==-1) if (x_shminfo[frm].shmid==-1)
Sys_Error("VID: Could not get any shared memory\n"); Sys_Error ("VID: Could not get any shared memory\n");
// attach to the shared memory segment // attach to the shared memory segment
x_shminfo[frm].shmaddr = x_shminfo[frm].shmaddr = (void *) shmat (x_shminfo[frm].shmid, 0, 0);
(void *) shmat(x_shminfo[frm].shmid, 0, 0);
printf("VID: shared memory id=%d, addr=0x%lx\n", x_shminfo[frm].shmid, printf ("VID: shared memory id=%d, addr=0x%lx\n", x_shminfo[frm].shmid,
(long) x_shminfo[frm].shmaddr); (long) x_shminfo[frm].shmaddr);
x_framebuffer[frm]->data = x_shminfo[frm].shmaddr; x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
// get the X server to attach to it // get the X server to attach to it
if (!XShmAttach(x_disp, &x_shminfo[frm])) if (!XShmAttach (x_disp, &x_shminfo[frm]))
Sys_Error("VID: XShmAttach() failed\n"); Sys_Error ("VID: XShmAttach() failed\n");
XSync(x_disp, 0); XSync (x_disp, 0);
shmctl(x_shminfo[frm].shmid, IPC_RMID, 0); shmctl (x_shminfo[frm].shmid, IPC_RMID, 0);
} }
} }
static void event_shm(XEvent *event) static void
event_shm (XEvent *event)
{ {
if (doShm) if (doShm)
oktodraw = true; 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 VID_Init
// the video driver will need it again
void VID_Init (unsigned char *palette) Set up color translation tables and the window. Takes a 256-color 8-bit
palette. Palette data will go away after the call, so copy it if you'll
need it later.
*/
void
VID_Init (unsigned char *palette)
{ {
int pnum, i; int pnum, i;
XVisualInfo template; XVisualInfo template;
@ -470,8 +501,8 @@ void VID_Init (unsigned char *palette)
VID_GetWindowSize (320, 200); VID_GetWindowSize (320, 200);
//plugin_load("in_x11.so"); // plugin_load ("in_x11.so");
// Cmd_AddCommand("gamma", VID_Gamma_f); // Cmd_AddCommand ("gamma", VID_Gamma_f);
for (i=0; i < 256; i++) vid_gamma[i] = i; for (i=0; i < 256; i++) vid_gamma[i] = i;
vid.width = vid_width->int_val; vid.width = vid_width->int_val;
@ -480,81 +511,74 @@ void VID_Init (unsigned char *palette)
vid.maxwarpheight = WARP_HEIGHT; vid.maxwarpheight = WARP_HEIGHT;
vid.numpages = 2; vid.numpages = 2;
vid.colormap = host_colormap; vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
srandom(getpid()); srandom (getpid ());
verbose=COM_CheckParm("-verbose"); verbose = COM_CheckParm ("-verbose");
// open the display // open the display
x11_open_display(); x11_open_display ();
// check for command-line window size
template_mask = 0; template_mask = 0;
// specify a visual id // specify a visual id
if ((pnum=COM_CheckParm("-visualid"))) if ((pnum = COM_CheckParm ("-visualid"))) {
{
if (pnum >= com_argc-1) if (pnum >= com_argc-1)
Sys_Error("VID: -visualid <id#>\n"); Sys_Error ("VID: -visualid <id#>\n");
template.visualid = atoi(com_argv[pnum+1]); template.visualid = atoi (com_argv[pnum+1]);
template_mask = VisualIDMask; template_mask = VisualIDMask;
} } else { // If not specified, use default visual
// If not specified, use default visual
else
{
template.visualid = template.visualid =
XVisualIDFromVisual(XDefaultVisual(x_disp, x_screen)); XVisualIDFromVisual (XDefaultVisual (x_disp, x_screen));
template_mask = VisualIDMask; template_mask = VisualIDMask;
} }
// pick a visual- warn if more than one was available // pick a visual -- warn if more than one was available
x_visinfo = XGetVisualInfo(x_disp, template_mask, &template, &num_visuals); x_visinfo = XGetVisualInfo (x_disp, template_mask, &template, &num_visuals);
x_vis = x_visinfo->visual; x_vis = x_visinfo->visual;
if (num_visuals > 1) { if (num_visuals > 1) {
printf("Found more than one visual id at depth %d:\n", template.depth); printf ("Found more than one visual id at depth %d:\n", template.depth);
for (i=0 ; i<num_visuals ; i++) for (i = 0; i < num_visuals; i++)
printf(" -visualid %d\n", (int)(x_visinfo[i].visualid)); printf (" -visualid %d\n", (int) x_visinfo[i].visualid);
} else if (num_visuals == 0) {
if (template_mask == VisualIDMask) {
Sys_Error("VID: Bad visual id %ld\n",
template.visualid);
} else { } else {
Sys_Error("VID: No visuals at depth %d\n", if (num_visuals == 0) {
template.depth); if (template_mask == VisualIDMask) {
Sys_Error ("VID: Bad visual ID %ld\n", template.visualid);
} else {
Sys_Error ("VID: No visuals at depth %d\n", template.depth);
}
} }
} }
if (verbose) { if (verbose) {
printf("Using visualid %d:\n", (int)(x_visinfo->visualid)); printf ("Using visualid %d:\n", (int) x_visinfo->visualid);
printf(" class %d\n", x_visinfo->class); printf (" class %d\n", x_visinfo->class);
printf(" screen %d\n", x_visinfo->screen); printf (" screen %d\n", x_visinfo->screen);
printf(" depth %d\n", x_visinfo->depth); printf (" depth %d\n", x_visinfo->depth);
printf(" red_mask 0x%x\n", (int)(x_visinfo->red_mask)); printf (" red_mask 0x%x\n", (int) x_visinfo->red_mask);
printf(" green_mask 0x%x\n", (int)(x_visinfo->green_mask)); printf (" green_mask 0x%x\n", (int) x_visinfo->green_mask);
printf(" blue_mask 0x%x\n", (int)(x_visinfo->blue_mask)); printf (" blue_mask 0x%x\n", (int) x_visinfo->blue_mask);
printf(" colormap_size %d\n", x_visinfo->colormap_size); printf (" colormap_size %d\n",x_visinfo->colormap_size);
printf(" bits_per_rgb %d\n", x_visinfo->bits_per_rgb); printf (" bits_per_rgb %d\n", x_visinfo->bits_per_rgb);
} }
/* Setup attributes for main window */ /* Setup attributes for main window */
x11_set_vidmode(vid.width, vid.height); x11_set_vidmode (vid.width, vid.height);
/* Create the main window */ /* Create the main window */
x11_create_window(vid.width, vid.height); x11_create_window (vid.width, vid.height);
/* Invisible cursor */ /* Invisible cursor */
x11_create_null_cursor(); x11_create_null_cursor ();
if (x_visinfo->depth == 8) { if (x_visinfo->depth == 8) {
/* Create and upload the palette */ /* Create and upload the palette */
if (x_visinfo->class == PseudoColor) { if (x_visinfo->class == PseudoColor) {
x_cmap = XCreateColormap(x_disp, x_win, x_cmap = XCreateColormap (x_disp, x_win, x_vis, AllocAll);
x_vis, AllocAll); VID_SetPalette (palette);
VID_SetPalette(palette); XSetWindowColormap (x_disp, x_win, x_cmap);
XSetWindowColormap(x_disp, x_win, x_cmap);
} }
} }
@ -562,18 +586,18 @@ void VID_Init (unsigned char *palette)
{ {
XGCValues xgcvalues; XGCValues xgcvalues;
int valuemask = GCGraphicsExposures; int valuemask = GCGraphicsExposures;
xgcvalues.graphics_exposures = False; xgcvalues.graphics_exposures = False;
x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues ); x_gc = XCreateGC (x_disp, x_win, valuemask, &xgcvalues );
} }
x11_grab_keyboard(); x11_grab_keyboard ();
// wait for first exposure event // wait for first exposure event
{ {
XEvent event; XEvent event;
do do {
{ XNextEvent (x_disp, &event);
XNextEvent(x_disp, &event);
if (event.type == Expose && !event.xexpose.count) if (event.type == Expose && !event.xexpose.count)
oktodraw = true; oktodraw = true;
} while (!oktodraw); } while (!oktodraw);
@ -581,29 +605,27 @@ void VID_Init (unsigned char *palette)
// now safe to draw // now safe to draw
// even if MITSHM is available, make sure it's a local connection // even if MITSHM is available, make sure it's a local connection
if (XShmQueryExtension(x_disp)) if (XShmQueryExtension (x_disp)) {
//if (0)
{
char *displayname; char *displayname;
char *d;
doShm = true; doShm = true;
displayname = (char *) getenv("DISPLAY");
if (displayname) if ((displayname = XDisplayName (NULL))) {
{ if ((d = strchr (displayname, ':')))
char *d = displayname; *d = '\0';
while (*d && (*d != ':')) d++;
if (*d) *d = 0;
if (!(!strcasecmp(displayname, "unix") || !*displayname)) if (!(!strcasecmp(displayname, "unix") || !*displayname))
doShm = false; doShm = false;
} }
} }
if (doShm) if (doShm) {
{ x_shmeventtype = XShmGetEventBase (x_disp) + ShmCompletion;
x_shmeventtype = XShmGetEventBase(x_disp) + ShmCompletion; ResetSharedFrameBuffers ();
ResetSharedFrameBuffers(); } else {
ResetFrameBuffer ();
} }
else
ResetFrameBuffer();
current_framebuffer = 0; current_framebuffer = 0;
vid.rowbytes = x_framebuffer[0]->bytes_per_line; vid.rowbytes = x_framebuffer[0]->bytes_per_line;
@ -613,88 +635,94 @@ void VID_Init (unsigned char *palette)
vid.conrowbytes = vid.rowbytes; vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width; vid.conwidth = vid.width;
vid.conheight = vid.height; vid.conheight = vid.height;
vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0); vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
// XSynchronize(x_disp, False); // XSynchronize (x_disp, False);
x11_add_event(x_shmeventtype, event_shm); x11_add_event (x_shmeventtype, event_shm);
} }
void void
VID_Init_Cvars () VID_Init_Cvars ()
{ {
x11_Init_Cvars(); x11_Init_Cvars ();
} }
void void
VID_ShiftPalette(unsigned char *p) VID_ShiftPalette (unsigned char *p)
{ {
VID_SetPalette(p); VID_SetPalette (p);
} }
void void
VID_SetPalette(unsigned char *palette) VID_SetPalette (unsigned char *palette)
{ {
int i; int i;
XColor colors[256]; XColor colors[256];
for (i=0;i<256;i++) { for (i = 0; i < 256; i++) {
st2d_8to16table[i] = xlib_rgb16(palette[i*3], palette[i*3+1], st2d_8to16table[i] = xlib_rgb16 (palette[i*3], palette[i*3+1],
palette[i*3+2]); palette[i*3+2]);
st2d_8to24table[i] = xlib_rgb24(palette[i*3], palette[i*3+1], st2d_8to24table[i] = xlib_rgb24 (palette[i*3], palette[i*3+1],
palette[i*3+2]); palette[i*3+2]);
} }
if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) { if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) {
if (palette != current_palette) { if (palette != current_palette) {
memcpy(current_palette, palette, 768); memcpy (current_palette, palette, 768);
} }
for (i=0 ; i<256 ; i++) { for (i = 0; i < 256; i++) {
colors[i].pixel = i; colors[i].pixel = i;
colors[i].flags = DoRed|DoGreen|DoBlue; colors[i].flags = DoRed|DoGreen|DoBlue;
colors[i].red = vid_gamma[palette[i*3]] * 256; colors[i].red = vid_gamma[palette[i*3]] * 256;
colors[i].green = vid_gamma[palette[i*3+1]] * 256; colors[i].green = vid_gamma[palette[i*3+1]] * 256;
colors[i].blue = vid_gamma[palette[i*3+2]] * 256; colors[i].blue = vid_gamma[palette[i*3+2]] * 256;
} }
XStoreColors(x_disp, x_cmap, colors, 256); XStoreColors (x_disp, x_cmap, colors, 256);
} }
} }
/* /*
Called at shutdown VID_Shutdown
Restore video mode
*/ */
void void
VID_Shutdown(void) VID_Shutdown (void)
{ {
Sys_Printf("VID_Shutdown\n"); Sys_Printf ("VID_Shutdown\n");
if (x_disp) { if (x_disp) {
x11_restore_vidmode(); x11_restore_vidmode ();
x11_close_display(); x11_close_display ();
} }
} }
static int config_notify=0; static int config_notify = 0;
static int config_notify_width; static int config_notify_width;
static int config_notify_height; static int config_notify_height;
/* /*
Flushes the given rectangles from the view buffer to the screen. VID_Update
Flush the given rectangles from the view buffer to the screen.
*/ */
void void
VID_Update(vrect_t *rects) VID_Update (vrect_t *rects)
{ {
/* If the window changes dimension, skip this frame. */ /* If the window changes dimension, skip this frame. */
if (config_notify) { if (config_notify) {
fprintf(stderr, "config notify\n"); fprintf (stderr, "config notify\n");
config_notify = 0; config_notify = 0;
vid.width = config_notify_width & ~7; vid.width = config_notify_width &~ 7;
vid.height = config_notify_height; vid.height = config_notify_height;
if (doShm) if (doShm)
ResetSharedFrameBuffers(); ResetSharedFrameBuffers ();
else else
ResetFrameBuffer(); ResetFrameBuffer ();
vid.rowbytes = x_framebuffer[0]->bytes_per_line; vid.rowbytes = x_framebuffer[0]->bytes_per_line;
vid.buffer = x_framebuffer[current_framebuffer]->data; vid.buffer = x_framebuffer[current_framebuffer]->data;
vid.conbuffer = vid.buffer; vid.conbuffer = vid.buffer;
@ -702,65 +730,59 @@ VID_Update(vrect_t *rects)
vid.conheight = vid.height; vid.conheight = vid.height;
vid.conrowbytes = vid.rowbytes; vid.conrowbytes = vid.rowbytes;
vid.recalc_refdef = 1; /* force a surface cache flush */ vid.recalc_refdef = 1; /* force a surface cache flush */
Con_CheckResize(); Con_CheckResize ();
Con_Clear_f(); Con_Clear_f ();
return; return;
} }
if (doShm) {
while (rects) { while (rects) {
if (x_visinfo->depth == 16) { switch (x_visinfo->depth) {
st2_fixup(x_framebuffer[current_framebuffer], case 16:
st2_fixup (x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width, rects->x, rects->y, rects->width,
rects->height); rects->height);
} else if (x_visinfo->depth == 24) { break;
st3_fixup(x_framebuffer[current_framebuffer], case 24:
st3_fixup (x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width, rects->x, rects->y, rects->width,
rects->height); rects->height);
break;
} }
if (!XShmPutImage(x_disp, x_win, x_gc, if (doShm) {
if (!XShmPutImage (x_disp, x_win, x_gc,
x_framebuffer[current_framebuffer], x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->x, rects->y, rects->x, rects->y,
rects->x, rects->y,
rects->width, rects->height, True)) { rects->width, rects->height, True)) {
Sys_Error("VID_Update: XShmPutImage failed\n"); Sys_Error ("VID_Update: XShmPutImage failed\n");
} }
oktodraw = false; oktodraw = false;
while (!oktodraw) x11_process_event(); while (!oktodraw)
x11_process_event ();
rects = rects->pnext; rects = rects->pnext;
}
current_framebuffer = !current_framebuffer; current_framebuffer = !current_framebuffer;
vid.buffer = x_framebuffer[current_framebuffer]->data; vid.buffer = x_framebuffer[current_framebuffer]->data;
vid.conbuffer = vid.buffer; vid.conbuffer = vid.buffer;
XSync(x_disp, False);
} else { } else {
while (rects) { if (!XPutImage (x_disp, x_win, x_gc, x_framebuffer[0],
if (x_visinfo->depth == 16) {
st2_fixup(x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width,
rects->height);
} else if (x_visinfo->depth == 24) {
st3_fixup(x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width,
rects->height);
}
XPutImage(x_disp, x_win, x_gc, x_framebuffer[0],
rects->x, rects->y, rects->x, rects->y, rects->x, rects->y, rects->x, rects->y,
rects->width, rects->height); rects->width, rects->height)) {
Sys_Error ("VID_Update: XPutImage failed\n");
}
rects = rects->pnext; rects = rects->pnext;
} }
XSync(x_disp, False);
} }
XSync (x_disp, False);
} }
static int dither; static qboolean dither;
void void
VID_DitherOn( void ) VID_DitherOn (void)
{ {
if (dither == 0) { if (!dither) {
vid.recalc_refdef = 1; vid.recalc_refdef = 1;
dither = 1; dither = true;
} }
} }
@ -770,17 +792,17 @@ VID_DitherOff (void)
{ {
if (dither) { if (dither) {
vid.recalc_refdef = 1; vid.recalc_refdef = 1;
dither = 0; dither = false;
} }
} }
void void
VID_LockBuffer ( void ) VID_LockBuffer (void)
{ {
} }
void void
VID_UnlockBuffer ( void ) VID_UnlockBuffer (void)
{ {
} }