Merge "Maybe fix issue #2881233: reboot loop at boot on stingray"
diff --git a/core/java/android/app/BackStackEntry.java b/core/java/android/app/BackStackEntry.java
index 7291438..d63b862 100644
--- a/core/java/android/app/BackStackEntry.java
+++ b/core/java/android/app/BackStackEntry.java
@@ -409,6 +409,7 @@
                     if (mAddToBackStack) {
                         f.mBackStackNesting--;
                     }
+                    f.mImmediateActivity = null;
                     mManager.removeFragment(f,
                             FragmentManager.reverseTransit(mTransition),
                             mTransitionStyle);
@@ -418,6 +419,7 @@
                     if (mAddToBackStack) {
                         f.mBackStackNesting--;
                     }
+                    f.mImmediateActivity = null;
                     mManager.removeFragment(f,
                             FragmentManager.reverseTransit(mTransition),
                             mTransitionStyle);
@@ -427,6 +429,7 @@
                             if (mAddToBackStack) {
                                 old.mBackStackNesting--;
                             }
+                            f.mImmediateActivity = mManager.mActivity;
                             mManager.addFragment(old, false);
                         }
                     }
@@ -436,6 +439,7 @@
                     if (mAddToBackStack) {
                         f.mBackStackNesting--;
                     }
