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