1 /*
2 dga_check.c
3
4 Routines to check for XFree86 DGA and VidMode extensions
5
6 Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
7 Copyright (C) 2000 contributors of the QuakeForge project
8 Please see the file "AUTHORS" for a list of contributors
9
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19 See the GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to:
23
24 Free Software Foundation, Inc.
25 59 Temple Place - Suite 330
26 Boston, MA 02111-1307, USA
27
28 */
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <stdlib.h>
34 #include <X11/Xlib.h>
35 #include <X11/Xproto.h>
36
37 #ifdef HAVE_DGA
38 # ifdef DGA_OLD_HEADERS
39 # include <X11/extensions/xf86dga.h>
40 # include <X11/extensions/xf86dgastr.h>
41 # else
42 # include <X11/extensions/Xxf86dga.h>
43 # include <X11/extensions/xf86dgaproto.h>
44 # endif
45 # ifndef XDGA_MAJOR_VERSION
46 # ifdef XF86DGA_MAJOR_VERSION
47 # define XDGA_MAJOR_VERSION XF86DGA_MAJOR_VERSION
48 # else
49 # error "Neither XDGA_MAJOR_VERSION nor XF86DGA_MAJOR_VERSION found."
50 # endif
51 # endif
52 #endif
53 #ifdef HAVE_VIDMODE
54 # include <X11/extensions/xf86vmode.h>
55 # ifdef DGA_OLD_HEADERS
56 # include <X11/extensions/xf86vmstr.h>
57 # else
58 # include <X11/extensions/xf86vmproto.h>
59 # endif
60 #endif
61
62 #include "QF/sys.h"
63
64 #include "dga_check.h"
65
66
67 /*
68 VID_CheckDGA
69
70 Check for the presence of the XFree86-DGA X server extension
71 */
72 qboolean
VID_CheckDGA(Display * dpy,int * maj_ver,int * min_ver,int * hasvideo)73 VID_CheckDGA (Display * dpy, int *maj_ver, int *min_ver, int *hasvideo)
74 {
75 #ifdef HAVE_DGA
76 int event_base, error_base, dgafeat;
77 int dummy, dummy_major, dummy_minor, dummy_video;
78
79 if (!XQueryExtension (dpy, XF86DGANAME, &dummy, &dummy, &dummy)) {
80 return false;
81 }
82
83 if (!XF86DGAQueryExtension (dpy, &event_base, &error_base)) {
84 return false;
85 }
86
87 if (!maj_ver)
88 maj_ver = &dummy_major;
89 if (!min_ver)
90 min_ver = &dummy_minor;
91
92 if (!XF86DGAQueryVersion (dpy, maj_ver, min_ver)) {
93 return false;
94 }
95
96 if ((!maj_ver) || (*maj_ver != XDGA_MAJOR_VERSION)) {
97 Sys_MaskPrintf (SYS_VID, "VID: Incorrect DGA version: %d.%d, \n",
98 *maj_ver, *min_ver);
99 return false;
100 }
101 Sys_MaskPrintf (SYS_VID, "VID: DGA version: %d.%d\n", *maj_ver, *min_ver);
102
103 if (!hasvideo)
104 hasvideo = &dummy_video;
105
106 if (!XF86DGAQueryDirectVideo (dpy, DefaultScreen (dpy), &dgafeat)) {
107 *hasvideo = 0;
108 } else {
109 *hasvideo = (dgafeat & XF86DGADirectGraphics);
110 }
111
112 if (!(dgafeat & (XF86DGADirectPresent | XF86DGADirectMouse))) {
113 return false;
114 }
115
116 return true;
117 #else
118 return false;
119 #endif // HAVE_DGA
120 }
121
122
123 /*
124 VID_CheckVMode
125
126 Check for the presence of the XFree86-VidMode X server extension
127 */
128 qboolean
VID_CheckVMode(Display * dpy,int * maj_ver,int * min_ver)129 VID_CheckVMode (Display * dpy, int *maj_ver, int *min_ver)
130 {
131 #ifdef HAVE_VIDMODE
132 int dummy, dummy_major, dummy_minor, event_base, error_base;
133
134 if (!XQueryExtension (dpy, XF86VIDMODENAME, &dummy, &dummy, &dummy)) {
135 return false;
136 }
137
138 if (!XF86VidModeQueryExtension (dpy, &event_base, &error_base)) {
139 return false;
140 }
141
142 if (!maj_ver)
143 maj_ver = &dummy_major;
144 if (!min_ver)
145 min_ver = &dummy_minor;
146
147 if (!XF86VidModeQueryVersion (dpy, maj_ver, min_ver))
148 return false;
149
150 if ((!maj_ver) || (*maj_ver != XF86VIDMODE_MAJOR_VERSION)) {
151 Sys_MaskPrintf (SYS_VID, "VID: Incorrect VidMode version: %d.%d\n",
152 *maj_ver, *min_ver);
153 return false;
154 }
155
156 Sys_MaskPrintf (SYS_VID, "VID: VidMode version: %d.%d\n",
157 *maj_ver, *min_ver);
158 return true;
159 #else
160 return false;
161 #endif // HAVE_VIDMODE
162 }
163