[clutter/android-enter-leave: 1/29] Add android backend



commit f2710a9058137f274dc69419d180333b648581e2
Author: Lionel Landwerlin <llandwerlin gmail com>
Date:   Fri May 25 15:06:42 2012 +0100

    Add android backend

 clutter/Makefile.am                              |   33 ++
 clutter/android/android_native_app_glue.h        |  349 ++++++++++++++++++++
 clutter/android/clutter-android-application.c    |  384 ++++++++++++++++++++++
 clutter/android/clutter-android-application.h    |   85 +++++
 clutter/android/clutter-android.h                |   36 ++
 clutter/android/clutter-backend-android.c        |   78 +++++
 clutter/android/clutter-backend-android.h        |   64 ++++
 clutter/android/clutter-device-manager-android.c |  211 ++++++++++++
 clutter/android/clutter-device-manager-android.h |   79 +++++
 clutter/clutter-backend.c                        |   11 +
 clutter/clutter-main.c                           |   14 +
 clutter/clutter-marshal.list                     |   12 +-
 configure.ac                                     |   27 ++
 13 files changed, 1378 insertions(+), 5 deletions(-)
---
diff --git a/clutter/Makefile.am b/clutter/Makefile.am
index 413950c..7cac79b 100644
--- a/clutter/Makefile.am
+++ b/clutter/Makefile.am
@@ -504,6 +504,39 @@ pc_files += clutter-gdk-$(CLUTTER_API_VERSION).pc
 gdk_introspection = $(gdk_source_c) $(gdk_source_h)
 endif # SUPPORT_GDK
 
+
+android_source_c = \
+	$(srcdir)/android/clutter-android-application.c	\
+	$(NULL)
+
+android_source_c_priv = \
+	$(srcdir)/android/clutter-device-manager-android.c \
+	$(srcdir)/android/clutter-backend-android.c \
+	$(NULL)
+
+android_source_h = \
+	$(srcdir)/android/clutter-android-application.h	\
+	$(srcdir)/android/clutter-android.h		\
+	$(NULL)
+
+android_source_h_priv = \
+	$(srcdir)/android/android_native_app_glue.h		\
+	$(srcdir)/android/clutter-device-manager-android.h	\
+	$(srcdir)/android/clutter-backend-android.h \
+	$(NULL)
+
+if SUPPORT_ANDROID
+
+AM_CFLAGS += -I$(srcdir)/android
+backend_source_h += $(android_source_h)
+backend_source_c += $(android_source_c)
+backend_source_h_priv += $(android_source_h_priv)
+backend_source_c_priv += $(android_source_c_priv)
+
+android_includedir = $(clutter_includedir)/android
+android_include_HEADERS = $(android_source_h)
+endif # SUPPORT_ANDROID
+
 # Windows backend rules
 win32_source_c = \
 	$(srcdir)/win32/clutter-backend-win32.c		\
