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 | |
10 #include <unordered_map> | 8 #include <unordered_map> |
11 #include <unordered_set> | 9 #include <unordered_set> |
| 10 |
12 #include "base/macros.h" | 11 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | |
14 #include "cc/base/cc_export.h" | 12 #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" | |
21 | |
22 namespace base { | |
23 class TimeDelta; | |
24 } // namespace base | |
25 | 13 |
26 namespace cc { | 14 namespace cc { |
27 | 15 |
28 namespace proto { | 16 namespace proto { |
29 class LayerTree; | 17 class LayerTree; |
30 class LayerUpdate; | 18 class LayerUpdate; |
31 } // namespace proto | 19 } |
32 | 20 |
33 class AnimationHost; | 21 class AnimationHost; |
34 class HeadsUpDisplayLayer; | |
35 class Layer; | 22 class Layer; |
36 class LayerTreeHost; | |
37 class LayerTreeImpl; | |
38 struct PendingPageScaleAnimation; | |
39 | 23 |
40 class CC_EXPORT LayerTree { | 24 class CC_EXPORT LayerTree { |
41 public: | 25 public: |
42 using LayerSet = std::unordered_set<Layer*>; | 26 using LayerSet = std::unordered_set<Layer*>; |
43 using LayerIdMap = std::unordered_map<int, Layer*>; | 27 using LayerIdMap = std::unordered_map<int, Layer*>; |
44 | 28 |
45 LayerTree(std::unique_ptr<AnimationHost> animation_host, | 29 explicit LayerTree(std::unique_ptr<AnimationHost> animation_host); |
46 LayerTreeHost* layer_tree_host); | 30 ~LayerTree(); |
47 virtual ~LayerTree(); | |
48 | 31 |
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 ------------------ | |
123 void RegisterLayer(Layer* layer); | 32 void RegisterLayer(Layer* layer); |
124 void UnregisterLayer(Layer* layer); | 33 void UnregisterLayer(Layer* layer); |
125 Layer* LayerById(int id) const; | 34 Layer* LayerById(int id) const; |
126 bool UpdateLayers(const LayerList& update_layer_list, | 35 bool UpdateLayers(const LayerList& update_layer_list, |
127 bool* content_is_suitable_for_gpu); | 36 bool* content_is_suitable_for_gpu); |
128 | 37 |
129 void AddLayerShouldPushProperties(Layer* layer); | 38 void AddLayerShouldPushProperties(Layer* layer); |
130 void RemoveLayerShouldPushProperties(Layer* layer); | 39 void RemoveLayerShouldPushProperties(Layer* layer); |
131 std::unordered_set<Layer*>& LayersThatShouldPushProperties(); | 40 std::unordered_set<Layer*>& LayersThatShouldPushProperties(); |
132 bool LayerNeedsPushPropertiesForTesting(Layer* layer) const; | 41 bool LayerNeedsPushPropertiesForTesting(Layer* layer) const; |
133 | 42 |
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 | |
154 void ToProtobuf(proto::LayerTree* proto); | 43 void ToProtobuf(proto::LayerTree* proto); |
155 void FromProtobuf(const proto::LayerTree& proto); | 44 void FromProtobuf(const proto::LayerTree& proto); |
156 | 45 |
| 46 AnimationHost* animation_host() const { return animation_host_.get(); } |
| 47 |
157 bool in_paint_layer_contents() const { return in_paint_layer_contents_; } | 48 bool in_paint_layer_contents() const { return in_paint_layer_contents_; } |
158 // --------------------------------------------------------------------- | |
159 | 49 |
160 private: | 50 private: |
161 friend class LayerTreeHostSerializationTest; | 51 friend class LayerTreeHostSerializationTest; |
162 | 52 |
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 | |
210 // Set of layers that need to push properties. | 53 // Set of layers that need to push properties. |
211 LayerSet layers_that_should_push_properties_; | 54 LayerSet layers_that_should_push_properties_; |
212 | 55 |
213 // Layer id to Layer map. | 56 // Layer id to Layer map. |
214 LayerIdMap layer_id_map_; | 57 LayerIdMap layer_id_map_; |
215 | 58 |
216 bool in_paint_layer_contents_; | 59 bool in_paint_layer_contents_; |
217 | 60 |
218 std::unique_ptr<AnimationHost> animation_host_; | 61 std::unique_ptr<AnimationHost> animation_host_; |
219 LayerTreeHost* layer_tree_host_; | |
220 | 62 |
221 DISALLOW_COPY_AND_ASSIGN(LayerTree); | 63 DISALLOW_COPY_AND_ASSIGN(LayerTree); |
222 }; | 64 }; |
223 | 65 |
224 } // namespace cc | 66 } // namespace cc |
225 | 67 |
226 #endif // CC_TREES_LAYER_TREE_H_ | 68 #endif // CC_TREES_LAYER_TREE_H_ |
OLD | NEW |