+                    f.mImmediateActivity = mManager.mActivity;
                     mManager.addFragment(f, false);
                 } break;
                 case OP_HIDE: {
diff --git a/include/camera/Camera.h b/include/camera/Camera.h
index 9974f2f..964700b 100644
--- a/include/camera/Camera.h
+++ b/include/camera/Camera.h
@@ -1,6 +1,5 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
- * Copyright (C) 2008 HTC Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/include/media/IMediaRecorder.h b/include/media/IMediaRecorder.h
index cfc17a5..54adca8 100644
--- a/include/media/IMediaRecorder.h
+++ b/include/media/IMediaRecorder.h
@@ -1,6 +1,6 @@
 /*
  **
- ** Copyright 2008, HTC Inc.
+ ** Copyright 2008, The Android Open Source Project
  **
  ** Licensed under the Apache License, Version 2.0 (the "License");
  ** you may not use this file except in compliance with the License.
diff --git a/include/media/PVMediaRecorder.h b/include/media/PVMediaRecorder.h
index f75d80d..c091c39 100644
--- a/include/media/PVMediaRecorder.h
+++ b/include/media/PVMediaRecorder.h
@@ -1,6 +1,6 @@
 /*
  **
- ** Copyright 2008, HTC Inc.
+ ** Copyright 2008, The Android Open Source Project
  **
  ** Licensed under the Apache License, Version 2.0 (the "License");
  ** you may not use this file except in compliance with the License.
diff --git a/libs/camera/Camera.cpp b/libs/camera/Camera.cpp
index 0037399..7efc6d7 100644
--- a/libs/camera/Camera.cpp
+++ b/libs/camera/Camera.cpp
@@ -1,7 +1,6 @@
 /*
 **
 ** Copyright (C) 2008, The Android Open Source Project
-** Copyright (C) 2008 HTC Inc.
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 6074ec8..5595ab0 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -327,7 +327,6 @@
     mTextTexture = new unsigned char[mCacheWidth * mCacheHeight];
     mUploadTexture = false;
 
-    glActiveTexture(GL_TEXTURE0);
     glGenTextures(1, &mTextureId);
     glBindTexture(GL_TEXTURE_2D, mTextureId);
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
diff --git a/libs/hwui/GenerationCache.h b/libs/hwui/GenerationCache.h
index 5c1b5e1..45b3ffa 100644
--- a/libs/hwui/GenerationCache.h
+++ b/libs/hwui/GenerationCache.h
@@ -34,13 +34,12 @@
 struct Entry: public LightRefBase<Entry<EntryKey, EntryValue> > {
     Entry() { }
     Entry(const Entry<EntryKey, EntryValue>& e):
-            key(e.key), value(e.value), index(e.index), parent(e.parent), child(e.child) { }
+            key(e.key), value(e.value), parent(e.parent), child(e.child) { }
     Entry(sp<Entry<EntryKey, EntryValue> > e):
-            key(e->key), value(e->value), index(e->index), parent(e->parent), child(e->child) { }
+            key(e->key), value(e->value), parent(e->parent), child(e->child) { }
 
     EntryKey key;
     EntryValue value;
-    ssize_t index;
 
     sp<Entry<EntryKey, EntryValue> > parent;
     sp<Entry<EntryKey, EntryValue> > child;
@@ -156,7 +155,7 @@
 void GenerationCache<K, V>::addToCache(sp<Entry<K, V> > entry, K key, V value) {
     entry->key = key;
     entry->value = value;
-    entry->index = mCache.add(key, entry);
+    mCache.add(key, entry);
     attachToCache(entry);
 }
 
@@ -185,7 +184,10 @@
 template<typename K, typename V>
 V GenerationCache<K, V>::removeOldest() {
     if (mOldest.get()) {
-        return removeAt(mOldest->index);
+        ssize_t index = mCache.indexOfKey(mOldest->key);
+        if (index >= 0) {
+            return removeAt(index);
+        }
     }
 
     return NULL;
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 3d9aa26..3c36f95 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -144,11 +144,13 @@
 
     memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices));
 
-    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxTextureUnits);
-    if (mMaxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
+    mFirstSnapshot = new Snapshot;
+
+    GLint maxTextureUnits;
+    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
+    if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
         LOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
     }
-    mLastTexture[0] = mLastTexture[1] = mLastTexture[2] = 0;
 }
 
 OpenGLRenderer::~OpenGLRenderer() {
@@ -171,11 +173,11 @@
 
     mWidth = width;
     mHeight = height;
-    mFirstSnapshot.height = height;
+    mFirstSnapshot->height = height;
 }
 
 void OpenGLRenderer::prepare() {
-    mSnapshot = &mFirstSnapshot;
+    mSnapshot = mFirstSnapshot;
     mSaveCount = 0;
 
     glDisable(GL_SCISSOR_TEST);
@@ -265,10 +267,6 @@
     glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight());
 
     Layer* layer = current->layer;
-
-    // Compute the correct texture coordinates for the FBO texture
-    // The texture is currently as big as the window but drawn with
-    // a quad of the appropriate size
     const Rect& rect = layer->layer;
 
     drawTextureRect(rect.left, rect.top, rect.right, rect.bottom,
@@ -323,7 +321,6 @@
 
 bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
         float right, float bottom, int alpha, SkXfermode::Mode mode,int flags) {
-
     LAYER_LOGD("Requesting layer %fx%f", right - left, bottom - top);
     LAYER_LOGD("Layer cache size = %d", mLayerCache.getSize());
 
@@ -537,8 +534,6 @@
         return;
     }
 
-    glActiveTexture(GL_TEXTURE0);
-
     float length;
     switch (paint->getTextAlign()) {
         case SkPaint::kCenter_Align:
@@ -687,7 +682,6 @@
 
 void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right, float bottom,
         float alpha, SkXfermode::Mode mode) {
-    glActiveTexture(GL_TEXTURE1);
     Texture* texture = mGradientCache.get(mShaderKey);
     if (!texture) {
         SkShader::TileMode tileMode = SkShader::kClamp_TileMode;
@@ -714,8 +708,8 @@
     mCurrentProgram->set(mOrthoMatrix, mModelView, mSnapshot->transform);
 
     chooseBlending(mShaderBlend || alpha < 1.0f, mode);
-    bindTexture(texture->id, mShaderTileX, mShaderTileY, 1);
-    glUniform1i(mCurrentProgram->getUniform("gradientSampler"), 1);
+    bindTexture(texture->id, mShaderTileX, mShaderTileY, 0);
+    glUniform1i(mCurrentProgram->getUniform("gradientSampler"), 0);
 
     Rect start(mShaderBounds[0], mShaderBounds[1], mShaderBounds[2], mShaderBounds[3]);
     if (mShaderMatrix) {
@@ -747,7 +741,6 @@
 
 void OpenGLRenderer::drawBitmapShader(float left, float top, float right, float bottom,
         float alpha, SkXfermode::Mode mode) {
-    glActiveTexture(GL_TEXTURE2);
     const Texture* texture = mTextureCache.get(mShaderBitmap);
 
     const float width = texture->width;
@@ -782,8 +775,8 @@
     chooseBlending(texture->blend || alpha < 1.0f, mode);
 
     // Texture
-    bindTexture(texture->id, mShaderTileX, mShaderTileY, 2);
-    glUniform1i(mCurrentProgram->getUniform("bitmapSampler"), 2);
+    bindTexture(texture->id, mShaderTileX, mShaderTileY, 0);
+    glUniform1i(mCurrentProgram->getUniform("bitmapSampler"), 0);
     glUniformMatrix4fv(mCurrentProgram->getUniform("textureTransform"), 1,
             GL_FALSE, &textureTransform.data[0]);
     glUniform2f(mCurrentProgram->getUniform("textureDimension"), 1.0f / width, 1.0f / height);
@@ -917,10 +910,7 @@
 
 void OpenGLRenderer::bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT, GLuint textureUnit) {
     glActiveTexture(gTextureUnits[textureUnit]);
-    if (texture != mLastTexture[textureUnit]) {
-        glBindTexture(GL_TEXTURE_2D, texture);
-        mLastTexture[textureUnit] = texture;
-    }
+    glBindTexture(GL_TEXTURE_2D, texture);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
 }
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 5e5c021..937ff08 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -315,7 +315,7 @@
     // Number of saved states
     int mSaveCount;
     // Base state
-    Snapshot mFirstSnapshot;
+    sp<Snapshot> mFirstSnapshot;
     // Current state
     sp<Snapshot> mSnapshot;
 
@@ -325,10 +325,6 @@
     // Used to draw textured quads
     TextureVertex mMeshVertices[4];
 
-    // Current texture state
-    GLuint mLastTexture[REQUIRED_TEXTURE_UNITS_COUNT];
-    GLint mMaxTextureUnits;
-
     // Last known blend state
     bool mBlend;
     GLenum mLastSrcMode;
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index cc7fde9..020bdb0 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -50,7 +50,7 @@
      * assumed to be dirty. The specified snapshot is stored as the previous
      * snapshot.
      */
-    Snapshot(const sp<Snapshot> s):
+    Snapshot(const sp<Snapshot>& s):
             height(s->height),
             transform(s->transform),
             clipRect(s->clipRect),
diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp
index e9971a2..bed0fce 100644
--- a/libs/rs/rsScriptC_LibGL.cpp
+++ b/libs/rs/rsScriptC_LibGL.cpp
@@ -91,6 +91,12 @@
 // VP
 //////////////////////////////////////////////////////////////////////////////
 
+static void SC_vpLoadProjectionMatrix(const rsc_Matrix *m)
+{
+    GET_TLS();
+    rsc->getVertex()->setProjectionMatrix(m);
+}
+
 static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
 {
     GET_TLS();
@@ -355,6 +361,7 @@
     { "rsgBindSampler", (void *)&SC_bindSampler },
     { "rsgBindTexture", (void *)&SC_bindTexture },
 
+    { "rsgProgramVertexLoadProjectionMatrix", (void *)&SC_vpLoadProjectionMatrix },
     { "rsgProgramVertexLoadModelMatrix", (void *)&SC_vpLoadModelMatrix },
     { "rsgProgramVertexLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix },
 
diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh
index 4dc351d..d6ef6e9 100644
--- a/libs/rs/scriptc/rs_graphics.rsh
+++ b/libs/rs/scriptc/rs_graphics.rsh
@@ -13,6 +13,7 @@
 extern void rsgBindSampler(rs_program_fragment, int slot, rs_sampler);
 extern void rsgBindTexture(rs_program_fragment, int slot, rs_allocation);
 
+extern void rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *);
 extern void rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *);
 extern void rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *);
 
