From 257913676d5a21c6192a6146e662c21f299c9b09 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 20 Feb 2011 17:01:46 +0100 Subject: ANDROID: Split code into multiple files And get rid of unnecessary JNI calls to get a pointer to g_system --- backends/platform/android/android.cpp | 970 +--------------------------------- 1 file changed, 9 insertions(+), 961 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index c49745f8bd..a0a53474e8 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -25,22 +25,10 @@ #if defined(__ANDROID__) -#include "backends/base-backend.h" -#include "base/main.h" -#include "graphics/surface.h" - -#include "backends/platform/android/android.h" -#include "backends/platform/android/video.h" - -#include - -#include -#include -#include #include #include +#include -#include "common/archive.h" #include "common/util.h" #include "common/rect.h" #include "common/queue.h" @@ -48,13 +36,11 @@ #include "common/events.h" #include "common/config-manager.h" -#include "backends/fs/posix/posix-fs-factory.h" #include "backends/keymapper/keymapper.h" #include "backends/saves/default/default-saves.h" #include "backends/timer/default/default-timer.h" -#include "backends/plugins/posix/posix-provider.h" -#include "audio/mixer_intern.h" +#include "backends/platform/android/android.h" #include "backends/platform/android/asset-archive.h" const char *android_log_tag = "ScummVM"; @@ -106,226 +92,13 @@ void checkGlError(const char *expr, const char *file, int line) { } #endif -static JavaVM *cached_jvm; -static jfieldID FID_Event_type; -static jfieldID FID_Event_synthetic; -static jfieldID FID_Event_kbd_keycode; -static jfieldID FID_Event_kbd_ascii; -static jfieldID FID_Event_kbd_flags; -static jfieldID FID_Event_mouse_x; -static jfieldID FID_Event_mouse_y; -static jfieldID FID_Event_mouse_relative; -static jfieldID FID_ScummVM_nativeScummVM; -static jmethodID MID_Object_wait; - -JNIEnv *JNU_GetEnv() { - JNIEnv *env = 0; - - jint res = cached_jvm->GetEnv((void **)&env, JNI_VERSION_1_2); - - if (res != JNI_OK) { - LOGE("GetEnv() failed: %d", res); - abort(); - } - - return env; -} - -static void JNU_ThrowByName(JNIEnv *env, const char *name, const char *msg) { - jclass cls = env->FindClass(name); - - // if cls is 0, an exception has already been thrown - if (cls != 0) - env->ThrowNew(cls, msg); - - env->DeleteLocalRef(cls); -} - // floating point. use sparingly template static inline T scalef(T in, float numerator, float denominator) { return static_cast(in) * numerator / denominator; } -static inline GLfixed xdiv(int numerator, int denominator) { - assert(numerator < (1 << 16)); - return (numerator << 16) / denominator; -} - -#ifdef DYNAMIC_MODULES -class AndroidPluginProvider : public POSIXPluginProvider { -protected: - virtual void addCustomDirectories(Common::FSList &dirs) const; -}; -#endif - -class OSystem_Android : public BaseBackend, public PaletteManager { -private: - // back pointer to (java) peer instance - jobject _back_ptr; - - jmethodID MID_displayMessageOnOSD; - jmethodID MID_setWindowCaption; - jmethodID MID_initBackend; - jmethodID MID_audioSampleRate; - jmethodID MID_showVirtualKeyboard; - jmethodID MID_getSysArchives; - jmethodID MID_getPluginDirectories; - jmethodID MID_setupScummVMSurface; - jmethodID MID_destroyScummVMSurface; - jmethodID MID_swapBuffers; - - int _screen_changeid; - int _egl_surface_width; - int _egl_surface_height; - - bool _force_redraw; - - // Game layer - GLESPaletteTexture *_game_texture; - int _shake_offset; - Common::Rect _focus_rect; - - // Overlay layer - GLES4444Texture *_overlay_texture; - bool _show_overlay; - - // Mouse layer - GLESPaletteATexture *_mouse_texture; - Common::Point _mouse_hotspot; - int _mouse_targetscale; - bool _show_mouse; - bool _use_mouse_palette; - - Common::Queue _event_queue; - MutexRef _event_queue_lock; - - bool _timer_thread_exit; - pthread_t _timer_thread; - static void *timerThreadFunc(void *arg); - - bool _enable_zoning; - bool _virtkeybd_on; - - Common::SaveFileManager *_savefile; - Audio::MixerImpl *_mixer; - Common::TimerManager *_timer; - FilesystemFactory *_fsFactory; - Common::Archive *_asset_archive; - timeval _startTime; - - void setupScummVMSurface(); - void destroyScummVMSurface(); - void setupKeymapper(); - void _setCursorPalette(const byte *colors, uint start, uint num); - -public: - OSystem_Android(jobject am); - virtual ~OSystem_Android(); - bool initJavaHooks(JNIEnv *env, jobject self); - - 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); - virtual bool getFeatureState(Feature f); - virtual const GraphicsMode *getSupportedGraphicsModes() const; - virtual int getDefaultGraphicsMode() const; - bool setGraphicsMode(const char *name); - virtual bool setGraphicsMode(int mode); - virtual int getGraphicsMode() const; - virtual void initSize(uint width, uint height, - const Graphics::PixelFormat *format); - - virtual int getScreenChangeID() const { - return _screen_changeid; - } - - virtual int16 getHeight(); - virtual int16 getWidth(); - - virtual PaletteManager *getPaletteManager() { - return this; - } - -protected: - // PaletteManager API - virtual void setPalette(const byte *colors, uint start, uint num); - virtual void grabPalette(byte *colors, uint start, uint num); - -public: - virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h); - virtual void updateScreen(); - virtual Graphics::Surface *lockScreen(); - virtual void unlockScreen(); - virtual void setShakePos(int shakeOffset); - virtual void fillScreen(uint32 col); - virtual void setFocusRectangle(const Common::Rect& rect); - virtual void clearFocusRectangle(); - - virtual void showOverlay(); - virtual void hideOverlay(); - virtual void clearOverlay(); - virtual void grabOverlay(OverlayColor *buf, int pitch); - virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); - virtual int16 getOverlayHeight(); - virtual int16 getOverlayWidth(); - - // RGBA 4444 - virtual Graphics::PixelFormat getOverlayFormat() const { - Graphics::PixelFormat format; - - format.bytesPerPixel = 2; - format.rLoss = 8 - 4; - format.gLoss = 8 - 4; - format.bLoss = 8 - 4; - format.aLoss = 8 - 4; - format.rShift = 3 * 4; - format.gShift = 2 * 4; - format.bShift = 1 * 4; - format.aShift = 0 * 4; - - return format; - } - - virtual bool showMouse(bool visible); - - virtual void warpMouse(int x, int y); - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format); - virtual void setCursorPalette(const byte *colors, uint start, uint num); - virtual void disableCursorPalette(bool disable); - - virtual bool pollEvent(Common::Event &event); - void pushEvent(const Common::Event& event); - virtual uint32 getMillis(); - virtual void delayMillis(uint msecs); - - virtual MutexRef createMutex(void); - virtual void lockMutex(MutexRef mutex); - virtual void unlockMutex(MutexRef mutex); - virtual void deleteMutex(MutexRef mutex); - - virtual void quit(); - - virtual void setWindowCaption(const char *caption); - virtual void displayMessageOnOSD(const char *msg); - virtual void showVirtualKeyboard(bool enable); - - virtual Common::SaveFileManager *getSavefileManager(); - virtual Audio::Mixer *getMixer(); - virtual void getTimeAndDate(TimeDate &t) const; - virtual Common::TimerManager *getTimerManager(); - virtual FilesystemFactory *getFilesystemFactory(); - virtual void logMessage(LogMessageType::Type type, const char *message); - virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); -}; +OSystem_Android *g_sys = 0; OSystem_Android::OSystem_Android(jobject am) : _back_ptr(0), @@ -357,6 +130,7 @@ OSystem_Android::~OSystem_Android() { destroyScummVMSurface(); JNIEnv *env = JNU_GetEnv(); + // see below //env->DeleteWeakGlobalRef(_back_ptr); env->DeleteGlobalRef(_back_ptr); @@ -369,14 +143,9 @@ OSystem_Android::~OSystem_Android() { deleteMutex(_event_queue_lock); } -OSystem_Android *OSystem_Android::fromJavaObject(JNIEnv *env, jobject obj) { - jlong peer = env->GetLongField(obj, FID_ScummVM_nativeScummVM); - return (OSystem_Android *)peer; -} - bool OSystem_Android::initJavaHooks(JNIEnv *env, jobject self) { // weak global ref to allow class to be unloaded - // ... except dalvik doesn't implement NewWeakGlobalRef (yet) + // ... except dalvik implements NewWeakGlobalRef only on froyo //_back_ptr = env->NewWeakGlobalRef(self); _back_ptr = env->NewGlobalRef(self); @@ -404,91 +173,11 @@ bool OSystem_Android::initJavaHooks(JNIEnv *env, jobject self) { return true; } -static void ScummVM_create(JNIEnv *env, jobject self, jobject am) { - OSystem_Android *cpp_obj = new OSystem_Android(am); - - // Exception already thrown by initJavaHooks? - if (!cpp_obj->initJavaHooks(env, self)) - return; - - env->SetLongField(self, FID_ScummVM_nativeScummVM, (jlong)cpp_obj); - -#ifdef DYNAMIC_MODULES - PluginManager::instance().addPluginProvider(new AndroidPluginProvider()); -#endif -} - -static void ScummVM_nativeDestroy(JNIEnv *env, jobject self) { - OSystem_Android *cpp_obj = OSystem_Android::fromJavaObject(env, self); - delete cpp_obj; -} - -static void ScummVM_audioMixCallback(JNIEnv *env, jobject self, - jbyteArray jbuf) { - OSystem_Android *cpp_obj = OSystem_Android::fromJavaObject(env, self); - jsize len = env->GetArrayLength(jbuf); - jbyte *buf = env->GetByteArrayElements(jbuf, 0); - - if (buf == 0) { - warning("Unable to get Java audio byte array. Skipping"); - return; - } - - Audio::MixerImpl *mixer = - static_cast(cpp_obj->getMixer()); - assert(mixer); - mixer->mixCallback(reinterpret_cast(buf), len); - - env->ReleaseByteArrayElements(jbuf, buf, 0); -} - -static void ScummVM_setConfManInt(JNIEnv *env, jclass cls, - jstring key_obj, jint value) { - ENTER("%p, %d", key_obj, (int)value); - - const char *key = env->GetStringUTFChars(key_obj, 0); - - if (key == 0) - return; - - ConfMan.setInt(key, value); - - env->ReleaseStringUTFChars(key_obj, key); -} - -static void ScummVM_setConfManString(JNIEnv *env, jclass cls, jstring key_obj, - jstring value_obj) { - ENTER("%p, %p", key_obj, value_obj); - - const char *key = env->GetStringUTFChars(key_obj, 0); - - if (key == 0) - return; - - const char *value = env->GetStringUTFChars(value_obj, 0); - - if (value == 0) { - env->ReleaseStringUTFChars(key_obj, key); - return; - } - - ConfMan.set(key, value); - - env->ReleaseStringUTFChars(value_obj, value); - env->ReleaseStringUTFChars(key_obj, key); -} - void *OSystem_Android::timerThreadFunc(void *arg) { OSystem_Android *system = (OSystem_Android *)arg; DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timer); - JNIEnv *env = 0; - jint res = cached_jvm->AttachCurrentThread(&env, 0); - - if (res != JNI_OK) { - LOGE("AttachCurrentThread() failed: %d", res); - abort(); - } + JNU_AttachThread(); struct timespec tv; tv.tv_sec = 0; @@ -499,12 +188,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { nanosleep(&tv, 0); } - res = cached_jvm->DetachCurrentThread(); - - if (res != JNI_OK) { - LOGE("DetachCurrentThread() failed: %d", res); - abort(); - } + JNU_DetachThread(); return 0; } @@ -627,430 +311,6 @@ bool OSystem_Android::getFeatureState(Feature f) { } } -const OSystem::GraphicsMode *OSystem_Android::getSupportedGraphicsModes() const { - static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { - { "default", "Default", 1 }, - { 0, 0, 0 }, - }; - - return s_supportedGraphicsModes; -} - - -int OSystem_Android::getDefaultGraphicsMode() const { - return 1; -} - -bool OSystem_Android::setGraphicsMode(const char *mode) { - ENTER("%s", mode); - return true; -} - -bool OSystem_Android::setGraphicsMode(int mode) { - ENTER("%d", mode); - return true; -} - -int OSystem_Android::getGraphicsMode() const { - return 1; -} - -void OSystem_Android::setupScummVMSurface() { - ENTER(); - - JNIEnv *env = JNU_GetEnv(); - env->CallVoidMethod(_back_ptr, MID_setupScummVMSurface); - - if (env->ExceptionCheck()) - return; - - // EGL set up with a new surface. Initialise OpenGLES context. - GLESTexture::initGLExtensions(); - - // Turn off anything that looks like 3D ;) - GLCALL(glDisable(GL_CULL_FACE)); - GLCALL(glDisable(GL_DEPTH_TEST)); - GLCALL(glDisable(GL_LIGHTING)); - GLCALL(glDisable(GL_FOG)); - GLCALL(glDisable(GL_DITHER)); - - GLCALL(glShadeModel(GL_FLAT)); - GLCALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)); - - GLCALL(glEnable(GL_BLEND)); - GLCALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - - GLCALL(glEnableClientState(GL_VERTEX_ARRAY)); - GLCALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - - GLCALL(glEnable(GL_TEXTURE_2D)); - - if (!_game_texture) - _game_texture = new GLESPaletteTexture(); - else - _game_texture->reinitGL(); - - if (!_overlay_texture) - _overlay_texture = new GLES4444Texture(); - else - _overlay_texture->reinitGL(); - - if (!_mouse_texture) - _mouse_texture = new GLESPaletteATexture(); - else - _mouse_texture->reinitGL(); - - GLCALL(glViewport(0, 0, _egl_surface_width, _egl_surface_height)); - - GLCALL(glMatrixMode(GL_PROJECTION)); - GLCALL(glLoadIdentity()); - GLCALL(glOrthof(0, _egl_surface_width, _egl_surface_height, 0, -1, 1)); - GLCALL(glMatrixMode(GL_MODELVIEW)); - GLCALL(glLoadIdentity()); - - clearFocusRectangle(); -} - -void OSystem_Android::destroyScummVMSurface() { - JNIEnv *env = JNU_GetEnv(); - env->CallVoidMethod(_back_ptr, MID_destroyScummVMSurface); - // Can't use OpenGLES functions after this -} - -void OSystem_Android::initSize(uint width, uint height, - const Graphics::PixelFormat *format) { - ENTER("%d, %d, %p", width, height, format); - - _game_texture->allocBuffer(width, height); - - // Cap at 320x200 or the ScummVM themes abort :/ - GLuint overlay_width = MIN(_egl_surface_width, 320); - GLuint overlay_height = MIN(_egl_surface_height, 200); - _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 however, so just take a guess at the desired - // size (it's small). - _mouse_texture->allocBuffer(20, 20); -} - -int16 OSystem_Android::getHeight() { - return _game_texture->height(); -} - -int16 OSystem_Android::getWidth() { - return _game_texture->width(); -} - -void OSystem_Android::setPalette(const byte *colors, uint start, uint num) { - ENTER("%p, %u, %u", colors, start, num); - - if (!_use_mouse_palette) - _setCursorPalette(colors, start, num); - - memcpy(_game_texture->palette() + start * 3, colors, num * 3); -} - -void OSystem_Android::grabPalette(byte *colors, uint start, uint num) { - ENTER("%p, %u, %u", colors, start, num); - memcpy(colors, _game_texture->palette_const() + start * 3, num * 3); -} - -void OSystem_Android::copyRectToScreen(const byte *buf, int pitch, - int x, int y, int w, int h) { - ENTER("%p, %d, %d, %d, %d, %d", buf, pitch, x, y, w, h); - - _game_texture->updateBuffer(x, y, w, h, buf, pitch); -} - -void OSystem_Android::updateScreen() { - //ENTER(); - - if (!_force_redraw && - !_game_texture->dirty() && - !_overlay_texture->dirty() && - !_mouse_texture->dirty()) - return; - - _force_redraw = false; - - GLCALL(glPushMatrix()); - - 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. - GLCALL(glClearColorx(0, 0, 0, 1 << 16)); - GLCALL(glClear(GL_COLOR_BUFFER_BIT)); - - // Move everything up by _shake_offset (game) pixels - GLCALL(glTranslatex(0, -_shake_offset << 16, 0)); - } - - if (_focus_rect.isEmpty()) { - _game_texture->drawTexture(0, 0, - _egl_surface_width, _egl_surface_height); - } else { - GLCALL(glPushMatrix()); - GLCALL(glScalex(xdiv(_egl_surface_width, _focus_rect.width()), - xdiv(_egl_surface_height, _focus_rect.height()), - 1 << 16)); - GLCALL(glTranslatex(-_focus_rect.left << 16, - -_focus_rect.top << 16, 0)); - GLCALL(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); - GLCALL(glPopMatrix()); - } - - int cs = _mouse_targetscale; - - if (_show_overlay) { - // ugly, but the modern theme sets a wacko factor, only god knows why - cs = 1; - - GLCALL(_overlay_texture->drawTexture(0, 0, - _egl_surface_width, - _egl_surface_height)); - } - - if (_show_mouse) { - GLCALL(glPushMatrix()); - - // Scale up ScummVM -> OpenGL (pixel) coordinates - int texwidth, texheight; - - if (_show_overlay) { - texwidth = getOverlayWidth(); - texheight = getOverlayHeight(); - } else { - texwidth = getWidth(); - texheight = getHeight(); - } - - GLCALL(glScalex(xdiv(_egl_surface_width, texwidth), - xdiv(_egl_surface_height, texheight), - 1 << 16)); - - GLCALL(glTranslatex((-_mouse_hotspot.x * cs) << 16, - (-_mouse_hotspot.y * cs) << 16, - 0)); - - // Note the extra half texel to position the mouse in - // the middle of the x,y square: - const Common::Point& mouse = getEventManager()->getMousePos(); - GLCALL(glTranslatex((mouse.x << 16) | 1 << 15, - (mouse.y << 16) | 1 << 15, 0)); - - GLCALL(glScalex(cs << 16, cs << 16, 1 << 16)); - - _mouse_texture->drawTexture(); - - GLCALL(glPopMatrix()); - } - - GLCALL(glPopMatrix()); - - JNIEnv *env = JNU_GetEnv(); - if (!env->CallBooleanMethod(_back_ptr, MID_swapBuffers)) { - // Context lost -> need to reinit GL - destroyScummVMSurface(); - setupScummVMSurface(); - } -} - -Graphics::Surface *OSystem_Android::lockScreen() { - ENTER(); - - Graphics::Surface *surface = _game_texture->surface(); - assert(surface->pixels); - - return surface; -} - -void OSystem_Android::unlockScreen() { - ENTER(); - - assert(_game_texture->dirty()); -} - -void OSystem_Android::setShakePos(int shake_offset) { - ENTER("%d", shake_offset); - - if (_shake_offset != shake_offset) { - _shake_offset = shake_offset; - _force_redraw = true; - } -} - -void OSystem_Android::fillScreen(uint32 col) { - ENTER("%u", col); - - assert(col < 256); - _game_texture->fillBuffer(col); -} - -void OSystem_Android::setFocusRectangle(const Common::Rect& rect) { - ENTER("%d, %d, %d, %d", rect.left, rect.top, rect.right, rect.bottom); - - if (_enable_zoning) { - _focus_rect = rect; - _force_redraw = true; - } -} - -void OSystem_Android::clearFocusRectangle() { - ENTER(); - - if (_enable_zoning) { - _focus_rect = Common::Rect(); - _force_redraw = true; - } -} - -void OSystem_Android::showOverlay() { - ENTER(); - - _show_overlay = true; - _force_redraw = true; -} - -void OSystem_Android::hideOverlay() { - ENTER(); - - _show_overlay = false; - _force_redraw = true; -} - -void OSystem_Android::clearOverlay() { - ENTER(); - - _overlay_texture->fillBuffer(0); - - // Shouldn't need this, but works around a 'blank screen' bug on Nexus1 - updateScreen(); -} - -void OSystem_Android::grabOverlay(OverlayColor *buf, int pitch) { - ENTER("%p, %d", buf, pitch); - - // We support overlay alpha blending, so the pixel data here - // shouldn't actually be used. Let's fill it with zeros, I'm sure - // it will be fine... - const Graphics::Surface *surface = _overlay_texture->surface_const(); - assert(surface->bytesPerPixel == sizeof(buf[0])); - - int h = surface->h; - - do { - memset(buf, 0, surface->w * sizeof(buf[0])); - - // This 'pitch' is pixels not bytes - buf += pitch; - } while (--h); -} - -void OSystem_Android::copyRectToOverlay(const OverlayColor *buf, int pitch, - int x, int y, int w, int h) { - ENTER("%p, %d, %d, %d, %d, %d", buf, pitch, x, y, w, h); - - const Graphics::Surface *surface = _overlay_texture->surface_const(); - assert(surface->bytesPerPixel == sizeof(buf[0])); - - // This 'pitch' is pixels not bytes - _overlay_texture->updateBuffer(x, y, w, h, buf, pitch * sizeof(buf[0])); - - // Shouldn't need this, but works around a 'blank screen' bug on Nexus1? - updateScreen(); -} - -int16 OSystem_Android::getOverlayHeight() { - return _overlay_texture->height(); -} - -int16 OSystem_Android::getOverlayWidth() { - return _overlay_texture->width(); -} - -bool OSystem_Android::showMouse(bool visible) { - ENTER("%d", visible); - - _show_mouse = visible; - - return true; -} - -void OSystem_Android::warpMouse(int x, int y) { - ENTER("%d, %d", x, y); - - // We use only the eventmanager's idea of the current mouse - // position, so there is nothing extra to do here. -} - -void OSystem_Android::setMouseCursor(const byte *buf, uint w, uint h, - int hotspotX, int hotspotY, - uint32 keycolor, int cursorTargetScale, - const Graphics::PixelFormat *format) { - ENTER("%p, %u, %u, %d, %d, %u, %d, %p", buf, w, h, hotspotX, hotspotY, - keycolor, cursorTargetScale, format); - - assert(keycolor < 256); - - _mouse_texture->allocBuffer(w, h); - - // Update palette alpha based on keycolor - byte *palette = _mouse_texture->palette(); - int i = 256; - - do { - palette[3] = 0xff; - palette += 4; - } while (--i); - - palette = _mouse_texture->palette(); - palette[keycolor * 4 + 3] = 0x00; - - _mouse_texture->updateBuffer(0, 0, w, h, buf, w); - - _mouse_hotspot = Common::Point(hotspotX, hotspotY); - _mouse_targetscale = cursorTargetScale; -} - -void OSystem_Android::_setCursorPalette(const byte *colors, - uint start, uint num) { - byte *palette = _mouse_texture->palette() + start * 4; - - do { - for (int i = 0; i < 3; ++i) - palette[i] = colors[i]; - - // Leave alpha untouched to preserve keycolor - - palette += 4; - colors += 3; - } while (--num); -} - -void OSystem_Android::setCursorPalette(const byte *colors, - uint start, uint num) { - ENTER("%p, %u, %u", colors, start, num); - - _setCursorPalette(colors, start, num); - _use_mouse_palette = true; -} - -void OSystem_Android::disableCursorPalette(bool disable) { - ENTER("%d", disable); - - _use_mouse_palette = !disable; -} - void OSystem_Android::setupKeymapper() { #ifdef ENABLE_KEYMAPPER using namespace Common; @@ -1168,52 +428,6 @@ void OSystem_Android::pushEvent(const Common::Event& event) { unlockMutex(_event_queue_lock); } -static void ScummVM_pushEvent(JNIEnv *env, jobject self, jobject java_event) { - OSystem_Android *cpp_obj = OSystem_Android::fromJavaObject(env, self); - - Common::Event event; - event.type = (Common::EventType)env->GetIntField(java_event, - FID_Event_type); - - event.synthetic = - env->GetBooleanField(java_event, FID_Event_synthetic); - - switch (event.type) { - case Common::EVENT_KEYDOWN: - case Common::EVENT_KEYUP: - event.kbd.keycode = (Common::KeyCode)env->GetIntField( - java_event, FID_Event_kbd_keycode); - event.kbd.ascii = static_cast(env->GetIntField( - java_event, FID_Event_kbd_ascii)); - event.kbd.flags = static_cast(env->GetIntField( - java_event, FID_Event_kbd_flags)); - break; - case Common::EVENT_MOUSEMOVE: - case Common::EVENT_LBUTTONDOWN: - case Common::EVENT_LBUTTONUP: - case Common::EVENT_RBUTTONDOWN: - case Common::EVENT_RBUTTONUP: - case Common::EVENT_WHEELUP: - case Common::EVENT_WHEELDOWN: - case Common::EVENT_MBUTTONDOWN: - case Common::EVENT_MBUTTONUP: - event.mouse.x = - env->GetIntField(java_event, FID_Event_mouse_x); - event.mouse.y = - env->GetIntField(java_event, FID_Event_mouse_y); - // This is a terrible hack. We stash "relativeness" - // in the kbd.flags field until pollEvent() can work - // it out. - event.kbd.flags = env->GetBooleanField( - java_event, FID_Event_mouse_relative) ? 1 : 0; - break; - default: - break; - } - - cpp_obj->pushEvent(event); -} - uint32 OSystem_Android::getMillis() { timeval curTime; @@ -1401,177 +615,11 @@ void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) } } -static jint ScummVM_scummVMMain(JNIEnv *env, jobject self, jobjectArray args) { - OSystem_Android *cpp_obj = OSystem_Android::fromJavaObject(env, self); - - const int MAX_NARGS = 32; - int res = -1; - - int argc = env->GetArrayLength(args); - if (argc > MAX_NARGS) { - JNU_ThrowByName(env, "java/lang/IllegalArgumentException", - "too many arguments"); - return 0; - } - - char *argv[MAX_NARGS]; - - // note use in cleanup loop below - int nargs; - - for (nargs = 0; nargs < argc; ++nargs) { - jstring arg = (jstring)env->GetObjectArrayElement(args, nargs); - - if (arg == 0) { - argv[nargs] = 0; - } else { - const char *cstr = env->GetStringUTFChars(arg, 0); - - argv[nargs] = const_cast(cstr); - - // exception already thrown? - if (cstr == 0) - goto cleanup; - } - - env->DeleteLocalRef(arg); - } - - g_system = cpp_obj; - assert(g_system); - - LOGI("Entering scummvm_main with %d args", argc); - - res = scummvm_main(argc, argv); - - LOGI("Exiting scummvm_main"); - - g_system->quit(); - -cleanup: - nargs--; - - for (int i = 0; i < nargs; ++i) { - if (argv[i] == 0) - continue; - - jstring arg = (jstring)env->GetObjectArrayElement(args, nargs); - - // Exception already thrown? - if (arg == 0) - return res; - - env->ReleaseStringUTFChars(arg, argv[i]); - env->DeleteLocalRef(arg); - } - - return res; -} - #ifdef DYNAMIC_MODULES void AndroidPluginProvider::addCustomDirectories(Common::FSList &dirs) const { - OSystem_Android *g_system_android = (OSystem_Android *)g_system; - g_system_android->addPluginDirectories(dirs); + g_sys->addPluginDirectories(dirs); } #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 }, - { "nativeDestroy", "()V", - (void *)ScummVM_nativeDestroy }, - { "scummVMMain", "([Ljava/lang/String;)I", - (void *)ScummVM_scummVMMain }, - { "pushEvent", "(Lorg/inodes/gus/scummvm/Event;)V", - (void *)ScummVM_pushEvent }, - { "audioMixCallback", "([B)V", - (void *)ScummVM_audioMixCallback }, - { "setConfMan", "(Ljava/lang/String;I)V", - (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 -JNI_OnLoad(JavaVM *jvm, void *reserved) { - cached_jvm = jvm; - - JNIEnv *env; - - if (jvm->GetEnv((void **)&env, JNI_VERSION_1_2)) - return JNI_ERR; - - jclass cls = env->FindClass("org/inodes/gus/scummvm/ScummVM"); - if (cls == 0) - return JNI_ERR; - - if (env->RegisterNatives(cls, gMethods, ARRAYSIZE(gMethods)) < 0) - return JNI_ERR; - - FID_ScummVM_nativeScummVM = env->GetFieldID(cls, "nativeScummVM", "J"); - if (FID_ScummVM_nativeScummVM == 0) - return JNI_ERR; - - jclass event = env->FindClass("org/inodes/gus/scummvm/Event"); - if (event == 0) - return JNI_ERR; - - FID_Event_type = env->GetFieldID(event, "type", "I"); - if (FID_Event_type == 0) - return JNI_ERR; - - FID_Event_synthetic = env->GetFieldID(event, "synthetic", "Z"); - if (FID_Event_synthetic == 0) - return JNI_ERR; - - FID_Event_kbd_keycode = env->GetFieldID(event, "kbd_keycode", "I"); - if (FID_Event_kbd_keycode == 0) - return JNI_ERR; - - FID_Event_kbd_ascii = env->GetFieldID(event, "kbd_ascii", "I"); - if (FID_Event_kbd_ascii == 0) - return JNI_ERR; - - FID_Event_kbd_flags = env->GetFieldID(event, "kbd_flags", "I"); - if (FID_Event_kbd_flags == 0) - return JNI_ERR; - - FID_Event_mouse_x = env->GetFieldID(event, "mouse_x", "I"); - if (FID_Event_mouse_x == 0) - return JNI_ERR; - - FID_Event_mouse_y = env->GetFieldID(event, "mouse_y", "I"); - if (FID_Event_mouse_y == 0) - return JNI_ERR; - - FID_Event_mouse_relative = env->GetFieldID(event, "mouse_relative", "Z"); - if (FID_Event_mouse_relative == 0) - return JNI_ERR; - - cls = env->FindClass("java/lang/Object"); - if (cls == 0) - return JNI_ERR; - - MID_Object_wait = env->GetMethodID(cls, "wait", "()V"); - if (MID_Object_wait == 0) - return JNI_ERR; - - return JNI_VERSION_1_2; -} - #endif + -- cgit v1.2.3 From c4706733d45de09803b7cd40c3536a4e04b4f767 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 20 Feb 2011 20:46:17 +0100 Subject: ANDROID: Move the global back reference to jni.cpp --- backends/platform/android/android.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index a0a53474e8..f2c9a7407d 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -101,7 +101,6 @@ static inline T scalef(T in, float numerator, float denominator) { OSystem_Android *g_sys = 0; OSystem_Android::OSystem_Android(jobject am) : - _back_ptr(0), _screen_changeid(0), _force_redraw(false), _game_texture(0), @@ -129,11 +128,6 @@ OSystem_Android::~OSystem_Android() { destroyScummVMSurface(); - JNIEnv *env = JNU_GetEnv(); - // see below - //env->DeleteWeakGlobalRef(_back_ptr); - env->DeleteGlobalRef(_back_ptr); - delete _savefile; delete _mixer; delete _timer; @@ -143,13 +137,8 @@ OSystem_Android::~OSystem_Android() { deleteMutex(_event_queue_lock); } -bool OSystem_Android::initJavaHooks(JNIEnv *env, jobject self) { - // weak global ref to allow class to be unloaded - // ... except dalvik implements NewWeakGlobalRef only on froyo - //_back_ptr = env->NewWeakGlobalRef(self); - _back_ptr = env->NewGlobalRef(self); - - jclass cls = env->GetObjectClass(_back_ptr); +bool OSystem_Android::initJavaHooks(JNIEnv *env) { + jclass cls = env->GetObjectClass(back_ptr); #define FIND_METHOD(name, signature) do { \ MID_ ## name = env->GetMethodID(cls, #name, signature); \ @@ -213,7 +202,7 @@ void OSystem_Android::initBackend() { gettimeofday(&_startTime, 0); - jint sample_rate = env->CallIntMethod(_back_ptr, MID_audioSampleRate); + jint sample_rate = env->CallIntMethod(back_ptr, MID_audioSampleRate); if (env->ExceptionCheck()) { warning("Error finding audio sample rate - assuming 11025HZ"); @@ -226,7 +215,7 @@ void OSystem_Android::initBackend() { _mixer = new Audio::MixerImpl(this, sample_rate); _mixer->setReady(true); - env->CallVoidMethod(_back_ptr, MID_initBackend); + env->CallVoidMethod(back_ptr, MID_initBackend); if (env->ExceptionCheck()) { error("Error in Java initBackend"); @@ -249,7 +238,7 @@ void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { JNIEnv *env = JNU_GetEnv(); jobjectArray array = - (jobjectArray)env->CallObjectMethod(_back_ptr, MID_getPluginDirectories); + (jobjectArray)env->CallObjectMethod(back_ptr, MID_getPluginDirectories); if (env->ExceptionCheck()) { warning("Error finding plugin directories"); @@ -490,7 +479,7 @@ void OSystem_Android::setWindowCaption(const char *caption) { JNIEnv *env = JNU_GetEnv(); jstring java_caption = env->NewStringUTF(caption); - env->CallVoidMethod(_back_ptr, MID_setWindowCaption, java_caption); + env->CallVoidMethod(back_ptr, MID_setWindowCaption, java_caption); if (env->ExceptionCheck()) { warning("Failed to set window caption"); @@ -508,7 +497,7 @@ void OSystem_Android::displayMessageOnOSD(const char *msg) { JNIEnv *env = JNU_GetEnv(); jstring java_msg = env->NewStringUTF(msg); - env->CallVoidMethod(_back_ptr, MID_displayMessageOnOSD, java_msg); + env->CallVoidMethod(back_ptr, MID_displayMessageOnOSD, java_msg); if (env->ExceptionCheck()) { warning("Failed to display OSD message"); @@ -525,7 +514,7 @@ void OSystem_Android::showVirtualKeyboard(bool enable) { JNIEnv *env = JNU_GetEnv(); - env->CallVoidMethod(_back_ptr, MID_showVirtualKeyboard, enable); + env->CallVoidMethod(back_ptr, MID_showVirtualKeyboard, enable); if (env->ExceptionCheck()) { error("Error trying to show virtual keyboard"); @@ -574,7 +563,7 @@ void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s, JNIEnv *env = JNU_GetEnv(); jobjectArray array = - (jobjectArray)env->CallObjectMethod(_back_ptr, MID_getSysArchives); + (jobjectArray)env->CallObjectMethod(back_ptr, MID_getSysArchives); if (env->ExceptionCheck()) { warning("Error finding system archive path"); -- cgit v1.2.3 From f80d993860257a8e74936bc74eb99bda2fbfcaa4 Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 23 Feb 2011 22:44:33 +0100 Subject: ANDROID: Wrap JNI code in a class --- backends/platform/android/android.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index f2c9a7407d..9437bf540c 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -98,8 +98,6 @@ static inline T scalef(T in, float numerator, float denominator) { return static_cast(in) * numerator / denominator; } -OSystem_Android *g_sys = 0; - OSystem_Android::OSystem_Android(jobject am) : _screen_changeid(0), _force_redraw(false), @@ -166,7 +164,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { OSystem_Android *system = (OSystem_Android *)arg; DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timer); - JNU_AttachThread(); + JNI::attachThread(); struct timespec tv; tv.tv_sec = 0; @@ -177,7 +175,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { nanosleep(&tv, 0); } - JNU_DetachThread(); + JNI::detachThread(); return 0; } @@ -185,7 +183,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { void OSystem_Android::initBackend() { ENTER(); - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); ConfMan.setInt("autosave_period", 0); ConfMan.setInt("FM_medium_quality", true); @@ -235,10 +233,10 @@ void OSystem_Android::initBackend() { void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { ENTER(); - JNIEnv *env = JNU_GetEnv(); - + JNIEnv *env = JNI::getEnv(); jobjectArray array = (jobjectArray)env->CallObjectMethod(back_ptr, MID_getPluginDirectories); + if (env->ExceptionCheck()) { warning("Error finding plugin directories"); @@ -477,7 +475,7 @@ void OSystem_Android::quit() { void OSystem_Android::setWindowCaption(const char *caption) { ENTER("%s", caption); - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); jstring java_caption = env->NewStringUTF(caption); env->CallVoidMethod(back_ptr, MID_setWindowCaption, java_caption); @@ -494,9 +492,8 @@ void OSystem_Android::setWindowCaption(const char *caption) { void OSystem_Android::displayMessageOnOSD(const char *msg) { ENTER("%s", msg); - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); jstring java_msg = env->NewStringUTF(msg); - env->CallVoidMethod(back_ptr, MID_displayMessageOnOSD, java_msg); if (env->ExceptionCheck()) { @@ -512,8 +509,7 @@ void OSystem_Android::displayMessageOnOSD(const char *msg) { void OSystem_Android::showVirtualKeyboard(bool enable) { ENTER("%d", enable); - JNIEnv *env = JNU_GetEnv(); - + JNIEnv *env = JNI::getEnv(); env->CallVoidMethod(back_ptr, MID_showVirtualKeyboard, enable); if (env->ExceptionCheck()) { @@ -560,8 +556,7 @@ void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { s.add("ASSET", _asset_archive, priority, false); - JNIEnv *env = JNU_GetEnv(); - + JNIEnv *env = JNI::getEnv(); jobjectArray array = (jobjectArray)env->CallObjectMethod(back_ptr, MID_getSysArchives); @@ -606,7 +601,7 @@ void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) #ifdef DYNAMIC_MODULES void AndroidPluginProvider::addCustomDirectories(Common::FSList &dirs) const { - g_sys->addPluginDirectories(dirs); + ((OSystem_Android *)g_system)->addPluginDirectories(dirs); } #endif -- cgit v1.2.3 From 53b5808d4f16a44779ef5fd8a5c8ca5e262e0379 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 24 Feb 2011 00:45:41 +0100 Subject: ANDROID: Move rest of everything JNI --- backends/platform/android/android.cpp | 162 +++------------------------------- 1 file changed, 14 insertions(+), 148 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 9437bf540c..36399873cd 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -40,8 +40,8 @@ #include "backends/saves/default/default-saves.h" #include "backends/timer/default/default-timer.h" +#include "backends/platform/android/jni.h" #include "backends/platform/android/android.h" -#include "backends/platform/android/asset-archive.h" const char *android_log_tag = "ScummVM"; @@ -98,7 +98,7 @@ static inline T scalef(T in, float numerator, float denominator) { return static_cast(in) * numerator / denominator; } -OSystem_Android::OSystem_Android(jobject am) : +OSystem_Android::OSystem_Android() : _screen_changeid(0), _force_redraw(false), _game_texture(0), @@ -112,7 +112,6 @@ OSystem_Android::OSystem_Android(jobject am) : _mixer(0), _timer(0), _fsFactory(new POSIXFilesystemFactory()), - _asset_archive(new AndroidAssetArchive(am)), _shake_offset(0), _event_queue_lock(createMutex()) { } @@ -124,42 +123,16 @@ OSystem_Android::~OSystem_Android() { delete _overlay_texture; delete _mouse_texture; - destroyScummVMSurface(); + JNI::destroySurface(); delete _savefile; delete _mixer; delete _timer; delete _fsFactory; - delete _asset_archive; deleteMutex(_event_queue_lock); } -bool OSystem_Android::initJavaHooks(JNIEnv *env) { - jclass cls = env->GetObjectClass(back_ptr); - -#define FIND_METHOD(name, signature) do { \ - MID_ ## name = env->GetMethodID(cls, #name, signature); \ - if (MID_ ## name == 0) \ - return false; \ - } while (0) - - FIND_METHOD(setWindowCaption, "(Ljava/lang/String;)V"); - FIND_METHOD(displayMessageOnOSD, "(Ljava/lang/String;)V"); - FIND_METHOD(initBackend, "()V"); - FIND_METHOD(audioSampleRate, "()I"); - FIND_METHOD(showVirtualKeyboard, "(Z)V"); - FIND_METHOD(getSysArchives, "()[Ljava/lang/String;"); - FIND_METHOD(getPluginDirectories, "()[Ljava/lang/String;"); - FIND_METHOD(setupScummVMSurface, "()V"); - FIND_METHOD(destroyScummVMSurface, "()V"); - FIND_METHOD(swapBuffers, "()Z"); - -#undef FIND_METHOD - - return true; -} - void *OSystem_Android::timerThreadFunc(void *arg) { OSystem_Android *system = (OSystem_Android *)arg; DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timer); @@ -183,8 +156,6 @@ void *OSystem_Android::timerThreadFunc(void *arg) { void OSystem_Android::initBackend() { ENTER(); - JNIEnv *env = JNI::getEnv(); - ConfMan.setInt("autosave_period", 0); ConfMan.setInt("FM_medium_quality", true); @@ -200,74 +171,23 @@ void OSystem_Android::initBackend() { gettimeofday(&_startTime, 0); - jint sample_rate = env->CallIntMethod(back_ptr, MID_audioSampleRate); - if (env->ExceptionCheck()) { - warning("Error finding audio sample rate - assuming 11025HZ"); - - env->ExceptionDescribe(); - env->ExceptionClear(); - - sample_rate = 11025; - } - - _mixer = new Audio::MixerImpl(this, sample_rate); + _mixer = new Audio::MixerImpl(this, JNI::getAudioSampleRate()); _mixer->setReady(true); - env->CallVoidMethod(back_ptr, MID_initBackend); - - if (env->ExceptionCheck()) { - error("Error in Java initBackend"); - - env->ExceptionDescribe(); - env->ExceptionClear(); - } + JNI::initBackend(); _timer_thread_exit = false; pthread_create(&_timer_thread, 0, timerThreadFunc, this); OSystem::initBackend(); - setupScummVMSurface(); + setupSurface(); } void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { ENTER(); - JNIEnv *env = JNI::getEnv(); - jobjectArray array = - (jobjectArray)env->CallObjectMethod(back_ptr, MID_getPluginDirectories); - - if (env->ExceptionCheck()) { - warning("Error finding plugin directories"); - - env->ExceptionDescribe(); - env->ExceptionClear(); - - return; - } - - jsize size = env->GetArrayLength(array); - for (jsize i = 0; i < size; ++i) { - jstring path_obj = (jstring)env->GetObjectArrayElement(array, i); - - if (path_obj == 0) - continue; - - const char *path = env->GetStringUTFChars(path_obj, 0); - if (path == 0) { - warning("Error getting string characters from plugin directory"); - - env->ExceptionClear(); - env->DeleteLocalRef(path_obj); - - continue; - } - - dirs.push_back(Common::FSNode(path)); - - env->ReleaseStringUTFChars(path_obj, path); - env->DeleteLocalRef(path_obj); - } + JNI::getPluginDirectories(dirs); } bool OSystem_Android::hasFeature(Feature f) { @@ -380,8 +300,8 @@ bool OSystem_Android::pollEvent(Common::Event &event) { case Common::EVENT_SCREEN_CHANGED: debug("EVENT_SCREEN_CHANGED"); _screen_changeid++; - destroyScummVMSurface(); - setupScummVMSurface(); + JNI::destroySurface(); + setupSurface(); break; default: break; @@ -475,49 +395,19 @@ void OSystem_Android::quit() { void OSystem_Android::setWindowCaption(const char *caption) { ENTER("%s", caption); - JNIEnv *env = JNI::getEnv(); - jstring java_caption = env->NewStringUTF(caption); - env->CallVoidMethod(back_ptr, MID_setWindowCaption, java_caption); - - if (env->ExceptionCheck()) { - warning("Failed to set window caption"); - - env->ExceptionDescribe(); - env->ExceptionClear(); - } - - env->DeleteLocalRef(java_caption); + JNI::setWindowCaption(caption); } void OSystem_Android::displayMessageOnOSD(const char *msg) { ENTER("%s", msg); - JNIEnv *env = JNI::getEnv(); - jstring java_msg = env->NewStringUTF(msg); - env->CallVoidMethod(back_ptr, MID_displayMessageOnOSD, java_msg); - - if (env->ExceptionCheck()) { - warning("Failed to display OSD message"); - - env->ExceptionDescribe(); - env->ExceptionClear(); - } - - env->DeleteLocalRef(java_msg); + JNI::displayMessageOnOSD(msg); } void OSystem_Android::showVirtualKeyboard(bool enable) { ENTER("%d", enable); - JNIEnv *env = JNI::getEnv(); - env->CallVoidMethod(back_ptr, MID_showVirtualKeyboard, enable); - - if (env->ExceptionCheck()) { - error("Error trying to show virtual keyboard"); - - env->ExceptionDescribe(); - env->ExceptionClear(); - } + JNI::showVirtualKeyboard(enable); } Common::SaveFileManager *OSystem_Android::getSavefileManager() { @@ -554,33 +444,9 @@ FilesystemFactory *OSystem_Android::getFilesystemFactory() { void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { - s.add("ASSET", _asset_archive, priority, false); - - JNIEnv *env = JNI::getEnv(); - jobjectArray array = - (jobjectArray)env->CallObjectMethod(back_ptr, MID_getSysArchives); - - if (env->ExceptionCheck()) { - warning("Error finding system archive path"); - - env->ExceptionDescribe(); - env->ExceptionClear(); + ENTER(""); - return; - } - - jsize size = env->GetArrayLength(array); - for (jsize i = 0; i < size; ++i) { - jstring path_obj = (jstring)env->GetObjectArrayElement(array, i); - const char *path = env->GetStringUTFChars(path_obj, 0); - - if (path != 0) { - s.addDirectory(path, path, priority); - env->ReleaseStringUTFChars(path_obj, path); - } - - env->DeleteLocalRef(path_obj); - } + JNI::addSysArchivesToSearchSet(s, priority); } void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) { -- cgit v1.2.3 From a636d41ca8c066adfed4fd16d9a2e46de5fab871 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 24 Feb 2011 18:24:27 +0100 Subject: ANDROID: Check thread origin when debugging GL --- backends/platform/android/android.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 36399873cd..4968e4bba1 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -156,6 +156,8 @@ void *OSystem_Android::timerThreadFunc(void *arg) { void OSystem_Android::initBackend() { ENTER(); + _main_thread = pthread_self(); + ConfMan.setInt("autosave_period", 0); ConfMan.setInt("FM_medium_quality", true); @@ -350,6 +352,7 @@ void OSystem_Android::delayMillis(uint msecs) { OSystem::MutexRef OSystem_Android::createMutex() { pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); -- cgit v1.2.3 From 25d895b859af0df8ea6daa85ba6ec5a0acb81f9d Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 26 Feb 2011 14:53:02 +0100 Subject: ANDROID: Rework audio system Move the audio thread to the bright side --- backends/platform/android/android.cpp | 87 ++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 4968e4bba1..08b957999e 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -26,6 +26,7 @@ #if defined(__ANDROID__) #include +#include #include #include @@ -98,7 +99,9 @@ static inline T scalef(T in, float numerator, float denominator) { return static_cast(in) * numerator / denominator; } -OSystem_Android::OSystem_Android() : +OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : + _audio_sample_rate(audio_sample_rate), + _audio_buffer_size(audio_buffer_size), _screen_changeid(0), _force_redraw(false), _game_texture(0), @@ -137,6 +140,10 @@ void *OSystem_Android::timerThreadFunc(void *arg) { OSystem_Android *system = (OSystem_Android *)arg; DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timer); + // renice this thread to boost the audio thread + if (setpriority(PRIO_PROCESS, 0, 19) < 0) + warning("couldn't renice the timer thread"); + JNI::attachThread(); struct timespec tv; @@ -153,6 +160,72 @@ void *OSystem_Android::timerThreadFunc(void *arg) { return 0; } +void *OSystem_Android::audioThreadFunc(void *arg) { + JNI::attachThread(); + + JNI::setAudioPlay(); + + OSystem_Android *system = (OSystem_Android *)arg; + Audio::MixerImpl *mixer = system->_mixer; + + uint buf_size = system->_audio_buffer_size; + + JNIEnv *env = JNI::getEnv(); + + jbyteArray bufa = env->NewByteArray(buf_size); + + byte *buf; + int offset, left, written; + + struct timespec tv; + tv.tv_sec = 0; + tv.tv_nsec = 20 * 1000 * 1000; + + while (!system->_audio_thread_exit) { + buf = (byte *)env->GetPrimitiveArrayCritical(bufa, 0); + assert(buf); + + mixer->mixCallback(buf, buf_size); + + env->ReleasePrimitiveArrayCritical(bufa, buf, 0); + + offset = 0; + left = buf_size; + written = 0; + + while (left > 0) { + written = JNI::writeAudio(env, bufa, offset, left); + + if (written < 0) { + error("AudioTrack error: %d", written); + break; + } + + // buffer full + if (written < left) + nanosleep(&tv, 0); + + offset += written; + left -= written; + } + + if (written < 0) + break; + + // sleep a little, prepare the next buffer, and run into the + // blocking AudioTrack.write + nanosleep(&tv, 0); + } + + JNI::setAudioStop(); + + env->DeleteLocalRef(bufa); + + JNI::detachThread(); + + return 0; +} + void OSystem_Android::initBackend() { ENTER(); @@ -173,7 +246,7 @@ void OSystem_Android::initBackend() { gettimeofday(&_startTime, 0); - _mixer = new Audio::MixerImpl(this, JNI::getAudioSampleRate()); + _mixer = new Audio::MixerImpl(this, _audio_sample_rate); _mixer->setReady(true); JNI::initBackend(); @@ -181,9 +254,16 @@ void OSystem_Android::initBackend() { _timer_thread_exit = false; pthread_create(&_timer_thread, 0, timerThreadFunc, this); + _audio_thread_exit = false; + pthread_create(&_audio_thread, 0, audioThreadFunc, this); + OSystem::initBackend(); setupSurface(); + + // renice this thread to boost the audio thread + if (setpriority(PRIO_PROCESS, 0, 19) < 0) + warning("couldn't renice the main thread"); } void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { @@ -391,6 +471,9 @@ void OSystem_Android::deleteMutex(MutexRef mutex) { void OSystem_Android::quit() { ENTER(); + _audio_thread_exit = true; + pthread_join(_audio_thread, 0); + _timer_thread_exit = true; pthread_join(_timer_thread, 0); } -- cgit v1.2.3 From 0e869a5cf0e455f7cd5ce5c39192f3433b931e97 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 26 Feb 2011 18:44:17 +0100 Subject: ANDROID: Pause the AudioTrack when possible Only works in situations without any registered channels (or all paused) at the mixer (like on the launcher or GMM). CPU usage before (Galaxy Tab): ~5% scummvm ~15% mediaserver After: ~2% scummvm 0% mediaserver ;) --- backends/platform/android/android.cpp | 53 +++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 08b957999e..860ff1f7ee 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -163,8 +163,6 @@ void *OSystem_Android::timerThreadFunc(void *arg) { void *OSystem_Android::audioThreadFunc(void *arg) { JNI::attachThread(); - JNI::setAudioPlay(); - OSystem_Android *system = (OSystem_Android *)arg; Audio::MixerImpl *mixer = system->_mixer; @@ -174,21 +172,60 @@ void *OSystem_Android::audioThreadFunc(void *arg) { jbyteArray bufa = env->NewByteArray(buf_size); + bool paused = true; + byte *buf; int offset, left, written; + int samples; - struct timespec tv; - tv.tv_sec = 0; - tv.tv_nsec = 20 * 1000 * 1000; + struct timespec tv_delay; + tv_delay.tv_sec = 0; + tv_delay.tv_nsec = 20 * 1000 * 1000; + + uint msecs_full = buf_size * 1000 / (mixer->getOutputRate() * 2 * 2); + + struct timespec tv_full; + tv_full.tv_sec = 0; + tv_full.tv_nsec = msecs_full * 1000 * 1000; + + uint silence_count = 0; while (!system->_audio_thread_exit) { buf = (byte *)env->GetPrimitiveArrayCritical(bufa, 0); assert(buf); - mixer->mixCallback(buf, buf_size); + samples = mixer->mixCallback(buf, buf_size); env->ReleasePrimitiveArrayCritical(bufa, buf, 0); + if (samples < 1) { + if (!paused) + silence_count++; + + // only pause after a while to prevent toggle mania + if (silence_count > 32) { + if (!paused) { + LOGD("AudioTrack pause"); + + JNI::setAudioPause(); + paused = true; + } + + nanosleep(&tv_full, 0); + + continue; + } + } + + if (paused) { + LOGD("AudioTrack play"); + + JNI::setAudioPlay(); + paused = false; + + silence_count = 0; + } + offset = 0; left = buf_size; written = 0; @@ -203,7 +240,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { // buffer full if (written < left) - nanosleep(&tv, 0); + nanosleep(&tv_delay, 0); offset += written; left -= written; @@ -214,7 +251,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { // sleep a little, prepare the next buffer, and run into the // blocking AudioTrack.write - nanosleep(&tv, 0); + nanosleep(&tv_delay, 0); } JNI::setAudioStop(); -- cgit v1.2.3 From d4c0501d1fcc8c98d39b2b7ba627cccb29cbc476 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 26 Feb 2011 22:23:17 +0100 Subject: ANDROID: Check audio buffer for silence Most games register a music channel, and when there is no music, they still stream silence (and run through all the Converter::flow code!). Scan the buffer for that to pause the AudioTrack. Ugly, but worth it - reduces CPU usage on many games and hence saves battery life. --- backends/platform/android/android.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 860ff1f7ee..f20cf848d4 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -176,7 +176,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { byte *buf; int offset, left, written; - int samples; + int samples, i; struct timespec tv_delay; tv_delay.tv_sec = 0; @@ -188,6 +188,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { tv_full.tv_sec = 0; tv_full.tv_nsec = msecs_full * 1000 * 1000; + bool silence; uint silence_count = 0; while (!system->_audio_thread_exit) { @@ -196,9 +197,24 @@ void *OSystem_Android::audioThreadFunc(void *arg) { samples = mixer->mixCallback(buf, buf_size); + silence = samples < 1; + + // looks stupid, and it is, but currently there's no way to detect + // silence-only buffers from the mixer + if (!silence) { + silence = true; + + for (i = 0; i < samples; i += 2) + // SID streams constant crap + if (READ_UINT16(buf + i) > 32) { + silence = false; + break; + } + } + env->ReleasePrimitiveArrayCritical(bufa, buf, 0); - if (samples < 1) { + if (silence) { if (!paused) silence_count++; -- cgit v1.2.3 From 72889ee24fc290ba9353084bbf1e1a3fa47a115c Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 27 Feb 2011 11:23:11 +0100 Subject: ANDROID: Remove dead code --- backends/platform/android/android.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index f20cf848d4..62b8b60495 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -285,7 +285,8 @@ void OSystem_Android::initBackend() { _main_thread = pthread_self(); ConfMan.setInt("autosave_period", 0); - ConfMan.setInt("FM_medium_quality", true); + ConfMan.setBool("FM_high_quality", false); + ConfMan.setBool("FM_medium_quality", true); // must happen before creating TimerManager to avoid race in // creating EventManager -- cgit v1.2.3 From 24a332bd22073257ae9ed33dc0549bfde4538f1b Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 27 Feb 2011 11:25:03 +0100 Subject: ANDROID: Prevent AudioTrack unpause on startup --- backends/platform/android/android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 62b8b60495..57e84d07c6 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -189,7 +189,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { tv_full.tv_nsec = msecs_full * 1000 * 1000; bool silence; - uint silence_count = 0; + uint silence_count = 33; while (!system->_audio_thread_exit) { buf = (byte *)env->GetPrimitiveArrayCritical(bufa, 0); -- cgit v1.2.3 From 807971f8af9430ee19f66c7bac7cc9566fccf432 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 27 Feb 2011 20:16:52 +0100 Subject: ANDROID: Don't use warning()/error() in a thread --- backends/platform/android/android.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 57e84d07c6..f886347685 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -142,7 +142,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { // renice this thread to boost the audio thread if (setpriority(PRIO_PROCESS, 0, 19) < 0) - warning("couldn't renice the timer thread"); + LOGW("couldn't renice the timer thread"); JNI::attachThread(); @@ -250,7 +250,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { written = JNI::writeAudio(env, bufa, offset, left); if (written < 0) { - error("AudioTrack error: %d", written); + LOGE("AudioTrack error: %d", written); break; } -- cgit v1.2.3 From 2333a32697cda8f5f73861856889001839f38f25 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 27 Feb 2011 20:13:48 +0100 Subject: ANDROID: Untangle JNI interweaving - make the startup sequence more linear - use SurfaceHolder events - get rid of the surface lock - remove unnecessary JNI calls - make the ScummVM class implement Runnable - cleanup --- backends/platform/android/android.cpp | 44 ++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index f886347685..2af367e903 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -103,6 +103,8 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _audio_sample_rate(audio_sample_rate), _audio_buffer_size(audio_buffer_size), _screen_changeid(0), + _egl_surface_width(0), + _egl_surface_height(0), _force_redraw(false), _game_texture(0), _overlay_texture(0), @@ -126,11 +128,9 @@ OSystem_Android::~OSystem_Android() { delete _overlay_texture; delete _mouse_texture; - JNI::destroySurface(); - delete _savefile; - delete _mixer; delete _timer; + delete _mixer; delete _fsFactory; deleteMutex(_event_queue_lock); @@ -303,21 +303,19 @@ void OSystem_Android::initBackend() { _mixer = new Audio::MixerImpl(this, _audio_sample_rate); _mixer->setReady(true); - JNI::initBackend(); - _timer_thread_exit = false; pthread_create(&_timer_thread, 0, timerThreadFunc, this); _audio_thread_exit = false; pthread_create(&_audio_thread, 0, audioThreadFunc, this); - OSystem::initBackend(); - setupSurface(); // renice this thread to boost the audio thread if (setpriority(PRIO_PROCESS, 0, 19) < 0) warning("couldn't renice the main thread"); + + JNI::setReadyForEvents(true); } void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { @@ -385,6 +383,28 @@ void OSystem_Android::setupKeymapper() { bool OSystem_Android::pollEvent(Common::Event &event) { //ENTER(); + if (pthread_self() == _main_thread) { + if (_screen_changeid != JNI::surface_changeid) { + if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) { + LOGD("initializing surface"); + + JNI::deinitSurface(); + setupSurface(); + + event.type = Common::EVENT_SCREEN_CHANGED; + + return true; + } + + LOGD("deinitialiting surface"); + + _screen_changeid = JNI::surface_changeid; + JNI::deinitSurface(); + + // TODO prevent swapBuffers + } + } + lockMutex(_event_queue_lock); if (_event_queue.empty()) { @@ -433,12 +453,6 @@ bool OSystem_Android::pollEvent(Common::Event &event) { } break; } - case Common::EVENT_SCREEN_CHANGED: - debug("EVENT_SCREEN_CHANGED"); - _screen_changeid++; - JNI::destroySurface(); - setupSurface(); - break; default: break; } @@ -525,11 +539,15 @@ void OSystem_Android::deleteMutex(MutexRef mutex) { void OSystem_Android::quit() { ENTER(); + JNI::setReadyForEvents(false); + _audio_thread_exit = true; pthread_join(_audio_thread, 0); _timer_thread_exit = true; pthread_join(_timer_thread, 0); + + JNI::deinitSurface(); } void OSystem_Android::setWindowCaption(const char *caption) { -- cgit v1.2.3 From bd7e3e9bb20dada6d40143557c473fabd373b5ed Mon Sep 17 00:00:00 2001 From: dhewg Date: Tue, 1 Mar 2011 22:16:10 +0100 Subject: ANDROID: cleanup --- backends/platform/android/android.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 2af367e903..a61f7daee3 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -442,9 +442,12 @@ bool OSystem_Android::pollEvent(Common::Event &event) { } else { // Touchscreen events need to be converted // from device to game coords first. - const GLESTexture *tex = _show_overlay - ? static_cast(_overlay_texture) - : static_cast(_game_texture); + const GLESTexture *tex; + if (_show_overlay) + tex = _overlay_texture; + else + tex = _game_texture; + event.mouse.x = scalef(event.mouse.x, tex->width(), _egl_surface_width); event.mouse.y = scalef(event.mouse.y, tex->height(), -- cgit v1.2.3 From ccfe427eb542235070e8576b4cc47217d92046fd Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 2 Mar 2011 19:48:29 +0100 Subject: ANDROID: Check for a surface in updateScreen() --- backends/platform/android/android.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index a61f7daee3..484f6886ec 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -400,8 +400,6 @@ bool OSystem_Android::pollEvent(Common::Event &event) { _screen_changeid = JNI::surface_changeid; JNI::deinitSurface(); - - // TODO prevent swapBuffers } } -- cgit v1.2.3 From c2d4cce429baa56b5a0962a854ece6163270995f Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 2 Mar 2011 22:26:15 +0100 Subject: ANDROID: On pause, put all threads in a coma Since not every engine respects pauseEngine(), or they're in a state where it simply gets ignored, put all threads in a group coma. Without this, code still kept looping and wasting cpu cycles, while the user might want to do use her/his droid for something else. --- backends/platform/android/android.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 484f6886ec..d4a2253c30 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -151,6 +151,12 @@ void *OSystem_Android::timerThreadFunc(void *arg) { tv.tv_nsec = 100 * 1000 * 1000; // 100ms while (!system->_timer_thread_exit) { + if (JNI::pause) { + LOGD("timer thread going to sleep"); + sem_wait(&JNI::pause_sem); + LOGD("timer thread woke up"); + } + timer->handler(); nanosleep(&tv, 0); } @@ -192,6 +198,12 @@ void *OSystem_Android::audioThreadFunc(void *arg) { uint silence_count = 33; while (!system->_audio_thread_exit) { + if (JNI::pause) { + LOGD("audio thread going to sleep"); + sem_wait(&JNI::pause_sem); + LOGD("audio thread woke up"); + } + buf = (byte *)env->GetPrimitiveArrayCritical(bufa, 0); assert(buf); @@ -401,6 +413,19 @@ bool OSystem_Android::pollEvent(Common::Event &event) { _screen_changeid = JNI::surface_changeid; JNI::deinitSurface(); } + + if (JNI::pause) { + // release some resources + // TODO + // free textures? they're garbled anyway since no engine + // respects EVENT_SCREEN_CHANGED + LOGD("deinitialiting surface"); + JNI::deinitSurface(); + + LOGD("main thread going to sleep"); + sem_wait(&JNI::pause_sem); + LOGD("main thread woke up"); + } } lockMutex(_event_queue_lock); -- cgit v1.2.3 From 2d4a64d18493b142b1899a822202015339733cfa Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 2 Mar 2011 23:00:48 +0100 Subject: ANDROID: Properly release texture resources When calling glDeleteTextures() we need a valid surface. --- backends/platform/android/android.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index d4a2253c30..491e5fbc72 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -124,10 +124,6 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : OSystem_Android::~OSystem_Android() { ENTER(); - delete _game_texture; - delete _overlay_texture; - delete _mouse_texture; - delete _savefile; delete _timer; delete _mixer; @@ -323,6 +319,10 @@ void OSystem_Android::initBackend() { setupSurface(); + _game_texture = new GLESPaletteTexture(); + _overlay_texture = new GLES4444Texture(); + _mouse_texture = new GLESPaletteATexture(); + // renice this thread to boost the audio thread if (setpriority(PRIO_PROCESS, 0, 19) < 0) warning("couldn't renice the main thread"); @@ -400,9 +400,17 @@ bool OSystem_Android::pollEvent(Common::Event &event) { if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) { LOGD("initializing surface"); + _game_texture->release(); + _overlay_texture->release(); + _mouse_texture->release(); + JNI::deinitSurface(); setupSurface(); + _game_texture->reinit(); + _overlay_texture->reinit(); + _mouse_texture->reinit(); + event.type = Common::EVENT_SCREEN_CHANGED; return true; @@ -410,15 +418,20 @@ bool OSystem_Android::pollEvent(Common::Event &event) { LOGD("deinitialiting surface"); + _game_texture->release(); + _overlay_texture->release(); + _mouse_texture->release(); + _screen_changeid = JNI::surface_changeid; JNI::deinitSurface(); } if (JNI::pause) { // release some resources - // TODO - // free textures? they're garbled anyway since no engine - // respects EVENT_SCREEN_CHANGED + _game_texture->release(); + _overlay_texture->release(); + _mouse_texture->release(); + LOGD("deinitialiting surface"); JNI::deinitSurface(); @@ -573,6 +586,10 @@ void OSystem_Android::quit() { _timer_thread_exit = true; pthread_join(_timer_thread, 0); + delete _game_texture; + delete _overlay_texture; + delete _mouse_texture; + JNI::deinitSurface(); } -- cgit v1.2.3 From 1e3c96b3efaea537dfe82b1d535d1d46cc82a8a0 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 3 Mar 2011 11:20:37 +0100 Subject: ANDROID: Formatting/whitespaces --- backends/platform/android/android.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 491e5fbc72..2d396f2c48 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -55,7 +55,8 @@ extern "C" { expr, file, line); } - void __assert2(const char *file, int line, const char *func, const char *expr) { + void __assert2(const char *file, int line, const char *func, + const char *expr) { __android_log_assert(expr, android_log_tag, "Assertion failure: '%s' in %s:%d (%s)", expr, file, line, func); @@ -152,7 +153,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { sem_wait(&JNI::pause_sem); LOGD("timer thread woke up"); } - + timer->handler(); nanosleep(&tv, 0); } @@ -199,7 +200,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { sem_wait(&JNI::pause_sem); LOGD("audio thread woke up"); } - + buf = (byte *)env->GetPrimitiveArrayCritical(bufa, 0); assert(buf); @@ -650,7 +651,8 @@ void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s, JNI::addSysArchivesToSearchSet(s, priority); } -void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) { +void OSystem_Android::logMessage(LogMessageType::Type type, + const char *message) { switch (type) { case LogMessageType::kDebug: __android_log_write(ANDROID_LOG_DEBUG, android_log_tag, message); -- cgit v1.2.3 From a7a7542d1de3f6bb8d076b04cf63a761f01472e1 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 3 Mar 2011 11:35:21 +0100 Subject: ANDROID: Remove an indirection when pausing --- backends/platform/android/android.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 2d396f2c48..35a6421ede 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -196,6 +196,11 @@ void *OSystem_Android::audioThreadFunc(void *arg) { while (!system->_audio_thread_exit) { if (JNI::pause) { + JNI::setAudioStop(); + + paused = true; + silence_count = 33; + LOGD("audio thread going to sleep"); sem_wait(&JNI::pause_sem); LOGD("audio thread woke up"); -- cgit v1.2.3 From 7157454e9b30db91462cb684dd20a61204a7fa43 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 3 Mar 2011 19:11:42 +0100 Subject: ANDROID: Implement surface resizes Split surface code into helper functions to avoid code duplication, and distinguish between screen resizes and surface recreation. The former happens when toggling the softkeyb, where we just have to reset the viewport. Fixes garbled textures in those cases. --- backends/platform/android/android.cpp | 55 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 35a6421ede..239ecd4138 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -323,7 +323,8 @@ void OSystem_Android::initBackend() { _audio_thread_exit = false; pthread_create(&_audio_thread, 0, audioThreadFunc, this); - setupSurface(); + initSurface(); + initViewport(); _game_texture = new GLESPaletteTexture(); _overlay_texture = new GLES4444Texture(); @@ -404,42 +405,38 @@ bool OSystem_Android::pollEvent(Common::Event &event) { if (pthread_self() == _main_thread) { if (_screen_changeid != JNI::surface_changeid) { if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) { - LOGD("initializing surface"); + if (_egl_surface_width > 0 && _egl_surface_height > 0) { + // surface still alive but changed + _screen_changeid = JNI::surface_changeid; + _egl_surface_width = JNI::egl_surface_width; + _egl_surface_height = JNI::egl_surface_height; - _game_texture->release(); - _overlay_texture->release(); - _mouse_texture->release(); + initViewport(); + // double buffered, flip twice + _force_redraw = true; + updateScreen(); + _force_redraw = true; - JNI::deinitSurface(); - setupSurface(); + event.type = Common::EVENT_SCREEN_CHANGED; - _game_texture->reinit(); - _overlay_texture->reinit(); - _mouse_texture->reinit(); + return true; + } else { + // new surface + initSurface(); + _force_redraw = true; - event.type = Common::EVENT_SCREEN_CHANGED; + event.type = Common::EVENT_SCREEN_CHANGED; - return true; + return true; + } + } else { + // surface lost + deinitSurface(); } - - LOGD("deinitialiting surface"); - - _game_texture->release(); - _overlay_texture->release(); - _mouse_texture->release(); - - _screen_changeid = JNI::surface_changeid; - JNI::deinitSurface(); } if (JNI::pause) { - // release some resources - _game_texture->release(); - _overlay_texture->release(); - _mouse_texture->release(); - - LOGD("deinitialiting surface"); - JNI::deinitSurface(); + deinitSurface(); LOGD("main thread going to sleep"); sem_wait(&JNI::pause_sem); @@ -596,7 +593,7 @@ void OSystem_Android::quit() { delete _overlay_texture; delete _mouse_texture; - JNI::deinitSurface(); + deinitSurface(); } void OSystem_Android::setWindowCaption(const char *caption) { -- cgit v1.2.3 From 68378150beb96159db7d959d9625107b721eef57 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 5 Mar 2011 10:02:56 +0100 Subject: ANDROID: Remove some vtable overhead on textures --- backends/platform/android/android.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 239ecd4138..43b618d37b 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -326,9 +326,9 @@ void OSystem_Android::initBackend() { initSurface(); initViewport(); - _game_texture = new GLESPaletteTexture(); + _game_texture = new GLESPalette888Texture(); _overlay_texture = new GLES4444Texture(); - _mouse_texture = new GLESPaletteATexture(); + _mouse_texture = new GLESPalette8888Texture(); // renice this thread to boost the audio thread if (setpriority(PRIO_PROCESS, 0, 19) < 0) -- cgit v1.2.3 From 94db3403a3fbe228aa25cdde310e2a8daa5c33eb Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 5 Mar 2011 18:21:35 +0100 Subject: ANDROID: Add initial 16bit gfx support Supported pixel formats: 565, 5551, 4444 Missing: 555 (doesn't exist on GLES) --- backends/platform/android/android.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 43b618d37b..0cfe7c9a22 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -110,6 +110,8 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _game_texture(0), _overlay_texture(0), _mouse_texture(0), + _mouse_texture_palette(0), + _mouse_texture_rgb(0), _use_mouse_palette(false), _show_mouse(false), _show_overlay(false), @@ -328,7 +330,8 @@ void OSystem_Android::initBackend() { _game_texture = new GLESPalette888Texture(); _overlay_texture = new GLES4444Texture(); - _mouse_texture = new GLESPalette8888Texture(); + _mouse_texture_palette = new GLESPalette8888Texture(); + _mouse_texture = _mouse_texture_palette; // renice this thread to boost the audio thread if (setpriority(PRIO_PROCESS, 0, 19) < 0) @@ -591,7 +594,8 @@ void OSystem_Android::quit() { delete _game_texture; delete _overlay_texture; - delete _mouse_texture; + delete _mouse_texture_palette; + delete _mouse_texture_rgb; deinitSurface(); } -- cgit v1.2.3 From e71fb5b0eb9c9c68bf328d557f09a3191e0c8b8f Mon Sep 17 00:00:00 2001 From: dhewg Date: Mon, 7 Mar 2011 21:49:51 +0100 Subject: ANDROID: Move the overlay initialization There's no point in doing that in initSize() every time --- backends/platform/android/android.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 0cfe7c9a22..2be435c701 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -333,6 +333,8 @@ void OSystem_Android::initBackend() { _mouse_texture_palette = new GLESPalette8888Texture(); _mouse_texture = _mouse_texture_palette; + initOverlay(); + // renice this thread to boost the audio thread if (setpriority(PRIO_PROCESS, 0, 19) < 0) warning("couldn't renice the main thread"); -- cgit v1.2.3 From 0cdaff65c104f11954167048455d4258d053e1cd Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 12 Mar 2011 09:33:45 +0100 Subject: ANDROID: Use 16bit pixel formats on CLUT8 textures This reduces the CPU usage on 640x480 games by ~5% on my droid when reuploading the textures to the GPU --- backends/platform/android/android.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 2be435c701..ca65863fc9 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -112,6 +112,8 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _mouse_texture(0), _mouse_texture_palette(0), _mouse_texture_rgb(0), + _mouse_hotspot(), + _mouse_keycolor(0), _use_mouse_palette(false), _show_mouse(false), _show_overlay(false), @@ -328,9 +330,9 @@ void OSystem_Android::initBackend() { initSurface(); initViewport(); - _game_texture = new GLESPalette888Texture(); + _game_texture = new GLESPalette565Texture(); _overlay_texture = new GLES4444Texture(); - _mouse_texture_palette = new GLESPalette8888Texture(); + _mouse_texture_palette = new GLESPalette5551Texture(); _mouse_texture = _mouse_texture_palette; initOverlay(); -- cgit v1.2.3 From a93229cae53bd35b320e72bd5fe794e8dd79c318 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 13 Mar 2011 14:16:39 +0100 Subject: ANDROID: Don't use compressed textures for the game screen Some GLES drivers suck so much that uploading data to the GPU takes ages. CLUT8 games now use a faked paletted texture, which internally uses a RGB565 hardware texture (Android's native pixel format). This seems to be the only way to efficiently implement constant changing textures with GLES1 - at the cost of extra buffers. Then again, we can now use glTexSubImage2D to only update the dirty rects, which wasn't possible before because glCompressedTexSubImage2D is only usable on GLES2. This commit does exactly that. Overall, the CPU usage is massively reduced for CLUT8 games. --- backends/platform/android/android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index ca65863fc9..56e56fb3dd 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -330,7 +330,7 @@ void OSystem_Android::initBackend() { initSurface(); initViewport(); - _game_texture = new GLESPalette565Texture(); + _game_texture = new GLESFakePalette565Texture(); _overlay_texture = new GLES4444Texture(); _mouse_texture_palette = new GLESPalette5551Texture(); _mouse_texture = _mouse_texture_palette; -- cgit v1.2.3 From 2721e287e5bcd1f4d524f869c26156e27f5ba187 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 13 Mar 2011 15:51:37 +0100 Subject: ANDROID: Buffer 16bit texture contents Same issue as in the last commit: glTexSubImage2D is slow, so cache all copyRect*() calls in a buffer, and update the dirty rect once when drawing. Reduces CPU usage on 16bit games significantly. Also, lockScreen() returns now pixel data for non-CLUT8 games instead of asserting. --- backends/platform/android/android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 56e56fb3dd..e2e3174877 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -488,7 +488,7 @@ bool OSystem_Android::pollEvent(Common::Event &event) { } else { // Touchscreen events need to be converted // from device to game coords first. - const GLESTexture *tex; + const GLESBaseTexture *tex; if (_show_overlay) tex = _overlay_texture; else -- cgit v1.2.3 From 787b27a4b1cde2bd8e750b4eb477189565588e28 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 13 Mar 2011 16:42:50 +0100 Subject: ANDROID: Add missing updateScreen() calls --- backends/platform/android/android.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index e2e3174877..4391cf50db 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -423,6 +423,7 @@ bool OSystem_Android::pollEvent(Common::Event &event) { _force_redraw = true; updateScreen(); _force_redraw = true; + updateScreen(); event.type = Common::EVENT_SCREEN_CHANGED; @@ -431,6 +432,7 @@ bool OSystem_Android::pollEvent(Common::Event &event) { // new surface initSurface(); _force_redraw = true; + updateScreen(); event.type = Common::EVENT_SCREEN_CHANGED; -- cgit v1.2.3 From 79d991081dbeaddd0294c6bbf01675d1ec1fbb72 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 13 Mar 2011 22:31:28 +0100 Subject: ANDROID: Add support for video feature flags kFeatureFullscreenMode and kFeatureAspectRatioCorrection are supported now. The former prevents scaling to the full display - it scales one axis and keeps the game AR. --- backends/platform/android/android.cpp | 50 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 4391cf50db..ba574564b4 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -115,6 +115,8 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _mouse_hotspot(), _mouse_keycolor(0), _use_mouse_palette(false), + _fullscreen(false), + _ar_correction(false), _show_mouse(false), _show_overlay(false), _enable_zoning(false), @@ -302,6 +304,9 @@ void OSystem_Android::initBackend() { _main_thread = pthread_self(); + ConfMan.registerDefault("fullscreen", true); + ConfMan.registerDefault("aspect_ratio", true); + ConfMan.setInt("autosave_period", 0); ConfMan.setBool("FM_high_quality", false); ConfMan.setBool("FM_medium_quality", true); @@ -351,7 +356,9 @@ void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { } bool OSystem_Android::hasFeature(Feature f) { - return (f == kFeatureCursorHasPalette || + return (f == kFeatureFullscreenMode || + f == kFeatureAspectRatioCorrection || + f == kFeatureCursorHasPalette || f == kFeatureVirtualKeyboard || f == kFeatureOverlaySupportsAlpha); } @@ -360,6 +367,14 @@ void OSystem_Android::setFeatureState(Feature f, bool enable) { ENTER("%d, %d", f, enable); switch (f) { + case kFeatureFullscreenMode: + _fullscreen = enable; + updateScreenRect(); + break; + case kFeatureAspectRatioCorrection: + _ar_correction = enable; + updateScreenRect(); + break; case kFeatureVirtualKeyboard: _virtkeybd_on = enable; showVirtualKeyboard(enable); @@ -490,17 +505,28 @@ bool OSystem_Android::pollEvent(Common::Event &event) { } else { // Touchscreen events need to be converted // from device to game coords first. - const GLESBaseTexture *tex; - if (_show_overlay) - tex = _overlay_texture; - else - tex = _game_texture; - - event.mouse.x = scalef(event.mouse.x, tex->width(), - _egl_surface_width); - event.mouse.y = scalef(event.mouse.y, tex->height(), - _egl_surface_height); - event.mouse.x -= _shake_offset; + if (_show_overlay) { + event.mouse.x = scalef(event.mouse.x, + _overlay_texture->width(), + _egl_surface_width); + event.mouse.y = scalef(event.mouse.y, + _overlay_texture->height(), + _egl_surface_height); + } else { + const Common::Rect &r = _game_texture->getDrawRect(); + + event.mouse.x -= r.left; + event.mouse.y -= r.top; + + event.mouse.x = scalef(event.mouse.x, + _game_texture->width(), + r.width()); + event.mouse.y = scalef(event.mouse.y, + _game_texture->height(), + r.height()); + + event.mouse.x -= _shake_offset; + } } break; } -- cgit v1.2.3 From 2dd669d808b89f0d3777d196091b404a4e9baf05 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 13 Mar 2011 22:41:07 +0100 Subject: ANDROID: Remove leftover TODO Resolved with a93229c and 2721e28 --- backends/platform/android/android.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index ba574564b4..9f57eb3fb5 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -480,7 +480,6 @@ bool OSystem_Android::pollEvent(Common::Event &event) { switch (event.type) { case Common::EVENT_MOUSEMOVE: - // TODO: only dirty/redraw move bounds _force_redraw = true; // fallthrough case Common::EVENT_LBUTTONDOWN: -- cgit v1.2.3 From df9167c6b33fbfcb259480c14b08be5c32de6fd3 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 13 Mar 2011 23:14:42 +0100 Subject: ANDROID: Add graphics mode for linear filtering --- backends/platform/android/android.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 9f57eb3fb5..606b825a51 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -116,6 +116,7 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _mouse_keycolor(0), _use_mouse_palette(false), _fullscreen(false), + _graphicsMode(0), _ar_correction(false), _show_mouse(false), _show_overlay(false), -- cgit v1.2.3 From f82121d2a279693f47a25e30e36c34e1e0ff21bd Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 13 Mar 2011 23:27:36 +0100 Subject: ANDROID: Don't merge mouse move events Breaks more than it solves --- backends/platform/android/android.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 606b825a51..9374a876d9 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -540,24 +540,7 @@ bool OSystem_Android::pollEvent(Common::Event &event) { void OSystem_Android::pushEvent(const Common::Event& event) { lockMutex(_event_queue_lock); - // Try to combine multiple queued mouse move events - if (event.type == Common::EVENT_MOUSEMOVE && - !_event_queue.empty() && - _event_queue.back().type == Common::EVENT_MOUSEMOVE) { - Common::Event tail = _event_queue.back(); - if (event.kbd.flags) { - // relative movement hack - tail.mouse.x += event.mouse.x; - tail.mouse.y += event.mouse.y; - } else { - // absolute position, clear relative flag - tail.kbd.flags = 0; - tail.mouse.x = event.mouse.x; - tail.mouse.y = event.mouse.y; - } - } else { - _event_queue.push(event); - } + _event_queue.push(event); unlockMutex(_event_queue_lock); } -- cgit v1.2.3 From 4b6e5e7b06c758d2c6738efaff5dceaaacfed214 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 13 Mar 2011 23:45:52 +0100 Subject: ANDROID: Clip mouse coordinates --- backends/platform/android/android.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 9374a876d9..4d83dd789e 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -526,6 +526,11 @@ bool OSystem_Android::pollEvent(Common::Event &event) { r.height()); event.mouse.x -= _shake_offset; + + event.mouse.x = CLIP(event.mouse.x, int16(0), + int16(_game_texture->width())); + event.mouse.y = CLIP(event.mouse.y, int16(0), + int16(_game_texture->height())); } } break; -- cgit v1.2.3 From 57635fe75cdf01a654d760efa0528a2aa186a391 Mon Sep 17 00:00:00 2001 From: dhewg Date: Mon, 14 Mar 2011 17:24:12 +0100 Subject: ANDROID: Update screen rects on surface changes Fixes regression introduced with 4267011e --- backends/platform/android/android.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 4d83dd789e..85d4817f29 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -435,6 +435,8 @@ bool OSystem_Android::pollEvent(Common::Event &event) { _egl_surface_height = JNI::egl_surface_height; initViewport(); + updateScreenRect(); + // double buffered, flip twice _force_redraw = true; updateScreen(); @@ -447,6 +449,8 @@ bool OSystem_Android::pollEvent(Common::Event &event) { } else { // new surface initSurface(); + updateScreenRect(); + _force_redraw = true; updateScreen(); -- cgit v1.2.3 From e1575e57f818f57b022531f31161e521869d7483 Mon Sep 17 00:00:00 2001 From: dhewg Date: Mon, 14 Mar 2011 17:50:19 +0100 Subject: ANDROID: Extend clearScreen to take care of all cases Hopefully that'll help me to not forget about the double buffering. This fixes some gfx leftovers when not running games in fullscreen mode. --- backends/platform/android/android.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 85d4817f29..7731c53873 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -438,10 +438,7 @@ bool OSystem_Android::pollEvent(Common::Event &event) { updateScreenRect(); // double buffered, flip twice - _force_redraw = true; - updateScreen(); - _force_redraw = true; - updateScreen(); + clearScreen(kClearUpdate, 2); event.type = Common::EVENT_SCREEN_CHANGED; @@ -451,8 +448,8 @@ bool OSystem_Android::pollEvent(Common::Event &event) { initSurface(); updateScreenRect(); - _force_redraw = true; - updateScreen(); + // double buffered, flip twice + clearScreen(kClearUpdate, 2); event.type = Common::EVENT_SCREEN_CHANGED; -- cgit v1.2.3 From 9e7ee4953ec5ca41a30c178ce778149a86f07b8f Mon Sep 17 00:00:00 2001 From: dhewg Date: Mon, 14 Mar 2011 20:26:35 +0100 Subject: ANDROID: Halve the audio buffer size Also, run into the blocking audio write without sleep. This hopefully fixes audio hickups on slow devices. --- backends/platform/android/android.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 7731c53873..72810b6fb7 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -286,9 +286,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { if (written < 0) break; - // sleep a little, prepare the next buffer, and run into the - // blocking AudioTrack.write - nanosleep(&tv_delay, 0); + // prepare the next buffer, and run into the blocking AudioTrack.write } JNI::setAudioStop(); -- cgit v1.2.3 From 7b850c18c7303fa06ff357cf2295e868a16ed1cf Mon Sep 17 00:00:00 2001 From: dhewg Date: Mon, 14 Mar 2011 23:44:43 +0100 Subject: ANDROID: Cleanup --- backends/platform/android/android.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 72810b6fb7..dc8dc9d9c0 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -534,6 +534,7 @@ bool OSystem_Android::pollEvent(Common::Event &event) { } break; } + default: break; } @@ -554,7 +555,7 @@ uint32 OSystem_Android::getMillis() { gettimeofday(&curTime, 0); - return (uint32)(((curTime.tv_sec - _startTime.tv_sec) * 1000) + \ + return (uint32)(((curTime.tv_sec - _startTime.tv_sec) * 1000) + ((curTime.tv_usec - _startTime.tv_usec) / 1000)); } -- cgit v1.2.3 From 6e4af65be1bbb7abb88bd75f5fe2f0260530f6ad Mon Sep 17 00:00:00 2001 From: dhewg Date: Mon, 14 Mar 2011 23:49:18 +0100 Subject: ANDROID: Add missing cases to getFeatureState() --- backends/platform/android/android.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index dc8dc9d9c0..ddef4275a4 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -385,6 +385,10 @@ void OSystem_Android::setFeatureState(Feature f, bool enable) { bool OSystem_Android::getFeatureState(Feature f) { switch (f) { + case kFeatureFullscreenMode: + return _fullscreen; + case kFeatureAspectRatioCorrection: + return _ar_correction; case kFeatureVirtualKeyboard: return _virtkeybd_on; default: -- cgit v1.2.3 From adef4c3f4256a690b374b9801279952c39ccf7a4 Mon Sep 17 00:00:00 2001 From: dhewg Date: Tue, 15 Mar 2011 23:30:17 +0100 Subject: ANDROID: Input system overhaul Rewritten input system with many new feature. Fixed related bugs and shortcomings on the way. --- backends/platform/android/android.cpp | 179 +++------------------------------- 1 file changed, 14 insertions(+), 165 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index ddef4275a4..4e1373a1b1 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -94,12 +94,6 @@ void checkGlError(const char *expr, const char *file, int line) { } #endif -// floating point. use sparingly -template -static inline T scalef(T in, float numerator, float denominator) { - return static_cast(in) * numerator / denominator; -} - OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _audio_sample_rate(audio_sample_rate), _audio_buffer_size(audio_buffer_size), @@ -126,7 +120,16 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _timer(0), _fsFactory(new POSIXFilesystemFactory()), _shake_offset(0), - _event_queue_lock(createMutex()) { + _event_queue_lock(createMutex()), + _touch_pt_down(), + _touch_pt_dt(), + _eventScaleX(100), + _eventScaleY(100), + // TODO put these values in some option dlg? + _touchpad_mode(true), + _touchpad_scale(50), + _dpad_scale(4), + _trackball_scale(2) { } OSystem_Android::~OSystem_Android() { @@ -310,6 +313,10 @@ void OSystem_Android::initBackend() { ConfMan.setBool("FM_high_quality", false); ConfMan.setBool("FM_medium_quality", true); + // TODO hackity hack + if (ConfMan.hasKey("multi_midi")) + _touchpad_mode = !ConfMan.getBool("multi_midi"); + // must happen before creating TimerManager to avoid race in // creating EventManager setupKeymapper(); @@ -396,164 +403,6 @@ bool OSystem_Android::getFeatureState(Feature f) { } } -void OSystem_Android::setupKeymapper() { -#ifdef ENABLE_KEYMAPPER - using namespace Common; - - Keymapper *mapper = getEventManager()->getKeymapper(); - - HardwareKeySet *keySet = new HardwareKeySet(); - - keySet->addHardwareKey( - new HardwareKey("n", KeyState(KEYCODE_n), "n (vk)", - kTriggerLeftKeyType, - kVirtualKeyboardActionType)); - - mapper->registerHardwareKeySet(keySet); - - Keymap *globalMap = new Keymap("global"); - Action *act; - - act = new Action(globalMap, "VIRT", "Display keyboard", - kVirtualKeyboardActionType); - act->addKeyEvent(KeyState(KEYCODE_F7, ASCII_F7, 0)); - - mapper->addGlobalKeymap(globalMap); - - mapper->pushKeymap("global"); -#endif -} - -bool OSystem_Android::pollEvent(Common::Event &event) { - //ENTER(); - - if (pthread_self() == _main_thread) { - if (_screen_changeid != JNI::surface_changeid) { - if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) { - if (_egl_surface_width > 0 && _egl_surface_height > 0) { - // surface still alive but changed - _screen_changeid = JNI::surface_changeid; - _egl_surface_width = JNI::egl_surface_width; - _egl_surface_height = JNI::egl_surface_height; - - initViewport(); - updateScreenRect(); - - // double buffered, flip twice - clearScreen(kClearUpdate, 2); - - event.type = Common::EVENT_SCREEN_CHANGED; - - return true; - } else { - // new surface - initSurface(); - updateScreenRect(); - - // double buffered, flip twice - clearScreen(kClearUpdate, 2); - - event.type = Common::EVENT_SCREEN_CHANGED; - - return true; - } - } else { - // surface lost - deinitSurface(); - } - } - - if (JNI::pause) { - deinitSurface(); - - LOGD("main thread going to sleep"); - sem_wait(&JNI::pause_sem); - LOGD("main thread woke up"); - } - } - - lockMutex(_event_queue_lock); - - if (_event_queue.empty()) { - unlockMutex(_event_queue_lock); - return false; - } - - event = _event_queue.pop(); - unlockMutex(_event_queue_lock); - - switch (event.type) { - case Common::EVENT_MOUSEMOVE: - _force_redraw = true; - // fallthrough - case Common::EVENT_LBUTTONDOWN: - case Common::EVENT_LBUTTONUP: - case Common::EVENT_RBUTTONDOWN: - case Common::EVENT_RBUTTONUP: - case Common::EVENT_WHEELUP: - case Common::EVENT_WHEELDOWN: - case Common::EVENT_MBUTTONDOWN: - case Common::EVENT_MBUTTONUP: { - // relative mouse hack - if (event.kbd.flags == 1) { - // Relative (trackball) mouse hack. - const Common::Point& mouse_pos = - getEventManager()->getMousePos(); - event.mouse.x += mouse_pos.x; - event.mouse.y += mouse_pos.y; - event.mouse.x = CLIP(event.mouse.x, (int16)0, _show_overlay ? - getOverlayWidth() : getWidth()); - event.mouse.y = CLIP(event.mouse.y, (int16)0, _show_overlay ? - getOverlayHeight() : getHeight()); - } else { - // Touchscreen events need to be converted - // from device to game coords first. - if (_show_overlay) { - event.mouse.x = scalef(event.mouse.x, - _overlay_texture->width(), - _egl_surface_width); - event.mouse.y = scalef(event.mouse.y, - _overlay_texture->height(), - _egl_surface_height); - } else { - const Common::Rect &r = _game_texture->getDrawRect(); - - event.mouse.x -= r.left; - event.mouse.y -= r.top; - - event.mouse.x = scalef(event.mouse.x, - _game_texture->width(), - r.width()); - event.mouse.y = scalef(event.mouse.y, - _game_texture->height(), - r.height()); - - event.mouse.x -= _shake_offset; - - event.mouse.x = CLIP(event.mouse.x, int16(0), - int16(_game_texture->width())); - event.mouse.y = CLIP(event.mouse.y, int16(0), - int16(_game_texture->height())); - } - } - break; - } - - default: - break; - } - - return true; -} - -void OSystem_Android::pushEvent(const Common::Event& event) { - lockMutex(_event_queue_lock); - - _event_queue.push(event); - - unlockMutex(_event_queue_lock); -} - uint32 OSystem_Android::getMillis() { timeval curTime; -- cgit v1.2.3 From 82bcddf8dacb894fe1155ca768df9a072984ef91 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 17 Mar 2011 19:03:51 +0100 Subject: ANDROID: Init vars to match with the defaults The feature flags are set too late, so lets fix that here --- backends/platform/android/android.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 4e1373a1b1..483b37310a 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -109,9 +109,9 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _mouse_hotspot(), _mouse_keycolor(0), _use_mouse_palette(false), - _fullscreen(false), _graphicsMode(0), - _ar_correction(false), + _fullscreen(true), + _ar_correction(true), _show_mouse(false), _show_overlay(false), _enable_zoning(false), -- cgit v1.2.3 From 8953581ec9dcde966ec7a5e2e7f2c37a4cf4d109 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 17 Mar 2011 20:48:44 +0100 Subject: ANDROID: Ignore the slop area on all touch scrolls Prevents initial cursor jumps --- backends/platform/android/android.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 483b37310a..cf711301fa 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -122,6 +122,7 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _shake_offset(0), _event_queue_lock(createMutex()), _touch_pt_down(), + _touch_pt_scroll(), _touch_pt_dt(), _eventScaleX(100), _eventScaleY(100), -- cgit v1.2.3 From 0eb5352290ddfea9d90f99b97fa0d89c806d25e0 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 17 Mar 2011 21:00:15 +0100 Subject: ANDROID: Increase default touchpad mode scale aka my display is bigger than yours --- backends/platform/android/android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index cf711301fa..6bb6de7289 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -128,7 +128,7 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _eventScaleY(100), // TODO put these values in some option dlg? _touchpad_mode(true), - _touchpad_scale(50), + _touchpad_scale(66), _dpad_scale(4), _trackball_scale(2) { } -- cgit v1.2.3 From 69e271225f43e7c6c34fbc9c1e0cf73afeedfe18 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 19 Mar 2011 12:17:43 +0100 Subject: ANDROID: Log some system properties --- backends/platform/android/android.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 6bb6de7289..73b310c0bc 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -131,6 +132,11 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _touchpad_scale(66), _dpad_scale(4), _trackball_scale(2) { + LOGI("Running on: [%s] [%s] SDK:%s ABI:%s", + getSystemProperty("ro.build.fingerprint").c_str(), + getSystemProperty("ro.build.display.id").c_str(), + getSystemProperty("ro.build.version.sdk").c_str(), + getSystemProperty("ro.product.cpu.abi").c_str()); } OSystem_Android::~OSystem_Android() { @@ -548,6 +554,14 @@ void OSystem_Android::logMessage(LogMessageType::Type type, } } +Common::String OSystem_Android::getSystemProperty(const char *name) const { + char value[PROP_VALUE_MAX]; + + int len = __system_property_get(name, value); + + return Common::String(value, len); +} + #ifdef DYNAMIC_MODULES void AndroidPluginProvider::addCustomDirectories(Common::FSList &dirs) const { ((OSystem_Android *)g_system)->addPluginDirectories(dirs); -- cgit v1.2.3 From 0d9a852f464e484d5733de6268d6d0b917294120 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 19 Mar 2011 12:36:27 +0100 Subject: ANDROID: Implement OSystem::getSystemLanguage() --- backends/platform/android/android.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 73b310c0bc..69b3f1e084 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -554,6 +554,12 @@ void OSystem_Android::logMessage(LogMessageType::Type type, } } +Common::String OSystem_Android::getSystemLanguage() const { + return Common::String::format("%s_%s", + getSystemProperty("persist.sys.language").c_str(), + getSystemProperty("persist.sys.country").c_str()); +} + Common::String OSystem_Android::getSystemProperty(const char *name) const { char value[PROP_VALUE_MAX]; -- cgit v1.2.3 From 5f96dc6867a509291af4e9b2632ae5c548101707 Mon Sep 17 00:00:00 2001 From: dhewg Date: Tue, 22 Mar 2011 20:29:08 +0100 Subject: ANDROID: Fix timer frequency to match SDL --- backends/platform/android/android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 69b3f1e084..9a6995646c 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -162,7 +162,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { struct timespec tv; tv.tv_sec = 0; - tv.tv_nsec = 100 * 1000 * 1000; // 100ms + tv.tv_nsec = 10 * 1000 * 1000; // 10ms while (!system->_timer_thread_exit) { if (JNI::pause) { -- cgit v1.2.3 From bceab2656bdff4aa99f99b047f6bbd18ad5f86fc Mon Sep 17 00:00:00 2001 From: dhewg Date: Sat, 2 Apr 2011 13:30:38 +0200 Subject: ANDROID: Attempt at working around some HTC fail --- backends/platform/android/android.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 9a6995646c..1a83289c25 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -101,6 +101,7 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _screen_changeid(0), _egl_surface_width(0), _egl_surface_height(0), + _htc_fail(false), _force_redraw(false), _game_texture(0), _overlay_texture(0), @@ -132,11 +133,19 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _touchpad_scale(66), _dpad_scale(4), _trackball_scale(2) { + Common::String fp = getSystemProperty("ro.build.fingerprint"); + LOGI("Running on: [%s] [%s] SDK:%s ABI:%s", - getSystemProperty("ro.build.fingerprint").c_str(), + fp.c_str(), getSystemProperty("ro.build.display.id").c_str(), getSystemProperty("ro.build.version.sdk").c_str(), getSystemProperty("ro.product.cpu.abi").c_str()); + + fp.toLowercase(); + _htc_fail = fp.contains("htc"); + + if (_htc_fail) + LOGI("Enabling HTC workaround"); } OSystem_Android::~OSystem_Android() { -- cgit v1.2.3 From ea253ff26d2d5ffeec85d34a79c00f0f50598111 Mon Sep 17 00:00:00 2001 From: dhewg Date: Tue, 5 Apr 2011 15:07:07 +0200 Subject: ANDROID: Use a faked paletted texture for CLUT cursors Same change as for the game screen, reduces CPU usage a little --- backends/platform/android/android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 1a83289c25..6346ffa7a3 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -359,7 +359,7 @@ void OSystem_Android::initBackend() { _game_texture = new GLESFakePalette565Texture(); _overlay_texture = new GLES4444Texture(); - _mouse_texture_palette = new GLESPalette5551Texture(); + _mouse_texture_palette = new GLESFakePalette5551Texture(); _mouse_texture = _mouse_texture_palette; initOverlay(); -- cgit v1.2.3 From 507bff8233662019e7b7078b645ce035e796af5b Mon Sep 17 00:00:00 2001 From: dhewg Date: Tue, 5 Apr 2011 19:01:51 +0200 Subject: ANDROID: Log device manufacturer, model and brand --- backends/platform/android/android.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 6346ffa7a3..eb0e164109 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -135,7 +135,10 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _trackball_scale(2) { Common::String fp = getSystemProperty("ro.build.fingerprint"); - LOGI("Running on: [%s] [%s] SDK:%s ABI:%s", + LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s", + getSystemProperty("ro.product.manufacturer").c_str(), + getSystemProperty("ro.product.model").c_str(), + getSystemProperty("ro.product.brand").c_str(), fp.c_str(), getSystemProperty("ro.build.display.id").c_str(), getSystemProperty("ro.build.version.sdk").c_str(), -- cgit v1.2.3 From 811b1fcc2a2d8e938c2e06489a04388c97715f48 Mon Sep 17 00:00:00 2001 From: dhewg Date: Tue, 5 Apr 2011 19:10:35 +0200 Subject: ANDROID: Use the manufacturer string for workarounds Some fingerprints don't contain it, so this should be more reliable. --- backends/platform/android/android.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index eb0e164109..ab3f1908c4 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -133,19 +133,19 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _touchpad_scale(66), _dpad_scale(4), _trackball_scale(2) { - Common::String fp = getSystemProperty("ro.build.fingerprint"); + Common::String mf = getSystemProperty("ro.product.manufacturer"); LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s", - getSystemProperty("ro.product.manufacturer").c_str(), + mf.c_str(), getSystemProperty("ro.product.model").c_str(), getSystemProperty("ro.product.brand").c_str(), - fp.c_str(), + getSystemProperty("ro.build.fingerprint").c_str(), getSystemProperty("ro.build.display.id").c_str(), getSystemProperty("ro.build.version.sdk").c_str(), getSystemProperty("ro.product.cpu.abi").c_str()); - fp.toLowercase(); - _htc_fail = fp.contains("htc"); + mf.toLowercase(); + _htc_fail = mf.contains("htc"); if (_htc_fail) LOGI("Enabling HTC workaround"); -- cgit v1.2.3 From a565e63c48b2bb55b9e1197addddd3c03cf85c48 Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 6 Apr 2011 18:08:38 +0200 Subject: ANDROID: Add multitouch support --- backends/platform/android/android.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index ab3f1908c4..bbfdb06b8d 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -132,6 +132,7 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _touchpad_mode(true), _touchpad_scale(66), _dpad_scale(4), + _fingersDown(0), _trackball_scale(2) { Common::String mf = getSystemProperty("ro.product.manufacturer"); -- cgit v1.2.3 From 8feac89bc7329f002d3c4beba370d9c6ea05e798 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 28 Apr 2011 20:02:01 +0200 Subject: ANDROID: Fix compilation some more --- backends/platform/android/android.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index bbfdb06b8d..c7f62f523b 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -32,6 +32,7 @@ #include #include "common/util.h" +#include "common/textconsole.h" #include "common/rect.h" #include "common/queue.h" #include "common/mutex.h" -- cgit v1.2.3 From 3d4e9fe674d2daf59ff4b481fc2f89f77b390a4f Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 3 May 2011 11:27:44 +0200 Subject: BACKENDS: Allow various files to use stuff from time.h --- backends/platform/android/android.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index c7f62f523b..7cf1e988fc 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -25,6 +25,9 @@ #if defined(__ANDROID__) +// Allow use of stuff in +#define FORBIDDEN_SYMBOL_EXCEPTION_time_h + #include #include #include -- cgit v1.2.3 From a50c36d1381be2e7d0748a2c734e41357fd4920f Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 3 May 2011 14:29:01 +0200 Subject: ANDROID: Fix various forbidden symbol clashes --- backends/platform/android/android.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'backends/platform/android/android.cpp') diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 7cf1e988fc..b1d0727d1f 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -28,6 +28,20 @@ // Allow use of stuff in #define FORBIDDEN_SYMBOL_EXCEPTION_time_h +// Disable printf override in common/forbidden.h to avoid +// clashes with log.h from the Android SDK. +// That header file uses +// __attribute__ ((format(printf, 3, 4))) +// which gets messed up by our override mechanism; this could +// be avoided by either changing the Android SDK to use the equally +// legal and valid +// __attribute__ ((format(printf, 3, 4))) +// or by refining our printf override to use a varadic macro +// (which then wouldn't be portable, though). +// Anyway, for now we just disable the printf override globally +// for the Android port +#define FORBIDDEN_SYMBOL_EXCEPTION_printf + #include #include #include -- cgit v1.2.3