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
;
45 static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay
, dri2Info
)
46 static /* const */ XExtensionHooks dri2ExtensionHooks
= {
51 NULL
, /* create_font */
53 DRI2CloseDisplay
, /* close_display */
54 NULL
, /* wire_to_event */
55 NULL
, /* event_to_wire */
57 NULL
, /* error_string */
60 static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay
, dri2Info
,
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
;
78 Bool
DRI2QueryVersion(Display
*dpy
, int *major
, int *minor
)
80 XExtDisplayInfo
*info
= DRI2FindDisplay (dpy
);
81 xDRI2QueryVersionReply rep
;
82 xDRI2QueryVersionReq
*req
;
84 XextCheckExtension (dpy
, info
, dri2ExtensionName
, False
);
87 GetReq(DRI2QueryVersion
, req
);
88 req
->reqType
= info
->codes
->major_opcode
;
89 req
->dri2ReqType
= X_DRI2QueryVersion
;
90 req
->majorVersion
= DRI2_MAJOR
;
91 req
->minorVersion
= DRI2_MINOR
;
92 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
97 *major
= rep
.majorVersion
;
98 *minor
= rep
.minorVersion
;
105 Bool
DRI2Connect(Display
*dpy
, XID window
,
106 char **driverName
, char **deviceName
)
108 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
109 xDRI2ConnectReply rep
;
110 xDRI2ConnectReq
*req
;
112 XextCheckExtension (dpy
, info
, dri2ExtensionName
, False
);
115 GetReq(DRI2Connect
, req
);
116 req
->reqType
= info
->codes
->major_opcode
;
117 req
->dri2ReqType
= X_DRI2Connect
;
118 req
->window
= window
;
119 req
->driverType
= DRI2DriverDRI
;
120 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
126 if (rep
.driverNameLength
== 0 && rep
.deviceNameLength
== 0) {
132 *driverName
= Xmalloc(rep
.driverNameLength
+ 1);
133 if (*driverName
== NULL
) {
135 ((rep
.driverNameLength
+ 3) & ~3) +
136 ((rep
.deviceNameLength
+ 3) & ~3));
141 _XReadPad(dpy
, *driverName
, rep
.driverNameLength
);
142 (*driverName
)[rep
.driverNameLength
] = '\0';
144 *deviceName
= Xmalloc(rep
.deviceNameLength
+ 1);
145 if (*deviceName
== NULL
) {
147 _XEatData(dpy
, ((rep
.deviceNameLength
+ 3) & ~3));
152 _XReadPad(dpy
, *deviceName
, rep
.deviceNameLength
);
153 (*deviceName
)[rep
.deviceNameLength
] = '\0';
161 Bool
DRI2Authenticate(Display
*dpy
, XID window
, drm_magic_t magic
)
163 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
164 xDRI2AuthenticateReq
*req
;
165 xDRI2AuthenticateReply rep
;
167 XextCheckExtension (dpy
, info
, dri2ExtensionName
, False
);
170 GetReq(DRI2Authenticate
, req
);
171 req
->reqType
= info
->codes
->major_opcode
;
172 req
->dri2ReqType
= X_DRI2Authenticate
;
173 req
->window
= window
;
176 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
185 return rep
.authenticated
;
188 void DRI2CreateDrawable(Display
*dpy
, XID drawable
)
190 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
191 xDRI2CreateDrawableReq
*req
;
193 XextSimpleCheckExtension (dpy
, info
, dri2ExtensionName
);
196 GetReq(DRI2CreateDrawable
, req
);
197 req
->reqType
= info
->codes
->major_opcode
;
198 req
->dri2ReqType
= X_DRI2CreateDrawable
;
199 req
->drawable
= drawable
;
204 void DRI2DestroyDrawable(Display
*dpy
, XID drawable
)
206 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
207 xDRI2DestroyDrawableReq
*req
;
209 XextSimpleCheckExtension (dpy
, info
, dri2ExtensionName
);
214 GetReq(DRI2DestroyDrawable
, req
);
215 req
->reqType
= info
->codes
->major_opcode
;
216 req
->dri2ReqType
= X_DRI2DestroyDrawable
;
217 req
->drawable
= drawable
;
222 DRI2Buffer
*DRI2GetBuffers(Display
*dpy
, XID drawable
,
223 int *width
, int *height
,
224 unsigned int *attachments
, int count
,
227 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
228 xDRI2GetBuffersReply rep
;
229 xDRI2GetBuffersReq
*req
;
231 xDRI2Buffer repBuffer
;
235 XextCheckExtension (dpy
, info
, dri2ExtensionName
, False
);
238 GetReqExtra(DRI2GetBuffers
, count
* 4, req
);
239 req
->reqType
= info
->codes
->major_opcode
;
240 req
->dri2ReqType
= X_DRI2GetBuffers
;
241 req
->drawable
= drawable
;
243 p
= (CARD32
*) &req
[1];
244 for (i
= 0; i
< count
; i
++)
245 p
[i
] = attachments
[i
];
247 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
254 *height
= rep
.height
;
255 *outCount
= rep
.count
;
257 buffers
= Xmalloc(count
* sizeof buffers
[0]);
258 if (buffers
== NULL
) {
259 _XEatData(dpy
, rep
.count
* sizeof repBuffer
);
265 for (i
= 0; i
< rep
.count
; i
++) {
266 _XReadPad(dpy
, (char *) &repBuffer
, sizeof repBuffer
);
267 buffers
[i
].attachment
= repBuffer
.attachment
;
268 buffers
[i
].name
= repBuffer
.name
;
269 buffers
[i
].pitch
= repBuffer
.pitch
;
270 buffers
[i
].cpp
= repBuffer
.cpp
;
271 buffers
[i
].flags
= repBuffer
.flags
;
280 void DRI2CopyRegion(Display
*dpy
, XID drawable
, XserverRegion region
,
281 CARD32 dest
, CARD32 src
)
283 XExtDisplayInfo
*info
= DRI2FindDisplay(dpy
);
284 xDRI2CopyRegionReq
*req
;
285 xDRI2CopyRegionReply rep
;
287 XextSimpleCheckExtension (dpy
, info
, dri2ExtensionName
);
290 GetReq(DRI2CopyRegion
, req
);
291 req
->reqType
= info
->codes
->major_opcode
;
292 req
->dri2ReqType
= X_DRI2CopyRegion
;
293 req
->drawable
= drawable
;
294 req
->region
= region
;
299 _XReply(dpy
, (xReply
*)&rep
, 0, xFalse
);