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)
35 #include <X11/Xlibint.h>
36 #include <X11/extensions/Xext.h>
37 #include <X11/extensions/extutil.h>
38 #include <X11/extensions/dri2proto.h>
42 /* Allow the build to work with an older versions of dri2proto.h and
48 #define X_DRI2GetBuffersWithFormat 7
52 static char dri2ExtensionName
[] = DRI2_NAME
;
53 static XExtensionInfo
*dri2Info
;
54 static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay
, dri2Info
)
56 static /* const */ XExtensionHooks dri2ExtensionHooks
= {
61 NULL
, /* create_font */
63 DRI2CloseDisplay
, /* close_display */
64 NULL
, /* wire_to_event */
65 NULL
, /* event_to_wire */
67 NULL
, /* error_string */
70 static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay
,
77 DRI2QueryExtension(Display
* dpy
, int *eventBase
, int *errorBase
)
79 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
81 if (XextHasExtension(info
)) {
82 *eventBase
= info
->codes
->first_event
;
83 *errorBase
= info
->codes
->first_error
;
91 DRI2QueryVersion(Display
* dpy
, int *major
, int *minor
)
93 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
94 xDRI2QueryVersionReply rep
;
95 xDRI2QueryVersionReq
*req
;
97 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
100 GetReq(DRI2QueryVersion
, req
);
101 req
->reqType
= info
->codes
->major_opcode
;
102 req
->dri2ReqType
= X_DRI2QueryVersion
;
103 req
->majorVersion
= DRI2_MAJOR
;
104 req
->minorVersion
= DRI2_MINOR
;
105 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
110 *major
= rep
.majorVersion
;
111 *minor
= rep
.minorVersion
;
119 DRI2Connect(Display
* dpy
, XID window
, char **driverName
, char **deviceName
)
121 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
122 xDRI2ConnectReply rep
;
123 xDRI2ConnectReq
*req
;
125 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
128 GetReq(DRI2Connect
, req
);
129 req
->reqType
= info
->codes
->major_opcode
;
130 req
->dri2ReqType
= X_DRI2Connect
;
131 req
->window
= window
;
132 req
->driverType
= DRI2DriverDRI
;
133 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
139 if (rep
.driverNameLength
== 0 && rep
.deviceNameLength
== 0) {
145 *driverName
= Xmalloc(rep
.driverNameLength
+ 1);
146 if (*driverName
== NULL
) {
148 ((rep
.driverNameLength
+ 3) & ~3) +
149 ((rep
.deviceNameLength
+ 3) & ~3));
154 _XReadPad(dpy
, *driverName
, rep
.driverNameLength
);
155 (*driverName
)[rep
.driverNameLength
] = '\0';
157 *deviceName
= Xmalloc(rep
.deviceNameLength
+ 1);
158 if (*deviceName
== NULL
) {
160 _XEatData(dpy
, ((rep
.deviceNameLength
+ 3) & ~3));
165 _XReadPad(dpy
, *deviceName
, rep
.deviceNameLength
);
166 (*deviceName
)[rep
.deviceNameLength
] = '\0';
175 DRI2Authenticate(Display
* dpy
, XID window
, drm_magic_t magic
)
177 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
178 xDRI2AuthenticateReq
*req
;
179 xDRI2AuthenticateReply rep
;
181 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
184 GetReq(DRI2Authenticate
, req
);
185 req
->reqType
= info
->codes
->major_opcode
;
186 req
->dri2ReqType
= X_DRI2Authenticate
;
187 req
->window
= window
;
190 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
199 return rep
.authenticated
;
203 DRI2CreateDrawable(Display
* dpy
, XID drawable
)
205 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
206 xDRI2CreateDrawableReq
*req
;
208 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
211 GetReq(DRI2CreateDrawable
, req
);
212 req
->reqType
= info
->codes
->major_opcode
;
213 req
->dri2ReqType
= X_DRI2CreateDrawable
;
214 req
->drawable
= drawable
;
220 DRI2DestroyDrawable(Display
* dpy
, XID drawable
)
222 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
223 xDRI2DestroyDrawableReq
*req
;
225 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
230 GetReq(DRI2DestroyDrawable
, req
);
231 req
->reqType
= info
->codes
->major_opcode
;
232 req
->dri2ReqType
= X_DRI2DestroyDrawable
;
233 req
->drawable
= drawable
;
239 DRI2GetBuffers(Display
* dpy
, XID drawable
,
240 int *width
, int *height
,
241 unsigned int *attachments
, int count
, int *outCount
)
243 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
244 xDRI2GetBuffersReply rep
;
245 xDRI2GetBuffersReq
*req
;
247 xDRI2Buffer repBuffer
;
251 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
254 GetReqExtra(DRI2GetBuffers
, count
* 4, req
);
255 req
->reqType
= info
->codes
->major_opcode
;
256 req
->dri2ReqType
= X_DRI2GetBuffers
;
257 req
->drawable
= drawable
;
259 p
= (CARD32
*) & req
[1];
260 for (i
= 0; i
< count
; i
++)
261 p
[i
] = attachments
[i
];
263 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
270 *height
= rep
.height
;
271 *outCount
= rep
.count
;
273 buffers
= Xmalloc(rep
.count
* sizeof buffers
[0]);
274 if (buffers
== NULL
) {
275 _XEatData(dpy
, rep
.count
* sizeof repBuffer
);
281 for (i
= 0; i
< rep
.count
; i
++) {
282 _XReadPad(dpy
, (char *) &repBuffer
, sizeof repBuffer
);
283 buffers
[i
].attachment
= repBuffer
.attachment
;
284 buffers
[i
].name
= repBuffer
.name
;
285 buffers
[i
].pitch
= repBuffer
.pitch
;
286 buffers
[i
].cpp
= repBuffer
.cpp
;
287 buffers
[i
].flags
= repBuffer
.flags
;
298 DRI2GetBuffersWithFormat(Display
* dpy
, XID drawable
,
299 int *width
, int *height
,
300 unsigned int *attachments
, int count
, int *outCount
)
302 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
303 xDRI2GetBuffersReply rep
;
304 xDRI2GetBuffersReq
*req
;
306 xDRI2Buffer repBuffer
;
310 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
313 GetReqExtra(DRI2GetBuffers
, count
* (4 * 2), req
);
314 req
->reqType
= info
->codes
->major_opcode
;
315 req
->dri2ReqType
= X_DRI2GetBuffersWithFormat
;
316 req
->drawable
= drawable
;
318 p
= (CARD32
*) & req
[1];
319 for (i
= 0; i
< (count
* 2); i
++)
320 p
[i
] = attachments
[i
];
322 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
329 *height
= rep
.height
;
330 *outCount
= rep
.count
;
332 buffers
= Xmalloc(rep
.count
* sizeof buffers
[0]);
333 if (buffers
== NULL
) {
334 _XEatData(dpy
, rep
.count
* sizeof repBuffer
);
340 for (i
= 0; i
< rep
.count
; i
++) {
341 _XReadPad(dpy
, (char *) &repBuffer
, sizeof repBuffer
);
342 buffers
[i
].attachment
= repBuffer
.attachment
;
343 buffers
[i
].name
= repBuffer
.name
;
344 buffers
[i
].pitch
= repBuffer
.pitch
;
345 buffers
[i
].cpp
= repBuffer
.cpp
;
346 buffers
[i
].flags
= repBuffer
.flags
;
357 DRI2CopyRegion(Display
* dpy
, XID drawable
, XserverRegion region
,
358 CARD32 dest
, CARD32 src
)
360 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
361 xDRI2CopyRegionReq
*req
;
362 xDRI2CopyRegionReply rep
;
364 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
367 GetReq(DRI2CopyRegion
, req
);
368 req
->reqType
= info
->codes
->major_opcode
;
369 req
->dri2ReqType
= X_DRI2CopyRegion
;
370 req
->drawable
= drawable
;
371 req
->region
= region
;
375 _XReply(dpy
, (xReply
*) & rep
, 0, xFalse
);