This commit is contained in:
Will Stott 2022-03-08 14:35:57 -03:00 committed by GitHub
commit e487fc2ca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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_PBUFFER_BIT | 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 "
@ -170,13 +178,6 @@ absl::Status GlContext::CreateContext(EGLContext share_context) {
}
MP_RETURN_IF_ERROR(status);
EGLint pbuffer_attr[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
surface_ = eglCreatePbufferSurface(display_, config_, pbuffer_attr);
RET_CHECK(surface_ != EGL_NO_SURFACE)
<< "eglCreatePbufferSurface() returned error " << std::showbase
<< std::hex << eglGetError();
return absl::OkStatus();
}