Reland "Prevents compositor frames from being sent when SurfaceLayer is not visible."

This is a reland of 6be34509e3e7f532e2ebf4f8390be6b094bd819d

[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
Original change's description:
> Prevents compositor frames from being sent when SurfaceLayer is not visible.
>
> This CL is 3/3 in effort to fix the regressions caused by sending
> unneeded compositor frames.
>
> This CL provides a signal from the SurfaceLayerImpl to the VideoFrameSubmitter
> to prevent compositor frames from being sent at undesired times (occlusion, not
> being added into the layer tree).
>
>
> Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
> Change-Id: I428860047eaf4c50abc2e662914a643158f1276b
> Reviewed-on: https://chromium-review.googlesource.com/1101708
> Commit-Queue: CJ DiMeglio <[email protected]>
> Reviewed-by: Frank Liberato <[email protected]>
> Reviewed-by: Justin Novosad <[email protected]>
> Reviewed-by: enne <[email protected]>
> Reviewed-by: Daniel Cheng <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#575462}

Change-Id: Idba341813f1202991c8cb5da94ea72d234db56eb
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Bug: 864358
Reviewed-on: https://chromium-review.googlesource.com/1140458
Reviewed-by: CJ DiMeglio <[email protected]>
Commit-Queue: CJ DiMeglio <[email protected]>
Cr-Commit-Position: refs/heads/master@{#575833}
diff --git a/cc/layers/surface_layer_impl.h b/cc/layers/surface_layer_impl.h
index ce24320..cd433f7 100644
--- a/cc/layers/surface_layer_impl.h
+++ b/cc/layers/surface_layer_impl.h
@@ -7,6 +7,7 @@
 
 #include <memory>
 
+#include "base/bind.h"
 #include "base/macros.h"
 #include "base/memory/ptr_util.h"
 #include "cc/cc_export.h"
@@ -17,12 +18,25 @@
 
 namespace cc {
 
+// This must match SurfaceLayer::UpdateSubmissionStateCB.
+using UpdateSubmissionStateCB = base::RepeatingCallback<void(bool)>;
+
 class CC_EXPORT SurfaceLayerImpl : public LayerImpl {
  public:
+  static std::unique_ptr<SurfaceLayerImpl> Create(
+      LayerTreeImpl* tree_impl,
+      int id,
+      UpdateSubmissionStateCB update_submission_state_callback) {
+    return base::WrapUnique(new SurfaceLayerImpl(
+        tree_impl, id, std::move(update_submission_state_callback)));
+  }
+
   static std::unique_ptr<SurfaceLayerImpl> Create(LayerTreeImpl* tree_impl,
                                                   int id) {
-    return base::WrapUnique(new SurfaceLayerImpl(tree_impl, id));
+    return base::WrapUnique(
+        new SurfaceLayerImpl(tree_impl, id, base::BindRepeating([](bool) {})));
   }
+
   ~SurfaceLayerImpl() override;
 
   void SetPrimarySurfaceId(const viz::SurfaceId& surface_id,
@@ -56,12 +70,14 @@
   // LayerImpl overrides.
   std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
   void PushPropertiesTo(LayerImpl* layer) override;
+  bool WillDraw(DrawMode draw_mode,
+                viz::ClientResourceProvider* resource_provider) override;
   void AppendQuads(viz::RenderPass* render_pass,
                    AppendQuadsData* append_quads_data) override;
   bool is_surface_layer() const override;
 
  protected:
-  SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id);
+  SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id, UpdateSubmissionStateCB);
 
  private:
   viz::SurfaceDrawQuad* CreateSurfaceDrawQuad(
@@ -74,12 +90,14 @@
   void AsValueInto(base::trace_event::TracedValue* dict) const override;
   const char* LayerTypeAsString() const override;
 
+  UpdateSubmissionStateCB update_submission_state_callback_;
   viz::SurfaceId primary_surface_id_;
   viz::SurfaceId fallback_surface_id_;
   base::Optional<uint32_t> deadline_in_frames_;
 
   bool stretch_content_to_fill_bounds_ = false;
   bool surface_hit_testable_ = false;
+  bool will_draw_ = false;
 
   DISALLOW_COPY_AND_ASSIGN(SurfaceLayerImpl);
 };