Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ RasterStatus Rasterizer::Draw(
delegate_.GetTaskRunners().GetRasterTaskRunner()->PostTask(
fml::MakeCopyable(
[weak_this = weak_factory_.GetWeakPtr(), pipeline,
resubmit_recorder = std::move(resubmit_recorder)]() mutable {
resubmit_recorder = std::move(resubmit_recorder),
discardCallback = std::move(discardCallback)]() mutable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Here and elsewhere, can we underscore case this before landing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (weak_this) {
weak_this->Draw(std::move(resubmit_recorder), pipeline);
weak_this->Draw(std::move(resubmit_recorder), pipeline,
std::move(discardCallback));
}
}));
break;
Expand Down
91 changes: 91 additions & 0 deletions shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,97 @@ TEST_F(ShellTest, DiscardLayerTreeOnResize) {
DestroyShell(std::move(shell));
}

TEST_F(ShellTest, DiscardResubmittedLayerTreeOnResize) {
auto settings = CreateSettingsForFixture();

SkISize origin_size = SkISize::Make(400, 100);
SkISize new_size = SkISize::Make(400, 200);

fml::AutoResetWaitableEvent end_frame_latch;

fml::AutoResetWaitableEvent resize_latch;

std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger_ref;
auto end_frame_callback =
[&](bool should_merge_thread,
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) {
if (!raster_thread_merger_ref) {
raster_thread_merger_ref = raster_thread_merger;
}
if (should_merge_thread) {
// TODO(cyanglaz): This test used external_view_embedder so we need to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think comment is related.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// merge the threads here. However, the scenario it is testing is
// unrelated to platform views. We should consider to update this test
// so it doesn't require external_view_embedder.
// https://github.com/flutter/flutter/issues/69895
raster_thread_merger->MergeWithLease(10);
external_view_embedder->UpdatePostPrerollResult(
PostPrerollResult::kSuccess);
}
end_frame_latch.Signal();

if (should_merge_thread) {
resize_latch.Wait();
}
};

external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
std::move(end_frame_callback), PostPrerollResult::kResubmitFrame, true);

std::unique_ptr<Shell> shell = CreateShell(
settings, GetTaskRunnersForFixture(), false, external_view_embedder);

// Create the surface needed by rasterizer
PlatformViewNotifyCreated(shell.get());

fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetPlatformTaskRunner(),
[&shell, &origin_size]() {
shell->GetPlatformView()->SetViewportMetrics(
{1.0, static_cast<double>(origin_size.width()),
static_cast<double>(origin_size.height()), 22});
});

auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("emptyMain");

RunEngine(shell.get(), std::move(configuration));

PumpOneFrame(shell.get(), static_cast<double>(origin_size.width()),
static_cast<double>(origin_size.height()));

end_frame_latch.Wait();
ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());

fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetPlatformTaskRunner(),
[&shell, &new_size, &resize_latch]() {
shell->GetPlatformView()->SetViewportMetrics(
{1.0, static_cast<double>(new_size.width()),
static_cast<double>(new_size.height()), 22});
resize_latch.Signal();
});

end_frame_latch.Wait();

// The frame resubmitted with origin size should be discarded after the
// viewport metrics changed.
ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());

// Threads will be merged at the end of this frame.
PumpOneFrame(shell.get(), static_cast<double>(new_size.width()),
static_cast<double>(new_size.height()));

end_frame_latch.Wait();
ASSERT_TRUE(raster_thread_merger_ref->IsMerged());
ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount());
ASSERT_EQ(new_size, external_view_embedder->GetLastSubmittedFrameSize());

PlatformViewNotifyDestroyed(shell.get());
DestroyShell(std::move(shell));
}

TEST_F(ShellTest, IgnoresInvalidMetrics) {
fml::AutoResetWaitableEvent latch;
double last_device_pixel_ratio;
Expand Down