Skip to content

Commit

Permalink
Don't crash but warn when the scene builder specifies no layers. (flu…
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored Nov 25, 2019
1 parent c0db9aa commit 9f64013
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
12 changes: 12 additions & 0 deletions flow/layers/layer_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ void LayerTree::RecordBuildTime(fml::TimePoint start) {
void LayerTree::Preroll(CompositorContext::ScopedFrame& frame,
bool ignore_raster_cache) {
TRACE_EVENT0("flutter", "LayerTree::Preroll");

if (!root_layer_) {
FML_LOG(ERROR) << "The scene did not specify any layers.";
return;
}

SkColorSpace* color_space =
frame.canvas() ? frame.canvas()->imageInfo().colorSpace() : nullptr;
frame.context().raster_cache().SetCheckboardCacheImages(
Expand Down Expand Up @@ -75,6 +81,12 @@ void LayerTree::UpdateScene(SceneUpdateContext& context,
void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
bool ignore_raster_cache) const {
TRACE_EVENT0("flutter", "LayerTree::Paint");

if (!root_layer_) {
FML_LOG(ERROR) << "The scene did not specify any layers to paint.";
return;
}

SkISize canvas_size = frame.canvas()->getBaseLayerSize();
SkNWayCanvas internal_nodes_canvas(canvas_size.width(), canvas_size.height());
internal_nodes_canvas.addCanvas(frame.canvas());
Expand Down
20 changes: 20 additions & 0 deletions shell/platform/embedder/fixtures/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,23 @@ void platform_view_mutators_with_pixel_ratio() {
};
window.scheduleFrame();
}

@pragma('vm:entry-point')
void empty_scene() {
window.onBeginFrame = (Duration duration) {
window.render(SceneBuilder().build());
signalNativeTest();
};
window.scheduleFrame();
}

@pragma('vm:entry-point')
void scene_with_no_container() {
window.onBeginFrame = (Duration duration) {
SceneBuilder builder = SceneBuilder();
builder.addPicture(Offset(0.0, 0.0), CreateGradientBox(Size(400.0, 300.0)));
window.render(builder.build());
signalNativeTest();
};
window.scheduleFrame();
}
52 changes: 52 additions & 0 deletions shell/platform/embedder/tests/embedder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3499,5 +3499,57 @@ TEST_F(EmbedderTest,
latch.Wait();
}

TEST_F(EmbedderTest, EmptySceneIsAcceptable) {
auto& context = GetEmbedderContext();

EmbedderConfigBuilder builder(context);
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
builder.SetCompositor();
builder.SetDartEntrypoint("empty_scene");
fml::AutoResetWaitableEvent latch;
context.AddNativeCallback(
"SignalNativeTest",
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));

auto engine = builder.LaunchEngine();

ASSERT_TRUE(engine.is_valid());

FlutterWindowMetricsEvent event = {};
event.struct_size = sizeof(event);
event.width = 800;
event.height = 600;
event.pixel_ratio = 1.0;
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
kSuccess);
latch.Wait();
}

TEST_F(EmbedderTest, SceneWithNoRootContainerIsAcceptable) {
auto& context = GetEmbedderContext();

EmbedderConfigBuilder builder(context);
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
builder.SetCompositor();
builder.SetDartEntrypoint("scene_with_no_container");
fml::AutoResetWaitableEvent latch;
context.AddNativeCallback(
"SignalNativeTest",
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));

auto engine = builder.LaunchEngine();

ASSERT_TRUE(engine.is_valid());

FlutterWindowMetricsEvent event = {};
event.struct_size = sizeof(event);
event.width = 800;
event.height = 600;
event.pixel_ratio = 1.0;
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
kSuccess);
latch.Wait();
}

} // namespace testing
} // namespace flutter

0 comments on commit 9f64013

Please sign in to comment.