Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
frame_pacer.h
Go to the documentation of this file.
1// Copyright 2026 The Symbian SDK Authors.
2// Licensed under the Apache License, Version 2.0.
3
4#ifndef SYMBIAN_API_TIME_FRAME_PACER_H_
5#define SYMBIAN_API_TIME_FRAME_PACER_H_
6
7#include <algorithm>
8#include <chrono>
9#include <cstdint>
10
12
14
16class FramePacer final {
17 public:
18 explicit FramePacer(std::uint32_t refresh_rate_hz)
19 : period_ns_(
20 (1000000000LL + std::max<std::uint32_t>(refresh_rate_hz, 1) - 1) /
21 std::max<std::uint32_t>(refresh_rate_hz, 1)) {
22 Reset();
23 }
24
25 void Reset() { deadline_ns_ = MonotonicClock::NowNanoseconds() + period_ns_; }
26
33 std::uint32_t NextDelayMilliseconds() {
34 const std::int64_t remaining = NextDelayNanoseconds().count();
35 return static_cast<std::uint32_t>((remaining + 999999) / 1000000);
36 }
37
39 std::chrono::nanoseconds NextDelayNanoseconds() {
40 const std::int64_t now = MonotonicClock::NowNanoseconds();
41 if (now >= deadline_ns_) {
42 deadline_ns_ = now + period_ns_;
43 return std::chrono::nanoseconds::zero();
44 }
45 const std::int64_t remaining = deadline_ns_ - now;
46 deadline_ns_ += period_ns_;
47 return std::chrono::nanoseconds(remaining);
48 }
49
50 private:
51 std::int64_t period_ns_;
52 std::int64_t deadline_ns_ = 0;
53};
54
55} // namespace symbian::api::time
56
57#endif // SYMBIAN_API_TIME_FRAME_PACER_H_
Monotonic frame deadlines for a reported display refresh rate.
Definition frame_pacer.h:16
FramePacer(std::uint32_t refresh_rate_hz)
Definition frame_pacer.h:18
void Reset()
Definition frame_pacer.h:25
std::chrono::nanoseconds NextDelayNanoseconds()
Precise remaining time to the next presentation deadline.
Definition frame_pacer.h:39
std::uint32_t NextDelayMilliseconds()
Return a whole millisecond sleep toward the next frame deadline.
Definition frame_pacer.h:33
static std::int64_t NowNanoseconds()
Definition monotonic_clock.h:15
Definition native_camera_stream.cc:19
Definition frame_pacer.h:13
std::uint32_t refresh_rate_hz
Definition window_surface.cc:116