[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] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 9 | #include "cc/output/context_provider.h" |
| 10 | #include "cc/output/output_surface.h" |
[email protected] | 89e8267 | 2013-03-18 07:50:56 | [diff] [blame] | 11 | #include "cc/quads/draw_quad.h" |
[email protected] | e12dd0e | 2013-03-18 08:24:40 | [diff] [blame] | 12 | #include "cc/resources/prioritized_resource_manager.h" |
| 13 | #include "cc/resources/resource_update_controller.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 14 | #include "cc/trees/layer_tree_host.h" |
| 15 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 16 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 17 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 18 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 19 | scoped_ptr<Proxy> SingleThreadProxy::Create(LayerTreeHost* layer_tree_host) { |
| 20 | return make_scoped_ptr( |
| 21 | new SingleThreadProxy(layer_tree_host)).PassAs<Proxy>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 22 | } |
| 23 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 24 | SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host) |
[email protected] | 810d40b7 | 2013-06-20 18:26:15 | [diff] [blame] | 25 | : Proxy(NULL), |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 26 | layer_tree_host_(layer_tree_host), |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 27 | created_offscreen_context_provider_(false), |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 28 | next_frame_is_newly_committed_frame_(false), |
[email protected] | ccd6d9d | 2013-03-30 19:08:58 | [diff] [blame] | 29 | inside_draw_(false) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 30 | TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 31 | DCHECK(Proxy::IsMainThread()); |
| 32 | DCHECK(layer_tree_host); |
[email protected] | 1e4c352b | 2013-01-10 02:05:23 | [diff] [blame] | 33 | |
[email protected] | 089102b | 2013-03-14 03:54:56 | [diff] [blame] | 34 | // Impl-side painting not supported without threaded compositing. |
[email protected] | d9c086a | 2013-04-17 16:12:48 | [diff] [blame] | 35 | CHECK(!layer_tree_host->settings().impl_side_painting) |
| 36 | << "Threaded compositing must be enabled to use impl-side painting."; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 37 | } |
| 38 | |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 39 | void SingleThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { |
| 40 | DCHECK(first_output_surface); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 41 | DebugScopedSetImplThread impl(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 42 | layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 43 | first_output_surface_ = first_output_surface.Pass(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | SingleThreadProxy::~SingleThreadProxy() { |
| 47 | TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| 48 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 49 | // Make sure Stop() got called or never Started. |
| 50 | DCHECK(!layer_tree_host_impl_); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 54 | TRACE_EVENT0("cc", "SingleThreadProxy::CompositeAndReadback"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 55 | DCHECK(Proxy::IsMainThread()); |
| 56 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 57 | gfx::Rect device_viewport_damage_rect = rect; |
| 58 | |
| 59 | LayerTreeHostImpl::FrameData frame; |
| 60 | if (!CommitAndComposite(base::TimeTicks::Now(), |
| 61 | device_viewport_damage_rect, |
[email protected] | 2921d04 | 2013-05-10 05:01:39 | [diff] [blame] | 62 | true, // for_readback |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 63 | &frame)) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 64 | return false; |
| 65 | |
| 66 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 67 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 68 | layer_tree_host_impl_->Readback(pixels, rect); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 69 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 70 | if (layer_tree_host_impl_->IsContextLost()) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 71 | return false; |
| 72 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 73 | layer_tree_host_impl_->SwapBuffers(frame); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 74 | } |
| 75 | DidSwapFrame(); |
| 76 | |
| 77 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 80 | void SingleThreadProxy::FinishAllRendering() { |
| 81 | DCHECK(Proxy::IsMainThread()); |
| 82 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 83 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 84 | layer_tree_host_impl_->FinishAllRendering(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 85 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 86 | } |
| 87 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 88 | bool SingleThreadProxy::IsStarted() const { |
| 89 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 3209161d | 2013-03-29 19:17:34 | [diff] [blame] | 90 | return layer_tree_host_impl_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | 14bd554 | 2013-05-08 21:51:30 | [diff] [blame] | 93 | void SingleThreadProxy::SetLayerTreeHostClientReady() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 94 | // Scheduling is controlled by the embedder in the single thread case, so |
| 95 | // nothing to do. |
| 96 | } |
| 97 | |
| 98 | void SingleThreadProxy::SetVisible(bool visible) { |
[email protected] | f7c01c8 | 2013-07-02 22:58:46 | [diff] [blame] | 99 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 100 | layer_tree_host_impl_->SetVisible(visible); |
[email protected] | 8ea875b | 2013-08-07 00:32:12 | [diff] [blame] | 101 | |
| 102 | // Changing visibility could change ShouldComposite(). |
| 103 | layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!ShouldComposite()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 104 | } |
| 105 | |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 106 | void SingleThreadProxy::CreateAndInitializeOutputSurface() { |
| 107 | TRACE_EVENT0( |
| 108 | "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 109 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 110 | |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 111 | scoped_ptr<OutputSurface> output_surface = first_output_surface_.Pass(); |
[email protected] | 486544b | 2013-04-26 18:46:22 | [diff] [blame] | 112 | if (!output_surface) |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 113 | output_surface = layer_tree_host_->CreateOutputSurface(); |
| 114 | if (!output_surface) { |
| 115 | OnOutputSurfaceInitializeAttempted(false); |
| 116 | return; |
| 117 | } |
| 118 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 119 | scoped_refptr<cc::ContextProvider> offscreen_context_provider; |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 120 | if (created_offscreen_context_provider_) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 121 | offscreen_context_provider = |
| 122 | layer_tree_host_->client()->OffscreenContextProviderForMainThread(); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 123 | if (!offscreen_context_provider.get()) { |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 124 | OnOutputSurfaceInitializeAttempted(false); |
| 125 | return; |
| 126 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 127 | } |
| 128 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 129 | { |
| 130 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 131 | DebugScopedSetImplThread impl(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 132 | layer_tree_host_->DeleteContentsTexturesOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 133 | layer_tree_host_impl_->resource_provider()); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | bool initialized; |
| 137 | { |
| 138 | DebugScopedSetImplThread impl(this); |
| 139 | |
| 140 | DCHECK(output_surface); |
| 141 | initialized = layer_tree_host_impl_->InitializeRenderer( |
| 142 | output_surface.Pass()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 143 | if (initialized) { |
| 144 | renderer_capabilities_for_main_thread_ = |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 145 | layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 146 | |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 147 | layer_tree_host_impl_->resource_provider()-> |
| 148 | set_offscreen_context_provider(offscreen_context_provider); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 149 | } else if (offscreen_context_provider.get()) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 150 | offscreen_context_provider->VerifyContexts(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 151 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 152 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 153 | |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 154 | OnOutputSurfaceInitializeAttempted(initialized); |
| 155 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 156 | |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 157 | void SingleThreadProxy::OnOutputSurfaceInitializeAttempted(bool success) { |
| 158 | LayerTreeHost::CreateResult result = |
| 159 | layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
| 160 | if (result == LayerTreeHost::CreateFailedButTryAgain) { |
| 161 | // Force another recreation attempt to happen by requesting another commit. |
| 162 | SetNeedsCommit(); |
| 163 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 164 | } |
| 165 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 166 | const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 167 | DCHECK(Proxy::IsMainThread()); |
| 168 | DCHECK(!layer_tree_host_->output_surface_lost()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 169 | return renderer_capabilities_for_main_thread_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 172 | void SingleThreadProxy::SetNeedsAnimate() { |
| 173 | // Thread-only feature. |
| 174 | NOTREACHED(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 175 | } |
| 176 | |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 177 | void SingleThreadProxy::SetNeedsUpdateLayers() { |
| 178 | DCHECK(Proxy::IsMainThread()); |
| 179 | layer_tree_host_->ScheduleComposite(); |
| 180 | } |
| 181 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 182 | void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { |
| 183 | DCHECK(Proxy::IsMainThread()); |
| 184 | // Commit immediately. |
| 185 | { |
[email protected] | f7c01c8 | 2013-07-02 22:58:46 | [diff] [blame] | 186 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 187 | DebugScopedSetImplThread impl(this); |
| 188 | |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 189 | RenderingStatsInstrumentation* stats_instrumentation = |
| 190 | layer_tree_host_->rendering_stats_instrumentation(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 191 | base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 192 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 193 | layer_tree_host_impl_->BeginCommit(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 194 | |
[email protected] | 6e8c5492 | 2013-06-02 19:17:35 | [diff] [blame] | 195 | if (layer_tree_host_->contents_texture_manager()) { |
| 196 | layer_tree_host_->contents_texture_manager()-> |
| 197 | PushTexturePrioritiesToBackings(); |
| 198 | } |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 199 | layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 200 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 201 | scoped_ptr<ResourceUpdateController> update_controller = |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 202 | ResourceUpdateController::Create( |
| 203 | NULL, |
[email protected] | 810d40b7 | 2013-06-20 18:26:15 | [diff] [blame] | 204 | Proxy::MainThreadTaskRunner(), |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 205 | queue.Pass(), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 206 | layer_tree_host_impl_->resource_provider()); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 207 | update_controller->Finalize(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 208 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 209 | layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 210 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 211 | layer_tree_host_impl_->CommitComplete(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 212 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 213 | #ifndef NDEBUG |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 214 | // In the single-threaded case, the scale and scroll deltas should never be |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 215 | // touched on the impl layer tree. |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 216 | scoped_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 217 | layer_tree_host_impl_->ProcessScrollDeltas(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 218 | DCHECK(!scroll_info->scrolls.size()); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 219 | DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 220 | #endif |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 221 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 222 | base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 223 | stats_instrumentation->AddCommit(duration); |
[email protected] | c1e6cc06 | 2013-08-24 03:35:35 | [diff] [blame] | 224 | stats_instrumentation->IssueTraceEventForMainThreadStats(); |
[email protected] | a9dc0d0f | 2013-08-17 02:43:18 | [diff] [blame] | 225 | stats_instrumentation->AccumulateAndClearMainThreadStats(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 226 | } |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 227 | layer_tree_host_->CommitComplete(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 228 | next_frame_is_newly_committed_frame_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 229 | } |
| 230 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 231 | void SingleThreadProxy::SetNeedsCommit() { |
| 232 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 233 | layer_tree_host_->ScheduleComposite(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | b9d4a36 | 2013-04-23 05:36:27 | [diff] [blame] | 236 | void SingleThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 237 | SetNeedsRedrawRectOnImplThread(damage_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 240 | void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
| 241 | // Thread-only feature. |
| 242 | NOTREACHED(); |
[email protected] | 6b16679e | 2012-10-27 00:44:28 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 245 | bool SingleThreadProxy::CommitRequested() const { return false; } |
| 246 | |
| 247 | size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
| 248 | return std::numeric_limits<size_t>::max(); |
| 249 | } |
| 250 | |
| 251 | void SingleThreadProxy::Stop() { |
| 252 | TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
| 253 | DCHECK(Proxy::IsMainThread()); |
| 254 | { |
| 255 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 256 | DebugScopedSetImplThread impl(this); |
| 257 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 258 | layer_tree_host_->DeleteContentsTexturesOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 259 | layer_tree_host_impl_->resource_provider()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 260 | layer_tree_host_impl_.reset(); |
| 261 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 262 | layer_tree_host_ = NULL; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 263 | } |
| 264 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 265 | void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
| 266 | DCHECK(Proxy::IsImplThread()); |
| 267 | layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!ShouldComposite()); |
| 268 | } |
| 269 | |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame^] | 270 | void SingleThreadProxy::NotifyReadyToActivate() { |
| 271 | // Thread-only feature. |
| 272 | NOTREACHED(); |
| 273 | } |
| 274 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 275 | void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 276 | layer_tree_host_->ScheduleComposite(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 277 | } |
| 278 | |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 279 | void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) { |
[email protected] | 27d851ab | 2013-06-28 01:09:50 | [diff] [blame] | 280 | // TODO(brianderson): Once we move render_widget scheduling into this class, |
| 281 | // we can treat redraw requests more efficiently than CommitAndRedraw |
| 282 | // requests. |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 283 | layer_tree_host_impl_->SetViewportDamage(damage_rect); |
| 284 | SetNeedsCommit(); |
| 285 | } |
| 286 | |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 287 | void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 288 | // Impl-side painting only. |
| 289 | NOTREACHED(); |
| 290 | } |
| 291 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 292 | void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 293 | layer_tree_host_->ScheduleComposite(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 294 | } |
| 295 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 296 | void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 297 | scoped_ptr<AnimationEventsVector> events, |
| 298 | base::Time wall_clock_time) { |
| 299 | DCHECK(Proxy::IsImplThread()); |
| 300 | DebugScopedSetMainThread main(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 301 | layer_tree_host_->SetAnimationEvents(events.Pass(), wall_clock_time); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 304 | bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 305 | size_t limit_bytes, |
| 306 | int priority_cutoff) { |
| 307 | DCHECK(IsImplThread()); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 308 | if (!layer_tree_host_->contents_texture_manager()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 309 | return false; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 310 | |
[email protected] | b56c130 | 2013-03-20 21:17:34 | [diff] [blame] | 311 | return layer_tree_host_->contents_texture_manager()->ReduceMemoryOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 312 | limit_bytes, priority_cutoff, layer_tree_host_impl_->resource_provider()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 313 | } |
| 314 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 315 | void SingleThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 316 | // Impl-side painting only. |
| 317 | NOTREACHED(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 320 | void SingleThreadProxy::SendManagedMemoryStats() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 321 | DCHECK(Proxy::IsImplThread()); |
[email protected] | 384b2c5e | 2013-04-23 01:02:22 | [diff] [blame] | 322 | if (!layer_tree_host_impl_) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 323 | return; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 324 | if (!layer_tree_host_->contents_texture_manager()) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 325 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 326 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 327 | PrioritizedResourceManager* contents_texture_manager = |
| 328 | layer_tree_host_->contents_texture_manager(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 329 | layer_tree_host_impl_->SendManagedMemoryStats( |
[email protected] | b56c130 | 2013-03-20 21:17:34 | [diff] [blame] | 330 | contents_texture_manager->MemoryVisibleBytes(), |
| 331 | contents_texture_manager->MemoryVisibleAndNearbyBytes(), |
| 332 | contents_texture_manager->MemoryUseBytes()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 333 | } |
| 334 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 335 | bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 336 | |
[email protected] | 2b154b2 | 2013-06-07 09:03:27 | [diff] [blame] | 337 | void SingleThreadProxy::DidTryInitializeRendererOnImplThread( |
| 338 | bool success, |
| 339 | scoped_refptr<ContextProvider> offscreen_context_provider) { |
| 340 | NOTREACHED() |
| 341 | << "This is only used on threaded compositing with impl-side painting"; |
| 342 | } |
| 343 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 344 | void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 345 | // Cause a commit so we can notice the lost context. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 346 | SetNeedsCommitOnImplThread(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 347 | } |
| 348 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 349 | // Called by the legacy scheduling path (e.g. where render_widget does the |
| 350 | // scheduling) |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 351 | void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 352 | gfx::Rect device_viewport_damage_rect; |
| 353 | |
| 354 | LayerTreeHostImpl::FrameData frame; |
| 355 | if (CommitAndComposite(frame_begin_time, |
| 356 | device_viewport_damage_rect, |
[email protected] | 2921d04 | 2013-05-10 05:01:39 | [diff] [blame] | 357 | false, // for_readback |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 358 | &frame)) { |
| 359 | layer_tree_host_impl_->SwapBuffers(frame); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 360 | DidSwapFrame(); |
| 361 | } |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 364 | scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
| 365 | scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 366 | { |
| 367 | // The following line casts away const modifiers because it is just |
| 368 | // setting debug state. We still want the AsValue() function and its |
| 369 | // call chain to be const throughout. |
| 370 | DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
| 371 | |
| 372 | state->Set("layer_tree_host_impl", |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 373 | layer_tree_host_impl_->AsValue().release()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 374 | } |
| 375 | return state.PassAs<base::Value>(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 376 | } |
| 377 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 378 | void SingleThreadProxy::ForceSerializeOnSwapBuffers() { |
| 379 | { |
| 380 | DebugScopedSetImplThread impl(this); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 381 | if (layer_tree_host_impl_->renderer()) { |
| 382 | DCHECK(!layer_tree_host_->output_surface_lost()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 383 | layer_tree_host_impl_->renderer()->DoNoOp(); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 384 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 385 | } |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 386 | } |
| 387 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 388 | bool SingleThreadProxy::CommitAndComposite( |
| 389 | base::TimeTicks frame_begin_time, |
| 390 | gfx::Rect device_viewport_damage_rect, |
[email protected] | 2921d04 | 2013-05-10 05:01:39 | [diff] [blame] | 391 | bool for_readback, |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 392 | LayerTreeHostImpl::FrameData* frame) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 393 | DCHECK(Proxy::IsMainThread()); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 394 | |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 395 | if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) |
[email protected] | 16288a4 | 2012-12-17 23:31:05 | [diff] [blame] | 396 | return false; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 397 | |
[email protected] | d776366 | 2013-05-09 18:14:37 | [diff] [blame] | 398 | layer_tree_host_->AnimateLayers(frame_begin_time); |
| 399 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 400 | scoped_refptr<cc::ContextProvider> offscreen_context_provider; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 401 | if (renderer_capabilities_for_main_thread_.using_offscreen_context3d && |
| 402 | layer_tree_host_->needs_offscreen_context()) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 403 | offscreen_context_provider = |
| 404 | layer_tree_host_->client()->OffscreenContextProviderForMainThread(); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 405 | if (offscreen_context_provider.get()) |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 406 | created_offscreen_context_provider_ = true; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 407 | } |
| 408 | |
[email protected] | 6e8c5492 | 2013-06-02 19:17:35 | [diff] [blame] | 409 | if (layer_tree_host_->contents_texture_manager()) { |
| 410 | layer_tree_host_->contents_texture_manager() |
| 411 | ->UnlinkAndClearEvictedBackings(); |
| 412 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 413 | |
| 414 | scoped_ptr<ResourceUpdateQueue> queue = |
| 415 | make_scoped_ptr(new ResourceUpdateQueue); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 416 | layer_tree_host_->UpdateLayers( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 417 | queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 418 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 419 | layer_tree_host_->WillCommit(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 420 | DoCommit(queue.Pass()); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 421 | bool result = DoComposite(offscreen_context_provider, |
| 422 | frame_begin_time, |
| 423 | device_viewport_damage_rect, |
[email protected] | 2921d04 | 2013-05-10 05:01:39 | [diff] [blame] | 424 | for_readback, |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 425 | frame); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 426 | layer_tree_host_->DidBeginFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 427 | return result; |
[email protected] | 16288a4 | 2012-12-17 23:31:05 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 430 | bool SingleThreadProxy::ShouldComposite() const { |
| 431 | DCHECK(Proxy::IsImplThread()); |
| 432 | return layer_tree_host_impl_->visible() && |
| 433 | layer_tree_host_impl_->CanDraw(); |
| 434 | } |
| 435 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 436 | bool SingleThreadProxy::DoComposite( |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 437 | scoped_refptr<cc::ContextProvider> offscreen_context_provider, |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 438 | base::TimeTicks frame_begin_time, |
| 439 | gfx::Rect device_viewport_damage_rect, |
[email protected] | 2921d04 | 2013-05-10 05:01:39 | [diff] [blame] | 440 | bool for_readback, |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 441 | LayerTreeHostImpl::FrameData* frame) { |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 442 | DCHECK(!layer_tree_host_->output_surface_lost()); |
| 443 | |
| 444 | bool lost_output_surface = false; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 445 | { |
| 446 | DebugScopedSetImplThread impl(this); |
| 447 | base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 448 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 449 | layer_tree_host_impl_->resource_provider()-> |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 450 | set_offscreen_context_provider(offscreen_context_provider); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 451 | |
[email protected] | 2921d04 | 2013-05-10 05:01:39 | [diff] [blame] | 452 | bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); |
| 453 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 454 | // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 455 | // frame, so can only be used when such a frame is possible. Since |
| 456 | // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 457 | // CanDraw() as well. |
[email protected] | 2921d04 | 2013-05-10 05:01:39 | [diff] [blame] | 458 | if (!ShouldComposite() || (for_readback && !can_do_readback)) { |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 459 | layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 460 | return false; |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 461 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 462 | |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 463 | layer_tree_host_impl_->Animate( |
| 464 | layer_tree_host_impl_->CurrentFrameTimeTicks(), |
| 465 | layer_tree_host_impl_->CurrentFrameTime()); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 466 | layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 467 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 468 | layer_tree_host_impl_->PrepareToDraw(frame, device_viewport_damage_rect); |
| 469 | layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
| 470 | layer_tree_host_impl_->DidDrawAllLayers(*frame); |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 471 | lost_output_surface = layer_tree_host_impl_->IsContextLost(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 472 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 473 | bool start_ready_animations = true; |
| 474 | layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
| 475 | |
[email protected] | 8347d69 | 2013-05-17 23:22:38 | [diff] [blame] | 476 | layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 477 | } |
| 478 | |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 479 | if (lost_output_surface) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 480 | cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_-> |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 481 | resource_provider()->offscreen_context_provider(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 482 | if (offscreen_contexts) |
| 483 | offscreen_contexts->VerifyContexts(); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 484 | layer_tree_host_->DidLoseOutputSurface(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 485 | return false; |
| 486 | } |
| 487 | |
| 488 | return true; |
| 489 | } |
| 490 | |
| 491 | void SingleThreadProxy::DidSwapFrame() { |
| 492 | if (next_frame_is_newly_committed_frame_) { |
| 493 | next_frame_is_newly_committed_frame_ = false; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 494 | layer_tree_host_->DidCommitAndDrawFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
| 498 | bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
| 499 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 500 | } // namespace cc |