Move some methods of VertexDataManager to helper methods.

Refactoring patch only.

BUG=angle:571

Change-Id: Ic318b4c4366e33b8d33f6003dd39f660f40d354a
Reviewed-on: https://chromium-review.googlesource.com/210649
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Shannon Woods <shannonwoods@chromium.org>
diff --git a/src/libGLESv2/renderer/d3d/VertexDataManager.cpp b/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
index 2e0d1da..f6aa255 100644
--- a/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
+++ b/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
@@ -92,29 +92,14 @@
         return GL_OUT_OF_MEMORY;
     }
 
+    // Invalidate static buffers that don't contain matching attributes
     for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
     {
         translated[attributeIndex].active = (programBinary->getSemanticIndex(attributeIndex) != -1);
-    }
 
-    // Invalidate static buffers that don't contain matching attributes
-    for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
-    {
-        if (translated[i].active && attribs[i].enabled)
+        if (translated[attributeIndex].active && attribs[attributeIndex].enabled)
         {
-            gl::Buffer *buffer = attribs[i].buffer.get();
-
-            if (buffer)
-            {
-                BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation());
-                StaticVertexBufferInterface *staticBuffer = bufferImpl->getStaticVertexBuffer();
-
-                if (staticBuffer && staticBuffer->getBufferSize() > 0 && !staticBuffer->lookupAttribute(attribs[i], NULL) &&
-                    !staticBuffer->directStoragePossible(attribs[i], currentValues[i]))
-                {
-                    bufferImpl->invalidateStaticData();
-                }
-            }
+            invalidateMatchingStaticData(attribs[attributeIndex], currentValues[attributeIndex]);
         }
     }
 
@@ -123,34 +108,9 @@
     {
         if (translated[i].active && attribs[i].enabled)
         {
-            gl::Buffer *buffer = attribs[i].buffer.get();
-            BufferD3D *bufferImpl = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL;
-            StaticVertexBufferInterface *staticBuffer = bufferImpl ? bufferImpl->getStaticVertexBuffer() : NULL;
-            VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
-
-            if (!vertexBuffer->directStoragePossible(attribs[i], currentValues[i]))
+            if (!reserveSpaceForAttrib(attribs[i], currentValues[i], count, instances))
             {
-                if (staticBuffer)
-                {
-                    if (staticBuffer->getBufferSize() == 0)
-                    {
-                        int totalCount = ElementsInBuffer(attribs[i], bufferImpl->getSize());
-                        if (!staticBuffer->reserveVertexSpace(attribs[i], totalCount, 0))
-                        {
-                            return GL_OUT_OF_MEMORY;
-                        }
-                    }
-                }
-                else
-                {
-                    int totalCount = StreamingBufferElementCount(attribs[i], count, instances);
-                    ASSERT(!bufferImpl || ElementsInBuffer(attribs[i], bufferImpl->getSize()) >= totalCount);
-
-                    if (!mStreamingBuffer->reserveVertexSpace(attribs[i], totalCount, instances))
-                    {
-                        return GL_OUT_OF_MEMORY;
-                    }
-                }
+                return GL_OUT_OF_MEMORY;
             }
         }
     }
@@ -203,6 +163,64 @@
     return GL_NO_ERROR;
 }
 
+void VertexDataManager::invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
+                                                     const gl::VertexAttribCurrentValueData &currentValue) const
+{
+    gl::Buffer *buffer = attrib.buffer.get();
+
+    if (buffer)
+    {
+        BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation());
+        StaticVertexBufferInterface *staticBuffer = bufferImpl->getStaticVertexBuffer();
+
+        if (staticBuffer &&
+            staticBuffer->getBufferSize() > 0 &&
+            !staticBuffer->lookupAttribute(attrib, NULL) &&
+            !staticBuffer->directStoragePossible(attrib, currentValue))
+        {
+            bufferImpl->invalidateStaticData();
+        }
+    }
+}
+
+bool VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
+                                              const gl::VertexAttribCurrentValueData &currentValue,
+                                              GLsizei count,
+                                              GLsizei instances) const
+{
+    gl::Buffer *buffer = attrib.buffer.get();
+    BufferD3D *bufferImpl = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL;
+    StaticVertexBufferInterface *staticBuffer = bufferImpl ? bufferImpl->getStaticVertexBuffer() : NULL;
+    VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
+
+    if (!vertexBuffer->directStoragePossible(attrib, currentValue))
+    {
+        if (staticBuffer)
+        {
+            if (staticBuffer->getBufferSize() == 0)
+            {
+                int totalCount = ElementsInBuffer(attrib, bufferImpl->getSize());
+                if (!staticBuffer->reserveVertexSpace(attrib, totalCount, 0))
+                {
+                    return false;
+                }
+            }
+        }
+        else
+        {
+            int totalCount = StreamingBufferElementCount(attrib, count, instances);
+            ASSERT(!bufferImpl || ElementsInBuffer(attrib, bufferImpl->getSize()) >= totalCount);
+
+            if (!mStreamingBuffer->reserveVertexSpace(attrib, totalCount, instances))
+            {
+                return false;
+            }
+        }
+    }
+
+    return true;
+}
+
 GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
                                          const gl::VertexAttribCurrentValueData &currentValue,
                                          TranslatedAttribute *translated,
diff --git a/src/libGLESv2/renderer/d3d/VertexDataManager.h b/src/libGLESv2/renderer/d3d/VertexDataManager.h
index 78124b6..9b27a44 100644
--- a/src/libGLESv2/renderer/d3d/VertexDataManager.h
+++ b/src/libGLESv2/renderer/d3d/VertexDataManager.h
@@ -58,6 +58,14 @@
   private:
     DISALLOW_COPY_AND_ASSIGN(VertexDataManager);
 
+    bool reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
+                               const gl::VertexAttribCurrentValueData &currentValue,
+                               GLsizei count,
+                               GLsizei instances) const;
+
+    void invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
+                                      const gl::VertexAttribCurrentValueData &currentValue) const;
+
     GLenum storeAttribute(const gl::VertexAttribute &attrib,
                           const gl::VertexAttribCurrentValueData &currentValue,
                           TranslatedAttribute *translated,