[Scummvm-cvs-logs] SF.net SVN: scummvm:[53824] scummvm/branches/branch-1-2-0/backends/platform /android

anguslees at users.sourceforge.net anguslees at users.sourceforge.net
Mon Oct 25 15:30:47 CEST 2010


Revision: 53824
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53824&view=rev
Author:   anguslees
Date:     2010-10-25 13:30:46 +0000 (Mon, 25 Oct 2010)

Log Message:
-----------
ANDROID: Backport fixes from trunk

r53801, r53808: explicit filtering/sorting of eglConfigs; force overlay
redraw to workaround an apparent Nexus1 bug.

Modified Paths:
--------------
    scummvm/branches/branch-1-2-0/backends/platform/android/android.cpp
    scummvm/branches/branch-1-2-0/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java

Property Changed:
----------------
    scummvm/branches/branch-1-2-0/backends/platform/android/android.cpp
    scummvm/branches/branch-1-2-0/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java

Modified: scummvm/branches/branch-1-2-0/backends/platform/android/android.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/backends/platform/android/android.cpp	2010-10-25 13:20:15 UTC (rev 53823)
+++ scummvm/branches/branch-1-2-0/backends/platform/android/android.cpp	2010-10-25 13:30:46 UTC (rev 53824)
@@ -109,7 +109,7 @@
 	env->DeleteLocalRef(cls);
 }
 
-// floating point.	use sparingly.
+// floating point. use sparingly.
 template <class T>
 static inline T scalef(T in, float numerator, float denominator) {
 	return static_cast<float>(in) * numerator / denominator;
@@ -177,7 +177,6 @@
 	GLESPaletteTexture* _game_texture;
 	int _shake_offset;
 	Common::Rect _focus_rect;
-	bool _full_screen_dirty;
 
 	// Overlay layer
 	GLES4444Texture* _overlay_texture;
@@ -320,7 +319,6 @@
 	  _fsFactory(new POSIXFilesystemFactory()),
 	  _asset_archive(new AndroidAssetArchive(am)),
 	  _shake_offset(0),
-	  _full_screen_dirty(false),
 	  _event_queue_lock(createMutex()) {
 }
 
@@ -862,6 +860,9 @@
 void OSystem_Android::clearOverlay() {
 	ENTER("clearOverlay()");
 	_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) {
@@ -887,6 +888,9 @@
 
 	// 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() {


Property changes on: scummvm/branches/branch-1-2-0/backends/platform/android/android.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + /scummvm/branches/gsoc2009-draci/backends/platform/android/android.cpp:41389-44325
/scummvm/trunk/backends/platform/android/android.cpp:53801

Modified: scummvm/branches/branch-1-2-0/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java
===================================================================
--- scummvm/branches/branch-1-2-0/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java	2010-10-25 13:20:15 UTC (rev 53823)
+++ scummvm/branches/branch-1-2-0/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java	2010-10-25 13:30:46 UTC (rev 53824)
@@ -23,6 +23,8 @@
 
 import java.io.File;
 import java.util.concurrent.Semaphore;
+import java.util.Map;
+import java.util.LinkedHashMap;
 
 
 // At least in Android 2.1, eglCreateWindowSurface() requires an
@@ -109,6 +111,51 @@
 		}
 	}
 
