Update V8 to version 4.7.42.
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.h
blob6101626fa0424c9ab1f011456965f02c93bdf65a
1 // Copyright 2012 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.
5 #ifndef CC_TREES_LAYER_TREE_IMPL_H_
6 #define CC_TREES_LAYER_TREE_IMPL_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/containers/hash_tables.h"
13 #include "base/values.h"
14 #include "cc/base/scoped_ptr_vector.h"
15 #include "cc/base/synced_property.h"
16 #include "cc/input/layer_selection_bound.h"
17 #include "cc/layers/layer_impl.h"
18 #include "cc/output/begin_frame_args.h"
19 #include "cc/output/renderer.h"
20 #include "cc/output/swap_promise.h"
21 #include "cc/resources/ui_resource_client.h"
22 #include "cc/trees/layer_tree_host_impl.h"
23 #include "cc/trees/property_tree.h"
25 namespace base {
26 namespace trace_event {
27 class TracedValue;
31 namespace cc {
33 class ContextProvider;
34 class DebugRectHistory;
35 class FrameRateCounter;
36 class HeadsUpDisplayLayerImpl;
37 class LayerExternalScrollOffsetListener;
38 class LayerScrollOffsetDelegate;
39 class LayerTreeDebugState;
40 class LayerTreeImpl;
41 class LayerTreeSettings;
42 class MemoryHistory;
43 class OutputSurface;
44 class PageScaleAnimation;
45 class PaintTimeCounter;
46 class PictureLayerImpl;
47 class Proxy;
48 class ResourceProvider;
49 class TileManager;
50 class UIResourceRequest;
51 class VideoFrameControllerClient;
52 struct PendingPageScaleAnimation;
53 struct RendererCapabilities;
55 typedef std::vector<UIResourceRequest> UIResourceRequestQueue;
56 typedef SyncedProperty<AdditionGroup<float>> SyncedTopControls;
57 typedef SyncedProperty<AdditionGroup<gfx::Vector2dF>> SyncedElasticOverscroll;
59 class CC_EXPORT LayerTreeImpl {
60 public:
61 static scoped_ptr<LayerTreeImpl> create(
62 LayerTreeHostImpl* layer_tree_host_impl,
63 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
64 scoped_refptr<SyncedTopControls> top_controls_shown_ratio,
65 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) {
66 return make_scoped_ptr(
67 new LayerTreeImpl(layer_tree_host_impl, page_scale_factor,
68 top_controls_shown_ratio, elastic_overscroll));
70 virtual ~LayerTreeImpl();
72 void Shutdown();
73 void ReleaseResources();
74 void RecreateResources();
76 // Methods called by the layer tree that pass-through or access LTHI.
77 // ---------------------------------------------------------------------------
78 const LayerTreeSettings& settings() const;
79 const LayerTreeDebugState& debug_state() const;
80 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
81 ContextProvider* context_provider() const;
82 OutputSurface* output_surface() const;
83 ResourceProvider* resource_provider() const;
84 TileManager* tile_manager() const;
85 FrameRateCounter* frame_rate_counter() const;
86 PaintTimeCounter* paint_time_counter() const;
87 MemoryHistory* memory_history() const;
88 gfx::Size device_viewport_size() const;
89 float device_scale_factor() const;
90 DebugRectHistory* debug_rect_history() const;
91 bool IsActiveTree() const;
92 bool IsPendingTree() const;
93 bool IsRecycleTree() const;
94 bool IsSyncTree() const;
95 LayerImpl* FindActiveTreeLayerById(int id);
96 LayerImpl* FindPendingTreeLayerById(int id);
97 bool PinchGestureActive() const;
98 BeginFrameArgs CurrentBeginFrameArgs() const;
99 base::TimeDelta CurrentBeginFrameInterval() const;
100 void SetNeedsCommit();
101 gfx::Rect DeviceViewport() const;
102 gfx::Size DrawViewportSize() const;
103 const gfx::Rect ViewportRectForTilePriority() const;
104 scoped_ptr<ScrollbarAnimationController> CreateScrollbarAnimationController(
105 LayerImpl* scrolling_layer);
106 void DidAnimateScrollOffset();
107 void InputScrollAnimationFinished();
108 bool use_gpu_rasterization() const;
109 GpuRasterizationStatus GetGpuRasterizationStatus() const;
110 bool create_low_res_tiling() const;
111 BlockingTaskRunner* BlockingMainThreadTaskRunner() const;
112 bool RequiresHighResToDraw() const;
113 bool SmoothnessTakesPriority() const;
114 VideoFrameControllerClient* GetVideoFrameControllerClient() const;
116 // Tree specific methods exposed to layer-impl tree.
117 // ---------------------------------------------------------------------------
118 void SetNeedsRedraw();
120 // Tracing methods.
121 // ---------------------------------------------------------------------------
122 void GetAllPrioritizedTilesForTracing(
123 std::vector<PrioritizedTile>* prioritized_tiles) const;
124 void AsValueInto(base::trace_event::TracedValue* dict) const;
126 // Other public methods
127 // ---------------------------------------------------------------------------
128 LayerImpl* root_layer() const { return root_layer_.get(); }
129 void SetRootLayer(scoped_ptr<LayerImpl>);
130 scoped_ptr<LayerImpl> DetachLayerTree();
132 void SetPropertyTrees(const PropertyTrees& property_trees) {
133 property_trees_ = property_trees;
134 property_trees_.transform_tree.set_source_to_parent_updates_allowed(false);
136 PropertyTrees* property_trees() { return &property_trees_; }
138 void UpdatePropertyTreesForBoundsDelta();
140 void PushPropertiesTo(LayerTreeImpl* tree_impl);
142 int source_frame_number() const { return source_frame_number_; }
143 void set_source_frame_number(int frame_number) {
144 source_frame_number_ = frame_number;
147 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
148 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
149 hud_layer_ = layer_impl;
152 LayerImpl* InnerViewportScrollLayer() const;
153 // This function may return NULL, it is the caller's responsibility to check.
154 LayerImpl* OuterViewportScrollLayer() const;
155 gfx::ScrollOffset TotalScrollOffset() const;
156 gfx::ScrollOffset TotalMaxScrollOffset() const;
158 LayerImpl* InnerViewportContainerLayer() const;
159 LayerImpl* OuterViewportContainerLayer() const;
160 LayerImpl* CurrentlyScrollingLayer() const;
161 void SetCurrentlyScrollingLayer(LayerImpl* layer);
162 void ClearCurrentlyScrollingLayer();
164 void SetViewportLayersFromIds(int overscroll_elasticity_layer,
165 int page_scale_layer_id,
166 int inner_viewport_scroll_layer_id,
167 int outer_viewport_scroll_layer_id);
168 void ClearViewportLayers();
169 LayerImpl* OverscrollElasticityLayer() {
170 return LayerById(overscroll_elasticity_layer_id_);
172 LayerImpl* PageScaleLayer() { return LayerById(page_scale_layer_id_); }
173 void ApplySentScrollAndScaleDeltasFromAbortedCommit();
175 SkColor background_color() const { return background_color_; }
176 void set_background_color(SkColor color) { background_color_ = color; }
178 bool has_transparent_background() const {
179 return has_transparent_background_;
181 void set_has_transparent_background(bool transparent) {
182 has_transparent_background_ = transparent;
185 void UpdatePropertyTreeScrollingAndAnimationFromMainThread();
186 void SetPageScaleOnActiveTree(float active_page_scale);
187 void PushPageScaleFromMainThread(float page_scale_factor,
188 float min_page_scale_factor,
189 float max_page_scale_factor);
190 float current_page_scale_factor() const {
191 return page_scale_factor()->Current(IsActiveTree());
193 float min_page_scale_factor() const { return min_page_scale_factor_; }
194 float max_page_scale_factor() const { return max_page_scale_factor_; }
196 float page_scale_delta() const { return page_scale_factor()->Delta(); }
198 SyncedProperty<ScaleGroup>* page_scale_factor();
199 const SyncedProperty<ScaleGroup>* page_scale_factor() const;
201 void set_hide_pinch_scrollbars_near_min_scale(bool hide) {
202 hide_pinch_scrollbars_near_min_scale_ = hide;
205 SyncedElasticOverscroll* elastic_overscroll() {
206 return elastic_overscroll_.get();
208 const SyncedElasticOverscroll* elastic_overscroll() const {
209 return elastic_overscroll_.get();
212 SyncedTopControls* top_controls_shown_ratio() {
213 return top_controls_shown_ratio_.get();
215 const SyncedTopControls* top_controls_shown_ratio() const {
216 return top_controls_shown_ratio_.get();
219 // Updates draw properties and render surface layer list, as well as tile
220 // priorities. Returns false if it was unable to update. Updating lcd
221 // text may cause invalidations, so should only be done after a commit.
222 bool UpdateDrawProperties(bool update_lcd_text);
223 void BuildPropertyTreesForTesting();
225 void set_needs_update_draw_properties() {
226 needs_update_draw_properties_ = true;
228 bool needs_update_draw_properties() const {
229 return needs_update_draw_properties_;
232 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
233 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
235 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
237 void set_has_ever_been_drawn(bool has_drawn) {
238 has_ever_been_drawn_ = has_drawn;
240 bool has_ever_been_drawn() const { return has_ever_been_drawn_; }
242 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
244 const LayerImplList& RenderSurfaceLayerList() const;
245 const Region& UnoccludedScreenSpaceRegion() const;
247 // These return the size of the root scrollable area and the size of
248 // the user-visible scrolling viewport, in CSS layout coordinates.
249 gfx::SizeF ScrollableSize() const;
250 gfx::SizeF ScrollableViewportSize() const;
252 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
254 LayerImpl* LayerById(int id) const;
256 // These should be called by LayerImpl's ctor/dtor.
257 void RegisterLayer(LayerImpl* layer);
258 void UnregisterLayer(LayerImpl* layer);
260 size_t NumLayers();
262 AnimationRegistrar* GetAnimationRegistrar() const;
264 void DidBecomeActive();
266 // Set on the active tree when the viewport size recently changed
267 // and the active tree's size is now out of date.
268 bool ViewportSizeInvalid() const;
269 void SetViewportSizeInvalid();
270 void ResetViewportSizeInvalid();
272 // Useful for debug assertions, probably shouldn't be used for anything else.
273 Proxy* proxy() const;
275 void SetRootLayerScrollOffsetDelegate(
276 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
277 void UpdateRootScrollOffsetDelegate();
278 // Distribute the root scroll between outer and inner viewport scroll layer.
279 // The outer viewport scroll layer scrolls first.
280 void DistributeRootScrollOffset(const gfx::ScrollOffset& root_offset);
282 void ApplyScroll(LayerImpl* layer, ScrollState* scroll_state) {
283 layer_tree_host_impl_->ApplyScroll(layer, scroll_state);
286 // Call this function when you expect there to be a swap buffer.
287 // See swap_promise.h for how to use SwapPromise.
289 // A swap promise queued by QueueSwapPromise travels with the layer
290 // information currently associated with the tree. For example, when
291 // a pending tree is activated, the swap promise is passed to the
292 // active tree along with the layer information. Similarly, when a
293 // new activation overwrites layer information on the active tree,
294 // queued swap promises are broken.
295 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
297 // Queue a swap promise, pinned to this tree. Pinned swap promises
298 // may only be queued on the active tree.
300 // An active tree pinned swap promise will see only DidSwap() or
301 // DidNotSwap(SWAP_FAILS). No DidActivate() will be seen because
302 // that has already happened prior to queueing of the swap promise.
304 // Pinned active tree swap promises will not be broken prematurely
305 // on the active tree if a new tree is activated.
306 void QueuePinnedSwapPromise(scoped_ptr<SwapPromise> swap_promise);
308 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
309 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
310 void FinishSwapPromises(CompositorFrameMetadata* metadata);
311 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
313 void DidModifyTilePriorities();
315 ResourceId ResourceIdForUIResource(UIResourceId uid) const;
316 void ProcessUIResourceRequestQueue();
318 bool IsUIResourceOpaque(UIResourceId uid) const;
320 void RegisterPictureLayerImpl(PictureLayerImpl* layer);
321 void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
322 const std::vector<PictureLayerImpl*>& picture_layers() const {
323 return picture_layers_;
326 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
327 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
328 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
330 int current_render_surface_list_id() const {
331 return render_surface_layer_list_id_;
334 LayerImpl* FindFirstScrollingLayerThatIsHitByPoint(
335 const gfx::PointF& screen_space_point);
337 LayerImpl* FindLayerThatIsHitByPoint(const gfx::PointF& screen_space_point);
339 LayerImpl* FindLayerWithWheelHandlerThatIsHitByPoint(
340 const gfx::PointF& screen_space_point);
342 LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
343 const gfx::PointF& screen_space_point);
345 void RegisterSelection(const LayerSelection& selection);
347 // Compute the current selection handle location and visbility with respect to
348 // the viewport.
349 void GetViewportSelection(ViewportSelection* selection);
351 void set_top_controls_shrink_blink_size(bool shrink);
352 bool top_controls_shrink_blink_size() const {
353 return top_controls_shrink_blink_size_;
355 bool SetCurrentTopControlsShownRatio(float ratio);
356 float CurrentTopControlsShownRatio() const {
357 return top_controls_shown_ratio_->Current(IsActiveTree());
359 void set_top_controls_height(float top_controls_height);
360 float top_controls_height() const { return top_controls_height_; }
361 void PushTopControlsFromMainThread(float top_controls_shown_ratio);
363 void SetPendingPageScaleAnimation(
364 scoped_ptr<PendingPageScaleAnimation> pending_animation);
365 scoped_ptr<PendingPageScaleAnimation> TakePendingPageScaleAnimation();
367 void GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids);
369 void DidUpdateScrollOffset(int layer_id);
371 bool IsAnimatingFilterProperty(const LayerImpl* layer) const;
372 bool IsAnimatingOpacityProperty(const LayerImpl* layer) const;
373 bool IsAnimatingTransformProperty(const LayerImpl* layer) const;
375 bool HasPotentiallyRunningFilterAnimation(const LayerImpl* layer) const;
376 bool HasPotentiallyRunningOpacityAnimation(const LayerImpl* layer) const;
377 bool HasPotentiallyRunningTransformAnimation(const LayerImpl* layer) const;
379 bool HasAnyAnimationTargetingProperty(
380 const LayerImpl* layer,
381 Animation::TargetProperty property) const;
383 bool FilterIsAnimatingOnImplOnly(const LayerImpl* layer) const;
384 bool OpacityIsAnimatingOnImplOnly(const LayerImpl* layer) const;
385 bool TransformIsAnimatingOnImplOnly(const LayerImpl* layer) const;
387 bool HasOnlyTranslationTransforms(const LayerImpl* layer) const;
389 bool MaximumTargetScale(const LayerImpl* layer, float* max_scale) const;
390 bool AnimationStartScale(const LayerImpl* layer, float* start_scale) const;
392 bool HasFilterAnimationThatInflatesBounds(const LayerImpl* layer) const;
393 bool HasTransformAnimationThatInflatesBounds(const LayerImpl* layer) const;
394 bool HasAnimationThatInflatesBounds(const LayerImpl* layer) const;
396 bool FilterAnimationBoundsForBox(const LayerImpl* layer,
397 const gfx::BoxF& box,
398 gfx::BoxF* bounds) const;
399 bool TransformAnimationBoundsForBox(const LayerImpl* layer,
400 const gfx::BoxF& box,
401 gfx::BoxF* bounds) const;
403 protected:
404 explicit LayerTreeImpl(
405 LayerTreeHostImpl* layer_tree_host_impl,
406 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
407 scoped_refptr<SyncedTopControls> top_controls_shown_ratio,
408 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll);
409 float ClampPageScaleFactorToLimits(float page_scale_factor) const;
410 void PushPageScaleFactorAndLimits(const float* page_scale_factor,
411 float min_page_scale_factor,
412 float max_page_scale_factor);
413 bool SetPageScaleFactorLimits(float min_page_scale_factor,
414 float max_page_scale_factor);
415 void DidUpdatePageScale();
416 void HideInnerViewportScrollbarsIfNeeded();
417 void PushTopControls(const float* top_controls_shown_ratio);
418 LayerTreeHostImpl* layer_tree_host_impl_;
419 int source_frame_number_;
420 scoped_ptr<LayerImpl> root_layer_;
421 HeadsUpDisplayLayerImpl* hud_layer_;
422 PropertyTrees property_trees_;
423 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
424 SkColor background_color_;
425 bool has_transparent_background_;
427 int currently_scrolling_layer_id_;
428 int overscroll_elasticity_layer_id_;
429 int page_scale_layer_id_;
430 int inner_viewport_scroll_layer_id_;
431 int outer_viewport_scroll_layer_id_;
433 LayerSelection selection_;
435 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor_;
436 float min_page_scale_factor_;
437 float max_page_scale_factor_;
438 bool hide_pinch_scrollbars_near_min_scale_;
440 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll_;
442 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
443 LayerIdMap layer_id_map_;
445 std::vector<PictureLayerImpl*> picture_layers_;
446 std::vector<LayerImpl*> layers_with_copy_output_request_;
448 // List of visible layers for the most recently prepared frame.
449 LayerImplList render_surface_layer_list_;
450 // After drawing the |render_surface_layer_list_| the areas in this region
451 // would not be fully covered by opaque content.
452 Region unoccluded_screen_space_region_;
454 bool viewport_size_invalid_;
455 bool needs_update_draw_properties_;
457 // In impl-side painting mode, this is true when the tree may contain
458 // structural differences relative to the active tree.
459 bool needs_full_tree_sync_;
461 bool next_activation_forces_redraw_;
463 bool has_ever_been_drawn_;
465 ScopedPtrVector<SwapPromise> swap_promise_list_;
466 ScopedPtrVector<SwapPromise> pinned_swap_promise_list_;
468 UIResourceRequestQueue ui_resource_request_queue_;
470 int render_surface_layer_list_id_;
472 // Whether or not Blink's viewport size was shrunk by the height of the top
473 // controls at the time of the last layout.
474 bool top_controls_shrink_blink_size_;
476 float top_controls_height_;
478 // The amount that the top controls are shown from 0 (hidden) to 1 (fully
479 // shown).
480 scoped_refptr<SyncedTopControls> top_controls_shown_ratio_;
482 scoped_ptr<PendingPageScaleAnimation> pending_page_scale_animation_;
484 private:
485 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
488 } // namespace cc
490 #endif // CC_TREES_LAYER_TREE_IMPL_H_