Remove MEDIAPIPE_OMIT_EGL_WINDOW_BIT flag, and autodetect

This commit is contained in:
Will S 2021-12-13 14:57:53 +00:00
parent 98b2d080be
commit 077aad9afd

View File

@ -67,6 +67,23 @@ static void EnsureEglThreadRelease() {
reinterpret_cast<void*>(0xDEADBEEF));
}
static std::array<EGLint, 16> MakeEglConfig(EGLint gl_version, EGLint buffer_type) {
return {
// clang-format off
EGL_RENDERABLE_TYPE, gl_version,
// Allow rendering to pixel buffers or directly to windows.
EGL_SURFACE_TYPE,
buffer_type,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8, // if you need the alpha channel
EGL_DEPTH_SIZE, 16, // if you need the depth buffer
EGL_NONE
// clang-format on
};
}
GlContext::StatusOrGlContext GlContext::Create(std::nullptr_t nullp,
bool create_thread) {
return Create(EGL_NO_CONTEXT, create_thread);
@ -89,35 +106,26 @@ absl::Status GlContext::CreateContextInternal(EGLContext share_context,
int gl_version) {
CHECK(gl_version == 2 || gl_version == 3);
const EGLint config_attr[] = {
// clang-format off
EGL_RENDERABLE_TYPE, gl_version == 3 ? EGL_OPENGL_ES3_BIT_KHR
: EGL_OPENGL_ES2_BIT,
// Allow rendering to pixel buffers or directly to windows.
EGL_SURFACE_TYPE,
#ifdef MEDIAPIPE_OMIT_EGL_WINDOW_BIT
EGL_PBUFFER_BIT,
#else
EGL_WINDOW_BIT,
#endif
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8, // if you need the alpha channel
EGL_DEPTH_SIZE, 16, // if you need the depth buffer
EGL_NONE
// clang-format on
EGLint gl_version_flag = gl_version == 3 ? EGL_OPENGL_ES3_BIT_KHR : EGL_OPENGL_ES2_BIT;
std::vector<std::array<EGLint, 16>> configs{
MakeEglConfig(gl_version_flag, EGL_PBUFFER_BIT),
MakeEglConfig(gl_version_flag, EGL_WINDOW_BIT)
};
// TODO: improve config selection.
EGLint num_configs;
for (auto cfg : configs) {
EGLBoolean success =
eglChooseConfig(display_, config_attr, &config_, 1, &num_configs);
eglChooseConfig(display_, &cfg[0], &config_, 1, &num_configs);
if (!success) {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "eglChooseConfig() returned error " << std::showbase << std::hex
<< eglGetError();
}
if (num_configs) break;
}
if (!num_configs) {
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "eglChooseConfig() returned no matching EGL configuration for "