| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_TREES_LAYER_TREE_HOST_H_ | 5 #ifndef CC_TREES_LAYER_TREE_HOST_H_ |
| 6 #define CC_TREES_LAYER_TREE_HOST_H_ | 6 #define CC_TREES_LAYER_TREE_HOST_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "cc/output/output_surface.h" | 36 #include "cc/output/output_surface.h" |
| 37 #include "cc/output/renderer_capabilities.h" | 37 #include "cc/output/renderer_capabilities.h" |
| 38 #include "cc/output/swap_promise.h" | 38 #include "cc/output/swap_promise.h" |
| 39 #include "cc/resources/resource_format.h" | 39 #include "cc/resources/resource_format.h" |
| 40 #include "cc/resources/scoped_ui_resource.h" | 40 #include "cc/resources/scoped_ui_resource.h" |
| 41 #include "cc/surfaces/surface_sequence.h" | 41 #include "cc/surfaces/surface_sequence.h" |
| 42 #include "cc/trees/compositor_mode.h" | 42 #include "cc/trees/compositor_mode.h" |
| 43 #include "cc/trees/layer_tree.h" | 43 #include "cc/trees/layer_tree.h" |
| 44 #include "cc/trees/layer_tree_host_client.h" | 44 #include "cc/trees/layer_tree_host_client.h" |
| 45 #include "cc/trees/layer_tree_settings.h" | 45 #include "cc/trees/layer_tree_settings.h" |
| 46 #include "cc/trees/mutator_host_client.h" | |
| 47 #include "cc/trees/proxy.h" | 46 #include "cc/trees/proxy.h" |
| 48 #include "cc/trees/swap_promise_monitor.h" | 47 #include "cc/trees/swap_promise_monitor.h" |
| 49 #include "third_party/skia/include/core/SkColor.h" | 48 #include "third_party/skia/include/core/SkColor.h" |
| 50 #include "ui/gfx/geometry/rect.h" | 49 #include "ui/gfx/geometry/rect.h" |
| 51 | 50 |
| 52 namespace gpu { | 51 namespace gpu { |
| 53 class GpuMemoryBufferManager; | 52 class GpuMemoryBufferManager; |
| 54 } | 53 } |
| 55 | 54 |
| 56 namespace cc { | 55 namespace cc { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 76 class TopControlsManager; | 75 class TopControlsManager; |
| 77 class UIResourceRequest; | 76 class UIResourceRequest; |
| 78 struct PendingPageScaleAnimation; | 77 struct PendingPageScaleAnimation; |
| 79 struct RenderingStats; | 78 struct RenderingStats; |
| 80 struct ScrollAndScaleSet; | 79 struct ScrollAndScaleSet; |
| 81 | 80 |
| 82 namespace proto { | 81 namespace proto { |
| 83 class LayerTreeHost; | 82 class LayerTreeHost; |
| 84 } | 83 } |
| 85 | 84 |
| 86 class CC_EXPORT LayerTreeHost : public MutatorHostClient { | 85 class CC_EXPORT LayerTreeHost { |
| 87 public: | 86 public: |
| 88 // TODO(sad): InitParams should be a movable type so that it can be | 87 // TODO(sad): InitParams should be a movable type so that it can be |
| 89 // std::move()d to the Create* functions. | 88 // std::move()d to the Create* functions. |
| 90 struct CC_EXPORT InitParams { | 89 struct CC_EXPORT InitParams { |
| 91 LayerTreeHostClient* client = nullptr; | 90 LayerTreeHostClient* client = nullptr; |
| 92 SharedBitmapManager* shared_bitmap_manager = nullptr; | 91 SharedBitmapManager* shared_bitmap_manager = nullptr; |
| 93 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = nullptr; | 92 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = nullptr; |
| 94 TaskGraphRunner* task_graph_runner = nullptr; | 93 TaskGraphRunner* task_graph_runner = nullptr; |
| 95 LayerTreeSettings const* settings = nullptr; | 94 LayerTreeSettings const* settings = nullptr; |
| 96 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner; | 95 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void DidInitializeOutputSurface(); | 144 void DidInitializeOutputSurface(); |
| 146 void DidFailToInitializeOutputSurface(); | 145 void DidFailToInitializeOutputSurface(); |
| 147 virtual std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 146 virtual std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
| 148 LayerTreeHostImplClient* client); | 147 LayerTreeHostImplClient* client); |
| 149 void DidLoseOutputSurface(); | 148 void DidLoseOutputSurface(); |
| 150 bool output_surface_lost() const { return output_surface_lost_; } | 149 bool output_surface_lost() const { return output_surface_lost_; } |
| 151 void DidCommitAndDrawFrame() { client_->DidCommitAndDrawFrame(); } | 150 void DidCommitAndDrawFrame() { client_->DidCommitAndDrawFrame(); } |
| 152 void DidCompleteSwapBuffers() { client_->DidCompleteSwapBuffers(); } | 151 void DidCompleteSwapBuffers() { client_->DidCompleteSwapBuffers(); } |
| 153 bool UpdateLayers(); | 152 bool UpdateLayers(); |
| 154 | 153 |
| 155 LayerListIterator<Layer> begin() const; | |
| 156 LayerListIterator<Layer> end() const; | |
| 157 LayerListReverseIterator<Layer> rbegin(); | |
| 158 LayerListReverseIterator<Layer> rend(); | |
| 159 | |
| 160 // Called when the compositor completed page scale animation. | 154 // Called when the compositor completed page scale animation. |
| 161 void DidCompletePageScaleAnimation(); | 155 void DidCompletePageScaleAnimation(); |
| 162 | 156 |
| 163 LayerTreeHostClient* client() { return client_; } | 157 LayerTreeHostClient* client() { return client_; } |
| 164 const base::WeakPtr<InputHandler>& GetInputHandler() { | 158 const base::WeakPtr<InputHandler>& GetInputHandler() { |
| 165 return input_handler_weak_ptr_; | 159 return input_handler_weak_ptr_; |
| 166 } | 160 } |
| 167 | 161 |
| 168 void NotifyInputThrottledUntilCommit(); | 162 void NotifyInputThrottledUntilCommit(); |
| 169 | 163 |
| 170 void LayoutAndUpdateLayers(); | 164 void LayoutAndUpdateLayers(); |
| 171 void Composite(base::TimeTicks frame_begin_time); | 165 void Composite(base::TimeTicks frame_begin_time); |
| 172 | 166 |
| 173 void SetDeferCommits(bool defer_commits); | 167 void SetDeferCommits(bool defer_commits); |
| 174 | 168 |
| 175 int source_frame_number() const { return source_frame_number_; } | 169 int source_frame_number() const { return source_frame_number_; } |
| 176 | 170 |
| 177 bool gpu_rasterization_histogram_recorded() const { | 171 bool gpu_rasterization_histogram_recorded() const { |
| 178 return gpu_rasterization_histogram_recorded_; | 172 return gpu_rasterization_histogram_recorded_; |
| 179 } | 173 } |
| 180 | 174 |
| 181 void SetNeedsDisplayOnAllLayers(); | |
| 182 | |
| 183 void CollectRenderingStats(RenderingStats* stats) const; | 175 void CollectRenderingStats(RenderingStats* stats) const; |
| 184 | 176 |
| 185 RenderingStatsInstrumentation* rendering_stats_instrumentation() const { | 177 RenderingStatsInstrumentation* rendering_stats_instrumentation() const { |
| 186 return rendering_stats_instrumentation_.get(); | 178 return rendering_stats_instrumentation_.get(); |
| 187 } | 179 } |
| 188 | 180 |
| 189 virtual const RendererCapabilities& GetRendererCapabilities() const; | 181 virtual const RendererCapabilities& GetRendererCapabilities() const; |
| 190 | 182 |
| 191 void SetNeedsAnimate(); | 183 void SetNeedsAnimate(); |
| 192 virtual void SetNeedsUpdateLayers(); | 184 virtual void SetNeedsUpdateLayers(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 void UpdateTopControlsState(TopControlsState constraints, | 279 void UpdateTopControlsState(TopControlsState constraints, |
| 288 TopControlsState current, | 280 TopControlsState current, |
| 289 bool animate); | 281 bool animate); |
| 290 | 282 |
| 291 HeadsUpDisplayLayer* hud_layer() const { return hud_layer_.get(); } | 283 HeadsUpDisplayLayer* hud_layer() const { return hud_layer_.get(); } |
| 292 | 284 |
| 293 Proxy* proxy() const { return proxy_.get(); } | 285 Proxy* proxy() const { return proxy_.get(); } |
| 294 TaskRunnerProvider* task_runner_provider() const { | 286 TaskRunnerProvider* task_runner_provider() const { |
| 295 return task_runner_provider_.get(); | 287 return task_runner_provider_.get(); |
| 296 } | 288 } |
| 297 AnimationHost* animation_host() const; | |
| 298 | 289 |
| 299 bool has_output_surface() const { return !!current_output_surface_; } | 290 bool has_output_surface() const { return !!current_output_surface_; } |
| 300 | 291 |
| 301 // CreateUIResource creates a resource given a bitmap. The bitmap is | 292 // CreateUIResource creates a resource given a bitmap. The bitmap is |
| 302 // generated via an interface function, which is called when initializing the | 293 // generated via an interface function, which is called when initializing the |
| 303 // resource and when the resource has been lost (due to lost context). The | 294 // resource and when the resource has been lost (due to lost context). The |
| 304 // parameter of the interface is a single boolean, which indicates whether the | 295 // parameter of the interface is a single boolean, which indicates whether the |
| 305 // resource has been lost or not. CreateUIResource returns an Id of the | 296 // resource has been lost or not. CreateUIResource returns an Id of the |
| 306 // resource, which is always positive. | 297 // resource, which is always positive. |
| 307 virtual UIResourceId CreateUIResource(UIResourceClient* client); | 298 virtual UIResourceId CreateUIResource(UIResourceClient* client); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 void set_surface_client_id(uint32_t client_id); | 332 void set_surface_client_id(uint32_t client_id); |
| 342 SurfaceSequence CreateSurfaceSequence(); | 333 SurfaceSequence CreateSurfaceSequence(); |
| 343 | 334 |
| 344 PropertyTrees* property_trees() { return &property_trees_; } | 335 PropertyTrees* property_trees() { return &property_trees_; } |
| 345 bool needs_meta_info_recomputation() { | 336 bool needs_meta_info_recomputation() { |
| 346 return needs_meta_info_recomputation_; | 337 return needs_meta_info_recomputation_; |
| 347 } | 338 } |
| 348 | 339 |
| 349 void SetLayerTreeMutator(std::unique_ptr<LayerTreeMutator> mutator); | 340 void SetLayerTreeMutator(std::unique_ptr<LayerTreeMutator> mutator); |
| 350 | 341 |
| 351 Layer* LayerById(int id) const; | |
| 352 | |
| 353 Layer* LayerByElementId(ElementId element_id) const; | |
| 354 void AddToElementMap(Layer* layer); | |
| 355 void RemoveFromElementMap(Layer* layer); | |
| 356 | |
| 357 // MutatorHostClient implementation. | |
| 358 bool IsElementInList(ElementId element_id, | |
| 359 ElementListType list_type) const override; | |
| 360 void SetMutatorsNeedCommit() override; | |
| 361 void SetMutatorsNeedRebuildPropertyTrees() override; | |
| 362 void SetElementFilterMutated(ElementId element_id, | |
| 363 ElementListType list_type, | |
| 364 const FilterOperations& filters) override; | |
| 365 void SetElementOpacityMutated(ElementId element_id, | |
| 366 ElementListType list_type, | |
| 367 float opacity) override; | |
| 368 void SetElementTransformMutated(ElementId element_id, | |
| 369 ElementListType list_type, | |
| 370 const gfx::Transform& transform) override; | |
| 371 void SetElementScrollOffsetMutated( | |
| 372 ElementId element_id, | |
| 373 ElementListType list_type, | |
| 374 const gfx::ScrollOffset& scroll_offset) override; | |
| 375 void ElementTransformIsAnimatingChanged(ElementId element_id, | |
| 376 ElementListType list_type, | |
| 377 AnimationChangeType change_type, | |
| 378 bool is_animating) override; | |
| 379 void ElementOpacityIsAnimatingChanged(ElementId element_id, | |
| 380 ElementListType list_type, | |
| 381 AnimationChangeType change_type, | |
| 382 bool is_animating) override; | |
| 383 void ElementFilterIsAnimatingChanged(ElementId element_id, | |
| 384 ElementListType list_type, | |
| 385 AnimationChangeType change_type, | |
| 386 bool is_animating) override; | |
| 387 void ScrollOffsetAnimationFinished() override {} | |
| 388 gfx::ScrollOffset GetScrollOffsetForAnimation( | |
| 389 ElementId element_id) const override; | |
| 390 | |
| 391 // Serializes the parts of this LayerTreeHost that is needed for a commit to a | 342 // Serializes the parts of this LayerTreeHost that is needed for a commit to a |
| 392 // protobuf message. Not all members are serialized as they are not helpful | 343 // protobuf message. Not all members are serialized as they are not helpful |
| 393 // for remote usage. | 344 // for remote usage. |
| 394 // The |swap_promise_list_| is transferred to the serializer in | 345 // The |swap_promise_list_| is transferred to the serializer in |
| 395 // |swap_promises|. | 346 // |swap_promises|. |
| 396 void ToProtobufForCommit( | 347 void ToProtobufForCommit( |
| 397 proto::LayerTreeHost* proto, | 348 proto::LayerTreeHost* proto, |
| 398 std::vector<std::unique_ptr<SwapPromise>>* swap_promises); | 349 std::vector<std::unique_ptr<SwapPromise>>* swap_promises); |
| 399 | 350 |
| 400 // Deserializes the protobuf into this LayerTreeHost before a commit. The | 351 // Deserializes the protobuf into this LayerTreeHost before a commit. The |
| 401 // expected input is a serialized remote LayerTreeHost. After deserializing | 352 // expected input is a serialized remote LayerTreeHost. After deserializing |
| 402 // the protobuf, the normal commit-flow should continue. | 353 // the protobuf, the normal commit-flow should continue. |
| 403 void FromProtobufForCommit(const proto::LayerTreeHost& proto); | 354 void FromProtobufForCommit(const proto::LayerTreeHost& proto); |
| 404 | 355 |
| 405 bool IsSingleThreaded() const; | 356 bool IsSingleThreaded() const; |
| 406 bool IsThreaded() const; | 357 bool IsThreaded() const; |
| 407 bool IsRemoteServer() const; | 358 bool IsRemoteServer() const; |
| 408 bool IsRemoteClient() const; | 359 bool IsRemoteClient() const; |
| 409 void BuildPropertyTreesForTesting(); | 360 void BuildPropertyTreesForTesting(); |
| 410 | 361 |
| 411 void SetElementIdsForTesting(); | |
| 412 | |
| 413 ImageSerializationProcessor* image_serialization_processor() const { | 362 ImageSerializationProcessor* image_serialization_processor() const { |
| 414 return image_serialization_processor_; | 363 return image_serialization_processor_; |
| 415 } | 364 } |
| 416 | 365 |
| 417 EnginePictureCache* engine_picture_cache() const { | 366 EnginePictureCache* engine_picture_cache() const { |
| 418 return engine_picture_cache_ ? engine_picture_cache_.get() : nullptr; | 367 return engine_picture_cache_ ? engine_picture_cache_.get() : nullptr; |
| 419 } | 368 } |
| 420 | 369 |
| 421 ClientPictureCache* client_picture_cache() const { | 370 ClientPictureCache* client_picture_cache() const { |
| 422 return client_picture_cache_ ? client_picture_cache_.get() : nullptr; | 371 return client_picture_cache_ ? client_picture_cache_.get() : nullptr; |
| 423 } | 372 } |
| 424 | 373 |
| 425 LayerTree* GetLayerTree() { return &layer_tree_; } | 374 LayerTree* GetLayerTree() { return layer_tree_.get(); } |
| 426 const LayerTree* GetLayerTree() const { return &layer_tree_; } | 375 const LayerTree* GetLayerTree() const { return layer_tree_.get(); } |
| 427 | 376 |
| 428 protected: | 377 protected: |
| 429 LayerTreeHost(InitParams* params, CompositorMode mode); | 378 LayerTreeHost(InitParams* params, CompositorMode mode); |
| 430 void InitializeThreaded( | 379 void InitializeThreaded( |
| 431 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 380 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 432 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | 381 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 433 std::unique_ptr<BeginFrameSource> external_begin_frame_source); | 382 std::unique_ptr<BeginFrameSource> external_begin_frame_source); |
| 434 void InitializeSingleThreaded( | 383 void InitializeSingleThreaded( |
| 435 LayerTreeHostSingleThreadClient* single_thread_client, | 384 LayerTreeHostSingleThreadClient* single_thread_client, |
| 436 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 385 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 463 return gpu_memory_buffer_manager_; | 412 return gpu_memory_buffer_manager_; |
| 464 } | 413 } |
| 465 TaskGraphRunner* task_graph_runner() const { return task_graph_runner_; } | 414 TaskGraphRunner* task_graph_runner() const { return task_graph_runner_; } |
| 466 | 415 |
| 467 MicroBenchmarkController micro_benchmark_controller_; | 416 MicroBenchmarkController micro_benchmark_controller_; |
| 468 | 417 |
| 469 void OnCommitForSwapPromises(); | 418 void OnCommitForSwapPromises(); |
| 470 | 419 |
| 471 void RecordGpuRasterizationHistogram(); | 420 void RecordGpuRasterizationHistogram(); |
| 472 | 421 |
| 422 // Layer tree that hold layers. |
| 423 std::unique_ptr<LayerTree> layer_tree_; |
| 424 |
| 473 private: | 425 private: |
| 474 friend class LayerTreeHostSerializationTest; | 426 friend class LayerTreeHostSerializationTest; |
| 475 | 427 |
| 476 // This is the number of consecutive frames in which we want the content to be | 428 // This is the number of consecutive frames in which we want the content to be |
| 477 // suitable for GPU rasterization before re-enabling it. | 429 // suitable for GPU rasterization before re-enabling it. |
| 478 enum { kNumFramesToConsiderBeforeGpuRasterization = 60 }; | 430 enum { kNumFramesToConsiderBeforeGpuRasterization = 60 }; |
| 479 | 431 |
| 480 void ApplyViewportDeltas(ScrollAndScaleSet* info); | 432 void ApplyViewportDeltas(ScrollAndScaleSet* info); |
| 481 void InitializeProxy( | 433 void InitializeProxy( |
| 482 std::unique_ptr<Proxy> proxy, | 434 std::unique_ptr<Proxy> proxy, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 | 534 |
| 583 ImageSerializationProcessor* image_serialization_processor_; | 535 ImageSerializationProcessor* image_serialization_processor_; |
| 584 std::unique_ptr<EnginePictureCache> engine_picture_cache_; | 536 std::unique_ptr<EnginePictureCache> engine_picture_cache_; |
| 585 std::unique_ptr<ClientPictureCache> client_picture_cache_; | 537 std::unique_ptr<ClientPictureCache> client_picture_cache_; |
| 586 | 538 |
| 587 std::vector<std::unique_ptr<SwapPromise>> swap_promise_list_; | 539 std::vector<std::unique_ptr<SwapPromise>> swap_promise_list_; |
| 588 std::set<SwapPromiseMonitor*> swap_promise_monitor_; | 540 std::set<SwapPromiseMonitor*> swap_promise_monitor_; |
| 589 | 541 |
| 590 PropertyTrees property_trees_; | 542 PropertyTrees property_trees_; |
| 591 | 543 |
| 592 using ElementLayersMap = std::unordered_map<ElementId, Layer*, ElementIdHash>; | |
| 593 ElementLayersMap element_layers_map_; | |
| 594 | |
| 595 uint32_t surface_client_id_; | 544 uint32_t surface_client_id_; |
| 596 uint32_t next_surface_sequence_; | 545 uint32_t next_surface_sequence_; |
| 597 uint32_t num_consecutive_frames_suitable_for_gpu_ = 0; | 546 uint32_t num_consecutive_frames_suitable_for_gpu_ = 0; |
| 598 | 547 |
| 599 // Layer tree that hold layers. | |
| 600 LayerTree layer_tree_; | |
| 601 | |
| 602 DISALLOW_COPY_AND_ASSIGN(LayerTreeHost); | 548 DISALLOW_COPY_AND_ASSIGN(LayerTreeHost); |
| 603 }; | 549 }; |
| 604 | 550 |
| 605 } // namespace cc | 551 } // namespace cc |
| 606 | 552 |
| 607 #endif // CC_TREES_LAYER_TREE_HOST_H_ | 553 #endif // CC_TREES_LAYER_TREE_HOST_H_ |
| OLD | NEW |