Use md5_check in proguard.py to detect when it's not really necessary
[chromium-blink-merge.git] / cc / trees / layer_tree_host_impl.h
blobe66a1ff92976debed7bf24ecba3b543b4e064751
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();
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();
368 int RequestedMSAASampleCount() const;
370 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
371 TileManager* tile_manager() { return tile_manager_.get(); }
373 void SetHasGpuRasterizationTrigger(bool flag) {
374 has_gpu_rasterization_trigger_ = flag;
375 UpdateGpuRasterizationStatus();
377 void SetContentIsSuitableForGpuRasterization(bool flag) {
378 content_is_suitable_for_gpu_rasterization_ = flag;
379 UpdateGpuRasterizationStatus();
381 bool CanUseGpuRasterization();
382 void UpdateTreeResourcesForGpuRasterizationIfNeeded();
383 bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
384 bool use_msaa() const { return use_msaa_; }
386 GpuRasterizationStatus gpu_rasterization_status() const {
387 return gpu_rasterization_status_;
390 bool create_low_res_tiling() const {
391 return settings_.create_low_res_tiling && !use_gpu_rasterization_;
393 ResourcePool* resource_pool() { return resource_pool_.get(); }
394 Renderer* renderer() { return renderer_.get(); }
395 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
397 virtual bool SwapBuffers(const FrameData& frame);
398 virtual void WillBeginImplFrame(const BeginFrameArgs& args);
399 virtual void DidFinishImplFrame();
400 void DidModifyTilePriorities();
402 LayerTreeImpl* active_tree() { return active_tree_.get(); }
403 const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
404 LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
405 const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
406 LayerTreeImpl* recycle_tree() { return recycle_tree_.get(); }
407 const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
408 // Returns the tree LTH synchronizes with.
409 LayerTreeImpl* sync_tree() {
410 // TODO(enne): This is bogus. It should return based on the value of
411 // Proxy::CommitToActiveTree and not whether the pending tree exists.
412 return pending_tree_ ? pending_tree_.get() : active_tree_.get();
414 virtual void CreatePendingTree();
415 virtual void ActivateSyncTree();
417 // Shortcuts to layers on the active tree.
418 LayerImpl* RootLayer() const;
419 LayerImpl* InnerViewportScrollLayer() const;
420 LayerImpl* OuterViewportScrollLayer() const;
421 LayerImpl* CurrentlyScrollingLayer() const;
423 int scroll_layer_id_when_mouse_over_scrollbar() const {
424 return scroll_layer_id_when_mouse_over_scrollbar_;
426 bool scroll_affects_scroll_handler() const {
427 return scroll_affects_scroll_handler_;
429 void QueueSwapPromiseForMainThreadScrollUpdate(
430 scoped_ptr<SwapPromise> swap_promise);
432 bool IsActivelyScrolling() const;
434 virtual void SetVisible(bool visible);
435 bool visible() const { return visible_; }
437 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
438 void SetNeedsAnimate();
439 void SetNeedsRedraw();
441 ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
443 size_t memory_allocation_limit_bytes() const;
445 void SetViewportSize(const gfx::Size& device_viewport_size);
446 gfx::Size device_viewport_size() const { return device_viewport_size_; }
448 void SetDeviceScaleFactor(float device_scale_factor);
449 float device_scale_factor() const { return device_scale_factor_; }
451 void SetPageScaleOnActiveTree(float page_scale_factor);
453 const gfx::Transform& DrawTransform() const;
455 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
457 void set_max_memory_needed_bytes(size_t bytes) {
458 max_memory_needed_bytes_ = bytes;
461 FrameRateCounter* fps_counter() {
462 return fps_counter_.get();
464 PaintTimeCounter* paint_time_counter() {
465 return paint_time_counter_.get();
467 MemoryHistory* memory_history() {
468 return memory_history_.get();
470 DebugRectHistory* debug_rect_history() {
471 return debug_rect_history_.get();
473 ResourceProvider* resource_provider() {
474 return resource_provider_.get();
476 TopControlsManager* top_controls_manager() {
477 return top_controls_manager_.get();
479 const GlobalStateThatImpactsTilePriority& global_tile_state() {
480 return global_tile_state_;
483 Proxy* proxy() const { return proxy_; }
485 AnimationRegistrar* animation_registrar() const {
486 return animation_registrar_.get();
488 AnimationHost* animation_host() const { return animation_host_.get(); }
490 void SetDebugState(const LayerTreeDebugState& new_debug_state);
491 const LayerTreeDebugState& debug_state() const { return debug_state_; }
493 gfx::Vector2dF accumulated_root_overscroll() const {
494 return accumulated_root_overscroll_;
497 bool pinch_gesture_active() const { return pinch_gesture_active_; }
499 void SetTreePriority(TreePriority priority);
500 TreePriority GetTreePriority() const;
502 // TODO(mithro): Remove this methods which exposes the internal
503 // BeginFrameArgs to external callers.
504 virtual BeginFrameArgs CurrentBeginFrameArgs() const;
506 // Expected time between two begin impl frame calls.
507 base::TimeDelta CurrentBeginFrameInterval() const;
509 void AsValueWithFrameInto(FrameData* frame,
510 base::trace_event::TracedValue* value) const;
511 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueWithFrame(
512 FrameData* frame) const;
513 void ActivationStateAsValueInto(base::trace_event::TracedValue* value) const;
515 bool page_scale_animation_active() const { return !!page_scale_animation_; }
517 virtual void CreateUIResource(UIResourceId uid,
518 const UIResourceBitmap& bitmap);
519 // Deletes a UI resource. May safely be called more than once.
520 virtual void DeleteUIResource(UIResourceId uid);
521 void EvictAllUIResources();
522 bool EvictedUIResourcesExist() const;
524 virtual ResourceId ResourceIdForUIResource(UIResourceId uid) const;
526 virtual bool IsUIResourceOpaque(UIResourceId uid) const;
528 struct UIResourceData {
529 ResourceId resource_id;
530 gfx::Size size;
531 bool opaque;
534 void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark);
536 CompositorFrameMetadata MakeCompositorFrameMetadata() const;
537 // Viewport rectangle and clip in nonflipped window space. These rects
538 // should only be used by Renderer subclasses to populate glViewport/glClip
539 // and their software-mode equivalents.
540 gfx::Rect DeviceViewport() const;
541 gfx::Rect DeviceClip() const;
543 // When a SwapPromiseMonitor is created on the impl thread, it calls
544 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl.
545 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
546 // to unregister itself.
547 void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
548 void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
550 // TODO(weiliangc): Replace RequiresHighResToDraw with scheduler waits for
551 // ReadyToDraw. crbug.com/469175
552 void SetRequiresHighResToDraw() { requires_high_res_to_draw_ = true; }
553 void ResetRequiresHighResToDraw() { requires_high_res_to_draw_ = false; }
554 bool RequiresHighResToDraw() const { return requires_high_res_to_draw_; }
556 // Only valid for synchronous (non-scheduled) single-threaded case.
557 void SynchronouslyInitializeAllTiles();
559 virtual void CreateResourceAndTileTaskWorkerPool(
560 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
561 scoped_ptr<ResourcePool>* resource_pool);
563 bool prepare_tiles_needed() const { return tile_priorities_dirty_; }
565 FrameTimingTracker* frame_timing_tracker() {
566 return frame_timing_tracker_.get();
569 gfx::Vector2dF ScrollLayer(LayerImpl* layer_impl,
570 const gfx::Vector2dF& delta,
571 const gfx::Point& viewport_point,
572 bool is_direct_manipulation);
574 // Record main frame timing information.
575 // |start_of_main_frame_args| is the BeginFrameArgs of the beginning of the
576 // main frame (ie the frame that kicked off the main frame).
577 // |expected_next_main_frame_args| is the BeginFrameArgs of the frame that
578 // follows the completion of the main frame (whether it is activation or some
579 // other completion, such as early out). Note that if there is a main frame
580 // scheduled in that frame, then this BeginFrameArgs will become the main
581 // frame args. However, if no such frame is scheduled, then this _would_ be
582 // the main frame args if it was scheduled.
583 void RecordMainFrameTiming(
584 const BeginFrameArgs& start_of_main_frame_args,
585 const BeginFrameArgs& expected_next_main_frame_args);
587 // Post the given frame timing events to the requester.
588 void PostFrameTimingEvents(
589 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
590 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events);
592 protected:
593 LayerTreeHostImpl(
594 const LayerTreeSettings& settings,
595 LayerTreeHostImplClient* client,
596 Proxy* proxy,
597 RenderingStatsInstrumentation* rendering_stats_instrumentation,
598 SharedBitmapManager* shared_bitmap_manager,
599 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
600 TaskGraphRunner* task_graph_runner,
601 int id);
603 // Virtual for testing.
604 virtual void AnimateLayers(base::TimeTicks monotonic_time);
606 bool is_likely_to_require_a_draw() const {
607 return is_likely_to_require_a_draw_;
610 // Removes empty or orphan RenderPasses from the frame.
611 static void RemoveRenderPasses(FrameData* frame);
613 LayerTreeHostImplClient* client_;
614 Proxy* proxy_;
616 BeginFrameTracker current_begin_frame_tracker_;
618 private:
619 gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
620 LayerImpl* layer_impl,
621 const gfx::PointF& viewport_point,
622 const gfx::Vector2dF& viewport_delta);
624 void CreateAndSetRenderer();
625 void CleanUpTileManager();
626 void CreateTileManagerResources();
627 void ReleaseTreeResources();
628 void RecreateTreeResources();
630 void UpdateGpuRasterizationStatus();
632 Viewport* viewport() { return viewport_.get(); }
634 // Scroll by preferring to move the outer viewport first, only moving the
635 // inner if the outer is at its scroll extents.
636 void ScrollViewportBy(gfx::Vector2dF scroll_delta);
637 // Scroll by preferring to move the inner viewport first, only moving the
638 // outer if the inner is at its scroll extents.
639 void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta);
641 InputHandler::ScrollStatus ScrollBeginImpl(
642 LayerImpl* scrolling_layer_impl,
643 InputHandler::ScrollInputType type);
645 void AnimateInput(base::TimeTicks monotonic_time);
646 void AnimatePageScale(base::TimeTicks monotonic_time);
647 void AnimateScrollbars(base::TimeTicks monotonic_time);
648 void AnimateTopControls(base::TimeTicks monotonic_time);
650 void TrackDamageForAllSurfaces(
651 LayerImpl* root_draw_layer,
652 const LayerImplList& render_surface_layer_list);
654 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
656 // This function should only be called from PrepareToDraw, as DidDrawAllLayers
657 // must be called if this helper function is called. Returns DRAW_SUCCESS if
658 // the frame should be drawn.
659 DrawResult CalculateRenderPasses(FrameData* frame);
661 void ClearCurrentlyScrollingLayer();
663 bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
664 const gfx::PointF& device_viewport_point);
666 LayerImpl* FindScrollLayerForDeviceViewportPoint(
667 const gfx::PointF& device_viewport_point,
668 InputHandler::ScrollInputType type,
669 LayerImpl* layer_hit_by_point,
670 bool* scroll_on_main_thread,
671 bool* optional_has_ancestor_scroll_handler) const;
672 float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point,
673 LayerImpl* layer_impl);
674 void StartScrollbarFadeRecursive(LayerImpl* layer);
675 void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
677 void MarkUIResourceNotEvicted(UIResourceId uid);
679 void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
680 void NotifySwapPromiseMonitorsOfForwardingToMainThread();
682 void ScrollAnimationCreate(LayerImpl* layer_impl,
683 const gfx::ScrollOffset& target_offset,
684 const gfx::ScrollOffset& current_offset);
685 bool ScrollAnimationUpdateTarget(LayerImpl* layer_impl,
686 const gfx::Vector2dF& scroll_delta);
688 base::SingleThreadTaskRunner* GetTaskRunner() const {
689 DCHECK(proxy_);
690 return proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
691 : proxy_->MainThreadTaskRunner();
694 typedef base::hash_map<UIResourceId, UIResourceData>
695 UIResourceMap;
696 UIResourceMap ui_resource_map_;
698 // Resources that were evicted by EvictAllUIResources. Resources are removed
699 // from this when they are touched by a create or destroy from the UI resource
700 // request queue.
701 std::set<UIResourceId> evicted_ui_resources_;
703 scoped_ptr<OutputSurface> output_surface_;
705 scoped_ptr<ResourceProvider> resource_provider_;
706 bool content_is_suitable_for_gpu_rasterization_;
707 bool has_gpu_rasterization_trigger_;
708 bool use_gpu_rasterization_;
709 bool use_msaa_;
710 GpuRasterizationStatus gpu_rasterization_status_;
711 bool tree_resources_for_gpu_rasterization_dirty_;
712 scoped_ptr<TileTaskWorkerPool> tile_task_worker_pool_;
713 scoped_ptr<ResourcePool> resource_pool_;
714 scoped_ptr<Renderer> renderer_;
716 GlobalStateThatImpactsTilePriority global_tile_state_;
718 // Tree currently being drawn.
719 scoped_ptr<LayerTreeImpl> active_tree_;
721 // In impl-side painting mode, tree with possibly incomplete rasterized
722 // content. May be promoted to active by ActivatePendingTree().
723 scoped_ptr<LayerTreeImpl> pending_tree_;
725 // In impl-side painting mode, inert tree with layers that can be recycled
726 // by the next sync from the main thread.
727 scoped_ptr<LayerTreeImpl> recycle_tree_;
729 InputHandlerClient* input_handler_client_;
730 bool did_lock_scrolling_layer_;
731 bool should_bubble_scrolls_;
732 bool wheel_scrolling_;
733 bool scroll_affects_scroll_handler_;
734 int scroll_layer_id_when_mouse_over_scrollbar_;
735 ScopedPtrVector<SwapPromise> swap_promises_for_main_thread_scroll_update_;
737 // An object to implement the ScrollElasticityHelper interface and
738 // hold all state related to elasticity. May be NULL if never requested.
739 scoped_ptr<ScrollElasticityHelper> scroll_elasticity_helper_;
741 bool tile_priorities_dirty_;
743 // The optional delegate for the root layer scroll offset.
744 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
745 LayerScrollOffsetDelegate::AnimationCallback root_layer_animation_callback_;
747 const LayerTreeSettings settings_;
748 LayerTreeDebugState debug_state_;
749 bool visible_;
750 ManagedMemoryPolicy cached_managed_memory_policy_;
752 const bool is_synchronous_single_threaded_;
753 scoped_ptr<TileManager> tile_manager_;
755 gfx::Vector2dF accumulated_root_overscroll_;
757 bool pinch_gesture_active_;
758 bool pinch_gesture_end_should_clear_scrolling_layer_;
760 scoped_ptr<TopControlsManager> top_controls_manager_;
762 scoped_ptr<PageScaleAnimation> page_scale_animation_;
764 scoped_ptr<FrameRateCounter> fps_counter_;
765 scoped_ptr<PaintTimeCounter> paint_time_counter_;
766 scoped_ptr<MemoryHistory> memory_history_;
767 scoped_ptr<DebugRectHistory> debug_rect_history_;
769 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
771 // The maximum memory that would be used by the prioritized resource
772 // manager, if there were no limit on memory usage.
773 size_t max_memory_needed_bytes_;
775 // Viewport size passed in from the main thread, in physical pixels. This
776 // value is the default size for all concepts of physical viewport (draw
777 // viewport, scrolling viewport and device viewport), but it can be
778 // overridden.
779 gfx::Size device_viewport_size_;
781 // Conversion factor from CSS pixels to physical pixels when
782 // pageScaleFactor=1.
783 float device_scale_factor_;
785 // Optional top-level constraints that can be set by the OutputSurface.
786 // - external_transform_ applies a transform above the root layer
787 // - external_viewport_ is used DrawProperties, tile management and
788 // glViewport/window projection matrix.
789 // - external_clip_ specifies a top-level clip rect
790 // - viewport_rect_for_tile_priority_ is the rect in view space used for
791 // tiling priority.
792 gfx::Transform external_transform_;
793 gfx::Rect external_viewport_;
794 gfx::Rect external_clip_;
795 gfx::Rect viewport_rect_for_tile_priority_;
796 bool resourceless_software_draw_;
798 gfx::Rect viewport_damage_rect_;
800 scoped_ptr<AnimationRegistrar> animation_registrar_;
801 scoped_ptr<AnimationHost> animation_host_;
802 std::set<ScrollbarAnimationController*> scrollbar_animation_controllers_;
803 std::set<VideoFrameController*> video_frame_controllers_;
805 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
806 MicroBenchmarkControllerImpl micro_benchmark_controller_;
807 scoped_ptr<TaskGraphRunner> single_thread_synchronous_task_graph_runner_;
809 // Optional callback to notify of new tree activations.
810 base::Closure tree_activation_callback_;
812 SharedBitmapManager* shared_bitmap_manager_;
813 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
814 TaskGraphRunner* task_graph_runner_;
815 int id_;
817 std::set<SwapPromiseMonitor*> swap_promise_monitor_;
819 bool requires_high_res_to_draw_;
820 bool is_likely_to_require_a_draw_;
822 scoped_ptr<FrameTimingTracker> frame_timing_tracker_;
824 scoped_ptr<Viewport> viewport_;
826 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
829 } // namespace cc
831 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_