Fix count of elements in buffer

There can be one extra element at the end even if an entire stride doesn't fit.

BUG=
TEST=

Review URL: http://codereview.appspot.com/5401046

git-svn-id: https://angleproject.googlecode.com/svn/trunk@884 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/common/version.h b/src/common/version.h
index c7a4ba7..c908530 100644
--- a/src/common/version.h
+++ b/src/common/version.h
@@ -1,7 +1,7 @@
 #define MAJOR_VERSION 0
 #define MINOR_VERSION 0
 #define BUILD_VERSION 0
-#define BUILD_REVISION 883
+#define BUILD_REVISION 884
 
 #define STRINGIFY(x) #x
 #define MACRO_STRINGIFY(x) STRINGIFY(x)
diff --git a/src/libGLESv2/VertexDataManager.cpp b/src/libGLESv2/VertexDataManager.cpp
index d0245ef..698d8b9 100644
--- a/src/libGLESv2/VertexDataManager.cpp
+++ b/src/libGLESv2/VertexDataManager.cpp
@@ -29,6 +29,12 @@
 {
 unsigned int VertexBuffer::mCurrentSerial = 1;
 
+int elementsInBuffer(const VertexAttribute &attribute, int size)
+{
+    int stride = attribute.stride();
+    return (size - attribute.mOffset % stride + (stride - attribute.typeSize())) / stride;
+}
+
 VertexDataManager::VertexDataManager(Context *context, IDirect3DDevice9 *device) : mContext(context), mDevice(device)
 {
     for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
@@ -137,7 +143,7 @@
             {
                 if (staticBuffer->size() == 0)
                 {
-                    int totalCount = buffer->size() / attribs[i].stride();
+                    int totalCount = elementsInBuffer(attribs[i], buffer->size());
                     staticBuffer->addRequiredSpace(spaceRequired(attribs[i], totalCount));
                 }
                 else if (staticBuffer->lookupAttribute(attribs[i]) == -1)
@@ -216,7 +222,7 @@
                     if (streamOffset == -1)
                     {
                         // Convert the entire buffer
-                        int totalCount = buffer->size() / attribs[i].stride();
+                        int totalCount = elementsInBuffer(attribs[i], buffer->size());
                         int startIndex = attribs[i].mOffset / attribs[i].stride();
 
                         streamOffset = writeAttributeData(staticBuffer, -startIndex, totalCount, attribs[i]);