[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / cc / trees / layer_tree_host_impl.h
blobb9a07f648382303b2a04483446a475a314aa4a22
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_
8 #include <set>
9 #include <string>
10 #include <vector>
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"
47 namespace gfx {
48 class ScrollOffset;
51 namespace cc {
53 class AnimationHost;
54 class CompletionEvent;
55 class CompositorFrameMetadata;
56 class DebugRectHistory;
57 class EvictionTilePriorityQueue;
58 class FrameRateCounter;
59 class LayerImpl;
60 class LayerTreeImpl;
61 class MemoryHistory;
62 class PageScaleAnimation;
63 class PaintTimeCounter;
64 class PictureLayerImpl;
65 class RasterTilePriorityQueue;
66 class TileTaskWorkerPool;
67 class RenderPassDrawQuad;
68 class RenderingStatsInstrumentation;
69 class ResourcePool;
70 class ScrollElasticityHelper;
71 class ScrollbarLayerImplBase;
72 class SwapPromise;
73 class SwapPromiseMonitor;
74 class TextureMailboxDeleter;
75 class TopControlsManager;
76 class UIResourceBitmap;
77 class UIResourceRequest;
78 struct ScrollAndScaleSet;
79 class Viewport;
81 enum class GpuRasterizationStatus {
82 ON,
83 ON_FORCED,
84 OFF_DEVICE,
85 OFF_VIEWPORT,
86 MSAA_CONTENT,
87 OFF_CONTENT
90 // LayerTreeHost->Proxy callback interface.
91 class LayerTreeHostImplClient {
92 public:
93 virtual void UpdateRendererCapabilitiesOnImplThread() = 0;
94 virtual void DidLoseOutputSurfaceOnImplThread() = 0;
95 virtual void CommitVSyncParameters(base::TimeTicks timebase,
96 base::TimeDelta interval) = 0;
97 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time) = 0;
98 virtual void SetMaxSwapsPendingOnImplThread(int max) = 0;
99 virtual void DidSwapBuffersOnImplThread() = 0;
100 virtual void DidSwapBuffersCompleteOnImplThread() = 0;
101 virtual void OnCanDrawStateChanged(bool can_draw) = 0;
102 virtual void NotifyReadyToActivate() = 0;
103 virtual void NotifyReadyToDraw() = 0;
104 // Please call these 3 functions through
105 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
106 // SetNeedsAnimate().
107 virtual void SetNeedsRedrawOnImplThread() = 0;
108 virtual void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) = 0;
109 virtual void SetNeedsAnimateOnImplThread() = 0;
110 virtual void SetNeedsCommitOnImplThread() = 0;
111 virtual void SetNeedsPrepareTilesOnImplThread() = 0;
112 virtual void SetVideoNeedsBeginFrames(bool needs_begin_frames) = 0;
113 virtual void PostAnimationEventsToMainThreadOnImplThread(
114 scoped_ptr<AnimationEventsVector> events) = 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 WillPrepareTiles() = 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;
129 virtual void PostFrameTimingEventsOnImplThread(
130 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
131 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) = 0;
133 protected:
134 virtual ~LayerTreeHostImplClient() {}
137 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
138 // state.
139 class CC_EXPORT LayerTreeHostImpl
140 : public InputHandler,
141 public RendererClient,
142 public TileManagerClient,
143 public OutputSurfaceClient,
144 public TopControlsManagerClient,
145 public ScrollbarAnimationControllerClient,
146 public VideoFrameControllerClient,
147 public MutatorHostClient,
148 public base::SupportsWeakPtr<LayerTreeHostImpl> {
149 public:
150 static scoped_ptr<LayerTreeHostImpl> Create(
151 const LayerTreeSettings& settings,
152 LayerTreeHostImplClient* client,
153 Proxy* proxy,
154 RenderingStatsInstrumentation* rendering_stats_instrumentation,
155 SharedBitmapManager* shared_bitmap_manager,
156 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
157 TaskGraphRunner* task_graph_runner,
158 int id);
159 ~LayerTreeHostImpl() override;
161 // InputHandler implementation
162 void BindToClient(InputHandlerClient* client) override;
163 InputHandler::ScrollStatus ScrollBegin(
164 const gfx::Point& viewport_point,
165 InputHandler::ScrollInputType type) override;
166 InputHandler::ScrollStatus RootScrollBegin(
167 InputHandler::ScrollInputType type) override;
168 InputHandler::ScrollStatus ScrollAnimated(
169 const gfx::Point& viewport_point,
170 const gfx::Vector2dF& scroll_delta) override;
171 void ApplyScroll(LayerImpl* layer, ScrollState* scroll_state);
172 InputHandlerScrollResult ScrollBy(
173 const gfx::Point& viewport_point,
174 const gfx::Vector2dF& scroll_delta) override;
175 bool ScrollVerticallyByPage(const gfx::Point& viewport_point,
176 ScrollDirection direction) override;
177 void SetRootLayerScrollOffsetDelegate(
178 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) override;
179 void OnRootLayerDelegatedScrollOffsetChanged() 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,
188 bool anchor_point,
189 float page_scale,
190 base::TimeDelta duration);
191 void SetNeedsAnimateInput() override;
192 bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point,
193 InputHandler::ScrollInputType type) override;
194 bool HaveWheelEventHandlersAt(const gfx::Point& viewport_point) override;
195 bool DoTouchEventsBlockScrollAt(const gfx::Point& viewport_port) override;
196 scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
197 ui::LatencyInfo* latency) override;
198 ScrollElasticityHelper* CreateScrollElasticityHelper() override;
200 // TopControlsManagerClient implementation.
201 float TopControlsHeight() const override;
202 void SetCurrentTopControlsShownRatio(float offset) override;
203 float CurrentTopControlsShownRatio() const override;
204 void DidChangeTopControlsPosition() override;
205 bool HaveRootScrollLayer() const override;
207 void UpdateViewportContainerSizes();
209 struct CC_EXPORT FrameData : public RenderPassSink {
210 FrameData();
211 ~FrameData() override;
212 void AsValueInto(base::trace_event::TracedValue* value) const;
214 std::vector<gfx::Rect> occluding_screen_space_rects;
215 std::vector<gfx::Rect> non_occluding_screen_space_rects;
216 std::vector<FrameTimingTracker::FrameAndRectIds> composite_events;
217 RenderPassList render_passes;
218 RenderPassIdHashMap render_passes_by_id;
219 const LayerImplList* render_surface_layer_list;
220 LayerImplList will_draw_layers;
221 bool has_no_damage;
223 // RenderPassSink implementation.
224 void AppendRenderPass(scoped_ptr<RenderPass> render_pass) override;
227 virtual void BeginMainFrameAborted(CommitEarlyOutReason reason);
228 virtual void BeginCommit();
229 virtual void CommitComplete();
230 virtual void Animate(base::TimeTicks monotonic_time);
231 virtual void UpdateAnimationState(bool start_ready_animations);
232 void ActivateAnimations();
233 void MainThreadHasStoppedFlinging();
234 void DidAnimateScrollOffset();
235 void SetViewportDamage(const gfx::Rect& damage_rect);
237 void SetTreeLayerFilterMutated(int layer_id,
238 LayerTreeImpl* tree,
239 const FilterOperations& filters);
240 void SetTreeLayerOpacityMutated(int layer_id,
241 LayerTreeImpl* tree,
242 float opacity);
243 void SetTreeLayerTransformMutated(int layer_id,
244 LayerTreeImpl* tree,
245 const gfx::Transform& transform);
246 void SetTreeLayerScrollOffsetMutated(int layer_id,
247 LayerTreeImpl* tree,
248 const gfx::ScrollOffset& scroll_offset);
249 void TreeLayerTransformIsPotentiallyAnimatingChanged(int layer_id,
250 LayerTreeImpl* tree,
251 bool is_animating);
253 // LayerTreeMutatorsClient implementation.
254 bool IsLayerInTree(int layer_id, LayerTreeType tree_type) const override;
255 void SetMutatorsNeedCommit() override;
256 void SetLayerFilterMutated(int layer_id,
257 LayerTreeType tree_type,
258 const FilterOperations& filters) override;
259 void SetLayerOpacityMutated(int layer_id,
260 LayerTreeType tree_type,
261 float opacity) override;
262 void SetLayerTransformMutated(int layer_id,
263 LayerTreeType tree_type,
264 const gfx::Transform& transform) override;
265 void SetLayerScrollOffsetMutated(
266 int layer_id,
267 LayerTreeType tree_type,
268 const gfx::ScrollOffset& scroll_offset) override;
269 void LayerTransformIsPotentiallyAnimatingChanged(int layer_id,
270 LayerTreeType tree_type,
271 bool is_animating) override;
272 void ScrollOffsetAnimationFinished() override;
273 gfx::ScrollOffset GetScrollOffsetForAnimation(int layer_id) const override;
275 virtual bool PrepareTiles();
277 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
278 // should try to avoid displaying the frame. If PrepareToDraw is called,
279 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
280 // called between the two.
281 virtual DrawResult PrepareToDraw(FrameData* frame);
282 virtual void DrawLayers(FrameData* frame);
283 // Must be called if and only if PrepareToDraw was called.
284 void DidDrawAllLayers(const FrameData& frame);
286 const LayerTreeSettings& settings() const { return settings_; }
288 // Evict all textures by enforcing a memory policy with an allocation of 0.
289 void EvictTexturesForTesting();
291 // When blocking, this prevents client_->NotifyReadyToActivate() from being
292 // called. When disabled, it calls client_->NotifyReadyToActivate()
293 // immediately if any notifications had been blocked while blocking.
294 virtual void BlockNotifyReadyToActivateForTesting(bool block);
296 // Resets all of the trees to an empty state.
297 void ResetTreesForTesting();
299 size_t SourceAnimationFrameNumberForTesting() const;
301 DrawMode GetDrawMode() const;
303 // Viewport size in draw space: this size is in physical pixels and is used
304 // for draw properties, tilings, quads and render passes.
305 gfx::Size DrawViewportSize() const;
307 // Viewport rect in view space used for tiling prioritization.
308 const gfx::Rect ViewportRectForTilePriority() const;
310 // RendererClient implementation.
311 void SetFullRootLayerDamage() override;
313 // TileManagerClient implementation.
314 void NotifyReadyToActivate() override;
315 void NotifyReadyToDraw() override;
316 void NotifyAllTileTasksCompleted() override;
317 void NotifyTileStateChanged(const Tile* tile) override;
318 scoped_ptr<RasterTilePriorityQueue> BuildRasterQueue(
319 TreePriority tree_priority,
320 RasterTilePriorityQueue::Type type) override;
321 scoped_ptr<EvictionTilePriorityQueue> BuildEvictionQueue(
322 TreePriority tree_priority) override;
323 void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) override;
325 // ScrollbarAnimationControllerClient implementation.
326 void StartAnimatingScrollbarAnimationController(
327 ScrollbarAnimationController* controller) override;
328 void StopAnimatingScrollbarAnimationController(
329 ScrollbarAnimationController* controller) override;
330 void PostDelayedScrollbarAnimationTask(const base::Closure& task,
331 base::TimeDelta delay) override;
332 void SetNeedsRedrawForScrollbarAnimation() override;
334 // VideoBeginFrameSource implementation.
335 void AddVideoFrameController(VideoFrameController* controller) override;
336 void RemoveVideoFrameController(VideoFrameController* controller) override;
338 // OutputSurfaceClient implementation.
339 void CommitVSyncParameters(base::TimeTicks timebase,
340 base::TimeDelta interval) override;
341 void SetNeedsRedrawRect(const gfx::Rect& rect) override;
342 void SetExternalDrawConstraints(
343 const gfx::Transform& transform,
344 const gfx::Rect& viewport,
345 const gfx::Rect& clip,
346 const gfx::Rect& viewport_rect_for_tile_priority,
347 const gfx::Transform& transform_for_tile_priority,
348 bool resourceless_software_draw) override;
349 void DidLoseOutputSurface() override;
350 void DidSwapBuffers() override;
351 void DidSwapBuffersComplete() override;
352 void ReclaimResources(const CompositorFrameAck* ack) override;
353 void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override;
354 void SetTreeActivationCallback(const base::Closure& callback) override;
355 void OnDraw() override;
357 // Called from LayerTreeImpl.
358 void OnCanDrawStateChangedForTree();
360 // Implementation.
361 int id() const { return id_; }
362 bool CanDraw() const;
363 OutputSurface* output_surface() const { return output_surface_.get(); }
365 std::string LayerTreeAsJson() const;
367 void FinishAllRendering();
369 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
370 TileManager* tile_manager() { return tile_manager_.get(); }
372 void SetHasGpuRasterizationTrigger(bool flag) {
373 has_gpu_rasterization_trigger_ = flag;
374 UpdateGpuRasterizationStatus();
376 void SetContentIsSuitableForGpuRasterization(bool flag) {
377 content_is_suitable_for_gpu_rasterization_ = flag;
378 UpdateGpuRasterizationStatus();
380 bool CanUseGpuRasterization();
381 void UpdateTreeResourcesForGpuRasterizationIfNeeded();
382 bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
383 bool use_msaa() const { return use_msaa_; }
385 GpuRasterizationStatus gpu_rasterization_status() const {
386 return gpu_rasterization_status_;
389 bool create_low_res_tiling() const {
390 return settings_.create_low_res_tiling && !use_gpu_rasterization_;
392 ResourcePool* resource_pool() { return resource_pool_.get(); }
393 Renderer* renderer() { return renderer_.get(); }
394 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
396 virtual bool SwapBuffers(const FrameData& frame);
397 virtual void WillBeginImplFrame(const BeginFrameArgs& args);
398 virtual void DidFinishImplFrame();
399 void DidModifyTilePriorities();
401 LayerTreeImpl* active_tree() { return active_tree_.get(); }
402 const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
403 LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
404 const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
405 LayerTreeImpl* recycle_tree() { return recycle_tree_.get(); }
406 const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
407 // Returns the tree LTH synchronizes with.
408 LayerTreeImpl* sync_tree() {
409 // TODO(enne): This is bogus. It should return based on the value of
410 // Proxy::CommitToActiveTree and not whether the pending tree exists.
411 return pending_tree_ ? pending_tree_.get() : active_tree_.get();
413 virtual void CreatePendingTree();
414 virtual void ActivateSyncTree();
416 // Shortcuts to layers on the active tree.
417 LayerImpl* RootLayer() const;
418 LayerImpl* InnerViewportScrollLayer() const;
419 LayerImpl* OuterViewportScrollLayer() const;
420 LayerImpl* CurrentlyScrollingLayer() const;
422 int scroll_layer_id_when_mouse_over_scrollbar() const {
423 return scroll_layer_id_when_mouse_over_scrollbar_;
425 bool scroll_affects_scroll_handler() const {
426 return scroll_affects_scroll_handler_;
428 void QueueSwapPromiseForMainThreadScrollUpdate(
429 scoped_ptr<SwapPromise> swap_promise);
431 bool IsActivelyScrolling() const;
433 virtual void SetVisible(bool visible);
434 bool visible() const { return visible_; }
436 bool AnimationsAreVisible() { return visible() && CanDraw(); }
438 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
439 void SetNeedsAnimate();
440 void SetNeedsRedraw();
442 ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
444 size_t memory_allocation_limit_bytes() const;
446 void SetViewportSize(const gfx::Size& device_viewport_size);
447 gfx::Size device_viewport_size() const { return device_viewport_size_; }
449 void SetDeviceScaleFactor(float device_scale_factor);
450 float device_scale_factor() const { return device_scale_factor_; }
452 void SetPageScaleOnActiveTree(float page_scale_factor);
454 const gfx::Transform& DrawTransform() const;
456 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
458 void set_max_memory_needed_bytes(size_t bytes) {
459 max_memory_needed_bytes_ = bytes;
462 FrameRateCounter* fps_counter() {
463 return fps_counter_.get();
465 PaintTimeCounter* paint_time_counter() {
466 return paint_time_counter_.get();
468 MemoryHistory* memory_history() {
469 return memory_history_.get();
471 DebugRectHistory* debug_rect_history() {
472 return debug_rect_history_.get();
474 ResourceProvider* resource_provider() {
475 return resource_provider_.get();
477 TopControlsManager* top_controls_manager() {
478 return top_controls_manager_.get();
480 const GlobalStateThatImpactsTilePriority& global_tile_state() {
481 return global_tile_state_;
484 Proxy* proxy() const { return proxy_; }
486 AnimationRegistrar* animation_registrar() const {
487 return animation_registrar_.get();
489 AnimationHost* animation_host() const { return animation_host_.get(); }
491 void SetDebugState(const LayerTreeDebugState& new_debug_state);
492 const LayerTreeDebugState& debug_state() const { return debug_state_; }
494 gfx::Vector2dF accumulated_root_overscroll() const {
495 return accumulated_root_overscroll_;
498 bool pinch_gesture_active() const { return pinch_gesture_active_; }
500 void SetTreePriority(TreePriority priority);
501 TreePriority GetTreePriority() const;
503 // TODO(mithro): Remove this methods which exposes the internal
504 // BeginFrameArgs to external callers.
505 virtual BeginFrameArgs CurrentBeginFrameArgs() const;
507 // Expected time between two begin impl frame calls.
508 base::TimeDelta CurrentBeginFrameInterval() const;
510 void AsValueWithFrameInto(FrameData* frame,
511 base::trace_event::TracedValue* value) const;
512 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueWithFrame(
513 FrameData* frame) const;
514 void ActivationStateAsValueInto(base::trace_event::TracedValue* value) const;
516 bool page_scale_animation_active() const { return !!page_scale_animation_; }
518 virtual void CreateUIResource(UIResourceId uid,
519 const UIResourceBitmap& bitmap);
520 // Deletes a UI resource. May safely be called more than once.
521 virtual void DeleteUIResource(UIResourceId uid);
522 void EvictAllUIResources();
523 bool EvictedUIResourcesExist() const;
525 virtual ResourceId ResourceIdForUIResource(UIResourceId uid) const;
527 virtual bool IsUIResourceOpaque(UIResourceId uid) const;
529 struct UIResourceData {
530 ResourceId resource_id;
531 gfx::Size size;
532 bool opaque;
535 void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark);
537 CompositorFrameMetadata MakeCompositorFrameMetadata() const;
538 // Viewport rectangle and clip in nonflipped window space. These rects
539 // should only be used by Renderer subclasses to populate glViewport/glClip
540 // and their software-mode equivalents.
541 gfx::Rect DeviceViewport() const;
542 gfx::Rect DeviceClip() const;
544 // When a SwapPromiseMonitor is created on the impl thread, it calls
545 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
546 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
547 // to unregister itself.
548 void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
549 void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
551 // TODO(weiliangc): Replace RequiresHighResToDraw with scheduler waits for
552 // ReadyToDraw. crbug.com/469175
553 void SetRequiresHighResToDraw() { requires_high_res_to_draw_ = true; }
554 void ResetRequiresHighResToDraw() { requires_high_res_to_draw_ = false; }
555 bool RequiresHighResToDraw() const { return requires_high_res_to_draw_; }
557 // Only valid for synchronous (non-scheduled) single-threaded case.
558 void SynchronouslyInitializeAllTiles();
560 virtual void CreateResourceAndTileTaskWorkerPool(
561 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
562 scoped_ptr<ResourcePool>* resource_pool,
563 scoped_ptr<ResourcePool>* staging_resource_pool);
565 bool prepare_tiles_needed() const { return tile_priorities_dirty_; }
567 FrameTimingTracker* frame_timing_tracker() {
568 return frame_timing_tracker_.get();
571 gfx::Vector2dF ScrollLayer(LayerImpl* layer_impl,
572 const gfx::Vector2dF& delta,
573 const gfx::Point& viewport_point,
574 bool is_direct_manipulation);
576 // Record main frame timing information.
577 // |start_of_main_frame_args| is the BeginFrameArgs of the beginning of the
578 // main frame (ie the frame that kicked off the main frame).
579 // |expected_next_main_frame_args| is the BeginFrameArgs of the frame that
580 // follows the completion of the main frame (whether it is activation or some
581 // other completion, such as early out). Note that if there is a main frame
582 // scheduled in that frame, then this BeginFrameArgs will become the main
583 // frame args. However, if no such frame is scheduled, then this _would_ be
584 // the main frame args if it was scheduled.
585 void RecordMainFrameTiming(
586 const BeginFrameArgs& start_of_main_frame_args,
587 const BeginFrameArgs& expected_next_main_frame_args);
589 // Post the given frame timing events to the requester.
590 void PostFrameTimingEvents(
591 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
592 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events);
594 protected:
595 LayerTreeHostImpl(
596 const LayerTreeSettings& settings,
597 LayerTreeHostImplClient* client,
598 Proxy* proxy,
599 RenderingStatsInstrumentation* rendering_stats_instrumentation,
600 SharedBitmapManager* shared_bitmap_manager,
601 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
602 TaskGraphRunner* task_graph_runner,
603 int id);
605 // Virtual for testing.
606 virtual void AnimateLayers(base::TimeTicks monotonic_time);
608 bool is_likely_to_require_a_draw() const {
609 return is_likely_to_require_a_draw_;
612 // Removes empty or orphan RenderPasses from the frame.
613 static void RemoveRenderPasses(FrameData* frame);
615 LayerTreeHostImplClient* client_;
616 Proxy* proxy_;
618 BeginFrameTracker current_begin_frame_tracker_;
620 private:
621 gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
622 LayerImpl* layer_impl,
623 const gfx::PointF& viewport_point,
624 const gfx::Vector2dF& viewport_delta);
626 void CreateAndSetRenderer();
627 void CleanUpTileManager();
628 void CreateTileManagerResources();
629 void ReleaseTreeResources();
630 void RecreateTreeResources();
632 void UpdateGpuRasterizationStatus();
634 Viewport* viewport() { return viewport_.get(); }
636 // Scroll by preferring to move the outer viewport first, only moving the
637 // inner if the outer is at its scroll extents.
638 void ScrollViewportBy(gfx::Vector2dF scroll_delta);
639 // Scroll by preferring to move the inner viewport first, only moving the
640 // outer if the inner is at its scroll extents.
641 void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta);
643 InputHandler::ScrollStatus ScrollBeginImpl(
644 LayerImpl* scrolling_layer_impl,
645 InputHandler::ScrollInputType type);
647 void AnimateInput(base::TimeTicks monotonic_time);
648 void AnimatePageScale(base::TimeTicks monotonic_time);
649 void AnimateScrollbars(base::TimeTicks monotonic_time);
650 void AnimateTopControls(base::TimeTicks monotonic_time);
652 void TrackDamageForAllSurfaces(
653 LayerImpl* root_draw_layer,
654 const LayerImplList& render_surface_layer_list);
656 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
658 // This function should only be called from PrepareToDraw, as DidDrawAllLayers
659 // must be called if this helper function is called. Returns DRAW_SUCCESS if
660 // the frame should be drawn.
661 DrawResult CalculateRenderPasses(FrameData* frame);
663 void ClearCurrentlyScrollingLayer();
665 bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
666 const gfx::PointF& device_viewport_point);
668 LayerImpl* FindScrollLayerForDeviceViewportPoint(
669 const gfx::PointF& device_viewport_point,
670 InputHandler::ScrollInputType type,
671 LayerImpl* layer_hit_by_point,
672 bool* scroll_on_main_thread,
673 bool* optional_has_ancestor_scroll_handler) const;
674 float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point,
675 LayerImpl* layer_impl);
676 void StartScrollbarFadeRecursive(LayerImpl* layer);
677 void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
679 void MarkUIResourceNotEvicted(UIResourceId uid);
681 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
682 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
684 void ScrollAnimationCreate(LayerImpl* layer_impl,
685 const gfx::ScrollOffset& target_offset,
686 const gfx::ScrollOffset& current_offset);
687 bool ScrollAnimationUpdateTarget(LayerImpl* layer_impl,
688 const gfx::Vector2dF& scroll_delta);
690 base::SingleThreadTaskRunner* GetTaskRunner() const {
691 DCHECK(proxy_);
692 return proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
693 : proxy_->MainThreadTaskRunner();
696 typedef base::hash_map<UIResourceId, UIResourceData>
697 UIResourceMap;
698 UIResourceMap ui_resource_map_;
700 // Resources that were evicted by EvictAllUIResources. Resources are removed
701 // from this when they are touched by a create or destroy from the UI resource
702 // request queue.
703 std::set<UIResourceId> evicted_ui_resources_;
705 scoped_ptr<OutputSurface> output_surface_;
707 scoped_ptr<ResourceProvider> resource_provider_;
708 bool content_is_suitable_for_gpu_rasterization_;
709 bool has_gpu_rasterization_trigger_;
710 bool use_gpu_rasterization_;
711 bool use_msaa_;
712 GpuRasterizationStatus gpu_rasterization_status_;
713 bool tree_resources_for_gpu_rasterization_dirty_;
714 scoped_ptr<TileTaskWorkerPool> tile_task_worker_pool_;
715 scoped_ptr<ResourcePool> resource_pool_;
716 scoped_ptr<ResourcePool> staging_resource_pool_;
717 scoped_ptr<Renderer> renderer_;
719 GlobalStateThatImpactsTilePriority global_tile_state_;
721 // Tree currently being drawn.
722 scoped_ptr<LayerTreeImpl> active_tree_;
724 // In impl-side painting mode, tree with possibly incomplete rasterized
725 // content. May be promoted to active by ActivatePendingTree().
726 scoped_ptr<LayerTreeImpl> pending_tree_;
728 // In impl-side painting mode, inert tree with layers that can be recycled
729 // by the next sync from the main thread.
730 scoped_ptr<LayerTreeImpl> recycle_tree_;
732 InputHandlerClient* input_handler_client_;
733 bool did_lock_scrolling_layer_;
734 bool should_bubble_scrolls_;
735 bool wheel_scrolling_;
736 bool scroll_affects_scroll_handler_;
737 int scroll_layer_id_when_mouse_over_scrollbar_;
738 ScopedPtrVector<SwapPromise> swap_promises_for_main_thread_scroll_update_;
740 // An object to implement the ScrollElasticityHelper interface and
741 // hold all state related to elasticity. May be NULL if never requested.
742 scoped_ptr<ScrollElasticityHelper> scroll_elasticity_helper_;
744 bool tile_priorities_dirty_;
746 // The optional delegate for the root layer scroll offset.
747 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
748 LayerScrollOffsetDelegate::AnimationCallback root_layer_animation_callback_;
750 const LayerTreeSettings settings_;
751 LayerTreeDebugState debug_state_;
752 bool visible_;
753 ManagedMemoryPolicy cached_managed_memory_policy_;
755 const bool is_synchronous_single_threaded_;
756 scoped_ptr<TileManager> tile_manager_;
758 gfx::Vector2dF accumulated_root_overscroll_;
760 bool pinch_gesture_active_;
761 bool pinch_gesture_end_should_clear_scrolling_layer_;
763 scoped_ptr<TopControlsManager> top_controls_manager_;
765 scoped_ptr<PageScaleAnimation> page_scale_animation_;
767 scoped_ptr<FrameRateCounter> fps_counter_;
768 scoped_ptr<PaintTimeCounter> paint_time_counter_;
769 scoped_ptr<MemoryHistory> memory_history_;
770 scoped_ptr<DebugRectHistory> debug_rect_history_;
772 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
774 // The maximum memory that would be used by the prioritized resource
775 // manager, if there were no limit on memory usage.
776 size_t max_memory_needed_bytes_;
778 // Viewport size passed in from the main thread, in physical pixels. This
779 // value is the default size for all concepts of physical viewport (draw
780 // viewport, scrolling viewport and device viewport), but it can be
781 // overridden.
782 gfx::Size device_viewport_size_;
784 // Conversion factor from CSS pixels to physical pixels when
785 // pageScaleFactor=1.
786 float device_scale_factor_;
788 // Optional top-level constraints that can be set by the OutputSurface.
789 // - external_transform_ applies a transform above the root layer
790 // - external_viewport_ is used DrawProperties, tile management and
791 // glViewport/window projection matrix.
792 // - external_clip_ specifies a top-level clip rect
793 // - viewport_rect_for_tile_priority_ is the rect in view space used for
794 // tiling priority.
795 gfx::Transform external_transform_;
796 gfx::Rect external_viewport_;
797 gfx::Rect external_clip_;
798 gfx::Rect viewport_rect_for_tile_priority_;
799 bool resourceless_software_draw_;
801 gfx::Rect viewport_damage_rect_;
803 scoped_ptr<AnimationRegistrar> animation_registrar_;
804 scoped_ptr<AnimationHost> animation_host_;
805 std::set<ScrollbarAnimationController*> scrollbar_animation_controllers_;
806 std::set<VideoFrameController*> video_frame_controllers_;
808 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
809 MicroBenchmarkControllerImpl micro_benchmark_controller_;
810 scoped_ptr<TaskGraphRunner> single_thread_synchronous_task_graph_runner_;
812 // Optional callback to notify of new tree activations.
813 base::Closure tree_activation_callback_;
815 SharedBitmapManager* shared_bitmap_manager_;
816 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
817 TaskGraphRunner* task_graph_runner_;
818 int id_;
820 std::set<SwapPromiseMonitor*> swap_promise_monitor_;
822 bool requires_high_res_to_draw_;
823 bool is_likely_to_require_a_draw_;
825 scoped_ptr<FrameTimingTracker> frame_timing_tracker_;
827 scoped_ptr<Viewport> viewport_;
829 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
832 } // namespace cc
834 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_