diff --git a/clutter/android/android_native_app_glue.h b/clutter/android/android_native_app_glue.h
new file mode 100644
index 0000000..1b8c1f1
--- /dev/null
+++ b/clutter/android/android_native_app_glue.h
@@ -0,0 +1,349 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _ANDROID_NATIVE_APP_GLUE_H
+#define _ANDROID_NATIVE_APP_GLUE_H
+
+#include <poll.h>
+#include <pthread.h>
+#include <sched.h>
+
+#include <android/configuration.h>
+#include <android/looper.h>
+#include <android/native_activity.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The native activity interface provided by <android/native_activity.h>
+ * is based on a set of application-provided callbacks that will be called
+ * by the Activity's main thread when certain events occur.
+ *
+ * This means that each one of this callbacks _should_ _not_ block, or they
+ * risk having the system force-close the application. This programming
+ * model is direct, lightweight, but constraining.
+ *
+ * The 'threaded_native_app' static library is used to provide a different
+ * execution model where the application can implement its own main event
+ * loop in a different thread instead. Here's how it works:
+ *
+ * 1/ The application must provide a function named "android_main()" that
+ *    will be called when the activity is created, in a new thread that is
+ *    distinct from the activity's main thread.
+ *
+ * 2/ android_main() receives a pointer to a valid "android_app" structure
+ *    that contains references to other important objects, e.g. the
+ *    ANativeActivity obejct instance the application is running in.
+ *
+ * 3/ the "android_app" object holds an ALooper instance that already
+ *    listens to two important things:
+ *
+ *      - activity lifecycle events (e.g. "pause", "resume"). See APP_CMD_XXX
+ *        declarations below.
+ *
+ *      - input events coming from the AInputQueue attached to the activity.
+ *
+ *    Each of these correspond to an ALooper identifier returned by
+ *    ALooper_pollOnce with values of LOOPER_ID_MAIN and LOOPER_ID_INPUT,
+ *    respectively.
+ *
+ *    Your application can use the same ALooper to listen to additional
+ *    file-descriptors.  They can either be callback based, or with return
+ *    identifiers starting with LOOPER_ID_USER.
+ *
+ * 4/ Whenever you receive a LOOPER_ID_MAIN or LOOPER_ID_INPUT event,
+ *    the returned data will point to an android_poll_source structure.  You
+ *    can call the process() function on it, and fill in android_app->onAppCmd
+ *    and android_app->onInputEvent to be called for your own processing
+ *    of the event.
+ *
+ *    Alternatively, you can call the low-level functions to read and process
+ *    the data directly...  look at the process_cmd() and process_input()
+ *    implementations in the glue to see how to do this.
+ *
+ * See the sample named "native-activity" that comes with the NDK with a
+ * full usage example.  Also look at the JavaDoc of NativeActivity.
+ */
+
+struct android_app;
+
+/**
+ * Data associated with an ALooper fd that will be returned as the "outData"
+ * when that source has data ready.
+ */
+struct android_poll_source {
+    // The identifier of this source.  May be LOOPER_ID_MAIN or
+    // LOOPER_ID_INPUT.
+    int32_t id;
+
+    // The android_app this ident is associated with.
+    struct android_app* app;
+
+    // Function to call to perform the standard processing of data from
+    // this source.
+    void (*process)(struct android_app* app, struct android_poll_source* source);
+};
+
+/**
+ * This is the interface for the standard glue code of a threaded
+ * application.  In this model, the application's code is running
+ * in its own thread separate from the main thread of the process.
+ * It is not required that this thread be associated with the Java
+ * VM, although it will need to be in order to make JNI calls any
+ * Java objects.
+ */
+struct android_app {
+    // The application can place a pointer to its own state object
+    // here if it likes.
+    void* userData;
+
+    // Fill this in with the function to process main app commands (APP_CMD_*)
+    void (*onAppCmd)(struct android_app* app, int32_t cmd);
+
+    // Fill this in with the function to process input events.  At this point
+    // the event has already been pre-dispatched, and it will be finished upon
+    // return.  Return 1 if you have handled the event, 0 for any default
+    // dispatching.
+    int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event);
+
+    // The ANativeActivity object instance that this app is running in.
+    ANativeActivity* activity;
+
+    // The current configuration the app is running in.
+    AConfiguration* config;
+
+    // This is the last instance's saved state, as provided at creation time.
+    // It is NULL if there was no state.  You can use this as you need; the
+    // memory will remain around until you call android_app_exec_cmd() for
+    // APP_CMD_RESUME, at which point it will be freed and savedState set to NULL.
+    // These variables should only be changed when processing a APP_CMD_SAVE_STATE,
+    // at which point they will be initialized to NULL and you can malloc your
+    // state and place the information here.  In that case the memory will be
+    // freed for you later.
+    void* savedState;
+    size_t savedStateSize;
+
+    // The ALooper associated with the app's thread.
+    ALooper* looper;
+
+    // When non-NULL, this is the input queue from which the app will
+    // receive user input events.
+    AInputQueue* inputQueue;
+
+    // When non-NULL, this is the window surface that the app can draw in.
+    ANativeWindow* window;
+
+    // Current content rectangle of the window; this is the area where the
+    // window's content should be placed to be seen by the user.
+    ARect contentRect;
+
+    // Current state of the app's activity.  May be either APP_CMD_START,
+    // APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below.
+    int activityState;
+
+    // This is non-zero when the application's NativeActivity is being
+    // destroyed and waiting for the app thread to complete.
+    int destroyRequested;
+
+    // -------------------------------------------------
+    // Below are "private" implementation of the glue code.
+
+    pthread_mutex_t mutex;
+    pthread_cond_t cond;
+
+    int msgread;
+    int msgwrite;
+
+    pthread_t thread;
+
+    struct android_poll_source cmdPollSource;
+    struct android_poll_source inputPollSource;
+
+    int running;
+    int stateSaved;
+    int destroyed;
+    int redrawNeeded;
+    AInputQueue* pendingInputQueue;
+    ANativeWindow* pendingWindow;
+    ARect pendingContentRect;
+};
+
+enum {
+    /**
+     * Looper data ID of commands coming from the app's main thread, which
+     * is returned as an identifier from ALooper_pollOnce().  The data for this
+     * identifier is a pointer to an android_poll_source structure.
+     * These can be retrieved and processed with android_app_read_cmd()
+     * and android_app_exec_cmd().
+     */
+    LOOPER_ID_MAIN = 1,
+
+    /**
+     * Looper data ID of events coming from the AInputQueue of the
+     * application's window, which is returned as an identifier from
+     * ALooper_pollOnce().  The data for this identifier is a pointer to an
+     * android_poll_source structure.  These can be read via the inputQueue
+     * object of android_app.
+     */
+    LOOPER_ID_INPUT = 2,
+
+    /**
+     * Start of user-defined ALooper identifiers.
+     */
+    LOOPER_ID_USER = 3,
+};
+
+enum {
+    /**
+     * Command from main thread: the AInputQueue has changed.  Upon processing
+     * this command, android_app->inputQueue will be updated to the new queue
+     * (or NULL).
+     */
+    APP_CMD_INPUT_CHANGED,
+
+    /**
+     * Command from main thread: a new ANativeWindow is ready for use.  Upon
+     * receiving this command, android_app->window will contain the new window
+     * surface.
+     */
+    APP_CMD_INIT_WINDOW,
+
+    /**
+     * Command from main thread: the existing ANativeWindow needs to be
+     * terminated.  Upon receiving this command, android_app->window still
+     * contains the existing window; after calling android_app_exec_cmd
+     * it will be set to NULL.
+     */
+    APP_CMD_TERM_WINDOW,
+
+    /**
+     * Command from main thread: the current ANativeWindow has been resized.
+     * Please redraw with its new size.
+     */
+    APP_CMD_WINDOW_RESIZED,
+
+    /**
+     * Command from main thread: the system needs that the current ANativeWindow
+     * be redrawn.  You should redraw the window before handing this to
+     * android_app_exec_cmd() in order to avoid transient drawing glitches.
+     */
+    APP_CMD_WINDOW_REDRAW_NEEDED,
+
+    /**
+     * Command from main thread: the content area of the window has changed,
+     * such as from the soft input window being shown or hidden.  You can
+     * find the new content rect in android_app::contentRect.
+     */
+    APP_CMD_CONTENT_RECT_CHANGED,
+
+    /**
+     * Command from main thread: the app's activity window has gained
+     * input focus.
+     */
+    APP_CMD_GAINED_FOCUS,
+
+    /**
+     * Command from main thread: the app's activity window has lost
+     * input focus.
+     */
+    APP_CMD_LOST_FOCUS,
+
+    /**
+     * Command from main thread: the current device configuration has changed.
+     */
+    APP_CMD_CONFIG_CHANGED,
+
+    /**
+     * Command from main thread: the system is running low on memory.
+     * Try to reduce your memory use.
+     */
+    APP_CMD_LOW_MEMORY,
+
+    /**
+     * Command from main thread: the app's activity has been started.
+     */
+    APP_CMD_START,
+
+    /**
+     * Command from main thread: the app's activity has been resumed.
+     */
+    APP_CMD_RESUME,
+
+    /**
+     * Command from main thread: the app should generate a new saved state
+     * for itself, to restore from later if needed.  If you have saved state,
+     * allocate it with malloc and place it in android_app.savedState with
+     * the size in android_app.savedStateSize.  The will be freed for you
+     * later.
+     */
+    APP_CMD_SAVE_STATE,
+
+    /**
+     * Command from main thread: the app's activity has been paused.
+     */
+    APP_CMD_PAUSE,
+
+    /**
+     * Command from main thread: the app's activity has been stopped.
+     */
+    APP_CMD_STOP,
+
+    /**
+     * Command from main thread: the app's activity is being destroyed,
+     * and waiting for the app thread to clean up and exit before proceeding.
+     */
+    APP_CMD_DESTROY,
+};
+
+/**
+ * Call when ALooper_pollAll() returns LOOPER_ID_MAIN, reading the next
+ * app command message.
+ */
+int8_t android_app_read_cmd(struct android_app* android_app);
+
+/**
+ * Call with the command returned by android_app_read_cmd() to do the
+ * initial pre-processing of the given command.  You can perform your own
+ * actions for the command after calling this function.
+ */
+void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd);
+
+/**
+ * Call with the command returned by android_app_read_cmd() to do the
+ * final post-processing of the given command.  You must have done your own
+ * actions for the command before calling this function.
+ */
+void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd);
+
+/**
+ * Dummy function you can call to ensure glue code isn't stripped.
+ */
+void app_dummy();
+
+/**
+ * This is the function that application code must implement, representing
+ * the main entry to the app.
+ */
+extern void android_main(struct android_app* app);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ANDROID_NATIVE_APP_GLUE_H */
diff --git a/clutter/android/clutter-android-application.c b/clutter/android/clutter-android-application.c
new file mode 100644
index 0000000..a82cf36
--- /dev/null
+++ b/clutter/android/clutter-android-application.c
@@ -0,0 +1,384 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2011 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *   Damien Lespiau <damien lespiau intel com>
+ */
+
+#include <stdlib.h>
+#include <config.h>
+
+#include <android_native_app_glue.h>
+#include <android/input.h>
+
+#include <cogl/cogl.h>
+#include <glib-android/glib-android.h>
+
+#include "clutter-main.h"
+#include "clutter-marshal.h"
+#include "clutter-private.h"
+#include "clutter-device-manager-private.h"
+
+#include "clutter-android-application.h"
+
+
+#include "deprecated/clutter-stage.h"
+
+G_DEFINE_TYPE (ClutterAndroidApplication,
+               clutter_android_application,
+               G_TYPE_OBJECT)
+
+#define ANDROID_APPLICATION_PRIVATE(o)                            \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o),                              \
+                                CLUTTER_TYPE_ANDROID_APPLICATION, \
+                                ClutterAndroidApplicationPrivate))
+
+enum
+{
+  READY,
+
+  LAST_SIGNAL,
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+struct _ClutterAndroidApplicationPrivate
+{
+  struct android_app* android_application;
+
+  gint have_window : 1;
+  GMainLoop *wait_for_window;
+};
+
+static gboolean
+clutter_android_application_ready (ClutterAndroidApplication *application)
+{
+  ClutterAndroidApplicationPrivate *priv = application->priv;
+  g_message ("ready!");
+
+  cogl_android_set_native_window (priv->android_application->window);
+
+  return TRUE;
+}
+
+static void
+clutter_android_application_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (clutter_android_application_parent_class)->finalize (object);
+}
+
+static void
+clutter_android_application_class_init (ClutterAndroidApplicationClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (ClutterAndroidApplicationPrivate));
+
+  object_class->finalize = clutter_android_application_finalize;
+
+  klass->ready = clutter_android_application_ready;
+
+  signals[READY] =
+    g_signal_new (I_("ready"),
+                  G_TYPE_FROM_CLASS (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (ClutterAndroidApplicationClass, ready),
+                  NULL, NULL,
+                  _clutter_marshal_BOOLEAN__VOID,
+                  G_TYPE_BOOLEAN, 0);
+}
+
+static void
+clutter_android_application_init (ClutterAndroidApplication *self)
+{
+  self->priv = ANDROID_APPLICATION_PRIVATE (self);
+}
+
+static ClutterAndroidApplication *
+clutter_android_application_new (void)
+{
+  return g_object_new (CLUTTER_TYPE_ANDROID_APPLICATION, NULL);
+}
+
+/*
+ * Process the next main command.
+ */
+static void
+clutter_android_handle_cmd (struct android_app *app,
+                            int32_t             cmd)
+{
+  ClutterAndroidApplication *application;
+  ClutterAndroidApplicationPrivate *priv;
+
+  application = CLUTTER_ANDROID_APPLICATION (app->userData);
+  priv = application->priv;
+
+  switch (cmd)
+    {
+    case APP_CMD_INIT_WINDOW:
+      /* The window is being shown, get it ready */
+      g_message ("command: INIT_WINDOW");
+      if (app->window != NULL)
+        {
+          gboolean initialized;
+
+          g_signal_emit (application, signals[READY], 0, &initialized);
+
+          if (initialized)
+            priv->have_window = TRUE;
+
+          if (priv->wait_for_window)
+            {
+              g_message ("Waking up the waiting main loop");
+              g_main_loop_quit (priv->wait_for_window);
+            }
+        }
+      break;
+
+    case APP_CMD_TERM_WINDOW:
+      /* The window is being hidden or closed, clean it up */
+      g_message ("command: TERM_WINDOW");
+      if (priv->wait_for_window)
+        g_main_loop_quit (priv->wait_for_window);
+      else
+        clutter_main_quit ();
+      exit (0);
+      //test_fini (data);
+      break;
+
+    case APP_CMD_GAINED_FOCUS:
+      g_message ("command: GAINED_FOCUS");
+      break;
+
+    case APP_CMD_LOST_FOCUS:
+      /* When our app loses focus, we stop monitoring the accelerometer.
+       * This is to avoid consuming battery while not being used. */
+      g_message ("command: LOST_FOCUS");
+      break;
+    }
+}
+
+static gboolean
+translate_motion_event (ClutterEvent *event, AInputEvent *a_event)
+{
+  int32_t action;
+  ClutterDeviceManager *manager;
+  ClutterInputDevice *pointer_device;
+
+  /* g_message ("\tbutton/motion event: (%.02lf,%0.2lf)", */
+  /*            AMotionEvent_getX (a_event, 0), */
+  /*            AMotionEvent_getY (a_event, 0)); */
+
+  manager = clutter_device_manager_get_default ();
+  pointer_device =
+    clutter_device_manager_get_core_device (manager,
+                                            CLUTTER_POINTER_DEVICE);
+  _clutter_input_device_set_stage (pointer_device, event->any.stage);
+
+  action = AMotionEvent_getAction (a_event);
+
+  switch (action & AMOTION_EVENT_ACTION_MASK)
+    {
+    case AMOTION_EVENT_ACTION_DOWN:
+      /* g_message ("\tPress"); */
+      event->button.type = event->type = CLUTTER_BUTTON_PRESS;
+      event->button.button = 1;
+      event->button.click_count = 1;
+      event->button.device = pointer_device;
+      event->button.time = AMotionEvent_getEventTime (a_event);
+      event->button.x = AMotionEvent_getX (a_event, 0);
+      event->button.y = AMotionEvent_getY (a_event, 0);
+      break;
+
+    case AMOTION_EVENT_ACTION_UP:
+      /* g_message ("\tRelease"); */
+      event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
+      event->button.button = 1;
+      event->button.click_count = 1;
+      event->button.device = pointer_device;
+      event->button.time = AMotionEvent_getEventTime (a_event);
+      event->button.x = AMotionEvent_getX (a_event, 0);
+      event->button.y = AMotionEvent_getY (a_event, 0);
+      break;
+
+    case AMOTION_EVENT_ACTION_MOVE:
+      /* g_message ("\tMove"); */
+      event->motion.type = event->type = CLUTTER_MOTION;
+      event->motion.device = pointer_device;
+      event->motion.modifier_state = CLUTTER_BUTTON1_MASK;
+      event->motion.time = AMotionEvent_getEventTime (a_event);
+      event->motion.x = AMotionEvent_getX (a_event, 0);
+      event->motion.y = AMotionEvent_getY (a_event, 0);
+      break;
+
+    default:
+      g_message ("\tmeh? %i\n", action);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+static gboolean
+translate_key_event (ClutterEvent *event, AInputEvent *a_event)
+{
+  int32_t state;
+
+  /* g_message ("\tbutton/motion event: (%.02lf,%0.2lf)", */
+  /*            AMotionEvent_getX (a_event, 0), */
+  /*            AMotionEvent_getY (a_event, 0)); */
+
+  state = AMotionEvent_getMetaState (a_event);
+
+  event->key.unicode_value = AKeyEvent_getKeyCode (a_event);
+
+  switch (state)
+    {
+    case AKEY_STATE_UP:
+      /* g_message ("\tkey release"); */
+      event->type = event->key.type = CLUTTER_KEY_RELEASE;
+      break;
+
+    case AKEY_STATE_DOWN:
+    case AKEY_STATE_VIRTUAL: /* TODO: Should we synthetize release? */
+      /* g_message ("\tkey press"); */
+      event->type = event->key.type = CLUTTER_KEY_PRESS;
+      break;
+
+    default:
+      /* g_message ("\tmeh? %i", state); */
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+/**
+ * Process the next input event
+ */
+static int32_t
+clutter_android_handle_input (struct android_app *app,
+                              AInputEvent        *a_event)
+{
+  ClutterEvent *event;
+  gboolean process = FALSE;
+
+  g_message ("input!");
+
+  event = clutter_event_new (CLUTTER_NOTHING);
+  event->any.stage =
+    clutter_stage_manager_get_default_stage (clutter_stage_manager_get_default ());
+
+  g_message ("plop!");
+  if (AInputEvent_getType (a_event) == AINPUT_EVENT_TYPE_KEY)
+    {
+      process = translate_key_event (event, a_event);
+    }
+  else if (AInputEvent_getType (a_event) == AINPUT_EVENT_TYPE_MOTION)
+    {
+      process = translate_motion_event (event, a_event);
+    }
+
+  if (process)
+    clutter_do_event (event);
+  clutter_event_free (event);
+
+  return (int32_t) process;
+}
+
+/* XXX: We should be able to get rid of that */
+static gboolean
+check_ready (gpointer user_data)
+{
+  ClutterAndroidApplication *application = user_data;
+  ClutterAndroidApplicationPrivate *priv = application->priv;
+
+  if (priv->have_window && priv->wait_for_window)
+    {
+      g_main_loop_quit (priv->wait_for_window);
+      return FALSE;
+    }
+
+  if (priv->have_window)
+    return FALSE;
+
+  return TRUE;
+}
+
+void
+clutter_android_application_run (ClutterAndroidApplication *application)
+{
+  ClutterAndroidApplicationPrivate *priv = application->priv;;
+
+  g_return_if_fail (CLUTTER_IS_ANDROID_APPLICATION (application));
+
+  /* XXX: eeew. We wait to have a window to initialize Clutter and thus to
+   * enter the clutter main loop */
+  if (!priv->have_window)
+    {
+      g_message ("Waiting for the window");
+      priv->wait_for_window = g_main_loop_new (NULL, FALSE);
+      g_timeout_add (1000, check_ready, application);
+      g_main_loop_run (priv->wait_for_window);
+      g_main_loop_unref (priv->wait_for_window);
+      priv->wait_for_window = NULL;
+    }
+
+  g_message ("entering main loop");
+  clutter_main ();
+}
+
+AAssetManager *
+clutter_android_application_get_asset_manager (ClutterAndroidApplication *application)
+{
+  g_return_val_if_fail (CLUTTER_IS_ANDROID_APPLICATION (application), NULL);
+
+  return application->priv->android_application->activity->assetManager;
+}
+
+
+/*
+ * This is the main entry point of a native application that is using
+ * android_native_app_glue.  It runs in its own thread, with its own
+ * event loop for receiving input events and doing other things.
+ */
+void
+android_main (struct android_app* android_application)
+{
+  ClutterAndroidApplication *clutter_application;
+  ClutterAndroidApplicationPrivate *priv;
+
+  /* Make sure glue isn't stripped */
+  app_dummy ();
+
+  g_type_init ();
+  g_android_init ();
+
+  clutter_application = clutter_android_application_new ();
+  priv = clutter_application->priv;
+
+  android_application->userData = clutter_application;
+  android_application->onAppCmd = clutter_android_handle_cmd;
+  android_application->onInputEvent = clutter_android_handle_input;
+
+  priv->android_application = android_application;
+
+  clutter_android_main (clutter_application);
+}
diff --git a/clutter/android/clutter-android-application.h b/clutter/android/clutter-android-application.h
new file mode 100644
index 0000000..d68a41f
--- /dev/null
+++ b/clutter/android/clutter-android-application.h
@@ -0,0 +1,85 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2011 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *   Damien Lespiau <damien lespiau intel com>
+ */
+
+#ifndef __CLUTTER_ANDROID_APPLICATION_H__
+#define __CLUTTER_ANDROID_APPLICATION_H__
+
+#include <glib-object.h>
+
+#include <android/asset_manager.h>
+
+G_BEGIN_DECLS
+
+#define CLUTTER_TYPE_ANDROID_APPLICATION clutter_android_application_get_type()
+
+#define CLUTTER_ANDROID_APPLICATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+  CLUTTER_TYPE_ANDROID_APPLICATION, ClutterAndroidApplication))
+
+#define CLUTTER_ANDROID_APPLICATION_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+  CLUTTER_TYPE_ANDROID_APPLICATION, ClutterAndroidApplicationClass))
+
+#define CLUTTER_IS_ANDROID_APPLICATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+  CLUTTER_TYPE_ANDROID_APPLICATION))
+
+#define CLUTTER_IS_ANDROID_APPLICATION_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+  CLUTTER_TYPE_ANDROID_APPLICATION))
+
+#define CLUTTER_ANDROID_APPLICATION_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+  CLUTTER_TYPE_ANDROID_APPLICATION, ClutterAndroidApplicationClass))
+
+typedef struct _ClutterAndroidApplication ClutterAndroidApplication;
+typedef struct _ClutterAndroidApplicationClass ClutterAndroidApplicationClass;
+typedef struct _ClutterAndroidApplicationPrivate ClutterAndroidApplicationPrivate;
+
+struct _ClutterAndroidApplication
+{
+  GObject parent;
+
+  ClutterAndroidApplicationPrivate *priv;
+};
+
+struct _ClutterAndroidApplicationClass
+{
+  GObjectClass parent_class;
+
+  /* signals */
+  gboolean (*ready) (ClutterAndroidApplication *self);
+};
+
+/* Entry point for android clutter applications */
+void clutter_android_main (ClutterAndroidApplication *application);
+
+GType clutter_android_application_get_type (void) G_GNUC_CONST;
+
+void              clutter_android_application_run                   (ClutterAndroidApplication *application);
+AAssetManager *   clutter_android_application_get_asset_manager     (ClutterAndroidApplication *application);
+
+G_END_DECLS
+
+#endif /* __CLUTTER_ANDROID_APPLICATION_H__ */
diff --git a/clutter/android/clutter-android.h b/clutter/android/clutter-android.h
new file mode 100644
index 0000000..863b007
--- /dev/null
+++ b/clutter/android/clutter-android.h
@@ -0,0 +1,36 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *   Damien Lespiau <damien lespiau intel com>
+ */
+
+#ifndef __CLUTTER_ANDROID_H__
+#define __CLUTTER_ANDROID_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#include <clutter/android/clutter-android-application.h>
+
+G_END_DECLS
+
+#endif /* __CLUTTER_ANDROID_H__ */
diff --git a/clutter/android/clutter-backend-android.c b/clutter/android/clutter-backend-android.c
new file mode 100644
index 0000000..fe3b207
--- /dev/null
+++ b/clutter/android/clutter-backend-android.c
@@ -0,0 +1,78 @@
+/* Clutter -  An OpenGL based 'interactive canvas' library.
+ * Android backend - initial entry point
+ *
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Lionel Landwerlin <lionel g landwerlin linux intel com>
+ */
+#include "config.h"
+
+#include "clutter-backend-android.h"
+#include "clutter-device-manager-android.h"
+
+#include "clutter-debug.h"
+#include "clutter-private.h"
+#include "clutter-stage-private.h"
+#include "cogl/clutter-stage-cogl.h"
+
+#include "cogl/cogl.h"
+
+#define DEFAULT_FONT_NAME       "Lucida Grande 13"
+
+#define clutter_backend_android_get_type    _clutter_backend_android_get_type
+
+G_DEFINE_TYPE (ClutterBackendAndroid, clutter_backend_android, CLUTTER_TYPE_BACKEND)
+
+/*************************************************************************/
+
+void
+_clutter_backend_android_events_init (ClutterBackend *backend)
+{
+  if (backend->device_manager != NULL)
+    return;
+
+  CLUTTER_NOTE (BACKEND, "init_events");
+
+  backend->device_manager =
+    g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_ANDROID,
+                  "backend", backend,
+                  NULL);
+}
+
+/*************************************************************************/
+
+static void
+clutter_backend_android_init (ClutterBackendAndroid *backend_android)
+{
+}
+
+static void
+clutter_backend_android_dispose (GObject *object)
+{
+  G_OBJECT_CLASS (clutter_backend_android_parent_class)->dispose (object);
+}
+
+static void
+clutter_backend_android_class_init (ClutterBackendAndroidClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
+
+  object_class->dispose = clutter_backend_android_dispose;
+
+  backend_class->stage_window_type = CLUTTER_TYPE_STAGE_COGL;
+}
diff --git a/clutter/android/clutter-backend-android.h b/clutter/android/clutter-backend-android.h
new file mode 100644
index 0000000..15024ea
--- /dev/null
+++ b/clutter/android/clutter-backend-android.h
@@ -0,0 +1,64 @@
+/* Clutter.
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2006, 2007 OpenedHand
+ * Copyright (C) 2010 Intel Corp
+ *               2011 Giovanni Campagna <scampa giovanni gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Matthew Allum
+ *  Robert Bragg
+ */
+
+#ifndef __CLUTTER_BACKEND_ANDROID_H__
+#define __CLUTTER_BACKEND_ANDROID__H__
+
+#include <glib-object.h>
+#include <clutter/clutter-event.h>
+#include <clutter/clutter-backend.h>
+#include <clutter/clutter-device-manager.h>
+
+#include "clutter-backend-private.h"
+
+G_BEGIN_DECLS
+
+#define CLUTTER_TYPE_BACKEND_ANDROID                (_clutter_backend_android_get_type ())
+#define CLUTTER_BACKEND_ANDROID(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_BACKEND_ANDROID, ClutterBackendAndroid))
+#define CLUTTER_IS_BACKEND_ANDROID(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BACKEND_ANDROID))
+#define CLUTTER_BACKEND_ANDROID_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_BACKEND_ANDROID, ClutterBackendAndroidClass))
+#define CLUTTER_IS_BACKEND_ANDROID_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_BACKEND_ANDROID))
+#define CLUTTER_BACKEND_ANDROID_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_BACKEND_ANDROID, ClutterBackendAndroidClass))
+
+typedef struct _ClutterBackendAndroid       ClutterBackendAndroid;
+typedef struct _ClutterBackendAndroidClass  ClutterBackendAndroidClass;
+
+struct _ClutterBackendAndroid
+{
+  ClutterBackend parent_instance;
+};
+
+struct _ClutterBackendAndroidClass
+{
+  ClutterBackendClass parent_class;
+};
+
+GType _clutter_backend_android_get_type (void) G_GNUC_CONST;
+
+void _clutter_backend_android_events_init (ClutterBackend *backend);
+
+G_END_DECLS
+
+#endif /* __CLUTTER_BACKEND_ANDROID_H__ */
diff --git a/clutter/android/clutter-device-manager-android.c b/clutter/android/clutter-device-manager-android.c
new file mode 100644
index 0000000..5326acd
--- /dev/null
+++ b/clutter/android/clutter-device-manager-android.c
@@ -0,0 +1,211 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2011 Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Damien Lespiau <damien lespiau intel com>
+ */
+
+#include "clutter-debug.h"
+#include "clutter-device-manager-private.h"
+#include "clutter-device-manager-android.h"
+
+#include "clutter-stage-manager.h"
+
+
+G_DEFINE_TYPE (ClutterDeviceManagerAndroid,
+	       clutter_device_manager_android,
+	       CLUTTER_TYPE_DEVICE_MANAGER)
+
+#define DEVICE_MANAGER_ANDROID_PRIVATE(o)			      \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o),				      \
+				CLUTTER_TYPE_DEVICE_MANAGER_ANDROID,  \
+				ClutterDeviceManagerAndroidPrivate))
+
+struct _ClutterDeviceManagerAndroidPrivate
+{
+  GSList *devices;
+
+  ClutterInputDevice *core_pointer;
+  ClutterInputDevice *core_keyboard;
+};
+
+/*
+ * ClutterDeviceManager implementation
+ */
+
+static void
+clutter_device_manager_android_add_device (ClutterDeviceManager *manager,
+					   ClutterInputDevice   *device)
+{
+  ClutterDeviceManagerAndroid *manager_android;
+  ClutterDeviceManagerAndroidPrivate *priv;
+
+  manager_android = CLUTTER_DEVICE_MANAGER_ANDROID (manager);
+  priv = manager_android->priv;
+
+  priv->devices = g_slist_prepend (priv->devices, device);
+}
+
+static void
+clutter_device_manager_android_remove_device (ClutterDeviceManager *manager,
+                                            ClutterInputDevice   *device)
+{
+  ClutterDeviceManagerAndroid *manager_android;
+  ClutterDeviceManagerAndroidPrivate *priv;
+
+  manager_android = CLUTTER_DEVICE_MANAGER_ANDROID (manager);
+  priv = manager_android->priv;
+
+  priv->devices = g_slist_remove (priv->devices, device);
+}
+
+static const GSList *
+clutter_device_manager_android_get_devices (ClutterDeviceManager *manager)
+{
+  return CLUTTER_DEVICE_MANAGER_ANDROID (manager)->priv->devices;
+}
+
+static ClutterInputDevice *
+clutter_device_manager_android_get_core_device (ClutterDeviceManager   *manager,
+                                              ClutterInputDeviceType  type)
+{
+  ClutterDeviceManagerAndroid *manager_android;
+  ClutterDeviceManagerAndroidPrivate *priv;
+
+  manager_android = CLUTTER_DEVICE_MANAGER_ANDROID (manager);
+  priv = manager_android->priv;
+
+  switch (type)
+    {
+    case CLUTTER_POINTER_DEVICE:
+      return priv->core_pointer;
+
+    case CLUTTER_KEYBOARD_DEVICE:
+      return priv->core_keyboard;
+
+    case CLUTTER_EXTENSION_DEVICE:
+    default:
+      return NULL;
+    }
+
+  return NULL;
+}
+
+static ClutterInputDevice *
+clutter_device_manager_android_get_device (ClutterDeviceManager *manager,
+					   gint                  id)
+{
+  ClutterDeviceManagerAndroid *manager_android;
+  ClutterDeviceManagerAndroidPrivate *priv;
+  GSList *l;
+
+  manager_android = CLUTTER_DEVICE_MANAGER_ANDROID (manager);
+  priv = manager_android->priv;
+
+  for (l = priv->devices; l; l = l->next)
+    {
+      ClutterInputDevice *device = l->data;
+
+      if (clutter_input_device_get_device_id (device) == id)
+        return device;
+    }
+
+  return NULL;
+}
+
+/*
+ * GObject implementation
+ */
+
+static void
+clutter_device_manager_android_constructed (GObject *object)
+{
+  ClutterDeviceManager *manager = CLUTTER_DEVICE_MANAGER (object);
+  ClutterDeviceManagerAndroid *android_manager;
+  ClutterDeviceManagerAndroidPrivate *priv;
+  ClutterStage *stage;
+
+  android_manager = CLUTTER_DEVICE_MANAGER_ANDROID (object);
+  priv = android_manager->priv;
+
+  priv->core_pointer = g_object_new (CLUTTER_TYPE_INPUT_DEVICE,
+				     "id", 0,
+				     "name", "Core Pointer Device",
+				     "device-type", CLUTTER_POINTER_DEVICE,
+				      "enabled", TRUE,
+				     NULL);
+
+  /* Always associate the device to the default stage */
+  stage = clutter_stage_manager_get_default_stage (clutter_stage_manager_get_default ());
+  _clutter_input_device_set_stage (priv->core_pointer, stage);
+
+  _clutter_device_manager_add_device (manager, priv->core_pointer);
+
+  CLUTTER_NOTE (EVENT, "Added Core Pointer device");
+
+  priv->core_keyboard = g_object_new (CLUTTER_TYPE_INPUT_DEVICE,
+				      "id", 1,
+				      "name", "Core Keyboard Device",
+				      "device-type", CLUTTER_KEYBOARD_DEVICE,
+				      "enabled", TRUE,
+				      NULL);
+
+  _clutter_input_device_set_stage (priv->core_keyboard, stage);
+
+  _clutter_device_manager_add_device (manager, priv->core_keyboard);
+
+  CLUTTER_NOTE (EVENT, "Added Core Keyboard device");
+}
+
+static void
+clutter_device_manager_android_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (clutter_device_manager_android_parent_class)->finalize (object);
+}
+
+static void
+clutter_device_manager_android_class_init (ClutterDeviceManagerAndroidClass *klass)
+{
+  ClutterDeviceManagerClass *manager_class;
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (ClutterDeviceManagerAndroidPrivate));
+
+  object_class->finalize = clutter_device_manager_android_finalize;
+  object_class->constructed = clutter_device_manager_android_constructed;
+
+  manager_class = CLUTTER_DEVICE_MANAGER_CLASS (klass);
+  manager_class->add_device = clutter_device_manager_android_add_device;
+  manager_class->remove_device = clutter_device_manager_android_remove_device;
+  manager_class->get_devices = clutter_device_manager_android_get_devices;
+  manager_class->get_core_device = clutter_device_manager_android_get_core_device;
+  manager_class->get_device = clutter_device_manager_android_get_device;
+}
+
+static void
+clutter_device_manager_android_init (ClutterDeviceManagerAndroid *self)
+{
+  self->priv = DEVICE_MANAGER_ANDROID_PRIVATE (self);
+}
+
+ClutterDeviceManagerAndroid *
+clutter_device_manager_android_new (void)
+{
+  return g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_ANDROID, NULL);
+}
diff --git a/clutter/android/clutter-device-manager-android.h b/clutter/android/clutter-device-manager-android.h
new file mode 100644
index 0000000..f01263e
--- /dev/null
+++ b/clutter/android/clutter-device-manager-android.h
@@ -0,0 +1,79 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2011 Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Damien Lespiau <damien lespiau intel com>
+ */
+
+#ifndef __CLUTTER_DEVICE_MANAGER_ANDROID_H__
+#define __CLUTTER_DEVICE_MANAGER_ANDROID_H__
+
+#include <glib-object.h>
+
+#include <clutter/clutter-device-manager.h>
+
+G_BEGIN_DECLS
+
+#define CLUTTER_TYPE_DEVICE_MANAGER_ANDROID clutter_device_manager_android_get_type()
+
+#define CLUTTER_DEVICE_MANAGER_ANDROID(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+  CLUTTER_TYPE_DEVICE_MANAGER_ANDROID, ClutterDeviceManagerAndroid))
+
+#define CLUTTER_DEVICE_MANAGER_ANDROID_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+  CLUTTER_TYPE_DEVICE_MANAGER_ANDROID, ClutterDeviceManagerAndroidClass))
+
+#define CLUTTER_IS_DEVICE_MANAGER_ANDROID(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+  CLUTTER_TYPE_DEVICE_MANAGER_ANDROID))
+
+#define CLUTTER_IS_DEVICE_MANAGER_ANDROID_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+  CLUTTER_TYPE_DEVICE_MANAGER_ANDROID))
+
+#define CLUTTER_DEVICE_MANAGER_ANDROID_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+  CLUTTER_TYPE_DEVICE_MANAGER_ANDROID, ClutterDeviceManagerAndroidClass))
+
+typedef struct _ClutterDeviceManagerAndroid ClutterDeviceManagerAndroid;
+typedef struct _ClutterDeviceManagerAndroidClass ClutterDeviceManagerAndroidClass;
+typedef struct _ClutterDeviceManagerAndroidPrivate ClutterDeviceManagerAndroidPrivate;
+
+struct _ClutterDeviceManagerAndroid
+{
+  ClutterDeviceManager parent;
+
+  ClutterDeviceManagerAndroidPrivate *priv;
+};
+
+struct _ClutterDeviceManagerAndroidClass
+{
+  ClutterDeviceManagerClass parent_class;
+};
+
+GType clutter_device_manager_android_get_type (void) G_GNUC_CONST;
+
+ClutterDeviceManagerAndroid * clutter_device_manager_android_new  (void);
+
+void			      _clutter_events_android_init	  (ClutterBackend *backend);
+void			      _clutter_events_android_uninit	  (ClutterBackend *backend);
+G_END_DECLS
+
+#endif /* __CLUTTER_DEVICE_MANAGER_ANDROID_H__ */
diff --git a/clutter/clutter-backend.c b/clutter/clutter-backend.c
index 8ce7c0e..a27045c 100644
--- a/clutter/clutter-backend.c
+++ b/clutter/clutter-backend.c
@@ -83,6 +83,9 @@
 #ifdef CLUTTER_INPUT_WAYLAND
 #include "wayland/clutter-device-manager-wayland.h"
 #endif
