[Impeller] Disable layer tree screenshots. (flutter/engine#46171)

The "rasterizer screenshot" VM service API uses the Skia software backend, even when running with impeller. At best, this leads to confusing half working screenshots that are missing images.

See https://github.com/flutter/flutter/issues/135052

We should disable this functionality when running with impeller. Perhaps this could be reworked to use picture toImage instead of the offscreen so that it uses the "real" backend regardless of the platform it is running on.

Fixes https://github.com/flutter/flutter/issues/135052
This commit is contained in:
Jonah Williams
2023-10-26 13:16:09 -07:00
committed by GitHub
parent 6ef260d4b5
commit 912c891a1d
2 changed files with 56 additions and 0 deletions

View File

@@ -876,6 +876,11 @@ Rasterizer::Screenshot Rasterizer::ScreenshotLastLayerTree(
return {};
}
// Impeller does not support this screenshot type.
if (surface_->GetAiksContext()) {
return {};
}
sk_sp<SkData> data = nullptr;
std::string format;

View File

@@ -2207,6 +2207,57 @@ TEST_F(ShellTest, Screenshot) {
DestroyShell(std::move(shell));
}
// Only supported on macOS hosts as a real metal surface needs to be created.
#if defined(FML_OS_MACOSX)
TEST_F(ShellTest, ScreenshotImpeller) {
auto settings = CreateSettingsForFixture();
settings.enable_impeller = true;
fml::AutoResetWaitableEvent firstFrameLatch;
settings.frame_rasterized_callback =
[&firstFrameLatch](const FrameTiming& t) { firstFrameLatch.Signal(); };
std::unique_ptr<Shell> shell = CreateShell({
.settings = settings,
.platform_view_create_callback = ShellTestPlatformViewBuilder({
.rendering_backend =
ShellTestPlatformView::BackendType::kMetalBackend,
}),
});
// Create the surface needed by rasterizer
PlatformViewNotifyCreated(shell.get());
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("emptyMain");
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
PumpOneFrame(shell.get(), 100, 100, builder);
firstFrameLatch.Wait();
std::promise<Rasterizer::Screenshot> screenshot_promise;
auto screenshot_future = screenshot_promise.get_future();
fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetRasterTaskRunner(),
[&screenshot_promise, &shell]() {
auto rasterizer = shell->GetRasterizer();
screenshot_promise.set_value(rasterizer->ScreenshotLastLayerTree(
Rasterizer::ScreenshotType::CompressedImage, false));
});
ASSERT_EQ(screenshot_future.get().data, nullptr);
DestroyShell(std::move(shell));
}
#endif
TEST_F(ShellTest, CanConvertToAndFromMappings) {
const size_t buffer_size = 2 << 20;