diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 01:58:35 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 01:58:35 +0000 |
commit | ff1211d9aee45ac4a75cfeb61dcc1b95c9c3f45e (patch) | |
tree | 59ef85af047a277de91a77bb6f6e0525b8de631c /cc/trees | |
parent | cb67080199d7b917ac4217889e3ad5c3ba905d8a (diff) | |
download | chromium_src-ff1211d9aee45ac4a75cfeb61dcc1b95c9c3f45e.zip chromium_src-ff1211d9aee45ac4a75cfeb61dcc1b95c9c3f45e.tar.gz chromium_src-ff1211d9aee45ac4a75cfeb61dcc1b95c9c3f45e.tar.bz2 |
Revert 204221 "cc: Make all layer recursion use CallFunctionForS..."
> cc: Make all layer recursion use CallFunctionForSubtree
>
> This is mostly a cleanup that I noticed while doing other code.
>
> The behavior change here is that SetNeedsDisplay and DidBecomeActive is
> now called for all mask and replica layers.
>
> Also, refactor CallFunctionForSubtree so that both functors and
> functions can be passed to it. As no uses in the codebase actually
> needed function objects with state, turn them all into simpler static
> functions.
>
> R=danakj@chromium.org
> BUG=239614
>
> Review URL: https://chromiumcodereview.appspot.com/15959012
TBR=enne@chromium.org
BUG=247349
Review URL: https://chromiumcodereview.appspot.com/16553003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204690 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/trees')
-rw-r--r-- | cc/trees/layer_tree_host.cc | 75 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_common.h | 19 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 55 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.h | 1 | ||||
-rw-r--r-- | cc/trees/layer_tree_impl.cc | 6 |
5 files changed, 88 insertions, 68 deletions
diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc index a637f02..3bc69bd 100644 --- a/cc/trees/layer_tree_host.cc +++ b/cc/trees/layer_tree_host.cc @@ -5,6 +5,7 @@ #include "cc/trees/layer_tree_host.h" #include <algorithm> +#include <stack> #include "base/bind.h" #include "base/command_line.h" @@ -437,13 +438,17 @@ void LayerTreeHost::SetDeferCommits(bool defer_commits) { void LayerTreeHost::DidDeferCommit() {} -static void SetNeedsDisplay(Layer* layer) { - layer->SetNeedsDisplay(); -} - void LayerTreeHost::SetNeedsDisplayOnAllLayers() { - if (root_layer()) - LayerTreeHostCommon::CallFunctionForSubtree(SetNeedsDisplay, root_layer()); + std::stack<Layer*> layer_stack; + layer_stack.push(root_layer()); + while (!layer_stack.empty()) { + Layer* current_layer = layer_stack.top(); + layer_stack.pop(); + current_layer->SetNeedsDisplay(); + for (unsigned int i = 0; i < current_layer->children().size(); i++) { + layer_stack.push(current_layer->child_at(i)); + } + } } void LayerTreeHost::CollectRenderingStats(RenderingStats* stats) const { @@ -667,26 +672,29 @@ static Layer* FindFirstScrollableLayer(Layer* layer) { return NULL; } -static void CalculateLCDTextMetrics(Layer* layer) { - LayerTreeHost* layer_tree_host = layer->layer_tree_host(); - if (!layer_tree_host) - return; +class CalculateLCDTextMetricsFunctor { + public: + void operator()(Layer* layer) { + LayerTreeHost* layer_tree_host = layer->layer_tree_host(); + if (!layer_tree_host) + return; - if (!layer->SupportsLCDText()) - return; + if (!layer->SupportsLCDText()) + return; - bool update_total_num_cc_layers_can_use_lcd_text = false; - bool update_total_num_cc_layers_will_use_lcd_text = false; - if (layer->draw_properties().can_use_lcd_text) { - update_total_num_cc_layers_can_use_lcd_text = true; - if (layer->contents_opaque()) - update_total_num_cc_layers_will_use_lcd_text = true; - } + bool update_total_num_cc_layers_can_use_lcd_text = false; + bool update_total_num_cc_layers_will_use_lcd_text = false; + if (layer->draw_properties().can_use_lcd_text) { + update_total_num_cc_layers_can_use_lcd_text = true; + if (layer->contents_opaque()) + update_total_num_cc_layers_will_use_lcd_text = true; + } - layer_tree_host->IncrementLCDTextMetrics( - update_total_num_cc_layers_can_use_lcd_text, - update_total_num_cc_layers_will_use_lcd_text); -} + layer_tree_host->IncrementLCDTextMetrics( + update_total_num_cc_layers_can_use_lcd_text, + update_total_num_cc_layers_will_use_lcd_text); + } +}; void LayerTreeHost::IncrementLCDTextMetrics( bool update_total_num_cc_layers_can_use_lcd_text, @@ -726,8 +734,8 @@ void LayerTreeHost::UpdateLayers(Layer* root_layer, if (total_frames_used_for_lcd_text_metrics_ <= kTotalFramesToUseForLCDTextMetrics) { - LayerTreeHostCommon::CallFunctionForSubtree(CalculateLCDTextMetrics, - root_layer); + LayerTreeHostCommon::CallFunctionForSubtree< + CalculateLCDTextMetricsFunctor, Layer>(root_layer); total_frames_used_for_lcd_text_metrics_++; } @@ -770,14 +778,19 @@ void LayerTreeHost::TriggerPrepaint() { SetNeedsCommit(); } -static void ReduceMemoryUsageForLayer(Layer* layer) { - layer->ReduceMemoryUsage(); -} +class LayerTreeHostReduceMemoryFunctor { + public: + void operator()(Layer* layer) { + layer->ReduceMemoryUsage(); + } +}; void LayerTreeHost::ReduceMemoryUsage() { - if (root_layer()) - LayerTreeHostCommon::CallFunctionForSubtree(ReduceMemoryUsageForLayer, - root_layer()); + if (!root_layer()) + return; + + LayerTreeHostCommon::CallFunctionForSubtree< + LayerTreeHostReduceMemoryFunctor, Layer>(root_layer()); } void LayerTreeHost::SetPrioritiesForSurfaces(size_t surface_memory_bytes) { diff --git a/cc/trees/layer_tree_host_common.h b/cc/trees/layer_tree_host_common.h index b2b39c4..15c1180 100644 --- a/cc/trees/layer_tree_host_common.h +++ b/cc/trees/layer_tree_host_common.h @@ -66,7 +66,7 @@ class CC_EXPORT LayerTreeHostCommon { int target_surface_layer_id); template <class Function, typename LayerType> - static void CallFunctionForSubtree(Function function, LayerType* root_layer); + static void CallFunctionForSubtree(LayerType* root_layer); // Returns a layer with the given id if one exists in the subtree starting // from the given root layer (including mask and replica layers). @@ -138,22 +138,21 @@ LayerType* LayerTreeHostCommon::FindLayerInSubtree(LayerType* root_layer, return NULL; } -template <typename Function, typename LayerType> -void LayerTreeHostCommon::CallFunctionForSubtree(Function function, - LayerType* root_layer) { - function(root_layer); +template <class Function, typename LayerType> +void LayerTreeHostCommon::CallFunctionForSubtree(LayerType* root_layer) { + Function()(root_layer); if (LayerType* mask_layer = root_layer->mask_layer()) - function(mask_layer); + Function()(mask_layer); if (LayerType* replica_layer = root_layer->replica_layer()) { - function(replica_layer); + Function()(replica_layer); if (LayerType* mask_layer = replica_layer->mask_layer()) - function(mask_layer); + Function()(mask_layer); } for (size_t i = 0; i < root_layer->children().size(); ++i) { - CallFunctionForSubtree(function, - get_child_as_raw_ptr(root_layer->children(), i)); + CallFunctionForSubtree<Function>( + get_child_as_raw_ptr(root_layer->children(), i)); } } diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 5d84fcd..2b8d453 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -1109,9 +1109,12 @@ bool LayerTreeHostImpl::AllowPartialSwap() const { return !debug_state_.ShowHudRects(); } -void DidBeginTracing(LayerImpl* layer) { - layer->DidBeginTracing(); -} +class DidBeginTracingFunctor { + public: + void operator()(LayerImpl* layer) { + layer->DidBeginTracing(); + } +}; void LayerTreeHostImpl::DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time) { @@ -1153,12 +1156,13 @@ void LayerTreeHostImpl::DrawLayers(FrameData* frame, bool is_new_trace; TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); if (is_new_trace) { - if (pending_tree_) { - LayerTreeHostCommon::CallFunctionForSubtree(DidBeginTracing, - pending_tree_->root_layer()); - } - LayerTreeHostCommon::CallFunctionForSubtree(DidBeginTracing, - active_tree_->root_layer()); + if (pending_tree_) + LayerTreeHostCommon::CallFunctionForSubtree< + DidBeginTracingFunctor, LayerImpl>( + pending_tree_->root_layer()); + LayerTreeHostCommon::CallFunctionForSubtree< + DidBeginTracingFunctor, LayerImpl>( + active_tree_->root_layer()); } TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( @@ -1425,10 +1429,6 @@ ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const { return actual; } -static void LostOutputSurface(LayerImpl* layer) { - layer->DidLoseOutputSurface(); -} - bool LayerTreeHostImpl::InitializeRenderer( scoped_ptr<OutputSurface> output_surface) { // Since we will create a new resource provider, we cannot continue to use @@ -1436,18 +1436,12 @@ bool LayerTreeHostImpl::InitializeRenderer( // before we destroy the old resource provider. if (active_tree_->root_layer()) ClearRenderSurfaces(); - if (active_tree_->root_layer()) { - LayerTreeHostCommon::CallFunctionForSubtree(LostOutputSurface, - active_tree_->root_layer()); - } - if (pending_tree_ && pending_tree_->root_layer()) { - LayerTreeHostCommon::CallFunctionForSubtree(LostOutputSurface, - pending_tree_->root_layer()); - } - if (recycle_tree_ && recycle_tree_->root_layer()) { - LayerTreeHostCommon::CallFunctionForSubtree(LostOutputSurface, - recycle_tree_->root_layer()); - } + if (active_tree_->root_layer()) + SendDidLoseOutputSurfaceRecursive(active_tree_->root_layer()); + if (pending_tree_ && pending_tree_->root_layer()) + SendDidLoseOutputSurfaceRecursive(pending_tree_->root_layer()); + if (recycle_tree_ && recycle_tree_->root_layer()) + SendDidLoseOutputSurfaceRecursive(recycle_tree_->root_layer()); if (resource_provider_) resource_provider_->DidLoseOutputSurface(); @@ -2077,6 +2071,17 @@ base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const { return base::TimeDelta::FromSeconds(1); } +void LayerTreeHostImpl::SendDidLoseOutputSurfaceRecursive(LayerImpl* current) { + DCHECK(current); + current->DidLoseOutputSurface(); + if (current->mask_layer()) + SendDidLoseOutputSurfaceRecursive(current->mask_layer()); + if (current->replica_layer()) + SendDidLoseOutputSurfaceRecursive(current->replica_layer()); + for (size_t i = 0; i < current->children().size(); ++i) + SendDidLoseOutputSurfaceRecursive(current->children()[i]); +} + void LayerTreeHostImpl::ClearRenderSurfaces() { active_tree_->ClearRenderSurfaces(); if (pending_tree_) diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h index e3671cf..055a7d6 100644 --- a/cc/trees/layer_tree_host_impl.h +++ b/cc/trees/layer_tree_host_impl.h @@ -419,6 +419,7 @@ class CC_EXPORT LayerTreeHostImpl // if this helper function is called. bool CalculateRenderPasses(FrameData* frame); + void SendDidLoseOutputSurfaceRecursive(LayerImpl* current); void ClearRenderSurfaces(); bool EnsureRenderSurfaceLayerList(); void ClearCurrentlyScrollingLayer(); diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc index e8ae6f1..d36e841 100644 --- a/cc/trees/layer_tree_impl.cc +++ b/cc/trees/layer_tree_impl.cc @@ -347,13 +347,15 @@ void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); } -static void MarkActive(LayerImpl* layer) { +static void DidBecomeActiveRecursive(LayerImpl* layer) { layer->DidBecomeActive(); + for (size_t i = 0; i < layer->children().size(); ++i) + DidBecomeActiveRecursive(layer->children()[i]); } void LayerTreeImpl::DidBecomeActive() { if (root_layer()) - LayerTreeHostCommon::CallFunctionForSubtree(MarkActive, root_layer()); + DidBecomeActiveRecursive(root_layer()); FindRootScrollLayer(); UpdateMaxScrollOffset(); } |