-
Notifications
You must be signed in to change notification settings - Fork 919
/
Copy pathvid_sunxil.c
1288 lines (1024 loc) · 29.3 KB
/
vid_sunxil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
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_sunxil.c -- uses X to setup windows and XIL to copy images (scaled as needed)
// to screen
#define _BSD
#define BYTE_DEFINED 1
#include <sys/time.h>
#include <sys/types.h>
#include <errno.h>
#include <thread.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 <xil/xil.h>
#include "quakedef.h"
#include "d_local.h"
#define MIN_WIDTH 320
#define MIN_HEIGHT 200
cvar_t _windowed_mouse = {"_windowed_mouse","0", true};
cvar_t m_filter = {"m_filter","0", true};
float old_windowed_mouse;
// 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;
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;
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 \
( \
StructureNotifyMask | \
KeyPressMask | \
KeyReleaseMask | \
ButtonPressMask | \
ButtonReleaseMask | \
ExposureMask | \
PointerMotionMask | \
FocusChangeMask \
)
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar;
byte *VGA_pagebase;
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 x_focus = true;
int global_dx, global_dy;
static Colormap x_cmap;
static GC x_gc;
static Visual *x_vis;
static XVisualInfo *x_visinfo;
static Atom aHints = NULL;
static Atom aWMDelete = NULL;
static qboolean oktodraw = false;
static qboolean X11_active = false;
static int verbose=1;
static byte current_palette[768];
cvar_t pixel_multiply = {"pixel_multiply", "2", true};
int current_pixel_multiply = 2;
#define PM(a) (int)((current_pixel_multiply)?((a)*current_pixel_multiply):(a))
#define MP(a) (int)((current_pixel_multiply)?((a)/current_pixel_multiply):(a))
static int render_pipeline[2];
static XilSystemState state;
static XilImage display_image = NULL;
static XilImage quake_image = NULL;
static int use_mt = 0;
static int count_frames = 0;
/*
================
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 isnt 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
}
}
qboolean CheckPixelMultiply (void)
{
int m;
int w, h;
XWindowAttributes wattr;
XWindowChanges chg;
unsigned int value_mask;
int old_pixel;
if ((m = (int)pixel_multiply.value) != current_pixel_multiply) {
if (m < 1)
m = 1;
if (m > 4)
m = 4;
old_pixel = current_pixel_multiply;
current_pixel_multiply = m;
Cvar_SetValue("pixel_multiply", m);
if(XGetWindowAttributes(x_disp, x_win, & wattr) == 0)
return true; // ???
memset(&chg, 0, sizeof(chg));
chg.width = wattr.width/old_pixel * current_pixel_multiply;
chg.height = wattr.height/old_pixel * current_pixel_multiply;
if (chg.width < MIN_WIDTH*current_pixel_multiply)
chg.width = MIN_WIDTH*current_pixel_multiply;
if (chg.height < MIN_HEIGHT*current_pixel_multiply)
chg.height = MIN_HEIGHT*current_pixel_multiply;
XConfigureWindow(x_disp, x_win, CWWidth | CWHeight, &chg);
vid.width = MP(wattr.width) & ~3;
vid.height = MP(wattr.height);
if (vid.width < 320)
vid.width = 320;
if (vid.height < 200)
vid.height = 200;
VID_ResetFramebuffer();
return true;
}
return false;
}
// ========================================================================
// Tragic death handler
// ========================================================================
void TragicDeath(int signal_num)
{
//XAutoRepeatOn(x_disp);
XCloseDisplay(x_disp);
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 VID_MenuDraw( void )
{
qpic_t *p;
char *ptr;
int i, j, column, row, dup;
char temp[100];
p = Draw_CachePic ("gfx/vidmodes.lmp");
M_DrawPic ( (320-p->width)/2, 4, p);
M_Print (4*8, 36 + MAX_COLUMN_SIZE * 8 + 8, "Video mode switching unavailable");
M_Print (9*8, 36 + MAX_COLUMN_SIZE * 8 + 8*6, "Press any key...");
}
void VID_MenuKey( int key ) { M_Menu_Options_f (); }
// 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
byte surfcache[1024*1024];
//
// VID_SetWindowTitle - set the window and icon titles
//
void VID_SetWindowTitle( Window win, char *pszName )
{
XTextProperty textprop;
XWMHints *wmHints;
// Setup ICCCM properties
textprop.value = (unsigned char *)pszName;
textprop.encoding = XA_STRING;
textprop.format = 8;
textprop.nitems = strlen(pszName);
wmHints = XAllocWMHints();
wmHints->initial_state = NormalState;
wmHints->flags = StateHint;
XSetWMProperties( x_disp, win, &textprop, &textprop,
// Only put WM_COMMAND property on first window.
com_argv, com_argc, NULL, NULL, NULL );
XFree( wmHints );
aWMDelete = XInternAtom( x_disp, "WM_DELETE_WINDOW", False );
XSetWMProtocols( x_disp, win, &aWMDelete, 1 );
}
//
// VID_FullScreen - open the window in full screen mode
//
qboolean VID_FullScreen( Window win )
{
MotifWmHints hints;
XWindowChanges changes;
aHints = XInternAtom( x_disp, "_MOTIF_WM_HINTS", 0 );
if (aHints == None) {
Con_Printf( "Could not intern X atom for _MOTIF_WM_HINTS." );
return( false );
}
hints.flags = MWM_HINTS_DECORATIONS;
hints.decorations = 0; // Absolutely no decorations.
XChangeProperty( x_disp, win, aHints, aHints, 32, PropModeReplace, (unsigned char *)&hints, 4 );
changes.x = 0;
changes.y = 0;
changes.width = x_screen_width;
changes.height = x_screen_height;
changes.stack_mode = TopIf;
XConfigureWindow( x_disp, win, CWX | CWY | CWWidth | CWHeight | CWStackMode, &changes);
return( true );
}
void VID_Init (unsigned char *palette)
{
int pnum, i;
XVisualInfo template;
int num_visuals;
int template_mask;
int w, h;
int desired_width=320, desired_height=200;
Cmd_AddCommand ("gamma", VID_Gamma_f);
Cvar_RegisterVariable (&pixel_multiply);
if (pipe(render_pipeline) < 0)
Sys_Error("VID_Init: pipe");
for (i=0 ; i<256 ; i++)
vid_gamma[i] = i;
vid.width = 320;
vid.height = 200;
vid.aspect = 1.0;
vid.numpages = 2;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
//vid.cbits = VID_CBITS;
//vid.grades = VID_GRADES;
srandom(getpid());
verbose = COM_CheckParm("-verbose");
count_frames = COM_CheckParm("-count_frames");
//
// open the display
//
x_disp = XOpenDisplay(0);
if (!x_disp) {
if (getenv("DISPLAY"))
Sys_Error("VID: Could not open display [%s]\n",
getenv("DISPLAY"));
else
Sys_Error("VID: Could not open local display\n");
}
x_screen = DefaultScreen( x_disp );
x_screen_width = WidthOfScreen( ScreenOfDisplay( x_disp, x_screen ) );
x_screen_height = HeightOfScreen( ScreenOfDisplay( x_disp, x_screen ) );
x_center_width = x_screen_width/2;
x_center_height = x_screen_height/2;
Con_Printf( "Using screen %d: %dx%d\n", x_screen, x_screen_width, x_screen_height );
x_root_win = DefaultRootWindow( x_disp);
//XAutoRepeatOff(x_disp);
// for debugging only
if (verbose)
XSynchronize(x_disp, True);
//
// check for command-line window size
//
if ((pnum=COM_CheckParm("-winsize"))) {
if (pnum >= com_argc-2)
Sys_Error("VID: -winsize <width> <height>\n");
desired_width = Q_atoi(com_argv[pnum+1]);
desired_height = Q_atoi(com_argv[pnum+2]);
if (desired_width < 1 || desired_height < 1)
Sys_Error("VID: Bad window width/height\n");
}
template_mask = VisualScreenMask; // make sure we get the right one
template.screen = x_screen;
//
// specify a visual id
//
if ((pnum=COM_CheckParm("-visualid"))) {
if (pnum >= com_argc-1)
Sys_Error("VID: -visualid <id#>\n");
template.visualid = Q_atoi(com_argv[pnum+1]);
template_mask |= VisualIDMask;
} else {
// If not specified, find an 8 bit visual since others don't work
// template.depth = 8;
// template_mask |= VisualDepthMask;
int screen;
screen = XDefaultScreen(x_disp);
template.visualid =
XVisualIDFromVisual(XDefaultVisual(x_disp, screen));
template_mask = VisualIDMask;
}
//
// pick a visual- warn if more than one was available
//
x_visinfo = XGetVisualInfo(x_disp, template_mask, &template, &num_visuals);
if (num_visuals > 1) {
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));
}
else if (num_visuals == 0) {
if (template_mask == VisualIDMask)
Sys_Error("VID: Bad visual id %d\n", template.visualid);
else
Sys_Error("VID: No visuals at depth %d\n", template.depth);
}
if (verbose) {
printf("Using visualid %d:\n", (int)(x_visinfo->visualid));
printf(" screen %d\n", x_visinfo->screen);
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);
}
x_vis = x_visinfo->visual;
//
// See if we're going to do pixel multiply
//
if (pixel_multiply.value < 1 || pixel_multiply.value > 4)
Cvar_SetValue("pixel_multiply", 2);
current_pixel_multiply = pixel_multiply.value;
w = 320*current_pixel_multiply; // minimum width
h = 200*current_pixel_multiply; // minimum height
if (desired_width < w)
desired_width = w;
if (desired_height < h)
desired_height = h;
vid.width = MP(desired_width);
vid.height = MP(desired_height);
//
// patch things up so game doesn't fail if window is too small
//
if (vid.width < 320)
vid.width = 320;
if (vid.height < 200)
vid.height = 200;
//
// see if we're going to use threads
//
if(((sysconf(_SC_NPROCESSORS_ONLN) > 1) || COM_CheckParm("-mt")) &&
(COM_CheckParm("-no_mt") == 0)) {
use_mt = 1;
printf("VID: Using multiple threads!\n");
}
// setup attributes for main window
{
int attribmask = CWEventMask | CWColormap | CWBorderPixel;
XSetWindowAttributes attribs;
Colormap tmpcmap;
tmpcmap = XCreateColormap(x_disp, XRootWindow(x_disp,
x_visinfo->screen), x_vis, AllocNone);
attribs.event_mask = x_std_event_mask;
attribs.border_pixel = 0;
attribs.colormap = tmpcmap;
// create the main window
x_win = XCreateWindow( x_disp,
XRootWindow(x_disp, x_visinfo->screen),
0, 0, // x, y
desired_width, desired_height,
0, // borderwidth
x_visinfo->depth,
InputOutput,
x_vis,
attribmask,
&attribs );
if (x_visinfo->class != TrueColor)
XFreeColormap(x_disp, tmpcmap);
}
if (x_visinfo->depth == 8) {
// create and upload the palette
if (x_visinfo->class == PseudoColor) {
x_cmap = XCreateColormap(x_disp, x_win, x_vis, AllocAll);
VID_SetPalette(palette);
XSetWindowColormap(x_disp, x_win, x_cmap);
}
}
VID_SetWindowTitle( x_win, "Quake" );
// inviso cursor
XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win));
// create the GC
{
XGCValues xgcvalues;
int valuemask = GCGraphicsExposures;
xgcvalues.graphics_exposures = False;
x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues );
}
// map the window
XMapWindow(x_disp, x_win);
XSync(x_disp, True) ; /* wait for map */
//
// wait for first exposure event
//
{
XEvent event;
do{
XNextEvent(x_disp, &event);
if (event.type == Expose && !event.xexpose.count)
oktodraw = true;
} while (!oktodraw);
}
//
// initialize XIL
//
state = xil_open();
if(state == NULL) {
//
// XIL's default error handler will print an error msg on stderr
//
Sys_Error("xil_open failed\n");
}
X11_active = true;
VID_ResetFramebuffer();
D_InitCaches (surfcache, sizeof(surfcache));
vid_menudrawfn = VID_MenuDraw;
vid_menukeyfn = VID_MenuKey;
}
VID_ResetFramebuffer()
{
XilMemoryStorage storage;
if (use_mt) {
VID_ResetFramebuffer_MT();
return;
}
//printf("VID_ResetFramebuffer: vid.width %d, vid.height %d\n", vid.width, vid.height);
xil_destroy(display_image);
xil_destroy(quake_image);
display_image = xil_create_from_window(state, x_disp, x_win);
quake_image = xil_create(state, vid.width, vid.height, 1, XIL_BYTE);
xil_export(quake_image);
if (xil_get_memory_storage(quake_image, &storage) == FALSE)
Sys_Error("xil_get_memory_storage");
xil_import(quake_image, TRUE);
xil_export(quake_image);
if (xil_get_memory_storage(quake_image, &storage) == FALSE)
Sys_Error("xil_get_memory_storage");
vid.rowbytes = storage.byte.scanline_stride;
vid.buffer = storage.byte.data;
vid.conbuffer = vid.buffer;
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.recalc_refdef = 1; // force a surface cache flush
free(d_pzbuffer);
d_pzbuffer = malloc(PM(vid.width)*PM(vid.height)*sizeof(*d_pzbuffer));
//Hunk_HighAllocName(PM(vid.width)*PM(vid.height)*sizeof(*d_pzbuffer),"zbuff");
}
VID_ResetFramebuffer_MT()
{
XilMemoryStorage storage;
XilImage drain_renderpipeline();
XilImage old_display_image;
void * update_thread();
printf("VID_ResetFramebuffer: vid.width %d, vid.height %d\n", vid.width, vid.height);
old_display_image = display_image;
display_image = xil_create_from_window(state, x_disp, x_win);
if (quake_image == NULL)
if (thr_create(NULL, NULL, update_thread, NULL, THR_NEW_LWP, NULL) != 0)
Sys_Error("VID: thr_create");
quake_image = drain_renderpipeline(quake_image);
xil_destroy(old_display_image);
free(d_pzbuffer);
d_pzbuffer = malloc(PM(vid.width)*PM(vid.height)*sizeof(*d_pzbuffer));
}
void VID_ShiftPalette(unsigned char *p)
{
VID_SetPalette(p);
}
void VID_SetPalette(unsigned char *palette)
{
int i;
XColor colors[256];
if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) {
if (palette != current_palette)
memcpy(current_palette, palette, 768);
for (i=0 ; i<256 ; i++)
{
colors[i].pixel = i;
colors[i].flags = DoRed|DoGreen|DoBlue;
colors[i].red = vid_gamma[palette[i*3]] * 257;
colors[i].green = vid_gamma[palette[i*3+1]] * 257;
colors[i].blue = vid_gamma[palette[i*3+2]] * 257;
}
XStoreColors(x_disp, x_cmap, colors, 256);
}
}
// Called at shutdown
void VID_Shutdown (void)
{
X11_active = false;
Con_Printf("VID_Shutdown\n");
//XAutoRepeatOn(x_disp);
xil_destroy(display_image);
xil_destroy(quake_image);
display_image = NULL;
quake_image = NULL;
XCloseDisplay(x_disp);
}
int XLateKey(XKeyEvent *ev)
{
int key;
char buf[64];
KeySym keysym;
XLookupString(ev, buf, sizeof buf, &keysym, 0);
switch(keysym) {
case XK_Page_Up: key = K_PGUP; break;
case XK_Page_Down: key = K_PGDN; break;
case XK_Home: key = K_HOME; break;
case XK_End: key = K_END; break;
case XK_Left: key = K_LEFTARROW; break;
case XK_Right: key = K_RIGHTARROW; break;
case XK_Down: key = K_DOWNARROW; break;
case XK_Up: key = K_UPARROW; break;
case XK_Escape: key = K_ESCAPE; break;
case XK_Return: key = K_ENTER; break;
case XK_Tab: key = K_TAB; break;
case XK_Help:
case XK_F1: key = K_F1; break;
case XK_F2: key = K_F2; break;
case XK_F3: key = K_F3; break;
case XK_F4: key = K_F4; break;
case XK_F5: key = K_F5; break;
case XK_F6: key = K_F6; break;
case XK_F7: key = K_F7; break;
case XK_F8: key = K_F8; break;
case XK_F9: key = K_F9; break;
case XK_F10: key = K_F10; break;
case XK_F11: key = K_F11; break;
case XK_F12: key = K_F12; break;
case XK_BackSpace:
case XK_Delete: key = K_BACKSPACE; break;
case XK_Pause: key = K_PAUSE; break;
case XK_Shift_L:
case XK_Shift_R: key = K_SHIFT; break;
case XK_Control_L:
case XK_Control_R: key = K_CTRL; break;
case XK_Alt_L:
case XK_Meta_L:
case XK_Alt_R:
case XK_Meta_R: key = K_ALT; break;
// various other keys on the keyboard
case XK_F27: key = K_HOME; break;
case XK_F29: key = K_PGUP; break;
case XK_F33: key = K_END; break;
case XK_F35: key = K_PGDN; break;
case XK_Insert:
case XK_KP_Insert: key = K_INS; break;
case XK_F24: key = '-'; break;
case XK_KP_Add: key = '+'; break;
case XK_KP_Subtract: key = '-'; break;
case XK_F25: key = '/'; break;
case XK_F26: key = '*'; break;
default:
key = (unsigned char)*buf;
break;
}
return key;
}
struct {
int key;
int down;
} keyq[64];
int keyq_head=0;
int keyq_tail=0;
int config_notify=0;
int config_notify_width;
int config_notify_height;
void GetEvent(void)
{
XEvent x_event;
int b;
XNextEvent(x_disp, &x_event);
switch(x_event.type) {
case KeyPress:
Key_Event(XLateKey(&x_event.xkey), true);
break;
case KeyRelease:
Key_Event(XLateKey(&x_event.xkey), false);
break;
case MotionNotify:
if (_windowed_mouse.value) {
mouse_x = (float) ((int)x_event.xmotion.x - (int)(vid.width/2));
mouse_y = (float) ((int)x_event.xmotion.y - (int)(vid.height/2));
//printf("m: x=%d,y=%d, mx=%3.2f,my=%3.2f\n",
// x_event.xmotion.x, x_event.xmotion.y, mouse_x, mouse_y);
/* move the mouse to the window center again */
XSelectInput( x_disp, x_win, x_std_event_mask & ~PointerMotionMask );
XWarpPointer(x_disp,None,x_win,0,0,0,0,
(vid.width/2),(vid.height/2));
XSelectInput( x_disp, x_win, x_std_event_mask );
} else {
mouse_x = (float) (x_event.xmotion.x-p_mouse_x);
mouse_y = (float) (x_event.xmotion.y-p_mouse_y);
p_mouse_x=x_event.xmotion.x;
p_mouse_y=x_event.xmotion.y;
}
break;
case ButtonPress:
b=-1;
if (x_event.xbutton.button == 1)
b = 0;
else if (x_event.xbutton.button == 2)
b = 2;
else if (x_event.xbutton.button == 3)
b = 1;
if (b>=0)
mouse_buttonstate |= 1<<b;
break;
case ButtonRelease:
b=-1;
if (x_event.xbutton.button == 1)
b = 0;
else if (x_event.xbutton.button == 2)
b = 2;
else if (x_event.xbutton.button == 3)
b = 1;
if (b>=0)
mouse_buttonstate &= ~(1<<b);
break;
case ConfigureNotify:
// printf("config notify\n");
config_notify_width = x_event.xconfigure.width;
config_notify_height = x_event.xconfigure.height;
config_notify = 1;
sb_updates = 0;
break;
case Expose:
sb_updates = 0;
break;
case ClientMessage:
if (x_event.xclient.data.l[0] == aWMDelete) Host_Quit_f();
break;
#if 0
case FocusIn:
printf("FocusIn...\n");
x_focus = true;
break;
case FocusOut:
printf("FocusOut...\n");
x_focus = false;
break;
#endif
}
if (old_windowed_mouse != _windowed_mouse.value) {
old_windowed_mouse = _windowed_mouse.value;
if (!_windowed_mouse.value) {
/* ungrab the pointer */
XUngrabPointer(x_disp,CurrentTime);
} else {
/* grab the pointer */
XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
GrabModeAsync,x_win,None,CurrentTime);
}
}
}
// flushes the given rectangles from the view buffer to the screen
void
VID_Update (vrect_t *rects)
{
void VID_Update_MT(vrect_t *);
if (count_frames) {
static int count;
static long long s;
long long gethrtime();
if (count == 0)
s = gethrtime();
if (count++ == 200) {
long long n = gethrtime();
count = 1;
printf("%lf frames/secs\n", 200.0/((double)(n-s) / 1e9));
s = n;
}
}
if (use_mt) {
VID_Update_MT(rects);
return;
}
// if the window changes dimension, skip this frame
if (config_notify) {
int w, h;
XWindowChanges chg;
unsigned int value_mask;
w = 320*current_pixel_multiply; // minimum width
h = 200*current_pixel_multiply; // minimum height
if (config_notify_width < w || config_notify_height < h) {
// We must resize the window
memset(&chg, 0, sizeof(chg));
value_mask = 0;
if (config_notify_width < w) {
config_notify_width = chg.width = w;
value_mask |= CWWidth;
}
if (config_notify_height < h) {
config_notify_height = chg.height = h;
value_mask |= CWHeight;
}
if (value_mask)
XConfigureWindow(x_disp, x_win, value_mask, &chg);
}
config_notify = 0;
vid.width = MP(config_notify_width) & ~3;
vid.height = MP(config_notify_height);
if (vid.width < 320)
vid.width = 320;
if (vid.height < 200)
vid.height = 200;
VID_ResetFramebuffer();
return;
}
// if pixel multiply changed, skip this frame
if (CheckPixelMultiply())
return;
while (rects) { // I've never seen more than one rect?
XilMemoryStorage storage;