+#ifdef CLUTTER_INPUT_ANDROID
+#include "android/clutter-backend-android.h"
+#endif
 
 #ifdef HAVE_CLUTTER_WAYLAND_COMPOSITOR
 #include <cogl/cogl-wayland-server.h>
@@ -504,6 +507,14 @@ clutter_backend_real_init_events (ClutterBackend *backend)
     }
   else
 #endif
+#ifdef CLUTTER_INPUT_ANDROID
+  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_ANDROID) &&
+      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_ANDROID)))
+    {
+      _clutter_backend_android_events_init (backend);
+    }
+  else
+#endif
 #ifdef CLUTTER_INPUT_EVDEV
   /* Evdev can be used regardless of the windowing system */
   if (input_backend != NULL &&
diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c
index b98e0b0..42a60a2 100644
--- a/clutter/clutter-main.c
+++ b/clutter/clutter-main.c
@@ -132,6 +132,9 @@
 #ifdef CLUTTER_WINDOWING_WAYLAND
 #include "wayland/clutter-backend-wayland.h"
 #endif
+#ifdef CLUTTER_WINDOWING_ANDROID
+#include "android/clutter-backend-android.h"
+#endif
 
 #include <cogl/cogl.h>
 #include <cogl-pango/cogl-pango.h>
@@ -1370,6 +1373,11 @@ clutter_create_backend (void)
     retval = g_object_new (CLUTTER_TYPE_BACKEND_GDK, NULL);
   else
 #endif
+#ifdef CLUTTER_WINDOWING_ANDROID
+  if (backend == NULL || backend == I_(CLUTTER_WINDOWING_ANDROID))
+    retval = g_object_new (CLUTTER_TYPE_BACKEND_ANDROID, NULL);
+  else
+#endif
   if (backend == NULL)
     g_error ("No default Clutter backend found.");
   else
@@ -3795,6 +3803,12 @@ clutter_check_windowing_backend (const char *backend_type)
     return TRUE;
   else
 #endif
+#ifdef CLUTTER_WINDOWING_ANDROID
+  if (backend_type == I_(CLUTTER_WINDOWING_ANDROID) &&
+      CLUTTER_IS_BACKEND_ANDROID (context->backend))
+    return TRUE;
+  else
+#endif
   return FALSE;
 }
 
