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/scheduler/video_frame_controller.h"
39 #include "cc/trees/layer_tree_settings.h"
40 #include "cc/trees/proxy.h"
41 #include "skia/ext/refptr.h"
42 #include "third_party/skia/include/core/SkColor.h"
43 #include "ui/gfx/geometry/rect.h"
51 class CompletionEvent
;
52 class CompositorFrameMetadata
;
53 class DebugRectHistory
;
54 class EvictionTilePriorityQueue
;
55 class FrameRateCounter
;
59 class PageScaleAnimation
;
60 class PaintTimeCounter
;
61 class PictureLayerImpl
;
62 class RasterTilePriorityQueue
;
63 class TileTaskWorkerPool
;
64 class RenderPassDrawQuad
;
65 class RenderingStatsInstrumentation
;
67 class ScrollElasticityHelper
;
68 class ScrollbarLayerImplBase
;
70 class SwapPromiseMonitor
;
71 class TextureMailboxDeleter
;
72 class TopControlsManager
;
73 class UIResourceBitmap
;
74 class UIResourceRequest
;
75 struct ScrollAndScaleSet
;
78 enum class GpuRasterizationStatus
{
86 // LayerTreeHost->Proxy callback interface.
87 class LayerTreeHostImplClient
{
89 virtual void UpdateRendererCapabilitiesOnImplThread() = 0;
90 virtual void DidLoseOutputSurfaceOnImplThread() = 0;
91 virtual void CommitVSyncParameters(base::TimeTicks timebase
,
92 base::TimeDelta interval
) = 0;
93 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time
) = 0;
94 virtual void SetMaxSwapsPendingOnImplThread(int max
) = 0;
95 virtual void DidSwapBuffersOnImplThread() = 0;
96 virtual void DidSwapBuffersCompleteOnImplThread() = 0;
97 virtual void OnCanDrawStateChanged(bool can_draw
) = 0;
98 virtual void NotifyReadyToActivate() = 0;
99 virtual void NotifyReadyToDraw() = 0;
100 // Please call these 3 functions through
101 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
102 // SetNeedsAnimate().
103 virtual void SetNeedsRedrawOnImplThread() = 0;
104 virtual void SetNeedsRedrawRectOnImplThread(const gfx::Rect
& damage_rect
) = 0;
105 virtual void SetNeedsAnimateOnImplThread() = 0;
106 virtual void SetNeedsCommitOnImplThread() = 0;
107 virtual void SetNeedsPrepareTilesOnImplThread() = 0;
108 virtual void SetVideoNeedsBeginFrames(bool needs_begin_frames
) = 0;
109 virtual void PostAnimationEventsToMainThreadOnImplThread(
110 scoped_ptr
<AnimationEventsVector
> events
) = 0;
111 // Returns true if resources were deleted by this call.
112 virtual bool ReduceContentsTextureMemoryOnImplThread(
114 int priority_cutoff
) = 0;
115 virtual bool IsInsideDraw() = 0;
116 virtual void RenewTreePriority() = 0;
117 virtual void PostDelayedAnimationTaskOnImplThread(const base::Closure
& task
,
118 base::TimeDelta delay
) = 0;
119 virtual void DidActivateSyncTree() = 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;
129 virtual ~LayerTreeHostImplClient() {}
132 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
134 class CC_EXPORT LayerTreeHostImpl
135 : public InputHandler
,
136 public RendererClient
,
137 public TileManagerClient
,
138 public OutputSurfaceClient
,
139 public TopControlsManagerClient
,
140 public ScrollbarAnimationControllerClient
,
141 public VideoFrameControllerClient
,
142 public base::SupportsWeakPtr
<LayerTreeHostImpl
> {
144 static scoped_ptr
<LayerTreeHostImpl
> Create(
145 const LayerTreeSettings
& settings
,
146 LayerTreeHostImplClient
* client
,
148 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
149 SharedBitmapManager
* shared_bitmap_manager
,
150 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
151 TaskGraphRunner
* task_graph_runner
,
153 ~LayerTreeHostImpl() override
;
155 // InputHandler implementation
156 void BindToClient(InputHandlerClient
* client
) override
;
157 InputHandler::ScrollStatus
ScrollBegin(
158 const gfx::Point
& viewport_point
,
159 InputHandler::ScrollInputType type
) override
;
160 InputHandler::ScrollStatus
ScrollAnimated(
161 const gfx::Point
& viewport_point
,
162 const gfx::Vector2dF
& scroll_delta
) override
;
163 InputHandlerScrollResult
ScrollBy(
164 const gfx::Point
& viewport_point
,
165 const gfx::Vector2dF
& scroll_delta
) override
;
166 bool ScrollVerticallyByPage(const gfx::Point
& viewport_point
,
167 ScrollDirection direction
) override
;
168 void SetRootLayerScrollOffsetDelegate(
169 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
) override
;
170 void OnRootLayerDelegatedScrollOffsetChanged() override
;
171 void ScrollEnd() override
;
172 InputHandler::ScrollStatus
FlingScrollBegin() override
;
173 void MouseMoveAt(const gfx::Point
& viewport_point
) override
;
174 void PinchGestureBegin() override
;
175 void PinchGestureUpdate(float magnify_delta
,
176 const gfx::Point
& anchor
) override
;
177 void PinchGestureEnd() override
;
178 void StartPageScaleAnimation(const gfx::Vector2d
& target_offset
,
181 base::TimeDelta duration
);
182 void SetNeedsAnimate() override
;
183 bool IsCurrentlyScrollingLayerAt(const gfx::Point
& viewport_point
,
184 InputHandler::ScrollInputType type
) override
;
185 bool HaveWheelEventHandlersAt(const gfx::Point
& viewport_point
) override
;
186 bool DoTouchEventsBlockScrollAt(const gfx::Point
& viewport_port
) override
;
187 scoped_ptr
<SwapPromiseMonitor
> CreateLatencyInfoSwapPromiseMonitor(
188 ui::LatencyInfo
* latency
) override
;
189 ScrollElasticityHelper
* CreateScrollElasticityHelper() override
;
191 // TopControlsManagerClient implementation.
192 float TopControlsHeight() const override
;
193 void SetCurrentTopControlsShownRatio(float offset
) override
;
194 float CurrentTopControlsShownRatio() const override
;
195 void DidChangeTopControlsPosition() override
;
196 bool HaveRootScrollLayer() const override
;
198 void UpdateViewportContainerSizes();
200 struct CC_EXPORT FrameData
: public RenderPassSink
{
202 ~FrameData() override
;
203 void AsValueInto(base::trace_event::TracedValue
* value
) const;
205 std::vector
<gfx::Rect
> occluding_screen_space_rects
;
206 std::vector
<gfx::Rect
> non_occluding_screen_space_rects
;
207 std::vector
<FrameTimingTracker::FrameAndRectIds
> composite_events
;
208 RenderPassList render_passes
;
209 RenderPassIdHashMap render_passes_by_id
;
210 const LayerImplList
* render_surface_layer_list
;
211 LayerImplList will_draw_layers
;
214 // RenderPassSink implementation.
215 void AppendRenderPass(scoped_ptr
<RenderPass
> render_pass
) override
;
218 virtual void BeginMainFrameAborted(CommitEarlyOutReason reason
);
219 virtual void BeginCommit();
220 virtual void CommitComplete();
221 virtual void Animate(base::TimeTicks monotonic_time
);
222 virtual void UpdateAnimationState(bool start_ready_animations
);
223 void ActivateAnimations();
224 void MainThreadHasStoppedFlinging();
225 void DidAnimateScrollOffset();
226 void SetViewportDamage(const gfx::Rect
& damage_rect
);
228 virtual void PrepareTiles();
230 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
231 // should try to avoid displaying the frame. If PrepareToDraw is called,
232 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
233 // called between the two.
234 virtual DrawResult
PrepareToDraw(FrameData
* frame
);
235 virtual void DrawLayers(FrameData
* frame
, base::TimeTicks frame_begin_time
);
236 // Must be called if and only if PrepareToDraw was called.
237 void DidDrawAllLayers(const FrameData
& frame
);
239 const LayerTreeSettings
& settings() const { return settings_
; }
241 // Evict all textures by enforcing a memory policy with an allocation of 0.
242 void EvictTexturesForTesting();
244 // When blocking, this prevents client_->NotifyReadyToActivate() from being
245 // called. When disabled, it calls client_->NotifyReadyToActivate()
246 // immediately if any notifications had been blocked while blocking.
247 virtual void BlockNotifyReadyToActivateForTesting(bool block
);
249 // Resets all of the trees to an empty state.
250 void ResetTreesForTesting();
252 DrawMode
GetDrawMode() const;
254 // Viewport size in draw space: this size is in physical pixels and is used
255 // for draw properties, tilings, quads and render passes.
256 gfx::Size
DrawViewportSize() const;
258 // Viewport rect in view space used for tiling prioritization.
259 const gfx::Rect
ViewportRectForTilePriority() const;
261 // RendererClient implementation.
262 void SetFullRootLayerDamage() override
;
264 // TileManagerClient implementation.
265 void NotifyReadyToActivate() override
;
266 void NotifyReadyToDraw() override
;
267 void NotifyTileStateChanged(const Tile
* tile
) override
;
268 scoped_ptr
<RasterTilePriorityQueue
> BuildRasterQueue(
269 TreePriority tree_priority
,
270 RasterTilePriorityQueue::Type type
) override
;
271 scoped_ptr
<EvictionTilePriorityQueue
> BuildEvictionQueue(
272 TreePriority tree_priority
) override
;
273 void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw
) override
;
275 // ScrollbarAnimationControllerClient implementation.
276 void StartAnimatingScrollbarAnimationController(
277 ScrollbarAnimationController
* controller
) override
;
278 void StopAnimatingScrollbarAnimationController(
279 ScrollbarAnimationController
* controller
) override
;
280 void PostDelayedScrollbarAnimationTask(const base::Closure
& task
,
281 base::TimeDelta delay
) override
;
282 void SetNeedsRedrawForScrollbarAnimation() override
;
284 // VideoBeginFrameSource implementation.
285 void AddVideoFrameController(VideoFrameController
* controller
) override
;
286 void RemoveVideoFrameController(VideoFrameController
* controller
) override
;
288 // OutputSurfaceClient implementation.
289 void CommitVSyncParameters(base::TimeTicks timebase
,
290 base::TimeDelta interval
) override
;
291 void SetNeedsRedrawRect(const gfx::Rect
& rect
) override
;
292 void SetExternalDrawConstraints(
293 const gfx::Transform
& transform
,
294 const gfx::Rect
& viewport
,
295 const gfx::Rect
& clip
,
296 const gfx::Rect
& viewport_rect_for_tile_priority
,
297 const gfx::Transform
& transform_for_tile_priority
,
298 bool resourceless_software_draw
) override
;
299 void DidLoseOutputSurface() override
;
300 void DidSwapBuffers() override
;
301 void DidSwapBuffersComplete() override
;
302 void ReclaimResources(const CompositorFrameAck
* ack
) override
;
303 void SetMemoryPolicy(const ManagedMemoryPolicy
& policy
) override
;
304 void SetTreeActivationCallback(const base::Closure
& callback
) override
;
305 void OnDraw() override
;
307 // Called from LayerTreeImpl.
308 void OnCanDrawStateChangedForTree();
311 int id() const { return id_
; }
312 bool CanDraw() const;
313 OutputSurface
* output_surface() const { return output_surface_
.get(); }
315 std::string
LayerTreeAsJson() const;
317 void FinishAllRendering();
318 int SourceAnimationFrameNumber() const;
320 virtual bool InitializeRenderer(scoped_ptr
<OutputSurface
> output_surface
);
321 TileManager
* tile_manager() { return tile_manager_
.get(); }
322 void SetUseGpuRasterization(bool use_gpu
);
323 bool use_gpu_rasterization() const { return use_gpu_rasterization_
; }
325 GpuRasterizationStatus
gpu_rasterization_status() const {
326 return gpu_rasterization_status_
;
328 void set_gpu_rasterization_status(
329 GpuRasterizationStatus gpu_rasterization_status
) {
330 gpu_rasterization_status_
= gpu_rasterization_status
;
333 bool create_low_res_tiling() const {
334 return settings_
.create_low_res_tiling
&& !use_gpu_rasterization_
;
336 ResourcePool
* resource_pool() { return resource_pool_
.get(); }
337 Renderer
* renderer() { return renderer_
.get(); }
338 const RendererCapabilitiesImpl
& GetRendererCapabilities() const;
340 virtual bool SwapBuffers(const FrameData
& frame
);
341 virtual void WillBeginImplFrame(const BeginFrameArgs
& args
);
342 void DidModifyTilePriorities();
344 LayerTreeImpl
* active_tree() { return active_tree_
.get(); }
345 const LayerTreeImpl
* active_tree() const { return active_tree_
.get(); }
346 LayerTreeImpl
* pending_tree() { return pending_tree_
.get(); }
347 const LayerTreeImpl
* pending_tree() const { return pending_tree_
.get(); }
348 LayerTreeImpl
* recycle_tree() { return recycle_tree_
.get(); }
349 const LayerTreeImpl
* recycle_tree() const { return recycle_tree_
.get(); }
350 // Returns the tree LTH synchronizes with.
351 LayerTreeImpl
* sync_tree() {
352 // TODO(enne): This is bogus. It should return based on the value of
353 // Proxy::CommitToActiveTree and not whether the pending tree exists.
354 return pending_tree_
? pending_tree_
.get() : active_tree_
.get();
356 virtual void CreatePendingTree();
357 virtual void ActivateSyncTree();
359 // Shortcuts to layers on the active tree.
360 LayerImpl
* RootLayer() const;
361 LayerImpl
* InnerViewportScrollLayer() const;
362 LayerImpl
* OuterViewportScrollLayer() const;
363 LayerImpl
* CurrentlyScrollingLayer() const;
365 int scroll_layer_id_when_mouse_over_scrollbar() const {
366 return scroll_layer_id_when_mouse_over_scrollbar_
;
368 bool scroll_affects_scroll_handler() const {
369 return scroll_affects_scroll_handler_
;
371 void QueueSwapPromiseForMainThreadScrollUpdate(
372 scoped_ptr
<SwapPromise
> swap_promise
);
374 bool IsActivelyScrolling() const;
376 virtual void SetVisible(bool visible
);
377 bool visible() const { return visible_
; }
379 bool AnimationsAreVisible() { return visible() && CanDraw(); }
381 void SetNeedsCommit() { client_
->SetNeedsCommitOnImplThread(); }
382 void SetNeedsRedraw();
384 ManagedMemoryPolicy
ActualManagedMemoryPolicy() const;
386 size_t memory_allocation_limit_bytes() const;
387 int memory_allocation_priority_cutoff() const;
389 void SetViewportSize(const gfx::Size
& device_viewport_size
);
390 gfx::Size
device_viewport_size() const { return device_viewport_size_
; }
392 void SetDeviceScaleFactor(float device_scale_factor
);
393 float device_scale_factor() const { return device_scale_factor_
; }
395 void SetPageScaleOnActiveTree(float page_scale_factor
);
397 const gfx::Transform
& DrawTransform() const;
399 scoped_ptr
<ScrollAndScaleSet
> ProcessScrollDeltas();
401 void set_max_memory_needed_bytes(size_t bytes
) {
402 max_memory_needed_bytes_
= bytes
;
405 FrameRateCounter
* fps_counter() {
406 return fps_counter_
.get();
408 PaintTimeCounter
* paint_time_counter() {
409 return paint_time_counter_
.get();
411 MemoryHistory
* memory_history() {
412 return memory_history_
.get();
414 DebugRectHistory
* debug_rect_history() {
415 return debug_rect_history_
.get();
417 ResourceProvider
* resource_provider() {
418 return resource_provider_
.get();
420 TopControlsManager
* top_controls_manager() {
421 return top_controls_manager_
.get();
423 const GlobalStateThatImpactsTilePriority
& global_tile_state() {
424 return global_tile_state_
;
427 Proxy
* proxy() const { return proxy_
; }
429 AnimationRegistrar
* animation_registrar() const {
430 return animation_registrar_
.get();
433 void SetDebugState(const LayerTreeDebugState
& new_debug_state
);
434 const LayerTreeDebugState
& debug_state() const { return debug_state_
; }
436 gfx::Vector2dF
accumulated_root_overscroll() const {
437 return accumulated_root_overscroll_
;
440 bool pinch_gesture_active() const { return pinch_gesture_active_
; }
442 void SetTreePriority(TreePriority priority
);
443 TreePriority
GetTreePriority() const;
445 void UpdateCurrentBeginFrameArgs(const BeginFrameArgs
& args
);
446 void ResetCurrentBeginFrameArgsForNextFrame();
447 virtual BeginFrameArgs
CurrentBeginFrameArgs() const;
449 // Expected time between two begin impl frame calls.
450 base::TimeDelta
begin_impl_frame_interval() const {
451 return begin_impl_frame_interval_
;
454 void AsValueWithFrameInto(FrameData
* frame
,
455 base::trace_event::TracedValue
* value
) const;
456 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValueWithFrame(
457 FrameData
* frame
) const;
458 void ActivationStateAsValueInto(base::trace_event::TracedValue
* value
) const;
460 bool page_scale_animation_active() const { return !!page_scale_animation_
; }
462 virtual void CreateUIResource(UIResourceId uid
,
463 const UIResourceBitmap
& bitmap
);
464 // Deletes a UI resource. May safely be called more than once.
465 virtual void DeleteUIResource(UIResourceId uid
);
466 void EvictAllUIResources();
467 bool EvictedUIResourcesExist() const;
469 virtual ResourceProvider::ResourceId
ResourceIdForUIResource(
470 UIResourceId uid
) const;
472 virtual bool IsUIResourceOpaque(UIResourceId uid
) const;
474 struct UIResourceData
{
475 ResourceProvider::ResourceId resource_id
;
480 void ScheduleMicroBenchmark(scoped_ptr
<MicroBenchmarkImpl
> benchmark
);
482 CompositorFrameMetadata
MakeCompositorFrameMetadata() const;
483 // Viewport rectangle and clip in nonflipped window space. These rects
484 // should only be used by Renderer subclasses to populate glViewport/glClip
485 // and their software-mode equivalents.
486 gfx::Rect
DeviceViewport() const;
487 gfx::Rect
DeviceClip() const;
489 // When a SwapPromiseMonitor is created on the impl thread, it calls
490 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
491 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
492 // to unregister itself.
493 void InsertSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
494 void RemoveSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
496 void GetPictureLayerImplPairs(std::vector
<PictureLayerImpl::Pair
>* layers
,
497 bool need_valid_tile_priorities
) const;
499 // TODO(weiliangc): Replace RequiresHighResToDraw with scheduler waits for
500 // ReadyToDraw. crbug.com/469175
501 void SetRequiresHighResToDraw() { requires_high_res_to_draw_
= true; }
502 void ResetRequiresHighResToDraw() { requires_high_res_to_draw_
= false; }
503 bool RequiresHighResToDraw() const { return requires_high_res_to_draw_
; }
505 // Only valid for synchronous (non-scheduled) single-threaded case.
506 void SynchronouslyInitializeAllTiles();
508 virtual void CreateResourceAndTileTaskWorkerPool(
509 scoped_ptr
<TileTaskWorkerPool
>* tile_task_worker_pool
,
510 scoped_ptr
<ResourcePool
>* resource_pool
,
511 scoped_ptr
<ResourcePool
>* staging_resource_pool
);
513 bool prepare_tiles_needed() const { return tile_priorities_dirty_
; }
515 FrameTimingTracker
* frame_timing_tracker() {
516 return frame_timing_tracker_
.get();
519 gfx::Vector2dF
ScrollLayer(LayerImpl
* layer_impl
,
520 const gfx::Vector2dF
& delta
,
521 const gfx::Point
& viewport_point
,
522 bool is_wheel_scroll
);
524 // Record main frame timing information.
525 // |start_of_main_frame_args| is the BeginFrameArgs of the beginning of the
526 // main frame (ie the frame that kicked off the main frame).
527 // |expected_next_main_frame_args| is the BeginFrameArgs of the frame that
528 // follows the completion of the main frame (whether it is activation or some
529 // other completion, such as early out). Note that if there is a main frame
530 // scheduled in that frame, then this BeginFrameArgs will become the main
531 // frame args. However, if no such frame is scheduled, then this _would_ be
532 // the main frame args if it was scheduled.
533 void RecordMainFrameTiming(
534 const BeginFrameArgs
& start_of_main_frame_args
,
535 const BeginFrameArgs
& expected_next_main_frame_args
);
539 const LayerTreeSettings
& settings
,
540 LayerTreeHostImplClient
* client
,
542 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
543 SharedBitmapManager
* shared_bitmap_manager
,
544 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
545 TaskGraphRunner
* task_graph_runner
,
548 // Virtual for testing.
549 virtual void AnimateLayers(base::TimeTicks monotonic_time
);
551 bool is_likely_to_require_a_draw() const {
552 return is_likely_to_require_a_draw_
;
555 // Removes empty or orphan RenderPasses from the frame.
556 static void RemoveRenderPasses(FrameData
* frame
);
558 LayerTreeHostImplClient
* client_
;
562 gfx::Vector2dF
ScrollLayerWithViewportSpaceDelta(
563 LayerImpl
* layer_impl
,
564 const gfx::PointF
& viewport_point
,
565 const gfx::Vector2dF
& viewport_delta
);
567 void CreateAndSetRenderer();
568 void CreateAndSetTileManager();
569 void DestroyTileManager();
570 void ReleaseTreeResources();
571 void RecreateTreeResources();
573 bool IsSynchronousSingleThreaded() const;
575 Viewport
* viewport() { return viewport_
.get(); }
577 // Scroll by preferring to move the outer viewport first, only moving the
578 // inner if the outer is at its scroll extents.
579 void ScrollViewportBy(gfx::Vector2dF scroll_delta
);
580 // Scroll by preferring to move the inner viewport first, only moving the
581 // outer if the inner is at its scroll extents.
582 void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta
);
584 void AnimatePageScale(base::TimeTicks monotonic_time
);
585 void AnimateScrollbars(base::TimeTicks monotonic_time
);
586 void AnimateTopControls(base::TimeTicks monotonic_time
);
588 void TrackDamageForAllSurfaces(
589 LayerImpl
* root_draw_layer
,
590 const LayerImplList
& render_surface_layer_list
);
592 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy
& policy
);
594 // This function should only be called from PrepareToDraw, as DidDrawAllLayers
595 // must be called if this helper function is called. Returns DRAW_SUCCESS if
596 // the frame should be drawn.
597 DrawResult
CalculateRenderPasses(FrameData
* frame
);
599 void ClearCurrentlyScrollingLayer();
601 bool HandleMouseOverScrollbar(LayerImpl
* layer_impl
,
602 const gfx::PointF
& device_viewport_point
);
604 LayerImpl
* FindScrollLayerForDeviceViewportPoint(
605 const gfx::PointF
& device_viewport_point
,
606 InputHandler::ScrollInputType type
,
607 LayerImpl
* layer_hit_by_point
,
608 bool* scroll_on_main_thread
,
609 bool* optional_has_ancestor_scroll_handler
) const;
610 float DeviceSpaceDistanceToLayer(const gfx::PointF
& device_viewport_point
,
611 LayerImpl
* layer_impl
);
612 void StartScrollbarFadeRecursive(LayerImpl
* layer
);
613 void SetManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
);
614 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
);
616 void MarkUIResourceNotEvicted(UIResourceId uid
);
618 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
619 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
621 void ScrollAnimationCreate(LayerImpl
* layer_impl
,
622 const gfx::ScrollOffset
& target_offset
,
623 const gfx::ScrollOffset
& current_offset
);
624 bool ScrollAnimationUpdateTarget(LayerImpl
* layer_impl
,
625 const gfx::Vector2dF
& scroll_delta
);
627 typedef base::hash_map
<UIResourceId
, UIResourceData
>
629 UIResourceMap ui_resource_map_
;
631 // Resources that were evicted by EvictAllUIResources. Resources are removed
632 // from this when they are touched by a create or destroy from the UI resource
634 std::set
<UIResourceId
> evicted_ui_resources_
;
636 scoped_ptr
<OutputSurface
> output_surface_
;
638 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
639 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
640 // |tile_manager_| can also be NULL when raster_enabled is false.
641 scoped_ptr
<ResourceProvider
> resource_provider_
;
642 scoped_ptr
<TileManager
> tile_manager_
;
643 bool use_gpu_rasterization_
;
644 GpuRasterizationStatus gpu_rasterization_status_
;
645 scoped_ptr
<TileTaskWorkerPool
> tile_task_worker_pool_
;
646 scoped_ptr
<ResourcePool
> resource_pool_
;
647 scoped_ptr
<ResourcePool
> staging_resource_pool_
;
648 scoped_ptr
<Renderer
> renderer_
;
650 GlobalStateThatImpactsTilePriority global_tile_state_
;
652 // Tree currently being drawn.
653 scoped_ptr
<LayerTreeImpl
> active_tree_
;
655 // In impl-side painting mode, tree with possibly incomplete rasterized
656 // content. May be promoted to active by ActivatePendingTree().
657 scoped_ptr
<LayerTreeImpl
> pending_tree_
;
659 // In impl-side painting mode, inert tree with layers that can be recycled
660 // by the next sync from the main thread.
661 scoped_ptr
<LayerTreeImpl
> recycle_tree_
;
663 InputHandlerClient
* input_handler_client_
;
664 bool did_lock_scrolling_layer_
;
665 bool should_bubble_scrolls_
;
666 bool wheel_scrolling_
;
667 bool scroll_affects_scroll_handler_
;
668 int scroll_layer_id_when_mouse_over_scrollbar_
;
669 ScopedPtrVector
<SwapPromise
> swap_promises_for_main_thread_scroll_update_
;
671 // An object to implement the ScrollElasticityHelper interface and
672 // hold all state related to elasticity. May be NULL if never requested.
673 scoped_ptr
<ScrollElasticityHelper
> scroll_elasticity_helper_
;
675 bool tile_priorities_dirty_
;
677 // The optional delegate for the root layer scroll offset.
678 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate_
;
679 LayerTreeSettings settings_
;
680 LayerTreeDebugState debug_state_
;
682 ManagedMemoryPolicy cached_managed_memory_policy_
;
684 gfx::Vector2dF accumulated_root_overscroll_
;
686 bool pinch_gesture_active_
;
687 bool pinch_gesture_end_should_clear_scrolling_layer_
;
688 gfx::Point previous_pinch_anchor_
;
690 scoped_ptr
<TopControlsManager
> top_controls_manager_
;
692 scoped_ptr
<PageScaleAnimation
> page_scale_animation_
;
694 scoped_ptr
<FrameRateCounter
> fps_counter_
;
695 scoped_ptr
<PaintTimeCounter
> paint_time_counter_
;
696 scoped_ptr
<MemoryHistory
> memory_history_
;
697 scoped_ptr
<DebugRectHistory
> debug_rect_history_
;
699 scoped_ptr
<TextureMailboxDeleter
> texture_mailbox_deleter_
;
701 // The maximum memory that would be used by the prioritized resource
702 // manager, if there were no limit on memory usage.
703 size_t max_memory_needed_bytes_
;
705 // Viewport size passed in from the main thread, in physical pixels. This
706 // value is the default size for all concepts of physical viewport (draw
707 // viewport, scrolling viewport and device viewport), but it can be
709 gfx::Size device_viewport_size_
;
711 // Conversion factor from CSS pixels to physical pixels when
712 // pageScaleFactor=1.
713 float device_scale_factor_
;
715 // Optional top-level constraints that can be set by the OutputSurface.
716 // - external_transform_ applies a transform above the root layer
717 // - external_viewport_ is used DrawProperties, tile management and
718 // glViewport/window projection matrix.
719 // - external_clip_ specifies a top-level clip rect
720 // - viewport_rect_for_tile_priority_ is the rect in view space used for
722 gfx::Transform external_transform_
;
723 gfx::Rect external_viewport_
;
724 gfx::Rect external_clip_
;
725 gfx::Rect viewport_rect_for_tile_priority_
;
726 bool resourceless_software_draw_
;
728 gfx::Rect viewport_damage_rect_
;
730 BeginFrameArgs current_begin_frame_args_
;
732 // Expected time between two begin impl frame calls.
733 base::TimeDelta begin_impl_frame_interval_
;
735 scoped_ptr
<AnimationRegistrar
> animation_registrar_
;
736 std::set
<ScrollbarAnimationController
*> scrollbar_animation_controllers_
;
737 std::set
<VideoFrameController
*> video_frame_controllers_
;
739 RenderingStatsInstrumentation
* rendering_stats_instrumentation_
;
740 MicroBenchmarkControllerImpl micro_benchmark_controller_
;
741 scoped_ptr
<TaskGraphRunner
> single_thread_synchronous_task_graph_runner_
;
743 // Optional callback to notify of new tree activations.
744 base::Closure tree_activation_callback_
;
746 SharedBitmapManager
* shared_bitmap_manager_
;
747 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager_
;
748 TaskGraphRunner
* task_graph_runner_
;
751 std::set
<SwapPromiseMonitor
*> swap_promise_monitor_
;
752 std::vector
<PictureLayerImpl::Pair
> picture_layer_pairs_
;
754 bool requires_high_res_to_draw_
;
755 bool is_likely_to_require_a_draw_
;
757 scoped_ptr
<FrameTimingTracker
> frame_timing_tracker_
;
759 scoped_ptr
<Viewport
> viewport_
;
761 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl
);
766 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_