247ec1ca6bdc651087900e18eb7459e4a687f935
[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
24 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
25
26 #include "glxclient.h"
27 #include "glx_error.h"
28 #include "dri2.h"
29 #include "dri_interface.h"
30 #include "dri2_priv.h"
31 #if defined(HAVE_DRI3)
32 #include "dri3_priv.h"
33 #endif
34 #include "drisw_priv.h"
35
36 #define __RENDERER(attrib) \
37 { GLX_RENDERER_##attrib##_MESA, __DRI2_RENDERER_##attrib }
38
39 static const struct {
40 unsigned int glx_attrib, dri2_attrib;
41 } query_renderer_map[] = {
42 __RENDERER(VENDOR_ID),
43 __RENDERER(DEVICE_ID),
44 __RENDERER(VERSION),
45 __RENDERER(ACCELERATED),
46 __RENDERER(VIDEO_MEMORY),
47 __RENDERER(UNIFIED_MEMORY_ARCHITECTURE),
48 __RENDERER(PREFERRED_PROFILE),
49 __RENDERER(OPENGL_CORE_PROFILE_VERSION),
50 __RENDERER(OPENGL_COMPATIBILITY_PROFILE_VERSION),
51 __RENDERER(OPENGL_ES_PROFILE_VERSION),
52 __RENDERER(OPENGL_ES2_PROFILE_VERSION),
53 };
54
55 #undef __RENDERER
56
57 static int
58 dri2_convert_glx_query_renderer_attribs(int attribute)
59 {
60 int i;
61
62 for (i = 0; i < ARRAY_SIZE(query_renderer_map); i++)
63 if (query_renderer_map[i].glx_attrib == attribute)
64 return query_renderer_map[i].dri2_attrib;
65
66 return -1;
67 }
68
69 _X_HIDDEN int
70 dri2_query_renderer_integer(struct glx_screen *base, int attribute,
71 unsigned int *value)
72 {
73 struct dri2_screen *const psc = (struct dri2_screen *) base;
74
75 /* Even though there are invalid values (and
76 * dri2_convert_glx_query_renderer_attribs may return -1), the higher level
77 * GLX code is required to perform the filtering. Assume that we got a
78 * good value.
79 */
80 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
81
82 if (psc->rendererQuery == NULL)
83 return -1;
84
85 return psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,
86 value);
87 }
88
89 _X_HIDDEN int
90 dri2_query_renderer_string(struct glx_screen *base, int attribute,
91 const char **value)
92 {
93 struct dri2_screen *const psc = (struct dri2_screen *) base;
94
95 /* Even though queryString only accepts a subset of the possible GLX
96 * queries, the higher level GLX code is required to perform the filtering.
97 * Assume that we got a good value.
98 */
99 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
100
101 if (psc->rendererQuery == NULL)
102 return -1;
103
104 return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);
105 }
106
107 #if defined(HAVE_DRI3)
108 _X_HIDDEN int
109 dri3_query_renderer_integer(struct glx_screen *base, int attribute,
110 unsigned int *value)
111 {
112 struct dri3_screen *const psc = (struct dri3_screen *) base;
113
114 /* Even though there are invalid values (and
115 * dri2_convert_glx_query_renderer_attribs may return -1), the higher level
116 * GLX code is required to perform the filtering. Assume that we got a
117 * good value.
118 */
119 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
120
121 if (psc->rendererQuery == NULL)
122 return -1;
123
124 return psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,
125 value);
126 }
127
128 _X_HIDDEN int
129 dri3_query_renderer_string(struct glx_screen *base, int attribute,
130 const char **value)
131 {
132 struct dri3_screen *const psc = (struct dri3_screen *) base;
133
134 /* Even though queryString only accepts a subset of the possible GLX
135 * queries, the higher level GLX code is required to perform the filtering.
136 * Assume that we got a good value.
137 */
138 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
139
140 if (psc->rendererQuery == NULL)
141 return -1;
142
143 return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);
144 }
145 #endif /* HAVE_DRI3 */
146
147 _X_HIDDEN int
148 drisw_query_renderer_integer(struct glx_screen *base, int attribute,
149 unsigned int *value)
150 {
151 struct drisw_screen *const psc = (struct drisw_screen *) base;
152
153 /* Even though there are invalid values (and
154 * dri2_convert_glx_query_renderer_attribs may return -1), the higher level
155 * GLX code is required to perform the filtering. Assume that we got a
156 * good value.
157 */
158 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
159
160 if (psc->rendererQuery == NULL)
161 return -1;
162
163 return psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,
164 value);
165 }
166
167 _X_HIDDEN int
168 drisw_query_renderer_string(struct glx_screen *base, int attribute,
169 const char **value)
170 {
171 struct drisw_screen *const psc = (struct drisw_screen *) base;
172
173 /* Even though queryString only accepts a subset of the possible GLX
174 * queries, the higher level GLX code is required to perform the filtering.
175 * Assume that we got a good value.
176 */
177 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
178
179 if (psc->rendererQuery == NULL)
180 return -1;
181
182 return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);
183 }
184
185
186 #endif /* GLX_DIRECT_RENDERING */