Generalize Context scratch buffer errors.

This refactor will allow us to generate different error types in
different backends. This makes Vulkan happy because it won't have to
generate gl::Errors and can stay with vk::Error.

Bug: angleproject:2713
Change-Id: I981402450f3b519d4f79851982547695d583355a
Reviewed-on: https://chromium-review.googlesource.com/1128921
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Frank Henigman <fjhenigman@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/TextureD3D.cpp b/src/libANGLE/renderer/d3d/TextureD3D.cpp
index 3d82eec..d016e4e 100644
--- a/src/libANGLE/renderer/d3d/TextureD3D.cpp
+++ b/src/libANGLE/renderer/d3d/TextureD3D.cpp
@@ -723,7 +723,8 @@
     zeroDataUnpackState.alignment = 1;
 
     angle::MemoryBuffer *zeroBuffer = nullptr;
-    ANGLE_TRY(context->getZeroFilledBuffer(imageBytes, &zeroBuffer));
+    ANGLE_TRY_ALLOCATION(context->getZeroFilledBuffer(imageBytes, &zeroBuffer));
+
     if (shouldUseSetData(image))
     {
         ANGLE_TRY(mTexStorage->setData(context, imageIndex, image, nullptr, formatInfo.type,
diff --git a/src/libANGLE/renderer/d3d/VertexDataManager.cpp b/src/libANGLE/renderer/d3d/VertexDataManager.cpp
index ca9a116..8e53155 100644
--- a/src/libANGLE/renderer/d3d/VertexDataManager.cpp
+++ b/src/libANGLE/renderer/d3d/VertexDataManager.cpp
@@ -206,11 +206,7 @@
 {
     mStreamingBuffer.reset(
         new StreamingVertexBufferInterface(mFactory, INITIAL_STREAM_BUFFER_SIZE));
-    if (!mStreamingBuffer)
-    {
-        return gl::OutOfMemory() << "Failed to allocate the streaming vertex buffer.";
-    }
-
+    ANGLE_TRY_ALLOCATION(mStreamingBuffer);
     return gl::NoError();
 }
 
diff --git a/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp b/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp
index 8336932..6f816c2 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp
@@ -502,10 +502,7 @@
         ANGLE_TRY_RESULT(getStagingStorage(context), mMappedStorage);
     }
 
-    if (!mMappedStorage)
-    {
-        return gl::OutOfMemory() << "Failed to allocate mappable internal buffer.";
-    }
+    ANGLE_TRY_ALLOCATION(mMappedStorage);
 
     if ((access & GL_MAP_WRITE_BIT) > 0)
     {
diff --git a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
index 37f5cf7..830d3cc 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
@@ -3649,10 +3649,7 @@
 
 gl::Error Renderer11::getScratchMemoryBuffer(size_t requestedSize, angle::MemoryBuffer **bufferOut)
 {
-    if (!mScratchMemoryBuffer.get(requestedSize, bufferOut))
-    {
-        return gl::OutOfMemory() << "Failed to allocate internal buffer.";
-    }
+    ANGLE_TRY_ALLOCATION(mScratchMemoryBuffer.get(requestedSize, bufferOut));
     return gl::NoError();
 }