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"
42 static char va_dri2ExtensionName[] = DRI2_NAME;
43 static XExtensionInfo _va_dri2_info_data;
44 static XExtensionInfo *va_dri2Info = &_va_dri2_info_data;
45 static XEXT_GENERATE_CLOSE_DISPLAY (VA_DRI2CloseDisplay, va_dri2Info)
46 static /* const */ XExtensionHooks va_dri2ExtensionHooks = {
51 NULL, /* create_font */
53 VA_DRI2CloseDisplay, /* close_display */
54 NULL, /* wire_to_event */
55 NULL, /* event_to_wire */
57 NULL, /* error_string */
60 static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay, va_dri2Info,
62 &va_dri2ExtensionHooks,
65 Bool VA_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 VA_DRI2QueryVersion(Display *dpy, int *major, int *minor)
80 XExtDisplayInfo *info = DRI2FindDisplay (dpy);
81 xDRI2QueryVersionReply rep;
82 xDRI2QueryVersionReq *req;
84 XextCheckExtension (dpy, info, va_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 VA_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, va_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 VA_DRI2Authenticate(Display *dpy, XID window, drm_magic_t magic)
163 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
164 xDRI2AuthenticateReq *req;
165 xDRI2AuthenticateReply rep;
167 XextCheckExtension (dpy, info, va_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 VA_DRI2CreateDrawable(Display *dpy, XID drawable)
190 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
191 xDRI2CreateDrawableReq *req;
193 XextSimpleCheckExtension (dpy, info, va_dri2ExtensionName);
196 GetReq(DRI2CreateDrawable, req);
197 req->reqType = info->codes->major_opcode;
198 req->dri2ReqType = X_DRI2CreateDrawable;
199 req->drawable = drawable;
204 void VA_DRI2DestroyDrawable(Display *dpy, XID drawable)
206 XExtDisplayInfo *info = DRI2FindDisplay(dpy);
207 xDRI2DestroyDrawableReq *req;
209 XextSimpleCheckExtension (dpy, info, va_dri2ExtensionName);
214 GetReq(DRI2DestroyDrawable, req);
215 req->reqType = info->codes->major_opcode;
216 req->dri2ReqType = X_DRI2DestroyDrawable;
217 req->drawable = drawable;
222 VA_DRI2Buffer *VA_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;
230 VA_DRI2Buffer *buffers;
231 xDRI2Buffer repBuffer;
235 XextCheckExtension (dpy, info, va_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(rep.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 VA_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, va_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;
298 _XReply(dpy, (xReply *)&rep, 0, xFalse);