-
Notifications
You must be signed in to change notification settings - Fork 6k
Ensure threads are merged when tearing down the Rasterizer #19919
Changes from 1 commit
f31e62f
54c8447
a9214c2
55f758d
c197572
edd4dfd
11e014c
2b8f977
cdbee3d
292a647
9863985
0c6e1c3
b4a37cb
566d3da
b104fcd
72049f3
bbb0210
5d60a2e
5471a38
f0aa0a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,55 +262,42 @@ TEST(RasterThreadMerger, WaitUntilMerged) { | |
| thread_raster.join(); | ||
| } | ||
|
|
||
| TEST(RasterThreadMerger, WaitUntilMergedReturnsIfAlreadyMerged) { | ||
| fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger; | ||
|
|
||
| fml::AutoResetWaitableEvent thread_merged_latch; | ||
| fml::MessageLoop* loop_platform = nullptr; | ||
| fml::AutoResetWaitableEvent latch_platform; | ||
| fml::AutoResetWaitableEvent term_platform; | ||
| fml::AutoResetWaitableEvent latch_wait_until_merged; | ||
| std::thread thread_platform([&]() { | ||
| TEST(RasterThreadMerger, HandleTaskQueuesAreTheSame) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: missing checks for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should make |
||
| fml::MessageLoop* loop1 = nullptr; | ||
| fml::AutoResetWaitableEvent latch1; | ||
| fml::AutoResetWaitableEvent term1; | ||
| std::thread thread1([&loop1, &latch1, &term1]() { | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
| loop_platform = &fml::MessageLoop::GetCurrent(); | ||
| latch_platform.Signal(); | ||
| thread_merged_latch.Wait(); | ||
| raster_thread_merger->WaitUntilMerged(); | ||
| latch_wait_until_merged.Signal(); | ||
| term_platform.Wait(); | ||
| loop1 = &fml::MessageLoop::GetCurrent(); | ||
| latch1.Signal(); | ||
| term1.Wait(); | ||
| }); | ||
|
|
||
| const int kNumFramesMerged = 5; | ||
| fml::MessageLoop* loop_raster = nullptr; | ||
| fml::AutoResetWaitableEvent term_raster; | ||
| std::thread thread_raster([&]() { | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
| loop_raster = &fml::MessageLoop::GetCurrent(); | ||
| latch_platform.Wait(); | ||
| fml::TaskQueueId qid_platform = | ||
| loop_platform->GetTaskRunner()->GetTaskQueueId(); | ||
| fml::TaskQueueId qid_raster = | ||
| loop_raster->GetTaskRunner()->GetTaskQueueId(); | ||
| raster_thread_merger = | ||
| fml::MakeRefCounted<fml::RasterThreadMerger>(qid_platform, qid_raster); | ||
| ASSERT_FALSE(raster_thread_merger->IsMerged()); | ||
| raster_thread_merger->MergeWithLease(kNumFramesMerged); | ||
| thread_merged_latch.Signal(); | ||
| term_raster.Wait(); | ||
| }); | ||
| latch1.Wait(); | ||
|
|
||
| latch_wait_until_merged.Wait(); | ||
| ASSERT_TRUE(raster_thread_merger->IsMerged()); | ||
| fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId(); | ||
| fml::TaskQueueId qid2 = qid1; | ||
| const auto raster_thread_merger_ = | ||
| fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2); | ||
| // Statically merged. | ||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| // Test decrement lease and unmerge are both no-ops. | ||
| // The task queues should be always merged. | ||
| const int kNumFramesMerged = 5; | ||
| raster_thread_merger_->MergeWithLease(kNumFramesMerged); | ||
|
|
||
| for (int i = 0; i < kNumFramesMerged; i++) { | ||
| ASSERT_TRUE(raster_thread_merger->IsMerged()); | ||
| raster_thread_merger->DecrementLease(); | ||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
| raster_thread_merger_->DecrementLease(); | ||
| } | ||
|
|
||
| ASSERT_FALSE(raster_thread_merger->IsMerged()); | ||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| term_platform.Signal(); | ||
| term_raster.Signal(); | ||
| thread_platform.join(); | ||
| thread_raster.join(); | ||
| // Wait until merged should also return immediately. | ||
| raster_thread_merger_->WaitUntilMerged(); | ||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| term1.Signal(); | ||
| thread1.join(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,11 +62,7 @@ void Rasterizer::Setup(std::unique_ptr<Surface> surface) { | |
| // TODO(sanjayc77): https://github.com/flutter/flutter/issues/53179. Add | ||
| // support for raster thread merger for Fuchsia. | ||
| if (surface_->GetExternalViewEmbedder() && | ||
| surface_->GetExternalViewEmbedder()->SupportsDynamicThreadMerging() && | ||
| // Don't create raster_thread_merger if platform and raster task runners | ||
| // are the same. | ||
| delegate_.GetTaskRunners().GetRasterTaskRunner() != | ||
| delegate_.GetTaskRunners().GetPlatformTaskRunner()) { | ||
| surface_->GetExternalViewEmbedder()->SupportsDynamicThreadMerging()) { | ||
| const auto platform_id = | ||
| delegate_.GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId(); | ||
| const auto gpu_id = | ||
|
|
@@ -668,11 +664,6 @@ std::optional<size_t> Rasterizer::GetResourceCacheMaxBytes() const { | |
| } | ||
|
|
||
| bool Rasterizer::EnsureThreadsAreMerged() { | ||
| // If threads are merged statically, always return true. | ||
| if (delegate_.GetTaskRunners().GetRasterTaskRunner() == | ||
| delegate_.GetTaskRunners().GetPlatformTaskRunner()) { | ||
| return true; | ||
| } | ||
| if (surface_ == nullptr || raster_thread_merger_.get() == nullptr) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in what case
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the rasterizer has already been torn down, the |
||
| return false; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Would you mind adding a TODO, and filing an issue about reverting this logic once Android is fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually might not need to revert this as I think this make sense. waiting for @iskakaushik to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, this is good.