summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChia-I Wu <olv@lunarg.com>2011-11-25 11:59:02 +0800
committerChia-I Wu <olv@lunarg.com>2011-11-25 12:34:33 +0800
commit75cc24c876059d6eb183e07ed802f997fb416864 (patch)
treed54eaf925a263684e7086a8671db540636e0660d
parent42c2c371d6c4c82c3e9176e028281a91edfadafd (diff)
android: add support for ICS
With ICS (Android 4.0), several headers and structs are renamed. Define ANDROID_VERSION so that we can choose a different path depending on the platform version. I've tested only softpipe and llvmpipe. r600g is also reported to work.
-rw-r--r--Android.common.mk6
-rw-r--r--include/EGL/eglext.h1
-rw-r--r--src/egl/drivers/dri2/egl_dri2.h21
-rw-r--r--src/egl/drivers/dri2/platform_android.c6
-rw-r--r--src/gallium/state_trackers/egl/android/native_android.cpp27
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_image.c4
-rw-r--r--src/gallium/state_trackers/egl/common/native_buffer.h4
-rw-r--r--src/gallium/winsys/sw/android/android_sw_winsys.cpp47
8 files changed, 74 insertions, 42 deletions
diff --git a/Android.common.mk b/Android.common.mk
index 83177a0cbe7..f28ddc2ef66 100644
--- a/Android.common.mk
+++ b/Android.common.mk
@@ -24,6 +24,12 @@
LOCAL_C_INCLUDES += \
$(MESA_TOP)/include
+# define ANDROID_VERSION (e.g., 4.0.x => 0x0400)
+major := $(word 1, $(subst ., , $(PLATFORM_VERSION)))
+minor := $(word 2, $(subst ., , $(PLATFORM_VERSION)))
+LOCAL_CFLAGS += \
+ -DANDROID_VERSION=0x0$(major)0$(minor)
+
LOCAL_CFLAGS += \
-DPTHREADS \
-fvisibility=hidden \
diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 0449ae2cd1a..9484b83c650 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -392,7 +392,6 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EG
#ifndef EGL_ANDROID_image_native_buffer
#define EGL_ANDROID_image_native_buffer 1
-struct android_native_buffer_t;
#define EGL_NATIVE_BUFFER_ANDROID 0x3140 /* eglCreateImageKHR target */
#endif
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 1c2c7fe5a64..95b87b87500 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -50,12 +50,21 @@
#ifdef HAVE_ANDROID_PLATFORM
#define LOG_TAG "EGL-DRI2"
-#include <ui/egl/android_natives.h>
-#include <ui/android_native_buffer.h>
-#include <cutils/log.h>
-#include <gralloc_drm_handle.h>
+
+#if ANDROID_VERSION >= 0x0400
+# include <system/window.h>
+#else
+# define android_native_buffer_t ANativeWindowBuffer
+# include <ui/egl/android_natives.h>
+# include <ui/android_native_buffer.h>
#endif
+#include <hardware/gralloc.h>
+#include <gralloc_drm_handle.h>
+#include <cutils/log.h>
+
+#endif /* HAVE_ANDROID_PLATFORM */
+
#include "eglconfig.h"
#include "eglcontext.h"
#include "egldisplay.h"
@@ -167,8 +176,8 @@ struct dri2_egl_surface
#endif
#ifdef HAVE_ANDROID_PLATFORM
- android_native_window_t *window;
- android_native_buffer_t *buffer;
+ struct ANativeWindow *window;
+ struct ANativeWindowBuffer *buffer;
/* EGL-owned buffers */
__DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index 3abd5363692..1998941f829 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -66,7 +66,7 @@ get_format_bpp(int native)
}
static int
-get_native_buffer_name(struct android_native_buffer_t *buf)
+get_native_buffer_name(struct ANativeWindowBuffer *buf)
{
struct gralloc_drm_handle_t *handle;
@@ -280,7 +280,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
static _EGLImage *
dri2_create_image_android_native_buffer(_EGLDisplay *disp,
- struct android_native_buffer_t *buf)
+ struct ANativeWindowBuffer *buf)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_image *dri2_img;
@@ -357,7 +357,7 @@ droid_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
switch (target) {
case EGL_NATIVE_BUFFER_ANDROID:
return dri2_create_image_android_native_buffer(disp,
- (struct android_native_buffer_t *) buffer);
+ (struct ANativeWindowBuffer *) buffer);
default:
return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list);
}
diff --git a/src/gallium/state_trackers/egl/android/native_android.cpp b/src/gallium/state_trackers/egl/android/native_android.cpp
index 490d6e83884..01d3a02d364 100644
--- a/src/gallium/state_trackers/egl/android/native_android.cpp
+++ b/src/gallium/state_trackers/egl/android/native_android.cpp
@@ -25,11 +25,20 @@
*/
#define LOG_TAG "EGL-GALLIUM"
-#include <cutils/log.h>
-#include <cutils/properties.h>
+
+#if ANDROID_VERSION >= 0x0400
+#include <stdlib.h>
+#include <system/window.h>
+#else
+#define android_native_buffer_t ANativeWindowBuffer
+#include <ui/egl/android_natives.h>
+#include <ui/android_native_buffer.h>
+#endif
+
#include <hardware/gralloc.h>
+#include <cutils/properties.h>
+#include <cutils/log.h>
#include <utils/Errors.h>
-#include <ui/android_native_buffer.h>
extern "C" {
#include "egllog.h"
@@ -59,13 +68,13 @@ struct android_surface {
struct native_surface base;
struct android_display *adpy;
- android_native_window_t *win;
+ ANativeWindow *win;
/* staging color buffer for when buffer preserving is enabled */
struct pipe_resource *color_res;
uint stamp;
- android_native_buffer_t *buf;
+ ANativeWindowBuffer *buf;
struct pipe_resource *buf_res;
/* cache the current back buffers */
@@ -161,11 +170,11 @@ get_handle_name(buffer_handle_t handle)
#endif /* ANDROID_BACKEND_NO_DRM */
/**
- * Import an android_native_buffer_t allocated by the server.
+ * Import an ANativeWindowBuffer allocated by the server.
*/
static struct pipe_resource *
import_buffer(struct android_display *adpy, const struct pipe_resource *templ,
- struct android_native_buffer_t *abuf)
+ ANativeWindowBuffer *abuf)
{
struct pipe_screen *screen = adpy->base.screen;
struct pipe_resource *res;
@@ -232,7 +241,7 @@ android_surface_clear_cache(struct native_surface *nsurf)
static struct pipe_resource *
android_surface_add_cache(struct native_surface *nsurf,
- struct android_native_buffer_t *abuf)
+ ANativeWindowBuffer *abuf)
{
struct android_surface *asurf = android_surface(nsurf);
void *handle;
@@ -716,7 +725,7 @@ android_display_import_buffer(struct native_display *ndpy,
struct native_buffer *nbuf)
{
struct android_display *adpy = android_display(ndpy);
- struct android_native_buffer_t *abuf;
+ ANativeWindowBuffer *abuf;
enum pipe_format format;
struct pipe_resource templ;
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.c b/src/gallium/state_trackers/egl/common/egl_g3d_image.c
index 4d90c400319..cf8ec98dbba 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d_image.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.c
@@ -206,7 +206,7 @@ egl_g3d_reference_wl_buffer(_EGLDisplay *dpy, struct wl_buffer *buffer,
static struct pipe_resource *
egl_g3d_reference_android_native_buffer(_EGLDisplay *dpy,
- struct android_native_buffer_t *buf)
+ struct ANativeWindowBuffer *buf)
{
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
struct native_buffer nbuf;
@@ -260,7 +260,7 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
#ifdef EGL_ANDROID_image_native_buffer
case EGL_NATIVE_BUFFER_ANDROID:
ptex = egl_g3d_reference_android_native_buffer(dpy,
- (struct android_native_buffer_t *) buffer);
+ (struct ANativeWindowBuffer *) buffer);
break;
#endif
default:
diff --git a/src/gallium/state_trackers/egl/common/native_buffer.h b/src/gallium/state_trackers/egl/common/native_buffer.h
index 503ed580b05..eb161b11a3d 100644
--- a/src/gallium/state_trackers/egl/common/native_buffer.h
+++ b/src/gallium/state_trackers/egl/common/native_buffer.h
@@ -33,7 +33,7 @@
#include "pipe/p_state.h"
struct native_display;
-struct android_native_buffer_t;
+struct ANativeWindowBuffer;
enum native_buffer_type {
NATIVE_BUFFER_DRM,
@@ -53,7 +53,7 @@ struct native_buffer {
unsigned stride;
} drm;
- struct android_native_buffer_t *android; /**< opaque native buffer */
+ struct ANativeWindowBuffer *android; /**< opaque native buffer */
} u;
};
diff --git a/src/gallium/winsys/sw/android/android_sw_winsys.cpp b/src/gallium/winsys/sw/android/android_sw_winsys.cpp
index 02faf1e0cca..f9b90044ac5 100644
--- a/src/gallium/winsys/sw/android/android_sw_winsys.cpp
+++ b/src/gallium/winsys/sw/android/android_sw_winsys.cpp
@@ -32,10 +32,12 @@
#include "util/u_format.h"
#include "state_tracker/sw_winsys.h"
+#include <hardware/gralloc.h>
#include <utils/Errors.h>
-#include <private/ui/sw_gralloc_handle.h>
-#include <hardware/gralloc.h>
+#if ANDROID_VERSION < 0x0300
+#include <private/ui/sw_gralloc_handle.h>
+#endif
#include "android_sw_winsys.h"
@@ -105,14 +107,17 @@ android_displaytarget_unmap(struct sw_winsys *ws,
struct android_sw_winsys *droid = android_sw_winsys(ws);
struct android_sw_displaytarget *adt = android_sw_displaytarget(dt);
+#if ANDROID_VERSION < 0x0300
+ /* try sw_gralloc first */
+ if (adt->mapped && sw_gralloc_handle_t::validate(adt->handle) >= 0) {
+ adt->mapped = NULL;
+ return;
+ }
+#endif
+
if (adt->mapped) {
- if (sw_gralloc_handle_t::validate(adt->handle) >= 0) {
- adt->mapped = NULL;
- }
- else {
- droid->grmod->unlock(droid->grmod, adt->handle);
- adt->mapped = NULL;
- }
+ droid->grmod->unlock(droid->grmod, adt->handle);
+ adt->mapped = NULL;
}
}
@@ -124,17 +129,21 @@ android_displaytarget_map(struct sw_winsys *ws,
struct android_sw_winsys *droid = android_sw_winsys(ws);
struct android_sw_displaytarget *adt = android_sw_displaytarget(dt);
+#if ANDROID_VERSION < 0x0300
+ /* try sw_gralloc first */
+ if (sw_gralloc_handle_t::validate(adt->handle) >= 0) {
+ const sw_gralloc_handle_t *swhandle =
+ reinterpret_cast<const sw_gralloc_handle_t *>(adt->handle);
+ adt->mapped = reinterpret_cast<void *>(swhandle->base);
+
+ return adt->mapped;
+ }
+#endif
+
if (!adt->mapped) {
- if (sw_gralloc_handle_t::validate(adt->handle) >= 0) {
- const sw_gralloc_handle_t *swhandle =
- reinterpret_cast<const sw_gralloc_handle_t *>(adt->handle);
- adt->mapped = reinterpret_cast<void *>(swhandle->base);
- }
- else {
- /* lock the buffer for CPU access */
- droid->grmod->lock(droid->grmod, adt->handle,
- adt->usage, 0, 0, adt->width, adt->height, &adt->mapped);
- }
+ /* lock the buffer for CPU access */
+ droid->grmod->lock(droid->grmod, adt->handle,
+ adt->usage, 0, 0, adt->width, adt->height, &adt->mapped);
}
return adt->mapped;