Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.h
blob01c8c1b314c5149bd99d49d40d0909d12e0c1c1c
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 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* overscroll_elasticity_layer() {
168 return overscroll_elasticity_layer_;
170 LayerImpl* page_scale_layer() { return page_scale_layer_; }
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 SetPageScaleOnActiveTree(float active_page_scale);
184 void PushPageScaleFromMainThread(float page_scale_factor,
185 float min_page_scale_factor,
186 float max_page_scale_factor);
187 float current_page_scale_factor() const {
188 return page_scale_factor()->Current(IsActiveTree());
190 float min_page_scale_factor() const { return min_page_scale_factor_; }
191 float max_page_scale_factor() const { return max_page_scale_factor_; }
193 float page_scale_delta() const { return page_scale_factor()->Delta(); }
195 SyncedProperty<ScaleGroup>* page_scale_factor();
196 const SyncedProperty<ScaleGroup>* page_scale_factor() const;
198 SyncedElasticOverscroll* elastic_overscroll() {
199 return elastic_overscroll_.get();
201 const SyncedElasticOverscroll* elastic_overscroll() const {
202 return elastic_overscroll_.get();
205 SyncedTopControls* top_controls_shown_ratio() {
206 return top_controls_shown_ratio_.get();
208 const SyncedTopControls* top_controls_shown_ratio() const {
209 return top_controls_shown_ratio_.get();
212 // Updates draw properties and render surface layer list, as well as tile
213 // priorities. Returns false if it was unable to update. Updating lcd
214 // text may cause invalidations, so should only be done after a commit.
215 bool UpdateDrawProperties(bool update_lcd_text);
216 void BuildPropertyTreesForTesting();
218 void set_needs_update_draw_properties() {
219 needs_update_draw_properties_ = true;
221 bool needs_update_draw_properties() const {
222 return needs_update_draw_properties_;
225 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
226 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
228 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
230 void set_has_ever_been_drawn(bool has_drawn) {
231 has_ever_been_drawn_ = has_drawn;
233 bool has_ever_been_drawn() const { return has_ever_been_drawn_; }
235 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
237 const LayerImplList& RenderSurfaceLayerList() const;
238 const Region& UnoccludedScreenSpaceRegion() const;
240 // These return the size of the root scrollable area and the size of
241 // the user-visible scrolling viewport, in CSS layout coordinates.
242 gfx::Size ScrollableSize() const;
243 gfx::SizeF ScrollableViewportSize() const;
245 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
247 LayerImpl* LayerById(int id);
249 // These should be called by LayerImpl's ctor/dtor.
250 void RegisterLayer(LayerImpl* layer);
251 void UnregisterLayer(LayerImpl* layer);
253 size_t NumLayers();
255 AnimationRegistrar* GetAnimationRegistrar() const;
257 void PushPersistedState(LayerTreeImpl* pending_tree);
259 void DidBecomeActive();
261 bool ContentsTexturesPurged() const;
262 void SetContentsTexturesPurged();
263 void ResetContentsTexturesPurged();
265 // Set on the active tree when the viewport size recently changed
266 // and the active tree's size is now out of date.
267 bool ViewportSizeInvalid() const;
268 void SetViewportSizeInvalid();
269 void ResetViewportSizeInvalid();
271 // Useful for debug assertions, probably shouldn't be used for anything else.
272 Proxy* proxy() const;
274 void SetRootLayerScrollOffsetDelegate(
275 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
276 void UpdateRootScrollOffsetDelegate();
277 // Distribute the rool scroll between outer and inner viewport scroll layer.
278 // The outer viewport scroll layer scrolls first.
279 void DistributeRootScrollOffset();
281 // Call this function when you expect there to be a swap buffer.
282 // See swap_promise.h for how to use SwapPromise.
283 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
285 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
286 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
287 void FinishSwapPromises(CompositorFrameMetadata* metadata);
288 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
290 void DidModifyTilePriorities();
292 ResourceId ResourceIdForUIResource(UIResourceId uid) const;
293 void ProcessUIResourceRequestQueue();
295 bool IsUIResourceOpaque(UIResourceId uid) const;
297 void RegisterPictureLayerImpl(PictureLayerImpl* layer);
298 void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
299 const std::vector<PictureLayerImpl*>& picture_layers() const {
300 return picture_layers_;
303 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
304 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
305 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
307 int current_render_surface_list_id() const {
308 return render_surface_layer_list_id_;
311 LayerImpl* FindFirstScrollingLayerThatIsHitByPoint(
312 const gfx::PointF& screen_space_point);
314 LayerImpl* FindLayerThatIsHitByPoint(const gfx::PointF& screen_space_point);
316 LayerImpl* FindLayerWithWheelHandlerThatIsHitByPoint(
317 const gfx::PointF& screen_space_point);
319 LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
320 const gfx::PointF& screen_space_point);
322 void RegisterSelection(const LayerSelection& selection);
324 // Compute the current selection handle location and visbility with respect to
325 // the viewport.
326 void GetViewportSelection(ViewportSelection* selection);
328 void set_top_controls_shrink_blink_size(bool shrink);
329 bool top_controls_shrink_blink_size() const {
330 return top_controls_shrink_blink_size_;
332 bool SetCurrentTopControlsShownRatio(float ratio);
333 float CurrentTopControlsShownRatio() const {
334 return top_controls_shown_ratio_->Current(IsActiveTree());
336 void set_top_controls_height(float top_controls_height);
337 float top_controls_height() const { return top_controls_height_; }
338 void PushTopControlsFromMainThread(float top_controls_shown_ratio);
340 void SetPendingPageScaleAnimation(
341 scoped_ptr<PendingPageScaleAnimation> pending_animation);
342 scoped_ptr<PendingPageScaleAnimation> TakePendingPageScaleAnimation();
344 void GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids);
346 bool IsExternalFlingActive() const;
347 void DidUpdateScrollOffset(int layer_id);
349 protected:
350 explicit LayerTreeImpl(
351 LayerTreeHostImpl* layer_tree_host_impl,
352 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
353 scoped_refptr<SyncedTopControls> top_controls_shown_ratio,
354 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll);
355 float ClampPageScaleFactorToLimits(float page_scale_factor) const;
356 void PushPageScaleFactorAndLimits(const float* page_scale_factor,
357 float min_page_scale_factor,
358 float max_page_scale_factor);
359 bool SetPageScaleFactorLimits(float min_page_scale_factor,
360 float max_page_scale_factor);
361 void DidUpdatePageScale();
362 void HideInnerViewportScrollbarsIfNearMinimumScale();
363 void PushTopControls(const float* top_controls_shown_ratio);
364 LayerTreeHostImpl* layer_tree_host_impl_;
365 int source_frame_number_;
366 scoped_ptr<LayerImpl> root_layer_;
367 HeadsUpDisplayLayerImpl* hud_layer_;
368 PropertyTrees property_trees_;
369 LayerImpl* currently_scrolling_layer_;
370 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
371 SkColor background_color_;
372 bool has_transparent_background_;
374 LayerImpl* overscroll_elasticity_layer_;
375 LayerImpl* page_scale_layer_;
376 LayerImpl* inner_viewport_scroll_layer_;
377 LayerImpl* outer_viewport_scroll_layer_;
379 LayerSelection selection_;
381 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor_;
382 float min_page_scale_factor_;
383 float max_page_scale_factor_;
385 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll_;
387 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
388 LayerIdMap layer_id_map_;
390 std::vector<PictureLayerImpl*> picture_layers_;
391 std::vector<LayerImpl*> layers_with_copy_output_request_;
393 // Persisted state for non-impl-side-painting.
394 int scrolling_layer_id_from_previous_tree_;
396 // List of visible layers for the most recently prepared frame.
397 LayerImplList render_surface_layer_list_;
398 // After drawing the |render_surface_layer_list_| the areas in this region
399 // would not be fully covered by opaque content.
400 Region unoccluded_screen_space_region_;
402 bool contents_textures_purged_;
403 bool viewport_size_invalid_;
404 bool needs_update_draw_properties_;
406 // In impl-side painting mode, this is true when the tree may contain
407 // structural differences relative to the active tree.
408 bool needs_full_tree_sync_;
410 bool next_activation_forces_redraw_;
412 bool has_ever_been_drawn_;
414 ScopedPtrVector<SwapPromise> swap_promise_list_;
416 UIResourceRequestQueue ui_resource_request_queue_;
418 int render_surface_layer_list_id_;
420 // Whether or not Blink's viewport size was shrunk by the height of the top
421 // controls at the time of the last layout.
422 bool top_controls_shrink_blink_size_;
424 float top_controls_height_;
426 // The amount that the top controls are shown from 0 (hidden) to 1 (fully
427 // shown).
428 scoped_refptr<SyncedTopControls> top_controls_shown_ratio_;
430 scoped_ptr<PendingPageScaleAnimation> pending_page_scale_animation_;
432 private:
433 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
436 } // namespace cc
438 #endif // CC_TREES_LAYER_TREE_IMPL_H_