[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] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 32 | class PinchZoomViewport; |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 33 | class ResourceProvider; |
34 | class TileManager; | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 35 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 36 | class CC_EXPORT LayerTreeImpl { |
37 | public: | ||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 38 | typedef std::vector<LayerImpl*> LayerList; |
39 | |||||
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 40 | static scoped_ptr<LayerTreeImpl> create(LayerTreeHostImpl* layer_tree_host_impl) |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 41 | { |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 42 | return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl)); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 43 | } |
44 | virtual ~LayerTreeImpl(); | ||||
45 | |||||
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 46 | // Methods called by the layer tree that pass-through or access LTHI. |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 47 | // --------------------------------------------------------------------------- |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 48 | const LayerTreeSettings& settings() const; |
49 | OutputSurface* output_surface() const; | ||||
50 | ResourceProvider* resource_provider() const; | ||||
51 | TileManager* tile_manager() const; | ||||
52 | FrameRateCounter* frame_rate_counter() const; | ||||
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 53 | bool IsActiveTree() const; |
54 | bool IsPendingTree() const; | ||||
55 | LayerImpl* FindActiveTreeLayerById(int id); | ||||
56 | LayerImpl* FindPendingTreeLayerById(int id); | ||||
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 57 | int MaxTextureSize() const; |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 58 | |
59 | // Tree specific methods exposed to layer-impl tree. | ||||
60 | // --------------------------------------------------------------------------- | ||||
61 | void SetNeedsRedraw(); | ||||
62 | void SetNeedsUpdateDrawProperties(); | ||||
63 | |||||
64 | // TODO(nduca): These are implemented in cc files temporarily, but will become | ||||
65 | // trivial accessors in a followup patch. | ||||
66 | const LayerTreeDebugState& debug_state() const; | ||||
67 | float device_scale_factor() const; | ||||
68 | const gfx::Size& device_viewport_size() const; | ||||
69 | const gfx::Size& layout_viewport_size() const; | ||||
70 | std::string layer_tree_as_text() const; | ||||
71 | DebugRectHistory* debug_rect_history() const; | ||||
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 72 | const PinchZoomViewport& pinch_zoom_viewport() const; |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 73 | |
74 | // Other public methods | ||||
75 | // --------------------------------------------------------------------------- | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 76 | LayerImpl* RootLayer() const { return root_layer_.get(); } |
77 | void SetRootLayer(scoped_ptr<LayerImpl>); | ||||
78 | scoped_ptr<LayerImpl> DetachLayerTree(); | ||||
79 | |||||
80 | int source_frame_number() const { return source_frame_number_; } | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 81 | void set_source_frame_number(int frame_number) { |
82 | source_frame_number_ = frame_number; | ||||
83 | } | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 84 | |
85 | HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; } | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 86 | void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) { |
87 | hud_layer_ = layer_impl; | ||||
88 | } | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 89 | |
90 | LayerImpl* root_scroll_layer() { return root_scroll_layer_; } | ||||
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 91 | const LayerImpl* root_scroll_layer() const { return root_scroll_layer_; } |
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 92 | void set_root_scroll_layer(LayerImpl* layer_impl) { |
93 | root_scroll_layer_ = layer_impl; | ||||
94 | } | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 95 | |
96 | LayerImpl* currently_scrolling_layer() { return currently_scrolling_layer_; } | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 97 | void set_currently_scrolling_layer(LayerImpl* layer_impl) { |
98 | currently_scrolling_layer_ = layer_impl; | ||||
99 | } | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 100 | |
101 | void ClearCurrentlyScrollingLayer(); | ||||
102 | |||||
[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] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 115 | // Updates draw properties and render surface layer list |
116 | void UpdateDrawProperties(); | ||||
117 | |||||
118 | void ClearRenderSurfaces(); | ||||
119 | |||||
120 | const LayerList& RenderSurfaceLayerList() const; | ||||
121 | |||||
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 122 | gfx::Size ContentSize() const; |
123 | |||||
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 124 | LayerImpl* LayerById(int id); |
125 | |||||
126 | // These should be called by LayerImpl's ctor/dtor. | ||||
127 | void RegisterLayer(LayerImpl* layer); | ||||
128 | void UnregisterLayer(LayerImpl* layer); | ||||
129 | |||||
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 130 | AnimationRegistrar* animationRegistrar() const; |
131 | |||||
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame^] | 132 | void PushPersistedState(LayerTreeImpl* pendingTree); |
133 | |||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 134 | protected: |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 135 | LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 136 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 137 | LayerTreeHostImpl* layer_tree_host_impl_; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 138 | int source_frame_number_; |
139 | scoped_ptr<LayerImpl> root_layer_; | ||||
140 | HeadsUpDisplayLayerImpl* hud_layer_; | ||||
141 | LayerImpl* root_scroll_layer_; | ||||
142 | LayerImpl* currently_scrolling_layer_; | ||||
[email protected] | a3029014 | 2013-01-05 01:27:00 | [diff] [blame] | 143 | SkColor background_color_; |
144 | bool has_transparent_background_; | ||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 145 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 146 | typedef base::hash_map<int, LayerImpl*> LayerIdMap; |
147 | LayerIdMap layer_id_map_; | ||||
148 | |||||
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame^] | 149 | // Persisted state for non-impl-side-painting. |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 150 | int scrolling_layer_id_from_previous_tree_; |
151 | |||||
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 152 | // List of visible layers for the most recently prepared frame. Used for |
153 | // rendering and input event hit testing. | ||||
154 | LayerList render_surface_layer_list_; | ||||
155 | |||||
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 156 | DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl); |
157 | }; | ||||
158 | |||||
159 | } | ||||
160 | |||||
161 | #endif // CC_LAYER_TREE_IMPL_H_ |