Skip hasMappedBuffer check in draw validations in WebGL contexts

MapBufferRange, FlushMappedBufferRange, and UnmapBuffer entry points
are removed from the WebGL 2.0 API[1], so we don't need to validate
if a vertex array buffer or an index buffer is mapped or not in draw
validations (ValidateDrawBase and ValidateDrawElementsCommon) in a
WebGL context.

According to profiling data, hasMappedBuffer weights over 1% (1.12%)
CPU times in WebGL Acquarium benchmark (10K fishes, Intel HD630).
With this patch, this hot spot has disappeared and no new hot spots
are introduced.

This optimization can also slightly improve FPS on WebGL benchmarks,
or keep the same at least.

[1] https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14

BUG=angleproject:1671

Change-Id: I96e770b19b691e81774cc8e0c1b66b65dcc3cc83
Reviewed-on: https://chromium-review.googlesource.com/753281
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 33b59c4..619b638 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -2527,17 +2527,25 @@
 
     const State &state = context->getGLState();
 
-    // Check for mapped buffers
-    if (state.hasMappedBuffer(GL_ARRAY_BUFFER))
+    const Extensions &extensions = context->getExtensions();
+
+    // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange,
+    // and UnmapBuffer entry points are removed from the WebGL 2.0 API.
+    // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14
+    if (!extensions.webglCompatibility)
     {
-        context->handleError(InvalidOperation());
-        return false;
+        // Check for mapped buffers
+        // TODO(jmadill): Optimize this check for non - WebGL contexts.
+        if (state.hasMappedBuffer(GL_ARRAY_BUFFER))
+        {
+            context->handleError(InvalidOperation());
+            return false;
+        }
     }
 
     // Note: these separate values are not supported in WebGL, due to D3D's limitations. See
     // Section 6.10 of the WebGL 1.0 spec.
     Framebuffer *framebuffer = state.getDrawFramebuffer();
-    const Extensions &extensions = context->getExtensions();
     if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility)
     {
         const FramebufferAttachment *dsAttachment =
@@ -2801,11 +2809,18 @@
         return false;
     }
 
-    // Check for mapped buffers
-    if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER))
+    // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange,
+    // and UnmapBuffer entry points are removed from the WebGL 2.0 API.
+    // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14
+    if (!context->getExtensions().webglCompatibility)
     {
-        context->handleError(InvalidOperation() << "Index buffer is mapped.");
-        return false;
+        // Check for mapped buffers
+        // TODO(jmadill): Optimize this check for non - WebGL contexts.
+        if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER))
+        {
+            context->handleError(InvalidOperation() << "Index buffer is mapped.");
+            return false;
+        }
     }
 
     const gl::VertexArray *vao     = state.getVertexArray();