]> git.cworth.org Git - fips/commitdiff
Add a new context.c file with context_enter and context_leave functions
authorCarl Worth <cworth@cworth.org>
Mon, 28 Oct 2013 21:34:26 +0000 (14:34 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 28 Oct 2013 21:34:26 +0000 (14:34 -0700)
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
context.c [new file with mode: 0644]
context.h [new file with mode: 0644]
eglwrap.c
glxwrap.c

index 4ace9aa0159fae299c1cf913ee250ad44ac6a1b4..db5c3bc4958632fe388427b179c1f6d927662b19 100644 (file)
@@ -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 (file)
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 (file)
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
index f5da71726db498c972d04e78e67748bbca709c00..fe7f736243195c0c51eaaedfa007dac30ed07e08 100644 (file)
--- a/eglwrap.c
+++ b/eglwrap.c
@@ -25,6 +25,7 @@
 
 #include <EGL/egl.h>
 
+#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;
 }
index 14b79b7b3b1e09dc79e65e0acaf72db212d5d133..4545d6fbd79186218145cddb5aaa666edb8fb859 100644 (file)
--- a/glxwrap.c
+++ b/glxwrap.c
@@ -27,6 +27,7 @@
 #include <GL/gl.h>
 #include <GL/glx.h>
 
+#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;
 }