[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" |
[email protected] | 6331a117 | 2012-10-18 11:35:13 | [diff] [blame] | 8 | #include "base/debug/trace_event.h" |
[email protected] | adbe30f | 2013-10-11 21:12:33 | [diff] [blame] | 9 | #include "cc/debug/benchmark_instrumentation.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 10 | #include "cc/output/context_provider.h" |
| 11 | #include "cc/output/output_surface.h" |
[email protected] | 89e8267 | 2013-03-18 07:50:56 | [diff] [blame] | 12 | #include "cc/quads/draw_quad.h" |
[email protected] | e12dd0e | 2013-03-18 08:24:40 | [diff] [blame] | 13 | #include "cc/resources/prioritized_resource_manager.h" |
| 14 | #include "cc/resources/resource_update_controller.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 15 | #include "cc/trees/layer_tree_host.h" |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 16 | #include "cc/trees/layer_tree_host_single_thread_client.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 17 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 18 | #include "cc/trees/scoped_abort_remaining_swap_promises.h" |
[email protected] | de2cf8c | 2013-10-25 19:46:46 | [diff] [blame] | 19 | #include "ui/gfx/frame_time.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 20 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 21 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 22 | |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 23 | scoped_ptr<Proxy> SingleThreadProxy::Create( |
| 24 | LayerTreeHost* layer_tree_host, |
[email protected] | 27e6a21 | 2014-07-18 15:51:27 | [diff] [blame] | 25 | LayerTreeHostSingleThreadClient* client, |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 26 | scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 27 | scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 28 | return make_scoped_ptr(new SingleThreadProxy( |
| 29 | layer_tree_host, |
| 30 | client, |
| 31 | main_task_runner, |
| 32 | external_begin_frame_source.Pass())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 33 | } |
| 34 | |
[email protected] | 27e6a21 | 2014-07-18 15:51:27 | [diff] [blame] | 35 | SingleThreadProxy::SingleThreadProxy( |
| 36 | LayerTreeHost* layer_tree_host, |
| 37 | LayerTreeHostSingleThreadClient* client, |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 38 | scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 39 | scoped_ptr<BeginFrameSource> external_begin_frame_source) |
[email protected] | 27e6a21 | 2014-07-18 15:51:27 | [diff] [blame] | 40 | : Proxy(main_task_runner, NULL), |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 41 | layer_tree_host_(layer_tree_host), |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 42 | client_(client), |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 43 | timing_history_(layer_tree_host->rendering_stats_instrumentation()), |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 44 | next_frame_is_newly_committed_frame_(false), |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 45 | inside_draw_(false), |
| 46 | defer_commits_(false), |
| 47 | commit_was_deferred_(false), |
| 48 | commit_requested_(false), |
jbauman | 399aec1a | 2014-10-25 02:33:32 | [diff] [blame] | 49 | inside_synchronous_composite_(false), |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 50 | output_surface_creation_requested_(false), |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 51 | external_begin_frame_source_(external_begin_frame_source.Pass()), |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 52 | weak_factory_(this) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 53 | TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 54 | DCHECK(Proxy::IsMainThread()); |
| 55 | DCHECK(layer_tree_host); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | e96e343 | 2013-12-19 18:56:07 | [diff] [blame] | 58 | void SingleThreadProxy::Start() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 59 | DebugScopedSetImplThread impl(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 60 | layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | SingleThreadProxy::~SingleThreadProxy() { |
| 64 | TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| 65 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 66 | // Make sure Stop() got called or never Started. |
| 67 | DCHECK(!layer_tree_host_impl_); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 70 | void SingleThreadProxy::FinishAllRendering() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 71 | TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 72 | DCHECK(Proxy::IsMainThread()); |
| 73 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 74 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 75 | layer_tree_host_impl_->FinishAllRendering(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 76 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 77 | } |
| 78 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 79 | bool SingleThreadProxy::IsStarted() const { |
| 80 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 3209161d | 2013-03-29 19:17:34 | [diff] [blame] | 81 | return layer_tree_host_impl_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 14bd554 | 2013-05-08 21:51:30 | [diff] [blame] | 84 | void SingleThreadProxy::SetLayerTreeHostClientReady() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 85 | TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 86 | // Scheduling is controlled by the embedder in the single thread case, so |
| 87 | // nothing to do. |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 88 | DCHECK(Proxy::IsMainThread()); |
| 89 | DebugScopedSetImplThread impl(this); |
| 90 | if (layer_tree_host_->settings().single_thread_proxy_scheduler && |
| 91 | !scheduler_on_impl_thread_) { |
| 92 | SchedulerSettings scheduler_settings(layer_tree_host_->settings()); |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 93 | scheduler_on_impl_thread_ = |
| 94 | Scheduler::Create(this, |
| 95 | scheduler_settings, |
| 96 | layer_tree_host_->id(), |
| 97 | MainThreadTaskRunner(), |
| 98 | base::PowerMonitor::Get(), |
| 99 | external_begin_frame_source_.Pass()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 100 | scheduler_on_impl_thread_->SetCanStart(); |
| 101 | scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
| 102 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void SingleThreadProxy::SetVisible(bool visible) { |
mithro | 46adf5a | 2014-11-19 14:52:40 | [diff] [blame] | 106 | TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible); |
[email protected] | f7c01c8 | 2013-07-02 22:58:46 | [diff] [blame] | 107 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 108 | layer_tree_host_impl_->SetVisible(visible); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 109 | if (scheduler_on_impl_thread_) |
| 110 | scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
[email protected] | 8ea875b | 2013-08-07 00:32:12 | [diff] [blame] | 111 | // Changing visibility could change ShouldComposite(). |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 112 | } |
| 113 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 114 | void SingleThreadProxy::RequestNewOutputSurface() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 115 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 497edf8 | 2014-05-20 21:53:15 | [diff] [blame] | 116 | DCHECK(layer_tree_host_->output_surface_lost()); |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 117 | output_surface_creation_callback_.Cancel(); |
| 118 | if (output_surface_creation_requested_) |
| 119 | return; |
| 120 | output_surface_creation_requested_ = true; |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 121 | layer_tree_host_->RequestNewOutputSurface(); |
| 122 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 123 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 124 | void SingleThreadProxy::SetOutputSurface( |
| 125 | scoped_ptr<OutputSurface> output_surface) { |
| 126 | DCHECK(Proxy::IsMainThread()); |
| 127 | DCHECK(layer_tree_host_->output_surface_lost()); |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 128 | output_surface_creation_requested_ = false; |
[email protected] | da8e3b72b | 2014-04-25 02:33:45 | [diff] [blame] | 129 | renderer_capabilities_for_main_thread_ = RendererCapabilities(); |
| 130 | |
| 131 | bool success = !!output_surface; |
| 132 | if (success) { |
[email protected] | 819b9f5 | 2013-09-22 23:29:51 | [diff] [blame] | 133 | DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 134 | DebugScopedSetImplThread impl(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 135 | layer_tree_host_->DeleteContentsTexturesOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 136 | layer_tree_host_impl_->resource_provider()); |
[email protected] | da8e3b72b | 2014-04-25 02:33:45 | [diff] [blame] | 137 | success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 138 | } |
| 139 | |
[email protected] | da8e3b72b | 2014-04-25 02:33:45 | [diff] [blame] | 140 | layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 141 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 142 | if (success) { |
| 143 | if (scheduler_on_impl_thread_) |
| 144 | scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); |
jbauman | 399aec1a | 2014-10-25 02:33:32 | [diff] [blame] | 145 | else if (!inside_synchronous_composite_) |
| 146 | SetNeedsCommit(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 147 | } else if (Proxy::MainThreadTaskRunner()) { |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 148 | ScheduleRequestNewOutputSurface(); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 149 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 152 | const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 153 | DCHECK(Proxy::IsMainThread()); |
| 154 | DCHECK(!layer_tree_host_->output_surface_lost()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 155 | return renderer_capabilities_for_main_thread_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 158 | void SingleThreadProxy::SetNeedsAnimate() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 159 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); |
[email protected] | c513417 | 2013-12-11 06:19:48 | [diff] [blame] | 160 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 06cbc31b | 2014-01-17 06:43:20 | [diff] [blame] | 161 | client_->ScheduleAnimation(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 162 | SetNeedsCommit(); |
[email protected] | c513417 | 2013-12-11 06:19:48 | [diff] [blame] | 163 | } |
| 164 | |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 165 | void SingleThreadProxy::SetNeedsUpdateLayers() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 166 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 167 | DCHECK(Proxy::IsMainThread()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 168 | SetNeedsCommit(); |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 169 | } |
| 170 | |
mithro | 719bf679 | 2014-11-10 15:36:47 | [diff] [blame] | 171 | void SingleThreadProxy::DoAnimate() { |
| 172 | // Don't animate if there is no root layer. |
| 173 | // TODO(mithro): Both Animate and UpdateAnimationState already have a |
| 174 | // "!active_tree_->root_layer()" check? |
| 175 | if (!layer_tree_host_impl_->active_tree()->root_layer()) { |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | layer_tree_host_impl_->Animate( |
| 180 | layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); |
| 181 | |
| 182 | // If animations are not visible, update the animation state now as it |
| 183 | // won't happen in DoComposite. |
| 184 | if (!layer_tree_host_impl_->AnimationsAreVisible()) { |
| 185 | layer_tree_host_impl_->UpdateAnimationState(true); |
| 186 | } |
| 187 | } |
| 188 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 189 | void SingleThreadProxy::DoCommit() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 190 | TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 191 | DCHECK(Proxy::IsMainThread()); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 192 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 193 | commit_requested_ = false; |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 194 | layer_tree_host_->WillCommit(); |
| 195 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 196 | // Commit immediately. |
| 197 | { |
[email protected] | 819b9f5 | 2013-09-22 23:29:51 | [diff] [blame] | 198 | DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
[email protected] | f7c01c8 | 2013-07-02 22:58:46 | [diff] [blame] | 199 | DebugScopedSetImplThread impl(this); |
| 200 | |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 201 | // This CapturePostTasks should be destroyed before CommitComplete() is |
| 202 | // called since that goes out to the embedder, and we want the embedder |
| 203 | // to receive its callbacks before that. |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 204 | commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks( |
| 205 | blocking_main_thread_task_runner())); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 206 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 207 | layer_tree_host_impl_->BeginCommit(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 208 | |
[email protected] | 5d2fec0 | 2013-11-28 20:08:33 | [diff] [blame] | 209 | if (PrioritizedResourceManager* contents_texture_manager = |
| 210 | layer_tree_host_->contents_texture_manager()) { |
| 211 | contents_texture_manager->PushTexturePrioritiesToBackings(); |
[email protected] | 6e8c5492 | 2013-06-02 19:17:35 | [diff] [blame] | 212 | } |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 213 | layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 214 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 215 | scoped_ptr<ResourceUpdateController> update_controller = |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 216 | ResourceUpdateController::Create( |
| 217 | NULL, |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 218 | MainThreadTaskRunner(), |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 219 | queue_for_commit_.Pass(), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 220 | layer_tree_host_impl_->resource_provider()); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 221 | update_controller->Finalize(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 222 | |
[email protected] | 127bdc1a | 2013-09-11 01:44:48 | [diff] [blame] | 223 | if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 224 | layer_tree_host_->RecreateUIResources(); |
| 225 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 226 | layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 227 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 228 | layer_tree_host_impl_->CommitComplete(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 229 | |
[email protected] | 767f38d7 | 2014-03-18 21:26:41 | [diff] [blame] | 230 | #if DCHECK_IS_ON |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 231 | // In the single-threaded case, the scale and scroll deltas should never be |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 232 | // touched on the impl layer tree. |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 233 | scoped_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 234 | layer_tree_host_impl_->ProcessScrollDeltas(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 235 | DCHECK(!scroll_info->scrolls.size()); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 236 | DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 237 | #endif |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 238 | } |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 239 | |
| 240 | if (layer_tree_host_->settings().impl_side_painting) { |
| 241 | // TODO(enne): just commit directly to the active tree. |
| 242 | // |
| 243 | // Synchronously activate during commit to satisfy any potential |
| 244 | // SetNextCommitWaitsForActivation calls. Unfortunately, the tree |
| 245 | // might not be ready to draw, so DidActivateSyncTree must set |
| 246 | // the flag to force the tree to not draw until textures are ready. |
| 247 | NotifyReadyToActivate(); |
| 248 | } else { |
| 249 | CommitComplete(); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void SingleThreadProxy::CommitComplete() { |
| 254 | DCHECK(!layer_tree_host_impl_->pending_tree()) |
| 255 | << "Activation is expected to have synchronously occurred by now."; |
| 256 | DCHECK(commit_blocking_task_runner_); |
| 257 | |
| 258 | DebugScopedSetMainThread main(this); |
| 259 | commit_blocking_task_runner_.reset(); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 260 | layer_tree_host_->CommitComplete(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 261 | layer_tree_host_->DidBeginMainFrame(); |
| 262 | timing_history_.DidCommit(); |
| 263 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 264 | next_frame_is_newly_committed_frame_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 267 | void SingleThreadProxy::SetNeedsCommit() { |
| 268 | DCHECK(Proxy::IsMainThread()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 269 | DebugScopedSetImplThread impl(this); |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 270 | client_->ScheduleComposite(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 271 | if (scheduler_on_impl_thread_) |
| 272 | scheduler_on_impl_thread_->SetNeedsCommit(); |
| 273 | commit_requested_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 276 | void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 277 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 278 | DCHECK(Proxy::IsMainThread()); |
| 279 | DebugScopedSetImplThread impl(this); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame] | 280 | client_->ScheduleComposite(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 281 | SetNeedsRedrawRectOnImplThread(damage_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 282 | } |
| 283 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 284 | void SingleThreadProxy::SetNextCommitWaitsForActivation() { |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 285 | // Activation always forced in commit, so nothing to do. |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 286 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 289 | void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 290 | DCHECK(Proxy::IsMainThread()); |
| 291 | // Deferring commits only makes sense if there's a scheduler. |
| 292 | if (!scheduler_on_impl_thread_) |
| 293 | return; |
| 294 | if (defer_commits_ == defer_commits) |
| 295 | return; |
| 296 | |
| 297 | if (defer_commits) |
| 298 | TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this); |
| 299 | else |
| 300 | TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this); |
| 301 | |
| 302 | defer_commits_ = defer_commits; |
| 303 | if (!defer_commits_ && commit_was_deferred_) { |
| 304 | commit_was_deferred_ = false; |
| 305 | BeginMainFrame(); |
| 306 | } |
[email protected] | 6b16679e | 2012-10-27 00:44:28 | [diff] [blame] | 307 | } |
| 308 | |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 309 | bool SingleThreadProxy::CommitRequested() const { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 310 | DCHECK(Proxy::IsMainThread()); |
| 311 | return commit_requested_; |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 312 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 313 | |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 314 | bool SingleThreadProxy::BeginMainFrameRequested() const { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 315 | DCHECK(Proxy::IsMainThread()); |
| 316 | // If there is no scheduler, then there can be no pending begin frame, |
| 317 | // as all frames are all manually initiated by the embedder of cc. |
| 318 | if (!scheduler_on_impl_thread_) |
| 319 | return false; |
| 320 | return commit_requested_; |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 321 | } |
[email protected] | 971728d | 2013-10-26 10:39:31 | [diff] [blame] | 322 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 323 | size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
| 324 | return std::numeric_limits<size_t>::max(); |
| 325 | } |
| 326 | |
| 327 | void SingleThreadProxy::Stop() { |
| 328 | TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
| 329 | DCHECK(Proxy::IsMainThread()); |
| 330 | { |
[email protected] | 819b9f5 | 2013-09-22 23:29:51 | [diff] [blame] | 331 | DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 332 | DebugScopedSetImplThread impl(this); |
| 333 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 334 | BlockingTaskRunner::CapturePostTasks blocked( |
| 335 | blocking_main_thread_task_runner()); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 336 | layer_tree_host_->DeleteContentsTexturesOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 337 | layer_tree_host_impl_->resource_provider()); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 338 | scheduler_on_impl_thread_ = nullptr; |
| 339 | layer_tree_host_impl_ = nullptr; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 340 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 341 | layer_tree_host_ = NULL; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 342 | } |
| 343 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 344 | void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 345 | TRACE_EVENT1( |
| 346 | "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 347 | DCHECK(Proxy::IsImplThread()); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 348 | if (scheduler_on_impl_thread_) |
| 349 | scheduler_on_impl_thread_->SetCanDraw(can_draw); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 350 | } |
| 351 | |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 352 | void SingleThreadProxy::NotifyReadyToActivate() { |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 353 | TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate"); |
| 354 | DebugScopedSetImplThread impl(this); |
| 355 | if (scheduler_on_impl_thread_) |
| 356 | scheduler_on_impl_thread_->NotifyReadyToActivate(); |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 357 | } |
| 358 | |
ernstm | dfac03e | 2014-11-11 20:18:05 | [diff] [blame] | 359 | void SingleThreadProxy::NotifyReadyToDraw() { |
| 360 | } |
| 361 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 362 | void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 363 | client_->ScheduleComposite(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 364 | if (scheduler_on_impl_thread_) |
| 365 | scheduler_on_impl_thread_->SetNeedsRedraw(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 366 | } |
| 367 | |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 368 | void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
mithro | 719bf679 | 2014-11-10 15:36:47 | [diff] [blame] | 369 | client_->ScheduleComposite(); |
| 370 | if (scheduler_on_impl_thread_) |
| 371 | scheduler_on_impl_thread_->SetNeedsAnimate(); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 374 | void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 375 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsManageTilesOnImplThread"); |
| 376 | if (scheduler_on_impl_thread_) |
| 377 | scheduler_on_impl_thread_->SetNeedsManageTiles(); |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 378 | } |
| 379 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 380 | void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
| 381 | const gfx::Rect& damage_rect) { |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 382 | layer_tree_host_impl_->SetViewportDamage(damage_rect); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 383 | SetNeedsRedrawOnImplThread(); |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 384 | } |
| 385 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 386 | void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 387 | client_->ScheduleComposite(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 388 | if (scheduler_on_impl_thread_) |
| 389 | scheduler_on_impl_thread_->SetNeedsCommit(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 390 | } |
| 391 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 392 | void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
[email protected] | 85b5750 | 2014-03-11 15:37:48 | [diff] [blame] | 393 | scoped_ptr<AnimationEventsVector> events) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 394 | TRACE_EVENT0( |
| 395 | "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 396 | DCHECK(Proxy::IsImplThread()); |
| 397 | DebugScopedSetMainThread main(this); |
[email protected] | 85b5750 | 2014-03-11 15:37:48 | [diff] [blame] | 398 | layer_tree_host_->SetAnimationEvents(events.Pass()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 399 | } |
| 400 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 401 | bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 402 | size_t limit_bytes, |
| 403 | int priority_cutoff) { |
| 404 | DCHECK(IsImplThread()); |
[email protected] | 5d2fec0 | 2013-11-28 20:08:33 | [diff] [blame] | 405 | PrioritizedResourceManager* contents_texture_manager = |
| 406 | layer_tree_host_->contents_texture_manager(); |
| 407 | |
| 408 | ResourceProvider* resource_provider = |
| 409 | layer_tree_host_impl_->resource_provider(); |
| 410 | |
| 411 | if (!contents_texture_manager || !resource_provider) |
[email protected] | e7595ead | 2013-10-10 10:10:07 | [diff] [blame] | 412 | return false; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 413 | |
[email protected] | 5d2fec0 | 2013-11-28 20:08:33 | [diff] [blame] | 414 | return contents_texture_manager->ReduceMemoryOnImplThread( |
| 415 | limit_bytes, priority_cutoff, resource_provider); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 418 | bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 419 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 420 | void SingleThreadProxy::DidActivateSyncTree() { |
| 421 | // Non-impl-side painting finishes commit in DoCommit. Impl-side painting |
| 422 | // defers until here to simulate SetNextCommitWaitsForActivation. |
| 423 | if (layer_tree_host_impl_->settings().impl_side_painting) { |
| 424 | // This is required because NotifyReadyToActivate gets called when |
| 425 | // the pending tree is not actually ready in the SingleThreadProxy. |
| 426 | layer_tree_host_impl_->SetRequiresHighResToDraw(); |
| 427 | |
| 428 | // Since activation could cause tasks to run, post CommitComplete |
| 429 | // separately so that it runs after these tasks. This is the loose |
| 430 | // equivalent of blocking commit until activation and also running |
| 431 | // all tasks posted during commit/activation before CommitComplete. |
| 432 | MainThreadTaskRunner()->PostTask( |
| 433 | FROM_HERE, |
| 434 | base::Bind(&SingleThreadProxy::CommitComplete, |
| 435 | weak_factory_.GetWeakPtr())); |
| 436 | } |
| 437 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 438 | timing_history_.DidActivateSyncTree(); |
| 439 | } |
| 440 | |
| 441 | void SingleThreadProxy::DidManageTiles() { |
| 442 | DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
| 443 | DCHECK(Proxy::IsImplThread()); |
| 444 | if (scheduler_on_impl_thread_) |
| 445 | scheduler_on_impl_thread_->DidManageTiles(); |
| 446 | } |
| 447 | |
[email protected] | fa33903 | 2014-02-18 22:11:59 | [diff] [blame] | 448 | void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
| 449 | DCHECK(IsImplThread()); |
| 450 | renderer_capabilities_for_main_thread_ = |
| 451 | layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
| 452 | } |
| 453 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 454 | void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 455 | TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 456 | { |
| 457 | DebugScopedSetMainThread main(this); |
| 458 | // This must happen before we notify the scheduler as it may try to recreate |
| 459 | // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. |
| 460 | layer_tree_host_->DidLoseOutputSurface(); |
| 461 | } |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 462 | client_->DidAbortSwapBuffers(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 463 | if (scheduler_on_impl_thread_) |
| 464 | scheduler_on_impl_thread_->DidLoseOutputSurface(); |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 468 | TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); |
| 469 | if (scheduler_on_impl_thread_) |
| 470 | scheduler_on_impl_thread_->DidSwapBuffers(); |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 471 | client_->DidPostSwapBuffers(); |
| 472 | } |
| 473 | |
[email protected] | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 474 | void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
| 475 | TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 476 | if (scheduler_on_impl_thread_) |
| 477 | scheduler_on_impl_thread_->DidSwapBuffersComplete(); |
| 478 | layer_tree_host_->DidCompleteSwapBuffers(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 481 | void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 482 | TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); |
[email protected] | 51f81da | 2014-05-16 21:29:26 | [diff] [blame] | 483 | DCHECK(Proxy::IsMainThread()); |
jbauman | 399aec1a | 2014-10-25 02:33:32 | [diff] [blame] | 484 | base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true); |
| 485 | |
| 486 | if (layer_tree_host_->output_surface_lost()) { |
| 487 | RequestNewOutputSurface(); |
| 488 | // RequestNewOutputSurface could have synchronously created an output |
| 489 | // surface, so check again before returning. |
| 490 | if (layer_tree_host_->output_surface_lost()) |
| 491 | return; |
| 492 | } |
[email protected] | 51f81da | 2014-05-16 21:29:26 | [diff] [blame] | 493 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 494 | { |
mithro | bfa0ec0 | 2014-11-21 15:13:49 | [diff] [blame] | 495 | BeginFrameArgs begin_frame_args(BeginFrameArgs::Create( |
mithro | 06d1f3bf | 2014-12-02 02:19:15 | [diff] [blame^] | 496 | BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(), |
| 497 | BeginFrameArgs::DefaultInterval(), BeginFrameArgs::SYNCHRONOUS)); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 498 | DoBeginMainFrame(begin_frame_args); |
| 499 | DoCommit(); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 500 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 501 | DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises()) |
| 502 | << "Commit should always succeed and transfer promises."; |
| 503 | } |
| 504 | |
| 505 | { |
| 506 | DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
enne | 69277cb | 2014-10-29 23:03:40 | [diff] [blame] | 507 | if (layer_tree_host_impl_->settings().impl_side_painting) { |
| 508 | layer_tree_host_impl_->ActivateSyncTree(); |
| 509 | layer_tree_host_impl_->active_tree()->UpdateDrawProperties(); |
| 510 | layer_tree_host_impl_->ManageTiles(); |
| 511 | layer_tree_host_impl_->SynchronouslyInitializeAllTiles(); |
| 512 | } |
| 513 | |
mithro | 719bf679 | 2014-11-10 15:36:47 | [diff] [blame] | 514 | DoAnimate(); |
| 515 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 516 | LayerTreeHostImpl::FrameData frame; |
| 517 | DoComposite(frame_begin_time, &frame); |
| 518 | |
| 519 | // DoComposite could abort, but because this is a synchronous composite |
| 520 | // another draw will never be scheduled, so break remaining promises. |
| 521 | layer_tree_host_impl_->active_tree()->BreakSwapPromises( |
| 522 | SwapPromise::SWAP_FAILS); |
| 523 | } |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 524 | } |
| 525 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 526 | void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const { |
| 527 | // The following line casts away const modifiers because it is just |
| 528 | // setting debug state. We still want the AsValue() function and its |
| 529 | // call chain to be const throughout. |
| 530 | DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 531 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 532 | state->BeginDictionary("layer_tree_host_impl"); |
| 533 | layer_tree_host_impl_->AsValueInto(state); |
| 534 | state->EndDictionary(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 535 | } |
| 536 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 537 | void SingleThreadProxy::ForceSerializeOnSwapBuffers() { |
| 538 | { |
| 539 | DebugScopedSetImplThread impl(this); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 540 | if (layer_tree_host_impl_->renderer()) { |
| 541 | DCHECK(!layer_tree_host_->output_surface_lost()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 542 | layer_tree_host_impl_->renderer()->DoNoOp(); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 543 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 544 | } |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 545 | } |
| 546 | |
[email protected] | 5d8bec7 | 2014-07-03 03:03:11 | [diff] [blame] | 547 | bool SingleThreadProxy::SupportsImplScrolling() const { |
| 548 | return false; |
| 549 | } |
| 550 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 551 | bool SingleThreadProxy::ShouldComposite() const { |
| 552 | DCHECK(Proxy::IsImplThread()); |
| 553 | return layer_tree_host_impl_->visible() && |
| 554 | layer_tree_host_impl_->CanDraw(); |
| 555 | } |
| 556 | |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 557 | void SingleThreadProxy::ScheduleRequestNewOutputSurface() { |
| 558 | if (output_surface_creation_callback_.IsCancelled() && |
| 559 | !output_surface_creation_requested_) { |
| 560 | output_surface_creation_callback_.Reset( |
| 561 | base::Bind(&SingleThreadProxy::RequestNewOutputSurface, |
| 562 | weak_factory_.GetWeakPtr())); |
| 563 | MainThreadTaskRunner()->PostTask( |
| 564 | FROM_HERE, output_surface_creation_callback_.callback()); |
| 565 | } |
| 566 | } |
| 567 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 568 | DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
| 569 | LayerTreeHostImpl::FrameData* frame) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 570 | TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 571 | DCHECK(!layer_tree_host_->output_surface_lost()); |
| 572 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 573 | DrawResult draw_result; |
| 574 | bool draw_frame; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 575 | { |
| 576 | DebugScopedSetImplThread impl(this); |
| 577 | base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 578 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 579 | // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 580 | // frame, so can only be used when such a frame is possible. Since |
| 581 | // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 582 | // CanDraw() as well. |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 583 | if (!ShouldComposite()) { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 584 | return DRAW_ABORTED_CANT_DRAW; |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 585 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 586 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 587 | timing_history_.DidStartDrawing(); |
| 588 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 589 | draw_result = layer_tree_host_impl_->PrepareToDraw(frame); |
| 590 | draw_frame = draw_result == DRAW_SUCCESS; |
| 591 | if (draw_frame) |
| 592 | layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
dneto | b71e30c | 2014-08-25 23:27:20 | [diff] [blame] | 593 | layer_tree_host_impl_->DidDrawAllLayers(*frame); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 594 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 595 | bool start_ready_animations = draw_frame; |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 596 | layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
[email protected] | 04c5900d | 2014-08-18 13:38:36 | [diff] [blame] | 597 | layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 598 | |
| 599 | timing_history_.DidFinishDrawing(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 600 | } |
| 601 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 602 | if (draw_frame) { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 603 | DebugScopedSetImplThread impl(this); |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 604 | |
dneto | b71e30c | 2014-08-25 23:27:20 | [diff] [blame] | 605 | // This CapturePostTasks should be destroyed before |
| 606 | // DidCommitAndDrawFrame() is called since that goes out to the |
| 607 | // embedder, |
| 608 | // and we want the embedder to receive its callbacks before that. |
| 609 | // NOTE: This maintains consistent ordering with the ThreadProxy since |
| 610 | // the DidCommitAndDrawFrame() must be post-tasked from the impl thread |
| 611 | // there as the main thread is not blocked, so any posted tasks inside |
| 612 | // the swap buffers will execute first. |
| 613 | DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 614 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 615 | BlockingTaskRunner::CapturePostTasks blocked( |
| 616 | blocking_main_thread_task_runner()); |
dneto | b71e30c | 2014-08-25 23:27:20 | [diff] [blame] | 617 | layer_tree_host_impl_->SwapBuffers(*frame); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 618 | } |
| 619 | DidCommitAndDrawFrame(); |
| 620 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 621 | return draw_result; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 622 | } |
| 623 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 624 | void SingleThreadProxy::DidCommitAndDrawFrame() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 625 | if (next_frame_is_newly_committed_frame_) { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 626 | DebugScopedSetMainThread main(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 627 | next_frame_is_newly_committed_frame_ = false; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 628 | layer_tree_host_->DidCommitAndDrawFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
[email protected] | 4ea293f7 | 2014-08-13 03:03:17 | [diff] [blame] | 632 | bool SingleThreadProxy::MainFrameWillHappenForTesting() { |
| 633 | return false; |
| 634 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 635 | |
simonhong | d3d5f7f | 2014-11-21 16:38:03 | [diff] [blame] | 636 | void SingleThreadProxy::SetChildrenNeedBeginFrames( |
| 637 | bool children_need_begin_frames) { |
| 638 | scheduler_on_impl_thread_->SetChildrenNeedBeginFrames( |
| 639 | children_need_begin_frames); |
| 640 | } |
| 641 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 642 | void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 643 | layer_tree_host_impl_->WillBeginImplFrame(args); |
| 644 | } |
| 645 | |
| 646 | void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { |
| 647 | TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); |
| 648 | // Although this proxy is single-threaded, it's problematic to synchronously |
| 649 | // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This |
| 650 | // could cause a commit to occur in between a series of SetNeedsCommit calls |
| 651 | // (i.e. property modifications) causing some to fall on one frame and some to |
| 652 | // fall on the next. Doing it asynchronously instead matches the semantics of |
| 653 | // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a |
| 654 | // synchronous commit. |
| 655 | MainThreadTaskRunner()->PostTask( |
| 656 | FROM_HERE, |
| 657 | base::Bind(&SingleThreadProxy::BeginMainFrame, |
| 658 | weak_factory_.GetWeakPtr())); |
| 659 | } |
| 660 | |
| 661 | void SingleThreadProxy::BeginMainFrame() { |
| 662 | if (defer_commits_) { |
| 663 | DCHECK(!commit_was_deferred_); |
| 664 | commit_was_deferred_ = true; |
| 665 | layer_tree_host_->DidDeferCommit(); |
| 666 | return; |
| 667 | } |
| 668 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 669 | // This checker assumes NotifyReadyToCommit in this stack causes a synchronous |
| 670 | // commit. |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 671 | ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); |
| 672 | |
| 673 | if (!layer_tree_host_->visible()) { |
| 674 | TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
| 675 | BeginMainFrameAbortedOnImplThread(); |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | if (layer_tree_host_->output_surface_lost()) { |
| 680 | TRACE_EVENT_INSTANT0( |
| 681 | "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); |
| 682 | BeginMainFrameAbortedOnImplThread(); |
| 683 | return; |
| 684 | } |
| 685 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 686 | const BeginFrameArgs& begin_frame_args = |
| 687 | layer_tree_host_impl_->CurrentBeginFrameArgs(); |
| 688 | DoBeginMainFrame(begin_frame_args); |
| 689 | } |
| 690 | |
| 691 | void SingleThreadProxy::DoBeginMainFrame( |
| 692 | const BeginFrameArgs& begin_frame_args) { |
| 693 | layer_tree_host_->WillBeginMainFrame(); |
| 694 | layer_tree_host_->BeginMainFrame(begin_frame_args); |
| 695 | layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); |
| 696 | layer_tree_host_->Layout(); |
| 697 | |
| 698 | if (PrioritizedResourceManager* contents_texture_manager = |
| 699 | layer_tree_host_->contents_texture_manager()) { |
| 700 | contents_texture_manager->UnlinkAndClearEvictedBackings(); |
| 701 | contents_texture_manager->SetMaxMemoryLimitBytes( |
| 702 | layer_tree_host_impl_->memory_allocation_limit_bytes()); |
| 703 | contents_texture_manager->SetExternalPriorityCutoff( |
| 704 | layer_tree_host_impl_->memory_allocation_priority_cutoff()); |
| 705 | } |
| 706 | |
| 707 | DCHECK(!queue_for_commit_); |
| 708 | queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue); |
| 709 | |
| 710 | layer_tree_host_->UpdateLayers(queue_for_commit_.get()); |
| 711 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 712 | timing_history_.DidBeginMainFrame(); |
| 713 | |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 714 | if (scheduler_on_impl_thread_) { |
| 715 | scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); |
| 716 | scheduler_on_impl_thread_->NotifyReadyToCommit(); |
| 717 | } |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | void SingleThreadProxy::BeginMainFrameAbortedOnImplThread() { |
| 721 | DebugScopedSetImplThread impl(this); |
| 722 | DCHECK(scheduler_on_impl_thread_->CommitPending()); |
| 723 | DCHECK(!layer_tree_host_impl_->pending_tree()); |
| 724 | |
| 725 | // TODO(enne): SingleThreadProxy does not support cancelling commits yet so |
| 726 | // did_handle is always false. |
| 727 | bool did_handle = false; |
| 728 | layer_tree_host_impl_->BeginMainFrameAborted(did_handle); |
| 729 | scheduler_on_impl_thread_->BeginMainFrameAborted(did_handle); |
| 730 | } |
| 731 | |
| 732 | DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
| 733 | DebugScopedSetImplThread impl(this); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 734 | LayerTreeHostImpl::FrameData frame; |
| 735 | return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time, |
| 736 | &frame); |
| 737 | } |
| 738 | |
| 739 | DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { |
| 740 | NOTREACHED(); |
| 741 | return INVALID_RESULT; |
| 742 | } |
| 743 | |
| 744 | void SingleThreadProxy::ScheduledActionCommit() { |
| 745 | DebugScopedSetMainThread main(this); |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 746 | DoCommit(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | void SingleThreadProxy::ScheduledActionAnimate() { |
| 750 | TRACE_EVENT0("cc", "ScheduledActionAnimate"); |
mithro | 719bf679 | 2014-11-10 15:36:47 | [diff] [blame] | 751 | DebugScopedSetImplThread impl(this); |
| 752 | DoAnimate(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 753 | } |
| 754 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 755 | void SingleThreadProxy::ScheduledActionActivateSyncTree() { |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 756 | DebugScopedSetImplThread impl(this); |
| 757 | layer_tree_host_impl_->ActivateSyncTree(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
| 761 | DebugScopedSetMainThread main(this); |
| 762 | DCHECK(scheduler_on_impl_thread_); |
| 763 | // If possible, create the output surface in a post task. Synchronously |
| 764 | // creating the output surface makes tests more awkward since this differs |
| 765 | // from the ThreadProxy behavior. However, sometimes there is no |
| 766 | // task runner. |
| 767 | if (Proxy::MainThreadTaskRunner()) { |
jbauman | 8ab0f9e | 2014-10-15 02:30:34 | [diff] [blame] | 768 | ScheduleRequestNewOutputSurface(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 769 | } else { |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 770 | RequestNewOutputSurface(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
| 774 | void SingleThreadProxy::ScheduledActionManageTiles() { |
enne | 98f3a6c | 2014-10-09 20:09:44 | [diff] [blame] | 775 | TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionManageTiles"); |
| 776 | DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
| 777 | DebugScopedSetImplThread impl(this); |
| 778 | layer_tree_host_impl_->ManageTiles(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
| 782 | } |
| 783 | |
| 784 | base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { |
| 785 | return timing_history_.DrawDurationEstimate(); |
| 786 | } |
| 787 | |
| 788 | base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { |
| 789 | return timing_history_.BeginMainFrameToCommitDurationEstimate(); |
| 790 | } |
| 791 | |
| 792 | base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { |
| 793 | return timing_history_.CommitToActivateDurationEstimate(); |
| 794 | } |
| 795 | |
| 796 | void SingleThreadProxy::DidBeginImplFrameDeadline() { |
| 797 | layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
| 798 | } |
| 799 | |
simonhong | d3d5f7f | 2014-11-21 16:38:03 | [diff] [blame] | 800 | void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 801 | layer_tree_host_->SendBeginFramesToChildren(args); |
| 802 | } |
| 803 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 804 | } // namespace cc |