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 static char dri2ExtensionName
[] = DRI2_NAME
;
43 static XExtensionInfo
*dri2Info
;
44 static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay
, dri2Info
)
45 static /* const */ XExtensionHooks dri2ExtensionHooks
= {
50 NULL
, /* create_font */
52 DRI2CloseDisplay
, /* close_display */
53 NULL
, /* wire_to_event */
54 NULL
, /* event_to_wire */
56 NULL
, /* error_string */
59 static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay
, dri2Info
,
64 Bool
DRI2QueryExtension(Display
*dpy
, int *eventBase
, int *errorBase
)
66 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
68 if (XextHasExtension(info
)) {
69 *eventBase
= info
->codes
->first_event
;
70 *errorBase
= info
->codes
->first_error
;
77 Bool
DRI2QueryVersion(Display
*dpy
, int *major
, int *minor
)
79 XExtDisplayInfo
*info
= DRI2FindDisplay (dpy
);
80 xDRI2QueryVersionReply rep
;
81 xDRI2QueryVersionReq
*req
;
83 XextCheckExtension (dpy
, info
, dri2ExtensionName
, False
);
86 GetReq(DRI2QueryVersion
, req
);
87 req
->reqType
= info
->codes
->major_opcode
;
88 req
->dri2ReqType
= X_DRI2QueryVersion
;
89 req
->majorVersion
= DRI2_MAJOR
;
90 req
->minorVersion
= DRI2_MINOR
;
91 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
96 *major
= rep
.majorVersion
;
97 *minor
= rep
.minorVersion
;
104 Bool
DRI2Connect(Display
*dpy
, int screen
,
105 char **driverName
, char **busId
, unsigned int *sareaHandle
)
107 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
108 xDRI2ConnectReply rep
;
109 xDRI2ConnectReq
*req
;
111 XextCheckExtension (dpy
, info
, dri2ExtensionName
, False
);
114 GetReq(DRI2Connect
, req
);
115 req
->reqType
= info
->codes
->major_opcode
;
116 req
->dri2ReqType
= X_DRI2Connect
;
117 req
->screen
= screen
;
118 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
124 if (rep
.driverNameLength
== 0 && rep
.busIdLength
== 0) {
130 *driverName
= Xmalloc(rep
.driverNameLength
+ 1);
131 if (*driverName
== NULL
) {
133 ((rep
.driverNameLength
+ 3) & ~3) +
134 ((rep
.busIdLength
+ 3) & ~3));
139 _XReadPad(dpy
, *driverName
, rep
.driverNameLength
);
140 (*driverName
)[rep
.driverNameLength
] = '\0';
142 *busId
= Xmalloc(rep
.busIdLength
+ 1);
143 if (*busId
== NULL
) {
145 _XEatData(dpy
, ((rep
.busIdLength
+ 3) & ~3));
150 _XReadPad(dpy
, *busId
, rep
.busIdLength
);
151 (*busId
)[rep
.busIdLength
] = '\0';
159 Bool
DRI2AuthConnection(Display
*dpy
, int screen
, drm_magic_t magic
)
161 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
162 xDRI2AuthConnectionReq
*req
;
163 xDRI2AuthConnectionReply rep
;
165 XextCheckExtension (dpy
, info
, dri2ExtensionName
, False
);
168 GetReq(DRI2AuthConnection
, req
);
169 req
->reqType
= info
->codes
->major_opcode
;
170 req
->dri2ReqType
= X_DRI2AuthConnection
;
171 req
->screen
= screen
;
173 rep
.authenticated
= 0;
174 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
182 return rep
.authenticated
;
185 void DRI2CreateDrawable(Display
*dpy
, XID drawable
)
187 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
188 xDRI2CreateDrawableReq
*req
;
190 XextSimpleCheckExtension (dpy
, info
, dri2ExtensionName
);
193 GetReq(DRI2CreateDrawable
, req
);
194 req
->reqType
= info
->codes
->major_opcode
;
195 req
->dri2ReqType
= X_DRI2CreateDrawable
;
196 req
->drawable
= drawable
;
201 DRI2Buffer
*DRI2GetBuffers(Display
*dpy
, XID drawable
,
202 int *width
, int *height
,
203 unsigned int *attachments
, int count
,
206 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
207 xDRI2GetBuffersReply rep
;
208 xDRI2GetBuffersReq
*req
;
210 xDRI2Buffer repBuffer
;
214 XextCheckExtension (dpy
, info
, dri2ExtensionName
, False
);
217 GetReqExtra(DRI2GetBuffers
, count
* 4, req
);
218 req
->reqType
= info
->codes
->major_opcode
;
219 req
->dri2ReqType
= X_DRI2GetBuffers
;
220 req
->drawable
= drawable
;
222 p
= (CARD32
*) &req
[1];
223 for (i
= 0; i
< count
; i
++)
224 p
[i
] = attachments
[i
];
226 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
233 *height
= rep
.height
;
234 *outCount
= rep
.count
;
236 buffers
= Xmalloc(count
* sizeof buffers
[0]);
237 if (buffers
== NULL
) {
238 _XEatData(dpy
, rep
.count
* sizeof repBuffer
);
244 for (i
= 0; i
< rep
.count
; i
++) {
245 _XReadPad(dpy
, (char *) &repBuffer
, sizeof repBuffer
);
246 buffers
[i
].attachment
= repBuffer
.attachment
;
247 buffers
[i
].name
= repBuffer
.name
;
248 buffers
[i
].pitch
= repBuffer
.pitch
;
249 buffers
[i
].cpp
= repBuffer
.cpp
;
250 buffers
[i
].flags
= repBuffer
.flags
;
259 void DRI2SwapBuffers(Display
*dpy
, XID drawable
,
260 int x
, int y
, int width
, int height
)
262 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
263 xDRI2SwapBuffersReq
*req
;
264 xDRI2SwapBuffersReply rep
;
266 XextSimpleCheckExtension (dpy
, info
, dri2ExtensionName
);
269 GetReq(DRI2SwapBuffers
, req
);
270 req
->reqType
= info
->codes
->major_opcode
;
271 req
->dri2ReqType
= X_DRI2SwapBuffers
;
272 req
->drawable
= drawable
;
276 req
->height
= height
;
278 _XReply(dpy
, (xReply
*)&rep
, 0, xFalse
);
284 void DRI2DestroyDrawable(Display
*dpy
, XID drawable
)
286 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
287 xDRI2DestroyDrawableReq
*req
;
289 XextSimpleCheckExtension (dpy
, info
, dri2ExtensionName
);
294 GetReq(DRI2DestroyDrawable
, req
);
295 req
->reqType
= info
->codes
->major_opcode
;
296 req
->dri2ReqType
= X_DRI2DestroyDrawable
;
297 req
->drawable
= drawable
;