diff --git a/clutter/clutter-marshal.list b/clutter/clutter-marshal.list
index 509aa0b..2304119 100644
--- a/clutter/clutter-marshal.list
+++ b/clutter/clutter-marshal.list
@@ -1,31 +1,33 @@
 BOOLEAN:BOXED
 BOOLEAN:BOXED,INT,INT
-BOOLEAN:OBJECT,ENUM
-BOOLEAN:STRING,UINT,FLAGS
 BOOLEAN:OBJECT
+BOOLEAN:OBJECT,ENUM
 BOOLEAN:OBJECT,FLOAT,FLOAT
+BOOLEAN:STRING,UINT,FLAGS
+BOOLEAN:VOID
 BOXED:UINT,UINT
 DOUBLE:VOID
 UINT:VOID
 VOID:BOXED
 VOID:BOXED,FLAGS
+VOID:FLOAT,FLOAT
 VOID:INT
-VOID:INT64,INT64,FLOAT,BOOLEAN
 VOID:INT,INT
-VOID:FLOAT,FLOAT
 VOID:INT,INT,INT,INT
+VOID:INT64,INT64,FLOAT,BOOLEAN
 VOID:OBJECT
 VOID:OBJECT,FLAGS
 VOID:OBJECT,FLOAT,FLOAT
 VOID:OBJECT,FLOAT,FLOAT,FLAGS
