Flutter Engine
The Flutter Engine
dart_timestamp_provider.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
6
7#include "dart_tools_api.h"
8
9namespace flutter {
10
11DartTimestampProvider::DartTimestampProvider() = default;
12
14
15int64_t DartTimestampProvider::ConvertToNanos(int64_t ticks,
16 int64_t frequency) {
17 int64_t nano_seconds = (ticks / frequency) * kNanosPerSecond;
18 int64_t leftover_ticks = ticks % frequency;
19 int64_t leftover_nanos = (leftover_ticks * kNanosPerSecond) / frequency;
20 return nano_seconds + leftover_nanos;
21}
22
24 const int64_t ticks = Dart_TimelineGetTicks();
25 const int64_t frequency = Dart_TimelineGetTicksFrequency();
26 // optimization for the most common case.
27 if (frequency != kNanosPerSecond) {
28 return fml::TimePoint::FromTicks(ConvertToNanos(ticks, frequency));
29 } else {
30 return fml::TimePoint::FromTicks(ticks);
31 }
32}
33
36}
37
38} // namespace flutter
static DartTimestampProvider & Instance()
static constexpr TimePoint FromTicks(int64_t ticks)
Definition: time_point.h:48
DART_EXPORT int64_t Dart_TimelineGetTicksFrequency()
DART_EXPORT int64_t Dart_TimelineGetTicks()
fml::TimePoint DartTimelineTicksSinceEpoch()