aboutsummaryrefslogtreecommitdiffstats
path: root/meta-emenlow/recipes-graphics/libva/libva-0.31.0/204_check_ATIFGLEXTENSION.patch
blob: 02920a894471a8117df9b295aa062c8c68713f27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
commit d91645f8b37aa43bafa76da3146dcdc9c17963ff
Author: Gwenole Beauchesne <gbeauchesne@splitted-desktop.com>
Date:   Fri Nov 20 15:51:22 2009 +0000

    Fix detection of fglrx.

diff --git a/src/x11/Makefile.am b/src/x11/Makefile.am
index b6916f2..0b61c33 100644
--- a/src/x11/Makefile.am
+++ b/src/x11/Makefile.am
@@ -25,6 +25,23 @@ noinst_LTLIBRARIES = libva_x11.la
 libva_x11includedir = ${includedir}/va
 libva_x11include_HEADERS = va_x11.h va_dri.h va_dri2.h va_dricommon.h
 
-libva_x11_la_SOURCES = va_x11.c va_dri.c va_dri2.c va_dricommon.c dri2_util.c dri1_util.c va_nvctrl.c libdrm_glue.c
+libva_x11_la_SOURCES =	\
+	dri1_util.c	\
+	dri2_util.c	\
+	libdrm_glue.c	\
+	va_dri.c	\
+	va_dri2.c	\
+	va_dricommon.c	\
+	va_fglext.c	\
+	va_nvctrl.c	\
+	va_x11.c	\
+	$(NULL)
 
-EXTRA_DIST = va_dristr.h va_dri2str.h va_dri2tokens.h va_nvctrl.h libdrm_glue.h
+EXTRA_DIST =		\
+	libdrm_glue.h	\
+	va_dri2str.h	\
+	va_dri2tokens.h	\
+	va_dristr.h	\
+	va_fglext.h	\
+	va_nvctrl.h	\
+	$(NULL)
diff --git a/src/x11/va_fglext.c b/src/x11/va_fglext.c
new file mode 100644
index 0000000..bc58e8b
--- /dev/null
+++ b/src/x11/va_fglext.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2009 Splitted-Desktop Systems. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#define _GNU_SOURCE 1
+#include <string.h>
+
+#define NEED_REPLIES
+#include <stdlib.h>
+#include <X11/Xlibint.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include "va_fglext.h"
+
+#define ATIFGL_EXTENSION_NAME "ATIFGLEXTENSION"
+#define ATIFGL_EXTENSION_EVENTS 0
+
+typedef struct _FGLGetDriverData {
+    CARD8   reqType;
+    CARD8   fireglReqType;
+    CARD16  length B16;
+    CARD32  screen B32;
+    CARD16  size B16;
+    CARD16  pad1;
+} xFGLGetDriverDataReq;
+#define sz_xFGLGetDriverDataReq sizeof(xFGLGetDriverDataReq)
+
+typedef struct {
+    BYTE    type;
+    BYTE    pad1;
+    CARD16  sequenceNumber B16;
+    CARD32  length B32;
+    CARD8   majorVersion;
+    CARD8   minorVersion;
+    CARD8   patchlevel B16;
+    CARD8   BIOSVersionMajor;
+    CARD8   BIOSVersionMinor;
+    CARD8   HasSecondary;
+    CARD16  pad3 B16;
+    CARD32  pad4 B32;
+    CARD32  pad5 B32;
+    CARD32  pad6 B32;
+    CARD32  pad7 B32;
+    // ... there are more fields
+} xFGLGetDriverDataReply;
+#define sz_xFGLGetDriverDataReply sizeof(xFGLGetDriverDataReply)
+
+#define X_FGLGetDriverData 0
+
+static XExtensionInfo _fglext_ext_info_data;
+static XExtensionInfo *fglext_ext_info = &_fglext_ext_info_data;
+static /* const */ char *fglext_extension_name = ATIFGL_EXTENSION_NAME;
+
+#define xFGLCheckExtension(dpy,i,val) \
+  XextCheckExtension (dpy, i, fglext_extension_name, val)
+
+static int close_display();
+static /* const */ XExtensionHooks fglext_extension_hooks = {
+    NULL,                               /* create_gc */
+    NULL,                               /* copy_gc */
+    NULL,                               /* flush_gc */
+    NULL,                               /* free_gc */
+    NULL,                               /* create_font */
+    NULL,                               /* free_font */
+    close_display,                      /* close_display */
+    NULL,                               /* wire_to_event */
+    NULL,                               /* event_to_wire */
+    NULL,                               /* error */
+    NULL,                               /* error_string */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, fglext_ext_info,
+                                   fglext_extension_name, 
+                                   &fglext_extension_hooks,
+                                   ATIFGL_EXTENSION_EVENTS, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, fglext_ext_info)
+
+Bool VA_FGLEXTQueryDirectRenderingCapable( Display *dpy, int screen,
+    Bool *isCapable )
+{
+    char **extensions;
+    int i, n_extensions, has_fglext = 0, has_fglrxdri = 0;
+
+    if (isCapable)
+        *isCapable = False;
+
+    extensions = XListExtensions(dpy, &n_extensions);
+    if (!extensions)
+        return False;
+
+    for (i = 0; i < n_extensions; i++) {
+        if (strcmp(extensions[i], ATIFGL_EXTENSION_NAME) == 0)
+            has_fglext = 1;
+        if (strcmp(extensions[i], "ATIFGLRXDRI") == 0)
+            has_fglrxdri = 1;
+    }
+    XFreeExtensionList(extensions);
+
+    if (!has_fglext)
+        return False;
+
+    if (isCapable)
+        *isCapable = has_fglrxdri;
+
+    return True;
+}
+
+Bool VA_FGLEXTGetClientDriverName( Display *dpy, int screen,
+    int *ddxDriverMajorVersion, int *ddxDriverMinorVersion,
+    int *ddxDriverPatchVersion, char **clientDriverName )
+{
+    XExtDisplayInfo *info = find_display (dpy);
+    xFGLGetDriverDataReply rep;
+    xFGLGetDriverDataReq  *req;
+
+    if (ddxDriverMajorVersion)
+        *ddxDriverMajorVersion = 0;
+    if (ddxDriverMinorVersion)
+        *ddxDriverMinorVersion = 0;
+    if (ddxDriverPatchVersion)
+        *ddxDriverPatchVersion = 0;
+    if (clientDriverName)
+        *clientDriverName = NULL;
+
+    if(!XextHasExtension(info))
+        return False;
+
+    xFGLCheckExtension (dpy, info, False);
+
+    LockDisplay (dpy);
+    GetReq (FGLGetDriverData, req);
+    req->reqType = info->codes->major_opcode;
+    req->fireglReqType = X_FGLGetDriverData;
+    req->screen = screen;
+    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+        UnlockDisplay (dpy);
+        SyncHandle ();
+        return False;
+    }
+    UnlockDisplay (dpy);
+    SyncHandle ();
+
+    if (ddxDriverMajorVersion)
+        *ddxDriverMajorVersion = rep.majorVersion;
+    if (ddxDriverMinorVersion)
+        *ddxDriverMinorVersion = rep.minorVersion;
+    if (ddxDriverPatchVersion)
+        *ddxDriverPatchVersion = rep.patchlevel;
+    if (clientDriverName)
+        *clientDriverName = strdup("fglrx");
+
+    return True;
+}
diff --git a/src/x11/va_fglext.h b/src/x11/va_fglext.h
new file mode 100644
index 0000000..f2d87c3
--- /dev/null
+++ b/src/x11/va_fglext.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 Splitted-Desktop Systems. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef VA_FGLEXTLIB_H
+#define VA_FGLEXTLIB_H
+
+#include <X11/Xlib.h>
+
+Bool VA_FGLEXTQueryDirectRenderingCapable( Display *dpy, int screen,
+    Bool *isCapable );
+
+Bool VA_FGLEXTGetClientDriverName( Display *dpy, int screen,
+    int *ddxDriverMajorVersion, int *ddxDriverMinorVersion,
+    int *ddxDriverPatchVersion, char **clientDriverName );
+
+#endif /* VA_FGLEXTLIB_H */
diff --git a/src/x11/va_x11.c b/src/x11/va_x11.c
index 414c261..0510e00 100644
--- a/src/x11/va_x11.c
+++ b/src/x11/va_x11.c
@@ -31,6 +31,7 @@
 #include "va_dri2.h"
 #include "va_dricommon.h"
 #include "va_nvctrl.h"
