Update Buffers to return Error objects instead of calling gl::error.

BUG=angle:520

Change-Id: I4b6af8e2d4fae97639518e2acd26e2d4be93c925
Reviewed-on: https://chromium-review.googlesource.com/209881
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/libGLESv2.cpp b/src/libGLESv2/libGLESv2.cpp
index 62f98d8..e0443da 100644
--- a/src/libGLESv2/libGLESv2.cpp
+++ b/src/libGLESv2/libGLESv2.cpp
@@ -542,7 +542,12 @@
             return;
         }
 
-        buffer->bufferData(data, size, usage);
+        gl::Error error = buffer->bufferData(data, size, usage);
+        if (error.isError())
+        {
+            context->recordError(error);
+            return;
+        }
     }
 }
 
@@ -598,7 +603,12 @@
             return;
         }
 
-        buffer->bufferSubData(data, size, offset);
+        gl::Error error = buffer->bufferSubData(data, size, offset);
+        if (error.isError())
+        {
+            context->recordError(error);
+            return;
+        }
     }
 }
 
@@ -6780,7 +6790,12 @@
         // if size is zero, the copy is a successful no-op
         if (size > 0)
         {
-            writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
+            gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
+            if (error.isError())
+            {
+                context->recordError(error);
+                return;
+            }
         }
     }
 }
@@ -8379,7 +8394,14 @@
             return NULL;
         }
 
-        return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
+        gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
+        if (error.isError())
+        {
+            context->recordError(error);
+            return NULL;
+        }
+
+        return buffer->getMapPointer();
     }
 
     return NULL;
@@ -8408,7 +8430,12 @@
 
         // TODO: detect if we had corruption. if so, throw an error and return false.
 
-        buffer->unmap();
+        gl::Error error = buffer->unmap();
+        if (error.isError())
+        {
+            context->recordError(error);
+            return GL_FALSE;
+        }
 
         return GL_TRUE;
     }
@@ -8498,7 +8525,14 @@
             return NULL;
         }
 
-        return buffer->mapRange(offset, length, access);
+        gl::Error error = buffer->mapRange(offset, length, access);
+        if (error.isError())
+        {
+            context->recordError(error);
+            return NULL;
+        }
+
+        return buffer->getMapPointer();
     }
 
     return NULL;