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

Commit 41d39f7

Browse files
committed
Make the GL context current in EmbedderSurfaceGLImpeller before creating the GPU surface
The GPUSurfaceGLImpeller ctor creates an AiksContext/ContentContext, which loads the shader pipelines. If the current thread does not have a GL context and can not execute ReactorGLES operations, then the pipeline futures will not complete. This can cause the raster thread to hang if the reactor has not run and the futures are still incomplete when a rendering task later needs to obtain the pipeline.
1 parent 3557277 commit 41d39f7

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

shell/platform/embedder/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ test_fixtures("fixtures") {
242242
"fixtures/dpr_noxform.png",
243243
"fixtures/dpr_xform.png",
244244
"fixtures/gradient.png",
245-
"fixtures/impeller_gl_gradient.png",
245+
"fixtures/impeller_gl_test.png",
246246
"fixtures/vk_dpr_noxform.png",
247247
"fixtures/vk_gradient.png",
248248
"fixtures/gradient_metal.png",

shell/platform/embedder/embedder_surface_gl_impeller.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ EmbedderSurfaceGLImpeller::GLContextFramebufferInfo() const {
178178

179179
// |EmbedderSurface|
180180
std::unique_ptr<Surface> EmbedderSurfaceGLImpeller::CreateGPUSurface() {
181+
// Ensure that the GL context is current before creating the GPU surface.
182+
// GPUSurfaceGLImpeller initialization will set up shader pipelines, and the
183+
// current thread needs to be able to execute reactor operations.
184+
GLContextMakeCurrent();
185+
181186
return std::make_unique<GPUSurfaceGLImpeller>(
182187
this, // GPU surface GL delegate
183188
impeller_context_, // Impeller context
Binary file not shown.
Loading

shell/platform/embedder/fixtures/main.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,3 +1364,21 @@ void render_gradient_retained() {
13641364
};
13651365
PlatformDispatcher.instance.scheduleFrame();
13661366
}
1367+
1368+
@pragma('vm:entry-point')
1369+
void render_impeller_gl_test() {
1370+
PlatformDispatcher.instance.onBeginFrame = (Duration duration) {
1371+
final SceneBuilder builder = SceneBuilder();
1372+
builder.pushOffset(0.0, 0.0);
1373+
final Paint paint = Paint();
1374+
paint.color = Color.fromARGB(255, 0, 0, 255);
1375+
final PictureRecorder baseRecorder = PictureRecorder();
1376+
final Canvas canvas = Canvas(baseRecorder);
1377+
canvas.drawPaint(Paint()..color = Color.fromARGB(255, 255, 0, 0));
1378+
canvas.drawRect(Rect.fromLTRB(20.0, 20.0, 200.0, 150.0), paint);
1379+
builder.addPicture(Offset.zero, baseRecorder.endRecording());
1380+
builder.pop();
1381+
PlatformDispatcher.instance.views.first.render(builder.build());
1382+
};
1383+
PlatformDispatcher.instance.scheduleFrame();
1384+
}

shell/platform/embedder/tests/embedder_gl_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4711,7 +4711,7 @@ TEST_F(EmbedderTest, CanRenderWithImpellerOpenGL) {
47114711
});
47124712

47134713
builder.AddCommandLineArgument("--enable-impeller");
4714-
builder.SetDartEntrypoint("render_gradient");
4714+
builder.SetDartEntrypoint("render_impeller_gl_test");
47154715
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
47164716
builder.SetCompositor();
47174717
builder.SetRenderTargetType(
@@ -4733,7 +4733,7 @@ TEST_F(EmbedderTest, CanRenderWithImpellerOpenGL) {
47334733

47344734
ASSERT_TRUE(ImageMatchesFixture(
47354735
FixtureNameForBackend(EmbedderTestContextType::kOpenGLContext,
4736-
"impeller_gl_gradient.png"),
4736+
"impeller_gl_test.png"),
47374737
rendered_scene));
47384738

47394739
// The scene will be rendered by the compositor, and the surface present

0 commit comments

Comments
 (0)