Revert "Plumb proper OOPIF compositor viewport rect."

This reverts commit 4a10b100d48705d18521f424dd40baf9393d831e.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> Plumb proper OOPIF compositor viewport rect.
> 
> This CL converts OOPIFs from using a compositor viewport that is the
> entire size of the content layer, to a much smaller one based on the
> visible intersection of the OOPIF's content with its parent's viewport.
> 
> This should decrease compositor resources used by the OOPIF, and
> prevent excessively large tiles being produced.
> 
> Bug: 852348
> Change-Id: I27977e2513d727bc6ba1a414504157cef3436a03
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778362
> Commit-Queue: Alex Moshchuk <[email protected]>
> Reviewed-by: Alex Moshchuk <[email protected]>
> Reviewed-by: Philip Rogers <[email protected]>
> Reviewed-by: Mike West <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#694066}

[email protected],[email protected],[email protected],[email protected]

Change-Id: Id0cdb4c77487861f8da76dd9de44768097bf480a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 852348
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789687
Reviewed-by: Tao Bai <[email protected]>
Commit-Queue: Tao Bai <[email protected]>
Cr-Commit-Position: refs/heads/master@{#694257}
diff --git a/content/renderer/render_frame_impl_browsertest.cc b/content/renderer/render_frame_impl_browsertest.cc
index ab2c344..609d9c8 100644
--- a/content/renderer/render_frame_impl_browsertest.cc
+++ b/content/renderer/render_frame_impl_browsertest.cc
@@ -222,7 +222,7 @@
   gfx::Size size(200, 200);
   visual_properties.screen_info = ScreenInfo();
   visual_properties.new_size = size;
-  visual_properties.compositor_viewport_pixel_rect = gfx::Rect(size);
+  visual_properties.compositor_viewport_pixel_size = size;
   visual_properties.visible_viewport_size = size;
   visual_properties.top_controls_height = 0.f;
   visual_properties.browser_controls_shrink_blink_size = false;
diff --git a/content/renderer/render_frame_proxy.cc b/content/renderer/render_frame_proxy.cc
index e130752..0a89003d 100644
--- a/content/renderer/render_frame_proxy.cc
+++ b/content/renderer/render_frame_proxy.cc
@@ -617,9 +617,6 @@
       sent_visual_properties_->capture_sequence_number !=
           pending_visual_properties_.capture_sequence_number;
 
-  pending_visual_properties_.compositor_viewport =
-      web_frame_->GetCompositingRect();
-
   bool synchronized_props_changed =
       !sent_visual_properties_ ||
       sent_visual_properties_->auto_resize_enabled !=
@@ -640,8 +637,6 @@
           pending_visual_properties_.page_scale_factor ||
       sent_visual_properties_->is_pinch_gesture_active !=
           pending_visual_properties_.is_pinch_gesture_active ||
-      sent_visual_properties_->compositor_viewport !=
-          pending_visual_properties_.compositor_viewport ||
       capture_sequence_number_changed;
 
   if (synchronized_props_changed) {
@@ -657,9 +652,7 @@
                                     ? cc::DeadlinePolicy::UseInfiniteDeadline()
                                     : cc::DeadlinePolicy::UseDefaultDeadline();
   viz::SurfaceId surface_id(frame_sink_id_, GetLocalSurfaceId());
-  compositing_helper_->SetSurfaceId(
-      surface_id, pending_visual_properties_.compositor_viewport.size(),
-      deadline);
+  compositing_helper_->SetSurfaceId(surface_id, local_frame_size(), deadline);
 
   bool rect_changed = !sent_visual_properties_ ||
                       sent_visual_properties_->screen_space_rect !=
@@ -684,6 +677,14 @@
       "FrameHostMsg_SynchronizeVisualProperties", "local_surface_id",
       pending_visual_properties_.local_surface_id_allocation.local_surface_id()
           .ToString());
+
+  // The visible rect that the OOPIF needs to raster depends partially on
+  // parameters that might have changed. If they affect the raster area, resend
+  // the intersection rects.
+  gfx::Rect new_compositor_visible_rect = web_frame_->GetCompositingRect();
+  if (new_compositor_visible_rect != last_compositor_visible_rect_)
+    UpdateRemoteViewportIntersection(last_intersection_rect_,
+                                     last_occlusion_state_);
 }
 
 void RenderFrameProxy::OnSetHasReceivedUserGestureBeforeNavigation(bool value) {
@@ -821,22 +822,12 @@
 void RenderFrameProxy::UpdateRemoteViewportIntersection(
     const blink::WebRect& viewport_intersection,
     blink::FrameOcclusionState occlusion_state) {
-  // If the remote viewport intersection has changed, then we should check if
-  // the compositing rect has also changed: if it has, then we should update the
-  // visible properties.
-  // TODO(wjmaclean): Maybe we should always call SynchronizeVisualProperties()
-  // here? If nothing has changed, it will early out, and it avoids duplicate
-  // checks here.
-  gfx::Rect compositor_visible_rect = web_frame_->GetCompositingRect();
-  bool compositor_visible_rect_changed =
-      compositor_visible_rect != pending_visual_properties_.compositor_viewport;
-
-  if (compositor_visible_rect_changed)
-    SynchronizeVisualProperties();
-
+  last_intersection_rect_ = viewport_intersection;
+  last_compositor_visible_rect_ = web_frame_->GetCompositingRect();
+  last_occlusion_state_ = occlusion_state;
   Send(new FrameHostMsg_UpdateViewportIntersection(
-      routing_id_, gfx::Rect(viewport_intersection), compositor_visible_rect,
-      occlusion_state));
+      routing_id_, gfx::Rect(viewport_intersection),
+      last_compositor_visible_rect_, last_occlusion_state_));
 }
 
 void RenderFrameProxy::VisibilityChanged(
diff --git a/content/renderer/render_frame_proxy.h b/content/renderer/render_frame_proxy.h
index c7202fe2..37145f1 100644
--- a/content/renderer/render_frame_proxy.h
+++ b/content/renderer/render_frame_proxy.h
@@ -322,6 +322,11 @@
   std::unique_ptr<viz::ParentLocalSurfaceIdAllocator>
       parent_local_surface_id_allocator_;
 
+  gfx::Rect last_intersection_rect_;
+  gfx::Rect last_compositor_visible_rect_;
+  blink::FrameOcclusionState last_occlusion_state_ =
+      blink::FrameOcclusionState::kUnknown;
+
   // The layer used to embed the out-of-process content.
   scoped_refptr<cc::Layer> embedded_layer_;
 
diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc
index ad387b2..bd871e1 100644
--- a/content/renderer/render_view_browsertest.cc
+++ b/content/renderer/render_view_browsertest.cc
@@ -471,7 +471,7 @@
     VisualProperties visual_properties;
     visual_properties.screen_info.device_scale_factor = dsf;
     visual_properties.new_size = gfx::Size(100, 100);
-    visual_properties.compositor_viewport_pixel_rect = gfx::Rect(200, 200);
+    visual_properties.compositor_viewport_pixel_size = gfx::Size(200, 200);
     visual_properties.visible_viewport_size = visual_properties.new_size;
     visual_properties.auto_resize_enabled =
         view()->GetWidget()->auto_resize_mode();
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 01ecce0..1598494e 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -765,10 +765,9 @@
   if (device_scale_factor_for_testing_) {
     visual_properties.screen_info.device_scale_factor =
         device_scale_factor_for_testing_;
-    visual_properties.compositor_viewport_pixel_rect =
-        gfx::Rect(gfx::ScaleToCeiledSize(
-            visual_properties.new_size,
-            visual_properties.screen_info.device_scale_factor));
+    visual_properties.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
+        visual_properties.new_size,
+        visual_properties.screen_info.device_scale_factor);
   }
 
   // Inform the rendering thread of the color space indicating the presence of
