[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; |
31 | class OutputSurface; | ||||
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 32 | class PaintTimeCounter; |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 33 | class PinchZoomViewport; |
[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] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 56 | bool IsActiveTree() const; |
57 | bool IsPendingTree() const; | ||||
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 58 | bool IsRecycleTree() const; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 59 | LayerImpl* FindActiveTreeLayerById(int id); |
60 | LayerImpl* FindPendingTreeLayerById(int id); | ||||
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 61 | int MaxTextureSize() const; |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 62 | bool PinchGestureActive() const; |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 63 | |
64 | // Tree specific methods exposed to layer-impl tree. | ||||
65 | // --------------------------------------------------------------------------- | ||||
66 | void SetNeedsRedraw(); | ||||
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 67 | |
68 | // TODO(nduca): These are implemented in cc files temporarily, but will become | ||||
69 | // trivial accessors in a followup patch. | ||||
70 | const LayerTreeDebugState& debug_state() const; | ||||
71 | float device_scale_factor() const; | ||||
72 | const gfx::Size& device_viewport_size() const; | ||||
73 | const gfx::Size& layout_viewport_size() const; | ||||
74 | std::string layer_tree_as_text() const; | ||||
75 | DebugRectHistory* debug_rect_history() const; | ||||
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 76 | const PinchZoomViewport& pinch_zoom_viewport() const; |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 77 | |
78 | // Other public methods | ||||
79 | // --------------------------------------------------------------------------- | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 80 | LayerImpl* RootLayer() const { return root_layer_.get(); } |
81 | void SetRootLayer(scoped_ptr<LayerImpl>); | ||||
82 | scoped_ptr<LayerImpl> DetachLayerTree(); | ||||
83 | |||||
84 | int source_frame_number() const { return source_frame_number_; } | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 85 | void set_source_frame_number(int frame_number) { |
86 | source_frame_number_ = frame_number; | ||||
87 | } | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 88 | |
89 | HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; } | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 90 | void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) { |
91 | hud_layer_ = layer_impl; | ||||
92 | } | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 93 | |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 94 | LayerImpl* RootScrollLayer(); |
95 | LayerImpl* CurrentlyScrollingLayer(); | ||||
96 | void set_currently_scrolling_layer(LayerImpl* layer) { | ||||
97 | currently_scrolling_layer_ = layer; | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 98 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 99 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 100 | void ClearCurrentlyScrollingLayer(); |
101 | |||||
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 102 | void FindRootScrollLayer(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 103 | void UpdateMaxScrollOffset(); |
104 | |||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 105 | SkColor background_color() const { return background_color_; } |
106 | void set_background_color(SkColor color) { background_color_ = color; } | ||||
107 | |||||
108 | bool has_transparent_background() const { | ||||
109 | return has_transparent_background_; | ||||
110 | } | ||||
111 | void set_has_transparent_background(bool transparent) { | ||||
112 | has_transparent_background_ = transparent; | ||||
113 | } | ||||
114 | |||||
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame^] | 115 | enum UpdateDrawPropertiesReason { |
116 | UPDATE_PENDING_TREE, | ||||
117 | UPDATE_ACTIVE_TREE, | ||||
118 | UPDATE_ACTIVE_TREE_FOR_DRAW | ||||
119 | }; | ||||
120 | |||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 121 | // Updates draw properties and render surface layer list |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame^] | 122 | void UpdateDrawProperties(UpdateDrawPropertiesReason reason); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 123 | void set_needs_update_draw_properties() { |
124 | needs_update_draw_properties_ = true; | ||||
125 | } | ||||
126 | bool needs_update_draw_properties() const { | ||||
127 | return needs_update_draw_properties_; | ||||
128 | } | ||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 129 | |
130 | void ClearRenderSurfaces(); | ||||
131 | |||||
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 132 | bool AreVisibleResourcesReady() const; |
133 | |||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 134 | const LayerList& RenderSurfaceLayerList() const; |
135 | |||||
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 136 | gfx::Size ScrollableSize() const; |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 137 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 138 | LayerImpl* LayerById(int id); |
139 | |||||
140 | // These should be called by LayerImpl's ctor/dtor. | ||||
141 | void RegisterLayer(LayerImpl* layer); | ||||
142 | void UnregisterLayer(LayerImpl* layer); | ||||
143 | |||||
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 144 | AnimationRegistrar* animationRegistrar() const; |
145 | |||||
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 146 | void PushPersistedState(LayerTreeImpl* pendingTree); |
147 | |||||
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 148 | void DidBecomeActive(); |
149 | |||||
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 150 | bool ContentsTexturesPurged() const; |
151 | void SetContentsTexturesPurged(); | ||||
152 | void ResetContentsTexturesPurged(); | ||||
153 | |||||
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 154 | // Useful for debug assertions, probably shouldn't be used for anything else. |
155 | Proxy* proxy() const; | ||||
156 | |||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 157 | protected: |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 158 | LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 159 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 160 | LayerTreeHostImpl* layer_tree_host_impl_; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 161 | int source_frame_number_; |
162 | scoped_ptr<LayerImpl> root_layer_; | ||||
163 | HeadsUpDisplayLayerImpl* hud_layer_; | ||||
164 | LayerImpl* root_scroll_layer_; | ||||
165 | LayerImpl* currently_scrolling_layer_; | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 166 | SkColor background_color_; |
167 | bool has_transparent_background_; | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 168 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 169 | typedef base::hash_map<int, LayerImpl*> LayerIdMap; |
170 | LayerIdMap layer_id_map_; | ||||
171 | |||||
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 172 | // Persisted state for non-impl-side-painting. |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 173 | int scrolling_layer_id_from_previous_tree_; |
174 | |||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 175 | // List of visible layers for the most recently prepared frame. Used for |
176 | // rendering and input event hit testing. | ||||
177 | LayerList render_surface_layer_list_; | ||||
178 | |||||
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 179 | bool contents_textures_purged_; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 180 | bool needs_update_draw_properties_; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 181 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 182 | DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl); |
183 | }; | ||||
184 | |||||
185 | } | ||||
186 | |||||
187 | #endif // CC_LAYER_TREE_IMPL_H_ |