blob: b8971f842d4005b67ec399385f818c76477f2253 [file] [log] [blame]
[email protected]3b31c6ac2012-12-06 21:27:291// 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]361bc00d2012-12-14 07:03:248#include "base/hash_tables.h"
[email protected]3b31c6ac2012-12-06 21:27:299#include "cc/layer_impl.h"
10
[email protected]361bc00d2012-12-14 07:03:2411#if defined(COMPILER_GCC)
12namespace BASE_HASH_NAMESPACE {
13template<>
14struct 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]3b31c6ac2012-12-06 21:27:2922namespace cc {
23
[email protected]ff762fb2012-12-12 19:18:3724class DebugRectHistory;
25class FrameRateCounter;
26class HeadsUpDisplayLayerImpl;
27class LayerTreeDebugState;
[email protected]3b31c6ac2012-12-06 21:27:2928class LayerTreeHostImpl;
29class LayerTreeImpl;
[email protected]ff762fb2012-12-12 19:18:3730class LayerTreeSettings;
[email protected]1191d9d2013-02-02 06:00:3331class MemoryHistory;
[email protected]ff762fb2012-12-12 19:18:3732class OutputSurface;
[email protected]71691c22013-01-18 03:14:2233class PaintTimeCounter;
[email protected]69b50ec2013-01-19 04:58:0134class Proxy;
[email protected]ff762fb2012-12-12 19:18:3735class ResourceProvider;
36class TileManager;
[email protected]3b31c6ac2012-12-06 21:27:2937
[email protected]3b31c6ac2012-12-06 21:27:2938class CC_EXPORT LayerTreeImpl {
39 public:
[email protected]76ffd9e2012-12-20 19:12:4740 typedef std::vector<LayerImpl*> LayerList;
41
[email protected]8bef40572012-12-11 21:38:0842 static scoped_ptr<LayerTreeImpl> create(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]3b31c6ac2012-12-06 21:27:2943 {
[email protected]8bef40572012-12-11 21:38:0844 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
[email protected]3b31c6ac2012-12-06 21:27:2945 }
46 virtual ~LayerTreeImpl();
47
[email protected]f117a4c2012-12-16 04:53:1048 // Methods called by the layer tree that pass-through or access LTHI.
[email protected]8bef40572012-12-11 21:38:0849 // ---------------------------------------------------------------------------
[email protected]ff762fb2012-12-12 19:18:3750 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]71691c22013-01-18 03:14:2255 PaintTimeCounter* paint_time_counter() const;
[email protected]1191d9d2013-02-02 06:00:3356 MemoryHistory* memory_history() const;
[email protected]f117a4c2012-12-16 04:53:1057 bool IsActiveTree() const;
58 bool IsPendingTree() const;
[email protected]48871fc2013-01-23 07:36:5159 bool IsRecycleTree() const;
[email protected]f117a4c2012-12-16 04:53:1060 LayerImpl* FindActiveTreeLayerById(int id);
61 LayerImpl* FindPendingTreeLayerById(int id);
[email protected]f6776532012-12-21 20:24:3362 int MaxTextureSize() const;
[email protected]166db5c82013-01-09 23:54:3163 bool PinchGestureActive() const;
[email protected]829ad972013-01-28 23:36:1064 base::TimeTicks CurrentFrameTime() const;
[email protected]ff762fb2012-12-12 19:18:3765
66 // Tree specific methods exposed to layer-impl tree.
67 // ---------------------------------------------------------------------------
68 void SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:3769
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]8bef40572012-12-11 21:38:0878
79 // Other public methods
80 // ---------------------------------------------------------------------------
[email protected]3b31c6ac2012-12-06 21:27:2981 LayerImpl* RootLayer() const { return root_layer_.get(); }
82 void SetRootLayer(scoped_ptr<LayerImpl>);
83 scoped_ptr<LayerImpl> DetachLayerTree();
84
[email protected]c60279472013-01-30 12:10:5185 void pushPropertiesTo(LayerTreeImpl*);
86
[email protected]3b31c6ac2012-12-06 21:27:2987 int source_frame_number() const { return source_frame_number_; }
[email protected]a30290142013-01-05 01:27:0088 void set_source_frame_number(int frame_number) {
89 source_frame_number_ = frame_number;
90 }
[email protected]3b31c6ac2012-12-06 21:27:2991
92 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
[email protected]a30290142013-01-05 01:27:0093 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
94 hud_layer_ = layer_impl;
95 }
[email protected]3b31c6ac2012-12-06 21:27:2996
[email protected]69b50ec2013-01-19 04:58:0197 LayerImpl* RootScrollLayer();
98 LayerImpl* CurrentlyScrollingLayer();
99 void set_currently_scrolling_layer(LayerImpl* layer) {
100 currently_scrolling_layer_ = layer;
[email protected]a30290142013-01-05 01:27:00101 }
[email protected]3b31c6ac2012-12-06 21:27:29102
[email protected]3b31c6ac2012-12-06 21:27:29103 void ClearCurrentlyScrollingLayer();
104
[email protected]69b50ec2013-01-19 04:58:01105 void FindRootScrollLayer();
[email protected]caa567d2012-12-20 07:56:16106 void UpdateMaxScrollOffset();
107
[email protected]a30290142013-01-05 01:27:00108 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]4c9bb952013-01-27 05:41:18118 enum UpdateDrawPropertiesReason {
119 UPDATE_PENDING_TREE,
120 UPDATE_ACTIVE_TREE,
121 UPDATE_ACTIVE_TREE_FOR_DRAW
122 };
123
[email protected]c60279472013-01-30 12:10:51124 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]76ffd9e2012-12-20 19:12:47141 // Updates draw properties and render surface layer list
[email protected]4c9bb952013-01-27 05:41:18142 void UpdateDrawProperties(UpdateDrawPropertiesReason reason);
[email protected]615c78a2013-01-24 23:44:16143 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]76ffd9e2012-12-20 19:12:47149
[email protected]db8259f2013-02-01 05:25:04150 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]76ffd9e2012-12-20 19:12:47153 void ClearRenderSurfaces();
154
[email protected]b0a917c8d2013-01-12 17:42:25155 bool AreVisibleResourcesReady() const;
156
[email protected]76ffd9e2012-12-20 19:12:47157 const LayerList& RenderSurfaceLayerList() const;
158
[email protected]257abfa82013-01-29 23:47:24159 // 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]42ccdbef2013-01-21 07:54:54161 gfx::Size ScrollableSize() const;
[email protected]257abfa82013-01-29 23:47:24162 gfx::SizeF ScrollableViewportSize() const;
[email protected]caa567d2012-12-20 07:56:16163
[email protected]361bc00d2012-12-14 07:03:24164 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]de4afb5e2012-12-20 00:11:34170 AnimationRegistrar* animationRegistrar() const;
171
[email protected]1e0f8d62013-01-09 07:41:35172 void PushPersistedState(LayerTreeImpl* pendingTree);
173
[email protected]37386f052013-01-13 00:42:22174 void DidBecomeActive();
175
[email protected]6f90b9e2013-01-17 23:42:00176 bool ContentsTexturesPurged() const;
177 void SetContentsTexturesPurged();
178 void ResetContentsTexturesPurged();
179
[email protected]48871fc2013-01-23 07:36:51180 // Useful for debug assertions, probably shouldn't be used for anything else.
181 Proxy* proxy() const;
182
[email protected]3b31c6ac2012-12-06 21:27:29183protected:
[email protected]8bef40572012-12-11 21:38:08184 LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
[email protected]3b31c6ac2012-12-06 21:27:29185
[email protected]8bef40572012-12-11 21:38:08186 LayerTreeHostImpl* layer_tree_host_impl_;
[email protected]3b31c6ac2012-12-06 21:27:29187 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]a30290142013-01-05 01:27:00192 SkColor background_color_;
193 bool has_transparent_background_;
[email protected]3b31c6ac2012-12-06 21:27:29194
[email protected]c60279472013-01-30 12:10:51195 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]361bc00d2012-12-14 07:03:24201 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
202 LayerIdMap layer_id_map_;
203
[email protected]1e0f8d62013-01-09 07:41:35204 // Persisted state for non-impl-side-painting.
[email protected]3b31c6ac2012-12-06 21:27:29205 int scrolling_layer_id_from_previous_tree_;
206
[email protected]76ffd9e2012-12-20 19:12:47207 // 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]6f90b9e2013-01-17 23:42:00211 bool contents_textures_purged_;
[email protected]615c78a2013-01-24 23:44:16212 bool needs_update_draw_properties_;
[email protected]6f90b9e2013-01-17 23:42:00213
[email protected]db8259f2013-02-01 05:25:04214 // 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]3b31c6ac2012-12-06 21:27:29218 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
219};
220
221}
222
223#endif // CC_LAYER_TREE_IMPL_H_