| OLD | NEW |
| 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 25 matching lines...) Expand all Loading... |
| 36 #include "cc/debug/rendering_stats_instrumentation.h" | 36 #include "cc/debug/rendering_stats_instrumentation.h" |
| 37 #include "cc/input/layer_selection_bound.h" | 37 #include "cc/input/layer_selection_bound.h" |
| 38 #include "cc/input/page_scale_animation.h" | 38 #include "cc/input/page_scale_animation.h" |
| 39 #include "cc/layers/heads_up_display_layer.h" | 39 #include "cc/layers/heads_up_display_layer.h" |
| 40 #include "cc/layers/heads_up_display_layer_impl.h" | 40 #include "cc/layers/heads_up_display_layer_impl.h" |
| 41 #include "cc/layers/layer.h" | 41 #include "cc/layers/layer.h" |
| 42 #include "cc/layers/layer_iterator.h" | 42 #include "cc/layers/layer_iterator.h" |
| 43 #include "cc/layers/painted_scrollbar_layer.h" | 43 #include "cc/layers/painted_scrollbar_layer.h" |
| 44 #include "cc/resources/ui_resource_manager.h" | 44 #include "cc/resources/ui_resource_manager.h" |
| 45 #include "cc/trees/draw_property_utils.h" | 45 #include "cc/trees/draw_property_utils.h" |
| 46 #include "cc/trees/effect_node.h" |
| 46 #include "cc/trees/layer_tree_host_client.h" | 47 #include "cc/trees/layer_tree_host_client.h" |
| 47 #include "cc/trees/layer_tree_host_common.h" | 48 #include "cc/trees/layer_tree_host_common.h" |
| 48 #include "cc/trees/layer_tree_host_impl.h" | 49 #include "cc/trees/layer_tree_host_impl.h" |
| 49 #include "cc/trees/layer_tree_impl.h" | 50 #include "cc/trees/layer_tree_impl.h" |
| 50 #include "cc/trees/mutator_host.h" | 51 #include "cc/trees/mutator_host.h" |
| 51 #include "cc/trees/property_tree_builder.h" | 52 #include "cc/trees/property_tree_builder.h" |
| 52 #include "cc/trees/proxy_main.h" | 53 #include "cc/trees/proxy_main.h" |
| 53 #include "cc/trees/single_thread_proxy.h" | 54 #include "cc/trees/single_thread_proxy.h" |
| 54 #include "cc/trees/swap_promise_manager.h" | 55 #include "cc/trees/swap_promise_manager.h" |
| 56 #include "cc/trees/transform_node.h" |
| 55 #include "cc/trees/tree_synchronizer.h" | 57 #include "cc/trees/tree_synchronizer.h" |
| 56 #include "ui/gfx/geometry/size_conversions.h" | 58 #include "ui/gfx/geometry/size_conversions.h" |
| 57 #include "ui/gfx/geometry/vector2d_conversions.h" | 59 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 58 | 60 |
| 59 namespace { | 61 namespace { |
| 60 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; | 62 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; |
| 61 } | 63 } |
| 62 | 64 |
| 63 namespace cc { | 65 namespace cc { |
| 64 | 66 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // will run after the commit, but on the main thread. | 267 // will run after the commit, but on the main thread. |
| 266 void LayerTreeHost::FinishCommitOnImplThread( | 268 void LayerTreeHost::FinishCommitOnImplThread( |
| 267 LayerTreeHostImpl* host_impl) { | 269 LayerTreeHostImpl* host_impl) { |
| 268 DCHECK(task_runner_provider_->IsImplThread()); | 270 DCHECK(task_runner_provider_->IsImplThread()); |
| 269 | 271 |
| 270 bool is_new_trace; | 272 bool is_new_trace; |
| 271 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); | 273 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); |
| 272 if (is_new_trace && | 274 if (is_new_trace && |
| 273 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && | 275 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && |
| 274 root_layer()) { | 276 root_layer()) { |
| 277 // We'll be dumping layer trees as part of trace, so make sure |
| 278 // PushPropertiesTo() propagates layer debug info to the impl side -- |
| 279 // otherwise this won't happen for the layers that remain unchanged since |
| 280 // tracing started. |
| 275 LayerTreeHostCommon::CallFunctionForEveryLayer( | 281 LayerTreeHostCommon::CallFunctionForEveryLayer( |
| 276 this, [](Layer* layer) { layer->DidBeginTracing(); }); | 282 this, [](Layer* layer) { layer->SetNeedsPushProperties(); }); |
| 277 } | 283 } |
| 278 | 284 |
| 279 LayerTreeImpl* sync_tree = host_impl->sync_tree(); | 285 LayerTreeImpl* sync_tree = host_impl->sync_tree(); |
| 280 | 286 |
| 281 if (next_commit_forces_redraw_) { | 287 if (next_commit_forces_redraw_) { |
| 282 sync_tree->ForceRedrawNextActivation(); | 288 sync_tree->ForceRedrawNextActivation(); |
| 283 next_commit_forces_redraw_ = false; | 289 next_commit_forces_redraw_ = false; |
| 284 } | 290 } |
| 285 if (next_commit_forces_recalculate_raster_scales_) { | 291 if (next_commit_forces_recalculate_raster_scales_) { |
| 286 sync_tree->ForceRecalculateRasterScales(); | 292 sync_tree->ForceRecalculateRasterScales(); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 636 |
| 631 if (hud_layer_) { | 637 if (hud_layer_) { |
| 632 hud_layer_->PrepareForCalculateDrawProperties(device_viewport_size_, | 638 hud_layer_->PrepareForCalculateDrawProperties(device_viewport_size_, |
| 633 device_scale_factor_); | 639 device_scale_factor_); |
| 634 } | 640 } |
| 635 | 641 |
| 636 gfx::Transform identity_transform; | 642 gfx::Transform identity_transform; |
| 637 LayerList update_layer_list; | 643 LayerList update_layer_list; |
| 638 | 644 |
| 639 { | 645 { |
| 646 base::AutoReset<bool> update_property_trees(&in_update_property_trees_, |
| 647 true); |
| 640 TRACE_EVENT0("cc", | 648 TRACE_EVENT0("cc", |
| 641 "LayerTreeHostInProcess::UpdateLayers::BuildPropertyTrees"); | 649 "LayerTreeHostInProcess::UpdateLayers::BuildPropertyTrees"); |
| 642 TRACE_EVENT0( | 650 TRACE_EVENT0( |
| 643 TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 651 TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
| 644 "LayerTreeHostInProcessCommon::ComputeVisibleRectsWithPropertyTrees"); | 652 "LayerTreeHostInProcessCommon::ComputeVisibleRectsWithPropertyTrees"); |
| 645 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); | 653 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 646 bool can_render_to_separate_surface = true; | 654 bool can_render_to_separate_surface = true; |
| 647 PropertyTrees* property_trees = &property_trees_; | 655 PropertyTrees* property_trees = &property_trees_; |
| 648 if (!settings_.use_layer_lists) { | 656 if (!settings_.use_layer_lists) { |
| 649 // If use_layer_lists is set, then the property trees should have been | 657 // If use_layer_lists is set, then the property trees should have been |
| (...skipping 17 matching lines...) Expand all Loading... |
| 667 can_render_to_separate_surface); | 675 can_render_to_separate_surface); |
| 668 draw_property_utils::FindLayersThatNeedUpdates(this, property_trees, | 676 draw_property_utils::FindLayersThatNeedUpdates(this, property_trees, |
| 669 &update_layer_list); | 677 &update_layer_list); |
| 670 } | 678 } |
| 671 | 679 |
| 672 for (const auto& layer : update_layer_list) | 680 for (const auto& layer : update_layer_list) |
| 673 layer->SavePaintProperties(); | 681 layer->SavePaintProperties(); |
| 674 | 682 |
| 675 bool content_is_suitable_for_gpu = true; | 683 bool content_is_suitable_for_gpu = true; |
| 676 bool did_paint_content = | 684 bool did_paint_content = |
| 677 UpdateLayers(update_layer_list, &content_is_suitable_for_gpu); | 685 PaintContent(update_layer_list, &content_is_suitable_for_gpu); |
| 678 | 686 |
| 679 if (content_is_suitable_for_gpu) { | 687 if (content_is_suitable_for_gpu) { |
| 680 ++num_consecutive_frames_suitable_for_gpu_; | 688 ++num_consecutive_frames_suitable_for_gpu_; |
| 681 if (num_consecutive_frames_suitable_for_gpu_ >= | 689 if (num_consecutive_frames_suitable_for_gpu_ >= |
| 682 kNumFramesToConsiderBeforeGpuRasterization) { | 690 kNumFramesToConsiderBeforeGpuRasterization) { |
| 683 content_is_suitable_for_gpu_rasterization_ = true; | 691 content_is_suitable_for_gpu_rasterization_ = true; |
| 684 } | 692 } |
| 685 } else { | 693 } else { |
| 686 num_consecutive_frames_suitable_for_gpu_ = 0; | 694 num_consecutive_frames_suitable_for_gpu_ = 0; |
| 687 content_is_suitable_for_gpu_rasterization_ = false; | 695 content_is_suitable_for_gpu_rasterization_ = false; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 | 992 |
| 985 Layer* LayerTreeHost::LayerById(int id) const { | 993 Layer* LayerTreeHost::LayerById(int id) const { |
| 986 auto iter = layer_id_map_.find(id); | 994 auto iter = layer_id_map_.find(id); |
| 987 return iter != layer_id_map_.end() ? iter->second : nullptr; | 995 return iter != layer_id_map_.end() ? iter->second : nullptr; |
| 988 } | 996 } |
| 989 | 997 |
| 990 size_t LayerTreeHost::NumLayers() const { | 998 size_t LayerTreeHost::NumLayers() const { |
| 991 return layer_id_map_.size(); | 999 return layer_id_map_.size(); |
| 992 } | 1000 } |
| 993 | 1001 |
| 994 bool LayerTreeHost::UpdateLayers(const LayerList& update_layer_list, | 1002 bool LayerTreeHost::PaintContent(const LayerList& update_layer_list, |
| 995 bool* content_is_suitable_for_gpu) { | 1003 bool* content_is_suitable_for_gpu) { |
| 996 base::AutoReset<bool> painting(&in_paint_layer_contents_, true); | 1004 base::AutoReset<bool> painting(&in_paint_layer_contents_, true); |
| 997 bool did_paint_content = false; | 1005 bool did_paint_content = false; |
| 998 for (const auto& layer : update_layer_list) { | 1006 for (const auto& layer : update_layer_list) { |
| 999 did_paint_content |= layer->Update(); | 1007 did_paint_content |= layer->Update(); |
| 1000 *content_is_suitable_for_gpu &= layer->IsSuitableForGpuRasterization(); | 1008 *content_is_suitable_for_gpu &= layer->IsSuitableForGpuRasterization(); |
| 1001 } | 1009 } |
| 1002 return did_paint_content; | 1010 return did_paint_content; |
| 1003 } | 1011 } |
| 1004 | 1012 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 Layer* layer = LayerByElementId(element_id); | 1211 Layer* layer = LayerByElementId(element_id); |
| 1204 DCHECK(layer); | 1212 DCHECK(layer); |
| 1205 layer->OnFilterAnimated(filters); | 1213 layer->OnFilterAnimated(filters); |
| 1206 } | 1214 } |
| 1207 | 1215 |
| 1208 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id, | 1216 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id, |
| 1209 ElementListType list_type, | 1217 ElementListType list_type, |
| 1210 float opacity) { | 1218 float opacity) { |
| 1211 Layer* layer = LayerByElementId(element_id); | 1219 Layer* layer = LayerByElementId(element_id); |
| 1212 DCHECK(layer); | 1220 DCHECK(layer); |
| 1221 DCHECK_GE(opacity, 0.f); |
| 1222 DCHECK_LE(opacity, 1.f); |
| 1213 layer->OnOpacityAnimated(opacity); | 1223 layer->OnOpacityAnimated(opacity); |
| 1224 |
| 1225 if (property_trees_.IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, |
| 1226 layer->id())) { |
| 1227 DCHECK_EQ(layer->effect_tree_index(), |
| 1228 property_trees_.layer_id_to_effect_node_index[layer->id()]); |
| 1229 EffectNode* node = |
| 1230 property_trees_.effect_tree.Node(layer->effect_tree_index()); |
| 1231 if (node->opacity == opacity) |
| 1232 return; |
| 1233 |
| 1234 node->opacity = opacity; |
| 1235 property_trees_.effect_tree.set_needs_update(true); |
| 1236 } |
| 1237 |
| 1238 SetNeedsUpdateLayers(); |
| 1214 } | 1239 } |
| 1215 | 1240 |
| 1216 void LayerTreeHost::SetElementTransformMutated( | 1241 void LayerTreeHost::SetElementTransformMutated( |
| 1217 ElementId element_id, | 1242 ElementId element_id, |
| 1218 ElementListType list_type, | 1243 ElementListType list_type, |
| 1219 const gfx::Transform& transform) { | 1244 const gfx::Transform& transform) { |
| 1220 Layer* layer = LayerByElementId(element_id); | 1245 Layer* layer = LayerByElementId(element_id); |
| 1221 DCHECK(layer); | 1246 DCHECK(layer); |
| 1222 layer->OnTransformAnimated(transform); | 1247 layer->OnTransformAnimated(transform); |
| 1248 |
| 1249 if (property_trees_.IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, |
| 1250 layer->id())) { |
| 1251 DCHECK_EQ(layer->transform_tree_index(), |
| 1252 property_trees_.layer_id_to_transform_node_index[layer->id()]); |
| 1253 TransformNode* node = |
| 1254 property_trees_.transform_tree.Node(layer->transform_tree_index()); |
| 1255 if (node->local == transform) |
| 1256 return; |
| 1257 |
| 1258 node->local = transform; |
| 1259 node->needs_local_transform_update = true; |
| 1260 node->has_potential_animation = true; |
| 1261 property_trees_.transform_tree.set_needs_update(true); |
| 1262 } |
| 1263 |
| 1264 SetNeedsUpdateLayers(); |
| 1223 } | 1265 } |
| 1224 | 1266 |
| 1225 void LayerTreeHost::SetElementScrollOffsetMutated( | 1267 void LayerTreeHost::SetElementScrollOffsetMutated( |
| 1226 ElementId element_id, | 1268 ElementId element_id, |
| 1227 ElementListType list_type, | 1269 ElementListType list_type, |
| 1228 const gfx::ScrollOffset& scroll_offset) { | 1270 const gfx::ScrollOffset& scroll_offset) { |
| 1229 Layer* layer = LayerByElementId(element_id); | 1271 Layer* layer = LayerByElementId(element_id); |
| 1230 DCHECK(layer); | 1272 DCHECK(layer); |
| 1231 layer->OnScrollOffsetAnimated(scroll_offset); | 1273 layer->OnScrollOffsetAnimated(scroll_offset); |
| 1232 } | 1274 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1263 LayerListReverseIterator<Layer> LayerTreeHost::rend() { | 1305 LayerListReverseIterator<Layer> LayerTreeHost::rend() { |
| 1264 return LayerListReverseIterator<Layer>(nullptr); | 1306 return LayerListReverseIterator<Layer>(nullptr); |
| 1265 } | 1307 } |
| 1266 | 1308 |
| 1267 void LayerTreeHost::SetNeedsDisplayOnAllLayers() { | 1309 void LayerTreeHost::SetNeedsDisplayOnAllLayers() { |
| 1268 for (auto* layer : *this) | 1310 for (auto* layer : *this) |
| 1269 layer->SetNeedsDisplay(); | 1311 layer->SetNeedsDisplay(); |
| 1270 } | 1312 } |
| 1271 | 1313 |
| 1272 } // namespace cc | 1314 } // namespace cc |
| OLD | NEW |