viz: Plumb LocalSurfaceIdAllocation to more places [part 2]

viz::LocalSurfaceIdAllocation bundles a viz::LocalSurfaceId and an
allocation time for that viz::LocalSurfaceId. The purpose of this allocation
time is to determine how long it takes for a surface to get embedded once
an ID has been allocated for it.

There was some concern raised about drift between LocalSurfaceIds and allocation
times and so a previous CL bundled the two together in a class. This CL plumbs
LocalSurfaceIdAllocation to more places to ensure the two quantities remain
in sync with one another.

This CL plumbs LocalSurfaceIdAllocation from ui::Compositor/RenderWidget to
LayerTreeHost to LayerTreeHostImpl.

Bug: 655231
Change-Id: I32b4734b187f4fb87dd3cb3e57a5ea86e0c4e359
Reviewed-on: https://chromium-review.googlesource.com/c/1318688
Commit-Queue: Fady Samuel <[email protected]>
Reviewed-by: Antoine Labour <[email protected]>
Reviewed-by: Jonathan Ross <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Cr-Commit-Position: refs/heads/master@{#605871}
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 9ef9715..65cfba5 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -563,9 +563,9 @@
   popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
   popup_screen_origin_for_emulation_ =
       emulator->original_screen_rect().origin();
-  UpdateSurfaceAndScreenInfo(
-      local_surface_id_from_parent_, allocation_time_from_parent_,
-      compositor_viewport_pixel_size_, emulator->original_screen_info());
+  UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
+                             compositor_viewport_pixel_size_,
+                             emulator->original_screen_info());
 }
 
 gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
@@ -779,7 +779,10 @@
     visual_properties.new_size = size_;
     visual_properties.compositor_viewport_pixel_size =
         compositor_viewport_pixel_size_;
-    visual_properties.local_surface_id = local_surface_id_from_parent_;
+    visual_properties.local_surface_id =
+        local_surface_id_allocation_from_parent_.local_surface_id();
+    visual_properties.local_surface_id_allocation_time =
+        local_surface_id_allocation_from_parent_.allocation_time();
     visual_properties.visible_viewport_size = visible_viewport_size_;
     visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
     visual_properties.display_mode = display_mode_;
@@ -1349,8 +1352,9 @@
                                    params.screen_info.device_scale_factor)
           : params.compositor_viewport_pixel_size;
   UpdateSurfaceAndScreenInfo(
-      params.local_surface_id.value_or(viz::LocalSurfaceId()),
-      params.local_surface_id_allocation_time.value_or(base::TimeTicks()),
+      viz::LocalSurfaceIdAllocation(
+          params.local_surface_id.value_or(viz::LocalSurfaceId()),
+          params.local_surface_id_allocation_time.value_or(base::TimeTicks())),
       new_compositor_viewport_pixel_size, params.screen_info);
   UpdateCaptureSequenceNumber(params.capture_sequence_number);
   if (layer_tree_view_) {
@@ -1539,8 +1543,7 @@
                                 screen_info_.device_scale_factor),
       compositor_deps_->CreateUkmRecorderFactory());
 
-  UpdateSurfaceAndScreenInfo(local_surface_id_from_parent_,
-                             allocation_time_from_parent_,
+  UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
                              compositor_viewport_pixel_size_, screen_info_);
   layer_tree_view_->SetRasterColorSpace(
       screen_info_.color_space.GetRasterColorSpace());
@@ -1890,8 +1893,7 @@
 }
 
 void RenderWidget::UpdateSurfaceAndScreenInfo(
-    const viz::LocalSurfaceId& new_local_surface_id,
-    base::TimeTicks new_allocation_time_,
+    const viz::LocalSurfaceIdAllocation& new_local_surface_id_allocation,
     const gfx::Size& new_compositor_viewport_pixel_size,
     const ScreenInfo& new_screen_info) {
   bool orientation_changed =
@@ -1901,8 +1903,7 @@
       screen_info_.device_scale_factor != new_screen_info.device_scale_factor;
   ScreenInfo previous_original_screen_info = GetOriginalScreenInfo();
 
-  local_surface_id_from_parent_ = new_local_surface_id;
-  allocation_time_from_parent_ = new_allocation_time_;
+  local_surface_id_allocation_from_parent_ = new_local_surface_id_allocation;
   compositor_viewport_pixel_size_ = new_compositor_viewport_pixel_size;
   screen_info_ = new_screen_info;
 
@@ -1913,7 +1914,7 @@
     layer_tree_view_->SetViewportSizeAndScale(
         compositor_viewport_pixel_size_,
         GetOriginalScreenInfo().device_scale_factor,
-        local_surface_id_from_parent_, allocation_time_from_parent_);
+        local_surface_id_allocation_from_parent_);
   }
 
   if (orientation_changed)
@@ -1942,7 +1943,10 @@
   visual_properties.visible_viewport_size = new_window_rect.size();
   visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
   visual_properties.display_mode = display_mode_;
-  visual_properties.local_surface_id = local_surface_id_from_parent_;
+  visual_properties.local_surface_id =
+      local_surface_id_allocation_from_parent_.local_surface_id();
+  visual_properties.local_surface_id_allocation_time =
+      local_surface_id_allocation_from_parent_.allocation_time();
   visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
   // We are resizing the window from the renderer, so allocate a new
   // viz::LocalSurfaceId to avoid surface invariants violations in tests.
@@ -2352,9 +2356,9 @@
       layer_tree_view_->RequestNewLocalSurfaceId();
     gfx::Size new_compositor_viewport_pixel_size =
         gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor);
-    UpdateSurfaceAndScreenInfo(
-        local_surface_id_from_parent_, allocation_time_from_parent_,
-        new_compositor_viewport_pixel_size, screen_info_);
+    UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
+                               new_compositor_viewport_pixel_size,
+                               screen_info_);
   }
 }
 
@@ -3137,7 +3141,10 @@
   visual_properties.top_controls_height = 0.f;
   visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
   visual_properties.display_mode = display_mode_;
-  visual_properties.local_surface_id = local_surface_id_from_parent_;
+  visual_properties.local_surface_id =
+      local_surface_id_allocation_from_parent_.local_surface_id();
+  visual_properties.local_surface_id_allocation_time =
+      local_surface_id_allocation_from_parent_.allocation_time();
   visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
   // We are changing the device scale factor from the renderer, so allocate a
   // new viz::LocalSurfaceId to avoid surface invariants violations in tests.
@@ -3160,7 +3167,10 @@
   visual_properties.top_controls_height = 0.f;
   visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
   visual_properties.display_mode = display_mode_;
-  visual_properties.local_surface_id = local_surface_id_from_parent_;
+  visual_properties.local_surface_id =
+      local_surface_id_allocation_from_parent_.local_surface_id();
+  visual_properties.local_surface_id_allocation_time =
+      local_surface_id_allocation_from_parent_.allocation_time();
   visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
   // We are changing the device color space from the renderer, so allocate a
   // new viz::LocalSurfaceId to avoid surface invariants violations in tests.
@@ -3182,6 +3192,7 @@
   visual_properties.max_size_for_auto_resize = max_size;
   visual_properties.local_surface_id = base::Optional<viz::LocalSurfaceId>(
       viz::LocalSurfaceId(1, 1, base::UnguessableToken::Create()));
+  visual_properties.local_surface_id_allocation_time = base::TimeTicks::Now();
   visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
   OnSynchronizeVisualProperties(visual_properties);
 }