Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1250)

Unified Diff: platform_tools/android/app/src/com/skia/SkiaSampleView.java

Issue 137223006: Fix SampleApp for devices who don't support the full OpenGL API (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: platform_tools/android/app/src/com/skia/SkiaSampleView.java
diff --git a/platform_tools/android/app/src/com/skia/SkiaSampleView.java b/platform_tools/android/app/src/com/skia/SkiaSampleView.java
index b1f7318319f8beebc984f23883c381945e33121a..cf06bea6a826526410ad34a94832d9a7be81efb5 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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698