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
Create a WeakPtrFactory for use on the UI thread in VsyncWaiter #13781
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
67adbcd
Create a WeakPtrFactory for use on the UI thread in VsyncWaiter
1a38bd2
Build fixes
d9cbd93
Review updates & code format
f35d546
Add a unittest and make fixes
55ac136
remove latch again
f622125
formatting
33d7d0f
attach async loop to current thread for platform thread
5e18880
review updates
a609fa6
some more review updates
1b84a43
formatting
cbdbae0
update licence file
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include <array> | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include <lib/zx/event.h> | ||
| #include <zircon/syscalls.h> | ||
|
|
||
| #include "flutter/fml/synchronization/waitable_event.h" | ||
| #include "flutter/shell/common/thread_host.h" | ||
| #include "flutter/shell/common/vsync_waiter.h" | ||
| #include "flutter/shell/platform/fuchsia/flutter/task_runner_adapter.h" | ||
| #include "flutter/shell/platform/fuchsia/flutter/thread.h" | ||
| #include "flutter/shell/platform/fuchsia/flutter/vsync_waiter.h" | ||
|
|
||
| namespace flutter_runner_test { | ||
|
|
||
| class VsyncWaiterTest : public testing::Test { | ||
| public: | ||
| VsyncWaiterTest() {} | ||
|
|
||
| ~VsyncWaiterTest() = default; | ||
|
|
||
| std::unique_ptr<flutter::VsyncWaiter> CreateVsyncWaiter( | ||
| flutter::TaskRunners task_runners) { | ||
| return std::make_unique<flutter_runner::VsyncWaiter>( | ||
| "VsyncWaiterTest", vsync_event_.get(), task_runners); | ||
| } | ||
|
|
||
| void SignalVsyncEvent() { | ||
| auto status = | ||
| zx_object_signal(vsync_event_.get(), 0, | ||
| flutter_runner::VsyncWaiter::SessionPresentSignal); | ||
| EXPECT_EQ(status, ZX_OK); | ||
| } | ||
|
|
||
| protected: | ||
| void SetUp() override { | ||
| auto status = zx::event::create(0, &vsync_event_); | ||
| EXPECT_EQ(status, ZX_OK); | ||
| } | ||
|
|
||
| private: | ||
| zx::event vsync_event_; | ||
| }; | ||
|
|
||
| TEST_F(VsyncWaiterTest, AwaitVsync) { | ||
| std::array<std::unique_ptr<flutter_runner::Thread>, 3> threads; | ||
|
|
||
| for (auto& thread : threads) { | ||
| thread.reset(new flutter_runner::Thread()); | ||
| } | ||
|
|
||
| async::Loop loop(&kAsyncLoopConfigAttachToThread); | ||
|
|
||
| const flutter::TaskRunners task_runners( | ||
| "VsyncWaiterTests", // Dart thread labels | ||
| flutter_runner::CreateFMLTaskRunner( | ||
| async_get_default_dispatcher()), // platform | ||
| flutter_runner::CreateFMLTaskRunner(threads[0]->dispatcher()), // gpu | ||
| flutter_runner::CreateFMLTaskRunner(threads[1]->dispatcher()), // ui | ||
| flutter_runner::CreateFMLTaskRunner(threads[2]->dispatcher()) // io | ||
| ); | ||
|
|
||
| auto vsync_waiter = CreateVsyncWaiter(std::move(task_runners)); | ||
|
|
||
| fml::AutoResetWaitableEvent latch; | ||
| vsync_waiter->AsyncWaitForVsync( | ||
| [&latch](fml::TimePoint frame_start_time, | ||
| fml::TimePoint frame_target_time) { latch.Signal(); }); | ||
| SignalVsyncEvent(); | ||
|
|
||
| bool did_timeout = | ||
| latch.WaitWithTimeout(fml::TimeDelta::FromMilliseconds(5000)); | ||
|
|
||
| // False indicates we were signalled rather than timed out | ||
| EXPECT_FALSE(did_timeout); | ||
|
|
||
| vsync_waiter.reset(); | ||
| for (const auto& thread : threads) { | ||
| thread->Quit(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace flutter_runner_test |
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.
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.
@chinmaygarde should we block this call. I think its ok to not block but jut want 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.
I think this is fine because of the reason mentioned in the comment.