OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CC_TREES_LAYER_TREE_H_ | 5 #ifndef CC_TREES_LAYER_TREE_H_ |
6 #define CC_TREES_LAYER_TREE_H_ | 6 #define CC_TREES_LAYER_TREE_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include <unordered_map> | 10 #include <unordered_map> |
9 #include <unordered_set> | 11 #include <unordered_set> |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "cc/base/cc_export.h" |
| 15 #include "cc/input/event_listener_properties.h" |
| 16 #include "cc/input/layer_selection_bound.h" |
| 17 #include "cc/layers/layer_collections.h" |
| 18 #include "cc/trees/property_tree.h" |
| 19 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/gfx/geometry/size.h" |
10 | 21 |
11 #include "base/macros.h" | 22 namespace base { |
12 #include "cc/base/cc_export.h" | 23 class TimeDelta; |
| 24 } // namespace base |
13 | 25 |
14 namespace cc { | 26 namespace cc { |
15 | 27 |
16 namespace proto { | 28 namespace proto { |
17 class LayerTree; | 29 class LayerTree; |
18 class LayerUpdate; | 30 class LayerUpdate; |
19 } | 31 } // namespace proto |
20 | 32 |
21 class AnimationHost; | 33 class AnimationHost; |
| 34 class HeadsUpDisplayLayer; |
22 class Layer; | 35 class Layer; |
| 36 class LayerTreeHost; |
| 37 class LayerTreeImpl; |
| 38 struct PendingPageScaleAnimation; |
23 | 39 |
24 class CC_EXPORT LayerTree { | 40 class CC_EXPORT LayerTree { |
25 public: | 41 public: |
26 using LayerSet = std::unordered_set<Layer*>; | 42 using LayerSet = std::unordered_set<Layer*>; |
27 using LayerIdMap = std::unordered_map<int, Layer*>; | 43 using LayerIdMap = std::unordered_map<int, Layer*>; |
28 | 44 |
29 explicit LayerTree(std::unique_ptr<AnimationHost> animation_host); | 45 LayerTree(std::unique_ptr<AnimationHost> animation_host, |
30 ~LayerTree(); | 46 LayerTreeHost* layer_tree_host); |
| 47 virtual ~LayerTree(); |
31 | 48 |
| 49 void SetRootLayer(scoped_refptr<Layer> root_layer); |
| 50 Layer* root_layer() { return inputs_.root_layer.get(); } |
| 51 const Layer* root_layer() const { return inputs_.root_layer.get(); } |
| 52 |
| 53 void RegisterViewportLayers(scoped_refptr<Layer> overscroll_elasticity_layer, |
| 54 scoped_refptr<Layer> page_scale_layer, |
| 55 scoped_refptr<Layer> inner_viewport_scroll_layer, |
| 56 scoped_refptr<Layer> outer_viewport_scroll_layer); |
| 57 |
| 58 Layer* overscroll_elasticity_layer() const { |
| 59 return inputs_.overscroll_elasticity_layer.get(); |
| 60 } |
| 61 Layer* page_scale_layer() const { return inputs_.page_scale_layer.get(); } |
| 62 Layer* inner_viewport_scroll_layer() const { |
| 63 return inputs_.inner_viewport_scroll_layer.get(); |
| 64 } |
| 65 Layer* outer_viewport_scroll_layer() const { |
| 66 return inputs_.outer_viewport_scroll_layer.get(); |
| 67 } |
| 68 |
| 69 void RegisterSelection(const LayerSelection& selection); |
| 70 |
| 71 void SetHaveScrollEventHandlers(bool have_event_handlers); |
| 72 bool have_scroll_event_handlers() const { |
| 73 return inputs_.have_scroll_event_handlers; |
| 74 } |
| 75 |
| 76 void SetEventListenerProperties(EventListenerClass event_class, |
| 77 EventListenerProperties event_properties); |
| 78 EventListenerProperties event_listener_properties( |
| 79 EventListenerClass event_class) const { |
| 80 return inputs_.event_listener_properties[static_cast<size_t>(event_class)]; |
| 81 } |
| 82 |
| 83 void SetViewportSize(const gfx::Size& device_viewport_size); |
| 84 gfx::Size device_viewport_size() const { |
| 85 return inputs_.device_viewport_size; |
| 86 } |
| 87 |
| 88 void SetTopControlsHeight(float height, bool shrink); |
| 89 void SetTopControlsShownRatio(float ratio); |
| 90 |
| 91 void SetPageScaleFactorAndLimits(float page_scale_factor, |
| 92 float min_page_scale_factor, |
| 93 float max_page_scale_factor); |
| 94 float page_scale_factor() const { return inputs_.page_scale_factor; } |
| 95 |
| 96 void set_background_color(SkColor color) { inputs_.background_color = color; } |
| 97 SkColor background_color() const { return inputs_.background_color; } |
| 98 |
| 99 void set_has_transparent_background(bool transparent) { |
| 100 inputs_.has_transparent_background = transparent; |
| 101 } |
| 102 |
| 103 void StartPageScaleAnimation(const gfx::Vector2d& target_offset, |
| 104 bool use_anchor, |
| 105 float scale, |
| 106 base::TimeDelta duration); |
| 107 bool HasPendingPageScaleAnimation() const; |
| 108 |
| 109 void SetDeviceScaleFactor(float device_scale_factor); |
| 110 float device_scale_factor() const { return inputs_.device_scale_factor; } |
| 111 |
| 112 void SetPaintedDeviceScaleFactor(float painted_device_scale_factor); |
| 113 |
| 114 AnimationHost* animation_host() const { return animation_host_.get(); } |
| 115 |
| 116 gfx::Vector2dF elastic_overscroll() const { return elastic_overscroll_; } |
| 117 |
| 118 // Used externally by blink for setting the PropertyTrees when |
| 119 // |settings_.use_layer_lists| is true. This is a SPV2 setting. |
| 120 PropertyTrees* property_trees() { return &property_trees_; } |
| 121 |
| 122 // Methods which should only be used internally in cc ------------------ |
32 void RegisterLayer(Layer* layer); | 123 void RegisterLayer(Layer* layer); |
33 void UnregisterLayer(Layer* layer); | 124 void UnregisterLayer(Layer* layer); |
34 Layer* LayerById(int id) const; | 125 Layer* LayerById(int id) const; |
35 bool UpdateLayers(const LayerList& update_layer_list, | 126 bool UpdateLayers(const LayerList& update_layer_list, |
36 bool* content_is_suitable_for_gpu); | 127 bool* content_is_suitable_for_gpu); |
37 | 128 |
38 void AddLayerShouldPushProperties(Layer* layer); | 129 void AddLayerShouldPushProperties(Layer* layer); |
39 void RemoveLayerShouldPushProperties(Layer* layer); | 130 void RemoveLayerShouldPushProperties(Layer* layer); |
40 std::unordered_set<Layer*>& LayersThatShouldPushProperties(); | 131 std::unordered_set<Layer*>& LayersThatShouldPushProperties(); |
41 bool LayerNeedsPushPropertiesForTesting(Layer* layer) const; | 132 bool LayerNeedsPushPropertiesForTesting(Layer* layer) const; |
42 | 133 |
| 134 virtual void SetNeedsMetaInfoRecomputation( |
| 135 bool needs_meta_info_recomputation); |
| 136 bool needs_meta_info_recomputation() const { |
| 137 return needs_meta_info_recomputation_; |
| 138 } |
| 139 |
| 140 void SetPageScaleFromImplSide(float page_scale); |
| 141 void SetElasticOverscrollFromImplSide(gfx::Vector2dF elastic_overscroll); |
| 142 |
| 143 void UpdateHudLayer(bool show_hud_info); |
| 144 HeadsUpDisplayLayer* hud_layer() const { return hud_layer_.get(); } |
| 145 |
| 146 virtual void SetNeedsFullTreeSync(); |
| 147 bool needs_full_tree_sync() const { return needs_full_tree_sync_; } |
| 148 |
| 149 void SetNeedsCommit(); |
| 150 void SetPropertyTreesNeedRebuild(); |
| 151 |
| 152 void PushPropertiesTo(LayerTreeImpl* tree_impl); |
| 153 |
43 void ToProtobuf(proto::LayerTree* proto); | 154 void ToProtobuf(proto::LayerTree* proto); |
44 void FromProtobuf(const proto::LayerTree& proto); | 155 void FromProtobuf(const proto::LayerTree& proto); |
45 | 156 |
46 AnimationHost* animation_host() const { return animation_host_.get(); } | |
47 | |
48 bool in_paint_layer_contents() const { return in_paint_layer_contents_; } | 157 bool in_paint_layer_contents() const { return in_paint_layer_contents_; } |
| 158 // --------------------------------------------------------------------- |
49 | 159 |
50 private: | 160 private: |
51 friend class LayerTreeHostSerializationTest; | 161 friend class LayerTreeHostSerializationTest; |
52 | 162 |
| 163 // Encapsulates the data, callbacks, interfaces received from the embedder. |
| 164 struct Inputs { |
| 165 Inputs(); |
| 166 ~Inputs(); |
| 167 |
| 168 scoped_refptr<Layer> root_layer; |
| 169 |
| 170 scoped_refptr<Layer> overscroll_elasticity_layer; |
| 171 scoped_refptr<Layer> page_scale_layer; |
| 172 scoped_refptr<Layer> inner_viewport_scroll_layer; |
| 173 scoped_refptr<Layer> outer_viewport_scroll_layer; |
| 174 |
| 175 float top_controls_height; |
| 176 float top_controls_shown_ratio; |
| 177 bool top_controls_shrink_blink_size; |
| 178 |
| 179 float device_scale_factor; |
| 180 float painted_device_scale_factor; |
| 181 float page_scale_factor; |
| 182 float min_page_scale_factor; |
| 183 float max_page_scale_factor; |
| 184 |
| 185 SkColor background_color; |
| 186 bool has_transparent_background; |
| 187 |
| 188 LayerSelection selection; |
| 189 |
| 190 gfx::Size device_viewport_size; |
| 191 |
| 192 bool have_scroll_event_handlers; |
| 193 EventListenerProperties event_listener_properties[static_cast<size_t>( |
| 194 EventListenerClass::kNumClasses)]; |
| 195 |
| 196 std::unique_ptr<PendingPageScaleAnimation> pending_page_scale_animation; |
| 197 }; |
| 198 |
| 199 Inputs inputs_; |
| 200 |
| 201 PropertyTrees property_trees_; |
| 202 |
| 203 bool needs_full_tree_sync_; |
| 204 bool needs_meta_info_recomputation_; |
| 205 |
| 206 gfx::Vector2dF elastic_overscroll_; |
| 207 |
| 208 scoped_refptr<HeadsUpDisplayLayer> hud_layer_; |
| 209 |
53 // Set of layers that need to push properties. | 210 // Set of layers that need to push properties. |
54 LayerSet layers_that_should_push_properties_; | 211 LayerSet layers_that_should_push_properties_; |
55 | 212 |
56 // Layer id to Layer map. | 213 // Layer id to Layer map. |
57 LayerIdMap layer_id_map_; | 214 LayerIdMap layer_id_map_; |
58 | 215 |
59 bool in_paint_layer_contents_; | 216 bool in_paint_layer_contents_; |
60 | 217 |
61 std::unique_ptr<AnimationHost> animation_host_; | 218 std::unique_ptr<AnimationHost> animation_host_; |
| 219 LayerTreeHost* layer_tree_host_; |
62 | 220 |
63 DISALLOW_COPY_AND_ASSIGN(LayerTree); | 221 DISALLOW_COPY_AND_ASSIGN(LayerTree); |
64 }; | 222 }; |
65 | 223 |
66 } // namespace cc | 224 } // namespace cc |
67 | 225 |
68 #endif // CC_TREES_LAYER_TREE_H_ | 226 #endif // CC_TREES_LAYER_TREE_H_ |
OLD | NEW |