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