2001-04-15 04:18:22 +00:00
|
|
|
/*
|
|
|
|
vid_fbdev.c
|
|
|
|
|
|
|
|
Linux FBDev video routines
|
|
|
|
|
|
|
|
based on vid_svgalib.c
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se]
|
|
|
|
Copyright (C) 1999-2000 David Symonds [xoxus@usa.net]
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include "string.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include "strings.h"
|
|
|
|
#endif
|
2001-04-15 04:18:22 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_IO_H
|
|
|
|
# include <sys/io.h>
|
|
|
|
#elif defined(HAVE_ASM_IO_H)
|
|
|
|
# include <asm/io.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#include <errno.h>
|
2001-04-15 04:18:22 +00:00
|
|
|
#include <fcntl.h>
|
2001-08-25 02:47:11 +00:00
|
|
|
#include <math.h>
|
2001-04-15 04:18:22 +00:00
|
|
|
#include <signal.h>
|
2001-08-25 02:47:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-04-15 04:18:22 +00:00
|
|
|
#include <linux/kd.h>
|
|
|
|
#include <linux/vt.h>
|
2001-08-25 02:47:11 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "d_iface.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "fbset.h"
|
2012-02-17 07:13:56 +00:00
|
|
|
#include "vid_internal.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2008-07-19 05:40:57 +00:00
|
|
|
#ifndef PAGE_SIZE
|
|
|
|
# define PAGE_SIZE (sysconf(_SC_PAGESIZE))
|
|
|
|
# define PAGE_MASK (~(PAGE_SIZE-1))
|
|
|
|
#endif
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
static struct VideoMode current_mode;
|
|
|
|
static char current_name[32];
|
|
|
|
static int num_modes;
|
|
|
|
|
|
|
|
static int fb_fd = -1;
|
|
|
|
static int tty_fd = 0;
|
|
|
|
|
|
|
|
static byte vid_current_palette[768];
|
|
|
|
|
|
|
|
static int fbdev_inited = 0;
|
|
|
|
static int fbdev_backgrounded = 0;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static int vid_redrawfull;
|
|
|
|
static cvar_t vid_redrawfull_cvar = {
|
|
|
|
.name = "vid_redrawfull",
|
|
|
|
.description =
|
|
|
|
"Redraw entire screen each frame instead of just dirty areas",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &vid_redrawfull },
|
|
|
|
};
|
|
|
|
static int vid_waitforrefresh;
|
|
|
|
static cvar_t vid_waitforrefresh_cvar = {
|
|
|
|
.name = "vid_waitforrefresh",
|
|
|
|
.description =
|
|
|
|
"Wait for vertical retrace before drawing next frame",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &vid_waitforrefresh },
|
|
|
|
};
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2005-06-08 06:35:48 +00:00
|
|
|
static byte *framebuffer_ptr;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
static byte backingbuf[48 * 24];
|
|
|
|
|
|
|
|
void
|
|
|
|
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
|
|
|
|
{
|
|
|
|
int i, j, reps, repshift, offset, off;
|
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
if (!fbdev_inited || !viddef.direct || fbdev_backgrounded)
|
2001-04-15 04:18:22 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
if (viddef.aspect > 1.5) {
|
2001-04-15 04:18:22 +00:00
|
|
|
reps = 2;
|
|
|
|
repshift = 1;
|
|
|
|
} else {
|
|
|
|
reps = 1;
|
|
|
|
repshift = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < (height << repshift); i += reps) {
|
|
|
|
for (j = 0; j < reps; j++) {
|
|
|
|
offset = x + ((y << repshift) + i + j)
|
2012-02-14 10:47:02 +00:00
|
|
|
* viddef.rowbytes;
|
2001-04-15 04:18:22 +00:00
|
|
|
off = offset % 0x10000;
|
2012-02-14 10:47:02 +00:00
|
|
|
memcpy (&backingbuf[(i + j) * 24], viddef.direct + off, width);
|
|
|
|
memcpy (viddef.direct + off,
|
2001-04-15 04:18:22 +00:00
|
|
|
&pbitmap[(i >> repshift) * width], width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
D_EndDirectRect (int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
int i, j, reps, repshift, offset, off;
|
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
if (!fbdev_inited || !viddef.direct || fbdev_backgrounded)
|
2001-04-15 04:18:22 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
if (viddef.aspect > 1.5) {
|
2001-04-15 04:18:22 +00:00
|
|
|
reps = 2;
|
|
|
|
repshift = 1;
|
|
|
|
} else {
|
|
|
|
reps = 1;
|
|
|
|
repshift = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < (height << repshift); i += reps) {
|
|
|
|
for (j = 0; j < reps; j++) {
|
|
|
|
offset = x + ((y << repshift) + i + j)
|
2012-02-14 10:47:02 +00:00
|
|
|
* viddef.rowbytes;
|
2001-04-15 04:18:22 +00:00
|
|
|
off = offset % 0x10000;
|
2012-02-14 10:47:02 +00:00
|
|
|
memcpy (viddef.direct + off, &backingbuf[(i + j) * 24], width);
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
VID_NumModes (void)
|
|
|
|
{
|
|
|
|
struct VideoMode *vmode;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (vmode = VideoModes; vmode; vmode = vmode->next)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VID_fbset_f (void)
|
|
|
|
{
|
|
|
|
int i, argc;
|
2001-07-19 21:46:34 +00:00
|
|
|
const char *argv[32];
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
argc = Cmd_Argc();
|
|
|
|
if (argc > 32)
|
|
|
|
argc = 32;
|
|
|
|
argv[0] = "vid_fbset";
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
argv[i] = Cmd_Argv(i);
|
|
|
|
}
|
|
|
|
fbset_main(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VID_InitModes (void)
|
|
|
|
{
|
|
|
|
ReadModeDB();
|
|
|
|
num_modes = VID_NumModes();
|
|
|
|
}
|
|
|
|
|
2001-11-20 03:40:57 +00:00
|
|
|
static const char *
|
2003-04-17 00:01:48 +00:00
|
|
|
get_mode (unsigned int width, unsigned int height, unsigned int depth)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
struct VideoMode *vmode;
|
|
|
|
|
|
|
|
for (vmode = VideoModes; vmode; vmode = vmode->next) {
|
2002-12-16 19:36:46 +00:00
|
|
|
if (vmode->xres == width
|
|
|
|
&& vmode->yres == height
|
|
|
|
&& vmode->depth == depth)
|
|
|
|
return vmode->name;
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Printf ("Mode %dx%d (%d bits) not supported\n",
|
2007-11-06 10:39:49 +00:00
|
|
|
width, height, depth);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
return "640x480-60";
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char *fb_map_addr = 0;
|
|
|
|
static unsigned long fb_map_length = 0;
|
|
|
|
|
|
|
|
static struct fb_var_screeninfo orig_var;
|
|
|
|
|
2019-07-12 14:15:26 +00:00
|
|
|
static void
|
|
|
|
VID_shutdown (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "VID_Shutdown\n");
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if (!fbdev_inited)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (munmap(fb_map_addr, fb_map_length) == -1) {
|
|
|
|
Sys_Printf("could not unmap framebuffer at %p: %s\n",
|
|
|
|
fb_map_addr, strerror(errno));
|
|
|
|
} else {
|
|
|
|
if (ioctl(fb_fd, FBIOPUT_VSCREENINFO, &orig_var))
|
|
|
|
Sys_Printf ("failed to get var screen info\n");
|
|
|
|
}
|
|
|
|
close(fb_fd);
|
|
|
|
|
2002-12-16 19:36:46 +00:00
|
|
|
ioctl(tty_fd, KDSETMODE, KD_TEXT);
|
2007-01-06 21:31:03 +00:00
|
|
|
if (write(tty_fd, "\033]R", 3) != 3) /* reset palette */
|
|
|
|
Sys_Printf("could not reset palette: %s\n", strerror(errno));
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
fbdev_inited = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
loadpalette (unsigned short *red, unsigned short *green, unsigned short *blue)
|
|
|
|
{
|
|
|
|
struct fb_cmap cmap;
|
|
|
|
|
|
|
|
cmap.len = 256;
|
|
|
|
cmap.red = red;
|
|
|
|
cmap.green = green;
|
|
|
|
cmap.blue = blue;
|
|
|
|
cmap.transp = NULL;
|
|
|
|
cmap.start = 0;
|
|
|
|
if (-1 == ioctl(fb_fd, FBIOPUTCMAP, (void *)&cmap))
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error("ioctl FBIOPUTCMAP %s", strerror(errno));
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2001-07-19 21:46:34 +00:00
|
|
|
VID_SetMode (const char *name, unsigned char *palette)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
struct VideoMode *vmode;
|
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
struct fb_fix_screeninfo fix;
|
|
|
|
int err;
|
2011-06-19 01:48:02 +00:00
|
|
|
//unsigned long smem_start;
|
|
|
|
unsigned long smem_offset;
|
2009-12-20 05:41:08 +00:00
|
|
|
long pagesize, pagemask;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
pagesize = sysconf(_SC_PAGESIZE);
|
|
|
|
if (errno) {
|
|
|
|
Con_Printf("Cannot get page size: %s\n", strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pagemask = ~(pagesize-1);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
vmode = FindVideoMode(name);
|
|
|
|
if (!vmode) {
|
2007-11-06 10:17:14 +00:00
|
|
|
// Sys_Printf ("No such video mode: %s\n", name);
|
2001-04-15 04:18:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_mode = *vmode;
|
|
|
|
strncpy(current_name, current_mode.name, sizeof(current_name)-1);
|
|
|
|
current_name[31] = 0;
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.width = vmode->xres;
|
|
|
|
viddef.height = vmode->yres;
|
|
|
|
viddef.rowbytes = vmode->xres * (vmode->depth >> 3);
|
|
|
|
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
|
|
|
|
viddef.conrowbytes = viddef.rowbytes;
|
|
|
|
viddef.numpages = 1;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
if (fb_map_addr) {
|
|
|
|
if (munmap(fb_map_addr, fb_map_length) == -1) {
|
|
|
|
Sys_Printf("could not unmap framebuffer at %p: %s\n",
|
|
|
|
fb_map_addr, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConvertFromVideoMode(¤t_mode, &var);
|
|
|
|
err = ioctl(fb_fd, FBIOPUT_VSCREENINFO, &var);
|
|
|
|
if (err)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Video mode failed: %s", name);
|
2001-04-15 04:18:22 +00:00
|
|
|
ConvertToVideoMode(&var, ¤t_mode);
|
|
|
|
current_mode.name = current_name;
|
2012-04-12 04:57:05 +00:00
|
|
|
viddef.set_palette (palette);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
err = ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix);
|
|
|
|
if (err)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Video mode failed: %s", name);
|
2011-06-19 01:48:02 +00:00
|
|
|
//smem_start = (unsigned long)fix.smem_start & pagemask;
|
2009-12-20 05:41:08 +00:00
|
|
|
smem_offset = (unsigned long)fix.smem_start & ~pagemask;
|
|
|
|
fb_map_length = (smem_offset+fix.smem_len+~pagemask) & pagemask;
|
2005-06-08 06:35:48 +00:00
|
|
|
fb_map_addr = mmap(0, fb_map_length, PROT_WRITE, MAP_SHARED,
|
2001-08-25 02:47:11 +00:00
|
|
|
fb_fd, 0);
|
2001-04-15 04:18:22 +00:00
|
|
|
if (!fb_map_addr)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("This mode isn't hapnin'");
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.direct = framebuffer_ptr = fb_map_addr;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
// alloc screen buffer, z-buffer, and surface cache
|
|
|
|
VID_InitBuffers ();
|
|
|
|
|
|
|
|
if (!fbdev_inited) {
|
|
|
|
fbdev_inited = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force a surface cache flush */
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.recalc_refdef = 1;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fb_switch_handler (int sig)
|
|
|
|
{
|
|
|
|
if (sig == SIGUSR1) {
|
|
|
|
fbdev_backgrounded = 1;
|
|
|
|
} else if (sig == SIGUSR2) {
|
|
|
|
fbdev_backgrounded = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fb_switch_release (void)
|
|
|
|
{
|
|
|
|
ioctl(tty_fd, VT_RELDISP, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fb_switch_acquire (void)
|
|
|
|
{
|
|
|
|
ioctl(tty_fd, VT_RELDISP, VT_ACKACQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fb_switch_init (void)
|
|
|
|
{
|
|
|
|
struct sigaction act;
|
|
|
|
struct vt_mode vtmode;
|
|
|
|
|
|
|
|
memset(&act, 0, sizeof(act));
|
|
|
|
act.sa_handler = fb_switch_handler;
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
sigaction(SIGUSR1, &act, 0);
|
|
|
|
sigaction(SIGUSR2, &act, 0);
|
|
|
|
|
|
|
|
if (ioctl(tty_fd, VT_GETMODE, &vtmode)) {
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error("ioctl VT_GETMODE: %s", strerror(errno));
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
vtmode.mode = VT_PROCESS;
|
|
|
|
vtmode.waitv = 0;
|
|
|
|
vtmode.relsig = SIGUSR1;
|
|
|
|
vtmode.acqsig = SIGUSR2;
|
|
|
|
if (ioctl(tty_fd, VT_SETMODE, &vtmode)) {
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error("ioctl VT_SETMODE: %s", strerror(errno));
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 04:57:05 +00:00
|
|
|
static void
|
|
|
|
VID_SetPalette (const byte *palette)
|
|
|
|
{
|
|
|
|
static unsigned short tmppalr[256], tmppalg[256], tmppalb[256];
|
|
|
|
unsigned short i, *tpr, *tpg, *tpb;
|
|
|
|
|
|
|
|
if (!fbdev_inited || fbdev_backgrounded || fb_fd < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy (vid_current_palette, palette, sizeof (vid_current_palette));
|
|
|
|
|
|
|
|
if (current_mode.depth == 8) {
|
|
|
|
tpr = tmppalr;
|
|
|
|
tpg = tmppalg;
|
|
|
|
tpb = tmppalb;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
*tpr++ = (*palette++) << 8;
|
|
|
|
*tpg++ = (*palette++) << 8;
|
|
|
|
*tpb++ = (*palette++) << 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadpalette(tmppalr, tmppalg, tmppalb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
void
|
2012-02-01 10:52:13 +00:00
|
|
|
VID_Init (byte *palette, byte *colormap)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
struct VideoMode *vmode;
|
2001-07-19 21:46:34 +00:00
|
|
|
const char *modestr;
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *fbname;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
// plugin_load("in_fbdev.so");
|
|
|
|
|
|
|
|
if (fbdev_inited)
|
|
|
|
return;
|
|
|
|
|
2019-07-12 14:15:26 +00:00
|
|
|
Sys_RegisterShutdown (VID_shutdown);
|
|
|
|
|
2013-01-16 02:23:47 +00:00
|
|
|
R_LoadModule (0, VID_SetPalette);
|
2012-04-12 04:57:05 +00:00
|
|
|
|
2004-04-13 02:13:35 +00:00
|
|
|
if (COM_CheckParm ("-novideo")) {
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.width = 320;
|
|
|
|
viddef.height = 200;
|
|
|
|
viddef.rowbytes = 320;
|
|
|
|
viddef.aspect = ((float) viddef.height
|
|
|
|
/ (float) viddef.width) * (4.0 / 3.0);
|
2012-02-17 07:13:56 +00:00
|
|
|
viddef.colormap8 = colormap;
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
|
|
|
|
viddef.conrowbytes = viddef.rowbytes;
|
|
|
|
viddef.conwidth = viddef.width;
|
|
|
|
viddef.conheight = viddef.height;
|
|
|
|
viddef.numpages = 1;
|
|
|
|
viddef.basepal = palette;
|
2004-04-13 02:13:35 +00:00
|
|
|
Con_CheckResize (); // Now that we have a window size, fix console
|
|
|
|
VID_InitBuffers ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-16 19:36:46 +00:00
|
|
|
fbname = getenv("FRAMEBUFFER");
|
|
|
|
if (!fbname)
|
|
|
|
fbname = "/dev/fb0";
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-12-16 19:36:46 +00:00
|
|
|
fb_fd = open(fbname, O_RDWR);
|
|
|
|
if (fb_fd < 0)
|
|
|
|
Sys_Error ("failed to open fb device");
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-12-16 19:36:46 +00:00
|
|
|
if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &orig_var))
|
|
|
|
Sys_Error ("failed to get var screen info");
|
2001-05-25 04:03:47 +00:00
|
|
|
|
2002-12-16 19:36:46 +00:00
|
|
|
fb_switch_init();
|
|
|
|
|
|
|
|
VID_InitModes ();
|
|
|
|
|
|
|
|
Cmd_AddCommand ("vid_fbset", VID_fbset_f, "No Description");
|
|
|
|
|
|
|
|
/* Interpret command-line params */
|
2013-01-24 06:43:04 +00:00
|
|
|
VID_GetWindowSize (640, 480);
|
2002-12-16 19:36:46 +00:00
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
modestr = get_mode (viddef.width, viddef.height, 8);
|
2002-12-16 19:36:46 +00:00
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
/* Set viddef parameters */
|
2002-12-16 19:36:46 +00:00
|
|
|
vmode = FindVideoMode(modestr);
|
|
|
|
if (!vmode)
|
|
|
|
Sys_Error("no video mode %s", modestr);
|
|
|
|
current_mode = *vmode;
|
|
|
|
ioctl(tty_fd, KDSETMODE, KD_GRAPHICS);
|
|
|
|
VID_SetMode (current_mode.name, palette);
|
|
|
|
|
|
|
|
VID_InitGamma (palette);
|
2012-04-12 04:57:05 +00:00
|
|
|
viddef.set_palette (viddef.palette);
|
2002-12-16 19:36:46 +00:00
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.initialized = true;
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Init_Cvars ()
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&vid_redrawfull_cvar, 0, 0);
|
|
|
|
Cvar_Register (&vid_waitforrefresh_cvar, 0, 0);
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Update (vrect_t *rects)
|
|
|
|
{
|
|
|
|
if (!fbdev_inited)
|
|
|
|
return;
|
|
|
|
if (fbdev_backgrounded) {
|
|
|
|
if (fbdev_backgrounded == 3) {
|
|
|
|
return;
|
|
|
|
} else if (fbdev_backgrounded == 2) {
|
|
|
|
fb_switch_acquire();
|
|
|
|
fbdev_backgrounded = 0;
|
2012-04-12 04:57:05 +00:00
|
|
|
viddef.set_palette (vid_current_palette);
|
2001-04-15 04:18:22 +00:00
|
|
|
} else if (fbdev_backgrounded == 1) {
|
|
|
|
fb_switch_release();
|
|
|
|
fbdev_backgrounded = 3;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (vid_waitforrefresh) {
|
2001-04-15 04:18:22 +00:00
|
|
|
// ???
|
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (vid_redrawfull) {
|
2012-02-14 10:47:02 +00:00
|
|
|
double *d = (double *)framebuffer_ptr, *s = (double *)viddef.buffer;
|
|
|
|
double *ends = (double *)(viddef.buffer
|
|
|
|
+ viddef.height*viddef.rowbytes);
|
2001-04-15 04:18:22 +00:00
|
|
|
while (s < ends)
|
|
|
|
*d++ = *s++;
|
|
|
|
} else {
|
|
|
|
while (rects) {
|
|
|
|
int height, width, lineskip, i, j, xoff, yoff;
|
|
|
|
double *d, *s;
|
|
|
|
|
|
|
|
height = rects->height;
|
|
|
|
width = rects->width / sizeof(double);
|
|
|
|
xoff = rects->x;
|
|
|
|
yoff = rects->y;
|
2012-02-14 10:47:02 +00:00
|
|
|
lineskip = (viddef.width - (xoff + rects->width)) / sizeof(double);
|
|
|
|
d = (double *)(framebuffer_ptr + yoff * viddef.rowbytes + xoff);
|
|
|
|
s = (double *)(viddef.buffer + yoff * viddef.rowbytes + xoff);
|
2001-04-15 04:18:22 +00:00
|
|
|
for (i = yoff; i < height; i++) {
|
|
|
|
for (j = xoff; j < width; j++)
|
|
|
|
*d++ = *s++;
|
|
|
|
d += lineskip;
|
|
|
|
s += lineskip;
|
|
|
|
}
|
2012-01-06 00:52:14 +00:00
|
|
|
rects = rects->next;
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
VID_SetCaption (const char *text)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-06-13 09:06:11 +00:00
|
|
|
bool
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_SetGamma (double gamma)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|