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