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

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

Issue 2873313004: Harmonize LayerTreeHost/LayerTreeHostImpl synchronization steps (Closed)
Patch Set: Ace of rebase 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
« no previous file with comments | « cc/trees/layer_tree_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_impl.h" 5 #include "cc/trees/layer_tree_impl.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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "cc/trees/scroll_node.h" 44 #include "cc/trees/scroll_node.h"
45 #include "cc/trees/transform_node.h" 45 #include "cc/trees/transform_node.h"
46 #include "ui/gfx/geometry/box_f.h" 46 #include "ui/gfx/geometry/box_f.h"
47 #include "ui/gfx/geometry/point_conversions.h" 47 #include "ui/gfx/geometry/point_conversions.h"
48 #include "ui/gfx/geometry/rect_conversions.h" 48 #include "ui/gfx/geometry/rect_conversions.h"
49 #include "ui/gfx/geometry/size_conversions.h" 49 #include "ui/gfx/geometry/size_conversions.h"
50 #include "ui/gfx/geometry/vector2d_conversions.h" 50 #include "ui/gfx/geometry/vector2d_conversions.h"
51 51
52 namespace cc { 52 namespace cc {
53 53
54 void LayerTreeLifecycle::AdvanceTo(LifecycleState next_state) {
55 switch (next_state) {
56 case (kNotSyncing):
57 DCHECK_EQ(state_, kLastSyncState);
58 break;
59 case (kBeginningSync):
60 case (kSyncedPropertyTrees):
61 case (kSyncedLayerProperties):
62 // Only allow tree synchronization states to be transitioned in order.
63 DCHECK_EQ(state_ + 1, next_state);
64 break;
65 }
66 state_ = next_state;
67 }
68
54 LayerTreeImpl::LayerTreeImpl( 69 LayerTreeImpl::LayerTreeImpl(
55 LayerTreeHostImpl* layer_tree_host_impl, 70 LayerTreeHostImpl* layer_tree_host_impl,
56 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, 71 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
57 scoped_refptr<SyncedBrowserControls> top_controls_shown_ratio, 72 scoped_refptr<SyncedBrowserControls> top_controls_shown_ratio,
58 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) 73 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll)
59 : layer_tree_host_impl_(layer_tree_host_impl), 74 : layer_tree_host_impl_(layer_tree_host_impl),
60 source_frame_number_(-1), 75 source_frame_number_(-1),
61 is_first_frame_after_commit_tracker_(-1), 76 is_first_frame_after_commit_tracker_(-1),
62 root_layer_for_testing_(nullptr), 77 root_layer_for_testing_(nullptr),
63 hud_layer_(nullptr), 78 hud_layer_(nullptr),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 DCHECK(OuterViewportContainerLayer()->viewport_layer_type() == 170 DCHECK(OuterViewportContainerLayer()->viewport_layer_type() ==
156 OUTER_VIEWPORT_CONTAINER); 171 OUTER_VIEWPORT_CONTAINER);
157 #endif 172 #endif
158 if (auto* layer = LayerById(id)) 173 if (auto* layer = LayerById(id))
159 return layer->viewport_layer_type() != NOT_VIEWPORT_LAYER; 174 return layer->viewport_layer_type() != NOT_VIEWPORT_LAYER;
160 return false; 175 return false;
161 } 176 }
162 177
163 void LayerTreeImpl::DidUpdateScrollOffset(int layer_id) { 178 void LayerTreeImpl::DidUpdateScrollOffset(int layer_id) {
164 DidUpdateScrollState(layer_id); 179 DidUpdateScrollState(layer_id);
180 DCHECK(lifecycle().AllowsPropertyTreeAccess());
165 TransformTree& transform_tree = property_trees()->transform_tree; 181 TransformTree& transform_tree = property_trees()->transform_tree;
166 ScrollTree& scroll_tree = property_trees()->scroll_tree; 182 ScrollTree& scroll_tree = property_trees()->scroll_tree;
167 int transform_id = TransformTree::kInvalidNodeId; 183 int transform_id = TransformTree::kInvalidNodeId;
168 184
169 // If pending tree topology changed and we still want to notify the pending 185 // If pending tree topology changed and we still want to notify the pending
170 // tree about scroll offset in the active tree, we may not find the 186 // tree about scroll offset in the active tree, we may not find the
171 // corresponding pending layer. 187 // corresponding pending layer.
172 if (LayerById(layer_id)) { 188 if (LayerById(layer_id)) {
173 // TODO(sunxd): when we have a layer_id to property_tree index map in 189 // TODO(sunxd): when we have a layer_id to property_tree index map in
174 // property trees, use the transform_id parameter instead of looking for 190 // property trees, use the transform_id parameter instead of looking for
(...skipping 17 matching lines...) Expand all
192 } 208 }
193 209
194 if (IsActiveTree() && layer_tree_host_impl_->pending_tree()) 210 if (IsActiveTree() && layer_tree_host_impl_->pending_tree())
195 layer_tree_host_impl_->pending_tree()->DidUpdateScrollOffset(layer_id); 211 layer_tree_host_impl_->pending_tree()->DidUpdateScrollOffset(layer_id);
196 } 212 }
197 213
198 void LayerTreeImpl::DidUpdateScrollState(int layer_id) { 214 void LayerTreeImpl::DidUpdateScrollState(int layer_id) {
199 if (!IsActiveTree()) 215 if (!IsActiveTree())
200 return; 216 return;
201 217
218 // The scroll_clip_layer Layer properties should be up-to-date.
219 // TODO(pdr): This DCHECK fails on existing tests but should be enabled.
220 // DCHECK(lifecycle().AllowsLayerPropertyAccess());
221
202 if (layer_id == Layer::INVALID_ID) 222 if (layer_id == Layer::INVALID_ID)
203 return; 223 return;
204 224
205 int scroll_layer_id, clip_layer_id; 225 int scroll_layer_id, clip_layer_id;
206 if (IsViewportLayerId(layer_id)) { 226 if (IsViewportLayerId(layer_id)) {
207 if (!InnerViewportContainerLayer()) 227 if (!InnerViewportContainerLayer())
208 return; 228 return;
209 229
210 // For scrollbar purposes, a change to any of the four viewport layers 230 // For scrollbar purposes, a change to any of the four viewport layers
211 // should affect the scrollbars tied to the outermost layers, which express 231 // should affect the scrollbars tied to the outermost layers, which express
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 property_trees_.effect_tree.CreateOrReuseRenderSurfaces( 395 property_trees_.effect_tree.CreateOrReuseRenderSurfaces(
376 &old_render_surfaces, this); 396 &old_render_surfaces, this);
377 if (render_surfaces_changed) 397 if (render_surfaces_changed)
378 set_needs_update_draw_properties(); 398 set_needs_update_draw_properties();
379 property_trees->effect_tree.PushCopyRequestsTo(&property_trees_.effect_tree); 399 property_trees->effect_tree.PushCopyRequestsTo(&property_trees_.effect_tree);
380 property_trees_.is_main_thread = false; 400 property_trees_.is_main_thread = false;
381 property_trees_.is_active = IsActiveTree(); 401 property_trees_.is_active = IsActiveTree();
382 property_trees_.transform_tree.set_source_to_parent_updates_allowed(false); 402 property_trees_.transform_tree.set_source_to_parent_updates_allowed(false);
383 } 403 }
384 404
385 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { 405 void LayerTreeImpl::PushPropertyTreesTo(LayerTreeImpl* target_tree) {
386 // The request queue should have been processed and does not require a push. 406 // Property trees may store damage status. We preserve the active tree
387 DCHECK_EQ(ui_resource_request_queue_.size(), 0u); 407 // damage status by pushing the damage status from active tree property
408 // trees to pending tree property trees or by moving it onto the layers.
409 if (target_tree->property_trees()->changed) {
410 if (property_trees()->sequence_number ==
411 target_tree->property_trees()->sequence_number)
412 target_tree->property_trees()->PushChangeTrackingTo(property_trees());
413 else
414 target_tree->MoveChangeTrackingToLayers();
415 }
388 416
389 // To maintain the current scrolling node we need to use element ids which 417 // To maintain the current scrolling node we need to use element ids which
390 // are stable across the property tree update in SetPropertyTrees. 418 // are stable across the property tree update in SetPropertyTrees.
391 ElementId scrolling_element_id; 419 ElementId scrolling_element_id;
392 if (ScrollNode* scrolling_node = target_tree->CurrentlyScrollingNode()) 420 if (ScrollNode* scrolling_node = target_tree->CurrentlyScrollingNode())
393 scrolling_element_id = scrolling_node->element_id; 421 scrolling_element_id = scrolling_node->element_id;
394 422
395 target_tree->SetPropertyTrees(&property_trees_); 423 target_tree->SetPropertyTrees(&property_trees_);
396 424
397 ScrollNode* scrolling_node = nullptr; 425 ScrollNode* scrolling_node = nullptr;
398 if (scrolling_element_id) { 426 if (scrolling_element_id) {
399 auto& scroll_tree = target_tree->property_trees()->scroll_tree; 427 auto& scroll_tree = target_tree->property_trees()->scroll_tree;
400 scrolling_node = scroll_tree.FindNodeFromElementId(scrolling_element_id); 428 scrolling_node = scroll_tree.FindNodeFromElementId(scrolling_element_id);
401 } 429 }
402 target_tree->SetCurrentlyScrollingNode(scrolling_node); 430 target_tree->SetCurrentlyScrollingNode(scrolling_node);
431 }
432
433 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
434 // The request queue should have been processed and does not require a push.
435 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
403 436
404 target_tree->property_trees()->scroll_tree.PushScrollUpdatesFromPendingTree( 437 target_tree->property_trees()->scroll_tree.PushScrollUpdatesFromPendingTree(
405 &property_trees_, target_tree); 438 &property_trees_, target_tree);
406 439
407 if (next_activation_forces_redraw_) { 440 if (next_activation_forces_redraw_) {
408 target_tree->ForceRedrawNextActivation(); 441 target_tree->ForceRedrawNextActivation();
409 next_activation_forces_redraw_ = false; 442 next_activation_forces_redraw_ = false;
410 } 443 }
411 444
412 target_tree->PassSwapPromises(std::move(swap_promise_list_)); 445 target_tree->PassSwapPromises(std::move(swap_promise_list_));
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 ++element_id_to_transform; 789 ++element_id_to_transform;
757 } 790 }
758 791
759 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [](LayerImpl* layer) { 792 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [](LayerImpl* layer) {
760 layer->UpdatePropertyTreeForScrollingAndAnimationIfNeeded(); 793 layer->UpdatePropertyTreeForScrollingAndAnimationIfNeeded();
761 }); 794 });
762 } 795 }
763 796
764 void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) { 797 void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) {
765 DCHECK(IsActiveTree()); 798 DCHECK(IsActiveTree());
799 DCHECK(lifecycle().AllowsPropertyTreeAccess());
766 if (page_scale_factor()->SetCurrent( 800 if (page_scale_factor()->SetCurrent(
767 ClampPageScaleFactorToLimits(active_page_scale))) { 801 ClampPageScaleFactorToLimits(active_page_scale))) {
768 DidUpdatePageScale(); 802 DidUpdatePageScale();
769 if (PageScaleLayer()) { 803 if (PageScaleLayer()) {
770 draw_property_utils::UpdatePageScaleFactor( 804 draw_property_utils::UpdatePageScaleFactor(
771 property_trees(), PageScaleLayer(), current_page_scale_factor(), 805 property_trees(), PageScaleLayer(), current_page_scale_factor(),
772 device_scale_factor(), layer_tree_host_impl_->DrawTransform()); 806 device_scale_factor(), layer_tree_host_impl_->DrawTransform());
773 } else { 807 } else {
774 DCHECK(layer_list_.empty() || active_page_scale == 1); 808 DCHECK(layer_list_.empty() || active_page_scale == 1);
775 } 809 }
(...skipping 30 matching lines...) Expand all
806 // TODO(enne): Pushing from pending to active should never require 840 // TODO(enne): Pushing from pending to active should never require
807 // DidUpdatePageScale. The values should already be set by the fully 841 // DidUpdatePageScale. The values should already be set by the fully
808 // computed property trees being synced from one tree to another. Remove 842 // computed property trees being synced from one tree to another. Remove
809 // this once CDP goes away. 843 // this once CDP goes away.
810 changed_page_scale |= page_scale_factor_->PushPendingToActive(); 844 changed_page_scale |= page_scale_factor_->PushPendingToActive();
811 } 845 }
812 846
813 if (changed_page_scale) 847 if (changed_page_scale)
814 DidUpdatePageScale(); 848 DidUpdatePageScale();
815 849
850 DCHECK(lifecycle().AllowsPropertyTreeAccess());
816 if (page_scale_factor) { 851 if (page_scale_factor) {
817 if (PageScaleLayer()) { 852 if (PageScaleLayer()) {
818 draw_property_utils::UpdatePageScaleFactor( 853 draw_property_utils::UpdatePageScaleFactor(
819 property_trees(), PageScaleLayer(), current_page_scale_factor(), 854 property_trees(), PageScaleLayer(), current_page_scale_factor(),
820 device_scale_factor(), layer_tree_host_impl_->DrawTransform()); 855 device_scale_factor(), layer_tree_host_impl_->DrawTransform());
821 } else { 856 } else {
822 DCHECK(layer_list_.empty() || *page_scale_factor == 1); 857 DCHECK(layer_list_.empty() || *page_scale_factor == 1);
823 } 858 }
824 } 859 }
825 } 860 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 1017
983 UpdateViewportLayerTypes(); 1018 UpdateViewportLayerTypes();
984 } 1019 }
985 1020
986 void LayerTreeImpl::ClearViewportLayers() { 1021 void LayerTreeImpl::ClearViewportLayers() {
987 SetViewportLayersFromIds(Layer::INVALID_ID, Layer::INVALID_ID, 1022 SetViewportLayersFromIds(Layer::INVALID_ID, Layer::INVALID_ID,
988 Layer::INVALID_ID, Layer::INVALID_ID); 1023 Layer::INVALID_ID, Layer::INVALID_ID);
989 } 1024 }
990 1025
991 void LayerTreeImpl::UpdateViewportLayerTypes() { 1026 void LayerTreeImpl::UpdateViewportLayerTypes() {
1027 // The scroll_clip_layer Layer properties should be up-to-date.
1028 // TODO(pdr): Enable this DCHECK by not calling this function unnecessarily
1029 // from LayerImpl::SetScrollClipLayer.
1030 // DCHECK(lifecycle().AllowsLayerPropertyAccess());
1031
992 if (auto* inner_scroll = LayerById(inner_viewport_scroll_layer_id_)) { 1032 if (auto* inner_scroll = LayerById(inner_viewport_scroll_layer_id_)) {
993 inner_scroll->SetViewportLayerType(INNER_VIEWPORT_SCROLL); 1033 inner_scroll->SetViewportLayerType(INNER_VIEWPORT_SCROLL);
994 if (auto* inner_container = inner_scroll->scroll_clip_layer()) 1034 if (auto* inner_container = inner_scroll->scroll_clip_layer())
995 inner_container->SetViewportLayerType(INNER_VIEWPORT_CONTAINER); 1035 inner_container->SetViewportLayerType(INNER_VIEWPORT_CONTAINER);
996 } 1036 }
997 if (auto* outer_scroll = LayerById(outer_viewport_scroll_layer_id_)) { 1037 if (auto* outer_scroll = LayerById(outer_viewport_scroll_layer_id_)) {
998 outer_scroll->SetViewportLayerType(OUTER_VIEWPORT_SCROLL); 1038 outer_scroll->SetViewportLayerType(OUTER_VIEWPORT_SCROLL);
999 if (auto* outer_container = outer_scroll->scroll_clip_layer()) 1039 if (auto* outer_container = outer_scroll->scroll_clip_layer())
1000 outer_container->SetViewportLayerType(OUTER_VIEWPORT_CONTAINER); 1040 outer_container->SetViewportLayerType(OUTER_VIEWPORT_CONTAINER);
1001 } 1041 }
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 2145
2106 void LayerTreeImpl::ResetAllChangeTracking() { 2146 void LayerTreeImpl::ResetAllChangeTracking() {
2107 layers_that_should_push_properties_.clear(); 2147 layers_that_should_push_properties_.clear();
2108 // Iterate over all layers, including masks. 2148 // Iterate over all layers, including masks.
2109 for (auto& layer : *layers_) 2149 for (auto& layer : *layers_)
2110 layer->ResetChangeTracking(); 2150 layer->ResetChangeTracking();
2111 property_trees_.ResetAllChangeTracking(); 2151 property_trees_.ResetAllChangeTracking();
2112 } 2152 }
2113 2153
2114 } // namespace cc 2154 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698