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
[testing] Move test vsync waiters to their own TUs #14456
Merged
iskakaushik
merged 1 commit into
flutter:master
from
iskakaushik:shell-test-vsync-waiters
Dec 12, 2019
Merged
Changes from all commits
Commits
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,61 @@ | ||
| // 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. | ||
|
|
||
| #define FML_USED_ON_EMBEDDER | ||
|
|
||
| #include "flutter/shell/common/shell_test.h" | ||
|
|
||
| #include "flutter/flow/layers/layer_tree.h" | ||
| #include "flutter/flow/layers/transform_layer.h" | ||
| #include "flutter/fml/make_copyable.h" | ||
| #include "flutter/fml/mapping.h" | ||
| #include "flutter/runtime/dart_vm.h" | ||
| #include "flutter/shell/gpu/gpu_surface_gl.h" | ||
| #include "flutter/testing/testing.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| void ShellTestVsyncClock::SimulateVSync() { | ||
| std::scoped_lock lock(mutex_); | ||
| if (vsync_issued_ >= vsync_promised_.size()) { | ||
| vsync_promised_.emplace_back(); | ||
| } | ||
| FML_CHECK(vsync_issued_ < vsync_promised_.size()); | ||
| vsync_promised_[vsync_issued_].set_value(vsync_issued_); | ||
| vsync_issued_ += 1; | ||
| } | ||
|
|
||
| std::future<int> ShellTestVsyncClock::NextVSync() { | ||
| std::scoped_lock lock(mutex_); | ||
| vsync_promised_.emplace_back(); | ||
| return vsync_promised_.back().get_future(); | ||
| } | ||
|
|
||
| void ShellTestVsyncWaiter::AwaitVSync() { | ||
| FML_DCHECK(task_runners_.GetUITaskRunner()->RunsTasksOnCurrentThread()); | ||
| auto vsync_future = clock_.NextVSync(); | ||
|
|
||
| auto async_wait = std::async([&vsync_future, this]() { | ||
| vsync_future.wait(); | ||
|
|
||
| // Post the `FireCallback` to the Platform thread so earlier Platform tasks | ||
| // (specifically, the `VSyncFlush` call) will be finished before | ||
| // `FireCallback` is executed. This is only needed for our unit tests. | ||
| // | ||
| // Without this, the repeated VSYNC signals in `VSyncFlush` may start both | ||
| // the current frame in the UI thread and the next frame in the secondary | ||
| // callback (both of them are waiting for VSYNCs). That breaks the unit | ||
| // test's assumption that each frame's VSYNC must be issued by different | ||
| // `VSyncFlush` call (which resets the `will_draw_new_frame` bit). | ||
| // | ||
| // For example, HandlesActualIphoneXsInputEvents will fail without this. | ||
| task_runners_.GetPlatformTaskRunner()->PostTask([this]() { | ||
| FireCallback(fml::TimePoint::Now(), fml::TimePoint::Now()); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // 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. | ||
|
|
||
| #define FML_USED_ON_EMBEDDER | ||
|
|
||
| #ifndef FLUTTER_SHELL_COMMON_TEST_VSYNC_WAITERS_H_ | ||
| #define FLUTTER_SHELL_COMMON_TEST_VSYNC_WAITERS_H_ | ||
|
|
||
| #include "flutter/shell/common/shell.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| class ShellTestVsyncClock { | ||
| public: | ||
| /// Simulate that a vsync signal is triggered. | ||
| void SimulateVSync(); | ||
|
|
||
| /// A future that will return the index the next vsync signal. | ||
| std::future<int> NextVSync(); | ||
|
|
||
| private: | ||
| std::mutex mutex_; | ||
| std::vector<std::promise<int>> vsync_promised_; | ||
| size_t vsync_issued_ = 0; | ||
| }; | ||
|
|
||
| class ShellTestVsyncWaiter : public VsyncWaiter { | ||
| public: | ||
| ShellTestVsyncWaiter(TaskRunners task_runners, ShellTestVsyncClock& clock) | ||
| : VsyncWaiter(std::move(task_runners)), clock_(clock) {} | ||
|
|
||
| protected: | ||
| void AwaitVSync() override; | ||
|
|
||
| private: | ||
| ShellTestVsyncClock& clock_; | ||
| }; | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_COMMON_TEST_VSYNC_WAITERS_H_ | ||
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.
IMO, it is better to have one TU per class as it makes code easier to navigate (just lookup the the file name for the class you want to navigate to). But your call.
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 have a few more changes coming up. Will move things around to their own files.