Fix alpha blending and improve fragment shaders performance.

Change-Id: Ib74f6941d25ca6f6a41708e541174eaa7e8d9bc2
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index e333060..6d041ae 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -469,9 +469,9 @@
 
     // Specify right and bottom as +1.0f from left/top to prevent scaling since the
     // patch mesh already defines the final size
-    drawTextureMesh(left, top, left + 1.0f, top + 1.0f, texture->id, alpha, mode, texture->blend,
-            true, &mesh->vertices[0].position[0], &mesh->vertices[0].texture[0], mesh->indices,
-            mesh->indicesCount);
+    drawTextureMesh(left, top, left + 1.0f, top + 1.0f, texture->id, alpha / 255.0f, mode,
+            texture->blend, true, &mesh->vertices[0].position[0],
+            &mesh->vertices[0].texture[0], mesh->indices, mesh->indicesCount);
 }
 
 void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
@@ -518,7 +518,7 @@
     glEnableVertexAttribArray(mDrawColorShader->position);
     glVertexAttribPointer(mDrawColorShader->position, 2, GL_FLOAT, GL_FALSE,
             gDrawColorVertexStride, p);
-    glVertexAttrib4f(mDrawColorShader->color, r, g, b, a);
+    glUniform4f(mDrawColorShader->color, r, g, b, a);
 
     glDrawArrays(GL_TRIANGLE_STRIP, 0, gDrawColorVertexCount);
 
@@ -558,6 +558,7 @@
 
     glActiveTexture(GL_TEXTURE0);
     glUniform1i(mDrawTextureShader->sampler, 0);
+    glUniform4f(mDrawTextureShader->color, 1.0f, 1.0f, 1.0f, alpha);
 
     glEnableVertexAttribArray(mDrawTextureShader->position);
     glVertexAttribPointer(mDrawTextureShader->position, 2, GL_FLOAT, GL_FALSE,
@@ -567,8 +568,6 @@
     glVertexAttribPointer(mDrawTextureShader->texCoords, 2, GL_FLOAT, GL_FALSE,
             gDrawTextureVertexStride, texCoords);
 
-    glVertexAttrib4f(mDrawTextureShader->color, 1.0f, 1.0f, 1.0f, alpha);
-
     if (!indices) {
         glDrawArrays(GL_TRIANGLE_STRIP, 0, gDrawTextureVertexCount);
     } else {
diff --git a/libs/hwui/Program.cpp b/libs/hwui/Program.cpp
index 2acddfc..819e736 100644
--- a/libs/hwui/Program.cpp
+++ b/libs/hwui/Program.cpp
@@ -126,7 +126,7 @@
 
 void DrawColorProgram::getAttribsAndUniforms() {
     position = addAttrib("position");
-    color = addAttrib("color");
+    color = addUniform("color");
     projection = addUniform("projection");
     modelView = addUniform("modelView");
     transform = addUniform("transform");
diff --git a/libs/hwui/shaders/drawColor.frag b/libs/hwui/shaders/drawColor.frag
index e84c47b..0628850 100644
--- a/libs/hwui/shaders/drawColor.frag
+++ b/libs/hwui/shaders/drawColor.frag
@@ -1,9 +1,9 @@
 SHADER_SOURCE(gDrawColorFragmentShader,
 
-varying lowp vec4 outColor;
+uniform vec4 color;
 
 void main(void) {
-    gl_FragColor = outColor;
+    gl_FragColor = color;
 }
 
 );
diff --git a/libs/hwui/shaders/drawColor.vert b/libs/hwui/shaders/drawColor.vert
index cef6e49..742ed98 100644
--- a/libs/hwui/shaders/drawColor.vert
+++ b/libs/hwui/shaders/drawColor.vert
@@ -1,16 +1,12 @@
 SHADER_SOURCE(gDrawColorVertexShader,
 
 attribute vec4 position;
-attribute vec4 color;
 
 uniform mat4 projection;
 uniform mat4 modelView;
 uniform mat4 transform;
 
-varying vec4 outColor;
-
 void main(void) {
-    outColor = color;
     gl_Position = projection * transform * modelView * position;
 }
 
diff --git a/libs/hwui/shaders/drawTexture.frag b/libs/hwui/shaders/drawTexture.frag
index 5bd420e..0f2aa91 100644
--- a/libs/hwui/shaders/drawTexture.frag
+++ b/libs/hwui/shaders/drawTexture.frag
@@ -1,12 +1,12 @@
 SHADER_SOURCE(gDrawTextureFragmentShader,
 
-varying lowp vec4 outColor;
 varying mediump vec2 outTexCoords;
 
+uniform vec4 color;
 uniform sampler2D sampler;
 
 void main(void) {
-    gl_FragColor = texture2D(sampler, outTexCoords) * outColor;
+    gl_FragColor = texture2D(sampler, outTexCoords) * color;
 }
 
 );
diff --git a/libs/hwui/shaders/drawTexture.vert b/libs/hwui/shaders/drawTexture.vert
index 310a812..8abddb8 100644
--- a/libs/hwui/shaders/drawTexture.vert
+++ b/libs/hwui/shaders/drawTexture.vert
@@ -2,17 +2,14 @@
 
 attribute vec4 position;
 attribute vec2 texCoords;
-attribute vec4 color;
 
 uniform mat4 projection;
 uniform mat4 modelView;
 uniform mat4 transform;
 
-varying vec4 outColor;
 varying vec2 outTexCoords;
 
 void main(void) {
-    outColor = color;
     outTexCoords = texCoords;
     gl_Position = projection * transform * modelView * position;
 }
diff --git a/tests/HwAccelerationTest/src/com/google/android/test/hwui/NinePatchesActivity.java b/tests/HwAccelerationTest/src/com/google/android/test/hwui/NinePatchesActivity.java
index dc8fbcc..3268fbf 100644
--- a/tests/HwAccelerationTest/src/com/google/android/test/hwui/NinePatchesActivity.java
+++ b/tests/HwAccelerationTest/src/com/google/android/test/hwui/NinePatchesActivity.java
@@ -34,6 +34,7 @@
                 FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
         b.setText("9 patches");
         layout.addView(b);
+        layout.setBackgroundColor(0xffffffff);
         
         setContentView(layout);
     }