Tighten error detection and correction on Mac compositing

Change the behavior on detecting an error from immediately
destroying all state to posting a task to destroy all state. This
cleans up the messy situation where a context would have all
of its references removed while it was still current (this was,
in theory, correctly handled before, but crash reports did not
corroborate this theory).

Change the concept of having a context "marked not shareable"
to being "poisoned". When an error occurs in a context, all
contexts in its sharegroup are poisoned, and can never be used
to draw a new frame again. Check for poisoning when new
frames come in and treat being poisoned in the same way that
having an error is treated (post a task to destroy everything,
request a new frame, and re-create everything when the new
frame comes in).

If drawing an IOSurface encounters an error, clear the screen to
light grey instead of allowing whatever was hanging out in the
backbuffer to be drawn.

Use base::ScopedClosureRunner and WARN_UNUSED_RESULT more
to robustify the implementation.

BUG=245900

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259217 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/renderer_host/compositing_iosurface_mac.h b/content/browser/renderer_host/compositing_iosurface_mac.h
index 18795af..fa139950 100644
--- a/content/browser/renderer_host/compositing_iosurface_mac.h
+++ b/content/browser/renderer_host/compositing_iosurface_mac.h
@@ -51,7 +51,7 @@
       scoped_refptr<CompositingIOSurfaceContext> current_context,
       uint64 io_surface_handle,
       const gfx::Size& size,
-      float scale_factor);
+      float scale_factor) WARN_UNUSED_RESULT;
 
   // Get the CGL renderer ID currently associated with this context.
   int GetRendererID();
@@ -64,7 +64,7 @@
       scoped_refptr<CompositingIOSurfaceContext> drawing_context,
       const gfx::Rect& window_rect,
       float window_scale_factor,
-      bool flush_drawable);
+      bool flush_drawable) WARN_UNUSED_RESULT;
 
   // Copy the data of the "live" OpenGL texture referring to this IOSurfaceRef
   // into |out|. The copied region is specified with |src_pixel_subrect| and
@@ -101,6 +101,10 @@
   // Returns true if asynchronous readback is supported on this system.
   bool IsAsynchronousReadbackSupported();
 
+  // Returns true if the offscreen context used by this surface has been
+  // poisoned.
+  bool HasBeenPoisoned() const;
+
  private:
   // Vertex structure for use in glDraw calls.
   struct SurfaceVertex {
@@ -204,7 +208,7 @@
   // Returns true if IOSurface is ready to render. False otherwise.
   bool MapIOSurfaceToTextureWithContextCurrent(
       const scoped_refptr<CompositingIOSurfaceContext>& current_context,
-      uint64 io_surface_handle);
+      uint64 io_surface_handle) WARN_UNUSED_RESULT;
 
   void UnrefIOSurfaceWithContextCurrent();