aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android
diff options
context:
space:
mode:
authordhewg2011-03-03 19:11:42 +0100
committerdhewg2011-03-03 21:29:15 +0100
commit7157454e9b30db91462cb684dd20a61204a7fa43 (patch)
treed872ddaa151171d3262b9f51c80bb27fdb46dfd0 /backends/platform/android
parent3df060b6567d37a1a3bee314a686bb2435e482f6 (diff)
downloadscummvm-rg350-7157454e9b30db91462cb684dd20a61204a7fa43.tar.gz
scummvm-rg350-7157454e9b30db91462cb684dd20a61204a7fa43.tar.bz2
scummvm-rg350-7157454e9b30db91462cb684dd20a61204a7fa43.zip
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.
Diffstat (limited to 'backends/platform/android')
-rw-r--r--backends/platform/android/android.cpp55
-rw-r--r--backends/platform/android/android.h5
-rw-r--r--backends/platform/android/gfx.cpp63
3 files changed, 81 insertions, 42 deletions
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) {
diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index 5db10fb180..bf72f98b01 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -140,7 +140,10 @@ private:
FilesystemFactory *_fsFactory;
timeval _startTime;
- void setupSurface();
+ void initSurface();
+ void deinitSurface();
+ void initViewport();
+
void setupKeymapper();
void _setCursorPalette(const byte *colors, uint start, uint num);
diff --git a/backends/platform/android/gfx.cpp b/backends/platform/android/gfx.cpp
index e2cc854a1d..31e8c4be18 100644
--- a/backends/platform/android/gfx.cpp
+++ b/backends/platform/android/gfx.cpp
@@ -62,20 +62,60 @@ int OSystem_Android::getGraphicsMode() const {
return 1;
}
-void OSystem_Android::setupSurface() {
- ENTER();
+void OSystem_Android::initSurface() {
+ LOGD("initializing surface");
- _screen_changeid = JNI::surface_changeid;
- JNI::initSurface();
+ assert(!JNI::haveSurface());
+ _screen_changeid = JNI::surface_changeid;
_egl_surface_width = JNI::egl_surface_width;
_egl_surface_height = JNI::egl_surface_height;
assert(_egl_surface_width > 0 && _egl_surface_height > 0);
- // EGL set up with a new surface. Initialise OpenGLES context.
+ JNI::initSurface();
+
+ // Initialise OpenGLES context.
GLESTexture::initGLExtensions();
+ if (_game_texture)
+ _game_texture->reinit();
+
+ if (_overlay_texture)
+ _overlay_texture->reinit();
+
+ if (_mouse_texture)
+ _mouse_texture->reinit();
+}
+
+void OSystem_Android::deinitSurface() {
+ if (!JNI::haveSurface())
+ return;
+
+ LOGD("deinitializing surface");
+
+ _screen_changeid = JNI::surface_changeid;
+ _egl_surface_width = 0;
+ _egl_surface_height = 0;
+
+ // release texture resources
+ if (_game_texture)
+ _game_texture->release();
+
+ if (_overlay_texture)
+ _overlay_texture->release();
+
+ if (_mouse_texture)
+ _mouse_texture->release();
+
+ JNI::deinitSurface();
+}
+
+void OSystem_Android::initViewport() {
+ LOGD("initializing viewport");
+
+ assert(JNI::haveSurface());
+
// Turn off anything that looks like 3D ;)
GLCALL(glDisable(GL_CULL_FACE));
GLCALL(glDisable(GL_DEPTH_TEST));
@@ -210,8 +250,8 @@ void OSystem_Android::updateScreen() {
}
if (_focus_rect.isEmpty()) {
- _game_texture->drawTexture(0, 0,
- _egl_surface_width, _egl_surface_height);
+ _game_texture->drawTexture(0, 0, _egl_surface_width,
+ _egl_surface_height);
} else {
GLCALL(glPushMatrix());
GLCALL(glScalex(xdiv(_egl_surface_width, _focus_rect.width()),
@@ -223,8 +263,8 @@ void OSystem_Android::updateScreen() {
xdiv(_game_texture->height(), _egl_surface_height),
1 << 16));
- _game_texture->drawTexture(0, 0,
- _egl_surface_width, _egl_surface_height);
+ _game_texture->drawTexture(0, 0, _egl_surface_width,
+ _egl_surface_height);
GLCALL(glPopMatrix());
}
@@ -234,9 +274,8 @@ void OSystem_Android::updateScreen() {
// 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));
+ GLCALL(_overlay_texture->drawTexture(0, 0, _egl_surface_width,
+ _egl_surface_height));
}
if (_show_mouse) {