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/draw_result.h"
35 #include "skia/ext/refptr.h"
36 #include "third_party/skia/include/core/SkColor.h"
37 #include "ui/gfx/rect.h"
41 class CompletionEvent;
42 class CompositorFrameMetadata;
43 class DebugRectHistory;
44 class EvictionTilePriorityQueue;
45 class FrameRateCounter;
47 class LayerTreeHostImplTimeSourceAdapter;
50 class PageScaleAnimation;
51 class PaintTimeCounter;
52 class PictureLayerImpl;
53 class RasterTilePriorityQueue;
54 class RasterWorkerPool;
55 class RenderPassDrawQuad;
56 class RenderingStatsInstrumentation;
58 class ScrollbarLayerImplBase;
59 class TextureMailboxDeleter;
60 class TopControlsManager;
61 class UIResourceBitmap;
62 class UIResourceRequest;
63 struct RendererCapabilitiesImpl;
65 // LayerTreeHost->Proxy callback interface.
66 class LayerTreeHostImplClient {
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
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 base::SupportsWeakPtr<LayerTreeHostImpl> {
117 static scoped_ptr<LayerTreeHostImpl> Create(
118 const LayerTreeSettings& settings,
119 LayerTreeHostImplClient* client,
121 RenderingStatsInstrumentation* rendering_stats_instrumentation,
122 SharedBitmapManager* manager,
124 virtual ~LayerTreeHostImpl();
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,
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;
161 // TopControlsManagerClient implementation.
162 virtual void DidChangeTopControlsPosition() OVERRIDE;
163 virtual bool HaveRootScrollLayer() const OVERRIDE;
165 struct CC_EXPORT FrameData : public RenderPassSink {
167 virtual ~FrameData();
168 void AsValueInto(base::debug::TracedValue* value) const;
170 std::vector<gfx::Rect> occluding_screen_space_rects;
171 std::vector<gfx::Rect> non_occluding_screen_space_rects;
172 RenderPassList render_passes;
173 RenderPassIdHashMap render_passes_by_id;
174 const LayerImplList* render_surface_layer_list;
175 LayerImplList will_draw_layers;
176 bool contains_incomplete_tile;
179 // RenderPassSink implementation.
180 virtual void AppendRenderPass(scoped_ptr<RenderPass> render_pass) OVERRIDE;
183 virtual void BeginMainFrameAborted(bool did_handle);
184 virtual void BeginCommit();
185 virtual void CommitComplete();
186 virtual void Animate(base::TimeTicks monotonic_time);
187 virtual void UpdateAnimationState(bool start_ready_animations);
188 void ActivateAnimations();
189 void MainThreadHasStoppedFlinging();
190 void UpdateBackgroundAnimateTicking(bool should_background_tick);
191 void DidAnimateScrollOffset();
192 void SetViewportDamage(const gfx::Rect& damage_rect);
194 virtual void ManageTiles();
196 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
197 // should try to avoid displaying the frame. If PrepareToDraw is called,
198 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
199 // called between the two.
200 virtual DrawResult PrepareToDraw(FrameData* frame);
201 virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
202 // Must be called if and only if PrepareToDraw was called.
203 void DidDrawAllLayers(const FrameData& frame);
205 const LayerTreeSettings& settings() const { return settings_; }
207 // Evict all textures by enforcing a memory policy with an allocation of 0.
208 void EvictTexturesForTesting();
210 // When blocking, this prevents client_->NotifyReadyToActivate() from being
211 // called. When disabled, it calls client_->NotifyReadyToActivate()
212 // immediately if any notifications had been blocked while blocking.
213 virtual void BlockNotifyReadyToActivateForTesting(bool block);
215 // This allows us to inject DidInitializeVisibleTile events for testing.
216 void DidInitializeVisibleTileForTesting();
218 // Resets all of the trees to an empty state.
219 void ResetTreesForTesting();
220 void ResetRecycleTreeForTesting();
222 DrawMode GetDrawMode() const;
224 // Viewport size in draw space: this size is in physical pixels and is used
225 // for draw properties, tilings, quads and render passes.
226 gfx::Size DrawViewportSize() const;
228 // Viewport rect in view space used for tiling prioritization.
229 const gfx::Rect ViewportRectForTilePriority() const;
231 // Viewport size for scrolling and fixed-position compensation. This value
232 // excludes the URL bar and non-overlay scrollbars and is in DIP (and
233 // invariant relative to page scale).
234 gfx::SizeF UnscaledScrollableViewportSize() const;
235 float VerticalAdjust() const;
237 // RendererClient implementation.
238 virtual void SetFullRootLayerDamage() OVERRIDE;
239 virtual void RunOnDemandRasterTask(Task* on_demand_raster_task) OVERRIDE;
241 // TileManagerClient implementation.
242 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers()
244 virtual void NotifyReadyToActivate() OVERRIDE;
245 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE;
246 virtual void BuildRasterQueue(RasterTilePriorityQueue* queue,
247 TreePriority tree_priority) OVERRIDE;
248 virtual void BuildEvictionQueue(EvictionTilePriorityQueue* queue,
249 TreePriority tree_priority) OVERRIDE;
251 // ScrollbarAnimationControllerClient implementation.
252 virtual void PostDelayedScrollbarFade(const base::Closure& start_fade,
253 base::TimeDelta delay) OVERRIDE;
254 virtual void SetNeedsScrollbarAnimationFrame() OVERRIDE;
256 // OutputSurfaceClient implementation.
257 virtual void DeferredInitialize() OVERRIDE;
258 virtual void ReleaseGL() OVERRIDE;
259 virtual void CommitVSyncParameters(base::TimeTicks timebase,
260 base::TimeDelta interval) OVERRIDE;
261 virtual void SetNeedsRedrawRect(const gfx::Rect& rect) OVERRIDE;
262 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE;
264 virtual void SetExternalDrawConstraints(
265 const gfx::Transform& transform,
266 const gfx::Rect& viewport,
267 const gfx::Rect& clip,
268 const gfx::Rect& viewport_rect_for_tile_priority,
269 const gfx::Transform& transform_for_tile_priority,
270 bool resourceless_software_draw) OVERRIDE;
271 virtual void DidLoseOutputSurface() OVERRIDE;
272 virtual void DidSwapBuffers() OVERRIDE;
273 virtual void DidSwapBuffersComplete() OVERRIDE;
274 virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE;
275 virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE;
276 virtual void SetTreeActivationCallback(const base::Closure& callback)
279 // Called from LayerTreeImpl.
280 void OnCanDrawStateChangedForTree();
283 int id() const { return id_; }
284 bool CanDraw() const;
285 OutputSurface* output_surface() const { return output_surface_.get(); }
287 std::string LayerTreeAsJson() const;
289 void FinishAllRendering();
290 int SourceAnimationFrameNumber() const;
292 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
293 bool IsContextLost();
294 TileManager* tile_manager() { return tile_manager_.get(); }
295 void SetUseGpuRasterization(bool use_gpu);
296 bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
297 bool create_low_res_tiling() const {
298 return settings_.create_low_res_tiling && !use_gpu_rasterization_;
300 ResourcePool* resource_pool() { return resource_pool_.get(); }
301 Renderer* renderer() { return renderer_.get(); }
302 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
304 virtual bool SwapBuffers(const FrameData& frame);
305 void SetNeedsBeginFrame(bool enable);
306 virtual void WillBeginImplFrame(const BeginFrameArgs& args);
307 void DidModifyTilePriorities();
309 LayerTreeImpl* active_tree() { return active_tree_.get(); }
310 const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
311 LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
312 const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
313 LayerTreeImpl* recycle_tree() { return recycle_tree_.get(); }
314 const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
315 // Returns the tree LTH synchronizes with.
316 LayerTreeImpl* sync_tree() {
317 return pending_tree_ ? pending_tree_.get() : active_tree_.get();
319 virtual void CreatePendingTree();
320 virtual void UpdateVisibleTiles();
321 virtual void ActivateSyncTree();
323 // Shortcuts to layers on the active tree.
324 LayerImpl* RootLayer() const;
325 LayerImpl* InnerViewportScrollLayer() const;
326 LayerImpl* OuterViewportScrollLayer() const;
327 LayerImpl* CurrentlyScrollingLayer() const;
329 int scroll_layer_id_when_mouse_over_scrollbar() const {
330 return scroll_layer_id_when_mouse_over_scrollbar_;
332 bool scroll_affects_scroll_handler() const {
333 return scroll_affects_scroll_handler_;
335 void QueueSwapPromiseForMainThreadScrollUpdate(
336 scoped_ptr<SwapPromise> swap_promise);
338 bool IsCurrentlyScrolling() const;
340 virtual void SetVisible(bool visible);
341 bool visible() const { return visible_; }
343 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
344 void SetNeedsRedraw();
346 ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
348 size_t memory_allocation_limit_bytes() const;
349 int memory_allocation_priority_cutoff() const;
351 void SetViewportSize(const gfx::Size& device_viewport_size);
352 gfx::Size device_viewport_size() const { return device_viewport_size_; }
354 void SetOverdrawBottomHeight(float overdraw_bottom_height);
355 float overdraw_bottom_height() const { return overdraw_bottom_height_; }
357 void SetOverhangUIResource(UIResourceId overhang_ui_resource_id,
358 const gfx::Size& overhang_ui_resource_size);
360 void SetDeviceScaleFactor(float device_scale_factor);
361 float device_scale_factor() const { return device_scale_factor_; }
363 const gfx::Transform& DrawTransform() const;
365 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
367 bool needs_animate_layers() const {
368 return !animation_registrar_->active_animation_controllers().empty();
371 void set_max_memory_needed_bytes(size_t bytes) {
372 max_memory_needed_bytes_ = bytes;
375 FrameRateCounter* fps_counter() {
376 return fps_counter_.get();
378 PaintTimeCounter* paint_time_counter() {
379 return paint_time_counter_.get();
381 MemoryHistory* memory_history() {
382 return memory_history_.get();
384 DebugRectHistory* debug_rect_history() {
385 return debug_rect_history_.get();
387 ResourceProvider* resource_provider() {
388 return resource_provider_.get();
390 TopControlsManager* top_controls_manager() {
391 return top_controls_manager_.get();
393 const GlobalStateThatImpactsTilePriority& global_tile_state() {
394 return global_tile_state_;
397 Proxy* proxy() const { return proxy_; }
399 AnimationRegistrar* animation_registrar() const {
400 return animation_registrar_.get();
403 void SetDebugState(const LayerTreeDebugState& new_debug_state);
404 const LayerTreeDebugState& debug_state() const { return debug_state_; }
406 class CC_EXPORT CullRenderPassesWithNoQuads {
408 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
409 const FrameData& frame) const;
411 // Iterates in draw order, so that when a surface is removed, and its
412 // target becomes empty, then its target can be removed also.
413 size_t RenderPassListBegin(const RenderPassList& list) const { return 0; }
414 size_t RenderPassListEnd(const RenderPassList& list) const {
417 size_t RenderPassListNext(size_t it) const { return it + 1; }
420 template <typename RenderPassCuller>
421 static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame);
423 gfx::Vector2dF accumulated_root_overscroll() const {
424 return accumulated_root_overscroll_;
427 bool pinch_gesture_active() const { return pinch_gesture_active_; }
429 void SetTreePriority(TreePriority priority);
431 void UpdateCurrentFrameTime();
432 void ResetCurrentFrameTimeForNextFrame();
433 virtual base::TimeTicks CurrentFrameTimeTicks();
435 // Expected time between two begin impl frame calls.
436 base::TimeDelta begin_impl_frame_interval() const {
437 return begin_impl_frame_interval_;
440 void AsValueInto(base::debug::TracedValue* value) const {
441 return AsValueWithFrameInto(NULL, value);
443 void AsValueWithFrameInto(FrameData* frame,
444 base::debug::TracedValue* value) const;
445 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const;
446 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValueWithFrame(
447 FrameData* frame) const;
448 scoped_refptr<base::debug::ConvertableToTraceFormat> ActivationStateAsValue()
450 void ActivationStateAsValueInto(base::debug::TracedValue* value) const;
452 bool page_scale_animation_active() const { return !!page_scale_animation_; }
454 virtual void CreateUIResource(UIResourceId uid,
455 const UIResourceBitmap& bitmap);
456 // Deletes a UI resource. May safely be called more than once.
457 virtual void DeleteUIResource(UIResourceId uid);
458 void EvictAllUIResources();
459 bool EvictedUIResourcesExist() const;
461 virtual ResourceProvider::ResourceId ResourceIdForUIResource(
462 UIResourceId uid) const;
464 virtual bool IsUIResourceOpaque(UIResourceId uid) const;
466 struct UIResourceData {
467 ResourceProvider::ResourceId resource_id;
472 void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark);
474 CompositorFrameMetadata MakeCompositorFrameMetadata() const;
475 // Viewport rectangle and clip in nonflipped window space. These rects
476 // should only be used by Renderer subclasses to populate glViewport/glClip
477 // and their software-mode equivalents.
478 gfx::Rect DeviceViewport() const;
479 gfx::Rect DeviceClip() const;
481 // When a SwapPromiseMonitor is created on the impl thread, it calls
482 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
483 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
484 // to unregister itself.
485 void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
486 void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
488 void RegisterPictureLayerImpl(PictureLayerImpl* layer);
489 void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
491 void GetPictureLayerImplPairs(
492 std::vector<PictureLayerImpl::Pair>* layers) const;
496 const LayerTreeSettings& settings,
497 LayerTreeHostImplClient* client,
499 RenderingStatsInstrumentation* rendering_stats_instrumentation,
500 SharedBitmapManager* manager,
503 gfx::SizeF ComputeInnerViewportContainerSize() const;
504 void UpdateInnerViewportContainerSize();
506 // Virtual for testing.
507 virtual void AnimateLayers(base::TimeTicks monotonic_time);
509 // Virtual for testing.
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 UseZeroCopyTextureUpload() const;
531 bool UseOneCopyTextureUpload() const;
533 void ScrollViewportBy(gfx::Vector2dF scroll_delta);
534 void AnimatePageScale(base::TimeTicks monotonic_time);
535 void AnimateScrollbars(base::TimeTicks monotonic_time);
536 void AnimateTopControls(base::TimeTicks monotonic_time);
538 gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
539 LayerImpl* layer_impl,
540 float scale_from_viewport_to_screen_space,
541 const gfx::PointF& viewport_point,
542 const gfx::Vector2dF& viewport_delta);
544 void TrackDamageForAllSurfaces(
545 LayerImpl* root_draw_layer,
546 const LayerImplList& render_surface_layer_list);
548 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
550 // This function should only be called from PrepareToDraw, as DidDrawAllLayers
551 // must be called if this helper function is called. Returns DRAW_SUCCESS if
552 // the frame should be drawn.
553 DrawResult CalculateRenderPasses(FrameData* frame);
555 void ClearCurrentlyScrollingLayer();
557 bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
558 const gfx::PointF& device_viewport_point);
560 void AnimateScrollbarsRecursive(LayerImpl* layer,
561 base::TimeTicks time);
563 LayerImpl* FindScrollLayerForDeviceViewportPoint(
564 const gfx::PointF& device_viewport_point,
565 InputHandler::ScrollInputType type,
566 LayerImpl* layer_hit_by_point,
567 bool* scroll_on_main_thread,
568 bool* optional_has_ancestor_scroll_handler) const;
569 float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point,
570 LayerImpl* layer_impl);
571 void StartScrollbarFadeRecursive(LayerImpl* layer);
572 void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy,
574 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
576 void DidInitializeVisibleTile();
578 void MarkUIResourceNotEvicted(UIResourceId uid);
580 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
581 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
583 typedef base::hash_map<UIResourceId, UIResourceData>
585 UIResourceMap ui_resource_map_;
587 // Resources that were evicted by EvictAllUIResources. Resources are removed
588 // from this when they are touched by a create or destroy from the UI resource
590 std::set<UIResourceId> evicted_ui_resources_;
592 scoped_ptr<OutputSurface> output_surface_;
593 scoped_refptr<ContextProvider> offscreen_context_provider_;
595 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
596 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
597 scoped_ptr<ResourceProvider> resource_provider_;
598 scoped_ptr<TileManager> tile_manager_;
599 bool use_gpu_rasterization_;
600 scoped_ptr<RasterWorkerPool> raster_worker_pool_;
601 scoped_ptr<ResourcePool> resource_pool_;
602 scoped_ptr<ResourcePool> staging_resource_pool_;
603 scoped_ptr<Renderer> renderer_;
605 TaskGraphRunner synchronous_task_graph_runner_;
606 TaskGraphRunner* on_demand_task_graph_runner_;
607 NamespaceToken on_demand_task_namespace_;
609 GlobalStateThatImpactsTilePriority global_tile_state_;
611 // Tree currently being drawn.
612 scoped_ptr<LayerTreeImpl> active_tree_;
614 // In impl-side painting mode, tree with possibly incomplete rasterized
615 // content. May be promoted to active by ActivatePendingTree().
616 scoped_ptr<LayerTreeImpl> pending_tree_;
618 // In impl-side painting mode, inert tree with layers that can be recycled
619 // by the next sync from the main thread.
620 scoped_ptr<LayerTreeImpl> recycle_tree_;
622 InputHandlerClient* input_handler_client_;
623 bool did_lock_scrolling_layer_;
624 bool should_bubble_scrolls_;
625 bool wheel_scrolling_;
626 bool scroll_affects_scroll_handler_;
627 int scroll_layer_id_when_mouse_over_scrollbar_;
628 ScopedPtrVector<SwapPromise> swap_promises_for_main_thread_scroll_update_;
630 bool tile_priorities_dirty_;
632 // The optional delegate for the root layer scroll offset.
633 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
634 LayerTreeSettings settings_;
635 LayerTreeDebugState debug_state_;
637 ManagedMemoryPolicy cached_managed_memory_policy_;
639 gfx::Vector2dF accumulated_root_overscroll_;
641 bool pinch_gesture_active_;
642 bool pinch_gesture_end_should_clear_scrolling_layer_;
643 gfx::Point previous_pinch_anchor_;
645 scoped_ptr<TopControlsManager> top_controls_manager_;
647 scoped_ptr<PageScaleAnimation> page_scale_animation_;
649 // This is used for ticking animations slowly when hidden.
650 scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
652 scoped_ptr<FrameRateCounter> fps_counter_;
653 scoped_ptr<PaintTimeCounter> paint_time_counter_;
654 scoped_ptr<MemoryHistory> memory_history_;
655 scoped_ptr<DebugRectHistory> debug_rect_history_;
657 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
659 // The maximum memory that would be used by the prioritized resource
660 // manager, if there were no limit on memory usage.
661 size_t max_memory_needed_bytes_;
665 // Viewport size passed in from the main thread, in physical pixels. This
666 // value is the default size for all concepts of physical viewport (draw
667 // viewport, scrolling viewport and device viewport), but it can be
669 gfx::Size device_viewport_size_;
671 // Conversion factor from CSS pixels to physical pixels when
672 // pageScaleFactor=1.
673 float device_scale_factor_;
675 // UI resource to use for drawing overhang gutters.
676 UIResourceId overhang_ui_resource_id_;
677 gfx::Size overhang_ui_resource_size_;
679 // Vertical amount of the viewport size that's known to covered by a
680 // browser-side UI element, such as an on-screen-keyboard. This affects
681 // scrollable size since we want to still be able to scroll to the bottom of
682 // the page when the keyboard is up.
683 float overdraw_bottom_height_;
685 // Optional top-level constraints that can be set by the OutputSurface.
686 // - external_transform_ applies a transform above the root layer
687 // - external_viewport_ is used DrawProperties, tile management and
688 // glViewport/window projection matrix.
689 // - external_clip_ specifies a top-level clip rect
690 // - viewport_rect_for_tile_priority_ is the rect in view space used for
692 gfx::Transform external_transform_;
693 gfx::Rect external_viewport_;
694 gfx::Rect external_clip_;
695 gfx::Rect viewport_rect_for_tile_priority_;
696 bool resourceless_software_draw_;
698 gfx::Rect viewport_damage_rect_;
700 base::TimeTicks current_frame_timeticks_;
702 // Expected time between two begin impl frame calls.
703 base::TimeDelta begin_impl_frame_interval_;
705 scoped_ptr<AnimationRegistrar> animation_registrar_;
707 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
708 MicroBenchmarkControllerImpl micro_benchmark_controller_;
710 bool need_to_update_visible_tiles_before_draw_;
711 bool have_valid_output_surface_;
713 // Optional callback to notify of new tree activations.
714 base::Closure tree_activation_callback_;
716 SharedBitmapManager* shared_bitmap_manager_;
719 std::set<SwapPromiseMonitor*> swap_promise_monitor_;
721 size_t transfer_buffer_memory_limit_;
723 std::vector<PictureLayerImpl*> picture_layers_;
724 std::vector<PictureLayerImpl::Pair> picture_layer_pairs_;
726 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
731 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_