+#include "va_fglext.h"
 #include "libdrm_glue.h"
 #include <stdio.h>
 #include <stdarg.h>
@@ -132,6 +133,29 @@ static VAStatus va_NVCTRL_GetDriverName (
     return VA_STATUS_SUCCESS;
 }
 
+static VAStatus va_FGLEXT_GetDriverName(
+    VADisplayContextP pDisplayContext,
+    char **driver_name
+)
+{
+    VADriverContextP ctx = pDisplayContext->pDriverContext;
+    int direct_capable, driver_major, driver_minor, driver_patch;
+    Bool result;
+
+    result = VA_FGLEXTQueryDirectRenderingCapable(ctx->x11_dpy, ctx->x11_screen,
+                                                  &direct_capable);
+    if (!result || !direct_capable)
+        return VA_STATUS_ERROR_UNKNOWN;
+
+    result = VA_FGLEXTGetClientDriverName(ctx->x11_dpy, ctx->x11_screen,
+                                          &driver_major, &driver_minor,
+                                          &driver_patch, driver_name);
+    if (!result)
+        return VA_STATUS_ERROR_UNKNOWN;
+
+    return VA_STATUS_SUCCESS;
+}
+
 static VAStatus va_DisplayContextGetDriverName (
     VADisplayContextP pDisplayContext,
     char **driver_name
@@ -156,7 +180,8 @@ static VAStatus va_DisplayContextGetDriverName (
         vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
     if (vaStatus != VA_STATUS_SUCCESS)
         vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
-   
+    if (vaStatus != VA_STATUS_SUCCESS)
+        vaStatus = va_FGLEXT_GetDriverName(pDisplayContext, driver_name);
     return vaStatus;
 }