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;
45 class PictureLayerImpl;
47 class ResourceProvider;
49 class UIResourceRequest;
50 struct RendererCapabilities;
52 typedef std::list<UIResourceRequest> UIResourceRequestQueue;
54 class CC_EXPORT LayerTreeImpl {
56 static scoped_ptr<LayerTreeImpl> create(
57 LayerTreeHostImpl* layer_tree_host_impl) {
58 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
60 virtual ~LayerTreeImpl();
63 void ReleaseResources();
65 // Methods called by the layer tree that pass-through or access LTHI.
66 // ---------------------------------------------------------------------------
67 const LayerTreeSettings& settings() const;
68 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
69 ContextProvider* context_provider() const;
70 OutputSurface* output_surface() const;
71 ResourceProvider* resource_provider() const;
72 TileManager* tile_manager() const;
73 FrameRateCounter* frame_rate_counter() const;
74 PaintTimeCounter* paint_time_counter() const;
75 MemoryHistory* memory_history() const;
76 bool device_viewport_valid_for_tile_management() const;
77 gfx::Size device_viewport_size() const;
78 bool IsActiveTree() const;
79 bool IsPendingTree() const;
80 bool IsRecycleTree() const;
81 LayerImpl* FindActiveTreeLayerById(int id);
82 LayerImpl* FindPendingTreeLayerById(int id);
83 int MaxTextureSize() const;
84 bool PinchGestureActive() const;
85 base::TimeTicks CurrentFrameTimeTicks() const;
86 base::TimeDelta begin_impl_frame_interval() const;
87 void SetNeedsCommit();
88 gfx::Size DrawViewportSize() const;
89 scoped_ptr<ScrollbarAnimationController> CreateScrollbarAnimationController(
90 LayerImpl* scrolling_layer);
91 void DidAnimateScrollOffset();
92 bool use_gpu_rasterization() const;
93 bool create_low_res_tiling() const;
95 // Tree specific methods exposed to layer-impl tree.
96 // ---------------------------------------------------------------------------
97 void SetNeedsRedraw();
99 // TODO(nduca): These are implemented in cc files temporarily, but will become
100 // trivial accessors in a followup patch.
101 const LayerTreeDebugState& debug_state() const;
102 float device_scale_factor() const;
103 DebugRectHistory* debug_rect_history() const;
104 scoped_ptr<base::Value> AsValue() const;
106 // Other public methods
107 // ---------------------------------------------------------------------------
108 LayerImpl* root_layer() const { return root_layer_.get(); }
109 void SetRootLayer(scoped_ptr<LayerImpl>);
110 scoped_ptr<LayerImpl> DetachLayerTree();
112 void PushPropertiesTo(LayerTreeImpl* tree_impl);
114 int source_frame_number() const { return source_frame_number_; }
115 void set_source_frame_number(int frame_number) {
116 source_frame_number_ = frame_number;
119 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
120 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
121 hud_layer_ = layer_impl;
124 LayerImpl* InnerViewportScrollLayer() const;
125 // This function may return NULL, it is the caller's responsibility to check.
126 LayerImpl* OuterViewportScrollLayer() const;
127 gfx::Vector2dF TotalScrollOffset() const;
128 gfx::Vector2dF TotalMaxScrollOffset() const;
129 gfx::Vector2dF TotalScrollDelta() const;
131 LayerImpl* InnerViewportContainerLayer() const;
132 LayerImpl* CurrentlyScrollingLayer() const;
133 void SetCurrentlyScrollingLayer(LayerImpl* layer);
134 void ClearCurrentlyScrollingLayer();
135 float VerticalAdjust(const int clip_layer_id) const;
137 void SetViewportLayersFromIds(int page_scale_layer_id,
138 int inner_viewport_scroll_layer_id,
139 int outer_viewport_scroll_layer_id);
140 void ClearViewportLayers();
141 LayerImpl* page_scale_layer() { return page_scale_layer_; }
142 void ApplySentScrollAndScaleDeltasFromAbortedCommit();
143 void ApplyScrollDeltasSinceBeginMainFrame();
145 SkColor background_color() const { return background_color_; }
146 void set_background_color(SkColor color) { background_color_ = color; }
148 bool has_transparent_background() const {
149 return has_transparent_background_;
151 void set_has_transparent_background(bool transparent) {
152 has_transparent_background_ = transparent;
155 void SetPageScaleFactorAndLimits(float page_scale_factor,
156 float min_page_scale_factor, float max_page_scale_factor);
157 void SetPageScaleDelta(float delta);
158 void SetPageScaleValues(float page_scale_factor,
159 float min_page_scale_factor, float max_page_scale_factor,
160 float page_scale_delta);
161 float total_page_scale_factor() const {
162 return page_scale_factor_ * page_scale_delta_;
164 float page_scale_factor() const { return page_scale_factor_; }
165 float min_page_scale_factor() const { return min_page_scale_factor_; }
166 float max_page_scale_factor() const { return max_page_scale_factor_; }
167 float page_scale_delta() const { return page_scale_delta_; }
168 void set_sent_page_scale_delta(float delta) {
169 sent_page_scale_delta_ = delta;
171 float sent_page_scale_delta() const { return sent_page_scale_delta_; }
173 // Updates draw properties and render surface layer list, as well as tile
174 // priorities. Returns false if it was unable to update.
175 bool UpdateDrawProperties();
177 void set_needs_update_draw_properties() {
178 needs_update_draw_properties_ = true;
180 bool needs_update_draw_properties() const {
181 return needs_update_draw_properties_;
184 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
185 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
187 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
189 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
191 const LayerImplList& RenderSurfaceLayerList() const;
193 // These return the size of the root scrollable area and the size of
194 // the user-visible scrolling viewport, in CSS layout coordinates.
195 gfx::Size ScrollableSize() const;
196 gfx::SizeF ScrollableViewportSize() const;
198 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
200 LayerImpl* LayerById(int id);
202 // These should be called by LayerImpl's ctor/dtor.
203 void RegisterLayer(LayerImpl* layer);
204 void UnregisterLayer(LayerImpl* layer);
206 AnimationRegistrar* animationRegistrar() const;
208 void PushPersistedState(LayerTreeImpl* pending_tree);
210 void DidBecomeActive();
212 bool ContentsTexturesPurged() const;
213 void SetContentsTexturesPurged();
214 void ResetContentsTexturesPurged();
216 void SetRequiresHighResToDraw();
217 void ResetRequiresHighResToDraw();
218 bool RequiresHighResToDraw() const;
220 // Set on the active tree when the viewport size recently changed
221 // and the active tree's size is now out of date.
222 bool ViewportSizeInvalid() const;
223 void SetViewportSizeInvalid();
224 void ResetViewportSizeInvalid();
226 // Useful for debug assertions, probably shouldn't be used for anything else.
227 Proxy* proxy() const;
229 void SetRootLayerScrollOffsetDelegate(
230 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
231 void UpdateScrollOffsetDelegate();
232 gfx::Vector2dF GetDelegatedScrollOffset(LayerImpl* layer);
234 // Call this function when you expect there to be a swap buffer.
235 // See swap_promise.h for how to use SwapPromise.
236 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
238 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
239 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
240 void FinishSwapPromises(CompositorFrameMetadata* metadata);
241 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
243 void DidModifyTilePriorities();
245 ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
246 void ProcessUIResourceRequestQueue();
248 bool IsUIResourceOpaque(UIResourceId uid) const;
250 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
251 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
252 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
254 int current_render_surface_list_id() const {
255 return render_surface_layer_list_id_;
258 LayerImpl* FindFirstScrollingLayerThatIsHitByPoint(
259 const gfx::PointF& screen_space_point);
261 LayerImpl* FindLayerThatIsHitByPoint(const gfx::PointF& screen_space_point);
263 LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
264 const gfx::PointF& screen_space_point);
266 void RegisterPictureLayerImpl(PictureLayerImpl* layer);
267 void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
270 explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
271 void ReleaseResourcesRecursive(LayerImpl* current);
273 LayerTreeHostImpl* layer_tree_host_impl_;
274 int source_frame_number_;
275 scoped_ptr<LayerImpl> root_layer_;
276 HeadsUpDisplayLayerImpl* hud_layer_;
277 LayerImpl* currently_scrolling_layer_;
278 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
279 scoped_ptr<LayerScrollOffsetDelegateProxy>
280 inner_viewport_scroll_delegate_proxy_;
281 scoped_ptr<LayerScrollOffsetDelegateProxy>
282 outer_viewport_scroll_delegate_proxy_;
283 SkColor background_color_;
284 bool has_transparent_background_;
286 LayerImpl* page_scale_layer_;
287 LayerImpl* inner_viewport_scroll_layer_;
288 LayerImpl* outer_viewport_scroll_layer_;
290 float page_scale_factor_;
291 float page_scale_delta_;
292 float sent_page_scale_delta_;
293 float min_page_scale_factor_;
294 float max_page_scale_factor_;
296 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
297 LayerIdMap layer_id_map_;
299 std::vector<LayerImpl*> layers_with_copy_output_request_;
301 // Persisted state for non-impl-side-painting.
302 int scrolling_layer_id_from_previous_tree_;
304 // List of visible layers for the most recently prepared frame.
305 LayerImplList render_surface_layer_list_;
307 bool contents_textures_purged_;
308 bool requires_high_res_to_draw_;
309 bool viewport_size_invalid_;
310 bool needs_update_draw_properties_;
312 // In impl-side painting mode, this is true when the tree may contain
313 // structural differences relative to the active tree.
314 bool needs_full_tree_sync_;
316 bool next_activation_forces_redraw_;
318 ScopedPtrVector<SwapPromise> swap_promise_list_;
320 UIResourceRequestQueue ui_resource_request_queue_;
322 int render_surface_layer_list_id_;
325 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
330 #endif // CC_TREES_LAYER_TREE_IMPL_H_