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/layers/layer_impl.h"
15 #include "cc/resources/ui_resource_client.h"
16 #include "ui/events/latency_info.h"
18 #if defined(COMPILER_GCC)
19 namespace BASE_HASH_NAMESPACE {
21 struct hash<cc::LayerImpl*> {
22 size_t operator()(cc::LayerImpl* ptr) const {
23 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
26 } // namespace BASE_HASH_NAMESPACE
31 class ContextProvider;
32 class DebugRectHistory;
33 class FrameRateCounter;
34 class HeadsUpDisplayLayerImpl;
35 class LayerTreeDebugState;
36 class LayerTreeHostImpl;
38 class LayerTreeSettings;
41 class PaintTimeCounter;
43 class ResourceProvider;
45 class UIResourceRequest;
46 struct RendererCapabilities;
48 typedef std::list<UIResourceRequest> UIResourceRequestQueue;
50 class CC_EXPORT LayerTreeImpl {
52 static scoped_ptr<LayerTreeImpl> create(
53 LayerTreeHostImpl* layer_tree_host_impl) {
54 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
56 virtual ~LayerTreeImpl();
58 // Methods called by the layer tree that pass-through or access LTHI.
59 // ---------------------------------------------------------------------------
60 const LayerTreeSettings& settings() const;
61 const RendererCapabilities& GetRendererCapabilities() const;
62 ContextProvider* context_provider() const;
63 OutputSurface* output_surface() const;
64 ResourceProvider* resource_provider() const;
65 TileManager* tile_manager() const;
66 FrameRateCounter* frame_rate_counter() const;
67 PaintTimeCounter* paint_time_counter() const;
68 MemoryHistory* memory_history() const;
69 bool device_viewport_valid_for_tile_management() const;
70 bool IsActiveTree() const;
71 bool IsPendingTree() const;
72 bool IsRecycleTree() const;
73 LayerImpl* FindActiveTreeLayerById(int id);
74 LayerImpl* FindPendingTreeLayerById(int id);
75 int MaxTextureSize() const;
76 bool PinchGestureActive() const;
77 base::TimeTicks CurrentFrameTimeTicks() const;
78 base::Time CurrentFrameTime() const;
79 base::TimeTicks CurrentPhysicalTimeTicks() const;
80 void SetNeedsCommit();
81 gfx::Size DrawViewportSize() const;
82 void StartScrollbarAnimation();
84 // Tree specific methods exposed to layer-impl tree.
85 // ---------------------------------------------------------------------------
86 void SetNeedsRedraw();
88 // TODO(nduca): These are implemented in cc files temporarily, but will become
89 // trivial accessors in a followup patch.
90 const LayerTreeDebugState& debug_state() const;
91 float device_scale_factor() const;
92 DebugRectHistory* debug_rect_history() const;
93 scoped_ptr<base::Value> AsValue() const;
95 // Other public methods
96 // ---------------------------------------------------------------------------
97 LayerImpl* root_layer() const { return root_layer_.get(); }
98 void SetRootLayer(scoped_ptr<LayerImpl>);
99 scoped_ptr<LayerImpl> DetachLayerTree();
101 void PushPropertiesTo(LayerTreeImpl* tree_impl);
103 int source_frame_number() const { return source_frame_number_; }
104 void set_source_frame_number(int frame_number) {
105 source_frame_number_ = frame_number;
108 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
109 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
110 hud_layer_ = layer_impl;
113 LayerImpl* RootScrollLayer() const;
114 LayerImpl* RootContainerLayer() const;
115 LayerImpl* CurrentlyScrollingLayer() const;
116 void SetCurrentlyScrollingLayer(LayerImpl* layer);
117 void ClearCurrentlyScrollingLayer();
119 void FindRootScrollLayer();
120 void UpdateMaxScrollOffset();
121 void SetViewportLayersFromIds(int page_scale_layer_id,
122 int inner_viewport_scroll_layer_id,
123 int outer_viewport_scroll_layer_id);
124 void ClearViewportLayers();
125 void ApplySentScrollAndScaleDeltasFromAbortedCommit();
126 void ApplyScrollDeltasSinceBeginMainFrame();
128 SkColor background_color() const { return background_color_; }
129 void set_background_color(SkColor color) { background_color_ = color; }
131 bool has_transparent_background() const {
132 return has_transparent_background_;
134 void set_has_transparent_background(bool transparent) {
135 has_transparent_background_ = transparent;
138 void SetPageScaleFactorAndLimits(float page_scale_factor,
139 float min_page_scale_factor, float max_page_scale_factor);
140 void SetPageScaleDelta(float delta);
141 float total_page_scale_factor() const {
142 return page_scale_factor_ * page_scale_delta_;
144 float page_scale_factor() const { return page_scale_factor_; }
145 float min_page_scale_factor() const { return min_page_scale_factor_; }
146 float max_page_scale_factor() const { return max_page_scale_factor_; }
147 float page_scale_delta() const { return page_scale_delta_; }
148 void set_sent_page_scale_delta(float delta) {
149 sent_page_scale_delta_ = delta;
151 float sent_page_scale_delta() const { return sent_page_scale_delta_; }
153 // Updates draw properties and render surface layer list, as well as tile
155 void UpdateDrawProperties();
157 void set_needs_update_draw_properties() {
158 needs_update_draw_properties_ = true;
160 bool needs_update_draw_properties() const {
161 return needs_update_draw_properties_;
164 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
165 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
167 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
169 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
171 const LayerImplList& RenderSurfaceLayerList() const;
173 // These return the size of the root scrollable area and the size of
174 // the user-visible scrolling viewport, in CSS layout coordinates.
175 gfx::Size ScrollableSize() const;
176 gfx::SizeF ScrollableViewportSize() const;
178 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
180 LayerImpl* LayerById(int id);
182 // These should be called by LayerImpl's ctor/dtor.
183 void RegisterLayer(LayerImpl* layer);
184 void UnregisterLayer(LayerImpl* layer);
186 AnimationRegistrar* animationRegistrar() const;
188 void PushPersistedState(LayerTreeImpl* pending_tree);
190 void DidBecomeActive();
192 bool ContentsTexturesPurged() const;
193 void SetContentsTexturesPurged();
194 void ResetContentsTexturesPurged();
196 // Set on the active tree when the viewport size recently changed
197 // and the active tree's size is now out of date.
198 bool ViewportSizeInvalid() const;
199 void SetViewportSizeInvalid();
200 void ResetViewportSizeInvalid();
202 // Useful for debug assertions, probably shouldn't be used for anything else.
203 Proxy* proxy() const;
205 void SetRootLayerScrollOffsetDelegate(
206 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
208 void SetLatencyInfo(const ui::LatencyInfo& latency_info);
209 const ui::LatencyInfo& GetLatencyInfo();
210 void ClearLatencyInfo();
212 void DidModifyTilePriorities();
214 ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
215 void ProcessUIResourceRequestQueue();
217 bool IsUIResourceOpaque(UIResourceId uid) const;
219 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
220 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
221 const std::vector<LayerImpl*> LayersWithCopyOutputRequest() const;
224 explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
226 void UpdateSolidColorScrollbars();
228 void UpdateRootScrollLayerSizeDelta();
230 LayerTreeHostImpl* layer_tree_host_impl_;
231 int source_frame_number_;
232 scoped_ptr<LayerImpl> root_layer_;
233 HeadsUpDisplayLayerImpl* hud_layer_;
234 LayerImpl* root_scroll_layer_;
235 LayerImpl* currently_scrolling_layer_;
236 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
237 SkColor background_color_;
238 bool has_transparent_background_;
240 LayerImpl* page_scale_layer_;
241 LayerImpl* inner_viewport_scroll_layer_;
242 LayerImpl* outer_viewport_scroll_layer_;
244 float page_scale_factor_;
245 float page_scale_delta_;
246 float sent_page_scale_delta_;
247 float min_page_scale_factor_;
248 float max_page_scale_factor_;
250 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
251 LayerIdMap layer_id_map_;
253 std::vector<LayerImpl*> layers_with_copy_output_request_;
255 // Persisted state for non-impl-side-painting.
256 int scrolling_layer_id_from_previous_tree_;
258 // List of visible or hit-testable layers for the most recently prepared
259 // frame. Used for rendering and input event hit testing.
260 LayerImplList render_surface_layer_list_;
262 bool contents_textures_purged_;
263 bool viewport_size_invalid_;
264 bool needs_update_draw_properties_;
266 // In impl-side painting mode, this is true when the tree may contain
267 // structural differences relative to the active tree.
268 bool needs_full_tree_sync_;
270 bool next_activation_forces_redraw_;
272 ui::LatencyInfo latency_info_;
274 UIResourceRequestQueue ui_resource_request_queue_;
277 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
282 #endif // CC_TREES_LAYER_TREE_IMPL_H_