From a636d41ca8c066adfed4fd16d9a2e46de5fab871 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 24 Feb 2011 18:24:27 +0100 Subject: [PATCH] ANDROID: Check thread origin when debugging GL --- backends/platform/android/android.cpp | 3 +++ backends/platform/android/android.h | 10 +++++++++- backends/platform/android/gfx.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 36399873cdc8..4968e4bba158 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); diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index 8fc138d42b47..23c1e85a4388 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -61,7 +61,7 @@ extern const char *android_log_tag; #ifdef ANDROID_DEBUG_ENTER #define ENTER(fmt, args...) LOGD("%s(" fmt ")", __FUNCTION__, ##args) #else -#define ENTER(fmt, args...) /**/ +#define ENTER(fmt, args...) do { } while (false) #endif #ifdef ANDROID_DEBUG_GL @@ -73,8 +73,14 @@ extern void checkGlError(const char *expr, const char *file, int line); checkGlError(#x, __FILE__, __LINE__); \ } while (false) +#define GLTHREADCHECK \ + do { \ + assert(pthread_self() == _main_thread); \ + } while (false) + #else #define GLCALL(x) do { (x); } while (false) +#define GLTHREADCHECK do { } while (false) #endif #ifdef DYNAMIC_MODULES @@ -111,6 +117,8 @@ class OSystem_Android : public BaseBackend, public PaletteManager { Common::Queue _event_queue; MutexRef _event_queue_lock; + pthread_t _main_thread; + bool _timer_thread_exit; pthread_t _timer_thread; static void *timerThreadFunc(void *arg); diff --git a/backends/platform/android/gfx.cpp b/backends/platform/android/gfx.cpp index d4d96a239c33..a84e5ce4a05b 100644 --- a/backends/platform/android/gfx.cpp +++ b/backends/platform/android/gfx.cpp @@ -119,6 +119,8 @@ void OSystem_Android::initSize(uint width, uint height, const Graphics::PixelFormat *format) { ENTER("%d, %d, %p", width, height, format); + GLTHREADCHECK; + _game_texture->allocBuffer(width, height); GLuint overlay_width = _egl_surface_width; @@ -157,6 +159,8 @@ int16 OSystem_Android::getWidth() { void OSystem_Android::setPalette(const byte *colors, uint start, uint num) { ENTER("%p, %u, %u", colors, start, num); + GLTHREADCHECK; + if (!_use_mouse_palette) _setCursorPalette(colors, start, num); @@ -166,6 +170,8 @@ void OSystem_Android::setPalette(const byte *colors, uint start, uint num) { void OSystem_Android::grabPalette(byte *colors, uint start, uint num) { ENTER("%p, %u, %u", colors, start, num); + GLTHREADCHECK; + memcpy(colors, _game_texture->palette_const() + start * 3, num * 3); } @@ -173,12 +179,16 @@ 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); + GLTHREADCHECK; + _game_texture->updateBuffer(x, y, w, h, buf, pitch); } void OSystem_Android::updateScreen() { //ENTER(); + GLTHREADCHECK; + if (!_force_redraw && !_game_texture->dirty() && !_overlay_texture->dirty() && @@ -279,6 +289,8 @@ void OSystem_Android::updateScreen() { Graphics::Surface *OSystem_Android::lockScreen() { ENTER(); + GLTHREADCHECK; + Graphics::Surface *surface = _game_texture->surface(); assert(surface->pixels); @@ -288,6 +300,8 @@ Graphics::Surface *OSystem_Android::lockScreen() { void OSystem_Android::unlockScreen() { ENTER(); + GLTHREADCHECK; + assert(_game_texture->dirty()); } @@ -303,6 +317,8 @@ void OSystem_Android::setShakePos(int shake_offset) { void OSystem_Android::fillScreen(uint32 col) { ENTER("%u", col); + GLTHREADCHECK; + assert(col < 256); _game_texture->fillBuffer(col); } @@ -342,6 +358,8 @@ void OSystem_Android::hideOverlay() { void OSystem_Android::clearOverlay() { ENTER(); + GLTHREADCHECK; + _overlay_texture->fillBuffer(0); // Shouldn't need this, but works around a 'blank screen' bug on Nexus1 @@ -351,6 +369,8 @@ void OSystem_Android::clearOverlay() { void OSystem_Android::grabOverlay(OverlayColor *buf, int pitch) { ENTER("%p, %d", buf, pitch); + GLTHREADCHECK; + // 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... @@ -371,6 +391,8 @@ 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); + GLTHREADCHECK; + const Graphics::Surface *surface = _overlay_texture->surface_const(); assert(surface->bytesPerPixel == sizeof(buf[0])); @@ -411,6 +433,8 @@ void OSystem_Android::setMouseCursor(const byte *buf, uint w, uint h, ENTER("%p, %u, %u, %d, %d, %u, %d, %p", buf, w, h, hotspotX, hotspotY, keycolor, cursorTargetScale, format); + GLTHREADCHECK; + assert(keycolor < 256); _mouse_texture->allocBuffer(w, h); @@ -452,6 +476,8 @@ void OSystem_Android::setCursorPalette(const byte *colors, uint start, uint num) { ENTER("%p, %u, %u", colors, start, num); + GLTHREADCHECK; + _setCursorPalette(colors, start, num); _use_mouse_palette = true; }