diff --git a/media/libmedia/IMediaRecorder.cpp b/media/libmedia/IMediaRecorder.cpp
index 9fe207c..4eb63e8 100644
--- a/media/libmedia/IMediaRecorder.cpp
+++ b/media/libmedia/IMediaRecorder.cpp
@@ -1,6 +1,6 @@
 /*
  **
- ** Copyright 2008, HTC Inc.
+ ** Copyright 2008, The Android Open Source Project
  **
  ** Licensed under the Apache License, Version 2.0 (the "License");
  ** you may not use this file except in compliance with the License.
diff --git a/media/libmediaplayerservice/MediaRecorderClient.cpp b/media/libmediaplayerservice/MediaRecorderClient.cpp
index fef3e6e..73862c3 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.cpp
+++ b/media/libmediaplayerservice/MediaRecorderClient.cpp
@@ -1,5 +1,5 @@
 /*
- ** Copyright 2008, HTC Inc.
+ ** Copyright 2008, The Android Open Source Project
  **
  ** Licensed under the Apache License, Version 2.0 (the "License");
  ** you may not use this file except in compliance with the License.
diff --git a/media/libmediaplayerservice/MediaRecorderClient.h b/media/libmediaplayerservice/MediaRecorderClient.h
index d12e558..1d1913d 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.h
+++ b/media/libmediaplayerservice/MediaRecorderClient.h
@@ -1,6 +1,6 @@
 /*
  **
- ** Copyright 2008, HTC Inc.
+ ** Copyright 2008, The Android Open Source Project
  **
  ** Licensed under the Apache License, Version 2.0 (the "License");
  ** you may not use this file except in compliance with the License.
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index c786f94..3b3904a 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -1,7 +1,6 @@
 /*
 **
 ** Copyright (C) 2008, The Android Open Source Project
-** Copyright (C) 2008 HTC Inc.
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index b0b2d7a..77ccf41 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -1,7 +1,6 @@
 /*
 **
 ** Copyright (C) 2008, The Android Open Source Project
-** Copyright (C) 2008 HTC Inc.
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
diff --git a/tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java b/tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java
index abd741c..0cd1426 100644
--- a/tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java
+++ b/tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java
@@ -78,7 +78,7 @@
             mScaledShader.setLocalMatrix(m2);
 
             mHorGradient = new LinearGradient(0.0f, 0.0f, mDrawWidth, 0.0f,
-                    Color.RED, Color.GREEN, Shader.TileMode.REPEAT);
+                    Color.RED, Color.GREEN, Shader.TileMode.CLAMP);
             
             mDiagGradient = new LinearGradient(0.0f, 0.0f, mDrawWidth / 1.5f, mDrawHeight,
                     Color.BLUE, Color.MAGENTA, Shader.TileMode.CLAMP);