am cf45b615: Merge "Adding support for GLES3" into klp-dev

* commit 'cf45b615e8e313f405e725370675e5fed783e4ed':
  Adding support for GLES3
diff --git a/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java b/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
index 30a1f67..85159a8 100644
--- a/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
+++ b/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
@@ -68,9 +68,12 @@
                 reportedVersion, getVersionFromPackageManager(mActivity));
 
         assertGlVersionString(1);
-        if (detectedVersion >= 2) {
+        if (detectedVersion == 2) {
             restartActivityWithClientVersion(2);
             assertGlVersionString(2);
+        } else if (detectedVersion == 3) {
+            restartActivityWithClientVersion(3);
+            assertGlVersionString(3);
         }
     }
 
@@ -190,9 +193,6 @@
         String versionString = "" + majorVersion;
         String message = "OpenGL version string '" + mActivity.getVersionString()
                 + "' is not " + majorVersion + ".0+.";
-        if (majorVersion == 2) {
-             versionString = "(2|3)";
-        }
         assertTrue(message, Pattern.matches(".*OpenGL.*ES.*" + versionString + "\\.\\d.*",
                 mActivity.getVersionString()));
     }
diff --git a/tools/device-setup/TestDeviceSetup/Android.mk b/tools/device-setup/TestDeviceSetup/Android.mk
index 39f989e..ba1998c 100644
--- a/tools/device-setup/TestDeviceSetup/Android.mk
+++ b/tools/device-setup/TestDeviceSetup/Android.mk
@@ -27,7 +27,7 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_SDK_VERSION := 17
+LOCAL_SDK_VERSION := current
 
 LOCAL_PACKAGE_NAME := TestDeviceSetup
 
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
index 3614e22..934e67d 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
@@ -23,6 +23,7 @@
 import android.content.res.Configuration;
 import android.os.Bundle;
 
+import java.util.HashSet;
 import java.util.Locale;
 import java.util.concurrent.CountDownLatch;
 
@@ -34,7 +35,7 @@
 
     // work done should be reported in GLES..View
     private CountDownLatch mDone = new CountDownLatch(1);
-    private GLESSurfaceView mGLView;
+    private HashSet<String> mFormats = new HashSet<String>();
 
     /**
      * Other classes can call this function to wait for this activity
@@ -47,6 +48,37 @@
         }
     }
 
+    private void runIterations(int glVersion) {
+        for (int i = 1; i <= glVersion; i++) {
+            final CountDownLatch done = new CountDownLatch(1);
+            final int version = i;
+            DeviceInfoActivity.this.runOnUiThread(new Runnable() {
+              public void run() {
+                setContentView(new GLESSurfaceView(DeviceInfoActivity.this, version, done));
+              }
+            });
+            try {
+                done.await();
+            } catch (InterruptedException e) {
+                // just move on
+            }
+        }
+
+        StringBuilder builder = new StringBuilder();
+        for (String format: mFormats) {
+            builder.append(format);
+            builder.append(";");
+        }
+        DeviceInfoInstrument.addResult(
+                DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS,
+                builder.toString());
+        mDone.countDown();
+    }
+
+    public void addCompressedTextureFormat(String format) {
+        mFormats.add(format);
+    }
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -54,10 +86,12 @@
         ActivityManager am =
                 (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
         ConfigurationInfo info = am.getDeviceConfigurationInfo();
-        boolean useGL20 = (info.reqGlEsVersion >= 0x20000);
-
-        mGLView = new GLESSurfaceView(this, useGL20, mDone);
-        setContentView(mGLView);
+        final int glVersion = (info.reqGlEsVersion & 0xffff0000) >> 16;
+        new Thread() {
+          public void run() {
+            runIterations(glVersion);
+          }
+        }.start();
 
         Configuration con = getResources().getConfiguration();
         String touchScreen = null;
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/GLESSurfaceView.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/GLESSurfaceView.java
index 0ec11b7..b2f2211 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/GLESSurfaceView.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/GLESSurfaceView.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.opengl.GLES20;
+import android.opengl.GLES30;
 import android.opengl.GLSurfaceView;
 import android.util.Log;
 
@@ -30,22 +31,24 @@
 class GLESSurfaceView extends GLSurfaceView {
     private static final String TAG = "GLESSurfaceView";
 
-    private boolean mUseGL20;
-    CountDownLatch mDone;
-
+    private int mGLVersion;//1, 2, 3
+    private CountDownLatch mDone;
+    private DeviceInfoActivity mParent;
     /**
      *
-     * @param context
+     * @param parent
      * @param useGL20 whether to use GLES2.0 API or not inside the view
      * @param done to notify the completion of the task
      */
-    public GLESSurfaceView(Context context, boolean useGL20, CountDownLatch done){
-        super(context);
+    public GLESSurfaceView(DeviceInfoActivity parent, int glVersion, CountDownLatch done){
+        super(parent);
 
-        mUseGL20 = useGL20;
+        mParent = parent;
+        mGLVersion = glVersion;
         mDone = done;
-        if (mUseGL20) {
-            setEGLContextClientVersion(2);
+        if (glVersion > 1) {
+            // Default is 1 so only set if bigger than 1
+            setEGLContextClientVersion(glVersion);
         }
         setRenderer(new OpenGLESRenderer());
     }
@@ -55,30 +58,26 @@
         @Override
         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
             String extensions;
-            if (mUseGL20) {
+            if (mGLVersion == 2) {
                 extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
+            } else if (mGLVersion == 3) {
+                extensions = GLES30.glGetString(GLES30.GL_EXTENSIONS);
             } else {
                 extensions = gl.glGetString(GL10.GL_EXTENSIONS);
             }
             Log.i(TAG, "extensions : " + extensions);
             Scanner scanner = new Scanner(extensions);
             scanner.useDelimiter(" ");
-            StringBuilder builder = new StringBuilder();
             while (scanner.hasNext()) {
                 String ext = scanner.next();
                 if (ext.contains("texture")) {
                     if (ext.contains("compression") || ext.contains("compressed")) {
                         Log.i(TAG, "Compression supported: " + ext);
-                        builder.append(ext);
-                        builder.append(";");
+                        mParent.addCompressedTextureFormat(ext);
                     }
                 }
             }
 
-            DeviceInfoInstrument.addResult(
-                    DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS,
-                    builder.toString());
-
             mDone.countDown();
         }
 
@@ -93,4 +92,4 @@
         }
 
     }
-}
\ No newline at end of file
+}