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_
12 #include "base/containers/hash_tables.h"
13 #include "base/values.h"
14 #include "cc/base/scoped_ptr_vector.h"
15 #include "cc/base/swap_promise.h"
16 #include "cc/layers/layer_impl.h"
17 #include "cc/output/renderer.h"
18 #include "cc/resources/ui_resource_client.h"
20 #if defined(COMPILER_GCC)
21 namespace BASE_HASH_NAMESPACE
{
23 struct hash
<cc::LayerImpl
*> {
24 size_t operator()(cc::LayerImpl
* ptr
) const {
25 return hash
<size_t>()(reinterpret_cast<size_t>(ptr
));
28 } // namespace BASE_HASH_NAMESPACE
33 class ContextProvider
;
34 class DebugRectHistory
;
35 class FrameRateCounter
;
36 class HeadsUpDisplayLayerImpl
;
37 class LayerScrollOffsetDelegateProxy
;
38 class LayerTreeDebugState
;
39 class LayerTreeHostImpl
;
41 class LayerTreeSettings
;
44 class PaintTimeCounter
;
46 class ResourceProvider
;
48 class UIResourceRequest
;
49 struct RendererCapabilities
;
51 typedef std::list
<UIResourceRequest
> UIResourceRequestQueue
;
53 class CC_EXPORT LayerTreeImpl
{
55 static scoped_ptr
<LayerTreeImpl
> create(
56 LayerTreeHostImpl
* layer_tree_host_impl
) {
57 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl
));
59 virtual ~LayerTreeImpl();
63 // Methods called by the layer tree that pass-through or access LTHI.
64 // ---------------------------------------------------------------------------
65 const LayerTreeSettings
& settings() const;
66 const RendererCapabilitiesImpl
& GetRendererCapabilities() const;
67 ContextProvider
* context_provider() const;
68 OutputSurface
* output_surface() const;
69 ResourceProvider
* resource_provider() const;
70 TileManager
* tile_manager() const;
71 FrameRateCounter
* frame_rate_counter() const;
72 PaintTimeCounter
* paint_time_counter() const;
73 MemoryHistory
* memory_history() const;
74 bool device_viewport_valid_for_tile_management() const;
75 gfx::Size
device_viewport_size() const;
76 bool IsActiveTree() const;
77 bool IsPendingTree() const;
78 bool IsRecycleTree() const;
79 LayerImpl
* FindActiveTreeLayerById(int id
);
80 LayerImpl
* FindPendingTreeLayerById(int id
);
81 int MaxTextureSize() const;
82 bool PinchGestureActive() const;
83 base::TimeTicks
CurrentFrameTimeTicks() const;
84 void SetNeedsCommit();
85 gfx::Size
DrawViewportSize() const;
86 scoped_ptr
<ScrollbarAnimationController
> CreateScrollbarAnimationController(
87 LayerImpl
* scrolling_layer
);
88 void DidAnimateScrollOffset();
90 // Tree specific methods exposed to layer-impl tree.
91 // ---------------------------------------------------------------------------
92 void SetNeedsRedraw();
94 // TODO(nduca): These are implemented in cc files temporarily, but will become
95 // trivial accessors in a followup patch.
96 const LayerTreeDebugState
& debug_state() const;
97 float device_scale_factor() const;
98 DebugRectHistory
* debug_rect_history() const;
99 scoped_ptr
<base::Value
> AsValue() const;
101 // Other public methods
102 // ---------------------------------------------------------------------------
103 LayerImpl
* root_layer() const { return root_layer_
.get(); }
104 void SetRootLayer(scoped_ptr
<LayerImpl
>);
105 scoped_ptr
<LayerImpl
> DetachLayerTree();
107 void PushPropertiesTo(LayerTreeImpl
* tree_impl
);
109 int source_frame_number() const { return source_frame_number_
; }
110 void set_source_frame_number(int frame_number
) {
111 source_frame_number_
= frame_number
;
114 HeadsUpDisplayLayerImpl
* hud_layer() { return hud_layer_
; }
115 void set_hud_layer(HeadsUpDisplayLayerImpl
* layer_impl
) {
116 hud_layer_
= layer_impl
;
119 LayerImpl
* InnerViewportScrollLayer() const;
120 // This function may return NULL, it is the caller's responsibility to check.
121 LayerImpl
* OuterViewportScrollLayer() const;
122 gfx::Vector2dF
TotalScrollOffset() const;
123 gfx::Vector2dF
TotalMaxScrollOffset() const;
124 gfx::Vector2dF
TotalScrollDelta() const;
126 LayerImpl
* InnerViewportContainerLayer() const;
127 LayerImpl
* CurrentlyScrollingLayer() const;
128 void SetCurrentlyScrollingLayer(LayerImpl
* layer
);
129 void ClearCurrentlyScrollingLayer();
130 float VerticalAdjust(const int clip_layer_id
) const;
132 void SetViewportLayersFromIds(int page_scale_layer_id
,
133 int inner_viewport_scroll_layer_id
,
134 int outer_viewport_scroll_layer_id
);
135 void ClearViewportLayers();
136 LayerImpl
* page_scale_layer() { return page_scale_layer_
; }
137 void ApplySentScrollAndScaleDeltasFromAbortedCommit();
138 void ApplyScrollDeltasSinceBeginMainFrame();
140 SkColor
background_color() const { return background_color_
; }
141 void set_background_color(SkColor color
) { background_color_
= color
; }
143 bool has_transparent_background() const {
144 return has_transparent_background_
;
146 void set_has_transparent_background(bool transparent
) {
147 has_transparent_background_
= transparent
;
150 void SetPageScaleFactorAndLimits(float page_scale_factor
,
151 float min_page_scale_factor
, float max_page_scale_factor
);
152 void SetPageScaleDelta(float delta
);
153 float total_page_scale_factor() const {
154 return page_scale_factor_
* page_scale_delta_
;
156 float page_scale_factor() const { return page_scale_factor_
; }
157 float min_page_scale_factor() const { return min_page_scale_factor_
; }
158 float max_page_scale_factor() const { return max_page_scale_factor_
; }
159 float page_scale_delta() const { return page_scale_delta_
; }
160 void set_sent_page_scale_delta(float delta
) {
161 sent_page_scale_delta_
= delta
;
163 float sent_page_scale_delta() const { return sent_page_scale_delta_
; }
165 // Updates draw properties and render surface layer list, as well as tile
167 void UpdateDrawProperties();
169 void set_needs_update_draw_properties() {
170 needs_update_draw_properties_
= true;
172 bool needs_update_draw_properties() const {
173 return needs_update_draw_properties_
;
176 void set_needs_full_tree_sync(bool needs
) { needs_full_tree_sync_
= needs
; }
177 bool needs_full_tree_sync() const { return needs_full_tree_sync_
; }
179 void ForceRedrawNextActivation() { next_activation_forces_redraw_
= true; }
181 void set_ui_resource_request_queue(const UIResourceRequestQueue
& queue
);
183 const LayerImplList
& RenderSurfaceLayerList() const;
185 // These return the size of the root scrollable area and the size of
186 // the user-visible scrolling viewport, in CSS layout coordinates.
187 gfx::Size
ScrollableSize() const;
188 gfx::SizeF
ScrollableViewportSize() const;
190 gfx::Rect
RootScrollLayerDeviceViewportBounds() const;
192 LayerImpl
* LayerById(int id
);
194 // These should be called by LayerImpl's ctor/dtor.
195 void RegisterLayer(LayerImpl
* layer
);
196 void UnregisterLayer(LayerImpl
* layer
);
198 AnimationRegistrar
* animationRegistrar() const;
200 void PushPersistedState(LayerTreeImpl
* pending_tree
);
202 void DidBecomeActive();
204 bool ContentsTexturesPurged() const;
205 void SetContentsTexturesPurged();
206 void ResetContentsTexturesPurged();
208 void SetRequiresHighResToDraw();
209 void ResetRequiresHighResToDraw();
210 bool RequiresHighResToDraw() const;
212 // Set on the active tree when the viewport size recently changed
213 // and the active tree's size is now out of date.
214 bool ViewportSizeInvalid() const;
215 void SetViewportSizeInvalid();
216 void ResetViewportSizeInvalid();
218 // Useful for debug assertions, probably shouldn't be used for anything else.
219 Proxy
* proxy() const;
221 void SetRootLayerScrollOffsetDelegate(
222 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
);
223 void UpdateScrollOffsetDelegate();
224 gfx::Vector2dF
GetDelegatedScrollOffset(LayerImpl
* layer
);
226 // Call this function when you expect there to be a swap buffer.
227 // See swap_promise.h for how to use SwapPromise.
228 void QueueSwapPromise(scoped_ptr
<SwapPromise
> swap_promise
);
230 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
231 void PassSwapPromises(ScopedPtrVector
<SwapPromise
>* new_swap_promise
);
232 void FinishSwapPromises(CompositorFrameMetadata
* metadata
);
233 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason
);
235 void DidModifyTilePriorities();
237 ResourceProvider::ResourceId
ResourceIdForUIResource(UIResourceId uid
) const;
238 void ProcessUIResourceRequestQueue();
240 bool IsUIResourceOpaque(UIResourceId uid
) const;
242 void AddLayerWithCopyOutputRequest(LayerImpl
* layer
);
243 void RemoveLayerWithCopyOutputRequest(LayerImpl
* layer
);
244 const std::vector
<LayerImpl
*>& LayersWithCopyOutputRequest() const;
247 explicit LayerTreeImpl(LayerTreeHostImpl
* layer_tree_host_impl
);
249 LayerTreeHostImpl
* layer_tree_host_impl_
;
250 int source_frame_number_
;
251 scoped_ptr
<LayerImpl
> root_layer_
;
252 HeadsUpDisplayLayerImpl
* hud_layer_
;
253 LayerImpl
* currently_scrolling_layer_
;
254 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate_
;
255 scoped_ptr
<LayerScrollOffsetDelegateProxy
>
256 inner_viewport_scroll_delegate_proxy_
;
257 scoped_ptr
<LayerScrollOffsetDelegateProxy
>
258 outer_viewport_scroll_delegate_proxy_
;
259 SkColor background_color_
;
260 bool has_transparent_background_
;
262 LayerImpl
* page_scale_layer_
;
263 LayerImpl
* inner_viewport_scroll_layer_
;
264 LayerImpl
* outer_viewport_scroll_layer_
;
266 float page_scale_factor_
;
267 float page_scale_delta_
;
268 float sent_page_scale_delta_
;
269 float min_page_scale_factor_
;
270 float max_page_scale_factor_
;
272 typedef base::hash_map
<int, LayerImpl
*> LayerIdMap
;
273 LayerIdMap layer_id_map_
;
275 std::vector
<LayerImpl
*> layers_with_copy_output_request_
;
277 // Persisted state for non-impl-side-painting.
278 int scrolling_layer_id_from_previous_tree_
;
280 // List of visible or hit-testable layers for the most recently prepared
281 // frame. Used for rendering and input event hit testing.
282 LayerImplList render_surface_layer_list_
;
284 bool contents_textures_purged_
;
285 bool requires_high_res_to_draw_
;
286 bool viewport_size_invalid_
;
287 bool needs_update_draw_properties_
;
289 // In impl-side painting mode, this is true when the tree may contain
290 // structural differences relative to the active tree.
291 bool needs_full_tree_sync_
;
293 bool next_activation_forces_redraw_
;
295 ScopedPtrVector
<SwapPromise
> swap_promise_list_
;
297 UIResourceRequestQueue ui_resource_request_queue_
;
300 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl
);
305 #endif // CC_TREES_LAYER_TREE_IMPL_H_