1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
3 * Copyright © 2008 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Soft-
7 * ware"), to deal in the Software without restriction, including without
8 * limitation the rights to use, copy, modify, merge, publish, distribute,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, provided that the above copyright
11 * notice(s) and this permission notice appear in all copies of the Soft-
12 * ware and that both the above copyright notice(s) and this permission
13 * notice appear in supporting documentation.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
18 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
19 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
20 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
23 * MANCE OF THIS SOFTWARE.
25 * Except as contained in this notice, the name of a copyright holder shall
26 * not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization of
28 * the copyright holder.
31 * Kristian Høgsberg (krh@redhat.com)
36 #include <X11/Xlibint.h>
37 #include <X11/extensions/Xext.h>
38 #include <X11/extensions/extutil.h>
39 #include <X11/extensions/dri2proto.h>
43 static char dri2ExtensionName
[] = DRI2_NAME
;
44 static XExtensionInfo
*dri2Info
;
46 XEXT_GENERATE_CLOSE_DISPLAY(DRI2CloseDisplay
, dri2Info
)
47 static /* const */ XExtensionHooks dri2ExtensionHooks
= {
52 NULL
, /* create_font */
54 DRI2CloseDisplay
, /* close_display */
55 NULL
, /* wire_to_event */
56 NULL
, /* event_to_wire */
58 NULL
, /* error_string */
62 XEXT_GENERATE_FIND_DISPLAY(DRI2FindDisplay
, dri2Info
,
63 dri2ExtensionName
, &dri2ExtensionHooks
, 0, NULL
)
65 Bool
DRI2QueryExtension(Display
* dpy
, int *eventBase
, int *errorBase
)
67 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
69 if (XextHasExtension(info
)) {
70 *eventBase
= info
->codes
->first_event
;
71 *errorBase
= info
->codes
->first_error
;
79 DRI2QueryVersion(Display
* dpy
, int *major
, int *minor
)
81 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
82 xDRI2QueryVersionReply rep
;
83 xDRI2QueryVersionReq
*req
;
85 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
88 GetReq(DRI2QueryVersion
, req
);
89 req
->reqType
= info
->codes
->major_opcode
;
90 req
->dri2ReqType
= X_DRI2QueryVersion
;
91 req
->majorVersion
= DRI2_MAJOR
;
92 req
->minorVersion
= DRI2_MINOR
;
93 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
98 *major
= rep
.majorVersion
;
99 *minor
= rep
.minorVersion
;
107 DRI2Connect(Display
* dpy
, int screen
,
108 char **driverName
, char **busId
, unsigned int *sareaHandle
)
110 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
111 xDRI2ConnectReply rep
;
112 xDRI2ConnectReq
*req
;
114 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
117 GetReq(DRI2Connect
, req
);
118 req
->reqType
= info
->codes
->major_opcode
;
119 req
->dri2ReqType
= X_DRI2Connect
;
120 req
->screen
= screen
;
121 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
127 if (rep
.driverNameLength
== 0 && rep
.busIdLength
== 0) {
133 *driverName
= Xmalloc(rep
.driverNameLength
+ 1);
134 if (*driverName
== NULL
) {
136 ((rep
.driverNameLength
+ 3) & ~3) +
137 ((rep
.busIdLength
+ 3) & ~3));
142 _XReadPad(dpy
, *driverName
, rep
.driverNameLength
);
143 (*driverName
)[rep
.driverNameLength
] = '\0';
145 *busId
= Xmalloc(rep
.busIdLength
+ 1);
146 if (*busId
== NULL
) {
148 _XEatData(dpy
, ((rep
.busIdLength
+ 3) & ~3));
153 _XReadPad(dpy
, *busId
, rep
.busIdLength
);
154 (*busId
)[rep
.busIdLength
] = '\0';
163 DRI2AuthConnection(Display
* dpy
, int screen
, drm_magic_t magic
)
165 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
166 xDRI2AuthConnectionReq
*req
;
167 xDRI2AuthConnectionReply rep
;
169 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
172 GetReq(DRI2AuthConnection
, req
);
173 req
->reqType
= info
->codes
->major_opcode
;
174 req
->dri2ReqType
= X_DRI2AuthConnection
;
175 req
->screen
= screen
;
177 rep
.authenticated
= 0;
178 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
186 return rep
.authenticated
;
190 DRI2CreateDrawable(Display
* dpy
, XID drawable
)
192 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
193 xDRI2CreateDrawableReq
*req
;
195 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
198 GetReq(DRI2CreateDrawable
, req
);
199 req
->reqType
= info
->codes
->major_opcode
;
200 req
->dri2ReqType
= X_DRI2CreateDrawable
;
201 req
->drawable
= drawable
;
207 DRI2GetBuffers(Display
* dpy
, XID drawable
,
208 int *width
, int *height
,
209 unsigned int *attachments
, int count
, int *outCount
)
211 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
212 xDRI2GetBuffersReply rep
;
213 xDRI2GetBuffersReq
*req
;
215 xDRI2Buffer repBuffer
;
219 XextCheckExtension(dpy
, info
, dri2ExtensionName
, False
);
222 GetReqExtra(DRI2GetBuffers
, count
* 4, req
);
223 req
->reqType
= info
->codes
->major_opcode
;
224 req
->dri2ReqType
= X_DRI2GetBuffers
;
225 req
->drawable
= drawable
;
227 p
= (CARD32
*) & req
[1];
228 for (i
= 0; i
< count
; i
++)
229 p
[i
] = attachments
[i
];
231 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
238 *height
= rep
.height
;
239 *outCount
= rep
.count
;
241 buffers
= Xmalloc(count
* sizeof buffers
[0]);
242 if (buffers
== NULL
) {
243 _XEatData(dpy
, rep
.count
* sizeof repBuffer
);
249 for (i
= 0; i
< rep
.count
; i
++) {
250 _XReadPad(dpy
, (char *) &repBuffer
, sizeof repBuffer
);
251 buffers
[i
].attachment
= repBuffer
.attachment
;
252 buffers
[i
].name
= repBuffer
.name
;
253 buffers
[i
].pitch
= repBuffer
.pitch
;
254 buffers
[i
].cpp
= repBuffer
.cpp
;
255 buffers
[i
].flags
= repBuffer
.flags
;
265 DRI2SwapBuffers(Display
* dpy
, XID drawable
,
266 int x
, int y
, int width
, int height
)
268 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
269 xDRI2SwapBuffersReq
*req
;
270 xDRI2SwapBuffersReply rep
;
272 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
275 GetReq(DRI2SwapBuffers
, req
);
276 req
->reqType
= info
->codes
->major_opcode
;
277 req
->dri2ReqType
= X_DRI2SwapBuffers
;
278 req
->drawable
= drawable
;
282 req
->height
= height
;
284 _XReply(dpy
, (xReply
*) & rep
, 0, xFalse
);
291 DRI2DestroyDrawable(Display
* dpy
, XID drawable
)
293 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
294 xDRI2DestroyDrawableReq
*req
;
296 XextSimpleCheckExtension(dpy
, info
, dri2ExtensionName
);
301 GetReq(DRI2DestroyDrawable
, req
);
302 req
->reqType
= info
->codes
->major_opcode
;
303 req
->dri2ReqType
= X_DRI2DestroyDrawable
;
304 req
->drawable
= drawable
;