eb5884aba638f65de548d2f46c6090757a3846c1
[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
35 #define __RENDERER(attrib) \
36 { GLX_RENDERER_##attrib##_MESA, __DRI2_RENDERER_##attrib }
37
38 static const struct {
39 unsigned int glx_attrib, dri2_attrib;
40 } query_renderer_map[] = {
41 __RENDERER(VENDOR_ID),
42 __RENDERER(DEVICE_ID),
43 __RENDERER(VERSION),
44 __RENDERER(ACCELERATED),
45 __RENDERER(VIDEO_MEMORY),
46 __RENDERER(UNIFIED_MEMORY_ARCHITECTURE),
47 __RENDERER(PREFERRED_PROFILE),
48 __RENDERER(OPENGL_CORE_PROFILE_VERSION),
49 __RENDERER(OPENGL_COMPATIBILITY_PROFILE_VERSION),
50 __RENDERER(OPENGL_ES_PROFILE_VERSION),
51 __RENDERER(OPENGL_ES2_PROFILE_VERSION),
52 };
53
54 #undef __RENDERER
55
56 static int
57 dri2_convert_glx_query_renderer_attribs(int attribute)
58 {
59 int i;
60
61 for (i = 0; i < ARRAY_SIZE(query_renderer_map); i++)
62 if (query_renderer_map[i].glx_attrib == attribute)
63 return query_renderer_map[i].dri2_attrib;
64
65 return -1;
66 }
67
68 _X_HIDDEN int
69 dri2_query_renderer_integer(struct glx_screen *base, int attribute,
70 unsigned int *value)
71 {
72 struct dri2_screen *const psc = (struct dri2_screen *) base;
73
74 /* Even though there are invalid values (and
75 * dri2_convert_glx_query_renderer_attribs may return -1), the higher level
76 * GLX code is required to perform the filtering. Assume that we got a
77 * good value.
78 */
79 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
80
81 if (psc->rendererQuery == NULL)
82 return -1;
83
84 return psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,
85 value);
86 }
87
88 _X_HIDDEN int
89 dri2_query_renderer_string(struct glx_screen *base, int attribute,
90 const char **value)
91 {
92 struct dri2_screen *const psc = (struct dri2_screen *) base;
93
94 /* Even though queryString only accepts a subset of the possible GLX
95 * queries, the higher level GLX code is required to perform the filtering.
96 * Assume that we got a good value.
97 */
98 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
99
100 if (psc->rendererQuery == NULL)
101 return -1;
102
103 return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);
104 }
105
106 #if defined(HAVE_DRI3)
107 _X_HIDDEN int
108 dri3_query_renderer_integer(struct glx_screen *base, int attribute,
109 unsigned int *value)
110 {
111 struct dri3_screen *const psc = (struct dri3_screen *) base;
112
113 /* Even though there are invalid values (and
114 * dri2_convert_glx_query_renderer_attribs may return -1), the higher level
115 * GLX code is required to perform the filtering. Assume that we got a
116 * good value.
117 */
118 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
119
120 if (psc->rendererQuery == NULL)
121 return -1;
122
123 return psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,
124 value);
125 }
126
127 _X_HIDDEN int
128 dri3_query_renderer_string(struct glx_screen *base, int attribute,
129 const char **value)
130 {
131 struct dri3_screen *const psc = (struct dri3_screen *) base;
132
133 /* Even though queryString only accepts a subset of the possible GLX
134 * queries, the higher level GLX code is required to perform the filtering.
135 * Assume that we got a good value.
136 */
137 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
138
139 if (psc->rendererQuery == NULL)
140 return -1;
141
142 return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);
143 }
144 #endif /* HAVE_DRI3 */
145
146 #endif /* GLX_DIRECT_RENDERING */