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, | |
|
brianderson
2014/06/20 23:08:12
Is this a tight polling mechanism? What happens if
danakj
2014/06/20 23:15:30
That's inside layer_tree_host_->OnCreateAndInitial
| |
| 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 DCHECK(scheduler_on_impl_thread_); |
| 262 if (defer_commits_ == defer_commits) | |
| 263 return; | |
| 264 | |
| 265 if (defer_commits) | |
| 266 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this); | |
| 267 else | |
| 268 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this); | |
| 269 | |
| 270 defer_commits_ = defer_commits; | |
| 271 if (!defer_commits_ && commit_was_deferred_) { | |
| 272 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | |
| 273 scheduler_on_impl_thread_->NotifyReadyToCommit(); | |
| 274 commit_was_deferred_ = false; | |
| 275 } | |
| 206 } | 276 } |
| 207 | 277 |
| 208 bool SingleThreadProxy::CommitRequested() const { return false; } | 278 bool SingleThreadProxy::CommitRequested() const { |
| 279 DCHECK(Proxy::IsMainThread()); | |
| 280 return commit_requested_; | |
| 281 } | |
| 209 | 282 |
| 210 bool SingleThreadProxy::BeginMainFrameRequested() const { return false; } | 283 bool SingleThreadProxy::BeginMainFrameRequested() const { |
| 284 DCHECK(Proxy::IsMainThread()); | |
| 285 return commit_requested_; | |
| 286 } | |
| 211 | 287 |
| 212 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { | 288 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
| 213 return std::numeric_limits<size_t>::max(); | 289 return std::numeric_limits<size_t>::max(); |
| 214 } | 290 } |
| 215 | 291 |
| 216 void SingleThreadProxy::Stop() { | 292 void SingleThreadProxy::Stop() { |
| 217 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); | 293 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
| 218 DCHECK(Proxy::IsMainThread()); | 294 DCHECK(Proxy::IsMainThread()); |
| 219 { | 295 { |
| 220 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 296 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 221 DebugScopedSetImplThread impl(this); | 297 DebugScopedSetImplThread impl(this); |
| 222 | 298 |
| 223 BlockingTaskRunner::CapturePostTasks blocked; | 299 BlockingTaskRunner::CapturePostTasks blocked; |
| 224 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 300 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
| 225 layer_tree_host_impl_->resource_provider()); | 301 layer_tree_host_impl_->resource_provider()); |
| 302 scheduler_on_impl_thread_.reset(); | |
| 226 layer_tree_host_impl_.reset(); | 303 layer_tree_host_impl_.reset(); |
| 227 } | 304 } |
| 228 layer_tree_host_ = NULL; | 305 layer_tree_host_ = NULL; |
| 229 } | 306 } |
| 230 | 307 |
| 231 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 308 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
| 232 TRACE_EVENT1( | 309 TRACE_EVENT1( |
| 233 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 310 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
| 234 DCHECK(Proxy::IsImplThread()); | 311 DCHECK(Proxy::IsImplThread()); |
| 235 UpdateBackgroundAnimateTicking(); | 312 UpdateBackgroundAnimateTicking(); |
| 313 if (scheduler_on_impl_thread_) | |
| 314 scheduler_on_impl_thread_->SetCanDraw(can_draw); | |
| 236 } | 315 } |
| 237 | 316 |
| 238 void SingleThreadProxy::NotifyReadyToActivate() { | 317 void SingleThreadProxy::NotifyReadyToActivate() { |
| 239 // Thread-only feature. | 318 // Impl-side painting only. |
| 240 NOTREACHED(); | 319 NOTREACHED(); |
| 241 } | 320 } |
| 242 | 321 |
| 243 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { | 322 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
| 244 client_->ScheduleComposite(); | 323 client_->ScheduleComposite(); |
| 324 if (scheduler_on_impl_thread_) | |
| 325 scheduler_on_impl_thread_->SetNeedsRedraw(); | |
| 245 } | 326 } |
| 246 | 327 |
| 247 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { | 328 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
| 248 SetNeedsRedrawOnImplThread(); | 329 SetNeedsRedrawOnImplThread(); |
| 249 } | 330 } |
| 250 | 331 |
| 251 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { | 332 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
| 252 // Thread-only/Impl-side-painting-only feature. | 333 // Impl-side painting only. |
| 253 NOTREACHED(); | 334 NOTREACHED(); |
| 254 } | 335 } |
| 255 | 336 |
| 256 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( | 337 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
| 257 const gfx::Rect& damage_rect) { | 338 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); | 339 layer_tree_host_impl_->SetViewportDamage(damage_rect); |
| 262 SetNeedsCommit(); | 340 SetNeedsRedrawOnImplThread(); |
| 263 } | 341 } |
| 264 | 342 |
| 265 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { | 343 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
| 266 // Impl-side painting only. | 344 // Impl-side painting only. |
| 267 NOTREACHED(); | 345 NOTREACHED(); |
| 268 } | 346 } |
| 269 | 347 |
| 270 void SingleThreadProxy::SetNeedsCommitOnImplThread() { | 348 void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
| 271 client_->ScheduleComposite(); | 349 client_->ScheduleComposite(); |
| 350 if (scheduler_on_impl_thread_) | |
| 351 scheduler_on_impl_thread_->SetNeedsCommit(); | |
| 272 } | 352 } |
| 273 | 353 |
| 274 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 354 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
| 275 scoped_ptr<AnimationEventsVector> events) { | 355 scoped_ptr<AnimationEventsVector> events) { |
| 276 TRACE_EVENT0( | 356 TRACE_EVENT0( |
| 277 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); | 357 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
| 278 DCHECK(Proxy::IsImplThread()); | 358 DCHECK(Proxy::IsImplThread()); |
| 279 DebugScopedSetMainThread main(this); | 359 DebugScopedSetMainThread main(this); |
| 280 layer_tree_host_->SetAnimationEvents(events.Pass()); | 360 layer_tree_host_->SetAnimationEvents(events.Pass()); |
| 281 } | 361 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 298 } | 378 } |
| 299 | 379 |
| 300 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 380 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
| 301 | 381 |
| 302 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { | 382 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
| 303 DCHECK(IsImplThread()); | 383 DCHECK(IsImplThread()); |
| 304 renderer_capabilities_for_main_thread_ = | 384 renderer_capabilities_for_main_thread_ = |
| 305 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); | 385 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
| 306 } | 386 } |
| 307 | 387 |
| 388 void SingleThreadProxy::DidActivatePendingTree() { | |
| 389 // Impl-side painting only. | |
| 390 NOTREACHED(); | |
| 391 } | |
| 392 | |
| 393 void SingleThreadProxy::DidManageTiles() { | |
| 394 // Impl-side painting only. | |
| 395 NOTREACHED(); | |
| 396 } | |
| 397 | |
| 308 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 398 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
| 309 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 399 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
| 310 // Cause a commit so we can notice the lost context. | 400 { |
| 311 SetNeedsCommitOnImplThread(); | 401 DebugScopedSetMainThread main(this); |
| 402 // This must happen before we notify the scheduler as it may try to recreate | |
| 403 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. | |
| 404 layer_tree_host_->DidLoseOutputSurface(); | |
| 405 } | |
| 312 client_->DidAbortSwapBuffers(); | 406 client_->DidAbortSwapBuffers(); |
| 407 if (scheduler_on_impl_thread_) | |
| 408 scheduler_on_impl_thread_->DidLoseOutputSurface(); | |
| 313 } | 409 } |
| 314 | 410 |
| 315 void SingleThreadProxy::DidSwapBuffersOnImplThread() { | 411 void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
| 412 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); | |
| 413 if (scheduler_on_impl_thread_) | |
| 414 scheduler_on_impl_thread_->DidSwapBuffers(); | |
| 316 client_->DidPostSwapBuffers(); | 415 client_->DidPostSwapBuffers(); |
| 317 } | 416 } |
| 318 | 417 |
| 319 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { | 418 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
| 320 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 419 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
| 321 client_->DidCompleteSwapBuffers(); | 420 if (scheduler_on_impl_thread_) |
| 421 scheduler_on_impl_thread_->DidSwapBuffersComplete(); | |
| 422 layer_tree_host_->DidCompleteSwapBuffers(); | |
| 322 } | 423 } |
| 323 | 424 |
| 324 // Called by the legacy scheduling path (e.g. where render_widget does the | 425 void SingleThreadProxy::BeginFrame(const BeginFrameArgs& args) { |
| 325 // scheduling) | 426 TRACE_EVENT0("cc", "SingleThreadProxy::BeginFrame"); |
| 427 if (scheduler_on_impl_thread_) | |
| 428 scheduler_on_impl_thread_->BeginImplFrame(args); | |
| 429 } | |
| 430 | |
| 326 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 431 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
| 327 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); | 432 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); |
| 328 DCHECK(Proxy::IsMainThread()); | 433 DCHECK(Proxy::IsMainThread()); |
| 329 DCHECK(!layer_tree_host_->output_surface_lost()); | 434 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 330 | 435 |
| 331 layer_tree_host_->AnimateLayers(frame_begin_time); | 436 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 | 437 |
| 349 LayerTreeHostImpl::FrameData frame; | 438 LayerTreeHostImpl::FrameData frame; |
| 350 if (DoComposite(frame_begin_time, &frame)) { | 439 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 } | 440 } |
| 369 | 441 |
| 370 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { | 442 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
| 371 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 443 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 372 { | 444 { |
| 373 // The following line casts away const modifiers because it is just | 445 // The following line casts away const modifiers because it is just |
| 374 // setting debug state. We still want the AsValue() function and its | 446 // setting debug state. We still want the AsValue() function and its |
| 375 // call chain to be const throughout. | 447 // call chain to be const throughout. |
| 376 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 448 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
| 377 | 449 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 396 return layer_tree_host_impl_->visible() && | 468 return layer_tree_host_impl_->visible() && |
| 397 layer_tree_host_impl_->CanDraw(); | 469 layer_tree_host_impl_->CanDraw(); |
| 398 } | 470 } |
| 399 | 471 |
| 400 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { | 472 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { |
| 401 DCHECK(Proxy::IsImplThread()); | 473 DCHECK(Proxy::IsImplThread()); |
| 402 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | 474 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
| 403 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); | 475 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
| 404 } | 476 } |
| 405 | 477 |
| 406 bool SingleThreadProxy::DoComposite( | 478 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
| 407 base::TimeTicks frame_begin_time, | 479 LayerTreeHostImpl::FrameData* frame) { |
| 408 LayerTreeHostImpl::FrameData* frame) { | |
| 409 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 480 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
| 410 DCHECK(!layer_tree_host_->output_surface_lost()); | 481 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 411 | 482 |
| 412 bool lost_output_surface = false; | |
| 413 { | 483 { |
| 414 DebugScopedSetImplThread impl(this); | 484 DebugScopedSetImplThread impl(this); |
| 415 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 485 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 416 | 486 |
| 417 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 487 // 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 | 488 // 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 | 489 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 420 // CanDraw() as well. | 490 // CanDraw() as well. |
| 421 if (!ShouldComposite()) { | 491 if (!ShouldComposite()) { |
| 422 UpdateBackgroundAnimateTicking(); | 492 UpdateBackgroundAnimateTicking(); |
| 423 return false; | 493 return DRAW_ABORTED_CANT_DRAW; |
| 424 } | 494 } |
| 425 | 495 |
| 496 timing_history_.DidStartDrawing(); | |
| 497 | |
| 426 layer_tree_host_impl_->Animate( | 498 layer_tree_host_impl_->Animate( |
| 427 layer_tree_host_impl_->CurrentFrameTimeTicks()); | 499 layer_tree_host_impl_->CurrentFrameTimeTicks()); |
| 428 UpdateBackgroundAnimateTicking(); | 500 UpdateBackgroundAnimateTicking(); |
| 429 | 501 |
| 430 if (!layer_tree_host_impl_->IsContextLost()) { | 502 if (!layer_tree_host_impl_->IsContextLost()) { |
| 431 layer_tree_host_impl_->PrepareToDraw(frame); | 503 layer_tree_host_impl_->PrepareToDraw(frame); |
| 432 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 504 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
| 433 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 505 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
| 434 } | 506 } |
| 435 lost_output_surface = layer_tree_host_impl_->IsContextLost(); | |
| 436 | 507 |
| 437 bool start_ready_animations = true; | 508 bool start_ready_animations = true; |
| 438 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 509 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
| 439 | 510 |
| 440 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | 511 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
| 512 | |
| 513 timing_history_.DidFinishDrawing(); | |
| 441 } | 514 } |
| 442 | 515 |
| 443 if (lost_output_surface) { | 516 { |
| 444 layer_tree_host_->DidLoseOutputSurface(); | 517 DebugScopedSetImplThread impl(this); |
| 445 return false; | 518 |
| 519 if (layer_tree_host_impl_->IsContextLost()) { | |
| 520 DidLoseOutputSurfaceOnImplThread(); | |
| 521 } else { | |
| 522 // This CapturePostTasks should be destroyed before | |
| 523 // DidCommitAndDrawFrame() is called since that goes out to the embedder, | |
| 524 // and we want the embedder to receive its callbacks before that. | |
| 525 // NOTE: This maintains consistent ordering with the ThreadProxy since | |
| 526 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread | |
| 527 // there as the main thread is not blocked, so any posted tasks inside | |
| 528 // the swap buffers will execute first. | |
| 529 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
| 530 | |
| 531 BlockingTaskRunner::CapturePostTasks blocked; | |
|
brianderson
2014/06/20 23:08:12
Is this only needed for the PostSwapBuffersComplet
danakj
2014/06/20 23:15:30
This is for releasing resources from ResourceProvi
| |
| 532 layer_tree_host_impl_->SwapBuffers(*frame); | |
| 533 } | |
| 446 } | 534 } |
| 535 DidCommitAndDrawFrame(); | |
| 447 | 536 |
| 448 return true; | 537 return DRAW_SUCCESS; |
| 449 } | 538 } |
| 450 | 539 |
| 451 void SingleThreadProxy::DidSwapFrame() { | 540 void SingleThreadProxy::DidCommitAndDrawFrame() { |
| 452 if (next_frame_is_newly_committed_frame_) { | 541 if (next_frame_is_newly_committed_frame_) { |
| 542 DebugScopedSetMainThread main(this); | |
| 453 next_frame_is_newly_committed_frame_ = false; | 543 next_frame_is_newly_committed_frame_ = false; |
| 454 layer_tree_host_->DidCommitAndDrawFrame(); | 544 layer_tree_host_->DidCommitAndDrawFrame(); |
| 455 } | 545 } |
| 456 } | 546 } |
| 457 | 547 |
| 458 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 548 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
| 459 | 549 |
| 550 scoped_ptr<base::Value> SingleThreadProxy::SchedulerAsValueForTesting() { | |
| 551 DebugScopedSetImplThread impl(this); | |
| 552 if (!scheduler_on_impl_thread_) | |
| 553 return make_scoped_ptr(base::Value::CreateNullValue()).Pass(); | |
| 554 return scheduler_on_impl_thread_->AsValue().Pass(); | |
| 555 } | |
| 556 | |
| 557 void SingleThreadProxy::SetNeedsBeginFrame(bool enable) { | |
| 558 layer_tree_host_impl_->SetNeedsBeginFrame(enable); | |
| 559 } | |
| 560 | |
| 561 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { | |
| 562 layer_tree_host_impl_->WillBeginImplFrame(args); | |
| 563 } | |
| 564 | |
| 565 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { | |
| 566 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); | |
| 567 if (defer_commits_) { | |
| 568 DCHECK(!commit_was_deferred_); | |
| 569 commit_was_deferred_ = true; | |
| 570 layer_tree_host_->DidDeferCommit(); | |
| 571 return; | |
| 572 } | |
| 573 timing_history_.DidBeginMainFrame(); | |
| 574 | |
| 575 DCHECK(scheduler_on_impl_thread_); | |
| 576 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | |
| 577 scheduler_on_impl_thread_->NotifyReadyToCommit(); | |
| 578 } | |
| 579 | |
| 580 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | |
| 581 DebugScopedSetImplThread impl(this); | |
| 582 if (layer_tree_host_impl_->IsContextLost()) { | |
| 583 DidCommitAndDrawFrame(); | |
| 584 return DRAW_SUCCESS; | |
| 585 } | |
| 586 | |
| 587 LayerTreeHostImpl::FrameData frame; | |
| 588 return DoComposite(gfx::FrameTime::Now(), &frame); | |
|
brianderson
2014/06/20 23:08:12
Instead of Now(), can you use layer_tree_host_impl
enne (OOO)
2014/06/23 17:08:45
Done.
| |
| 589 } | |
| 590 | |
| 591 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { | |
| 592 NOTREACHED(); | |
| 593 return INVALID_RESULT; | |
| 594 } | |
| 595 | |
| 596 void SingleThreadProxy::ScheduledActionCommit() { | |
| 597 DebugScopedSetMainThread main(this); | |
| 598 DoCommit(gfx::FrameTime::Now()); | |
|
brianderson
2014/06/20 23:08:12
Instead of Now(), can you use layer_tree_host_impl
enne (OOO)
2014/06/23 17:08:45
Done.
| |
| 599 } | |
| 600 | |
| 601 void SingleThreadProxy::ScheduledActionAnimate() { | |
| 602 TRACE_EVENT0("cc", "ScheduledActionAnimate"); | |
| 603 layer_tree_host_impl_->Animate( | |
| 604 layer_tree_host_impl_->CurrentFrameTimeTicks()); | |
| 605 } | |
| 606 | |
| 607 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { | |
| 608 // Impl-side painting only. | |
| 609 NOTREACHED(); | |
| 610 } | |
| 611 | |
| 612 void SingleThreadProxy::ScheduledActionActivatePendingTree() { | |
| 613 // Impl-side painting only. | |
| 614 NOTREACHED(); | |
| 615 } | |
| 616 | |
| 617 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | |
| 618 DebugScopedSetMainThread main(this); | |
| 619 DCHECK(scheduler_on_impl_thread_); | |
| 620 // If possible, create the output surface in a post task. Synchronously | |
| 621 // creating the output surface makes tests more awkward since this differs | |
| 622 // from the ThreadProxy behavior. However, sometimes there is no | |
| 623 // task runner. | |
| 624 if (Proxy::MainThreadTaskRunner()) { | |
| 625 Proxy::MainThreadTaskRunner()->PostTask( | |
| 626 FROM_HERE, | |
| 627 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, | |
| 628 weak_factory_.GetWeakPtr())); | |
| 629 } else { | |
| 630 CreateAndInitializeOutputSurface(); | |
| 631 } | |
| 632 } | |
| 633 | |
| 634 void SingleThreadProxy::ScheduledActionManageTiles() { | |
| 635 // Impl-side painting only. | |
| 636 NOTREACHED(); | |
| 637 } | |
| 638 | |
| 639 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | |
| 640 } | |
| 641 | |
| 642 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { | |
| 643 return timing_history_.DrawDurationEstimate(); | |
| 644 } | |
| 645 | |
| 646 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { | |
| 647 return timing_history_.BeginMainFrameToCommitDurationEstimate(); | |
| 648 } | |
| 649 | |
| 650 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { | |
| 651 return timing_history_.CommitToActivateDurationEstimate(); | |
| 652 } | |
| 653 | |
| 654 void SingleThreadProxy::DidBeginImplFrameDeadline() { | |
| 655 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
| 656 } | |
| 657 | |
| 460 } // namespace cc | 658 } // namespace cc |
| OLD | NEW |