From 39e81ab33cc441f5011177bce804e70d129a8d7d Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Fri, 30 Oct 2015 11:03:52 +0900 Subject: [PATCH] pepper: env var option for printing FPS PEPPER_DEBUG_FPS=1 to print FPS on the console. Change-Id: I4d96b5abe6063d0e1ebb54e24aa0391d06ffbf41 --- src/lib/pepper/output.c | 43 ++++++++++++++++++++++++++++++++++++---- src/lib/pepper/pepper-internal.h | 12 +++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/lib/pepper/output.c b/src/lib/pepper/output.c index 5cc6883..63a8bfc 100644 --- a/src/lib/pepper/output.c +++ b/src/lib/pepper/output.c @@ -188,12 +188,42 @@ pepper_output_add_damage_region(pepper_output_t *output, pixman_region32_t *regi PEPPER_API void pepper_output_finish_frame(pepper_output_t *output, struct timespec *ts) { + struct timespec time; + output->frame.pending = PEPPER_FALSE; if (ts) - output->frame.time = *ts; + time = *ts; else - pepper_compositor_get_time(output->compositor, &output->frame.time); + pepper_compositor_get_time(output->compositor, &time); + + if (output->frame.print_fps) + { + if (output->frame.count > 0) + { + uint32_t tick = (time.tv_sec - output->frame.time.tv_sec) * 1000 + + (time.tv_nsec - output->frame.time.tv_nsec) / 1000000; + uint32_t tick_count; + + output->frame.total_time += tick; + output->frame.total_time -= output->frame.ticks[output->frame.tick_index]; + output->frame.ticks[output->frame.tick_index] = tick; + + if (++output->frame.tick_index == PEPPER_OUTPUT_MAX_TICK_COUNT) + output->frame.tick_index = 0; + + if (output->frame.count < PEPPER_OUTPUT_MAX_TICK_COUNT) + tick_count = output->frame.count; + else + tick_count = PEPPER_OUTPUT_MAX_TICK_COUNT; + + PEPPER_TRACE("%s FPS : %.2f\n", output->name, + (double)(tick_count * 1000) / (double)output->frame.total_time); + } + } + + output->frame.count++; + output->frame.time = time; if (output->frame.scheduled) output_repaint(output); @@ -218,6 +248,7 @@ pepper_compositor_add_output(pepper_compositor_t *compositor, { pepper_output_t *output; uint32_t id; + const char *str; PEPPER_CHECK(name, return NULL, "Output name must be given.\n"); @@ -273,10 +304,14 @@ pepper_compositor_add_output(pepper_compositor_t *compositor, output->geometry.h = output->current_mode.h; pepper_list_insert(&compositor->output_list, &output->link); - pepper_list_init(&output->plane_list); - pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_OUTPUT_ADD, output); + /* FPS */ + str = getenv("PEPPER_DEBUG_FPS"); + if (str && atoi(str) != 0) + output->frame.print_fps = PEPPER_TRUE; + + pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_OUTPUT_ADD, output); return output; } diff --git a/src/lib/pepper/pepper-internal.h b/src/lib/pepper/pepper-internal.h index 32f1c03..586c172 100644 --- a/src/lib/pepper/pepper-internal.h +++ b/src/lib/pepper/pepper-internal.h @@ -7,8 +7,9 @@ #include "pepper-output-backend.h" #include "pepper-input-backend.h" -#define PEPPER_OBJECT_BUCKET_BITS 5 -#define PEPPER_MAX_OUTPUT_COUNT 32 +#define PEPPER_OBJECT_BUCKET_BITS 5 +#define PEPPER_MAX_OUTPUT_COUNT 32 +#define PEPPER_OUTPUT_MAX_TICK_COUNT 10 typedef struct pepper_region pepper_region_t; typedef struct pepper_surface_state pepper_surface_state_t; @@ -101,6 +102,13 @@ struct pepper_output pepper_bool_t scheduled; pepper_bool_t pending; struct timespec time; + uint32_t count; + + /* For FPS measuring */ + pepper_bool_t print_fps; + uint32_t ticks[PEPPER_OUTPUT_MAX_TICK_COUNT]; + int tick_index; + uint32_t total_time; } frame; pepper_list_t plane_list; -- 2.7.4