blob: 01caba4d5f1ad02c81a68b3441507e65ddf7ed9c [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;
31class OutputSurface;
[email protected]71691c22013-01-18 03:14:2232class PaintTimeCounter;
[email protected]caa567d2012-12-20 07:56:1633class PinchZoomViewport;
[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]f117a4c2012-12-16 04:53:1056 bool IsActiveTree() const;
57 bool IsPendingTree() const;
58 LayerImpl* FindActiveTreeLayerById(int id);
59 LayerImpl* FindPendingTreeLayerById(int id);
[email protected]f6776532012-12-21 20:24:3360 int MaxTextureSize() const;
[email protected]166db5c82013-01-09 23:54:3161 bool PinchGestureActive() const;
[email protected]ff762fb2012-12-12 19:18:3762
63 // Tree specific methods exposed to layer-impl tree.
64 // ---------------------------------------------------------------------------
65 void SetNeedsRedraw();
66 void SetNeedsUpdateDrawProperties();
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]caa567d2012-12-20 07:56:1676 const PinchZoomViewport& pinch_zoom_viewport() const;
[email protected]8bef40572012-12-11 21:38:0877
78 // Other public methods
79 // ---------------------------------------------------------------------------
[email protected]3b31c6ac2012-12-06 21:27:2980 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]a30290142013-01-05 01:27:0085 void set_source_frame_number(int frame_number) {
86 source_frame_number_ = frame_number;
87 }
[email protected]3b31c6ac2012-12-06 21:27:2988
89 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
[email protected]a30290142013-01-05 01:27:0090 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
91 hud_layer_ = layer_impl;
92 }
[email protected]3b31c6ac2012-12-06 21:27:2993
[email protected]69b50ec2013-01-19 04:58:0194 LayerImpl* RootScrollLayer();
95 LayerImpl* CurrentlyScrollingLayer();
96 void set_currently_scrolling_layer(LayerImpl* layer) {
97 currently_scrolling_layer_ = layer;
[email protected]a30290142013-01-05 01:27:0098 }
[email protected]3b31c6ac2012-12-06 21:27:2999
[email protected]3b31c6ac2012-12-06 21:27:29100 void ClearCurrentlyScrollingLayer();
101
[email protected]69b50ec2013-01-19 04:58:01102 void FindRootScrollLayer();
[email protected]caa567d2012-12-20 07:56:16103 void UpdateMaxScrollOffset();
104
[email protected]a30290142013-01-05 01:27:00105 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]76ffd9e2012-12-20 19:12:47115 // Updates draw properties and render surface layer list
116 void UpdateDrawProperties();
117
118 void ClearRenderSurfaces();
119
[email protected]b0a917c8d2013-01-12 17:42:25120 bool AreVisibleResourcesReady() const;
121
[email protected]76ffd9e2012-12-20 19:12:47122 const LayerList& RenderSurfaceLayerList() const;
123
[email protected]caa567d2012-12-20 07:56:16124 gfx::Size ContentSize() const;
125
[email protected]361bc00d2012-12-14 07:03:24126 LayerImpl* LayerById(int id);
127
128 // These should be called by LayerImpl's ctor/dtor.
129 void RegisterLayer(LayerImpl* layer);
130 void UnregisterLayer(LayerImpl* layer);
131
[email protected]de4afb5e2012-12-20 00:11:34132 AnimationRegistrar* animationRegistrar() const;
133
[email protected]1e0f8d62013-01-09 07:41:35134 void PushPersistedState(LayerTreeImpl* pendingTree);
135
[email protected]37386f052013-01-13 00:42:22136 void DidBecomeActive();
137
[email protected]6f90b9e2013-01-17 23:42:00138 bool ContentsTexturesPurged() const;
139 void SetContentsTexturesPurged();
140 void ResetContentsTexturesPurged();
141
[email protected]3b31c6ac2012-12-06 21:27:29142protected:
[email protected]8bef40572012-12-11 21:38:08143 LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
[email protected]3b31c6ac2012-12-06 21:27:29144
[email protected]8bef40572012-12-11 21:38:08145 LayerTreeHostImpl* layer_tree_host_impl_;
[email protected]3b31c6ac2012-12-06 21:27:29146 int source_frame_number_;
147 scoped_ptr<LayerImpl> root_layer_;
148 HeadsUpDisplayLayerImpl* hud_layer_;
149 LayerImpl* root_scroll_layer_;
150 LayerImpl* currently_scrolling_layer_;
[email protected]a30290142013-01-05 01:27:00151 SkColor background_color_;
152 bool has_transparent_background_;
[email protected]3b31c6ac2012-12-06 21:27:29153
[email protected]361bc00d2012-12-14 07:03:24154 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
155 LayerIdMap layer_id_map_;
156
[email protected]1e0f8d62013-01-09 07:41:35157 // Persisted state for non-impl-side-painting.
[email protected]3b31c6ac2012-12-06 21:27:29158 int scrolling_layer_id_from_previous_tree_;
159
[email protected]76ffd9e2012-12-20 19:12:47160 // List of visible layers for the most recently prepared frame. Used for
161 // rendering and input event hit testing.
162 LayerList render_surface_layer_list_;
163
[email protected]6f90b9e2013-01-17 23:42:00164 bool contents_textures_purged_;
165
[email protected]3b31c6ac2012-12-06 21:27:29166 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
167};
168
169}
170
171#endif // CC_LAYER_TREE_IMPL_H_