diff options
Diffstat (limited to 'opengl/java')
-rw-r--r-- | opengl/java/android/opengl/GLSurfaceView.java | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java index fb3747c..8954ec6 100644 --- a/opengl/java/android/opengl/GLSurfaceView.java +++ b/opengl/java/android/opengl/GLSurfaceView.java @@ -29,6 +29,8 @@ import javax.microedition.khronos.opengles.GL; import javax.microedition.khronos.opengles.GL10; import android.content.Context; +import android.content.pm.ConfigurationInfo; +import android.os.SystemProperties; import android.util.AttributeSet; import android.util.Log; import android.view.SurfaceHolder; @@ -685,7 +687,10 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback } public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { int[] num_config = new int[1]; - egl.eglChooseConfig(display, mConfigSpec, null, 0, num_config); + if (!egl.eglChooseConfig(display, mConfigSpec, null, 0, + num_config)) { + throw new IllegalArgumentException("eglChooseConfig failed"); + } int numConfigs = num_config[0]; @@ -695,8 +700,10 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback } EGLConfig[] configs = new EGLConfig[numConfigs]; - egl.eglChooseConfig(display, mConfigSpec, configs, numConfigs, - num_config); + if (!egl.eglChooseConfig(display, mConfigSpec, configs, numConfigs, + num_config)) { + throw new IllegalArgumentException("eglChooseConfig#2 failed"); + } EGLConfig config = chooseConfig(egl, display, configs); if (config == null) { throw new IllegalArgumentException("No config chosen"); @@ -821,11 +828,17 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback */ mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); + if (mEglDisplay == EGL10.EGL_NO_DISPLAY) { + throw new RuntimeException("eglGetDisplay failed"); + } + /* * We can now initialize EGL for that display */ int[] version = new int[2]; - mEgl.eglInitialize(mEglDisplay, version); + if(!mEgl.eglInitialize(mEglDisplay, version)) { + throw new RuntimeException("eglInitialize failed"); + } mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay); /* @@ -1095,6 +1108,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback if (createEglSurface) { gl = (GL10) mEglHelper.createSurface(getHolder()); + sGLThreadManager.checkGLDriver(gl); if (LOG_RENDERER) { Log.w("GLThread", "onSurfaceCreated"); } @@ -1308,9 +1322,14 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback } /* +<<<<<<< HEAD + * Tries to acquire the right to use an EGL + * surface. Does not block. +======= * Tries once to acquire the right to use an EGL * surface. Does not block. Requires that we are already * in the sGLThreadManager monitor when this is called. +>>>>>>> dc49acb0 * @return true if the right to use an EGL surface was acquired. */ public boolean tryAcquireEglSurfaceLocked(GLThread thread) { @@ -1319,6 +1338,10 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback notifyAll(); return true; } + checkGLESVersion(); + if (mMultipleGLESContextsAllowed) { + return true; + } return false; } /* @@ -1332,6 +1355,40 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback notifyAll(); } + public synchronized void checkGLDriver(GL10 gl) { + if (! mGLESDriverCheckComplete) { + checkGLESVersion(); + if (mGLESVersion < kGLES_20) { + String renderer = gl.glGetString(GL10.GL_RENDERER); + mMultipleGLESContextsAllowed = + ! renderer.startsWith(kMSM7K_RENDERER_PREFIX); + notifyAll(); + } + mGLESDriverCheckComplete = true; + } + } + + private void checkGLESVersion() { + if (! mGLESVersionCheckComplete) { + mGLESVersion = SystemProperties.getInt( + "ro.opengles.version", + ConfigurationInfo.GL_ES_VERSION_UNDEFINED); + if (mGLESVersion >= kGLES_20) { + mMultipleGLESContextsAllowed = true; + } + mGLESVersionCheckComplete = true; + } + + } + + private boolean mGLESVersionCheckComplete; + private int mGLESVersion; + private boolean mGLESDriverCheckComplete; + private boolean mMultipleGLESContextsAllowed; + private int mGLContextCount; + private static final int kGLES_20 = 0x20000; + private static final String kMSM7K_RENDERER_PREFIX = + "Q3Dimension MSM7500 "; private GLThread mEglOwner; } |