]> git.cworth.org Git - fips/blob - context.c
Begin re-factoring metrics.c into separate context.c and metrics-info.c
[fips] / context.c
1 /* Copyright © 2013, Intel Corporation
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  */
21
22 #include "context.h"
23
24 #include "metrics.h"
25
26 /* FIXME: Need a map from integers to context objects and track the
27  * current context with glXMakeContextCurrent, eglMakeCurrent, etc. */
28
29 context_t current_context;
30
31 void
32 context_enter (fips_api_t api, void *system_context_id unused)
33 {
34         context_t *ctx = &current_context;
35
36         fips_dispatch_init (api);
37
38         metrics_info_init (&ctx->metrics_info);
39
40         metrics_set_current_op (METRICS_OP_SHADER + 0);
41         metrics_counter_start ();
42 }
43
44 void
45 context_leave (void)
46 {
47         context_t *ctx = &current_context;
48         timer_query_t *timer, *timer_next;
49         monitor_t *monitor, *monitor_next;
50
51         metrics_collect_available ();
52
53         if (ctx->timer_begun_id) {
54                 glEndQuery (GL_TIME_ELAPSED);
55                 glDeleteQueries (1, &ctx->timer_begun_id);
56                 ctx->timer_begun_id = 0;
57         }
58
59         for (timer = ctx->timer_head;
60              timer;
61              timer = timer_next)
62         {
63                 glDeleteQueries (1, &timer->id);
64                 timer_next = timer->next;
65                 free (timer);
66         }
67         ctx->timer_head = NULL;
68         ctx->timer_tail = NULL;
69
70         if (ctx->monitor_begun_id) {
71                 glEndPerfMonitorAMD (ctx->monitor_begun_id);
72                 glDeletePerfMonitorsAMD (1, &ctx->monitor_begun_id);
73                 ctx->monitor_begun_id = 0;
74         }
75
76         for (monitor = ctx->monitor_head;
77              monitor;
78              monitor = monitor_next)
79         {
80                 glDeletePerfMonitorsAMD (1, &monitor->id);
81                 monitor_next = monitor->next;
82                 free (monitor);
83         }
84         ctx->monitor_head = NULL;
85         ctx->monitor_tail = NULL;
86
87         current_context.monitors_in_flight = 0;
88
89         metrics_info_fini (&ctx->metrics_info);
90 }
91
92 context_t *
93 context_get_current (void)
94 {
95         return &current_context;
96 }