Skip to content

Instantly share code, notes, and snippets.

@jlHertel
Created September 1, 2019 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlHertel/0ec9b8ef1da0e314e0cef0cc18d4c83b to your computer and use it in GitHub Desktop.
Save jlHertel/0ec9b8ef1da0e314e0cef0cc18d4c83b to your computer and use it in GitHub Desktop.
Test availability of MESA_query_driver with different platforms
// Compile with g++ -o gbm_test.bin gbm_test.cpp -lgbm -lGL -lEGL -I/usr/include/libdrm -I/usr/include/EGL -ldrm
#include <iostream>
#include <xf86drm.h>
#include <fcntl.h>
#include <gbm.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <drm.h>
#include <string>
typedef const char *eglGetDisplayDriverName_t(EGLDisplay disp);
typedef const char *eglGetDisplayDriverconfig_t(EGLDisplay disp);
int main() {
EGLint major = 0, minor = 0;
EGLBoolean binded = eglBindAPI(EGL_OPENGL_API);
if (!binded) {
std::cout << "Failed to bind EGL API" << std::endl;
return 0;
}
auto driverName = (eglGetDisplayDriverName_t *) eglGetProcAddress("eglGetDisplayDriverName");
auto driverConfig = (eglGetDisplayDriverconfig_t *) eglGetProcAddress("eglGetDisplayDriverConfig");
EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (eglDpy == EGL_NO_DISPLAY) {
std::cout << "Failed to get display" << std::endl;
return 1;
}
EGLBoolean initialized = eglInitialize(eglDpy, &major, &minor);
if (initialized == EGL_FALSE) {
std::cout << "Failed to initialize EGL" << std::endl;
return 1;
}
const char *extensions = eglQueryString(eglDpy, EGL_EXTENSIONS);
std::string extStr(extensions);
std::size_t found = extStr.find("EGL_MESA_query_driver");
if (found == std::string::npos) {
std::cout << "Extension EGL_MESA_query_driver missing!" << std::endl;
std::cout << "Available extensions: " << extensions << std::endl;
return 1;
}
std::cout << "Extension EGL_MESA_query_driver found!" << std::endl;
std::cout << "Querying driver name..." << std::endl;
const char *name = (* driverName) (eglDpy);
if (name != nullptr) {
std::cout << "Driver is named " << name << std::endl;
}
std::cout << "Querying driver config..." << std::endl;
const char *configsFound = (* driverConfig) (eglDpy);
if (configsFound != nullptr) {
std::cout << "Driver has the configs: ";
std::cout << configsFound << std::endl;
}
eglTerminate(eglDpy);
return 0;
}
@jlHertel
Copy link
Author

jlHertel commented Sep 1, 2019

Executing with EGL_PLATFORM=x11 ./gbm_test.bin works as expected and the extension EGL_MESA_query_driver is available.
Executing with EGL_PLATFORM=gbm ./gbm_test.bin fails, saying that the extension is not available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment