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