/* * Compile: * gcc egl-glx-driver-bug33758.c -lEGL -o egl-glx * */ #include #include struct egl_test { EGLDisplay edpy; EGLContext egl_context; void *egl_config; EGLSurface egl_surface; }; static int get_display (struct egl_test *test) { EGLBoolean status; EGLint major, minor; test->edpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (test->edpy == EGL_NO_DISPLAY) return -1; status = eglInitialize (test->edpy, &major, &minor); if (status != EGL_TRUE) return -2; return 0; } static int make_dummy_surface (struct egl_test *test) { static const EGLint attrs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, // EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_NONE }; EGLint num_configs; eglGetConfigs(test->edpy, &test->egl_config, 1, &num_configs); if (num_configs < 1) return -1; test->egl_surface = eglCreatePbufferSurface(test->edpy, test->egl_config, attrs); if (test->egl_surface == EGL_NO_SURFACE) return -2; return 0; } static int create_context (struct egl_test *test) { static const EGLint *attribs = NULL; test->egl_context = eglCreateContext (test->edpy, test->egl_config, EGL_NO_CONTEXT, attribs); if (test->egl_context == EGL_NO_CONTEXT) return -1; if (!eglMakeCurrent(test->edpy, test->egl_surface, test->egl_surface, test->egl_context)) return -2; return 0; } static int teardown (struct egl_test *test) { if (!eglDestroyContext(test->edpy, test->egl_context)) return -1; if (!eglDestroySurface(test->edpy, test->egl_surface)) return -2; if (!eglMakeCurrent(test->edpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) return -3; if (!eglTerminate(test->edpy)) return -4; return 0; } int main(int argc, char **argv) { struct egl_test test; if (setenv("EGL_DRIVER", "egl_glx", /*overwrite=*/ 1) < 0) return 1; if (get_display(&test) < 0) return 2; eglBindAPI(EGL_OPENGL_API); if (make_dummy_surface(&test) < 0) return 3; if (create_context(&test) < 0) return 4; if (teardown(&test) < 0) return 5; return 0; }