comparison src/video/Xext/XME/xme.c @ 1242:caf0328c8058

Add XME hooks to X11 driver instead of relying on libxme...libxme hasn't changed in five years, and it's a small .c file that just calls into the X11 dependencies we already use elsewhere. Including it directly allows us to make use of the dynamic X11 code. Fixes Bugzilla #41. --ryan.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 12 Jan 2006 22:46:36 +0000
parents
children 19418e4422cb
comparison
equal deleted inserted replaced
1241:4b2146866b82 1242:caf0328c8058
1 /*
2 * Copyright 1993-2001 by Xi Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * Please see the LICENSE file accompanying this distribution for licensing
6 * information.
7 *
8 * Please send any bug fixes and modifications to src@xig.com.
9 *
10 * $XiGId: xme.c,v 1.2 2001/11/30 21:56:59 jon Exp $
11 *
12 */
13
14 #define NEED_EVENTS
15 #define NEED_REPLIES
16
17 #include <X11/Xlibint.h>
18 #include <X11/Xthreads.h>
19 #include <X11/Xmd.h>
20 #include <X11/Xproto.h>
21 #include <X11/extensions/Xext.h>
22 #include "extutil.h"
23
24 #include "../../x11/SDL_x11dyn.h"
25
26 /*****************************************************************************/
27
28
29 #define XIGMISC_PROTOCOL_NAME "XiG-SUNDRY-NONSTANDARD"
30 #define XIGMISC_MAJOR_VERSION 2
31 #define XIGMISC_MINOR_VERSION 0
32
33 #define XiGMiscNumberEvents 0
34
35 #define X_XiGMiscQueryVersion 0
36 #define X_XiGMiscQueryViews 1
37 #define X_XiGMiscQueryResolutions 2
38 #define X_XiGMiscChangeResolution 3
39 #define X_XiGMiscFullScreen 4
40
41 #define sz_xXiGMiscQueryVersionReq 8
42 #define sz_xXiGMiscQueryViewsReq 8
43 #define sz_xXiGMiscQueryResolutionsReq 8
44 #define sz_xXiGMiscChangeResolutionReq 16
45 #define sz_xXiGMiscFullScreenReq 16
46
47 #define sz_xXiGMiscQueryVersionReply 32
48 #define sz_xXiGMiscQueryViewsReply 32
49 #define sz_xXiGMiscQueryResolutionsReply 32
50 #define sz_xXiGMiscQueryFullScreenReply 32
51
52 /*******************************************************************/
53
54 typedef struct {
55 CARD8 reqType; /* always codes->major_opcode */
56 CARD8 xigmiscReqType; /* always X_XiGMiscQueryVersion */
57 CARD16 length;
58 CARD16 major;
59 CARD16 minor;
60 } xXiGMiscQueryVersionReq;
61
62 typedef struct {
63 CARD8 reqType; /* always codes->major_opcode */
64 CARD8 xigmiscReqType; /* always X_XiGMiscQueryViews */
65 CARD16 length;
66 CARD8 screen;
67 CARD8 pad0;
68 CARD16 pad1;
69 } xXiGMiscQueryViewsReq;
70
71 typedef struct {
72 CARD8 reqType; /* always codes->major_opcode */
73 CARD8 xigmiscReqType; /* always X_XiGMiscQueryResolutions */
74 CARD16 length;
75 CARD8 screen;
76 CARD8 view;
77 CARD16 pad0;
78 } xXiGMiscQueryResolutionsReq;
79
80 typedef struct {
81 CARD8 reqType; /* always codes->major_opcode */
82 CARD8 xigmiscReqType; /* always X_XiGMiscChangeResolution */
83 CARD16 length;
84 CARD8 screen;
85 CARD8 view;
86 CARD16 pad0;
87 CARD16 width;
88 CARD16 height;
89 INT32 refresh;
90 } xXiGMiscChangeResolutionReq;
91
92 typedef struct {
93 CARD8 reqType; /* always codes->major_opcode */
94 CARD8 xigmiscReqType; /* always X_XiGMiscFullScreen */
95 CARD16 length;
96 CARD8 screen;
97 CARD8 pad0;
98 CARD16 pad1;
99 CARD32 window;
100 CARD32 cmap;
101 } xXiGMiscFullScreenReq;
102
103 /*******************************************************************/
104
105 typedef struct {
106 BYTE type; /* X_Reply */
107 CARD8 pad0;
108 CARD16 sequenceNumber;
109 CARD32 length;
110 CARD16 major;
111 CARD16 minor;
112 CARD32 pad1;
113 CARD32 pad2;
114 CARD32 pad3;
115 CARD32 pad4;
116 CARD32 pad5;
117 } xXiGMiscQueryVersionReply;
118
119 typedef struct {
120 BYTE type; /* X_Reply */
121 CARD8 pad0;
122 CARD16 sequenceNumber;
123 CARD32 length;
124 CARD32 nviews;
125 CARD32 pad1;
126 CARD32 pad2;
127 CARD32 pad3;
128 CARD32 pad4;
129 CARD32 pad5;
130 } xXiGMiscQueryViewsReply;
131
132 typedef struct {
133 BYTE type; /* X_Reply */
134 CARD8 pad0;
135 CARD16 sequenceNumber;
136 CARD32 length;
137 CARD16 active;
138 CARD16 nresolutions;
139 CARD32 pad1;
140 CARD32 pad2;
141 CARD32 pad3;
142 CARD32 pad4;
143 CARD32 pad5;
144 } xXiGMiscQueryResolutionsReply;
145
146 typedef struct {
147 BYTE type; /* X_Reply */
148 BOOL success;
149 CARD16 sequenceNumber;
150 CARD32 length;
151 CARD32 pad1;
152 CARD32 pad2;
153 CARD32 pad3;
154 CARD32 pad4;
155 CARD32 pad5;
156 CARD32 pad6;
157 } xXiGMiscFullScreenReply;
158
159 /*******************************************************************/
160
161 typedef struct {
162 INT16 x;
163 INT16 y;
164 CARD16 w;
165 CARD16 h;
166 } XiGMiscViewInfo;
167
168 typedef struct {
169 CARD16 width;
170 CARD16 height;
171 INT32 refresh;
172 } XiGMiscResolutionInfo;
173
174 /*****************************************************************************/
175
176 static XExtensionInfo *xigmisc_info = NULL;
177 static char *xigmisc_extension_name = XIGMISC_PROTOCOL_NAME;
178
179 #define XiGMiscCheckExtension(dpy,i,val) \
180 XextCheckExtension (dpy, i, xigmisc_extension_name, val)
181 #define XiGMiscSimpleCheckExtension(dpy,i) \
182 XextSimpleCheckExtension (dpy, i, xigmisc_extension_name)
183
184 #if defined(__STDC__) && !defined(UNIXCPP)
185 #define XiGMiscGetReq(name,req,info) GetReq (name, req); \
186 req->reqType = info->codes->major_opcode; \
187 req->xigmiscReqType = X_##name;
188
189 #define XiGMiscGetReqExtra(name,n,req,info) GetReqExtra (name, n, req); \
190 req->reqType = info->codes->major_opcode; \
191 req->xigmicReqType = X_##name;
192 #else
193 #define XiGMiscGetReq(name,req,info) GetReq (name, req); \
194 req->reqType = info->codes->major_opcode; \
195 req->xigmiscReqType = X_/**/name;
196 #define XiGMiscGetReqExtra(name,n,req,info) GetReqExtra (name, n, req); \
197 req->reqType = info->codes->major_opcode; \
198 req->xigmiscReqType = X_/**/name;
199 #endif
200
201
202
203 /*
204 * find_display - locate the display info block
205 */
206 static int XiGMiscCloseDisplay();
207
208 static XExtensionHooks xigmisc_extension_hooks = {
209 NULL, /* create_gc */
210 NULL, /* copy_gc */
211 NULL, /* flush_gc */
212 NULL, /* free_gc */
213 NULL, /* create_font */
214 NULL, /* free_font */
215 XiGMiscCloseDisplay, /* close_display */
216 NULL, /* wire_to_event */
217 NULL, /* event_to_wire */
218 NULL, /* error */
219 NULL, /* error_string */
220 };
221
222
223 static XEXT_GENERATE_CLOSE_DISPLAY (XiGMiscCloseDisplay, xigmisc_info)
224
225 static XEXT_GENERATE_FIND_DISPLAY (XiGMiscFindDisplay, xigmisc_info,
226 xigmisc_extension_name,
227 &xigmisc_extension_hooks, XiGMiscNumberEvents, NULL)
228
229
230 /*****************************************************************************/
231
232 Bool XiGMiscQueryVersion(Display *dpy, int *major, int *minor)
233 {
234 int opcode, event, error;
235 xXiGMiscQueryVersionReq *req;
236 xXiGMiscQueryVersionReply rep;
237 XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
238
239 if (!pXQueryExtension(dpy, XIGMISC_PROTOCOL_NAME, &opcode, &event, &error))
240 return xFalse;
241
242 XiGMiscCheckExtension(dpy, info, xFalse);
243
244 LockDisplay (dpy);
245 XiGMiscGetReq (XiGMiscQueryVersion, req, info);
246
247 req->major = XIGMISC_MAJOR_VERSION;
248 req->minor = XIGMISC_MINOR_VERSION;
249
250 if (!p_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
251 UnlockDisplay(dpy);
252 SyncHandle();
253 return xFalse;
254 }
255
256 *major = rep.major;
257 *minor = rep.minor;
258 UnlockDisplay(dpy);
259 SyncHandle();
260
261 return xTrue;
262 }
263
264 int XiGMiscQueryViews(Display *dpy, int screen, XiGMiscViewInfo **pviews)
265 {
266 int n, size;
267 XiGMiscViewInfo *views;
268 xXiGMiscQueryViewsReq *req;
269 xXiGMiscQueryViewsReply rep;
270 XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
271 XiGMiscCheckExtension(dpy, info, 0);
272
273 LockDisplay (dpy);
274 XiGMiscGetReq (XiGMiscQueryViews, req, info);
275 req->screen = screen;
276
277 if (!p_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
278 UnlockDisplay(dpy);
279 SyncHandle();
280 return 0;
281 }
282
283 n = rep.nviews;
284
285 if (n > 0) {
286 size = sizeof(XiGMiscViewInfo) * n;
287 views = (XiGMiscViewInfo*)Xmalloc(size);
288 if (!views) {
289 p_XEatData(dpy, (unsigned long)size);
290 UnlockDisplay(dpy);
291 SyncHandle();
292 return 0;
293 }
294
295 p_XReadPad(dpy, (void*)views, size);
296
297 *pviews = views;
298 }
299
300 UnlockDisplay(dpy);
301 SyncHandle();
302
303 return n;
304 }
305
306 int XiGMiscQueryResolutions(Display *dpy, int screen, int view, int *pactive, XiGMiscResolutionInfo **presolutions)
307 {
308 int n, size;
309 XiGMiscResolutionInfo *resolutions;
310 xXiGMiscQueryResolutionsReq *req;
311 xXiGMiscQueryResolutionsReply rep;
312 XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
313 XiGMiscCheckExtension(dpy, info, 0);
314
315 LockDisplay (dpy);
316 XiGMiscGetReq (XiGMiscQueryResolutions, req, info);
317 req->screen = screen;
318 req->view = view;
319
320 if (!p_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
321 UnlockDisplay(dpy);
322 SyncHandle();
323 return 0;
324 }
325
326 n = rep.nresolutions;
327
328 if (n > 0) {
329 size = sizeof(XiGMiscResolutionInfo) * n;
330 resolutions = (XiGMiscResolutionInfo*)Xmalloc(size);
331 if (!resolutions) {
332 p_XEatData(dpy, (unsigned long)size);
333 UnlockDisplay(dpy);
334 SyncHandle();
335 return 0;
336 }
337
338 p_XReadPad(dpy, (void*)resolutions, size);
339
340 *presolutions = resolutions;
341 *pactive = rep.active;
342 }
343
344 UnlockDisplay(dpy);
345 SyncHandle();
346
347 return n;
348 }
349
350 void XiGMiscChangeResolution(Display *dpy, int screen, int view, int width, int height, int refresh)
351 {
352 xXiGMiscChangeResolutionReq *req;
353 XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
354
355 XiGMiscSimpleCheckExtension(dpy, info);
356
357 LockDisplay (dpy);
358 XiGMiscGetReq (XiGMiscChangeResolution, req, info);
359 req->screen = screen;
360 req->view = view;
361 req->width = width;
362 req->height = height;
363 req->refresh = refresh;
364
365 UnlockDisplay(dpy);
366 SyncHandle();
367 }
368
369
370 Bool XiGMiscFullScreen(Display *dpy, int screen, XID window, XID cmap)
371 {
372 xXiGMiscFullScreenReq *req;
373 xXiGMiscFullScreenReply rep;
374 XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
375
376 XiGMiscCheckExtension(dpy, info, xFalse);
377
378 LockDisplay (dpy);
379 XiGMiscGetReq (XiGMiscFullScreen, req, info);
380 req->screen = screen;
381 req->pad0 = 0;
382 req->pad1 = 0;
383 req->window = window;
384 req->cmap = cmap;
385
386 if (!p_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
387 UnlockDisplay(dpy);
388 SyncHandle();
389 return xFalse;
390 }
391
392 UnlockDisplay(dpy);
393 SyncHandle();
394
395 return (rep.success ? xTrue : xFalse);
396 }
397