Skip to content

Commit

Permalink
ANDROID: Check thread origin when debugging GL
Browse files Browse the repository at this point in the history
  • Loading branch information
dhewg committed Feb 24, 2011
1 parent 3613544 commit a636d41
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions backends/platform/android/android.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
10 changes: 9 additions & 1 deletion backends/platform/android/android.h
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -111,6 +117,8 @@ class OSystem_Android : public BaseBackend, public PaletteManager {
Common::Queue<Common::Event> _event_queue;
MutexRef _event_queue_lock;

pthread_t _main_thread;

bool _timer_thread_exit;
pthread_t _timer_thread;
static void *timerThreadFunc(void *arg);
Expand Down
26 changes: 26 additions & 0 deletions backends/platform/android/gfx.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -166,19 +170,25 @@ 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);
}

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() &&
Expand Down Expand Up @@ -279,6 +289,8 @@ void OSystem_Android::updateScreen() {
Graphics::Surface *OSystem_Android::lockScreen() {
ENTER();

GLTHREADCHECK;

Graphics::Surface *surface = _game_texture->surface();
assert(surface->pixels);

Expand All @@ -288,6 +300,8 @@ Graphics::Surface *OSystem_Android::lockScreen() {
void OSystem_Android::unlockScreen() {
ENTER();

GLTHREADCHECK;

assert(_game_texture->dirty());
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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...
Expand All @@ -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]));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a636d41

Please sign in to comment.