Enable asynchronous glReadPixels on Windows.

Chromium is using the GL ES 2.0 spec with ANGLE, which doesn't allow
for async readback on its own.  However, ANGLE also provides two
extensions which, together, provide all the needed extra implementation:
GL_NV_pixel_buffer_object and GL_EXT_map_buffer_range.

This change enables the appropriate feature flags when the two
extensions are present.  It also changes the auto-generated bindings for
the glMapBufferRange function so that glMapBufferRangeEXT is used
instead of glMapBufferRange when ANGLE is initialized below the version
3 spec.

In addition, this change adds propagation of service-side glMapBuffer()
errors back to the glMapBufferCHROMIUM call client-side.  In the process
of writing tests for this, a minor shared memory allocation bug was
revealed and also fixed.

BUG=431420

Review URL: https://codereview.chromium.org/706173005

Cr-Commit-Position: refs/heads/master@{#304340}
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 4d54739..5dd9f64 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -7578,6 +7578,11 @@
     } else {
       data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY);
     }
+    if (!data) {
+      LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glMapBuffer",
+                         "Unable to map memory for readback.");
+      return;
+    }
     memcpy(pixels, data, pixels_size);
     // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't
     // have to restore the state.
@@ -7779,7 +7784,10 @@
       GLuint buffer = 0;
       glGenBuffersARB(1, &buffer);
       glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer);
-      glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, GL_STREAM_READ);
+      // For ANGLE client version 2, GL_STREAM_READ is not available.
+      const GLenum usage_hint =
+          features().is_angle ? GL_STATIC_DRAW : GL_STREAM_READ;
+      glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, usage_hint);
       GLenum error = glGetError();
       if (error == GL_NO_ERROR) {
         glReadPixels(x, y, width, height, format, type, 0);