From a2573ad2ad39931d2a817d4585d87b70c3f86526 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 1 Mar 2010 11:38:41 +0000 Subject: [PATCH] eglnative: Add CLUTTER_FB_DEVICE Some EGL drivers for embedded devices require a specific framebuffer device to be opened and passed to eglCreateWindowSurface(). Since it's optional, we can provide an environment variabled called CLUTTER_FB_DEVICE that can be used to specify the path of the device to be opened. http://bugzilla.openedhand.com/show_bug.cgi?id=1997 --- clutter/eglnative/clutter-backend-egl.c | 59 ++++++++++++++++++++++--- clutter/eglnative/clutter-backend-egl.h | 3 ++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/clutter/eglnative/clutter-backend-egl.c b/clutter/eglnative/clutter-backend-egl.c index 59fee18dc..d3c992e03 100644 --- a/clutter/eglnative/clutter-backend-egl.c +++ b/clutter/eglnative/clutter-backend-egl.c @@ -2,14 +2,21 @@ #include "config.h" #endif +#include +#include +#include + #include "clutter-backend-egl.h" #include "clutter-stage-egl.h" + #include "../clutter-private.h" #include "../clutter-main.h" #include "../clutter-debug.h" static ClutterBackendEGL *backend_singleton = NULL; +static const gchar *clutter_fb_device = NULL; + G_DEFINE_TYPE (ClutterBackendEGL, clutter_backend_egl, CLUTTER_TYPE_BACKEND); static void @@ -23,6 +30,12 @@ static gboolean clutter_backend_egl_pre_parse (ClutterBackend *backend, GError **error) { + const gchar *env_string; + + env_string = g_getenv ("CLUTTER_FB_DEVICE"); + if (env_string != NULL && env_string[0] != '\0') + clutter_fb_device = g_strdup (env_string); + return TRUE; } @@ -130,11 +143,39 @@ clutter_backend_egl_create_context (ClutterBackend *backend, backend_egl->egl_context = NULL; } - backend_egl->egl_surface = - eglCreateWindowSurface (backend_egl->edpy, - configs[0], - NULL, - NULL); + if (clutter_fb_device != NULL) + { + int fd = open (clutter_fb_device, O_RDWR); + + if (fd < 0) + { + int errno_save = errno; + + g_set_error (error, CLUTTER_INIT_ERROR, + CLUTTER_INIT_ERROR_BACKEND, + "Unable to open the framebuffer device '%s': %s", + clutter_fb_device, + g_strerror (errno_save)); + + return FALSE; + } + else + backend_egl->fb_device_id = fd; + + backend_egl->egl_surface = + eglCreateWindowSurface (backend_egl->edpy, + configs[0], + (NativeWindowType) backend_egl->fb_device_id, + NULL); + } + else + { + backend_egl->egl_surface = + eglCreateWindowSurface (backend_egl->edpy, + configs[0], + NULL, + NULL); + } if (backend_egl->egl_surface == EGL_NO_SURFACE) { @@ -295,6 +336,12 @@ clutter_backend_egl_dispose (GObject *gobject) backend_egl->egl_surface = EGL_NO_SURFACE; } + if (backend_egl->fb_device_id != -1) + { + close (backend_egl->fb_device_id); + backend_egl->fb_device_id = -1; + } + if (backend_egl->egl_context != NULL) { eglDestroyContext (backend_egl->edpy, backend_egl->egl_context); @@ -394,6 +441,8 @@ clutter_backend_egl_init (ClutterBackendEGL *backend_egl) clutter_backend_set_double_click_distance (backend, 5); backend_egl->event_timer = g_timer_new (); + + backend_egl->fb_device_id = -1; } GType diff --git a/clutter/eglnative/clutter-backend-egl.h b/clutter/eglnative/clutter-backend-egl.h index 9731d7908..deb4e8a41 100644 --- a/clutter/eglnative/clutter-backend-egl.h +++ b/clutter/eglnative/clutter-backend-egl.h @@ -66,6 +66,9 @@ struct _ClutterBackendEGL /* event timer */ GTimer *event_timer; + /* FB device */ + gint fb_device_id; + /*< private >*/ };