Update To 11.40.268.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/animation/scrollbar_animation_controller.h"
20 #include "cc/base/cc_export.h"
21 #include "cc/debug/micro_benchmark_controller_impl.h"
22 #include "cc/input/input_handler.h"
23 #include "cc/input/layer_scroll_offset_delegate.h"
24 #include "cc/input/top_controls_manager_client.h"
25 #include "cc/layers/layer_lists.h"
26 #include "cc/layers/render_pass_sink.h"
27 #include "cc/output/begin_frame_args.h"
28 #include "cc/output/managed_memory_policy.h"
29 #include "cc/output/output_surface_client.h"
30 #include "cc/output/renderer.h"
31 #include "cc/quads/render_pass.h"
32 #include "cc/resources/resource_provider.h"
33 #include "cc/resources/tile_manager.h"
34 #include "cc/scheduler/begin_frame_source.h"
35 #include "cc/scheduler/draw_result.h"
36 #include "skia/ext/refptr.h"
37 #include "third_party/skia/include/core/SkColor.h"
38 #include "ui/gfx/geometry/rect.h"
39
40 namespace cc {
41
42 class CompletionEvent;
43 class CompositorFrameMetadata;
44 class DebugRectHistory;
45 class EvictionTilePriorityQueue;
46 class FrameRateCounter;
47 class LayerImpl;
48 class LayerTreeHostImplTimeSourceAdapter;
49 class LayerTreeImpl;
50 class MemoryHistory;
51 class PageScaleAnimation;
52 class PaintTimeCounter;
53 class PictureLayerImpl;
54 class RasterTilePriorityQueue;
55 class RasterWorkerPool;
56 class RenderPassDrawQuad;
57 class RenderingStatsInstrumentation;
58 class ResourcePool;
59 class ScrollbarLayerImplBase;
60 class TextureMailboxDeleter;
61 class TopControlsManager;
62 class UIResourceBitmap;
63 class UIResourceRequest;
64 struct RendererCapabilitiesImpl;
65
66 // LayerTreeHost->Proxy callback interface.
67 class LayerTreeHostImplClient {
68  public:
69   virtual void UpdateRendererCapabilitiesOnImplThread() = 0;
70   virtual void DidLoseOutputSurfaceOnImplThread() = 0;
71   virtual void CommitVSyncParameters(base::TimeTicks timebase,
72                                      base::TimeDelta interval) = 0;
73   virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time) = 0;
74   virtual void SetMaxSwapsPendingOnImplThread(int max) = 0;
75   virtual void DidSwapBuffersOnImplThread() = 0;
76   virtual void DidSwapBuffersCompleteOnImplThread() = 0;
77   virtual void OnCanDrawStateChanged(bool can_draw) = 0;
78   virtual void NotifyReadyToActivate() = 0;
79   // Please call these 3 functions through
80   // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
81   // SetNeedsAnimate().
82   virtual void SetNeedsRedrawOnImplThread() = 0;
83   virtual void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) = 0;
84   virtual void SetNeedsAnimateOnImplThread() = 0;
85   virtual void DidInitializeVisibleTileOnImplThread() = 0;
86   virtual void SetNeedsCommitOnImplThread() = 0;
87   virtual void SetNeedsManageTilesOnImplThread() = 0;
88   virtual void PostAnimationEventsToMainThreadOnImplThread(
89       scoped_ptr<AnimationEventsVector> events) = 0;
90   // Returns true if resources were deleted by this call.
91   virtual bool ReduceContentsTextureMemoryOnImplThread(
92       size_t limit_bytes,
93       int priority_cutoff) = 0;
94   virtual bool IsInsideDraw() = 0;
95   virtual void RenewTreePriority() = 0;
96   virtual void PostDelayedScrollbarFadeOnImplThread(
97       const base::Closure& start_fade,
98       base::TimeDelta delay) = 0;
99   virtual void DidActivateSyncTree() = 0;
100   virtual void DidManageTiles() = 0;
101
102  protected:
103   virtual ~LayerTreeHostImplClient() {}
104 };
105
106 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
107 // state.
108 class CC_EXPORT LayerTreeHostImpl
109     : public InputHandler,
110       public RendererClient,
111       public TileManagerClient,
112       public OutputSurfaceClient,
113       public TopControlsManagerClient,
114       public ScrollbarAnimationControllerClient,
115       public BeginFrameSourceMixIn,
116       public base::SupportsWeakPtr<LayerTreeHostImpl> {
117  public:
118   static scoped_ptr<LayerTreeHostImpl> Create(
119       const LayerTreeSettings& settings,
120       LayerTreeHostImplClient* client,
121       Proxy* proxy,
122       RenderingStatsInstrumentation* rendering_stats_instrumentation,
123       SharedBitmapManager* shared_bitmap_manager,
124       gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
125       int id);
126   ~LayerTreeHostImpl() override;
127
128   // BeginFrameSourceMixIn implementation
129   void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
130
131   // InputHandler implementation
132   void BindToClient(InputHandlerClient* client) override;
133   InputHandler::ScrollStatus ScrollBegin(
134       const gfx::Point& viewport_point,
135       InputHandler::ScrollInputType type) override;
136   InputHandler::ScrollStatus ScrollAnimated(
137       const gfx::Point& viewport_point,
138       const gfx::Vector2dF& scroll_delta) override;
139   InputHandlerScrollResult ScrollBy(
140       const gfx::Point& viewport_point,
141       const gfx::Vector2dF& scroll_delta) override;
142   bool ScrollVerticallyByPage(const gfx::Point& viewport_point,
143                               ScrollDirection direction) override;
144   void SetRootLayerScrollOffsetDelegate(
145       LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) override;
146   void OnRootLayerDelegatedScrollOffsetChanged() override;
147   void ScrollEnd() override;
148   InputHandler::ScrollStatus FlingScrollBegin() override;
149   void MouseMoveAt(const gfx::Point& viewport_point) override;
150   void PinchGestureBegin() override;
151   void PinchGestureUpdate(float magnify_delta,
152                           const gfx::Point& anchor) override;
153   void PinchGestureEnd() override;
154   void SetNeedsAnimate() override;
155   bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point,
156                                    InputHandler::ScrollInputType type) override;
157   bool HaveTouchEventHandlersAt(const gfx::Point& viewport_port) override;
158   scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
159       ui::LatencyInfo* latency) override;
160
161   // TopControlsManagerClient implementation.
162   void SetControlsTopOffset(float offset) override;
163   float ControlsTopOffset() const override;
164   void DidChangeTopControlsPosition() override;
165   bool HaveRootScrollLayer() const override;
166
167   struct CC_EXPORT FrameData : public RenderPassSink {
168     FrameData();
169     ~FrameData() override;
170     void AsValueInto(base::debug::TracedValue* value) const;
171
172     std::vector<gfx::Rect> occluding_screen_space_rects;
173     std::vector<gfx::Rect> non_occluding_screen_space_rects;
174     RenderPassList render_passes;
175     RenderPassIdHashMap render_passes_by_id;
176     const LayerImplList* render_surface_layer_list;
177     LayerImplList will_draw_layers;
178     bool contains_incomplete_tile;
179     bool has_no_damage;
180
181     // RenderPassSink implementation.
182     void AppendRenderPass(scoped_ptr<RenderPass> render_pass) override;
183   };
184
185   virtual void BeginMainFrameAborted(bool did_handle);
186   virtual void BeginCommit();
187   virtual void CommitComplete();
188   virtual void Animate(base::TimeTicks monotonic_time);
189   virtual void UpdateAnimationState(bool start_ready_animations);
190   void ActivateAnimations();
191   void MainThreadHasStoppedFlinging();
192   void UpdateBackgroundAnimateTicking(bool should_background_tick);
193   void DidAnimateScrollOffset();
194   void SetViewportDamage(const gfx::Rect& damage_rect);
195
196   virtual void ManageTiles();
197
198   // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
199   // should try to avoid displaying the frame. If PrepareToDraw is called,
200   // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
201   // called between the two.
202   virtual DrawResult PrepareToDraw(FrameData* frame);
203   virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
204   // Must be called if and only if PrepareToDraw was called.
205   void DidDrawAllLayers(const FrameData& frame);
206
207   const LayerTreeSettings& settings() const { return settings_; }
208
209   // Evict all textures by enforcing a memory policy with an allocation of 0.
210   void EvictTexturesForTesting();
211
212   // When blocking, this prevents client_->NotifyReadyToActivate() from being
213   // called. When disabled, it calls client_->NotifyReadyToActivate()
214   // immediately if any notifications had been blocked while blocking.
215   virtual void BlockNotifyReadyToActivateForTesting(bool block);
216
217   // This allows us to inject DidInitializeVisibleTile events for testing.
218   void DidInitializeVisibleTileForTesting();
219
220   // Resets all of the trees to an empty state.
221   void ResetTreesForTesting();
222
223   DrawMode GetDrawMode() const;
224
225   // Viewport size in draw space: this size is in physical pixels and is used
226   // for draw properties, tilings, quads and render passes.
227   gfx::Size DrawViewportSize() const;
228
229   // Viewport rect in view space used for tiling prioritization.
230   const gfx::Rect ViewportRectForTilePriority() const;
231
232   // RendererClient implementation.
233   void SetFullRootLayerDamage() override;
234
235   // TileManagerClient implementation.
236   const std::vector<PictureLayerImpl*>& GetPictureLayers() const override;
237   void NotifyReadyToActivate() override;
238   void NotifyTileStateChanged(const Tile* tile) override;
239   void BuildRasterQueue(RasterTilePriorityQueue* queue,
240                         TreePriority tree_priority) override;
241   void BuildEvictionQueue(EvictionTilePriorityQueue* queue,
242                           TreePriority tree_priority) override;
243
244   // ScrollbarAnimationControllerClient implementation.
245   void PostDelayedScrollbarFade(const base::Closure& start_fade,
246                                 base::TimeDelta delay) override;
247   void SetNeedsScrollbarAnimationFrame() override;
248
249   // OutputSurfaceClient implementation.
250   void DeferredInitialize() override;
251   void ReleaseGL() override;
252   void CommitVSyncParameters(base::TimeTicks timebase,
253                              base::TimeDelta interval) override;
254   void SetNeedsRedrawRect(const gfx::Rect& rect) override;
255   void BeginFrame(const BeginFrameArgs& args) override;
256
257   void SetExternalDrawConstraints(
258       const gfx::Transform& transform,
259       const gfx::Rect& viewport,
260       const gfx::Rect& clip,
261       const gfx::Rect& viewport_rect_for_tile_priority,
262       const gfx::Transform& transform_for_tile_priority,
263       bool resourceless_software_draw) override;
264   void DidLoseOutputSurface() override;
265   void DidSwapBuffers() override;
266   void DidSwapBuffersComplete() override;
267   void ReclaimResources(const CompositorFrameAck* ack) override;
268   void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override;
269   void SetTreeActivationCallback(const base::Closure& callback) override;
270
271   // Called from LayerTreeImpl.
272   void OnCanDrawStateChangedForTree();
273
274   // Implementation.
275   int id() const { return id_; }
276   bool CanDraw() const;
277   OutputSurface* output_surface() const { return output_surface_.get(); }
278
279   std::string LayerTreeAsJson() const;
280
281   void FinishAllRendering();
282   int SourceAnimationFrameNumber() const;
283
284   virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
285   TileManager* tile_manager() { return tile_manager_.get(); }
286   void SetUseGpuRasterization(bool use_gpu);
287   bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
288   bool create_low_res_tiling() const {
289     return settings_.create_low_res_tiling && !use_gpu_rasterization_;
290   }
291   ResourcePool* resource_pool() { return resource_pool_.get(); }
292   Renderer* renderer() { return renderer_.get(); }
293   const RendererCapabilitiesImpl& GetRendererCapabilities() const;
294
295   virtual bool SwapBuffers(const FrameData& frame);
296   virtual void WillBeginImplFrame(const BeginFrameArgs& args);
297   void DidModifyTilePriorities();
298
299   LayerTreeImpl* active_tree() { return active_tree_.get(); }
300   const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
301   LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
302   const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
303   LayerTreeImpl* recycle_tree() { return recycle_tree_.get(); }
304   const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
305   // Returns the tree LTH synchronizes with.
306   LayerTreeImpl* sync_tree() {
307     return pending_tree_ ? pending_tree_.get() : active_tree_.get();
308   }
309   virtual void CreatePendingTree();
310   virtual void UpdateVisibleTiles();
311   virtual void ActivateSyncTree();
312
313   // Shortcuts to layers on the active tree.
314   LayerImpl* RootLayer() const;
315   LayerImpl* InnerViewportScrollLayer() const;
316   LayerImpl* OuterViewportScrollLayer() const;
317   LayerImpl* CurrentlyScrollingLayer() const;
318
319   int scroll_layer_id_when_mouse_over_scrollbar() const {
320     return scroll_layer_id_when_mouse_over_scrollbar_;
321   }
322   bool scroll_affects_scroll_handler() const {
323     return scroll_affects_scroll_handler_;
324   }
325   void QueueSwapPromiseForMainThreadScrollUpdate(
326       scoped_ptr<SwapPromise> swap_promise);
327
328   bool IsActivelyScrolling() const;
329
330   virtual void SetVisible(bool visible);
331   bool visible() const { return visible_; }
332
333   void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
334   void SetNeedsRedraw();
335
336   ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
337
338   size_t memory_allocation_limit_bytes() const;
339   int memory_allocation_priority_cutoff() const;
340
341   void SetViewportSize(const gfx::Size& device_viewport_size);
342   gfx::Size device_viewport_size() const { return device_viewport_size_; }
343
344   void SetOverhangUIResource(UIResourceId overhang_ui_resource_id,
345                              const gfx::Size& overhang_ui_resource_size);
346
347   void SetDeviceScaleFactor(float device_scale_factor);
348   float device_scale_factor() const { return device_scale_factor_; }
349
350   const gfx::Transform& DrawTransform() const;
351
352   scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
353
354   bool needs_animate_layers() const {
355     return !animation_registrar_->active_animation_controllers().empty();
356   }
357
358   void set_max_memory_needed_bytes(size_t bytes) {
359     max_memory_needed_bytes_ = bytes;
360   }
361
362   FrameRateCounter* fps_counter() {
363     return fps_counter_.get();
364   }
365   PaintTimeCounter* paint_time_counter() {
366     return paint_time_counter_.get();
367   }
368   MemoryHistory* memory_history() {
369     return memory_history_.get();
370   }
371   DebugRectHistory* debug_rect_history() {
372     return debug_rect_history_.get();
373   }
374   ResourceProvider* resource_provider() {
375     return resource_provider_.get();
376   }
377   TopControlsManager* top_controls_manager() {
378     return top_controls_manager_.get();
379   }
380   const GlobalStateThatImpactsTilePriority& global_tile_state() {
381     return global_tile_state_;
382   }
383
384   Proxy* proxy() const { return proxy_; }
385
386   AnimationRegistrar* animation_registrar() const {
387     return animation_registrar_.get();
388   }
389
390   void SetDebugState(const LayerTreeDebugState& new_debug_state);
391   const LayerTreeDebugState& debug_state() const { return debug_state_; }
392
393   class CC_EXPORT CullRenderPassesWithNoQuads {
394    public:
395     bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
396                                 const FrameData& frame) const;
397
398     // Iterates in draw order, so that when a surface is removed, and its
399     // target becomes empty, then its target can be removed also.
400     size_t RenderPassListBegin(const RenderPassList& list) const { return 0; }
401     size_t RenderPassListEnd(const RenderPassList& list) const {
402       return list.size();
403     }
404     size_t RenderPassListNext(size_t it) const { return it + 1; }
405   };
406
407   template <typename RenderPassCuller>
408       static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame);
409
410   gfx::Vector2dF accumulated_root_overscroll() const {
411     return accumulated_root_overscroll_;
412   }
413
414   bool pinch_gesture_active() const { return pinch_gesture_active_; }
415
416   void SetTreePriority(TreePriority priority);
417   TreePriority GetTreePriority() const;
418
419   void UpdateCurrentBeginFrameArgs(const BeginFrameArgs& args);
420   void ResetCurrentBeginFrameArgsForNextFrame();
421   virtual BeginFrameArgs CurrentBeginFrameArgs() const;
422
423   // Expected time between two begin impl frame calls.
424   base::TimeDelta begin_impl_frame_interval() const {
425     return begin_impl_frame_interval_;
426   }
427
428   void AsValueInto(base::debug::TracedValue* value) const override;
429   void AsValueWithFrameInto(FrameData* frame,
430                             base::debug::TracedValue* value) const;
431   scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const;
432   scoped_refptr<base::debug::ConvertableToTraceFormat> AsValueWithFrame(
433       FrameData* frame) const;
434   scoped_refptr<base::debug::ConvertableToTraceFormat> ActivationStateAsValue()
435       const;
436   void ActivationStateAsValueInto(base::debug::TracedValue* value) const;
437
438   bool page_scale_animation_active() const { return !!page_scale_animation_; }
439
440   virtual void CreateUIResource(UIResourceId uid,
441                                 const UIResourceBitmap& bitmap);
442   // Deletes a UI resource.  May safely be called more than once.
443   virtual void DeleteUIResource(UIResourceId uid);
444   void EvictAllUIResources();
445   bool EvictedUIResourcesExist() const;
446
447   virtual ResourceProvider::ResourceId ResourceIdForUIResource(
448       UIResourceId uid) const;
449
450   virtual bool IsUIResourceOpaque(UIResourceId uid) const;
451
452   struct UIResourceData {
453     ResourceProvider::ResourceId resource_id;
454     gfx::Size size;
455     bool opaque;
456   };
457
458   void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark);
459
460   CompositorFrameMetadata MakeCompositorFrameMetadata() const;
461   // Viewport rectangle and clip in nonflipped window space.  These rects
462   // should only be used by Renderer subclasses to populate glViewport/glClip
463   // and their software-mode equivalents.
464   gfx::Rect DeviceViewport() const;
465   gfx::Rect DeviceClip() const;
466
467   // When a SwapPromiseMonitor is created on the impl thread, it calls
468   // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
469   // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
470   // to unregister itself.
471   void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
472   void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
473
474   void RegisterPictureLayerImpl(PictureLayerImpl* layer);
475   void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
476
477   void GetPictureLayerImplPairs(
478       std::vector<PictureLayerImpl::Pair>* layers) const;
479
480   void SetTopControlsLayoutHeight(float height);
481
482   void SetRequiresHighResToDraw() { requires_high_res_to_draw_ = true; }
483   void ResetRequiresHighResToDraw() { requires_high_res_to_draw_ = false; }
484   bool RequiresHighResToDraw() const { return requires_high_res_to_draw_; }
485
486   // Only valid for synchronous (non-scheduled) single-threaded case.
487   void SynchronouslyInitializeAllTiles();
488
489   bool CanUseZeroCopyRasterizer() const;
490   bool CanUseOneCopyRasterizer() const;
491   virtual void CreateResourceAndRasterWorkerPool(
492       scoped_ptr<RasterWorkerPool>* raster_worker_pool,
493       scoped_ptr<ResourcePool>* resource_pool,
494       scoped_ptr<ResourcePool>* staging_resource_pool);
495
496  protected:
497   LayerTreeHostImpl(
498       const LayerTreeSettings& settings,
499       LayerTreeHostImplClient* client,
500       Proxy* proxy,
501       RenderingStatsInstrumentation* rendering_stats_instrumentation,
502       SharedBitmapManager* shared_bitmap_manager,
503       gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
504       int id);
505
506   void UpdateViewportContainerSizes();
507
508   // Virtual for testing.
509   virtual void AnimateLayers(base::TimeTicks monotonic_time);
510   virtual base::TimeDelta LowFrequencyAnimationInterval() const;
511
512   const AnimationRegistrar::AnimationControllerMap&
513       active_animation_controllers() const {
514     return animation_registrar_->active_animation_controllers();
515   }
516
517   bool manage_tiles_needed() const { return tile_priorities_dirty_; }
518
519   LayerTreeHostImplClient* client_;
520   Proxy* proxy_;
521
522  private:
523   void CreateAndSetRenderer();
524   void CreateAndSetTileManager();
525   void DestroyTileManager();
526   void ReleaseTreeResources();
527   void EnforceZeroBudget(bool zero_budget);
528
529   bool UsePendingTreeForSync() const;
530   bool IsSynchronousSingleThreaded() const;
531
532   // Scroll by preferring to move the outer viewport first, only moving the
533   // inner if the outer is at its scroll extents.
534   void ScrollViewportBy(gfx::Vector2dF scroll_delta);
535   // Scroll by preferring to move the inner viewport first, only moving the
536   // outer if the inner is at its scroll extents.
537   void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta);
538   void AnimatePageScale(base::TimeTicks monotonic_time);
539   void AnimateScrollbars(base::TimeTicks monotonic_time);
540   void AnimateTopControls(base::TimeTicks monotonic_time);
541
542   bool ShouldTopControlsConsumeScroll(const gfx::Vector2dF& scroll_delta) const;
543
544   gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
545       LayerImpl* layer_impl,
546       float scale_from_viewport_to_screen_space,
547       const gfx::PointF& viewport_point,
548       const gfx::Vector2dF& viewport_delta);
549
550   void TrackDamageForAllSurfaces(
551       LayerImpl* root_draw_layer,
552       const LayerImplList& render_surface_layer_list);
553
554   void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
555
556   // This function should only be called from PrepareToDraw, as DidDrawAllLayers
557   // must be called if this helper function is called.  Returns DRAW_SUCCESS if
558   // the frame should be drawn.
559   DrawResult CalculateRenderPasses(FrameData* frame);
560
561   void ClearCurrentlyScrollingLayer();
562
563   bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
564                                 const gfx::PointF& device_viewport_point);
565
566   void AnimateScrollbarsRecursive(LayerImpl* layer,
567                                   base::TimeTicks time);
568
569   LayerImpl* FindScrollLayerForDeviceViewportPoint(
570       const gfx::PointF& device_viewport_point,
571       InputHandler::ScrollInputType type,
572       LayerImpl* layer_hit_by_point,
573       bool* scroll_on_main_thread,
574       bool* optional_has_ancestor_scroll_handler) const;
575   float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point,
576                                    LayerImpl* layer_impl);
577   void StartScrollbarFadeRecursive(LayerImpl* layer);
578   void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy,
579                               bool zero_budget);
580   void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
581
582   void DidInitializeVisibleTile();
583
584   void MarkUIResourceNotEvicted(UIResourceId uid);
585
586   void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
587   void NotifySwapPromiseMonitorsOfForwardingToMainThread();
588
589   typedef base::hash_map<UIResourceId, UIResourceData>
590       UIResourceMap;
591   UIResourceMap ui_resource_map_;
592
593   // Resources that were evicted by EvictAllUIResources. Resources are removed
594   // from this when they are touched by a create or destroy from the UI resource
595   // request queue.
596   std::set<UIResourceId> evicted_ui_resources_;
597
598   scoped_ptr<OutputSurface> output_surface_;
599
600   // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
601   // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
602   scoped_ptr<ResourceProvider> resource_provider_;
603   scoped_ptr<TileManager> tile_manager_;
604   bool use_gpu_rasterization_;
605   scoped_ptr<RasterWorkerPool> raster_worker_pool_;
606   scoped_ptr<ResourcePool> resource_pool_;
607   scoped_ptr<ResourcePool> staging_resource_pool_;
608   scoped_ptr<Renderer> renderer_;
609
610   GlobalStateThatImpactsTilePriority global_tile_state_;
611
612   // Tree currently being drawn.
613   scoped_ptr<LayerTreeImpl> active_tree_;
614
615   // In impl-side painting mode, tree with possibly incomplete rasterized
616   // content. May be promoted to active by ActivatePendingTree().
617   scoped_ptr<LayerTreeImpl> pending_tree_;
618
619   // In impl-side painting mode, inert tree with layers that can be recycled
620   // by the next sync from the main thread.
621   scoped_ptr<LayerTreeImpl> recycle_tree_;
622
623   InputHandlerClient* input_handler_client_;
624   bool did_lock_scrolling_layer_;
625   bool should_bubble_scrolls_;
626   bool wheel_scrolling_;
627   bool scroll_affects_scroll_handler_;
628   int scroll_layer_id_when_mouse_over_scrollbar_;
629   ScopedPtrVector<SwapPromise> swap_promises_for_main_thread_scroll_update_;
630
631   bool tile_priorities_dirty_;
632
633   // The optional delegate for the root layer scroll offset.
634   LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
635   LayerTreeSettings settings_;
636   LayerTreeDebugState debug_state_;
637   bool visible_;
638   ManagedMemoryPolicy cached_managed_memory_policy_;
639
640   gfx::Vector2dF accumulated_root_overscroll_;
641
642   bool pinch_gesture_active_;
643   bool pinch_gesture_end_should_clear_scrolling_layer_;
644   gfx::Point previous_pinch_anchor_;
645
646   scoped_ptr<TopControlsManager> top_controls_manager_;
647
648   scoped_ptr<PageScaleAnimation> page_scale_animation_;
649
650   // This is used for ticking animations slowly when hidden.
651   scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
652
653   scoped_ptr<FrameRateCounter> fps_counter_;
654   scoped_ptr<PaintTimeCounter> paint_time_counter_;
655   scoped_ptr<MemoryHistory> memory_history_;
656   scoped_ptr<DebugRectHistory> debug_rect_history_;
657
658   scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
659
660   // The maximum memory that would be used by the prioritized resource
661   // manager, if there were no limit on memory usage.
662   size_t max_memory_needed_bytes_;
663
664   bool zero_budget_;
665
666   // Viewport size passed in from the main thread, in physical pixels.  This
667   // value is the default size for all concepts of physical viewport (draw
668   // viewport, scrolling viewport and device viewport), but it can be
669   // overridden.
670   gfx::Size device_viewport_size_;
671
672   // Conversion factor from CSS pixels to physical pixels when
673   // pageScaleFactor=1.
674   float device_scale_factor_;
675
676   // UI resource to use for drawing overhang gutters.
677   UIResourceId overhang_ui_resource_id_;
678   gfx::Size overhang_ui_resource_size_;
679
680   // Optional top-level constraints that can be set by the OutputSurface.
681   // - external_transform_ applies a transform above the root layer
682   // - external_viewport_ is used DrawProperties, tile management and
683   // glViewport/window projection matrix.
684   // - external_clip_ specifies a top-level clip rect
685   // - viewport_rect_for_tile_priority_ is the rect in view space used for
686   // tiling priority.
687   gfx::Transform external_transform_;
688   gfx::Rect external_viewport_;
689   gfx::Rect external_clip_;
690   gfx::Rect viewport_rect_for_tile_priority_;
691   bool resourceless_software_draw_;
692
693   gfx::Rect viewport_damage_rect_;
694
695   BeginFrameArgs current_begin_frame_args_;
696
697   // Expected time between two begin impl frame calls.
698   base::TimeDelta begin_impl_frame_interval_;
699
700   scoped_ptr<AnimationRegistrar> animation_registrar_;
701
702   RenderingStatsInstrumentation* rendering_stats_instrumentation_;
703   MicroBenchmarkControllerImpl micro_benchmark_controller_;
704   scoped_ptr<TaskGraphRunner> single_thread_synchronous_task_graph_runner_;
705
706   bool need_to_update_visible_tiles_before_draw_;
707
708   // Optional callback to notify of new tree activations.
709   base::Closure tree_activation_callback_;
710
711   SharedBitmapManager* shared_bitmap_manager_;
712   gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
713   int id_;
714
715   std::set<SwapPromiseMonitor*> swap_promise_monitor_;
716
717   std::vector<PictureLayerImpl*> picture_layers_;
718   std::vector<PictureLayerImpl::Pair> picture_layer_pairs_;
719
720   bool requires_high_res_to_draw_;
721
722   DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
723 };
724
725 }  // namespace cc
726
727 #endif  // CC_TREES_LAYER_TREE_HOST_IMPL_H_