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) || defined(GLX_USE_APPLE))
25
26 #include "glxclient.h"
27 #include "glx_error.h"
28 #include "mesa_interface.h"
29 #include "dri_util.h"
30 #include "dri_common.h"
31
32 #define __RENDERER(attrib) \
33 { GLX_RENDERER_##attrib##_MESA, __DRI2_RENDERER_##attrib }
34
35 static const struct {
36 unsigned int glx_attrib, dri2_attrib;
37 } query_renderer_map[] = {
38 __RENDERER(VENDOR_ID),
39 __RENDERER(DEVICE_ID),
40 __RENDERER(VERSION),
41 __RENDERER(ACCELERATED),
42 __RENDERER(VIDEO_MEMORY),
43 __RENDERER(UNIFIED_MEMORY_ARCHITECTURE),
44 __RENDERER(PREFERRED_PROFILE),
45 __RENDERER(OPENGL_CORE_PROFILE_VERSION),
46 __RENDERER(OPENGL_COMPATIBILITY_PROFILE_VERSION),
47 __RENDERER(OPENGL_ES_PROFILE_VERSION),
48 __RENDERER(OPENGL_ES2_PROFILE_VERSION),
49 };
50
51 #undef __RENDERER
52
53 static int
dri2_convert_glx_query_renderer_attribs(int attribute)54 dri2_convert_glx_query_renderer_attribs(int attribute)
55 {
56 unsigned i;
57
58 for (i = 0; i < ARRAY_SIZE(query_renderer_map); i++)
59 if (query_renderer_map[i].glx_attrib == attribute)
60 return query_renderer_map[i].dri2_attrib;
61
62 return -1;
63 }
64
65 /* Convert internal dri context profile bits into GLX context profile bits */
66 static inline void
dri_convert_context_profile_bits(int attribute,unsigned int * value)67 dri_convert_context_profile_bits(int attribute, unsigned int *value)
68 {
69 if (attribute == GLX_RENDERER_PREFERRED_PROFILE_MESA) {
70 if (value[0] == (1U << __DRI_API_OPENGL_CORE))
71 value[0] = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
72 else if (value[0] == (1U << __DRI_API_OPENGL))
73 value[0] = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
74 }
75 }
76
77 _X_HIDDEN int
glx_dri_query_renderer_integer(struct glx_screen * base,int attribute,unsigned int * value)78 glx_dri_query_renderer_integer(struct glx_screen *base, int attribute,
79 unsigned int *value)
80 {
81 int ret;
82 /* Even though there are invalid values (and
83 * dri2_convert_glx_query_renderer_attribs may return -1), the higher level
84 * GLX code is required to perform the filtering. Assume that we got a
85 * good value.
86 */
87 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
88
89 ret = dri_query_renderer_integer(base->frontend_screen, dri_attribute, value);
90 dri_convert_context_profile_bits(attribute, value);
91
92 return ret;
93 }
94
95 _X_HIDDEN int
glx_dri_query_renderer_string(struct glx_screen * base,int attribute,const char ** value)96 glx_dri_query_renderer_string(struct glx_screen *base, int attribute,
97 const char **value)
98 {
99 /* Even though queryString only accepts a subset of the possible GLX
100 * queries, the higher level GLX code is required to perform the filtering.
101 * Assume that we got a good value.
102 */
103 const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
104
105 return dri_query_renderer_string(base->frontend_screen, dri_attribute, value);
106 }
107
108 #endif /* GLX_DIRECT_RENDERING */
109