Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / cc / trees / layer_tree_host_impl.h
1 // Copyright 2011 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_HOST_IMPL_H_
6 #define CC_TREES_LAYER_TREE_HOST_IMPL_H_
7
8 #include <list>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/containers/hash_tables.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/time/time.h"
17 #include "cc/animation/animation_events.h"
18 #include "cc/animation/animation_registrar.h"
19 #include "cc/base/cc_export.h"
20 #include "cc/debug/micro_benchmark_controller_impl.h"
21 #include "cc/input/input_handler.h"
22 #include "cc/input/layer_scroll_offset_delegate.h"
23 #include "cc/input/top_controls_manager_client.h"
24 #include "cc/layers/layer_lists.h"
25 #include "cc/layers/render_pass_sink.h"
26 #include "cc/output/begin_frame_args.h"
27 #include "cc/output/managed_memory_policy.h"
28 #include "cc/output/output_surface_client.h"
29 #include "cc/output/renderer.h"
30 #include "cc/quads/render_pass.h"
31 #include "cc/resources/resource_provider.h"
32 #include "cc/resources/tile_manager.h"
33 #include "cc/scheduler/draw_swap_readback_result.h"
34 #include "skia/ext/refptr.h"
35 #include "third_party/skia/include/core/SkColor.h"
36 #include "ui/gfx/rect.h"
37
38 namespace cc {
39
40 class CompletionEvent;
41 class CompositorFrameMetadata;
42 class DebugRectHistory;
43 class FrameRateCounter;
44 class LayerImpl;
45 class LayerTreeHostImplTimeSourceAdapter;
46 class LayerTreeImpl;
47 class PageScaleAnimation;
48 class PaintTimeCounter;
49 class MemoryHistory;
50 class RenderingStatsInstrumentation;
51 class RenderPassDrawQuad;
52 class ScrollbarLayerImplBase;
53 class TextureMailboxDeleter;
54 class TopControlsManager;
55 class UIResourceBitmap;
56 class UIResourceRequest;
57 struct RendererCapabilitiesImpl;
58
59 // LayerTreeHost->Proxy callback interface.
60 class LayerTreeHostImplClient {
61  public:
62   virtual void UpdateRendererCapabilitiesOnImplThread() = 0;
63   virtual void DidLoseOutputSurfaceOnImplThread() = 0;
64   virtual void DidSwapBuffersOnImplThread() = 0;
65   virtual void OnSwapBuffersCompleteOnImplThread() = 0;
66   virtual void BeginImplFrame(const BeginFrameArgs& args) = 0;
67   virtual void OnCanDrawStateChanged(bool can_draw) = 0;
68   virtual void NotifyReadyToActivate() = 0;
69   // Please call these 2 functions through
70   // LayerTreeHostImpl's SetNeedsRedraw() and SetNeedsRedrawRect().
71   virtual void SetNeedsRedrawOnImplThread() = 0;
72   virtual void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) = 0;
73   virtual void DidInitializeVisibleTileOnImplThread() = 0;
74   virtual void SetNeedsCommitOnImplThread() = 0;
75   virtual void SetNeedsManageTilesOnImplThread() = 0;
76   virtual void PostAnimationEventsToMainThreadOnImplThread(
77       scoped_ptr<AnimationEventsVector> events) = 0;
78   // Returns true if resources were deleted by this call.
79   virtual bool ReduceContentsTextureMemoryOnImplThread(
80       size_t limit_bytes,
81       int priority_cutoff) = 0;
82   virtual void SendManagedMemoryStats() = 0;
83   virtual bool IsInsideDraw() = 0;
84   virtual void RenewTreePriority() = 0;
85   virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) = 0;
86   virtual void DidActivatePendingTree() = 0;
87   virtual void DidManageTiles() = 0;
88
89  protected:
90   virtual ~LayerTreeHostImplClient() {}
91 };
92
93 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
94 // state.
95 class CC_EXPORT LayerTreeHostImpl
96     : public InputHandler,
97       public RendererClient,
98       public TileManagerClient,
99       public OutputSurfaceClient,
100       public TopControlsManagerClient,
101       public base::SupportsWeakPtr<LayerTreeHostImpl> {
102  public:
103   static scoped_ptr<LayerTreeHostImpl> Create(
104       const LayerTreeSettings& settings,
105       LayerTreeHostImplClient* client,
106       Proxy* proxy,
107       RenderingStatsInstrumentation* rendering_stats_instrumentation,
108       SharedBitmapManager* manager,
109       int id);
110   virtual ~LayerTreeHostImpl();
111
112   // InputHandler implementation
113   virtual void BindToClient(InputHandlerClient* client) OVERRIDE;
114   virtual InputHandler::ScrollStatus ScrollBegin(
115       const gfx::Point& viewport_point,
116       InputHandler::ScrollInputType type) OVERRIDE;
117   virtual bool ScrollBy(const gfx::Point& viewport_point,
118                         const gfx::Vector2dF& scroll_delta) OVERRIDE;
119   virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point,
120                                       ScrollDirection direction) OVERRIDE;
121   virtual void SetRootLayerScrollOffsetDelegate(
122       LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) OVERRIDE;
123   virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE;
124   virtual void ScrollEnd() OVERRIDE;
125   virtual InputHandler::ScrollStatus FlingScrollBegin() OVERRIDE;
126   virtual void NotifyCurrentFlingVelocity(
127       const gfx::Vector2dF& velocity) OVERRIDE;
128   virtual void MouseMoveAt(const gfx::Point& viewport_point) OVERRIDE;
129   virtual void PinchGestureBegin() OVERRIDE;
130   virtual void PinchGestureUpdate(float magnify_delta,
131                                   const gfx::Point& anchor) OVERRIDE;
132   virtual void PinchGestureEnd() OVERRIDE;
133   virtual void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
134                                        bool anchor_point,
135                                        float page_scale,
136                                        base::TimeDelta duration) OVERRIDE;
137   virtual void ScheduleAnimation() OVERRIDE;
138   virtual bool HaveTouchEventHandlersAt(const gfx::Point& viewport_port)
139       OVERRIDE;
140   virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
141       ui::LatencyInfo* latency) OVERRIDE;
142
143   // TopControlsManagerClient implementation.
144   virtual void DidChangeTopControlsPosition() OVERRIDE;
145   virtual bool HaveRootScrollLayer() const OVERRIDE;
146
147   void StartScrollbarAnimation();
148
149   struct CC_EXPORT FrameData : public RenderPassSink {
150     FrameData();
151     virtual ~FrameData();
152     scoped_ptr<base::Value> AsValue() const;
153
154     std::vector<gfx::Rect> occluding_screen_space_rects;
155     std::vector<gfx::Rect> non_occluding_screen_space_rects;
156     RenderPassList render_passes;
157     RenderPassIdHashMap render_passes_by_id;
158     const LayerImplList* render_surface_layer_list;
159     LayerImplList will_draw_layers;
160     bool contains_incomplete_tile;
161     bool has_no_damage;
162
163     // RenderPassSink implementation.
164     virtual void AppendRenderPass(scoped_ptr<RenderPass> render_pass) OVERRIDE;
165   };
166
167   virtual void BeginMainFrameAborted(bool did_handle);
168   virtual void BeginCommit();
169   virtual void CommitComplete();
170   virtual void Animate(base::TimeTicks monotonic_time);
171   virtual void UpdateAnimationState(bool start_ready_animations);
172   void MainThreadHasStoppedFlinging();
173   void UpdateBackgroundAnimateTicking(bool should_background_tick);
174   void DidAnimateScrollOffset();
175   void SetViewportDamage(const gfx::Rect& damage_rect);
176
177   virtual void ManageTiles();
178
179   // Returns false if problems occured preparing the frame, and we should try
180   // to avoid displaying the frame. If PrepareToDraw is called, DidDrawAllLayers
181   // must also be called, regardless of whether DrawLayers is called between the
182   // two.
183   virtual DrawSwapReadbackResult::DrawResult PrepareToDraw(
184       FrameData* frame,
185       const gfx::Rect& damage_rect);
186   virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
187   // Must be called if and only if PrepareToDraw was called.
188   void DidDrawAllLayers(const FrameData& frame);
189
190   const LayerTreeSettings& settings() const { return settings_; }
191
192   // Evict all textures by enforcing a memory policy with an allocation of 0.
193   void EvictTexturesForTesting();
194
195   // When blocking, this prevents client_->NotifyReadyToActivate() from being
196   // called. When disabled, it calls client_->NotifyReadyToActivate()
197   // immediately if any notifications had been blocked while blocking.
198   virtual void BlockNotifyReadyToActivateForTesting(bool block);
199
200   // This allows us to inject DidInitializeVisibleTile events for testing.
201   void DidInitializeVisibleTileForTesting();
202
203   bool device_viewport_valid_for_tile_management() const {
204     return device_viewport_valid_for_tile_management_;
205   }
206
207   // Viewport size in draw space: this size is in physical pixels and is used
208   // for draw properties, tilings, quads and render passes.
209   gfx::Size DrawViewportSize() const;
210
211   // Viewport size for scrolling and fixed-position compensation. This value
212   // excludes the URL bar and non-overlay scrollbars and is in DIP (and
213   // invariant relative to page scale).
214   gfx::SizeF UnscaledScrollableViewportSize() const;
215   float VerticalAdjust() const;
216
217   // RendererClient implementation.
218   virtual void SetFullRootLayerDamage() OVERRIDE;
219
220   // TileManagerClient implementation.
221   virtual void NotifyReadyToActivate() OVERRIDE;
222
223   // OutputSurfaceClient implementation.
224   virtual bool DeferredInitialize(
225       scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE;
226   virtual void ReleaseGL() OVERRIDE;
227   virtual void SetNeedsRedrawRect(const gfx::Rect& rect) OVERRIDE;
228   virtual void BeginImplFrame(const BeginFrameArgs& args) OVERRIDE;
229   virtual void SetExternalDrawConstraints(
230       const gfx::Transform& transform,
231       const gfx::Rect& viewport,
232       const gfx::Rect& clip,
233       bool valid_for_tile_management) OVERRIDE;
234   virtual void DidLoseOutputSurface() OVERRIDE;
235   virtual void DidSwapBuffers() OVERRIDE;
236   virtual void OnSwapBuffersComplete() OVERRIDE;
237   virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE;
238   virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE;
239   virtual void SetTreeActivationCallback(const base::Closure& callback)
240       OVERRIDE;
241
242   // Called from LayerTreeImpl.
243   void OnCanDrawStateChangedForTree();
244
245   // Implementation.
246   bool CanDraw() const;
247   OutputSurface* output_surface() const { return output_surface_.get(); }
248
249   void SetOffscreenContextProvider(
250       const scoped_refptr<ContextProvider>& offscreen_context_provider);
251   ContextProvider* offscreen_context_provider() const {
252     return offscreen_context_provider_.get();
253   }
254
255   std::string LayerTreeAsJson() const;
256
257   void FinishAllRendering();
258   int SourceAnimationFrameNumber() const;
259
260   virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
261   bool IsContextLost();
262   TileManager* tile_manager() { return tile_manager_.get(); }
263   Renderer* renderer() { return renderer_.get(); }
264   const RendererCapabilitiesImpl& GetRendererCapabilities() const;
265
266   virtual bool SwapBuffers(const FrameData& frame);
267   void SetNeedsBeginImplFrame(bool enable);
268   void DidModifyTilePriorities();
269
270   void Readback(void* pixels, const gfx::Rect& rect_in_device_viewport);
271
272   LayerTreeImpl* active_tree() { return active_tree_.get(); }
273   const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
274   LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
275   const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
276   const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
277   virtual void CreatePendingTree();
278   virtual void UpdateVisibleTiles();
279   virtual void ActivatePendingTree();
280
281   // Shortcuts to layers on the active tree.
282   LayerImpl* RootLayer() const;
283   LayerImpl* InnerViewportScrollLayer() const;
284   LayerImpl* OuterViewportScrollLayer() const;
285   LayerImpl* CurrentlyScrollingLayer() const;
286
287   int scroll_layer_id_when_mouse_over_scrollbar() {
288     return scroll_layer_id_when_mouse_over_scrollbar_;
289   }
290
291   bool IsCurrentlyScrolling() const;
292
293   virtual void SetVisible(bool visible);
294   bool visible() const { return visible_; }
295
296   void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
297   void SetNeedsRedraw();
298
299   ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
300
301   size_t memory_allocation_limit_bytes() const;
302   int memory_allocation_priority_cutoff() const;
303
304   void SetViewportSize(const gfx::Size& device_viewport_size);
305
306   void SetOverdrawBottomHeight(float overdraw_bottom_height);
307   float overdraw_bottom_height() const { return overdraw_bottom_height_; }
308
309   void SetOverhangUIResource(UIResourceId overhang_ui_resource_id,
310                              const gfx::Size& overhang_ui_resource_size);
311
312   void SetDeviceScaleFactor(float device_scale_factor);
313   float device_scale_factor() const { return device_scale_factor_; }
314
315   const gfx::Transform& DrawTransform() const;
316
317   scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
318
319   bool needs_animate_layers() const {
320     return !animation_registrar_->active_animation_controllers().empty();
321   }
322
323   void SendManagedMemoryStats(
324       size_t memory_visible_bytes,
325       size_t memory_visible_and_nearby_bytes,
326       size_t memory_use_bytes);
327
328   void set_max_memory_needed_bytes(size_t bytes) {
329     max_memory_needed_bytes_ = bytes;
330   }
331
332   FrameRateCounter* fps_counter() {
333     return fps_counter_.get();
334   }
335   PaintTimeCounter* paint_time_counter() {
336     return paint_time_counter_.get();
337   }
338   MemoryHistory* memory_history() {
339     return memory_history_.get();
340   }
341   DebugRectHistory* debug_rect_history() {
342     return debug_rect_history_.get();
343   }
344   ResourceProvider* resource_provider() {
345     return resource_provider_.get();
346   }
347   TopControlsManager* top_controls_manager() {
348     return top_controls_manager_.get();
349   }
350   const GlobalStateThatImpactsTilePriority& global_tile_state() {
351     return global_tile_state_;
352   }
353
354   Proxy* proxy() const { return proxy_; }
355
356   AnimationRegistrar* animation_registrar() const {
357     return animation_registrar_.get();
358   }
359
360   void SetDebugState(const LayerTreeDebugState& new_debug_state);
361   const LayerTreeDebugState& debug_state() const { return debug_state_; }
362
363   class CC_EXPORT CullRenderPassesWithNoQuads {
364  public:
365     bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
366                                 const FrameData& frame) const;
367
368     // Iterates in draw order, so that when a surface is removed, and its
369     // target becomes empty, then its target can be removed also.
370     size_t RenderPassListBegin(const RenderPassList& list) const { return 0; }
371     size_t RenderPassListEnd(const RenderPassList& list) const {
372       return list.size();
373     }
374     size_t RenderPassListNext(size_t it) const { return it + 1; }
375   };
376
377   template <typename RenderPassCuller>
378       static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame);
379
380   gfx::Vector2dF accumulated_root_overscroll() const {
381     return accumulated_root_overscroll_;
382   }
383   gfx::Vector2dF current_fling_velocity() const {
384     return current_fling_velocity_;
385   }
386
387   bool pinch_gesture_active() const { return pinch_gesture_active_; }
388
389   void SetTreePriority(TreePriority priority);
390
391   void UpdateCurrentFrameTime();
392   void ResetCurrentFrameTimeForNextFrame();
393   virtual base::TimeTicks CurrentFrameTimeTicks();
394
395   scoped_ptr<base::Value> AsValue() const { return AsValueWithFrame(NULL); }
396   scoped_ptr<base::Value> AsValueWithFrame(FrameData* frame) const;
397   scoped_ptr<base::Value> ActivationStateAsValue() const;
398
399   bool page_scale_animation_active() const { return !!page_scale_animation_; }
400
401   virtual void CreateUIResource(UIResourceId uid,
402                                 const UIResourceBitmap& bitmap);
403   // Deletes a UI resource.  May safely be called more than once.
404   virtual void DeleteUIResource(UIResourceId uid);
405   void EvictAllUIResources();
406   bool EvictedUIResourcesExist() const;
407
408   virtual ResourceProvider::ResourceId ResourceIdForUIResource(
409       UIResourceId uid) const;
410
411   virtual bool IsUIResourceOpaque(UIResourceId uid) const;
412
413   struct UIResourceData {
414     ResourceProvider::ResourceId resource_id;
415     gfx::Size size;
416     bool opaque;
417   };
418
419   void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark);
420
421   CompositorFrameMetadata MakeCompositorFrameMetadata() const;
422   // Viewport rectangle and clip in nonflipped window space.  These rects
423   // should only be used by Renderer subclasses to populate glViewport/glClip
424   // and their software-mode equivalents.
425   gfx::Rect DeviceViewport() const;
426   gfx::Rect DeviceClip() const;
427
428   // When a SwapPromiseMonitor is created on the impl thread, it calls
429   // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
430   // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
431   // to unregister itself.
432   void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
433   void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
434
435  protected:
436   LayerTreeHostImpl(
437       const LayerTreeSettings& settings,
438       LayerTreeHostImplClient* client,
439       Proxy* proxy,
440       RenderingStatsInstrumentation* rendering_stats_instrumentation,
441       SharedBitmapManager* manager,
442       int id);
443
444   gfx::SizeF ComputeInnerViewportContainerSize() const;
445   void UpdateInnerViewportContainerSize();
446
447   // Virtual for testing.
448   virtual void AnimateLayers(base::TimeTicks monotonic_time);
449
450   // Virtual for testing.
451   virtual base::TimeDelta LowFrequencyAnimationInterval() const;
452
453   const AnimationRegistrar::AnimationControllerMap&
454       active_animation_controllers() const {
455     return animation_registrar_->active_animation_controllers();
456   }
457
458   bool manage_tiles_needed() const { return tile_priorities_dirty_; }
459
460   LayerTreeHostImplClient* client_;
461   Proxy* proxy_;
462
463  private:
464   void CreateAndSetRenderer(
465       OutputSurface* output_surface,
466       ResourceProvider* resource_provider,
467       bool skip_gl_renderer);
468   void CreateAndSetTileManager(ResourceProvider* resource_provider,
469                                ContextProvider* context_provider,
470                                bool using_map_image,
471                                bool allow_rasterize_on_demand);
472   void ReleaseTreeResources();
473   void EnforceZeroBudget(bool zero_budget);
474
475   void ScrollViewportBy(gfx::Vector2dF scroll_delta);
476   void AnimatePageScale(base::TimeTicks monotonic_time);
477   void AnimateScrollbars(base::TimeTicks monotonic_time);
478   void AnimateTopControls(base::TimeTicks monotonic_time);
479
480   gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
481       LayerImpl* layer_impl,
482       float scale_from_viewport_to_screen_space,
483       const gfx::PointF& viewport_point,
484       const gfx::Vector2dF& viewport_delta);
485
486   void TrackDamageForAllSurfaces(
487       LayerImpl* root_draw_layer,
488       const LayerImplList& render_surface_layer_list);
489
490   void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
491
492   // This function should only be called from PrepareToDraw, as DidDrawAllLayers
493   // must be called if this helper function is called.  Returns DRAW_SUCCESS if
494   // the frame should be drawn.
495   DrawSwapReadbackResult::DrawResult CalculateRenderPasses(FrameData* frame);
496
497   void SendReleaseResourcesRecursive(LayerImpl* current);
498   bool EnsureRenderSurfaceLayerList();
499   void ClearCurrentlyScrollingLayer();
500
501   bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
502                                 const gfx::PointF& device_viewport_point);
503
504   void AnimateScrollbarsRecursive(LayerImpl* layer,
505                                   base::TimeTicks time);
506
507   LayerImpl* FindScrollLayerForDeviceViewportPoint(
508       const gfx::PointF& device_viewport_point,
509       InputHandler::ScrollInputType type,
510       LayerImpl* layer_hit_by_point,
511       bool* scroll_on_main_thread) const;
512   float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point,
513                                    LayerImpl* layer_impl);
514   void StartScrollbarAnimationRecursive(LayerImpl* layer, base::TimeTicks time);
515   void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy,
516                               bool zero_budget);
517   void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
518
519   void DidInitializeVisibleTile();
520
521   void MarkUIResourceNotEvicted(UIResourceId uid);
522
523   void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
524
525   typedef base::hash_map<UIResourceId, UIResourceData>
526       UIResourceMap;
527   UIResourceMap ui_resource_map_;
528
529   // Resources that were evicted by EvictAllUIResources. Resources are removed
530   // from this when they are touched by a create or destroy from the UI resource
531   // request queue.
532   std::set<UIResourceId> evicted_ui_resources_;
533
534   scoped_ptr<OutputSurface> output_surface_;
535   scoped_refptr<ContextProvider> offscreen_context_provider_;
536
537   // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
538   // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
539   scoped_ptr<ResourceProvider> resource_provider_;
540   scoped_ptr<TileManager> tile_manager_;
541   scoped_ptr<Renderer> renderer_;
542
543   GlobalStateThatImpactsTilePriority global_tile_state_;
544
545   // Tree currently being drawn.
546   scoped_ptr<LayerTreeImpl> active_tree_;
547
548   // In impl-side painting mode, tree with possibly incomplete rasterized
549   // content. May be promoted to active by ActivatePendingTree().
550   scoped_ptr<LayerTreeImpl> pending_tree_;
551
552   // In impl-side painting mode, inert tree with layers that can be recycled
553   // by the next sync from the main thread.
554   scoped_ptr<LayerTreeImpl> recycle_tree_;
555
556   InputHandlerClient* input_handler_client_;
557   bool did_lock_scrolling_layer_;
558   bool should_bubble_scrolls_;
559   bool wheel_scrolling_;
560   int scroll_layer_id_when_mouse_over_scrollbar_;
561
562   bool tile_priorities_dirty_;
563
564   // The optional delegate for the root layer scroll offset.
565   LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
566   LayerTreeSettings settings_;
567   LayerTreeDebugState debug_state_;
568   bool visible_;
569   ManagedMemoryPolicy cached_managed_memory_policy_;
570
571   gfx::Vector2dF accumulated_root_overscroll_;
572   gfx::Vector2dF current_fling_velocity_;
573
574   bool pinch_gesture_active_;
575   bool pinch_gesture_end_should_clear_scrolling_layer_;
576   gfx::Point previous_pinch_anchor_;
577
578   scoped_ptr<TopControlsManager> top_controls_manager_;
579
580   scoped_ptr<PageScaleAnimation> page_scale_animation_;
581
582   // This is used for ticking animations slowly when hidden.
583   scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
584
585   scoped_ptr<FrameRateCounter> fps_counter_;
586   scoped_ptr<PaintTimeCounter> paint_time_counter_;
587   scoped_ptr<MemoryHistory> memory_history_;
588   scoped_ptr<DebugRectHistory> debug_rect_history_;
589
590   scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
591
592   // The maximum memory that would be used by the prioritized resource
593   // manager, if there were no limit on memory usage.
594   size_t max_memory_needed_bytes_;
595
596   size_t last_sent_memory_visible_bytes_;
597   size_t last_sent_memory_visible_and_nearby_bytes_;
598   size_t last_sent_memory_use_bytes_;
599   bool zero_budget_;
600
601   // Viewport size passed in from the main thread, in physical pixels.  This
602   // value is the default size for all concepts of physical viewport (draw
603   // viewport, scrolling viewport and device viewport), but it can be
604   // overridden.
605   gfx::Size device_viewport_size_;
606
607   // Conversion factor from CSS pixels to physical pixels when
608   // pageScaleFactor=1.
609   float device_scale_factor_;
610
611   // UI resource to use for drawing overhang gutters.
612   UIResourceId overhang_ui_resource_id_;
613   gfx::Size overhang_ui_resource_size_;
614
615   // Vertical amount of the viewport size that's known to covered by a
616   // browser-side UI element, such as an on-screen-keyboard.  This affects
617   // scrollable size since we want to still be able to scroll to the bottom of
618   // the page when the keyboard is up.
619   float overdraw_bottom_height_;
620
621   // Optional top-level constraints that can be set by the OutputSurface.
622   // - external_transform_ applies a transform above the root layer
623   // - external_viewport_ is used DrawProperties, tile management and
624   // glViewport/window projection matrix.
625   // - external_clip_ specifies a top-level clip rect
626   // - external_stencil_test_enabled_ tells CC to respect existing stencil bits
627   // (When these are specified, device_viewport_size_ remains used only for
628   // scrollable size.)
629   gfx::Transform external_transform_;
630   gfx::Rect external_viewport_;
631   gfx::Rect external_clip_;
632   bool device_viewport_valid_for_tile_management_;
633   bool external_stencil_test_enabled_;
634
635   gfx::Rect viewport_damage_rect_;
636
637   base::TimeTicks current_frame_timeticks_;
638
639   scoped_ptr<AnimationRegistrar> animation_registrar_;
640
641   RenderingStatsInstrumentation* rendering_stats_instrumentation_;
642   MicroBenchmarkControllerImpl micro_benchmark_controller_;
643
644   bool need_to_update_visible_tiles_before_draw_;
645 #if DCHECK_IS_ON
646   bool did_lose_called_;
647 #endif
648
649   // Optional callback to notify of new tree activations.
650   base::Closure tree_activation_callback_;
651
652   SharedBitmapManager* shared_bitmap_manager_;
653   int id_;
654
655   std::set<SwapPromiseMonitor*> swap_promise_monitor_;
656
657   DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
658 };
659
660 }  // namespace cc
661
662 #endif  // CC_TREES_LAYER_TREE_HOST_IMPL_H_