diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-05 16:39:41 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-05 16:39:41 +0000 |
commit | 495157b9916a9f5cfb845cc929aaaf403b4a4d13 (patch) | |
tree | 1caf89e7520310ae3b7102e3349a6668f541fa2a /platform_tools | |
parent | d4adfa37fb33fa0779da6401d7befbee14bb49df (diff) |
Fix SampleApp for devices who don't support the full OpenGL API
R=bsalomon@google.com, ernstm@google.com
Author: djsollen@google.com
Review URL: https://codereview.chromium.org/137223006
git-svn-id: http://skia.googlecode.com/svn/trunk@13322 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'platform_tools')
-rw-r--r-- | platform_tools/android/app/src/com/skia/SkiaSampleView.java | 80 |
1 files changed, 45 insertions, 35 deletions
diff --git a/platform_tools/android/app/src/com/skia/SkiaSampleView.java b/platform_tools/android/app/src/com/skia/SkiaSampleView.java index b1f7318319..cf06bea6a8 100644 --- a/platform_tools/android/app/src/com/skia/SkiaSampleView.java +++ b/platform_tools/android/app/src/com/skia/SkiaSampleView.java @@ -16,6 +16,7 @@ import android.content.Context; import android.opengl.EGL14; import android.opengl.GLSurfaceView; import android.os.Build; +import android.util.Log; import android.view.MotionEvent; public class SkiaSampleView extends GLSurfaceView { @@ -187,37 +188,30 @@ public class SkiaSampleView extends GLSurfaceView { } private class SampleViewEGLConfigChooser implements GLSurfaceView.EGLConfigChooser { - private int[] mValue; @Override public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { - mValue = new int[1]; - - int glAPIToTry; - - if (mRequestedOpenGLAPI) { - glAPIToTry = EGL14.EGL_OPENGL_API; - } else { - glAPIToTry = EGL14.EGL_OPENGL_ES_API; - } - int numConfigs = 0; int[] configSpec = null; - - do { - EGL14.eglBindAPI(glAPIToTry); - - int renderableType; - if (glAPIToTry == EGL14.EGL_OPENGL_API) { + int[] value = new int[1]; + + int[] validAPIs = new int[] { + EGL14.EGL_OPENGL_API, + EGL14.EGL_OPENGL_ES_API + }; + int initialAPI = mRequestedOpenGLAPI ? 0 : 1; + + for (int i = initialAPI; i < validAPIs.length && numConfigs == 0; i++) { + int currentAPI = validAPIs[i]; + EGL14.eglBindAPI(currentAPI); + + // setup the renderableType which will only be included in the + // spec if we are attempting to get access to the OpenGL APIs. + int renderableType = EGL14.EGL_OPENGL_BIT; + if (currentAPI == EGL14.EGL_OPENGL_API) { renderableType = EGL14.EGL_OPENGL_ES2_BIT; - - // If this API does not work, try ES next. - glAPIToTry = EGL14.EGL_OPENGL_ES_API; - } else { - renderableType = EGL14.EGL_OPENGL_BIT; } - if (mRequestedMSAASampleCount > 0) { configSpec = new int[] { EGL10.EGL_RED_SIZE, 8, @@ -226,17 +220,25 @@ public class SkiaSampleView extends GLSurfaceView { EGL10.EGL_ALPHA_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 0, EGL10.EGL_STENCIL_SIZE, 8, - EGL10.EGL_RENDERABLE_TYPE, renderableType, EGL10.EGL_SAMPLE_BUFFERS, 1, EGL10.EGL_SAMPLES, mRequestedMSAASampleCount, + EGL10.EGL_RENDERABLE_TYPE, renderableType, EGL10.EGL_NONE }; - if (!egl.eglChooseConfig(display, configSpec, null, 0, mValue)) { - throw new IllegalArgumentException("Could not get MSAA context count"); + // EGL_RENDERABLE_TYPE is only needed when attempting to use + // the OpenGL API (not ES) and causes many EGL drivers to fail + // with a BAD_ATTRIBUTE error. + if (!mRequestedOpenGLAPI) { + configSpec[16] = EGL10.EGL_NONE; + Log.i("Skia", "spec: " + configSpec); + } + + if (!egl.eglChooseConfig(display, configSpec, null, 0, value)) { + Log.i("Skia", "Could not get MSAA context count: " + mRequestedMSAASampleCount); } - numConfigs = mValue[0]; + numConfigs = value[0]; } if (numConfigs <= 0) { @@ -251,14 +253,21 @@ public class SkiaSampleView extends GLSurfaceView { EGL10.EGL_RENDERABLE_TYPE, renderableType, EGL10.EGL_NONE }; + + // EGL_RENDERABLE_TYPE is only needed when attempting to use + // the OpenGL API (not ES) and causes many EGL drivers to fail + // with a BAD_ATTRIBUTE error. + if (!mRequestedOpenGLAPI) { + configSpec[12] = EGL10.EGL_NONE; + Log.i("Skia", "spec: " + configSpec); + } - if (!egl.eglChooseConfig(display, configSpec, null, 0, mValue)) { - throw new IllegalArgumentException("Could not get non-MSAA context count"); + if (!egl.eglChooseConfig(display, configSpec, null, 0, value)) { + Log.i("Skia", "Could not get non-MSAA context count"); } - numConfigs = mValue[0]; + numConfigs = value[0]; } - - } while (glAPIToTry != EGL14.EGL_OPENGL_ES_API && numConfigs == 0); + } if (numConfigs <= 0) { throw new IllegalArgumentException("No configs match configSpec"); @@ -266,7 +275,7 @@ public class SkiaSampleView extends GLSurfaceView { // Get all matching configurations. EGLConfig[] configs = new EGLConfig[numConfigs]; - if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, mValue)) { + if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, value)) { throw new IllegalArgumentException("Could not get config data"); } @@ -286,8 +295,9 @@ public class SkiaSampleView extends GLSurfaceView { private int findConfigAttrib(EGL10 egl, EGLDisplay display, EGLConfig config, int attribute, int defaultValue) { - if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) { - return mValue[0]; + int[] value = new int[1]; + if (egl.eglGetConfigAttrib(display, config, attribute, value)) { + return value[0]; } return defaultValue; } |