+	// For debugging
+	private static final Map<String, Integer> attribs;
+	static {
+		attribs = new LinkedHashMap<String, Integer>();
+		attribs.put("CONFIG_ID", EGL10.EGL_CONFIG_ID);
+		attribs.put("BUFFER_SIZE", EGL10.EGL_BUFFER_SIZE);
+		attribs.put("RED_SIZE", EGL10.EGL_RED_SIZE);
+		attribs.put("GREEN_SIZE", EGL10.EGL_GREEN_SIZE);
+		attribs.put("BLUE_SIZE", EGL10.EGL_BLUE_SIZE);
+		attribs.put("ALPHA_SIZE", EGL10.EGL_ALPHA_SIZE);
+		//attribs.put("BIND_TO_RGB", EGL10.EGL_BIND_TO_TEXTURE_RGB);
+		//attribs.put("BIND_TO_RGBA", EGL10.EGL_BIND_TO_TEXTURE_RGBA);
+		attribs.put("CONFIG_CAVEAT", EGL10.EGL_CONFIG_CAVEAT);
+		attribs.put("DEPTH_SIZE", EGL10.EGL_DEPTH_SIZE);
+		attribs.put("LEVEL", EGL10.EGL_LEVEL);
+		attribs.put("MAX_PBUFFER_WIDTH", EGL10.EGL_MAX_PBUFFER_WIDTH);
+		attribs.put("MAX_PBUFFER_HEIGHT", EGL10.EGL_MAX_PBUFFER_HEIGHT);
+		attribs.put("MAX_PBUFFER_PIXELS", EGL10.EGL_MAX_PBUFFER_PIXELS);
+		//attribs.put("MAX_SWAP_INTERVAL", EGL10.EGL_MAX_SWAP_INTERVAL);
+		//attribs.put("MIN_SWAP_INTERVAL", EGL10.EGL_MIN_SWAP_INTERVAL);
+		attribs.put("NATIVE_RENDERABLE", EGL10.EGL_NATIVE_RENDERABLE);
+		attribs.put("NATIVE_VISUAL_ID", EGL10.EGL_NATIVE_VISUAL_ID);
+		attribs.put("NATIVE_VISUAL_TYPE", EGL10.EGL_NATIVE_VISUAL_TYPE);
+		attribs.put("SAMPLE_BUFFERS", EGL10.EGL_SAMPLE_BUFFERS);
+		attribs.put("SAMPLES", EGL10.EGL_SAMPLES);
+		attribs.put("STENCIL_SIZE", EGL10.EGL_STENCIL_SIZE);
+		attribs.put("SURFACE_TYPE", EGL10.EGL_SURFACE_TYPE);
+		attribs.put("TRANSPARENT_TYPE", EGL10.EGL_TRANSPARENT_TYPE);
+		attribs.put("TRANSPARENT_RED_VALUE", EGL10.EGL_TRANSPARENT_RED_VALUE);
+		attribs.put("TRANSPARENT_GREEN_VALUE", EGL10.EGL_TRANSPARENT_GREEN_VALUE);
+		attribs.put("TRANSPARENT_BLUE_VALUE", EGL10.EGL_TRANSPARENT_BLUE_VALUE);
+	}
+	private void dumpEglConfig(EGLConfig config) {
+		int[] value = new int[1];
+		for (Map.Entry<String, Integer> entry : attribs.entrySet()) {
+			egl.eglGetConfigAttrib(eglDisplay, config,
+								   entry.getValue(), value);
+			if (value[0] == EGL10.EGL_NONE)
+				Log.d(LOG_TAG, entry.getKey() + ": NONE");
+			else
+				Log.d(LOG_TAG, String.format("%s: %d",
+											 entry.getKey(), value[0]));
+		}
+	}
+
 	// Called by ScummVM thread (from initBackend)
 	private void createScummVMGLContext() {
 		egl = (EGL10)EGLContext.getEGL();
@@ -125,24 +172,90 @@
 		EGLConfig[] configs = new EGLConfig[numConfigs];
 		egl.eglChooseConfig(eglDisplay, configSpec, configs, numConfigs,
 							num_config);
-		eglConfig = configs[0];
 
+		if (false) {
+			Log.d(LOG_TAG,
+				  String.format("Found %d EGL configurations.", numConfigs));
+			for (EGLConfig config : configs)
+				dumpEglConfig(config);
+		}
+
+		// Android's eglChooseConfig is busted in several versions and
+		// devices so we have to filter/rank the configs again ourselves.
+		eglConfig = chooseEglConfig(configs);
+		if (false) {
+			Log.d(LOG_TAG,
+				  String.format("Chose EGL config from %d possibilities.", numConfigs));
+			dumpEglConfig(eglConfig);
+		}
+
 		eglContext = egl.eglCreateContext(eglDisplay, eglConfig,
 										  EGL10.EGL_NO_CONTEXT, null);
+		if (eglContext == EGL10.EGL_NO_CONTEXT)
+			throw new RuntimeException("Failed to create context");
 	}
 
