Merge change 27177 into eclair

* changes:
  Add auto-brightness mode to the list of backed-up settings
diff --git a/opengl/libs/Android.mk b/opengl/libs/Android.mk
index 9578452..d6c7114 100644
--- a/opengl/libs/Android.mk
+++ b/opengl/libs/Android.mk
@@ -32,6 +32,10 @@
 LOCAL_CFLAGS += -DADRENO130=1
 endif
 
+ifeq ($(TARGET_BOARD_PLATFORM),qsd8k)
+LOCAL_CFLAGS += -DADRENO130=1
+endif
+
 include $(BUILD_SHARED_LIBRARY)
 installed_libEGL := $(LOCAL_INSTALLED_MODULE)
 
diff --git a/opengl/tests/gl2_basic/gl2_basic.cpp b/opengl/tests/gl2_basic/gl2_basic.cpp
index ba9a717..9345de5 100644
--- a/opengl/tests/gl2_basic/gl2_basic.cpp
+++ b/opengl/tests/gl2_basic/gl2_basic.cpp
@@ -44,17 +44,6 @@
     fprintf(stderr, "GL %s = %s\n", name, v);
 }
 
-static const char* eglErrorToString[] = {
-        "EGL_SUCCESS", // 0x3000 12288
-        "EGL_NOT_INITIALIZED",
-        "EGL_BAD_ACCESS", // 0x3002 12290
-        "EGL_BAD_ALLOC", "EGL_BAD_ATTRIBUTE",
-        "EGL_BAD_CONFIG",
-        "EGL_BAD_CONTEXT", // 0x3006 12294
-        "EGL_BAD_CURRENT_SURFACE", "EGL_BAD_DISPLAY", "EGL_BAD_MATCH",
-        "EGL_BAD_NATIVE_PIXMAP", "EGL_BAD_NATIVE_WINDOW", "EGL_BAD_PARAMETER", // 0x300c 12300
-        "EGL_BAD_SURFACE" };
-
 static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) {
     if (returnVal != EGL_TRUE) {
         fprintf(stderr, "%s() returned %d\n", op, returnVal);
@@ -62,11 +51,7 @@
 
     for (EGLint error = eglGetError(); error != EGL_SUCCESS; error
             = eglGetError()) {
-        const char* errorString = "unknown";
-        if (error >= EGL_SUCCESS && error <= EGL_BAD_SURFACE) {
-            errorString = eglErrorToString[error - EGL_SUCCESS];
-        }
-        fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, errorString,
+        fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, EGLUtils::strerror(error),
                 error);
     }
 }
@@ -190,22 +175,33 @@
     checkGlError("glDrawArrays");
 }
 
+#if 0
+
+void PrintEGLConfig(EGLDisplay dpy, EGLConfig config) {
+	int attrib[] = {EGL_RED_SIZE, EGL_GREEN_SIZE, EGL_BLUE_SIZE, EGL_ALPHA_SIZE,
+			EGL_DEPTH_SIZE, EGL_SURFACE_TYPE, EGL_RENDERABLE_TYPE
+	};
+	for(size_t i = 0; i < sizeof(attrib)/sizeof(attrib[0]); i++) {
+        int value = 0;
+        int a = attrib[i];
+        if (eglGetConfigAttrib(dpy, config, a, &value)) {
+            printf(" 0x%04x: %d", a, value);
+        }
+	}
+	printf("\n");
+}
+
+#endif
+
 int main(int argc, char** argv) {
     EGLBoolean returnValue;
-    EGLConfig configs[2];
-    EGLint config_count;
+    EGLConfig myConfig = {0};
 
     EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
-    EGLint s_configAttribs[] = { EGL_BUFFER_SIZE, EGL_DONT_CARE, EGL_RED_SIZE,
-            5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_DEPTH_SIZE, 8,
-            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE };
-
-    EGLint s_configAttribs2[] =
-    {
-            EGL_DEPTH_SIZE,     16,
-            EGL_NONE
-    };
-
+    EGLint s_configAttribs[] = {
+            EGL_SURFACE_TYPE, EGL_PBUFFER_BIT|EGL_WINDOW_BIT,
+            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+            EGL_NONE };
     EGLint majorVersion;
     EGLint minorVersion;
     EGLContext context;
@@ -214,9 +210,6 @@
 
     EGLDisplay dpy;
 
-    EGLNativeWindowType window = 0;
-    window = android_createDisplaySurface();
-
     checkEglError("<init>");
     dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     checkEglError("eglGetDisplay");
@@ -233,43 +226,31 @@
         return 0;
     }
 
