| 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/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <stack> | 8 #include <stack> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 107 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 108 const LayerTreeSettings& settings) | 108 const LayerTreeSettings& settings) |
| 109 : micro_benchmark_controller_(this), | 109 : micro_benchmark_controller_(this), |
| 110 next_ui_resource_id_(1), | 110 next_ui_resource_id_(1), |
| 111 inside_begin_main_frame_(false), | 111 inside_begin_main_frame_(false), |
| 112 needs_full_tree_sync_(true), | 112 needs_full_tree_sync_(true), |
| 113 client_(client), | 113 client_(client), |
| 114 source_frame_number_(0), | 114 source_frame_number_(0), |
| 115 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 115 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
| 116 output_surface_lost_(true), | 116 output_surface_lost_(true), |
| 117 num_failed_recreate_attempts_(0), | |
| 118 settings_(settings), | 117 settings_(settings), |
| 119 debug_state_(settings.initial_debug_state), | 118 debug_state_(settings.initial_debug_state), |
| 120 top_controls_shrink_blink_size_(false), | 119 top_controls_shrink_blink_size_(false), |
| 121 top_controls_height_(0.f), | 120 top_controls_height_(0.f), |
| 122 top_controls_content_offset_(0.f), | 121 top_controls_content_offset_(0.f), |
| 123 device_scale_factor_(1.f), | 122 device_scale_factor_(1.f), |
| 124 visible_(true), | 123 visible_(true), |
| 125 page_scale_factor_(1.f), | 124 page_scale_factor_(1.f), |
| 126 min_page_scale_factor_(1.f), | 125 min_page_scale_factor_(1.f), |
| 127 max_page_scale_factor_(1.f), | 126 max_page_scale_factor_(1.f), |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 209 } |
| 211 | 210 |
| 212 void LayerTreeHost::SetLayerTreeHostClientReady() { | 211 void LayerTreeHost::SetLayerTreeHostClientReady() { |
| 213 proxy_->SetLayerTreeHostClientReady(); | 212 proxy_->SetLayerTreeHostClientReady(); |
| 214 } | 213 } |
| 215 | 214 |
| 216 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer* layer) { | 215 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer* layer) { |
| 217 layer->OnOutputSurfaceCreated(); | 216 layer->OnOutputSurfaceCreated(); |
| 218 } | 217 } |
| 219 | 218 |
| 220 void LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted(bool success) { | |
| 221 DCHECK(output_surface_lost_); | |
| 222 TRACE_EVENT1("cc", | |
| 223 "LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted", | |
| 224 "success", | |
| 225 success); | |
| 226 | |
| 227 if (!success) { | |
| 228 // Tolerate a certain number of recreation failures to work around races | |
| 229 // in the output-surface-lost machinery. | |
| 230 ++num_failed_recreate_attempts_; | |
| 231 if (num_failed_recreate_attempts_ >= 5) | |
| 232 LOG(FATAL) << "Failed to create a fallback OutputSurface."; | |
| 233 client_->DidFailToInitializeOutputSurface(); | |
| 234 return; | |
| 235 } | |
| 236 | |
| 237 output_surface_lost_ = false; | |
| 238 | |
| 239 if (!contents_texture_manager_ && !settings_.impl_side_painting) { | |
| 240 contents_texture_manager_ = | |
| 241 PrioritizedResourceManager::Create(proxy_.get()); | |
| 242 surface_memory_placeholder_ = | |
| 243 contents_texture_manager_->CreateTexture(gfx::Size(), RGBA_8888); | |
| 244 } | |
| 245 | |
| 246 if (root_layer()) { | |
| 247 LayerTreeHostCommon::CallFunctionForSubtree( | |
| 248 root_layer(), base::Bind(&LayerTreeHostOnOutputSurfaceCreatedCallback)); | |
| 249 } | |
| 250 | |
| 251 client_->DidInitializeOutputSurface(); | |
| 252 } | |
| 253 | |
| 254 void LayerTreeHost::DeleteContentsTexturesOnImplThread( | 219 void LayerTreeHost::DeleteContentsTexturesOnImplThread( |
| 255 ResourceProvider* resource_provider) { | 220 ResourceProvider* resource_provider) { |
| 256 DCHECK(proxy_->IsImplThread()); | 221 DCHECK(proxy_->IsImplThread()); |
| 257 if (contents_texture_manager_) | 222 if (contents_texture_manager_) |
| 258 contents_texture_manager_->ClearAllMemory(resource_provider); | 223 contents_texture_manager_->ClearAllMemory(resource_provider); |
| 259 } | 224 } |
| 260 | 225 |
| 261 void LayerTreeHost::DidBeginMainFrame() { | 226 void LayerTreeHost::DidBeginMainFrame() { |
| 262 client_->DidBeginMainFrame(); | 227 client_->DidBeginMainFrame(); |
| 263 } | 228 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 hud_layer_ = NULL; | 399 hud_layer_ = NULL; |
| 435 } | 400 } |
| 436 } | 401 } |
| 437 | 402 |
| 438 void LayerTreeHost::CommitComplete() { | 403 void LayerTreeHost::CommitComplete() { |
| 439 source_frame_number_++; | 404 source_frame_number_++; |
| 440 client_->DidCommit(); | 405 client_->DidCommit(); |
| 441 } | 406 } |
| 442 | 407 |
| 443 void LayerTreeHost::SetOutputSurface(scoped_ptr<OutputSurface> surface) { | 408 void LayerTreeHost::SetOutputSurface(scoped_ptr<OutputSurface> surface) { |
| 409 TRACE_EVENT0("cc", "LayerTreeHost::SetOutputSurface"); |
| 410 DCHECK(output_surface_lost_); |
| 411 DCHECK(surface); |
| 412 |
| 444 proxy_->SetOutputSurface(surface.Pass()); | 413 proxy_->SetOutputSurface(surface.Pass()); |
| 445 } | 414 } |
| 446 | 415 |
| 447 void LayerTreeHost::RequestNewOutputSurface() { | 416 void LayerTreeHost::RequestNewOutputSurface() { |
| 448 client_->RequestNewOutputSurface(num_failed_recreate_attempts_ >= 4); | 417 client_->RequestNewOutputSurface(); |
| 418 } |
| 419 |
| 420 void LayerTreeHost::DidInitializeOutputSurface() { |
| 421 output_surface_lost_ = false; |
| 422 |
| 423 if (!contents_texture_manager_ && !settings_.impl_side_painting) { |
| 424 contents_texture_manager_ = |
| 425 PrioritizedResourceManager::Create(proxy_.get()); |
| 426 surface_memory_placeholder_ = |
| 427 contents_texture_manager_->CreateTexture(gfx::Size(), RGBA_8888); |
| 428 } |
| 429 |
| 430 if (root_layer()) { |
| 431 LayerTreeHostCommon::CallFunctionForSubtree( |
| 432 root_layer(), base::Bind(&LayerTreeHostOnOutputSurfaceCreatedCallback)); |
| 433 } |
| 434 |
| 435 client_->DidInitializeOutputSurface(); |
| 436 } |
| 437 |
| 438 void LayerTreeHost::DidFailToInitializeOutputSurface() { |
| 439 DCHECK(output_surface_lost_); |
| 440 client_->DidFailToInitializeOutputSurface(); |
| 449 } | 441 } |
| 450 | 442 |
| 451 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 443 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
| 452 LayerTreeHostImplClient* client) { | 444 LayerTreeHostImplClient* client) { |
| 453 DCHECK(proxy_->IsImplThread()); | 445 DCHECK(proxy_->IsImplThread()); |
| 454 scoped_ptr<LayerTreeHostImpl> host_impl = | 446 scoped_ptr<LayerTreeHostImpl> host_impl = |
| 455 LayerTreeHostImpl::Create(settings_, | 447 LayerTreeHostImpl::Create(settings_, |
| 456 client, | 448 client, |
| 457 proxy_.get(), | 449 proxy_.get(), |
| 458 rendering_stats_instrumentation_.get(), | 450 rendering_stats_instrumentation_.get(), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 471 return host_impl.Pass(); | 463 return host_impl.Pass(); |
| 472 } | 464 } |
| 473 | 465 |
| 474 void LayerTreeHost::DidLoseOutputSurface() { | 466 void LayerTreeHost::DidLoseOutputSurface() { |
| 475 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); | 467 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); |
| 476 DCHECK(proxy_->IsMainThread()); | 468 DCHECK(proxy_->IsMainThread()); |
| 477 | 469 |
| 478 if (output_surface_lost_) | 470 if (output_surface_lost_) |
| 479 return; | 471 return; |
| 480 | 472 |
| 481 num_failed_recreate_attempts_ = 0; | |
| 482 output_surface_lost_ = true; | 473 output_surface_lost_ = true; |
| 483 SetNeedsCommit(); | 474 SetNeedsCommit(); |
| 484 } | 475 } |
| 485 | 476 |
| 486 void LayerTreeHost::FinishAllRendering() { | 477 void LayerTreeHost::FinishAllRendering() { |
| 487 proxy_->FinishAllRendering(); | 478 proxy_->FinishAllRendering(); |
| 488 } | 479 } |
| 489 | 480 |
| 490 void LayerTreeHost::SetDeferCommits(bool defer_commits) { | 481 void LayerTreeHost::SetDeferCommits(bool defer_commits) { |
| 491 proxy_->SetDeferCommits(defer_commits); | 482 proxy_->SetDeferCommits(defer_commits); |
| (...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 bool children_need_begin_frames) const { | 1382 bool children_need_begin_frames) const { |
| 1392 proxy_->SetChildrenNeedBeginFrames(children_need_begin_frames); | 1383 proxy_->SetChildrenNeedBeginFrames(children_need_begin_frames); |
| 1393 } | 1384 } |
| 1394 | 1385 |
| 1395 void LayerTreeHost::SendBeginFramesToChildren( | 1386 void LayerTreeHost::SendBeginFramesToChildren( |
| 1396 const BeginFrameArgs& args) const { | 1387 const BeginFrameArgs& args) const { |
| 1397 client_->SendBeginFramesToChildren(args); | 1388 client_->SendBeginFramesToChildren(args); |
| 1398 } | 1389 } |
| 1399 | 1390 |
| 1400 } // namespace cc | 1391 } // namespace cc |
| OLD | NEW |