[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 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_LAYER_TREE_IMPL_H_ | ||||
6 | #define CC_LAYER_TREE_IMPL_H_ | ||||
7 | |||||
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 8 | #include "base/hash_tables.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 9 | #include "cc/layer_impl.h" |
10 | |||||
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 11 | #if defined(COMPILER_GCC) |
12 | namespace BASE_HASH_NAMESPACE { | ||||
13 | template<> | ||||
14 | struct hash<cc::LayerImpl*> { | ||||
15 | size_t operator()(cc::LayerImpl* ptr) const { | ||||
16 | return hash<size_t>()(reinterpret_cast<size_t>(ptr)); | ||||
17 | } | ||||
18 | }; | ||||
19 | } // namespace BASE_HASH_NAMESPACE | ||||
20 | #endif // COMPILER | ||||
21 | |||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 22 | namespace cc { |
23 | |||||
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 24 | class DebugRectHistory; |
25 | class FrameRateCounter; | ||||
26 | class HeadsUpDisplayLayerImpl; | ||||
27 | class LayerTreeDebugState; | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 28 | class LayerTreeHostImpl; |
29 | class LayerTreeImpl; | ||||
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 30 | class LayerTreeSettings; |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 31 | class MemoryHistory; |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 32 | class OutputSurface; |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 33 | class PaintTimeCounter; |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 34 | class Proxy; |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 35 | class ResourceProvider; |
36 | class TileManager; | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 37 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 38 | class CC_EXPORT LayerTreeImpl { |
39 | public: | ||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 40 | typedef std::vector<LayerImpl*> LayerList; |
41 | |||||
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 42 | static scoped_ptr<LayerTreeImpl> create(LayerTreeHostImpl* layer_tree_host_impl) |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 43 | { |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 44 | return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl)); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 45 | } |
46 | virtual ~LayerTreeImpl(); | ||||
47 | |||||
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 48 | // Methods called by the layer tree that pass-through or access LTHI. |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 49 | // --------------------------------------------------------------------------- |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 50 | const LayerTreeSettings& settings() const; |
51 | OutputSurface* output_surface() const; | ||||
52 | ResourceProvider* resource_provider() const; | ||||
53 | TileManager* tile_manager() const; | ||||
54 | FrameRateCounter* frame_rate_counter() const; | ||||
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 55 | PaintTimeCounter* paint_time_counter() const; |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 56 | MemoryHistory* memory_history() const; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 57 | bool IsActiveTree() const; |
58 | bool IsPendingTree() const; | ||||
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 59 | bool IsRecycleTree() const; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 60 | LayerImpl* FindActiveTreeLayerById(int id); |
61 | LayerImpl* FindPendingTreeLayerById(int id); | ||||
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 62 | int MaxTextureSize() const; |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 63 | bool PinchGestureActive() const; |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 64 | base::TimeTicks CurrentFrameTime() const; |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 65 | |
66 | // Tree specific methods exposed to layer-impl tree. | ||||
67 | // --------------------------------------------------------------------------- | ||||
68 | void SetNeedsRedraw(); | ||||
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 69 | |
70 | // TODO(nduca): These are implemented in cc files temporarily, but will become | ||||
71 | // trivial accessors in a followup patch. | ||||
72 | const LayerTreeDebugState& debug_state() const; | ||||
73 | float device_scale_factor() const; | ||||
74 | const gfx::Size& device_viewport_size() const; | ||||
75 | const gfx::Size& layout_viewport_size() const; | ||||
76 | std::string layer_tree_as_text() const; | ||||
77 | DebugRectHistory* debug_rect_history() const; | ||||
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 78 | |
79 | // Other public methods | ||||
80 | // --------------------------------------------------------------------------- | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 81 | LayerImpl* RootLayer() const { return root_layer_.get(); } |
82 | void SetRootLayer(scoped_ptr<LayerImpl>); | ||||
83 | scoped_ptr<LayerImpl> DetachLayerTree(); | ||||
84 | |||||
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 85 | void pushPropertiesTo(LayerTreeImpl*); |
86 | |||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 87 | int source_frame_number() const { return source_frame_number_; } |
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 88 | void set_source_frame_number(int frame_number) { |
89 | source_frame_number_ = frame_number; | ||||
90 | } | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 91 | |
92 | HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; } | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 93 | void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) { |
94 | hud_layer_ = layer_impl; | ||||
95 | } | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 96 | |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 97 | LayerImpl* RootScrollLayer(); |
98 | LayerImpl* CurrentlyScrollingLayer(); | ||||
99 | void set_currently_scrolling_layer(LayerImpl* layer) { | ||||
100 | currently_scrolling_layer_ = layer; | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 101 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 102 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 103 | void ClearCurrentlyScrollingLayer(); |
104 | |||||
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 105 | void FindRootScrollLayer(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 106 | void UpdateMaxScrollOffset(); |
107 | |||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 108 | SkColor background_color() const { return background_color_; } |
109 | void set_background_color(SkColor color) { background_color_ = color; } | ||||
110 | |||||
111 | bool has_transparent_background() const { | ||||
112 | return has_transparent_background_; | ||||
113 | } | ||||
114 | void set_has_transparent_background(bool transparent) { | ||||
115 | has_transparent_background_ = transparent; | ||||
116 | } | ||||
117 | |||||
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 118 | enum UpdateDrawPropertiesReason { |
119 | UPDATE_PENDING_TREE, | ||||
120 | UPDATE_ACTIVE_TREE, | ||||
121 | UPDATE_ACTIVE_TREE_FOR_DRAW | ||||
122 | }; | ||||
123 | |||||
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 124 | gfx::Transform ImplTransform() const; |
125 | |||||
126 | void SetPageScaleFactorAndLimits(float page_scale_factor, | ||||
127 | float min_page_scale_factor, float max_page_scale_factor); | ||||
128 | void SetPageScaleDelta(float delta); | ||||
129 | float total_page_scale_factor() const { | ||||
130 | return page_scale_factor_ * page_scale_delta_; | ||||
131 | } | ||||
132 | float page_scale_factor() const { return page_scale_factor_; } | ||||
133 | float min_page_scale_factor() const { return min_page_scale_factor_; } | ||||
134 | float max_page_scale_factor() const { return max_page_scale_factor_; } | ||||
135 | float page_scale_delta() const { return page_scale_delta_; } | ||||
136 | void set_sent_page_scale_delta(float delta) { | ||||
137 | sent_page_scale_delta_ = delta; | ||||
138 | } | ||||
139 | float sent_page_scale_delta() const { return sent_page_scale_delta_; } | ||||
140 | |||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 141 | // Updates draw properties and render surface layer list |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 142 | void UpdateDrawProperties(UpdateDrawPropertiesReason reason); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 143 | void set_needs_update_draw_properties() { |
144 | needs_update_draw_properties_ = true; | ||||
145 | } | ||||
146 | bool needs_update_draw_properties() const { | ||||
147 | return needs_update_draw_properties_; | ||||
148 | } | ||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 149 | |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 150 | void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; } |
151 | bool needs_full_tree_sync() const { return needs_full_tree_sync_; } | ||||
152 | |||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 153 | void ClearRenderSurfaces(); |
154 | |||||
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 155 | bool AreVisibleResourcesReady() const; |
156 | |||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 157 | const LayerList& RenderSurfaceLayerList() const; |
158 | |||||
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 159 | // These return the size of the root scrollable area and the size of |
160 | // the user-visible scrolling viewport, in CSS layout coordinates. | ||||
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 161 | gfx::Size ScrollableSize() const; |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 162 | gfx::SizeF ScrollableViewportSize() const; |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 163 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 164 | LayerImpl* LayerById(int id); |
165 | |||||
166 | // These should be called by LayerImpl's ctor/dtor. | ||||
167 | void RegisterLayer(LayerImpl* layer); | ||||
168 | void UnregisterLayer(LayerImpl* layer); | ||||
169 | |||||
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 170 | AnimationRegistrar* animationRegistrar() const; |
171 | |||||
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 172 | void PushPersistedState(LayerTreeImpl* pendingTree); |
173 | |||||
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 174 | void DidBecomeActive(); |
175 | |||||
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 176 | bool ContentsTexturesPurged() const; |
177 | void SetContentsTexturesPurged(); | ||||
178 | void ResetContentsTexturesPurged(); | ||||
179 | |||||
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 180 | // Useful for debug assertions, probably shouldn't be used for anything else. |
181 | Proxy* proxy() const; | ||||
182 | |||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 183 | protected: |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 184 | LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 185 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 186 | LayerTreeHostImpl* layer_tree_host_impl_; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 187 | int source_frame_number_; |
188 | scoped_ptr<LayerImpl> root_layer_; | ||||
189 | HeadsUpDisplayLayerImpl* hud_layer_; | ||||
190 | LayerImpl* root_scroll_layer_; | ||||
191 | LayerImpl* currently_scrolling_layer_; | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 192 | SkColor background_color_; |
193 | bool has_transparent_background_; | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 194 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 195 | float page_scale_factor_; |
196 | float page_scale_delta_; | ||||
197 | float sent_page_scale_delta_; | ||||
198 | float min_page_scale_factor_; | ||||
199 | float max_page_scale_factor_; | ||||
200 | |||||
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 201 | typedef base::hash_map<int, LayerImpl*> LayerIdMap; |
202 | LayerIdMap layer_id_map_; | ||||
203 | |||||
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 204 | // Persisted state for non-impl-side-painting. |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 205 | int scrolling_layer_id_from_previous_tree_; |
206 | |||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 207 | // List of visible layers for the most recently prepared frame. Used for |
208 | // rendering and input event hit testing. | ||||
209 | LayerList render_surface_layer_list_; | ||||
210 | |||||
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 211 | bool contents_textures_purged_; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 212 | bool needs_update_draw_properties_; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 213 | |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 214 | // In impl-side painting mode, this is true when the tree may contain |
215 | // structural differences relative to the active tree. | ||||
216 | bool needs_full_tree_sync_; | ||||
217 | |||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 218 | DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl); |
219 | }; | ||||
220 | |||||
221 | } | ||||
222 | |||||
223 | #endif // CC_LAYER_TREE_IMPL_H_ |