Fix build break
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.h
blob41b6f65bad608a140b836455b9f97aead4df64da
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_
8 #include <string>
9 #include <vector>
11 #include "base/hash_tables.h"
12 #include "base/values.h"
13 #include "cc/layers/layer_impl.h"
15 #if defined(COMPILER_GCC)
16 namespace BASE_HASH_NAMESPACE {
17 template<>
18 struct hash<cc::LayerImpl*> {
19 size_t operator()(cc::LayerImpl* ptr) const {
20 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
23 } // namespace BASE_HASH_NAMESPACE
24 #endif // COMPILER
26 namespace cc {
28 class DebugRectHistory;
29 class FrameRateCounter;
30 class HeadsUpDisplayLayerImpl;
31 class LayerTreeDebugState;
32 class LayerTreeHostImpl;
33 class LayerTreeImpl;
34 class LayerTreeSettings;
35 class MemoryHistory;
36 class OutputSurface;
37 class PaintTimeCounter;
38 class Proxy;
39 class ResourceProvider;
40 class ScrollbarLayerImpl;
41 class TileManager;
42 struct RendererCapabilities;
44 class CC_EXPORT LayerTreeImpl {
45 public:
46 static scoped_ptr<LayerTreeImpl> create(
47 LayerTreeHostImpl* layer_tree_host_impl) {
48 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
50 virtual ~LayerTreeImpl();
52 // Methods called by the layer tree that pass-through or access LTHI.
53 // ---------------------------------------------------------------------------
54 const LayerTreeSettings& settings() const;
55 const RendererCapabilities& GetRendererCapabilities() const;
56 OutputSurface* output_surface() const;
57 ResourceProvider* resource_provider() const;
58 TileManager* tile_manager() const;
59 FrameRateCounter* frame_rate_counter() const;
60 PaintTimeCounter* paint_time_counter() const;
61 MemoryHistory* memory_history() const;
62 bool IsActiveTree() const;
63 bool IsPendingTree() const;
64 bool IsRecycleTree() const;
65 LayerImpl* FindActiveTreeLayerById(int id);
66 LayerImpl* FindPendingTreeLayerById(int id);
67 int MaxTextureSize() const;
68 bool PinchGestureActive() const;
69 base::TimeTicks CurrentFrameTime() const;
70 void SetNeedsCommit();
72 // Tree specific methods exposed to layer-impl tree.
73 // ---------------------------------------------------------------------------
74 void SetNeedsRedraw();
76 // TODO(nduca): These are implemented in cc files temporarily, but will become
77 // trivial accessors in a followup patch.
78 const LayerTreeDebugState& debug_state() const;
79 float device_scale_factor() const;
80 gfx::Size device_viewport_size() const;
81 std::string layer_tree_as_text() const;
82 DebugRectHistory* debug_rect_history() const;
83 scoped_ptr<base::Value> AsValue() const;
85 // Other public methods
86 // ---------------------------------------------------------------------------
87 LayerImpl* root_layer() const { return root_layer_.get(); }
88 void SetRootLayer(scoped_ptr<LayerImpl>);
89 scoped_ptr<LayerImpl> DetachLayerTree();
91 void PushPropertiesTo(LayerTreeImpl* tree_impl);
93 int source_frame_number() const { return source_frame_number_; }
94 void set_source_frame_number(int frame_number) {
95 source_frame_number_ = frame_number;
98 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
99 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
100 hud_layer_ = layer_impl;
103 LayerImpl* RootScrollLayer() const;
104 LayerImpl* RootClipLayer() const;
105 LayerImpl* CurrentlyScrollingLayer() const;
106 void SetCurrentlyScrollingLayer(LayerImpl* layer);
107 void ClearCurrentlyScrollingLayer();
109 void FindRootScrollLayer();
110 void UpdateMaxScrollOffset();
112 SkColor background_color() const { return background_color_; }
113 void set_background_color(SkColor color) { background_color_ = color; }
115 bool has_transparent_background() const {
116 return has_transparent_background_;
118 void set_has_transparent_background(bool transparent) {
119 has_transparent_background_ = transparent;
122 enum UpdateDrawPropertiesReason {
123 UPDATE_PENDING_TREE,
124 UPDATE_ACTIVE_TREE,
125 UPDATE_ACTIVE_TREE_FOR_DRAW
128 gfx::Transform ImplTransform() const;
130 void SetPageScaleFactorAndLimits(float page_scale_factor,
131 float min_page_scale_factor, float max_page_scale_factor);
132 void SetPageScaleDelta(float delta);
133 float total_page_scale_factor() const {
134 return page_scale_factor_ * page_scale_delta_;
136 float page_scale_factor() const { return page_scale_factor_; }
137 float min_page_scale_factor() const { return min_page_scale_factor_; }
138 float max_page_scale_factor() const { return max_page_scale_factor_; }
139 float page_scale_delta() const { return page_scale_delta_; }
140 void set_sent_page_scale_delta(float delta) {
141 sent_page_scale_delta_ = delta;
143 float sent_page_scale_delta() const { return sent_page_scale_delta_; }
145 // Updates draw properties and render surface layer list
146 void UpdateDrawProperties(UpdateDrawPropertiesReason reason);
147 void set_needs_update_draw_properties() {
148 needs_update_draw_properties_ = true;
150 bool needs_update_draw_properties() const {
151 return needs_update_draw_properties_;
154 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
155 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
157 void ClearRenderSurfaces();
159 bool AreVisibleResourcesReady() const;
161 const LayerImplList& RenderSurfaceLayerList() const;
163 // These return the size of the root scrollable area and the size of
164 // the user-visible scrolling viewport, in CSS layout coordinates.
165 gfx::Size ScrollableSize() const;
166 gfx::SizeF ScrollableViewportSize() const;
168 LayerImpl* LayerById(int id);
170 // These should be called by LayerImpl's ctor/dtor.
171 void RegisterLayer(LayerImpl* layer);
172 void UnregisterLayer(LayerImpl* layer);
174 AnimationRegistrar* animationRegistrar() const;
176 void PushPersistedState(LayerTreeImpl* pending_tree);
178 void DidBecomeActive();
180 bool ContentsTexturesPurged() const;
181 void SetContentsTexturesPurged();
182 void ResetContentsTexturesPurged();
184 // Set on the active tree when the viewport size recently changed
185 // and the active tree's size is now out of date.
186 bool ViewportSizeInvalid() const;
187 void SetViewportSizeInvalid();
188 void ResetViewportSizeInvalid();
190 // Useful for debug assertions, probably shouldn't be used for anything else.
191 Proxy* proxy() const;
193 void SetPinchZoomHorizontalLayerId(int layer_id);
194 void SetPinchZoomVerticalLayerId(int layer_id);
196 void DidBeginScroll();
197 void DidUpdateScroll();
198 void DidEndScroll();
200 protected:
201 explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
203 void UpdateSolidColorScrollbars();
205 // Hide existence of pinch-zoom scrollbars.
206 void UpdatePinchZoomScrollbars();
207 void FadeInPinchZoomScrollbars();
208 void FadeOutPinchZoomScrollbars();
209 ScrollbarLayerImpl* PinchZoomScrollbarHorizontal();
210 ScrollbarLayerImpl* PinchZoomScrollbarVertical();
211 bool HasPinchZoomScrollbars() const;
213 void UpdateRootScrollLayerSizeDelta();
215 LayerTreeHostImpl* layer_tree_host_impl_;
216 int source_frame_number_;
217 scoped_ptr<LayerImpl> root_layer_;
218 HeadsUpDisplayLayerImpl* hud_layer_;
219 LayerImpl* root_scroll_layer_;
220 LayerImpl* currently_scrolling_layer_;
221 SkColor background_color_;
222 bool has_transparent_background_;
224 int pinch_zoom_scrollbar_horizontal_layer_id_;
225 int pinch_zoom_scrollbar_vertical_layer_id_;
227 float page_scale_factor_;
228 float page_scale_delta_;
229 float sent_page_scale_delta_;
230 float min_page_scale_factor_;
231 float max_page_scale_factor_;
233 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
234 LayerIdMap layer_id_map_;
236 // Persisted state for non-impl-side-painting.
237 int scrolling_layer_id_from_previous_tree_;
239 // List of visible layers for the most recently prepared frame. Used for
240 // rendering and input event hit testing.
241 LayerImplList render_surface_layer_list_;
243 bool contents_textures_purged_;
244 bool viewport_size_invalid_;
245 bool needs_update_draw_properties_;
247 // In impl-side painting mode, this is true when the tree may contain
248 // structural differences relative to the active tree.
249 bool needs_full_tree_sync_;
251 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
254 } // namespace cc
256 #endif // CC_TREES_LAYER_TREE_IMPL_H_