Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
time_point.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 "flutter/fml/time/time_point.h"
6
7#include <atomic>
8
9#include "flutter/fml/build_config.h"
10#include "flutter/fml/logging.h"
11
12#if defined(OS_FUCHSIA)
13#include <zircon/syscalls.h>
14#else
15#include <chrono>
16#endif
17
18namespace fml {
19
20#if defined(OS_FUCHSIA)
21
22// static
24 return TimePoint(zx_clock_get_monotonic());
25}
26
28 return Now();
29}
30
31void TimePoint::SetClockSource(ClockSource source) {}
32#else
33
34namespace {
35std::atomic<TimePoint::ClockSource> gSteadyClockSource;
36}
37
38template <typename Clock, typename Duration>
39static int64_t NanosSinceEpoch(
40 std::chrono::time_point<Clock, Duration> time_point) {
41 const auto elapsed = time_point.time_since_epoch();
42 return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
43}
44
46 gSteadyClockSource = source;
47}
48
50 if (gSteadyClockSource) {
51 return gSteadyClockSource.load()();
52 }
53 const int64_t nanos = NanosSinceEpoch(std::chrono::steady_clock::now());
54 return TimePoint(nanos);
55}
56
58 const int64_t nanos = NanosSinceEpoch(std::chrono::system_clock::now());
59 return TimePoint(nanos);
60}
61
62#endif
63
64} // namespace fml
TimePoint(*)() ClockSource
Definition time_point.h:24
static void SetClockSource(ClockSource source)
Definition time_point.cc:45
static TimePoint CurrentWallTime()
Definition time_point.cc:57
static TimePoint Now()
Definition time_point.cc:49
constexpr TimePoint()=default
SkBitmap source
Definition examples.cpp:28
static int64_t NanosSinceEpoch(std::chrono::time_point< Clock, Duration > time_point)
Definition time_point.cc:39
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
Definition timing.h:15