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_
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/time/time.h"
16 #include "cc/animation/animation_events.h"
17 #include "cc/animation/animation_registrar.h"
18 #include "cc/animation/scrollbar_animation_controller.h"
19 #include "cc/base/cc_export.h"
20 #include "cc/base/synced_property.h"
21 #include "cc/debug/frame_timing_tracker.h"
22 #include "cc/debug/micro_benchmark_controller_impl.h"
23 #include "cc/input/input_handler.h"
24 #include "cc/input/layer_scroll_offset_delegate.h"
25 #include "cc/input/top_controls_manager_client.h"
26 #include "cc/layers/layer_lists.h"
27 #include "cc/layers/render_pass_sink.h"
28 #include "cc/output/begin_frame_args.h"
29 #include "cc/output/managed_memory_policy.h"
30 #include "cc/output/output_surface_client.h"
31 #include "cc/output/renderer.h"
32 #include "cc/quads/render_pass.h"
33 #include "cc/resources/resource_provider.h"
34 #include "cc/resources/tile_manager.h"
35 #include "cc/resources/ui_resource_client.h"
36 #include "cc/scheduler/commit_earlyout_reason.h"
37 #include "cc/scheduler/draw_result.h"
38 #include "cc/trees/layer_tree_settings.h"
39 #include "cc/trees/proxy.h"
40 #include "skia/ext/refptr.h"
41 #include "third_party/skia/include/core/SkColor.h"
42 #include "ui/gfx/geometry/rect.h"
50 class CompletionEvent
;
51 class CompositorFrameMetadata
;
52 class DebugRectHistory
;
53 class EvictionTilePriorityQueue
;
54 class FrameRateCounter
;
58 class PageScaleAnimation
;
59 class PaintTimeCounter
;
60 class PictureLayerImpl
;
61 class RasterTilePriorityQueue
;
62 class TileTaskWorkerPool
;
63 class RenderPassDrawQuad
;
64 class RenderingStatsInstrumentation
;
66 class ScrollElasticityHelper
;
67 class ScrollbarLayerImplBase
;
69 class SwapPromiseMonitor
;
70 class TextureMailboxDeleter
;
71 class TopControlsManager
;
72 class UIResourceBitmap
;
73 class UIResourceRequest
;
74 struct ScrollAndScaleSet
;
77 enum class GpuRasterizationStatus
{
85 // LayerTreeHost->Proxy callback interface.
86 class LayerTreeHostImplClient
{
88 virtual void UpdateRendererCapabilitiesOnImplThread() = 0;
89 virtual void DidLoseOutputSurfaceOnImplThread() = 0;
90 virtual void CommitVSyncParameters(base::TimeTicks timebase
,
91 base::TimeDelta interval
) = 0;
92 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time
) = 0;
93 virtual void SetMaxSwapsPendingOnImplThread(int max
) = 0;
94 virtual void DidSwapBuffersOnImplThread() = 0;
95 virtual void DidSwapBuffersCompleteOnImplThread() = 0;
96 virtual void OnCanDrawStateChanged(bool can_draw
) = 0;
97 virtual void NotifyReadyToActivate() = 0;
98 virtual void NotifyReadyToDraw() = 0;
99 // Please call these 3 functions through
100 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
101 // SetNeedsAnimate().
102 virtual void SetNeedsRedrawOnImplThread() = 0;
103 virtual void SetNeedsRedrawRectOnImplThread(const gfx::Rect
& damage_rect
) = 0;
104 virtual void SetNeedsAnimateOnImplThread() = 0;
105 virtual void SetNeedsCommitOnImplThread() = 0;
106 virtual void SetNeedsPrepareTilesOnImplThread() = 0;
107 virtual void PostAnimationEventsToMainThreadOnImplThread(
108 scoped_ptr
<AnimationEventsVector
> events
) = 0;
109 // Returns true if resources were deleted by this call.
110 virtual bool ReduceContentsTextureMemoryOnImplThread(
112 int priority_cutoff
) = 0;
113 virtual bool IsInsideDraw() = 0;
114 virtual void RenewTreePriority() = 0;
115 virtual void PostDelayedAnimationTaskOnImplThread(const base::Closure
& task
,
116 base::TimeDelta delay
) = 0;
117 virtual void DidActivateSyncTree() = 0;
118 virtual void DidPrepareTiles() = 0;
120 // Called when page scale animation has completed on the impl thread.
121 virtual void DidCompletePageScaleAnimationOnImplThread() = 0;
123 // Called when output surface asks for a draw.
124 virtual void OnDrawForOutputSurface() = 0;
127 virtual ~LayerTreeHostImplClient() {}
130 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
132 class CC_EXPORT LayerTreeHostImpl
133 : public InputHandler
,
134 public RendererClient
,
135 public TileManagerClient
,
136 public OutputSurfaceClient
,
137 public TopControlsManagerClient
,
138 public ScrollbarAnimationControllerClient
,
139 public base::SupportsWeakPtr
<LayerTreeHostImpl
> {
141 static scoped_ptr
<LayerTreeHostImpl
> Create(
142 const LayerTreeSettings
& settings
,
143 LayerTreeHostImplClient
* client
,
145 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
146 SharedBitmapManager
* shared_bitmap_manager
,
147 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
148 TaskGraphRunner
* task_graph_runner
,
150 ~LayerTreeHostImpl() override
;
152 // InputHandler implementation
153 void BindToClient(InputHandlerClient
* client
) override
;
154 InputHandler::ScrollStatus
ScrollBegin(
155 const gfx::Point
& viewport_point
,
156 InputHandler::ScrollInputType type
) override
;
157 InputHandler::ScrollStatus
ScrollAnimated(
158 const gfx::Point
& viewport_point
,
159 const gfx::Vector2dF
& scroll_delta
) override
;
160 InputHandlerScrollResult
ScrollBy(
161 const gfx::Point
& viewport_point
,
162 const gfx::Vector2dF
& scroll_delta
) override
;
163 bool ScrollVerticallyByPage(const gfx::Point
& viewport_point
,
164 ScrollDirection direction
) override
;
165 void SetRootLayerScrollOffsetDelegate(
166 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
) override
;
167 void OnRootLayerDelegatedScrollOffsetChanged() override
;
168 void ScrollEnd() override
;
169 InputHandler::ScrollStatus
FlingScrollBegin() override
;
170 void MouseMoveAt(const gfx::Point
& viewport_point
) override
;
171 void PinchGestureBegin() override
;
172 void PinchGestureUpdate(float magnify_delta
,
173 const gfx::Point
& anchor
) override
;
174 void PinchGestureEnd() override
;
175 void StartPageScaleAnimation(const gfx::Vector2d
& target_offset
,
178 base::TimeDelta duration
);
179 void SetNeedsAnimate() override
;
180 bool IsCurrentlyScrollingLayerAt(const gfx::Point
& viewport_point
,
181 InputHandler::ScrollInputType type
) override
;
182 bool HaveWheelEventHandlersAt(const gfx::Point
& viewport_point
) override
;
183 bool DoTouchEventsBlockScrollAt(const gfx::Point
& viewport_port
) override
;
184 scoped_ptr
<SwapPromiseMonitor
> CreateLatencyInfoSwapPromiseMonitor(
185 ui::LatencyInfo
* latency
) override
;
186 ScrollElasticityHelper
* CreateScrollElasticityHelper() override
;
188 // TopControlsManagerClient implementation.
189 float TopControlsHeight() const override
;
190 void SetCurrentTopControlsShownRatio(float offset
) override
;
191 float CurrentTopControlsShownRatio() const override
;
192 void DidChangeTopControlsPosition() override
;
193 bool HaveRootScrollLayer() const override
;
195 void UpdateViewportContainerSizes();
197 struct CC_EXPORT FrameData
: public RenderPassSink
{
199 ~FrameData() override
;
200 void AsValueInto(base::trace_event::TracedValue
* value
) const;
202 std::vector
<gfx::Rect
> occluding_screen_space_rects
;
203 std::vector
<gfx::Rect
> non_occluding_screen_space_rects
;
204 std::vector
<FrameTimingTracker::FrameAndRectIds
> composite_events
;
205 RenderPassList render_passes
;
206 RenderPassIdHashMap render_passes_by_id
;
207 const LayerImplList
* render_surface_layer_list
;
208 LayerImplList will_draw_layers
;
211 // RenderPassSink implementation.
212 void AppendRenderPass(scoped_ptr
<RenderPass
> render_pass
) override
;
215 virtual void BeginMainFrameAborted(CommitEarlyOutReason reason
);
216 virtual void BeginCommit();
217 virtual void CommitComplete();
218 virtual void Animate(base::TimeTicks monotonic_time
);
219 virtual void UpdateAnimationState(bool start_ready_animations
);
220 void ActivateAnimations();
221 void MainThreadHasStoppedFlinging();
222 void DidAnimateScrollOffset();
223 void SetViewportDamage(const gfx::Rect
& damage_rect
);
225 virtual void PrepareTiles();
227 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
228 // should try to avoid displaying the frame. If PrepareToDraw is called,
229 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
230 // called between the two.
231 virtual DrawResult
PrepareToDraw(FrameData
* frame
);
232 virtual void DrawLayers(FrameData
* frame
, base::TimeTicks frame_begin_time
);
233 // Must be called if and only if PrepareToDraw was called.
234 void DidDrawAllLayers(const FrameData
& frame
);
236 const LayerTreeSettings
& settings() const { return settings_
; }
238 // Evict all textures by enforcing a memory policy with an allocation of 0.
239 void EvictTexturesForTesting();
241 // When blocking, this prevents client_->NotifyReadyToActivate() from being
242 // called. When disabled, it calls client_->NotifyReadyToActivate()
243 // immediately if any notifications had been blocked while blocking.
244 virtual void BlockNotifyReadyToActivateForTesting(bool block
);
246 // Resets all of the trees to an empty state.
247 void ResetTreesForTesting();
249 DrawMode
GetDrawMode() const;
251 // Viewport size in draw space: this size is in physical pixels and is used
252 // for draw properties, tilings, quads and render passes.
253 gfx::Size
DrawViewportSize() const;
255 // Viewport rect in view space used for tiling prioritization.
256 const gfx::Rect
ViewportRectForTilePriority() const;
258 // RendererClient implementation.
259 void SetFullRootLayerDamage() override
;
261 // TileManagerClient implementation.
262 void NotifyReadyToActivate() override
;
263 void NotifyReadyToDraw() override
;
264 void NotifyTileStateChanged(const Tile
* tile
) override
;
265 scoped_ptr
<RasterTilePriorityQueue
> BuildRasterQueue(
266 TreePriority tree_priority
,
267 RasterTilePriorityQueue::Type type
) override
;
268 scoped_ptr
<EvictionTilePriorityQueue
> BuildEvictionQueue(
269 TreePriority tree_priority
) override
;
270 void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw
) override
;
272 // ScrollbarAnimationControllerClient implementation.
273 void StartAnimatingScrollbarAnimationController(
274 ScrollbarAnimationController
* controller
) override
;
275 void StopAnimatingScrollbarAnimationController(
276 ScrollbarAnimationController
* controller
) override
;
277 void PostDelayedScrollbarAnimationTask(const base::Closure
& task
,
278 base::TimeDelta delay
) override
;
279 void SetNeedsRedrawForScrollbarAnimation() override
;
281 // OutputSurfaceClient implementation.
282 void DeferredInitialize() override
;
283 void ReleaseGL() override
;
284 void CommitVSyncParameters(base::TimeTicks timebase
,
285 base::TimeDelta interval
) override
;
286 void SetNeedsRedrawRect(const gfx::Rect
& rect
) override
;
287 void SetExternalDrawConstraints(
288 const gfx::Transform
& transform
,
289 const gfx::Rect
& viewport
,
290 const gfx::Rect
& clip
,
291 const gfx::Rect
& viewport_rect_for_tile_priority
,
292 const gfx::Transform
& transform_for_tile_priority
,
293 bool resourceless_software_draw
) override
;
294 void DidLoseOutputSurface() override
;
295 void DidSwapBuffers() override
;
296 void DidSwapBuffersComplete() override
;
297 void ReclaimResources(const CompositorFrameAck
* ack
) override
;
298 void SetMemoryPolicy(const ManagedMemoryPolicy
& policy
) override
;
299 void SetTreeActivationCallback(const base::Closure
& callback
) override
;
300 void OnDraw() override
;
302 // Called from LayerTreeImpl.
303 void OnCanDrawStateChangedForTree();
306 int id() const { return id_
; }
307 bool CanDraw() const;
308 OutputSurface
* output_surface() const { return output_surface_
.get(); }
310 std::string
LayerTreeAsJson() const;
312 void FinishAllRendering();
313 int SourceAnimationFrameNumber() const;
315 virtual bool InitializeRenderer(scoped_ptr
<OutputSurface
> output_surface
);
316 TileManager
* tile_manager() { return tile_manager_
.get(); }
317 void SetUseGpuRasterization(bool use_gpu
);
318 bool use_gpu_rasterization() const { return use_gpu_rasterization_
; }
320 GpuRasterizationStatus
gpu_rasterization_status() const {
321 return gpu_rasterization_status_
;
323 void set_gpu_rasterization_status(
324 GpuRasterizationStatus gpu_rasterization_status
) {
325 gpu_rasterization_status_
= gpu_rasterization_status
;
328 bool create_low_res_tiling() const {
329 return settings_
.create_low_res_tiling
&& !use_gpu_rasterization_
;
331 ResourcePool
* resource_pool() { return resource_pool_
.get(); }
332 Renderer
* renderer() { return renderer_
.get(); }
333 const RendererCapabilitiesImpl
& GetRendererCapabilities() const;
335 virtual bool SwapBuffers(const FrameData
& frame
);
336 virtual void WillBeginImplFrame(const BeginFrameArgs
& args
);
337 void DidModifyTilePriorities();
339 LayerTreeImpl
* active_tree() { return active_tree_
.get(); }
340 const LayerTreeImpl
* active_tree() const { return active_tree_
.get(); }
341 LayerTreeImpl
* pending_tree() { return pending_tree_
.get(); }
342 const LayerTreeImpl
* pending_tree() const { return pending_tree_
.get(); }
343 LayerTreeImpl
* recycle_tree() { return recycle_tree_
.get(); }
344 const LayerTreeImpl
* recycle_tree() const { return recycle_tree_
.get(); }
345 // Returns the tree LTH synchronizes with.
346 LayerTreeImpl
* sync_tree() {
347 // TODO(enne): This is bogus. It should return based on the value of
348 // Proxy::CommitToActiveTree and not whether the pending tree exists.
349 return pending_tree_
? pending_tree_
.get() : active_tree_
.get();
351 virtual void CreatePendingTree();
352 virtual void ActivateSyncTree();
354 // Shortcuts to layers on the active tree.
355 LayerImpl
* RootLayer() const;
356 LayerImpl
* InnerViewportScrollLayer() const;
357 LayerImpl
* OuterViewportScrollLayer() const;
358 LayerImpl
* CurrentlyScrollingLayer() const;
360 int scroll_layer_id_when_mouse_over_scrollbar() const {
361 return scroll_layer_id_when_mouse_over_scrollbar_
;
363 bool scroll_affects_scroll_handler() const {
364 return scroll_affects_scroll_handler_
;
366 void QueueSwapPromiseForMainThreadScrollUpdate(
367 scoped_ptr
<SwapPromise
> swap_promise
);
369 bool IsActivelyScrolling() const;
371 virtual void SetVisible(bool visible
);
372 bool visible() const { return visible_
; }
374 bool AnimationsAreVisible() { return visible() && CanDraw(); }
376 void SetNeedsCommit() { client_
->SetNeedsCommitOnImplThread(); }
377 void SetNeedsRedraw();
379 ManagedMemoryPolicy
ActualManagedMemoryPolicy() const;
381 size_t memory_allocation_limit_bytes() const;
382 int memory_allocation_priority_cutoff() const;
384 void SetViewportSize(const gfx::Size
& device_viewport_size
);
385 gfx::Size
device_viewport_size() const { return device_viewport_size_
; }
387 void SetDeviceScaleFactor(float device_scale_factor
);
388 float device_scale_factor() const { return device_scale_factor_
; }
390 void SetPageScaleOnActiveTree(float page_scale_factor
);
392 const gfx::Transform
& DrawTransform() const;
394 scoped_ptr
<ScrollAndScaleSet
> ProcessScrollDeltas();
396 void set_max_memory_needed_bytes(size_t bytes
) {
397 max_memory_needed_bytes_
= bytes
;
400 FrameRateCounter
* fps_counter() {
401 return fps_counter_
.get();
403 PaintTimeCounter
* paint_time_counter() {
404 return paint_time_counter_
.get();
406 MemoryHistory
* memory_history() {
407 return memory_history_
.get();
409 DebugRectHistory
* debug_rect_history() {
410 return debug_rect_history_
.get();
412 ResourceProvider
* resource_provider() {
413 return resource_provider_
.get();
415 TopControlsManager
* top_controls_manager() {
416 return top_controls_manager_
.get();
418 const GlobalStateThatImpactsTilePriority
& global_tile_state() {
419 return global_tile_state_
;
422 Proxy
* proxy() const { return proxy_
; }
424 AnimationRegistrar
* animation_registrar() const {
425 return animation_registrar_
.get();
428 void SetDebugState(const LayerTreeDebugState
& new_debug_state
);
429 const LayerTreeDebugState
& debug_state() const { return debug_state_
; }
431 class CC_EXPORT CullRenderPassesWithNoQuads
{
433 bool ShouldRemoveRenderPass(const RenderPassDrawQuad
& quad
,
434 const FrameData
& frame
) const;
436 // Iterates in draw order, so that when a surface is removed, and its
437 // target becomes empty, then its target can be removed also.
438 size_t RenderPassListBegin(const RenderPassList
& list
) const { return 0; }
439 size_t RenderPassListEnd(const RenderPassList
& list
) const {
442 size_t RenderPassListNext(size_t it
) const { return it
+ 1; }
445 template <typename RenderPassCuller
>
446 static void RemoveRenderPasses(RenderPassCuller culler
, FrameData
* frame
);
448 gfx::Vector2dF
accumulated_root_overscroll() const {
449 return accumulated_root_overscroll_
;
452 bool pinch_gesture_active() const { return pinch_gesture_active_
; }
454 void SetTreePriority(TreePriority priority
);
455 TreePriority
GetTreePriority() const;
457 void UpdateCurrentBeginFrameArgs(const BeginFrameArgs
& args
);
458 void ResetCurrentBeginFrameArgsForNextFrame();
459 virtual BeginFrameArgs
CurrentBeginFrameArgs() const;
461 // Expected time between two begin impl frame calls.
462 base::TimeDelta
begin_impl_frame_interval() const {
463 return begin_impl_frame_interval_
;
466 void AsValueWithFrameInto(FrameData
* frame
,
467 base::trace_event::TracedValue
* value
) const;
468 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValueWithFrame(
469 FrameData
* frame
) const;
470 void ActivationStateAsValueInto(base::trace_event::TracedValue
* value
) const;
472 bool page_scale_animation_active() const { return !!page_scale_animation_
; }
474 virtual void CreateUIResource(UIResourceId uid
,
475 const UIResourceBitmap
& bitmap
);
476 // Deletes a UI resource. May safely be called more than once.
477 virtual void DeleteUIResource(UIResourceId uid
);
478 void EvictAllUIResources();
479 bool EvictedUIResourcesExist() const;
481 virtual ResourceProvider::ResourceId
ResourceIdForUIResource(
482 UIResourceId uid
) const;
484 virtual bool IsUIResourceOpaque(UIResourceId uid
) const;
486 struct UIResourceData
{
487 ResourceProvider::ResourceId resource_id
;
492 void ScheduleMicroBenchmark(scoped_ptr
<MicroBenchmarkImpl
> benchmark
);
494 CompositorFrameMetadata
MakeCompositorFrameMetadata() const;
495 // Viewport rectangle and clip in nonflipped window space. These rects
496 // should only be used by Renderer subclasses to populate glViewport/glClip
497 // and their software-mode equivalents.
498 gfx::Rect
DeviceViewport() const;
499 gfx::Rect
DeviceClip() const;
501 // When a SwapPromiseMonitor is created on the impl thread, it calls
502 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
503 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
504 // to unregister itself.
505 void InsertSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
506 void RemoveSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
508 void GetPictureLayerImplPairs(std::vector
<PictureLayerImpl::Pair
>* layers
,
509 bool need_valid_tile_priorities
) const;
511 // TODO(weiliangc): Replace RequiresHighResToDraw with scheduler waits for
512 // ReadyToDraw. crbug.com/469175
513 void SetRequiresHighResToDraw() { requires_high_res_to_draw_
= true; }
514 void ResetRequiresHighResToDraw() { requires_high_res_to_draw_
= false; }
515 bool RequiresHighResToDraw() const { return requires_high_res_to_draw_
; }
517 // Only valid for synchronous (non-scheduled) single-threaded case.
518 void SynchronouslyInitializeAllTiles();
520 virtual void CreateResourceAndTileTaskWorkerPool(
521 scoped_ptr
<TileTaskWorkerPool
>* tile_task_worker_pool
,
522 scoped_ptr
<ResourcePool
>* resource_pool
,
523 scoped_ptr
<ResourcePool
>* staging_resource_pool
);
525 bool prepare_tiles_needed() const { return tile_priorities_dirty_
; }
527 FrameTimingTracker
* frame_timing_tracker() {
528 return frame_timing_tracker_
.get();
531 gfx::Vector2dF
ScrollLayer(LayerImpl
* layer_impl
,
532 const gfx::Vector2dF
& delta
,
533 const gfx::Point
& viewport_point
,
534 bool is_wheel_scroll
);
536 // Record main frame timing information.
537 // |start_of_main_frame_args| is the BeginFrameArgs of the beginning of the
538 // main frame (ie the frame that kicked off the main frame).
539 // |expected_next_main_frame_args| is the BeginFrameArgs of the frame that
540 // follows the completion of the main frame (whether it is activation or some
541 // other completion, such as early out). Note that if there is a main frame
542 // scheduled in that frame, then this BeginFrameArgs will become the main
543 // frame args. However, if no such frame is scheduled, then this _would_ be
544 // the main frame args if it was scheduled.
545 void RecordMainFrameTiming(
546 const BeginFrameArgs
& start_of_main_frame_args
,
547 const BeginFrameArgs
& expected_next_main_frame_args
);
551 const LayerTreeSettings
& settings
,
552 LayerTreeHostImplClient
* client
,
554 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
555 SharedBitmapManager
* shared_bitmap_manager
,
556 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
557 TaskGraphRunner
* task_graph_runner
,
560 // Virtual for testing.
561 virtual void AnimateLayers(base::TimeTicks monotonic_time
);
563 bool is_likely_to_require_a_draw() const {
564 return is_likely_to_require_a_draw_
;
567 LayerTreeHostImplClient
* client_
;
571 gfx::Vector2dF
ScrollLayerWithViewportSpaceDelta(
572 LayerImpl
* layer_impl
,
573 const gfx::PointF
& viewport_point
,
574 const gfx::Vector2dF
& viewport_delta
);
576 void CreateAndSetRenderer();
577 void CreateAndSetTileManager();
578 void DestroyTileManager();
579 void ReleaseTreeResources();
580 void RecreateTreeResources();
581 void EnforceZeroBudget(bool zero_budget
);
583 bool IsSynchronousSingleThreaded() const;
585 Viewport
* viewport() { return viewport_
.get(); }
587 // Scroll by preferring to move the outer viewport first, only moving the
588 // inner if the outer is at its scroll extents.
589 void ScrollViewportBy(gfx::Vector2dF scroll_delta
);
590 // Scroll by preferring to move the inner viewport first, only moving the
591 // outer if the inner is at its scroll extents.
592 void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta
);
593 void AnimatePageScale(base::TimeTicks monotonic_time
);
594 void AnimateScrollbars(base::TimeTicks monotonic_time
);
595 void AnimateTopControls(base::TimeTicks monotonic_time
);
597 void TrackDamageForAllSurfaces(
598 LayerImpl
* root_draw_layer
,
599 const LayerImplList
& render_surface_layer_list
);
601 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy
& policy
);
603 // This function should only be called from PrepareToDraw, as DidDrawAllLayers
604 // must be called if this helper function is called. Returns DRAW_SUCCESS if
605 // the frame should be drawn.
606 DrawResult
CalculateRenderPasses(FrameData
* frame
);
608 void ClearCurrentlyScrollingLayer();
610 bool HandleMouseOverScrollbar(LayerImpl
* layer_impl
,
611 const gfx::PointF
& device_viewport_point
);
613 LayerImpl
* FindScrollLayerForDeviceViewportPoint(
614 const gfx::PointF
& device_viewport_point
,
615 InputHandler::ScrollInputType type
,
616 LayerImpl
* layer_hit_by_point
,
617 bool* scroll_on_main_thread
,
618 bool* optional_has_ancestor_scroll_handler
) const;
619 float DeviceSpaceDistanceToLayer(const gfx::PointF
& device_viewport_point
,
620 LayerImpl
* layer_impl
);
621 void StartScrollbarFadeRecursive(LayerImpl
* layer
);
622 void SetManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
,
624 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
);
626 void MarkUIResourceNotEvicted(UIResourceId uid
);
628 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
629 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
631 void ScrollAnimationCreate(LayerImpl
* layer_impl
,
632 const gfx::ScrollOffset
& target_offset
,
633 const gfx::ScrollOffset
& current_offset
);
634 bool ScrollAnimationUpdateTarget(LayerImpl
* layer_impl
,
635 const gfx::Vector2dF
& scroll_delta
);
637 typedef base::hash_map
<UIResourceId
, UIResourceData
>
639 UIResourceMap ui_resource_map_
;
641 // Resources that were evicted by EvictAllUIResources. Resources are removed
642 // from this when they are touched by a create or destroy from the UI resource
644 std::set
<UIResourceId
> evicted_ui_resources_
;
646 scoped_ptr
<OutputSurface
> output_surface_
;
648 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
649 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
650 // |tile_manager_| can also be NULL when raster_enabled is false.
651 scoped_ptr
<ResourceProvider
> resource_provider_
;
652 scoped_ptr
<TileManager
> tile_manager_
;
653 bool use_gpu_rasterization_
;
654 GpuRasterizationStatus gpu_rasterization_status_
;
655 scoped_ptr
<TileTaskWorkerPool
> tile_task_worker_pool_
;
656 scoped_ptr
<ResourcePool
> resource_pool_
;
657 scoped_ptr
<ResourcePool
> staging_resource_pool_
;
658 scoped_ptr
<Renderer
> renderer_
;
660 GlobalStateThatImpactsTilePriority global_tile_state_
;
662 // Tree currently being drawn.
663 scoped_ptr
<LayerTreeImpl
> active_tree_
;
665 // In impl-side painting mode, tree with possibly incomplete rasterized
666 // content. May be promoted to active by ActivatePendingTree().
667 scoped_ptr
<LayerTreeImpl
> pending_tree_
;
669 // In impl-side painting mode, inert tree with layers that can be recycled
670 // by the next sync from the main thread.
671 scoped_ptr
<LayerTreeImpl
> recycle_tree_
;
673 InputHandlerClient
* input_handler_client_
;
674 bool did_lock_scrolling_layer_
;
675 bool should_bubble_scrolls_
;
676 bool wheel_scrolling_
;
677 bool scroll_affects_scroll_handler_
;
678 int scroll_layer_id_when_mouse_over_scrollbar_
;
679 ScopedPtrVector
<SwapPromise
> swap_promises_for_main_thread_scroll_update_
;
681 // An object to implement the ScrollElasticityHelper interface and
682 // hold all state related to elasticity. May be NULL if never requested.
683 scoped_ptr
<ScrollElasticityHelper
> scroll_elasticity_helper_
;
685 bool tile_priorities_dirty_
;
687 // The optional delegate for the root layer scroll offset.
688 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate_
;
689 LayerTreeSettings settings_
;
690 LayerTreeDebugState debug_state_
;
692 ManagedMemoryPolicy cached_managed_memory_policy_
;
694 gfx::Vector2dF accumulated_root_overscroll_
;
696 bool pinch_gesture_active_
;
697 bool pinch_gesture_end_should_clear_scrolling_layer_
;
698 gfx::Point previous_pinch_anchor_
;
700 scoped_ptr
<TopControlsManager
> top_controls_manager_
;
702 scoped_ptr
<PageScaleAnimation
> page_scale_animation_
;
704 scoped_ptr
<FrameRateCounter
> fps_counter_
;
705 scoped_ptr
<PaintTimeCounter
> paint_time_counter_
;
706 scoped_ptr
<MemoryHistory
> memory_history_
;
707 scoped_ptr
<DebugRectHistory
> debug_rect_history_
;
709 scoped_ptr
<TextureMailboxDeleter
> texture_mailbox_deleter_
;
711 // The maximum memory that would be used by the prioritized resource
712 // manager, if there were no limit on memory usage.
713 size_t max_memory_needed_bytes_
;
717 // Viewport size passed in from the main thread, in physical pixels. This
718 // value is the default size for all concepts of physical viewport (draw
719 // viewport, scrolling viewport and device viewport), but it can be
721 gfx::Size device_viewport_size_
;
723 // Conversion factor from CSS pixels to physical pixels when
724 // pageScaleFactor=1.
725 float device_scale_factor_
;
727 // Optional top-level constraints that can be set by the OutputSurface.
728 // - external_transform_ applies a transform above the root layer
729 // - external_viewport_ is used DrawProperties, tile management and
730 // glViewport/window projection matrix.
731 // - external_clip_ specifies a top-level clip rect
732 // - viewport_rect_for_tile_priority_ is the rect in view space used for
734 gfx::Transform external_transform_
;
735 gfx::Rect external_viewport_
;
736 gfx::Rect external_clip_
;
737 gfx::Rect viewport_rect_for_tile_priority_
;
738 bool resourceless_software_draw_
;
740 gfx::Rect viewport_damage_rect_
;
742 BeginFrameArgs current_begin_frame_args_
;
744 // Expected time between two begin impl frame calls.
745 base::TimeDelta begin_impl_frame_interval_
;
747 scoped_ptr
<AnimationRegistrar
> animation_registrar_
;
748 std::set
<ScrollbarAnimationController
*> scrollbar_animation_controllers_
;
750 RenderingStatsInstrumentation
* rendering_stats_instrumentation_
;
751 MicroBenchmarkControllerImpl micro_benchmark_controller_
;
752 scoped_ptr
<TaskGraphRunner
> single_thread_synchronous_task_graph_runner_
;
754 // Optional callback to notify of new tree activations.
755 base::Closure tree_activation_callback_
;
757 SharedBitmapManager
* shared_bitmap_manager_
;
758 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager_
;
759 TaskGraphRunner
* task_graph_runner_
;
762 std::set
<SwapPromiseMonitor
*> swap_promise_monitor_
;
763 std::vector
<PictureLayerImpl::Pair
> picture_layer_pairs_
;
765 bool requires_high_res_to_draw_
;
766 bool is_likely_to_require_a_draw_
;
768 scoped_ptr
<FrameTimingTracker
> frame_timing_tracker_
;
770 scoped_ptr
<Viewport
> viewport_
;
772 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl
);
777 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_