Improve rendering performance on some GPUs

This change sets textures filtering to GL_NEAREST by default. GL_LINEAR
filtering is only used when textures are transformed with a scale or
a rotation. This helps save a couple of fps on some GPUs.

Change-Id: I1efaa452c2c79905f00238e54d886a37203a2ac1
diff --git a/libs/hwui/Texture.h b/libs/hwui/Texture.h
index c6ae326..48229b6 100644
--- a/libs/hwui/Texture.h
+++ b/libs/hwui/Texture.h
@@ -35,16 +35,45 @@
 
         minFilter = GL_NEAREST;
         magFilter = GL_NEAREST;
+
+        firstFilter = true;
+        firstWrap = true;
     }
 
-    void setWrap(GLenum wrapS, GLenum wrapT) {
-        this->wrapS = wrapS;
-        this->wrapT = wrapT;
+    void setWrap(GLenum wrapS, GLenum wrapT, bool bindTexture = false, bool force = false,
+            GLenum renderTarget = GL_TEXTURE_2D) {
+
+        if (firstWrap || force || wrapS != this->wrapS || wrapT != this->wrapT) {
+            firstWrap = true;
+
+            this->wrapS = wrapS;
+            this->wrapT = wrapT;
+
+            if (bindTexture) {
+                glBindTexture(renderTarget, id);
+            }
+
+            glTexParameteri(renderTarget, GL_TEXTURE_WRAP_S, wrapS);
+            glTexParameteri(renderTarget, GL_TEXTURE_WRAP_T, wrapT);
+        }
     }
 
-    void setFilter(GLenum min, GLenum mag) {
-        minFilter = min;
-        magFilter = mag;
+    void setFilter(GLenum min, GLenum mag, bool bindTexture = false, bool force = false,
+            GLenum renderTarget = GL_TEXTURE_2D) {
+
+        if (firstFilter || force || min != minFilter || mag != magFilter) {
+            firstFilter = false;
+
+            minFilter = min;
+            magFilter = mag;
+
+            if (bindTexture) {
+                glBindTexture(renderTarget, id);
+            }
+
+            glTexParameteri(renderTarget, GL_TEXTURE_MIN_FILTER, min);
+            glTexParameteri(renderTarget, GL_TEXTURE_MAG_FILTER, mag);
+        }
     }
 
     /**
@@ -87,6 +116,10 @@
      */
     GLenum minFilter;
     GLenum magFilter;
+
+private:
+    bool firstFilter;
+    bool firstWrap;
 }; // struct Texture
 
 class AutoTexture {