D3D: Add streaming buffer initialize.

This gives us better control over the error returned by the init
routine. Also changes the streaming buffer in VertexDataManager to not
be a unique_ptr.

Bug: angleproject:2738
Change-Id: I3193840dfb71c7574adbe65bc5f9227f4add1fd3
Reviewed-on: https://chromium-review.googlesource.com/1151448
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/VertexDataManager.cpp b/src/libANGLE/renderer/d3d/VertexDataManager.cpp
index fa47053..e9f8df6 100644
--- a/src/libANGLE/renderer/d3d/VertexDataManager.cpp
+++ b/src/libANGLE/renderer/d3d/VertexDataManager.cpp
@@ -197,7 +197,7 @@
 }
 
 VertexDataManager::VertexDataManager(BufferFactoryD3D *factory)
-    : mFactory(factory), mStreamingBuffer(), mCurrentValueCache(gl::MAX_VERTEX_ATTRIBS)
+    : mFactory(factory), mStreamingBuffer(factory), mCurrentValueCache(gl::MAX_VERTEX_ATTRIBS)
 {
 }
 
@@ -207,10 +207,7 @@
 
 gl::Error VertexDataManager::initialize()
 {
-    mStreamingBuffer.reset(
-        new StreamingVertexBufferInterface(mFactory, INITIAL_STREAM_BUFFER_SIZE));
-    ANGLE_TRY_ALLOCATION(mStreamingBuffer);
-    return gl::NoError();
+    return mStreamingBuffer.initialize(INITIAL_STREAM_BUFFER_SIZE);
 }
 
 void VertexDataManager::deinitialize()
@@ -225,8 +222,6 @@
                                                std::vector<TranslatedAttribute> *translatedAttribs,
                                                GLsizei instances)
 {
-    ASSERT(mStreamingBuffer);
-
     const gl::State &state             = context->getGLState();
     const gl::VertexArray *vertexArray = state.getVertexArray();
     const auto &vertexAttributes       = vertexArray->getVertexAttributes();
@@ -410,7 +405,7 @@
     };
 
     // Will trigger unmapping on return.
-    StreamingBufferUnmapper localUnmapper(mStreamingBuffer.get());
+    StreamingBufferUnmapper localUnmapper(&mStreamingBuffer);
 
     // Reserve the required space for the dynamic buffers.
     for (auto attribIndex : dynamicAttribsMask)
@@ -455,7 +450,7 @@
 gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &translatedAttrib,
                                                    GLint start,
                                                    size_t count,
-                                                   GLsizei instances) const
+                                                   GLsizei instances)
 {
     ASSERT(translatedAttrib.attribute && translatedAttrib.binding);
     const auto &attrib  = *translatedAttrib.attribute;
@@ -486,14 +481,14 @@
             return gl::InvalidOperation() << "Vertex buffer is not big enough for the draw call.";
         }
     }
-    return mStreamingBuffer->reserveVertexSpace(attrib, binding, totalCount, instances);
+    return mStreamingBuffer.reserveVertexSpace(attrib, binding, totalCount, instances);
 }
 
 gl::Error VertexDataManager::storeDynamicAttrib(const gl::Context *context,
                                                 TranslatedAttribute *translated,
                                                 GLint start,
                                                 size_t count,
-                                                GLsizei instances) const
+                                                GLsizei instances)
 {
     ASSERT(translated->attribute && translated->binding);
     const auto &attrib  = *translated->attribute;
@@ -531,11 +526,11 @@
     size_t totalCount = gl::ComputeVertexBindingElementCount(binding.getDivisor(), count,
                                                              static_cast<size_t>(instances));
 
-    ANGLE_TRY(mStreamingBuffer->storeDynamicAttribute(
+    ANGLE_TRY(mStreamingBuffer.storeDynamicAttribute(
         attrib, binding, translated->currentValueType, firstVertexIndex,
         static_cast<GLsizei>(totalCount), instances, &streamOffset, sourceData));
 
-    VertexBuffer *vertexBuffer = mStreamingBuffer->getVertexBuffer();
+    VertexBuffer *vertexBuffer = mStreamingBuffer.getVertexBuffer();
 
     translated->vertexBuffer.set(vertexBuffer);
     translated->serial = vertexBuffer->getSerial();
@@ -554,7 +549,8 @@
 
     if (!buffer)
     {
-        buffer.reset(new StreamingVertexBufferInterface(mFactory, CONSTANT_VERTEX_BUFFER_SIZE));
+        buffer.reset(new StreamingVertexBufferInterface(mFactory));
+        ANGLE_TRY(buffer->initialize(CONSTANT_VERTEX_BUFFER_SIZE));
     }
 
     if (cachedState->data != currentValue)