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