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

Commit a68011e

Browse files
author
Emmanuel Garcia
committed
Test and fixes
1 parent cf55c18 commit a68011e

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

fml/raster_thread_merger_unittests.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,5 +579,53 @@ TEST(RasterThreadMerger, RunExpiredTasksWhileFirstTaskUnMergesThreads) {
579579
thread_raster.join();
580580
}
581581

582+
TEST(RasterThreadMerger, SetMergeUnmergeCallback) {
583+
fml::MessageLoop* loop1 = nullptr;
584+
fml::AutoResetWaitableEvent latch1;
585+
fml::AutoResetWaitableEvent term1;
586+
std::thread thread1([&loop1, &latch1, &term1]() {
587+
fml::MessageLoop::EnsureInitializedForCurrentThread();
588+
loop1 = &fml::MessageLoop::GetCurrent();
589+
latch1.Signal();
590+
term1.Wait();
591+
});
592+
593+
fml::MessageLoop* loop2 = nullptr;
594+
fml::AutoResetWaitableEvent latch2;
595+
fml::AutoResetWaitableEvent term2;
596+
std::thread thread2([&loop2, &latch2, &term2]() {
597+
fml::MessageLoop::EnsureInitializedForCurrentThread();
598+
loop2 = &fml::MessageLoop::GetCurrent();
599+
latch2.Signal();
600+
term2.Wait();
601+
});
602+
603+
latch1.Wait();
604+
latch2.Wait();
605+
606+
fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
607+
fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
608+
609+
const auto raster_thread_merger =
610+
fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
611+
612+
int callbacks = 0;
613+
raster_thread_merger->SetMergeUnmergeCallback(
614+
[&callbacks]() { callbacks++; });
615+
616+
ASSERT_EQ(0, callbacks);
617+
618+
raster_thread_merger->MergeWithLease(1);
619+
ASSERT_EQ(1, callbacks);
620+
621+
raster_thread_merger->DecrementLease();
622+
ASSERT_EQ(2, callbacks);
623+
624+
term1.Signal();
625+
term2.Signal();
626+
thread1.join();
627+
thread2.join();
628+
}
629+
582630
} // namespace testing
583631
} // namespace fml

shell/common/rasterizer.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ void Rasterizer::Setup(std::unique_ptr<Surface> surface) {
8989
delegate_.GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId();
9090
raster_thread_merger_ =
9191
fml::MakeRefCounted<fml::RasterThreadMerger>(platform_id, gpu_id);
92-
93-
raster_thread_merger_->SetMergeUnmergeCallback(
94-
[weak_this = weak_factory_.GetWeakPtr()]() {
95-
// Clear the GL context after the thread configuration has changed.
96-
if (weak_this && weak_this->surface_) {
97-
weak_this->surface_->ClearRenderContext();
98-
}
99-
});
92+
raster_thread_merger_->SetMergeUnmergeCallback([=]() {
93+
// Clear the GL context after the thread configuration has changed.
94+
if (surface_) {
95+
surface_->ClearRenderContext();
96+
}
97+
});
10098
}
10199
#endif
102100
}

0 commit comments

Comments
 (0)