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/rasterizer.h"
34 #include "cc/resources/resource_provider.h"
35 #include "cc/resources/tile_manager.h"
36 #include "cc/resources/ui_resource_client.h"
37 #include "cc/scheduler/commit_earlyout_reason.h"
38 #include "cc/scheduler/draw_result.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 PostAnimationEventsToMainThreadOnImplThread(
109 scoped_ptr
<AnimationEventsVector
> events
) = 0;
110 // Returns true if resources were deleted by this call.
111 virtual bool ReduceContentsTextureMemoryOnImplThread(
113 int priority_cutoff
) = 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 DidPrepareTiles() = 0;
121 // Called when page scale animation has completed on the impl thread.
122 virtual void DidCompletePageScaleAnimationOnImplThread() = 0;
125 virtual ~LayerTreeHostImplClient() {}
128 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
130 class CC_EXPORT LayerTreeHostImpl
131 : public InputHandler
,
132 public RendererClient
,
133 public TileManagerClient
,
134 public OutputSurfaceClient
,
135 public TopControlsManagerClient
,
136 public ScrollbarAnimationControllerClient
,
137 public base::SupportsWeakPtr
<LayerTreeHostImpl
> {
139 static scoped_ptr
<LayerTreeHostImpl
> Create(
140 const LayerTreeSettings
& settings
,
141 LayerTreeHostImplClient
* client
,
143 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
144 SharedBitmapManager
* shared_bitmap_manager
,
145 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
146 TaskGraphRunner
* task_graph_runner
,
148 ~LayerTreeHostImpl() override
;
150 // InputHandler implementation
151 void BindToClient(InputHandlerClient
* client
) override
;
152 InputHandler::ScrollStatus
ScrollBegin(
153 const gfx::Point
& viewport_point
,
154 InputHandler::ScrollInputType type
) override
;
155 InputHandler::ScrollStatus
ScrollAnimated(
156 const gfx::Point
& viewport_point
,
157 const gfx::Vector2dF
& scroll_delta
) override
;
158 InputHandlerScrollResult
ScrollBy(
159 const gfx::Point
& viewport_point
,
160 const gfx::Vector2dF
& scroll_delta
) override
;
161 bool ScrollVerticallyByPage(const gfx::Point
& viewport_point
,
162 ScrollDirection direction
) override
;
163 void SetRootLayerScrollOffsetDelegate(
164 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
) override
;
165 void OnRootLayerDelegatedScrollOffsetChanged() override
;
166 void ScrollEnd() override
;
167 InputHandler::ScrollStatus
FlingScrollBegin() override
;
168 void MouseMoveAt(const gfx::Point
& viewport_point
) override
;
169 void PinchGestureBegin() override
;
170 void PinchGestureUpdate(float magnify_delta
,
171 const gfx::Point
& anchor
) override
;
172 void PinchGestureEnd() override
;
173 void StartPageScaleAnimation(const gfx::Vector2d
& target_offset
,
176 base::TimeDelta duration
);
177 void SetNeedsAnimate() override
;
178 bool IsCurrentlyScrollingLayerAt(const gfx::Point
& viewport_point
,
179 InputHandler::ScrollInputType type
) override
;
180 bool HaveWheelEventHandlersAt(const gfx::Point
& viewport_point
) override
;
181 bool DoTouchEventsBlockScrollAt(const gfx::Point
& viewport_port
) override
;
182 scoped_ptr
<SwapPromiseMonitor
> CreateLatencyInfoSwapPromiseMonitor(
183 ui::LatencyInfo
* latency
) override
;
184 ScrollElasticityHelper
* CreateScrollElasticityHelper() override
;
186 // TopControlsManagerClient implementation.
187 float TopControlsHeight() const override
;
188 void SetCurrentTopControlsShownRatio(float offset
) override
;
189 float CurrentTopControlsShownRatio() const override
;
190 void DidChangeTopControlsPosition() override
;
191 bool HaveRootScrollLayer() const override
;
193 void UpdateViewportContainerSizes();
195 struct CC_EXPORT FrameData
: public RenderPassSink
{
197 ~FrameData() override
;
198 void AsValueInto(base::trace_event::TracedValue
* value
) const;
200 std::vector
<gfx::Rect
> occluding_screen_space_rects
;
201 std::vector
<gfx::Rect
> non_occluding_screen_space_rects
;
202 std::vector
<FrameTimingTracker::FrameAndRectIds
> composite_events
;
203 RenderPassList render_passes
;
204 RenderPassIdHashMap render_passes_by_id
;
205 const LayerImplList
* render_surface_layer_list
;
206 LayerImplList will_draw_layers
;
209 // RenderPassSink implementation.
210 void AppendRenderPass(scoped_ptr
<RenderPass
> render_pass
) override
;
213 virtual void BeginMainFrameAborted(CommitEarlyOutReason reason
);
214 virtual void BeginCommit();
215 virtual void CommitComplete();
216 virtual void Animate(base::TimeTicks monotonic_time
);
217 virtual void UpdateAnimationState(bool start_ready_animations
);
218 void ActivateAnimations();
219 void MainThreadHasStoppedFlinging();
220 void DidAnimateScrollOffset();
221 void SetViewportDamage(const gfx::Rect
& damage_rect
);
223 virtual void PrepareTiles();
225 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
226 // should try to avoid displaying the frame. If PrepareToDraw is called,
227 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
228 // called between the two.
229 virtual DrawResult
PrepareToDraw(FrameData
* frame
);
230 virtual void DrawLayers(FrameData
* frame
, base::TimeTicks frame_begin_time
);
231 // Must be called if and only if PrepareToDraw was called.
232 void DidDrawAllLayers(const FrameData
& frame
);
234 const LayerTreeSettings
& settings() const { return settings_
; }
236 // Evict all textures by enforcing a memory policy with an allocation of 0.
237 void EvictTexturesForTesting();
239 // When blocking, this prevents client_->NotifyReadyToActivate() from being
240 // called. When disabled, it calls client_->NotifyReadyToActivate()
241 // immediately if any notifications had been blocked while blocking.
242 virtual void BlockNotifyReadyToActivateForTesting(bool block
);
244 // Resets all of the trees to an empty state.
245 void ResetTreesForTesting();
247 DrawMode
GetDrawMode() const;
249 // Viewport size in draw space: this size is in physical pixels and is used
250 // for draw properties, tilings, quads and render passes.
251 gfx::Size
DrawViewportSize() const;
253 // Viewport rect in view space used for tiling prioritization.
254 const gfx::Rect
ViewportRectForTilePriority() const;
256 // RendererClient implementation.
257 void SetFullRootLayerDamage() override
;
259 // TileManagerClient implementation.
260 void NotifyReadyToActivate() override
;
261 void NotifyReadyToDraw() override
;
262 void NotifyTileStateChanged(const Tile
* tile
) override
;
263 scoped_ptr
<RasterTilePriorityQueue
> BuildRasterQueue(
264 TreePriority tree_priority
,
265 RasterTilePriorityQueue::Type type
) override
;
266 scoped_ptr
<EvictionTilePriorityQueue
> BuildEvictionQueue(
267 TreePriority tree_priority
) override
;
268 void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw
) override
;
270 // ScrollbarAnimationControllerClient implementation.
271 void StartAnimatingScrollbarAnimationController(
272 ScrollbarAnimationController
* controller
) override
;
273 void StopAnimatingScrollbarAnimationController(
274 ScrollbarAnimationController
* controller
) override
;
275 void PostDelayedScrollbarAnimationTask(const base::Closure
& task
,
276 base::TimeDelta delay
) override
;
277 void SetNeedsRedrawForScrollbarAnimation() override
;
279 // OutputSurfaceClient implementation.
280 void DeferredInitialize() override
;
281 void ReleaseGL() override
;
282 void CommitVSyncParameters(base::TimeTicks timebase
,
283 base::TimeDelta interval
) override
;
284 void SetNeedsRedrawRect(const gfx::Rect
& rect
) override
;
285 void SetExternalDrawConstraints(
286 const gfx::Transform
& transform
,
287 const gfx::Rect
& viewport
,
288 const gfx::Rect
& clip
,
289 const gfx::Rect
& viewport_rect_for_tile_priority
,
290 const gfx::Transform
& transform_for_tile_priority
,
291 bool resourceless_software_draw
) override
;
292 void DidLoseOutputSurface() override
;
293 void DidSwapBuffers() override
;
294 void DidSwapBuffersComplete() override
;
295 void ReclaimResources(const CompositorFrameAck
* ack
) override
;
296 void SetMemoryPolicy(const ManagedMemoryPolicy
& policy
) override
;
297 void SetTreeActivationCallback(const base::Closure
& callback
) override
;
299 // Called from LayerTreeImpl.
300 void OnCanDrawStateChangedForTree();
303 int id() const { return id_
; }
304 bool CanDraw() const;
305 OutputSurface
* output_surface() const { return output_surface_
.get(); }
307 std::string
LayerTreeAsJson() const;
309 void FinishAllRendering();
310 int SourceAnimationFrameNumber() const;
312 virtual bool InitializeRenderer(scoped_ptr
<OutputSurface
> output_surface
);
313 TileManager
* tile_manager() { return tile_manager_
.get(); }
314 void SetUseGpuRasterization(bool use_gpu
);
315 bool use_gpu_rasterization() const { return use_gpu_rasterization_
; }
317 GpuRasterizationStatus
gpu_rasterization_status() const {
318 return gpu_rasterization_status_
;
320 void set_gpu_rasterization_status(
321 GpuRasterizationStatus gpu_rasterization_status
) {
322 gpu_rasterization_status_
= gpu_rasterization_status
;
325 bool create_low_res_tiling() const {
326 return settings_
.create_low_res_tiling
&& !use_gpu_rasterization_
;
328 ResourcePool
* resource_pool() { return resource_pool_
.get(); }
329 Renderer
* renderer() { return renderer_
.get(); }
330 Rasterizer
* rasterizer() { return rasterizer_
.get(); }
331 const RendererCapabilitiesImpl
& GetRendererCapabilities() const;
333 virtual bool SwapBuffers(const FrameData
& frame
);
334 virtual void WillBeginImplFrame(const BeginFrameArgs
& args
);
335 void DidModifyTilePriorities();
337 LayerTreeImpl
* active_tree() { return active_tree_
.get(); }
338 const LayerTreeImpl
* active_tree() const { return active_tree_
.get(); }
339 LayerTreeImpl
* pending_tree() { return pending_tree_
.get(); }
340 const LayerTreeImpl
* pending_tree() const { return pending_tree_
.get(); }
341 LayerTreeImpl
* recycle_tree() { return recycle_tree_
.get(); }
342 const LayerTreeImpl
* recycle_tree() const { return recycle_tree_
.get(); }
343 // Returns the tree LTH synchronizes with.
344 LayerTreeImpl
* sync_tree() {
345 // TODO(enne): This is bogus. It should return based on the value of
346 // Proxy::CommitToActiveTree and not whether the pending tree exists.
347 return pending_tree_
? pending_tree_
.get() : active_tree_
.get();
349 virtual void CreatePendingTree();
350 virtual void ActivateSyncTree();
352 // Shortcuts to layers on the active tree.
353 LayerImpl
* RootLayer() const;
354 LayerImpl
* InnerViewportScrollLayer() const;
355 LayerImpl
* OuterViewportScrollLayer() const;
356 LayerImpl
* CurrentlyScrollingLayer() const;
358 int scroll_layer_id_when_mouse_over_scrollbar() const {
359 return scroll_layer_id_when_mouse_over_scrollbar_
;
361 bool scroll_affects_scroll_handler() const {
362 return scroll_affects_scroll_handler_
;
364 void QueueSwapPromiseForMainThreadScrollUpdate(
365 scoped_ptr
<SwapPromise
> swap_promise
);
367 bool IsActivelyScrolling() const;
369 virtual void SetVisible(bool visible
);
370 bool visible() const { return visible_
; }
372 bool AnimationsAreVisible() { return visible() && CanDraw(); }
374 void SetNeedsCommit() { client_
->SetNeedsCommitOnImplThread(); }
375 void SetNeedsRedraw();
377 ManagedMemoryPolicy
ActualManagedMemoryPolicy() const;
379 size_t memory_allocation_limit_bytes() const;
380 int memory_allocation_priority_cutoff() const;
382 void SetViewportSize(const gfx::Size
& device_viewport_size
);
383 gfx::Size
device_viewport_size() const { return device_viewport_size_
; }
385 void SetDeviceScaleFactor(float device_scale_factor
);
386 float device_scale_factor() const { return device_scale_factor_
; }
388 void SetPageScaleOnActiveTree(float page_scale_factor
);
390 const gfx::Transform
& DrawTransform() const;
392 scoped_ptr
<ScrollAndScaleSet
> ProcessScrollDeltas();
394 void set_max_memory_needed_bytes(size_t bytes
) {
395 max_memory_needed_bytes_
= bytes
;
398 FrameRateCounter
* fps_counter() {
399 return fps_counter_
.get();
401 PaintTimeCounter
* paint_time_counter() {
402 return paint_time_counter_
.get();
404 MemoryHistory
* memory_history() {
405 return memory_history_
.get();
407 DebugRectHistory
* debug_rect_history() {
408 return debug_rect_history_
.get();
410 ResourceProvider
* resource_provider() {
411 return resource_provider_
.get();
413 TopControlsManager
* top_controls_manager() {
414 return top_controls_manager_
.get();
416 const GlobalStateThatImpactsTilePriority
& global_tile_state() {
417 return global_tile_state_
;
420 Proxy
* proxy() const { return proxy_
; }
422 AnimationRegistrar
* animation_registrar() const {
423 return animation_registrar_
.get();
426 void SetDebugState(const LayerTreeDebugState
& new_debug_state
);
427 const LayerTreeDebugState
& debug_state() const { return debug_state_
; }
429 class CC_EXPORT CullRenderPassesWithNoQuads
{
431 bool ShouldRemoveRenderPass(const RenderPassDrawQuad
& quad
,
432 const FrameData
& frame
) const;
434 // Iterates in draw order, so that when a surface is removed, and its
435 // target becomes empty, then its target can be removed also.
436 size_t RenderPassListBegin(const RenderPassList
& list
) const { return 0; }
437 size_t RenderPassListEnd(const RenderPassList
& list
) const {
440 size_t RenderPassListNext(size_t it
) const { return it
+ 1; }
443 template <typename RenderPassCuller
>
444 static void RemoveRenderPasses(RenderPassCuller culler
, FrameData
* frame
);
446 gfx::Vector2dF
accumulated_root_overscroll() const {
447 return accumulated_root_overscroll_
;
450 bool pinch_gesture_active() const { return pinch_gesture_active_
; }
452 void SetTreePriority(TreePriority priority
);
453 TreePriority
GetTreePriority() const;
455 void UpdateCurrentBeginFrameArgs(const BeginFrameArgs
& args
);
456 void ResetCurrentBeginFrameArgsForNextFrame();
457 virtual BeginFrameArgs
CurrentBeginFrameArgs() const;
459 // Expected time between two begin impl frame calls.
460 base::TimeDelta
begin_impl_frame_interval() const {
461 return begin_impl_frame_interval_
;
464 void AsValueWithFrameInto(FrameData
* frame
,
465 base::trace_event::TracedValue
* value
) const;
466 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValueWithFrame(
467 FrameData
* frame
) const;
468 void ActivationStateAsValueInto(base::trace_event::TracedValue
* value
) const;
470 bool page_scale_animation_active() const { return !!page_scale_animation_
; }
472 virtual void CreateUIResource(UIResourceId uid
,
473 const UIResourceBitmap
& bitmap
);
474 // Deletes a UI resource. May safely be called more than once.
475 virtual void DeleteUIResource(UIResourceId uid
);
476 void EvictAllUIResources();
477 bool EvictedUIResourcesExist() const;
479 virtual ResourceProvider::ResourceId
ResourceIdForUIResource(
480 UIResourceId uid
) const;
482 virtual bool IsUIResourceOpaque(UIResourceId uid
) const;
484 struct UIResourceData
{
485 ResourceProvider::ResourceId resource_id
;
490 void ScheduleMicroBenchmark(scoped_ptr
<MicroBenchmarkImpl
> benchmark
);
492 CompositorFrameMetadata
MakeCompositorFrameMetadata() const;
493 // Viewport rectangle and clip in nonflipped window space. These rects
494 // should only be used by Renderer subclasses to populate glViewport/glClip
495 // and their software-mode equivalents.
496 gfx::Rect
DeviceViewport() const;
497 gfx::Rect
DeviceClip() const;
499 // When a SwapPromiseMonitor is created on the impl thread, it calls
500 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
501 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
502 // to unregister itself.
503 void InsertSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
504 void RemoveSwapPromiseMonitor(SwapPromiseMonitor
* monitor
);
506 void GetPictureLayerImplPairs(std::vector
<PictureLayerImpl::Pair
>* layers
,
507 bool need_valid_tile_priorities
) const;
509 void SetRequiresHighResToDraw() { requires_high_res_to_draw_
= true; }
510 void ResetRequiresHighResToDraw() { requires_high_res_to_draw_
= false; }
511 bool RequiresHighResToDraw() const { return requires_high_res_to_draw_
; }
513 // Only valid for synchronous (non-scheduled) single-threaded case.
514 void SynchronouslyInitializeAllTiles();
516 virtual scoped_ptr
<Rasterizer
> CreateRasterizer();
517 virtual void CreateResourceAndTileTaskWorkerPool(
518 scoped_ptr
<TileTaskWorkerPool
>* tile_task_worker_pool
,
519 scoped_ptr
<ResourcePool
>* resource_pool
,
520 scoped_ptr
<ResourcePool
>* staging_resource_pool
);
522 bool prepare_tiles_needed() const { return tile_priorities_dirty_
; }
524 FrameTimingTracker
* frame_timing_tracker() {
525 return frame_timing_tracker_
.get();
528 gfx::Vector2dF
ScrollLayer(LayerImpl
* layer_impl
,
529 const gfx::Vector2dF
& delta
,
530 const gfx::Point
& viewport_point
,
531 bool is_wheel_scroll
);
535 const LayerTreeSettings
& settings
,
536 LayerTreeHostImplClient
* client
,
538 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
539 SharedBitmapManager
* shared_bitmap_manager
,
540 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
541 TaskGraphRunner
* task_graph_runner
,
544 // Virtual for testing.
545 virtual void AnimateLayers(base::TimeTicks monotonic_time
);
547 bool is_likely_to_require_a_draw() const {
548 return is_likely_to_require_a_draw_
;
551 LayerTreeHostImplClient
* client_
;
555 gfx::Vector2dF
ScrollLayerWithViewportSpaceDelta(
556 LayerImpl
* layer_impl
,
557 const gfx::PointF
& viewport_point
,
558 const gfx::Vector2dF
& viewport_delta
);
560 void CreateAndSetRenderer();
561 void CreateAndSetTileManager();
562 void DestroyTileManager();
563 void ReleaseTreeResources();
564 void RecreateTreeResources();
565 void EnforceZeroBudget(bool zero_budget
);
567 bool IsSynchronousSingleThreaded() const;
569 Viewport
* viewport() { return viewport_
.get(); }
571 // Scroll by preferring to move the outer viewport first, only moving the
572 // inner if the outer is at its scroll extents.
573 void ScrollViewportBy(gfx::Vector2dF scroll_delta
);
574 // Scroll by preferring to move the inner viewport first, only moving the
575 // outer if the inner is at its scroll extents.
576 void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta
);
577 void AnimatePageScale(base::TimeTicks monotonic_time
);
578 void AnimateScrollbars(base::TimeTicks monotonic_time
);
579 void AnimateTopControls(base::TimeTicks monotonic_time
);
581 void TrackDamageForAllSurfaces(
582 LayerImpl
* root_draw_layer
,
583 const LayerImplList
& render_surface_layer_list
);
585 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy
& policy
);
587 // This function should only be called from PrepareToDraw, as DidDrawAllLayers
588 // must be called if this helper function is called. Returns DRAW_SUCCESS if
589 // the frame should be drawn.
590 DrawResult
CalculateRenderPasses(FrameData
* frame
);
592 void ClearCurrentlyScrollingLayer();
594 bool HandleMouseOverScrollbar(LayerImpl
* layer_impl
,
595 const gfx::PointF
& device_viewport_point
);
597 LayerImpl
* FindScrollLayerForDeviceViewportPoint(
598 const gfx::PointF
& device_viewport_point
,
599 InputHandler::ScrollInputType type
,
600 LayerImpl
* layer_hit_by_point
,
601 bool* scroll_on_main_thread
,
602 bool* optional_has_ancestor_scroll_handler
) const;
603 float DeviceSpaceDistanceToLayer(const gfx::PointF
& device_viewport_point
,
604 LayerImpl
* layer_impl
);
605 void StartScrollbarFadeRecursive(LayerImpl
* layer
);
606 void SetManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
,
608 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy
& policy
);
610 void MarkUIResourceNotEvicted(UIResourceId uid
);
612 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
613 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
615 void ScrollAnimationCreate(LayerImpl
* layer_impl
,
616 const gfx::ScrollOffset
& target_offset
,
617 const gfx::ScrollOffset
& current_offset
);
618 bool ScrollAnimationUpdateTarget(LayerImpl
* layer_impl
,
619 const gfx::Vector2dF
& scroll_delta
);
621 typedef base::hash_map
<UIResourceId
, UIResourceData
>
623 UIResourceMap ui_resource_map_
;
625 // Resources that were evicted by EvictAllUIResources. Resources are removed
626 // from this when they are touched by a create or destroy from the UI resource
628 std::set
<UIResourceId
> evicted_ui_resources_
;
630 scoped_ptr
<OutputSurface
> output_surface_
;
632 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
633 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
634 // |tile_manager_| can also be NULL when raster_enabled is false.
635 scoped_ptr
<ResourceProvider
> resource_provider_
;
636 scoped_ptr
<TileManager
> tile_manager_
;
637 bool use_gpu_rasterization_
;
638 GpuRasterizationStatus gpu_rasterization_status_
;
639 scoped_ptr
<TileTaskWorkerPool
> tile_task_worker_pool_
;
640 scoped_ptr
<Rasterizer
> rasterizer_
;
641 scoped_ptr
<ResourcePool
> resource_pool_
;
642 scoped_ptr
<ResourcePool
> staging_resource_pool_
;
643 scoped_ptr
<Renderer
> renderer_
;
645 GlobalStateThatImpactsTilePriority global_tile_state_
;
647 // Tree currently being drawn.
648 scoped_ptr
<LayerTreeImpl
> active_tree_
;
650 // In impl-side painting mode, tree with possibly incomplete rasterized
651 // content. May be promoted to active by ActivatePendingTree().
652 scoped_ptr
<LayerTreeImpl
> pending_tree_
;
654 // In impl-side painting mode, inert tree with layers that can be recycled
655 // by the next sync from the main thread.
656 scoped_ptr
<LayerTreeImpl
> recycle_tree_
;
658 InputHandlerClient
* input_handler_client_
;
659 bool did_lock_scrolling_layer_
;
660 bool should_bubble_scrolls_
;
661 bool wheel_scrolling_
;
662 bool scroll_affects_scroll_handler_
;
663 int scroll_layer_id_when_mouse_over_scrollbar_
;
664 ScopedPtrVector
<SwapPromise
> swap_promises_for_main_thread_scroll_update_
;
666 // An object to implement the ScrollElasticityHelper interface and
667 // hold all state related to elasticity. May be NULL if never requested.
668 scoped_ptr
<ScrollElasticityHelper
> scroll_elasticity_helper_
;
670 bool tile_priorities_dirty_
;
672 // The optional delegate for the root layer scroll offset.
673 LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate_
;
674 LayerTreeSettings settings_
;
675 LayerTreeDebugState debug_state_
;
677 ManagedMemoryPolicy cached_managed_memory_policy_
;
679 gfx::Vector2dF accumulated_root_overscroll_
;
681 bool pinch_gesture_active_
;
682 bool pinch_gesture_end_should_clear_scrolling_layer_
;
683 gfx::Point previous_pinch_anchor_
;
685 scoped_ptr
<TopControlsManager
> top_controls_manager_
;
687 scoped_ptr
<PageScaleAnimation
> page_scale_animation_
;
689 scoped_ptr
<FrameRateCounter
> fps_counter_
;
690 scoped_ptr
<PaintTimeCounter
> paint_time_counter_
;
691 scoped_ptr
<MemoryHistory
> memory_history_
;
692 scoped_ptr
<DebugRectHistory
> debug_rect_history_
;
694 scoped_ptr
<TextureMailboxDeleter
> texture_mailbox_deleter_
;
696 // The maximum memory that would be used by the prioritized resource
697 // manager, if there were no limit on memory usage.
698 size_t max_memory_needed_bytes_
;
702 // Viewport size passed in from the main thread, in physical pixels. This
703 // value is the default size for all concepts of physical viewport (draw
704 // viewport, scrolling viewport and device viewport), but it can be
706 gfx::Size device_viewport_size_
;
708 // Conversion factor from CSS pixels to physical pixels when
709 // pageScaleFactor=1.
710 float device_scale_factor_
;
712 // Optional top-level constraints that can be set by the OutputSurface.
713 // - external_transform_ applies a transform above the root layer
714 // - external_viewport_ is used DrawProperties, tile management and
715 // glViewport/window projection matrix.
716 // - external_clip_ specifies a top-level clip rect
717 // - viewport_rect_for_tile_priority_ is the rect in view space used for
719 gfx::Transform external_transform_
;
720 gfx::Rect external_viewport_
;
721 gfx::Rect external_clip_
;
722 gfx::Rect viewport_rect_for_tile_priority_
;
723 bool resourceless_software_draw_
;
725 gfx::Rect viewport_damage_rect_
;
727 BeginFrameArgs current_begin_frame_args_
;
729 // Expected time between two begin impl frame calls.
730 base::TimeDelta begin_impl_frame_interval_
;
732 scoped_ptr
<AnimationRegistrar
> animation_registrar_
;
733 std::set
<ScrollbarAnimationController
*> scrollbar_animation_controllers_
;
735 RenderingStatsInstrumentation
* rendering_stats_instrumentation_
;
736 MicroBenchmarkControllerImpl micro_benchmark_controller_
;
737 scoped_ptr
<TaskGraphRunner
> single_thread_synchronous_task_graph_runner_
;
739 // Optional callback to notify of new tree activations.
740 base::Closure tree_activation_callback_
;
742 SharedBitmapManager
* shared_bitmap_manager_
;
743 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager_
;
744 TaskGraphRunner
* task_graph_runner_
;
747 std::set
<SwapPromiseMonitor
*> swap_promise_monitor_
;
748 std::vector
<PictureLayerImpl::Pair
> picture_layer_pairs_
;
750 bool requires_high_res_to_draw_
;
751 bool is_likely_to_require_a_draw_
;
753 scoped_ptr
<FrameTimingTracker
> frame_timing_tracker_
;
755 scoped_ptr
<Viewport
> viewport_
;
757 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl
);
762 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_