Upstream version 5.34.104.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,
78       base::Time wall_clock_time) = 0;
79   // Returns true if resources were deleted by this call.
80   virtual bool ReduceContentsTextureMemoryOnImplThread(
81       size_t limit_bytes,
82       int priority_cutoff) = 0;
83   virtual void SendManagedMemoryStats() = 0;
84   virtual bool IsInsideDraw() = 0;
85   virtual void RenewTreePriority() = 0;
86   virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) = 0;
87   virtual void DidActivatePendingTree() = 0;
88   virtual void DidManageTiles() = 0;
89
90  protected:
91   virtual ~LayerTreeHostImplClient() {}
92 };
93
94 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
95 // state.
96 class CC_EXPORT LayerTreeHostImpl
97     : public InputHandler,
98       public RendererClient,
99       public TileManagerClient,
100       public OutputSurfaceClient,
101       public TopControlsManagerClient,
102       public base::SupportsWeakPtr<LayerTreeHostImpl> {
103  public:
104   static scoped_ptr<LayerTreeHostImpl> Create(
105       const LayerTreeSettings& settings,
106       LayerTreeHostImplClient* client,
107       Proxy* proxy,
108       RenderingStatsInstrumentation* rendering_stats_instrumentation,
109       SharedBitmapManager* manager,
110       int id);
111   virtual ~LayerTreeHostImpl();
112
113   // InputHandler implementation
114   virtual void BindToClient(InputHandlerClient* client) OVERRIDE;
115   virtual InputHandler::ScrollStatus ScrollBegin(
116       gfx::Point viewport_point,
117       InputHandler::ScrollInputType type) OVERRIDE;
118   virtual bool ScrollBy(gfx::Point viewport_point,
119                         const gfx::Vector2dF& scroll_delta) OVERRIDE;
120   virtual bool ScrollVerticallyByPage(gfx::Point viewport_point,
121                                       ScrollDirection direction) OVERRIDE;
122   virtual void SetRootLayerScrollOffsetDelegate(
123       LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) OVERRIDE;
124   virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE;
125   virtual void ScrollEnd() OVERRIDE;
126   virtual InputHandler::ScrollStatus FlingScrollBegin() OVERRIDE;
127   virtual void NotifyCurrentFlingVelocity(
128       const gfx::Vector2dF& velocity) OVERRIDE;
129   virtual void MouseMoveAt(gfx::Point viewport_point) OVERRIDE;
130   virtual void PinchGestureBegin() OVERRIDE;
131   virtual void PinchGestureUpdate(float magnify_delta,
132                                   gfx::Point anchor) OVERRIDE;
133   virtual void PinchGestureEnd() OVERRIDE;
134   virtual void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
135                                        bool anchor_point,
136                                        float page_scale,
137                                        base::TimeDelta duration) OVERRIDE;
138   virtual void ScheduleAnimation() OVERRIDE;
139   virtual bool HaveTouchEventHandlersAt(gfx::Point viewport_port) 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                        base::Time wall_clock_time);
172   virtual void UpdateAnimationState(bool start_ready_animations);
173   void MainThreadHasStoppedFlinging();
174   void UpdateBackgroundAnimateTicking(bool should_background_tick);
175   void DidAnimateScrollOffset();
176   void SetViewportDamage(const gfx::Rect& damage_rect);
177
178   virtual void ManageTiles();
179
180   // Returns false if problems occured preparing the frame, and we should try
181   // to avoid displaying the frame. If PrepareToDraw is called, DidDrawAllLayers
182   // must also be called, regardless of whether DrawLayers is called between the
183   // two.
184   virtual DrawSwapReadbackResult::DrawResult PrepareToDraw(
185       FrameData* frame,
186       const gfx::Rect& damage_rect);
187   virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
188   // Must be called if and only if PrepareToDraw was called.
189   void DidDrawAllLayers(const FrameData& frame);
190
191   const LayerTreeSettings& settings() const { return settings_; }
192
193   // Evict all textures by enforcing a memory policy with an allocation of 0.
194   void EvictTexturesForTesting();
195
196   // When blocking, this prevents client_->NotifyReadyToActivate() from being
197   // called. When disabled, it calls client_->NotifyReadyToActivate()
198   // immediately if any notifications had been blocked while blocking.
199   virtual void BlockNotifyReadyToActivateForTesting(bool block);
200
201   // This allows us to inject DidInitializeVisibleTile events for testing.
202   void DidInitializeVisibleTileForTesting();
203
204   bool device_viewport_valid_for_tile_management() const {
205     return device_viewport_valid_for_tile_management_;
206   }
207
208   // Viewport size in draw space: this size is in physical pixels and is used
209   // for draw properties, tilings, quads and render passes.
210   gfx::Size DrawViewportSize() const;
211
212   // Viewport size for scrolling and fixed-position compensation. This value
213   // excludes the URL bar and non-overlay scrollbars and is in DIP (and
214   // invariant relative to page scale).
215   gfx::SizeF UnscaledScrollableViewportSize() const;
216   float VerticalAdjust() const;
217
218   // RendererClient implementation.
219   virtual void SetFullRootLayerDamage() OVERRIDE;
220
221   // TileManagerClient implementation.
222   virtual void NotifyReadyToActivate() OVERRIDE;
223
224   // OutputSurfaceClient implementation.
225   virtual bool DeferredInitialize(
226       scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE;
227   virtual void ReleaseGL() OVERRIDE;
228   virtual void SetNeedsRedrawRect(const gfx::Rect& rect) OVERRIDE;
229   virtual void BeginImplFrame(const BeginFrameArgs& args) OVERRIDE;
230   virtual void SetExternalDrawConstraints(
231       const gfx::Transform& transform,
232       const gfx::Rect& viewport,
233       const gfx::Rect& clip,
234       bool valid_for_tile_management) OVERRIDE;
235   virtual void DidLoseOutputSurface() OVERRIDE;
236   virtual void DidSwapBuffers() OVERRIDE;
237   virtual void OnSwapBuffersComplete() OVERRIDE;
238   virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE;
239   virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE;
240   virtual void SetTreeActivationCallback(const base::Closure& callback)
241       OVERRIDE;
242
243   // Called from LayerTreeImpl.
244   void OnCanDrawStateChangedForTree();
245
246   // Implementation.
247   bool CanDraw() const;
248   OutputSurface* output_surface() const { return output_surface_.get(); }
249
250   void SetOffscreenContextProvider(
251       const scoped_refptr<ContextProvider>& offscreen_context_provider);
252   ContextProvider* offscreen_context_provider() const {
253     return offscreen_context_provider_.get();
254   }
255
256   std::string LayerTreeAsJson() const;
257
258   void FinishAllRendering();
259   int SourceAnimationFrameNumber() const;
260
261   virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
262   bool IsContextLost();
263   TileManager* tile_manager() { return tile_manager_.get(); }
264   Renderer* renderer() { return renderer_.get(); }
265   const RendererCapabilitiesImpl& GetRendererCapabilities() const;
266
267   virtual bool SwapBuffers(const FrameData& frame);
268   void SetNeedsBeginImplFrame(bool enable);
269   void DidModifyTilePriorities();
270
271   void Readback(void* pixels, const gfx::Rect& rect_in_device_viewport);
272
273   LayerTreeImpl* active_tree() { return active_tree_.get(); }
274   const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
275   LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
276   const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
277   const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
278   virtual void CreatePendingTree();
279   virtual void UpdateVisibleTiles();
280   virtual void ActivatePendingTree();
281
282   // Shortcuts to layers on the active tree.
283   LayerImpl* RootLayer() const;
284   LayerImpl* InnerViewportScrollLayer() const;
285   LayerImpl* OuterViewportScrollLayer() const;
286   LayerImpl* CurrentlyScrollingLayer() const;
287
288   int scroll_layer_id_when_mouse_over_scrollbar() {
289     return scroll_layer_id_when_mouse_over_scrollbar_;
290   }
291
292   bool IsCurrentlyScrolling() const;
293
294   virtual void SetVisible(bool visible);
295   bool visible() const { return visible_; }
296
297   void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
298   void SetNeedsRedraw();
299
300   ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
301
302   size_t memory_allocation_limit_bytes() const;
303   int memory_allocation_priority_cutoff() const;
304
305   void SetViewportSize(const gfx::Size& device_viewport_size);
306
307   void SetOverdrawBottomHeight(float overdraw_bottom_height);
308   float overdraw_bottom_height() const { return overdraw_bottom_height_; }
309
310   void SetOverhangUIResource(UIResourceId overhang_ui_resource_id,
311                              const gfx::Size& overhang_ui_resource_size);
312
313   void SetDeviceScaleFactor(float device_scale_factor);
314   float device_scale_factor() const { return device_scale_factor_; }
315
316   const gfx::Transform& DrawTransform() const;
317
318   scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
319
320   bool needs_animate_layers() const {
321     return !animation_registrar_->active_animation_controllers().empty();
322   }
323
324   void SendManagedMemoryStats(
325       size_t memory_visible_bytes,
326       size_t memory_visible_and_nearby_bytes,
327       size_t memory_use_bytes);
328
329   void set_max_memory_needed_bytes(size_t bytes) {
330     max_memory_needed_bytes_ = bytes;
331   }
332
333   FrameRateCounter* fps_counter() {
334     return fps_counter_.get();
335   }
336   PaintTimeCounter* paint_time_counter() {
337     return paint_time_counter_.get();
338   }
339   MemoryHistory* memory_history() {
340     return memory_history_.get();
341   }
342   DebugRectHistory* debug_rect_history() {
343     return debug_rect_history_.get();
344   }
345   ResourceProvider* resource_provider() {
346     return resource_provider_.get();
347   }
348   TopControlsManager* top_controls_manager() {
349     return top_controls_manager_.get();
350   }
351
352   Proxy* proxy() const { return proxy_; }
353
354   AnimationRegistrar* animation_registrar() const {
355     return animation_registrar_.get();
356   }
357
358   void SetDebugState(const LayerTreeDebugState& new_debug_state);
359   const LayerTreeDebugState& debug_state() const { return debug_state_; }
360
361   class CC_EXPORT CullRenderPassesWithNoQuads {
362  public:
363     bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
364                                 const FrameData& frame) const;
365
366     // Iterates in draw order, so that when a surface is removed, and its
367     // target becomes empty, then its target can be removed also.
368     size_t RenderPassListBegin(const RenderPassList& list) const { return 0; }
369     size_t RenderPassListEnd(const RenderPassList& list) const {
370       return list.size();
371     }
372     size_t RenderPassListNext(size_t it) const { return it + 1; }
373   };
374
375   template <typename RenderPassCuller>
376       static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame);
377
378   gfx::Vector2dF accumulated_root_overscroll() const {
379     return accumulated_root_overscroll_;
380   }
381   gfx::Vector2dF current_fling_velocity() const {
382     return current_fling_velocity_;
383   }
384
385   bool pinch_gesture_active() const { return pinch_gesture_active_; }
386
387   void SetTreePriority(TreePriority priority);
388
389   void ResetCurrentFrameTimeForNextFrame();
390   virtual base::TimeTicks CurrentFrameTimeTicks();
391   base::Time CurrentFrameTime();
392
393   virtual base::TimeTicks CurrentPhysicalTimeTicks() const;
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                              base::Time wall_clock_time);
450
451   // Virtual for testing.
452   virtual base::TimeDelta LowFrequencyAnimationInterval() const;
453
454   const AnimationRegistrar::AnimationControllerMap&
455       active_animation_controllers() const {
456     return animation_registrar_->active_animation_controllers();
457   }
458
459   bool manage_tiles_needed() const { return tile_priorities_dirty_; }
460
461   LayerTreeHostImplClient* client_;
462   Proxy* proxy_;
463
464  private:
465   void CreateAndSetRenderer(
466       OutputSurface* output_surface,
467       ResourceProvider* resource_provider,
468       bool skip_gl_renderer);
469   void CreateAndSetTileManager(ResourceProvider* resource_provider,
470                                ContextProvider* context_provider,
471                                bool using_map_image,
472                                bool allow_rasterize_on_demand);
473   void ReleaseTreeResources();
474   void EnforceZeroBudget(bool zero_budget);
475
476   void ScrollViewportBy(gfx::Vector2dF scroll_delta);
477   void AnimatePageScale(base::TimeTicks monotonic_time);
478   void AnimateScrollbars(base::TimeTicks monotonic_time);
479   void AnimateTopControls(base::TimeTicks monotonic_time);
480
481   gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
482       LayerImpl* layer_impl,
483       float scale_from_viewport_to_screen_space,
484       const gfx::PointF& viewport_point,
485       const gfx::Vector2dF& viewport_delta);
486
487   void TrackDamageForAllSurfaces(
488       LayerImpl* root_draw_layer,
489       const LayerImplList& render_surface_layer_list);
490
491   void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
492
493   // This function should only be called from PrepareToDraw, as DidDrawAllLayers
494   // must be called if this helper function is called.  Returns DRAW_SUCCESS if
495   // the frame should be drawn.
496   DrawSwapReadbackResult::DrawResult CalculateRenderPasses(FrameData* frame);
497
498   void SendReleaseResourcesRecursive(LayerImpl* current);
499   bool EnsureRenderSurfaceLayerList();
500   void ClearCurrentlyScrollingLayer();
501
502   bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
503                                 const gfx::PointF& device_viewport_point);
504
505   void AnimateScrollbarsRecursive(LayerImpl* layer,
506                                   base::TimeTicks time);
507
508   void UpdateCurrentFrameTime(base::TimeTicks* ticks, base::Time* now) const;
509
510   LayerImpl* FindScrollLayerForDeviceViewportPoint(
511       const gfx::PointF& device_viewport_point,
512       InputHandler::ScrollInputType type,
513       LayerImpl* layer_hit_by_point,
514       bool* scroll_on_main_thread) const;
515   float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point,
516                                    LayerImpl* layer_impl);
517   void StartScrollbarAnimationRecursive(LayerImpl* layer, base::TimeTicks time);
518   void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy,
519                               bool zero_budget);
520   void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
521
522   void DidInitializeVisibleTile();
523
524   void MarkUIResourceNotEvicted(UIResourceId uid);
525
526   void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
527
528   typedef base::hash_map<UIResourceId, UIResourceData>
529       UIResourceMap;
530   UIResourceMap ui_resource_map_;
531
532   // Resources that were evicted by EvictAllUIResources. Resources are removed
533   // from this when they are touched by a create or destroy from the UI resource
534   // request queue.
535   std::set<UIResourceId> evicted_ui_resources_;
536
537   scoped_ptr<OutputSurface> output_surface_;
538   scoped_refptr<ContextProvider> offscreen_context_provider_;
539
540   // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
541   // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
542   scoped_ptr<ResourceProvider> resource_provider_;
543   scoped_ptr<TileManager> tile_manager_;
544   scoped_ptr<Renderer> renderer_;
545
546   GlobalStateThatImpactsTilePriority global_tile_state_;
547
548   // Tree currently being drawn.
549   scoped_ptr<LayerTreeImpl> active_tree_;
550
551   // In impl-side painting mode, tree with possibly incomplete rasterized
552   // content. May be promoted to active by ActivatePendingTree().
553   scoped_ptr<LayerTreeImpl> pending_tree_;
554
555   // In impl-side painting mode, inert tree with layers that can be recycled
556   // by the next sync from the main thread.
557   scoped_ptr<LayerTreeImpl> recycle_tree_;
558
559   InputHandlerClient* input_handler_client_;
560   bool did_lock_scrolling_layer_;
561   bool should_bubble_scrolls_;
562   bool wheel_scrolling_;
563   int scroll_layer_id_when_mouse_over_scrollbar_;
564
565   bool tile_priorities_dirty_;
566
567   // The optional delegate for the root layer scroll offset.
568   LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
569   LayerTreeSettings settings_;
570   LayerTreeDebugState debug_state_;
571   bool visible_;
572   ManagedMemoryPolicy cached_managed_memory_policy_;
573
574   gfx::Vector2dF accumulated_root_overscroll_;
575   gfx::Vector2dF current_fling_velocity_;
576
577   bool pinch_gesture_active_;
578   bool pinch_gesture_end_should_clear_scrolling_layer_;
579   gfx::Point previous_pinch_anchor_;
580
581   // This is set by AnimateLayers() and used by UpdateAnimationState()
582   // when sending animation events to the main thread.
583   base::Time last_animation_time_;
584
585   scoped_ptr<TopControlsManager> top_controls_manager_;
586
587   scoped_ptr<PageScaleAnimation> page_scale_animation_;
588
589   // This is used for ticking animations slowly when hidden.
590   scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
591
592   scoped_ptr<FrameRateCounter> fps_counter_;
593   scoped_ptr<PaintTimeCounter> paint_time_counter_;
594   scoped_ptr<MemoryHistory> memory_history_;
595   scoped_ptr<DebugRectHistory> debug_rect_history_;
596
597   scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
598
599   // The maximum memory that would be used by the prioritized resource
600   // manager, if there were no limit on memory usage.
601   size_t max_memory_needed_bytes_;
602
603   size_t last_sent_memory_visible_bytes_;
604   size_t last_sent_memory_visible_and_nearby_bytes_;
605   size_t last_sent_memory_use_bytes_;
606   bool zero_budget_;
607
608   // Viewport size passed in from the main thread, in physical pixels.  This
609   // value is the default size for all concepts of physical viewport (draw
610   // viewport, scrolling viewport and device viewport), but it can be
611   // overridden.
612   gfx::Size device_viewport_size_;
613
614   // Conversion factor from CSS pixels to physical pixels when
615   // pageScaleFactor=1.
616   float device_scale_factor_;
617
618   // UI resource to use for drawing overhang gutters.
619   UIResourceId overhang_ui_resource_id_;
620   gfx::Size overhang_ui_resource_size_;
621
622   // Vertical amount of the viewport size that's known to covered by a
623   // browser-side UI element, such as an on-screen-keyboard.  This affects
624   // scrollable size since we want to still be able to scroll to the bottom of
625   // the page when the keyboard is up.
626   float overdraw_bottom_height_;
627
628   // Optional top-level constraints that can be set by the OutputSurface.
629   // - external_transform_ applies a transform above the root layer
630   // - external_viewport_ is used DrawProperties, tile management and
631   // glViewport/window projection matrix.
632   // - external_clip_ specifies a top-level clip rect
633   // - external_stencil_test_enabled_ tells CC to respect existing stencil bits
634   // (When these are specified, device_viewport_size_ remains used only for
635   // scrollable size.)
636   gfx::Transform external_transform_;
637   gfx::Rect external_viewport_;
638   gfx::Rect external_clip_;
639   bool device_viewport_valid_for_tile_management_;
640   bool external_stencil_test_enabled_;
641
642   gfx::Rect viewport_damage_rect_;
643
644   base::TimeTicks current_frame_timeticks_;
645   base::Time current_frame_time_;
646
647   scoped_ptr<AnimationRegistrar> animation_registrar_;
648
649   RenderingStatsInstrumentation* rendering_stats_instrumentation_;
650   MicroBenchmarkControllerImpl micro_benchmark_controller_;
651
652   bool need_to_update_visible_tiles_before_draw_;
653 #ifndef NDEBUG
654   bool did_lose_called_;
655 #endif
656
657   // Optional callback to notify of new tree activations.
658   base::Closure tree_activation_callback_;
659
660   SharedBitmapManager* shared_bitmap_manager_;
661   int id_;
662
663   std::set<SwapPromiseMonitor*> swap_promise_monitor_;
664
665   DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
666 };
667
668 }  // namespace cc
669
670 #endif  // CC_TREES_LAYER_TREE_HOST_IMPL_H_