From 7e91d041465d46b1b0283146091dc96735edae93 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 30 Jul 2024 17:18:08 -0700 Subject: [PATCH] Update flutter_shell_native_unittests for compatibility with Android API 35 emulators (flutter/engine#54235) Previously this was using a zero EGLConfig handle in tests which use an AndroidContextGLImpeller that creates EGL surfaces. This apparently worked with older emulators, but the API 35 system image requires a real EGLConfig. See https://github.com/flutter/flutter/pull/152498 --- .../android_context_gl_impeller_unittests.cc | 51 ++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/android_context_gl_impeller_unittests.cc b/engine/src/flutter/shell/platform/android/android_context_gl_impeller_unittests.cc index 0a76dd985d..6d8243e8dd 100644 --- a/engine/src/flutter/shell/platform/android/android_context_gl_impeller_unittests.cc +++ b/engine/src/flutter/shell/platform/android/android_context_gl_impeller_unittests.cc @@ -28,14 +28,47 @@ class MockDisplay : public impeller::egl::Display { (ConfigDescriptor), (const, override)); }; + +bool GetEGLConfigForSurface(EGLint surface_bit, EGLConfig* result) { + EGLint attributes[] = { + // clang-format off + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, surface_bit, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_NONE, + // clang-format on + }; + EGLint config_count = 0; + return eglChooseConfig(eglGetDisplay(EGL_DEFAULT_DISPLAY), attributes, result, + 1, &config_count); +} + } // namespace -TEST(AndroidContextGLImpeller, MSAAFirstAttempt) { +class AndroidContextGLImpellerTest : public ::testing::Test { + public: + AndroidContextGLImpellerTest() {} + + void SetUp() override { + EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + ASSERT_TRUE(eglInitialize(egl_display, nullptr, nullptr)); + } +}; + +TEST_F(AndroidContextGLImpellerTest, MSAAFirstAttempt) { + EGLConfig window_egl_config, pbuffer_egl_config; + ASSERT_TRUE(GetEGLConfigForSurface(EGL_WINDOW_BIT, &window_egl_config)); + ASSERT_TRUE(GetEGLConfigForSurface(EGL_PBUFFER_BIT, &pbuffer_egl_config)); + auto display = std::make_unique(); EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true)); - auto first_result = std::make_unique(ConfigDescriptor(), EGLConfig()); + auto first_result = + std::make_unique(ConfigDescriptor(), window_egl_config); auto second_result = - std::make_unique(ConfigDescriptor(), EGLConfig()); + std::make_unique(ConfigDescriptor(), pbuffer_egl_config); EXPECT_CALL( *display, ChooseConfig(Matcher(AllOf( @@ -54,13 +87,18 @@ TEST(AndroidContextGLImpeller, MSAAFirstAttempt) { ASSERT_TRUE(context); } -TEST(AndroidContextGLImpeller, FallbackForEmulator) { +TEST_F(AndroidContextGLImpellerTest, FallbackForEmulator) { + EGLConfig window_egl_config, pbuffer_egl_config; + ASSERT_TRUE(GetEGLConfigForSurface(EGL_WINDOW_BIT, &window_egl_config)); + ASSERT_TRUE(GetEGLConfigForSurface(EGL_PBUFFER_BIT, &pbuffer_egl_config)); + auto display = std::make_unique(); EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true)); std::unique_ptr first_result; auto second_result = - std::make_unique(ConfigDescriptor(), EGLConfig()); - auto third_result = std::make_unique(ConfigDescriptor(), EGLConfig()); + std::make_unique(ConfigDescriptor(), window_egl_config); + auto third_result = + std::make_unique(ConfigDescriptor(), pbuffer_egl_config); EXPECT_CALL( *display, ChooseConfig(Matcher(AllOf( @@ -85,5 +123,6 @@ TEST(AndroidContextGLImpeller, FallbackForEmulator) { std::make_unique(std::move(display), true); ASSERT_TRUE(context); } + } // namespace testing } // namespace flutter