[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] | 9794fb3 | 2013-08-29 09:49:59 | [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] | 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, |
| 26 | scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 27 | return make_scoped_ptr( |
[email protected] | 27e6a21 | 2014-07-18 15:51:27 | [diff] [blame] | 28 | new SingleThreadProxy(layer_tree_host, client, main_task_runner)) |
| 29 | .PassAs<Proxy>(); |
[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] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 39 | next_frame_is_newly_committed_frame_(false), |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 40 | inside_draw_(false) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 41 | TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 42 | DCHECK(Proxy::IsMainThread()); |
| 43 | DCHECK(layer_tree_host); |
[email protected] | 1e4c352b | 2013-01-10 02:05:23 | [diff] [blame] | 44 | |
[email protected] | 089102b | 2013-03-14 03:54:56 | [diff] [blame] | 45 | // Impl-side painting not supported without threaded compositing. |
[email protected] | d9c086a | 2013-04-17 16:12:48 | [diff] [blame] | 46 | CHECK(!layer_tree_host->settings().impl_side_painting) |
| 47 | << "Threaded compositing must be enabled to use impl-side painting."; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | e96e343 | 2013-12-19 18:56:07 | [diff] [blame] | 50 | void SingleThreadProxy::Start() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 51 | DebugScopedSetImplThread impl(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 52 | layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | SingleThreadProxy::~SingleThreadProxy() { |
| 56 | TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| 57 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 58 | // Make sure Stop() got called or never Started. |
| 59 | DCHECK(!layer_tree_host_impl_); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 62 | void SingleThreadProxy::FinishAllRendering() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 63 | TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 64 | DCHECK(Proxy::IsMainThread()); |
| 65 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 66 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 67 | layer_tree_host_impl_->FinishAllRendering(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 68 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 71 | bool SingleThreadProxy::IsStarted() const { |
| 72 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 3209161d | 2013-03-29 19:17:34 | [diff] [blame] | 73 | return layer_tree_host_impl_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 74 | } |
| 75 | |
[email protected] | 14bd554 | 2013-05-08 21:51:30 | [diff] [blame] | 76 | void SingleThreadProxy::SetLayerTreeHostClientReady() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 77 | TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 78 | // Scheduling is controlled by the embedder in the single thread case, so |
| 79 | // nothing to do. |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void SingleThreadProxy::SetVisible(bool visible) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 83 | TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); |
[email protected] | f7c01c8 | 2013-07-02 22:58:46 | [diff] [blame] | 84 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 85 | layer_tree_host_impl_->SetVisible(visible); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 86 | |
[email protected] | 8ea875b | 2013-08-07 00:32:12 | [diff] [blame] | 87 | // Changing visibility could change ShouldComposite(). |
[email protected] | d9fce672 | 2013-08-30 01:10:01 | [diff] [blame] | 88 | UpdateBackgroundAnimateTicking(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 91 | void SingleThreadProxy::CreateAndInitializeOutputSurface() { |
| 92 | TRACE_EVENT0( |
| 93 | "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 94 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 497edf8 | 2014-05-20 21:53:15 | [diff] [blame] | 95 | DCHECK(layer_tree_host_->output_surface_lost()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 96 | |
[email protected] | e96e343 | 2013-12-19 18:56:07 | [diff] [blame] | 97 | scoped_ptr<OutputSurface> output_surface = |
| 98 | layer_tree_host_->CreateOutputSurface(); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 99 | |
[email protected] | da8e3b72b | 2014-04-25 02:33:45 | [diff] [blame] | 100 | renderer_capabilities_for_main_thread_ = RendererCapabilities(); |
| 101 | |
| 102 | bool success = !!output_surface; |
| 103 | if (success) { |
[email protected] | 819b9f5 | 2013-09-22 23:29:51 | [diff] [blame] | 104 | DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 105 | DebugScopedSetImplThread impl(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 106 | layer_tree_host_->DeleteContentsTexturesOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 107 | layer_tree_host_impl_->resource_provider()); |
[email protected] | da8e3b72b | 2014-04-25 02:33:45 | [diff] [blame] | 108 | success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | da8e3b72b | 2014-04-25 02:33:45 | [diff] [blame] | 111 | layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 112 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 113 | if (!success) { |
| 114 | // Force another recreation attempt to happen by requesting another commit. |
| 115 | SetNeedsCommit(); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 116 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 119 | const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 120 | DCHECK(Proxy::IsMainThread()); |
| 121 | DCHECK(!layer_tree_host_->output_surface_lost()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 122 | return renderer_capabilities_for_main_thread_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 123 | } |
| 124 | |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 125 | void SingleThreadProxy::SetNeedsAnimate() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 126 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); |
[email protected] | c513417 | 2013-12-11 06:19:48 | [diff] [blame] | 127 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 06cbc31b | 2014-01-17 06:43:20 | [diff] [blame] | 128 | client_->ScheduleAnimation(); |
[email protected] | c513417 | 2013-12-11 06:19:48 | [diff] [blame] | 129 | } |
| 130 | |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 131 | void SingleThreadProxy::SetNeedsUpdateLayers() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 132 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 133 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 134 | client_->ScheduleComposite(); |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 137 | void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 138 | TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 139 | DCHECK(Proxy::IsMainThread()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 140 | // Commit immediately. |
| 141 | { |
[email protected] | 819b9f5 | 2013-09-22 23:29:51 | [diff] [blame] | 142 | DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
[email protected] | f7c01c8 | 2013-07-02 22:58:46 | [diff] [blame] | 143 | DebugScopedSetImplThread impl(this); |
| 144 | |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 145 | // This CapturePostTasks should be destroyed before CommitComplete() is |
| 146 | // called since that goes out to the embedder, and we want the embedder |
| 147 | // to receive its callbacks before that. |
| 148 | BlockingTaskRunner::CapturePostTasks blocked; |
| 149 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 150 | layer_tree_host_impl_->BeginCommit(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 151 | |
[email protected] | 5d2fec0 | 2013-11-28 20:08:33 | [diff] [blame] | 152 | if (PrioritizedResourceManager* contents_texture_manager = |
| 153 | layer_tree_host_->contents_texture_manager()) { |
| 154 | contents_texture_manager->PushTexturePrioritiesToBackings(); |
[email protected] | 6e8c5492 | 2013-06-02 19:17:35 | [diff] [blame] | 155 | } |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 156 | layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 157 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 158 | scoped_ptr<ResourceUpdateController> update_controller = |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 159 | ResourceUpdateController::Create( |
| 160 | NULL, |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 161 | Proxy::MainThreadTaskRunner(), |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 162 | queue.Pass(), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 163 | layer_tree_host_impl_->resource_provider()); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 164 | update_controller->Finalize(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 165 | |
[email protected] | 127bdc1a | 2013-09-11 01:44:48 | [diff] [blame] | 166 | if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 167 | layer_tree_host_->RecreateUIResources(); |
| 168 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 169 | layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 170 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 171 | layer_tree_host_impl_->CommitComplete(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 172 | |
[email protected] | 767f38d7 | 2014-03-18 21:26:41 | [diff] [blame] | 173 | #if DCHECK_IS_ON |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 174 | // In the single-threaded case, the scale and scroll deltas should never be |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 175 | // touched on the impl layer tree. |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 176 | scoped_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 177 | layer_tree_host_impl_->ProcessScrollDeltas(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 178 | DCHECK(!scroll_info->scrolls.size()); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 179 | DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 180 | #endif |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 181 | |
[email protected] | 922c6e1f | 2013-10-09 04:04:09 | [diff] [blame] | 182 | RenderingStatsInstrumentation* stats_instrumentation = |
| 183 | layer_tree_host_->rendering_stats_instrumentation(); |
[email protected] | 1bbed7a | 2014-07-08 02:54:00 | [diff] [blame] | 184 | benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( |
[email protected] | adbe30f | 2013-10-11 21:12:33 | [diff] [blame] | 185 | stats_instrumentation->main_thread_rendering_stats()); |
[email protected] | a9dc0d0f | 2013-08-17 02:43:18 | [diff] [blame] | 186 | stats_instrumentation->AccumulateAndClearMainThreadStats(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 187 | } |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 188 | layer_tree_host_->CommitComplete(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 189 | next_frame_is_newly_committed_frame_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 192 | void SingleThreadProxy::SetNeedsCommit() { |
| 193 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 194 | client_->ScheduleComposite(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 197 | void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 198 | TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 199 | SetNeedsRedrawRectOnImplThread(damage_rect); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 200 | client_->ScheduleComposite(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 201 | } |
| 202 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 203 | void SingleThreadProxy::SetNextCommitWaitsForActivation() { |
| 204 | // There is no activation here other than commit. So do nothing. |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 207 | void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
[email protected] | 6b16679e | 2012-10-27 00:44:28 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 210 | bool SingleThreadProxy::CommitRequested() const { |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 211 | return false; |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 212 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 213 | |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 214 | bool SingleThreadProxy::BeginMainFrameRequested() const { |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 215 | return false; |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 216 | } |
[email protected] | 971728d | 2013-10-26 10:39:31 | [diff] [blame] | 217 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 218 | size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
| 219 | return std::numeric_limits<size_t>::max(); |
| 220 | } |
| 221 | |
| 222 | void SingleThreadProxy::Stop() { |
| 223 | TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
| 224 | DCHECK(Proxy::IsMainThread()); |
| 225 | { |
[email protected] | 819b9f5 | 2013-09-22 23:29:51 | [diff] [blame] | 226 | DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 227 | DebugScopedSetImplThread impl(this); |
| 228 | |
[email protected] | 446b23d | 2014-05-16 18:24:18 | [diff] [blame] | 229 | BlockingTaskRunner::CapturePostTasks blocked; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 230 | layer_tree_host_->DeleteContentsTexturesOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 231 | layer_tree_host_impl_->resource_provider()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 232 | layer_tree_host_impl_.reset(); |
| 233 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 234 | layer_tree_host_ = NULL; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 235 | } |
| 236 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 237 | void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 238 | TRACE_EVENT1( |
| 239 | "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 240 | DCHECK(Proxy::IsImplThread()); |
[email protected] | d9fce672 | 2013-08-30 01:10:01 | [diff] [blame] | 241 | UpdateBackgroundAnimateTicking(); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 244 | void SingleThreadProxy::NotifyReadyToActivate() { |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 245 | // Thread-only feature. |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 246 | NOTREACHED(); |
| 247 | } |
| 248 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 249 | void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 250 | client_->ScheduleComposite(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 253 | void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
| 254 | SetNeedsRedrawOnImplThread(); |
| 255 | } |
| 256 | |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 257 | void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 258 | // Thread-only/Impl-side-painting-only feature. |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 259 | NOTREACHED(); |
| 260 | } |
| 261 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 262 | void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
| 263 | const gfx::Rect& damage_rect) { |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 264 | // TODO(brianderson): Once we move render_widget scheduling into this class, |
| 265 | // we can treat redraw requests more efficiently than CommitAndRedraw |
| 266 | // requests. |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 267 | layer_tree_host_impl_->SetViewportDamage(damage_rect); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 268 | SetNeedsCommit(); |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 271 | void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 272 | // Impl-side painting only. |
| 273 | NOTREACHED(); |
| 274 | } |
| 275 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 276 | void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 277 | client_->ScheduleComposite(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 280 | void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
[email protected] | 85b5750 | 2014-03-11 15:37:48 | [diff] [blame] | 281 | scoped_ptr<AnimationEventsVector> events) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 282 | TRACE_EVENT0( |
| 283 | "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 284 | DCHECK(Proxy::IsImplThread()); |
| 285 | DebugScopedSetMainThread main(this); |
[email protected] | 85b5750 | 2014-03-11 15:37:48 | [diff] [blame] | 286 | layer_tree_host_->SetAnimationEvents(events.Pass()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 289 | bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 290 | size_t limit_bytes, |
| 291 | int priority_cutoff) { |
| 292 | DCHECK(IsImplThread()); |
[email protected] | 5d2fec0 | 2013-11-28 20:08:33 | [diff] [blame] | 293 | PrioritizedResourceManager* contents_texture_manager = |
| 294 | layer_tree_host_->contents_texture_manager(); |
| 295 | |
| 296 | ResourceProvider* resource_provider = |
| 297 | layer_tree_host_impl_->resource_provider(); |
| 298 | |
| 299 | if (!contents_texture_manager || !resource_provider) |
[email protected] | e7595ead | 2013-10-10 10:10:07 | [diff] [blame] | 300 | return false; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 301 | |
[email protected] | 5d2fec0 | 2013-11-28 20:08:33 | [diff] [blame] | 302 | return contents_texture_manager->ReduceMemoryOnImplThread( |
| 303 | limit_bytes, priority_cutoff, resource_provider); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 304 | } |
| 305 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 306 | bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 307 | |
[email protected] | fa33903 | 2014-02-18 22:11:59 | [diff] [blame] | 308 | void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
| 309 | DCHECK(IsImplThread()); |
| 310 | renderer_capabilities_for_main_thread_ = |
| 311 | layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
| 312 | } |
| 313 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 314 | void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 315 | TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 316 | // Cause a commit so we can notice the lost context. |
| 317 | SetNeedsCommitOnImplThread(); |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 318 | client_->DidAbortSwapBuffers(); |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 322 | client_->DidPostSwapBuffers(); |
| 323 | } |
| 324 | |
[email protected] | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 325 | void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
| 326 | TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 327 | client_->DidCompleteSwapBuffers(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 328 | } |
| 329 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 330 | // Called by the legacy scheduling path (e.g. where render_widget does the |
| 331 | // scheduling) |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 332 | void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 333 | TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); |
[email protected] | 51f81da | 2014-05-16 21:29:26 | [diff] [blame] | 334 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 497edf8 | 2014-05-20 21:53:15 | [diff] [blame] | 335 | DCHECK(!layer_tree_host_->output_surface_lost()); |
[email protected] | 51f81da | 2014-05-16 21:29:26 | [diff] [blame] | 336 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 337 | layer_tree_host_->AnimateLayers(frame_begin_time); |
| 338 | |
| 339 | if (PrioritizedResourceManager* contents_texture_manager = |
| 340 | layer_tree_host_->contents_texture_manager()) { |
| 341 | contents_texture_manager->UnlinkAndClearEvictedBackings(); |
| 342 | contents_texture_manager->SetMaxMemoryLimitBytes( |
| 343 | layer_tree_host_impl_->memory_allocation_limit_bytes()); |
| 344 | contents_texture_manager->SetExternalPriorityCutoff( |
| 345 | layer_tree_host_impl_->memory_allocation_priority_cutoff()); |
| 346 | } |
| 347 | |
| 348 | scoped_ptr<ResourceUpdateQueue> queue = |
| 349 | make_scoped_ptr(new ResourceUpdateQueue); |
| 350 | layer_tree_host_->UpdateLayers(queue.get()); |
| 351 | layer_tree_host_->WillCommit(); |
| 352 | DoCommit(queue.Pass()); |
| 353 | layer_tree_host_->DidBeginMainFrame(); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 354 | |
| 355 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 356 | if (DoComposite(frame_begin_time, &frame)) { |
| 357 | { |
| 358 | DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 359 | DebugScopedSetImplThread impl(this); |
| 360 | |
| 361 | // This CapturePostTasks should be destroyed before |
| 362 | // DidCommitAndDrawFrame() is called since that goes out to the embedder, |
| 363 | // and we want the embedder to receive its callbacks before that. |
| 364 | // NOTE: This maintains consistent ordering with the ThreadProxy since |
| 365 | // the DidCommitAndDrawFrame() must be post-tasked from the impl thread |
| 366 | // there as the main thread is not blocked, so any posted tasks inside |
| 367 | // the swap buffers will execute first. |
| 368 | BlockingTaskRunner::CapturePostTasks blocked; |
| 369 | |
| 370 | layer_tree_host_impl_->SwapBuffers(frame); |
| 371 | } |
| 372 | DidSwapFrame(); |
| 373 | } |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 376 | void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const { |
| 377 | // The following line casts away const modifiers because it is just |
| 378 | // setting debug state. We still want the AsValue() function and its |
| 379 | // call chain to be const throughout. |
| 380 | DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 381 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 382 | state->BeginDictionary("layer_tree_host_impl"); |
| 383 | layer_tree_host_impl_->AsValueInto(state); |
| 384 | state->EndDictionary(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 385 | } |
| 386 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 387 | void SingleThreadProxy::ForceSerializeOnSwapBuffers() { |
| 388 | { |
| 389 | DebugScopedSetImplThread impl(this); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 390 | if (layer_tree_host_impl_->renderer()) { |
| 391 | DCHECK(!layer_tree_host_->output_surface_lost()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 392 | layer_tree_host_impl_->renderer()->DoNoOp(); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 393 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 394 | } |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 395 | } |
| 396 | |
[email protected] | 5d8bec7 | 2014-07-03 03:03:11 | [diff] [blame] | 397 | bool SingleThreadProxy::SupportsImplScrolling() const { |
| 398 | return false; |
| 399 | } |
| 400 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 401 | bool SingleThreadProxy::ShouldComposite() const { |
| 402 | DCHECK(Proxy::IsImplThread()); |
| 403 | return layer_tree_host_impl_->visible() && |
| 404 | layer_tree_host_impl_->CanDraw(); |
| 405 | } |
| 406 | |
[email protected] | d9fce672 | 2013-08-30 01:10:01 | [diff] [blame] | 407 | void SingleThreadProxy::UpdateBackgroundAnimateTicking() { |
| 408 | DCHECK(Proxy::IsImplThread()); |
| 409 | layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
| 410 | !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
| 411 | } |
| 412 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 413 | bool SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
| 414 | LayerTreeHostImpl::FrameData* frame) { |
[email protected] | ccc08dc | 2014-01-30 07:33:20 | [diff] [blame] | 415 | TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 416 | DCHECK(!layer_tree_host_->output_surface_lost()); |
| 417 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 418 | bool lost_output_surface = false; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 419 | { |
| 420 | DebugScopedSetImplThread impl(this); |
| 421 | base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 422 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 423 | // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 424 | // frame, so can only be used when such a frame is possible. Since |
| 425 | // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 426 | // CanDraw() as well. |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 427 | if (!ShouldComposite()) { |
[email protected] | d9fce672 | 2013-08-30 01:10:01 | [diff] [blame] | 428 | UpdateBackgroundAnimateTicking(); |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 429 | return false; |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 430 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 431 | |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 432 | layer_tree_host_impl_->Animate( |
[email protected] | 2715264 | 2014-03-11 20:42:00 | [diff] [blame] | 433 | layer_tree_host_impl_->CurrentFrameTimeTicks()); |
[email protected] | d9fce672 | 2013-08-30 01:10:01 | [diff] [blame] | 434 | UpdateBackgroundAnimateTicking(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 435 | |
[email protected] | 13044fe7 | 2013-12-02 20:52:19 | [diff] [blame] | 436 | if (!layer_tree_host_impl_->IsContextLost()) { |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 437 | layer_tree_host_impl_->PrepareToDraw(frame); |
[email protected] | 2e316b27 | 2014-07-19 05:01:20 | [diff] [blame] | 438 | layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
[email protected] | 13044fe7 | 2013-12-02 20:52:19 | [diff] [blame] | 439 | layer_tree_host_impl_->DidDrawAllLayers(*frame); |
| 440 | } |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 441 | lost_output_surface = layer_tree_host_impl_->IsContextLost(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 442 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 443 | bool start_ready_animations = true; |
| 444 | layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
| 445 | |
[email protected] | 8347d69 | 2013-05-17 23:22:38 | [diff] [blame] | 446 | layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 447 | } |
| 448 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 449 | if (lost_output_surface) { |
| 450 | layer_tree_host_->DidLoseOutputSurface(); |
| 451 | return false; |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 452 | } |
[email protected] | 174c6d4 | 2014-08-12 01:43:06 | [diff] [blame] | 453 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 454 | return true; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | 2decdd78 | 2014-08-13 22:36:06 | [diff] [blame^] | 457 | void SingleThreadProxy::DidSwapFrame() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 458 | if (next_frame_is_newly_committed_frame_) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 459 | next_frame_is_newly_committed_frame_ = false; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 460 | layer_tree_host_->DidCommitAndDrawFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
[email protected] | 4ea293f7 | 2014-08-13 03:03:17 | [diff] [blame] | 464 | bool SingleThreadProxy::MainFrameWillHappenForTesting() { |
| 465 | return false; |
| 466 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 467 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 468 | } // namespace cc |