| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "cc/trees/proxy_impl.h" | 5 #include "cc/trees/proxy_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 12 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
| 13 #include "base/trace_event/trace_event_synthetic_delay.h" | 14 #include "base/trace_event/trace_event_synthetic_delay.h" |
| 14 #include "cc/animation/animation_events.h" | 15 #include "cc/animation/animation_events.h" |
| 15 #include "cc/debug/benchmark_instrumentation.h" | 16 #include "cc/debug/benchmark_instrumentation.h" |
| 16 #include "cc/debug/devtools_instrumentation.h" | 17 #include "cc/debug/devtools_instrumentation.h" |
| 17 #include "cc/input/top_controls_manager.h" | 18 #include "cc/input/top_controls_manager.h" |
| 18 #include "cc/output/context_provider.h" | 19 #include "cc/output/context_provider.h" |
| 19 #include "cc/output/output_surface.h" | 20 #include "cc/output/output_surface.h" |
| 20 #include "cc/scheduler/compositor_timing_history.h" | 21 #include "cc/scheduler/compositor_timing_history.h" |
| 21 #include "cc/trees/layer_tree_host.h" | 22 #include "cc/trees/layer_tree_host.h" |
| 22 #include "cc/trees/layer_tree_impl.h" | 23 #include "cc/trees/layer_tree_impl.h" |
| 23 #include "cc/trees/task_runner_provider.h" | 24 #include "cc/trees/task_runner_provider.h" |
| 24 #include "gpu/command_buffer/client/gles2_interface.h" | 25 #include "gpu/command_buffer/client/gles2_interface.h" |
| 25 | 26 |
| 26 namespace cc { | 27 namespace cc { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // Measured in seconds. | 31 // Measured in seconds. |
| 31 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; | 32 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; |
| 32 | 33 |
| 33 unsigned int nextBeginFrameId = 0; | 34 unsigned int nextBeginFrameId = 0; |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 scoped_ptr<ProxyImpl> ProxyImpl::Create( | 38 std::unique_ptr<ProxyImpl> ProxyImpl::Create( |
| 38 ChannelImpl* channel_impl, | 39 ChannelImpl* channel_impl, |
| 39 LayerTreeHost* layer_tree_host, | 40 LayerTreeHost* layer_tree_host, |
| 40 TaskRunnerProvider* task_runner_provider, | 41 TaskRunnerProvider* task_runner_provider, |
| 41 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 42 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
| 42 return make_scoped_ptr(new ProxyImpl(channel_impl, layer_tree_host, | 43 return base::WrapUnique( |
| 43 task_runner_provider, | 44 new ProxyImpl(channel_impl, layer_tree_host, task_runner_provider, |
| 44 std::move(external_begin_frame_source))); | 45 std::move(external_begin_frame_source))); |
| 45 } | 46 } |
| 46 | 47 |
| 47 ProxyImpl::ProxyImpl(ChannelImpl* channel_impl, | 48 ProxyImpl::ProxyImpl( |
| 48 LayerTreeHost* layer_tree_host, | 49 ChannelImpl* channel_impl, |
| 49 TaskRunnerProvider* task_runner_provider, | 50 LayerTreeHost* layer_tree_host, |
| 50 scoped_ptr<BeginFrameSource> external_begin_frame_source) | 51 TaskRunnerProvider* task_runner_provider, |
| 52 std::unique_ptr<BeginFrameSource> external_begin_frame_source) |
| 51 : layer_tree_host_id_(layer_tree_host->id()), | 53 : layer_tree_host_id_(layer_tree_host->id()), |
| 52 next_commit_waits_for_activation_(false), | 54 next_commit_waits_for_activation_(false), |
| 53 commit_completion_event_(nullptr), | 55 commit_completion_event_(nullptr), |
| 54 next_frame_is_newly_committed_frame_(false), | 56 next_frame_is_newly_committed_frame_(false), |
| 55 inside_draw_(false), | 57 inside_draw_(false), |
| 56 input_throttled_until_commit_(false), | 58 input_throttled_until_commit_(false), |
| 57 task_runner_provider_(task_runner_provider), | 59 task_runner_provider_(task_runner_provider), |
| 58 smoothness_priority_expiration_notifier_( | 60 smoothness_priority_expiration_notifier_( |
| 59 task_runner_provider->ImplThreadTaskRunner(), | 61 task_runner_provider->ImplThreadTaskRunner(), |
| 60 base::Bind(&ProxyImpl::RenewTreePriority, base::Unretained(this)), | 62 base::Bind(&ProxyImpl::RenewTreePriority, base::Unretained(this)), |
| 61 base::TimeDelta::FromSecondsD( | 63 base::TimeDelta::FromSecondsD( |
| 62 kSmoothnessTakesPriorityExpirationDelay)), | 64 kSmoothnessTakesPriorityExpirationDelay)), |
| 63 external_begin_frame_source_(std::move(external_begin_frame_source)), | 65 external_begin_frame_source_(std::move(external_begin_frame_source)), |
| 64 rendering_stats_instrumentation_( | 66 rendering_stats_instrumentation_( |
| 65 layer_tree_host->rendering_stats_instrumentation()), | 67 layer_tree_host->rendering_stats_instrumentation()), |
| 66 channel_impl_(channel_impl) { | 68 channel_impl_(channel_impl) { |
| 67 TRACE_EVENT0("cc", "ProxyImpl::ProxyImpl"); | 69 TRACE_EVENT0("cc", "ProxyImpl::ProxyImpl"); |
| 68 DCHECK(IsImplThread()); | 70 DCHECK(IsImplThread()); |
| 69 DCHECK(IsMainThreadBlocked()); | 71 DCHECK(IsMainThreadBlocked()); |
| 70 | 72 |
| 71 layer_tree_host_impl_ = layer_tree_host->CreateLayerTreeHostImpl(this); | 73 layer_tree_host_impl_ = layer_tree_host->CreateLayerTreeHostImpl(this); |
| 72 | 74 |
| 73 SchedulerSettings scheduler_settings( | 75 SchedulerSettings scheduler_settings( |
| 74 layer_tree_host->settings().ToSchedulerSettings()); | 76 layer_tree_host->settings().ToSchedulerSettings()); |
| 75 | 77 |
| 76 scoped_ptr<CompositorTimingHistory> compositor_timing_history( | 78 std::unique_ptr<CompositorTimingHistory> compositor_timing_history( |
| 77 new CompositorTimingHistory( | 79 new CompositorTimingHistory( |
| 78 scheduler_settings.using_synchronous_renderer_compositor, | 80 scheduler_settings.using_synchronous_renderer_compositor, |
| 79 CompositorTimingHistory::RENDERER_UMA, | 81 CompositorTimingHistory::RENDERER_UMA, |
| 80 rendering_stats_instrumentation_)); | 82 rendering_stats_instrumentation_)); |
| 81 | 83 |
| 82 BeginFrameSource* frame_source = external_begin_frame_source_.get(); | 84 BeginFrameSource* frame_source = external_begin_frame_source_.get(); |
| 83 if (!scheduler_settings.throttle_frame_production) { | 85 if (!scheduler_settings.throttle_frame_production) { |
| 84 // Unthrottled source takes precedence over external sources. | 86 // Unthrottled source takes precedence over external sources. |
| 85 unthrottled_begin_frame_source_.reset(new BackToBackBeginFrameSource( | 87 unthrottled_begin_frame_source_.reset(new BackToBackBeginFrameSource( |
| 86 task_runner_provider_->ImplThreadTaskRunner())); | 88 task_runner_provider_->ImplThreadTaskRunner())); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 void ProxyImpl::SetVideoNeedsBeginFrames(bool needs_begin_frames) { | 370 void ProxyImpl::SetVideoNeedsBeginFrames(bool needs_begin_frames) { |
| 369 TRACE_EVENT1("cc", "ProxyImpl::SetVideoNeedsBeginFrames", | 371 TRACE_EVENT1("cc", "ProxyImpl::SetVideoNeedsBeginFrames", |
| 370 "needs_begin_frames", needs_begin_frames); | 372 "needs_begin_frames", needs_begin_frames); |
| 371 DCHECK(IsImplThread()); | 373 DCHECK(IsImplThread()); |
| 372 // In tests the layer tree is destroyed after the scheduler is. | 374 // In tests the layer tree is destroyed after the scheduler is. |
| 373 if (scheduler_) | 375 if (scheduler_) |
| 374 scheduler_->SetVideoNeedsBeginFrames(needs_begin_frames); | 376 scheduler_->SetVideoNeedsBeginFrames(needs_begin_frames); |
| 375 } | 377 } |
| 376 | 378 |
| 377 void ProxyImpl::PostAnimationEventsToMainThreadOnImplThread( | 379 void ProxyImpl::PostAnimationEventsToMainThreadOnImplThread( |
| 378 scoped_ptr<AnimationEvents> events) { | 380 std::unique_ptr<AnimationEvents> events) { |
| 379 TRACE_EVENT0("cc", "ProxyImpl::PostAnimationEventsToMainThreadOnImplThread"); | 381 TRACE_EVENT0("cc", "ProxyImpl::PostAnimationEventsToMainThreadOnImplThread"); |
| 380 DCHECK(IsImplThread()); | 382 DCHECK(IsImplThread()); |
| 381 channel_impl_->SetAnimationEvents(std::move(events)); | 383 channel_impl_->SetAnimationEvents(std::move(events)); |
| 382 } | 384 } |
| 383 | 385 |
| 384 bool ProxyImpl::IsInsideDraw() { | 386 bool ProxyImpl::IsInsideDraw() { |
| 385 return inside_draw_; | 387 return inside_draw_; |
| 386 } | 388 } |
| 387 | 389 |
| 388 void ProxyImpl::RenewTreePriority() { | 390 void ProxyImpl::RenewTreePriority() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 DCHECK(IsImplThread()); | 468 DCHECK(IsImplThread()); |
| 467 channel_impl_->DidCompletePageScaleAnimation(); | 469 channel_impl_->DidCompletePageScaleAnimation(); |
| 468 } | 470 } |
| 469 | 471 |
| 470 void ProxyImpl::OnDrawForOutputSurface(bool resourceless_software_draw) { | 472 void ProxyImpl::OnDrawForOutputSurface(bool resourceless_software_draw) { |
| 471 DCHECK(IsImplThread()); | 473 DCHECK(IsImplThread()); |
| 472 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 474 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 473 } | 475 } |
| 474 | 476 |
| 475 void ProxyImpl::PostFrameTimingEventsOnImplThread( | 477 void ProxyImpl::PostFrameTimingEventsOnImplThread( |
| 476 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 478 std::unique_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 477 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 479 std::unique_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 478 DCHECK(IsImplThread()); | 480 DCHECK(IsImplThread()); |
| 479 channel_impl_->PostFrameTimingEventsOnMain(std::move(composite_events), | 481 channel_impl_->PostFrameTimingEventsOnMain(std::move(composite_events), |
| 480 std::move(main_frame_events)); | 482 std::move(main_frame_events)); |
| 481 } | 483 } |
| 482 | 484 |
| 483 void ProxyImpl::WillBeginImplFrame(const BeginFrameArgs& args) { | 485 void ProxyImpl::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 484 DCHECK(IsImplThread()); | 486 DCHECK(IsImplThread()); |
| 485 layer_tree_host_impl_->WillBeginImplFrame(args); | 487 layer_tree_host_impl_->WillBeginImplFrame(args); |
| 486 if (last_processed_begin_main_frame_args_.IsValid()) { | 488 if (last_processed_begin_main_frame_args_.IsValid()) { |
| 487 // Last processed begin main frame args records the frame args that we sent | 489 // Last processed begin main frame args records the frame args that we sent |
| 488 // to the main thread for the last frame that we've processed. If that is | 490 // to the main thread for the last frame that we've processed. If that is |
| 489 // set, that means the current frame is one past the frame in which we've | 491 // set, that means the current frame is one past the frame in which we've |
| 490 // finished the processing. | 492 // finished the processing. |
| 491 layer_tree_host_impl_->RecordMainFrameTiming( | 493 layer_tree_host_impl_->RecordMainFrameTiming( |
| 492 last_processed_begin_main_frame_args_, args); | 494 last_processed_begin_main_frame_args_, args); |
| 493 last_processed_begin_main_frame_args_ = BeginFrameArgs(); | 495 last_processed_begin_main_frame_args_ = BeginFrameArgs(); |
| 494 } | 496 } |
| 495 } | 497 } |
| 496 | 498 |
| 497 void ProxyImpl::DidFinishImplFrame() { | 499 void ProxyImpl::DidFinishImplFrame() { |
| 498 DCHECK(IsImplThread()); | 500 DCHECK(IsImplThread()); |
| 499 layer_tree_host_impl_->DidFinishImplFrame(); | 501 layer_tree_host_impl_->DidFinishImplFrame(); |
| 500 } | 502 } |
| 501 | 503 |
| 502 void ProxyImpl::ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) { | 504 void ProxyImpl::ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) { |
| 503 DCHECK(IsImplThread()); | 505 DCHECK(IsImplThread()); |
| 504 unsigned int begin_frame_id = nextBeginFrameId++; | 506 unsigned int begin_frame_id = nextBeginFrameId++; |
| 505 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( | 507 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( |
| 506 benchmark_instrumentation::kSendBeginFrame, begin_frame_id); | 508 benchmark_instrumentation::kSendBeginFrame, begin_frame_id); |
| 507 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state( | 509 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state( |
| 508 new BeginMainFrameAndCommitState); | 510 new BeginMainFrameAndCommitState); |
| 509 begin_main_frame_state->begin_frame_id = begin_frame_id; | 511 begin_main_frame_state->begin_frame_id = begin_frame_id; |
| 510 begin_main_frame_state->begin_frame_args = args; | 512 begin_main_frame_state->begin_frame_args = args; |
| 511 begin_main_frame_state->scroll_info = | 513 begin_main_frame_state->scroll_info = |
| 512 layer_tree_host_impl_->ProcessScrollDeltas(); | 514 layer_tree_host_impl_->ProcessScrollDeltas(); |
| 513 begin_main_frame_state->memory_allocation_limit_bytes = | 515 begin_main_frame_state->memory_allocation_limit_bytes = |
| 514 layer_tree_host_impl_->memory_allocation_limit_bytes(); | 516 layer_tree_host_impl_->memory_allocation_limit_bytes(); |
| 515 begin_main_frame_state->evicted_ui_resources = | 517 begin_main_frame_state->evicted_ui_resources = |
| 516 layer_tree_host_impl_->EvictedUIResourcesExist(); | 518 layer_tree_host_impl_->EvictedUIResourcesExist(); |
| 517 // TODO(vmpstr): This needs to be fixed if | 519 // TODO(vmpstr): This needs to be fixed if |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 bool ProxyImpl::IsMainThreadBlocked() const { | 682 bool ProxyImpl::IsMainThreadBlocked() const { |
| 681 return task_runner_provider_->IsMainThreadBlocked(); | 683 return task_runner_provider_->IsMainThreadBlocked(); |
| 682 } | 684 } |
| 683 | 685 |
| 684 ProxyImpl::BlockedMainCommitOnly& ProxyImpl::blocked_main_commit() { | 686 ProxyImpl::BlockedMainCommitOnly& ProxyImpl::blocked_main_commit() { |
| 685 DCHECK(IsMainThreadBlocked() && commit_completion_event_); | 687 DCHECK(IsMainThreadBlocked() && commit_completion_event_); |
| 686 return main_thread_blocked_commit_vars_unsafe_; | 688 return main_thread_blocked_commit_vars_unsafe_; |
| 687 } | 689 } |
| 688 | 690 |
| 689 } // namespace cc | 691 } // namespace cc |
| OLD | NEW |