summaryrefslogtreecommitdiff
path: root/include/yasl/timing.h
blob: 7c669679c775d78a9951fe9ade959584f278d797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef YASL_TIMING_H
#define YASL_TIMING_H

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

struct yasl_resize_stats {
    uint64_t count;
    double avg_us;
    double max_us;
    long minflt;
};

struct yasl_timing {
    double refresh_ns;
    uint64_t last_present_ns;
    uint64_t next_present_ns;
    uint64_t frames_skipped;
    struct yasl_resize_stats resize;
};

#define YASL_REFRESH_DEFAULT_NS 16666666.0

struct yasl_frame_clock {
    uint64_t last_present_ns;
    uint64_t resize_count;
    uint64_t resize_sum_ns;
    uint64_t resize_max_ns;
    long resize_minflt;
    uint64_t frame_time_ns;
    double refresh_ns;
};

uint64_t yasl_clock_extend_ms(uint32_t ms, uint64_t now_ns);
void yasl_clock_presented(struct yasl_frame_clock *c, uint64_t now, bool sample);
void yasl_clock_note_resize(struct yasl_frame_clock *c, uint64_t dt_ns);
void yasl_clock_resize_stats(const struct yasl_frame_clock *c,
                             struct yasl_resize_stats *out);
double yasl_clock_refresh_ms(const struct yasl_frame_clock *c);
uint64_t yasl_clock_next_present_ns(const struct yasl_frame_clock *c);
uint64_t yasl_clock_frame_timestamp_ns(struct yasl_frame_clock *c, uint64_t now);

#ifdef __cplusplus
}
#endif

#endif /* YASL_TIMING_H */