Updated the index buffer classes to use Error objects.

BUG=angle:520

Change-Id: Ifc249058a3ed3ffffe163a9e3ec21d6fc8c75bd0
Reviewed-on: https://chromium-review.googlesource.com/217101
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/renderer/d3d/IndexDataManager.cpp b/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
index cd775c1..8d455b4 100644
--- a/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
+++ b/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
@@ -70,7 +70,7 @@
     SafeDelete(mStreamingBufferInt);
 }
 
-GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer *buffer, const GLvoid *indices, TranslatedIndexData *translated)
+gl::Error IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer *buffer, const GLvoid *indices, TranslatedIndexData *translated)
 {
     const gl::Type &typeInfo = gl::GetTypeInfo(type);
 
@@ -83,10 +83,6 @@
 
     if (buffer != NULL)
     {
-        if (reinterpret_cast<uintptr_t>(indices) > std::numeric_limits<unsigned int>::max())
-        {
-            return GL_OUT_OF_MEMORY;
-        }
         offset = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(indices));
 
         storage = BufferD3D::makeBufferD3D(buffer->getImplementation());
@@ -143,10 +139,10 @@
 
     if (!directStorage && !indexBuffer)
     {
-        GLenum err = getStreamingIndexBuffer(destinationIndexType, &indexBuffer);
-        if (err != GL_NO_ERROR)
+        gl::Error error = getStreamingIndexBuffer(destinationIndexType, &indexBuffer);
+        if (error.isError())
         {
-            return err;
+            return error;
         }
 
         unsigned int convertCount = count;
@@ -169,30 +165,30 @@
 
         if (convertCount > std::numeric_limits<unsigned int>::max() / destTypeInfo.bytes)
         {
-            ERR("Reserving %u indicies of %u bytes each exceeds the maximum buffer size.", convertCount, destTypeInfo.bytes);
-            return GL_OUT_OF_MEMORY;
+            return gl::Error(GL_OUT_OF_MEMORY, "Reserving %u indices of %u bytes each exceeds the maximum buffer size.",
+                             convertCount, destTypeInfo.bytes);
         }
 
         unsigned int bufferSizeRequired = convertCount * destTypeInfo.bytes;
-        if (!indexBuffer->reserveBufferSpace(bufferSizeRequired, type))
+        error = indexBuffer->reserveBufferSpace(bufferSizeRequired, type);
+        if (error.isError())
         {
-            ERR("Failed to reserve %u bytes in an index buffer.", bufferSizeRequired);
-            return GL_OUT_OF_MEMORY;
+            return error;
         }
 
         void* output = NULL;
-        if (!indexBuffer->mapBuffer(bufferSizeRequired, &output, &streamOffset))
+        error = indexBuffer->mapBuffer(bufferSizeRequired, &output, &streamOffset);
+        if (error.isError())
         {
-            ERR("Failed to map index buffer.");
-            return GL_OUT_OF_MEMORY;
+            return error;
         }
 
         ConvertIndices(type, destinationIndexType, staticBuffer ? storage->getData() : indices, convertCount, output);
 
-        if (!indexBuffer->unmapBuffer())
+        error = indexBuffer->unmapBuffer();
+        if (error.isError())
         {
-            ERR("Failed to unmap index buffer.");
-            return GL_OUT_OF_MEMORY;
+            return error;
         }
 
         if (staticBuffer)
@@ -214,10 +210,10 @@
         storage->promoteStaticUsage(count * typeInfo.bytes);
     }
 
-    return GL_NO_ERROR;
+    return gl::Error(GL_NO_ERROR);
 }
 
-GLenum IndexDataManager::getStreamingIndexBuffer(GLenum destinationIndexType, IndexBufferInterface **outBuffer)
+gl::Error IndexDataManager::getStreamingIndexBuffer(GLenum destinationIndexType, IndexBufferInterface **outBuffer)
 {
     ASSERT(outBuffer);
     if (destinationIndexType == GL_UNSIGNED_INT)
@@ -225,16 +221,16 @@
         if (!mStreamingBufferInt)
         {
             mStreamingBufferInt = new StreamingIndexBufferInterface(mRenderer);
-            if (!mStreamingBufferInt->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT))
+            gl::Error error = mStreamingBufferInt->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT);
+            if (error.isError())
             {
                 SafeDelete(mStreamingBufferInt);
-                ERR("Failed to allocate the streaming GL_UNSIGNED_INT index buffer.");
-                return GL_OUT_OF_MEMORY;
+                return error;
             }
         }
 
         *outBuffer = mStreamingBufferInt;
-        return GL_NO_ERROR;
+        return gl::Error(GL_NO_ERROR);
     }
     else
     {
@@ -243,16 +239,16 @@
         if (!mStreamingBufferShort)
         {
             mStreamingBufferShort = new StreamingIndexBufferInterface(mRenderer);
-            if (!mStreamingBufferShort->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_SHORT))
+            gl::Error error = mStreamingBufferShort->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_SHORT);
+            if (error.isError())
             {
                 SafeDelete(mStreamingBufferShort);
-                ERR("Failed to allocate the streaming GL_UNSIGNED_SHORT index buffer.");
-                return GL_OUT_OF_MEMORY;
+                return error;
             }
         }
 
         *outBuffer = mStreamingBufferShort;
-        return GL_NO_ERROR;
+        return gl::Error(GL_NO_ERROR);
     }
 }