Fix for surfaceless implementation

- The image format used wasn't supported with the memory buffer framework
- The glClear on the init path causes an INVALID_FRAMEBUFFER_OPERATION error
  when executed with no framebuffer, as in the surfaceless case

BUG=380861

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

Cr-Commit-Position: refs/heads/master@{#297003}
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index d5f1e354..0e99bb9 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -1748,6 +1748,8 @@
   bool back_buffer_has_depth_;
   bool back_buffer_has_stencil_;
 
+  bool surfaceless_;
+
   // Backbuffer attachments that are currently undefined.
   uint32 backbuffer_needs_clear_bits_;
 
@@ -2304,6 +2306,7 @@
       back_buffer_color_format_(0),
       back_buffer_has_depth_(false),
       back_buffer_has_stencil_(false),
+      surfaceless_(false),
       backbuffer_needs_clear_bits_(0),
       current_decoder_error_(error::kNoError),
       use_shader_translator_(true),
@@ -2369,6 +2372,8 @@
   DCHECK(context->IsCurrent(surface.get()));
   DCHECK(!context_.get());
 
+  surfaceless_ = surface->IsSurfaceless();
+
   set_initialized();
   gpu_tracer_.reset(new GPUTracer(this));
   gpu_state_tracer_ = GPUStateTracer::Create(&state_);
@@ -2626,17 +2631,19 @@
     // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we
     // can't do anything about that.
 
-    GLint v = 0;
-    glGetIntegerv(GL_ALPHA_BITS, &v);
-    // This checks if the user requested RGBA and we have RGBA then RGBA. If the
-    // user requested RGB then RGB. If the user did not specify a preference
-    // than use whatever we were given. Same for DEPTH and STENCIL.
-    back_buffer_color_format_ =
-        (attrib_parser.alpha_size != 0 && v > 0) ? GL_RGBA : GL_RGB;
-    glGetIntegerv(GL_DEPTH_BITS, &v);
-    back_buffer_has_depth_ = attrib_parser.depth_size != 0 && v > 0;
-    glGetIntegerv(GL_STENCIL_BITS, &v);
-    back_buffer_has_stencil_ = attrib_parser.stencil_size != 0 && v > 0;
+    if (!surfaceless_) {
+      GLint v = 0;
+      glGetIntegerv(GL_ALPHA_BITS, &v);
+      // This checks if the user requested RGBA and we have RGBA then RGBA. If
+      // the user requested RGB then RGB. If the user did not specify a
+      // preference than use whatever we were given. Same for DEPTH and STENCIL.
+      back_buffer_color_format_ =
+          (attrib_parser.alpha_size != 0 && v > 0) ? GL_RGBA : GL_RGB;
+      glGetIntegerv(GL_DEPTH_BITS, &v);
+      back_buffer_has_depth_ = attrib_parser.depth_size != 0 && v > 0;
+      glGetIntegerv(GL_STENCIL_BITS, &v);
+      back_buffer_has_stencil_ = attrib_parser.stencil_size != 0 && v > 0;
+    }
   }
 
   // OpenGL ES 2.0 implicitly enables the desktop GL capability
@@ -2679,7 +2686,7 @@
   DoBindFramebuffer(GL_FRAMEBUFFER, 0);
   DoBindRenderbuffer(GL_RENDERBUFFER, 0);
 
-  bool call_gl_clear = true;
+  bool call_gl_clear = !surfaceless_;
 #if defined(OS_ANDROID)
   // Temporary workaround for Android WebView because this clear ignores the
   // clip and corrupts that external UI of the App. Not calling glClear is ok
@@ -3123,6 +3130,8 @@
     Framebuffer* framebuffer,
     GLenum target, const char* func_name) {
   if (!framebuffer) {
+    if (surfaceless_)
+      return false;
     if (backbuffer_needs_clear_bits_) {
       glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat(
           offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1);