1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2013 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci#include "glxclient.h" 24bf215546Sopenharmony_ci#include "glx_error.h" 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include <assert.h> 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_cistatic Bool 29bf215546Sopenharmony_ci__glXQueryRendererInteger(struct glx_screen *psc, int attribute, 30bf215546Sopenharmony_ci unsigned int *value) 31bf215546Sopenharmony_ci{ 32bf215546Sopenharmony_ci unsigned int values_for_query = 0; 33bf215546Sopenharmony_ci unsigned int buffer[32]; 34bf215546Sopenharmony_ci int err; 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci /* This probably means the caller is trying to use an extension function 37bf215546Sopenharmony_ci * that isn't actually supported. 38bf215546Sopenharmony_ci */ 39bf215546Sopenharmony_ci if (psc->vtable->query_renderer_integer == NULL) 40bf215546Sopenharmony_ci return False; 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci switch (attribute) { 43bf215546Sopenharmony_ci case GLX_RENDERER_VENDOR_ID_MESA: 44bf215546Sopenharmony_ci case GLX_RENDERER_DEVICE_ID_MESA: 45bf215546Sopenharmony_ci values_for_query = 1; 46bf215546Sopenharmony_ci break; 47bf215546Sopenharmony_ci case GLX_RENDERER_VERSION_MESA: 48bf215546Sopenharmony_ci values_for_query = 3; 49bf215546Sopenharmony_ci break; 50bf215546Sopenharmony_ci case GLX_RENDERER_ACCELERATED_MESA: 51bf215546Sopenharmony_ci case GLX_RENDERER_VIDEO_MEMORY_MESA: 52bf215546Sopenharmony_ci case GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA: 53bf215546Sopenharmony_ci case GLX_RENDERER_PREFERRED_PROFILE_MESA: 54bf215546Sopenharmony_ci values_for_query = 1; 55bf215546Sopenharmony_ci break; 56bf215546Sopenharmony_ci case GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA: 57bf215546Sopenharmony_ci case GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA: 58bf215546Sopenharmony_ci case GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA: 59bf215546Sopenharmony_ci case GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA: 60bf215546Sopenharmony_ci values_for_query = 2; 61bf215546Sopenharmony_ci break; 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci default: 64bf215546Sopenharmony_ci return False; 65bf215546Sopenharmony_ci } 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci err = psc->vtable->query_renderer_integer(psc, attribute, buffer); 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci /* If there was no error, copy the correct number of values from the driver 70bf215546Sopenharmony_ci * out to the application. 71bf215546Sopenharmony_ci */ 72bf215546Sopenharmony_ci if (err == 0) 73bf215546Sopenharmony_ci memcpy(value, buffer, sizeof(unsigned int) * values_for_query); 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci return err == 0; 76bf215546Sopenharmony_ci} 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci_X_HIDDEN Bool 79bf215546Sopenharmony_ciglXQueryRendererIntegerMESA(Display *dpy, int screen, 80bf215546Sopenharmony_ci int renderer, int attribute, 81bf215546Sopenharmony_ci unsigned int *value) 82bf215546Sopenharmony_ci{ 83bf215546Sopenharmony_ci struct glx_screen *psc; 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci if (dpy == NULL) 86bf215546Sopenharmony_ci return False; 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci /* This probably means the caller passed the wrong display pointer or 89bf215546Sopenharmony_ci * screen number. 90bf215546Sopenharmony_ci */ 91bf215546Sopenharmony_ci psc = GetGLXScreenConfigs(dpy, screen); 92bf215546Sopenharmony_ci if (psc == NULL) 93bf215546Sopenharmony_ci return False; 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci /* Right now only a single renderer per display / screen combination is 96bf215546Sopenharmony_ci * supported. 97bf215546Sopenharmony_ci */ 98bf215546Sopenharmony_ci if (renderer != 0) 99bf215546Sopenharmony_ci return False; 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci return __glXQueryRendererInteger(psc, attribute, value); 102bf215546Sopenharmony_ci} 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci_X_HIDDEN Bool 105bf215546Sopenharmony_ciglXQueryCurrentRendererIntegerMESA(int attribute, unsigned int *value) 106bf215546Sopenharmony_ci{ 107bf215546Sopenharmony_ci struct glx_context *gc = __glXGetCurrentContext(); 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci if (gc == &dummyContext) 110bf215546Sopenharmony_ci return False; 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci return __glXQueryRendererInteger(gc->psc, attribute, value); 113bf215546Sopenharmony_ci} 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_cistatic const char * 116bf215546Sopenharmony_ci__glXQueryRendererString(struct glx_screen *psc, int attribute) 117bf215546Sopenharmony_ci{ 118bf215546Sopenharmony_ci const char *value; 119bf215546Sopenharmony_ci int err; 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci /* This probably means the caller is trying to use an extension function 122bf215546Sopenharmony_ci * that isn't actually supported. 123bf215546Sopenharmony_ci */ 124bf215546Sopenharmony_ci if (psc->vtable->query_renderer_integer == NULL) 125bf215546Sopenharmony_ci return NULL; 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci switch (attribute) { 128bf215546Sopenharmony_ci case GLX_RENDERER_VENDOR_ID_MESA: 129bf215546Sopenharmony_ci case GLX_RENDERER_DEVICE_ID_MESA: 130bf215546Sopenharmony_ci break; 131bf215546Sopenharmony_ci default: 132bf215546Sopenharmony_ci return NULL; 133bf215546Sopenharmony_ci } 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci err = psc->vtable->query_renderer_string(psc, attribute, &value); 136bf215546Sopenharmony_ci return (err == 0) ? value : NULL; 137bf215546Sopenharmony_ci} 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci_X_HIDDEN const char * 140bf215546Sopenharmony_ciglXQueryRendererStringMESA(Display *dpy, int screen, 141bf215546Sopenharmony_ci int renderer, int attribute) 142bf215546Sopenharmony_ci{ 143bf215546Sopenharmony_ci struct glx_screen *psc; 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_ci if (dpy == NULL) 146bf215546Sopenharmony_ci return NULL; 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci /* This probably means the caller passed the wrong display pointer or 149bf215546Sopenharmony_ci * screen number. 150bf215546Sopenharmony_ci */ 151bf215546Sopenharmony_ci psc = GetGLXScreenConfigs(dpy, screen); 152bf215546Sopenharmony_ci if (psc == NULL) 153bf215546Sopenharmony_ci return NULL; 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ci /* Right now only a single renderer per display / screen combination is 156bf215546Sopenharmony_ci * supported. 157bf215546Sopenharmony_ci */ 158bf215546Sopenharmony_ci if (renderer != 0) 159bf215546Sopenharmony_ci return NULL; 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci return __glXQueryRendererString(psc, attribute); 162bf215546Sopenharmony_ci} 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci_X_HIDDEN const char * 165bf215546Sopenharmony_ciglXQueryCurrentRendererStringMESA(int attribute) 166bf215546Sopenharmony_ci{ 167bf215546Sopenharmony_ci struct glx_context *gc = __glXGetCurrentContext(); 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci if (gc == &dummyContext) 170bf215546Sopenharmony_ci return NULL; 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci return __glXQueryRendererString(gc->psc, attribute); 173bf215546Sopenharmony_ci} 174