@@ -921,7 +920,8 @@
     VisualProperties visual_properties;
     visual_properties.screen_info = screen_info_;
     visual_properties.new_size = size_;
-    visual_properties.compositor_viewport_pixel_rect = CompositorViewportRect();
+    visual_properties.compositor_viewport_pixel_size =
+        CompositorViewportRect().size();
     visual_properties.local_surface_id_allocation =
         local_surface_id_allocation_from_parent_;
     visual_properties.visible_viewport_size = visible_viewport_size_;
@@ -1650,15 +1650,16 @@
 
 void RenderWidget::SynchronizeVisualProperties(
     const VisualProperties& visual_properties) {
-  gfx::Rect new_compositor_viewport_pixel_rect =
+  gfx::Size new_compositor_viewport_pixel_size =
       visual_properties.auto_resize_enabled
-          ? gfx::Rect(gfx::ScaleToCeiledSize(
-                size_, visual_properties.screen_info.device_scale_factor))
-          : visual_properties.compositor_viewport_pixel_rect;
+          ? gfx::ScaleToCeiledSize(
+                size_, visual_properties.screen_info.device_scale_factor)
+          : visual_properties.compositor_viewport_pixel_size;
   UpdateSurfaceAndScreenInfo(
       visual_properties.local_surface_id_allocation.value_or(
           viz::LocalSurfaceIdAllocation()),
-      new_compositor_viewport_pixel_rect, visual_properties.screen_info);
+      gfx::Rect(new_compositor_viewport_pixel_size),
+      visual_properties.screen_info);
   UpdateCaptureSequenceNumber(visual_properties.capture_sequence_number);
   layer_tree_view_->layer_tree_host()->SetBrowserControlsHeight(
       visual_properties.top_controls_height,
@@ -2217,15 +2218,15 @@
   local_surface_id_allocation_from_parent_ = new_local_surface_id_allocation;
   screen_info_ = new_screen_info;
 
-  // The ViewportVisibleRect derives from the LayerTreeView's viewport size,
-  // which is set above.
-  layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect());
   // Note carefully that the DSF specified in |new_screen_info| is not the
   // DSF used by the compositor during device emulation!
   layer_tree_view_->SetViewportRectAndScale(
       compositor_viewport_pixel_rect,
       GetOriginalScreenInfo().device_scale_factor,
       local_surface_id_allocation_from_parent_);
