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. 4 5 #ifndef CC_TREES_LAYER_TREE_HOST_IMPL_H_ 6 #define CC_TREES_LAYER_TREE_HOST_IMPL_H_ 7 8 #include <list> 9 #include <set> 10 #include <string> 11 #include <vector> 12 13 #include "base/basictypes.h" 14 #include "base/containers/hash_tables.h" 15 #include "base/memory/scoped_ptr.h" 16 #include "base/time/time.h" 17 #include "cc/animation/animation_events.h" 18 #include "cc/animation/animation_registrar.h" 19 #include "cc/animation/scrollbar_animation_controller.h" 20 #include "cc/base/cc_export.h" 21 #include "cc/debug/micro_benchmark_controller_impl.h" 22 #include "cc/input/input_handler.h" 23 #include "cc/input/layer_scroll_offset_delegate.h" 24 #include "cc/input/top_controls_manager_client.h" 25 #include "cc/layers/layer_lists.h" 26 #include "cc/layers/render_pass_sink.h" 27 #include "cc/output/begin_frame_args.h" 28 #include "cc/output/managed_memory_policy.h" 29 #include "cc/output/output_surface_client.h" 30 #include "cc/output/renderer.h" 31 #include "cc/quads/render_pass.h" 32 #include "cc/resources/resource_provider.h" 33 #include "cc/resources/tile_manager.h" 34 #include "cc/scheduler/draw_result.h" 35 #include "skia/ext/refptr.h" 36 #include "third_party/skia/include/core/SkColor.h" 37 #include "ui/gfx/rect.h" 38 39 namespace cc { 40 41 class CompletionEvent; 42 class CompositorFrameMetadata; 43 class DebugRectHistory; 44 class FrameRateCounter; 45 class LayerImpl; 46 class LayerTreeHostImplTimeSourceAdapter; 47 class LayerTreeImpl; 48 class MemoryHistory; 49 class PageScaleAnimation; 50 class PaintTimeCounter; 51 class PictureLayerImpl; 52 class RasterWorkerPool; 53 class RenderPassDrawQuad; 54 class RenderingStatsInstrumentation; 55 class ResourcePool; 56 class ScrollbarLayerImplBase; 57 class TextureMailboxDeleter; 58 class TopControlsManager; 59 class UIResourceBitmap; 60 class UIResourceRequest; 61 struct RendererCapabilitiesImpl; 62 63 // LayerTreeHost->Proxy callback interface. 64 class LayerTreeHostImplClient { 65 public: 66 virtual void UpdateRendererCapabilitiesOnImplThread() = 0; 67 virtual void DidLoseOutputSurfaceOnImplThread() = 0; 68 virtual void CommitVSyncParameters(base::TimeTicks timebase, 69 base::TimeDelta interval) = 0; 70 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time) = 0; 71 virtual void SetMaxSwapsPendingOnImplThread(int max) = 0; 72 virtual void DidSwapBuffersOnImplThread() = 0; 73 virtual void DidSwapBuffersCompleteOnImplThread() = 0; 74 virtual void BeginFrame(const BeginFrameArgs& args) = 0; 75 virtual void OnCanDrawStateChanged(bool can_draw) = 0; 76 virtual void NotifyReadyToActivate() = 0; 77 // Please call these 3 functions through 78 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and 79 // SetNeedsAnimate(). 80 virtual void SetNeedsRedrawOnImplThread() = 0; 81 virtual void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) = 0; 82 virtual void SetNeedsAnimateOnImplThread() = 0; 83 virtual void DidInitializeVisibleTileOnImplThread() = 0; 84 virtual void SetNeedsCommitOnImplThread() = 0; 85 virtual void SetNeedsManageTilesOnImplThread() = 0; 86 virtual void PostAnimationEventsToMainThreadOnImplThread( 87 scoped_ptr<AnimationEventsVector> events) = 0; 88 // Returns true if resources were deleted by this call. 89 virtual bool ReduceContentsTextureMemoryOnImplThread( 90 size_t limit_bytes, 91 int priority_cutoff) = 0; 92 virtual bool IsInsideDraw() = 0; 93 virtual void RenewTreePriority() = 0; 94 virtual void PostDelayedScrollbarFadeOnImplThread( 95 const base::Closure& start_fade, 96 base::TimeDelta delay) = 0; 97 virtual void DidActivatePendingTree() = 0; 98 virtual void DidManageTiles() = 0; 99 100 protected: ~LayerTreeHostImplClient()101 virtual ~LayerTreeHostImplClient() {} 102 }; 103 104 // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering 105 // state. 106 class CC_EXPORT LayerTreeHostImpl 107 : public InputHandler, 108 public RendererClient, 109 public TileManagerClient, 110 public OutputSurfaceClient, 111 public TopControlsManagerClient, 112 public ScrollbarAnimationControllerClient, 113 public base::SupportsWeakPtr<LayerTreeHostImpl> { 114 public: 115 static scoped_ptr<LayerTreeHostImpl> Create( 116 const LayerTreeSettings& settings, 117 LayerTreeHostImplClient* client, 118 Proxy* proxy, 119 RenderingStatsInstrumentation* rendering_stats_instrumentation, 120 SharedBitmapManager* manager, 121 int id); 122 virtual ~LayerTreeHostImpl(); 123 124 // InputHandler implementation 125 virtual void BindToClient(InputHandlerClient* client) OVERRIDE; 126 virtual InputHandler::ScrollStatus ScrollBegin( 127 const gfx::Point& viewport_point, 128 InputHandler::ScrollInputType type) OVERRIDE; 129 virtual bool ScrollBy(const gfx::Point& viewport_point, 130 const gfx::Vector2dF& scroll_delta) OVERRIDE; 131 virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point, 132 ScrollDirection direction) OVERRIDE; 133 virtual void SetRootLayerScrollOffsetDelegate( 134 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) OVERRIDE; 135 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE; 136 virtual void ScrollEnd() OVERRIDE; 137 virtual InputHandler::ScrollStatus FlingScrollBegin() OVERRIDE; 138 virtual void MouseMoveAt(const gfx::Point& viewport_point) OVERRIDE; 139 virtual void PinchGestureBegin() OVERRIDE; 140 virtual void PinchGestureUpdate(float magnify_delta, 141 const gfx::Point& anchor) OVERRIDE; 142 virtual void PinchGestureEnd() OVERRIDE; 143 virtual void StartPageScaleAnimation(const gfx::Vector2d& target_offset, 144 bool anchor_point, 145 float page_scale, 146 base::TimeDelta duration) OVERRIDE; 147 virtual void SetNeedsAnimate() OVERRIDE; 148 virtual bool IsCurrentlyScrollingLayerAt( 149 const gfx::Point& viewport_point, 150 InputHandler::ScrollInputType type) OVERRIDE; 151 virtual bool HaveTouchEventHandlersAt( 152 const gfx::Point& viewport_port) OVERRIDE; 153 virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor( 154 ui::LatencyInfo* latency) OVERRIDE; 155 156 // TopControlsManagerClient implementation. 157 virtual void DidChangeTopControlsPosition() OVERRIDE; 158 virtual bool HaveRootScrollLayer() const OVERRIDE; 159 160 struct CC_EXPORT FrameData : public RenderPassSink { 161 FrameData(); 162 virtual ~FrameData(); 163 scoped_ptr<base::Value> AsValue() const; 164 165 std::vector<gfx::Rect> occluding_screen_space_rects; 166 std::vector<gfx::Rect> non_occluding_screen_space_rects; 167 RenderPassList render_passes; 168 RenderPassIdHashMap render_passes_by_id; 169 const LayerImplList* render_surface_layer_list; 170 LayerImplList will_draw_layers; 171 bool contains_incomplete_tile; 172 bool has_no_damage; 173 174 // RenderPassSink implementation. 175 virtual void AppendRenderPass(scoped_ptr<RenderPass> render_pass) OVERRIDE; 176 }; 177 178 virtual void BeginMainFrameAborted(bool did_handle); 179 virtual void BeginCommit(); 180 virtual void CommitComplete(); 181 virtual void Animate(base::TimeTicks monotonic_time); 182 virtual void UpdateAnimationState(bool start_ready_animations); 183 void ActivateAnimations(); 184 void MainThreadHasStoppedFlinging(); 185 void UpdateBackgroundAnimateTicking(bool should_background_tick); 186 void DidAnimateScrollOffset(); 187 void SetViewportDamage(const gfx::Rect& damage_rect); 188 189 virtual void ManageTiles(); 190 191 // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we 192 // should try to avoid displaying the frame. If PrepareToDraw is called, 193 // DidDrawAllLayers must also be called, regardless of whether DrawLayers is 194 // called between the two. 195 virtual DrawResult PrepareToDraw(FrameData* frame); 196 virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time); 197 // Must be called if and only if PrepareToDraw was called. 198 void DidDrawAllLayers(const FrameData& frame); 199 settings()200 const LayerTreeSettings& settings() const { return settings_; } 201 202 // Evict all textures by enforcing a memory policy with an allocation of 0. 203 void EvictTexturesForTesting(); 204 205 // When blocking, this prevents client_->NotifyReadyToActivate() from being 206 // called. When disabled, it calls client_->NotifyReadyToActivate() 207 // immediately if any notifications had been blocked while blocking. 208 virtual void BlockNotifyReadyToActivateForTesting(bool block); 209 210 // This allows us to inject DidInitializeVisibleTile events for testing. 211 void DidInitializeVisibleTileForTesting(); 212 213 // Resets all of the trees to an empty state. 214 void ResetTreesForTesting(); 215 void ResetRecycleTreeForTesting(); 216 217 DrawMode GetDrawMode() const; 218 219 // Viewport size in draw space: this size is in physical pixels and is used 220 // for draw properties, tilings, quads and render passes. 221 gfx::Size DrawViewportSize() const; 222 223 // Viewport rect in view space used for tiling prioritization. 224 const gfx::Rect ViewportRectForTilePriority() const; 225 226 // Viewport size for scrolling and fixed-position compensation. This value 227 // excludes the URL bar and non-overlay scrollbars and is in DIP (and 228 // invariant relative to page scale). 229 gfx::SizeF UnscaledScrollableViewportSize() const; 230 float VerticalAdjust() const; 231 232 // RendererClient implementation. 233 virtual void SetFullRootLayerDamage() OVERRIDE; 234 virtual void RunOnDemandRasterTask(Task* on_demand_raster_task) OVERRIDE; 235 236 // TileManagerClient implementation. 237 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() OVERRIDE; 238 virtual void NotifyReadyToActivate() OVERRIDE; 239 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE; 240 241 // ScrollbarAnimationControllerClient implementation. 242 virtual void PostDelayedScrollbarFade(const base::Closure& start_fade, 243 base::TimeDelta delay) OVERRIDE; 244 virtual void SetNeedsScrollbarAnimationFrame() OVERRIDE; 245 246 // OutputSurfaceClient implementation. 247 virtual void DeferredInitialize() OVERRIDE; 248 virtual void ReleaseGL() OVERRIDE; 249 virtual void CommitVSyncParameters(base::TimeTicks timebase, 250 base::TimeDelta interval) OVERRIDE; 251 virtual void SetNeedsRedrawRect(const gfx::Rect& rect) OVERRIDE; 252 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; 253 254 virtual void SetExternalDrawConstraints( 255 const gfx::Transform& transform, 256 const gfx::Rect& viewport, 257 const gfx::Rect& clip, 258 const gfx::Rect& viewport_rect_for_tile_priority, 259 const gfx::Transform& transform_for_tile_priority, 260 bool resourceless_software_draw) OVERRIDE; 261 virtual void DidLoseOutputSurface() OVERRIDE; 262 virtual void DidSwapBuffers() OVERRIDE; 263 virtual void DidSwapBuffersComplete() OVERRIDE; 264 virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE; 265 virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE; 266 virtual void SetTreeActivationCallback(const base::Closure& callback) 267 OVERRIDE; 268 269 // Called from LayerTreeImpl. 270 void OnCanDrawStateChangedForTree(); 271 272 // Implementation. id()273 int id() const { return id_; } 274 bool CanDraw() const; output_surface()275 OutputSurface* output_surface() const { return output_surface_.get(); } 276 277 std::string LayerTreeAsJson() const; 278 279 void FinishAllRendering(); 280 int SourceAnimationFrameNumber() const; 281 282 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface); 283 bool IsContextLost(); tile_manager()284 TileManager* tile_manager() { return tile_manager_.get(); } 285 void SetUseGpuRasterization(bool use_gpu); use_gpu_rasterization()286 bool use_gpu_rasterization() const { return use_gpu_rasterization_; } create_low_res_tiling()287 bool create_low_res_tiling() const { 288 return settings_.create_low_res_tiling && !use_gpu_rasterization_; 289 } resource_pool()290 ResourcePool* resource_pool() { return resource_pool_.get(); } renderer()291 Renderer* renderer() { return renderer_.get(); } 292 const RendererCapabilitiesImpl& GetRendererCapabilities() const; 293 294 virtual bool SwapBuffers(const FrameData& frame); 295 void SetNeedsBeginFrame(bool enable); 296 virtual void WillBeginImplFrame(const BeginFrameArgs& args); 297 void DidModifyTilePriorities(); 298 active_tree()299 LayerTreeImpl* active_tree() { return active_tree_.get(); } active_tree()300 const LayerTreeImpl* active_tree() const { return active_tree_.get(); } pending_tree()301 LayerTreeImpl* pending_tree() { return pending_tree_.get(); } pending_tree()302 const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); } recycle_tree()303 LayerTreeImpl* recycle_tree() { return recycle_tree_.get(); } recycle_tree()304 const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); } 305 // Returns the tree LTH synchronizes with. sync_tree()306 LayerTreeImpl* sync_tree() { 307 // In impl-side painting, synchronize to the pending tree so that it has 308 // time to raster before being displayed. 309 return settings_.impl_side_painting ? pending_tree_.get() 310 : active_tree_.get(); 311 } 312 virtual void CreatePendingTree(); 313 virtual void UpdateVisibleTiles(); 314 virtual void ActivatePendingTree(); 315 316 // Shortcuts to layers on the active tree. 317 LayerImpl* RootLayer() const; 318 LayerImpl* InnerViewportScrollLayer() const; 319 LayerImpl* OuterViewportScrollLayer() const; 320 LayerImpl* CurrentlyScrollingLayer() const; 321 scroll_layer_id_when_mouse_over_scrollbar()322 int scroll_layer_id_when_mouse_over_scrollbar() const { 323 return scroll_layer_id_when_mouse_over_scrollbar_; 324 } scroll_affects_scroll_handler()325 bool scroll_affects_scroll_handler() const { 326 return scroll_affects_scroll_handler_; 327 } 328 329 bool IsCurrentlyScrolling() const; 330 331 virtual void SetVisible(bool visible); visible()332 bool visible() const { return visible_; } 333 SetNeedsCommit()334 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); } 335 void SetNeedsRedraw(); 336 337 ManagedMemoryPolicy ActualManagedMemoryPolicy() const; 338 339 size_t memory_allocation_limit_bytes() const; 340 int memory_allocation_priority_cutoff() const; 341 342 void SetViewportSize(const gfx::Size& device_viewport_size); device_viewport_size()343 gfx::Size device_viewport_size() const { return device_viewport_size_; } 344 345 void SetOverdrawBottomHeight(float overdraw_bottom_height); overdraw_bottom_height()346 float overdraw_bottom_height() const { return overdraw_bottom_height_; } 347 348 void SetOverhangUIResource(UIResourceId overhang_ui_resource_id, 349 const gfx::Size& overhang_ui_resource_size); 350 351 void SetDeviceScaleFactor(float device_scale_factor); device_scale_factor()352 float device_scale_factor() const { return device_scale_factor_; } 353 354 const gfx::Transform& DrawTransform() const; 355 356 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas(); 357 needs_animate_layers()358 bool needs_animate_layers() const { 359 return !animation_registrar_->active_animation_controllers().empty(); 360 } 361 set_max_memory_needed_bytes(size_t bytes)362 void set_max_memory_needed_bytes(size_t bytes) { 363 max_memory_needed_bytes_ = bytes; 364 } 365 fps_counter()366 FrameRateCounter* fps_counter() { 367 return fps_counter_.get(); 368 } paint_time_counter()369 PaintTimeCounter* paint_time_counter() { 370 return paint_time_counter_.get(); 371 } memory_history()372 MemoryHistory* memory_history() { 373 return memory_history_.get(); 374 } debug_rect_history()375 DebugRectHistory* debug_rect_history() { 376 return debug_rect_history_.get(); 377 } resource_provider()378 ResourceProvider* resource_provider() { 379 return resource_provider_.get(); 380 } top_controls_manager()381 TopControlsManager* top_controls_manager() { 382 return top_controls_manager_.get(); 383 } global_tile_state()384 const GlobalStateThatImpactsTilePriority& global_tile_state() { 385 return global_tile_state_; 386 } 387 proxy()388 Proxy* proxy() const { return proxy_; } 389 animation_registrar()390 AnimationRegistrar* animation_registrar() const { 391 return animation_registrar_.get(); 392 } 393 394 void SetDebugState(const LayerTreeDebugState& new_debug_state); debug_state()395 const LayerTreeDebugState& debug_state() const { return debug_state_; } 396 397 class CC_EXPORT CullRenderPassesWithNoQuads { 398 public: 399 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad, 400 const FrameData& frame) const; 401 402 // Iterates in draw order, so that when a surface is removed, and its 403 // target becomes empty, then its target can be removed also. RenderPassListBegin(const RenderPassList & list)404 size_t RenderPassListBegin(const RenderPassList& list) const { return 0; } RenderPassListEnd(const RenderPassList & list)405 size_t RenderPassListEnd(const RenderPassList& list) const { 406 return list.size(); 407 } RenderPassListNext(size_t it)408 size_t RenderPassListNext(size_t it) const { return it + 1; } 409 }; 410 411 template <typename RenderPassCuller> 412 static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame); 413 accumulated_root_overscroll()414 gfx::Vector2dF accumulated_root_overscroll() const { 415 return accumulated_root_overscroll_; 416 } 417 pinch_gesture_active()418 bool pinch_gesture_active() const { return pinch_gesture_active_; } 419 420 void SetTreePriority(TreePriority priority); 421 422 void UpdateCurrentFrameTime(); 423 void ResetCurrentFrameTimeForNextFrame(); 424 virtual base::TimeTicks CurrentFrameTimeTicks(); 425 426 // Expected time between two begin impl frame calls. begin_impl_frame_interval()427 base::TimeDelta begin_impl_frame_interval() const { 428 return begin_impl_frame_interval_; 429 } 430 AsValue()431 scoped_ptr<base::Value> AsValue() const { return AsValueWithFrame(NULL); } 432 scoped_ptr<base::Value> AsValueWithFrame(FrameData* frame) const; 433 scoped_ptr<base::Value> ActivationStateAsValue() const; 434 page_scale_animation_active()435 bool page_scale_animation_active() const { return !!page_scale_animation_; } 436 437 virtual void CreateUIResource(UIResourceId uid, 438 const UIResourceBitmap& bitmap); 439 // Deletes a UI resource. May safely be called more than once. 440 virtual void DeleteUIResource(UIResourceId uid); 441 void EvictAllUIResources(); 442 bool EvictedUIResourcesExist() const; 443 444 virtual ResourceProvider::ResourceId ResourceIdForUIResource( 445 UIResourceId uid) const; 446 447 virtual bool IsUIResourceOpaque(UIResourceId uid) const; 448 449 struct UIResourceData { 450 ResourceProvider::ResourceId resource_id; 451 gfx::Size size; 452 bool opaque; 453 }; 454 455 void ScheduleMicroBenchmark(scoped_ptr<MicroBenchmarkImpl> benchmark); 456 457 CompositorFrameMetadata MakeCompositorFrameMetadata() const; 458 // Viewport rectangle and clip in nonflipped window space. These rects 459 // should only be used by Renderer subclasses to populate glViewport/glClip 460 // and their software-mode equivalents. 461 gfx::Rect DeviceViewport() const; 462 gfx::Rect DeviceClip() const; 463 464 // When a SwapPromiseMonitor is created on the impl thread, it calls 465 // InsertSwapPromiseMonitor() to register itself with LayerTreeHostImpl. 466 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor() 467 // to unregister itself. 468 void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor); 469 void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor); 470 471 void RegisterPictureLayerImpl(PictureLayerImpl* layer); 472 void UnregisterPictureLayerImpl(PictureLayerImpl* layer); 473 474 protected: 475 LayerTreeHostImpl( 476 const LayerTreeSettings& settings, 477 LayerTreeHostImplClient* client, 478 Proxy* proxy, 479 RenderingStatsInstrumentation* rendering_stats_instrumentation, 480 SharedBitmapManager* manager, 481 int id); 482 483 gfx::SizeF ComputeInnerViewportContainerSize() const; 484 void UpdateInnerViewportContainerSize(); 485 486 // Virtual for testing. 487 virtual void AnimateLayers(base::TimeTicks monotonic_time); 488 489 // Virtual for testing. 490 virtual base::TimeDelta LowFrequencyAnimationInterval() const; 491 492 const AnimationRegistrar::AnimationControllerMap& active_animation_controllers()493 active_animation_controllers() const { 494 return animation_registrar_->active_animation_controllers(); 495 } 496 manage_tiles_needed()497 bool manage_tiles_needed() const { return tile_priorities_dirty_; } 498 499 LayerTreeHostImplClient* client_; 500 Proxy* proxy_; 501 502 private: 503 void CreateAndSetRenderer(); 504 void CreateAndSetTileManager(); 505 void DestroyTileManager(); 506 void ReleaseTreeResources(); 507 void EnforceZeroBudget(bool zero_budget); 508 509 bool UseZeroCopyTextureUpload() const; 510 bool UseOneCopyTextureUpload() const; 511 512 void ScrollViewportBy(gfx::Vector2dF scroll_delta); 513 void AnimatePageScale(base::TimeTicks monotonic_time); 514 void AnimateScrollbars(base::TimeTicks monotonic_time); 515 void AnimateTopControls(base::TimeTicks monotonic_time); 516 517 gfx::Vector2dF ScrollLayerWithViewportSpaceDelta( 518 LayerImpl* layer_impl, 519 float scale_from_viewport_to_screen_space, 520 const gfx::PointF& viewport_point, 521 const gfx::Vector2dF& viewport_delta); 522 523 void TrackDamageForAllSurfaces( 524 LayerImpl* root_draw_layer, 525 const LayerImplList& render_surface_layer_list); 526 527 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy); 528 529 // This function should only be called from PrepareToDraw, as DidDrawAllLayers 530 // must be called if this helper function is called. Returns DRAW_SUCCESS if 531 // the frame should be drawn. 532 DrawResult CalculateRenderPasses(FrameData* frame); 533 534 void ClearCurrentlyScrollingLayer(); 535 536 bool HandleMouseOverScrollbar(LayerImpl* layer_impl, 537 const gfx::PointF& device_viewport_point); 538 539 void AnimateScrollbarsRecursive(LayerImpl* layer, 540 base::TimeTicks time); 541 542 LayerImpl* FindScrollLayerForDeviceViewportPoint( 543 const gfx::PointF& device_viewport_point, 544 InputHandler::ScrollInputType type, 545 LayerImpl* layer_hit_by_point, 546 bool* scroll_on_main_thread, 547 bool* optional_has_ancestor_scroll_handler) const; 548 float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point, 549 LayerImpl* layer_impl); 550 void StartScrollbarFadeRecursive(LayerImpl* layer); 551 void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy, 552 bool zero_budget); 553 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy); 554 555 void DidInitializeVisibleTile(); 556 557 void MarkUIResourceNotEvicted(UIResourceId uid); 558 559 void NotifySwapPromiseMonitorsOfSetNeedsRedraw(); 560 561 typedef base::hash_map<UIResourceId, UIResourceData> 562 UIResourceMap; 563 UIResourceMap ui_resource_map_; 564 565 // Resources that were evicted by EvictAllUIResources. Resources are removed 566 // from this when they are touched by a create or destroy from the UI resource 567 // request queue. 568 std::set<UIResourceId> evicted_ui_resources_; 569 570 scoped_ptr<OutputSurface> output_surface_; 571 scoped_refptr<ContextProvider> offscreen_context_provider_; 572 573 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile- 574 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice(). 575 scoped_ptr<ResourceProvider> resource_provider_; 576 scoped_ptr<TileManager> tile_manager_; 577 bool use_gpu_rasterization_; 578 scoped_ptr<RasterWorkerPool> raster_worker_pool_; 579 scoped_ptr<ResourcePool> resource_pool_; 580 scoped_ptr<ResourcePool> staging_resource_pool_; 581 scoped_ptr<Renderer> renderer_; 582 583 TaskGraphRunner synchronous_task_graph_runner_; 584 TaskGraphRunner* on_demand_task_graph_runner_; 585 NamespaceToken on_demand_task_namespace_; 586 587 GlobalStateThatImpactsTilePriority global_tile_state_; 588 589 // Tree currently being drawn. 590 scoped_ptr<LayerTreeImpl> active_tree_; 591 592 // In impl-side painting mode, tree with possibly incomplete rasterized 593 // content. May be promoted to active by ActivatePendingTree(). 594 scoped_ptr<LayerTreeImpl> pending_tree_; 595 596 // In impl-side painting mode, inert tree with layers that can be recycled 597 // by the next sync from the main thread. 598 scoped_ptr<LayerTreeImpl> recycle_tree_; 599 600 InputHandlerClient* input_handler_client_; 601 bool did_lock_scrolling_layer_; 602 bool should_bubble_scrolls_; 603 bool wheel_scrolling_; 604 bool scroll_affects_scroll_handler_; 605 int scroll_layer_id_when_mouse_over_scrollbar_; 606 607 bool tile_priorities_dirty_; 608 609 // The optional delegate for the root layer scroll offset. 610 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_; 611 LayerTreeSettings settings_; 612 LayerTreeDebugState debug_state_; 613 bool visible_; 614 ManagedMemoryPolicy cached_managed_memory_policy_; 615 616 gfx::Vector2dF accumulated_root_overscroll_; 617 618 bool pinch_gesture_active_; 619 bool pinch_gesture_end_should_clear_scrolling_layer_; 620 gfx::Point previous_pinch_anchor_; 621 622 scoped_ptr<TopControlsManager> top_controls_manager_; 623 624 scoped_ptr<PageScaleAnimation> page_scale_animation_; 625 626 // This is used for ticking animations slowly when hidden. 627 scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_; 628 629 scoped_ptr<FrameRateCounter> fps_counter_; 630 scoped_ptr<PaintTimeCounter> paint_time_counter_; 631 scoped_ptr<MemoryHistory> memory_history_; 632 scoped_ptr<DebugRectHistory> debug_rect_history_; 633 634 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_; 635 636 // The maximum memory that would be used by the prioritized resource 637 // manager, if there were no limit on memory usage. 638 size_t max_memory_needed_bytes_; 639 640 bool zero_budget_; 641 642 // Viewport size passed in from the main thread, in physical pixels. This 643 // value is the default size for all concepts of physical viewport (draw 644 // viewport, scrolling viewport and device viewport), but it can be 645 // overridden. 646 gfx::Size device_viewport_size_; 647 648 // Conversion factor from CSS pixels to physical pixels when 649 // pageScaleFactor=1. 650 float device_scale_factor_; 651 652 // UI resource to use for drawing overhang gutters. 653 UIResourceId overhang_ui_resource_id_; 654 gfx::Size overhang_ui_resource_size_; 655 656 // Vertical amount of the viewport size that's known to covered by a 657 // browser-side UI element, such as an on-screen-keyboard. This affects 658 // scrollable size since we want to still be able to scroll to the bottom of 659 // the page when the keyboard is up. 660 float overdraw_bottom_height_; 661 662 // Optional top-level constraints that can be set by the OutputSurface. 663 // - external_transform_ applies a transform above the root layer 664 // - external_viewport_ is used DrawProperties, tile management and 665 // glViewport/window projection matrix. 666 // - external_clip_ specifies a top-level clip rect 667 // - viewport_rect_for_tile_priority_ is the rect in view space used for 668 // tiling priority. 669 gfx::Transform external_transform_; 670 gfx::Rect external_viewport_; 671 gfx::Rect external_clip_; 672 gfx::Rect viewport_rect_for_tile_priority_; 673 bool resourceless_software_draw_; 674 675 gfx::Rect viewport_damage_rect_; 676 677 base::TimeTicks current_frame_timeticks_; 678 679 // Expected time between two begin impl frame calls. 680 base::TimeDelta begin_impl_frame_interval_; 681 682 scoped_ptr<AnimationRegistrar> animation_registrar_; 683 684 RenderingStatsInstrumentation* rendering_stats_instrumentation_; 685 MicroBenchmarkControllerImpl micro_benchmark_controller_; 686 687 bool need_to_update_visible_tiles_before_draw_; 688 #if DCHECK_IS_ON 689 bool did_lose_called_; 690 #endif 691 692 // Optional callback to notify of new tree activations. 693 base::Closure tree_activation_callback_; 694 695 SharedBitmapManager* shared_bitmap_manager_; 696 int id_; 697 698 std::set<SwapPromiseMonitor*> swap_promise_monitor_; 699 700 size_t transfer_buffer_memory_limit_; 701 702 std::vector<PictureLayerImpl*> picture_layers_; 703 704 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl); 705 }; 706 707 } // namespace cc 708 709 #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_ 710