2018-02-15 18:10:58 +08:00
|
|
|
#ifndef FPSCOUNTER_H
|
|
|
|
#define FPSCOUNTER_H
|
|
|
|
|
2021-01-09 02:24:51 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2020-04-03 01:16:33 +08:00
|
|
|
#include <stdatomic.h>
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2021-02-01 01:24:35 +08:00
|
|
|
|
|
|
|
#include "util/thread.h"
|
2018-02-15 18:10:58 +08:00
|
|
|
|
|
|
|
struct fps_counter {
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_thread thread;
|
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond state_cond;
|
|
|
|
|
|
|
|
bool thread_started;
|
2019-06-07 22:55:19 +08:00
|
|
|
|
|
|
|
// atomic so that we can check without locking the mutex
|
|
|
|
// if the FPS counter is disabled, we don't want to lock unnecessarily
|
2020-04-03 01:16:33 +08:00
|
|
|
atomic_bool started;
|
2019-06-07 22:55:19 +08:00
|
|
|
|
|
|
|
// the following fields are protected by the mutex
|
|
|
|
bool interrupted;
|
|
|
|
unsigned nr_rendered;
|
|
|
|
unsigned nr_skipped;
|
2021-07-04 22:50:19 +08:00
|
|
|
sc_tick next_timestamp;
|
2018-02-15 18:10:58 +08:00
|
|
|
};
|
|
|
|
|
2019-06-07 22:55:19 +08:00
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
fps_counter_init(struct fps_counter *counter);
|
|
|
|
|
|
|
|
void
|
2019-06-07 22:55:19 +08:00
|
|
|
fps_counter_destroy(struct fps_counter *counter);
|
|
|
|
|
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
fps_counter_start(struct fps_counter *counter);
|
|
|
|
|
|
|
|
void
|
|
|
|
fps_counter_stop(struct fps_counter *counter);
|
|
|
|
|
2019-06-07 22:55:19 +08:00
|
|
|
bool
|
|
|
|
fps_counter_is_started(struct fps_counter *counter);
|
|
|
|
|
|
|
|
// request to stop the thread (on quit)
|
|
|
|
// must be called before fps_counter_join()
|
|
|
|
void
|
|
|
|
fps_counter_interrupt(struct fps_counter *counter);
|
|
|
|
|
|
|
|
void
|
|
|
|
fps_counter_join(struct fps_counter *counter);
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
fps_counter_add_rendered_frame(struct fps_counter *counter);
|
2018-02-15 18:10:58 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
fps_counter_add_skipped_frame(struct fps_counter *counter);
|
2018-02-15 18:10:58 +08:00
|
|
|
|
|
|
|
#endif
|