+  // The ViewportVisibleRect derives from the LayerTreeView's viewport size,
+  // which is set above.
+  layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect());
   layer_tree_view_->SetRasterColorSpace(
       screen_info_.color_space.GetRasterColorSpace());
 
@@ -2250,9 +2251,8 @@
   VisualProperties visual_properties;
   visual_properties.screen_info = screen_info_;
   visual_properties.new_size = new_window_rect.size();
-  visual_properties.compositor_viewport_pixel_rect =
-      gfx::Rect(gfx::ScaleToCeiledSize(new_window_rect.size(),
-                                       GetWebScreenInfo().device_scale_factor));
+  visual_properties.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
+      new_window_rect.size(), GetWebScreenInfo().device_scale_factor);
   visual_properties.visible_viewport_size = new_window_rect.size();
   visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
   visual_properties.display_mode = display_mode_;
@@ -2681,13 +2681,13 @@
 
     // TODO(ccameron): Note that this destroys any information differentiating
     // |size_| from the compositor's viewport size. Also note that the
-    // calculation of |new_compositor_viewport_pixel_rect| does not appear to
+    // calculation of |new_compositor_viewport_pixel_size| does not appear to
     // take into account device emulation.
     layer_tree_view_->RequestNewLocalSurfaceId();
-    gfx::Rect new_compositor_viewport_pixel_rect = gfx::Rect(
-        gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor));
+    gfx::Size new_compositor_viewport_pixel_size =
+        gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor);
     UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
-                               new_compositor_viewport_pixel_rect,
+                               gfx::Rect(new_compositor_viewport_pixel_size),
                                screen_info_);
   }
 }
@@ -3767,7 +3767,7 @@
 
   // Make sure the DSF override stays for future VisualProperties updates, and
   // that includes overriding the VisualProperties'
-  // compositor_viewport_pixel_rect with size * this for-testing DSF.
+  // compositor_viewport_pixel_size with size * this for-testing DSF.
   device_scale_factor_for_testing_ = factor;
 }
 
@@ -3810,7 +3810,8 @@
   visual_properties.auto_resize_enabled = false;
   visual_properties.screen_info = screen_info_;
   visual_properties.new_size = new_size;
-  visual_properties.compositor_viewport_pixel_rect = CompositorViewportRect();
+  visual_properties.compositor_viewport_pixel_size =
+      CompositorViewportRect().size();
   visual_properties.browser_controls_shrink_blink_size =
       browser_controls_shrink_blink_size_;
   visual_properties.top_controls_height = top_controls_height_;
diff --git a/content/renderer/render_widget_browsertest.cc b/content/renderer/render_widget_browsertest.cc
index 80b547f3..91aaae7f 100644
--- a/content/renderer/render_widget_browsertest.cc
+++ b/content/renderer/render_widget_browsertest.cc
@@ -57,7 +57,7 @@
   VisualProperties visual_properties;
   visual_properties.screen_info = ScreenInfo();
   visual_properties.new_size = gfx::Size();
-  visual_properties.compositor_viewport_pixel_rect = gfx::Rect();
+  visual_properties.compositor_viewport_pixel_size = gfx::Size();
   visual_properties.top_controls_height = 0.f;
   visual_properties.browser_controls_shrink_blink_size = false;
   visual_properties.is_fullscreen_granted = false;
@@ -75,7 +75,7 @@
   visual_properties.local_surface_id_allocation =
       local_surface_id_allocator.GetCurrentLocalSurfaceIdAllocation();
   visual_properties.new_size = size;
-  visual_properties.compositor_viewport_pixel_rect = gfx::Rect(size);
+  visual_properties.compositor_viewport_pixel_size = size;
   OnSynchronizeVisualProperties(visual_properties);
 
   // Clear the flag.
@@ -87,7 +87,7 @@
 
   // Resetting the rect to empty should not send the ack.
   visual_properties.new_size = gfx::Size();
-  visual_properties.compositor_viewport_pixel_rect = gfx::Rect();
+  visual_properties.compositor_viewport_pixel_size = gfx::Size();
   visual_properties.local_surface_id_allocation = base::nullopt;
   OnSynchronizeVisualProperties(visual_properties);
 
@@ -106,8 +106,7 @@
     std::unique_ptr<VisualProperties> initial_visual_properties(
         new VisualProperties());
     initial_visual_properties->new_size = initial_size_;
-    initial_visual_properties->compositor_viewport_pixel_rect =
-        gfx::Rect(initial_size_);
+    initial_visual_properties->compositor_viewport_pixel_size = initial_size_;
     initial_visual_properties->local_surface_id_allocation =
         local_surface_id_allocator_.GetCurrentLocalSurfaceIdAllocation();
     return initial_visual_properties;