Add support for drawPoint() and drawPoints().

Change-Id: I01bef50c08ec3160f8d40dc060b2cf6c2e4d7639
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index a711289..6c454a4 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -879,6 +879,11 @@
     mDescription.hasAlpha8Texture = isAlpha8;
 }
 
+void OpenGLRenderer::setupDrawPoint(float pointSize) {
+    mDescription.isPoint = true;
+    mDescription.pointSize = pointSize;
+}
+
 void OpenGLRenderer::setupDrawColor(int color) {
     setupDrawColor(color, (color >> 24) & 0xFF);
 }
@@ -987,6 +992,11 @@
     }
 }
 
+void OpenGLRenderer::setupDrawPointUniforms() {
+    int slot = mCaches.currentProgram->getUniform("pointSize");
+    glUniform1f(slot, mDescription.pointSize);
+}
+
 void OpenGLRenderer::setupDrawColorUniforms() {
     if (mColorSet || (mShader && mSetShaderColor)) {
         mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA);
@@ -1446,6 +1456,48 @@
     }
 }
 
+void OpenGLRenderer::drawPoints(float* points, int count, SkPaint* paint) {
+    if (mSnapshot->isIgnored()) return;
+
+    // TODO: The paint's cap style defines whether the points are square or circular
+    // TODO: Handle AA for round points
+
+    // A stroke width of 0 has a special meaningin Skia:
+    // it draws an unscaled 1px point
+    const bool isHairLine = paint->getStrokeWidth() == 0.0f;
+
+    int alpha;
+    SkXfermode::Mode mode;
+    getAlphaAndMode(paint, &alpha, &mode);
+
+    int verticesCount = count >> 1;
+    int generatedVerticesCount = 0;
+
+    TextureVertex pointsData[verticesCount];
+    TextureVertex* vertex = &pointsData[0];
+
+    setupDraw();
+    setupDrawPoint(isHairLine ? 1.0f : paint->getStrokeWidth());
+    setupDrawColor(paint->getColor(), alpha);
+    setupDrawColorFilter();
+    setupDrawShader();
+    setupDrawBlending(mode);
+    setupDrawProgram();
+    setupDrawModelViewIdentity();
+    setupDrawColorUniforms();
+    setupDrawColorFilterUniforms();
+    setupDrawPointUniforms();
+    setupDrawShaderIdentityUniforms();
+    setupDrawMesh(vertex);
+
+    for (int i = 0; i < count; i += 2) {
+        TextureVertex::set(vertex++, points[i], points[i + 1], 0.0f, 0.0f);
+        generatedVerticesCount++;
+    }
+
+    glDrawArrays(GL_POINTS, 0, generatedVerticesCount);
+}
+
 void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
     // No need to check against the clip, we fill the clip region
     if (mSnapshot->isIgnored()) return;