[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 7 | #include "base/auto_reset.h" |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 8 | #include "base/profiler/scoped_tracker.h" |
primiano | c06e238 | 2015-01-28 04:21:49 | [diff] [blame] | 9 | #include "base/trace_event/trace_event.h" |
[email protected] | adbe30f | 2013-10-11 21:12:33 | [diff] [blame] | 10 | #include "cc/debug/benchmark_instrumentation.h" |
caseq | 7d2f4c9 | 2015-02-04 16:43:27 | [diff] [blame] | 11 | #include "cc/debug/devtools_instrumentation.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 12 | #include "cc/output/context_provider.h" |
| 13 | #include "cc/output/output_surface.h" |
[email protected] | 89e8267 | 2013-03-18 07:50:56 | [diff] [blame] | 14 | #include "cc/quads/draw_quad.h" |
mithro | f7a2150 | 2014-12-17 03:24:48 | [diff] [blame] | 15 | #include "cc/scheduler/commit_earlyout_reason.h" |
brianderson | c9f5035 | 2015-06-24 03:38:58 | [diff] [blame] | 16 | #include "cc/scheduler/compositor_timing_history.h" |
| 17 | #include "cc/scheduler/scheduler.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 18 | #include "cc/trees/layer_tree_host.h" |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 19 | #include "cc/trees/layer_tree_host_single_thread_client.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 20 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 21 | #include "cc/trees/scoped_abort_remaining_swap_promises.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 22 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 23 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 24 | |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 25 | scoped_ptr<Proxy> SingleThreadProxy::Create( |
| 26 | LayerTreeHost* layer_tree_host, |
[email protected] | 27e6a21 | 2014-07-18 15:51:27 | [diff] [blame] | 27 | LayerTreeHostSingleThreadClient* client, |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 28 | TaskRunnerProvider* task_runner_provider, |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 29 | scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 30 | return make_scoped_ptr( |
| 31 | new SingleThreadProxy(layer_tree_host, client, task_runner_provider, |
| 32 | external_begin_frame_source.Pass())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 33 | } |
| 34 | |
[email protected] | 27e6a21 | 2014-07-18 15:51:27 | [diff] [blame] | 35 | SingleThreadProxy::SingleThreadProxy( |
| 36 | LayerTreeHost* layer_tree_host, |
| 37 | LayerTreeHostSingleThreadClient* client, |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 38 | TaskRunnerProvider* task_runner_provider, |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 39 | scoped_ptr<BeginFrameSource> external_begin_frame_source) |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 40 | : layer_tree_host_(layer_tree_host), |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 41 | client_(client), |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 42 | task_runner_provider_(task_runner_provider), |
sunnyps | f381ede | 2015-06-23 01:46:53 | [diff] [blame] | 43 | external_begin_frame_source_(external_begin_frame_source.Pass()), |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 44 | next_frame_is_newly_committed_frame_(false), |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 45 | #if DCHECK_IS_ON() |
mithro | 69fd3bb5 | 2015-05-01 03:45:02 | [diff] [blame] | 46 | inside_impl_frame_(false), |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 47 | #endif |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 48 | inside_draw_(false), |
| 49 | defer_commits_(false), |
brianderson | 49e101d2 | 2015-04-29 00:05:33 | [diff] [blame] | 50 | animate_requested_(false), |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 51 | commit_requested_(false), |
jbauman | 399aec1a | 2014-10-25 02:33:32 | [diff] [blame] | 52 | inside_synchronous_composite_(false), |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 53 | output_surface_creation_requested_(false), |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 54 | weak_factory_(this) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 55 | TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 56 | DCHECK(task_runner_provider_); |
| 57 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 58 | DCHECK(layer_tree_host); |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 59 | |
| 60 | if (layer_tree_host->settings().single_thread_proxy_scheduler && |
| 61 | !scheduler_on_impl_thread_) { |
| 62 | SchedulerSettings scheduler_settings( |
| 63 | layer_tree_host->settings().ToSchedulerSettings()); |
danakj | 5f2e92de | 2015-06-20 00:25:58 | [diff] [blame] | 64 | scheduler_settings.commit_to_active_tree = CommitToActiveTree(); |
brianderson | c9f5035 | 2015-06-24 03:38:58 | [diff] [blame] | 65 | |
| 66 | scoped_ptr<CompositorTimingHistory> compositor_timing_history( |
| 67 | new CompositorTimingHistory( |
brianderson | c68220f | 2015-07-20 20:08:35 | [diff] [blame] | 68 | CompositorTimingHistory::BROWSER_UMA, |
brianderson | c9f5035 | 2015-06-24 03:38:58 | [diff] [blame] | 69 | layer_tree_host->rendering_stats_instrumentation())); |
| 70 | |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 71 | scheduler_on_impl_thread_ = Scheduler::Create( |
| 72 | this, scheduler_settings, layer_tree_host_->id(), |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 73 | task_runner_provider_->MainThreadTaskRunner(), |
| 74 | external_begin_frame_source_.get(), compositor_timing_history.Pass()); |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 75 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | e96e343 | 2013-12-19 18:56:07 | [diff] [blame] | 78 | void SingleThreadProxy::Start() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 79 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 80 | layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | SingleThreadProxy::~SingleThreadProxy() { |
| 84 | TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 85 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 86 | // Make sure Stop() got called or never Started. |
| 87 | DCHECK(!layer_tree_host_impl_); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 88 | } |
| 89 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 90 | void SingleThreadProxy::FinishAllRendering() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 91 | TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 92 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 93 | { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 94 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 95 | layer_tree_host_impl_->FinishAllRendering(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 96 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 97 | } |
| 98 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 99 | bool SingleThreadProxy::IsStarted() const { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 100 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | 3209161d | 2013-03-29 19:17:34 | [diff] [blame] | 101 | return layer_tree_host_impl_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 102 | } |
| 103 | |
danakj | 009cdfdf | 2015-02-17 22:35:14 | [diff] [blame] | 104 | bool SingleThreadProxy::CommitToActiveTree() const { |
| 105 | // With SingleThreadProxy we skip the pending tree and commit directly to the |
| 106 | // active tree. |
| 107 | return true; |
| 108 | } |
| 109 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 110 | void SingleThreadProxy::SetVisible(bool visible) { |
mithro | 46adf5a | 2014-11-19 14:52:40 | [diff] [blame] | 111 | TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 112 | DebugScopedSetImplThread impl(task_runner_provider_); |
sunnyps | c3f6e0c | 2015-07-25 01:00:59 | [diff] [blame] | 113 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 114 | layer_tree_host_impl_->SetVisible(visible); |
sunnyps | c3f6e0c | 2015-07-25 01:00:59 | [diff] [blame] | 115 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 116 | if (scheduler_on_impl_thread_) |
| 117 | scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 118 | } |
| 119 | |
bajones | 27411061 | 2015-01-06 20:53:59 | [diff] [blame] | 120 | void SingleThreadProxy::SetThrottleFrameProduction(bool throttle) { |
| 121 | TRACE_EVENT1("cc", "SingleThreadProxy::SetThrottleFrameProduction", |
| 122 | "throttle", throttle); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 123 | DebugScopedSetImplThread impl(task_runner_provider_); |
bajones | 27411061 | 2015-01-06 20:53:59 | [diff] [blame] | 124 | if (scheduler_on_impl_thread_) |
| 125 | scheduler_on_impl_thread_->SetThrottleFrameProduction(throttle); |
| 126 | } |
| 127 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 128 | void SingleThreadProxy::RequestNewOutputSurface() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 129 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | 497edf8 | 2014-05-20 21:53:15 | [diff] [blame] | 130 | DCHECK(layer_tree_host_->output_surface_lost()); |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 131 | output_surface_creation_callback_.Cancel(); |
| 132 | if (output_surface_creation_requested_) |
| 133 | return; |
| 134 | output_surface_creation_requested_ = true; |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 135 | layer_tree_host_->RequestNewOutputSurface(); |
| 136 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 137 | |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 138 | void SingleThreadProxy::ReleaseOutputSurface() { |
sievers | e83e41d | 2015-09-18 23:33:26 | [diff] [blame] | 139 | // |layer_tree_host_| should already be aware of this. |
| 140 | DCHECK(layer_tree_host_->output_surface_lost()); |
| 141 | |
sohan.jyoti | 3a33d87 | 2015-09-18 22:32:55 | [diff] [blame] | 142 | if (scheduler_on_impl_thread_) |
| 143 | scheduler_on_impl_thread_->DidLoseOutputSurface(); |
| 144 | return layer_tree_host_impl_->ReleaseOutputSurface(); |
| 145 | } |
| 146 | |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 147 | void SingleThreadProxy::SetOutputSurface(OutputSurface* output_surface) { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 148 | DCHECK(task_runner_provider_->IsMainThread()); |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 149 | DCHECK(layer_tree_host_->output_surface_lost()); |
enne | 5232fbb | 2015-01-27 21:22:41 | [diff] [blame] | 150 | DCHECK(output_surface_creation_requested_); |
[email protected] | da8e3b72b | 2014-04-25 02:33:45 | [diff] [blame] | 151 | renderer_capabilities_for_main_thread_ = RendererCapabilities(); |
| 152 | |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 153 | bool success; |
| 154 | { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 155 | DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 156 | DebugScopedSetImplThread impl(task_runner_provider_); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 157 | success = layer_tree_host_impl_->InitializeRenderer(output_surface); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 160 | if (success) { |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 161 | layer_tree_host_->DidInitializeOutputSurface(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 162 | if (scheduler_on_impl_thread_) |
| 163 | scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); |
jbauman | 399aec1a | 2014-10-25 02:33:32 | [diff] [blame] | 164 | else if (!inside_synchronous_composite_) |
| 165 | SetNeedsCommit(); |
enne | 5232fbb | 2015-01-27 21:22:41 | [diff] [blame] | 166 | output_surface_creation_requested_ = false; |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 167 | } else { |
enne | 5232fbb | 2015-01-27 21:22:41 | [diff] [blame] | 168 | // DidFailToInitializeOutputSurface is treated as a RequestNewOutputSurface, |
| 169 | // and so output_surface_creation_requested remains true. |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 170 | layer_tree_host_->DidFailToInitializeOutputSurface(); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 171 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 172 | } |
| 173 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 174 | const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 175 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 176 | DCHECK(!layer_tree_host_->output_surface_lost()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 177 | return renderer_capabilities_for_main_thread_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 180 | void SingleThreadProxy::SetNeedsAnimate() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 181 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 182 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | 06cbc31b | 2014-01-17 06:43:20 | [diff] [blame] | 183 | client_->ScheduleAnimation(); |
brianderson | 49e101d2 | 2015-04-29 00:05:33 | [diff] [blame] | 184 | if (animate_requested_) |
| 185 | return; |
| 186 | animate_requested_ = true; |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 187 | DebugScopedSetImplThread impl(task_runner_provider_); |
brianderson | 49e101d2 | 2015-04-29 00:05:33 | [diff] [blame] | 188 | if (scheduler_on_impl_thread_) |
mithro | e77254b3 | 2015-07-22 09:36:01 | [diff] [blame] | 189 | scheduler_on_impl_thread_->SetNeedsBeginMainFrame(); |
[email protected] | c513417 | 2013-12-11 06:19:48 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 192 | void SingleThreadProxy::SetNeedsUpdateLayers() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 193 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 194 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 195 | SetNeedsCommit(); |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 196 | } |
| 197 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 198 | void SingleThreadProxy::DoCommit() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 199 | TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 200 | DCHECK(task_runner_provider_->IsMainThread()); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 201 | |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 202 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is |
| 203 | // fixed. |
| 204 | tracked_objects::ScopedTracker tracking_profile1( |
| 205 | FROM_HERE_WITH_EXPLICIT_FUNCTION("461509 SingleThreadProxy::DoCommit1")); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 206 | layer_tree_host_->WillCommit(); |
caseq | 7d2f4c9 | 2015-02-04 16:43:27 | [diff] [blame] | 207 | devtools_instrumentation::ScopedCommitTrace commit_task( |
| 208 | layer_tree_host_->id()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 209 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 210 | // Commit immediately. |
| 211 | { |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 212 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 213 | // is fixed. |
| 214 | tracked_objects::ScopedTracker tracking_profile2( |
| 215 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 216 | "461509 SingleThreadProxy::DoCommit2")); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 217 | DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 218 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | f7c01c8 | 2013-07-02 22:58:46 | [diff] [blame] | 219 | |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 220 | // This CapturePostTasks should be destroyed before CommitComplete() is |
| 221 | // called since that goes out to the embedder, and we want the embedder |
| 222 | // to receive its callbacks before that. |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 223 | commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks( |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 224 | task_runner_provider_->blocking_main_thread_task_runner())); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 225 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 226 | layer_tree_host_impl_->BeginCommit(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 227 | |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 228 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 229 | // is fixed. |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 230 | tracked_objects::ScopedTracker tracking_profile6( |
| 231 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 232 | "461509 SingleThreadProxy::DoCommit6")); |
[email protected] | 127bdc1a | 2013-09-11 01:44:48 | [diff] [blame] | 233 | if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 234 | layer_tree_host_->RecreateUIResources(); |
| 235 | |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 236 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 237 | // is fixed. |
| 238 | tracked_objects::ScopedTracker tracking_profile7( |
| 239 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 240 | "461509 SingleThreadProxy::DoCommit7")); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 241 | layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 242 | |
danakj | e649f57 | 2015-01-08 23:35:58 | [diff] [blame] | 243 | #if DCHECK_IS_ON() |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 244 | // In the single-threaded case, the scale and scroll deltas should never be |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 245 | // touched on the impl layer tree. |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 246 | scoped_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 247 | layer_tree_host_impl_->ProcessScrollDeltas(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 248 | DCHECK(!scroll_info->scrolls.size()); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 249 | DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 250 | #endif |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 251 | |
danakj | 3c3973b | 2015-08-25 21:50:18 | [diff] [blame] | 252 | if (scheduler_on_impl_thread_) |
| 253 | scheduler_on_impl_thread_->DidCommit(); |
| 254 | |
| 255 | layer_tree_host_impl_->CommitComplete(); |
| 256 | |
danakj | 68803fc | 2015-06-19 20:55:53 | [diff] [blame] | 257 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 258 | // is fixed. |
| 259 | tracked_objects::ScopedTracker tracking_profile8( |
| 260 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 261 | "461509 SingleThreadProxy::DoCommit8")); |
| 262 | // Commit goes directly to the active tree, but we need to synchronously |
| 263 | // "activate" the tree still during commit to satisfy any potential |
| 264 | // SetNextCommitWaitsForActivation calls. Unfortunately, the tree |
| 265 | // might not be ready to draw, so DidActivateSyncTree must set |
| 266 | // the flag to force the tree to not draw until textures are ready. |
| 267 | NotifyReadyToActivate(); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
| 271 | void SingleThreadProxy::CommitComplete() { |
danakj | 3c3973b | 2015-08-25 21:50:18 | [diff] [blame] | 272 | // Commit complete happens on the main side after activate to satisfy any |
| 273 | // SetNextCommitWaitsForActivation calls. |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 274 | DCHECK(!layer_tree_host_impl_->pending_tree()) |
| 275 | << "Activation is expected to have synchronously occurred by now."; |
| 276 | DCHECK(commit_blocking_task_runner_); |
| 277 | |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 278 | DebugScopedSetMainThread main(task_runner_provider_); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 279 | commit_blocking_task_runner_.reset(); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 280 | layer_tree_host_->CommitComplete(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 281 | layer_tree_host_->DidBeginMainFrame(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 282 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 283 | next_frame_is_newly_committed_frame_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 286 | void SingleThreadProxy::SetNeedsCommit() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 287 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 288 | client_->ScheduleComposite(); |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 289 | if (commit_requested_) |
| 290 | return; |
brianderson | 49e101d2 | 2015-04-29 00:05:33 | [diff] [blame] | 291 | commit_requested_ = true; |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 292 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 293 | if (scheduler_on_impl_thread_) |
mithro | e77254b3 | 2015-07-22 09:36:01 | [diff] [blame] | 294 | scheduler_on_impl_thread_->SetNeedsBeginMainFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 297 | void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 298 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 299 | DCHECK(task_runner_provider_->IsMainThread()); |
| 300 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame] | 301 | client_->ScheduleComposite(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 302 | SetNeedsRedrawRectOnImplThread(damage_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 303 | } |
| 304 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 305 | void SingleThreadProxy::SetNextCommitWaitsForActivation() { |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 306 | // Activation always forced in commit, so nothing to do. |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 307 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 308 | } |
| 309 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 310 | void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 311 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 312 | // Deferring commits only makes sense if there's a scheduler. |
| 313 | if (!scheduler_on_impl_thread_) |
| 314 | return; |
| 315 | if (defer_commits_ == defer_commits) |
| 316 | return; |
| 317 | |
| 318 | if (defer_commits) |
| 319 | TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this); |
| 320 | else |
| 321 | TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this); |
| 322 | |
| 323 | defer_commits_ = defer_commits; |
simonhong | c6309f79 | 2015-01-31 15:47:15 | [diff] [blame] | 324 | scheduler_on_impl_thread_->SetDeferCommits(defer_commits); |
[email protected] | 6b16679e | 2012-10-27 00:44:28 | [diff] [blame] | 325 | } |
| 326 | |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 327 | bool SingleThreadProxy::CommitRequested() const { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 328 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 329 | return commit_requested_; |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 330 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 331 | |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 332 | bool SingleThreadProxy::BeginMainFrameRequested() const { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 333 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 334 | // If there is no scheduler, then there can be no pending begin frame, |
| 335 | // as all frames are all manually initiated by the embedder of cc. |
| 336 | if (!scheduler_on_impl_thread_) |
| 337 | return false; |
| 338 | return commit_requested_; |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 339 | } |
[email protected] | 971728d | 2013-10-26 10:39:31 | [diff] [blame] | 340 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 341 | void SingleThreadProxy::Stop() { |
| 342 | TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 343 | DCHECK(task_runner_provider_->IsMainThread()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 344 | { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 345 | DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 346 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 347 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 348 | BlockingTaskRunner::CapturePostTasks blocked( |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 349 | task_runner_provider_->blocking_main_thread_task_runner()); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 350 | scheduler_on_impl_thread_ = nullptr; |
| 351 | layer_tree_host_impl_ = nullptr; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 352 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 353 | layer_tree_host_ = NULL; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 354 | } |
| 355 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 356 | void SingleThreadProxy::OnResourcelessSoftareDrawStateChanged( |
| 357 | bool resourceless_draw) { |
| 358 | NOTREACHED(); |
| 359 | } |
| 360 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 361 | void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 362 | TRACE_EVENT1( |
| 363 | "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 364 | DCHECK(task_runner_provider_->IsImplThread()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 365 | if (scheduler_on_impl_thread_) |
| 366 | scheduler_on_impl_thread_->SetCanDraw(can_draw); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 369 | void SingleThreadProxy::NotifyReadyToActivate() { |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 370 | TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 371 | DebugScopedSetImplThread impl(task_runner_provider_); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 372 | if (scheduler_on_impl_thread_) |
| 373 | scheduler_on_impl_thread_->NotifyReadyToActivate(); |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 374 | } |
| 375 | |
ernstm | dfac03e | 2014-11-11 20:18:05 | [diff] [blame] | 376 | void SingleThreadProxy::NotifyReadyToDraw() { |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 377 | TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToDraw"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 378 | DebugScopedSetImplThread impl(task_runner_provider_); |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 379 | if (scheduler_on_impl_thread_) |
| 380 | scheduler_on_impl_thread_->NotifyReadyToDraw(); |
ernstm | dfac03e | 2014-11-11 20:18:05 | [diff] [blame] | 381 | } |
| 382 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 383 | void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 384 | client_->ScheduleComposite(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 385 | if (scheduler_on_impl_thread_) |
| 386 | scheduler_on_impl_thread_->SetNeedsRedraw(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 389 | void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
mithro | 719bf679 | 2014-11-10 15:36:47 | [diff] [blame] | 390 | client_->ScheduleComposite(); |
| 391 | if (scheduler_on_impl_thread_) |
| 392 | scheduler_on_impl_thread_->SetNeedsAnimate(); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 393 | } |
| 394 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 395 | void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() { |
| 396 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread"); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 397 | if (scheduler_on_impl_thread_) |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 398 | scheduler_on_impl_thread_->SetNeedsPrepareTiles(); |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 399 | } |
| 400 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 401 | void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
| 402 | const gfx::Rect& damage_rect) { |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 403 | layer_tree_host_impl_->SetViewportDamage(damage_rect); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 404 | SetNeedsRedrawOnImplThread(); |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 405 | } |
| 406 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 407 | void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 408 | client_->ScheduleComposite(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 409 | if (scheduler_on_impl_thread_) |
mithro | e77254b3 | 2015-07-22 09:36:01 | [diff] [blame] | 410 | scheduler_on_impl_thread_->SetNeedsBeginMainFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 411 | } |
| 412 | |
sunnyps | 7d073dc | 2015-04-16 23:29:12 | [diff] [blame] | 413 | void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) { |
| 414 | TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames", |
| 415 | "needs_begin_frames", needs_begin_frames); |
| 416 | // In tests the layer tree is destroyed after the scheduler is. |
| 417 | if (scheduler_on_impl_thread_) |
| 418 | scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames); |
| 419 | } |
| 420 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 421 | void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
[email protected] | 85b5750 | 2014-03-11 15:37:48 | [diff] [blame] | 422 | scoped_ptr<AnimationEventsVector> events) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 423 | TRACE_EVENT0( |
| 424 | "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 425 | DCHECK(task_runner_provider_->IsImplThread()); |
| 426 | DebugScopedSetMainThread main(task_runner_provider_); |
[email protected] | 85b5750 | 2014-03-11 15:37:48 | [diff] [blame] | 427 | layer_tree_host_->SetAnimationEvents(events.Pass()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 430 | bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 431 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 432 | void SingleThreadProxy::DidActivateSyncTree() { |
danakj | 68803fc | 2015-06-19 20:55:53 | [diff] [blame] | 433 | // Synchronously call to CommitComplete. Resetting |
| 434 | // |commit_blocking_task_runner| would make sure all tasks posted during |
| 435 | // commit/activation before CommitComplete. |
| 436 | CommitComplete(); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 437 | } |
| 438 | |
brianderson | 6874981 | 2015-07-07 22:39:39 | [diff] [blame] | 439 | void SingleThreadProxy::WillPrepareTiles() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 440 | DCHECK(task_runner_provider_->IsImplThread()); |
brianderson | 6874981 | 2015-07-07 22:39:39 | [diff] [blame] | 441 | if (scheduler_on_impl_thread_) |
| 442 | scheduler_on_impl_thread_->WillPrepareTiles(); |
| 443 | } |
| 444 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 445 | void SingleThreadProxy::DidPrepareTiles() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 446 | DCHECK(task_runner_provider_->IsImplThread()); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 447 | if (scheduler_on_impl_thread_) |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 448 | scheduler_on_impl_thread_->DidPrepareTiles(); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 449 | } |
| 450 | |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 451 | void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() { |
| 452 | layer_tree_host_->DidCompletePageScaleAnimation(); |
| 453 | } |
| 454 | |
[email protected] | fa33903 | 2014-02-18 22:11:59 | [diff] [blame] | 455 | void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 456 | DCHECK(task_runner_provider_->IsImplThread()); |
[email protected] | fa33903 | 2014-02-18 22:11:59 | [diff] [blame] | 457 | renderer_capabilities_for_main_thread_ = |
| 458 | layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
| 459 | } |
| 460 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 461 | void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 462 | TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 463 | { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 464 | DebugScopedSetMainThread main(task_runner_provider_); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 465 | // This must happen before we notify the scheduler as it may try to recreate |
| 466 | // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. |
| 467 | layer_tree_host_->DidLoseOutputSurface(); |
| 468 | } |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 469 | client_->DidAbortSwapBuffers(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 470 | if (scheduler_on_impl_thread_) |
| 471 | scheduler_on_impl_thread_->DidLoseOutputSurface(); |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 472 | } |
| 473 | |
weiliangc | af17af4 | 2014-12-15 22:17:02 | [diff] [blame] | 474 | void SingleThreadProxy::CommitVSyncParameters(base::TimeTicks timebase, |
| 475 | base::TimeDelta interval) { |
| 476 | if (scheduler_on_impl_thread_) |
| 477 | scheduler_on_impl_thread_->CommitVSyncParameters(timebase, interval); |
| 478 | } |
| 479 | |
jbauman | 93a5a90 | 2015-03-13 22:16:55 | [diff] [blame] | 480 | void SingleThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { |
| 481 | if (scheduler_on_impl_thread_) |
| 482 | scheduler_on_impl_thread_->SetEstimatedParentDrawTime(draw_time); |
| 483 | } |
| 484 | |
alexst | 346f30c | 2015-03-25 13:24:05 | [diff] [blame] | 485 | void SingleThreadProxy::SetMaxSwapsPendingOnImplThread(int max) { |
| 486 | if (scheduler_on_impl_thread_) |
| 487 | scheduler_on_impl_thread_->SetMaxSwapsPending(max); |
| 488 | } |
| 489 | |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 490 | void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 491 | TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); |
| 492 | if (scheduler_on_impl_thread_) |
| 493 | scheduler_on_impl_thread_->DidSwapBuffers(); |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 494 | client_->DidPostSwapBuffers(); |
| 495 | } |
| 496 | |
[email protected] | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 497 | void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
miletus | fed8c43b | 2015-01-26 20:04:52 | [diff] [blame] | 498 | TRACE_EVENT0("cc,benchmark", |
| 499 | "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 500 | if (scheduler_on_impl_thread_) |
| 501 | scheduler_on_impl_thread_->DidSwapBuffersComplete(); |
| 502 | layer_tree_host_->DidCompleteSwapBuffers(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 503 | } |
| 504 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 505 | void SingleThreadProxy::OnDrawForOutputSurface() { |
| 506 | NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor."; |
| 507 | } |
| 508 | |
mpb | ed24c2c | 2015-06-05 20:57:13 | [diff] [blame] | 509 | void SingleThreadProxy::PostFrameTimingEventsOnImplThread( |
| 510 | scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 511 | scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 512 | layer_tree_host_->RecordFrameTimingEvents(composite_events.Pass(), |
| 513 | main_frame_events.Pass()); |
| 514 | } |
| 515 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 516 | void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
miletus | fed8c43b | 2015-01-26 20:04:52 | [diff] [blame] | 517 | TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 518 | DCHECK(task_runner_provider_->IsMainThread()); |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 519 | #if DCHECK_IS_ON() |
mithro | c76d7031 | 2015-05-04 23:51:13 | [diff] [blame] | 520 | DCHECK(!inside_impl_frame_); |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 521 | #endif |
jbauman | 399aec1a | 2014-10-25 02:33:32 | [diff] [blame] | 522 | base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true); |
| 523 | |
| 524 | if (layer_tree_host_->output_surface_lost()) { |
| 525 | RequestNewOutputSurface(); |
| 526 | // RequestNewOutputSurface could have synchronously created an output |
| 527 | // surface, so check again before returning. |
| 528 | if (layer_tree_host_->output_surface_lost()) |
| 529 | return; |
| 530 | } |
[email protected] | 51f81da | 2014-05-16 21:29:26 | [diff] [blame] | 531 | |
mithro | c76d7031 | 2015-05-04 23:51:13 | [diff] [blame] | 532 | BeginFrameArgs begin_frame_args(BeginFrameArgs::Create( |
| 533 | BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(), |
| 534 | BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL)); |
| 535 | |
| 536 | // Start the impl frame. |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 537 | { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 538 | DebugScopedSetImplThread impl(task_runner_provider_); |
mithro | c76d7031 | 2015-05-04 23:51:13 | [diff] [blame] | 539 | WillBeginImplFrame(begin_frame_args); |
| 540 | } |
| 541 | |
| 542 | // Run the "main thread" and get it to commit. |
| 543 | { |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 544 | #if DCHECK_IS_ON() |
mithro | c76d7031 | 2015-05-04 23:51:13 | [diff] [blame] | 545 | DCHECK(inside_impl_frame_); |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 546 | #endif |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 547 | DoBeginMainFrame(begin_frame_args); |
| 548 | DoCommit(); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 549 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 550 | DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises()) |
| 551 | << "Commit should always succeed and transfer promises."; |
| 552 | } |
| 553 | |
mithro | c76d7031 | 2015-05-04 23:51:13 | [diff] [blame] | 554 | // Finish the impl frame. |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 555 | { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 556 | DebugScopedSetImplThread impl(task_runner_provider_); |
danakj | 68803fc | 2015-06-19 20:55:53 | [diff] [blame] | 557 | layer_tree_host_impl_->ActivateSyncTree(); |
| 558 | DCHECK( |
| 559 | !layer_tree_host_impl_->active_tree()->needs_update_draw_properties()); |
| 560 | layer_tree_host_impl_->PrepareTiles(); |
| 561 | layer_tree_host_impl_->SynchronouslyInitializeAllTiles(); |
enne | 69277cb | 2014-10-29 23:03:40 | [diff] [blame] | 562 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 563 | // TODO(danakj): Don't do this last... we prepared the wrong things. D: |
| 564 | layer_tree_host_impl_->Animate(); |
mithro | 719bf679 | 2014-11-10 15:36:47 | [diff] [blame] | 565 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 566 | LayerTreeHostImpl::FrameData frame; |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 567 | DoComposite(&frame); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 568 | |
| 569 | // DoComposite could abort, but because this is a synchronous composite |
| 570 | // another draw will never be scheduled, so break remaining promises. |
| 571 | layer_tree_host_impl_->active_tree()->BreakSwapPromises( |
| 572 | SwapPromise::SWAP_FAILS); |
mithro | c76d7031 | 2015-05-04 23:51:13 | [diff] [blame] | 573 | |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 574 | DidFinishImplFrame(); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 575 | } |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 576 | } |
| 577 | |
[email protected] | 5d8bec7 | 2014-07-03 03:03:11 | [diff] [blame] | 578 | bool SingleThreadProxy::SupportsImplScrolling() const { |
| 579 | return false; |
| 580 | } |
| 581 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 582 | bool SingleThreadProxy::ShouldComposite() const { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 583 | DCHECK(task_runner_provider_->IsImplThread()); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 584 | return layer_tree_host_impl_->visible() && |
| 585 | layer_tree_host_impl_->CanDraw(); |
| 586 | } |
| 587 | |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 588 | void SingleThreadProxy::ScheduleRequestNewOutputSurface() { |
| 589 | if (output_surface_creation_callback_.IsCancelled() && |
| 590 | !output_surface_creation_requested_) { |
| 591 | output_surface_creation_callback_.Reset( |
| 592 | base::Bind(&SingleThreadProxy::RequestNewOutputSurface, |
| 593 | weak_factory_.GetWeakPtr())); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 594 | task_runner_provider_->MainThreadTaskRunner()->PostTask( |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 595 | FROM_HERE, output_surface_creation_callback_.callback()); |
| 596 | } |
| 597 | } |
| 598 | |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 599 | DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 600 | TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 601 | DCHECK(!layer_tree_host_->output_surface_lost()); |
| 602 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 603 | DrawResult draw_result; |
| 604 | bool draw_frame; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 605 | { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 606 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 607 | base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 608 | |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 609 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 610 | // is fixed. |
| 611 | tracked_objects::ScopedTracker tracking_profile1( |
| 612 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 613 | "461509 SingleThreadProxy::DoComposite1")); |
| 614 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 615 | // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 616 | // frame, so can only be used when such a frame is possible. Since |
| 617 | // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 618 | // CanDraw() as well. |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 619 | if (!ShouldComposite()) { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 620 | return DRAW_ABORTED_CANT_DRAW; |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 621 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 622 | |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 623 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 624 | // is fixed. |
| 625 | tracked_objects::ScopedTracker tracking_profile2( |
| 626 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 627 | "461509 SingleThreadProxy::DoComposite2")); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 628 | draw_result = layer_tree_host_impl_->PrepareToDraw(frame); |
| 629 | draw_frame = draw_result == DRAW_SUCCESS; |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 630 | if (draw_frame) { |
| 631 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 632 | // is fixed. |
| 633 | tracked_objects::ScopedTracker tracking_profile3( |
| 634 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 635 | "461509 SingleThreadProxy::DoComposite3")); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 636 | layer_tree_host_impl_->DrawLayers(frame); |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 637 | } |
| 638 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 639 | // is fixed. |
| 640 | tracked_objects::ScopedTracker tracking_profile4( |
| 641 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 642 | "461509 SingleThreadProxy::DoComposite4")); |
dneto | b71e30c | 2014-08-25 23:27:20 | [diff] [blame] | 643 | layer_tree_host_impl_->DidDrawAllLayers(*frame); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 644 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 645 | bool start_ready_animations = draw_frame; |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 646 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 647 | // is fixed. |
| 648 | tracked_objects::ScopedTracker tracking_profile5( |
| 649 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 650 | "461509 SingleThreadProxy::DoComposite5")); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 651 | layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 652 | |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 653 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 654 | // is fixed. |
| 655 | tracked_objects::ScopedTracker tracking_profile7( |
| 656 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 657 | "461509 SingleThreadProxy::DoComposite7")); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 658 | } |
| 659 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 660 | if (draw_frame) { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 661 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 662 | |
dneto | b71e30c | 2014-08-25 23:27:20 | [diff] [blame] | 663 | // This CapturePostTasks should be destroyed before |
| 664 | // DidCommitAndDrawFrame() is called since that goes out to the |
| 665 | // embedder, |
| 666 | // and we want the embedder to receive its callbacks before that. |
| 667 | // NOTE: This maintains consistent ordering with the ThreadProxy since |
| 668 | // the DidCommitAndDrawFrame() must be post-tasked from the impl thread |
| 669 | // there as the main thread is not blocked, so any posted tasks inside |
| 670 | // the swap buffers will execute first. |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 671 | DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 672 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 673 | BlockingTaskRunner::CapturePostTasks blocked( |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 674 | task_runner_provider_->blocking_main_thread_task_runner()); |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 675 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 676 | // is fixed. |
| 677 | tracked_objects::ScopedTracker tracking_profile8( |
| 678 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 679 | "461509 SingleThreadProxy::DoComposite8")); |
dneto | b71e30c | 2014-08-25 23:27:20 | [diff] [blame] | 680 | layer_tree_host_impl_->SwapBuffers(*frame); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 681 | } |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 682 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is |
| 683 | // fixed. |
| 684 | tracked_objects::ScopedTracker tracking_profile9( |
| 685 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 686 | "461509 SingleThreadProxy::DoComposite9")); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 687 | DidCommitAndDrawFrame(); |
| 688 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 689 | return draw_result; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 690 | } |
| 691 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 692 | void SingleThreadProxy::DidCommitAndDrawFrame() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 693 | if (next_frame_is_newly_committed_frame_) { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 694 | DebugScopedSetMainThread main(task_runner_provider_); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 695 | next_frame_is_newly_committed_frame_ = false; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 696 | layer_tree_host_->DidCommitAndDrawFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | |
[email protected] | 4ea293f7 | 2014-08-13 03:03:17 | [diff] [blame] | 700 | bool SingleThreadProxy::MainFrameWillHappenForTesting() { |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 701 | if (layer_tree_host_->output_surface_lost()) |
| 702 | return false; |
| 703 | if (!scheduler_on_impl_thread_) |
| 704 | return false; |
| 705 | return scheduler_on_impl_thread_->MainFrameForTestingWillHappen(); |
[email protected] | 4ea293f7 | 2014-08-13 03:03:17 | [diff] [blame] | 706 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 707 | |
simonhong | d3d5f7f | 2014-11-21 16:38:03 | [diff] [blame] | 708 | void SingleThreadProxy::SetChildrenNeedBeginFrames( |
| 709 | bool children_need_begin_frames) { |
| 710 | scheduler_on_impl_thread_->SetChildrenNeedBeginFrames( |
| 711 | children_need_begin_frames); |
| 712 | } |
| 713 | |
simonhong | 298590fe | 2015-03-25 06:51:13 | [diff] [blame] | 714 | void SingleThreadProxy::SetAuthoritativeVSyncInterval( |
| 715 | const base::TimeDelta& interval) { |
| 716 | scheduler_on_impl_thread_->SetAuthoritativeVSyncInterval(interval); |
| 717 | } |
| 718 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 719 | void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 720 | #if DCHECK_IS_ON() |
mithro | 69fd3bb5 | 2015-05-01 03:45:02 | [diff] [blame] | 721 | DCHECK(!inside_impl_frame_) |
| 722 | << "WillBeginImplFrame called while already inside an impl frame!"; |
| 723 | inside_impl_frame_ = true; |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 724 | #endif |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 725 | layer_tree_host_impl_->WillBeginImplFrame(args); |
| 726 | } |
| 727 | |
| 728 | void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { |
| 729 | TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); |
| 730 | // Although this proxy is single-threaded, it's problematic to synchronously |
| 731 | // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This |
| 732 | // could cause a commit to occur in between a series of SetNeedsCommit calls |
| 733 | // (i.e. property modifications) causing some to fall on one frame and some to |
| 734 | // fall on the next. Doing it asynchronously instead matches the semantics of |
| 735 | // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a |
| 736 | // synchronous commit. |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 737 | #if DCHECK_IS_ON() |
mithro | 69fd3bb5 | 2015-05-01 03:45:02 | [diff] [blame] | 738 | DCHECK(inside_impl_frame_) |
| 739 | << "BeginMainFrame should only be sent inside a BeginImplFrame"; |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 740 | #endif |
mithro | 69fd3bb5 | 2015-05-01 03:45:02 | [diff] [blame] | 741 | const BeginFrameArgs& begin_frame_args = |
| 742 | layer_tree_host_impl_->CurrentBeginFrameArgs(); |
| 743 | |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 744 | task_runner_provider_->MainThreadTaskRunner()->PostTask( |
mithro | 69fd3bb5 | 2015-05-01 03:45:02 | [diff] [blame] | 745 | FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame, |
| 746 | weak_factory_.GetWeakPtr(), begin_frame_args)); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 747 | } |
| 748 | |
rmcilroy | 0a19362a | 2015-02-18 12:34:25 | [diff] [blame] | 749 | void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() { |
| 750 | layer_tree_host_->BeginMainFrameNotExpectedSoon(); |
| 751 | } |
| 752 | |
mithro | 69fd3bb5 | 2015-05-01 03:45:02 | [diff] [blame] | 753 | void SingleThreadProxy::BeginMainFrame(const BeginFrameArgs& begin_frame_args) { |
brianderson | 21aef16 | 2015-11-11 05:12:23 | [diff] [blame] | 754 | if (scheduler_on_impl_thread_) { |
| 755 | scheduler_on_impl_thread_->NotifyBeginMainFrameStarted( |
| 756 | base::TimeTicks::Now()); |
| 757 | } |
| 758 | |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 759 | commit_requested_ = false; |
brianderson | 49e101d2 | 2015-04-29 00:05:33 | [diff] [blame] | 760 | animate_requested_ = false; |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 761 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 762 | if (defer_commits_) { |
simonhong | c6309f79 | 2015-01-31 15:47:15 | [diff] [blame] | 763 | TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", |
| 764 | TRACE_EVENT_SCOPE_THREAD); |
| 765 | BeginMainFrameAbortedOnImplThread( |
| 766 | CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 767 | return; |
| 768 | } |
| 769 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 770 | // This checker assumes NotifyReadyToCommit in this stack causes a synchronous |
| 771 | // commit. |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 772 | ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); |
| 773 | |
| 774 | if (!layer_tree_host_->visible()) { |
| 775 | TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
mithro | f7a2150 | 2014-12-17 03:24:48 | [diff] [blame] | 776 | BeginMainFrameAbortedOnImplThread( |
| 777 | CommitEarlyOutReason::ABORTED_NOT_VISIBLE); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 778 | return; |
| 779 | } |
| 780 | |
| 781 | if (layer_tree_host_->output_surface_lost()) { |
| 782 | TRACE_EVENT_INSTANT0( |
| 783 | "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); |
mithro | f7a2150 | 2014-12-17 03:24:48 | [diff] [blame] | 784 | BeginMainFrameAbortedOnImplThread( |
| 785 | CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 786 | return; |
| 787 | } |
| 788 | |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 789 | // Prevent new commits from being requested inside DoBeginMainFrame. |
brianderson | 49e101d2 | 2015-04-29 00:05:33 | [diff] [blame] | 790 | // Note: We do not want to prevent SetNeedsAnimate from requesting |
| 791 | // a commit here. |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 792 | commit_requested_ = true; |
| 793 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 794 | DoBeginMainFrame(begin_frame_args); |
| 795 | } |
| 796 | |
| 797 | void SingleThreadProxy::DoBeginMainFrame( |
| 798 | const BeginFrameArgs& begin_frame_args) { |
| 799 | layer_tree_host_->WillBeginMainFrame(); |
| 800 | layer_tree_host_->BeginMainFrame(begin_frame_args); |
| 801 | layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); |
wkorman | 7265db01 | 2015-11-03 04:08:25 | [diff] [blame] | 802 | layer_tree_host_->RequestMainFrameUpdate(); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 803 | |
danakj | fcdaba12 | 2015-04-24 21:41:52 | [diff] [blame] | 804 | // New commits requested inside UpdateLayers should be respected. |
| 805 | commit_requested_ = false; |
| 806 | |
danakj | 5f46636a | 2015-06-19 00:01:40 | [diff] [blame] | 807 | layer_tree_host_->UpdateLayers(); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 808 | |
mithro | f7a2150 | 2014-12-17 03:24:48 | [diff] [blame] | 809 | // TODO(enne): SingleThreadProxy does not support cancelling commits yet, |
| 810 | // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside |
| 811 | // thread_proxy.cc |
brianderson | 21aef16 | 2015-11-11 05:12:23 | [diff] [blame] | 812 | if (scheduler_on_impl_thread_) |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 813 | scheduler_on_impl_thread_->NotifyReadyToCommit(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 814 | } |
| 815 | |
mithro | f7a2150 | 2014-12-17 03:24:48 | [diff] [blame] | 816 | void SingleThreadProxy::BeginMainFrameAbortedOnImplThread( |
| 817 | CommitEarlyOutReason reason) { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 818 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 819 | DCHECK(scheduler_on_impl_thread_->CommitPending()); |
| 820 | DCHECK(!layer_tree_host_impl_->pending_tree()); |
| 821 | |
mithro | f7a2150 | 2014-12-17 03:24:48 | [diff] [blame] | 822 | layer_tree_host_impl_->BeginMainFrameAborted(reason); |
| 823 | scheduler_on_impl_thread_->BeginMainFrameAborted(reason); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 827 | DebugScopedSetImplThread impl(task_runner_provider_); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 828 | LayerTreeHostImpl::FrameData frame; |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 829 | return DoComposite(&frame); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { |
| 833 | NOTREACHED(); |
| 834 | return INVALID_RESULT; |
| 835 | } |
| 836 | |
| 837 | void SingleThreadProxy::ScheduledActionCommit() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 838 | DebugScopedSetMainThread main(task_runner_provider_); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 839 | DoCommit(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | void SingleThreadProxy::ScheduledActionAnimate() { |
| 843 | TRACE_EVENT0("cc", "ScheduledActionAnimate"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 844 | DebugScopedSetImplThread impl(task_runner_provider_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 845 | layer_tree_host_impl_->Animate(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 846 | } |
| 847 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 848 | void SingleThreadProxy::ScheduledActionActivateSyncTree() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 849 | DebugScopedSetImplThread impl(task_runner_provider_); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 850 | layer_tree_host_impl_->ActivateSyncTree(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 854 | DebugScopedSetMainThread main(task_runner_provider_); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 855 | DCHECK(scheduler_on_impl_thread_); |
| 856 | // If possible, create the output surface in a post task. Synchronously |
| 857 | // creating the output surface makes tests more awkward since this differs |
| 858 | // from the ThreadProxy behavior. However, sometimes there is no |
| 859 | // task runner. |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 860 | if (task_runner_provider_->MainThreadTaskRunner()) { |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 861 | ScheduleRequestNewOutputSurface(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 862 | } else { |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 863 | RequestNewOutputSurface(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 864 | } |
| 865 | } |
| 866 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 867 | void SingleThreadProxy::ScheduledActionPrepareTiles() { |
| 868 | TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles"); |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame^] | 869 | DebugScopedSetImplThread impl(task_runner_provider_); |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 870 | layer_tree_host_impl_->PrepareTiles(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 871 | } |
| 872 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 873 | void SingleThreadProxy::ScheduledActionInvalidateOutputSurface() { |
| 874 | NOTREACHED(); |
| 875 | } |
| 876 | |
khushalsagar | c646cd6 | 2015-10-17 00:05:48 | [diff] [blame] | 877 | void SingleThreadProxy::UpdateTopControlsState(TopControlsState constraints, |
| 878 | TopControlsState current, |
| 879 | bool animate) { |
| 880 | NOTREACHED() << "Top Controls are used only in threaded mode"; |
| 881 | } |
| 882 | |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 883 | void SingleThreadProxy::DidFinishImplFrame() { |
| 884 | layer_tree_host_impl_->DidFinishImplFrame(); |
| 885 | #if DCHECK_IS_ON() |
mithro | 69fd3bb5 | 2015-05-01 03:45:02 | [diff] [blame] | 886 | DCHECK(inside_impl_frame_) |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 887 | << "DidFinishImplFrame called while not inside an impl frame!"; |
mithro | 69fd3bb5 | 2015-05-01 03:45:02 | [diff] [blame] | 888 | inside_impl_frame_ = false; |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 889 | #endif |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 890 | } |
| 891 | |
simonhong | d3d5f7f | 2014-11-21 16:38:03 | [diff] [blame] | 892 | void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 893 | layer_tree_host_->SendBeginFramesToChildren(args); |
| 894 | } |
| 895 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 896 | } // namespace cc |