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
This commit is contained in:
Jason Simmons
2024-07-30 17:18:08 -07:00
committed by GitHub
parent b5c7bfdb41
commit 7e91d04146

View File

@@ -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<MockDisplay>();
EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true));
auto first_result = std::make_unique<Config>(ConfigDescriptor(), EGLConfig());
auto first_result =
std::make_unique<Config>(ConfigDescriptor(), window_egl_config);
auto second_result =
std::make_unique<Config>(ConfigDescriptor(), EGLConfig());
std::make_unique<Config>(ConfigDescriptor(), pbuffer_egl_config);
EXPECT_CALL(
*display,
ChooseConfig(Matcher<ConfigDescriptor>(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<MockDisplay>();
EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true));
std::unique_ptr<Config> first_result;
auto second_result =
std::make_unique<Config>(ConfigDescriptor(), EGLConfig());
auto third_result = std::make_unique<Config>(ConfigDescriptor(), EGLConfig());
std::make_unique<Config>(ConfigDescriptor(), window_egl_config);
auto third_result =
std::make_unique<Config>(ConfigDescriptor(), pbuffer_egl_config);
EXPECT_CALL(
*display,
ChooseConfig(Matcher<ConfigDescriptor>(AllOf(
@@ -85,5 +123,6 @@ TEST(AndroidContextGLImpeller, FallbackForEmulator) {
std::make_unique<AndroidContextGLImpeller>(std::move(display), true);
ASSERT_TRUE(context);
}
} // namespace testing
} // namespace flutter