[Piglit] [PATCH 3/5] glut_waffle: Refactor some code into common.[ch]

Chad Versace chad.versace at linux.intel.com
Wed Aug 29 23:16:49 PDT 2012


This is in preparation for adding support for input to glut_waffle. Input
for each platform (X11, Wayland, etc) will be implemented in a separate
file. This patch moves common code needed for each platform from
glut_waffle.c into common.[ch].

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/glut_waffle/CMakeLists.no_api.txt |  2 ++
 src/glut_waffle/CMakeLists.txt        |  2 ++
 src/glut_waffle/glut_waffle.c         | 66 +---------------------------------
 src/glut_waffle/priv/common.c         | 52 +++++++++++++++++++++++++++
 src/glut_waffle/priv/common.h         | 67 +++++++++++++++++++++++++++++++++++
 5 files changed, 124 insertions(+), 65 deletions(-)
 create mode 100644 src/glut_waffle/priv/common.c
 create mode 100644 src/glut_waffle/priv/common.h

diff --git a/src/glut_waffle/CMakeLists.no_api.txt b/src/glut_waffle/CMakeLists.no_api.txt
index 70bd193..63a2e19 100644
--- a/src/glut_waffle/CMakeLists.no_api.txt
+++ b/src/glut_waffle/CMakeLists.no_api.txt
@@ -2,4 +2,6 @@ link_libraries(${WAFFLE_LIBRARIES})
 
 add_library(glut_waffle SHARED
     glut_waffle.c
+
+    priv/common.c
     )
diff --git a/src/glut_waffle/CMakeLists.txt b/src/glut_waffle/CMakeLists.txt
index 144a306..c88d072 100644
--- a/src/glut_waffle/CMakeLists.txt
+++ b/src/glut_waffle/CMakeLists.txt
@@ -1 +1,3 @@
+include_directories(.)
+
 piglit_include_target_api()
diff --git a/src/glut_waffle/glut_waffle.c b/src/glut_waffle/glut_waffle.c
index 3381a2e..1c3b812 100644
--- a/src/glut_waffle/glut_waffle.c
+++ b/src/glut_waffle/glut_waffle.c
@@ -21,8 +21,6 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include "glut_waffle.h"
-
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -30,69 +28,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <waffle.h>
-
-struct glut_waffle_window;
-
-struct glut_waffle_state {
-	/** \brief One of `WAFFLE_PLATFORM_*`. */
-	int waffle_platform;
-
-	/** \brief One of `WAFFLE_CONTEXT_OPENGL*`.
-	 *
-	 * The default value is `WAFFLE_CONTEXT_OPENGL`. To change the value,
-	 * call glutInitAPIMask().
-	 */
-	int waffle_context_api;
-
-	/** \brief A bitmask of enum glut_display_mode`. */
-	int display_mode;
-
-	int window_width;
-	int window_height;
-
-	struct waffle_display *display;
-	struct waffle_context *context;
-	struct glut_window *window;
-
-	int redisplay;
-	int window_id_pool;
-};
-
-static struct glut_waffle_state _glut_waffle_state = {
-	.display_mode = GLUT_RGB,
-	.window_width = 300,
-	.window_height = 300,
-	.window_id_pool = 0,
-};
-
-static struct glut_waffle_state *const _glut = &_glut_waffle_state;
-
-struct glut_window {
-	struct waffle_window *waffle;
-
-	int id;
-
-	GLUT_EGLreshapeCB reshape_cb;
-	GLUT_EGLdisplayCB display_cb;
-	GLUT_EGLkeyboardCB keyboard_cb;
-};
-
-static void
-glutFatal(char *format, ...)
-{
-	va_list args;
-
-	va_start(args, format);
-
-	fflush(stdout);
-	fprintf(stderr, "glut_waffle: ");
-	vfprintf(stderr, format, args);
-	va_end(args);
-	putc('\n', stderr);
-
-	exit(1);
-}
+#include "priv/common.h"
 
 void
 glutInitAPIMask(int mask)
diff --git a/src/glut_waffle/priv/common.c b/src/glut_waffle/priv/common.c
new file mode 100644
index 0000000..71e979e
--- /dev/null
+++ b/src/glut_waffle/priv/common.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2012 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 <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+struct glut_waffle_state _glut_waffle_state = {
+	.display_mode = GLUT_RGB,
+	.window_width = 300,
+	.window_height = 300,
+	.window_id_pool = 0,
+};
+
+struct glut_waffle_state *const _glut = &_glut_waffle_state;
+
+void
+glutFatal(char *format, ...)
+{
+	va_list args;
+
+	va_start(args, format);
+
+	fflush(stdout);
+	fprintf(stderr, "glut_waffle: ");
+	vfprintf(stderr, format, args);
+	va_end(args);
+	putc('\n', stderr);
+
+	exit(1);
+}
diff --git a/src/glut_waffle/priv/common.h b/src/glut_waffle/priv/common.h
new file mode 100644
index 0000000..2b3ebca
--- /dev/null
+++ b/src/glut_waffle/priv/common.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2012 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.
+ */
+
+#pragma once
+
+#include <waffle.h>
+
+#include "glut_waffle.h"
+
+struct glut_window {
+        struct waffle_window *waffle;
+
+        int id;
+
+        GLUT_EGLreshapeCB reshape_cb;
+        GLUT_EGLdisplayCB display_cb;
+        GLUT_EGLkeyboardCB keyboard_cb;
+};
+
+struct glut_waffle_state {
+	/** \brief One of `WAFFLE_PLATFORM_*`. */
+	int waffle_platform;
+
+	/** \brief One of `WAFFLE_CONTEXT_OPENGL*`.
+	 *
+	 * The default value is `WAFFLE_CONTEXT_OPENGL`. To change the value,
+	 * call glutInitAPIMask().
+	 */
+	int waffle_context_api;
+
+	/** \brief A bitmask of enum glut_display_mode`. */
+	int display_mode;
+
+	int window_width;
+	int window_height;
+
+	struct waffle_display *display;
+	struct waffle_context *context;
+	struct glut_window *window;
+
+	int redisplay;
+	int window_id_pool;
+};
+
+extern struct glut_waffle_state *const _glut;
+
+void
+glutFatal(char *format, ...);
-- 
1.7.12



More information about the Piglit mailing list