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
|
|
|
|
2022-02-18 02:55:14 +08:00
|
|
|
struct sc_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
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_init(struct sc_fps_counter *counter);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
|
|
|
void
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_destroy(struct sc_fps_counter *counter);
|
2019-06-07 22:55:19 +08:00
|
|
|
|
|
|
|
bool
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_start(struct sc_fps_counter *counter);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
|
|
|
void
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_stop(struct sc_fps_counter *counter);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
2019-06-07 22:55:19 +08:00
|
|
|
bool
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_is_started(struct sc_fps_counter *counter);
|
2019-06-07 22:55:19 +08:00
|
|
|
|
|
|
|
// request to stop the thread (on quit)
|
2022-02-18 02:55:14 +08:00
|
|
|
// must be called before sc_fps_counter_join()
|
2019-06-07 22:55:19 +08:00
|
|
|
void
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_interrupt(struct sc_fps_counter *counter);
|
2019-06-07 22:55:19 +08:00
|
|
|
|
|
|
|
void
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_join(struct sc_fps_counter *counter);
|
2019-06-07 22:55:19 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_add_rendered_frame(struct sc_fps_counter *counter);
|
2018-02-15 18:10:58 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
2022-02-18 02:55:14 +08:00
|
|
|
sc_fps_counter_add_skipped_frame(struct sc_fps_counter *counter);
|
2018-02-15 18:10:58 +08:00
|
|
|
|
|
|
|
#endif
|