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>
40 #include "va_dri2str.h"
41 #include "va_dri2tokens.h"
44 #define DRI2DriverDRI 0
47 static char va_dri2ExtensionName[] = DRI2_NAME;
48 static XExtensionInfo _va_dri2_info_data;
49 static XExtensionInfo *va_dri2Info = &_va_dri2_info_data;
50 static XEXT_GENERATE_CLOSE_DISPLAY (VA_DRI2CloseDisplay, va_dri2Info)
51 static /* const */ XExtensionHooks va_dri2ExtensionHooks = {
56 NULL, /* create_font */
58 VA_DRI2CloseDisplay, /* close_display */
59 NULL, /* wire_to_event */
60 NULL, /* event_to_wire */
62 NULL, /* error_string */
65 static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay, va_dri2Info,
67 &va_dri2ExtensionHooks,
70 Bool VA_DRI2QueryExtension(Display *dpy, int *eventBase, int *errorBase)
72 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
74 if (XextHasExtension(info)) {
75 *eventBase = info->codes->first_event;
76 *errorBase = info->codes->first_error;
83 Bool VA_DRI2QueryVersion(Display *dpy, int *major, int *minor)
85 XExtDisplayInfo *info = DRI2FindDisplay (dpy);
86 xDRI2QueryVersionReply rep;
87 xDRI2QueryVersionReq *req;
89 XextCheckExtension (dpy, info, va_dri2ExtensionName, False);
92 GetReq(DRI2QueryVersion, req);
93 req->reqType = info->codes->major_opcode;
94 req->dri2ReqType = X_DRI2QueryVersion;
95 req->majorVersion = DRI2_MAJOR;
96 req->minorVersion = DRI2_MINOR;
97 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
102 *major = rep.majorVersion;
103 *minor = rep.minorVersion;
110 Bool VA_DRI2Connect(Display *dpy, XID window,
111 char **driverName, char **deviceName)
113 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
114 xDRI2ConnectReply rep;
115 xDRI2ConnectReq *req;
117 XextCheckExtension (dpy, info, va_dri2ExtensionName, False);
120 GetReq(DRI2Connect, req);
121 req->reqType = info->codes->major_opcode;
122 req->dri2ReqType = X_DRI2Connect;
123 req->window = window;
124 req->driverType = DRI2DriverDRI;
125 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
131 if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) {
137 *driverName = Xmalloc(rep.driverNameLength + 1);
138 if (*driverName == NULL) {
140 ((rep.driverNameLength + 3) & ~3) +
141 ((rep.deviceNameLength + 3) & ~3));
146 _XReadPad(dpy, *driverName, rep.driverNameLength);
147 (*driverName)[rep.driverNameLength] = '\0';
149 *deviceName = Xmalloc(rep.deviceNameLength + 1);
150 if (*deviceName == NULL) {
152 _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3));
157 _XReadPad(dpy, *deviceName, rep.deviceNameLength);
158 (*deviceName)[rep.deviceNameLength] = '\0';
166 Bool VA_DRI2Authenticate(Display *dpy, XID window, drm_magic_t magic)
168 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
169 xDRI2AuthenticateReq *req;
170 xDRI2AuthenticateReply rep;
172 XextCheckExtension (dpy, info, va_dri2ExtensionName, False);
175 GetReq(DRI2Authenticate, req);
176 req->reqType = info->codes->major_opcode;
177 req->dri2ReqType = X_DRI2Authenticate;
178 req->window = window;
181 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
190 return rep.authenticated;
193 void VA_DRI2CreateDrawable(Display *dpy, XID drawable)
195 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
196 xDRI2CreateDrawableReq *req;
198 XextSimpleCheckExtension (dpy, info, va_dri2ExtensionName);
201 GetReq(DRI2CreateDrawable, req);
202 req->reqType = info->codes->major_opcode;
203 req->dri2ReqType = X_DRI2CreateDrawable;
204 req->drawable = drawable;
209 void VA_DRI2DestroyDrawable(Display *dpy, XID drawable)
211 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
212 xDRI2DestroyDrawableReq *req;
214 XextSimpleCheckExtension (dpy, info, va_dri2ExtensionName);
219 GetReq(DRI2DestroyDrawable, req);
220 req->reqType = info->codes->major_opcode;
221 req->dri2ReqType = X_DRI2DestroyDrawable;
222 req->drawable = drawable;
227 VA_DRI2Buffer *VA_DRI2GetBuffers(Display *dpy, XID drawable,
228 int *width, int *height,
229 unsigned int *attachments, int count,
232 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
233 xDRI2GetBuffersReply rep;
234 xDRI2GetBuffersReq *req;
235 VA_DRI2Buffer *buffers;
236 xDRI2Buffer repBuffer;
240 XextCheckExtension (dpy, info, va_dri2ExtensionName, False);
243 GetReqExtra(DRI2GetBuffers, count * 4, req);
244 req->reqType = info->codes->major_opcode;
245 req->dri2ReqType = X_DRI2GetBuffers;
246 req->drawable = drawable;
248 p = (CARD32 *) &req[1];
249 for (i = 0; i < count; i++)
250 p[i] = attachments[i];
252 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
259 *height = rep.height;
260 *outCount = rep.count;
262 buffers = Xmalloc(rep.count * sizeof buffers[0]);
263 if (buffers == NULL) {
264 _XEatData(dpy, rep.count * sizeof repBuffer);
270 for (i = 0; i < rep.count; i++) {
271 _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
272 buffers[i].attachment = repBuffer.attachment;
273 buffers[i].name = repBuffer.name;
274 buffers[i].pitch = repBuffer.pitch;
275 buffers[i].cpp = repBuffer.cpp;
276 buffers[i].flags = repBuffer.flags;
285 void VA_DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region,
286 CARD32 dest, CARD32 src)
288 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
289 xDRI2CopyRegionReq *req;
290 xDRI2CopyRegionReply rep;
292 XextSimpleCheckExtension (dpy, info, va_dri2ExtensionName);
295 GetReq(DRI2CopyRegion, req);
296 req->reqType = info->codes->major_opcode;
297 req->dri2ReqType = X_DRI2CopyRegion;
298 req->drawable = drawable;
299 req->region = region;
303 _XReply(dpy, (xReply *)&rep, 0, xFalse);