Path: blob/21.2-virgl/src/glx/dri_common_query_renderer.c
4558 views
/*1* Copyright © 2013 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*/2223#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)2425#include "glxclient.h"26#include "glx_error.h"27#include "GL/internal/dri_interface.h"28#include "dri2_priv.h"29#if defined(HAVE_DRI3)30#include "dri3_priv.h"31#endif32#include "drisw_priv.h"3334#define __RENDERER(attrib) \35{ GLX_RENDERER_##attrib##_MESA, __DRI2_RENDERER_##attrib }3637static const struct {38unsigned int glx_attrib, dri2_attrib;39} query_renderer_map[] = {40__RENDERER(VENDOR_ID),41__RENDERER(DEVICE_ID),42__RENDERER(VERSION),43__RENDERER(ACCELERATED),44__RENDERER(VIDEO_MEMORY),45__RENDERER(UNIFIED_MEMORY_ARCHITECTURE),46__RENDERER(PREFERRED_PROFILE),47__RENDERER(OPENGL_CORE_PROFILE_VERSION),48__RENDERER(OPENGL_COMPATIBILITY_PROFILE_VERSION),49__RENDERER(OPENGL_ES_PROFILE_VERSION),50__RENDERER(OPENGL_ES2_PROFILE_VERSION),51};5253#undef __RENDERER5455static int56dri2_convert_glx_query_renderer_attribs(int attribute)57{58unsigned i;5960for (i = 0; i < ARRAY_SIZE(query_renderer_map); i++)61if (query_renderer_map[i].glx_attrib == attribute)62return query_renderer_map[i].dri2_attrib;6364return -1;65}6667/* Convert internal dri context profile bits into GLX context profile bits */68static inline void69dri_convert_context_profile_bits(int attribute, unsigned int *value)70{71if (attribute == GLX_RENDERER_PREFERRED_PROFILE_MESA) {72if (value[0] == (1U << __DRI_API_OPENGL_CORE))73value[0] = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;74else if (value[0] == (1U << __DRI_API_OPENGL))75value[0] = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;76}77}7879_X_HIDDEN int80dri2_query_renderer_integer(struct glx_screen *base, int attribute,81unsigned int *value)82{83int ret;84struct dri2_screen *const psc = (struct dri2_screen *) base;8586/* Even though there are invalid values (and87* dri2_convert_glx_query_renderer_attribs may return -1), the higher level88* GLX code is required to perform the filtering. Assume that we got a89* good value.90*/91const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);9293if (psc->rendererQuery == NULL)94return -1;9596ret = psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,97value);98dri_convert_context_profile_bits(attribute, value);99100return ret;101}102103_X_HIDDEN int104dri2_query_renderer_string(struct glx_screen *base, int attribute,105const char **value)106{107struct dri2_screen *const psc = (struct dri2_screen *) base;108109/* Even though queryString only accepts a subset of the possible GLX110* queries, the higher level GLX code is required to perform the filtering.111* Assume that we got a good value.112*/113const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);114115if (psc->rendererQuery == NULL)116return -1;117118return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);119}120121#if defined(HAVE_DRI3)122_X_HIDDEN int123dri3_query_renderer_integer(struct glx_screen *base, int attribute,124unsigned int *value)125{126int ret;127struct dri3_screen *const psc = (struct dri3_screen *) base;128129/* Even though there are invalid values (and130* dri2_convert_glx_query_renderer_attribs may return -1), the higher level131* GLX code is required to perform the filtering. Assume that we got a132* good value.133*/134const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);135136if (psc->rendererQuery == NULL)137return -1;138139ret = psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,140value);141dri_convert_context_profile_bits(attribute, value);142143return ret;144}145146_X_HIDDEN int147dri3_query_renderer_string(struct glx_screen *base, int attribute,148const char **value)149{150struct dri3_screen *const psc = (struct dri3_screen *) base;151152/* Even though queryString only accepts a subset of the possible GLX153* queries, the higher level GLX code is required to perform the filtering.154* Assume that we got a good value.155*/156const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);157158if (psc->rendererQuery == NULL)159return -1;160161return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);162}163#endif /* HAVE_DRI3 */164165_X_HIDDEN int166drisw_query_renderer_integer(struct glx_screen *base, int attribute,167unsigned int *value)168{169int ret;170struct drisw_screen *const psc = (struct drisw_screen *) base;171172/* Even though there are invalid values (and173* dri2_convert_glx_query_renderer_attribs may return -1), the higher level174* GLX code is required to perform the filtering. Assume that we got a175* good value.176*/177const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);178179if (psc->rendererQuery == NULL)180return -1;181182ret = psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,183value);184dri_convert_context_profile_bits(attribute, value);185186return ret;187}188189_X_HIDDEN int190drisw_query_renderer_string(struct glx_screen *base, int attribute,191const char **value)192{193struct drisw_screen *const psc = (struct drisw_screen *) base;194195/* Even though queryString only accepts a subset of the possible GLX196* queries, the higher level GLX code is required to perform the filtering.197* Assume that we got a good value.198*/199const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);200201if (psc->rendererQuery == NULL)202return -1;203204return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);205}206207208#endif /* GLX_DIRECT_RENDERING */209210211