gpu: Initialize masked alpha values to 1.0.

This fixes several broken Windows gles2 conformance tests. Because
ANGLE uses an RGBA format while command buffer was reporting an RGB
format, command buffer was incorrectly clearing the alpha channel
in ANGLE to 0.0 and the tests were seeing wrong values.

BUG=484636

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

Cr-Commit-Position: refs/heads/master@{#328602}
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 8903c7d..602d261 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -2622,6 +2622,9 @@
   glActiveTexture(GL_TEXTURE0);
   CHECK_GL_ERROR();
 
+  // cache ALPHA_BITS result for re-use with clear behaviour
+  GLint alpha_bits = 0;
+
   if (offscreen) {
     if (attrib_parser.samples > 0 && attrib_parser.sample_buffers > 0 &&
         features().chromium_framebuffer_multisample) {
@@ -2774,7 +2777,6 @@
     // can't do anything about that.
 
     if (!surfaceless_) {
-      GLint alpha_bits = 0;
       GLint depth_bits = 0;
       GLint stencil_bits = 0;
 
@@ -2862,8 +2864,20 @@
   call_gl_clear = surface_->GetHandle();
 #endif
   if (call_gl_clear) {
+    // On configs where we report no alpha, if the underlying surface has
+    // alpha, clear the surface alpha to 1.0 to be correct on ReadPixels/etc.
+    bool clear_alpha = back_buffer_color_format_ == GL_RGB && alpha_bits > 0;
+    if (clear_alpha) {
+      glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+    }
+
     // Clear the backbuffer.
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+    // Restore alpha clear value if we changed it.
+    if (clear_alpha) {
+      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+    }
   }
 
   supports_post_sub_buffer_ = surface->SupportsPostSubBuffer();