| 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_layout_height_(0.f), |   119       top_controls_layout_height_(0.f), | 
|   121       top_controls_content_offset_(0.f), |   120       top_controls_content_offset_(0.f), | 
|   122       device_scale_factor_(1.f), |   121       device_scale_factor_(1.f), | 
|   123       visible_(true), |   122       visible_(true), | 
|   124       page_scale_factor_(1.f), |   123       page_scale_factor_(1.f), | 
|   125       min_page_scale_factor_(1.f), |   124       min_page_scale_factor_(1.f), | 
|   126       max_page_scale_factor_(1.f), |   125       max_page_scale_factor_(1.f), | 
|   127       has_gpu_rasterization_trigger_(false), |   126       has_gpu_rasterization_trigger_(false), | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   209 } |   208 } | 
|   210  |   209  | 
|   211 void LayerTreeHost::SetLayerTreeHostClientReady() { |   210 void LayerTreeHost::SetLayerTreeHostClientReady() { | 
|   212   proxy_->SetLayerTreeHostClientReady(); |   211   proxy_->SetLayerTreeHostClientReady(); | 
|   213 } |   212 } | 
|   214  |   213  | 
|   215 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer* layer) { |   214 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer* layer) { | 
|   216   layer->OnOutputSurfaceCreated(); |   215   layer->OnOutputSurfaceCreated(); | 
|   217 } |   216 } | 
|   218  |   217  | 
|   219 void LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted(bool success) { |  | 
|   220   DCHECK(output_surface_lost_); |  | 
|   221   TRACE_EVENT1("cc", |  | 
|   222                "LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted", |  | 
|   223                "success", |  | 
|   224                success); |  | 
|   225  |  | 
|   226   if (!success) { |  | 
|   227     // Tolerate a certain number of recreation failures to work around races |  | 
|   228     // in the output-surface-lost machinery. |  | 
|   229     ++num_failed_recreate_attempts_; |  | 
|   230     if (num_failed_recreate_attempts_ >= 5) |  | 
|   231       LOG(FATAL) << "Failed to create a fallback OutputSurface."; |  | 
|   232     client_->DidFailToInitializeOutputSurface(); |  | 
|   233     return; |  | 
|   234   } |  | 
|   235  |  | 
|   236   output_surface_lost_ = false; |  | 
|   237  |  | 
|   238   if (!contents_texture_manager_ && !settings_.impl_side_painting) { |  | 
|   239     contents_texture_manager_ = |  | 
|   240         PrioritizedResourceManager::Create(proxy_.get()); |  | 
|   241     surface_memory_placeholder_ = |  | 
|   242         contents_texture_manager_->CreateTexture(gfx::Size(), RGBA_8888); |  | 
|   243   } |  | 
|   244  |  | 
|   245   if (root_layer()) { |  | 
|   246     LayerTreeHostCommon::CallFunctionForSubtree( |  | 
|   247         root_layer(), base::Bind(&LayerTreeHostOnOutputSurfaceCreatedCallback)); |  | 
|   248   } |  | 
|   249  |  | 
|   250   client_->DidInitializeOutputSurface(); |  | 
|   251 } |  | 
|   252  |  | 
|   253 void LayerTreeHost::DeleteContentsTexturesOnImplThread( |   218 void LayerTreeHost::DeleteContentsTexturesOnImplThread( | 
|   254     ResourceProvider* resource_provider) { |   219     ResourceProvider* resource_provider) { | 
|   255   DCHECK(proxy_->IsImplThread()); |   220   DCHECK(proxy_->IsImplThread()); | 
|   256   if (contents_texture_manager_) |   221   if (contents_texture_manager_) | 
|   257     contents_texture_manager_->ClearAllMemory(resource_provider); |   222     contents_texture_manager_->ClearAllMemory(resource_provider); | 
|   258 } |   223 } | 
|   259  |   224  | 
|   260 void LayerTreeHost::DidBeginMainFrame() { |   225 void LayerTreeHost::DidBeginMainFrame() { | 
|   261   client_->DidBeginMainFrame(); |   226   client_->DidBeginMainFrame(); | 
|   262 } |   227 } | 
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   425     hud_layer_ = NULL; |   390     hud_layer_ = NULL; | 
|   426   } |   391   } | 
|   427 } |   392 } | 
|   428  |   393  | 
|   429 void LayerTreeHost::CommitComplete() { |   394 void LayerTreeHost::CommitComplete() { | 
|   430   source_frame_number_++; |   395   source_frame_number_++; | 
|   431   client_->DidCommit(); |   396   client_->DidCommit(); | 
|   432 } |   397 } | 
|   433  |   398  | 
|   434 void LayerTreeHost::SetOutputSurface(scoped_ptr<OutputSurface> surface) { |   399 void LayerTreeHost::SetOutputSurface(scoped_ptr<OutputSurface> surface) { | 
 |   400   TRACE_EVENT0("cc", "LayerTreeHost::SetOutputSurface"); | 
 |   401   DCHECK(output_surface_lost_); | 
 |   402   DCHECK(surface); | 
 |   403  | 
|   435   proxy_->SetOutputSurface(surface.Pass()); |   404   proxy_->SetOutputSurface(surface.Pass()); | 
|   436 } |   405 } | 
|   437  |   406  | 
|   438 void LayerTreeHost::RequestNewOutputSurface() { |   407 void LayerTreeHost::RequestNewOutputSurface() { | 
|   439   client_->RequestNewOutputSurface(num_failed_recreate_attempts_ >= 4); |   408   client_->RequestNewOutputSurface(); | 
 |   409 } | 
 |   410  | 
 |   411 void LayerTreeHost::DidInitializeOutputSurface() { | 
 |   412   output_surface_lost_ = false; | 
 |   413  | 
 |   414   if (!contents_texture_manager_ && !settings_.impl_side_painting) { | 
 |   415     contents_texture_manager_ = | 
 |   416         PrioritizedResourceManager::Create(proxy_.get()); | 
 |   417     surface_memory_placeholder_ = | 
 |   418         contents_texture_manager_->CreateTexture(gfx::Size(), RGBA_8888); | 
 |   419   } | 
 |   420  | 
 |   421   if (root_layer()) { | 
 |   422     LayerTreeHostCommon::CallFunctionForSubtree( | 
 |   423         root_layer(), base::Bind(&LayerTreeHostOnOutputSurfaceCreatedCallback)); | 
 |   424   } | 
 |   425  | 
 |   426   client_->DidInitializeOutputSurface(); | 
 |   427 } | 
 |   428  | 
 |   429 void LayerTreeHost::DidFailToInitializeOutputSurface() { | 
 |   430   DCHECK(output_surface_lost_); | 
 |   431   client_->DidFailToInitializeOutputSurface(); | 
|   440 } |   432 } | 
|   441  |   433  | 
|   442 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |   434 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 
|   443     LayerTreeHostImplClient* client) { |   435     LayerTreeHostImplClient* client) { | 
|   444   DCHECK(proxy_->IsImplThread()); |   436   DCHECK(proxy_->IsImplThread()); | 
|   445   scoped_ptr<LayerTreeHostImpl> host_impl = |   437   scoped_ptr<LayerTreeHostImpl> host_impl = | 
|   446       LayerTreeHostImpl::Create(settings_, |   438       LayerTreeHostImpl::Create(settings_, | 
|   447                                 client, |   439                                 client, | 
|   448                                 proxy_.get(), |   440                                 proxy_.get(), | 
|   449                                 rendering_stats_instrumentation_.get(), |   441                                 rendering_stats_instrumentation_.get(), | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|   462   return host_impl.Pass(); |   454   return host_impl.Pass(); | 
|   463 } |   455 } | 
|   464  |   456  | 
|   465 void LayerTreeHost::DidLoseOutputSurface() { |   457 void LayerTreeHost::DidLoseOutputSurface() { | 
|   466   TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); |   458   TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); | 
|   467   DCHECK(proxy_->IsMainThread()); |   459   DCHECK(proxy_->IsMainThread()); | 
|   468  |   460  | 
|   469   if (output_surface_lost_) |   461   if (output_surface_lost_) | 
|   470     return; |   462     return; | 
|   471  |   463  | 
|   472   num_failed_recreate_attempts_ = 0; |  | 
|   473   output_surface_lost_ = true; |   464   output_surface_lost_ = true; | 
|   474   SetNeedsCommit(); |   465   SetNeedsCommit(); | 
|   475 } |   466 } | 
|   476  |   467  | 
|   477 void LayerTreeHost::FinishAllRendering() { |   468 void LayerTreeHost::FinishAllRendering() { | 
|   478   proxy_->FinishAllRendering(); |   469   proxy_->FinishAllRendering(); | 
|   479 } |   470 } | 
|   480  |   471  | 
|   481 void LayerTreeHost::SetDeferCommits(bool defer_commits) { |   472 void LayerTreeHost::SetDeferCommits(bool defer_commits) { | 
|   482   proxy_->SetDeferCommits(defer_commits); |   473   proxy_->SetDeferCommits(defer_commits); | 
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1357     bool children_need_begin_frames) const { |  1348     bool children_need_begin_frames) const { | 
|  1358   proxy_->SetChildrenNeedBeginFrames(children_need_begin_frames); |  1349   proxy_->SetChildrenNeedBeginFrames(children_need_begin_frames); | 
|  1359 } |  1350 } | 
|  1360  |  1351  | 
|  1361 void LayerTreeHost::SendBeginFramesToChildren( |  1352 void LayerTreeHost::SendBeginFramesToChildren( | 
|  1362     const BeginFrameArgs& args) const { |  1353     const BeginFrameArgs& args) const { | 
|  1363   client_->SendBeginFramesToChildren(args); |  1354   client_->SendBeginFramesToChildren(args); | 
|  1364 } |  1355 } | 
|  1365  |  1356  | 
|  1366 }  // namespace cc |  1357 }  // namespace cc | 
| OLD | NEW |