Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/single_thread_proxy.h" | 5 #include "cc/trees/single_thread_proxy.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "cc/debug/benchmark_instrumentation.h" | 9 #include "cc/debug/benchmark_instrumentation.h" |
| 10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 return make_scoped_ptr( | 26 return make_scoped_ptr( |
| 27 new SingleThreadProxy(layer_tree_host, client)).PassAs<Proxy>(); | 27 new SingleThreadProxy(layer_tree_host, client)).PassAs<Proxy>(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, | 30 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, |
| 31 LayerTreeHostSingleThreadClient* client) | 31 LayerTreeHostSingleThreadClient* client) |
| 32 : Proxy(NULL), | 32 : Proxy(NULL), |
| 33 layer_tree_host_(layer_tree_host), | 33 layer_tree_host_(layer_tree_host), |
| 34 client_(client), | 34 client_(client), |
| 35 next_frame_is_newly_committed_frame_(false), | 35 next_frame_is_newly_committed_frame_(false), |
| 36 inside_draw_(false) { | 36 inside_draw_(false), |
| 37 defer_commits_(false), | |
| 38 commit_was_deferred_(false), | |
| 39 commit_requested_(false), | |
| 40 weak_factory_(this) { | |
| 37 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 41 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 38 DCHECK(Proxy::IsMainThread()); | 42 DCHECK(Proxy::IsMainThread()); |
| 39 DCHECK(layer_tree_host); | 43 DCHECK(layer_tree_host); |
| 40 | 44 |
| 41 // Impl-side painting not supported without threaded compositing. | 45 // Impl-side painting not supported without threaded compositing. |
| 42 CHECK(!layer_tree_host->settings().impl_side_painting) | 46 CHECK(!layer_tree_host->settings().impl_side_painting) |
| 43 << "Threaded compositing must be enabled to use impl-side painting."; | 47 << "Threaded compositing must be enabled to use impl-side painting."; |
| 44 } | 48 } |
| 45 | 49 |
| 46 void SingleThreadProxy::Start() { | 50 void SingleThreadProxy::Start() { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 66 | 70 |
| 67 bool SingleThreadProxy::IsStarted() const { | 71 bool SingleThreadProxy::IsStarted() const { |
| 68 DCHECK(Proxy::IsMainThread()); | 72 DCHECK(Proxy::IsMainThread()); |
| 69 return layer_tree_host_impl_; | 73 return layer_tree_host_impl_; |
| 70 } | 74 } |
| 71 | 75 |
| 72 void SingleThreadProxy::SetLayerTreeHostClientReady() { | 76 void SingleThreadProxy::SetLayerTreeHostClientReady() { |
| 73 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); | 77 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
| 74 // Scheduling is controlled by the embedder in the single thread case, so | 78 // Scheduling is controlled by the embedder in the single thread case, so |
| 75 // nothing to do. | 79 // nothing to do. |
| 80 DCHECK(Proxy::IsMainThread()); | |
| 81 DebugScopedSetImplThread impl(this); | |
| 82 if (layer_tree_host_->settings().single_thread_proxy_scheduler && | |
| 83 !scheduler_on_impl_thread_) { | |
| 84 SchedulerSettings scheduler_settings(layer_tree_host_->settings()); | |
| 85 scheduler_on_impl_thread_ = Scheduler::Create(this, | |
| 86 scheduler_settings, | |
| 87 layer_tree_host_->id(), | |
| 88 MainThreadTaskRunner()); | |
| 89 scheduler_on_impl_thread_->SetCanStart(); | |
| 90 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | |
| 91 } | |
| 76 } | 92 } |
| 77 | 93 |
| 78 void SingleThreadProxy::SetVisible(bool visible) { | 94 void SingleThreadProxy::SetVisible(bool visible) { |
| 79 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); | 95 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); |
| 80 DebugScopedSetImplThread impl(this); | 96 DebugScopedSetImplThread impl(this); |
| 81 layer_tree_host_impl_->SetVisible(visible); | 97 layer_tree_host_impl_->SetVisible(visible); |
| 82 | 98 if (scheduler_on_impl_thread_) |
| 99 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | |
| 83 // Changing visibility could change ShouldComposite(). | 100 // Changing visibility could change ShouldComposite(). |
| 84 UpdateBackgroundAnimateTicking(); | 101 UpdateBackgroundAnimateTicking(); |
| 85 } | 102 } |
| 86 | 103 |
| 87 void SingleThreadProxy::CreateAndInitializeOutputSurface() { | 104 void SingleThreadProxy::CreateAndInitializeOutputSurface() { |
| 88 TRACE_EVENT0( | 105 TRACE_EVENT0( |
| 89 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); | 106 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); |
| 90 DCHECK(Proxy::IsMainThread()); | 107 DCHECK(Proxy::IsMainThread()); |
| 91 DCHECK(layer_tree_host_->output_surface_lost()); | 108 DCHECK(layer_tree_host_->output_surface_lost()); |
| 92 | 109 |
| 93 scoped_ptr<OutputSurface> output_surface = | 110 scoped_ptr<OutputSurface> output_surface = |
| 94 layer_tree_host_->CreateOutputSurface(); | 111 layer_tree_host_->CreateOutputSurface(); |
| 95 | 112 |
| 96 renderer_capabilities_for_main_thread_ = RendererCapabilities(); | 113 renderer_capabilities_for_main_thread_ = RendererCapabilities(); |
| 97 | 114 |
| 98 bool success = !!output_surface; | 115 bool success = !!output_surface; |
| 99 if (success) { | 116 if (success) { |
| 100 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 117 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 101 DebugScopedSetImplThread impl(this); | 118 DebugScopedSetImplThread impl(this); |
| 102 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 119 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
| 103 layer_tree_host_impl_->resource_provider()); | 120 layer_tree_host_impl_->resource_provider()); |
| 104 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); | 121 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); |
| 105 } | 122 } |
| 106 | 123 |
| 107 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); | 124 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
| 108 | 125 |
| 109 if (!success) { | 126 if (success) { |
| 110 // Force another recreation attempt to happen by requesting another commit. | 127 if (scheduler_on_impl_thread_) |
| 111 SetNeedsCommit(); | 128 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); |
| 129 } else if (Proxy::MainThreadTaskRunner()) { | |
| 130 Proxy::MainThreadTaskRunner()->PostTask( | |
| 131 FROM_HERE, | |
| 132 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, | |
| 133 weak_factory_.GetWeakPtr())); | |
| 112 } | 134 } |
| 113 } | 135 } |
| 114 | 136 |
| 115 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { | 137 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
| 116 DCHECK(Proxy::IsMainThread()); | 138 DCHECK(Proxy::IsMainThread()); |
| 117 DCHECK(!layer_tree_host_->output_surface_lost()); | 139 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 118 return renderer_capabilities_for_main_thread_; | 140 return renderer_capabilities_for_main_thread_; |
| 119 } | 141 } |
| 120 | 142 |
| 121 void SingleThreadProxy::SetNeedsAnimate() { | 143 void SingleThreadProxy::SetNeedsAnimate() { |
| 122 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); | 144 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); |
| 123 DCHECK(Proxy::IsMainThread()); | 145 DCHECK(Proxy::IsMainThread()); |
| 124 client_->ScheduleAnimation(); | 146 client_->ScheduleAnimation(); |
| 147 SetNeedsCommit(); | |
| 125 } | 148 } |
| 126 | 149 |
| 127 void SingleThreadProxy::SetNeedsUpdateLayers() { | 150 void SingleThreadProxy::SetNeedsUpdateLayers() { |
| 128 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); | 151 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
| 129 DCHECK(Proxy::IsMainThread()); | 152 DCHECK(Proxy::IsMainThread()); |
| 130 client_->ScheduleComposite(); | 153 SetNeedsCommit(); |
| 131 } | 154 } |
| 132 | 155 |
| 133 void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { | 156 void SingleThreadProxy::DoCommit(base::TimeTicks frame_begin_time) { |
| 134 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); | 157 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
| 135 DCHECK(Proxy::IsMainThread()); | 158 DCHECK(Proxy::IsMainThread()); |
| 159 layer_tree_host_->WillBeginMainFrame(); | |
| 160 layer_tree_host_->Layout(); | |
| 161 layer_tree_host_->AnimateLayers(frame_begin_time); | |
| 162 commit_requested_ = false; | |
| 163 | |
| 164 if (PrioritizedResourceManager* contents_texture_manager = | |
| 165 layer_tree_host_->contents_texture_manager()) { | |
| 166 contents_texture_manager->UnlinkAndClearEvictedBackings(); | |
| 167 contents_texture_manager->SetMaxMemoryLimitBytes( | |
| 168 layer_tree_host_impl_->memory_allocation_limit_bytes()); | |
| 169 contents_texture_manager->SetExternalPriorityCutoff( | |
| 170 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | |
| 171 } | |
| 172 | |
| 173 scoped_ptr<ResourceUpdateQueue> queue = | |
| 174 make_scoped_ptr(new ResourceUpdateQueue); | |
| 175 | |
| 176 layer_tree_host_->UpdateLayers(queue.get()); | |
| 177 | |
| 178 layer_tree_host_->WillCommit(); | |
| 179 | |
| 136 // Commit immediately. | 180 // Commit immediately. |
| 137 { | 181 { |
| 138 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 182 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 139 DebugScopedSetImplThread impl(this); | 183 DebugScopedSetImplThread impl(this); |
| 140 | 184 |
| 141 // This CapturePostTasks should be destroyed before CommitComplete() is | 185 // This CapturePostTasks should be destroyed before CommitComplete() is |
| 142 // called since that goes out to the embedder, and we want the embedder | 186 // called since that goes out to the embedder, and we want the embedder |
| 143 // to receive its callbacks before that. | 187 // to receive its callbacks before that. |
| 144 BlockingTaskRunner::CapturePostTasks blocked; | 188 BlockingTaskRunner::CapturePostTasks blocked; |
| 145 | 189 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 159 layer_tree_host_impl_->resource_provider()); | 203 layer_tree_host_impl_->resource_provider()); |
| 160 update_controller->Finalize(); | 204 update_controller->Finalize(); |
| 161 | 205 |
| 162 if (layer_tree_host_impl_->EvictedUIResourcesExist()) | 206 if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 163 layer_tree_host_->RecreateUIResources(); | 207 layer_tree_host_->RecreateUIResources(); |
| 164 | 208 |
| 165 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 209 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
| 166 | 210 |
| 167 layer_tree_host_impl_->CommitComplete(); | 211 layer_tree_host_impl_->CommitComplete(); |
| 168 | 212 |
| 213 UpdateBackgroundAnimateTicking(); | |
| 214 | |
| 169 #if DCHECK_IS_ON | 215 #if DCHECK_IS_ON |
| 170 // In the single-threaded case, the scale and scroll deltas should never be | 216 // In the single-threaded case, the scale and scroll deltas should never be |
| 171 // touched on the impl layer tree. | 217 // touched on the impl layer tree. |
| 172 scoped_ptr<ScrollAndScaleSet> scroll_info = | 218 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 173 layer_tree_host_impl_->ProcessScrollDeltas(); | 219 layer_tree_host_impl_->ProcessScrollDeltas(); |
| 174 DCHECK(!scroll_info->scrolls.size()); | 220 DCHECK(!scroll_info->scrolls.size()); |
| 175 DCHECK_EQ(1.f, scroll_info->page_scale_delta); | 221 DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
| 176 #endif | 222 #endif |
| 177 | 223 |
| 178 RenderingStatsInstrumentation* stats_instrumentation = | 224 RenderingStatsInstrumentation* stats_instrumentation = |
| 179 layer_tree_host_->rendering_stats_instrumentation(); | 225 layer_tree_host_->rendering_stats_instrumentation(); |
| 180 BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent( | 226 BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent( |
| 181 stats_instrumentation->main_thread_rendering_stats()); | 227 stats_instrumentation->main_thread_rendering_stats()); |
| 182 stats_instrumentation->AccumulateAndClearMainThreadStats(); | 228 stats_instrumentation->AccumulateAndClearMainThreadStats(); |
| 183 } | 229 } |
| 184 layer_tree_host_->CommitComplete(); | 230 layer_tree_host_->CommitComplete(); |
| 231 layer_tree_host_->DidBeginMainFrame(); | |
| 232 timing_history_.DidCommit(); | |
| 233 | |
| 185 next_frame_is_newly_committed_frame_ = true; | 234 next_frame_is_newly_committed_frame_ = true; |
| 186 } | 235 } |
| 187 | 236 |
| 188 void SingleThreadProxy::SetNeedsCommit() { | 237 void SingleThreadProxy::SetNeedsCommit() { |
| 189 DCHECK(Proxy::IsMainThread()); | 238 DCHECK(Proxy::IsMainThread()); |
| 239 DebugScopedSetImplThread impl(this); | |
| 190 client_->ScheduleComposite(); | 240 client_->ScheduleComposite(); |
| 241 if (scheduler_on_impl_thread_) | |
| 242 scheduler_on_impl_thread_->SetNeedsCommit(); | |
| 243 commit_requested_ = true; | |
| 191 } | 244 } |
| 192 | 245 |
| 193 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { | 246 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
| 194 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); | 247 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
| 248 DCHECK(Proxy::IsMainThread()); | |
| 249 DebugScopedSetImplThread impl(this); | |
| 250 client_->ScheduleComposite(); | |
| 195 SetNeedsRedrawRectOnImplThread(damage_rect); | 251 SetNeedsRedrawRectOnImplThread(damage_rect); |
| 196 client_->ScheduleComposite(); | |
| 197 } | 252 } |
| 198 | 253 |
| 199 void SingleThreadProxy::SetNextCommitWaitsForActivation() { | 254 void SingleThreadProxy::SetNextCommitWaitsForActivation() { |
| 200 // There is no activation here other than commit. So do nothing. | 255 // There is no activation here other than commit. So do nothing. |
| 256 DCHECK(Proxy::IsMainThread()); | |
| 201 } | 257 } |
| 202 | 258 |
| 203 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { | 259 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
| 204 // Thread-only feature. | 260 DCHECK(Proxy::IsMainThread()); |
| 205 NOTREACHED(); | 261 // Deferring commits only makes sense if there's a scheduler. |
| 262 if (!scheduler_on_impl_thread_) | |
|
enne (OOO)
2014/06/27 19:16:51
This has to not be a DCHECK anymore because the sc
| |
| 263 return; | |
| 264 if (defer_commits_ == defer_commits) | |
| 265 return; | |
| 266 | |
| 267 if (defer_commits) | |
| 268 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this); | |
| 269 else | |
| 270 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this); | |
| 271 | |
| 272 defer_commits_ = defer_commits; | |
| 273 if (!defer_commits_ && commit_was_deferred_) { | |
| 274 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | |
| 275 scheduler_on_impl_thread_->NotifyReadyToCommit(); | |
| 276 commit_was_deferred_ = false; | |
| 277 } | |
| 206 } | 278 } |
| 207 | 279 |
| 208 bool SingleThreadProxy::CommitRequested() const { return false; } | 280 bool SingleThreadProxy::CommitRequested() const { |
| 281 DCHECK(Proxy::IsMainThread()); | |
| 282 return commit_requested_; | |
| 283 } | |
| 209 | 284 |
| 210 bool SingleThreadProxy::BeginMainFrameRequested() const { return false; } | 285 bool SingleThreadProxy::BeginMainFrameRequested() const { |
| 286 DCHECK(Proxy::IsMainThread()); | |
| 287 return commit_requested_; | |
| 288 } | |
| 211 | 289 |
| 212 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { | 290 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
| 213 return std::numeric_limits<size_t>::max(); | 291 return std::numeric_limits<size_t>::max(); |
| 214 } | 292 } |
| 215 | 293 |
| 216 void SingleThreadProxy::Stop() { | 294 void SingleThreadProxy::Stop() { |
| 217 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); | 295 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
| 218 DCHECK(Proxy::IsMainThread()); | 296 DCHECK(Proxy::IsMainThread()); |
| 219 { | 297 { |
| 220 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 298 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 221 DebugScopedSetImplThread impl(this); | 299 DebugScopedSetImplThread impl(this); |
| 222 | 300 |
| 223 BlockingTaskRunner::CapturePostTasks blocked; | 301 BlockingTaskRunner::CapturePostTasks blocked; |
| 224 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 302 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
| 225 layer_tree_host_impl_->resource_provider()); | 303 layer_tree_host_impl_->resource_provider()); |
| 304 scheduler_on_impl_thread_.reset(); | |
| 226 layer_tree_host_impl_.reset(); | 305 layer_tree_host_impl_.reset(); |
| 227 } | 306 } |
| 228 layer_tree_host_ = NULL; | 307 layer_tree_host_ = NULL; |
| 229 } | 308 } |
| 230 | 309 |
| 231 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 310 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
| 232 TRACE_EVENT1( | 311 TRACE_EVENT1( |
| 233 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 312 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
| 234 DCHECK(Proxy::IsImplThread()); | 313 DCHECK(Proxy::IsImplThread()); |
| 235 UpdateBackgroundAnimateTicking(); | 314 UpdateBackgroundAnimateTicking(); |
| 315 if (scheduler_on_impl_thread_) | |
| 316 scheduler_on_impl_thread_->SetCanDraw(can_draw); | |
| 236 } | 317 } |
| 237 | 318 |
| 238 void SingleThreadProxy::NotifyReadyToActivate() { | 319 void SingleThreadProxy::NotifyReadyToActivate() { |
| 239 // Thread-only feature. | 320 // Impl-side painting only. |
| 240 NOTREACHED(); | 321 NOTREACHED(); |
| 241 } | 322 } |
| 242 | 323 |
| 243 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { | 324 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
| 244 client_->ScheduleComposite(); | 325 client_->ScheduleComposite(); |
| 326 if (scheduler_on_impl_thread_) | |
| 327 scheduler_on_impl_thread_->SetNeedsRedraw(); | |
| 245 } | 328 } |
| 246 | 329 |
| 247 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { | 330 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
| 248 SetNeedsRedrawOnImplThread(); | 331 SetNeedsRedrawOnImplThread(); |
| 249 } | 332 } |
| 250 | 333 |
| 251 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { | 334 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
| 252 // Thread-only/Impl-side-painting-only feature. | 335 // Impl-side painting only. |
| 253 NOTREACHED(); | 336 NOTREACHED(); |
| 254 } | 337 } |
| 255 | 338 |
| 256 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( | 339 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
| 257 const gfx::Rect& damage_rect) { | 340 const gfx::Rect& damage_rect) { |
| 258 // TODO(brianderson): Once we move render_widget scheduling into this class, | |
| 259 // we can treat redraw requests more efficiently than CommitAndRedraw | |
| 260 // requests. | |
| 261 layer_tree_host_impl_->SetViewportDamage(damage_rect); | 341 layer_tree_host_impl_->SetViewportDamage(damage_rect); |
| 262 SetNeedsCommit(); | 342 SetNeedsRedrawOnImplThread(); |
| 263 } | 343 } |
| 264 | 344 |
| 265 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { | 345 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
| 266 // Impl-side painting only. | 346 // Impl-side painting only. |
| 267 NOTREACHED(); | 347 NOTREACHED(); |
| 268 } | 348 } |
| 269 | 349 |
| 270 void SingleThreadProxy::SetNeedsCommitOnImplThread() { | 350 void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
| 271 client_->ScheduleComposite(); | 351 client_->ScheduleComposite(); |
| 352 if (scheduler_on_impl_thread_) | |
| 353 scheduler_on_impl_thread_->SetNeedsCommit(); | |
| 272 } | 354 } |
| 273 | 355 |
| 274 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 356 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
| 275 scoped_ptr<AnimationEventsVector> events) { | 357 scoped_ptr<AnimationEventsVector> events) { |
| 276 TRACE_EVENT0( | 358 TRACE_EVENT0( |
| 277 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); | 359 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
| 278 DCHECK(Proxy::IsImplThread()); | 360 DCHECK(Proxy::IsImplThread()); |
| 279 DebugScopedSetMainThread main(this); | 361 DebugScopedSetMainThread main(this); |
| 280 layer_tree_host_->SetAnimationEvents(events.Pass()); | 362 layer_tree_host_->SetAnimationEvents(events.Pass()); |
| 281 } | 363 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 298 } | 380 } |
| 299 | 381 |
| 300 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 382 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
| 301 | 383 |
| 302 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { | 384 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
| 303 DCHECK(IsImplThread()); | 385 DCHECK(IsImplThread()); |
| 304 renderer_capabilities_for_main_thread_ = | 386 renderer_capabilities_for_main_thread_ = |
| 305 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); | 387 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
| 306 } | 388 } |
| 307 | 389 |
| 390 void SingleThreadProxy::DidActivatePendingTree() { | |
| 391 // Impl-side painting only. | |
| 392 NOTREACHED(); | |
| 393 } | |
| 394 | |
| 395 void SingleThreadProxy::DidManageTiles() { | |
| 396 // Impl-side painting only. | |
| 397 NOTREACHED(); | |
| 398 } | |
| 399 | |
| 308 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 400 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
| 309 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 401 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
| 310 // Cause a commit so we can notice the lost context. | 402 { |
| 311 SetNeedsCommitOnImplThread(); | 403 DebugScopedSetMainThread main(this); |
| 404 // This must happen before we notify the scheduler as it may try to recreate | |
| 405 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. | |
| 406 layer_tree_host_->DidLoseOutputSurface(); | |
| 407 } | |
| 312 client_->DidAbortSwapBuffers(); | 408 client_->DidAbortSwapBuffers(); |
| 409 if (scheduler_on_impl_thread_) | |
| 410 scheduler_on_impl_thread_->DidLoseOutputSurface(); | |
| 313 } | 411 } |
| 314 | 412 |
| 315 void SingleThreadProxy::DidSwapBuffersOnImplThread() { | 413 void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
| 414 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); | |
| 415 if (scheduler_on_impl_thread_) | |
| 416 scheduler_on_impl_thread_->DidSwapBuffers(); | |
| 316 client_->DidPostSwapBuffers(); | 417 client_->DidPostSwapBuffers(); |
| 317 } | 418 } |
| 318 | 419 |
| 319 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { | 420 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
| 320 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 421 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
| 321 client_->DidCompleteSwapBuffers(); | 422 if (scheduler_on_impl_thread_) |
| 423 scheduler_on_impl_thread_->DidSwapBuffersComplete(); | |
| 424 layer_tree_host_->DidCompleteSwapBuffers(); | |
| 322 } | 425 } |
| 323 | 426 |
| 324 // Called by the legacy scheduling path (e.g. where render_widget does the | 427 void SingleThreadProxy::BeginFrame(const BeginFrameArgs& args) { |
| 325 // scheduling) | 428 TRACE_EVENT0("cc", "SingleThreadProxy::BeginFrame"); |
| 429 if (scheduler_on_impl_thread_) | |
| 430 scheduler_on_impl_thread_->BeginImplFrame(args); | |
| 431 } | |
| 432 | |
| 326 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 433 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
| 327 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); | 434 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); |
| 328 DCHECK(Proxy::IsMainThread()); | 435 DCHECK(Proxy::IsMainThread()); |
| 329 DCHECK(!layer_tree_host_->output_surface_lost()); | 436 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 330 | 437 |
| 331 layer_tree_host_->AnimateLayers(frame_begin_time); | 438 DoCommit(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(); | |
| 348 | 439 |
| 349 LayerTreeHostImpl::FrameData frame; | 440 LayerTreeHostImpl::FrameData frame; |
| 350 if (DoComposite(frame_begin_time, &frame)) { | 441 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 } | |
| 368 } | 442 } |
| 369 | 443 |
| 370 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { | 444 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
| 371 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 445 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 372 { | 446 { |
| 373 // The following line casts away const modifiers because it is just | 447 // The following line casts away const modifiers because it is just |
| 374 // setting debug state. We still want the AsValue() function and its | 448 // setting debug state. We still want the AsValue() function and its |
| 375 // call chain to be const throughout. | 449 // call chain to be const throughout. |
| 376 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 450 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
| 377 | 451 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 396 return layer_tree_host_impl_->visible() && | 470 return layer_tree_host_impl_->visible() && |
| 397 layer_tree_host_impl_->CanDraw(); | 471 layer_tree_host_impl_->CanDraw(); |
| 398 } | 472 } |
| 399 | 473 |
| 400 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { | 474 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { |
| 401 DCHECK(Proxy::IsImplThread()); | 475 DCHECK(Proxy::IsImplThread()); |
| 402 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | 476 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
| 403 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); | 477 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
| 404 } | 478 } |
| 405 | 479 |
| 406 bool SingleThreadProxy::DoComposite( | 480 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
| 407 base::TimeTicks frame_begin_time, | 481 LayerTreeHostImpl::FrameData* frame) { |
| 408 LayerTreeHostImpl::FrameData* frame) { | |
| 409 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 482 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
| 410 DCHECK(!layer_tree_host_->output_surface_lost()); | 483 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 411 | 484 |
| 412 bool lost_output_surface = false; | |
| 413 { | 485 { |
| 414 DebugScopedSetImplThread impl(this); | 486 DebugScopedSetImplThread impl(this); |
| 415 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 487 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 416 | 488 |
| 417 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 489 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 418 // frame, so can only be used when such a frame is possible. Since | 490 // frame, so can only be used when such a frame is possible. Since |
| 419 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 491 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 420 // CanDraw() as well. | 492 // CanDraw() as well. |
| 421 if (!ShouldComposite()) { | 493 if (!ShouldComposite()) { |
| 422 UpdateBackgroundAnimateTicking(); | 494 UpdateBackgroundAnimateTicking(); |
| 423 return false; | 495 return DRAW_ABORTED_CANT_DRAW; |
| 424 } | 496 } |
| 425 | 497 |
| 498 timing_history_.DidStartDrawing(); | |
| 499 | |
| 426 layer_tree_host_impl_->Animate( | 500 layer_tree_host_impl_->Animate( |
| 427 layer_tree_host_impl_->CurrentFrameTimeTicks()); | 501 layer_tree_host_impl_->CurrentFrameTimeTicks()); |
| 428 UpdateBackgroundAnimateTicking(); | 502 UpdateBackgroundAnimateTicking(); |
| 429 | 503 |
| 430 if (!layer_tree_host_impl_->IsContextLost()) { | 504 if (!layer_tree_host_impl_->IsContextLost()) { |
| 431 layer_tree_host_impl_->PrepareToDraw(frame); | 505 layer_tree_host_impl_->PrepareToDraw(frame); |
| 432 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 506 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
| 433 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 507 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
| 434 } | 508 } |
| 435 lost_output_surface = layer_tree_host_impl_->IsContextLost(); | |
| 436 | 509 |
| 437 bool start_ready_animations = true; | 510 bool start_ready_animations = true; |
| 438 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 511 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
| 439 | 512 |
| 440 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | 513 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
| 514 | |
| 515 timing_history_.DidFinishDrawing(); | |
| 441 } | 516 } |
| 442 | 517 |
| 443 if (lost_output_surface) { | 518 { |
| 444 layer_tree_host_->DidLoseOutputSurface(); | 519 DebugScopedSetImplThread impl(this); |
| 445 return false; | 520 |
| 521 if (layer_tree_host_impl_->IsContextLost()) { | |
| 522 DidLoseOutputSurfaceOnImplThread(); | |
| 523 } else { | |
| 524 // This CapturePostTasks should be destroyed before | |
| 525 // DidCommitAndDrawFrame() is called since that goes out to the embedder, | |
| 526 // and we want the embedder to receive its callbacks before that. | |
| 527 // NOTE: This maintains consistent ordering with the ThreadProxy since | |
| 528 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread | |
| 529 // there as the main thread is not blocked, so any posted tasks inside | |
| 530 // the swap buffers will execute first. | |
| 531 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
| 532 | |
| 533 BlockingTaskRunner::CapturePostTasks blocked; | |
| 534 layer_tree_host_impl_->SwapBuffers(*frame); | |
| 535 } | |
| 446 } | 536 } |
| 537 DidCommitAndDrawFrame(); | |
| 447 | 538 |
| 448 return true; | 539 return DRAW_SUCCESS; |
| 449 } | 540 } |
| 450 | 541 |
| 451 void SingleThreadProxy::DidSwapFrame() { | 542 void SingleThreadProxy::DidCommitAndDrawFrame() { |
| 452 if (next_frame_is_newly_committed_frame_) { | 543 if (next_frame_is_newly_committed_frame_) { |
| 544 DebugScopedSetMainThread main(this); | |
| 453 next_frame_is_newly_committed_frame_ = false; | 545 next_frame_is_newly_committed_frame_ = false; |
| 454 layer_tree_host_->DidCommitAndDrawFrame(); | 546 layer_tree_host_->DidCommitAndDrawFrame(); |
| 455 } | 547 } |
| 456 } | 548 } |
| 457 | 549 |
| 458 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 550 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
| 459 | 551 |
| 552 scoped_ptr<base::Value> SingleThreadProxy::SchedulerAsValueForTesting() { | |
| 553 DebugScopedSetImplThread impl(this); | |
| 554 if (!scheduler_on_impl_thread_) | |
| 555 return make_scoped_ptr(base::Value::CreateNullValue()).Pass(); | |
| 556 return scheduler_on_impl_thread_->AsValue().Pass(); | |
| 557 } | |
| 558 | |
| 559 void SingleThreadProxy::SetNeedsBeginFrame(bool enable) { | |
| 560 layer_tree_host_impl_->SetNeedsBeginFrame(enable); | |
| 561 } | |
| 562 | |
| 563 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { | |
| 564 layer_tree_host_impl_->WillBeginImplFrame(args); | |
| 565 } | |
| 566 | |
| 567 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { | |
| 568 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); | |
| 569 if (defer_commits_) { | |
| 570 DCHECK(!commit_was_deferred_); | |
| 571 commit_was_deferred_ = true; | |
| 572 layer_tree_host_->DidDeferCommit(); | |
| 573 return; | |
| 574 } | |
| 575 timing_history_.DidBeginMainFrame(); | |
| 576 | |
| 577 DCHECK(scheduler_on_impl_thread_); | |
| 578 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | |
| 579 scheduler_on_impl_thread_->NotifyReadyToCommit(); | |
| 580 } | |
| 581 | |
| 582 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | |
| 583 DebugScopedSetImplThread impl(this); | |
| 584 if (layer_tree_host_impl_->IsContextLost()) { | |
| 585 DidCommitAndDrawFrame(); | |
| 586 return DRAW_SUCCESS; | |
| 587 } | |
| 588 | |
| 589 LayerTreeHostImpl::FrameData frame; | |
| 590 return DoComposite(layer_tree_host_impl_->CurrentFrameTimeTicks(), &frame); | |
| 591 } | |
| 592 | |
| 593 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { | |
| 594 NOTREACHED(); | |
| 595 return INVALID_RESULT; | |
| 596 } | |
| 597 | |
| 598 void SingleThreadProxy::ScheduledActionCommit() { | |
| 599 DebugScopedSetMainThread main(this); | |
| 600 DoCommit(layer_tree_host_impl_->CurrentFrameTimeTicks()); | |
| 601 } | |
| 602 | |
| 603 void SingleThreadProxy::ScheduledActionAnimate() { | |
| 604 TRACE_EVENT0("cc", "ScheduledActionAnimate"); | |
| 605 layer_tree_host_impl_->Animate( | |
| 606 layer_tree_host_impl_->CurrentFrameTimeTicks()); | |
| 607 } | |
| 608 | |
| 609 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { | |
| 610 // Impl-side painting only. | |
| 611 NOTREACHED(); | |
| 612 } | |
| 613 | |
| 614 void SingleThreadProxy::ScheduledActionActivatePendingTree() { | |
| 615 // Impl-side painting only. | |
| 616 NOTREACHED(); | |
| 617 } | |
| 618 | |
| 619 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | |
| 620 DebugScopedSetMainThread main(this); | |
| 621 DCHECK(scheduler_on_impl_thread_); | |
| 622 // If possible, create the output surface in a post task. Synchronously | |
| 623 // creating the output surface makes tests more awkward since this differs | |
| 624 // from the ThreadProxy behavior. However, sometimes there is no | |
| 625 // task runner. | |
| 626 if (Proxy::MainThreadTaskRunner()) { | |
| 627 Proxy::MainThreadTaskRunner()->PostTask( | |
| 628 FROM_HERE, | |
| 629 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, | |
| 630 weak_factory_.GetWeakPtr())); | |
| 631 } else { | |
| 632 CreateAndInitializeOutputSurface(); | |
| 633 } | |
| 634 } | |
| 635 | |
| 636 void SingleThreadProxy::ScheduledActionManageTiles() { | |
| 637 // Impl-side painting only. | |
| 638 NOTREACHED(); | |
| 639 } | |
| 640 | |
| 641 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | |
| 642 } | |
| 643 | |
| 644 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { | |
| 645 return timing_history_.DrawDurationEstimate(); | |
| 646 } | |
| 647 | |
| 648 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { | |
| 649 return timing_history_.BeginMainFrameToCommitDurationEstimate(); | |
| 650 } | |
| 651 | |
| 652 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { | |
| 653 return timing_history_.CommitToActivateDurationEstimate(); | |
| 654 } | |
| 655 | |
| 656 void SingleThreadProxy::DidBeginImplFrameDeadline() { | |
| 657 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
| 658 } | |
| 659 | |
| 460 } // namespace cc | 660 } // namespace cc |
| OLD | NEW |