Add support for non AA lines.

Change-Id: Id5200e94815404d62760437d0d2dbb0a9276c700
diff --git a/libs/hwui/Line.h b/libs/hwui/Line.h
index 75f3321e..820793c 100644
--- a/libs/hwui/Line.h
+++ b/libs/hwui/Line.h
@@ -80,8 +80,12 @@
         glDeleteTextures(1, &mTexture);
     }
 
+    inline float getLength(float x1, float y1, float x2, float y2) {
+        return sqrtf((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+    }
+
     void update(float x1, float y1, float x2, float y2, float lineWidth, float& tx, float& ty) {
-        const float length = sqrtf((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+        const float length = getLength(x1, y1, x2, y2);
         const float half = lineWidth * 0.5f;
 
         mPatch->updateVertices(gLineTextureWidth, gLineTextureHeight,
@@ -89,7 +93,7 @@
                 mXDivs, mYDivs, mXDivsCount, mYDivsCount);
 
         tx = -gLineAABias;
-        ty = -half - gLineAABias;
+        ty = lineWidth == 1.0f ? -gLineAABias : -half - gLineAABias;
     }
 
     inline GLvoid* getVertices() const {
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index ecc02fa..eb85169 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -612,16 +612,29 @@
     const GLfloat g = a * ((color >>  8) & 0xFF) / 255.0f;
     const GLfloat b = a * ((color      ) & 0xFF) / 255.0f;
 
-    GLuint textureUnit = 0;
-    setupTextureAlpha8(mLine.getTexture(), 0, 0, textureUnit, 0.0f, 0.0f, r, g, b, a,
-            mode, false, true, mLine.getVertices(), mLine.getTexCoords());
+    const bool isAA = paint->isAntiAlias();
+    if (isAA) {
+        GLuint textureUnit = 0;
+        setupTextureAlpha8(mLine.getTexture(), 0, 0, textureUnit, 0.0f, 0.0f, r, g, b, a,
+                mode, false, true, mLine.getVertices(), mLine.getTexCoords());
+    } else {
+        setupColorRect(0.0f, 0.0f, 1.0f, 1.0f, r, g, b, a, mode, false);
+    }
+
+    const float strokeWidth = paint->getStrokeWidth();
+    const GLsizei elementsCount = isAA ? mLine.getElementsCount() : gMeshCount;
+    const GLenum drawMode = isAA ? GL_TRIANGLES : GL_TRIANGLE_STRIP;
 
     for (int i = 0; i < count; i += 4) {
         float tx = 0.0f;
         float ty = 0.0f;
 
-        mLine.update(points[i], points[i + 1], points[i + 2], points[i + 3],
-                paint->getStrokeWidth(), tx, ty);
+        if (isAA) {
+            mLine.update(points[i], points[i + 1], points[i + 2], points[i + 3],
+                    strokeWidth, tx, ty);
+        } else {
+            ty = -strokeWidth * 0.5f;
+        }
 
         const float dx = points[i + 2] - points[i];
         const float dy = points[i + 3] - points[i + 1];
@@ -633,13 +646,17 @@
             mModelView.rotate(angle * RAD_TO_DEG, 0.0f, 0.0f, 1.0f);
         }
         mModelView.translate(tx, ty, 0.0f);
+        if (!isAA) {
+            float length = mLine.getLength(points[i], points[i + 1], points[i + 2], points[i + 3]);
+            mModelView.scale(length, strokeWidth, 1.0f);
+        }
         mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
 
         if (mShader) {
             mShader->updateTransforms(mCaches.currentProgram, mModelView, *mSnapshot);
         }
 
-        glDrawArrays(GL_TRIANGLES, 0, mLine.getElementsCount());
+        glDrawArrays(drawMode, 0, elementsCount);
     }
 
     glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
@@ -978,6 +995,14 @@
     const GLfloat g = a * ((color >>  8) & 0xFF) / 255.0f;
     const GLfloat b = a * ((color      ) & 0xFF) / 255.0f;
 
+    setupColorRect(left, top, right, bottom, r, g, b, a, mode, ignoreTransform);
+
+    // Draw the mesh
+    glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
+}
+
+void OpenGLRenderer::setupColorRect(float left, float top, float right, float bottom,
+        float r, float g, float b, float a, SkXfermode::Mode mode, bool ignoreTransform) {
     GLuint textureUnit = 0;
 
     // Describe the required shaders
@@ -990,7 +1015,7 @@
     }
 
     // Setup the blending mode
-    chooseBlending(alpha < 255 || (mShader && mShader->blend()), mode, description);
+    chooseBlending(a < 1.0f || (mShader && mShader->blend()), mode, description);
 
     // Build and use the appropriate shader
     useProgram(mCaches.programCache.get(description));
@@ -1017,9 +1042,6 @@
     if (mColorFilter) {
         mColorFilter->setupProgram(mCaches.currentProgram);
     }
-
-    // Draw the mesh
-    glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
 }
 
 void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index cd7963f..eba0f41 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -189,6 +189,12 @@
             int color, SkXfermode::Mode mode, bool ignoreTransform = false);
 
     /**
+     * Setups shaders to draw a colored rect.
+     */
+    void setupColorRect(float left, float top, float right, float bottom,
+            float r, float g, float b, float a, SkXfermode::Mode mode, bool ignoreTransform);
+
+    /**
      * Draws a textured rectangle with the specified texture. The specified coordinates
      * are transformed by the current snapshot's transform matrix.
      *