OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CC_TREES_LAYER_TREE_IMPL_H_ | |
6 #define CC_TREES_LAYER_TREE_IMPL_H_ | |
7 | |
8 #include <set> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
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 | |
24 namespace base { | |
25 namespace trace_event { | |
26 class TracedValue; | |
27 } | |
28 } | |
29 | |
30 namespace cc { | |
31 | |
32 class ContextProvider; | |
33 class DebugRectHistory; | |
34 class FrameRateCounter; | |
35 class HeadsUpDisplayLayerImpl; | |
36 class LayerScrollOffsetDelegateProxy; | |
37 class LayerTreeDebugState; | |
38 class LayerTreeImpl; | |
39 class LayerTreeSettings; | |
40 class MemoryHistory; | |
41 class OutputSurface; | |
42 class PageScaleAnimation; | |
43 class PaintTimeCounter; | |
44 class PictureLayerImpl; | |
45 class Proxy; | |
46 class ResourceProvider; | |
47 class TileManager; | |
48 class UIResourceRequest; | |
49 struct PendingPageScaleAnimation; | |
50 struct RendererCapabilities; | |
51 struct SelectionHandle; | |
52 | |
53 typedef std::vector<UIResourceRequest> UIResourceRequestQueue; | |
54 typedef SyncedProperty<AdditionGroup<float>> SyncedTopControls; | |
55 typedef SyncedProperty<AdditionGroup<gfx::Vector2dF>> SyncedElasticOverscroll; | |
56 | |
57 class CC_EXPORT LayerTreeImpl { | |
58 public: | |
59 static scoped_ptr<LayerTreeImpl> create( | |
60 LayerTreeHostImpl* layer_tree_host_impl, | |
61 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, | |
62 scoped_refptr<SyncedTopControls> top_controls_shown_ratio, | |
63 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) { | |
64 return make_scoped_ptr( | |
65 new LayerTreeImpl(layer_tree_host_impl, page_scale_factor, | |
66 top_controls_shown_ratio, elastic_overscroll)); | |
67 } | |
68 virtual ~LayerTreeImpl(); | |
69 | |
70 void Shutdown(); | |
71 void ReleaseResources(); | |
72 void RecreateResources(); | |
73 | |
74 // Methods called by the layer tree that pass-through or access LTHI. | |
75 // --------------------------------------------------------------------------- | |
76 const LayerTreeSettings& settings() const; | |
77 const LayerTreeDebugState& debug_state() const; | |
78 const RendererCapabilitiesImpl& GetRendererCapabilities() const; | |
79 ContextProvider* context_provider() const; | |
80 OutputSurface* output_surface() const; | |
81 ResourceProvider* resource_provider() const; | |
82 TileManager* tile_manager() const; | |
83 FrameRateCounter* frame_rate_counter() const; | |
84 PaintTimeCounter* paint_time_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 begin_impl_frame_interval() 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 | |
113 // Tree specific methods exposed to layer-impl tree. | |
114 // --------------------------------------------------------------------------- | |
115 void SetNeedsRedraw(); | |
116 | |
117 // Tracing methods. | |
118 // --------------------------------------------------------------------------- | |
119 void GetAllTilesAndPrioritiesForTracing( | |
120 std::map<const Tile*, TilePriority>* tile_map) const; | |
121 void AsValueInto(base::trace_event::TracedValue* dict) const; | |
122 | |
123 // Other public methods | |
124 // --------------------------------------------------------------------------- | |
125 LayerImpl* root_layer() const { return root_layer_.get(); } | |
126 void SetRootLayer(scoped_ptr<LayerImpl>); | |
127 scoped_ptr<LayerImpl> DetachLayerTree(); | |
128 | |
129 void PushPropertiesTo(LayerTreeImpl* tree_impl); | |
130 | |
131 int source_frame_number() const { return source_frame_number_; } | |
132 void set_source_frame_number(int frame_number) { | |
133 source_frame_number_ = frame_number; | |
134 } | |
135 | |
136 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; } | |
137 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) { | |
138 hud_layer_ = layer_impl; | |
139 } | |
140 | |
141 LayerImpl* InnerViewportScrollLayer() const; | |
142 // This function may return NULL, it is the caller's responsibility to check. | |
143 LayerImpl* OuterViewportScrollLayer() const; | |
144 gfx::ScrollOffset TotalScrollOffset() const; | |
145 gfx::ScrollOffset TotalMaxScrollOffset() const; | |
146 | |
147 LayerImpl* InnerViewportContainerLayer() const; | |
148 LayerImpl* OuterViewportContainerLayer() const; | |
149 LayerImpl* CurrentlyScrollingLayer() const; | |
150 void SetCurrentlyScrollingLayer(LayerImpl* layer); | |
151 void ClearCurrentlyScrollingLayer(); | |
152 | |
153 void SetViewportLayersFromIds(int overscroll_elasticity_layer, | |
154 int page_scale_layer_id, | |
155 int inner_viewport_scroll_layer_id, | |
156 int outer_viewport_scroll_layer_id); | |
157 void ClearViewportLayers(); | |
158 LayerImpl* overscroll_elasticity_layer() { | |
159 return overscroll_elasticity_layer_; | |
160 } | |
161 LayerImpl* page_scale_layer() { return page_scale_layer_; } | |
162 void ApplySentScrollAndScaleDeltasFromAbortedCommit(); | |
163 | |
164 SkColor background_color() const { return background_color_; } | |
165 void set_background_color(SkColor color) { background_color_ = color; } | |
166 | |
167 bool has_transparent_background() const { | |
168 return has_transparent_background_; | |
169 } | |
170 void set_has_transparent_background(bool transparent) { | |
171 has_transparent_background_ = transparent; | |
172 } | |
173 | |
174 void SetPageScaleOnActiveTree(float active_page_scale); | |
175 void PushPageScaleFromMainThread(float page_scale_factor, | |
176 float min_page_scale_factor, | |
177 float max_page_scale_factor); | |
178 float current_page_scale_factor() const { | |
179 return page_scale_factor()->Current(IsActiveTree()); | |
180 } | |
181 float min_page_scale_factor() const { return min_page_scale_factor_; } | |
182 float max_page_scale_factor() const { return max_page_scale_factor_; } | |
183 | |
184 float page_scale_delta() const { return page_scale_factor()->Delta(); } | |
185 | |
186 SyncedProperty<ScaleGroup>* page_scale_factor(); | |
187 const SyncedProperty<ScaleGroup>* page_scale_factor() const; | |
188 | |
189 SyncedElasticOverscroll* elastic_overscroll() { | |
190 return elastic_overscroll_.get(); | |
191 } | |
192 const SyncedElasticOverscroll* elastic_overscroll() const { | |
193 return elastic_overscroll_.get(); | |
194 } | |
195 | |
196 SyncedTopControls* top_controls_shown_ratio() { | |
197 return top_controls_shown_ratio_.get(); | |
198 } | |
199 const SyncedTopControls* top_controls_shown_ratio() const { | |
200 return top_controls_shown_ratio_.get(); | |
201 } | |
202 | |
203 // Updates draw properties and render surface layer list, as well as tile | |
204 // priorities. Returns false if it was unable to update. Updating lcd | |
205 // text may cause invalidations, so should only be done after a commit. | |
206 bool UpdateDrawProperties(bool update_lcd_text); | |
207 | |
208 void set_needs_update_draw_properties() { | |
209 needs_update_draw_properties_ = true; | |
210 } | |
211 bool needs_update_draw_properties() const { | |
212 return needs_update_draw_properties_; | |
213 } | |
214 | |
215 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; } | |
216 bool needs_full_tree_sync() const { return needs_full_tree_sync_; } | |
217 | |
218 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; } | |
219 | |
220 void set_has_ever_been_drawn(bool has_drawn) { | |
221 has_ever_been_drawn_ = has_drawn; | |
222 } | |
223 bool has_ever_been_drawn() const { return has_ever_been_drawn_; } | |
224 | |
225 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue); | |
226 | |
227 const LayerImplList& RenderSurfaceLayerList() const; | |
228 const Region& UnoccludedScreenSpaceRegion() const; | |
229 | |
230 // These return the size of the root scrollable area and the size of | |
231 // the user-visible scrolling viewport, in CSS layout coordinates. | |
232 gfx::Size ScrollableSize() const; | |
233 gfx::SizeF ScrollableViewportSize() const; | |
234 | |
235 gfx::Rect RootScrollLayerDeviceViewportBounds() const; | |
236 | |
237 LayerImpl* LayerById(int id); | |
238 | |
239 // These should be called by LayerImpl's ctor/dtor. | |
240 void RegisterLayer(LayerImpl* layer); | |
241 void UnregisterLayer(LayerImpl* layer); | |
242 | |
243 size_t NumLayers(); | |
244 | |
245 AnimationRegistrar* GetAnimationRegistrar() const; | |
246 | |
247 void PushPersistedState(LayerTreeImpl* pending_tree); | |
248 | |
249 void DidBecomeActive(); | |
250 | |
251 bool ContentsTexturesPurged() const; | |
252 void SetContentsTexturesPurged(); | |
253 void ResetContentsTexturesPurged(); | |
254 | |
255 // Set on the active tree when the viewport size recently changed | |
256 // and the active tree's size is now out of date. | |
257 bool ViewportSizeInvalid() const; | |
258 void SetViewportSizeInvalid(); | |
259 void ResetViewportSizeInvalid(); | |
260 | |
261 // Useful for debug assertions, probably shouldn't be used for anything else. | |
262 Proxy* proxy() const; | |
263 | |
264 void SetRootLayerScrollOffsetDelegate( | |
265 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate); | |
266 void OnRootLayerDelegatedScrollOffsetChanged(); | |
267 void UpdateScrollOffsetDelegate(); | |
268 gfx::ScrollOffset GetDelegatedScrollOffset(LayerImpl* layer); | |
269 | |
270 // Call this function when you expect there to be a swap buffer. | |
271 // See swap_promise.h for how to use SwapPromise. | |
272 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise); | |
273 | |
274 // Take the |new_swap_promise| and append it to |swap_promise_list_|. | |
275 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise); | |
276 void FinishSwapPromises(CompositorFrameMetadata* metadata); | |
277 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason); | |
278 | |
279 void DidModifyTilePriorities(); | |
280 | |
281 ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const; | |
282 void ProcessUIResourceRequestQueue(); | |
283 | |
284 bool IsUIResourceOpaque(UIResourceId uid) const; | |
285 | |
286 void RegisterPictureLayerImpl(PictureLayerImpl* layer); | |
287 void UnregisterPictureLayerImpl(PictureLayerImpl* layer); | |
288 const std::vector<PictureLayerImpl*>& picture_layers() const { | |
289 return picture_layers_; | |
290 } | |
291 | |
292 void AddLayerWithCopyOutputRequest(LayerImpl* layer); | |
293 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer); | |
294 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const; | |
295 | |
296 int current_render_surface_list_id() const { | |
297 return render_surface_layer_list_id_; | |
298 } | |
299 | |
300 LayerImpl* FindFirstScrollingLayerThatIsHitByPoint( | |
301 const gfx::PointF& screen_space_point); | |
302 | |
303 LayerImpl* FindLayerThatIsHitByPoint(const gfx::PointF& screen_space_point); | |
304 | |
305 LayerImpl* FindLayerWithWheelHandlerThatIsHitByPoint( | |
306 const gfx::PointF& screen_space_point); | |
307 | |
308 LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion( | |
309 const gfx::PointF& screen_space_point); | |
310 | |
311 void RegisterSelection(const LayerSelectionBound& start, | |
312 const LayerSelectionBound& end); | |
313 | |
314 // Compute the current selection handle location and visbility with respect to | |
315 // the viewport. | |
316 void GetViewportSelection(ViewportSelectionBound* start, | |
317 ViewportSelectionBound* end); | |
318 | |
319 void set_top_controls_shrink_blink_size(bool shrink); | |
320 bool top_controls_shrink_blink_size() const { | |
321 return top_controls_shrink_blink_size_; | |
322 } | |
323 bool SetCurrentTopControlsShownRatio(float ratio); | |
324 float CurrentTopControlsShownRatio() const { | |
325 return top_controls_shown_ratio_->Current(IsActiveTree()); | |
326 } | |
327 void set_top_controls_height(float top_controls_height); | |
328 float top_controls_height() const { return top_controls_height_; } | |
329 void PushTopControlsFromMainThread(float top_controls_shown_ratio); | |
330 | |
331 void SetPendingPageScaleAnimation( | |
332 scoped_ptr<PendingPageScaleAnimation> pending_animation); | |
333 scoped_ptr<PendingPageScaleAnimation> TakePendingPageScaleAnimation(); | |
334 | |
335 protected: | |
336 explicit LayerTreeImpl( | |
337 LayerTreeHostImpl* layer_tree_host_impl, | |
338 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, | |
339 scoped_refptr<SyncedTopControls> top_controls_shown_ratio, | |
340 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll); | |
341 float ClampPageScaleFactorToLimits(float page_scale_factor) const; | |
342 void PushPageScaleFactorAndLimits(const float* page_scale_factor, | |
343 float min_page_scale_factor, | |
344 float max_page_scale_factor); | |
345 bool SetPageScaleFactorLimits(float min_page_scale_factor, | |
346 float max_page_scale_factor); | |
347 void DidUpdatePageScale(); | |
348 void HideInnerViewportScrollbarsIfNearMinimumScale(); | |
349 void PushTopControls(const float* top_controls_shown_ratio); | |
350 LayerTreeHostImpl* layer_tree_host_impl_; | |
351 int source_frame_number_; | |
352 scoped_ptr<LayerImpl> root_layer_; | |
353 HeadsUpDisplayLayerImpl* hud_layer_; | |
354 LayerImpl* currently_scrolling_layer_; | |
355 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_; | |
356 scoped_ptr<LayerScrollOffsetDelegateProxy> | |
357 inner_viewport_scroll_delegate_proxy_; | |
358 scoped_ptr<LayerScrollOffsetDelegateProxy> | |
359 outer_viewport_scroll_delegate_proxy_; | |
360 SkColor background_color_; | |
361 bool has_transparent_background_; | |
362 | |
363 LayerImpl* overscroll_elasticity_layer_; | |
364 LayerImpl* page_scale_layer_; | |
365 LayerImpl* inner_viewport_scroll_layer_; | |
366 LayerImpl* outer_viewport_scroll_layer_; | |
367 | |
368 LayerSelectionBound selection_start_; | |
369 LayerSelectionBound selection_end_; | |
370 | |
371 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor_; | |
372 float min_page_scale_factor_; | |
373 float max_page_scale_factor_; | |
374 | |
375 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll_; | |
376 | |
377 typedef base::hash_map<int, LayerImpl*> LayerIdMap; | |
378 LayerIdMap layer_id_map_; | |
379 | |
380 std::vector<PictureLayerImpl*> picture_layers_; | |
381 std::vector<LayerImpl*> layers_with_copy_output_request_; | |
382 | |
383 // Persisted state for non-impl-side-painting. | |
384 int scrolling_layer_id_from_previous_tree_; | |
385 | |
386 // List of visible layers for the most recently prepared frame. | |
387 LayerImplList render_surface_layer_list_; | |
388 // After drawing the |render_surface_layer_list_| the areas in this region | |
389 // would not be fully covered by opaque content. | |
390 Region unoccluded_screen_space_region_; | |
391 | |
392 bool contents_textures_purged_; | |
393 bool viewport_size_invalid_; | |
394 bool needs_update_draw_properties_; | |
395 | |
396 // In impl-side painting mode, this is true when the tree may contain | |
397 // structural differences relative to the active tree. | |
398 bool needs_full_tree_sync_; | |
399 | |
400 bool next_activation_forces_redraw_; | |
401 | |
402 bool has_ever_been_drawn_; | |
403 | |
404 ScopedPtrVector<SwapPromise> swap_promise_list_; | |
405 | |
406 UIResourceRequestQueue ui_resource_request_queue_; | |
407 | |
408 int render_surface_layer_list_id_; | |
409 | |
410 // Whether or not Blink's viewport size was shrunk by the height of the top | |
411 // controls at the time of the last layout. | |
412 bool top_controls_shrink_blink_size_; | |
413 | |
414 float top_controls_height_; | |
415 | |
416 // The amount that the top controls are shown from 0 (hidden) to 1 (fully | |
417 // shown). | |
418 scoped_refptr<SyncedTopControls> top_controls_shown_ratio_; | |
419 | |
420 scoped_ptr<PendingPageScaleAnimation> pending_page_scale_animation_; | |
421 | |
422 private: | |
423 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl); | |
424 }; | |
425 | |
426 } // namespace cc | |
427 | |
428 #endif // CC_TREES_LAYER_TREE_IMPL_H_ | |
OLD | NEW |