1 /************************************************************
2 Copyright (c) 1997 by Silicon Graphics Computer Systems, Inc.
3 Permission to use, copy, modify, and distribute this
4 software and its documentation for any purpose and without
5 fee is hereby granted, provided that the above copyright
6 notice appear in all copies and that both that copyright
7 notice and this permission notice appear in supporting
8 documentation, and that the name of Silicon Graphics not be
9 used in advertising or publicity pertaining to distribution
10 of the software without specific prior written permission.
11 Silicon Graphics makes no representation about the suitability
12 of this software for any purpose. It is provided "as is"
13 without any express or implied warranty.
14 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
15 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
17 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
18 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
20 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
21 THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 ********************************************************/
27 #include <X11/Xlibint.h>
28 #include <X11/extensions/XEVI.h>
29 #include <X11/extensions/EVIproto.h>
30 #include <X11/extensions/Xext.h>
31 #include <X11/extensions/extutil.h>
32 #include <X11/Xutil.h>
33 static XExtensionInfo *xevi_info;/* needs to move to globals.c */
34 static const char *xevi_extension_name = EVINAME;
35 #define XeviCheckExtension(dpy,i,val) \
36 XextCheckExtension (dpy, i, xevi_extension_name, val)
37 /*****************************************************************************
39 * private utility routines *
41 *****************************************************************************/
42 static /* const */ XExtensionHooks xevi_extension_hooks = {
47 NULL, /* create_font */
49 NULL, /* close_display */
50 NULL, /* wire_to_event */
51 NULL, /* event_to_wire */
53 NULL, /* error_string */
55 static XEXT_GENERATE_FIND_DISPLAY (find_display, xevi_info,
57 &xevi_extension_hooks, 0, NULL)
58 Bool XeviQueryExtension (Display *dpy)
60 XExtDisplayInfo *info = find_display (dpy);
61 if (XextHasExtension(info)) {
67 Bool XeviQueryVersion(Display *dpy, int *majorVersion, int *minorVersion)
69 XExtDisplayInfo *info = find_display (dpy);
70 xEVIQueryVersionReply rep;
71 register xEVIQueryVersionReq *req;
72 XeviCheckExtension (dpy, info, False);
74 GetReq(EVIQueryVersion, req);
75 req->reqType = info->codes->major_opcode;
76 req->xeviReqType = X_EVIQueryVersion;
77 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
82 *majorVersion = rep.majorVersion;
83 *minorVersion = rep.minorVersion;
88 static Bool notInList(VisualID32 *visual, int sz_visual, VisualID newVisualid)
90 while (sz_visual-- > 0) {
91 if (*visual == newVisualid)
97 Status XeviGetVisualInfo(
98 register Display *dpy,
101 ExtendedVisualInfo **evi_return,
104 XExtDisplayInfo *info = find_display (dpy);
105 register xEVIGetVisualInfoReq *req;
106 xEVIGetVisualInfoReply rep;
107 int sz_info, sz_xInfo, sz_conflict, sz_xConflict;
108 VisualID32 *temp_conflict, *temp_visual, *xConflictPtr;
110 xExtendedVisualInfo *temp_xInfo;
112 register ExtendedVisualInfo *infoPtr;
113 register xExtendedVisualInfo *xInfoPtr;
114 register int n_data, visualIndex, vinfoIndex;
116 XeviCheckExtension (dpy, info, 0);
117 if (!n_info_return || !evi_return) {
122 vinfo = XGetVisualInfo(dpy, 0, NULL, &sz_info);
126 if (!n_visual || !visual) { /* copy the all visual */
127 temp_visual = (VisualID32 *)Xmalloc(sz_VisualID32 * sz_info);
129 for (vinfoIndex = 0; vinfoIndex < sz_info; vinfoIndex++)
130 if (notInList(temp_visual, n_visual, vinfo[vinfoIndex].visualid))
131 temp_visual[n_visual++] = vinfo[vinfoIndex].visualid;
133 else { /* check if the visual is valid */
134 for (visualIndex = 0; visualIndex < n_visual; visualIndex++) {
136 for (vinfoIndex = 0; vinfoIndex < sz_info; vinfoIndex++) {
137 if (visual[visualIndex] == vinfo[vinfoIndex].visualid) {
147 temp_visual = (VisualID32 *)Xmalloc(sz_VisualID32 * n_visual);
148 for (visualIndex = 0; visualIndex < n_visual; visualIndex++)
149 temp_visual[visualIndex] = visual[visualIndex];
153 GetReq(EVIGetVisualInfo, req);
154 req->reqType = info->codes->major_opcode;
155 req->xeviReqType = X_EVIGetVisualInfo;
156 req->n_visual = n_visual;
157 SetReqLen(req, n_visual, 1);
158 Data(dpy, (char *)temp_visual, n_visual * sz_VisualID32);
159 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
166 sz_info = rep.n_info * sizeof(ExtendedVisualInfo);
167 sz_xInfo = rep.n_info * sz_xExtendedVisualInfo;
168 sz_conflict = rep.n_conflicts * sizeof(VisualID);
169 sz_xConflict = rep.n_conflicts * sz_VisualID32;
170 infoPtr = *evi_return = (ExtendedVisualInfo *)Xmalloc(sz_info + sz_conflict);
171 xInfoPtr = temp_xInfo = (xExtendedVisualInfo *)Xmalloc(sz_xInfo);
172 xConflictPtr = temp_conflict = (VisualID32 *)Xmalloc(sz_xConflict);
173 if (!*evi_return || !temp_xInfo || !temp_conflict) {
174 _XEatData(dpy, (sz_xInfo + sz_xConflict + 3) & ~3);
182 Xfree(temp_conflict);
185 _XRead(dpy, (char *)temp_xInfo, sz_xInfo);
186 _XRead(dpy, (char *)temp_conflict, sz_xConflict);
190 conflict = (VisualID *)(infoPtr + n_data);
191 while (n_data-- > 0) {
192 infoPtr->core_visual_id = xInfoPtr->core_visual_id;
193 infoPtr->screen = xInfoPtr->screen;
194 infoPtr->level = xInfoPtr->level;
195 infoPtr->transparency_type = xInfoPtr->transparency_type;
196 infoPtr->transparency_value = xInfoPtr->transparency_value;
197 infoPtr->min_hw_colormaps = xInfoPtr->min_hw_colormaps;
198 infoPtr->max_hw_colormaps = xInfoPtr->max_hw_colormaps;
199 infoPtr->num_colormap_conflicts = xInfoPtr->num_colormap_conflicts;
200 infoPtr->colormap_conflicts = conflict;
201 conflict += infoPtr->num_colormap_conflicts;
205 n_data = rep.n_conflicts;
206 conflict = (VisualID *)(infoPtr);
208 *conflict++ = *xConflictPtr++;
210 Xfree(temp_conflict);
211 *n_info_return = rep.n_info;