Skip to content

Commit

Permalink
Do not rasterize wrong size layer tree after viewport metrics change
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp committed Sep 15, 2020
1 parent 9bbd42b commit 9dab1f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 15 additions & 3 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,12 @@ void Shell::OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) {
engine->SetViewportMetrics(metrics);
}
});

{
std::scoped_lock<std::mutex> lock(resize_mutex_);
expected_frame_size_ =
SkISize::Make(metrics.physical_width, metrics.physical_height);
}
}

// |PlatformView::Delegate|
Expand Down Expand Up @@ -1021,13 +1027,19 @@ void Shell::OnAnimatorDraw(fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline,
}
}

auto discard_callback = [this](flutter::LayerTree& tree) {
std::scoped_lock<std::mutex> lock(resize_mutex_);
return !expected_frame_size_.isEmpty() &&
tree.frame_size() != expected_frame_size_;
};

task_runners_.GetRasterTaskRunner()->PostTask(
[&waiting_for_first_frame = waiting_for_first_frame_,
&waiting_for_first_frame_condition = waiting_for_first_frame_condition_,
rasterizer = rasterizer_->GetWeakPtr(),
pipeline = std::move(pipeline)]() {
rasterizer = rasterizer_->GetWeakPtr(), pipeline = std::move(pipeline),
discard_callback = std::move(discard_callback)]() {
if (rasterizer) {
rasterizer->Draw(pipeline);
rasterizer->Draw(pipeline, std::move(discard_callback));

if (waiting_for_first_frame.load()) {
waiting_for_first_frame.store(false);
Expand Down
7 changes: 7 additions & 0 deletions shell/common/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ class Shell final : public PlatformView::Delegate,
// and read from the raster thread.
std::atomic<float> display_refresh_rate_ = 0.0f;

// protects expected_frame_size_ which is set on platform thread and read on
// raster thread
std::mutex resize_mutex_;

// used to discard wrong size layer tree produced during interactive resizing
SkISize expected_frame_size_ = SkISize::MakeEmpty();

// How many frames have been timed since last report.
size_t UnreportedFramesCount() const;

Expand Down

0 comments on commit 9dab1f2

Please sign in to comment.