]> git.cworth.org Git - fips/blobdiff - context.c
Add explicit link to libpthread, to work around debugging issues
[fips] / context.c
index ccaa96a3bd4c13d20cfa181dbaf3c2c9656cf6d8..3c58a60e6b2fbd76ca7a13dfaa3248f67fd43828 100644 (file)
--- a/context.c
+++ b/context.c
 #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;
@@ -61,8 +78,9 @@ context_enter (fips_api_t api, void *system_context_id)
 
        current_context = context_create (api, system_context_id);
 
-       metrics_set_current_op (METRICS_OP_SHADER + 0);
-       metrics_counter_start ();
+       metrics_set_current_op (current_context->metrics,
+                               METRICS_OP_SHADER + 0);
+       metrics_counter_start (current_context->metrics);
 }
 
 void
@@ -76,8 +94,51 @@ context_leave (void)
        metrics_destroy (ctx->metrics);
 }
 
-context_t *
-context_get_current (void)
+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);
+}
+
+/* Is the given extension available? */
+static bool
+check_extension (const char *extension)
 {
-       return current_context;
+       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;
 }