2018-02-15 18:10:58 +08:00
|
|
|
#ifndef FPSCOUNTER_H
|
|
|
|
#define FPSCOUNTER_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>
|
2019-06-07 22:55:19 +08:00
|
|
|
#include <SDL2/SDL_mutex.h>
|
|
|
|
#include <SDL2/SDL_thread.h>
|
2018-02-15 18:10:58 +08:00
|
|
|
|
2019-09-30 04:36:56 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-02-15 18:10:58 +08:00
|
|
|
struct fps_counter {
|
2019-06-07 22:55:19 +08:00
|
|
|
SDL_Thread *thread;
|
|
|
|
SDL_mutex *mutex;
|
|
|
|
SDL_cond *state_cond;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
uint32_t 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
|