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/ui_resource_client.h"
35 #include "cc/scheduler/begin_frame_tracker.h"
36 #include "cc/scheduler/commit_earlyout_reason.h"
37 #include "cc/scheduler/draw_result.h"
38 #include "cc/scheduler/video_frame_controller.h"
39 #include "cc/tiles/tile_manager.h"
40 #include "cc/trees/layer_tree_settings.h"
41 #include "cc/trees/mutator_host_client.h"
42 #include "cc/trees/proxy.h"
43 #include "skia/ext/refptr.h"
44 #include "third_party/skia/include/core/SkColor.h"
45 #include "ui/gfx/geometry/rect.h"
54 class CompletionEvent
;
55 class CompositorFrameMetadata
;
56 class DebugRectHistory
;
57 class EvictionTilePriorityQueue
;
58 class FrameRateCounter
;
62 class PageScaleAnimation
;
63 class PictureLayerImpl
;
64 class RasterTilePriorityQueue
;
65 class TileTaskWorkerPool
;
66 class RenderPassDrawQuad
;
67 class RenderingStatsInstrumentation
;
69 class ScrollElasticityHelper
;
70 class ScrollbarLayerImplBase
;
72 class SwapPromiseMonitor
;
73 class TextureMailboxDeleter
;
74 class TopControlsManager
;
75 class UIResourceBitmap
;
76 class UIResourceRequest
;
77 struct ScrollAndScaleSet
;
80 enum class GpuRasterizationStatus
{
89 // LayerTreeHost->Proxy callback interface.
90 class LayerTreeHostImplClient
{
92 virtual void UpdateRendererCapabilitiesOnImplThread() = 0;
93 virtual void DidLoseOutputSurfaceOnImplThread() = 0;
94 virtual void CommitVSyncParameters(base::TimeTicks timebase
,
95 base::TimeDelta interval
) = 0;
96 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time
) = 0;
97 virtual void SetMaxSwapsPendingOnImplThread(int max
) = 0;
98 virtual void DidSwapBuffersOnImplThread() = 0;
99 virtual void DidSwapBuffersCompleteOnImplThread() = 0;
100 virtual void OnCanDrawStateChanged(bool can_draw
) = 0;
101 virtual void NotifyReadyToActivate() = 0;
102 virtual void NotifyReadyToDraw() = 0;
103 // Please call these 3 functions through
104 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
105 // SetNeedsAnimate().
106 virtual void SetNeedsRedrawOnImplThread() = 0;
107 virtual void SetNeedsRedrawRectOnImplThread(const gfx::Rect
& damage_rect
) = 0;
108 virtual void SetNeedsAnimateOnImplThread() = 0;
109 virtual void SetNeedsCommitOnImplThread() = 0;
110 virtual void SetNeedsPrepareTilesOnImplThread() = 0;
111 virtual void SetVideoNeedsBeginFrames(bool needs_begin_frames
) = 0;
112 virtual void PostAnimationEventsToMainThreadOnImplThread(
113 scoped_ptr
<AnimationEventsVector
> events
) = 0;
114 virtual bool IsInsideDraw() = 0;
115 virtual void RenewTreePriority() = 0;
116 virtual void PostDelayedAnimationTaskOnImplThread(const base::Closure
& task
,
117 base::TimeDelta delay
) = 0;
118 virtual void DidActivateSyncTree() = 0;
119 virtual void WillPrepareTiles() = 0;
120 virtual void DidPrepareTiles() = 0;
122 // Called when page scale animation has completed on the impl thread.
123 virtual void DidCompletePageScaleAnimationOnImplThread() = 0;
125 // Called when output surface asks for a draw.
126 virtual void OnDrawForOutputSurface() = 0;
128 virtual void PostFrameTimingEventsOnImplThread(
129 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> composite_events
,
130 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> main_frame_events
) = 0;
133 virtual ~LayerTreeHostImplClient() {}
136 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
138 class CC_EXPORT LayerTreeHostImpl
139 : public InputHandler
,
140 public RendererClient
,
141 public TileManagerClient
,
142 public OutputSurfaceClient
,
143 public TopControlsManagerClient
,
144 public ScrollbarAnimationControllerClient
,
145 public VideoFrameControllerClient
,
146 public MutatorHostClient
,
147 public base::SupportsWeakPtr
<LayerTreeHostImpl
> {
149 static scoped_ptr
<LayerTreeHostImpl
> Create(
150 const LayerTreeSettings
& settings
,
151 LayerTreeHostImplClient
* client
,
153 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
154 SharedBitmapManager
* shared_bitmap_manager
,
155 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
156 TaskGraphRunner
* task_graph_runner
,
158 ~LayerTreeHostImpl() override
;
160 // InputHandler implementation
161 void BindToClient(InputHandlerClient
* client
) override
;
162 InputHandler::ScrollStatus
ScrollBegin(
163 const gfx::Point
& viewport_point
,
164 InputHandler::ScrollInputType type
) override
;
165 InputHandler::ScrollStatus
RootScrollBegin(
166 InputHandler::ScrollInputType type
) override
;
167 InputHandler::ScrollStatus
ScrollAnimated(
168 const gfx::Point
& viewport_point
,
169 const gfx::Vector2dF
& scroll_delta
) override
;
170 void ApplyScroll(LayerImpl
* layer
, ScrollState
* scroll_state
);
171 InputHandlerScrollResult
ScrollBy(
172 const gfx::Point
& viewport_point
,
173 const gfx::Vector2dF
& scroll_delta
) override
;
174 bool ScrollVerticallyByPage(const gfx::Point
& viewport_point
,
175 ScrollDirection direction
) override
;
176 void SetRootLayerScrollOffsetDelegate(
177 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
) override
;
178 void OnRootLayerDelegatedScrollOffsetChanged(
179 const gfx::ScrollOffset
& root_offset
) override
;
180 void ScrollEnd() override
;
181 InputHandler::ScrollStatus
FlingScrollBegin() override
;
182 void MouseMoveAt(const gfx::Point
& viewport_point
) override
;
183 void PinchGestureBegin() override
;
184 void PinchGestureUpdate(float magnify_delta
,
185 const gfx::Point
& anchor
) override
;
186 void PinchGestureEnd() override
;
187 void StartPageScaleAnimation(const gfx::Vector2d
& target_offset
,
190 base::TimeDelta duration
);
191 void SetNeedsAnimateInput() override
;
192 bool IsCurrentlyScrollingRoot() const override
;
193 bool IsCurrentlyScrollingLayerAt(
194 const gfx::Point
& viewport_point
,
195 InputHandler::ScrollInputType type
) const override
;
196 bool HaveWheelEventHandlersAt(const gfx::Point
& viewport_point
) override
;
197 bool DoTouchEventsBlockScrollAt(const gfx::Point
& viewport_port
) override
;
198 scoped_ptr
<SwapPromiseMonitor
> CreateLatencyInfoSwapPromiseMonitor(
199 ui::LatencyInfo
* latency
) override
;
200 ScrollElasticityHelper
* CreateScrollElasticityHelper() override
;
202 // TopControlsManagerClient implementation.
203 float TopControlsHeight() const override
;
204 void SetCurrentTopControlsShownRatio(float offset
) override
;
205 float CurrentTopControlsShownRatio() const override
;
206 void DidChangeTopControlsPosition() override
;
207 bool HaveRootScrollLayer() const override
;
209 void UpdateViewportContainerSizes();
211 struct CC_EXPORT FrameData
: public RenderPassSink
{
213 ~FrameData() override
;
214 void AsValueInto(base::trace_event::TracedValue
* value
) const;
216 std::vector
<gfx::Rect
> occluding_screen_space_rects
;
217 std::vector
<gfx::Rect
> non_occluding_screen_space_rects
;
218 std::vector
<FrameTimingTracker::FrameAndRectIds
> composite_events
;
219 RenderPassList render_passes
;
220 RenderPassIdHashMap render_passes_by_id
;
221 const LayerImplList
* render_surface_layer_list
;
222 LayerImplList will_draw_layers
;
225 // RenderPassSink implementation.
226 void AppendRenderPass(scoped_ptr
<RenderPass
> render_pass
) override
;
229 virtual void BeginMainFrameAborted(CommitEarlyOutReason reason
);
230 virtual void BeginCommit();
231 virtual void CommitComplete();
232 virtual void Animate();
233 virtual void UpdateAnimationState(bool start_ready_animations
);
234 void ActivateAnimations();
235 void MainThreadHasStoppedFlinging();
236 void DidAnimateScrollOffset();
237 void SetViewportDamage(const gfx::Rect
& damage_rect
);
239 void SetTreeLayerFilterMutated(int layer_id
,
241 const FilterOperations
& filters
);
242 void SetTreeLayerOpacityMutated(int layer_id
,
245 void SetTreeLayerTransformMutated(int layer_id
,
247 const gfx::Transform
& transform
);
248 void SetTreeLayerScrollOffsetMutated(int layer_id
,
250 const gfx::ScrollOffset
& scroll_offset
);
251 void TreeLayerTransformIsPotentiallyAnimatingChanged(int layer_id
,
255 // LayerTreeMutatorsClient implementation.
256 bool IsLayerInTree(int layer_id
, LayerTreeType tree_type
) const override
;
257 void SetMutatorsNeedCommit() override
;
258 void SetLayerFilterMutated(int layer_id
,
259 LayerTreeType tree_type
,
260 const FilterOperations
& filters
) override
;
261 void SetLayerOpacityMutated(int layer_id
,
262 LayerTreeType tree_type
,
263 float opacity
) override
;
264 void SetLayerTransformMutated(int layer_id
,
265 LayerTreeType tree_type
,
266 const gfx::Transform
& transform
) override
;
267 void SetLayerScrollOffsetMutated(
269 LayerTreeType tree_type
,
270 const gfx::ScrollOffset
& scroll_offset
) override
;
271 void LayerTransformIsPotentiallyAnimatingChanged(int layer_id
,
272 LayerTreeType tree_type
,
273 bool is_animating
) override
;
274 void ScrollOffsetAnimationFinished() override
;
275 gfx::ScrollOffset
GetScrollOffsetForAnimation(int layer_id
) const override
;
277 virtual bool PrepareTiles();
279 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
280 // should try to avoid displaying the frame. If PrepareToDraw is called,
281 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
282 // called between the two.
283 virtual DrawResult
PrepareToDraw(FrameData
* frame
);
284 virtual void DrawLayers(FrameData
* frame
);
285 // Must be called if and only if PrepareToDraw was called.
286 void DidDrawAllLayers(const FrameData
& frame
);
288 const LayerTreeSettings
& settings() const { return settings_
; }
290 // Evict all textures by enforcing a memory policy with an allocation of 0.
291 void EvictTexturesForTesting();
293 // When blocking, this prevents client_->NotifyReadyToActivate() from being
294 // called. When disabled, it calls client_->NotifyReadyToActivate()
295 // immediately if any notifications had been blocked while blocking.
296 virtual void BlockNotifyReadyToActivateForTesting(bool block
);
298 // Resets all of the trees to an empty state.
299 void ResetTreesForTesting();
301 size_t SourceAnimationFrameNumberForTesting() const;
303 DrawMode
GetDrawMode() const;
305 // Viewport size in draw space: this size is in physical pixels and is used
306 // for draw properties, tilings, quads and render passes.
307 gfx::Size
DrawViewportSize() const;
309 // Viewport rect in view space used for tiling prioritization.
310 const gfx::Rect
ViewportRectForTilePriority() const;
312 // RendererClient implementation.
313 void SetFullRootLayerDamage() override
;
315 // TileManagerClient implementation.
316 void NotifyReadyToActivate() override
;
317 void NotifyReadyToDraw() override
;
318 void NotifyAllTileTasksCompleted() override
;
319 void NotifyTileStateChanged(const Tile
* tile
) override
;
320 scoped_ptr
<RasterTilePriorityQueue
> BuildRasterQueue(
321 TreePriority tree_priority
,
322 RasterTilePriorityQueue::Type type
) override
;
323 scoped_ptr
<EvictionTilePriorityQueue
> BuildEvictionQueue(
324 TreePriority tree_priority
) override
;
325 void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw
) override
;
327 // ScrollbarAnimationControllerClient implementation.
328 void StartAnimatingScrollbarAnimationController(
329 ScrollbarAnimationController
* controller
) override
;
330 void StopAnimatingScrollbarAnimationController(
331 ScrollbarAnimationController
* controller
) override
;
332 void PostDelayedScrollbarAnimationTask(const base::Closure
& task
,
333 base::TimeDelta delay
) override
;
334 void SetNeedsRedrawForScrollbarAnimation() override
;
336 // VideoBeginFrameSource implementation.
337 void AddVideoFrameController(VideoFrameController
* controller
) override
;
338 void RemoveVideoFrameController(VideoFrameController
* controller
) override
;
340 // OutputSurfaceClient implementation.
341 void CommitVSyncParameters(base::TimeTicks timebase
,
342 base::TimeDelta interval
) override
;
343 void SetNeedsRedrawRect(const gfx::Rect
& rect
) override
;
344 void SetExternalDrawConstraints(
345 const gfx::Transform
& transform
,
346 const gfx::Rect
& viewport
,
347 const gfx::Rect
& clip
,
348 const gfx::Rect
& viewport_rect_for_tile_priority
,
349 const gfx::Transform
& transform_for_tile_priority
,
350 bool resourceless_software_draw
) override
;
351 void DidLoseOutputSurface() override
;
352 void DidSwapBuffers() override
;
353 void DidSwapBuffersComplete() override
;
354 void ReclaimResources(const CompositorFrameAck
* ack
) override
;
355 void SetMemoryPolicy(const ManagedMemoryPolicy
& policy
) override
;
356 void SetTreeActivationCallback(const base::Closure
& callback
) override
;
357 void OnDraw() override
;
359 // Called from LayerTreeImpl.
360 void OnCanDrawStateChangedForTree();
363 int id() const { return id_
; }
364 bool CanDraw() const;
365 OutputSurface
* output_surface() const { return output_surface_
.get(); }
366 scoped_ptr
<OutputSurface
> ReleaseOutputSurface();
367 std::string
LayerTreeAsJson() const;
369 void FinishAllRendering();
370 int RequestedMSAASampleCount() const;
372 virtual bool InitializeRenderer(scoped_ptr
<OutputSurface
> output_surface
);
373 TileManager
* tile_manager() { return tile_manager_
.get(); }
375 void SetHasGpuRasterizationTrigger(bool flag
) {
376 has_gpu_rasterization_trigger_
= flag
;
377 UpdateGpuRasterizationStatus();
379 void SetContentIsSuitableForGpuRasterization(bool flag
) {
380 content_is_suitable_for_gpu_rasterization_
= flag
;
381 UpdateGpuRasterizationStatus();
383 bool CanUseGpuRasterization();
384 void UpdateTreeResourcesForGpuRasterizationIfNeeded();
385 bool use_gpu_rasterization() const { return use_gpu_rasterization_
; }
386 bool use_msaa() const { return use_msaa_
; }
388 GpuRasterizationStatus
gpu_rasterization_status() const {
389 return gpu_rasterization_status_
;
392 bool create_low_res_tiling() const {
393 return settings_
.create_low_res_tiling
&& !use_gpu_rasterization_
;
395 ResourcePool
* resource_pool() { return resource_pool_
.get(); }
396 Renderer
* renderer() { return renderer_
.get(); }
397 const RendererCapabilitiesImpl
& GetRendererCapabilities() const;
399 virtual bool SwapBuffers(const FrameData
& frame
);
400 virtual void WillBeginImplFrame(const BeginFrameArgs
& args
);
401 virtual void DidFinishImplFrame();
402 void DidModifyTilePriorities();
404 LayerTreeImpl
* active_tree() { return active_tree_
.get(); }
405 const LayerTreeImpl
* active_tree() const { return active_tree_
.get(); }
406 LayerTreeImpl
* pending_tree() { return pending_tree_
.get(); }
407 const LayerTreeImpl
* pending_tree() const { return pending_tree_
.get(); }
408 LayerTreeImpl
* recycle_tree() { return recycle_tree_
.get(); }
409 const LayerTreeImpl
* recycle_tree() const { return recycle_tree_
.get(); }
410 // Returns the tree LTH synchronizes with.
411 LayerTreeImpl
* sync_tree() {
412 // TODO(enne): This is bogus. It should return based on the value of
413 // Proxy::CommitToActiveTree and not whether the pending tree exists.
414 return pending_tree_
? pending_tree_
.get() : active_tree_
.get();
416 virtual void CreatePendingTree();
417 virtual void ActivateSyncTree();
419 // Shortcuts to layers on the active tree.
420 LayerImpl
* RootLayer() const;
421 LayerImpl
* InnerViewportScrollLayer() const;
422 LayerImpl
* OuterViewportScrollLayer() const;
423 LayerImpl
* CurrentlyScrollingLayer() const;
425 int scroll_layer_id_when_mouse_over_scrollbar() const {
426 return scroll_layer_id_when_mouse_over_scrollbar_
;
428 bool scroll_affects_scroll_handler() const {
429 return scroll_affects_scroll_handler_
;
431 void QueueSwapPromiseForMainThreadScrollUpdate(
432 scoped_ptr
<SwapPromise
> swap_promise
);
434 bool IsActivelyScrolling() const;
436 virtual void SetVisible(bool visible
);
437 bool visible() const { return visible_
; }
439 void SetNeedsCommit() { client_
->SetNeedsCommitOnImplThread(); }
440 void SetNeedsAnimate();
441 void SetNeedsRedraw();
443 ManagedMemoryPolicy
ActualManagedMemoryPolicy() const;
445 size_t memory_allocation_limit_bytes() const;
447 void SetViewportSize(const gfx::Size
& device_viewport_size
);
448 gfx::Size
device_viewport_size() const { return device_viewport_size_
; }
450 void SetDeviceScaleFactor(float device_scale_factor
);
451 float device_scale_factor() const { return device_scale_factor_
; }
453 const gfx::Transform
& DrawTransform() const;
455 scoped_ptr
<ScrollAndScaleSet
> ProcessScrollDeltas();
457 void set_max_memory_needed_bytes(size_t bytes
) {
458 max_memory_needed_bytes_
= bytes
;
461 FrameRateCounter
* fps_counter() {
462 return fps_counter_
.get();
464 MemoryHistory
* memory_history() {
465 return memory_history_
.get();
467 DebugRectHistory
* debug_rect_history() {
468 return debug_rect_history_
.get();
470 ResourceProvider
* resource_provider() {
471 return resource_provider_
.get();
473 TopControlsManager
* top_controls_manager() {
474 return top_controls_manager_
.get();
476 const GlobalStateThatImpactsTilePriority
& global_tile_state() {
477 return global_tile_state_
;
480 Proxy
* proxy() const { return proxy_
; }
482 AnimationRegistrar
* animation_registrar() const {
483 return animation_registrar_
.get();
485 AnimationHost
* animation_host() const { return animation_host_
.get(); }
487 void SetDebugState(const LayerTreeDebugState
& new_debug_state
);
488 const LayerTreeDebugState
& debug_state() const { return debug_state_
; }
490 gfx::Vector2dF
accumulated_root_overscroll() const {
491 return accumulated_root_overscroll_
;
494 bool pinch_gesture_active() const { return pinch_gesture_active_
; }
496 void SetTreePriority(TreePriority priority
);
497 TreePriority
GetTreePriority() const;
499 // TODO(mithro): Remove this methods which exposes the internal
500 // BeginFrameArgs to external callers.
501 virtual BeginFrameArgs
CurrentBeginFrameArgs() const;
503 // Expected time between two begin impl frame calls.
504 base::TimeDelta
CurrentBeginFrameInterval() const;
506 void AsValueWithFrameInto(FrameData
* frame
,
507 base::trace_event::TracedValue
* value
) const;
508 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValueWithFrame(
509 FrameData
* frame
) const;
510 void ActivationStateAsValueInto(base::trace_event::TracedValue
* value
) const;
512 bool page_scale_animation_active() const { return !!page_scale_animation_
; }
514 virtual void CreateUIResource(UIResourceId uid
,
515 const UIResourceBitmap
& bitmap
);
516 // Deletes a UI resource. May safely be called more than once.
517 virtual void DeleteUIResource(UIResourceId uid
);
518 void EvictAllUIResources();
519 bool EvictedUIResourcesExist() const;
521 virtual ResourceId
ResourceIdForUIResource(UIResourceId uid
) const;
523 virtual bool IsUIResourceOpaque(UIResourceId uid
) const;
525 struct UIResourceData
{
526 ResourceId resource_id
;
531 void ScheduleMicroBenchmark(scoped_ptr
<MicroBenchmarkImpl
> benchmark
);
533 CompositorFrameMetadata
MakeCompositorFrameMetadata() const;
534 // Viewport rectangle and clip in nonflipped window space. These rects
535 // should only be used by Renderer subclasses to populate glViewport/glClip
536 // and their software-mode equivalents.
537 gfx::Rect
DeviceViewport() const;
538 gfx::Rect
DeviceClip() const;
540 // When a SwapPromiseMonitor is created on the impl thread, it calls
541 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
542 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
543 // to unregister itself.
544 void InsertSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
545 void RemoveSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
547 // TODO(weiliangc): Replace RequiresHighResToDraw with scheduler waits for
548 // ReadyToDraw. crbug.com/469175
549 void SetRequiresHighResToDraw() { requires_high_res_to_draw_
= true; }
550 void ResetRequiresHighResToDraw() { requires_high_res_to_draw_
= false; }
551 bool RequiresHighResToDraw() const { return requires_high_res_to_draw_
; }
553 // Only valid for synchronous (non-scheduled) single-threaded case.
554 void SynchronouslyInitializeAllTiles();
556 virtual void CreateResourceAndTileTaskWorkerPool(
557 scoped_ptr
<TileTaskWorkerPool
>* tile_task_worker_pool
,
558 scoped_ptr
<ResourcePool
>* resource_pool
);
560 bool prepare_tiles_needed() const { return tile_priorities_dirty_
; }
562 FrameTimingTracker
* frame_timing_tracker() {
563 return frame_timing_tracker_
.get();
566 gfx::Vector2dF
ScrollLayer(LayerImpl
* layer_impl
,
567 const gfx::Vector2dF
& delta
,
568 const gfx::Point
& viewport_point
,
569 bool is_direct_manipulation
);
571 // Record main frame timing information.
572 // |start_of_main_frame_args| is the BeginFrameArgs of the beginning of the
573 // main frame (ie the frame that kicked off the main frame).
574 // |expected_next_main_frame_args| is the BeginFrameArgs of the frame that
575 // follows the completion of the main frame (whether it is activation or some
576 // other completion, such as early out). Note that if there is a main frame
577 // scheduled in that frame, then this BeginFrameArgs will become the main
578 // frame args. However, if no such frame is scheduled, then this _would_ be
579 // the main frame args if it was scheduled.
580 void RecordMainFrameTiming(
581 const BeginFrameArgs
& start_of_main_frame_args
,
582 const BeginFrameArgs
& expected_next_main_frame_args
);
584 // Post the given frame timing events to the requester.
585 void PostFrameTimingEvents(
586 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> composite_events
,
587 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> main_frame_events
);
591 const LayerTreeSettings
& settings
,
592 LayerTreeHostImplClient
* client
,
594 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
595 SharedBitmapManager
* shared_bitmap_manager
,
596 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
597 TaskGraphRunner
* task_graph_runner
,
600 // Virtual for testing.
601 virtual void AnimateLayers(base::TimeTicks monotonic_time
);
603 bool is_likely_to_require_a_draw() const {
604 return is_likely_to_require_a_draw_
;
607 // Removes empty or orphan RenderPasses from the frame.
608 static void RemoveRenderPasses(FrameData
* frame
);
610 LayerTreeHostImplClient
* client_
;
613 BeginFrameTracker current_begin_frame_tracker_
;
616 gfx::Vector2dF
ScrollLayerWithViewportSpaceDelta(
617 LayerImpl
* layer_impl
,
618 const gfx::PointF
& viewport_point
,
619 const gfx::Vector2dF
& viewport_delta
);
621 void CreateAndSetRenderer();
622 void CleanUpTileManager();
623 void CreateTileManagerResources();
624 void ReleaseTreeResources();
625 void RecreateTreeResources();
627 void UpdateGpuRasterizationStatus();
629 Viewport
* viewport() { return viewport_
.get(); }
631 // Scroll by preferring to move the outer viewport first, only moving the
632 // inner if the outer is at its scroll extents.
633 void ScrollViewportBy(gfx::Vector2dF scroll_delta
);
634 // Scroll by preferring to move the inner viewport first, only moving the
635 // outer if the inner is at its scroll extents.
636 void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta
);
638 InputHandler::ScrollStatus
ScrollBeginImpl(
639 LayerImpl
* scrolling_layer_impl
,
640 InputHandler::ScrollInputType type
);
642 void AnimatePageScale(base::TimeTicks monotonic_time
);
643 void AnimateScrollbars(base::TimeTicks monotonic_time
);
644 void AnimateTopControls(base::TimeTicks monotonic_time
);
646 void TrackDamageForAllSurfaces(
647 LayerImpl
* root_draw_layer
,
648 const LayerImplList
& render_surface_layer_list
);
650 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy
& policy
);
652 // This function should only be called from PrepareToDraw, as DidDrawAllLayers
653 // must be called if this helper function is called. Returns DRAW_SUCCESS if
654 // the frame should be drawn.
655 DrawResult
CalculateRenderPasses(FrameData
* frame
);
657 void ClearCurrentlyScrollingLayer();
659 bool HandleMouseOverScrollbar(LayerImpl
* layer_impl
,
660 const gfx::PointF
& device_viewport_point
);
662 LayerImpl
* FindScrollLayerForDeviceViewportPoint(
663 const gfx::PointF
& device_viewport_point
,
664 InputHandler::ScrollInputType type
,
665 LayerImpl
* layer_hit_by_point
,
666 bool* scroll_on_main_thread
,
667 bool* optional_has_ancestor_scroll_handler
) const;
668 float DeviceSpaceDistanceToLayer(const gfx::PointF
& device_viewport_point
,
669 LayerImpl
* layer_impl
);
670 void StartScrollbarFadeRecursive(LayerImpl
* layer
);
671 void SetManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
);
673 void MarkUIResourceNotEvicted(UIResourceId uid
);
675 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
676 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
677 void NotifyRootLayerScrollOffsetDelegate();
679 void ScrollAnimationCreate(LayerImpl
* layer_impl
,
680 const gfx::ScrollOffset
& target_offset
,
681 const gfx::ScrollOffset
& current_offset
);
682 bool ScrollAnimationUpdateTarget(LayerImpl
* layer_impl
,
683 const gfx::Vector2dF
& scroll_delta
);
685 base::SingleThreadTaskRunner
* GetTaskRunner() const {
687 return proxy_
->HasImplThread() ? proxy_
->ImplThreadTaskRunner()
688 : proxy_
->MainThreadTaskRunner();
691 typedef base::hash_map
<UIResourceId
, UIResourceData
>
693 UIResourceMap ui_resource_map_
;
695 // Resources that were evicted by EvictAllUIResources. Resources are removed
696 // from this when they are touched by a create or destroy from the UI resource
698 std::set
<UIResourceId
> evicted_ui_resources_
;
700 scoped_ptr
<OutputSurface
> output_surface_
;
702 scoped_ptr
<ResourceProvider
> resource_provider_
;
703 bool content_is_suitable_for_gpu_rasterization_
;
704 bool has_gpu_rasterization_trigger_
;
705 bool use_gpu_rasterization_
;
707 GpuRasterizationStatus gpu_rasterization_status_
;
708 bool tree_resources_for_gpu_rasterization_dirty_
;
709 scoped_ptr
<TileTaskWorkerPool
> tile_task_worker_pool_
;
710 scoped_ptr
<ResourcePool
> resource_pool_
;
711 scoped_ptr
<Renderer
> renderer_
;
713 GlobalStateThatImpactsTilePriority global_tile_state_
;
715 // Tree currently being drawn.
716 scoped_ptr
<LayerTreeImpl
> active_tree_
;
718 // In impl-side painting mode, tree with possibly incomplete rasterized
719 // content. May be promoted to active by ActivatePendingTree().
720 scoped_ptr
<LayerTreeImpl
> pending_tree_
;
722 // In impl-side painting mode, inert tree with layers that can be recycled
723 // by the next sync from the main thread.
724 scoped_ptr
<LayerTreeImpl
> recycle_tree_
;
726 InputHandlerClient
* input_handler_client_
;
727 bool did_lock_scrolling_layer_
;
728 bool should_bubble_scrolls_
;
729 bool wheel_scrolling_
;
730 bool scroll_affects_scroll_handler_
;
731 int scroll_layer_id_when_mouse_over_scrollbar_
;
732 ScopedPtrVector
<SwapPromise
> swap_promises_for_main_thread_scroll_update_
;
734 // An object to implement the ScrollElasticityHelper interface and
735 // hold all state related to elasticity. May be NULL if never requested.
736 scoped_ptr
<ScrollElasticityHelper
> scroll_elasticity_helper_
;
738 bool tile_priorities_dirty_
;
740 // The optional delegate for the root layer scroll offset.
741 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate_
;
743 const LayerTreeSettings settings_
;
744 LayerTreeDebugState debug_state_
;
746 ManagedMemoryPolicy cached_managed_memory_policy_
;
748 const bool is_synchronous_single_threaded_
;
749 scoped_ptr
<TileManager
> tile_manager_
;
751 gfx::Vector2dF accumulated_root_overscroll_
;
753 bool pinch_gesture_active_
;
754 bool pinch_gesture_end_should_clear_scrolling_layer_
;
756 scoped_ptr
<TopControlsManager
> top_controls_manager_
;
758 scoped_ptr
<PageScaleAnimation
> page_scale_animation_
;
760 scoped_ptr
<FrameRateCounter
> fps_counter_
;
761 scoped_ptr
<MemoryHistory
> memory_history_
;
762 scoped_ptr
<DebugRectHistory
> debug_rect_history_
;
764 scoped_ptr
<TextureMailboxDeleter
> texture_mailbox_deleter_
;
766 // The maximum memory that would be used by the prioritized resource
767 // manager, if there were no limit on memory usage.
768 size_t max_memory_needed_bytes_
;
770 // Viewport size passed in from the main thread, in physical pixels. This
771 // value is the default size for all concepts of physical viewport (draw
772 // viewport, scrolling viewport and device viewport), but it can be
774 gfx::Size device_viewport_size_
;
776 // Conversion factor from CSS pixels to physical pixels when
777 // pageScaleFactor=1.
778 float device_scale_factor_
;
780 // Optional top-level constraints that can be set by the OutputSurface.
781 // - external_transform_ applies a transform above the root layer
782 // - external_viewport_ is used DrawProperties, tile management and
783 // glViewport/window projection matrix.
784 // - external_clip_ specifies a top-level clip rect
785 // - viewport_rect_for_tile_priority_ is the rect in view space used for
787 gfx::Transform external_transform_
;
788 gfx::Rect external_viewport_
;
789 gfx::Rect external_clip_
;
790 gfx::Rect viewport_rect_for_tile_priority_
;
791 bool resourceless_software_draw_
;
793 gfx::Rect viewport_damage_rect_
;
795 scoped_ptr
<AnimationRegistrar
> animation_registrar_
;
796 scoped_ptr
<AnimationHost
> animation_host_
;
797 std::set
<ScrollbarAnimationController
*> scrollbar_animation_controllers_
;
798 std::set
<VideoFrameController
*> video_frame_controllers_
;
800 RenderingStatsInstrumentation
* rendering_stats_instrumentation_
;
801 MicroBenchmarkControllerImpl micro_benchmark_controller_
;
802 scoped_ptr
<TaskGraphRunner
> single_thread_synchronous_task_graph_runner_
;
804 // Optional callback to notify of new tree activations.
805 base::Closure tree_activation_callback_
;
807 SharedBitmapManager
* shared_bitmap_manager_
;
808 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager_
;
809 TaskGraphRunner
* task_graph_runner_
;
812 std::set
<SwapPromiseMonitor
*> swap_promise_monitor_
;
814 bool requires_high_res_to_draw_
;
815 bool is_likely_to_require_a_draw_
;
817 scoped_ptr
<FrameTimingTracker
> frame_timing_tracker_
;
819 scoped_ptr
<Viewport
> viewport_
;
821 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl
);
826 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_