X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=context.c;h=133c37c168d6b04016579cbf3ccbd3938f11e241;hb=c27d7ce0b3ce5a2b9b753a654fdebcc1627aae52;hp=6fbd7f2228ea2bfc2ff3b4b1d2d933f24f4ed27a;hpb=bc106316b96ce7bfdbec3ee54ba37e49f156dea5;p=fips diff --git a/context.c b/context.c index 6fbd7f2..133c37c 100644 --- a/context.c +++ b/context.c @@ -20,22 +20,98 @@ */ #include "context.h" - #include "metrics.h" +#include "xmalloc.h" -void -context_enter (fips_api_t api, void *system_context_id unused) +typedef struct context +{ + /* Pointer to the system's context ID, (such as a GLXContext) */ + void *system_id; + + metrics_info_t metrics_info; + metrics_t *metrics; +} context_t; + +context_t *current_context; + +static context_t * +context_create (fips_api_t api, void *system_context_id) { + context_t *ctx; + + ctx = xcalloc (1, sizeof (*ctx)); + + ctx->system_id = system_context_id; + fips_dispatch_init (api); - metrics_info_init (); + metrics_info_init (&ctx->metrics_info); + ctx->metrics = metrics_create (&ctx->metrics_info); + + return ctx; +} + +static void +context_destroy (context_t *ctx) +{ + metrics_info_fini (&ctx->metrics_info); +} + +void +context_enter (fips_api_t api, void *system_context_id) +{ + /* Do nothing if the application is setting the same context + * as is already current. */ + if (current_context && current_context->system_id == system_context_id) + return; + + if (current_context) + context_destroy (current_context); - metrics_set_current_op (METRICS_OP_SHADER + 0); - metrics_counter_start (); + current_context = context_create (api, system_context_id); + + metrics_set_current_op (current_context->metrics, + METRICS_OP_SHADER + 0); + metrics_counter_start (current_context->metrics); } void context_leave (void) { - metrics_info_fini (); + context_t *ctx = current_context; + + if (ctx == NULL) + return; + + metrics_destroy (ctx->metrics); +} + +void +context_counter_start (void) +{ + metrics_counter_start (current_context->metrics); +} + +void +context_counter_stop (void) +{ + metrics_counter_stop (current_context->metrics); +} + +void +context_set_current_op (metrics_op_t op) +{ + metrics_set_current_op (current_context->metrics, op); +} + +metrics_op_t +context_get_current_op (void) +{ + return metrics_get_current_op (current_context->metrics); +} + +void +context_end_frame (void) +{ + return metrics_end_frame (current_context->metrics); }