From fd3bfb778d8a792cd3a0d03d3baad39e9d465e7a Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Thu, 27 Oct 2022 23:18:46 +0000 Subject: [PATCH] EGLWindow: workaround eglQueryString behavior before Android 10 EGL_NO_DISPLAY + EGL_EXTENSIONS returns NULL before angle support introduced in Android 10. See aosp/760681 for the reference. Bug: b/255844932 Test: build and run angle trace on Android Pie Change-Id: I23a8236cbd220ce34ebbcc602d6ced351fc76619 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3988422 Reviewed-by: Cody Northrop Commit-Queue: Cody Northrop --- util/EGLWindow.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/EGLWindow.cpp b/util/EGLWindow.cpp index 7e31463a0..21383a5d5 100644 --- a/util/EGLWindow.cpp +++ b/util/EGLWindow.cpp @@ -178,8 +178,14 @@ bool EGLWindow::initializeDisplay(OSWindow *osWindow, LoadUtilEGL(getProcAddress); #endif // defined(ANGLE_USE_UTIL_LOADER) + // EGL_NO_DISPLAY + EGL_EXTENSIONS returns NULL before Android 10 const char *extensionString = static_cast(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS)); + if (!extensionString) + { + // fallback to an empty string for strstr + extensionString = ""; + } std::vector displayAttributes; displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE); @@ -879,10 +885,11 @@ void EGLWindow::Delete(EGLWindow **window) void EGLWindow::queryFeatures() { + // EGL_NO_DISPLAY + EGL_EXTENSIONS returns NULL before Android 10 const char *extensionString = static_cast(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS)); const bool hasFeatureControlANGLE = - strstr(extensionString, "EGL_ANGLE_feature_control") != nullptr; + extensionString && strstr(extensionString, "EGL_ANGLE_feature_control") != nullptr; if (!hasFeatureControlANGLE) {