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
{
87 // LayerTreeHost->Proxy callback interface.
88 class LayerTreeHostImplClient
{
90 virtual void UpdateRendererCapabilitiesOnImplThread() = 0;
91 virtual void DidLoseOutputSurfaceOnImplThread() = 0;
92 virtual void CommitVSyncParameters(base::TimeTicks timebase
,
93 base::TimeDelta interval
) = 0;
94 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time
) = 0;
95 virtual void SetMaxSwapsPendingOnImplThread(int max
) = 0;
96 virtual void DidSwapBuffersOnImplThread() = 0;
97 virtual void DidSwapBuffersCompleteOnImplThread() = 0;
98 virtual void OnCanDrawStateChanged(bool can_draw
) = 0;
99 virtual void NotifyReadyToActivate() = 0;
100 virtual void NotifyReadyToDraw() = 0;
101 // Please call these 3 functions through
102 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
103 // SetNeedsAnimate().
104 virtual void SetNeedsRedrawOnImplThread() = 0;
105 virtual void SetNeedsRedrawRectOnImplThread(const gfx::Rect
& damage_rect
) = 0;
106 virtual void SetNeedsAnimateOnImplThread() = 0;
107 virtual void SetNeedsCommitOnImplThread() = 0;
108 virtual void SetNeedsPrepareTilesOnImplThread() = 0;
109 virtual void SetVideoNeedsBeginFrames(bool needs_begin_frames
) = 0;
110 virtual void PostAnimationEventsToMainThreadOnImplThread(
111 scoped_ptr
<AnimationEventsVector
> events
) = 0;
112 // Returns true if resources were deleted by this call.
113 virtual bool ReduceContentsTextureMemoryOnImplThread(
115 int priority_cutoff
) = 0;
116 virtual bool IsInsideDraw() = 0;
117 virtual void RenewTreePriority() = 0;
118 virtual void PostDelayedAnimationTaskOnImplThread(const base::Closure
& task
,
119 base::TimeDelta delay
) = 0;
120 virtual void DidActivateSyncTree() = 0;
121 virtual void DidPrepareTiles() = 0;
123 // Called when page scale animation has completed on the impl thread.
124 virtual void DidCompletePageScaleAnimationOnImplThread() = 0;
126 // Called when output surface asks for a draw.
127 virtual void OnDrawForOutputSurface() = 0;
130 virtual ~LayerTreeHostImplClient() {}
133 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
135 class CC_EXPORT LayerTreeHostImpl
136 : public InputHandler
,
137 public RendererClient
,
138 public TileManagerClient
,
139 public OutputSurfaceClient
,
140 public TopControlsManagerClient
,
141 public ScrollbarAnimationControllerClient
,
142 public VideoFrameControllerClient
,
143 public base::SupportsWeakPtr
<LayerTreeHostImpl
> {
145 static scoped_ptr
<LayerTreeHostImpl
> Create(
146 const LayerTreeSettings
& settings
,
147 LayerTreeHostImplClient
* client
,
149 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
150 SharedBitmapManager
* shared_bitmap_manager
,
151 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
152 TaskGraphRunner
* task_graph_runner
,
154 ~LayerTreeHostImpl() override
;
156 // InputHandler implementation
157 void BindToClient(InputHandlerClient
* client
) override
;
158 InputHandler::ScrollStatus
ScrollBegin(
159 const gfx::Point
& viewport_point
,
160 InputHandler::ScrollInputType type
) override
;
161 InputHandler::ScrollStatus
ScrollAnimated(
162 const gfx::Point
& viewport_point
,
163 const gfx::Vector2dF
& scroll_delta
) override
;
164 InputHandlerScrollResult
ScrollBy(
165 const gfx::Point
& viewport_point
,
166 const gfx::Vector2dF
& scroll_delta
) override
;
167 bool ScrollVerticallyByPage(const gfx::Point
& viewport_point
,
168 ScrollDirection direction
) override
;
169 void SetRootLayerScrollOffsetDelegate(
170 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
) override
;
171 void OnRootLayerDelegatedScrollOffsetChanged() override
;
172 void ScrollEnd() override
;
173 InputHandler::ScrollStatus
FlingScrollBegin() override
;
174 void MouseMoveAt(const gfx::Point
& viewport_point
) override
;
175 void PinchGestureBegin() override
;
176 void PinchGestureUpdate(float magnify_delta
,
177 const gfx::Point
& anchor
) override
;
178 void PinchGestureEnd() override
;
179 void StartPageScaleAnimation(const gfx::Vector2d
& target_offset
,
182 base::TimeDelta duration
);
183 void SetNeedsAnimate() override
;
184 bool IsCurrentlyScrollingLayerAt(const gfx::Point
& viewport_point
,
185 InputHandler::ScrollInputType type
) override
;
186 bool HaveWheelEventHandlersAt(const gfx::Point
& viewport_point
) override
;
187 bool DoTouchEventsBlockScrollAt(const gfx::Point
& viewport_port
) override
;
188 scoped_ptr
<SwapPromiseMonitor
> CreateLatencyInfoSwapPromiseMonitor(
189 ui::LatencyInfo
* latency
) override
;
190 ScrollElasticityHelper
* CreateScrollElasticityHelper() override
;
192 // TopControlsManagerClient implementation.
193 float TopControlsHeight() const override
;
194 void SetCurrentTopControlsShownRatio(float offset
) override
;
195 float CurrentTopControlsShownRatio() const override
;
196 void DidChangeTopControlsPosition() override
;
197 bool HaveRootScrollLayer() const override
;
199 void UpdateViewportContainerSizes();
201 struct CC_EXPORT FrameData
: public RenderPassSink
{
203 ~FrameData() override
;
204 void AsValueInto(base::trace_event::TracedValue
* value
) const;
206 std::vector
<gfx::Rect
> occluding_screen_space_rects
;
207 std::vector
<gfx::Rect
> non_occluding_screen_space_rects
;
208 std::vector
<FrameTimingTracker::FrameAndRectIds
> composite_events
;
209 RenderPassList render_passes
;
210 RenderPassIdHashMap render_passes_by_id
;
211 const LayerImplList
* render_surface_layer_list
;
212 LayerImplList will_draw_layers
;
215 // RenderPassSink implementation.
216 void AppendRenderPass(scoped_ptr
<RenderPass
> render_pass
) override
;
219 virtual void BeginMainFrameAborted(CommitEarlyOutReason reason
);
220 virtual void BeginCommit();
221 virtual void CommitComplete();
222 virtual void Animate(base::TimeTicks monotonic_time
);
223 virtual void UpdateAnimationState(bool start_ready_animations
);
224 void ActivateAnimations();
225 void MainThreadHasStoppedFlinging();
226 void DidAnimateScrollOffset();
227 void SetViewportDamage(const gfx::Rect
& damage_rect
);
229 virtual void PrepareTiles();
231 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
232 // should try to avoid displaying the frame. If PrepareToDraw is called,
233 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
234 // called between the two.
235 virtual DrawResult
PrepareToDraw(FrameData
* frame
);
236 virtual void DrawLayers(FrameData
* frame
);
237 // Must be called if and only if PrepareToDraw was called.
238 void DidDrawAllLayers(const FrameData
& frame
);
240 const LayerTreeSettings
& settings() const { return settings_
; }
242 // Evict all textures by enforcing a memory policy with an allocation of 0.
243 void EvictTexturesForTesting();
245 // When blocking, this prevents client_->NotifyReadyToActivate() from being
246 // called. When disabled, it calls client_->NotifyReadyToActivate()
247 // immediately if any notifications had been blocked while blocking.
248 virtual void BlockNotifyReadyToActivateForTesting(bool block
);
250 // Resets all of the trees to an empty state.
251 void ResetTreesForTesting();
253 DrawMode
GetDrawMode() const;
255 // Viewport size in draw space: this size is in physical pixels and is used
256 // for draw properties, tilings, quads and render passes.
257 gfx::Size
DrawViewportSize() const;
259 // Viewport rect in view space used for tiling prioritization.
260 const gfx::Rect
ViewportRectForTilePriority() const;
262 // RendererClient implementation.
263 void SetFullRootLayerDamage() override
;
265 // TileManagerClient implementation.
266 void NotifyReadyToActivate() override
;
267 void NotifyReadyToDraw() override
;
268 void NotifyTileStateChanged(const Tile
* tile
) override
;
269 scoped_ptr
<RasterTilePriorityQueue
> BuildRasterQueue(
270 TreePriority tree_priority
,
271 RasterTilePriorityQueue::Type type
) override
;
272 scoped_ptr
<EvictionTilePriorityQueue
> BuildEvictionQueue(
273 TreePriority tree_priority
) override
;
274 void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw
) override
;
276 // ScrollbarAnimationControllerClient implementation.
277 void StartAnimatingScrollbarAnimationController(
278 ScrollbarAnimationController
* controller
) override
;
279 void StopAnimatingScrollbarAnimationController(
280 ScrollbarAnimationController
* controller
) override
;
281 void PostDelayedScrollbarAnimationTask(const base::Closure
& task
,
282 base::TimeDelta delay
) override
;
283 void SetNeedsRedrawForScrollbarAnimation() override
;
285 // VideoBeginFrameSource implementation.
286 void AddVideoFrameController(VideoFrameController
* controller
) override
;
287 void RemoveVideoFrameController(VideoFrameController
* controller
) override
;
289 // OutputSurfaceClient implementation.
290 void CommitVSyncParameters(base::TimeTicks timebase
,
291 base::TimeDelta interval
) override
;
292 void SetNeedsRedrawRect(const gfx::Rect
& rect
) override
;
293 void SetExternalDrawConstraints(
294 const gfx::Transform
& transform
,
295 const gfx::Rect
& viewport
,
296 const gfx::Rect
& clip
,
297 const gfx::Rect
& viewport_rect_for_tile_priority
,
298 const gfx::Transform
& transform_for_tile_priority
,
299 bool resourceless_software_draw
) override
;
300 void DidLoseOutputSurface() override
;
301 void DidSwapBuffers() override
;
302 void DidSwapBuffersComplete() override
;
303 void ReclaimResources(const CompositorFrameAck
* ack
) override
;
304 void SetMemoryPolicy(const ManagedMemoryPolicy
& policy
) override
;
305 void SetTreeActivationCallback(const base::Closure
& callback
) override
;
306 void OnDraw() override
;
308 // Called from LayerTreeImpl.
309 void OnCanDrawStateChangedForTree();
312 int id() const { return id_
; }
313 bool CanDraw() const;
314 OutputSurface
* output_surface() const { return output_surface_
.get(); }
316 std::string
LayerTreeAsJson() const;
318 void FinishAllRendering();
319 int SourceAnimationFrameNumber() const;
321 virtual bool InitializeRenderer(scoped_ptr
<OutputSurface
> output_surface
);
322 TileManager
* tile_manager() { return tile_manager_
.get(); }
324 void set_has_gpu_rasterization_trigger(bool flag
) {
325 has_gpu_rasterization_trigger_
= flag
;
327 void set_content_is_suitable_for_gpu_rasterization(bool flag
) {
328 content_is_suitable_for_gpu_rasterization_
= flag
;
330 void UpdateGpuRasterizationStatus();
331 bool use_gpu_rasterization() const { return use_gpu_rasterization_
; }
332 bool use_msaa() const { return use_msaa_
; }
334 GpuRasterizationStatus
gpu_rasterization_status() const {
335 return gpu_rasterization_status_
;
338 bool create_low_res_tiling() const {
339 return settings_
.create_low_res_tiling
&& !use_gpu_rasterization_
;
341 ResourcePool
* resource_pool() { return resource_pool_
.get(); }
342 Renderer
* renderer() { return renderer_
.get(); }
343 const RendererCapabilitiesImpl
& GetRendererCapabilities() const;
345 virtual bool SwapBuffers(const FrameData
& frame
);
346 virtual void WillBeginImplFrame(const BeginFrameArgs
& args
);
347 virtual void DidFinishImplFrame();
348 void DidModifyTilePriorities();
350 LayerTreeImpl
* active_tree() { return active_tree_
.get(); }
351 const LayerTreeImpl
* active_tree() const { return active_tree_
.get(); }
352 LayerTreeImpl
* pending_tree() { return pending_tree_
.get(); }
353 const LayerTreeImpl
* pending_tree() const { return pending_tree_
.get(); }
354 LayerTreeImpl
* recycle_tree() { return recycle_tree_
.get(); }
355 const LayerTreeImpl
* recycle_tree() const { return recycle_tree_
.get(); }
356 // Returns the tree LTH synchronizes with.
357 LayerTreeImpl
* sync_tree() {
358 // TODO(enne): This is bogus. It should return based on the value of
359 // Proxy::CommitToActiveTree and not whether the pending tree exists.
360 return pending_tree_
? pending_tree_
.get() : active_tree_
.get();
362 virtual void CreatePendingTree();
363 virtual void ActivateSyncTree();
365 // Shortcuts to layers on the active tree.
366 LayerImpl
* RootLayer() const;
367 LayerImpl
* InnerViewportScrollLayer() const;
368 LayerImpl
* OuterViewportScrollLayer() const;
369 LayerImpl
* CurrentlyScrollingLayer() const;
371 int scroll_layer_id_when_mouse_over_scrollbar() const {
372 return scroll_layer_id_when_mouse_over_scrollbar_
;
374 bool scroll_affects_scroll_handler() const {
375 return scroll_affects_scroll_handler_
;
377 void QueueSwapPromiseForMainThreadScrollUpdate(
378 scoped_ptr
<SwapPromise
> swap_promise
);
380 bool IsActivelyScrolling() const;
382 virtual void SetVisible(bool visible
);
383 bool visible() const { return visible_
; }
385 bool AnimationsAreVisible() { return visible() && CanDraw(); }
387 void SetNeedsCommit() { client_
->SetNeedsCommitOnImplThread(); }
388 void SetNeedsRedraw();
390 ManagedMemoryPolicy
ActualManagedMemoryPolicy() const;
392 size_t memory_allocation_limit_bytes() const;
393 int memory_allocation_priority_cutoff() const;
395 void SetViewportSize(const gfx::Size
& device_viewport_size
);
396 gfx::Size
device_viewport_size() const { return device_viewport_size_
; }
398 void SetDeviceScaleFactor(float device_scale_factor
);
399 float device_scale_factor() const { return device_scale_factor_
; }
401 void SetPageScaleOnActiveTree(float page_scale_factor
);
403 const gfx::Transform
& DrawTransform() const;
405 scoped_ptr
<ScrollAndScaleSet
> ProcessScrollDeltas();
407 void set_max_memory_needed_bytes(size_t bytes
) {
408 max_memory_needed_bytes_
= bytes
;
411 FrameRateCounter
* fps_counter() {
412 return fps_counter_
.get();
414 PaintTimeCounter
* paint_time_counter() {
415 return paint_time_counter_
.get();
417 MemoryHistory
* memory_history() {
418 return memory_history_
.get();
420 DebugRectHistory
* debug_rect_history() {
421 return debug_rect_history_
.get();
423 ResourceProvider
* resource_provider() {
424 return resource_provider_
.get();
426 TopControlsManager
* top_controls_manager() {
427 return top_controls_manager_
.get();
429 const GlobalStateThatImpactsTilePriority
& global_tile_state() {
430 return global_tile_state_
;
433 Proxy
* proxy() const { return proxy_
; }
435 AnimationRegistrar
* animation_registrar() const {
436 return animation_registrar_
.get();
439 void SetDebugState(const LayerTreeDebugState
& new_debug_state
);
440 const LayerTreeDebugState
& debug_state() const { return debug_state_
; }
442 gfx::Vector2dF
accumulated_root_overscroll() const {
443 return accumulated_root_overscroll_
;
446 bool pinch_gesture_active() const { return pinch_gesture_active_
; }
448 void SetTreePriority(TreePriority priority
);
449 TreePriority
GetTreePriority() const;
451 virtual BeginFrameArgs
CurrentBeginFrameArgs() const;
453 // Expected time between two begin impl frame calls.
454 base::TimeDelta
begin_impl_frame_interval() const {
455 return begin_impl_frame_interval_
;
458 void AsValueWithFrameInto(FrameData
* frame
,
459 base::trace_event::TracedValue
* value
) const;
460 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValueWithFrame(
461 FrameData
* frame
) const;
462 void ActivationStateAsValueInto(base::trace_event::TracedValue
* value
) const;
464 bool page_scale_animation_active() const { return !!page_scale_animation_
; }
466 virtual void CreateUIResource(UIResourceId uid
,
467 const UIResourceBitmap
& bitmap
);
468 // Deletes a UI resource. May safely be called more than once.
469 virtual void DeleteUIResource(UIResourceId uid
);
470 void EvictAllUIResources();
471 bool EvictedUIResourcesExist() const;
473 virtual ResourceProvider::ResourceId
ResourceIdForUIResource(
474 UIResourceId uid
) const;
476 virtual bool IsUIResourceOpaque(UIResourceId uid
) const;
478 struct UIResourceData
{
479 ResourceProvider::ResourceId resource_id
;
484 void ScheduleMicroBenchmark(scoped_ptr
<MicroBenchmarkImpl
> benchmark
);
486 CompositorFrameMetadata
MakeCompositorFrameMetadata() const;
487 // Viewport rectangle and clip in nonflipped window space. These rects
488 // should only be used by Renderer subclasses to populate glViewport/glClip
489 // and their software-mode equivalents.
490 gfx::Rect
DeviceViewport() const;
491 gfx::Rect
DeviceClip() const;
493 // When a SwapPromiseMonitor is created on the impl thread, it calls
494 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
495 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
496 // to unregister itself.
497 void InsertSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
498 void RemoveSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
500 // TODO(weiliangc): Replace RequiresHighResToDraw with scheduler waits for
501 // ReadyToDraw. crbug.com/469175
502 void SetRequiresHighResToDraw() { requires_high_res_to_draw_
= true; }
503 void ResetRequiresHighResToDraw() { requires_high_res_to_draw_
= false; }
504 bool RequiresHighResToDraw() const { return requires_high_res_to_draw_
; }
506 // Only valid for synchronous (non-scheduled) single-threaded case.
507 void SynchronouslyInitializeAllTiles();
509 virtual void CreateResourceAndTileTaskWorkerPool(
510 scoped_ptr
<TileTaskWorkerPool
>* tile_task_worker_pool
,
511 scoped_ptr
<ResourcePool
>* resource_pool
,
512 scoped_ptr
<ResourcePool
>* staging_resource_pool
);
514 bool prepare_tiles_needed() const { return tile_priorities_dirty_
; }
516 FrameTimingTracker
* frame_timing_tracker() {
517 return frame_timing_tracker_
.get();
520 gfx::Vector2dF
ScrollLayer(LayerImpl
* layer_impl
,
521 const gfx::Vector2dF
& delta
,
522 const gfx::Point
& viewport_point
,
523 bool is_wheel_scroll
);
525 // Record main frame timing information.
526 // |start_of_main_frame_args| is the BeginFrameArgs of the beginning of the
527 // main frame (ie the frame that kicked off the main frame).
528 // |expected_next_main_frame_args| is the BeginFrameArgs of the frame that
529 // follows the completion of the main frame (whether it is activation or some
530 // other completion, such as early out). Note that if there is a main frame
531 // scheduled in that frame, then this BeginFrameArgs will become the main
532 // frame args. However, if no such frame is scheduled, then this _would_ be
533 // the main frame args if it was scheduled.
534 void RecordMainFrameTiming(
535 const BeginFrameArgs
& start_of_main_frame_args
,
536 const BeginFrameArgs
& expected_next_main_frame_args
);
540 const LayerTreeSettings
& settings
,
541 LayerTreeHostImplClient
* client
,
543 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
544 SharedBitmapManager
* shared_bitmap_manager
,
545 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
546 TaskGraphRunner
* task_graph_runner
,
549 // Virtual for testing.
550 virtual void AnimateLayers(base::TimeTicks monotonic_time
);
552 bool is_likely_to_require_a_draw() const {
553 return is_likely_to_require_a_draw_
;
556 // Removes empty or orphan RenderPasses from the frame.
557 static void RemoveRenderPasses(FrameData
* frame
);
559 LayerTreeHostImplClient
* client_
;
563 gfx::Vector2dF
ScrollLayerWithViewportSpaceDelta(
564 LayerImpl
* layer_impl
,
565 const gfx::PointF
& viewport_point
,
566 const gfx::Vector2dF
& viewport_delta
);
568 void CreateAndSetRenderer();
569 void CreateAndSetTileManager();
570 void DestroyTileManager();
571 void ReleaseTreeResources();
572 void RecreateTreeResources();
574 bool IsSynchronousSingleThreaded() const;
576 Viewport
* viewport() { return viewport_
.get(); }
578 // Scroll by preferring to move the outer viewport first, only moving the
579 // inner if the outer is at its scroll extents.
580 void ScrollViewportBy(gfx::Vector2dF scroll_delta
);
581 // Scroll by preferring to move the inner viewport first, only moving the
582 // outer if the inner is at its scroll extents.
583 void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta
);
585 void AnimatePageScale(base::TimeTicks monotonic_time
);
586 void AnimateScrollbars(base::TimeTicks monotonic_time
);
587 void AnimateTopControls(base::TimeTicks monotonic_time
);
589 void TrackDamageForAllSurfaces(
590 LayerImpl
* root_draw_layer
,
591 const LayerImplList
& render_surface_layer_list
);
593 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy
& policy
);
595 // This function should only be called from PrepareToDraw, as DidDrawAllLayers
596 // must be called if this helper function is called. Returns DRAW_SUCCESS if
597 // the frame should be drawn.
598 DrawResult
CalculateRenderPasses(FrameData
* frame
);
600 void ClearCurrentlyScrollingLayer();
602 bool HandleMouseOverScrollbar(LayerImpl
* layer_impl
,
603 const gfx::PointF
& device_viewport_point
);
605 LayerImpl
* FindScrollLayerForDeviceViewportPoint(
606 const gfx::PointF
& device_viewport_point
,
607 InputHandler::ScrollInputType type
,
608 LayerImpl
* layer_hit_by_point
,
609 bool* scroll_on_main_thread
,
610 bool* optional_has_ancestor_scroll_handler
) const;
611 float DeviceSpaceDistanceToLayer(const gfx::PointF
& device_viewport_point
,
612 LayerImpl
* layer_impl
);
613 void StartScrollbarFadeRecursive(LayerImpl
* layer
);
614 void SetManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
);
615 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
);
617 void MarkUIResourceNotEvicted(UIResourceId uid
);
619 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
620 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
622 void ScrollAnimationCreate(LayerImpl
* layer_impl
,
623 const gfx::ScrollOffset
& target_offset
,
624 const gfx::ScrollOffset
& current_offset
);
625 bool ScrollAnimationUpdateTarget(LayerImpl
* layer_impl
,
626 const gfx::Vector2dF
& scroll_delta
);
628 typedef base::hash_map
<UIResourceId
, UIResourceData
>
630 UIResourceMap ui_resource_map_
;
632 // Resources that were evicted by EvictAllUIResources. Resources are removed
633 // from this when they are touched by a create or destroy from the UI resource
635 std::set
<UIResourceId
> evicted_ui_resources_
;
637 scoped_ptr
<OutputSurface
> output_surface_
;
639 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
640 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
641 // |tile_manager_| can also be NULL when raster_enabled is false.
642 scoped_ptr
<ResourceProvider
> resource_provider_
;
643 scoped_ptr
<TileManager
> tile_manager_
;
644 bool content_is_suitable_for_gpu_rasterization_
;
645 bool has_gpu_rasterization_trigger_
;
646 bool use_gpu_rasterization_
;
648 GpuRasterizationStatus gpu_rasterization_status_
;
649 scoped_ptr
<TileTaskWorkerPool
> tile_task_worker_pool_
;
650 scoped_ptr
<ResourcePool
> resource_pool_
;
651 scoped_ptr
<ResourcePool
> staging_resource_pool_
;
652 scoped_ptr
<Renderer
> renderer_
;
654 GlobalStateThatImpactsTilePriority global_tile_state_
;
656 // Tree currently being drawn.
657 scoped_ptr
<LayerTreeImpl
> active_tree_
;
659 // In impl-side painting mode, tree with possibly incomplete rasterized
660 // content. May be promoted to active by ActivatePendingTree().
661 scoped_ptr
<LayerTreeImpl
> pending_tree_
;
663 // In impl-side painting mode, inert tree with layers that can be recycled
664 // by the next sync from the main thread.
665 scoped_ptr
<LayerTreeImpl
> recycle_tree_
;
667 InputHandlerClient
* input_handler_client_
;
668 bool did_lock_scrolling_layer_
;
669 bool should_bubble_scrolls_
;
670 bool wheel_scrolling_
;
671 bool scroll_affects_scroll_handler_
;
672 int scroll_layer_id_when_mouse_over_scrollbar_
;
673 ScopedPtrVector
<SwapPromise
> swap_promises_for_main_thread_scroll_update_
;
675 // An object to implement the ScrollElasticityHelper interface and
676 // hold all state related to elasticity. May be NULL if never requested.
677 scoped_ptr
<ScrollElasticityHelper
> scroll_elasticity_helper_
;
679 bool tile_priorities_dirty_
;
681 // The optional delegate for the root layer scroll offset.
682 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate_
;
683 const LayerTreeSettings settings_
;
684 LayerTreeDebugState debug_state_
;
686 ManagedMemoryPolicy cached_managed_memory_policy_
;
688 gfx::Vector2dF accumulated_root_overscroll_
;
690 bool pinch_gesture_active_
;
691 bool pinch_gesture_end_should_clear_scrolling_layer_
;
692 gfx::Point previous_pinch_anchor_
;
694 scoped_ptr
<TopControlsManager
> top_controls_manager_
;
696 scoped_ptr
<PageScaleAnimation
> page_scale_animation_
;
698 scoped_ptr
<FrameRateCounter
> fps_counter_
;
699 scoped_ptr
<PaintTimeCounter
> paint_time_counter_
;
700 scoped_ptr
<MemoryHistory
> memory_history_
;
701 scoped_ptr
<DebugRectHistory
> debug_rect_history_
;
703 scoped_ptr
<TextureMailboxDeleter
> texture_mailbox_deleter_
;
705 // The maximum memory that would be used by the prioritized resource
706 // manager, if there were no limit on memory usage.
707 size_t max_memory_needed_bytes_
;
709 // Viewport size passed in from the main thread, in physical pixels. This
710 // value is the default size for all concepts of physical viewport (draw
711 // viewport, scrolling viewport and device viewport), but it can be
713 gfx::Size device_viewport_size_
;
715 // Conversion factor from CSS pixels to physical pixels when
716 // pageScaleFactor=1.
717 float device_scale_factor_
;
719 // Optional top-level constraints that can be set by the OutputSurface.
720 // - external_transform_ applies a transform above the root layer
721 // - external_viewport_ is used DrawProperties, tile management and
722 // glViewport/window projection matrix.
723 // - external_clip_ specifies a top-level clip rect
724 // - viewport_rect_for_tile_priority_ is the rect in view space used for
726 gfx::Transform external_transform_
;
727 gfx::Rect external_viewport_
;
728 gfx::Rect external_clip_
;
729 gfx::Rect viewport_rect_for_tile_priority_
;
730 bool resourceless_software_draw_
;
732 gfx::Rect viewport_damage_rect_
;
734 BeginFrameArgs current_begin_frame_args_
;
736 // Expected time between two begin impl frame calls.
737 base::TimeDelta begin_impl_frame_interval_
;
739 scoped_ptr
<AnimationRegistrar
> animation_registrar_
;
740 std::set
<ScrollbarAnimationController
*> scrollbar_animation_controllers_
;
741 std::set
<VideoFrameController
*> video_frame_controllers_
;
743 RenderingStatsInstrumentation
* rendering_stats_instrumentation_
;
744 MicroBenchmarkControllerImpl micro_benchmark_controller_
;
745 scoped_ptr
<TaskGraphRunner
> single_thread_synchronous_task_graph_runner_
;
747 // Optional callback to notify of new tree activations.
748 base::Closure tree_activation_callback_
;
750 SharedBitmapManager
* shared_bitmap_manager_
;
751 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager_
;
752 TaskGraphRunner
* task_graph_runner_
;
755 std::set
<SwapPromiseMonitor
*> swap_promise_monitor_
;
757 bool requires_high_res_to_draw_
;
758 bool is_likely_to_require_a_draw_
;
760 scoped_ptr
<FrameTimingTracker
> frame_timing_tracker_
;
762 scoped_ptr
<Viewport
> viewport_
;
764 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl
);
769 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_