+VOID:OBJECT,INT
 VOID:OBJECT,PARAM
 VOID:OBJECT,POINTER
 VOID:OBJECT,UINT
 VOID:POINTER
 VOID:STRING,BOOLEAN,BOOLEAN
 VOID:STRING,INT
+VOID:STRING,INT,POINTER
 VOID:UINT
 VOID:UINT,STRING,UINT
 VOID:UINT,UINT
 VOID:VOID
-VOID:STRING,INT,POINTER
diff --git a/configure.ac b/configure.ac
index b8b7a0f..8e16fb6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -246,6 +246,10 @@ AC_ARG_ENABLE([cex100-backend],
               [AS_HELP_STRING([--enable-cex100-backend=@<:@yes/no@:>@], [Enable the CEx100 backend (default=no)])],
               [enable_cex100=$enableval],
               [enable_cex100=no])
+AC_ARG_ENABLE([android-backend],
+              [AS_HELP_STRING([--enable-android-backend=@<:@yes/no@:>@], [Enable the Android backend (default=no)])],
+              [enable_android=$enableval],
+              [enable_android=no])
 
 dnl Define default values
 AS_IF([test "x$enable_x11" = "xcheck"],
@@ -431,6 +435,19 @@ AS_IF([test "x$enable_win32" = "xyes"],
         SUPPORT_WIN32=1
       ])
 
