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

Commit 28603f1

Browse files
committed
Only one draw call needs to be active on the raster task runner.
1 parent 3d9b581 commit 28603f1

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

shell/common/rasterizer.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,6 @@ void Rasterizer::Draw(std::shared_ptr<LayerTreeHolder> layer_tree_holder,
196196
raster_thread_merger_);
197197
}
198198

199-
// Note: This behaviour is left as-is to be inline with the pipeline
200-
// semantics. TODO(kaushikiska): explore removing this block.
201-
if (!layer_tree_holder->IsEmpty()) {
202-
delegate_.GetTaskRunners().GetRasterTaskRunner()->PostTask(
203-
[weak_this = weak_factory_.GetWeakPtr(), layer_tree_holder]() {
204-
if (weak_this) {
205-
weak_this->Draw(layer_tree_holder);
206-
}
207-
});
208-
}
209199
}
210200

211201
namespace {

shell/common/shell.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ Shell::Shell(DartVMRef vm,
372372
vm_(std::move(vm)),
373373
is_gpu_disabled_sync_switch_(new fml::SyncSwitch(is_gpu_disabled)),
374374
volatile_path_tracker_(std::move(volatile_path_tracker)),
375+
pending_draw_semaphore_(1),
375376
weak_factory_gpu_(nullptr),
376377
weak_factory_(this) {
377378
FML_CHECK(vm_) << "Must have access to VM to create a shell.";
@@ -1158,8 +1159,15 @@ void Shell::OnAnimatorDraw(std::shared_ptr<LayerTreeHolder> layer_tree_holder,
11581159
tree.frame_size() != expected_frame_size_;
11591160
};
11601161

1162+
if (!pending_draw_semaphore_.TryWait()) {
1163+
// Multiple calls to OnAnimatorDraw will still result in a
1164+
// single request to the Rasterizer::Draw.
1165+
return;
1166+
}
1167+
11611168
task_runners_.GetRasterTaskRunner()->PostTask(
1162-
[&waiting_for_first_frame = waiting_for_first_frame_,
1169+
[&pending_draw_semaphore = pending_draw_semaphore_,
1170+
&waiting_for_first_frame = waiting_for_first_frame_,
11631171
&waiting_for_first_frame_condition = waiting_for_first_frame_condition_,
11641172
rasterizer = rasterizer_->GetWeakPtr(),
11651173
discard_callback = std::move(discard_callback),
@@ -1172,6 +1180,7 @@ void Shell::OnAnimatorDraw(std::shared_ptr<LayerTreeHolder> layer_tree_holder,
11721180
waiting_for_first_frame_condition.notify_all();
11731181
}
11741182
}
1183+
pending_draw_semaphore.Signal();
11751184
});
11761185
}
11771186

shell/common/shell.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ class Shell final : public PlatformView::Delegate,
385385
std::mutex waiting_for_first_frame_mutex_;
386386
std::condition_variable waiting_for_first_frame_condition_;
387387

388+
// Signalled when draw task on the raster thread is complete.
389+
fml::Semaphore pending_draw_semaphore_;
390+
388391
// Written in the UI thread and read from the raster thread. Hence make it
389392
// atomic.
390393
std::atomic<bool> needs_report_timings_{false};

0 commit comments

Comments
 (0)