-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VSyncWaiter on Fuchsia will defer firing until frame start time (#29287…
…) (#30079) * VSyncWaiter on Fuchsia will defer firing until frame start time The common vsync waiter implementation expects this invariant to be held. * Add a test for vsync_waiter Co-authored-by: Kaushik Iska <iska.kaushik@gmail.com>
- Loading branch information
1 parent
6f7b8f9
commit 1789394
Showing
5 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,62 @@ | ||
// 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 <gtest/gtest.h> | ||
|
||
#include <string> | ||
|
||
#include "flutter/fml/task_runner.h" | ||
#include "flutter/shell/common/thread_host.h" | ||
#include "fml/make_copyable.h" | ||
#include "fml/message_loop.h" | ||
#include "fml/synchronization/waitable_event.h" | ||
#include "fml/time/time_delta.h" | ||
#include "fml/time/time_point.h" | ||
#include "vsync_waiter.h" | ||
|
||
namespace flutter_runner { | ||
|
||
TEST(VSyncWaiterFuchsia, FrameScheduledForStartTime) { | ||
using flutter::ThreadHost; | ||
std::string prefix = "vsync_waiter_test"; | ||
|
||
fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
|
||
ThreadHost thread_host = ThreadHost( | ||
prefix, | ||
flutter::ThreadHost::Type::RASTER | flutter::ThreadHost::Type::UI | | ||
flutter::ThreadHost::Type::IO | flutter::ThreadHost::Type::Platform); | ||
const flutter::TaskRunners task_runners( | ||
prefix, // Dart thread labels | ||
thread_host.raster_thread->GetTaskRunner(), // raster | ||
thread_host.ui_thread->GetTaskRunner(), // ui | ||
thread_host.io_thread->GetTaskRunner(), // io | ||
thread_host.platform_thread->GetTaskRunner() // platform | ||
); | ||
|
||
// await vsync will invoke the callback right away, but vsync waiter will post | ||
// the task for frame_start time. | ||
VsyncWaiter vsync_waiter( | ||
[](FireCallbackCallback callback) { | ||
const auto now = fml::TimePoint::Now(); | ||
const auto frame_start = now + fml::TimeDelta::FromMilliseconds(20); | ||
const auto frame_end = now + fml::TimeDelta::FromMilliseconds(36); | ||
callback(frame_start, frame_end); | ||
}, | ||
/*secondary callback*/ nullptr, task_runners); | ||
|
||
fml::AutoResetWaitableEvent latch; | ||
task_runners.GetUITaskRunner()->PostTask([&]() { | ||
vsync_waiter.AsyncWaitForVsync( | ||
[&](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) { | ||
const auto now = fml::TimePoint::Now(); | ||
EXPECT_GT(now, recorder->GetVsyncStartTime()); | ||
latch.Signal(); | ||
}); | ||
}); | ||
|
||
latch.Wait(); | ||
} | ||
|
||
} // namespace flutter_runner |