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