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