summaryrefslogtreecommitdiffstats
path: root/cc/layer_tree_impl.h
blob: 4b16f46d0b7069730ff7dce04c03e689763bd4c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_LAYER_TREE_IMPL_H_
#define CC_LAYER_TREE_IMPL_H_

#include "base/hash_tables.h"
#include "cc/layer_impl.h"

#if defined(COMPILER_GCC)
namespace BASE_HASH_NAMESPACE {
template<>
struct hash<cc::LayerImpl*> {
  size_t operator()(cc::LayerImpl* ptr) const {
    return hash<size_t>()(reinterpret_cast<size_t>(ptr));
  }
};
} // namespace BASE_HASH_NAMESPACE
#endif // COMPILER

namespace cc {

class DebugRectHistory;
class FrameRateCounter;
class HeadsUpDisplayLayerImpl;
class LayerTreeDebugState;
class LayerTreeHostImpl;
class LayerTreeImpl;
class LayerTreeSettings;
class OutputSurface;
class PinchZoomViewport;
class ResourceProvider;
class TileManager;

class CC_EXPORT LayerTreeImpl {
 public:
  typedef std::vector<LayerImpl*> LayerList;

  static scoped_ptr<LayerTreeImpl> create(LayerTreeHostImpl* layer_tree_host_impl)
  {
    return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
  }
  virtual ~LayerTreeImpl();

  // Methods called by the layer tree that pass-through or access LTHI.
  // ---------------------------------------------------------------------------
  const LayerTreeSettings& settings() const;
  OutputSurface* output_surface() const;
  ResourceProvider* resource_provider() const;
  TileManager* tile_manager() const;
  FrameRateCounter* frame_rate_counter() const;
  bool IsActiveTree() const;
  bool IsPendingTree() const;
  LayerImpl* FindActiveTreeLayerById(int id);
  LayerImpl* FindPendingTreeLayerById(int id);

  // Tree specific methods exposed to layer-impl tree.
  // ---------------------------------------------------------------------------
  void SetNeedsRedraw();
  void SetNeedsUpdateDrawProperties();

  // TODO(nduca): These are implemented in cc files temporarily, but will become
  // trivial accessors in a followup patch.
  const LayerTreeDebugState& debug_state() const;
  float device_scale_factor() const;
  const gfx::Size& device_viewport_size() const;
  const gfx::Size& layout_viewport_size() const;
  std::string layer_tree_as_text() const;
  DebugRectHistory* debug_rect_history() const;
  const PinchZoomViewport& pinch_zoom_viewport() const;

  // Other public methods
  // ---------------------------------------------------------------------------
  LayerImpl* RootLayer() const { return root_layer_.get(); }
  void SetRootLayer(scoped_ptr<LayerImpl>);
  scoped_ptr<LayerImpl> DetachLayerTree();

  int source_frame_number() const { return source_frame_number_; }
  void set_source_frame_number(int frame_number) { source_frame_number_ = frame_number; }

  HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
  void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) { hud_layer_ = layer_impl; }

  LayerImpl* root_scroll_layer() { return root_scroll_layer_; }
  const LayerImpl* root_scroll_layer() const { return root_scroll_layer_; }
  void set_root_scroll_layer(LayerImpl* layer_impl) { root_scroll_layer_ = layer_impl; }

  LayerImpl* currently_scrolling_layer() { return currently_scrolling_layer_; }
  void set_currently_scrolling_layer(LayerImpl* layer_impl) { currently_scrolling_layer_ = layer_impl; }

  void ClearCurrentlyScrollingLayer();

  void UpdateMaxScrollOffset();

  // Updates draw properties and render surface layer list
  void UpdateDrawProperties();

  void ClearRenderSurfaces();

  const LayerList& RenderSurfaceLayerList() const;

  gfx::Size ContentSize() const;

  LayerImpl* LayerById(int id);

  // These should be called by LayerImpl's ctor/dtor.
  void RegisterLayer(LayerImpl* layer);
  void UnregisterLayer(LayerImpl* layer);

  AnimationRegistrar* animationRegistrar() const;

protected:
  LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);

  LayerTreeHostImpl* layer_tree_host_impl_;
  int source_frame_number_;
  scoped_ptr<LayerImpl> root_layer_;
  HeadsUpDisplayLayerImpl* hud_layer_;
  LayerImpl* root_scroll_layer_;
  LayerImpl* currently_scrolling_layer_;

  typedef base::hash_map<int, LayerImpl*> LayerIdMap;
  LayerIdMap layer_id_map_;

  // Persisted state
  int scrolling_layer_id_from_previous_tree_;

  // List of visible layers for the most recently prepared frame. Used for
  // rendering and input event hit testing.
  LayerList render_surface_layer_list_;

  DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
};

}

#endif  // CC_LAYER_TREE_IMPL_H_