aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android
diff options
context:
space:
mode:
Diffstat (limited to 'backends/platform/android')
-rw-r--r--backends/platform/android/README.build71
-rw-r--r--backends/platform/android/android.cpp161
-rw-r--r--backends/platform/android/android.mk9
-rw-r--r--backends/platform/android/module.mk31
-rw-r--r--backends/platform/android/org/inodes/gus/scummvm/ScummVM.java130
-rw-r--r--backends/platform/android/org/inodes/gus/scummvm/ScummVMActivity.java24
-rw-r--r--backends/platform/android/org/inodes/gus/scummvm/Unpacker.java4
-rw-r--r--backends/platform/android/scummvm-android-themeengine.patch135
-rw-r--r--backends/platform/android/video.cpp334
-rw-r--r--backends/platform/android/video.h140
10 files changed, 723 insertions, 316 deletions
diff --git a/backends/platform/android/README.build b/backends/platform/android/README.build
index fa56bfc180..1c407bd469 100644
--- a/backends/platform/android/README.build
+++ b/backends/platform/android/README.build
@@ -2,41 +2,38 @@ Building the ScummVM Android port
=================================
You will need these things to build:
-1. Android EGL headers and library
-2. Android SDK
-3. An arm-android-eabi GCC toolchain
+1. Android SDK
+2. An arm-oe-linux-androideabi GCC toolchain(*)
In the example commands, we are going to build against the Android 1.5
native ABI (but using the Android 1.6 SDK tools). Other version
combinations might/should be possible with a bit of tweaking.
-In detail:
-
-1. Android EGL headers and library
+(*) Any other sane Android toolchain should be easy to use, but this
+is the toolchain prefix that is used by default. You can trivially
+find and modify the single location where it appears in ./configure if
+you have some other prefix variation.
-You can build these from the full Android source, but it is far easier
-to just download the 3 Android EGL headers from here:
- http://android.git.kernel.org/?p=platform/frameworks/base.git;a=tree;f=opengl/include/EGL;hb=HEAD
- (copy them to a directory called "EGL" somewhere)
-... and grab libEGL.so off an existing phone/emulator:
- adb pull /system/lib/libEGL.so /tmp
+In detail:
-2. Android SDK
+1. Android SDK
-Download and install somewhere.
+Download the SDK from http://developer.android.com/ and install
+somewhere. You will need both the API level 8 (aka Android 2.2) and
+API level 3 (aka Android 1.5) platforms.
-3. arm-android-eabi GCC toolchain
+2. arm-*-linux-androideabi GCC toolchain
You have several choices for toolchains:
-- Use Google arm-eabi prebuilt toolchain.
+ - Use Google arm-eabi prebuilt toolchain.
This is shipped with both the Android source release and Android NDK.
The problem is that "arm-eabi-gcc" can't actually link anything
successfully without extra command line flags. To use this with the
ScummVM configure/build environment you will need to create a family
-of shell wrapper scripts that convert "arm-android-eabi-foo" to
+of shell wrapper scripts that convert "arm-oe-linux-androideabi-foo" to
"arm-eabi-foo -mandroid".
For example, I use this script:
@@ -44,17 +41,24 @@ For example, I use this script:
exec arm-eabi-${0##*-} -mandroid -DANDROID "$@"
... and create a family of symlinks/hardlinks pointing to it called
-arm-android-eabi-gcc, arm-android-eabi-g++, etc. For tools that don't
-take a "-mandroid" argument - like arm-eabi-strip - I bypass the shell
-wrapper and just create an arm-android-eabi-strip symlink to the tool
-directly.
+arm-oe-android-linuxeabi-gcc, arm-oe-android-linuxeabi-g++, etc. For
+tools that don't take a "-mandroid" argument - like arm-eabi-strip - I
+bypass the shell wrapper and just create an arm-oe-android-linuxeabi-strip
+symlink to the tool directly.
+
+In practice you will probably need significant linker command line
+massaging in order to get the crtbegin/end and libraries all linked in
+the right way. It's not hard to do manually, but it is annoying to
+script in a general purpose way.
-- Build your own arm-android-eabi toolchain from GCC source.
+ - Build your own arm-*-linux-androideabi toolchain from GCC source.
-This is lots of fun. I suggest my Android openembedded patches, see:
- http://wiki.github.com/anguslees/openembedded-android/
-(You just need to have lots of disk space and type a few commands)
-If you get stuck, ask
+This is lots of fun, but will become significantly easier once gcc-4.6
+is released. In the interim, I suggest using my precompiled Android
+openembedded-based toolchain:
+ wget http://commondatastorage.googleapis.com/anr/sdk/android-2.2-i686-linux-armv5te-linux-androideabi-toolchain-android.tar.bz2
+ sudo tar jxf android-2.2-i686-linux-armv5te-linux-androideabi-toolchain-android.tar.bz2 -C /
+ . /usr/local/android/arm/environment-setup
Alternatively, do a websearch - there are several other cross-compile
toolchains around.
@@ -63,18 +67,21 @@ toolchains around.
Building ScummVM
================
+(Optionally) compress scummmodern.zip:
+(ScummVM usually ships it uncompressed, but Android can read it more
+efficiently if it is compressed *before* adding it to the apk)
+
+ ( cd gui/themes/scummmodern && zip -f ../scummmodern.zip )
+
+Then build ScummVM:
+
export ANDROID_SDK=<root of Android SDK>
PATH=$ANDROID_SDK/platforms/android-1.6/tools:$ANDROID_SDK/tools:$PATH
- # You also want to ensure your arm-android-eabi toolchain is in your $PATH
+ # You also want to ensure your arm-oe-linux-androideabi toolchain is in $PATH
export ANDROID_TOP=<root of built Android source>
- EGL_INC="-I<location of EGL/ header directory>"
- EGL_LIBS="-L<location of libEGL.so>"
-
- CPPFLAGS="$EGL_INC" \
- LDFLAGS="-g $EGL_LIBS" \
./configure --backend=android --host=android --enable-zlib #and any other flags
make scummvm.apk
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index a6258df554..f6af0fcff5 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -31,10 +31,6 @@
#if defined(ANDROID_BACKEND)
-#define ANDROID_VERSION_GE(major,minor) \
- (ANDROID_MAJOR_VERSION > (major) || \
- (ANDROID_MAJOR_VERSION == (major) && ANDROID_MINOR_VERSION >= (minor)))
-
#include <jni.h>
#include <string.h>
@@ -45,7 +41,6 @@
#include <GLES/gl.h>
#include <GLES/glext.h>
-#include <EGL/egl.h>
#include <android/log.h>
#include "common/archive.h"
@@ -78,6 +73,14 @@
#undef JNIEXPORT
#define JNIEXPORT __attribute__ ((visibility("default")))
+// This replaces the bionic libc assert message with something that
+// actually prints the assertion failure before aborting.
+extern "C"
+void __assert(const char *file, int line, const char *expr) {
+ __android_log_assert(expr, LOG_TAG, "%s:%d: Assertion failure: %s",
+ file, line, expr);
+}
+
static JavaVM *cached_jvm;
static jfieldID FID_Event_type;
static jfieldID FID_Event_synthetic;
@@ -162,20 +165,19 @@ private:
jmethodID MID_getPluginDirectories;
jmethodID MID_setupScummVMSurface;
jmethodID MID_destroyScummVMSurface;
+ jmethodID MID_swapBuffers;
int _screen_changeid;
- EGLDisplay _egl_display;
- EGLSurface _egl_surface;
- EGLint _egl_surface_width;
- EGLint _egl_surface_height;
+ int _egl_surface_width;
+ int _egl_surface_height;
bool _force_redraw;
// Game layer
GLESPaletteTexture* _game_texture;
int _shake_offset;
+ Common::Rect _focus_rect;
bool _full_screen_dirty;
- Common::Array<Common::Rect> _dirty_rects;
// Overlay layer
GLES4444Texture* _overlay_texture;
@@ -195,6 +197,7 @@ private:
pthread_t _timer_thread;
static void* timerThreadFunc(void* arg);
+ bool _enable_zoning;
bool _virtkeybd_on;
Common::SaveFileManager *_savefile;
@@ -217,6 +220,11 @@ public:
static OSystem_Android* fromJavaObject(JNIEnv* env, jobject obj);
virtual void initBackend();
void addPluginDirectories(Common::FSList &dirs) const;
+ void enableZoning(bool enable) { _enable_zoning = enable; }
+ void setSurfaceSize(int width, int height) {
+ _egl_surface_width = width;
+ _egl_surface_height = height;
+ }
virtual bool hasFeature(Feature f);
virtual void setFeatureState(Feature f, bool enable);
@@ -297,8 +305,6 @@ public:
OSystem_Android::OSystem_Android(jobject am)
: _back_ptr(0),
- _egl_display(EGL_NO_DISPLAY),
- _egl_surface(EGL_NO_SURFACE),
_screen_changeid(0),
_force_redraw(false),
_game_texture(NULL),
@@ -307,6 +313,7 @@ OSystem_Android::OSystem_Android(jobject am)
_use_mouse_palette(false),
_show_mouse(false),
_show_overlay(false),
+ _enable_zoning(false),
_savefile(0),
_mixer(0),
_timer(0),
@@ -362,6 +369,7 @@ bool OSystem_Android::initJavaHooks(JNIEnv* env, jobject self) {
FIND_METHOD(getPluginDirectories, "()[Ljava/lang/String;");
FIND_METHOD(setupScummVMSurface, "()V");
FIND_METHOD(destroyScummVMSurface, "()V");
+ FIND_METHOD(swapBuffers, "()Z");
#undef FIND_METHOD
@@ -574,6 +582,7 @@ int OSystem_Android::getGraphicsMode() const {
}
void OSystem_Android::setupScummVMSurface() {
+ ENTER("setupScummVMSurface");
JNIEnv* env = JNU_GetEnv();
env->CallVoidMethod(_back_ptr, MID_setupScummVMSurface);
if (env->ExceptionCheck())
@@ -581,37 +590,8 @@ void OSystem_Android::setupScummVMSurface() {
// EGL set up with a new surface. Initialise OpenGLES context.
- _egl_display = eglGetCurrentDisplay();
- _egl_surface = eglGetCurrentSurface(EGL_DRAW);
-
- static bool log_version = true;
- if (log_version) {
- __android_log_print(ANDROID_LOG_INFO, LOG_TAG,
- "Using EGL %s (%s); GL %s/%s (%s)",
- eglQueryString(_egl_display, EGL_VERSION),
- eglQueryString(_egl_display, EGL_VENDOR),
- glGetString(GL_VERSION),
- glGetString(GL_RENDERER),
- glGetString(GL_VENDOR));
- log_version = false; // only log this once
- }
-
GLESTexture::initGLExtensions();
- if (!eglQuerySurface(_egl_display, _egl_surface,
- EGL_WIDTH, &_egl_surface_width) ||
- !eglQuerySurface(_egl_display, _egl_surface,
- EGL_HEIGHT, &_egl_surface_height)) {
- JNU_ThrowByName(env, "java/lang/RuntimeException",
- "Error fetching EGL surface width/height");
- return;
- }
- __android_log_print(ANDROID_LOG_INFO, LOG_TAG,
- "New surface is %dx%d",
- _egl_surface_width, _egl_surface_height);
-
- CHECK_GL_ERROR();
-
// Turn off anything that looks like 3D ;)
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
@@ -645,20 +625,18 @@ void OSystem_Android::setupScummVMSurface() {
_mouse_texture->reinitGL();
glViewport(0, 0, _egl_surface_width, _egl_surface_height);
+
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, _egl_surface_width, _egl_surface_height, 0, -1, 1);
-
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
+ clearFocusRectangle();
CHECK_GL_ERROR();
-
- _force_redraw = true;
}
void OSystem_Android::destroyScummVMSurface() {
- _egl_surface = EGL_NO_SURFACE;
JNIEnv* env = JNU_GetEnv();
env->CallVoidMethod(_back_ptr, MID_destroyScummVMSurface);
// Can't use OpenGLES functions after this
@@ -676,7 +654,7 @@ void OSystem_Android::initSize(uint width, uint height,
_overlay_texture->allocBuffer(overlay_width, overlay_height);
// Don't know mouse size yet - it gets reallocated in
- // setMouseCursor. We need the palette allocated before
+ // setMouseCursor. We need the palette allocated before
// setMouseCursor however, so just take a guess at the desired
// size (it's small).
_mouse_texture->allocBuffer(20, 20);
@@ -691,7 +669,7 @@ int16 OSystem_Android::getWidth() {
}
void OSystem_Android::setPalette(const byte* colors, uint start, uint num) {
- ENTER("setPalette(%p, %u, %u)", colors, start, num);
+ ENTER("setPalette(%p, %u, %u)", colors, start, num);
if (!_use_mouse_palette)
_setCursorPalette(colors, start, num);
@@ -739,8 +717,11 @@ void OSystem_Android::updateScreen() {
glPushMatrix();
- if (_shake_offset != 0) {
- // This is the only case where _game_texture doesn't
+ if (_shake_offset != 0 ||
+ (!_focus_rect.isEmpty() &&
+ !Common::Rect(_game_texture->width(),
+ _game_texture->height()).contains(_focus_rect))) {
+ // These are the only cases where _game_texture doesn't
// cover the entire screen.
glClearColorx(0, 0, 0, 1 << 16);
glClear(GL_COLOR_BUFFER_BIT);
@@ -749,15 +730,29 @@ void OSystem_Android::updateScreen() {
glTranslatex(0, -_shake_offset << 16, 0);
}
- _game_texture->drawTexture(0, 0,
- _egl_surface_width, _egl_surface_height);
+ if (_focus_rect.isEmpty()) {
+ _game_texture->drawTexture(0, 0,
+ _egl_surface_width, _egl_surface_height);
+ } else {
+ glPushMatrix();
+ glScalex(xdiv(_egl_surface_width, _focus_rect.width()),
+ xdiv(_egl_surface_height, _focus_rect.height()),
+ 1 << 16);
+ glTranslatex(-_focus_rect.left << 16, -_focus_rect.top << 16, 0);
+ glScalex(xdiv(_game_texture->width(), _egl_surface_width),
+ xdiv(_game_texture->height(), _egl_surface_height),
+ 1 << 16);
+ _game_texture->drawTexture(0, 0,
+ _egl_surface_width, _egl_surface_height);
+ glPopMatrix();
+ }
CHECK_GL_ERROR();
if (_show_overlay) {
_overlay_texture->drawTexture(0, 0,
- _egl_surface_width,
- _egl_surface_height);
+ _egl_surface_width,
+ _egl_surface_height);
CHECK_GL_ERROR();
}
@@ -765,8 +760,8 @@ void OSystem_Android::updateScreen() {
glPushMatrix();
glTranslatex(-_mouse_hotspot.x << 16,
- -_mouse_hotspot.y << 16,
- 0);
+ -_mouse_hotspot.y << 16,
+ 0);
// Scale up ScummVM -> OpenGL (pixel) coordinates
int texwidth, texheight;
@@ -778,8 +773,8 @@ void OSystem_Android::updateScreen() {
texheight = getHeight();
}
glScalex(xdiv(_egl_surface_width, texwidth),
- xdiv(_egl_surface_height, texheight),
- 1 << 16);
+ xdiv(_egl_surface_height, texheight),
+ 1 << 16);
// Note the extra half texel to position the mouse in
// the middle of the x,y square:
@@ -801,14 +796,11 @@ void OSystem_Android::updateScreen() {
CHECK_GL_ERROR();
- if (!eglSwapBuffers(_egl_display, _egl_surface)) {
- EGLint error = eglGetError();
- warning("eglSwapBuffers exited with error 0x%x", error);
- // Some errors mean we need to reinit GL
- if (error == EGL_CONTEXT_LOST) {
- destroyScummVMSurface();
- setupScummVMSurface();
- }
+ JNIEnv* env = JNU_GetEnv();
+ if (!env->CallBooleanMethod(_back_ptr, MID_swapBuffers)) {
+ // Context lost -> need to reinit GL
+ destroyScummVMSurface();
+ setupScummVMSurface();
}
}
@@ -841,26 +833,18 @@ void OSystem_Android::fillScreen(uint32 col) {
void OSystem_Android::setFocusRectangle(const Common::Rect& rect) {
ENTER("setFocusRectangle(%d,%d,%d,%d)",
rect.left, rect.top, rect.right, rect.bottom);
-#if 0
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrthof(rect.left, rect.right, rect.top, rect.bottom, 0, 1);
- glMatrixMode(GL_MODELVIEW);
-
- _force_redraw = true;
-#endif
+ if (_enable_zoning) {
+ _focus_rect = rect;
+ _force_redraw = true;
+ }
}
void OSystem_Android::clearFocusRectangle() {
ENTER("clearFocusRectangle()");
-#if 0
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrthof(0, _egl_surface_width, _egl_surface_height, 0, -1, 1);
- glMatrixMode(GL_MODELVIEW);
-
- _force_redraw = true;
-#endif
+ if (_enable_zoning) {
+ _focus_rect = Common::Rect();
+ _force_redraw = true;
+ }
}
void OSystem_Android::showOverlay() {
@@ -1338,6 +1322,17 @@ void AndroidPluginProvider::addCustomDirectories(Common::FSList &dirs) const {
}
#endif
+static void ScummVM_enableZoning(JNIEnv* env, jobject self, jboolean enable) {
+ OSystem_Android* cpp_obj = OSystem_Android::fromJavaObject(env, self);
+ cpp_obj->enableZoning(enable);
+}
+
+static void ScummVM_setSurfaceSize(JNIEnv* env, jobject self,
+ jint width, jint height) {
+ OSystem_Android* cpp_obj = OSystem_Android::fromJavaObject(env, self);
+ cpp_obj->setSurfaceSize(width, height);
+}
+
const static JNINativeMethod gMethods[] = {
{ "create", "(Landroid/content/res/AssetManager;)V",
(void*)ScummVM_create },
@@ -1352,6 +1347,10 @@ const static JNINativeMethod gMethods[] = {
(void*)ScummVM_setConfManInt },
{ "setConfMan", "(Ljava/lang/String;Ljava/lang/String;)V",
(void*)ScummVM_setConfManString },
+ { "enableZoning", "(Z)V",
+ (void*)ScummVM_enableZoning },
+ { "setSurfaceSize", "(II)V",
+ (void*)ScummVM_setSurfaceSize },
};
JNIEXPORT jint JNICALL
diff --git a/backends/platform/android/android.mk b/backends/platform/android/android.mk
index 0bc8fa265e..95e848e0d9 100644
--- a/backends/platform/android/android.mk
+++ b/backends/platform/android/android.mk
@@ -4,7 +4,6 @@ AAPT = aapt
DX = dx
APKBUILDER = apkbuilder
ADB = adb -e
-ANDROID_JAR = $(ANDROID_SDK)/platforms/android-1.6/android.jar
JAVAC ?= javac
JAVACFLAGS = -source 1.5 -target 1.5
@@ -12,6 +11,14 @@ JAVACFLAGS = -source 1.5 -target 1.5
#LDFLAGS += -Wl,--gc-sections
#CXXFLAGS += -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden
+resources.ap_: $(srcdir)/dists/android/AndroidManifest.xml $(RESOURCES) $(ASSETS) $(ANDROID_JAR8) $(DIST_FILES_THEMES) $(DIST_FILES_ENGINEDATA)
+ $(INSTALL) -d build.tmp/assets/
+ $(INSTALL) -c -m 644 $(DIST_FILES_THEMES) $(DIST_FILES_ENGINEDATA) build.tmp/assets/
+ $(AAPT) package -f -M $< -S $(srcdir)/dists/android/res -A build.tmp/assets -I $(ANDROID_JAR8) -F $@
+
+build.tmp/%/resources.ap_: build.tmp/%/AndroidManifest.xml build.stage/%/res/values/strings.xml build.stage/%/res/drawable/scummvm.png $(ANDROID_JAR8)
+ $(AAPT) package -f -M $< -S build.stage/$*/res -I $(ANDROID_JAR8) -F $@
+
scummvm.apk: build.tmp/libscummvm.so resources.ap_ classes.dex
# Package installer won't delete old libscummvm.so on upgrade so
# replace it with a zero size file
diff --git a/backends/platform/android/module.mk b/backends/platform/android/module.mk
index fdb0ed2ac4..b457b388b1 100644
--- a/backends/platform/android/module.mk
+++ b/backends/platform/android/module.mk
@@ -3,11 +3,10 @@ MODULE := backends/platform/android
MODULE_OBJS := \
android.o asset-archive.o video.o
-MODULE_DIRS += \
- backends/platform/android/
-
-# We don't use the rules.mk here on purpose
-OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS)
+# We don't use rules.mk but rather manually update OBJS and MODULE_DIRS.
+MODULE_OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS))
+OBJS := $(MODULE_OBJS) $(OBJS)
+MODULE_DIRS += $(sort $(dir $(MODULE_OBJS)))
JAVA_SRC = \
$(MODULE)/org/inodes/gus/scummvm/ScummVM.java \
@@ -39,14 +38,22 @@ PLUGIN_RESOURCES = \
#ANDROID_VERSIONCODE = 6 Specified in dists/android/AndroidManifest.xml.in
ANDROID_PLUGIN_VERSIONCODE = 6
+# This is a bit silly. I want to compile against the 1.6 android.jar,
+# to make the compiler check that I don't use something that requires
+# a newer Android. However, in order to use android:installLocation,
+# we need to give aapt a version >=8 android.jar - even though the
+# result will work ok on 1.5+.
+ANDROID_JAR = $(ANDROID_SDK)/platforms/android-1.5/android.jar
+ANDROID_JAR8 = $(ANDROID_SDK)/platforms/android-8/android.jar
+
# This library contains scummvm proper
build.tmp/libscummvm.so: $(OBJS)
@$(MKDIR) -p $(@D)
- $(CXX) $(PLUGIN_LDFLAGS) -shared $(LDFLAGS) -Wl,-soname,$(@F) -Wl,--no-undefined -o $@ $(PRE_OBJS_FLAGS) $(OBJS) $(POST_OBJS_FLAGS) $(LIBS)
+ $(QUIET_LINK)$(CXX) -shared $(LDFLAGS) -Wl,-Bsymbolic -Wl,-soname,$(@F) -Wl,--no-undefined -o $@ $(PRE_OBJS_FLAGS) $(OBJS) $(POST_OBJS_FLAGS) $(LIBS)
-backends/platform/android/org/inodes/gus/scummvm/R.java backends/platform/android/org/inodes/gus/scummvm/Manifest.java: $(srcdir)/dists/android/AndroidManifest.xml $(filter %.xml,$(RESOURCES)) $(ANDROID_JAR)
- $(AAPT) package -m -J backends/platform/android -M $< -S $(srcdir)/dists/android/res -I $(ANDROID_JAR)
+backends/platform/android/org/inodes/gus/scummvm/R.java backends/platform/android/org/inodes/gus/scummvm/Manifest.java: $(srcdir)/dists/android/AndroidManifest.xml $(filter %.xml,$(RESOURCES)) $(ANDROID_JAR8)
+ $(AAPT) package -m -J backends/platform/android -M $< -S $(srcdir)/dists/android/res -I $(ANDROID_JAR8)
build.tmp/classes/%.class: $(srcdir)/backends/platform/android/%.java $(srcdir)/backends/platform/android/org/inodes/gus/scummvm/R.java
@$(MKDIR) -p $(@D)
@@ -63,14 +70,6 @@ build.tmp/plugins/classes.dex: $(JAVA_PLUGIN_SRC:backends/platform/android/%.jav
@$(MKDIR) -p $(@D)
$(DX) --dex --output=$@ build.tmp/classes.plugin
-resources.ap_: $(srcdir)/dists/android/AndroidManifest.xml $(RESOURCES) $(ASSETS) $(ANDROID_JAR) $(DIST_FILES_THEMES) $(DIST_FILES_ENGINEDATA)
- $(INSTALL) -d build.tmp/assets/
- $(INSTALL) -c -m 644 $(DIST_FILES_THEMES) $(DIST_FILES_ENGINEDATA) build.tmp/assets/
- $(AAPT) package -f -M $< -S $(srcdir)/dists/android/res -A build.tmp/assets -I $(ANDROID_JAR) -F $@
-
-build.tmp/%/resources.ap_: build.tmp/%/AndroidManifest.xml build.stage/%/res/values/strings.xml build.stage/%/res/drawable/scummvm.png $(ANDROID_JAR)
- $(AAPT) package -f -M $< -S build.stage/$*/res -I $(ANDROID_JAR) -F $@
-
build.tmp/%/AndroidManifest.xml build.stage/%/res/values/strings.xml: dists/android/mkmanifest.pl configure dists/android/AndroidManifest.xml
dists/android/mkmanifest.pl --id=$* --configure=configure \
--version-name=$(VERSION) \
diff --git a/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java b/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java
index f4dca0e7e5..d39aa363ef 100644
--- a/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java
+++ b/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java
@@ -12,7 +12,10 @@ import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
+import javax.microedition.khronos.opengles.GL;
+import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGL11;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
@@ -30,11 +33,11 @@ import java.util.concurrent.Semaphore;
public class ScummVM implements SurfaceHolder.Callback {
private final static String LOG_TAG = "ScummVM.java";
- private final int AUDIO_FRAME_SIZE = 2 * 2; // bytes. 16bit audio * stereo
+ private final int AUDIO_FRAME_SIZE = 2 * 2; // bytes. 16bit audio * stereo
public static class AudioSetupException extends Exception {}
private long nativeScummVM; // native code hangs itself here
- boolean scummVMRunning = false;
+ boolean scummVMRunning = false;
private native void create(AssetManager am);
@@ -54,49 +57,49 @@ public class ScummVM implements SurfaceHolder.Callback {
destroy();
}
- // Surface creation:
- // GUI thread: create surface, release lock
- // ScummVM thread: acquire lock (block), read surface
- //
- // Surface deletion:
- // GUI thread: post event, acquire lock (block), return
- // ScummVM thread: read event, free surface, release lock
- //
- // In other words, ScummVM thread does this:
- // acquire lock
- // setup surface
- // when SCREEN_CHANGED arrives:
- // destroy surface
- // release lock
- // back to acquire lock
- static final int configSpec[] = {
+ // Surface creation:
+ // GUI thread: create surface, release lock
+ // ScummVM thread: acquire lock (block), read surface
+ //
+ // Surface deletion:
+ // GUI thread: post event, acquire lock (block), return
+ // ScummVM thread: read event, free surface, release lock
+ //
+ // In other words, ScummVM thread does this:
+ // acquire lock
+ // setup surface
+ // when SCREEN_CHANGED arrives:
+ // destroy surface
+ // release lock
+ // back to acquire lock
+ static final int configSpec[] = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 5,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_SURFACE_TYPE, EGL10.EGL_WINDOW_BIT,
EGL10.EGL_NONE,
- };
- EGL10 egl;
- EGLDisplay eglDisplay = EGL10.EGL_NO_DISPLAY;
- EGLConfig eglConfig;
- EGLContext eglContext = EGL10.EGL_NO_CONTEXT;
- EGLSurface eglSurface = EGL10.EGL_NO_SURFACE;
- Semaphore surfaceLock = new Semaphore(0, true);
- SurfaceHolder nativeSurface;
-
- public void surfaceCreated(SurfaceHolder holder) {
+ };
+ EGL10 egl;
+ EGLDisplay eglDisplay = EGL10.EGL_NO_DISPLAY;
+ EGLConfig eglConfig;
+ EGLContext eglContext = EGL10.EGL_NO_CONTEXT;
+ EGLSurface eglSurface = EGL10.EGL_NO_SURFACE;
+ Semaphore surfaceLock = new Semaphore(0, true);
+ SurfaceHolder nativeSurface;
+
+ public void surfaceCreated(SurfaceHolder holder) {
nativeSurface = holder;
surfaceLock.release();
- }
+ }
- public void surfaceChanged(SurfaceHolder holder, int format,
+ public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// Disabled while I debug GL problems
//pushEvent(new Event(Event.EVENT_SCREEN_CHANGED));
- }
+ }
- public void surfaceDestroyed(SurfaceHolder holder) {
+ public void surfaceDestroyed(SurfaceHolder holder) {
pushEvent(new Event(Event.EVENT_SCREEN_CHANGED));
try {
surfaceLock.acquire();
@@ -104,10 +107,10 @@ public class ScummVM implements SurfaceHolder.Callback {
Log.e(this.toString(),
"Interrupted while waiting for surface lock", e);
}
- }
+ }
- // Called by ScummVM thread (from initBackend)
- private void createScummVMGLContext() {
+ // Called by ScummVM thread (from initBackend)
+ private void createScummVMGLContext() {
egl = (EGL10)EGLContext.getEGL();
eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
@@ -126,10 +129,11 @@ public class ScummVM implements SurfaceHolder.Callback {
eglContext = egl.eglCreateContext(eglDisplay, eglConfig,
EGL10.EGL_NO_CONTEXT, null);
- }
+ }
- // Called by ScummVM thread
- protected void setupScummVMSurface() {
+ // Called by ScummVM thread
+ static private boolean _log_version = true;
+ protected void setupScummVMSurface() {
try {
surfaceLock.acquire();
} catch (InterruptedException e) {
@@ -140,10 +144,30 @@ public class ScummVM implements SurfaceHolder.Callback {
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig,
nativeSurface, null);
egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
- }
- // Called by ScummVM thread
- protected void destroyScummVMSurface() {
+ GL10 gl = (GL10)eglContext.getGL();
+
+ if (_log_version) {
+ Log.i(LOG_TAG, String.format("Using EGL %s (%s); GL %s/%s (%s)",
+ egl.eglQueryString(eglDisplay, EGL10.EGL_VERSION),
+ egl.eglQueryString(eglDisplay, EGL10.EGL_VENDOR),
+ gl.glGetString(GL10.GL_VERSION),
+ gl.glGetString(GL10.GL_RENDERER),
+ gl.glGetString(GL10.GL_VENDOR)));
+ _log_version = false; // only log this once
+ }
+
+ int[] value = new int[1];
+ egl.eglQuerySurface(eglDisplay, eglSurface, EGL10.EGL_WIDTH, value);
+ int width = value[0];
+ egl.eglQuerySurface(eglDisplay, eglSurface, EGL10.EGL_HEIGHT, value);
+ int height = value[0];
+ Log.i(LOG_TAG, String.format("New surface is %dx%d", width, height));
+ setSurfaceSize(width, height);
+ }
+
+ // Called by ScummVM thread
+ protected void destroyScummVMSurface() {
if (eglSurface != null) {
egl.eglMakeCurrent(eglDisplay, EGL10.EGL_NO_SURFACE,
EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
@@ -152,16 +176,28 @@ public class ScummVM implements SurfaceHolder.Callback {
}
surfaceLock.release();
- }
+ }
- public void setSurface(SurfaceHolder holder) {
+ public void setSurface(SurfaceHolder holder) {
holder.addCallback(this);
- }
+ }
+
+ final public boolean swapBuffers() {
+ if (!egl.eglSwapBuffers(eglDisplay, eglSurface)) {
+ int error = egl.eglGetError();
+ Log.w(LOG_TAG, String.format("eglSwapBuffers exited with error 0x%x", error));
+ if (error == EGL11.EGL_CONTEXT_LOST)
+ return false;
+ }
+ return true;
+ }
// Set scummvm config options
final public native static void loadConfigFile(String path);
final public native static void setConfMan(String key, int value);
final public native static void setConfMan(String key, String value);
+ final public native void enableZoning(boolean enable);
+ final public native void setSurfaceSize(int width, int height);
// Feed an event to ScummVM. Safe to call from other threads.
final public native void pushEvent(Event e);
@@ -179,10 +215,10 @@ public class ScummVM implements SurfaceHolder.Callback {
protected void showVirtualKeyboard(boolean enable) {}
protected String[] getSysArchives() { return new String[0]; }
protected String[] getPluginDirectories() { return new String[0]; }
- protected void initBackend() throws AudioSetupException {
+ protected void initBackend() throws AudioSetupException {
createScummVMGLContext();
initAudio();
- }
+ }
private static class AudioThread extends Thread {
final private int buf_size;
@@ -239,7 +275,7 @@ public class ScummVM implements SurfaceHolder.Callback {
break;
} else if (ret != len) {
Log.w(LOG_TAG, String.format(
- "Short audio write. Wrote %dB, not %dB",
+ "Short audio write. Wrote %dB, not %dB",
ret, buf.length));
// Buffer is full, so yield cpu for a while
Thread.sleep(100);
diff --git a/backends/platform/android/org/inodes/gus/scummvm/ScummVMActivity.java b/backends/platform/android/org/inodes/gus/scummvm/ScummVMActivity.java
index fb3cd6348f..b37b2b8a52 100644
--- a/backends/platform/android/org/inodes/gus/scummvm/ScummVMActivity.java
+++ b/backends/platform/android/org/inodes/gus/scummvm/ScummVMActivity.java
@@ -1,7 +1,7 @@
package org.inodes.gus.scummvm;
-import android.app.AlertDialog;
import android.app.Activity;
+import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.media.AudioManager;
@@ -9,13 +9,14 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
+import android.util.DisplayMetrics;
import android.util.Log;
-import android.view.inputmethod.InputMethodManager;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewConfiguration;
+import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
import java.io.IOException;
@@ -31,8 +32,27 @@ public class ScummVMActivity extends Activity {
private class MyScummVM extends ScummVM {
private boolean scummvmRunning = false;
+ private boolean usingSmallScreen() {
+ // Multiple screen sizes came in with Android 1.6. Have
+ // to use reflection in order to continue supporting 1.5
+ // devices :(
+ DisplayMetrics metrics = new DisplayMetrics();
+ getWindowManager().getDefaultDisplay().getMetrics(metrics);
+ try {
+ // This 'density' term is very confusing.
+ int DENSITY_LOW = metrics.getClass().getField("DENSITY_LOW").getInt(null);
+ int densityDpi = metrics.getClass().getField("densityDpi").getInt(metrics);
+ return densityDpi <= DENSITY_LOW;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
public MyScummVM() {
super(ScummVMActivity.this);
+
+ // Enable ScummVM zoning on 'small' screens.
+ enableZoning(usingSmallScreen());
}
@Override
diff --git a/backends/platform/android/org/inodes/gus/scummvm/Unpacker.java b/backends/platform/android/org/inodes/gus/scummvm/Unpacker.java
index efa3e1d2ef..7280aac7d4 100644
--- a/backends/platform/android/org/inodes/gus/scummvm/Unpacker.java
+++ b/backends/platform/android/org/inodes/gus/scummvm/Unpacker.java
@@ -34,6 +34,7 @@ import java.util.zip.ZipFile;
import java.util.zip.ZipEntry;
public class Unpacker extends Activity {
+ private final static boolean PLUGINS_ENABLED = true;
private final static String META_NEXT_ACTIVITY =
"org.inodes.gus.unpacker.nextActivity";
private ProgressBar mProgress;
@@ -79,7 +80,6 @@ public class Unpacker extends Activity {
if (cn != null) {
final Intent origIntent = getIntent();
Intent intent = new Intent();
- intent.setPackage(origIntent.getPackage());
intent.setComponent(cn);
if (origIntent.getExtras() != null)
intent.putExtras(origIntent.getExtras());
@@ -294,7 +294,7 @@ public class Unpacker extends Activity {
Intent intent = new Intent(ScummVMApplication.ACTION_PLUGIN_QUERY);
List<ResolveInfo> plugins = getPackageManager()
.queryBroadcastReceivers(intent, 0);
- if (plugins.isEmpty()) {
+ if (PLUGINS_ENABLED && plugins.isEmpty()) {
// No plugins installed
AlertDialog.Builder alert = new AlertDialog.Builder(this)
.setTitle(R.string.no_plugins_title)
diff --git a/backends/platform/android/scummvm-android-themeengine.patch b/backends/platform/android/scummvm-android-themeengine.patch
deleted file mode 100644
index 1eafe7fb62..0000000000
--- a/backends/platform/android/scummvm-android-themeengine.patch
+++ /dev/null
@@ -1,135 +0,0 @@
-diff -r 884e66fd1b9c gui/ThemeEngine.cpp
---- a/gui/ThemeEngine.cpp Tue Apr 13 09:30:52 2010 +1000
-+++ b/gui/ThemeEngine.cpp Fri May 28 23:24:43 2010 +1000
-@@ -390,21 +390,19 @@
-
- // Try to create a Common::Archive with the files of the theme.
- if (!_themeArchive && !_themeFile.empty()) {
-- Common::FSNode node(_themeFile);
-- if (node.getName().hasSuffix(".zip") && !node.isDirectory()) {
-+ Common::ArchiveMemberPtr member = SearchMan.getMember(_themeFile);
-+ if (member && member->getName().hasSuffix(".zip")) {
- #ifdef USE_ZLIB
-- Common::Archive *zipArchive = Common::makeZipArchive(node);
-+ Common::Archive *zipArchive = Common::makeZipArchive(member->createReadStream());
-
- if (!zipArchive) {
-- warning("Failed to open Zip archive '%s'.", node.getPath().c_str());
-+ warning("Failed to open Zip archive '%s'.", member->getDisplayName().c_str());
- }
- _themeArchive = zipArchive;
- #else
- warning("Trying to load theme '%s' in a Zip archive without zLib support", _themeFile.c_str());
- return false;
- #endif
-- } else if (node.isDirectory()) {
-- _themeArchive = new Common::FSDirectory(node);
- }
- }
-
-@@ -1436,6 +1434,30 @@
- return tok.empty();
- }
-
-+bool ThemeEngine::themeConfigUsable(const Common::ArchiveMember &member, Common::String &themeName) {
-+ Common::File stream;
-+ bool foundHeader = false;
-+
-+ if (member.getName().hasSuffix(".zip")) {
-+#ifdef USE_ZLIB
-+ Common::Archive *zipArchive = Common::makeZipArchive(member.createReadStream());
-+
-+ if (zipArchive && zipArchive->hasFile("THEMERC")) {
-+ stream.open("THEMERC", *zipArchive);
-+ }
-+
-+ delete zipArchive;
-+#endif
-+ }
-+
-+ if (stream.isOpen()) {
-+ Common::String stxHeader = stream.readLine();
-+ foundHeader = themeConfigParseHeader(stxHeader, themeName);
-+ }
-+
-+ return foundHeader;
-+}
-+
- bool ThemeEngine::themeConfigUsable(const Common::FSNode &node, Common::String &themeName) {
- Common::File stream;
- bool foundHeader = false;
-@@ -1493,10 +1515,6 @@
- if (ConfMan.hasKey("themepath"))
- listUsableThemes(Common::FSNode(ConfMan.get("themepath")), list);
-
--#ifdef DATA_PATH
-- listUsableThemes(Common::FSNode(DATA_PATH), list);
--#endif
--
- #if defined(MACOSX) || defined(IPHONE)
- CFURLRef resourceUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
- if (resourceUrl) {
-@@ -1509,10 +1527,7 @@
- }
- #endif
-
-- if (ConfMan.hasKey("extrapath"))
-- listUsableThemes(Common::FSNode(ConfMan.get("extrapath")), list);
--
-- listUsableThemes(Common::FSNode("."), list, 1);
-+ listUsableThemes(SearchMan, list);
-
- // Now we need to strip all duplicates
- // TODO: It might not be the best idea to strip duplicates. The user might
-@@ -1531,6 +1546,34 @@
- output.clear();
- }
-
-+void ThemeEngine::listUsableThemes(Common::Archive &archive, Common::List<ThemeDescriptor> &list) {
-+ ThemeDescriptor td;
-+
-+#ifdef USE_ZLIB
-+ Common::ArchiveMemberList fileList;
-+ archive.listMatchingMembers(fileList, "*.zip");
-+ for (Common::ArchiveMemberList::iterator i = fileList.begin();
-+ i != fileList.end(); ++i) {
-+ td.name.clear();
-+ if (themeConfigUsable(**i, td.name)) {
-+ td.filename = (*i)->getName();
-+ td.id = (*i)->getDisplayName();
-+
-+ // If the name of the node object also contains
-+ // the ".zip" suffix, we will strip it.
-+ if (td.id.hasSuffix(".zip")) {
-+ for (int j = 0; j < 4; ++j)
-+ td.id.deleteLastChar();
-+ }
-+
-+ list.push_back(td);
-+ }
-+ }
-+
-+ fileList.clear();
-+#endif
-+}
-+
- void ThemeEngine::listUsableThemes(const Common::FSNode &node, Common::List<ThemeDescriptor> &list, int depth) {
- if (!node.exists() || !node.isReadable() || !node.isDirectory())
- return;
-diff -r 884e66fd1b9c gui/ThemeEngine.h
---- a/gui/ThemeEngine.h Tue Apr 13 09:30:52 2010 +1000
-+++ b/gui/ThemeEngine.h Fri May 28 23:24:43 2010 +1000
-@@ -560,11 +560,13 @@
- static void listUsableThemes(Common::List<ThemeDescriptor> &list);
- private:
- static bool themeConfigUsable(const Common::FSNode &node, Common::String &themeName);
-+ static bool themeConfigUsable(const Common::ArchiveMember &member, Common::String &themeName);
- static bool themeConfigParseHeader(Common::String header, Common::String &themeName);
-
- static Common::String getThemeFile(const Common::String &id);
- static Common::String getThemeId(const Common::String &filename);
- static void listUsableThemes(const Common::FSNode &node, Common::List<ThemeDescriptor> &list, int depth = -1);
-+ static void listUsableThemes(Common::Archive &archive, Common::List<ThemeDescriptor> &list);
-
- protected:
- OSystem *_system; /** Global system object. */
diff --git a/backends/platform/android/video.cpp b/backends/platform/android/video.cpp
new file mode 100644
index 0000000000..d4c002fbd0
--- /dev/null
+++ b/backends/platform/android/video.cpp
@@ -0,0 +1,334 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program 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 General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/null/null.cpp $
+ * $Id: null.cpp 34912 2008-11-06 15:02:50Z fingolfin $
+ *
+ */
+
+#include "base/main.h"
+#include "graphics/surface.h"
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+
+#include <android/log.h>
+
+#include "common/rect.h"
+#include "common/array.h"
+#include "common/util.h"
+#include "common/tokenizer.h"
+
+#include "backends/platform/android/video.h"
+
+#undef LOG_TAG
+#define LOG_TAG "ScummVM-video"
+
+#if 0
+#define ENTER(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, args)
+#else
+#define ENTER(args...) /**/
+#endif
+
+#if 0
+#define CHECK_GL_ERROR() checkGlError(__FILE__, __LINE__)
+static const char* getGlErrStr(GLenum error) {
+ switch (error) {
+ case GL_NO_ERROR: return "GL_NO_ERROR";
+ case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
+ case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
+ case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
+ case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
+ case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
+ }
+
+ static char buf[40];
+ snprintf(buf, sizeof(buf), "(Unknown GL error code 0x%x)", error);
+ return buf;
+}
+static void checkGlError(const char* file, int line) {
+ GLenum error = glGetError();
+ if (error != GL_NO_ERROR)
+ warning("%s:%d: GL error: %s", file, line, getGlErrStr(error));
+}
+#else
+#define CHECK_GL_ERROR() do {} while (false)
+#endif
+
+// Supported GL extensions
+static bool npot_supported = false;
+#ifdef GL_OES_draw_texture
+static bool draw_tex_supported = false;
+#endif
+
+static inline GLfixed xdiv(int numerator, int denominator) {
+ assert(numerator < (1<<16));
+ return (numerator << 16) / denominator;
+}
+
+template <class T>
+static T nextHigher2(T k) {
+ if (k == 0)
+ return 1;
+ --k;
+ for (uint i = 1; i < sizeof(T)*CHAR_BIT; i <<= 1)
+ k = k | k >> i;
+ return k + 1;
+}
+
+void GLESTexture::initGLExtensions() {
+ const char* ext_string =
+ reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
+ __android_log_print(ANDROID_LOG_INFO, LOG_TAG,
+ "Extensions: %s", ext_string);
+ Common::StringTokenizer tokenizer(ext_string, " ");
+ while (!tokenizer.empty()) {
+ Common::String token = tokenizer.nextToken();
+ if (token == "GL_ARB_texture_non_power_of_two")
+ npot_supported = true;
+#ifdef GL_OES_draw_texture
+ if (token == "GL_OES_draw_texture")
+ draw_tex_supported = true;
+#endif
+ }
+}
+
+GLESTexture::GLESTexture() :
+ _texture_width(0),
+ _texture_height(0),
+ _all_dirty(true)
+{
+ glGenTextures(1, &_texture_name);
+ // This all gets reset later in allocBuffer:
+ _surface.w = 0;
+ _surface.h = 0;
+ _surface.pitch = _texture_width;
+ _surface.pixels = NULL;
+ _surface.bytesPerPixel = 0;
+}
+
+GLESTexture::~GLESTexture() {
+ debug("Destroying texture %u", _texture_name);
+ glDeleteTextures(1, &_texture_name);
+}
+
+void GLESTexture::reinitGL() {
+ glGenTextures(1, &_texture_name);
+ setDirty();
+}
+
+void GLESTexture::allocBuffer(GLuint w, GLuint h) {
+ CHECK_GL_ERROR();
+ int bpp = bytesPerPixel();
+ _surface.w = w;
+ _surface.h = h;
+ _surface.bytesPerPixel = bpp;
+
+ if (w <= _texture_width && h <= _texture_height)
+ // Already allocated a sufficiently large buffer
+ return;
+
+ if (npot_supported) {
+ _texture_width = _surface.w;
+ _texture_height = _surface.h;
+ } else {
+ _texture_width = nextHigher2(_surface.w);
+ _texture_height = nextHigher2(_surface.h);
+ }
+ _surface.pitch = _texture_width * bpp;
+
+ // Allocate room for the texture now, but pixel data gets uploaded
+ // later (perhaps with multiple TexSubImage2D operations).
+ CHECK_GL_ERROR();
+ glBindTexture(GL_TEXTURE_2D, _texture_name);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ CHECK_GL_ERROR();
+ glTexImage2D(GL_TEXTURE_2D, 0, glFormat(),
+ _texture_width, _texture_height,
+ 0, glFormat(), glType(), NULL);
+ CHECK_GL_ERROR();
+}
+
+void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
+ const void* buf, int pitch) {
+ ENTER("updateBuffer(%u, %u, %u, %u, %p, %d)", x, y, w, h, buf, pitch);
+ glBindTexture(GL_TEXTURE_2D, _texture_name);
+
+ setDirtyRect(Common::Rect(x, y, x+w, y+h));
+
+ if (static_cast<int>(w) * bytesPerPixel() == pitch) {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
+ glFormat(), glType(), buf);
+ } else {
+ // GLES removed the ability to specify pitch, so we
+ // have to do this row by row.
+ const byte* src = static_cast<const byte*>(buf);
+ do {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
+ w, 1, glFormat(), glType(), src);
+ ++y;
+ src += pitch;
+ } while (--h);
+ }
+}
+
+void GLESTexture::fillBuffer(byte x) {
+ byte tmpbuf[_surface.h * _surface.w * bytesPerPixel()];
+ memset(tmpbuf, 0, _surface.h * _surface.w * bytesPerPixel());
+ glBindTexture(GL_TEXTURE_2D, _texture_name);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _surface.w, _surface.h,
+ glFormat(), glType(), tmpbuf);
+ setDirty();
+}
+
+void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
+ glBindTexture(GL_TEXTURE_2D, _texture_name);
+
+#ifdef GL_OES_draw_texture
+ // Great extension, but only works under specific conditions.
+ // Still a work-in-progress - disabled for now.
+ if (false && draw_tex_supported && paletteSize() == 0) {
+ //glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ const GLint crop[4] = {0, _surface.h, _surface.w, -_surface.h};
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
+ glDrawTexiOES(x, y, 0, w, h);
+ } else
+#endif
+ {
+ const GLfixed tex_width = xdiv(_surface.w, _texture_width);
+ const GLfixed tex_height = xdiv(_surface.h, _texture_height);
+ const GLfixed texcoords[] = {
+ 0, 0,
+ tex_width, 0,
+ 0, tex_height,
+ tex_width, tex_height,
+ };
+ glTexCoordPointer(2, GL_FIXED, 0, texcoords);
+
+ const GLshort vertices[] = {
+ x, y,
+ x+w, y,
+ x, y+h,
+ x+w, y+h,
+ };
+ glVertexPointer(2, GL_SHORT, 0, vertices);
+
+ assert(ARRAYSIZE(vertices) == ARRAYSIZE(texcoords));
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAYSIZE(vertices)/2);
+ }
+
+ _all_dirty = false;
+ _dirty_rect = Common::Rect();
+}
+
+GLESPaletteTexture::GLESPaletteTexture() :
+ GLESTexture(),
+ _texture(NULL)
+{
+}
+
+GLESPaletteTexture::~GLESPaletteTexture() {
+ delete[] _texture;
+}
+
+void GLESPaletteTexture::allocBuffer(GLuint w, GLuint h) {
+ CHECK_GL_ERROR();
+ int bpp = bytesPerPixel();
+ _surface.w = w;
+ _surface.h = h;
+ _surface.bytesPerPixel = bpp;
+
+ if (w <= _texture_width && h <= _texture_height)
+ // Already allocated a sufficiently large buffer
+ return;
+
+ if (npot_supported) {
+ _texture_width = _surface.w;
+ _texture_height = _surface.h;
+ } else {
+ _texture_width = nextHigher2(_surface.w);
+ _texture_height = nextHigher2(_surface.h);
+ }
+ _surface.pitch = _texture_width * bpp;
+
+ // Texture gets uploaded later (from drawTexture())
+
+ byte* new_buffer = new byte[paletteSize() +
+ _texture_width * _texture_height * bytesPerPixel()];
+ if (_texture) {
+ memcpy(new_buffer, _texture, paletteSize()); // preserve palette
+ delete[] _texture;
+ }
+ _texture = new_buffer;
+ _surface.pixels = _texture + paletteSize();
+}
+
+void GLESPaletteTexture::fillBuffer(byte x) {
+ assert(_surface.pixels);
+ memset(_surface.pixels, x, _surface.pitch * _surface.h);
+ setDirty();
+}
+
+void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y,
+ GLuint w, GLuint h,
+ const void* buf, int pitch) {
+ _all_dirty = true;
+
+ const byte* src = static_cast<const byte*>(buf);
+ byte* dst = static_cast<byte*>(_surface.getBasePtr(x, y));
+ do {
+ memcpy(dst, src, w * bytesPerPixel());
+ dst += _surface.pitch;
+ src += pitch;
+ } while (--h);
+}
+
+void GLESPaletteTexture::uploadTexture() const {
+ const size_t texture_size =
+ paletteSize() + _texture_width * _texture_height * bytesPerPixel();
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, glType(),
+ _texture_width, _texture_height,
+ 0, texture_size, _texture);
+ CHECK_GL_ERROR();
+}
+
+void GLESPaletteTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
+ if (_all_dirty) {
+ glBindTexture(GL_TEXTURE_2D, _texture_name);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ CHECK_GL_ERROR();
+ uploadTexture();
+ _all_dirty = false;
+ }
+
+ GLESTexture::drawTexture(x, y, w, h);
+}
diff --git a/backends/platform/android/video.h b/backends/platform/android/video.h
new file mode 100644
index 0000000000..ee707e4cb5
--- /dev/null
+++ b/backends/platform/android/video.h
@@ -0,0 +1,140 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program 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 General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/null/null.cpp $
+ * $Id: null.cpp 34912 2008-11-06 15:02:50Z fingolfin $
+ *
+ */
+
+#if defined(ANDROID)
+
+#include <GLES/gl.h>
+
+#include "graphics/surface.h"
+
+#include "common/rect.h"
+#include "common/array.h"
+
+class GLESTexture {
+public:
+ static void initGLExtensions();
+
+ GLESTexture();
+ virtual ~GLESTexture();
+ virtual void reinitGL();
+ virtual void allocBuffer(GLuint width, GLuint height);
+ const Graphics::Surface* surface_const() const { return &_surface; }
+ GLuint width() const { return _surface.w; }
+ GLuint height() const { return _surface.h; }
+ GLuint texture_name() const { return _texture_name; }
+ bool dirty() const { return _all_dirty || !_dirty_rect.isEmpty(); }
+ virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
+ const void* buf, int pitch);
+ virtual void fillBuffer(byte x);
+ virtual void drawTexture() {
+ drawTexture(0, 0, _surface.w, _surface.h);
+ }
+ virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);
+
+protected:
+ virtual byte bytesPerPixel() const = 0;
+ virtual GLenum glFormat() const = 0;
+ virtual GLenum glType() const = 0;
+ virtual size_t paletteSize() const { return 0; };
+ void setDirty() {
+ _all_dirty = true;
+ _dirty_rect = Common::Rect();
+ }
+ void setDirtyRect(const Common::Rect& r) {
+ if (!_all_dirty) {
+ if (_dirty_rect.isEmpty())
+ _dirty_rect = r;
+ else
+ _dirty_rect.extend(r);
+ }
+ }
+ GLuint _texture_name;
+ Graphics::Surface _surface;
+ GLuint _texture_width;
+ GLuint _texture_height;
+ bool _all_dirty;
+ Common::Rect _dirty_rect; // Covers dirty area
+};
+
+// RGBA4444 texture
+class GLES4444Texture : public GLESTexture {
+protected:
+ virtual byte bytesPerPixel() const { return 2; }
+ virtual GLenum glFormat() const { return GL_RGBA; }
+ virtual GLenum glType() const { return GL_UNSIGNED_SHORT_4_4_4_4; }
+};
+
+// RGB565 texture
+class GLES565Texture : public GLESTexture {
+protected:
+ virtual byte bytesPerPixel() const { return 2; }
+ virtual GLenum glFormat() const { return GL_RGB; }
+ virtual GLenum glType() const { return GL_UNSIGNED_SHORT_5_6_5; }
+};
+
+// RGB888 256-entry paletted texture
+class GLESPaletteTexture : public GLESTexture {
+public:
+ GLESPaletteTexture();
+ virtual ~GLESPaletteTexture();
+ virtual void allocBuffer(GLuint width, GLuint height);
+ virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
+ const void* buf, int pitch);
+ Graphics::Surface* surface() {
+ setDirty();
+ return &_surface;
+ }
+ void* pixels() {
+ setDirty();
+ return _surface.pixels;
+ }
+ const byte* palette_const() const { return _texture; };
+ byte* palette() {
+ setDirty();
+ return _texture;
+ };
+ virtual void drawTexture() {
+ drawTexture(0, 0, _surface.w, _surface.h);
+ }
+ virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);
+ virtual void fillBuffer(byte x);
+protected:
+ virtual byte bytesPerPixel() const { return 1; }
+ virtual GLenum glFormat() const { return GL_RGB; }
+ virtual GLenum glType() const { return GL_PALETTE8_RGB8_OES; }
+ virtual size_t paletteSize() const { return 256 * 3; };
+ virtual void uploadTexture() const;
+ byte* _texture;
+};
+
+// RGBA8888 256-entry paletted texture
+class GLESPaletteATexture : public GLESPaletteTexture {
+protected:
+ virtual GLenum glFormat() const { return GL_RGBA; }
+ virtual GLenum glType() const { return GL_PALETTE8_RGBA8_OES; }
+ virtual size_t paletteSize() const { return 256 * 4; };
+};
+
+#endif