2 * Copyright © 2008 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Soft-
6 * ware"), to deal in the Software without restriction, including without
7 * limitation the rights to use, copy, modify, merge, publish, distribute,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, provided that the above copyright
10 * notice(s) and this permission notice appear in all copies of the Soft-
11 * ware and that both the above copyright notice(s) and this permission
12 * notice appear in supporting documentation.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
17 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
18 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
19 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
22 * MANCE OF THIS SOFTWARE.
24 * Except as contained in this notice, the name of a copyright holder shall
25 * not be used in advertising or otherwise to promote the sale, use or
26 * other dealings in this Software without prior written authorization of
27 * the copyright holder.
30 * Kristian Høgsberg (krh@redhat.com)
34 #ifdef GLX_DIRECT_RENDERING
37 #include <X11/Xlibint.h>
38 #include <X11/extensions/Xext.h>
39 #include <X11/extensions/extutil.h>
40 #include <X11/extensions/dri2proto.h>
44 /* Allow the build to work with an older versions of dri2proto.h and
50 #define X_DRI2GetBuffersWithFormat 7
54 static char dri2ExtensionName
[] = DRI2_NAME
;
55 static XExtensionInfo
*dri2Info
;
56 static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay
, dri2Info
)
58 static /* const */ XExtensionHooks dri2ExtensionHooks
= {
63 NULL
, /* create_font */
65 DRI2CloseDisplay
, /* close_display */
66 NULL
, /* wire_to_event */
67 NULL
, /* event_to_wire */
69 NULL
, /* error_string */
72 static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay
,
79 DRI2QueryExtension(Display
* dpy
, int *eventBase
, int *errorBase
)
81 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
83 if (XextHasExtension(info
)) {
84 *eventBase
= info
->codes
->first_event
;
85 *errorBase
= info
->codes
->first_error
;
93 DRI2QueryVersion(Display
* dpy
, int *major
, int *minor
)
95 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
96 xDRI2QueryVersionReply rep
;
97 xDRI2QueryVersionReq
*req
;
99 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
102 GetReq(DRI2QueryVersion
, req
);
103 req
->reqType
= info
->codes
->major_opcode
;
104 req
->dri2ReqType
= X_DRI2QueryVersion
;
105 req
->majorVersion
= DRI2_MAJOR
;
106 req
->minorVersion
= DRI2_MINOR
;
107 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
112 *major
= rep
.majorVersion
;
113 *minor
= rep
.minorVersion
;
121 DRI2Connect(Display
* dpy
, XID window
, char **driverName
, char **deviceName
)
123 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
124 xDRI2ConnectReply rep
;
125 xDRI2ConnectReq
*req
;
127 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
130 GetReq(DRI2Connect
, req
);
131 req
->reqType
= info
->codes
->major_opcode
;
132 req
->dri2ReqType
= X_DRI2Connect
;
133 req
->window
= window
;
134 req
->driverType
= DRI2DriverDRI
;
135 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
141 if (rep
.driverNameLength
== 0 && rep
.deviceNameLength
== 0) {
147 *driverName
= Xmalloc(rep
.driverNameLength
+ 1);
148 if (*driverName
== NULL
) {
150 ((rep
.driverNameLength
+ 3) & ~3) +
151 ((rep
.deviceNameLength
+ 3) & ~3));
156 _XReadPad(dpy
, *driverName
, rep
.driverNameLength
);
157 (*driverName
)[rep
.driverNameLength
] = '\0';
159 *deviceName
= Xmalloc(rep
.deviceNameLength
+ 1);
160 if (*deviceName
== NULL
) {
162 _XEatData(dpy
, ((rep
.deviceNameLength
+ 3) & ~3));
167 _XReadPad(dpy
, *deviceName
, rep
.deviceNameLength
);
168 (*deviceName
)[rep
.deviceNameLength
] = '\0';
177 DRI2Authenticate(Display
* dpy
, XID window
, drm_magic_t magic
)
179 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
180 xDRI2AuthenticateReq
*req
;
181 xDRI2AuthenticateReply rep
;
183 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
186 GetReq(DRI2Authenticate
, req
);
187 req
->reqType
= info
->codes
->major_opcode
;
188 req
->dri2ReqType
= X_DRI2Authenticate
;
189 req
->window
= window
;
192 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
201 return rep
.authenticated
;
205 DRI2CreateDrawable(Display
* dpy
, XID drawable
)
207 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
208 xDRI2CreateDrawableReq
*req
;
210 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
213 GetReq(DRI2CreateDrawable
, req
);
214 req
->reqType
= info
->codes
->major_opcode
;
215 req
->dri2ReqType
= X_DRI2CreateDrawable
;
216 req
->drawable
= drawable
;
222 DRI2DestroyDrawable(Display
* dpy
, XID drawable
)
224 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
225 xDRI2DestroyDrawableReq
*req
;
227 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
232 GetReq(DRI2DestroyDrawable
, req
);
233 req
->reqType
= info
->codes
->major_opcode
;
234 req
->dri2ReqType
= X_DRI2DestroyDrawable
;
235 req
->drawable
= drawable
;
241 DRI2GetBuffers(Display
* dpy
, XID drawable
,
242 int *width
, int *height
,
243 unsigned int *attachments
, int count
, int *outCount
)
245 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
246 xDRI2GetBuffersReply rep
;
247 xDRI2GetBuffersReq
*req
;
249 xDRI2Buffer repBuffer
;
253 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
256 GetReqExtra(DRI2GetBuffers
, count
* 4, req
);
257 req
->reqType
= info
->codes
->major_opcode
;
258 req
->dri2ReqType
= X_DRI2GetBuffers
;
259 req
->drawable
= drawable
;
261 p
= (CARD32
*) & req
[1];
262 for (i
= 0; i
< count
; i
++)
263 p
[i
] = attachments
[i
];
265 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
272 *height
= rep
.height
;
273 *outCount
= rep
.count
;
275 buffers
= Xmalloc(rep
.count
* sizeof buffers
[0]);
276 if (buffers
== NULL
) {
277 _XEatData(dpy
, rep
.count
* sizeof repBuffer
);
283 for (i
= 0; i
< rep
.count
; i
++) {
284 _XReadPad(dpy
, (char *) &repBuffer
, sizeof repBuffer
);
285 buffers
[i
].attachment
= repBuffer
.attachment
;
286 buffers
[i
].name
= repBuffer
.name
;
287 buffers
[i
].pitch
= repBuffer
.pitch
;
288 buffers
[i
].cpp
= repBuffer
.cpp
;
289 buffers
[i
].flags
= repBuffer
.flags
;
300 DRI2GetBuffersWithFormat(Display
* dpy
, XID drawable
,
301 int *width
, int *height
,
302 unsigned int *attachments
, int count
, int *outCount
)
304 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
305 xDRI2GetBuffersReply rep
;
306 xDRI2GetBuffersReq
*req
;
308 xDRI2Buffer repBuffer
;
312 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
315 GetReqExtra(DRI2GetBuffers
, count
* (4 * 2), req
);
316 req
->reqType
= info
->codes
->major_opcode
;
317 req
->dri2ReqType
= X_DRI2GetBuffersWithFormat
;
318 req
->drawable
= drawable
;
320 p
= (CARD32
*) & req
[1];
321 for (i
= 0; i
< (count
* 2); i
++)
322 p
[i
] = attachments
[i
];
324 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
331 *height
= rep
.height
;
332 *outCount
= rep
.count
;
334 buffers
= Xmalloc(rep
.count
* sizeof buffers
[0]);
335 if (buffers
== NULL
) {
336 _XEatData(dpy
, rep
.count
* sizeof repBuffer
);
342 for (i
= 0; i
< rep
.count
; i
++) {
343 _XReadPad(dpy
, (char *) &repBuffer
, sizeof repBuffer
);
344 buffers
[i
].attachment
= repBuffer
.attachment
;
345 buffers
[i
].name
= repBuffer
.name
;
346 buffers
[i
].pitch
= repBuffer
.pitch
;
347 buffers
[i
].cpp
= repBuffer
.cpp
;
348 buffers
[i
].flags
= repBuffer
.flags
;
359 DRI2CopyRegion(Display
* dpy
, XID drawable
, XserverRegion region
,
360 CARD32 dest
, CARD32 src
)
362 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
363 xDRI2CopyRegionReq
*req
;
364 xDRI2CopyRegionReply rep
;
366 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
369 GetReq(DRI2CopyRegion
, req
);
370 req
->reqType
= info
->codes
->major_opcode
;
371 req
->dri2ReqType
= X_DRI2CopyRegion
;
372 req
->drawable
= drawable
;
373 req
->region
= region
;
377 _XReply(dpy
, (xReply
*) & rep
, 0, xFalse
);
383 #endif /* GLX_DIRECT_RENDERING */