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