X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=context.c;h=764e159f25cc9989722160bfc4cc6419d58bf979;hb=refs%2Fheads%2Fframe-timings;hp=933e1ed03207ad2e533ae0b68a6000f924a73d1f;hpb=b0e640a505171550746af20e940076c579a0e638;p=fips diff --git a/context.c b/context.c index 933e1ed..764e159 100644 --- a/context.c +++ b/context.c @@ -23,8 +23,23 @@ #include "metrics.h" #include "xmalloc.h" +typedef struct context +{ + /* Pointer to the system's context ID, (such as a GLXContext) */ + void *system_id; + + /* Does this context have the AMD_performance_monitor extension? */ + bool have_perfmon; + + metrics_info_t metrics_info; + metrics_t *metrics; +} context_t; + context_t *current_context; +static bool +check_extension (const char *extension); + static context_t * context_create (fips_api_t api, void *system_context_id) { @@ -36,7 +51,9 @@ context_create (fips_api_t api, void *system_context_id) fips_dispatch_init (api); - metrics_info_init (&ctx->metrics_info); + ctx->have_perfmon = check_extension ("GL_AMD_performance_monitor"); + + metrics_info_init (&ctx->metrics_info, ctx->have_perfmon); ctx->metrics = metrics_create (&ctx->metrics_info); return ctx; @@ -51,6 +68,14 @@ context_destroy (context_t *ctx) void context_enter (fips_api_t api, void *system_context_id) { + /* Do nothing for a NULL system_context_id. (Don't ask me why, + * but Dota 2 likes to call MakeCurrent with a NULL context ID + * just before calling MakeCurrent with the same context it + * had been using before. We want to do nothing in this case.) + */ + if (system_context_id == NULL) + return; + /* Do nothing if the application is setting the same context * as is already current. */ if (current_context && current_context->system_id == system_context_id) @@ -74,7 +99,7 @@ context_leave (void) if (ctx == NULL) return; - metrics_destroy (ctx->metrics); + metrics_fini (ctx->metrics); } void @@ -102,7 +127,32 @@ context_get_current_op (void) } void -context_end_frame (void) +context_end_frame_pre_swap (void) +{ + return metrics_end_frame_pre_swap (current_context->metrics); +} + +void +context_end_frame_post_swap (void) { - return metrics_end_frame (current_context->metrics); + return metrics_end_frame_post_swap (current_context->metrics); +} + +/* Is the given extension available? */ +static bool +check_extension (const char *extension) +{ + int i, num_extensions; + const char *available; + + glGetIntegerv (GL_NUM_EXTENSIONS, &num_extensions); + + for (i = 0; i < num_extensions; i++) { + available = (char *) glGetStringi (GL_EXTENSIONS, i); + if (strcmp (extension, available) == 0) { + return true; + } + } + + return false; }