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.
5 #ifndef CC_TREES_LAYER_TREE_HOST_IMPL_H_
6 #define CC_TREES_LAYER_TREE_HOST_IMPL_H_
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"
42 class CompletionEvent;
43 class CompositorFrameMetadata;
44 class DebugRectHistory;
45 class EvictionTilePriorityQueue;
46 class FrameRateCounter;
48 class LayerTreeHostImplTimeSourceAdapter;
51 class PageScaleAnimation;
52 class PaintTimeCounter;
53 class PictureLayerImpl;
54 class RasterTilePriorityQueue;
55 class RasterWorkerPool;
56 class RenderPassDrawQuad;
57 class RenderingStatsInstrumentation;
59 class ScrollbarLayerImplBase;
60 class TextureMailboxDeleter;
61 class TopControlsManager;
62 class UIResourceBitmap;
63 class UIResourceRequest;
64 struct RendererCapabilitiesImpl;
66 // LayerTreeHost->Proxy callback interface.
67 class LayerTreeHostImplClient {
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
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(
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;
103 virtual ~LayerTreeHostImplClient() {}
106 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
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> {
118 static scoped_ptr<LayerTreeHostImpl> Create(
119 const LayerTreeSettings& settings,
120 LayerTreeHostImplClient* client,
122 RenderingStatsInstrumentation* rendering_stats_instrumentation,
123 SharedBitmapManager* shared_bitmap_manager,
124 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
126 ~LayerTreeHostImpl() override;
128 // BeginFrameSourceMixIn implementation
129 void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
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;
161 // TopControlsManagerClient implementation.
162 void SetControlsTopOffset(float offset) override;
163 float ControlsTopOffset() const override;
164 void DidChangeTopControlsPosition() override;
165 bool HaveRootScrollLayer() const override;
167 struct CC_EXPORT FrameData : public RenderPassSink {
169 ~FrameData() override;
170 void AsValueInto(base::debug::TracedValue* value) const;
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;
181 // RenderPassSink implementation.
182 void AppendRenderPass(scoped_ptr<RenderPass> render_pass) override;
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);
196 virtual void ManageTiles();
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);
207 const LayerTreeSettings& settings() const { return settings_; }
209 // Evict all textures by enforcing a memory policy with an allocation of 0.
210 void EvictTexturesForTesting();
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);
217 // This allows us to inject DidInitializeVisibleTile events for testing.
218 void DidInitializeVisibleTileForTesting();
220 // Resets all of the trees to an empty state.
221 void ResetTreesForTesting();
223 DrawMode GetDrawMode() const;
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;
229 // Viewport rect in view space used for tiling prioritization.
230 const gfx::Rect ViewportRectForTilePriority() const;
232 // RendererClient implementation.
233 void SetFullRootLayerDamage() override;
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;
244 // ScrollbarAnimationControllerClient implementation.
245 void PostDelayedScrollbarFade(const base::Closure& start_fade,
246 base::TimeDelta delay) override;
247 void SetNeedsScrollbarAnimationFrame() override;
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;
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;
271 // Called from LayerTreeImpl.
272 void OnCanDrawStateChangedForTree();
275 int id() const { return id_; }
276 bool CanDraw() const;
277 OutputSurface* output_surface() const { return output_surface_.get(); }
279 std::string LayerTreeAsJson() const;
281 void FinishAllRendering();
282 int SourceAnimationFrameNumber() const;
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_;
291 ResourcePool* resource_pool() { return resource_pool_.get(); }
292 Renderer* renderer() { return renderer_.get(); }
293 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
295 virtual bool SwapBuffers(const FrameData& frame);
296 virtual void WillBeginImplFrame(const BeginFrameArgs& args);
297 void DidModifyTilePriorities();
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();
309 virtual void CreatePendingTree();
310 virtual void UpdateVisibleTiles();
311 virtual void ActivateSyncTree();
313 // Shortcuts to layers on the active tree.
314 LayerImpl* RootLayer() const;
315 LayerImpl* InnerViewportScrollLayer() const;
316 LayerImpl* OuterViewportScrollLayer() const;
317 LayerImpl* CurrentlyScrollingLayer() const;
319 int scroll_layer_id_when_mouse_over_scrollbar() const {
320 return scroll_layer_id_when_mouse_over_scrollbar_;
322 bool scroll_affects_scroll_handler() const {
323 return scroll_affects_scroll_handler_;
325 void QueueSwapPromiseForMainThreadScrollUpdate(
326 scoped_ptr<SwapPromise> swap_promise);
328 bool IsActivelyScrolling() const;
330 virtual void SetVisible(bool visible);
331 bool visible() const { return visible_; }
333 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
334 void SetNeedsRedraw();
336 ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
338 size_t memory_allocation_limit_bytes() const;
339 int memory_allocation_priority_cutoff() const;
341 void SetViewportSize(const gfx::Size& device_viewport_size);
342 gfx::Size device_viewport_size() const { return device_viewport_size_; }
344 void SetOverhangUIResource(UIResourceId overhang_ui_resource_id,
345 const gfx::Size& overhang_ui_resource_size);
347 void SetDeviceScaleFactor(float device_scale_factor);
348 float device_scale_factor() const { return device_scale_factor_; }
350 const gfx::Transform& DrawTransform() const;
352 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
354 bool needs_animate_layers() const {
355 return !animation_registrar_->active_animation_controllers().empty();
358 void set_max_memory_needed_bytes(size_t bytes) {
359 max_memory_needed_bytes_ = bytes;
362 FrameRateCounter* fps_counter() {
363 return fps_counter_.get();
365 PaintTimeCounter* paint_time_counter() {
366 return paint_time_counter_.get();
368 MemoryHistory* memory_history() {
369 return memory_history_.get();
371 DebugRectHistory* debug_rect_history() {
372 return debug_rect_history_.get();
374 ResourceProvider* resource_provider() {
375 return resource_provider_.get();
377 TopControlsManager* top_controls_manager() {
378 return top_controls_manager_.get();
380 const GlobalStateThatImpactsTilePriority& global_tile_state() {
381 return global_tile_state_;
384 Proxy* proxy() const { return proxy_; }
386 AnimationRegistrar* animation_registrar() const {
387 return animation_registrar_.get();
390 void SetDebugState(const LayerTreeDebugState& new_debug_state);
391 const LayerTreeDebugState& debug_state() const { return debug_state_; }
393 class CC_EXPORT CullRenderPassesWithNoQuads {
395 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
396 const FrameData& frame) const;
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 {
404 size_t RenderPassListNext(size_t it) const { return it + 1; }
407 template <typename RenderPassCuller>
408 static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame);
410 gfx::Vector2dF accumulated_root_overscroll() const {
411 return accumulated_root_overscroll_;
414 bool pinch_gesture_active() const { return pinch_gesture_active_; }
416 void SetTreePriority(TreePriority priority);
417 TreePriority GetTreePriority() const;
419 void UpdateCurrentBeginFrameArgs(const BeginFrameArgs& args);
420 void ResetCurrentBeginFrameArgsForNextFrame();
421 virtual BeginFrameArgs CurrentBeginFrameArgs() const;
423 // Expected time between two begin impl frame calls.
424 base::TimeDelta begin_impl_frame_interval() const {
425 return begin_impl_frame_interval_;
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()
436 void ActivationStateAsValueInto(base::debug::TracedValue* value) const;
438 bool page_scale_animation_active() const { return !!page_scale_animation_; }
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;
447 virtual ResourceProvider::ResourceId ResourceIdForUIResource(
448 UIResourceId uid) const;
450 virtual bool IsUIResourceOpaque(UIResourceId uid) const;
452 struct UIResourceData {
453 ResourceProvider::ResourceId resource_id;
458 void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark);
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;
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);
474 void RegisterPictureLayerImpl(PictureLayerImpl* layer);
475 void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
477 void GetPictureLayerImplPairs(
478 std::vector<PictureLayerImpl::Pair>* layers) const;
480 void SetTopControlsLayoutHeight(float height);
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_; }
486 // Only valid for synchronous (non-scheduled) single-threaded case.
487 void SynchronouslyInitializeAllTiles();
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);
498 const LayerTreeSettings& settings,
499 LayerTreeHostImplClient* client,
501 RenderingStatsInstrumentation* rendering_stats_instrumentation,
502 SharedBitmapManager* shared_bitmap_manager,
503 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
506 void UpdateViewportContainerSizes();
508 // Virtual for testing.
509 virtual void AnimateLayers(base::TimeTicks monotonic_time);
510 virtual base::TimeDelta LowFrequencyAnimationInterval() const;
512 const AnimationRegistrar::AnimationControllerMap&
513 active_animation_controllers() const {
514 return animation_registrar_->active_animation_controllers();
517 bool manage_tiles_needed() const { return tile_priorities_dirty_; }
519 LayerTreeHostImplClient* client_;
523 void CreateAndSetRenderer();
524 void CreateAndSetTileManager();
525 void DestroyTileManager();
526 void ReleaseTreeResources();
527 void EnforceZeroBudget(bool zero_budget);
529 bool UsePendingTreeForSync() const;
530 bool IsSynchronousSingleThreaded() const;
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);
542 bool ShouldTopControlsConsumeScroll(const gfx::Vector2dF& scroll_delta) const;
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);
550 void TrackDamageForAllSurfaces(
551 LayerImpl* root_draw_layer,
552 const LayerImplList& render_surface_layer_list);
554 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
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);
561 void ClearCurrentlyScrollingLayer();
563 bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
564 const gfx::PointF& device_viewport_point);
566 void AnimateScrollbarsRecursive(LayerImpl* layer,
567 base::TimeTicks time);
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,
580 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
582 void DidInitializeVisibleTile();
584 void MarkUIResourceNotEvicted(UIResourceId uid);
586 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
587 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
589 typedef base::hash_map<UIResourceId, UIResourceData>
591 UIResourceMap ui_resource_map_;
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
596 std::set<UIResourceId> evicted_ui_resources_;
598 scoped_ptr<OutputSurface> output_surface_;
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_;
610 GlobalStateThatImpactsTilePriority global_tile_state_;
612 // Tree currently being drawn.
613 scoped_ptr<LayerTreeImpl> active_tree_;
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_;
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_;
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_;
631 bool tile_priorities_dirty_;
633 // The optional delegate for the root layer scroll offset.
634 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
635 LayerTreeSettings settings_;
636 LayerTreeDebugState debug_state_;
638 ManagedMemoryPolicy cached_managed_memory_policy_;
640 gfx::Vector2dF accumulated_root_overscroll_;
642 bool pinch_gesture_active_;
643 bool pinch_gesture_end_should_clear_scrolling_layer_;
644 gfx::Point previous_pinch_anchor_;
646 scoped_ptr<TopControlsManager> top_controls_manager_;
648 scoped_ptr<PageScaleAnimation> page_scale_animation_;
650 // This is used for ticking animations slowly when hidden.
651 scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
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_;
658 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
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_;
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
670 gfx::Size device_viewport_size_;
672 // Conversion factor from CSS pixels to physical pixels when
673 // pageScaleFactor=1.
674 float device_scale_factor_;
676 // UI resource to use for drawing overhang gutters.
677 UIResourceId overhang_ui_resource_id_;
678 gfx::Size overhang_ui_resource_size_;
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
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_;
693 gfx::Rect viewport_damage_rect_;
695 BeginFrameArgs current_begin_frame_args_;
697 // Expected time between two begin impl frame calls.
698 base::TimeDelta begin_impl_frame_interval_;
700 scoped_ptr<AnimationRegistrar> animation_registrar_;
702 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
703 MicroBenchmarkControllerImpl micro_benchmark_controller_;
704 scoped_ptr<TaskGraphRunner> single_thread_synchronous_task_graph_runner_;
706 bool need_to_update_visible_tiles_before_draw_;
708 // Optional callback to notify of new tree activations.
709 base::Closure tree_activation_callback_;
711 SharedBitmapManager* shared_bitmap_manager_;
712 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
715 std::set<SwapPromiseMonitor*> swap_promise_monitor_;
717 std::vector<PictureLayerImpl*> picture_layers_;
718 std::vector<PictureLayerImpl::Pair> picture_layer_pairs_;
720 bool requires_high_res_to_draw_;
722 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
727 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_