Move the IndexRangeCache and Range types to the gl namespace.

BUG=angleproject:881

Change-Id: Ib05149facee9fcc7714cb957ca8647b3498a36b6
Reviewed-on: https://chromium-review.googlesource.com/269254
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp
index a5332e3..9379c29 100644
--- a/src/common/utilities.cpp
+++ b/src/common/utilities.cpp
@@ -366,6 +366,33 @@
     return FirstCubeMapTextureTarget + static_cast<GLenum>(index);
 }
 
+template <class IndexType>
+static RangeUI ComputeTypedIndexRange(const IndexType *indices, GLsizei count)
+{
+    ASSERT(count > 0);
+    IndexType minIndex = indices[0];
+    IndexType maxIndex = indices[0];
+
+    for (GLsizei i = 1; i < count; i++)
+    {
+        if (minIndex > indices[i]) minIndex = indices[i];
+        if (maxIndex < indices[i]) maxIndex = indices[i];
+    }
+
+    return RangeUI(static_cast<GLuint>(minIndex), static_cast<GLuint>(maxIndex));
+}
+
+RangeUI ComputeIndexRange(GLenum indexType, const GLvoid *indices, GLsizei count)
+{
+    switch (indexType)
+    {
+      case GL_UNSIGNED_BYTE:  return ComputeTypedIndexRange(static_cast<const GLubyte*>(indices), count);
+      case GL_UNSIGNED_SHORT: return ComputeTypedIndexRange(static_cast<const GLushort*>(indices), count);
+      case GL_UNSIGNED_INT:   return ComputeTypedIndexRange(static_cast<const GLuint*>(indices), count);
+      default: UNREACHABLE(); return RangeUI(0, 0);
+    }
+}
+
 bool IsTriangleMode(GLenum drawMode)
 {
     switch (drawMode)