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