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