From bc106316b96ce7bfdbec3ee54ba37e49f156dea5 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 28 Oct 2013 14:34:26 -0700 Subject: [PATCH] Add a new context.c file with context_enter and context_leave functions So far, this just factors out some duplicated code from glxwrap.c and eglwrap.c into the new context_enter/leave functions. Eventually, some of the code currently living in metrics.c should migrate up into context.c, (such as the global current_context variable in metrics.c). Additionally, the context.c layer will give us a natural place to query things such as "is the AMD_performance_monitor extension available?". --- Makefile.local | 1 + context.c | 41 +++++++++++++++++++++++++++++++++++++++++ context.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ eglwrap.c | 10 +++------- glxwrap.c | 19 +++++-------------- 5 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 context.c create mode 100644 context.h diff --git a/Makefile.local b/Makefile.local index 4ace9aa..db5c3bc 100644 --- a/Makefile.local +++ b/Makefile.local @@ -90,6 +90,7 @@ LIBRARY_LINK_FLAGS = -shared -Wl,--version-script=libfips.sym extra_cflags += -I$(srcdir) -fPIC libfips_srcs = \ + context.c \ dlwrap.c \ fips-dispatch.c \ fips-dispatch-gl.c \ diff --git a/context.c b/context.c new file mode 100644 index 0000000..6fbd7f2 --- /dev/null +++ b/context.c @@ -0,0 +1,41 @@ +/* Copyright © 2013, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "context.h" + +#include "metrics.h" + +void +context_enter (fips_api_t api, void *system_context_id unused) +{ + fips_dispatch_init (api); + + metrics_info_init (); + + metrics_set_current_op (METRICS_OP_SHADER + 0); + metrics_counter_start (); +} + +void +context_leave (void) +{ + metrics_info_fini (); +} diff --git a/context.h b/context.h new file mode 100644 index 0000000..ded2202 --- /dev/null +++ b/context.h @@ -0,0 +1,44 @@ +/* Copyright © 2013, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef CONTEXT_H +#define CONTEXT_H + +#include "fips-dispatch.h" + +/* Inidcate that a new context has come into use. + * + * Here, 'system_context_id' is a pointer to a system context (such as + * a GLXContext) which fips can use to map to persistent contex_t + * objects if it cares to. + */ +void +context_enter (fips_api_t api, void *system_context_id); + +/* Indicate that the application is done using the current context for now. + * + * The context_enter function should be called before any subsequent + * OpenGL calls are made (other than glXMakeCurrent or similar). + */ +void +context_leave (void); + +#endif diff --git a/eglwrap.c b/eglwrap.c index f5da717..fe7f736 100644 --- a/eglwrap.c +++ b/eglwrap.c @@ -25,6 +25,7 @@ #include +#include "context.h" #include "eglwrap.h" #include "dlwrap.h" #include "metrics.h" @@ -109,16 +110,11 @@ eglMakeCurrent (EGLDisplay display, EGLSurface draw, EGLSurface read, { EGLBoolean ret; - metrics_info_fini (); - - fips_dispatch_init (FIPS_API_EGL); + context_leave (); EGLWRAP_DEFER_WITH_RETURN (ret, eglMakeCurrent, display, draw, read, context); - metrics_info_init (); - - metrics_set_current_op (METRICS_OP_SHADER + 0); - metrics_counter_start (); + context_enter (FIPS_API_EGL, context); return ret; } diff --git a/glxwrap.c b/glxwrap.c index 14b79b7..4545d6f 100644 --- a/glxwrap.c +++ b/glxwrap.c @@ -27,6 +27,7 @@ #include #include +#include "context.h" #include "dlwrap.h" #include "glwrap.h" #include "metrics.h" @@ -84,16 +85,11 @@ glXMakeCurrent (Display *dpy, GLXDrawable drawable, GLXContext ctx) { Bool ret; - metrics_info_fini (); - - fips_dispatch_init (FIPS_API_GLX); + context_leave (); GLWRAP_DEFER_WITH_RETURN (ret, glXMakeCurrent, dpy, drawable, ctx); - metrics_info_init (); - - metrics_set_current_op (METRICS_OP_SHADER + 0); - metrics_counter_start (); + context_enter (FIPS_API_GLX, ctx); return ret; } @@ -103,16 +99,11 @@ glXMakeContextCurrent (Display *dpy, GLXDrawable drawable, GLXDrawable read, GLX { Bool ret; - metrics_info_fini (); - - fips_dispatch_init (FIPS_API_GLX); + context_leave (); GLWRAP_DEFER_WITH_RETURN (ret, glXMakeContextCurrent, dpy, drawable, read, ctx); - metrics_info_init (); - - metrics_set_current_op (METRICS_OP_SHADER + 0); - metrics_counter_start (); + context_enter (FIPS_API_GLX, ctx); return ret; } -- 2.43.0