Wrapper script for isolating telemetry_gpu_unittests.
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.h
blob4e524e7d798a736180efbdd65edb22493b4cbdca
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 SyncedElasticOverscroll* elastic_overscroll() {
202 return elastic_overscroll_.get();
204 const SyncedElasticOverscroll* elastic_overscroll() const {
205 return elastic_overscroll_.get();
208 SyncedTopControls* top_controls_shown_ratio() {
209 return top_controls_shown_ratio_.get();
211 const SyncedTopControls* top_controls_shown_ratio() const {
212 return top_controls_shown_ratio_.get();
215 // Updates draw properties and render surface layer list, as well as tile
216 // priorities. Returns false if it was unable to update. Updating lcd
217 // text may cause invalidations, so should only be done after a commit.
218 bool UpdateDrawProperties(bool update_lcd_text);
219 void BuildPropertyTreesForTesting();
221 void set_needs_update_draw_properties() {
222 needs_update_draw_properties_ = true;
224 bool needs_update_draw_properties() const {
225 return needs_update_draw_properties_;
228 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
229 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
231 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
233 void set_has_ever_been_drawn(bool has_drawn) {
234 has_ever_been_drawn_ = has_drawn;
236 bool has_ever_been_drawn() const { return has_ever_been_drawn_; }
238 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
240 const LayerImplList& RenderSurfaceLayerList() const;
241 const Region& UnoccludedScreenSpaceRegion() const;
243 // These return the size of the root scrollable area and the size of
244 // the user-visible scrolling viewport, in CSS layout coordinates.
245 gfx::Size ScrollableSize() const;
246 gfx::SizeF ScrollableViewportSize() const;
248 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
250 LayerImpl* LayerById(int id) const;
252 // These should be called by LayerImpl's ctor/dtor.
253 void RegisterLayer(LayerImpl* layer);
254 void UnregisterLayer(LayerImpl* layer);
256 size_t NumLayers();
258 AnimationRegistrar* GetAnimationRegistrar() const;
260 void DidBecomeActive();
262 // Set on the active tree when the viewport size recently changed
263 // and the active tree's size is now out of date.
264 bool ViewportSizeInvalid() const;
265 void SetViewportSizeInvalid();
266 void ResetViewportSizeInvalid();
268 // Useful for debug assertions, probably shouldn't be used for anything else.
269 Proxy* proxy() const;
271 void SetRootLayerScrollOffsetDelegate(
272 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
273 void UpdateRootScrollOffsetDelegate();
274 // Distribute the rool scroll between outer and inner viewport scroll layer.
275 // The outer viewport scroll layer scrolls first.
276 void DistributeRootScrollOffset();
278 // Call this function when you expect there to be a swap buffer.
279 // See swap_promise.h for how to use SwapPromise.
280 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
282 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
283 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
284 void FinishSwapPromises(CompositorFrameMetadata* metadata);
285 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
287 void DidModifyTilePriorities();
289 ResourceId ResourceIdForUIResource(UIResourceId uid) const;
290 void ProcessUIResourceRequestQueue();
292 bool IsUIResourceOpaque(UIResourceId uid) const;
294 void RegisterPictureLayerImpl(PictureLayerImpl* layer);
295 void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
296 const std::vector<PictureLayerImpl*>& picture_layers() const {
297 return picture_layers_;
300 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
301 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
302 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
304 int current_render_surface_list_id() const {
305 return render_surface_layer_list_id_;
308 LayerImpl* FindFirstScrollingLayerThatIsHitByPoint(
309 const gfx::PointF& screen_space_point);
311 LayerImpl* FindLayerThatIsHitByPoint(const gfx::PointF& screen_space_point);
313 LayerImpl* FindLayerWithWheelHandlerThatIsHitByPoint(
314 const gfx::PointF& screen_space_point);
316 LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
317 const gfx::PointF& screen_space_point);
319 void RegisterSelection(const LayerSelection& selection);
321 // Compute the current selection handle location and visbility with respect to
322 // the viewport.
323 void GetViewportSelection(ViewportSelection* selection);
325 void set_top_controls_shrink_blink_size(bool shrink);
326 bool top_controls_shrink_blink_size() const {
327 return top_controls_shrink_blink_size_;
329 bool SetCurrentTopControlsShownRatio(float ratio);
330 float CurrentTopControlsShownRatio() const {
331 return top_controls_shown_ratio_->Current(IsActiveTree());
333 void set_top_controls_height(float top_controls_height);
334 float top_controls_height() const { return top_controls_height_; }
335 void PushTopControlsFromMainThread(float top_controls_shown_ratio);
337 void SetPendingPageScaleAnimation(
338 scoped_ptr<PendingPageScaleAnimation> pending_animation);
339 scoped_ptr<PendingPageScaleAnimation> TakePendingPageScaleAnimation();
341 void GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids);
343 bool IsExternalScrollActive() const;
344 void DidUpdateScrollOffset(int layer_id);
346 bool IsAnimatingFilterProperty(const LayerImpl* layer) const;
347 bool IsAnimatingOpacityProperty(const LayerImpl* layer) const;
348 bool IsAnimatingTransformProperty(const LayerImpl* layer) const;
350 bool HasPotentiallyRunningOpacityAnimation(const LayerImpl* layer) const;
351 bool HasPotentiallyRunningTransformAnimation(const LayerImpl* layer) const;
353 bool HasAnyAnimationTargetingProperty(
354 const LayerImpl* layer,
355 Animation::TargetProperty property) const;
357 bool FilterIsAnimatingOnImplOnly(const LayerImpl* layer) const;
358 bool OpacityIsAnimatingOnImplOnly(const LayerImpl* layer) const;
359 bool TransformIsAnimatingOnImplOnly(const LayerImpl* layer) const;
361 bool HasOnlyTranslationTransforms(const LayerImpl* layer) const;
363 bool MaximumTargetScale(const LayerImpl* layer, float* max_scale) const;
364 bool AnimationStartScale(const LayerImpl* layer, float* start_scale) const;
366 bool HasFilterAnimationThatInflatesBounds(const LayerImpl* layer) const;
367 bool HasTransformAnimationThatInflatesBounds(const LayerImpl* layer) const;
368 bool HasAnimationThatInflatesBounds(const LayerImpl* layer) const;
370 bool FilterAnimationBoundsForBox(const LayerImpl* layer,
371 const gfx::BoxF& box,
372 gfx::BoxF* bounds) const;
373 bool TransformAnimationBoundsForBox(const LayerImpl* layer,
374 const gfx::BoxF& box,
375 gfx::BoxF* bounds) const;
377 protected:
378 explicit LayerTreeImpl(
379 LayerTreeHostImpl* layer_tree_host_impl,
380 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
381 scoped_refptr<SyncedTopControls> top_controls_shown_ratio,
382 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll);
383 float ClampPageScaleFactorToLimits(float page_scale_factor) const;
384 void PushPageScaleFactorAndLimits(const float* page_scale_factor,
385 float min_page_scale_factor,
386 float max_page_scale_factor);
387 bool SetPageScaleFactorLimits(float min_page_scale_factor,
388 float max_page_scale_factor);
389 void DidUpdatePageScale();
390 void HideInnerViewportScrollbarsIfNearMinimumScale();
391 void PushTopControls(const float* top_controls_shown_ratio);
392 LayerTreeHostImpl* layer_tree_host_impl_;
393 int source_frame_number_;
394 scoped_ptr<LayerImpl> root_layer_;
395 HeadsUpDisplayLayerImpl* hud_layer_;
396 PropertyTrees property_trees_;
397 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
398 SkColor background_color_;
399 bool has_transparent_background_;
401 int currently_scrolling_layer_id_;
402 int overscroll_elasticity_layer_id_;
403 int page_scale_layer_id_;
404 int inner_viewport_scroll_layer_id_;
405 int outer_viewport_scroll_layer_id_;
407 LayerSelection selection_;
409 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor_;
410 float min_page_scale_factor_;
411 float max_page_scale_factor_;
413 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll_;
415 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
416 LayerIdMap layer_id_map_;
418 std::vector<PictureLayerImpl*> picture_layers_;
419 std::vector<LayerImpl*> layers_with_copy_output_request_;
421 // List of visible layers for the most recently prepared frame.
422 LayerImplList render_surface_layer_list_;
423 // After drawing the |render_surface_layer_list_| the areas in this region
424 // would not be fully covered by opaque content.
425 Region unoccluded_screen_space_region_;
427 bool viewport_size_invalid_;
428 bool needs_update_draw_properties_;
430 // In impl-side painting mode, this is true when the tree may contain
431 // structural differences relative to the active tree.
432 bool needs_full_tree_sync_;
434 bool next_activation_forces_redraw_;
436 bool has_ever_been_drawn_;
438 ScopedPtrVector<SwapPromise> swap_promise_list_;
440 UIResourceRequestQueue ui_resource_request_queue_;
442 int render_surface_layer_list_id_;
444 // Whether or not Blink's viewport size was shrunk by the height of the top
445 // controls at the time of the last layout.
446 bool top_controls_shrink_blink_size_;
448 float top_controls_height_;
450 // The amount that the top controls are shown from 0 (hidden) to 1 (fully
451 // shown).
452 scoped_refptr<SyncedTopControls> top_controls_shown_ratio_;
454 scoped_ptr<PendingPageScaleAnimation> pending_page_scale_animation_;
456 private:
457 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
460 } // namespace cc
462 #endif // CC_TREES_LAYER_TREE_IMPL_H_