Ambient shadow tessellation improvement.

Using the vertices, instead of ray casting for the triangulation.

This request a dynamic index buffer associated with vertex buffer,
so we update the VertexBuffer to support it.

The ambient shadow could be 3x-6x times faster for circle and rect now.

b/16712006
b/14257173

Change-Id: I2f22a8fe19bc59acee5c18e4a3a395acd5042a66
diff --git a/libs/hwui/VertexBuffer.h b/libs/hwui/VertexBuffer.h
index 3837f88..966fa4e 100644
--- a/libs/hwui/VertexBuffer.h
+++ b/libs/hwui/VertexBuffer.h
@@ -17,6 +17,7 @@
 #ifndef ANDROID_HWUI_VERTEX_BUFFER_H
 #define ANDROID_HWUI_VERTEX_BUFFER_H
 
+#include "utils/MathUtils.h"
 
 namespace android {
 namespace uirenderer {
@@ -26,19 +27,27 @@
     enum Mode {
         kStandard = 0,
         kOnePolyRingShadow = 1,
-        kTwoPolyRingShadow = 2
+        kTwoPolyRingShadow = 2,
+        kIndices = 3
     };
 
     VertexBuffer()
             : mBuffer(0)
+            , mIndices(0)
             , mVertexCount(0)
+            , mIndexCount(0)
+            , mAllocatedVertexCount(0)
+            , mAllocatedIndexCount(0)
             , mByteCount(0)
             , mMode(kStandard)
+            , mReallocBuffer(0)
             , mCleanupMethod(NULL)
+            , mCleanupIndexMethod(NULL)
     {}
 
     ~VertexBuffer() {
         if (mCleanupMethod) mCleanupMethod(mBuffer);
+        if (mCleanupIndexMethod) mCleanupIndexMethod(mIndices);
     }
 
     /**
@@ -59,6 +68,7 @@
             mReallocBuffer = reallocBuffer + vertexCount;
             return reallocBuffer;
         }
+        mAllocatedVertexCount = vertexCount;
         mVertexCount = vertexCount;
         mByteCount = mVertexCount * sizeof(TYPE);
         mReallocBuffer = mBuffer = (void*)new TYPE[vertexCount];
@@ -69,6 +79,17 @@
     }
 
     template <class TYPE>
+    TYPE* allocIndices(int indexCount) {
+        mAllocatedIndexCount = indexCount;
+        mIndexCount = indexCount;
+        mIndices = (void*)new TYPE[indexCount];
+
+        mCleanupIndexMethod = &(cleanup<TYPE>);
+
+        return (TYPE*)mIndices;
+    }
+
+    template <class TYPE>
     void copyInto(const VertexBuffer& srcBuffer, float xOffset, float yOffset) {
         int verticesToCopy = srcBuffer.getVertexCount();
 
@@ -103,9 +124,17 @@
     }
 
     const void* getBuffer() const { return mBuffer; }
+    const void* getIndices() const { return mIndices; }
     const Rect& getBounds() const { return mBounds; }
     unsigned int getVertexCount() const { return mVertexCount; }
     unsigned int getSize() const { return mByteCount; }
+    unsigned int getIndexCount() const { return mIndexCount; }
+    void updateIndexCount(unsigned int newCount)  {
+        mIndexCount = MathUtils::min(newCount, mAllocatedIndexCount);
+    }
+    void updateVertexCount(unsigned int newCount)  {
+        newCount = MathUtils::min(newCount, mAllocatedVertexCount);
+    }
     Mode getMode() const { return mMode; }
 
     void setBounds(Rect bounds) { mBounds = bounds; }
@@ -127,14 +156,22 @@
     }
 
     Rect mBounds;
+
     void* mBuffer;
+    void* mIndices;
+
     unsigned int mVertexCount;
+    unsigned int mIndexCount;
+    unsigned int mAllocatedVertexCount;
+    unsigned int mAllocatedIndexCount;
     unsigned int mByteCount;
+
     Mode mMode;
 
     void* mReallocBuffer; // used for multi-allocation
 
     void (*mCleanupMethod)(void*);
+    void (*mCleanupIndexMethod)(void*);
 };
 
 }; // namespace uirenderer