Update V8 to version 4.7.44.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_impl.h
blob6a77dfcb05f10ae90a3dbbb5b6e88bbffdef1a33
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(
180 const gfx::ScrollOffset& root_offset) override;
181 void ScrollEnd() override;
182 InputHandler::ScrollStatus FlingScrollBegin() override;
183 void MouseMoveAt(const gfx::Point& viewport_point) override;
184 void PinchGestureBegin() override;
185 void PinchGestureUpdate(float magnify_delta,
186 const gfx::Point& anchor) override;
187 void PinchGestureEnd() override;
188 void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
189 bool anchor_point,
190 float page_scale,
191 base::TimeDelta duration);
192 void SetNeedsAnimateInput() override;
193 bool IsCurrentlyScrollingRoot() const override;
194 bool IsCurrentlyScrollingLayerAt(
195 const gfx::Point& viewport_point,
196 InputHandler::ScrollInputType type) const override;
197 bool HaveWheelEventHandlersAt(const gfx::Point& viewport_point) override;
198 bool DoTouchEventsBlockScrollAt(const gfx::Point& viewport_port) override;
199 scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
200 ui::LatencyInfo* latency) override;
201 ScrollElasticityHelper* CreateScrollElasticityHelper() override;
203 // TopControlsManagerClient implementation.
204 float TopControlsHeight() const override;
205 void SetCurrentTopControlsShownRatio(float offset) override;
206 float CurrentTopControlsShownRatio() const override;
207 void DidChangeTopControlsPosition() override;
208 bool HaveRootScrollLayer() const override;
210 void UpdateViewportContainerSizes();
212 struct CC_EXPORT FrameData : public RenderPassSink {
213 FrameData();
214 ~FrameData() override;
215 void AsValueInto(base::trace_event::TracedValue* value) const;
217 std::vector<gfx::Rect> occluding_screen_space_rects;
218 std::vector<gfx::Rect> non_occluding_screen_space_rects;
219 std::vector<FrameTimingTracker::FrameAndRectIds> composite_events;
220 RenderPassList render_passes;
221 RenderPassIdHashMap render_passes_by_id;
222 const LayerImplList* render_surface_layer_list;
223 LayerImplList will_draw_layers;
224 bool has_no_damage;
226 // RenderPassSink implementation.
227 void AppendRenderPass(scoped_ptr<RenderPass> render_pass) override;
230 virtual void BeginMainFrameAborted(CommitEarlyOutReason reason);
231 virtual void BeginCommit();
232 virtual void CommitComplete();
233 virtual void Animate();
234 virtual void UpdateAnimationState(bool start_ready_animations);
235 void ActivateAnimations();
236 void MainThreadHasStoppedFlinging();
237 void DidAnimateScrollOffset();
238 void SetViewportDamage(const gfx::Rect& damage_rect);
240 void SetTreeLayerFilterMutated(int layer_id,
241 LayerTreeImpl* tree,
242 const FilterOperations& filters);
243 void SetTreeLayerOpacityMutated(int layer_id,
244 LayerTreeImpl* tree,
245 float opacity);
246 void SetTreeLayerTransformMutated(int layer_id,
247 LayerTreeImpl* tree,
248 const gfx::Transform& transform);
249 void SetTreeLayerScrollOffsetMutated(int layer_id,
250 LayerTreeImpl* tree,
251 const gfx::ScrollOffset& scroll_offset);
252 void TreeLayerTransformIsPotentiallyAnimatingChanged(int layer_id,
253 LayerTreeImpl* tree,
254 bool is_animating);
256 // LayerTreeMutatorsClient implementation.
257 bool IsLayerInTree(int layer_id, LayerTreeType tree_type) const override;
258 void SetMutatorsNeedCommit() override;
259 void SetLayerFilterMutated(int layer_id,
260 LayerTreeType tree_type,
261 const FilterOperations& filters) override;
262 void SetLayerOpacityMutated(int layer_id,
263 LayerTreeType tree_type,
264 float opacity) override;
265 void SetLayerTransformMutated(int layer_id,
266 LayerTreeType tree_type,
267 const gfx::Transform& transform) override;
268 void SetLayerScrollOffsetMutated(
269 int layer_id,
270 LayerTreeType tree_type,
271 const gfx::ScrollOffset& scroll_offset) override;
272 void LayerTransformIsPotentiallyAnimatingChanged(int layer_id,
273 LayerTreeType tree_type,
274 bool is_animating) override;
275 void ScrollOffsetAnimationFinished() override;
276 gfx::ScrollOffset GetScrollOffsetForAnimation(int layer_id) const override;
278 virtual bool PrepareTiles();
280 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
281 // should try to avoid displaying the frame. If PrepareToDraw is called,
282 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
283 // called between the two.
284 virtual DrawResult PrepareToDraw(FrameData* frame);
285 virtual void DrawLayers(FrameData* frame);
286 // Must be called if and only if PrepareToDraw was called.
287 void DidDrawAllLayers(const FrameData& frame);
289 const LayerTreeSettings& settings() const { return settings_; }
291 // Evict all textures by enforcing a memory policy with an allocation of 0.
292 void EvictTexturesForTesting();
294 // When blocking, this prevents client_->NotifyReadyToActivate() from being
295 // called. When disabled, it calls client_->NotifyReadyToActivate()
296 // immediately if any notifications had been blocked while blocking.
297 virtual void BlockNotifyReadyToActivateForTesting(bool block);
299 // Resets all of the trees to an empty state.
300 void ResetTreesForTesting();
302 size_t SourceAnimationFrameNumberForTesting() const;
304 DrawMode GetDrawMode() const;
306 // Viewport size in draw space: this size is in physical pixels and is used
307 // for draw properties, tilings, quads and render passes.
308 gfx::Size DrawViewportSize() const;
310 // Viewport rect in view space used for tiling prioritization.
311 const gfx::Rect ViewportRectForTilePriority() const;
313 // RendererClient implementation.
314 void SetFullRootLayerDamage() override;
316 // TileManagerClient implementation.
317 void NotifyReadyToActivate() override;
318 void NotifyReadyToDraw() override;
319 void NotifyAllTileTasksCompleted() override;
320 void NotifyTileStateChanged(const Tile* tile) override;
321 scoped_ptr<RasterTilePriorityQueue> BuildRasterQueue(
322 TreePriority tree_priority,
323 RasterTilePriorityQueue::Type type) override;
324 scoped_ptr<EvictionTilePriorityQueue> BuildEvictionQueue(
325 TreePriority tree_priority) override;
326 void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) override;
328 // ScrollbarAnimationControllerClient implementation.
329 void StartAnimatingScrollbarAnimationController(
330 ScrollbarAnimationController* controller) override;
331 void StopAnimatingScrollbarAnimationController(
332 ScrollbarAnimationController* controller) override;
333 void PostDelayedScrollbarAnimationTask(const base::Closure& task,
334 base::TimeDelta delay) override;
335 void SetNeedsRedrawForScrollbarAnimation() override;
337 // VideoBeginFrameSource implementation.
338 void AddVideoFrameController(VideoFrameController* controller) override;
339 void RemoveVideoFrameController(VideoFrameController* controller) override;
341 // OutputSurfaceClient implementation.
342 void CommitVSyncParameters(base::TimeTicks timebase,
343 base::TimeDelta interval) override;
344 void SetNeedsRedrawRect(const gfx::Rect& rect) override;
345 void SetExternalDrawConstraints(
346 const gfx::Transform& transform,
347 const gfx::Rect& viewport,
348 const gfx::Rect& clip,
349 const gfx::Rect& viewport_rect_for_tile_priority,
350 const gfx::Transform& transform_for_tile_priority,
351 bool resourceless_software_draw) override;
352 void DidLoseOutputSurface() override;
353 void DidSwapBuffers() override;
354 void DidSwapBuffersComplete() override;
355 void ReclaimResources(const CompositorFrameAck* ack) override;
356 void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override;
357 void SetTreeActivationCallback(const base::Closure& callback) override;
358 void OnDraw() override;
360 // Called from LayerTreeImpl.
361 void OnCanDrawStateChangedForTree();
363 // Implementation.
364 int id() const { return id_; }
365 bool CanDraw() const;
366 OutputSurface* output_surface() const { return output_surface_.get(); }
368 std::string LayerTreeAsJson() const;
370 void FinishAllRendering();
371 int RequestedMSAASampleCount() const;
373 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
374 TileManager* tile_manager() { return tile_manager_.get(); }
376 void SetHasGpuRasterizationTrigger(bool flag) {
377 has_gpu_rasterization_trigger_ = flag;
378 UpdateGpuRasterizationStatus();
380 void SetContentIsSuitableForGpuRasterization(bool flag) {
381 content_is_suitable_for_gpu_rasterization_ = flag;
382 UpdateGpuRasterizationStatus();
384 bool CanUseGpuRasterization();
385 void UpdateTreeResourcesForGpuRasterizationIfNeeded();
386 bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
387 bool use_msaa() const { return use_msaa_; }
389 GpuRasterizationStatus gpu_rasterization_status() const {
390 return gpu_rasterization_status_;
393 bool create_low_res_tiling() const {
394 return settings_.create_low_res_tiling && !use_gpu_rasterization_;
396 ResourcePool* resource_pool() { return resource_pool_.get(); }
397 Renderer* renderer() { return renderer_.get(); }
398 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
400 virtual bool SwapBuffers(const FrameData& frame);
401 virtual void WillBeginImplFrame(const BeginFrameArgs& args);
402 virtual void DidFinishImplFrame();
403 void DidModifyTilePriorities();
405 LayerTreeImpl* active_tree() { return active_tree_.get(); }
406 const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
407 LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
408 const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
409 LayerTreeImpl* recycle_tree() { return recycle_tree_.get(); }
410 const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
411 // Returns the tree LTH synchronizes with.
412 LayerTreeImpl* sync_tree() {
413 // TODO(enne): This is bogus. It should return based on the value of
414 // Proxy::CommitToActiveTree and not whether the pending tree exists.
415 return pending_tree_ ? pending_tree_.get() : active_tree_.get();
417 virtual void CreatePendingTree();
418 virtual void ActivateSyncTree();
420 // Shortcuts to layers on the active tree.
421 LayerImpl* RootLayer() const;
422 LayerImpl* InnerViewportScrollLayer() const;
423 LayerImpl* OuterViewportScrollLayer() const;
424 LayerImpl* CurrentlyScrollingLayer() const;
426 int scroll_layer_id_when_mouse_over_scrollbar() const {
427 return scroll_layer_id_when_mouse_over_scrollbar_;
429 bool scroll_affects_scroll_handler() const {
430 return scroll_affects_scroll_handler_;
432 void QueueSwapPromiseForMainThreadScrollUpdate(
433 scoped_ptr<SwapPromise> swap_promise);
435 bool IsActivelyScrolling() const;
437 virtual void SetVisible(bool visible);
438 bool visible() const { return visible_; }
440 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
441 void SetNeedsAnimate();
442 void SetNeedsRedraw();
444 ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
446 size_t memory_allocation_limit_bytes() const;
448 void SetViewportSize(const gfx::Size& device_viewport_size);
449 gfx::Size device_viewport_size() const { return device_viewport_size_; }
451 void SetDeviceScaleFactor(float device_scale_factor);
452 float device_scale_factor() const { return device_scale_factor_; }
454 void SetPageScaleOnActiveTree(float page_scale_factor);
456 const gfx::Transform& DrawTransform() const;
458 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
460 void set_max_memory_needed_bytes(size_t bytes) {
461 max_memory_needed_bytes_ = bytes;
464 FrameRateCounter* fps_counter() {
465 return fps_counter_.get();
467 PaintTimeCounter* paint_time_counter() {
468 return paint_time_counter_.get();
470 MemoryHistory* memory_history() {
471 return memory_history_.get();
473 DebugRectHistory* debug_rect_history() {
474 return debug_rect_history_.get();
476 ResourceProvider* resource_provider() {
477 return resource_provider_.get();
479 TopControlsManager* top_controls_manager() {
480 return top_controls_manager_.get();
482 const GlobalStateThatImpactsTilePriority& global_tile_state() {
483 return global_tile_state_;
486 Proxy* proxy() const { return proxy_; }
488 AnimationRegistrar* animation_registrar() const {
489 return animation_registrar_.get();
491 AnimationHost* animation_host() const { return animation_host_.get(); }
493 void SetDebugState(const LayerTreeDebugState& new_debug_state);
494 const LayerTreeDebugState& debug_state() const { return debug_state_; }
496 gfx::Vector2dF accumulated_root_overscroll() const {
497 return accumulated_root_overscroll_;
500 bool pinch_gesture_active() const { return pinch_gesture_active_; }
502 void SetTreePriority(TreePriority priority);
503 TreePriority GetTreePriority() const;
505 // TODO(mithro): Remove this methods which exposes the internal
506 // BeginFrameArgs to external callers.
507 virtual BeginFrameArgs CurrentBeginFrameArgs() const;
509 // Expected time between two begin impl frame calls.
510 base::TimeDelta CurrentBeginFrameInterval() const;
512 void AsValueWithFrameInto(FrameData* frame,
513 base::trace_event::TracedValue* value) const;
514 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueWithFrame(
515 FrameData* frame) const;
516 void ActivationStateAsValueInto(base::trace_event::TracedValue* value) const;
518 bool page_scale_animation_active() const { return !!page_scale_animation_; }
520 virtual void CreateUIResource(UIResourceId uid,
521 const UIResourceBitmap& bitmap);
522 // Deletes a UI resource. May safely be called more than once.
523 virtual void DeleteUIResource(UIResourceId uid);
524 void EvictAllUIResources();
525 bool EvictedUIResourcesExist() const;
527 virtual ResourceId ResourceIdForUIResource(UIResourceId uid) const;
529 virtual bool IsUIResourceOpaque(UIResourceId uid) const;
531 struct UIResourceData {
532 ResourceId resource_id;
533 gfx::Size size;
534 bool opaque;
537 void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark);
539 CompositorFrameMetadata MakeCompositorFrameMetadata() const;
540 // Viewport rectangle and clip in nonflipped window space. These rects
541 // should only be used by Renderer subclasses to populate glViewport/glClip
542 // and their software-mode equivalents.
543 gfx::Rect DeviceViewport() const;
544 gfx::Rect DeviceClip() const;
546 // When a SwapPromiseMonitor is created on the impl thread, it calls
547 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
548 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
549 // to unregister itself.
550 void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
551 void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
553 // TODO(weiliangc): Replace RequiresHighResToDraw with scheduler waits for
554 // ReadyToDraw. crbug.com/469175
555 void SetRequiresHighResToDraw() { requires_high_res_to_draw_ = true; }
556 void ResetRequiresHighResToDraw() { requires_high_res_to_draw_ = false; }
557 bool RequiresHighResToDraw() const { return requires_high_res_to_draw_; }
559 // Only valid for synchronous (non-scheduled) single-threaded case.
560 void SynchronouslyInitializeAllTiles();
562 virtual void CreateResourceAndTileTaskWorkerPool(
563 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
564 scoped_ptr<ResourcePool>* resource_pool);
566 bool prepare_tiles_needed() const { return tile_priorities_dirty_; }
568 FrameTimingTracker* frame_timing_tracker() {
569 return frame_timing_tracker_.get();
572 gfx::Vector2dF ScrollLayer(LayerImpl* layer_impl,
573 const gfx::Vector2dF& delta,
574 const gfx::Point& viewport_point,
575 bool is_direct_manipulation);
577 // Record main frame timing information.
578 // |start_of_main_frame_args| is the BeginFrameArgs of the beginning of the
579 // main frame (ie the frame that kicked off the main frame).
580 // |expected_next_main_frame_args| is the BeginFrameArgs of the frame that
581 // follows the completion of the main frame (whether it is activation or some
582 // other completion, such as early out). Note that if there is a main frame
583 // scheduled in that frame, then this BeginFrameArgs will become the main
584 // frame args. However, if no such frame is scheduled, then this _would_ be
585 // the main frame args if it was scheduled.
586 void RecordMainFrameTiming(
587 const BeginFrameArgs& start_of_main_frame_args,
588 const BeginFrameArgs& expected_next_main_frame_args);
590 // Post the given frame timing events to the requester.
591 void PostFrameTimingEvents(
592 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
593 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events);
595 protected:
596 LayerTreeHostImpl(
597 const LayerTreeSettings& settings,
598 LayerTreeHostImplClient* client,
599 Proxy* proxy,
600 RenderingStatsInstrumentation* rendering_stats_instrumentation,
601 SharedBitmapManager* shared_bitmap_manager,
602 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
603 TaskGraphRunner* task_graph_runner,
604 int id);
606 // Virtual for testing.
607 virtual void AnimateLayers(base::TimeTicks monotonic_time);
609 bool is_likely_to_require_a_draw() const {
610 return is_likely_to_require_a_draw_;
613 // Removes empty or orphan RenderPasses from the frame.
614 static void RemoveRenderPasses(FrameData* frame);
616 LayerTreeHostImplClient* client_;
617 Proxy* proxy_;
619 BeginFrameTracker current_begin_frame_tracker_;
621 private:
622 gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
623 LayerImpl* layer_impl,
624 const gfx::PointF& viewport_point,
625 const gfx::Vector2dF& viewport_delta);
627 void CreateAndSetRenderer();
628 void CleanUpTileManager();
629 void CreateTileManagerResources();
630 void ReleaseTreeResources();
631 void RecreateTreeResources();
633 void UpdateGpuRasterizationStatus();
635 Viewport* viewport() { return viewport_.get(); }
637 // Scroll by preferring to move the outer viewport first, only moving the
638 // inner if the outer is at its scroll extents.
639 void ScrollViewportBy(gfx::Vector2dF scroll_delta);
640 // Scroll by preferring to move the inner viewport first, only moving the
641 // outer if the inner is at its scroll extents.
642 void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta);
644 InputHandler::ScrollStatus ScrollBeginImpl(
645 LayerImpl* scrolling_layer_impl,
646 InputHandler::ScrollInputType type);
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<Renderer> renderer_;
718 GlobalStateThatImpactsTilePriority global_tile_state_;
720 // Tree currently being drawn.
721 scoped_ptr<LayerTreeImpl> active_tree_;
723 // In impl-side painting mode, tree with possibly incomplete rasterized
724 // content. May be promoted to active by ActivatePendingTree().
725 scoped_ptr<LayerTreeImpl> pending_tree_;
727 // In impl-side painting mode, inert tree with layers that can be recycled
728 // by the next sync from the main thread.
729 scoped_ptr<LayerTreeImpl> recycle_tree_;
731 InputHandlerClient* input_handler_client_;
732 bool did_lock_scrolling_layer_;
733 bool should_bubble_scrolls_;
734 bool wheel_scrolling_;
735 bool scroll_affects_scroll_handler_;
736 int scroll_layer_id_when_mouse_over_scrollbar_;
737 ScopedPtrVector<SwapPromise> swap_promises_for_main_thread_scroll_update_;
739 // An object to implement the ScrollElasticityHelper interface and
740 // hold all state related to elasticity. May be NULL if never requested.
741 scoped_ptr<ScrollElasticityHelper> scroll_elasticity_helper_;
743 bool tile_priorities_dirty_;
745 // The optional delegate for the root layer scroll offset.
746 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
748 const LayerTreeSettings settings_;
749 LayerTreeDebugState debug_state_;
750 bool visible_;
751 ManagedMemoryPolicy cached_managed_memory_policy_;
753 const bool is_synchronous_single_threaded_;
754 scoped_ptr<TileManager> tile_manager_;
756 gfx::Vector2dF accumulated_root_overscroll_;
758 bool pinch_gesture_active_;
759 bool pinch_gesture_end_should_clear_scrolling_layer_;
761 scoped_ptr<TopControlsManager> top_controls_manager_;
763 scoped_ptr<PageScaleAnimation> page_scale_animation_;
765 scoped_ptr<FrameRateCounter> fps_counter_;
766 scoped_ptr<PaintTimeCounter> paint_time_counter_;
767 scoped_ptr<MemoryHistory> memory_history_;
768 scoped_ptr<DebugRectHistory> debug_rect_history_;
770 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
772 // The maximum memory that would be used by the prioritized resource
773 // manager, if there were no limit on memory usage.
774 size_t max_memory_needed_bytes_;
776 // Viewport size passed in from the main thread, in physical pixels. This
777 // value is the default size for all concepts of physical viewport (draw
778 // viewport, scrolling viewport and device viewport), but it can be
779 // overridden.
780 gfx::Size device_viewport_size_;
782 // Conversion factor from CSS pixels to physical pixels when
783 // pageScaleFactor=1.
784 float device_scale_factor_;
786 // Optional top-level constraints that can be set by the OutputSurface.
787 // - external_transform_ applies a transform above the root layer
788 // - external_viewport_ is used DrawProperties, tile management and
789 // glViewport/window projection matrix.
790 // - external_clip_ specifies a top-level clip rect
791 // - viewport_rect_for_tile_priority_ is the rect in view space used for
792 // tiling priority.
793 gfx::Transform external_transform_;
794 gfx::Rect external_viewport_;
795 gfx::Rect external_clip_;
796 gfx::Rect viewport_rect_for_tile_priority_;
797 bool resourceless_software_draw_;
799 gfx::Rect viewport_damage_rect_;
801 scoped_ptr<AnimationRegistrar> animation_registrar_;
802 scoped_ptr<AnimationHost> animation_host_;
803 std::set<ScrollbarAnimationController*> scrollbar_animation_controllers_;
804 std::set<VideoFrameController*> video_frame_controllers_;
806 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
807 MicroBenchmarkControllerImpl micro_benchmark_controller_;
808 scoped_ptr<TaskGraphRunner> single_thread_synchronous_task_graph_runner_;
810 // Optional callback to notify of new tree activations.
811 base::Closure tree_activation_callback_;
813 SharedBitmapManager* shared_bitmap_manager_;
814 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
815 TaskGraphRunner* task_graph_runner_;
816 int id_;
818 std::set<SwapPromiseMonitor*> swap_promise_monitor_;
820 bool requires_high_res_to_draw_;
821 bool is_likely_to_require_a_draw_;
823 scoped_ptr<FrameTimingTracker> frame_timing_tracker_;
825 scoped_ptr<Viewport> viewport_;
827 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
830 } // namespace cc
832 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_