+	private EGLConfig chooseEglConfig(EGLConfig[] configs) {
+		int best = 0;
+		int bestScore = -1;
+		int[] value = new int[1];
+		for (int i = 0; i < configs.length; i++) {
+			EGLConfig config = configs[i];
+			int score = 10000;
+			egl.eglGetConfigAttrib(eglDisplay, config,
+								   EGL10.EGL_SURFACE_TYPE, value);
+			if ((value[0] & EGL10.EGL_WINDOW_BIT) == 0)
+				continue;  // must have
+
+			egl.eglGetConfigAttrib(eglDisplay, config,
+								   EGL10.EGL_CONFIG_CAVEAT, value);
+			if (value[0] != EGL10.EGL_NONE)
+				score -= 1000;
+
+			// Must be at least 555, but then smaller is better
+			final int[] colorBits = {EGL10.EGL_RED_SIZE,
+									 EGL10.EGL_GREEN_SIZE,
+									 EGL10.EGL_BLUE_SIZE,
+									 EGL10.EGL_ALPHA_SIZE};
+			for (int component : colorBits) {
+				egl.eglGetConfigAttrib(eglDisplay, config,
+									   component, value);
+				if (value[0] >= 5)
+					score += 10;   // boost if >5 bits accuracy
+				score -= value[0]; // penalize for wasted bits
+			}
+
+			egl.eglGetConfigAttrib(eglDisplay, config,
+								   EGL10.EGL_DEPTH_SIZE, value);
+			score -= value[0];  // penalize for wasted bits
+
+			if (score > bestScore) {
+				best = i;
+				bestScore = score;
+			}
+		}
+
+		if (bestScore < 0) {
+			Log.e(LOG_TAG, "Unable to find an acceptable EGL config, expect badness.");
+			return configs[0];
+		}
+
+		return configs[best];
+	}
+
 	// Called by ScummVM thread
 	static private boolean _log_version = true;
 	protected void setupScummVMSurface() {
 		try {
 			surfaceLock.acquire();
 		} catch (InterruptedException e) {
-			Log.e(this.toString(),
-				  "Interrupted while waiting for surface lock", e);
+			Log.e(LOG_TAG, "Interrupted while waiting for surface lock", e);
 			return;
 		}
 		eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig,
 												nativeSurface, null);
+		if (eglSurface == EGL10.EGL_NO_SURFACE)
+			Log.e(LOG_TAG,  "CreateWindowSurface failed!");
 		egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
 
 		GL10 gl = (GL10)eglContext.getGL();
@@ -302,8 +415,8 @@
 		if (buf_size < 0) {
 			int guess = AUDIO_FRAME_SIZE * sample_rate / 100;  // 10ms of audio
 			Log.w(LOG_TAG, String.format(
-										 "Unable to get min audio buffer size (error %d). Guessing %dB.",
-										 buf_size, guess));
+				"Unable to get min audio buffer size (error %d). Guessing %dB.",
+				buf_size, guess));
 			buf_size = guess;
 		}
 		Log.d(LOG_TAG, String.format("Using %dB buffer for %dHZ audio",


Property changes on: scummvm/branches/branch-1-2-0/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java
___________________________________________________________________
Added: svn:mergeinfo
   + /scummvm/branches/gsoc2009-draci/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java:41389-44325
/scummvm/trunk/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java:53808


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list