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)); 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, GlContext::StatusOrGlContext GlContext::Create(std::nullptr_t nullp,
bool create_thread) { bool create_thread) {
return Create(EGL_NO_CONTEXT, create_thread); return Create(EGL_NO_CONTEXT, create_thread);
@ -89,35 +106,26 @@ absl::Status GlContext::CreateContextInternal(EGLContext share_context,
int gl_version) { int gl_version) {
CHECK(gl_version == 2 || gl_version == 3); CHECK(gl_version == 2 || gl_version == 3);
const EGLint config_attr[] = { EGLint gl_version_flag = gl_version == 3 ? EGL_OPENGL_ES3_BIT_KHR : EGL_OPENGL_ES2_BIT;
// clang-format off
EGL_RENDERABLE_TYPE, gl_version == 3 ? EGL_OPENGL_ES3_BIT_KHR std::vector<std::array<EGLint, 16>> configs{
: EGL_OPENGL_ES2_BIT, MakeEglConfig(gl_version_flag, EGL_PBUFFER_BIT),
// Allow rendering to pixel buffers or directly to windows. MakeEglConfig(gl_version_flag, EGL_WINDOW_BIT)
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
}; };
// TODO: improve config selection.
EGLint num_configs; EGLint num_configs;
for (auto cfg : configs) {
EGLBoolean success = EGLBoolean success =
eglChooseConfig(display_, config_attr, &config_, 1, &num_configs); eglChooseConfig(display_, &cfg[0], &config_, 1, &num_configs);
if (!success) { if (!success) {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC) return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "eglChooseConfig() returned error " << std::showbase << std::hex << "eglChooseConfig() returned error " << std::showbase << std::hex
<< eglGetError(); << eglGetError();
} }
if (num_configs) break;
}
if (!num_configs) { if (!num_configs) {
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC) return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "eglChooseConfig() returned no matching EGL configuration for " << "eglChooseConfig() returned no matching EGL configuration for "