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