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_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/timer/elapsed_timer.h" | 12 #include "base/timer/elapsed_timer.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "base/trace_event/trace_event_argument.h" | 14 #include "base/trace_event/trace_event_argument.h" |
15 #include "cc/animation/animation_host.h" | 15 #include "cc/animation/animation_host.h" |
16 #include "cc/animation/keyframed_animation_curve.h" | 16 #include "cc/animation/keyframed_animation_curve.h" |
17 #include "cc/animation/mutable_properties.h" | |
17 #include "cc/animation/scrollbar_animation_controller.h" | 18 #include "cc/animation/scrollbar_animation_controller.h" |
18 #include "cc/animation/scrollbar_animation_controller_linear_fade.h" | 19 #include "cc/animation/scrollbar_animation_controller_linear_fade.h" |
19 #include "cc/animation/scrollbar_animation_controller_thinning.h" | 20 #include "cc/animation/scrollbar_animation_controller_thinning.h" |
20 #include "cc/base/histograms.h" | 21 #include "cc/base/histograms.h" |
21 #include "cc/base/math_util.h" | 22 #include "cc/base/math_util.h" |
22 #include "cc/base/synced_property.h" | 23 #include "cc/base/synced_property.h" |
23 #include "cc/debug/devtools_instrumentation.h" | 24 #include "cc/debug/devtools_instrumentation.h" |
24 #include "cc/debug/traced_value.h" | 25 #include "cc/debug/traced_value.h" |
25 #include "cc/input/page_scale_animation.h" | 26 #include "cc/input/page_scale_animation.h" |
26 #include "cc/layers/heads_up_display_layer_impl.h" | 27 #include "cc/layers/heads_up_display_layer_impl.h" |
27 #include "cc/layers/layer.h" | 28 #include "cc/layers/layer.h" |
28 #include "cc/layers/layer_iterator.h" | 29 #include "cc/layers/layer_iterator.h" |
29 #include "cc/layers/render_surface_impl.h" | 30 #include "cc/layers/render_surface_impl.h" |
30 #include "cc/layers/scrollbar_layer_impl_base.h" | 31 #include "cc/layers/scrollbar_layer_impl_base.h" |
31 #include "cc/resources/ui_resource_request.h" | 32 #include "cc/resources/ui_resource_request.h" |
32 #include "cc/trees/draw_property_utils.h" | 33 #include "cc/trees/draw_property_utils.h" |
33 #include "cc/trees/layer_tree_host_common.h" | 34 #include "cc/trees/layer_tree_host_common.h" |
34 #include "cc/trees/layer_tree_host_impl.h" | 35 #include "cc/trees/layer_tree_host_impl.h" |
35 #include "cc/trees/occlusion_tracker.h" | 36 #include "cc/trees/occlusion_tracker.h" |
36 #include "cc/trees/property_tree.h" | 37 #include "cc/trees/property_tree.h" |
37 #include "cc/trees/property_tree_builder.h" | 38 #include "cc/trees/property_tree_builder.h" |
38 #include "ui/gfx/geometry/box_f.h" | 39 #include "ui/gfx/geometry/box_f.h" |
39 #include "ui/gfx/geometry/point_conversions.h" | 40 #include "ui/gfx/geometry/point_conversions.h" |
40 #include "ui/gfx/geometry/size_conversions.h" | 41 #include "ui/gfx/geometry/size_conversions.h" |
41 #include "ui/gfx/geometry/vector2d_conversions.h" | 42 #include "ui/gfx/geometry/vector2d_conversions.h" |
42 | 43 |
43 namespace cc { | 44 namespace cc { |
44 | 45 |
46 namespace { | |
47 | |
48 const uint32_t kMainLayerFlags = | |
enne (OOO)
2015/11/16 19:12:33
What does "main" here mean?
Ian Vollick
2015/11/18 17:20:33
Added comments in the header. It's analogous to m_
| |
49 kMutablePropertyOpacity | kMutablePropertyTransform; | |
50 const uint32_t kScrollLayerFlags = | |
51 kMutablePropertyScrollLeft | kMutablePropertyScrollTop; | |
52 const uint32_t kMainLayerIndex = 0; | |
enne (OOO)
2015/11/16 19:12:33
Do you expect to have more layer types? It looks a
Ian Vollick
2015/11/18 17:20:33
It is odd. The whole ElementLayers class was wonky
| |
53 const uint32_t kScrollLayerIndex = 1; | |
54 | |
55 } // namespace | |
56 | |
57 class ElementLayers { | |
58 public: | |
59 ElementLayers() { | |
60 layers[0] = nullptr; | |
61 layers[1] = nullptr; | |
62 } | |
63 LayerImpl*& main() { return layers[kMainLayerIndex]; } | |
64 LayerImpl*& scroll() { return layers[kScrollLayerIndex]; } | |
65 | |
66 private: | |
67 LayerImpl* layers[2]; | |
esprehn
2015/11/16 20:01:04
just add two members, why use an array? Also this
Ian Vollick
2015/11/18 17:20:33
Agreed. Updated.
| |
68 }; | |
69 | |
45 LayerTreeImpl::LayerTreeImpl( | 70 LayerTreeImpl::LayerTreeImpl( |
46 LayerTreeHostImpl* layer_tree_host_impl, | 71 LayerTreeHostImpl* layer_tree_host_impl, |
47 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, | 72 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, |
48 scoped_refptr<SyncedTopControls> top_controls_shown_ratio, | 73 scoped_refptr<SyncedTopControls> top_controls_shown_ratio, |
49 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) | 74 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) |
50 : layer_tree_host_impl_(layer_tree_host_impl), | 75 : layer_tree_host_impl_(layer_tree_host_impl), |
51 source_frame_number_(-1), | 76 source_frame_number_(-1), |
52 hud_layer_(0), | 77 hud_layer_(0), |
53 background_color_(0), | 78 background_color_(0), |
54 has_transparent_background_(false), | 79 has_transparent_background_(false), |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 | 371 |
347 if (hud_layer()) | 372 if (hud_layer()) |
348 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( | 373 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
349 LayerTreeHostCommon::FindLayerInSubtree( | 374 LayerTreeHostCommon::FindLayerInSubtree( |
350 target_tree->root_layer(), hud_layer()->id()))); | 375 target_tree->root_layer(), hud_layer()->id()))); |
351 else | 376 else |
352 target_tree->set_hud_layer(NULL); | 377 target_tree->set_hud_layer(NULL); |
353 | 378 |
354 target_tree->has_ever_been_drawn_ = false; | 379 target_tree->has_ever_been_drawn_ = false; |
355 } | 380 } |
381 void LayerTreeImpl::AddToElementMap(LayerImpl* layer) { | |
382 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), | |
383 "LayerTreeImpl::AddToElementMap", "element_id", | |
384 layer->element_id(), "layer_id", layer->id()); | |
385 ElementLayers& layers = element_layers_map_[layer->element_id()]; | |
386 if (layer->mutable_properties() & kMainLayerFlags) { | |
387 if (!layers.main() || layer->IsActive()) | |
388 layers.main() = layer; | |
esprehn
2015/11/16 20:01:04
this is very weird, why not just make the fields p
Ian Vollick
2015/11/18 17:20:33
Done.
| |
389 } | |
390 if (layer->mutable_properties() & kScrollLayerFlags) { | |
391 if (!layers.scroll() || layer->IsActive()) { | |
392 TRACE_EVENT2("compositor-worker", "LayerTreeImpl::AddToElementMap scroll", | |
393 "element_id", layer->element_id(), "layer_id", layer->id()); | |
394 layers.scroll() = layer; | |
395 } | |
396 } | |
397 } | |
398 | |
399 void LayerTreeImpl::RemoveFromElementMap(LayerImpl* layer) { | |
400 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), | |
401 "LayerTreeImpl::RemoveFromElementMap", "element_id", | |
402 layer->element_id(), "layer_id", layer->id()); | |
403 ElementLayers& layers = element_layers_map_[layer->element_id()]; | |
404 if (layer->mutable_properties() & kMainLayerFlags) | |
405 layers.main() = nullptr; | |
406 if (layer->mutable_properties() & kScrollLayerFlags) | |
407 layers.scroll() = nullptr; | |
408 | |
409 if (!layers.main() && !layers.scroll()) | |
410 element_layers_map_.erase(layer->element_id()); | |
411 } | |
412 | |
413 bool LayerTreeImpl::GetMutableLayers(uint64_t element_id, | |
414 LayerImpl** main_layer, | |
415 LayerImpl** scroll_layer) { | |
416 auto iter = element_layers_map_.find(element_id); | |
417 if (iter == element_layers_map_.end()) | |
418 return false; | |
419 | |
420 *main_layer = iter->second.main(); | |
421 *scroll_layer = iter->second.scroll(); | |
esprehn
2015/11/16 20:01:04
just return the ElementLayers object by value, it'
Ian Vollick
2015/11/18 17:20:33
Done.
| |
422 return true; | |
423 } | |
356 | 424 |
357 LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { | 425 LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { |
358 return InnerViewportScrollLayer() | 426 return InnerViewportScrollLayer() |
359 ? InnerViewportScrollLayer()->scroll_clip_layer() | 427 ? InnerViewportScrollLayer()->scroll_clip_layer() |
360 : NULL; | 428 : NULL; |
361 } | 429 } |
362 | 430 |
363 LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const { | 431 LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const { |
364 return OuterViewportScrollLayer() | 432 return OuterViewportScrollLayer() |
365 ? OuterViewportScrollLayer()->scroll_clip_layer() | 433 ? OuterViewportScrollLayer()->scroll_clip_layer() |
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1927 const gfx::BoxF& box, | 1995 const gfx::BoxF& box, |
1928 gfx::BoxF* bounds) const { | 1996 gfx::BoxF* bounds) const { |
1929 *bounds = gfx::BoxF(); | 1997 *bounds = gfx::BoxF(); |
1930 return layer_tree_host_impl_->animation_host() | 1998 return layer_tree_host_impl_->animation_host() |
1931 ? layer_tree_host_impl_->animation_host() | 1999 ? layer_tree_host_impl_->animation_host() |
1932 ->TransformAnimationBoundsForBox(layer->id(), box, bounds) | 2000 ->TransformAnimationBoundsForBox(layer->id(), box, bounds) |
1933 : true; | 2001 : true; |
1934 } | 2002 } |
1935 | 2003 |
1936 } // namespace cc | 2004 } // namespace cc |
OLD | NEW |