Upstream version 5.34.104.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   base::Time CurrentFrameTime() const;
84   base::TimeTicks CurrentPhysicalTimeTicks() const;
85   void SetNeedsCommit();
86   gfx::Size DrawViewportSize() const;
87   void StartScrollbarAnimation();
88   void DidAnimateScrollOffset();
89
90   // Tree specific methods exposed to layer-impl tree.
91   // ---------------------------------------------------------------------------
92   void SetNeedsRedraw();
93
94   // TODO(nduca): These are implemented in cc files temporarily, but will become
95   // trivial accessors in a followup patch.
96   const LayerTreeDebugState& debug_state() const;
97   float device_scale_factor() const;
98   DebugRectHistory* debug_rect_history() const;
99   scoped_ptr<base::Value> AsValue() const;
100
101   // Other public methods
102   // ---------------------------------------------------------------------------
103   LayerImpl* root_layer() const { return root_layer_.get(); }
104   void SetRootLayer(scoped_ptr<LayerImpl>);
105   scoped_ptr<LayerImpl> DetachLayerTree();
106
107   void PushPropertiesTo(LayerTreeImpl* tree_impl);
108
109   int source_frame_number() const { return source_frame_number_; }
110   void set_source_frame_number(int frame_number) {
111     source_frame_number_ = frame_number;
112   }
113
114   HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
115   void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
116     hud_layer_ = layer_impl;
117   }
118
119   LayerImpl* InnerViewportScrollLayer() const;
120   // This function may return NULL, it is the caller's responsibility to check.
121   LayerImpl* OuterViewportScrollLayer() const;
122   gfx::Vector2dF TotalScrollOffset() const;
123   gfx::Vector2dF TotalMaxScrollOffset() const;
124   gfx::Vector2dF TotalScrollDelta() const;
125
126   LayerImpl* InnerViewportContainerLayer() const;
127   LayerImpl* CurrentlyScrollingLayer() const;
128   void SetCurrentlyScrollingLayer(LayerImpl* layer);
129   void ClearCurrentlyScrollingLayer();
130   float VerticalAdjust(const LayerImpl* layer) const;
131
132   void SetViewportLayersFromIds(int page_scale_layer_id,
133                                 int inner_viewport_scroll_layer_id,
134                                 int outer_viewport_scroll_layer_id);
135   void ClearViewportLayers();
136   LayerImpl* page_scale_layer() { return page_scale_layer_; }
137   void ApplySentScrollAndScaleDeltasFromAbortedCommit();
138   void ApplyScrollDeltasSinceBeginMainFrame();
139
140   SkColor background_color() const { return background_color_; }
141   void set_background_color(SkColor color) { background_color_ = color; }
142
143   bool has_transparent_background() const {
144     return has_transparent_background_;
145   }
146   void set_has_transparent_background(bool transparent) {
147     has_transparent_background_ = transparent;
148   }
149
150   void SetPageScaleFactorAndLimits(float page_scale_factor,
151       float min_page_scale_factor, float max_page_scale_factor);
152   void SetPageScaleDelta(float delta);
153   float total_page_scale_factor() const {
154     return page_scale_factor_ * page_scale_delta_;
155   }
156   float page_scale_factor() const { return page_scale_factor_; }
157   float min_page_scale_factor() const { return min_page_scale_factor_; }
158   float max_page_scale_factor() const { return max_page_scale_factor_; }
159   float page_scale_delta() const  { return page_scale_delta_; }
160   void set_sent_page_scale_delta(float delta) {
161     sent_page_scale_delta_ = delta;
162   }
163   float sent_page_scale_delta() const { return sent_page_scale_delta_; }
164
165   // Updates draw properties and render surface layer list, as well as tile
166   // priorities.
167   void UpdateDrawProperties();
168
169   void set_needs_update_draw_properties() {
170     needs_update_draw_properties_ = true;
171   }
172   bool needs_update_draw_properties() const {
173     return needs_update_draw_properties_;
174   }
175
176   void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
177   bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
178
179   void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
180
181   void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
182
183   const LayerImplList& RenderSurfaceLayerList() const;
184
185   // These return the size of the root scrollable area and the size of
186   // the user-visible scrolling viewport, in CSS layout coordinates.
187   gfx::Size ScrollableSize() const;
188   gfx::SizeF ScrollableViewportSize() const;
189
190   gfx::Rect RootScrollLayerDeviceViewportBounds() const;
191
192   LayerImpl* LayerById(int id);
193
194   // These should be called by LayerImpl's ctor/dtor.
195   void RegisterLayer(LayerImpl* layer);
196   void UnregisterLayer(LayerImpl* layer);
197
198   AnimationRegistrar* animationRegistrar() const;
199
200   void PushPersistedState(LayerTreeImpl* pending_tree);
201
202   void DidBecomeActive();
203
204   bool ContentsTexturesPurged() const;
205   void SetContentsTexturesPurged();
206   void ResetContentsTexturesPurged();
207
208   void SetRequiresHighResToDraw();
209   void ResetRequiresHighResToDraw();
210   bool RequiresHighResToDraw() const;
211
212   // Set on the active tree when the viewport size recently changed
213   // and the active tree's size is now out of date.
214   bool ViewportSizeInvalid() const;
215   void SetViewportSizeInvalid();
216   void ResetViewportSizeInvalid();
217
218   // Useful for debug assertions, probably shouldn't be used for anything else.
219   Proxy* proxy() const;
220
221   void SetRootLayerScrollOffsetDelegate(
222       LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
223   void UpdateScrollOffsetDelegate();
224   gfx::Vector2dF GetDelegatedScrollOffset(LayerImpl* layer);
225
226   // Call this function when you expect there to be a swap buffer.
227   // See swap_promise.h for how to use SwapPromise.
228   void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
229
230   // Take the |new_swap_promise| and append it to |swap_promise_list_|.
231   void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
232   void FinishSwapPromises(CompositorFrameMetadata* metadata);
233   void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
234
235   void DidModifyTilePriorities();
236
237   ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
238   void ProcessUIResourceRequestQueue();
239
240   bool IsUIResourceOpaque(UIResourceId uid) const;
241
242   void AddLayerWithCopyOutputRequest(LayerImpl* layer);
243   void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
244   const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
245
246  protected:
247   explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
248
249   LayerTreeHostImpl* layer_tree_host_impl_;
250   int source_frame_number_;
251   scoped_ptr<LayerImpl> root_layer_;
252   HeadsUpDisplayLayerImpl* hud_layer_;
253   LayerImpl* currently_scrolling_layer_;
254   LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
255   scoped_ptr<LayerScrollOffsetDelegateProxy>
256       inner_viewport_scroll_delegate_proxy_;
257   scoped_ptr<LayerScrollOffsetDelegateProxy>
258       outer_viewport_scroll_delegate_proxy_;
259   SkColor background_color_;
260   bool has_transparent_background_;
261
262   LayerImpl* page_scale_layer_;
263   LayerImpl* inner_viewport_scroll_layer_;
264   LayerImpl* outer_viewport_scroll_layer_;
265
266   float page_scale_factor_;
267   float page_scale_delta_;
268   float sent_page_scale_delta_;
269   float min_page_scale_factor_;
270   float max_page_scale_factor_;
271
272   typedef base::hash_map<int, LayerImpl*> LayerIdMap;
273   LayerIdMap layer_id_map_;
274
275   std::vector<LayerImpl*> layers_with_copy_output_request_;
276
277   // Persisted state for non-impl-side-painting.
278   int scrolling_layer_id_from_previous_tree_;
279
280   // List of visible or hit-testable layers for the most recently prepared
281   // frame. Used for rendering and input event hit testing.
282   LayerImplList render_surface_layer_list_;
283
284   bool contents_textures_purged_;
285   bool requires_high_res_to_draw_;
286   bool viewport_size_invalid_;
287   bool needs_update_draw_properties_;
288
289   // In impl-side painting mode, this is true when the tree may contain
290   // structural differences relative to the active tree.
291   bool needs_full_tree_sync_;
292
293   bool next_activation_forces_redraw_;
294
295   ScopedPtrVector<SwapPromise> swap_promise_list_;
296
297   UIResourceRequestQueue ui_resource_request_queue_;
298
299  private:
300   DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
301 };
302
303 }  // namespace cc
304
305 #endif  // CC_TREES_LAYER_TREE_IMPL_H_