Remove the 'gyp_config' concept from MB.
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.h
blob3f8b564e3af1746597e2eccf5268649563e0b51d
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 PictureLayerImpl;
46 class Proxy;
47 class ResourceProvider;
48 class TileManager;
49 class UIResourceRequest;
50 class VideoFrameControllerClient;
51 struct PendingPageScaleAnimation;
52 struct RendererCapabilities;
54 typedef std::vector<UIResourceRequest> UIResourceRequestQueue;
55 typedef SyncedProperty<AdditionGroup<float>> SyncedTopControls;
56 typedef SyncedProperty<AdditionGroup<gfx::Vector2dF>> SyncedElasticOverscroll;
58 class CC_EXPORT LayerTreeImpl {
59 public:
60 static scoped_ptr<LayerTreeImpl> create(
61 LayerTreeHostImpl* layer_tree_host_impl,
62 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
63 scoped_refptr<SyncedTopControls> top_controls_shown_ratio,
64 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) {
65 return make_scoped_ptr(
66 new LayerTreeImpl(layer_tree_host_impl, page_scale_factor,
67 top_controls_shown_ratio, elastic_overscroll));
69 virtual ~LayerTreeImpl();
71 void Shutdown();
72 void ReleaseResources();
73 void RecreateResources();
75 // Methods called by the layer tree that pass-through or access LTHI.
76 // ---------------------------------------------------------------------------
77 const LayerTreeSettings& settings() const;
78 const LayerTreeDebugState& debug_state() const;
79 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
80 ContextProvider* context_provider() const;
81 OutputSurface* output_surface() const;
82 ResourceProvider* resource_provider() const;
83 TileManager* tile_manager() const;
84 FrameRateCounter* frame_rate_counter() const;
85 MemoryHistory* memory_history() const;
86 gfx::Size device_viewport_size() const;
87 float device_scale_factor() const;
88 DebugRectHistory* debug_rect_history() const;
89 bool IsActiveTree() const;
90 bool IsPendingTree() const;
91 bool IsRecycleTree() const;
92 bool IsSyncTree() const;
93 LayerImpl* FindActiveTreeLayerById(int id);
94 LayerImpl* FindPendingTreeLayerById(int id);
95 bool PinchGestureActive() const;
96 BeginFrameArgs CurrentBeginFrameArgs() const;
97 base::TimeDelta CurrentBeginFrameInterval() const;
98 void SetNeedsCommit();
99 gfx::Rect DeviceViewport() const;
100 gfx::Size DrawViewportSize() const;
101 const gfx::Rect ViewportRectForTilePriority() const;
102 scoped_ptr<ScrollbarAnimationController> CreateScrollbarAnimationController(
103 LayerImpl* scrolling_layer);
104 void DidAnimateScrollOffset();
105 void InputScrollAnimationFinished();
106 bool use_gpu_rasterization() const;
107 GpuRasterizationStatus GetGpuRasterizationStatus() const;
108 bool create_low_res_tiling() const;
109 BlockingTaskRunner* BlockingMainThreadTaskRunner() const;
110 bool RequiresHighResToDraw() const;
111 bool SmoothnessTakesPriority() const;
112 VideoFrameControllerClient* GetVideoFrameControllerClient() const;
114 // Tree specific methods exposed to layer-impl tree.
115 // ---------------------------------------------------------------------------
116 void SetNeedsRedraw();
118 // Tracing methods.
119 // ---------------------------------------------------------------------------
120 void GetAllPrioritizedTilesForTracing(
121 std::vector<PrioritizedTile>* prioritized_tiles) const;
122 void AsValueInto(base::trace_event::TracedValue* dict) const;
124 // Other public methods
125 // ---------------------------------------------------------------------------
126 LayerImpl* root_layer() const { return root_layer_.get(); }
127 void SetRootLayer(scoped_ptr<LayerImpl>);
128 scoped_ptr<LayerImpl> DetachLayerTree();
130 void SetPropertyTrees(const PropertyTrees& property_trees) {
131 property_trees_ = property_trees;
132 property_trees_.transform_tree.set_source_to_parent_updates_allowed(false);
134 PropertyTrees* property_trees() { return &property_trees_; }
136 void UpdatePropertyTreesForBoundsDelta();
138 void PushPropertiesTo(LayerTreeImpl* tree_impl);
140 int source_frame_number() const { return source_frame_number_; }
141 void set_source_frame_number(int frame_number) {
142 source_frame_number_ = frame_number;
145 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
146 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
147 hud_layer_ = layer_impl;
150 LayerImpl* InnerViewportScrollLayer() const;
151 // This function may return NULL, it is the caller's responsibility to check.
152 LayerImpl* OuterViewportScrollLayer() const;
153 gfx::ScrollOffset TotalScrollOffset() const;
154 gfx::ScrollOffset TotalMaxScrollOffset() const;
156 LayerImpl* InnerViewportContainerLayer() const;
157 LayerImpl* OuterViewportContainerLayer() const;
158 LayerImpl* CurrentlyScrollingLayer() const;
159 void SetCurrentlyScrollingLayer(LayerImpl* layer);
160 void ClearCurrentlyScrollingLayer();
162 void SetViewportLayersFromIds(int overscroll_elasticity_layer,
163 int page_scale_layer_id,
164 int inner_viewport_scroll_layer_id,
165 int outer_viewport_scroll_layer_id);
166 void ClearViewportLayers();
167 LayerImpl* OverscrollElasticityLayer() {
168 return LayerById(overscroll_elasticity_layer_id_);
170 LayerImpl* PageScaleLayer() { return LayerById(page_scale_layer_id_); }
171 void ApplySentScrollAndScaleDeltasFromAbortedCommit();
173 SkColor background_color() const { return background_color_; }
174 void set_background_color(SkColor color) { background_color_ = color; }
176 bool has_transparent_background() const {
177 return has_transparent_background_;
179 void set_has_transparent_background(bool transparent) {
180 has_transparent_background_ = transparent;
183 void UpdatePropertyTreeScrollingAndAnimationFromMainThread();
184 void SetPageScaleOnActiveTree(float active_page_scale);
185 void PushPageScaleFromMainThread(float page_scale_factor,
186 float min_page_scale_factor,
187 float max_page_scale_factor);
188 float current_page_scale_factor() const {
189 return page_scale_factor()->Current(IsActiveTree());
191 float min_page_scale_factor() const { return min_page_scale_factor_; }
192 float max_page_scale_factor() const { return max_page_scale_factor_; }
194 float page_scale_delta() const { return page_scale_factor()->Delta(); }
196 SyncedProperty<ScaleGroup>* page_scale_factor();
197 const SyncedProperty<ScaleGroup>* page_scale_factor() const;
199 void set_hide_pinch_scrollbars_near_min_scale(bool hide) {
200 hide_pinch_scrollbars_near_min_scale_ = hide;
203 SyncedElasticOverscroll* elastic_overscroll() {
204 return elastic_overscroll_.get();
206 const SyncedElasticOverscroll* elastic_overscroll() const {
207 return elastic_overscroll_.get();
210 SyncedTopControls* top_controls_shown_ratio() {
211 return top_controls_shown_ratio_.get();
213 const SyncedTopControls* top_controls_shown_ratio() const {
214 return top_controls_shown_ratio_.get();
217 // Updates draw properties and render surface layer list, as well as tile
218 // priorities. Returns false if it was unable to update. Updating lcd
219 // text may cause invalidations, so should only be done after a commit.
220 bool UpdateDrawProperties(bool update_lcd_text);
221 void BuildPropertyTreesForTesting();
223 void set_needs_update_draw_properties() {
224 needs_update_draw_properties_ = true;
226 bool needs_update_draw_properties() const {
227 return needs_update_draw_properties_;
230 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
231 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
233 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
235 void set_has_ever_been_drawn(bool has_drawn) {
236 has_ever_been_drawn_ = has_drawn;
238 bool has_ever_been_drawn() const { return has_ever_been_drawn_; }
240 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
242 const LayerImplList& RenderSurfaceLayerList() const;
243 const Region& UnoccludedScreenSpaceRegion() const;
245 // These return the size of the root scrollable area and the size of
246 // the user-visible scrolling viewport, in CSS layout coordinates.
247 gfx::SizeF ScrollableSize() const;
248 gfx::SizeF ScrollableViewportSize() const;
250 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
252 LayerImpl* LayerById(int id) const;
254 // These should be called by LayerImpl's ctor/dtor.
255 void RegisterLayer(LayerImpl* layer);
256 void UnregisterLayer(LayerImpl* layer);
258 size_t NumLayers();
260 AnimationRegistrar* GetAnimationRegistrar() const;
262 void DidBecomeActive();
264 // Set on the active tree when the viewport size recently changed
265 // and the active tree's size is now out of date.
266 bool ViewportSizeInvalid() const;
267 void SetViewportSizeInvalid();
268 void ResetViewportSizeInvalid();
270 // Useful for debug assertions, probably shouldn't be used for anything else.
271 Proxy* proxy() const;
273 void SetRootLayerScrollOffsetDelegate(
274 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
275 // Distribute the root scroll between outer and inner viewport scroll layer.
276 // The outer viewport scroll layer scrolls first.
277 void DistributeRootScrollOffset(const gfx::ScrollOffset& root_offset);
279 void ApplyScroll(LayerImpl* layer, ScrollState* scroll_state) {
280 layer_tree_host_impl_->ApplyScroll(layer, scroll_state);
283 // Call this function when you expect there to be a swap buffer.
284 // See swap_promise.h for how to use SwapPromise.
286 // A swap promise queued by QueueSwapPromise travels with the layer
287 // information currently associated with the tree. For example, when
288 // a pending tree is activated, the swap promise is passed to the
289 // active tree along with the layer information. Similarly, when a
290 // new activation overwrites layer information on the active tree,
291 // queued swap promises are broken.
292 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
294 // Queue a swap promise, pinned to this tree. Pinned swap promises
295 // may only be queued on the active tree.
297 // An active tree pinned swap promise will see only DidSwap() or
298 // DidNotSwap(SWAP_FAILS). No DidActivate() will be seen because
299 // that has already happened prior to queueing of the swap promise.
301 // Pinned active tree swap promises will not be broken prematurely
302 // on the active tree if a new tree is activated.
303 void QueuePinnedSwapPromise(scoped_ptr<SwapPromise> swap_promise);
305 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
306 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
307 void FinishSwapPromises(CompositorFrameMetadata* metadata);
308 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
310 void DidModifyTilePriorities();
312 ResourceId ResourceIdForUIResource(UIResourceId uid) const;
313 void ProcessUIResourceRequestQueue();
315 bool IsUIResourceOpaque(UIResourceId uid) const;
317 void RegisterPictureLayerImpl(PictureLayerImpl* layer);
318 void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
319 const std::vector<PictureLayerImpl*>& picture_layers() const {
320 return picture_layers_;
323 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
324 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
325 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
327 int current_render_surface_list_id() const {
328 return render_surface_layer_list_id_;
331 LayerImpl* FindFirstScrollingLayerThatIsHitByPoint(
332 const gfx::PointF& screen_space_point);
334 LayerImpl* FindLayerThatIsHitByPoint(const gfx::PointF& screen_space_point);
336 LayerImpl* FindLayerWithWheelHandlerThatIsHitByPoint(
337 const gfx::PointF& screen_space_point);
339 LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
340 const gfx::PointF& screen_space_point);
342 void RegisterSelection(const LayerSelection& selection);
344 // Compute the current selection handle location and visbility with respect to
345 // the viewport.
346 void GetViewportSelection(ViewportSelection* selection);
348 void set_top_controls_shrink_blink_size(bool shrink);
349 bool top_controls_shrink_blink_size() const {
350 return top_controls_shrink_blink_size_;
352 bool SetCurrentTopControlsShownRatio(float ratio);
353 float CurrentTopControlsShownRatio() const {
354 return top_controls_shown_ratio_->Current(IsActiveTree());
356 void set_top_controls_height(float top_controls_height);
357 float top_controls_height() const { return top_controls_height_; }
358 void PushTopControlsFromMainThread(float top_controls_shown_ratio);
360 void SetPendingPageScaleAnimation(
361 scoped_ptr<PendingPageScaleAnimation> pending_animation);
362 scoped_ptr<PendingPageScaleAnimation> TakePendingPageScaleAnimation();
364 void GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids);
366 void DidUpdateScrollOffset(int layer_id);
368 bool IsAnimatingFilterProperty(const LayerImpl* layer) const;
369 bool IsAnimatingOpacityProperty(const LayerImpl* layer) const;
370 bool IsAnimatingTransformProperty(const LayerImpl* layer) const;
372 bool HasPotentiallyRunningFilterAnimation(const LayerImpl* layer) const;
373 bool HasPotentiallyRunningOpacityAnimation(const LayerImpl* layer) const;
374 bool HasPotentiallyRunningTransformAnimation(const LayerImpl* layer) const;
376 bool HasAnyAnimationTargetingProperty(
377 const LayerImpl* layer,
378 Animation::TargetProperty property) const;
380 bool FilterIsAnimatingOnImplOnly(const LayerImpl* layer) const;
381 bool OpacityIsAnimatingOnImplOnly(const LayerImpl* layer) const;
382 bool TransformIsAnimatingOnImplOnly(const LayerImpl* layer) const;
384 bool HasOnlyTranslationTransforms(const LayerImpl* layer) const;
386 bool MaximumTargetScale(const LayerImpl* layer, float* max_scale) const;
387 bool AnimationStartScale(const LayerImpl* layer, float* start_scale) const;
389 bool HasFilterAnimationThatInflatesBounds(const LayerImpl* layer) const;
390 bool HasTransformAnimationThatInflatesBounds(const LayerImpl* layer) const;
391 bool HasAnimationThatInflatesBounds(const LayerImpl* layer) const;
393 bool FilterAnimationBoundsForBox(const LayerImpl* layer,
394 const gfx::BoxF& box,
395 gfx::BoxF* bounds) const;
396 bool TransformAnimationBoundsForBox(const LayerImpl* layer,
397 const gfx::BoxF& box,
398 gfx::BoxF* bounds) const;
400 protected:
401 explicit LayerTreeImpl(
402 LayerTreeHostImpl* layer_tree_host_impl,
403 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
404 scoped_refptr<SyncedTopControls> top_controls_shown_ratio,
405 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll);
406 float ClampPageScaleFactorToLimits(float page_scale_factor) const;
407 void PushPageScaleFactorAndLimits(const float* page_scale_factor,
408 float min_page_scale_factor,
409 float max_page_scale_factor);
410 bool SetPageScaleFactorLimits(float min_page_scale_factor,
411 float max_page_scale_factor);
412 void DidUpdatePageScale();
413 void HideInnerViewportScrollbarsIfNeeded();
414 void PushTopControls(const float* top_controls_shown_ratio);
415 LayerTreeHostImpl* layer_tree_host_impl_;
416 int source_frame_number_;
417 scoped_ptr<LayerImpl> root_layer_;
418 HeadsUpDisplayLayerImpl* hud_layer_;
419 PropertyTrees property_trees_;
420 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
421 SkColor background_color_;
422 bool has_transparent_background_;
424 int currently_scrolling_layer_id_;
425 int overscroll_elasticity_layer_id_;
426 int page_scale_layer_id_;
427 int inner_viewport_scroll_layer_id_;
428 int outer_viewport_scroll_layer_id_;
430 LayerSelection selection_;
432 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor_;
433 float min_page_scale_factor_;
434 float max_page_scale_factor_;
435 bool hide_pinch_scrollbars_near_min_scale_;
437 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll_;
439 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
440 LayerIdMap layer_id_map_;
442 std::vector<PictureLayerImpl*> picture_layers_;
443 std::vector<LayerImpl*> layers_with_copy_output_request_;
445 // List of visible layers for the most recently prepared frame.
446 LayerImplList render_surface_layer_list_;
447 // After drawing the |render_surface_layer_list_| the areas in this region
448 // would not be fully covered by opaque content.
449 Region unoccluded_screen_space_region_;
451 bool viewport_size_invalid_;
452 bool needs_update_draw_properties_;
454 // In impl-side painting mode, this is true when the tree may contain
455 // structural differences relative to the active tree.
456 bool needs_full_tree_sync_;
458 bool next_activation_forces_redraw_;
460 bool has_ever_been_drawn_;
462 ScopedPtrVector<SwapPromise> swap_promise_list_;
463 ScopedPtrVector<SwapPromise> pinned_swap_promise_list_;
465 UIResourceRequestQueue ui_resource_request_queue_;
467 int render_surface_layer_list_id_;
469 // Whether or not Blink's viewport size was shrunk by the height of the top
470 // controls at the time of the last layout.
471 bool top_controls_shrink_blink_size_;
473 float top_controls_height_;
475 // The amount that the top controls are shown from 0 (hidden) to 1 (fully
476 // shown).
477 scoped_refptr<SyncedTopControls> top_controls_shown_ratio_;
479 scoped_ptr<PendingPageScaleAnimation> pending_page_scale_animation_;
481 private:
482 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
485 } // namespace cc
487 #endif // CC_TREES_LAYER_TREE_IMPL_H_