This quite big patch will enable Waffle for Android ICS, it currently use
Android make files. I tested it with the examples/gl_basic test which also
has the Android make file now.

Most of the stuff in the src/waffle/android folder is very similar to rest
of Waffle, just mixed with Android's SurfaceFlinger negotiation.

Patch in the attachment.

/Juha-Pekka
>From 3cb32dd8cf60bb97b6e21c1d7044d621dc8961ba Mon Sep 17 00:00:00 2001
From: Juha-Pekka Heikkila <[email protected]>
Date: Tue, 26 Jun 2012 10:27:55 +0300
Subject: [PATCH] Enabling Waffle library for Android. Currently building for
 Android is done with Android.mk files and not with CMake,
 will need to fix this later.

Signed-off-by: Juha-Pekka Heikkila <[email protected]>
---
 Android.mk                                        |   54 ++++++
 examples/Android.mk                               |   21 +++
 include/waffle/native/waffle_android.h            |   58 +++++++
 src/waffle/android/android_config.c               |  121 ++++++++++++++
 src/waffle/android/android_config.h               |   65 ++++++++
 src/waffle/android/android_context.c              |  113 +++++++++++++
 src/waffle/android/android_context.h              |   54 ++++++
 src/waffle/android/android_display.c              |  122 ++++++++++++++
 src/waffle/android/android_display.h              |   61 +++++++
 src/waffle/android/android_platform.c             |  133 +++++++++++++++
 src/waffle/android/android_platform.h             |   45 +++++
 src/waffle/android/android_priv_egl.c             |   27 +++
 src/waffle/android/android_priv_egl.h             |   29 ++++
 src/waffle/android/android_surfaceflingerlink.cpp |  183 +++++++++++++++++++++
 src/waffle/android/android_surfaceflingerlink.h   |   44 +++++
 src/waffle/android/android_window.c               |  134 +++++++++++++++
 src/waffle/android/android_window.h               |   60 +++++++
 src/waffle/api/waffle_init.c                      |    4 +-
 18 files changed, 1326 insertions(+), 2 deletions(-)

diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..f28c897
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,54 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE:= libwaffle
+
+LOCAL_CFLAGS:= \
+    -DANDROID_STUB \
+    -DWAFFLE_HAS_ANDROID \
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ \
+    $(LOCAL_PATH)/src/ \
+    bionic \
+    bionic/libstdc++/include \
+    external/gtest/include \
+    external/stlport/stlport \
+
+LOCAL_SRC_FILES:= \
+    src/waffle/core/wcore_tinfo.c \
+    src/waffle/core/wcore_config_attrs.c \
+    src/waffle/core/wcore_error.c \
+	src/waffle/api/api_priv.c \
+	src/waffle/api/waffle_attrib_list.c \
+	src/waffle/api/waffle_config.c \
+	src/waffle/api/waffle_context.c \
+	src/waffle/api/waffle_display.c \
+	src/waffle/api/waffle_enum.c \
+	src/waffle/api/waffle_error.c \
+	src/waffle/api/waffle_gl_misc.c \
+	src/waffle/api/waffle_init.c \
+	src/waffle/api/waffle_window.c \
+    src/waffle/api/waffle_dl.c \
+    src/waffle/linux/linux_dl.c \
+    src/waffle/linux/linux_platform.c \
+    src/waffle/android/android_priv_egl.c \
+    src/waffle/android/android_platform.c \
+    src/waffle/android/android_display.c \
+    src/waffle/android/android_config.c \
+    src/waffle/android/android_context.c \
+    src/waffle/android/android_window.c \
+    src/waffle/android/android_surfaceflingerlink.cpp \
+    src/waffle/egl/egl_no_native.c \
+    src/waffle/core/wcore_util.c \
+    src/waffle/core/wcore_display.c \
+
+LOCAL_SHARED_LIBRARIES := \
+    libEGL \
+    libdl \
+	libGLESv2 \
+	libutils \
+	libgui \
+
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/examples/Android.mk b/examples/Android.mk
new file mode 100644
index 0000000..0daec1d
--- /dev/null
+++ b/examples/Android.mk
@@ -0,0 +1,21 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE:= gl_basic
+
+LOCAL_CFLAGS:= \
+        -DANDROID_STUB \
+        -DWAFFLE_HAS_ANDROID \
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include/
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/../src/
+
+LOCAL_SRC_FILES:= \
+    gl_basic.c \
+
+LOCAL_SHARED_LIBRARIES := libwaffle
+
+include $(BUILD_EXECUTABLE)
+
+
diff --git a/include/waffle/native/waffle_android.h b/include/waffle/native/waffle_android.h
new file mode 100644
index 0000000..8806e70
--- /dev/null
+++ b/include/waffle/native/waffle_android.h
@@ -0,0 +1,58 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <EGL/egl.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct waffle_android_display {
+    EGLDisplay egl_display;
+};
+
+struct waffle_android_config {
+    struct waffle_android_display display;
+    EGLConfig egl_config;
+};
+
+struct waffle_android_context {
+    struct waffle_android_display display;
+    EGLContext egl_context;
+};
+
+struct waffle_android_window {
+    struct waffle_android_display display;
+    EGLSurface egl_surface;
+};
+
+#ifdef __cplusplus
+} // end extern "C"
+#endif
diff --git a/src/waffle/android/android_config.c b/src/waffle/android/android_config.c
new file mode 100644
index 0000000..6ea4f58
--- /dev/null
+++ b/src/waffle/android/android_config.c
@@ -0,0 +1,121 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "android_config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <waffle/core/wcore_config_attrs.h>
+#include <waffle/core/wcore_error.h>
+
+#include <waffle/linux/linux_platform.h>
+#include <waffle/egl/egl_no_native.h>
+
+#include "android_display.h"
+#include "android_surfaceflingerlink.h"
+
+
+static const struct wcore_config_vtbl android_config_wcore_vtbl;
+
+
+struct wcore_config*
+android_config_choose(struct wcore_platform *wc_plat,
+                   struct wcore_display *wc_dpy,
+                   const struct wcore_config_attrs *attrs)
+{
+    struct android_config *self;
+    struct android_display *dpy = android_display(wc_dpy);
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_config_init(&self->wcore, wc_dpy);
+    if (!ok)
+        goto error;
+
+    ok = egl_get_render_buffer_attrib(attrs, &self->egl_render_buffer);
+    if (!ok)
+        goto error;
+
+    self->egl = egl_choose_config(wc_plat, dpy->android_display, attrs);
+    if (!self->egl)
+        goto error;
+
+    ok = eglGetConfigAttrib(dpy->android_display,
+                            self->egl,
+                            EGL_NATIVE_VISUAL_ID,
+                            (EGLint*) &self->visual_id);
+    if (!ok) {
+        egl_get_error("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID)");
+        goto error;
+    }
+
+    self->waffle_context_api = attrs->context_api;
+    self->wcore.vtbl = &android_config_wcore_vtbl;
+    return &self->wcore;
+
+error:
+    android_config_destroy(&self->wcore);
+    return NULL;
+}
+
+static bool
+android_config_destroy(struct wcore_config *wc_self)
+{
+    struct android_config *self = android_config(wc_self);
+    bool ok = true;
+
+    if (!self)
+        return ok;
+
+    ok &= wcore_config_teardown(wc_self);
+    free(self);
+    return ok;
+}
+
+static union waffle_native_config*
+android_config_get_native(struct wcore_config *wc_self)
+{
+    struct android_config *self = android_config(wc_self);
+    struct android_display *dpy = android_display(wc_self->display);
+    struct waffle_android_config *n_config;
+
+    n_config = wcore_malloc(sizeof(*n_config));
+    if (n_config == NULL)
+        return NULL;
+
+    android_display_fill_native(dpy, &n_config->display);
+    n_config->egl_config = self->egl;
+
+    return (union waffle_native_config*) n_config;
+}
+
+static const struct wcore_config_vtbl android_config_wcore_vtbl = {
+    .destroy = android_config_destroy,
+    .get_native = android_config_get_native,
+};
diff --git a/src/waffle/android/android_config.h b/src/waffle/android/android_config.h
new file mode 100644
index 0000000..039ccb9
--- /dev/null
+++ b/src/waffle/android/android_config.h
@@ -0,0 +1,65 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <EGL/egl.h>
+#include <waffle/core/wcore_config.h>
+#include <waffle/core/wcore_util.h>
+
+struct wcore_config_attrs;
+struct wcore_platform;
+
+
+struct android_config {
+    struct wcore_config wcore;
+
+    EGLConfig egl;
+    EGLint visual_id;
+
+    /// The value of @c EGL_RENDER_BUFFER that will be set in the attrib_list
+    /// of eglCreateWindowSurface().
+    EGLint egl_render_buffer;
+
+    /// The API given to android_config_choose(). This is later used to
+    /// select the value of the EGL_RENDERABLE attribute.
+    int32_t waffle_context_api;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(android_config,
+                           struct android_config,
+                           struct wcore_config,
+                           wcore)
+
+struct wcore_config*
+android_config_choose(struct wcore_platform *wc_plat,
+                   struct wcore_display *wc_dpy,
+                   const struct wcore_config_attrs *attrs);
+
+static bool
+android_config_destroy(struct wcore_config *wc_self);
diff --git a/src/waffle/android/android_context.c b/src/waffle/android/android_context.c
new file mode 100644
index 0000000..fae3018
--- /dev/null
+++ b/src/waffle/android/android_context.c
@@ -0,0 +1,113 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "android_context.h"
+
+#include <stdlib.h>
+
+#include <waffle/core/wcore_error.h>
+
+#include "android_display.h"
+#include "android_config.h"
+#include "android_priv_egl.h"
+#include "android_surfaceflingerlink.h"
+
+static const struct wcore_context_vtbl android_context_wcore_vtbl;
+
+struct wcore_context*
+android_context_create(struct wcore_platform *wc_plat,
+                    struct wcore_config *wc_config,
+                    struct wcore_context *wc_share_ctx)
+{
+    struct android_context *self;
+    struct android_config *config = android_config(wc_config);
+    struct android_context *share_ctx = android_context(wc_share_ctx);
+    struct android_display *dpy = android_display(wc_config->display);
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_context_init(&self->wcore, wc_config);
+    if (!ok)
+        goto error;
+
+    self->egl = egl_create_context(dpy->android_display,
+                                   config->egl,
+                                   share_ctx
+                                      ? share_ctx->egl
+                                      : NULL,
+                                   config->waffle_context_api);
+    if (!self->egl)
+        goto error;
+
+    self->wcore.vtbl = &android_context_wcore_vtbl;
+    return &self->wcore;
+
+error:
+    android_context_destroy(&self->wcore);
+    return NULL;
+}
+
+static bool
+android_context_destroy(struct wcore_context *wc_self)
+{
+    struct android_context *self = android_context(wc_self);
+    bool ok = true;
+
+    if (!self)
+        return ok;
+
+    if (self->egl)
+        ok &= egl_destroy_context(
+            android_display(wc_self->display)->android_display, self->egl);
+
+    ok &= wcore_context_teardown(wc_self);
+    free(self);
+    return ok;
+}
+
+static union waffle_native_context*
+android_context_get_native(struct wcore_context *wc_self)
+{
+    struct android_context *self = android_context(wc_self);
+    struct android_display *dpy = android_display(wc_self->display);
+    struct waffle_android_context *n_ctx;
+
+    n_ctx = wcore_malloc(sizeof(*n_ctx));
+    if (n_ctx == NULL)
+        return NULL;
+
+    android_display_fill_native(dpy, &n_ctx->display);
+    n_ctx->egl_context = self->egl;
+
+    return (union waffle_native_context*) n_ctx;
+}
+
+static const struct wcore_context_vtbl android_context_wcore_vtbl = {
+    .destroy = android_context_destroy,
+    .get_native = android_context_get_native,
+};
diff --git a/src/waffle/android/android_context.h b/src/waffle/android/android_context.h
new file mode 100644
index 0000000..b1d8be7
--- /dev/null
+++ b/src/waffle/android/android_context.h
@@ -0,0 +1,54 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <stdbool.h>
+#include <EGL/egl.h>
+
+#include <waffle/core/wcore_context.h>
+#include <waffle/core/wcore_util.h>
+
+struct wcore_config;
+struct wcore_platform;
+
+struct android_context {
+    struct wcore_context wcore;
+    EGLContext egl;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(android_context,
+                           struct android_context,
+                           struct wcore_context,
+                           wcore)
+
+
+struct wcore_context*
+android_context_create(struct wcore_platform *wc_plat,
+                    struct wcore_config *wc_config,
+                    struct wcore_context *wc_share_ctx);
+
+static bool
+android_context_destroy(struct wcore_context *wc_self);
diff --git a/src/waffle/android/android_display.c b/src/waffle/android/android_display.c
new file mode 100644
index 0000000..fa8159d
--- /dev/null
+++ b/src/waffle/android/android_display.c
@@ -0,0 +1,122 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "android_display.h"
+#include "android_platform.h"
+
+#include <stdlib.h>
+
+#include <waffle/linux/linux_platform.h>
+#include <waffle/core/wcore_error.h>
+#include <waffle/core/wcore_display.h>
+
+#include "android_priv_egl.h"
+#include "android_surfaceflingerlink.h"
+
+static const struct wcore_display_vtbl android_display_wcore_vtbl;
+
+struct wcore_display*
+android_display_connect(struct wcore_platform *wc_plat,
+                        const char *name)
+{
+    bool ok = true;
+    struct android_display *self;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_display_init(&self->wcore, wc_plat);
+    if (!ok)
+        goto error;
+
+    if(!android_init_gl())
+        goto error;
+
+    self->android_display = android_get_waffle_egl_display();
+
+    if (!self->android_display)
+        goto error;
+
+    self->wcore.vtbl = &android_display_wcore_vtbl;
+    return &self->wcore;
+
+error:
+    android_display_disconnect(&self->wcore);
+    return NULL;
+}
+
+static bool
+android_display_disconnect(struct wcore_display *wc_self)
+{
+    struct android_display *self = android_display(wc_self);
+    bool ok = true;
+
+    if (!self)
+        return true;
+
+    if (self->android_display)
+        ok &= egl_terminate(self->android_display);
+
+    android_deinit_gl();
+    free(self);
+    return ok;
+}
+
+void
+android_display_fill_native(struct android_display *self,
+                         struct waffle_android_display *n_dpy)
+{
+    n_dpy->egl_display = self->android_display;
+}
+
+
+static union waffle_native_display*
+android_display_get_native(struct wcore_display *wc_self)
+{
+    struct android_display *self = android_display(wc_self);
+    struct waffle_android_display *n_dpy;
+
+    n_dpy = wcore_malloc(sizeof(*n_dpy));
+    if (n_dpy == NULL)
+        return NULL;
+
+    return (union waffle_native_display*) n_dpy;
+}
+
+static bool
+android_display_supports_context_api(
+        struct wcore_display *wc_self,
+        int32_t context_api)
+{
+    return egl_supports_context_api(wc_self->platform, context_api);
+}
+
+static const struct wcore_display_vtbl android_display_wcore_vtbl = {
+    .destroy = android_display_disconnect,
+    .get_native = android_display_get_native,
+    .supports_context_api = android_display_supports_context_api,
+};
+
diff --git a/src/waffle/android/android_display.h b/src/waffle/android/android_display.h
new file mode 100644
index 0000000..ab57f84
--- /dev/null
+++ b/src/waffle/android/android_display.h
@@ -0,0 +1,61 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <EGL/egl.h>
+#include <waffle/core/wcore_display.h>
+#include <waffle/core/wcore_util.h>
+#include <waffle/native/waffle_android.h>
+
+struct wcore_platform;
+
+struct android_display {
+    struct wcore_display wcore;
+    EGLDisplay android_display;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(android_display,
+                           struct android_display,
+                           struct wcore_display,
+                           wcore)
+
+struct wcore_display*
+android_display_connect(struct wcore_platform *wc_plat, const char *name);
+
+static bool
+android_display_disconnect(struct wcore_display *wc_self);
+
+void
+android_display_fill_native(struct android_display *self,
+                         struct waffle_android_display *n_dpy);
+
+static bool
+android_display_supports_context_api(
+        struct wcore_display *wc_self,
+        int32_t context_api);
diff --git a/src/waffle/android/android_platform.c b/src/waffle/android/android_platform.c
new file mode 100644
index 0000000..8b848bb
--- /dev/null
+++ b/src/waffle/android/android_platform.c
@@ -0,0 +1,133 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "android_platform.h"
+
+#include <dlfcn.h>
+#include <stdlib.h>
+
+#include <waffle/core/wcore_error.h>
+#include <waffle/linux/linux_platform.h>
+
+#include "android_config.h"
+#include "android_context.h"
+#include "android_display.h"
+#include "android_priv_egl.h"
+#include "android_window.h"
+
+static const struct wcore_platform_vtbl android_platform_wcore_vtbl;
+
+static bool
+android_platform_destroy(struct wcore_platform *wc_self)
+{
+    struct android_platform *self = android_platform(wc_self);
+    bool ok = true;
+
+    if (!self)
+        return true;
+
+    if (self->linux)
+        ok &= linux_platform_destroy(self->linux);
+
+    ok &= wcore_platform_teardown(wc_self);
+    free(self);
+    return ok;
+}
+
+struct wcore_platform*
+android_platform_create(void)
+{
+    struct android_platform *self;
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_platform_init(&self->wcore);
+    if (!ok)
+        goto error;
+
+    self->linux = linux_platform_create();
+    if (!self->linux)
+        goto error;
+
+    self->wcore.vtbl = &android_platform_wcore_vtbl;
+    return &self->wcore;
+
+error:
+    android_platform_destroy(&self->wcore);
+    return NULL;
+}
+
+static bool
+android_make_current(struct wcore_platform *wc_self,
+                           struct wcore_display *wc_dpy,
+                           struct wcore_window *wc_window,
+                           struct wcore_context *wc_ctx)
+{
+    return egl_make_current(android_display(wc_dpy)->android_display,
+                            wc_window ? android_window(wc_window)->egl : NULL,
+                            wc_ctx ? android_context(wc_ctx)->egl : NULL);
+}
+
+static void*
+android_get_proc_address(
+        struct wcore_platform *wc_self,
+        const char *name)
+{
+    return eglGetProcAddress(name);
+}
+
+static bool
+android_dl_can_open(
+        struct wcore_platform *wc_self,
+        int32_t waffle_dl)
+{
+    return linux_platform_dl_can_open(android_platform(wc_self)->linux,
+                                      waffle_dl);
+}
+
+static void*
+android_dl_sym(
+        struct wcore_platform *wc_self,
+        int32_t waffle_dl,
+        const char *name)
+{
+    return linux_platform_dl_sym(android_platform(wc_self)->linux,
+                                 waffle_dl, name);
+}
+
+static const struct wcore_platform_vtbl android_platform_wcore_vtbl = {
+    .destroy = android_platform_destroy,
+    .connect_to_display = android_display_connect,
+    .choose_config = android_config_choose,
+    .create_context = android_context_create,
+    .create_window = android_window_create,
+    .make_current = android_make_current,
+    .get_proc_address = android_get_proc_address,
+    .dl_can_open = android_dl_can_open,
+    .dl_sym = android_dl_sym,
+};
diff --git a/src/waffle/android/android_platform.h b/src/waffle/android/android_platform.h
new file mode 100644
index 0000000..1f9a647
--- /dev/null
+++ b/src/waffle/android/android_platform.h
@@ -0,0 +1,45 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <stdbool.h>
+#include <waffle/core/wcore_platform.h>
+#include <waffle/core/wcore_util.h>
+
+struct linux_platform;
+
+struct android_platform {
+    struct wcore_platform wcore;
+    struct linux_platform *linux;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(android_platform,
+                           struct android_platform,
+                           struct wcore_platform,
+                           wcore)
+
+struct wcore_platform*
+android_platform_create(void);
diff --git a/src/waffle/android/android_priv_egl.c b/src/waffle/android/android_priv_egl.c
new file mode 100644
index 0000000..f96880b
--- /dev/null
+++ b/src/waffle/android/android_priv_egl.c
@@ -0,0 +1,27 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "android_priv_egl.h"
+#include <waffle/egl/egl_native_template.c>
diff --git a/src/waffle/android/android_priv_egl.h b/src/waffle/android/android_priv_egl.h
new file mode 100644
index 0000000..b63ab76
--- /dev/null
+++ b/src/waffle/android/android_priv_egl.h
@@ -0,0 +1,29 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#define NATIVE_EGL(basename) android_egl_##basename
+#include <waffle/egl/egl.h>
diff --git a/src/waffle/android/android_surfaceflingerlink.cpp b/src/waffle/android/android_surfaceflingerlink.cpp
new file mode 100644
index 0000000..3d1f7a6
--- /dev/null
+++ b/src/waffle/android/android_surfaceflingerlink.cpp
@@ -0,0 +1,183 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <gui/SurfaceTexture.h>
+#include <gui/SurfaceTextureClient.h>
+#include <ui/GraphicBuffer.h>
+#include <utils/String8.h>
+#include <utils/threads.h>
+
+#include <surfaceflinger/ISurfaceComposer.h>
+#include <surfaceflinger/Surface.h>
+#include <surfaceflinger/SurfaceComposerClient.h>
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+#include <ui/FramebufferNativeWindow.h>
+
+#include "android_surfaceflingerlink.h"
+
+namespace android {
+
+void tear_down_surfaceflinger_link();
+bool setup_surfaceflinger_link();
+
+EGLDisplay waffle_egl_display(EGL_NO_DISPLAY);
+EGLSurface waffle_egl_surface(EGL_NO_SURFACE);
+
+sp<SurfaceComposerClient> waffle_composer_client;
+sp<SurfaceControl> waffle_surface_control;
+
+bool
+setup_surfaceflinger_link()
+{
+    bool bRVal;
+    EGLint iRVal;
+
+    waffle_egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+    iRVal = eglGetError();
+    if (iRVal != EGL_SUCCESS) {
+        return false;
+    }
+
+    iRVal = eglGetError();
+    if (waffle_egl_display == EGL_NO_DISPLAY) {
+        return false;
+    }
+
+    eglInitialize(waffle_egl_display, NULL, NULL);
+    iRVal = eglGetError();
+    if (iRVal != EGL_SUCCESS) {
+        return false;
+    }
+    return true;
+}
+
+EGLSurface
+SetUpSurface(int width, int height, EGLConfig cfg, EGLDisplay dpy)
+{
+    bool bRVal;
+    EGLint iRVal;
+
+    waffle_composer_client = new SurfaceComposerClient;
+    iRVal = waffle_composer_client->initCheck();
+    if (iRVal != NO_ERROR) {
+        waffle_composer_client->dispose();
+        waffle_composer_client = NULL;
+        return EGL_NO_SURFACE;
+    }
+
+    waffle_surface_control = waffle_composer_client->createSurface(
+            String8("Waffle Surface"), 0,
+            width, height,
+            PIXEL_FORMAT_RGB_888, 0);
+
+    if (waffle_surface_control == NULL) {
+        waffle_composer_client->dispose();
+        waffle_composer_client = NULL;
+        return EGL_NO_SURFACE;
+    }
+
+    bRVal = waffle_surface_control->isValid();
+    if (bRVal != true) {
+        waffle_composer_client->dispose();
+        waffle_composer_client = NULL;
+        return EGL_NO_SURFACE;
+    }
+
+    SurfaceComposerClient::openGlobalTransaction();
+    iRVal = waffle_surface_control->setLayer(0x7FFFFFFF);
+    if (iRVal != NO_ERROR) {
+        waffle_composer_client->dispose();
+        waffle_composer_client = NULL;
+        return EGL_NO_SURFACE;
+    }
+
+    iRVal = waffle_surface_control->show();
+    if (iRVal != NO_ERROR) {
+        waffle_composer_client->dispose();
+        waffle_composer_client = NULL;
+        return EGL_NO_SURFACE;
+    }
+
+    SurfaceComposerClient::closeGlobalTransaction();
+
+    sp<ANativeWindow> window = waffle_surface_control->getSurface();
+    waffle_egl_surface = eglCreateWindowSurface(dpy, cfg,
+            window.get(), NULL);
+
+    iRVal = eglGetError();
+    if (iRVal != EGL_SUCCESS) {
+        waffle_composer_client->dispose();
+        waffle_composer_client = NULL;
+        return EGL_NO_SURFACE;
+    }
+
+    if (EGL_NO_SURFACE == waffle_egl_surface) {
+        waffle_composer_client->dispose();
+        waffle_composer_client = NULL;
+        return EGL_NO_SURFACE;
+    }
+
+    return waffle_egl_surface;
+}
+
+void
+tear_down_surfaceflinger_link()
+{
+    if (waffle_composer_client != NULL) {
+        waffle_composer_client->dispose();
+    }
+}
+
+}; // namespace android
+
+extern "C" bool
+android_init_gl()
+{
+    return android::setup_surfaceflinger_link();
+}
+
+extern "C" bool
+android_deinit_gl()
+{
+    android::tear_down_surfaceflinger_link();
+    return true;
+}
+
+extern "C" EGLDisplay
+android_get_waffle_egl_display()
+{
+    return android::waffle_egl_display;
+}
+
+extern "C" EGLSurface
+android_create_surface(int width, int height, EGLConfig cfg, EGLDisplay dpy)
+{
+    return android::SetUpSurface(width, height, cfg, dpy);
+}
diff --git a/src/waffle/android/android_surfaceflingerlink.h b/src/waffle/android/android_surfaceflingerlink.h
new file mode 100644
index 0000000..e206c4a
--- /dev/null
+++ b/src/waffle/android/android_surfaceflingerlink.h
@@ -0,0 +1,44 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+EGLSurface
+android_create_surface(int width, int height, EGLConfig cfg, EGLDisplay dpy);
+
+bool
+android_init_gl();
+
+bool
+android_deinit_gl();
+
+EGLDisplay
+android_get_waffle_egl_display();
+
+#ifdef __cplusplus
+};
+#endif
diff --git a/src/waffle/android/android_window.c b/src/waffle/android/android_window.c
new file mode 100644
index 0000000..2c29cdc
--- /dev/null
+++ b/src/waffle/android/android_window.c
@@ -0,0 +1,134 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "android_window.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <waffle/core/wcore_error.h>
+
+#include "android_priv_egl.h"
+#include "android_config.h"
+#include "android_display.h"
+#include "android_surfaceflingerlink.h"
+
+static const struct wcore_window_vtbl android_window_wcore_vtbl;
+
+struct wcore_window*
+android_window_create(struct wcore_platform *wc_plat,
+                   struct wcore_config *wc_config,
+                   int width,
+                   int height)
+{
+    struct android_window *self;
+    struct android_config *config = android_config(wc_config);
+    struct android_display *dpy = android_display(wc_config->display);
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_window_init(&self->wcore, wc_config);
+    if (!ok)
+        goto error;
+
+    self->egl = android_create_surface(
+        width,
+        height,
+        config->egl,
+        dpy->android_display);
+
+    if (!self->egl)
+        goto error;
+
+    self->wcore.vtbl = &android_window_wcore_vtbl;
+    return &self->wcore;
+
+error:
+    android_window_destroy(&self->wcore);
+    return NULL;
+}
+
+static bool
+android_window_destroy(struct wcore_window *wc_self)
+{
+    struct android_window *self = android_window(wc_self);
+    struct android_display *dpy;
+    bool ok = true;
+
+    if (!self)
+        return ok;
+
+    dpy = android_display(wc_self->display);
+
+    if (self->egl)
+        ok &= egl_destroy_surface(dpy->android_display, self->egl);
+
+    ok &= wcore_window_teardown(&self->wcore);
+    free(self);
+    return ok;
+}
+
+static bool
+android_window_show(struct wcore_window *wc_self)
+{
+    return true;
+}
+
+static union waffle_native_window*
+android_window_get_native(struct wcore_window *wc_self)
+{
+    struct android_window *self = android_window(wc_self);
+    struct android_display *dpy = android_display(wc_self->display);
+    struct waffle_android_window *n_window;
+
+    n_window = wcore_malloc(sizeof(*n_window));
+    if (n_window == NULL)
+        return NULL;
+
+    android_display_fill_native(dpy, &n_window->display);
+    n_window->egl_surface = self->egl;
+
+    return (union waffle_native_window*) n_window;
+}
+
+
+static bool
+android_window_swap_buffers(struct wcore_window *wc_self)
+{
+    struct android_window *self = android_window(wc_self);
+    struct android_display *dpy = android_display(wc_self->display);
+
+    return egl_swap_buffers(dpy->android_display, self->egl);
+}
+
+static const struct wcore_window_vtbl android_window_wcore_vtbl = {
+    .destroy = android_window_destroy,
+    .get_native = android_window_get_native,
+    .show = android_window_show,
+    .swap_buffers = android_window_swap_buffers,
+};
diff --git a/src/waffle/android/android_window.h b/src/waffle/android/android_window.h
new file mode 100644
index 0000000..7ef8c13
--- /dev/null
+++ b/src/waffle/android/android_window.h
@@ -0,0 +1,60 @@
+// Copyright 2012 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <stdbool.h>
+#include <EGL/egl.h>
+
+#include <waffle/core/wcore_window.h>
+#include <waffle/core/wcore_util.h>
+
+struct wcore_platform;
+
+struct android_window {
+    struct wcore_window wcore;
+    EGLSurface egl;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(android_window,
+                           struct android_window,
+                           struct wcore_window,
+                           wcore)
+struct wcore_window*
+android_window_create(struct wcore_platform *wc_plat,
+                   struct wcore_config *wc_config,
+                   int width,
+                   int height);
+
+
+static bool
+android_window_destroy(struct wcore_window *wc_self);
+
+static bool
+android_window_show(struct wcore_window *wc_self);
+
+static bool
+android_window_swap_buffers(struct wcore_window *wc_self);
+
diff --git a/src/waffle/api/waffle_init.c b/src/waffle/api/waffle_init.c
index c70e8e9..0004082 100644
--- a/src/waffle/api/waffle_init.c
+++ b/src/waffle/api/waffle_init.c
@@ -36,7 +36,7 @@
 
 #include "api_priv.h"
 
-struct wcore_platform* droid_platform_create(void);
+struct wcore_platform* android_platform_create(void);
 struct wcore_platform* cgl_platform_create(void);
 struct wcore_platform* glx_platform_create(void);
 struct wcore_platform* wayland_platform_create(void);
@@ -106,7 +106,7 @@ waffle_init_create_platform(int32_t waffle_platform)
     switch (waffle_platform) {
 #ifdef WAFFLE_HAS_ANDROID
         case WAFFLE_PLATFORM_ANDROID:
-            return droid_platform_create();
+            return android_platform_create();
 #endif
 #ifdef WAFFLE_HAS_CGL
         case WAFFLE_PLATFORM_CGL:
-- 
1.7.5.4
_______________________________________________
waffle mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/waffle

Reply via email to