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_LAYER_TREE_IMPL_H_
6 #define CC_LAYER_TREE_IMPL_H_
8 #include "base/hash_tables.h"
9 #include "cc/layer_impl.h"
11 #if defined(COMPILER_GCC)
12 namespace BASE_HASH_NAMESPACE
{
14 struct hash
<cc::LayerImpl
*> {
15 size_t operator()(cc::LayerImpl
* ptr
) const {
16 return hash
<size_t>()(reinterpret_cast<size_t>(ptr
));
19 } // namespace BASE_HASH_NAMESPACE
24 class DebugRectHistory
;
25 class FrameRateCounter
;
26 class HeadsUpDisplayLayerImpl
;
27 class LayerTreeDebugState
;
28 class LayerTreeHostImpl
;
30 class LayerTreeSettings
;
32 class PinchZoomViewport
;
33 class ResourceProvider
;
36 class CC_EXPORT LayerTreeImpl
{
38 typedef std::vector
<LayerImpl
*> LayerList
;
40 static scoped_ptr
<LayerTreeImpl
> create(LayerTreeHostImpl
* layer_tree_host_impl
)
42 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl
));
44 virtual ~LayerTreeImpl();
46 // Methods called by the layer tree that pass-through or access LTHI.
47 // ---------------------------------------------------------------------------
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;
53 bool IsActiveTree() const;
54 bool IsPendingTree() const;
55 LayerImpl
* FindActiveTreeLayerById(int id
);
56 LayerImpl
* FindPendingTreeLayerById(int id
);
57 int MaxTextureSize() const;
59 // Tree specific methods exposed to layer-impl tree.
60 // ---------------------------------------------------------------------------
61 void SetNeedsRedraw();
62 void SetNeedsUpdateDrawProperties();
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;
72 const PinchZoomViewport
& pinch_zoom_viewport() const;
74 // Other public methods
75 // ---------------------------------------------------------------------------
76 LayerImpl
* RootLayer() const { return root_layer_
.get(); }
77 void SetRootLayer(scoped_ptr
<LayerImpl
>);
78 scoped_ptr
<LayerImpl
> DetachLayerTree();
80 int source_frame_number() const { return source_frame_number_
; }
81 void set_source_frame_number(int frame_number
) {
82 source_frame_number_
= frame_number
;
85 HeadsUpDisplayLayerImpl
* hud_layer() { return hud_layer_
; }
86 void set_hud_layer(HeadsUpDisplayLayerImpl
* layer_impl
) {
87 hud_layer_
= layer_impl
;
90 LayerImpl
* root_scroll_layer() { return root_scroll_layer_
; }
91 const LayerImpl
* root_scroll_layer() const { return root_scroll_layer_
; }
92 void set_root_scroll_layer(LayerImpl
* layer_impl
) {
93 root_scroll_layer_
= layer_impl
;
96 LayerImpl
* currently_scrolling_layer() { return currently_scrolling_layer_
; }
97 void set_currently_scrolling_layer(LayerImpl
* layer_impl
) {
98 currently_scrolling_layer_
= layer_impl
;
101 void ClearCurrentlyScrollingLayer();
103 void UpdateMaxScrollOffset();
105 SkColor
background_color() const { return background_color_
; }
106 void set_background_color(SkColor color
) { background_color_
= color
; }
108 bool has_transparent_background() const {
109 return has_transparent_background_
;
111 void set_has_transparent_background(bool transparent
) {
112 has_transparent_background_
= transparent
;
115 // Updates draw properties and render surface layer list
116 void UpdateDrawProperties();
118 void ClearRenderSurfaces();
120 const LayerList
& RenderSurfaceLayerList() const;
122 gfx::Size
ContentSize() const;
124 LayerImpl
* LayerById(int id
);
126 // These should be called by LayerImpl's ctor/dtor.
127 void RegisterLayer(LayerImpl
* layer
);
128 void UnregisterLayer(LayerImpl
* layer
);
130 AnimationRegistrar
* animationRegistrar() const;
133 LayerTreeImpl(LayerTreeHostImpl
* layer_tree_host_impl
);
135 LayerTreeHostImpl
* layer_tree_host_impl_
;
136 int source_frame_number_
;
137 scoped_ptr
<LayerImpl
> root_layer_
;
138 HeadsUpDisplayLayerImpl
* hud_layer_
;
139 LayerImpl
* root_scroll_layer_
;
140 LayerImpl
* currently_scrolling_layer_
;
141 SkColor background_color_
;
142 bool has_transparent_background_
;
144 typedef base::hash_map
<int, LayerImpl
*> LayerIdMap
;
145 LayerIdMap layer_id_map_
;
148 int scrolling_layer_id_from_previous_tree_
;
150 // List of visible layers for the most recently prepared frame. Used for
151 // rendering and input event hit testing.
152 LayerList render_surface_layer_list_
;
154 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl
);
159 #endif // CC_LAYER_TREE_IMPL_H_