| 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_->UpdateClientAnimations(frame_begin_time); |
| 161 layer_tree_host_->AnimateLayers(frame_begin_time); |
| 162 layer_tree_host_->Layout(); |
| 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 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( | 227 benchmark_instrumentation::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::DidManageTiles() { |
| 392 // Impl-side painting only. |
| 393 NOTREACHED(); |
| 394 } |
| 395 |
| 308 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 396 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
| 309 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 397 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
| 310 // Cause a commit so we can notice the lost context. | 398 { |
| 311 SetNeedsCommitOnImplThread(); | 399 DebugScopedSetMainThread main(this); |
| 400 // This must happen before we notify the scheduler as it may try to recreate |
| 401 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. |
| 402 layer_tree_host_->DidLoseOutputSurface(); |
| 403 } |
| 312 client_->DidAbortSwapBuffers(); | 404 client_->DidAbortSwapBuffers(); |
| 405 if (scheduler_on_impl_thread_) |
| 406 scheduler_on_impl_thread_->DidLoseOutputSurface(); |
| 313 } | 407 } |
| 314 | 408 |
| 315 void SingleThreadProxy::DidSwapBuffersOnImplThread() { | 409 void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
| 410 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); |
| 411 if (scheduler_on_impl_thread_) |
| 412 scheduler_on_impl_thread_->DidSwapBuffers(); |
| 316 client_->DidPostSwapBuffers(); | 413 client_->DidPostSwapBuffers(); |
| 317 } | 414 } |
| 318 | 415 |
| 319 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { | 416 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
| 320 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 417 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
| 321 client_->DidCompleteSwapBuffers(); | 418 if (scheduler_on_impl_thread_) |
| 419 scheduler_on_impl_thread_->DidSwapBuffersComplete(); |
| 420 layer_tree_host_->DidCompleteSwapBuffers(); |
| 322 } | 421 } |
| 323 | 422 |
| 324 // Called by the legacy scheduling path (e.g. where render_widget does the | 423 void SingleThreadProxy::BeginFrame(const BeginFrameArgs& args) { |
| 325 // scheduling) | 424 TRACE_EVENT0("cc", "SingleThreadProxy::BeginFrame"); |
| 326 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 425 if (scheduler_on_impl_thread_) |
| 426 scheduler_on_impl_thread_->BeginImplFrame(args); |
| 427 } |
| 428 |
| 429 void SingleThreadProxy::CompositeImmediatelyInternal( |
| 430 base::TimeTicks frame_begin_time, |
| 431 bool do_swap) { |
| 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, do_swap); |
| 351 { | 440 } |
| 352 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
| 353 DebugScopedSetImplThread impl(this); | |
| 354 | 441 |
| 355 // This CapturePostTasks should be destroyed before | 442 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
| 356 // DidCommitAndDrawFrame() is called since that goes out to the embedder, | 443 bool do_swap = true; |
| 357 // and we want the embedder to receive its callbacks before that. | 444 CompositeImmediatelyInternal(frame_begin_time, do_swap); |
| 358 // NOTE: This maintains consistent ordering with the ThreadProxy since | 445 } |
| 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 | 446 |
| 364 layer_tree_host_impl_->SwapBuffers(frame); | 447 void SingleThreadProxy::CompositeImmediatelyNoSwap( |
| 365 } | 448 base::TimeTicks frame_begin_time) { |
| 366 DidSwapFrame(); | 449 bool do_swap = false; |
| 367 } | 450 CompositeImmediatelyInternal(frame_begin_time, do_swap); |
| 368 } | 451 } |
| 369 | 452 |
| 370 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { | 453 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
| 371 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 454 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 372 { | 455 { |
| 373 // The following line casts away const modifiers because it is just | 456 // The following line casts away const modifiers because it is just |
| 374 // setting debug state. We still want the AsValue() function and its | 457 // setting debug state. We still want the AsValue() function and its |
| 375 // call chain to be const throughout. | 458 // call chain to be const throughout. |
| 376 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 459 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
| 377 | 460 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 400 return layer_tree_host_impl_->visible() && | 483 return layer_tree_host_impl_->visible() && |
| 401 layer_tree_host_impl_->CanDraw(); | 484 layer_tree_host_impl_->CanDraw(); |
| 402 } | 485 } |
| 403 | 486 |
| 404 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { | 487 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { |
| 405 DCHECK(Proxy::IsImplThread()); | 488 DCHECK(Proxy::IsImplThread()); |
| 406 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | 489 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
| 407 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); | 490 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
| 408 } | 491 } |
| 409 | 492 |
| 410 bool SingleThreadProxy::DoComposite( | 493 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
| 411 base::TimeTicks frame_begin_time, | 494 LayerTreeHostImpl::FrameData* frame, |
| 412 LayerTreeHostImpl::FrameData* frame) { | 495 bool do_swap) { |
| 413 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 496 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
| 414 DCHECK(!layer_tree_host_->output_surface_lost()); | 497 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 415 | 498 |
| 416 bool lost_output_surface = false; | |
| 417 { | 499 { |
| 418 DebugScopedSetImplThread impl(this); | 500 DebugScopedSetImplThread impl(this); |
| 419 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 501 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 420 | 502 |
| 421 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 503 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 422 // frame, so can only be used when such a frame is possible. Since | 504 // frame, so can only be used when such a frame is possible. Since |
| 423 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 505 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 424 // CanDraw() as well. | 506 // CanDraw() as well. |
| 425 if (!ShouldComposite()) { | 507 if (!ShouldComposite()) { |
| 426 UpdateBackgroundAnimateTicking(); | 508 UpdateBackgroundAnimateTicking(); |
| 427 return false; | 509 return DRAW_ABORTED_CANT_DRAW; |
| 428 } | 510 } |
| 429 | 511 |
| 512 timing_history_.DidStartDrawing(); |
| 513 |
| 430 layer_tree_host_impl_->Animate( | 514 layer_tree_host_impl_->Animate( |
| 431 layer_tree_host_impl_->CurrentFrameTimeTicks()); | 515 layer_tree_host_impl_->CurrentFrameTimeTicks()); |
| 432 UpdateBackgroundAnimateTicking(); | 516 UpdateBackgroundAnimateTicking(); |
| 433 | 517 |
| 434 if (!layer_tree_host_impl_->IsContextLost()) { | 518 if (!layer_tree_host_impl_->IsContextLost()) { |
| 435 layer_tree_host_impl_->PrepareToDraw(frame); | 519 layer_tree_host_impl_->PrepareToDraw(frame); |
| 436 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 520 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
| 437 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 521 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
| 438 } | 522 } |
| 439 lost_output_surface = layer_tree_host_impl_->IsContextLost(); | |
| 440 | 523 |
| 441 bool start_ready_animations = true; | 524 bool start_ready_animations = true; |
| 442 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 525 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
| 443 | 526 |
| 444 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | 527 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
| 528 |
| 529 timing_history_.DidFinishDrawing(); |
| 445 } | 530 } |
| 446 | 531 |
| 447 if (lost_output_surface) { | 532 if (do_swap) { |
| 448 layer_tree_host_->DidLoseOutputSurface(); | 533 { |
| 449 return false; | 534 DebugScopedSetImplThread impl(this); |
| 535 |
| 536 if (layer_tree_host_impl_->IsContextLost()) { |
| 537 DidLoseOutputSurfaceOnImplThread(); |
| 538 } else { |
| 539 // This CapturePostTasks should be destroyed before |
| 540 // DidCommitAndDrawFrame() is called since that goes out to the |
| 541 // embedder, |
| 542 // and we want the embedder to receive its callbacks before that. |
| 543 // NOTE: This maintains consistent ordering with the ThreadProxy since |
| 544 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread |
| 545 // there as the main thread is not blocked, so any posted tasks inside |
| 546 // the swap buffers will execute first. |
| 547 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 548 |
| 549 BlockingTaskRunner::CapturePostTasks blocked; |
| 550 layer_tree_host_impl_->SwapBuffers(*frame); |
| 551 } |
| 552 } |
| 553 DidCommitAndDrawFrame(); |
| 450 } | 554 } |
| 451 | 555 |
| 452 return true; | 556 return DRAW_SUCCESS; |
| 453 } | 557 } |
| 454 | 558 |
| 455 void SingleThreadProxy::DidSwapFrame() { | 559 void SingleThreadProxy::DidCommitAndDrawFrame() { |
| 456 if (next_frame_is_newly_committed_frame_) { | 560 if (next_frame_is_newly_committed_frame_) { |
| 561 DebugScopedSetMainThread main(this); |
| 457 next_frame_is_newly_committed_frame_ = false; | 562 next_frame_is_newly_committed_frame_ = false; |
| 458 layer_tree_host_->DidCommitAndDrawFrame(); | 563 layer_tree_host_->DidCommitAndDrawFrame(); |
| 459 } | 564 } |
| 460 } | 565 } |
| 461 | 566 |
| 462 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 567 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
| 463 | 568 |
| 569 scoped_ptr<base::Value> SingleThreadProxy::SchedulerAsValueForTesting() { |
| 570 DebugScopedSetImplThread impl(this); |
| 571 if (!scheduler_on_impl_thread_) |
| 572 return make_scoped_ptr(base::Value::CreateNullValue()).Pass(); |
| 573 return scheduler_on_impl_thread_->AsValue().Pass(); |
| 574 } |
| 575 |
| 576 void SingleThreadProxy::SetNeedsBeginFrame(bool enable) { |
| 577 layer_tree_host_impl_->SetNeedsBeginFrame(enable); |
| 578 } |
| 579 |
| 580 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 581 layer_tree_host_impl_->WillBeginImplFrame(args); |
| 582 } |
| 583 |
| 584 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { |
| 585 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); |
| 586 if (defer_commits_) { |
| 587 DCHECK(!commit_was_deferred_); |
| 588 commit_was_deferred_ = true; |
| 589 layer_tree_host_->DidDeferCommit(); |
| 590 return; |
| 591 } |
| 592 timing_history_.DidBeginMainFrame(); |
| 593 |
| 594 DCHECK(scheduler_on_impl_thread_); |
| 595 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); |
| 596 scheduler_on_impl_thread_->NotifyReadyToCommit(); |
| 597 } |
| 598 |
| 599 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
| 600 DebugScopedSetImplThread impl(this); |
| 601 if (layer_tree_host_impl_->IsContextLost()) { |
| 602 DidCommitAndDrawFrame(); |
| 603 return DRAW_SUCCESS; |
| 604 } |
| 605 |
| 606 LayerTreeHostImpl::FrameData frame; |
| 607 bool do_swap = true; |
| 608 return DoComposite( |
| 609 layer_tree_host_impl_->CurrentFrameTimeTicks(), &frame, do_swap); |
| 610 } |
| 611 |
| 612 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { |
| 613 NOTREACHED(); |
| 614 return INVALID_RESULT; |
| 615 } |
| 616 |
| 617 void SingleThreadProxy::ScheduledActionCommit() { |
| 618 DebugScopedSetMainThread main(this); |
| 619 DoCommit(layer_tree_host_impl_->CurrentFrameTimeTicks()); |
| 620 } |
| 621 |
| 622 void SingleThreadProxy::ScheduledActionAnimate() { |
| 623 TRACE_EVENT0("cc", "ScheduledActionAnimate"); |
| 624 layer_tree_host_impl_->Animate( |
| 625 layer_tree_host_impl_->CurrentFrameTimeTicks()); |
| 626 } |
| 627 |
| 628 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { |
| 629 // Impl-side painting only. |
| 630 NOTREACHED(); |
| 631 } |
| 632 |
| 633 void SingleThreadProxy::ScheduledActionActivatePendingTree() { |
| 634 // Impl-side painting only. |
| 635 NOTREACHED(); |
| 636 } |
| 637 |
| 638 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
| 639 DebugScopedSetMainThread main(this); |
| 640 DCHECK(scheduler_on_impl_thread_); |
| 641 // If possible, create the output surface in a post task. Synchronously |
| 642 // creating the output surface makes tests more awkward since this differs |
| 643 // from the ThreadProxy behavior. However, sometimes there is no |
| 644 // task runner. |
| 645 if (Proxy::MainThreadTaskRunner()) { |
| 646 Proxy::MainThreadTaskRunner()->PostTask( |
| 647 FROM_HERE, |
| 648 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, |
| 649 weak_factory_.GetWeakPtr())); |
| 650 } else { |
| 651 CreateAndInitializeOutputSurface(); |
| 652 } |
| 653 } |
| 654 |
| 655 void SingleThreadProxy::ScheduledActionManageTiles() { |
| 656 // Impl-side painting only. |
| 657 NOTREACHED(); |
| 658 } |
| 659 |
| 660 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
| 661 } |
| 662 |
| 663 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { |
| 664 return timing_history_.DrawDurationEstimate(); |
| 665 } |
| 666 |
| 667 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { |
| 668 return timing_history_.BeginMainFrameToCommitDurationEstimate(); |
| 669 } |
| 670 |
| 671 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { |
| 672 return timing_history_.CommitToActivateDurationEstimate(); |
| 673 } |
| 674 |
| 675 void SingleThreadProxy::DidBeginImplFrameDeadline() { |
| 676 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
| 677 } |
| 678 |
| 464 } // namespace cc | 679 } // namespace cc |
| OLD | NEW |