Flutter Engine
The Flutter Engine
vsync_waiter_unittest.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <gtest/gtest.h>
6
7#include <string>
8
9#include "flutter/fml/task_runner.h"
10#include "flutter/shell/common/thread_host.h"
11#include "fml/make_copyable.h"
12#include "fml/message_loop.h"
14#include "fml/time/time_delta.h"
15#include "fml/time/time_point.h"
16#include "vsync_waiter.h"
17
18namespace flutter_runner {
19
20TEST(VSyncWaiterFuchsia, FrameScheduledForStartTime) {
22 std::string prefix = "vsync_waiter_test";
23
25 auto platform_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
26
27 ThreadHost thread_host =
29 flutter::ThreadHost::Type::kUi |
30 flutter::ThreadHost::Type::kIo);
31 const flutter::TaskRunners task_runners(
32 prefix, // Dart thread labels
33 platform_task_runner, // platform
34 thread_host.raster_thread->GetTaskRunner(), // raster
35 thread_host.ui_thread->GetTaskRunner(), // ui
36 thread_host.io_thread->GetTaskRunner() // io
37 );
38
39 // await vsync will invoke the callback right away, but vsync waiter will post
40 // the task for frame_start time.
41 VsyncWaiter vsync_waiter(
43 const auto now = fml::TimePoint::Now();
44 const auto frame_start = now + fml::TimeDelta::FromMilliseconds(20);
45 const auto frame_end = now + fml::TimeDelta::FromMilliseconds(36);
46 callback(frame_start, frame_end);
47 },
48 /*secondary callback*/ nullptr, task_runners);
49
51 task_runners.GetUITaskRunner()->PostTask([&]() {
52 vsync_waiter.AsyncWaitForVsync(
53 [&](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {
54 const auto now = fml::TimePoint::Now();
55 EXPECT_GT(now, recorder->GetVsyncStartTime());
56 latch.Signal();
57 });
58 });
59
60 latch.Wait();
61}
62
63} // namespace flutter_runner
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
Definition: task_runners.cc:34
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46
static TimePoint Now()
Definition: time_point.cc:49
@ kRaster
Suitable for thread which raster data.
Definition: embedder.h:266
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
std::function< void(fml::TimePoint, fml::TimePoint)> FireCallbackCallback
Definition: vsync_waiter.h:20
TEST(RunnerTZDataTest, LoadsWithoutTZDataPresent)
The collection of all the threads used by the engine.
Definition: thread_host.h:21