Generate shaders to cover all possible cases.

With this change, all the vertex and fragment shaders used by the GL
renderer are now generated based on a program description supplied
by the caller. This allows the renderer to generate a large number
of shaders without having to write all the possible combinations by
hand. The generated shaders are stored in a program cache.

Change-Id: If54d286e77ae021c724d42090da476df12a18ebb
diff --git a/libs/hwui/Program.cpp b/libs/hwui/Program.cpp
index 6e60808..86fc154 100644
--- a/libs/hwui/Program.cpp
+++ b/libs/hwui/Program.cpp
@@ -27,7 +27,6 @@
 
 #define SHADER_SOURCE(name, source) const char* name = #source
 
-#include "shaders/drawColor.vert"
 #include "shaders/drawColor.frag"
 
 #include "shaders/drawTexture.vert"
@@ -127,7 +126,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 DrawColorProgram::DrawColorProgram():
-        Program(gDrawColorVertexShader, gDrawColorFragmentShader) {
+        Program(gDrawTextureVertexShader, gDrawColorFragmentShader) {
     getAttribsAndUniforms();
 }
 
@@ -138,6 +137,7 @@
 
 void DrawColorProgram::getAttribsAndUniforms() {
     position = addAttrib("position");
+    texCoords = addAttrib("texCoords");
     color = addUniform("color");
     transform = addUniform("transform");
 }
@@ -154,11 +154,13 @@
 void DrawColorProgram::use() {
     Program::use();
     glEnableVertexAttribArray(position);
+    glEnableVertexAttribArray(texCoords);
 }
 
 void DrawColorProgram::remove() {
     Program::remove();
     glDisableVertexAttribArray(position);
+    glDisableVertexAttribArray(texCoords);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -167,26 +169,21 @@
 
 DrawTextureProgram::DrawTextureProgram():
         DrawColorProgram(gDrawTextureVertexShader, gDrawTextureFragmentShader) {
-    texCoords = addAttrib("texCoords");
     sampler = addUniform("sampler");
 }
 
 DrawTextureProgram::DrawTextureProgram(const char* vertex, const char* fragment):
         DrawColorProgram(vertex, fragment) {
-    texCoords = addAttrib("texCoords");
     sampler = addUniform("sampler");
 }
 
 void DrawTextureProgram::use() {
     DrawColorProgram::use();
-    glActiveTexture(GL_TEXTURE0);
     glUniform1i(sampler, 0);
-    glEnableVertexAttribArray(texCoords);
 }
 
 void DrawTextureProgram::remove() {
     DrawColorProgram::remove();
-    glDisableVertexAttribArray(texCoords);
 }
 
 ///////////////////////////////////////////////////////////////////////////////