glx/dri2: Add DRI2 support for GLX_MESA_query_renderer
[mesa.git] / src / glx / dri2_query_renderer.c
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23 #include "glxclient.h"
24 #include "glx_error.h"
25 #include "xf86drm.h"
26 #include "dri2.h"
27 #include "dri_interface.h"
28 #include "dri2_priv.h"
29
30 static int
31 dri2_convert_glx_query_renderer_attribs(int attribute)
32 {
33 switch (attribute) {
34 case GLX_RENDERER_VENDOR_ID_MESA:
35 return __DRI2_RENDERER_VENDOR_ID;
36 case GLX_RENDERER_DEVICE_ID_MESA:
37 return __DRI2_RENDERER_DEVICE_ID;
38 case GLX_RENDERER_VERSION_MESA:
39 return __DRI2_RENDERER_VERSION;
40 case GLX_RENDERER_ACCELERATED_MESA:
41 return __DRI2_RENDERER_ACCELERATED;
42 case GLX_RENDERER_VIDEO_MEMORY_MESA:
43 return __DRI2_RENDERER_VIDEO_MEMORY;
44 case GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA:
45 return __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE;
46 case GLX_RENDERER_PREFERRED_PROFILE_MESA:
47 return __DRI2_RENDERER_PREFERRED_PROFILE;
48 case GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA:
49 return __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION;
50 case GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA:
51 return __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION;
52 case GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA:
53 return __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION;
54 case GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA:
55 return __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION;
56 default:
57 return -1;
58 }
59 }
60
61 _X_HIDDEN int
62 dri2_query_renderer_integer(struct glx_screen *base, int attribute,
63 unsigned int *value)
64 {
65 struct dri2_screen *const psc = (struct dri2_screen *) base;
66
67 /* Even though there are invalid values (and
68 * dri2_convert_glx_query_renderer_attribs may return -1), the higher level
69 * GLX code is required to perform the filtering. Assume that we got a
70 * good value.
71 */
72 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
73
74 if (psc->rendererQuery == NULL)
75 return -1;
76
77 return psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,
78 value);
79 }
80
81 _X_HIDDEN int
82 dri2_query_renderer_string(struct glx_screen *base, int attribute,
83 const char **value)
84 {
85 struct dri2_screen *const psc = (struct dri2_screen *) base;
86
87 /* Even though queryString only accepts a subset of the possible GLX
88 * queries, the higher level GLX code is required to perform the filtering.
89 * Assume that we got a good value.
90 */
91 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
92
93 if (psc->rendererQuery == NULL)
94 return -1;
95
96 return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);
97 }