-    returnValue = eglGetConfigs(dpy, configs, 2, &config_count);
-    checkEglError("eglGetConfigs", returnValue);
-    fprintf(stderr, "Config count: %d\n", config_count);
-    for (int i = 0; i < config_count; i++) {
-        fprintf(stderr, "%d: 0x%08x\n", i, (unsigned int) configs[i]);
+    EGLNativeWindowType window = android_createDisplaySurface();

+    returnValue = EGLUtils::selectConfigForNativeWindow(dpy, s_configAttribs, window, &myConfig);
+    if (returnValue) {
+    	printf("EGLUtils::selectConfigForNativeWindow() returned %d", returnValue);
+    	return 0;
     }
 
-#if 0
-    EGLConfig config;
-    EGLUtils::selectConfigForNativeWindow(dpy, s_configAttribs, window, &config);
-    checkEglError("EGLUtils::selectConfigForNativeWindow");
-#else
-    int chooseConfigResult = eglChooseConfig(dpy, s_configAttribs2, configs, 2,
-            &config_count);
-    checkEglError("eglChooseConfig", chooseConfigResult);
-    if (chooseConfigResult != EGL_TRUE) {
-        printf("eglChooseConfig failed\n");
-        return 0;
-    }
-#endif
-
-    surface = eglCreateWindowSurface(dpy, configs[0], window, NULL);
+    surface = eglCreateWindowSurface(dpy, myConfig, window, NULL);
     checkEglError("eglCreateWindowSurface");
     if (surface == EGL_NO_SURFACE) {
         printf("gelCreateWindowSurface failed.\n");
         return 0;
     }
-    EGLint gl2_0Attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
 
-    context = eglCreateContext(dpy, configs[0], EGL_NO_CONTEXT, context_attribs);
+    context = eglCreateContext(dpy, myConfig, EGL_NO_CONTEXT, context_attribs);
     checkEglError("eglCreateContext");
     if (context == EGL_NO_CONTEXT) {
         printf("eglCreateContext failed\n");
         return 0;
     }
-    eglMakeCurrent(dpy, surface, surface, context);
-    checkEglError("eglMakeCurrent");
+    returnValue = eglMakeCurrent(dpy, surface, surface, context);
+    checkEglError("eglMakeCurrent", returnValue);
+    if (returnValue != EGL_TRUE) {
+        return 0;
+    }
     eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
     checkEglError("eglQuerySurface");
     eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
diff --git a/opengl/tests/gl2_jni/Android.mk b/opengl/tests/gl2_jni/Android.mk
index ff15814..81247df 100644
--- a/opengl/tests/gl2_jni/Android.mk
+++ b/opengl/tests/gl2_jni/Android.mk
@@ -44,8 +44,6 @@
 
 LOCAL_MODULE := libgl2jni
 
-LOCAL_ARM_MODE := arm
-
 LOCAL_PRELINK_MODULE := false
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/opengl/tests/gl2_jni/jni/gl_code.cpp b/opengl/tests/gl2_jni/jni/gl_code.cpp
index 146d52a..c2fabe6 100644
--- a/opengl/tests/gl2_jni/jni/gl_code.cpp
+++ b/opengl/tests/gl2_jni/jni/gl_code.cpp
@@ -3,12 +3,12 @@
 #include <nativehelper/jni.h>
 #define LOG_TAG "GL2JNI gl_code.cpp"
 #include <utils/Log.h>
-

+
 #include <EGL/egl.h>
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 
-#include <stdio.h>

+#include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 
@@ -23,7 +23,7 @@
         LOGI("after %s() glError (0x%x)\n", op, error);
     }
 }
-

+
 static const char gVertexShader[] = "attribute vec4 vPosition;\n"
     "void main() {\n"
     "  gl_Position = vPosition;\n"
@@ -151,15 +151,15 @@
 extern "C" {
     JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj,  jint width, jint height);
     JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_step(JNIEnv * env, jobject obj);
-};

-

-JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj,  jint width, jint height)

-{

-    setupGraphics(width, height);

-}

+};
 
-JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_step(JNIEnv * env, jobject obj)

-{

-    renderFrame();

-}

+JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj,  jint width, jint height)

+{
+    setupGraphics(width, height);
+}
+
+JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_step(JNIEnv * env, jobject obj)
+{
+    renderFrame();
+}
 
diff --git a/opengl/tests/gl2_jni/src/com/android/gl2jni/GL2JNIView.java b/opengl/tests/gl2_jni/src/com/android/gl2jni/GL2JNIView.java
index baa10af..2dae090 100644
--- a/opengl/tests/gl2_jni/src/com/android/gl2jni/GL2JNIView.java
+++ b/opengl/tests/gl2_jni/src/com/android/gl2jni/GL2JNIView.java
@@ -44,6 +44,7 @@
 import javax.microedition.khronos.egl.EGLContext;
 import javax.microedition.khronos.egl.EGLDisplay;
 import javax.microedition.khronos.opengles.GL10;
+
 /**
  * An implementation of SurfaceView that uses the dedicated surface for
  * displaying an OpenGL animation.  This allows the animation to run in a
@@ -67,13 +68,14 @@
 
     private void init() {
         setEGLContextFactory(new ContextFactory());
-        // setEGLConfigChooser(new ConfigChooser());
+        setEGLConfigChooser(new ConfigChooser());
         setRenderer(new Renderer());
     }
 
     private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
         private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
         public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
+            Log.w(TAG, "creating OpenGL ES 2.0 context");
             checkEglError("Before eglCreateContext", egl);
             int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
             EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
@@ -83,7 +85,7 @@
 
         public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
             egl.eglDestroyContext(display, context);
-        } 
+        }
     }
 
     private static void checkEglError(String prompt, EGL10 egl) {
@@ -95,11 +97,13 @@
 
     private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser {
         private static int EGL_OPENGL_ES2_BIT = 4;
-        private static int[]  s_configAttribs2 =
+        private static int[] s_configAttribs2 =
         {
-                EGL10.EGL_DEPTH_SIZE,     16,
-                // EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
-                EGL10.EGL_NONE
+            EGL10.EGL_RED_SIZE, 4,
+            EGL10.EGL_GREEN_SIZE, 4,
+            EGL10.EGL_BLUE_SIZE, 4,
+            EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+            EGL10.EGL_NONE
         };
         public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
 
@@ -108,6 +112,7 @@
 
             int numConfigs = num_config[0];
 
+            Log.w(TAG, String.format("Found %d configurations", numConfigs));
             if (numConfigs <= 0) {
                 throw new IllegalArgumentException("No configs match configSpec");
             }