X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=context.c;h=ccaa96a3bd4c13d20cfa181dbaf3c2c9656cf6d8;hb=778d86ef913e3c4fa3618232c6f34f0655e92dd2;hp=f4694c1ae8052152c9d36383e64170ccca2a0832;hpb=076c1c37c1fc8bf3e56a615adfb4c38542cbd4c5;p=fips diff --git a/context.c b/context.c index f4694c1..ccaa96a 100644 --- a/context.c +++ b/context.c @@ -20,22 +20,46 @@ */ #include "context.h" - #include "metrics.h" +#include "xmalloc.h" -/* FIXME: Need a map from integers to context objects and track the - * current context with glXMakeContextCurrent, eglMakeCurrent, etc. */ - -context_t current_context; +context_t *current_context; -void -context_enter (fips_api_t api, void *system_context_id unused) +static context_t * +context_create (fips_api_t api, void *system_context_id) { - context_t *ctx = ¤t_context; + context_t *ctx; + + ctx = xcalloc (1, sizeof (*ctx)); + + ctx->system_id = system_context_id; fips_dispatch_init (api); 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); + + current_context = context_create (api, system_context_id); metrics_set_current_op (METRICS_OP_SHADER + 0); metrics_counter_start (); @@ -44,53 +68,16 @@ context_enter (fips_api_t api, void *system_context_id unused) void context_leave (void) { - context_t *ctx = ¤t_context; - timer_query_t *timer, *timer_next; - monitor_t *monitor, *monitor_next; - - metrics_collect_available (); - - if (ctx->timer_begun_id) { - glEndQuery (GL_TIME_ELAPSED); - glDeleteQueries (1, &ctx->timer_begun_id); - ctx->timer_begun_id = 0; - } - - for (timer = ctx->timer_head; - timer; - timer = timer_next) - { - glDeleteQueries (1, &timer->id); - timer_next = timer->next; - free (timer); - } - ctx->timer_head = NULL; - ctx->timer_tail = NULL; - - if (ctx->monitor_begun_id) { - glEndPerfMonitorAMD (ctx->monitor_begun_id); - glDeletePerfMonitorsAMD (1, &ctx->monitor_begun_id); - ctx->monitor_begun_id = 0; - } - - for (monitor = ctx->monitor_head; - monitor; - monitor = monitor_next) - { - glDeletePerfMonitorsAMD (1, &monitor->id); - monitor_next = monitor->next; - free (monitor); - } - ctx->monitor_head = NULL; - ctx->monitor_tail = NULL; - - current_context.monitors_in_flight = 0; + context_t *ctx = current_context; - metrics_info_fini (&ctx->metrics_info); + if (ctx == NULL) + return; + + metrics_destroy (ctx->metrics); } context_t * context_get_current (void) { - return ¤t_context; + return current_context; }