This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Windows] Add callback for when the next frame is drawn #35408
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f1b81e
[Windows] Add callback for when next frame is drawn
loic-sharma 5e454aa
Add comment
loic-sharma e98ed64
Improve comment
loic-sharma 694acbd
Fix formatting issue
loic-sharma 326c292
Fix second formatting issue
loic-sharma f7ed3b9
Fix more formatting
loic-sharma 8c23308
Address feedback
loic-sharma b74309c
Prefer move over const ref
loic-sharma 34c2d3c
Check frame is scheduled before frame is drawn
loic-sharma 8bab3ff
Format
loic-sharma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,5 +149,59 @@ TEST_F(WindowsTest, VerifyNativeFunctionWithReturn) { | |
| EXPECT_TRUE(bool_value_passed); | ||
| } | ||
|
|
||
| // Verify the next frame callback is executed. | ||
| TEST_F(WindowsTest, NextFrameCallback) { | ||
| struct Captures { | ||
| fml::AutoResetWaitableEvent frame_scheduled_latch; | ||
| fml::AutoResetWaitableEvent frame_drawn_latch; | ||
| std::thread::id thread_id; | ||
| }; | ||
| Captures captures; | ||
|
|
||
| CreateNewThread("test_platform_thread")->PostTask([&]() { | ||
| captures.thread_id = std::this_thread::get_id(); | ||
|
|
||
| auto& context = GetContext(); | ||
| WindowsConfigBuilder builder(context); | ||
| builder.SetDartEntrypoint("drawHelloWorld"); | ||
|
|
||
| auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { | ||
| ASSERT_FALSE(captures.frame_drawn_latch.IsSignaledForTest()); | ||
| captures.frame_scheduled_latch.Signal(); | ||
| }); | ||
| context.AddNativeFunction("NotifyFirstFrameScheduled", native_entry); | ||
|
|
||
| ViewControllerPtr controller{builder.Run()}; | ||
| ASSERT_NE(controller, nullptr); | ||
|
|
||
| auto engine = FlutterDesktopViewControllerGetEngine(controller.get()); | ||
|
|
||
| FlutterDesktopEngineSetNextFrameCallback( | ||
| engine, | ||
| [](void* user_data) { | ||
| auto captures = static_cast<Captures*>(user_data); | ||
|
|
||
| ASSERT_TRUE(captures->frame_scheduled_latch.IsSignaledForTest()); | ||
|
|
||
| // Callback should execute on platform thread. | ||
| ASSERT_EQ(std::this_thread::get_id(), captures->thread_id); | ||
|
|
||
| // Signal the test passed and end the Windows message loop. | ||
| captures->frame_drawn_latch.Signal(); | ||
| ::PostQuitMessage(0); | ||
| }, | ||
| &captures); | ||
|
|
||
| // Pump messages for the Windows platform task runner. | ||
| ::MSG msg; | ||
| while (::GetMessage(&msg, nullptr, 0, 0)) { | ||
| ::TranslateMessage(&msg); | ||
| ::DispatchMessage(&msg); | ||
| } | ||
|
Comment on lines
+195
to
+200
Member
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. This is necessary as otherwise platform tasks - including the next frame callback - won't run. The Windows platform thread's task runner is actually a window. It is woken up by posting a message to its window. If messages aren't dispatched, the Windows platform task runner is never woken up, and platform tasks are never executed. |
||
| }); | ||
|
|
||
| captures.frame_drawn_latch.Wait(); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.