Disable compositing for tooltips on Linux

This CL is to fix the elusive bug 442111, which only occurs on intel
hardware.  It is known that --disable-gpu solves the issue, but that
would hurt performance, so this CL selectively disables compositing
only for tooltips.  Tooltips only ever render one frame, so
compositing provides little benefit anyway.

Thanks to danakj@ in [1] for the idea.

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=442111#c125

BUG=442111
R=erg@chromium.org,danakj@chromium.org

Change-Id: I01740c7ea2b696fff491dd8e6908511ac79d9780
Reviewed-on: https://chromium-review.googlesource.com/599189
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Reviewed-by: Elliot Glaysher <erg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#492841}
diff --git a/content/browser/compositor/gpu_process_transport_factory.cc b/content/browser/compositor/gpu_process_transport_factory.cc
index da1f666..1a1d723 100644
--- a/content/browser/compositor/gpu_process_transport_factory.cc
+++ b/content/browser/compositor/gpu_process_transport_factory.cc
@@ -344,6 +344,10 @@
   // Software fallback does not happen on Chrome OS.
   return true;
 #endif
+
+  if (compositor->force_software_compositor())
+    return false;
+
 #if defined(OS_WIN)
   if (::GetProp(compositor->widget(), kForceSoftwareCompositor) &&
       ::RemoveProp(compositor->widget(), kForceSoftwareCompositor))
diff --git a/ui/aura/window_tree_host.cc b/ui/aura/window_tree_host.cc
index 8508220..dc6bcfd 100644
--- a/ui/aura/window_tree_host.cc
+++ b/ui/aura/window_tree_host.cc
@@ -256,7 +256,8 @@
   //window()->RemoveOrDestroyChildren();
 }
 
-void WindowTreeHost::CreateCompositor(const viz::FrameSinkId& frame_sink_id) {
+void WindowTreeHost::CreateCompositor(const viz::FrameSinkId& frame_sink_id,
+                                      bool force_software_compositor) {
   DCHECK(Env::GetInstance());
   ui::ContextFactory* context_factory = Env::GetInstance()->context_factory();
   DCHECK(context_factory);
@@ -272,7 +273,7 @@
           : context_factory_private->AllocateFrameSinkId(),
       context_factory, context_factory_private,
       base::ThreadTaskRunnerHandle::Get(), enable_surface_synchronization,
-      ui::IsPixelCanvasRecordingEnabled()));
+      ui::IsPixelCanvasRecordingEnabled(), false, force_software_compositor));
   if (!dispatcher()) {
     window()->Init(ui::LAYER_NOT_DRAWN);
     window()->set_host(this);
diff --git a/ui/aura/window_tree_host.h b/ui/aura/window_tree_host.h
index f0757f56..31301558 100644
--- a/ui/aura/window_tree_host.h
+++ b/ui/aura/window_tree_host.h
@@ -195,7 +195,8 @@
   // If frame_sink_id is not passed in, one will be grabbed from
   // ContextFactoryPrivate.
   void CreateCompositor(
-      const viz::FrameSinkId& frame_sink_id = viz::FrameSinkId());
+      const viz::FrameSinkId& frame_sink_id = viz::FrameSinkId(),
+      bool force_software_compositor = false);
 
   void InitCompositor();
   void OnAcceleratedWidgetAvailable();
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
index 3a64eaf..262ac1f 100644
--- a/ui/compositor/compositor.cc
+++ b/ui/compositor/compositor.cc
@@ -61,13 +61,15 @@
                        scoped_refptr<base::SingleThreadTaskRunner> task_runner,
                        bool enable_surface_synchronization,
                        bool enable_pixel_canvas,
-                       bool external_begin_frames_enabled)
+                       bool external_begin_frames_enabled,
+                       bool force_software_compositor)
     : context_factory_(context_factory),
       context_factory_private_(context_factory_private),
       frame_sink_id_(frame_sink_id),
       task_runner_(task_runner),
       vsync_manager_(new CompositorVSyncManager()),
       external_begin_frames_enabled_(external_begin_frames_enabled),
+      force_software_compositor_(force_software_compositor),
       layer_animator_collection_(this),
       scheduled_timeout_(base::TimeTicks()),
       allow_locks_to_extend_timeout_(false),
diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
index f70914f..6babbc1c 100644
--- a/ui/compositor/compositor.h
+++ b/ui/compositor/compositor.h
@@ -195,7 +195,8 @@
              scoped_refptr<base::SingleThreadTaskRunner> task_runner,
              bool enable_surface_synchronization,
              bool enable_pixel_canvas,
-             bool external_begin_frames_enabled = false);
+             bool external_begin_frames_enabled = false,
+             bool force_software_compositor = false);
   ~Compositor() override;
 
   ui::ContextFactory* context_factory() { return context_factory_; }
@@ -321,6 +322,8 @@
   // the compositor if the enable_external_begin_frames setting is true.
   void OnNeedsExternalBeginFrames(bool needs_begin_frames);
 
+  bool force_software_compositor() { return force_software_compositor_; }
+
   // Returns the main thread task runner this compositor uses. Users of the
   // compositor generally shouldn't use this.
   scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
@@ -461,6 +464,8 @@
   ExternalBeginFrameClient* external_begin_frame_client_ = nullptr;
   bool needs_external_begin_frames_ = false;
 
+  const bool force_software_compositor_;
+
   // The device scale factor of the monitor that this compositor is compositing
   // layers on.
   float device_scale_factor_ = 0.f;
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index e8a7a79..f43f179 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -166,8 +166,7 @@
       has_pointer_focus_(false),
       modal_dialog_counter_(0),
       close_widget_factory_(this),
-      weak_factory_(this) {
-}
+      weak_factory_(this) {}
 
 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() {
   window()->ClearProperty(kHostForRootWindow);
@@ -1530,7 +1529,10 @@
   if (window_icon) {
     SetWindowIcons(gfx::ImageSkia(), *window_icon);
   }
-  CreateCompositor();
+  // Disable compositing on tooltips as a workaround for
+  // https://crbug.com/442111.
+  CreateCompositor(viz::FrameSinkId(),
+                   params.type == Widget::InitParams::TYPE_TOOLTIP);
   OnAcceleratedWidgetAvailable();
 }