-
Notifications
You must be signed in to change notification settings - Fork 6k
Do not involve external_view_embedder in submit frame process if threads are not merged. #22275
Changes from all commits
e1a9d81
8fa56f3
4a1e8f5
b357f74
dbb7b63
ed75ac6
ce7e971
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 |
|---|---|---|
|
|
@@ -1051,20 +1051,25 @@ TEST_F(ShellTest, | |
| auto settings = CreateSettingsForFixture(); | ||
| fml::AutoResetWaitableEvent end_frame_latch; | ||
| std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder; | ||
|
|
||
| fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger_ref; | ||
| auto end_frame_callback = | ||
| [&](bool should_resubmit_frame, | ||
| fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) { | ||
| external_view_embedder->UpdatePostPrerollResult( | ||
| PostPrerollResult::kSuccess); | ||
| if (!raster_thread_merger_ref) { | ||
| raster_thread_merger_ref = raster_thread_merger; | ||
|
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. For future improvements: this would be much easier if we were to create, and supply the thread merger in the test. Right now, this dependency is hardcoded in the rasterizer, which creates patterns like this. |
||
| } | ||
| if (should_resubmit_frame && !raster_thread_merger->IsMerged()) { | ||
| raster_thread_merger->MergeWithLease(10); | ||
| external_view_embedder->UpdatePostPrerollResult( | ||
| PostPrerollResult::kSuccess); | ||
| } | ||
| end_frame_latch.Signal(); | ||
| }; | ||
| external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>( | ||
| end_frame_callback, PostPrerollResult::kResubmitFrame, true); | ||
|
|
||
| auto shell = CreateShell(std::move(settings), GetTaskRunnersForFixture(), | ||
| false, external_view_embedder); | ||
|
|
||
| PlatformViewNotifyCreated(shell.get()); | ||
|
|
||
| auto configuration = RunConfiguration::InferFromSettings(settings); | ||
|
|
@@ -1074,13 +1079,18 @@ TEST_F(ShellTest, | |
| ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount()); | ||
|
|
||
| PumpOneFrame(shell.get()); | ||
| // `EndFrame` changed the post preroll result to `kSuccess`. | ||
| // `EndFrame` changed the post preroll result to `kSuccess` and merged the | ||
| // threads. During the frame, the threads are not merged, So no | ||
| // `external_view_embedder->GetSubmittedFrameCount()` is called. | ||
| end_frame_latch.Wait(); | ||
| ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount()); | ||
| ASSERT_TRUE(raster_thread_merger_ref->IsMerged()); | ||
| ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount()); | ||
|
|
||
| // This is the resubmitted frame, which threads are also merged. | ||
| end_frame_latch.Wait(); | ||
| ASSERT_EQ(2, external_view_embedder->GetSubmittedFrameCount()); | ||
| ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount()); | ||
|
|
||
| PlatformViewNotifyDestroyed(shell.get()); | ||
| DestroyShell(std::move(shell)); | ||
| } | ||
|
|
||
|
|
@@ -2020,14 +2030,29 @@ TEST_F(ShellTest, DiscardLayerTreeOnResize) { | |
| SkISize expected_size = SkISize::Make(400, 200); | ||
|
|
||
| fml::AutoResetWaitableEvent end_frame_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 | ||
| // 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(); | ||
| }; | ||
|
|
||
| auto end_frame_callback = [&](bool, fml::RefPtr<fml::RasterThreadMerger>) { | ||
| end_frame_latch.Signal(); | ||
| }; | ||
|
|
||
| std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder = | ||
| std::make_shared<ShellTestExternalViewEmbedder>( | ||
| std::move(end_frame_callback), PostPrerollResult::kSuccess, true); | ||
| 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); | ||
|
|
@@ -2048,23 +2073,29 @@ TEST_F(ShellTest, DiscardLayerTreeOnResize) { | |
|
|
||
| RunEngine(shell.get(), std::move(configuration)); | ||
|
|
||
| fml::WeakPtr<RuntimeDelegate> runtime_delegate = shell->GetEngine(); | ||
|
|
||
| PumpOneFrame(shell.get(), static_cast<double>(wrong_size.width()), | ||
| static_cast<double>(wrong_size.height())); | ||
|
|
||
| end_frame_latch.Wait(); | ||
|
|
||
| ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount()); | ||
|
|
||
| // Threads will be merged at the end of this frame. | ||
| PumpOneFrame(shell.get(), static_cast<double>(expected_size.width()), | ||
| static_cast<double>(expected_size.height())); | ||
|
|
||
| end_frame_latch.Wait(); | ||
| // Even the threads are merged at the end of the frame, | ||
| // during the frame, the threads are not merged, | ||
| // So no `external_view_embedder->GetSubmittedFrameCount()` is called. | ||
| ASSERT_TRUE(raster_thread_merger_ref->IsMerged()); | ||
| ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount()); | ||
|
|
||
| end_frame_latch.Wait(); | ||
| ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount()); | ||
|
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: is it possible to assert that threads are merged before this assert? Same where you have the comment
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. Done
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. Actually, we can't assert if threads are not merged here, the threads are merged at the end of the frame. So it is actually merged here. |
||
| ASSERT_EQ(expected_size, external_view_embedder->GetLastSubmittedFrameSize()); | ||
|
|
||
| PlatformViewNotifyDestroyed(shell.get()); | ||
| DestroyShell(std::move(shell)); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.