[clutter/multi-backend: 4/18] Allow checking the backend type at run-time
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/multi-backend: 4/18] Allow checking the backend type at run-time
- Date: Fri, 14 Oct 2011 11:08:02 +0000 (UTC)
commit 540675455187a9e44a553d58ae67a387132438aa
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Mon Sep 26 13:14:26 2011 +0100
Allow checking the backend type at run-time
Portable code should be allowed to check type backend currently being
used, so that it can use platform-specific API (not just Clutter's).
We don't want to go down the GDK route, with public types for
ClutterBackend and ClutterStageWindow implementations, and use the type
system, e.g.:
#ifdef GDK_WINDOWING_X11
if (GDK_IS_WINDOW_X11 (window))
use_x11_api (window);
else
#endif
#ifdef GDK_WINDOWING_WIN32
if (GDK_IS_WINDOW_WIN32 (window))
use_win32_api (window);
else
#endif
g_critical ("Unsupported backend");
This system would make us expose the backend system, and we want to
still reserve us the option to change the backend system to increase its
granularity â e.g. choosing different input event systems regardless of
the windowing system.
This commit adds a simple function that checks the backend type against
a symbolic constant â the same constant string that can be used to
select the backend at run-time through the CLUTTER_BACKEND environment
variable.
clutter/clutter-backend.h | 67 ++++++++++++++++++++++++++++++++++++++++
clutter/clutter-main.c | 70 ++++++++++++++++++++++++++++++++++++++---
clutter/clutter-version.h.in | 2 +
3 files changed, 133 insertions(+), 6 deletions(-)
---
diff --git a/clutter/clutter-backend.h b/clutter/clutter-backend.h
index 22707fc..c51c8dd 100644
--- a/clutter/clutter-backend.h
+++ b/clutter/clutter-backend.h
@@ -49,6 +49,73 @@ G_BEGIN_DECLS
#define CLUTTER_IS_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BACKEND))
/**
+ * CLUTTER_OSX_BACKEND:
+ *
+ * Evaluates to the symbolic name of the Quartz Clutter backend.
+ *
+ * This macro should be used with clutter_check_backend().
+ *
+ * Since: 1.10
+ */
+#define CLUTTER_OSX_BACKEND "osx"
+
+/**
+ * CLUTTER_X11_BACKEND:
+ *
+ * Evaluates to the symbolic name of the X11 Clutter backend.
+ *
+ * This macro should be used with clutter_check_backend().
+ *
+ * Since: 1.10
+ */
+
+#define CLUTTER_X11_BACKEND "x11"
+
+/**
+ * CLUTTER_WIN32_BACKEND:
+ *
+ * Evaluates to the symbolic name of the Windows Clutter backend.
+ *
+ * This macro should be used with clutter_check_backend().
+ *
+ * Since: 1.10
+ */
+#define CLUTTER_WIN32_BACKEND "win32"
+
+/**
+ * CLUTTER_EGL_NATIVE_BACKEND:
+ *
+ * Evaluates to the symbolic name of the EGL framebuffer Clutter backend.
+ *
+ * This macro should be used with clutter_check_backend().
+ *
+ * Since: 1.10
+ */
+#define CLUTTER_EGL_NATIVE_BACKEND "eglnative"
+
+/**
+ * CLUTTER_WAYLAND_BACKEND:
+ *
+ * Evaluates to the symbolic name of the Wayland client Clutter backend.
+ *
+ * This macro should be used with clutter_check_backend().
+ *
+ * Since: 1.10
+ */
+#define CLUTTER_WAYLAND_BACKEND "wayland"
+
+/**
+ * CLUTTER_GDK_BACKEND:
+ *
+ * Evaluates to the symbolic name of the GDK Clutter backend.
+ *
+ * This macro should be used with clutter_check_backend().
+ *
+ * Since: 1.10
+ */
+#define CLUTTER_GDK_BACKEND "gdk"
+
+/**
* ClutterBackend:
*
* <structname>ClutterBackend</structname> is an opaque structure whose
diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c
index 390f9f0..b8bc0bd 100644
--- a/clutter/clutter-main.c
+++ b/clutter/clutter-main.c
@@ -1324,32 +1324,32 @@ clutter_context_get_default_unlocked (void)
backend = g_getenv ("CLUTTER_BACKEND");
#ifdef CLUTTER_WINDOWING_OSX
- if (backend == NULL || strcmp (backend, "osx") == 0)
+ if (backend == NULL || strcmp (backend, CLUTTER_OSX_BACKEND) == 0)
ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_OSX, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_WIN32
- if (backend == NULL || strcmp (backend, "win32") == 0)
+ if (backend == NULL || strcmp (backend, CLUTTER_WIN32_BACKEND) == 0)
ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_WIN32, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_WAYLAND
- if (backend == NULL || strcmp (backend, "wayland") == 0)
+ if (backend == NULL || strcmp (backend, CLUTTER_WAYLAND_BACKEND) == 0)
ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_WAYLAND, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_EGL
- if (backend == NULL || strcmp (backend, "eglnative") == 0)
+ if (backend == NULL || strcmp (backend, CLUTTER_EGL_NATIVE_BACKEND) == 0)
ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_EGLNATIVE, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_X11
- if (backend == NULL || strcmp (backend, "x11") == 0)
+ if (backend == NULL || strcmp (backend, CLUTTER_X11_BACKEND) == 0)
ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_X11, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_GDK
- if (backend == NULL || strcmp (backend, "gdk") == 0)
+ if (backend == NULL || strcmp (backend, CLUTTER_GDK_BACKEND) == 0)
ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_GDK, NULL);
else
#endif
@@ -3599,3 +3599,61 @@ _clutter_context_get_motion_events_enabled (void)
return context->motion_events_per_actor;
}
+
+/**
+ * clutter_check_backend:
+ * @backend_type: the name of the backend to check
+ *
+ * Checks the run-time name of the Clutter backend, using the symbolic
+ * macros like %CLUTTER_OSX_BACKEND or %CLUTTER_X11_BACKEND.
+ *
+ * Return value: %TRUE if the current Clutter backend is the one checked,
+ * and %FALSE otherwise
+ *
+ * Since: 1.10
+ */
+gboolean
+clutter_check_backend (const char *backend_type)
+{
+ ClutterMainContext *context = _clutter_context_get_default ();
+
+ g_return_val_if_fail (backend_type != NULL, FALSE);
+
+#ifdef CLUTTER_WINDOWING_OSX
+ if (strcmp (backend_type, CLUTTER_OSX_BACKEND) == 0 &&
+ CLUTTER_IS_BACKEND_OSX (context->backend))
+ return TRUE;
+ else
+#endif
+#ifdef CLUTTER_WINDOWING_WIN32
+ if (strcmp (backend_type, CLUTTER_WIN32_BACKEND) == 0 &&
+ CLUTTER_IS_BACKEND_WIN32 (context->backend))
+ return TRUE;
+ else
+#endif
+#ifdef CLUTTER_WINDOWING_WAYLAND
+ if (strcmp (backend_type, CLUTTER_WAYLAND_BACKEND) == 0 &&
+ CLUTTER_IS_BACKEND_WAYLAND (context->backend))
+ return TRUE;
+ else
+#endif
+#ifdef CLUTTER_WINDOWING_EGL
+ if (strcmp (backend_type, CLUTTER_EGL_BACKEND) == 0 &&
+ CLUTTER_IS_BACKEND_EGL_NATIVE (context->backend))
+ return TRUE;
+ else
+#endif
+#ifdef CLUTTER_WINDOWING_X11
+ if (strcmp (backend_type, CLUTTER_X11_BACKEND) == 0 &&
+ CLUTTER_IS_BACKEND_X11 (context->backend))
+ return TRUE;
+ else
+#endif
+#ifdef CLUTTER_WINDOWING_GDK
+ if (strcmp (backend_type, CLUTTER_GDK_BACKEND) == 0 &&
+ CLUTTER_IS_BACKEND_GDK (context->backend))
+ return TRUE;
+ else
+#endif
+ return FALSE;
+}
diff --git a/clutter/clutter-version.h.in b/clutter/clutter-version.h.in
index 835e29f..5b38ee0 100644
--- a/clutter/clutter-version.h.in
+++ b/clutter/clutter-version.h.in
@@ -195,6 +195,8 @@ gboolean clutter_check_version (guint major,
guint minor,
guint micro);
+gboolean clutter_check_backend (const char *backend_type);
+
G_END_DECLS
#endif /* __CLUTTER_VERSION_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]