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