Use Range type for index ranges.

This compacts a lot of parameter passing. Refactoring patch only.

BUG=angle:571

Change-Id: Ic918478d0c6b81093bfea6154ce0f6bf1d2b5be2
Reviewed-on: https://chromium-review.googlesource.com/210645
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/renderer/d3d/IndexDataManager.cpp b/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
index 98716c1..45d7d37 100644
--- a/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
+++ b/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
@@ -95,33 +95,34 @@
 }
 
 template <class IndexType>
-static void computeRange(const IndexType *indices, GLsizei count, GLuint *minIndex, GLuint *maxIndex)
+static RangeUI computeRange(const IndexType *indices, GLsizei count)
 {
-    *minIndex = indices[0];
-    *maxIndex = indices[0];
+    unsigned int minIndex = indices[0];
+    unsigned int maxIndex = indices[0];
 
-    for (GLsizei i = 0; i < count; i++)
+    for (GLsizei i = 1; i < count; i++)
     {
-        if (*minIndex > indices[i]) *minIndex = indices[i];
-        if (*maxIndex < indices[i]) *maxIndex = indices[i];
+        if (minIndex > indices[i]) minIndex = indices[i];
+        if (maxIndex < indices[i]) maxIndex = indices[i];
     }
+
+    return RangeUI(minIndex, maxIndex);
 }
 
-static void computeRange(GLenum type, const GLvoid *indices, GLsizei count, GLuint *minIndex, GLuint *maxIndex)
+static RangeUI computeRange(GLenum type, const GLvoid *indices, GLsizei count)
 {
-    if (type == GL_UNSIGNED_BYTE)
+    switch (type)
     {
-        computeRange(static_cast<const GLubyte*>(indices), count, minIndex, maxIndex);
+      case GL_UNSIGNED_BYTE:
+        return computeRange(static_cast<const GLubyte*>(indices), count);
+      case GL_UNSIGNED_INT:
+        return computeRange(static_cast<const GLuint*>(indices), count);
+      case GL_UNSIGNED_SHORT:
+        return computeRange(static_cast<const GLushort*>(indices), count);
+      default:
+        UNREACHABLE();
+        return RangeUI();
     }
-    else if (type == GL_UNSIGNED_INT)
-    {
-        computeRange(static_cast<const GLuint*>(indices), count, minIndex, maxIndex);
-    }
-    else if (type == GL_UNSIGNED_SHORT)
-    {
-        computeRange(static_cast<const GLushort*>(indices), count, minIndex, maxIndex);
-    }
-    else UNREACHABLE();
 }
 
 GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer *buffer, const GLvoid *indices, TranslatedIndexData *translated)
@@ -183,35 +184,31 @@
     {
         streamOffset = offset;
 
-        if (!storage->getIndexRangeCache()->findRange(type, offset, count, &translated->minIndex,
-                                                     &translated->maxIndex, NULL))
+        if (!storage->getIndexRangeCache()->findRange(type, offset, count, &translated->indexRange, NULL))
         {
-            computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
-            storage->getIndexRangeCache()->addRange(type, offset, count, translated->minIndex,
-                                                   translated->maxIndex, offset);
+            translated->indexRange = computeRange(type, indices, count);
+            storage->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, offset);
         }
     }
     else if (staticBuffer && staticBuffer->getBufferSize() != 0 && staticBuffer->getIndexType() == type && alignedOffset)
     {
         indexBuffer = staticBuffer;
 
-        if (!staticBuffer->getIndexRangeCache()->findRange(type, offset, count, &translated->minIndex,
-                                                           &translated->maxIndex, &streamOffset))
+        if (!staticBuffer->getIndexRangeCache()->findRange(type, offset, count, &translated->indexRange, &streamOffset))
         {
             streamOffset = (offset / typeInfo.bytes) * gl::GetTypeInfo(destinationIndexType).bytes;
-            computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
-            staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->minIndex,
-                                                         translated->maxIndex, streamOffset);
+            translated->indexRange = computeRange(type, indices, count);
+            staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, streamOffset);
         }
     }
     else
     {
-        computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
+        translated->indexRange = computeRange(type, indices, count);
     }
 
     // Avoid D3D11's primitive restart index value
     // see http://msdn.microsoft.com/en-us/library/windows/desktop/bb205124(v=vs.85).aspx
-    if (translated->maxIndex == 0xFFFF && type == GL_UNSIGNED_SHORT && mRenderer->getMajorShaderModel() > 3)
+    if (translated->indexRange.end == 0xFFFF && type == GL_UNSIGNED_SHORT && mRenderer->getMajorShaderModel() > 3)
     {
         destinationIndexType = GL_UNSIGNED_INT;
         directStorage = false;
@@ -277,8 +274,7 @@
         if (staticBuffer)
         {
             streamOffset = (offset / typeInfo.bytes) * destTypeInfo.bytes;
-            staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->minIndex,
-                                                         translated->maxIndex, streamOffset);
+            staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, streamOffset);
         }
     }