Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: cc/trees/layer_tree_host.cc

Issue 2873313004: Harmonize LayerTreeHost/LayerTreeHostImpl synchronization steps (Closed)
Patch Set: Fix merge conflict with https://codereview.chromium.org/2877033002 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 root_layer()) { 283 root_layer()) {
284 // We'll be dumping layer trees as part of trace, so make sure 284 // We'll be dumping layer trees as part of trace, so make sure
285 // PushPropertiesTo() propagates layer debug info to the impl side -- 285 // PushPropertiesTo() propagates layer debug info to the impl side --
286 // otherwise this won't happen for the layers that remain unchanged since 286 // otherwise this won't happen for the layers that remain unchanged since
287 // tracing started. 287 // tracing started.
288 LayerTreeHostCommon::CallFunctionForEveryLayer( 288 LayerTreeHostCommon::CallFunctionForEveryLayer(
289 this, [](Layer* layer) { layer->SetNeedsPushProperties(); }); 289 this, [](Layer* layer) { layer->SetNeedsPushProperties(); });
290 } 290 }
291 291
292 LayerTreeImpl* sync_tree = host_impl->sync_tree(); 292 LayerTreeImpl* sync_tree = host_impl->sync_tree();
293 sync_tree->lifecycle().AdvanceTo(LayerTreeLifecycle::kBeginningSync);
293 294
294 if (next_commit_forces_redraw_) { 295 if (next_commit_forces_redraw_) {
295 sync_tree->ForceRedrawNextActivation(); 296 sync_tree->ForceRedrawNextActivation();
296 next_commit_forces_redraw_ = false; 297 next_commit_forces_redraw_ = false;
297 } 298 }
298 if (next_commit_forces_recalculate_raster_scales_) { 299 if (next_commit_forces_recalculate_raster_scales_) {
299 sync_tree->ForceRecalculateRasterScales(); 300 sync_tree->ForceRecalculateRasterScales();
300 next_commit_forces_recalculate_raster_scales_ = false; 301 next_commit_forces_recalculate_raster_scales_ = false;
301 } 302 }
302 303
303 sync_tree->set_source_frame_number(SourceFrameNumber()); 304 sync_tree->set_source_frame_number(SourceFrameNumber());
304 305
305 if (needs_full_tree_sync_) 306 if (needs_full_tree_sync_)
306 TreeSynchronizer::SynchronizeTrees(root_layer(), sync_tree); 307 TreeSynchronizer::SynchronizeTrees(root_layer(), sync_tree);
307 308
308 PushPropertiesTo(sync_tree);
309
310 sync_tree->PassSwapPromises(swap_promise_manager_.TakeSwapPromises());
311
312 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_);
313 host_impl->SetContentIsSuitableForGpuRasterization(
314 content_is_suitable_for_gpu_rasterization_);
315 RecordGpuRasterizationHistogram(host_impl);
316
317 host_impl->SetViewportSize(device_viewport_size_);
318 sync_tree->SetDeviceScaleFactor(device_scale_factor_);
319 host_impl->SetDebugState(debug_state_);
320
321 if (did_navigate_) {
322 did_navigate_ = false;
323 host_impl->ClearImageCacheOnNavigation();
324 }
325
326 sync_tree->set_ui_resource_request_queue(
327 ui_resource_manager_->TakeUIResourcesRequests());
328
329 { 309 {
330 TRACE_EVENT0("cc", "LayerTreeHostInProcess::PushProperties"); 310 TRACE_EVENT0("cc", "LayerTreeHostInProcess::PushProperties");
331 311
312 PushPropertyTreesTo(sync_tree);
313 sync_tree->lifecycle().AdvanceTo(LayerTreeLifecycle::kSyncedPropertyTrees);
314
332 TreeSynchronizer::PushLayerProperties(this, sync_tree); 315 TreeSynchronizer::PushLayerProperties(this, sync_tree);
316 sync_tree->lifecycle().AdvanceTo(
317 LayerTreeLifecycle::kSyncedLayerProperties);
318
319 PushLayerTreePropertiesTo(sync_tree);
320 PushLayerTreeHostPropertiesTo(host_impl);
321
322 sync_tree->PassSwapPromises(swap_promise_manager_.TakeSwapPromises());
323
324 // TODO(pdr): Move this into PushPropertyTreesTo or introduce a lifecycle
325 // state for it.
326 sync_tree->SetDeviceScaleFactor(device_scale_factor_);
327
328 if (did_navigate_) {
329 did_navigate_ = false;
330 host_impl->ClearImageCacheOnNavigation();
331 }
332
333 sync_tree->set_ui_resource_request_queue(
334 ui_resource_manager_->TakeUIResourcesRequests());
333 335
334 // This must happen after synchronizing property trees and after pushing 336 // This must happen after synchronizing property trees and after pushing
335 // properties, which updates the clobber_active_value flag. 337 // properties, which updates the clobber_active_value flag.
338 // TODO(pdr): Enforce this comment with DCHECKS and a lifecycle state.
336 sync_tree->property_trees()->scroll_tree.PushScrollUpdatesFromMainThread( 339 sync_tree->property_trees()->scroll_tree.PushScrollUpdatesFromMainThread(
337 property_trees(), sync_tree); 340 property_trees(), sync_tree);
338 341
339 // This must happen after synchronizing property trees and after push 342 // This must happen after synchronizing property trees and after push
340 // properties, which updates property tree indices, but before animation 343 // properties, which updates property tree indices, but before animation
341 // host pushes properties as animation host push properties can change 344 // host pushes properties as animation host push properties can change
342 // Animation::InEffect and we want the old InEffect value for updating 345 // Animation::InEffect and we want the old InEffect value for updating
343 // property tree scrolling and animation. 346 // property tree scrolling and animation.
347 // TODO(pdr): Enforce this comment with DCHECKS and a lifecycle state.
344 bool is_impl_side_update = false; 348 bool is_impl_side_update = false;
345 sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread( 349 sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread(
346 is_impl_side_update); 350 is_impl_side_update);
347 351
348 TRACE_EVENT0("cc", "LayerTreeHostInProcess::AnimationHost::PushProperties"); 352 TRACE_EVENT0("cc", "LayerTreeHostInProcess::AnimationHost::PushProperties");
349 DCHECK(host_impl->mutator_host()); 353 DCHECK(host_impl->mutator_host());
350 mutator_host_->PushPropertiesTo(host_impl->mutator_host()); 354 mutator_host_->PushPropertiesTo(host_impl->mutator_host());
355
356 sync_tree->lifecycle().AdvanceTo(LayerTreeLifecycle::kNotSyncing);
351 } 357 }
352 358
353 // Transfer image decode requests to the impl thread. 359 // Transfer image decode requests to the impl thread.
354 for (auto& request : queued_image_decodes_) 360 for (auto& request : queued_image_decodes_)
355 host_impl->QueueImageDecode(std::move(request.first), request.second); 361 host_impl->QueueImageDecode(std::move(request.first), request.second);
356 queued_image_decodes_.clear(); 362 queued_image_decodes_.clear();
357 363
358 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); 364 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl);
359 property_trees_.ResetAllChangeTracking(); 365 property_trees_.ResetAllChangeTracking();
360 } 366 }
361 367
368 void LayerTreeHost::PushPropertyTreesTo(LayerTreeImpl* tree_impl) {
369 bool property_trees_changed_on_active_tree =
370 tree_impl->IsActiveTree() && tree_impl->property_trees()->changed;
371 // Property trees may store damage status. We preserve the sync tree damage
372 // status by pushing the damage status from sync tree property trees to main
373 // thread property trees or by moving it onto the layers.
374 if (root_layer_ && property_trees_changed_on_active_tree) {
375 if (property_trees_.sequence_number ==
376 tree_impl->property_trees()->sequence_number)
377 tree_impl->property_trees()->PushChangeTrackingTo(&property_trees_);
378 else
379 tree_impl->MoveChangeTrackingToLayers();
380 }
381
382 tree_impl->SetPropertyTrees(&property_trees_);
383 }
384
362 void LayerTreeHost::WillCommit() { 385 void LayerTreeHost::WillCommit() {
363 swap_promise_manager_.WillCommit(); 386 swap_promise_manager_.WillCommit();
364 client_->WillCommit(); 387 client_->WillCommit();
365 } 388 }
366 389
367 390
368 void LayerTreeHost::UpdateDeferCommitsInternal() { 391 void LayerTreeHost::UpdateDeferCommitsInternal() {
369 proxy_->SetDeferCommits(defer_commits_ || 392 proxy_->SetDeferCommits(defer_commits_ ||
370 (settings_.enable_surface_synchronization && 393 (settings_.enable_surface_synchronization &&
371 !local_surface_id_.is_valid())); 394 !local_surface_id_.is_valid()));
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 needs_full_tree_sync_ = true; 1138 needs_full_tree_sync_ = true;
1116 property_trees_.needs_rebuild = true; 1139 property_trees_.needs_rebuild = true;
1117 SetNeedsCommit(); 1140 SetNeedsCommit();
1118 } 1141 }
1119 1142
1120 void LayerTreeHost::SetPropertyTreesNeedRebuild() { 1143 void LayerTreeHost::SetPropertyTreesNeedRebuild() {
1121 property_trees_.needs_rebuild = true; 1144 property_trees_.needs_rebuild = true;
1122 SetNeedsUpdateLayers(); 1145 SetNeedsUpdateLayers();
1123 } 1146 }
1124 1147
1125 void LayerTreeHost::PushPropertiesTo(LayerTreeImpl* tree_impl) { 1148 void LayerTreeHost::PushLayerTreePropertiesTo(LayerTreeImpl* tree_impl) {
1126 tree_impl->set_needs_full_tree_sync(needs_full_tree_sync_); 1149 tree_impl->set_needs_full_tree_sync(needs_full_tree_sync_);
1127 needs_full_tree_sync_ = false; 1150 needs_full_tree_sync_ = false;
1128 1151
1129 if (hud_layer_.get()) { 1152 if (hud_layer_.get()) {
1130 LayerImpl* hud_impl = tree_impl->LayerById(hud_layer_->id()); 1153 LayerImpl* hud_impl = tree_impl->LayerById(hud_layer_->id());
1131 tree_impl->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(hud_impl)); 1154 tree_impl->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(hud_impl));
1132 } else { 1155 } else {
1133 tree_impl->set_hud_layer(nullptr); 1156 tree_impl->set_hud_layer(nullptr);
1134 } 1157 }
1135 1158
(...skipping 17 matching lines...) Expand all
1153 page_scale_layer_->id(), inner_viewport_scroll_layer_->id(), 1176 page_scale_layer_->id(), inner_viewport_scroll_layer_->id(),
1154 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() 1177 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
1155 : Layer::INVALID_ID); 1178 : Layer::INVALID_ID);
1156 DCHECK(inner_viewport_scroll_layer_->IsContainerForFixedPositionLayers()); 1179 DCHECK(inner_viewport_scroll_layer_->IsContainerForFixedPositionLayers());
1157 } else { 1180 } else {
1158 tree_impl->ClearViewportLayers(); 1181 tree_impl->ClearViewportLayers();
1159 } 1182 }
1160 1183
1161 tree_impl->RegisterSelection(selection_); 1184 tree_impl->RegisterSelection(selection_);
1162 1185
1163 bool property_trees_changed_on_active_tree =
1164 tree_impl->IsActiveTree() && tree_impl->property_trees()->changed;
1165 // Property trees may store damage status. We preserve the sync tree damage
1166 // status by pushing the damage status from sync tree property trees to main
1167 // thread property trees or by moving it onto the layers.
1168 if (root_layer_ && property_trees_changed_on_active_tree) {
1169 if (property_trees_.sequence_number ==
1170 tree_impl->property_trees()->sequence_number)
1171 tree_impl->property_trees()->PushChangeTrackingTo(&property_trees_);
1172 else
1173 tree_impl->MoveChangeTrackingToLayers();
1174 }
1175 // Setting property trees must happen before pushing the page scale.
1176 tree_impl->SetPropertyTrees(&property_trees_);
1177
1178 tree_impl->PushPageScaleFromMainThread( 1186 tree_impl->PushPageScaleFromMainThread(
1179 page_scale_factor_, min_page_scale_factor_, max_page_scale_factor_); 1187 page_scale_factor_, min_page_scale_factor_, max_page_scale_factor_);
1180 1188
1181 tree_impl->set_browser_controls_shrink_blink_size( 1189 tree_impl->set_browser_controls_shrink_blink_size(
1182 browser_controls_shrink_blink_size_); 1190 browser_controls_shrink_blink_size_);
1183 tree_impl->set_top_controls_height(top_controls_height_); 1191 tree_impl->set_top_controls_height(top_controls_height_);
1184 tree_impl->set_bottom_controls_height(bottom_controls_height_); 1192 tree_impl->set_bottom_controls_height(bottom_controls_height_);
1185 tree_impl->PushBrowserControlsFromMainThread(top_controls_shown_ratio_); 1193 tree_impl->PushBrowserControlsFromMainThread(top_controls_shown_ratio_);
1186 tree_impl->elastic_overscroll()->PushFromMainThread(elastic_overscroll_); 1194 tree_impl->elastic_overscroll()->PushFromMainThread(elastic_overscroll_);
1187 if (tree_impl->IsActiveTree()) 1195 if (tree_impl->IsActiveTree())
(...skipping 10 matching lines...) Expand all
1198 if (pending_page_scale_animation_) { 1206 if (pending_page_scale_animation_) {
1199 tree_impl->SetPendingPageScaleAnimation( 1207 tree_impl->SetPendingPageScaleAnimation(
1200 std::move(pending_page_scale_animation_)); 1208 std::move(pending_page_scale_animation_));
1201 } 1209 }
1202 1210
1203 DCHECK(!tree_impl->ViewportSizeInvalid()); 1211 DCHECK(!tree_impl->ViewportSizeInvalid());
1204 1212
1205 tree_impl->set_has_ever_been_drawn(false); 1213 tree_impl->set_has_ever_been_drawn(false);
1206 } 1214 }
1207 1215
1216 void LayerTreeHost::PushLayerTreeHostPropertiesTo(
1217 LayerTreeHostImpl* host_impl) {
1218 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_);
1219 host_impl->SetContentIsSuitableForGpuRasterization(
1220 content_is_suitable_for_gpu_rasterization_);
1221 RecordGpuRasterizationHistogram(host_impl);
1222
1223 host_impl->SetViewportSize(device_viewport_size_);
1224 host_impl->SetDebugState(debug_state_);
1225 }
1226
1208 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const { 1227 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const {
1209 auto iter = element_layers_map_.find(element_id); 1228 auto iter = element_layers_map_.find(element_id);
1210 return iter != element_layers_map_.end() ? iter->second : nullptr; 1229 return iter != element_layers_map_.end() ? iter->second : nullptr;
1211 } 1230 }
1212 1231
1213 void LayerTreeHost::RegisterElement(ElementId element_id, 1232 void LayerTreeHost::RegisterElement(ElementId element_id,
1214 ElementListType list_type, 1233 ElementListType list_type,
1215 Layer* layer) { 1234 Layer* layer) {
1216 if (layer->element_id()) { 1235 if (layer->element_id()) {
1217 element_layers_map_[layer->element_id()] = layer; 1236 element_layers_map_[layer->element_id()] = layer;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 void LayerTreeHost::SetNeedsDisplayOnAllLayers() { 1475 void LayerTreeHost::SetNeedsDisplayOnAllLayers() {
1457 for (auto* layer : *this) 1476 for (auto* layer : *this)
1458 layer->SetNeedsDisplay(); 1477 layer->SetNeedsDisplay();
1459 } 1478 }
1460 1479
1461 void LayerTreeHost::SetHasCopyRequest(bool has_copy_request) { 1480 void LayerTreeHost::SetHasCopyRequest(bool has_copy_request) {
1462 has_copy_request_ = has_copy_request; 1481 has_copy_request_ = has_copy_request;
1463 } 1482 }
1464 1483
1465 } // namespace cc 1484 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698