Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1ba8fc0

Browse files
authored
Fix GetImpellerContext for ShellTestPlatformViewGL (#49337)
I tried to do this for Vulkan too but hit the limit of my patience for today on debugging why the Vulkan backend was segfaulting on shutdown. Half of flutter/flutter#140419
1 parent 6f77dc7 commit 1ba8fc0

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

shell/common/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ if (enable_unittests) {
262262
"//flutter/third_party/rapidjson",
263263
]
264264

265+
if (impeller_supports_rendering) {
266+
deps += [ "//flutter/impeller" ]
267+
}
268+
265269
public_configs = [
266270
":shell_test_fixture_sources_config",
267271
":shell_unittests_gpu_configuration_config",

shell/common/shell_test_platform_view_gl.cc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,30 @@
66

77
#include <utility>
88

9+
#include <EGL/egl.h>
10+
911
#include "flutter/shell/gpu/gpu_surface_gl_skia.h"
12+
#include "impeller/entity/gles/entity_shaders_gles.h"
13+
14+
#if IMPELLER_ENABLE_3D
15+
#include "impeller/scene/shaders/gles/scene_shaders_gles.h" // nogncheck
16+
#endif
1017

1118
namespace flutter {
1219
namespace testing {
1320

21+
static std::vector<std::shared_ptr<fml::Mapping>> ShaderLibraryMappings() {
22+
return {
23+
std::make_shared<fml::NonOwnedMapping>(
24+
impeller_entity_shaders_gles_data,
25+
impeller_entity_shaders_gles_length),
26+
#if IMPELLER_ENABLE_3D
27+
std::make_shared<fml::NonOwnedMapping>(
28+
impeller_scene_shaders_gles_data, impeller_scene_shaders_gles_length),
29+
#endif
30+
};
31+
}
32+
1433
ShellTestPlatformViewGL::ShellTestPlatformViewGL(
1534
PlatformView::Delegate& delegate,
1635
const TaskRunners& task_runners,
@@ -23,7 +42,23 @@ ShellTestPlatformViewGL::ShellTestPlatformViewGL(
2342
create_vsync_waiter_(std::move(create_vsync_waiter)),
2443
vsync_clock_(std::move(vsync_clock)),
2544
shell_test_external_view_embedder_(
26-
std::move(shell_test_external_view_embedder)) {}
45+
std::move(shell_test_external_view_embedder)) {
46+
if (GetSettings().enable_impeller) {
47+
auto resolver = [](const char* name) -> void* {
48+
return reinterpret_cast<void*>(::eglGetProcAddress(name));
49+
};
50+
// ANGLE needs this to initialize version strings checked by
51+
// impeller::ProcTableGLES.
52+
gl_surface_.MakeCurrent();
53+
auto gl = std::make_unique<impeller::ProcTableGLES>(resolver);
54+
if (!gl->IsValid()) {
55+
FML_LOG(ERROR) << "Proc table when a shell unittests invalid.";
56+
return;
57+
}
58+
impeller_context_ = impeller::ContextGLES::Create(
59+
std::move(gl), ShaderLibraryMappings(), true);
60+
}
61+
}
2762

2863
ShellTestPlatformViewGL::~ShellTestPlatformViewGL() = default;
2964

shell/common/shell_test_platform_view_gl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "flutter/shell/common/shell_test_platform_view.h"
1010
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
1111
#include "flutter/testing/test_gl_surface.h"
12+
#include "impeller/renderer/backend/gles/context_gles.h"
1213

1314
namespace flutter {
1415
namespace testing {
@@ -29,7 +30,14 @@ class ShellTestPlatformViewGL : public ShellTestPlatformView,
2930
// |ShellTestPlatformView|
3031
virtual void SimulateVSync() override;
3132

33+
// |PlatformView|
34+
std::shared_ptr<impeller::Context> GetImpellerContext() const {
35+
return impeller_context_;
36+
}
37+
3238
private:
39+
std::shared_ptr<impeller::ContextGLES> impeller_context_;
40+
3341
TestGLSurface gl_surface_;
3442

3543
CreateVsyncWaiter create_vsync_waiter_;

shell/common/shell_unittests.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4597,9 +4597,7 @@ TEST_F(ShellTest, RuntimeStageBackendDefaultsToSkSLWithoutImpeller) {
45974597
DestroyShell(std::move(shell), task_runners);
45984598
}
45994599

4600-
// TODO(dnfield): Enable GL and Vulkan after
4601-
// https://github.com/flutter/flutter/issues/140419
4602-
#if SHELL_ENABLE_METAL
4600+
#if IMPELLER_SUPPORTS_RENDERING
46034601
TEST_F(ShellTest, RuntimeStageBackendWithImpeller) {
46044602
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
46054603
Settings settings = CreateSettingsForFixture();
@@ -4653,7 +4651,7 @@ TEST_F(ShellTest, RuntimeStageBackendWithImpeller) {
46534651

46544652
DestroyShell(std::move(shell), task_runners);
46554653
}
4656-
#endif // SHELL_ENABLE_METAL
4654+
#endif // IMPELLER_SUPPORTS_RENDERING
46574655

46584656
} // namespace testing
46594657
} // namespace flutter

0 commit comments

Comments
 (0)