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