Getting rid of GetDefaultProfile(), clean up of ProfileManager (which was in a seriou...
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.h
blob2f27460fe041950166daa9bb6af90c4f149653ac
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 <list>
9 #include <string>
10 #include <vector>
12 #include "base/containers/hash_tables.h"
13 #include "base/values.h"
14 #include "cc/base/scoped_ptr_vector.h"
15 #include "cc/base/swap_promise.h"
16 #include "cc/layers/layer_impl.h"
17 #include "cc/resources/ui_resource_client.h"
19 #if defined(COMPILER_GCC)
20 namespace BASE_HASH_NAMESPACE {
21 template<>
22 struct hash<cc::LayerImpl*> {
23 size_t operator()(cc::LayerImpl* ptr) const {
24 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
27 } // namespace BASE_HASH_NAMESPACE
28 #endif // COMPILER
30 namespace cc {
32 class ContextProvider;
33 class DebugRectHistory;
34 class FrameRateCounter;
35 class HeadsUpDisplayLayerImpl;
36 class LayerTreeDebugState;
37 class LayerTreeHostImpl;
38 class LayerTreeImpl;
39 class LayerTreeSettings;
40 class MemoryHistory;
41 class OutputSurface;
42 class PaintTimeCounter;
43 class Proxy;
44 class ResourceProvider;
45 class TileManager;
46 class UIResourceRequest;
47 struct RendererCapabilities;
49 typedef std::list<UIResourceRequest> UIResourceRequestQueue;
51 class CC_EXPORT LayerTreeImpl {
52 public:
53 static scoped_ptr<LayerTreeImpl> create(
54 LayerTreeHostImpl* layer_tree_host_impl) {
55 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
57 virtual ~LayerTreeImpl();
59 // Methods called by the layer tree that pass-through or access LTHI.
60 // ---------------------------------------------------------------------------
61 const LayerTreeSettings& settings() const;
62 const RendererCapabilities& GetRendererCapabilities() const;
63 ContextProvider* context_provider() const;
64 OutputSurface* output_surface() const;
65 ResourceProvider* resource_provider() const;
66 TileManager* tile_manager() const;
67 FrameRateCounter* frame_rate_counter() const;
68 PaintTimeCounter* paint_time_counter() const;
69 MemoryHistory* memory_history() const;
70 bool device_viewport_valid_for_tile_management() const;
71 bool IsActiveTree() const;
72 bool IsPendingTree() const;
73 bool IsRecycleTree() const;
74 LayerImpl* FindActiveTreeLayerById(int id);
75 LayerImpl* FindPendingTreeLayerById(int id);
76 int MaxTextureSize() const;
77 bool PinchGestureActive() const;
78 base::TimeTicks CurrentFrameTimeTicks() const;
79 base::Time CurrentFrameTime() const;
80 base::TimeTicks CurrentPhysicalTimeTicks() const;
81 void SetNeedsCommit();
82 gfx::Size DrawViewportSize() const;
83 void StartScrollbarAnimation();
84 void DidAnimateScrollOffset();
86 // Tree specific methods exposed to layer-impl tree.
87 // ---------------------------------------------------------------------------
88 void SetNeedsRedraw();
90 // TODO(nduca): These are implemented in cc files temporarily, but will become
91 // trivial accessors in a followup patch.
92 const LayerTreeDebugState& debug_state() const;
93 float device_scale_factor() const;
94 DebugRectHistory* debug_rect_history() const;
95 scoped_ptr<base::Value> AsValue() const;
97 // Other public methods
98 // ---------------------------------------------------------------------------
99 LayerImpl* root_layer() const { return root_layer_.get(); }
100 void SetRootLayer(scoped_ptr<LayerImpl>);
101 scoped_ptr<LayerImpl> DetachLayerTree();
103 void PushPropertiesTo(LayerTreeImpl* tree_impl);
105 int source_frame_number() const { return source_frame_number_; }
106 void set_source_frame_number(int frame_number) {
107 source_frame_number_ = frame_number;
110 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
111 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
112 hud_layer_ = layer_impl;
115 LayerImpl* RootScrollLayer() const;
116 LayerImpl* RootContainerLayer() const;
117 LayerImpl* CurrentlyScrollingLayer() const;
118 void SetCurrentlyScrollingLayer(LayerImpl* layer);
119 void ClearCurrentlyScrollingLayer();
121 void FindRootScrollLayer();
122 void UpdateMaxScrollOffset();
123 void SetViewportLayersFromIds(int page_scale_layer_id,
124 int inner_viewport_scroll_layer_id,
125 int outer_viewport_scroll_layer_id);
126 void ClearViewportLayers();
127 void ApplySentScrollAndScaleDeltasFromAbortedCommit();
128 void ApplyScrollDeltasSinceBeginMainFrame();
130 SkColor background_color() const { return background_color_; }
131 void set_background_color(SkColor color) { background_color_ = color; }
133 bool has_transparent_background() const {
134 return has_transparent_background_;
136 void set_has_transparent_background(bool transparent) {
137 has_transparent_background_ = transparent;
140 void SetPageScaleFactorAndLimits(float page_scale_factor,
141 float min_page_scale_factor, float max_page_scale_factor);
142 void SetPageScaleDelta(float delta);
143 float total_page_scale_factor() const {
144 return page_scale_factor_ * page_scale_delta_;
146 float page_scale_factor() const { return page_scale_factor_; }
147 float min_page_scale_factor() const { return min_page_scale_factor_; }
148 float max_page_scale_factor() const { return max_page_scale_factor_; }
149 float page_scale_delta() const { return page_scale_delta_; }
150 void set_sent_page_scale_delta(float delta) {
151 sent_page_scale_delta_ = delta;
153 float sent_page_scale_delta() const { return sent_page_scale_delta_; }
155 // Updates draw properties and render surface layer list, as well as tile
156 // priorities.
157 void UpdateDrawProperties();
159 void set_needs_update_draw_properties() {
160 needs_update_draw_properties_ = true;
162 bool needs_update_draw_properties() const {
163 return needs_update_draw_properties_;
166 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
167 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
169 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
171 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
173 const LayerImplList& RenderSurfaceLayerList() const;
175 // These return the size of the root scrollable area and the size of
176 // the user-visible scrolling viewport, in CSS layout coordinates.
177 gfx::Size ScrollableSize() const;
178 gfx::SizeF ScrollableViewportSize() const;
180 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
182 LayerImpl* LayerById(int id);
184 // These should be called by LayerImpl's ctor/dtor.
185 void RegisterLayer(LayerImpl* layer);
186 void UnregisterLayer(LayerImpl* layer);
188 AnimationRegistrar* animationRegistrar() const;
190 void PushPersistedState(LayerTreeImpl* pending_tree);
192 void DidBecomeActive();
194 bool ContentsTexturesPurged() const;
195 void SetContentsTexturesPurged();
196 void ResetContentsTexturesPurged();
198 // Set on the active tree when the viewport size recently changed
199 // and the active tree's size is now out of date.
200 bool ViewportSizeInvalid() const;
201 void SetViewportSizeInvalid();
202 void ResetViewportSizeInvalid();
204 // Useful for debug assertions, probably shouldn't be used for anything else.
205 Proxy* proxy() const;
207 void SetRootLayerScrollOffsetDelegate(
208 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
210 // Call this function when you expect there to be a swap buffer.
211 // See swap_promise.h for how to use SwapPromise.
212 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
214 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
215 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
216 void FinishSwapPromises(CompositorFrameMetadata* metadata);
217 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
219 void DidModifyTilePriorities();
221 ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
222 void ProcessUIResourceRequestQueue();
224 bool IsUIResourceOpaque(UIResourceId uid) const;
226 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
227 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
228 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
230 protected:
231 explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
233 void UpdateSolidColorScrollbars();
235 void UpdateRootScrollLayerSizeDelta();
237 LayerTreeHostImpl* layer_tree_host_impl_;
238 int source_frame_number_;
239 scoped_ptr<LayerImpl> root_layer_;
240 HeadsUpDisplayLayerImpl* hud_layer_;
241 LayerImpl* root_scroll_layer_;
242 LayerImpl* currently_scrolling_layer_;
243 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
244 SkColor background_color_;
245 bool has_transparent_background_;
247 LayerImpl* page_scale_layer_;
248 LayerImpl* inner_viewport_scroll_layer_;
249 LayerImpl* outer_viewport_scroll_layer_;
251 float page_scale_factor_;
252 float page_scale_delta_;
253 float sent_page_scale_delta_;
254 float min_page_scale_factor_;
255 float max_page_scale_factor_;
257 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
258 LayerIdMap layer_id_map_;
260 std::vector<LayerImpl*> layers_with_copy_output_request_;
262 // Persisted state for non-impl-side-painting.
263 int scrolling_layer_id_from_previous_tree_;
265 // List of visible or hit-testable layers for the most recently prepared
266 // frame. Used for rendering and input event hit testing.
267 LayerImplList render_surface_layer_list_;
269 bool contents_textures_purged_;
270 bool viewport_size_invalid_;
271 bool needs_update_draw_properties_;
273 // In impl-side painting mode, this is true when the tree may contain
274 // structural differences relative to the active tree.
275 bool needs_full_tree_sync_;
277 bool next_activation_forces_redraw_;
279 ScopedPtrVector<SwapPromise> swap_promise_list_;
281 UIResourceRequestQueue ui_resource_request_queue_;
283 private:
284 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
287 } // namespace cc
289 #endif // CC_TREES_LAYER_TREE_IMPL_H_