Home | History | Annotate | Download | only in trees
      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 SetNeedsAnimate() OVERRIDE;
    149   virtual bool IsCurrentlyScrollingLayerAt(
    150       const gfx::Point& viewport_point,
    151       InputHandler::ScrollInputType type) OVERRIDE;
    152   virtual bool HaveTouchEventHandlersAt(
    153       const gfx::Point& viewport_port) OVERRIDE;
    154   virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
    155       ui::LatencyInfo* latency) OVERRIDE;
    156 
    157   // TopControlsManagerClient implementation.
    158   virtual void SetControlsTopOffset(float offset) OVERRIDE;
    159   virtual float ControlsTopOffset() const OVERRIDE;
    160   virtual void DidChangeTopControlsPosition() OVERRIDE;
    161   virtual bool HaveRootScrollLayer() const OVERRIDE;
    162 
    163   struct CC_EXPORT FrameData : public RenderPassSink {
    164     FrameData();
    165     virtual ~FrameData();
    166     void AsValueInto(base::debug::TracedValue* value) const;
    167 
    168     std::vector<gfx::Rect> occluding_screen_space_rects;
    169     std::vector<gfx::Rect> non_occluding_screen_space_rects;
    170     RenderPassList render_passes;
    171     RenderPassIdHashMap render_passes_by_id;
    172     const LayerImplList* render_surface_layer_list;
    173     LayerImplList will_draw_layers;
    174     bool contains_incomplete_tile;
    175     bool has_no_damage;
    176 
    177     // RenderPassSink implementation.
    178     virtual void AppendRenderPass(scoped_ptr<RenderPass> render_pass) OVERRIDE;
    179   };
    180 
    181   virtual void BeginMainFrameAborted(bool did_handle);
    182   virtual void BeginCommit();
    183   virtual void CommitComplete();
    184   virtual void Animate(base::TimeTicks monotonic_time);
    185   virtual void UpdateAnimationState(bool start_ready_animations);
    186   void ActivateAnimations();
    187   void MainThreadHasStoppedFlinging();
    188   void UpdateBackgroundAnimateTicking(bool should_background_tick);
    189   void DidAnimateScrollOffset();
    190   void SetViewportDamage(const gfx::Rect& damage_rect);
    191 
    192   virtual void ManageTiles();
    193 
    194   // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
    195   // should try to avoid displaying the frame. If PrepareToDraw is called,
    196   // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
    197   // called between the two.
    198   virtual DrawResult PrepareToDraw(FrameData* frame);
    199   virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
    200   // Must be called if and only if PrepareToDraw was called.
    201   void DidDrawAllLayers(const FrameData& frame);
    202 
    203   const LayerTreeSettings& settings() const { return settings_; }
    204 
    205   // Evict all textures by enforcing a memory policy with an allocation of 0.
    206   void EvictTexturesForTesting();
    207 
    208   // When blocking, this prevents client_->NotifyReadyToActivate() from being
    209   // called. When disabled, it calls client_->NotifyReadyToActivate()
    210   // immediately if any notifications had been blocked while blocking.
    211   virtual void BlockNotifyReadyToActivateForTesting(bool block);
    212 
    213   // This allows us to inject DidInitializeVisibleTile events for testing.
    214   void DidInitializeVisibleTileForTesting();
    215 
    216   // Resets all of the trees to an empty state.
    217   void ResetTreesForTesting();
    218   void ResetRecycleTreeForTesting();
    219 
    220   DrawMode GetDrawMode() const;
    221 
    222   // Viewport size in draw space: this size is in physical pixels and is used
    223   // for draw properties, tilings, quads and render passes.
    224   gfx::Size DrawViewportSize() const;
    225 
    226   // Viewport rect in view space used for tiling prioritization.
    227   const gfx::Rect ViewportRectForTilePriority() const;
    228 
    229   // RendererClient implementation.
    230   virtual void SetFullRootLayerDamage() OVERRIDE;
    231 
    232   // TileManagerClient implementation.
    233   virtual const std::vector<PictureLayerImpl*>& GetPictureLayers()
    234       const OVERRIDE;
    235   virtual void NotifyReadyToActivate() OVERRIDE;
    236   virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE;
    237   virtual void BuildRasterQueue(RasterTilePriorityQueue* queue,
    238                                 TreePriority tree_priority) OVERRIDE;
    239   virtual void BuildEvictionQueue(EvictionTilePriorityQueue* queue,
    240                                   TreePriority tree_priority) OVERRIDE;
    241 
    242   // ScrollbarAnimationControllerClient implementation.
    243   virtual void PostDelayedScrollbarFade(const base::Closure& start_fade,
    244                                         base::TimeDelta delay) OVERRIDE;
    245   virtual void SetNeedsScrollbarAnimationFrame() OVERRIDE;
    246 
    247   // OutputSurfaceClient implementation.
    248   virtual void DeferredInitialize() OVERRIDE;
    249   virtual void ReleaseGL() OVERRIDE;
    250   virtual void CommitVSyncParameters(base::TimeTicks timebase,
    251                                      base::TimeDelta interval) OVERRIDE;
    252   virtual void SetNeedsRedrawRect(const gfx::Rect& rect) OVERRIDE;
    253   virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE;
    254 
    255   virtual void SetExternalDrawConstraints(
    256       const gfx::Transform& transform,
    257       const gfx::Rect& viewport,
    258       const gfx::Rect& clip,
    259       const gfx::Rect& viewport_rect_for_tile_priority,
    260       const gfx::Transform& transform_for_tile_priority,
    261       bool resourceless_software_draw) OVERRIDE;
    262   virtual void DidLoseOutputSurface() OVERRIDE;
    263   virtual void DidSwapBuffers() OVERRIDE;
    264   virtual void DidSwapBuffersComplete() OVERRIDE;
    265   virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE;
    266   virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE;
    267   virtual void SetTreeActivationCallback(const base::Closure& callback)
    268       OVERRIDE;
    269 
    270   // Called from LayerTreeImpl.
    271   void OnCanDrawStateChangedForTree();
    272 
    273   // Implementation.
    274   int id() const { return id_; }
    275   bool CanDraw() const;
    276   OutputSurface* output_surface() const { return output_surface_.get(); }
    277 
    278   std::string LayerTreeAsJson() const;
    279 
    280   void FinishAllRendering();
    281   int SourceAnimationFrameNumber() const;
    282 
    283   virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
    284   TileManager* tile_manager() { return tile_manager_.get(); }
    285   void SetUseGpuRasterization(bool use_gpu);
    286   bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
    287   bool create_low_res_tiling() const {
    288     return settings_.create_low_res_tiling && !use_gpu_rasterization_;
    289   }
    290   ResourcePool* resource_pool() { return resource_pool_.get(); }
    291   Renderer* renderer() { return renderer_.get(); }
    292   const RendererCapabilitiesImpl& GetRendererCapabilities() const;
    293 
    294   virtual bool SwapBuffers(const FrameData& frame);
    295   void SetNeedsBeginFrame(bool enable);
    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 
    418   void UpdateCurrentBeginFrameArgs(const BeginFrameArgs& args);
    419   void ResetCurrentBeginFrameArgsForNextFrame();
    420   virtual BeginFrameArgs CurrentBeginFrameArgs() const;
    421 
    422   // Expected time between two begin impl frame calls.
    423   base::TimeDelta begin_impl_frame_interval() const {
    424     return begin_impl_frame_interval_;
    425   }
    426 
    427   void AsValueInto(base::debug::TracedValue* value) const {
    428     return AsValueWithFrameInto(NULL, value);
    429   }
    430   void AsValueWithFrameInto(FrameData* frame,
    431                             base::debug::TracedValue* value) const;
    432   scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const;
    433   scoped_refptr<base::debug::ConvertableToTraceFormat> AsValueWithFrame(
    434       FrameData* frame) const;
    435   scoped_refptr<base::debug::ConvertableToTraceFormat> ActivationStateAsValue()
    436       const;
    437   void ActivationStateAsValueInto(base::debug::TracedValue* value) const;
    438 
    439   bool page_scale_animation_active() const { return !!page_scale_animation_; }
    440 
    441   virtual void CreateUIResource(UIResourceId uid,
    442                                 const UIResourceBitmap& bitmap);
    443   // Deletes a UI resource.  May safely be called more than once.
    444   virtual void DeleteUIResource(UIResourceId uid);
    445   void EvictAllUIResources();
    446   bool EvictedUIResourcesExist() const;
    447 
    448   virtual ResourceProvider::ResourceId ResourceIdForUIResource(
    449       UIResourceId uid) const;
    450 
    451   virtual bool IsUIResourceOpaque(UIResourceId uid) const;
    452 
    453   struct UIResourceData {
    454     ResourceProvider::ResourceId resource_id;
    455     gfx::Size size;
    456     bool opaque;
    457   };
    458 
    459   void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark);
    460 
    461   CompositorFrameMetadata MakeCompositorFrameMetadata() const;
    462   // Viewport rectangle and clip in nonflipped window space.  These rects
    463   // should only be used by Renderer subclasses to populate glViewport/glClip
    464   // and their software-mode equivalents.
    465   gfx::Rect DeviceViewport() const;
    466   gfx::Rect DeviceClip() const;
    467 
    468   // When a SwapPromiseMonitor is created on the impl thread, it calls
    469   // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
    470   // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
    471   // to unregister itself.
    472   void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
    473   void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
    474 
    475   void RegisterPictureLayerImpl(PictureLayerImpl* layer);
    476   void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
    477 
    478   void GetPictureLayerImplPairs(
    479       std::vector<PictureLayerImpl::Pair>* layers) const;
    480 
    481   void SetTopControlsLayoutHeight(float height);
    482 
    483  protected:
    484   LayerTreeHostImpl(
    485       const LayerTreeSettings& settings,
    486       LayerTreeHostImplClient* client,
    487       Proxy* proxy,
    488       RenderingStatsInstrumentation* rendering_stats_instrumentation,
    489       SharedBitmapManager* manager,
    490       int id);
    491 
    492   void UpdateInnerViewportContainerSize();
    493 
    494   // Virtual for testing.
    495   virtual void AnimateLayers(base::TimeTicks monotonic_time);
    496 
    497   // Virtual for testing.
    498   virtual base::TimeDelta LowFrequencyAnimationInterval() const;
    499 
    500   const AnimationRegistrar::AnimationControllerMap&
    501       active_animation_controllers() const {
    502     return animation_registrar_->active_animation_controllers();
    503   }
    504 
    505   bool manage_tiles_needed() const { return tile_priorities_dirty_; }
    506 
    507   LayerTreeHostImplClient* client_;
    508   Proxy* proxy_;
    509 
    510  private:
    511   void CreateAndSetRenderer();
    512   void CreateAndSetTileManager();
    513   void DestroyTileManager();
    514   void ReleaseTreeResources();
    515   void EnforceZeroBudget(bool zero_budget);
    516 
    517   bool UsePendingTreeForSync() const;
    518   bool UseZeroCopyRasterizer() const;
    519   bool UseOneCopyRasterizer() const;
    520 
    521   void ScrollViewportBy(gfx::Vector2dF scroll_delta);
    522   void AnimatePageScale(base::TimeTicks monotonic_time);
    523   void AnimateScrollbars(base::TimeTicks monotonic_time);
    524   void AnimateTopControls(base::TimeTicks monotonic_time);
    525 
    526   gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
    527       LayerImpl* layer_impl,
    528       float scale_from_viewport_to_screen_space,
    529       const gfx::PointF& viewport_point,
    530       const gfx::Vector2dF& viewport_delta);
    531 
    532   void TrackDamageForAllSurfaces(
    533       LayerImpl* root_draw_layer,
    534       const LayerImplList& render_surface_layer_list);
    535 
    536   void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
    537 
    538   // This function should only be called from PrepareToDraw, as DidDrawAllLayers
    539   // must be called if this helper function is called.  Returns DRAW_SUCCESS if
    540   // the frame should be drawn.
    541   DrawResult CalculateRenderPasses(FrameData* frame);
    542 
    543   void ClearCurrentlyScrollingLayer();
    544 
    545   bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
    546                                 const gfx::PointF& device_viewport_point);
    547 
    548   void AnimateScrollbarsRecursive(LayerImpl* layer,
    549                                   base::TimeTicks time);
    550 
    551   LayerImpl* FindScrollLayerForDeviceViewportPoint(
    552       const gfx::PointF& device_viewport_point,
    553       InputHandler::ScrollInputType type,
    554       LayerImpl* layer_hit_by_point,
    555       bool* scroll_on_main_thread,
    556       bool* optional_has_ancestor_scroll_handler) const;
    557   float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point,
    558                                    LayerImpl* layer_impl);
    559   void StartScrollbarFadeRecursive(LayerImpl* layer);
    560   void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy,
    561                               bool zero_budget);
    562   void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
    563 
    564   void DidInitializeVisibleTile();
    565 
    566   void MarkUIResourceNotEvicted(UIResourceId uid);
    567 
    568   void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
    569   void NotifySwapPromiseMonitorsOfForwardingToMainThread();
    570 
    571   typedef base::hash_map<UIResourceId, UIResourceData>
    572       UIResourceMap;
    573   UIResourceMap ui_resource_map_;
    574 
    575   // Resources that were evicted by EvictAllUIResources. Resources are removed
    576   // from this when they are touched by a create or destroy from the UI resource
    577   // request queue.
    578   std::set<UIResourceId> evicted_ui_resources_;
    579 
    580   scoped_ptr<OutputSurface> output_surface_;
    581 
    582   // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
    583   // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
    584   scoped_ptr<ResourceProvider> resource_provider_;
    585   scoped_ptr<TileManager> tile_manager_;
    586   bool use_gpu_rasterization_;
    587   scoped_ptr<RasterWorkerPool> raster_worker_pool_;
    588   scoped_ptr<ResourcePool> resource_pool_;
    589   scoped_ptr<ResourcePool> staging_resource_pool_;
    590   scoped_ptr<Renderer> renderer_;
    591 
    592   GlobalStateThatImpactsTilePriority global_tile_state_;
    593 
    594   // Tree currently being drawn.
    595   scoped_ptr<LayerTreeImpl> active_tree_;
    596 
    597   // In impl-side painting mode, tree with possibly incomplete rasterized
    598   // content. May be promoted to active by ActivatePendingTree().
    599   scoped_ptr<LayerTreeImpl> pending_tree_;
    600 
    601   // In impl-side painting mode, inert tree with layers that can be recycled
    602   // by the next sync from the main thread.
    603   scoped_ptr<LayerTreeImpl> recycle_tree_;
    604 
    605   InputHandlerClient* input_handler_client_;
    606   bool did_lock_scrolling_layer_;
    607   bool should_bubble_scrolls_;
    608   bool wheel_scrolling_;
    609   bool scroll_affects_scroll_handler_;
    610   int scroll_layer_id_when_mouse_over_scrollbar_;
    611   ScopedPtrVector<SwapPromise> swap_promises_for_main_thread_scroll_update_;
    612 
    613   bool tile_priorities_dirty_;
    614 
    615   // The optional delegate for the root layer scroll offset.
    616   LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
    617   LayerTreeSettings settings_;
    618   LayerTreeDebugState debug_state_;
    619   bool visible_;
    620   ManagedMemoryPolicy cached_managed_memory_policy_;
    621 
    622   gfx::Vector2dF accumulated_root_overscroll_;
    623 
    624   bool pinch_gesture_active_;
    625   bool pinch_gesture_end_should_clear_scrolling_layer_;
    626   gfx::Point previous_pinch_anchor_;
    627 
    628   scoped_ptr<TopControlsManager> top_controls_manager_;
    629 
    630   scoped_ptr<PageScaleAnimation> page_scale_animation_;
    631 
    632   // This is used for ticking animations slowly when hidden.
    633   scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
    634 
    635   scoped_ptr<FrameRateCounter> fps_counter_;
    636   scoped_ptr<PaintTimeCounter> paint_time_counter_;
    637   scoped_ptr<MemoryHistory> memory_history_;
    638   scoped_ptr<DebugRectHistory> debug_rect_history_;
    639 
    640   scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
    641 
    642   // The maximum memory that would be used by the prioritized resource
    643   // manager, if there were no limit on memory usage.
    644   size_t max_memory_needed_bytes_;
    645 
    646   bool zero_budget_;
    647 
    648   // Viewport size passed in from the main thread, in physical pixels.  This
    649   // value is the default size for all concepts of physical viewport (draw
    650   // viewport, scrolling viewport and device viewport), but it can be
    651   // overridden.
    652   gfx::Size device_viewport_size_;
    653 
    654   // Conversion factor from CSS pixels to physical pixels when
    655   // pageScaleFactor=1.
    656   float device_scale_factor_;
    657 
    658   // UI resource to use for drawing overhang gutters.
    659   UIResourceId overhang_ui_resource_id_;
    660   gfx::Size overhang_ui_resource_size_;
    661 
    662   // Optional top-level constraints that can be set by the OutputSurface.
    663   // - external_transform_ applies a transform above the root layer
    664   // - external_viewport_ is used DrawProperties, tile management and
    665   // glViewport/window projection matrix.
    666   // - external_clip_ specifies a top-level clip rect
    667   // - viewport_rect_for_tile_priority_ is the rect in view space used for
    668   // tiling priority.
    669   gfx::Transform external_transform_;
    670   gfx::Rect external_viewport_;
    671   gfx::Rect external_clip_;
    672   gfx::Rect viewport_rect_for_tile_priority_;
    673   bool resourceless_software_draw_;
    674 
    675   gfx::Rect viewport_damage_rect_;
    676 
    677   BeginFrameArgs current_begin_frame_args_;
    678 
    679   // Expected time between two begin impl frame calls.
    680   base::TimeDelta begin_impl_frame_interval_;
    681 
    682   scoped_ptr<AnimationRegistrar> animation_registrar_;
    683 
    684   RenderingStatsInstrumentation* rendering_stats_instrumentation_;
    685   MicroBenchmarkControllerImpl micro_benchmark_controller_;
    686 
    687   bool need_to_update_visible_tiles_before_draw_;
    688 
    689   // Optional callback to notify of new tree activations.
    690   base::Closure tree_activation_callback_;
    691 
    692   SharedBitmapManager* shared_bitmap_manager_;
    693   int id_;
    694 
    695   std::set<SwapPromiseMonitor*> swap_promise_monitor_;
    696 
    697   std::vector<PictureLayerImpl*> picture_layers_;
    698   std::vector<PictureLayerImpl::Pair> picture_layer_pairs_;
    699 
    700   DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
    701 };
    702 
    703 }  // namespace cc
    704 
    705 #endif  // CC_TREES_LAYER_TREE_HOST_IMPL_H_
    706