| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_TREES_LAYER_TREE_H_ | |
| 6 #define CC_TREES_LAYER_TREE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <unordered_map> | |
| 10 #include <unordered_set> | |
| 11 | |
| 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/layers/layer_list_iterator.h" | |
| 19 #include "cc/trees/mutator_host_client.h" | |
| 20 #include "cc/trees/property_tree.h" | |
| 21 #include "third_party/skia/include/core/SkColor.h" | |
| 22 #include "ui/gfx/color_space.h" | |
| 23 #include "ui/gfx/geometry/size.h" | |
| 24 | |
| 25 namespace base { | |
| 26 class TimeDelta; | |
| 27 } // namespace base | |
| 28 | |
| 29 namespace cc { | |
| 30 class HeadsUpDisplayLayer; | |
| 31 class Layer; | |
| 32 class LayerTreeHost; | |
| 33 class LayerTreeImpl; | |
| 34 class LayerTreeSettings; | |
| 35 class MutatorHost; | |
| 36 struct PendingPageScaleAnimation; | |
| 37 | |
| 38 class CC_EXPORT LayerTree : public MutatorHostClient { | |
| 39 public: | |
| 40 using LayerSet = std::unordered_set<Layer*>; | |
| 41 using LayerIdMap = std::unordered_map<int, Layer*>; | |
| 42 | |
| 43 LayerTree(MutatorHost* mutator_host, LayerTreeHost* layer_tree_host); | |
| 44 virtual ~LayerTree(); | |
| 45 | |
| 46 void SetRootLayer(scoped_refptr<Layer> root_layer); | |
| 47 Layer* root_layer() { return root_layer_.get(); } | |
| 48 const Layer* root_layer() const { return root_layer_.get(); } | |
| 49 | |
| 50 void RegisterViewportLayers(scoped_refptr<Layer> overscroll_elasticity_layer, | |
| 51 scoped_refptr<Layer> page_scale_layer, | |
| 52 scoped_refptr<Layer> inner_viewport_scroll_layer, | |
| 53 scoped_refptr<Layer> outer_viewport_scroll_layer); | |
| 54 | |
| 55 Layer* overscroll_elasticity_layer() const { | |
| 56 return overscroll_elasticity_layer_.get(); | |
| 57 } | |
| 58 Layer* page_scale_layer() const { return page_scale_layer_.get(); } | |
| 59 Layer* inner_viewport_scroll_layer() const { | |
| 60 return inner_viewport_scroll_layer_.get(); | |
| 61 } | |
| 62 Layer* outer_viewport_scroll_layer() const { | |
| 63 return outer_viewport_scroll_layer_.get(); | |
| 64 } | |
| 65 | |
| 66 void RegisterSelection(const LayerSelection& selection); | |
| 67 const LayerSelection& selection() const { return selection_; } | |
| 68 | |
| 69 void SetHaveScrollEventHandlers(bool have_event_handlers); | |
| 70 bool have_scroll_event_handlers() const { | |
| 71 return have_scroll_event_handlers_; | |
| 72 } | |
| 73 | |
| 74 void SetEventListenerProperties(EventListenerClass event_class, | |
| 75 EventListenerProperties event_properties); | |
| 76 EventListenerProperties event_listener_properties( | |
| 77 EventListenerClass event_class) const { | |
| 78 return event_listener_properties_[static_cast<size_t>(event_class)]; | |
| 79 } | |
| 80 | |
| 81 void SetViewportSize(const gfx::Size& device_viewport_size); | |
| 82 gfx::Size device_viewport_size() const { return device_viewport_size_; } | |
| 83 | |
| 84 void SetBrowserControlsHeight(float height, bool shrink); | |
| 85 void SetBrowserControlsShownRatio(float ratio); | |
| 86 void SetBottomControlsHeight(float height); | |
| 87 | |
| 88 void SetPageScaleFactorAndLimits(float page_scale_factor, | |
| 89 float min_page_scale_factor, | |
| 90 float max_page_scale_factor); | |
| 91 float page_scale_factor() const { return page_scale_factor_; } | |
| 92 float min_page_scale_factor() const { return min_page_scale_factor_; } | |
| 93 float max_page_scale_factor() const { return max_page_scale_factor_; } | |
| 94 | |
| 95 void set_background_color(SkColor color) { background_color_ = color; } | |
| 96 SkColor background_color() const { return background_color_; } | |
| 97 | |
| 98 void set_has_transparent_background(bool transparent) { | |
| 99 has_transparent_background_ = transparent; | |
| 100 } | |
| 101 bool has_transparent_background() const { | |
| 102 return has_transparent_background_; | |
| 103 } | |
| 104 | |
| 105 void StartPageScaleAnimation(const gfx::Vector2d& target_offset, | |
| 106 bool use_anchor, | |
| 107 float scale, | |
| 108 base::TimeDelta duration); | |
| 109 bool HasPendingPageScaleAnimation() const; | |
| 110 | |
| 111 void SetDeviceScaleFactor(float device_scale_factor); | |
| 112 float device_scale_factor() const { return device_scale_factor_; } | |
| 113 | |
| 114 void SetPaintedDeviceScaleFactor(float painted_device_scale_factor); | |
| 115 float painted_device_scale_factor() const { | |
| 116 return painted_device_scale_factor_; | |
| 117 } | |
| 118 | |
| 119 void SetDeviceColorSpace(const gfx::ColorSpace& device_color_space); | |
| 120 const gfx::ColorSpace& device_color_space() const { | |
| 121 return device_color_space_; | |
| 122 } | |
| 123 | |
| 124 // Used externally by blink for setting the PropertyTrees when | |
| 125 // |settings_.use_layer_lists| is true. This is a SPV2 setting. | |
| 126 PropertyTrees* property_trees() { return &property_trees_; } | |
| 127 | |
| 128 void SetNeedsDisplayOnAllLayers(); | |
| 129 | |
| 130 void SetNeedsCommit(); | |
| 131 | |
| 132 const LayerTreeSettings& GetSettings() const; | |
| 133 | |
| 134 // Methods which should only be used internally in cc ------------------ | |
| 135 void RegisterLayer(Layer* layer); | |
| 136 void UnregisterLayer(Layer* layer); | |
| 137 Layer* LayerById(int id) const; | |
| 138 | |
| 139 size_t NumLayers() const; | |
| 140 | |
| 141 bool UpdateLayers(const LayerList& update_layer_list, | |
| 142 bool* content_is_suitable_for_gpu); | |
| 143 bool in_paint_layer_contents() const { return in_paint_layer_contents_; } | |
| 144 | |
| 145 void AddLayerShouldPushProperties(Layer* layer); | |
| 146 void RemoveLayerShouldPushProperties(Layer* layer); | |
| 147 std::unordered_set<Layer*>& LayersThatShouldPushProperties(); | |
| 148 bool LayerNeedsPushPropertiesForTesting(Layer* layer) const; | |
| 149 | |
| 150 virtual void SetNeedsMetaInfoRecomputation( | |
| 151 bool needs_meta_info_recomputation); | |
| 152 bool needs_meta_info_recomputation() const { | |
| 153 return needs_meta_info_recomputation_; | |
| 154 } | |
| 155 | |
| 156 void SetPageScaleFromImplSide(float page_scale); | |
| 157 void SetElasticOverscrollFromImplSide(gfx::Vector2dF elastic_overscroll); | |
| 158 gfx::Vector2dF elastic_overscroll() const { return elastic_overscroll_; } | |
| 159 | |
| 160 void UpdateHudLayer(bool show_hud_info); | |
| 161 HeadsUpDisplayLayer* hud_layer() const { return hud_layer_.get(); } | |
| 162 | |
| 163 virtual void SetNeedsFullTreeSync(); | |
| 164 bool needs_full_tree_sync() const { return needs_full_tree_sync_; } | |
| 165 | |
| 166 void SetPropertyTreesNeedRebuild(); | |
| 167 | |
| 168 void PushPropertiesTo(LayerTreeImpl* tree_impl); | |
| 169 | |
| 170 MutatorHost* mutator_host() const { return mutator_host_; } | |
| 171 | |
| 172 Layer* LayerByElementId(ElementId element_id) const; | |
| 173 void RegisterElement(ElementId element_id, | |
| 174 ElementListType list_type, | |
| 175 Layer* layer); | |
| 176 void UnregisterElement(ElementId element_id, | |
| 177 ElementListType list_type, | |
| 178 Layer* layer); | |
| 179 void SetElementIdsForTesting(); | |
| 180 | |
| 181 void BuildPropertyTreesForTesting(); | |
| 182 | |
| 183 // Layer iterators. | |
| 184 LayerListIterator<Layer> begin() const; | |
| 185 LayerListIterator<Layer> end() const; | |
| 186 LayerListReverseIterator<Layer> rbegin(); | |
| 187 LayerListReverseIterator<Layer> rend(); | |
| 188 // --------------------------------------------------------------------- | |
| 189 | |
| 190 private: | |
| 191 // MutatorHostClient implementation. | |
| 192 bool IsElementInList(ElementId element_id, | |
| 193 ElementListType list_type) const override; | |
| 194 void SetMutatorsNeedCommit() override; | |
| 195 void SetMutatorsNeedRebuildPropertyTrees() override; | |
| 196 void SetElementFilterMutated(ElementId element_id, | |
| 197 ElementListType list_type, | |
| 198 const FilterOperations& filters) override; | |
| 199 void SetElementOpacityMutated(ElementId element_id, | |
| 200 ElementListType list_type, | |
| 201 float opacity) override; | |
| 202 void SetElementTransformMutated(ElementId element_id, | |
| 203 ElementListType list_type, | |
| 204 const gfx::Transform& transform) override; | |
| 205 void SetElementScrollOffsetMutated( | |
| 206 ElementId element_id, | |
| 207 ElementListType list_type, | |
| 208 const gfx::ScrollOffset& scroll_offset) override; | |
| 209 | |
| 210 void ElementIsAnimatingChanged(ElementId element_id, | |
| 211 ElementListType list_type, | |
| 212 const PropertyAnimationState& mask, | |
| 213 const PropertyAnimationState& state) override; | |
| 214 | |
| 215 void ScrollOffsetAnimationFinished() override {} | |
| 216 gfx::ScrollOffset GetScrollOffsetForAnimation( | |
| 217 ElementId element_id) const override; | |
| 218 | |
| 219 scoped_refptr<Layer> root_layer_; | |
| 220 | |
| 221 scoped_refptr<Layer> overscroll_elasticity_layer_; | |
| 222 scoped_refptr<Layer> page_scale_layer_; | |
| 223 scoped_refptr<Layer> inner_viewport_scroll_layer_; | |
| 224 scoped_refptr<Layer> outer_viewport_scroll_layer_; | |
| 225 | |
| 226 float top_controls_height_ = 0.f; | |
| 227 float top_controls_shown_ratio_ = 0.f; | |
| 228 bool browser_controls_shrink_blink_size_ = false; | |
| 229 | |
| 230 float bottom_controls_height_ = 0.f; | |
| 231 | |
| 232 float device_scale_factor_ = 1.f; | |
| 233 float painted_device_scale_factor_ = 1.f; | |
| 234 float page_scale_factor_ = 1.f; | |
| 235 float min_page_scale_factor_ = 1.f; | |
| 236 float max_page_scale_factor_ = 1.f; | |
| 237 gfx::ColorSpace device_color_space_; | |
| 238 | |
| 239 SkColor background_color_ = SK_ColorWHITE; | |
| 240 bool has_transparent_background_ = false; | |
| 241 | |
| 242 LayerSelection selection_; | |
| 243 | |
| 244 gfx::Size device_viewport_size_; | |
| 245 | |
| 246 bool have_scroll_event_handlers_ = false; | |
| 247 EventListenerProperties event_listener_properties_[static_cast<size_t>( | |
| 248 EventListenerClass::kNumClasses)]; | |
| 249 | |
| 250 std::unique_ptr<PendingPageScaleAnimation> pending_page_scale_animation_; | |
| 251 | |
| 252 PropertyTrees property_trees_; | |
| 253 | |
| 254 bool needs_full_tree_sync_ = true; | |
| 255 bool needs_meta_info_recomputation_ = true; | |
| 256 | |
| 257 gfx::Vector2dF elastic_overscroll_; | |
| 258 | |
| 259 scoped_refptr<HeadsUpDisplayLayer> hud_layer_; | |
| 260 | |
| 261 // Set of layers that need to push properties. | |
| 262 LayerSet layers_that_should_push_properties_; | |
| 263 | |
| 264 // Layer id to Layer map. | |
| 265 LayerIdMap layer_id_map_; | |
| 266 | |
| 267 using ElementLayersMap = std::unordered_map<ElementId, Layer*, ElementIdHash>; | |
| 268 ElementLayersMap element_layers_map_; | |
| 269 | |
| 270 bool in_paint_layer_contents_ = false; | |
| 271 | |
| 272 MutatorHost* mutator_host_; | |
| 273 LayerTreeHost* layer_tree_host_; | |
| 274 | |
| 275 DISALLOW_COPY_AND_ASSIGN(LayerTree); | |
| 276 }; | |
| 277 | |
| 278 } // namespace cc | |
| 279 | |
| 280 #endif // CC_TREES_LAYER_TREE_H_ | |
| OLD | NEW |