diff options
author | dhewg | 2011-02-19 17:30:30 +0100 |
---|---|---|
committer | dhewg | 2011-02-19 20:15:51 +0100 |
commit | adf2225eb414b04a0e58f1fad221cdef27017391 (patch) | |
tree | 57b56e98bf8391d95ed898c73942ecf0b8c85e43 /backends/platform | |
parent | 229e3ca5bf4bbc91b6bf85a5fe6dd9356a97a5ef (diff) | |
download | scummvm-rg350-adf2225eb414b04a0e58f1fad221cdef27017391.tar.gz scummvm-rg350-adf2225eb414b04a0e58f1fad221cdef27017391.tar.bz2 scummvm-rg350-adf2225eb414b04a0e58f1fad221cdef27017391.zip |
ANDROID: Move helper defines in a new header file
- added a few macros for convinience
- use them
- replaced CHECK_GL_ERROR with GLCALL
- spam GLCALL
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/android/android.cpp | 272 | ||||
-rw-r--r-- | backends/platform/android/android.h | 70 | ||||
-rw-r--r-- | backends/platform/android/video.cpp | 133 |
3 files changed, 241 insertions, 234 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 6566146313..0424983824 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -29,6 +29,7 @@ #include "base/main.h" #include "graphics/surface.h" +#include "backends/platform/android/android.h" #include "backends/platform/android/video.h" #include <jni.h> @@ -39,10 +40,6 @@ #include <sys/time.h> #include <time.h> -#include <GLES/gl.h> -#include <GLES/glext.h> -#include <android/log.h> - #include "common/archive.h" #include "common/util.h" #include "common/rect.h" @@ -60,35 +57,55 @@ #include "backends/platform/android/asset-archive.h" -#undef LOG_TAG -#define LOG_TAG "ScummVM" - -#if 0 -#define ENTER(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, args) -#else -#define ENTER(args...) /**/ -#endif - -// Fix JNIEXPORT declaration to actually do something useful -#undef JNIEXPORT -#define JNIEXPORT __attribute__ ((visibility("default"))) +const char *android_log_tag = "ScummVM"; // This replaces the bionic libc assert functions with something that // actually prints the assertion failure before aborting. extern "C" { void __assert(const char *file, int line, const char *expr) { - __android_log_assert(expr, LOG_TAG, + __android_log_assert(expr, android_log_tag, "Assertion failure: '%s' in %s:%d", expr, file, line); } void __assert2(const char *file, int line, const char *func, const char *expr) { - __android_log_assert(expr, LOG_TAG, + __android_log_assert(expr, android_log_tag, "Assertion failure: '%s' in %s:%d (%s)", expr, file, line, func); } } +#ifdef ANDROID_DEBUG_GL +static const char *getGlErrStr(GLenum error) { + switch (error) { + case GL_INVALID_ENUM: + return "GL_INVALID_ENUM"; + case GL_INVALID_VALUE: + return "GL_INVALID_VALUE"; + case GL_INVALID_OPERATION: + return "GL_INVALID_OPERATION"; + case GL_STACK_OVERFLOW: + return "GL_STACK_OVERFLOW"; + case GL_STACK_UNDERFLOW: + return "GL_STACK_UNDERFLOW"; + case GL_OUT_OF_MEMORY: + return "GL_OUT_OF_MEMORY"; + } + + static char buf[40]; + snprintf(buf, sizeof(buf), "(Unknown GL error code 0x%x)", error); + + return buf; +} + +void checkGlError(const char *expr, const char *file, int line) { + GLenum error = glGetError(); + + if (error != GL_NO_ERROR) + LOGE("GL ERROR: %s on %s (%s:%d)", getGlErrStr(error), expr, file, line); +} +#endif + static JavaVM *cached_jvm; static jfieldID FID_Event_type; static jfieldID FID_Event_synthetic; @@ -107,7 +124,7 @@ JNIEnv *JNU_GetEnv() { jint res = cached_jvm->GetEnv((void **)&env, JNI_VERSION_1_2); if (res != JNI_OK) { - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "GetEnv() failed: %d", res); + LOGE("GetEnv() failed: %d", res); abort(); } @@ -142,31 +159,6 @@ protected: }; #endif -#if 0 -#define CHECK_GL_ERROR() checkGlError(__FILE__, __LINE__) -static const char *getGlErrStr(GLenum error) { - switch (error) { - case GL_NO_ERROR: return "GL_NO_ERROR"; - case GL_INVALID_ENUM: return "GL_INVALID_ENUM"; - case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION"; - case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW"; - case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW"; - case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY"; - } - - static char buf[40]; - snprintf(buf, sizeof(buf), "(Unknown GL error code 0x%x)", error); - return buf; -} -static void checkGlError(const char *file, int line) { - GLenum error = glGetError(); - if (error != GL_NO_ERROR) - warning("%s:%d: GL error: %s", file, line, getGlErrStr(error)); -} -#else -#define CHECK_GL_ERROR() do {} while (false) -#endif - class OSystem_Android : public BaseBackend, public PaletteManager { private: // back pointer to (java) peer instance @@ -356,7 +348,7 @@ OSystem_Android::OSystem_Android(jobject am) : } OSystem_Android::~OSystem_Android() { - ENTER("~OSystem_Android()"); + ENTER(); delete _game_texture; delete _overlay_texture; @@ -452,7 +444,7 @@ static void ScummVM_audioMixCallback(JNIEnv *env, jobject self, static void ScummVM_setConfManInt(JNIEnv *env, jclass cls, jstring key_obj, jint value) { - ENTER("setConfManInt(%p, %d)", key_obj, (int)value); + ENTER("%p, %d", key_obj, (int)value); const char *key = env->GetStringUTFChars(key_obj, 0); @@ -466,7 +458,7 @@ static void ScummVM_setConfManInt(JNIEnv *env, jclass cls, static void ScummVM_setConfManString(JNIEnv *env, jclass cls, jstring key_obj, jstring value_obj) { - ENTER("setConfManStr(%p, %p)", key_obj, value_obj); + ENTER("%p, %p", key_obj, value_obj); const char *key = env->GetStringUTFChars(key_obj, 0); @@ -494,7 +486,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { jint res = cached_jvm->AttachCurrentThread(&env, 0); if (res != JNI_OK) { - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "AttachCurrentThread() failed: %d", res); + LOGE("AttachCurrentThread() failed: %d", res); abort(); } @@ -510,7 +502,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { res = cached_jvm->DetachCurrentThread(); if (res != JNI_OK) { - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "DetachCurrentThread() failed: %d", res); + LOGE("DetachCurrentThread() failed: %d", res); abort(); } @@ -518,7 +510,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { } void OSystem_Android::initBackend() { - ENTER("initBackend()"); + ENTER(); JNIEnv *env = JNU_GetEnv(); @@ -568,7 +560,7 @@ void OSystem_Android::initBackend() { } void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { - ENTER("OSystem_Android::addPluginDirectories()"); + ENTER(); JNIEnv *env = JNU_GetEnv(); @@ -614,7 +606,7 @@ bool OSystem_Android::hasFeature(Feature f) { } void OSystem_Android::setFeatureState(Feature f, bool enable) { - ENTER("setFeatureState(%d, %d)", f, enable); + ENTER("%d, %d", f, enable); switch (f) { case kFeatureVirtualKeyboard: @@ -650,12 +642,12 @@ int OSystem_Android::getDefaultGraphicsMode() const { } bool OSystem_Android::setGraphicsMode(const char *mode) { - ENTER("setGraphicsMode(%s)", mode); + ENTER("%s", mode); return true; } bool OSystem_Android::setGraphicsMode(int mode) { - ENTER("setGraphicsMode(%d)", mode); + ENTER("%d", mode); return true; } @@ -664,7 +656,7 @@ int OSystem_Android::getGraphicsMode() const { } void OSystem_Android::setupScummVMSurface() { - ENTER("setupScummVMSurface"); + ENTER(); JNIEnv *env = JNU_GetEnv(); env->CallVoidMethod(_back_ptr, MID_setupScummVMSurface); @@ -676,22 +668,22 @@ void OSystem_Android::setupScummVMSurface() { GLESTexture::initGLExtensions(); // Turn off anything that looks like 3D ;) - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glDisable(GL_FOG); - glDisable(GL_DITHER); + GLCALL(glDisable(GL_CULL_FACE)); + GLCALL(glDisable(GL_DEPTH_TEST)); + GLCALL(glDisable(GL_LIGHTING)); + GLCALL(glDisable(GL_FOG)); + GLCALL(glDisable(GL_DITHER)); - glShadeModel(GL_FLAT); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + GLCALL(glShadeModel(GL_FLAT)); + GLCALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + GLCALL(glEnable(GL_BLEND)); + GLCALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + GLCALL(glEnableClientState(GL_VERTEX_ARRAY)); + GLCALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - glEnable(GL_TEXTURE_2D); + GLCALL(glEnable(GL_TEXTURE_2D)); if (!_game_texture) _game_texture = new GLESPaletteTexture(); @@ -708,16 +700,15 @@ void OSystem_Android::setupScummVMSurface() { else _mouse_texture->reinitGL(); - glViewport(0, 0, _egl_surface_width, _egl_surface_height); + GLCALL(glViewport(0, 0, _egl_surface_width, _egl_surface_height)); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrthof(0, _egl_surface_width, _egl_surface_height, 0, -1, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + 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(); - CHECK_GL_ERROR(); } void OSystem_Android::destroyScummVMSurface() { @@ -728,7 +719,7 @@ void OSystem_Android::destroyScummVMSurface() { void OSystem_Android::initSize(uint width, uint height, const Graphics::PixelFormat *format) { - ENTER("initSize(%d,%d,%p)", width, height, format); + ENTER("%d, %d, %p", width, height, format); _game_texture->allocBuffer(width, height); @@ -753,7 +744,7 @@ int16 OSystem_Android::getWidth() { } void OSystem_Android::setPalette(const byte *colors, uint start, uint num) { - ENTER("setPalette(%p, %u, %u)", colors, start, num); + ENTER("%p, %u, %u", colors, start, num); if (!_use_mouse_palette) _setCursorPalette(colors, start, num); @@ -770,7 +761,7 @@ void OSystem_Android::setPalette(const byte *colors, uint start, uint num) { } void OSystem_Android::grabPalette(byte *colors, uint start, uint num) { - ENTER("grabPalette(%p, %u, %u)", colors, start, num); + ENTER("%p, %u, %u", colors, start, num); const byte *palette = _game_texture->palette_const() + start * 3; @@ -788,14 +779,13 @@ void OSystem_Android::grabPalette(byte *colors, uint start, uint num) { void OSystem_Android::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) { - ENTER("copyRectToScreen(%p, %d, %d, %d, %d, %d)", - buf, pitch, x, y, w, 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("updateScreen()"); + //ENTER(); if (!_force_redraw && !_game_texture->dirty() && @@ -805,7 +795,7 @@ void OSystem_Android::updateScreen() { _force_redraw = false; - glPushMatrix(); + GLCALL(glPushMatrix()); if (_shake_offset != 0 || (!_focus_rect.isEmpty() && @@ -813,46 +803,44 @@ void OSystem_Android::updateScreen() { _game_texture->height()).contains(_focus_rect))) { // These are the only cases where _game_texture doesn't // cover the entire screen. - glClearColorx(0, 0, 0, 1 << 16); - glClear(GL_COLOR_BUFFER_BIT); + GLCALL(glClearColorx(0, 0, 0, 1 << 16)); + GLCALL(glClear(GL_COLOR_BUFFER_BIT)); // Move everything up by _shake_offset (game) pixels - glTranslatex(0, -_shake_offset << 16, 0); + GLCALL(glTranslatex(0, -_shake_offset << 16, 0)); } if (_focus_rect.isEmpty()) { _game_texture->drawTexture(0, 0, _egl_surface_width, _egl_surface_height); } else { - glPushMatrix(); - glScalex(xdiv(_egl_surface_width, _focus_rect.width()), - xdiv(_egl_surface_height, _focus_rect.height()), - 1 << 16); - glTranslatex(-_focus_rect.left << 16, -_focus_rect.top << 16, 0); - glScalex(xdiv(_game_texture->width(), _egl_surface_width), - xdiv(_game_texture->height(), _egl_surface_height), - 1 << 16); + 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); - glPopMatrix(); + GLCALL(glPopMatrix()); } - CHECK_GL_ERROR(); - if (_show_overlay) { - _overlay_texture->drawTexture(0, 0, - _egl_surface_width, - _egl_surface_height); - CHECK_GL_ERROR(); + GLCALL(_overlay_texture->drawTexture(0, 0, + _egl_surface_width, + _egl_surface_height)); } if (_show_mouse) { - glPushMatrix(); + GLCALL(glPushMatrix()); - glTranslatex(-_mouse_hotspot.x << 16, - -_mouse_hotspot.y << 16, - 0); + GLCALL(glTranslatex(-_mouse_hotspot.x << 16, + -_mouse_hotspot.y << 16, + 0)); // Scale up ScummVM -> OpenGL (pixel) coordinates int texwidth, texheight; @@ -865,29 +853,27 @@ void OSystem_Android::updateScreen() { texheight = getHeight(); } - glScalex(xdiv(_egl_surface_width, texwidth), - xdiv(_egl_surface_height, texheight), - 1 << 16); + GLCALL(glScalex(xdiv(_egl_surface_width, texwidth), + xdiv(_egl_surface_height, texheight), + 1 << 16)); // Note the extra half texel to position the mouse in // the middle of the x,y square: const Common::Point& mouse = getEventManager()->getMousePos(); - glTranslatex((mouse.x << 16) | 1 << 15, - (mouse.y << 16) | 1 << 15, 0); + GLCALL(glTranslatex((mouse.x << 16) | 1 << 15, + (mouse.y << 16) | 1 << 15, 0)); // Mouse targetscale just seems to make the cursor way // too big :/ - //glScalex(_mouse_targetscale << 16, _mouse_targetscale << 16, - // 1 << 16); + //GLCALL(glScalex(_mouse_targetscale << 16, _mouse_targetscale << 16, + // 1 << 16)); _mouse_texture->drawTexture(); - glPopMatrix(); + GLCALL(glPopMatrix()); } - glPopMatrix(); - - CHECK_GL_ERROR(); + GLCALL(glPopMatrix()); JNIEnv *env = JNU_GetEnv(); if (!env->CallBooleanMethod(_back_ptr, MID_swapBuffers)) { @@ -898,7 +884,7 @@ void OSystem_Android::updateScreen() { } Graphics::Surface *OSystem_Android::lockScreen() { - ENTER("lockScreen()"); + ENTER(); Graphics::Surface *surface = _game_texture->surface(); assert(surface->pixels); @@ -907,13 +893,13 @@ Graphics::Surface *OSystem_Android::lockScreen() { } void OSystem_Android::unlockScreen() { - ENTER("unlockScreen()"); + ENTER(); assert(_game_texture->dirty()); } void OSystem_Android::setShakePos(int shake_offset) { - ENTER("setShakePos(%d)", shake_offset); + ENTER("%d", shake_offset); if (_shake_offset != shake_offset) { _shake_offset = shake_offset; @@ -922,15 +908,14 @@ void OSystem_Android::setShakePos(int shake_offset) { } void OSystem_Android::fillScreen(uint32 col) { - ENTER("fillScreen(%u)", col); + ENTER("%u", col); assert(col < 256); _game_texture->fillBuffer(col); } void OSystem_Android::setFocusRectangle(const Common::Rect& rect) { - ENTER("setFocusRectangle(%d,%d,%d,%d)", - rect.left, rect.top, rect.right, rect.bottom); + ENTER("%d, %d, %d, %d", rect.left, rect.top, rect.right, rect.bottom); if (_enable_zoning) { _focus_rect = rect; @@ -939,7 +924,7 @@ void OSystem_Android::setFocusRectangle(const Common::Rect& rect) { } void OSystem_Android::clearFocusRectangle() { - ENTER("clearFocusRectangle()"); + ENTER(); if (_enable_zoning) { _focus_rect = Common::Rect(); @@ -948,21 +933,21 @@ void OSystem_Android::clearFocusRectangle() { } void OSystem_Android::showOverlay() { - ENTER("showOverlay()"); + ENTER(); _show_overlay = true; _force_redraw = true; } void OSystem_Android::hideOverlay() { - ENTER("hideOverlay()"); + ENTER(); _show_overlay = false; _force_redraw = true; } void OSystem_Android::clearOverlay() { - ENTER("clearOverlay()"); + ENTER(); _overlay_texture->fillBuffer(0); @@ -971,7 +956,7 @@ void OSystem_Android::clearOverlay() { } void OSystem_Android::grabOverlay(OverlayColor *buf, int pitch) { - ENTER("grabOverlay(%p, %d)", buf, 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 @@ -991,8 +976,7 @@ void OSystem_Android::grabOverlay(OverlayColor *buf, int pitch) { void OSystem_Android::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) { - ENTER("copyRectToOverlay(%p, %d, %d, %d, %d, %d)", - buf, pitch, x, y, w, 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])); @@ -1013,7 +997,7 @@ int16 OSystem_Android::getOverlayWidth() { } bool OSystem_Android::showMouse(bool visible) { - ENTER("showMouse(%d)", visible); + ENTER("%d", visible); _show_mouse = visible; @@ -1021,7 +1005,7 @@ bool OSystem_Android::showMouse(bool visible) { } void OSystem_Android::warpMouse(int x, int y) { - ENTER("warpMouse(%d, %d)", x, 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. @@ -1031,9 +1015,8 @@ void OSystem_Android::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { - ENTER("setMouseCursor(%p, %u, %u, %d, %d, %d, %d, %p)", - buf, w, h, hotspotX, hotspotY, (int)keycolor, cursorTargetScale, - format); + ENTER("%p, %u, %u, %d, %d, %u, %d, %p", buf, w, h, hotspotX, hotspotY, + keycolor, cursorTargetScale, format); assert(keycolor < 256); @@ -1074,14 +1057,14 @@ void OSystem_Android::_setCursorPalette(const byte *colors, void OSystem_Android::setCursorPalette(const byte *colors, uint start, uint num) { - ENTER("setCursorPalette(%p, %u, %u)", colors, start, num); + ENTER("%p, %u, %u", colors, start, num); _setCursorPalette(colors, start, num); _use_mouse_palette = true; } void OSystem_Android::disableCursorPalette(bool disable) { - ENTER("disableCursorPalette(%d)", disable); + ENTER("%d", disable); _use_mouse_palette = !disable; } @@ -1115,7 +1098,7 @@ void OSystem_Android::setupKeymapper() { } bool OSystem_Android::pollEvent(Common::Event &event) { - //ENTER("pollEvent()"); + //ENTER(); lockMutex(_event_queue_lock); @@ -1300,14 +1283,14 @@ void OSystem_Android::deleteMutex(MutexRef mutex) { } void OSystem_Android::quit() { - ENTER("quit()"); + ENTER(); _timer_thread_exit = true; pthread_join(_timer_thread, 0); } void OSystem_Android::setWindowCaption(const char *caption) { - ENTER("setWindowCaption(%s)", caption); + ENTER("%s", caption); JNIEnv *env = JNU_GetEnv(); jstring java_caption = env->NewStringUTF(caption); @@ -1324,7 +1307,7 @@ void OSystem_Android::setWindowCaption(const char *caption) { } void OSystem_Android::displayMessageOnOSD(const char *msg) { - ENTER("displayMessageOnOSD(%s)", msg); + ENTER("%s", msg); JNIEnv *env = JNU_GetEnv(); jstring java_msg = env->NewStringUTF(msg); @@ -1342,7 +1325,7 @@ void OSystem_Android::displayMessageOnOSD(const char *msg) { } void OSystem_Android::showVirtualKeyboard(bool enable) { - ENTER("showVirtualKeyboard(%d)", enable); + ENTER("%d", enable); JNIEnv *env = JNU_GetEnv(); @@ -1423,15 +1406,15 @@ void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s, void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) { switch (type) { case LogMessageType::kDebug: - __android_log_write(ANDROID_LOG_DEBUG, LOG_TAG, message); + __android_log_write(ANDROID_LOG_DEBUG, android_log_tag, message); break; case LogMessageType::kWarning: - __android_log_write(ANDROID_LOG_WARN, LOG_TAG, message); + __android_log_write(ANDROID_LOG_WARN, android_log_tag, message); break; case LogMessageType::kError: - __android_log_write(ANDROID_LOG_ERROR, LOG_TAG, message); + __android_log_write(ANDROID_LOG_ERROR, android_log_tag, message); break; } } @@ -1475,12 +1458,11 @@ static jint ScummVM_scummVMMain(JNIEnv *env, jobject self, jobjectArray args) { g_system = cpp_obj; assert(g_system); - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, - "Entering scummvm_main with %d args", argc); + LOGI("Entering scummvm_main with %d args", argc); res = scummvm_main(argc, argv); - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Exiting scummvm_main"); + LOGI("Exiting scummvm_main"); g_system->quit(); diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h new file mode 100644 index 0000000000..855fb04b5d --- /dev/null +++ b/backends/platform/android/android.h @@ -0,0 +1,70 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#if defined(__ANDROID__) + +#include <android/log.h> + +#include <GLES/gl.h> +#include <GLES/glext.h> + +// toggles start +//#define ANDROID_DEBUG_ENTER +//#define ANDROID_DEBUG_GL +// toggles end + +extern const char *android_log_tag; + +#define _ANDROID_LOG(prio, fmt, args...) __android_log_print(prio, android_log_tag, fmt, ## args) +#define LOGD(fmt, args...) _ANDROID_LOG(ANDROID_LOG_DEBUG, fmt, ##args) +#define LOGI(fmt, args...) _ANDROID_LOG(ANDROID_LOG_INFO, fmt, ##args) +#define LOGW(fmt, args...) _ANDROID_LOG(ANDROID_LOG_WARN, fmt, ##args) +#define LOGE(fmt, args...) _ANDROID_LOG(ANDROID_LOG_ERROR, fmt, ##args) + +#ifdef ANDROID_DEBUG_ENTER +#define ENTER(fmt, args...) LOGD("%s(" fmt ")", __FUNCTION__, ##args) +#else +#define ENTER(fmt, args...) /**/ +#endif + +#ifdef ANDROID_DEBUG_GL +extern void checkGlError(const char *expr, const char *file, int line); + +#define GLCALL(x) \ + do { \ + (x); \ + checkGlError(#x, __FILE__, __LINE__); \ + } while (false) + +#else +#define GLCALL(x) do { (x); } while (false) +#endif + +// Fix JNIEXPORT declaration to actually do something useful +#undef JNIEXPORT +#define JNIEXPORT __attribute__ ((visibility("default"))) + +#endif + diff --git a/backends/platform/android/video.cpp b/backends/platform/android/video.cpp index f5ec0b45d9..f8427c2ac8 100644 --- a/backends/platform/android/video.cpp +++ b/backends/platform/android/video.cpp @@ -28,55 +28,17 @@ #include "base/main.h" #include "graphics/surface.h" -#include <GLES/gl.h> -#include <GLES/glext.h> - -#include <android/log.h> - #include "common/rect.h" #include "common/array.h" #include "common/util.h" #include "common/tokenizer.h" +#include "backends/platform/android/android.h" #include "backends/platform/android/video.h" // Unfortunately, Android devices are too varied to make broad assumptions :/ #define TEXSUBIMAGE_IS_EXPENSIVE 0 -#undef LOG_TAG -#define LOG_TAG "ScummVM" - -#if 0 -#define ENTER(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, args) -#else -#define ENTER(args...) /**/ -#endif - -#if 0 -#define CHECK_GL_ERROR() checkGlError(__FILE__, __LINE__) -static const char *getGlErrStr(GLenum error) { - switch (error) { - case GL_NO_ERROR: return "GL_NO_ERROR"; - case GL_INVALID_ENUM: return "GL_INVALID_ENUM"; - case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION"; - case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW"; - case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW"; - case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY"; - } - - static char buf[40]; - snprintf(buf, sizeof(buf), "(Unknown GL error code 0x%x)", error); - return buf; -} -static void checkGlError(const char *file, int line) { - GLenum error = glGetError(); - if (error != GL_NO_ERROR) - warning("%s:%d: GL error: %s", file, line, getGlErrStr(error)); -} -#else -#define CHECK_GL_ERROR() do {} while (false) -#endif - // Supported GL extensions static bool npot_supported = false; #ifdef GL_OES_draw_texture @@ -104,8 +66,7 @@ void GLESTexture::initGLExtensions() { const char *ext_string = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)); - __android_log_print(ANDROID_LOG_INFO, LOG_TAG, - "Extensions: %s", ext_string); + LOGI("Extensions: %s", ext_string); Common::StringTokenizer tokenizer(ext_string, " "); while (!tokenizer.empty()) { @@ -126,7 +87,7 @@ GLESTexture::GLESTexture() : _texture_height(0), _all_dirty(true) { - glGenTextures(1, &_texture_name); + GLCALL(glGenTextures(1, &_texture_name)); // This all gets reset later in allocBuffer: _surface.w = 0; @@ -138,12 +99,12 @@ GLESTexture::GLESTexture() : GLESTexture::~GLESTexture() { debug("Destroying texture %u", _texture_name); - glDeleteTextures(1, &_texture_name); + GLCALL(glDeleteTextures(1, &_texture_name)); } void GLESTexture::reinitGL() { - glDeleteTextures(1, &_texture_name); - glGenTextures(1, &_texture_name); + GLCALL(glDeleteTextures(1, &_texture_name)); + GLCALL(glGenTextures(1, &_texture_name)); // bypass allocBuffer() shortcut to reinit the texture properly _texture_width = 0; @@ -154,7 +115,6 @@ void GLESTexture::reinitGL() { } void GLESTexture::allocBuffer(GLuint w, GLuint h) { - CHECK_GL_ERROR(); int bpp = bytesPerPixel(); _surface.w = w; _surface.h = h; @@ -176,33 +136,29 @@ void GLESTexture::allocBuffer(GLuint w, GLuint h) { // Allocate room for the texture now, but pixel data gets uploaded // later (perhaps with multiple TexSubImage2D operations). - CHECK_GL_ERROR(); - glBindTexture(GL_TEXTURE_2D, _texture_name); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - CHECK_GL_ERROR(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - CHECK_GL_ERROR(); - glTexImage2D(GL_TEXTURE_2D, 0, glFormat(), - _texture_width, _texture_height, - 0, glFormat(), glType(), 0); - CHECK_GL_ERROR(); + GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name)); + GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); + GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); + GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); + GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); + GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, glFormat(), + _texture_width, _texture_height, + 0, glFormat(), glType(), 0)); } void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h, const void *buf, int pitch) { - ENTER("updateBuffer(%u, %u, %u, %u, %p, %d)", x, y, w, h, buf, pitch); + ENTER("%u, %u, %u, %u, %p, %d", x, y, w, h, buf, pitch); - glBindTexture(GL_TEXTURE_2D, _texture_name); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name)); + GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); setDirtyRect(Common::Rect(x, y, x+w, y+h)); if (static_cast<int>(w) * bytesPerPixel() == pitch) { - glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, - glFormat(), glType(), buf); + GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, + glFormat(), glType(), buf)); } else { // GLES removed the ability to specify pitch, so we // have to do this ourselves. @@ -221,15 +177,15 @@ void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h, src += pitch; } while (--count); - glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, - glFormat(), glType(), tmpbuf); + GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, + glFormat(), glType(), tmpbuf)); #else // This version avoids the intermediate copy at the expense of // repeat glTexSubImage2D calls. On some devices this is worse. const byte *src = static_cast<const byte *>(buf); do { - glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, - w, 1, glFormat(), glType(), src); + GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, + w, 1, glFormat(), glType(), src)); ++y; src += pitch; } while (--h); @@ -245,21 +201,21 @@ void GLESTexture::fillBuffer(byte x) { } void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) { - glBindTexture(GL_TEXTURE_2D, _texture_name); + GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name)); #ifdef GL_OES_draw_texture // Great extension, but only works under specific conditions. // Still a work-in-progress - disabled for now. if (false && draw_tex_supported && paletteSize() == 0) { - //glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + //GLCALL(glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)); const GLint crop[4] = { 0, _surface.h, _surface.w, -_surface.h }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); + GLCALL(glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop)); // Android GLES bug? - glColor4ub(0xff, 0xff, 0xff, 0xff); + GLCALL(glColor4ub(0xff, 0xff, 0xff, 0xff)); - glDrawTexiOES(x, y, 0, w, h); + GLCALL(glDrawTexiOES(x, y, 0, w, h)); } else #endif { @@ -272,7 +228,7 @@ void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) { tex_width, tex_height, }; - glTexCoordPointer(2, GL_FIXED, 0, texcoords); + GLCALL(glTexCoordPointer(2, GL_FIXED, 0, texcoords)); const GLshort vertices[] = { x, y, @@ -281,10 +237,10 @@ void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) { x + w, y + h, }; - glVertexPointer(2, GL_SHORT, 0, vertices); + GLCALL(glVertexPointer(2, GL_SHORT, 0, vertices)); assert(ARRAYSIZE(vertices) == ARRAYSIZE(texcoords)); - glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAYSIZE(vertices) / 2); + GLCALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAYSIZE(vertices) / 2)); } _all_dirty = false; @@ -302,7 +258,6 @@ GLESPaletteTexture::~GLESPaletteTexture() { } void GLESPaletteTexture::allocBuffer(GLuint w, GLuint h) { - CHECK_GL_ERROR(); int bpp = bytesPerPixel(); _surface.w = w; _surface.h = h; @@ -360,22 +315,22 @@ void GLESPaletteTexture::uploadTexture() const { const size_t texture_size = paletteSize() + _texture_width * _texture_height * bytesPerPixel(); - glCompressedTexImage2D(GL_TEXTURE_2D, 0, glType(), - _texture_width, _texture_height, - 0, texture_size, _texture); - CHECK_GL_ERROR(); + GLCALL(glCompressedTexImage2D(GL_TEXTURE_2D, 0, glType(), + _texture_width, _texture_height, + 0, texture_size, _texture)); } void GLESPaletteTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) { if (_all_dirty) { - glBindTexture(GL_TEXTURE_2D, _texture_name); - CHECK_GL_ERROR(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - CHECK_GL_ERROR(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - CHECK_GL_ERROR(); + GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name)); + GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + GL_NEAREST)); + GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST)); + GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, + GL_CLAMP_TO_EDGE)); + GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, + GL_CLAMP_TO_EDGE)); uploadTexture(); _all_dirty = false; } |