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