2022-04-12 23:59:01 +02:00
|
|
|
#ifndef SC_FPSCOUNTER_H
|
|
|
|
#define SC_FPSCOUNTER_H
|
2018-02-15 11:10:58 +01:00
|
|
|
|
2021-01-08 19:24:51 +01:00
|
|
|
#include "common.h"
|
|
|
|
|
2020-04-02 19:16:33 +02:00
|
|
|
#include <stdatomic.h>
|
2019-03-02 23:52:22 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2021-01-31 18:24:35 +01:00
|
|
|
|
|
|
|
#include "util/thread.h"
|
2018-02-15 11:10:58 +01:00
|
|
|
|
2022-02-17 19:55:14 +01:00
|
|
|
struct sc_fps_counter {
|
2021-01-31 18:24:35 +01:00
|
|
|
sc_thread thread;
|
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond state_cond;
|
|
|
|
|
|
|
|
bool thread_started;
|
2019-06-07 16:55:19 +02: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-02 19:16:33 +02:00
|
|
|
atomic_bool started;
|
2019-06-07 16:55:19 +02:00
|
|
|
|
|
|
|
// the following fields are protected by the mutex
|
|
|
|
bool interrupted;
|
|
|
|
unsigned nr_rendered;
|
|
|
|
unsigned nr_skipped;
|
2021-07-04 16:50:19 +02:00
|
|
|
sc_tick next_timestamp;
|
2018-02-15 11:10:58 +01:00
|
|
|
};
|
|
|
|
|
2019-06-07 16:55:19 +02:00
|
|
|
bool
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_init(struct sc_fps_counter *counter);
|
2019-03-02 20:09:56 +01:00
|
|
|
|
|
|
|
void
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_destroy(struct sc_fps_counter *counter);
|
2019-06-07 16:55:19 +02:00
|
|
|
|
|
|
|
bool
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_start(struct sc_fps_counter *counter);
|
2019-03-02 20:09:56 +01:00
|
|
|
|
|
|
|
void
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_stop(struct sc_fps_counter *counter);
|
2019-03-02 20:09:56 +01:00
|
|
|
|
2019-06-07 16:55:19 +02:00
|
|
|
bool
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_is_started(struct sc_fps_counter *counter);
|
2019-06-07 16:55:19 +02:00
|
|
|
|
|
|
|
// request to stop the thread (on quit)
|
2022-02-17 19:55:14 +01:00
|
|
|
// must be called before sc_fps_counter_join()
|
2019-06-07 16:55:19 +02:00
|
|
|
void
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_interrupt(struct sc_fps_counter *counter);
|
2019-06-07 16:55:19 +02:00
|
|
|
|
|
|
|
void
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_join(struct sc_fps_counter *counter);
|
2019-06-07 16:55:19 +02:00
|
|
|
|
2019-03-02 20:09:56 +01:00
|
|
|
void
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_add_rendered_frame(struct sc_fps_counter *counter);
|
2018-02-15 11:10:58 +01:00
|
|
|
|
2019-03-02 20:09:56 +01:00
|
|
|
void
|
2022-02-17 19:55:14 +01:00
|
|
|
sc_fps_counter_add_skipped_frame(struct sc_fps_counter *counter);
|
2018-02-15 11:10:58 +01:00
|
|
|
|
|
|
|
#endif
|