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