+AS_IF([test "x$enable_android" = "xyes"],
+      [
+        SUPPORT_COGL=1
+        SUPPORT_ANDROID=1
+
+        CLUTTER_BACKENDS="$CLUTTER_BACKENDS android"
+        CLUTTER_INPUT_BACKENDS="$CLUTTER_INPUT_BACKENDS android"
+
+        AC_DEFINE([HAVE_CLUTTER_ANDROID], [1], [Have the Android backend])
+
+        BACKEND_PC_FILES="$BACKEND_PC_FILES glib-android-1.0"
+      ])
+
 AS_IF([test "x$CLUTTER_BACKENDS" = "x"],
       [
         AC_MSG_ERROR([No backend enabled. You need to enable at least one backend.])
@@ -481,6 +498,7 @@ AM_CONDITIONAL(SUPPORT_OSX,     [test "x$SUPPORT_OSX" = "x1"])
 AM_CONDITIONAL(SUPPORT_WIN32,   [test "x$SUPPORT_WIN32" = "x1"])
 AM_CONDITIONAL(SUPPORT_CEX100,  [test "x$SUPPORT_CEX100" = "x1"])
 AM_CONDITIONAL(SUPPORT_WAYLAND, [test "x$SUPPORT_WAYLAND" = "x1"])
+AM_CONDITIONAL(SUPPORT_ANDROID, [test "x$SUPPORT_ANDROID" = "x1"])
 
 AM_CONDITIONAL(USE_COGL,  [test "x$SUPPORT_COGL" = "x1"])
 AM_CONDITIONAL(USE_TSLIB, [test "x$have_tslib" = "xyes"])
@@ -545,6 +563,10 @@ AS_IF([test "x$SUPPORT_TSLIB" = "x1"],
 AS_IF([test "x$SUPPORT_WAYLAND" = "x1"],
       [CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
 #define CLUTTER_INPUT_WAYLAND \"wayland\""])
+AS_IF([test "x$SUPPORT_ANDROID" = "x1"],
+      [CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
+#define CLUTTER_WINDOWING_ANDROID \"android\"
+#define CLUTTER_INPUT_ANDROID \"android\""])
 
 # the 'null' input backend is special
 CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
@@ -1205,6 +1227,11 @@ echo ""
 echo "     - Wayland compositor support enabled (WARNING: Experimental)"
 fi
 
+if test "x$SUPPORT_ANDROID" = "x1"; then
+echo ""
+echo "     - Android backend enabled (WARNING: Experimental)"
+fi
+
 echo ""
 
 # General warning about experimental features



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]