diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-16 04:53:10 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-16 04:53:10 +0000 |
commit | f117a4cc7c6cae265071109a9133ff5f853a06f1 (patch) | |
tree | 57eba0519d44af2d0d4f6b30b0492160c86c21c0 /cc | |
parent | 344e58d0497d68437f9653fcfc3788d85f3f8450 (diff) | |
download | chromium_src-f117a4cc7c6cae265071109a9133ff5f853a06f1.zip chromium_src-f117a4cc7c6cae265071109a9133ff5f853a06f1.tar.gz chromium_src-f117a4cc7c6cae265071109a9133ff5f853a06f1.tar.bz2 |
cc: Add some more infrastructure for two trees
PictureLayerImpl gets the ability to sync a tiling from active
to pending tree when it gets created so that layers can share tiles.
A few functions are added to make this possible.
BUG=155209
Review URL: https://chromiumcodereview.appspot.com/11574026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173366 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layer_tree_host_impl.h | 2 | ||||
-rw-r--r-- | cc/layer_tree_impl.cc | 22 | ||||
-rw-r--r-- | cc/layer_tree_impl.h | 6 | ||||
-rw-r--r-- | cc/picture_layer.cc | 20 | ||||
-rw-r--r-- | cc/picture_layer_impl.cc | 48 | ||||
-rw-r--r-- | cc/picture_layer_impl.h | 6 | ||||
-rw-r--r-- | cc/picture_layer_tiling_set.cc | 22 | ||||
-rw-r--r-- | cc/picture_layer_tiling_set.h | 15 |
8 files changed, 122 insertions, 19 deletions
diff --git a/cc/layer_tree_host_impl.h b/cc/layer_tree_host_impl.h index 9943da2..79c26c02 100644 --- a/cc/layer_tree_host_impl.h +++ b/cc/layer_tree_host_impl.h @@ -204,6 +204,7 @@ public: void readback(void* pixels, const gfx::Rect&); LayerTreeImpl* activeTree() { return m_activeTree.get(); } + LayerTreeImpl* pendingTree() { return m_pendingTree.get(); } // TODO(nduca): Remove these in favor of LayerTreeImpl. void setRootLayer(scoped_ptr<LayerImpl>); @@ -354,6 +355,7 @@ private: scoped_ptr<Renderer> m_renderer; scoped_ptr<TileManager> m_tileManager; + scoped_ptr<LayerTreeImpl> m_pendingTree; scoped_ptr<LayerTreeImpl> m_activeTree; bool m_scrollDeltaIsInViewportSpace; diff --git a/cc/layer_tree_impl.cc b/cc/layer_tree_impl.cc index a113316..0c68bb9 100644 --- a/cc/layer_tree_impl.cc +++ b/cc/layer_tree_impl.cc @@ -106,6 +106,28 @@ FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { return layer_tree_host_impl_->fpsCounter(); } +bool LayerTreeImpl::IsActiveTree() const { + return layer_tree_host_impl_->activeTree() == this; +} + +bool LayerTreeImpl::IsPendingTree() const { + return layer_tree_host_impl_->pendingTree() == this; +} + +LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { + LayerTreeImpl* tree = layer_tree_host_impl_->activeTree(); + if (!tree) + return NULL; + return tree->LayerById(id); +} + +LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { + LayerTreeImpl* tree = layer_tree_host_impl_->pendingTree(); + if (!tree) + return NULL; + return tree->LayerById(id); +} + void LayerTreeImpl::SetNeedsRedraw() { layer_tree_host_impl_->setNeedsRedraw(); } diff --git a/cc/layer_tree_impl.h b/cc/layer_tree_impl.h index 62e0135..8b7c925 100644 --- a/cc/layer_tree_impl.h +++ b/cc/layer_tree_impl.h @@ -40,13 +40,17 @@ class CC_EXPORT LayerTreeImpl { } virtual ~LayerTreeImpl(); - // Methods called by the layer tree that pass-through to LHTI. + // Methods called by the layer tree that pass-through or access LTHI. // --------------------------------------------------------------------------- const LayerTreeSettings& settings() const; OutputSurface* output_surface() const; ResourceProvider* resource_provider() const; TileManager* tile_manager() const; FrameRateCounter* frame_rate_counter() const; + bool IsActiveTree() const; + bool IsPendingTree() const; + LayerImpl* FindActiveTreeLayerById(int id); + LayerImpl* FindPendingTreeLayerById(int id); // Tree specific methods exposed to layer-impl tree. // --------------------------------------------------------------------------- diff --git a/cc/picture_layer.cc b/cc/picture_layer.cc index ca2bf4a..b1fe87c 100644 --- a/cc/picture_layer.cc +++ b/cc/picture_layer.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include "cc/picture_layer.h" + +#include "cc/layer_tree_impl.h" #include "cc/picture_layer_impl.h" #include "ui/gfx/rect_conversions.h" @@ -29,15 +31,21 @@ scoped_ptr<LayerImpl> PictureLayer::createLayerImpl(LayerTreeImpl* treeImpl) { void PictureLayer::pushPropertiesTo(LayerImpl* base_layer) { Layer::pushPropertiesTo(base_layer); + PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); - layer_impl->didUpdateBounds(); + layer_impl->tilings_.SetLayerBounds(bounds()); + layer_impl->invalidation_.Clear(); + layer_impl->invalidation_.Swap(pile_invalidation_); pile_.PushPropertiesTo(layer_impl->pile_); - // TODO(enne): Once we have two trees on the impl side, we need to - // sync the active layer's tiles prior to this Invalidate call since it - // will make new tiles for anything intersecting the invalidation. - layer_impl->tilings_.Invalidate(pile_invalidation_); - pile_invalidation_.Clear(); + // TODO(enne): Remove this once syncing happens to the pending tree rather + // than the active one. + if (layer_impl->layerTreeImpl()->IsActiveTree()) { + layer_impl->tilings_.Invalidate(layer_impl->invalidation_); + return; + } + + layer_impl->SyncFromActiveLayer(); } void PictureLayer::setNeedsDisplayRect(const gfx::RectF& layer_rect) { diff --git a/cc/picture_layer_impl.cc b/cc/picture_layer_impl.cc index 523c5f1..e844f67 100644 --- a/cc/picture_layer_impl.cc +++ b/cc/picture_layer_impl.cc @@ -129,13 +129,15 @@ void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { void PictureLayerImpl::didUpdateTransforms() { if (drawsContent()) { - // TODO(enne): Add more tilings during pinch zoom. + // TODO(enne): Add tilings during pinch zoom + // TODO(enne): Consider culling old tilings after pinch finishes. if (!tilings_.num_tilings()) { gfx::Size tile_size = layerTreeImpl()->settings().defaultTileSize; - tilings_.AddTiling(contentsScaleX(), tile_size); - // TODO(enne): handle invalidations, create new tiles + AddTiling(contentsScaleX(), tile_size); + // TODO(enne): Add a low-res tiling as well. } } else { + // TODO(enne): This should be unnecessary once there are two trees. tilings_.Reset(); } @@ -181,8 +183,46 @@ scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, tiling->contents_scale())); } +void PictureLayerImpl::SyncFromActiveLayer() { + DCHECK(layerTreeImpl()->IsPendingTree()); + if (!drawsContent()) + return; + + // If there is an active tree version of this layer, get a copy of its + // tiles. This needs to be done last, after setting invalidation and the + // pile. + PictureLayerImpl* active_twin = static_cast<PictureLayerImpl*>( + layerTreeImpl()->FindActiveTreeLayerById(id())); + if (!active_twin) + return; + SyncFromActiveLayer(active_twin); +} + void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { - tilings_.CloneFrom(other->tilings_); + tilings_.CloneAll(other->tilings_, invalidation_); +} + +void PictureLayerImpl::SyncTiling( + const PictureLayerTiling* tiling) { + tilings_.Clone(tiling, invalidation_); +} + +void PictureLayerImpl::AddTiling(float contents_scale, gfx::Size tile_size) { + const PictureLayerTiling* tiling = tilings_.AddTiling( + contents_scale, + tile_size); + + // If a new tiling is created on the active tree, sync it to the pending tree + // so that it can share the same tiles. + if (layerTreeImpl()->IsActiveTree()) + return; + + PictureLayerImpl* pending_twin = static_cast<PictureLayerImpl*>( + layerTreeImpl()->FindPendingTreeLayerById(id())); + if (!pending_twin) + return; + DCHECK_EQ(id(), pending_twin->id()); + pending_twin->SyncTiling(tiling); } } // namespace cc diff --git a/cc/picture_layer_impl.h b/cc/picture_layer_impl.h index 2d592d3..66f739b 100644 --- a/cc/picture_layer_impl.h +++ b/cc/picture_layer_impl.h @@ -38,13 +38,17 @@ public: gfx::Rect) OVERRIDE; // PushPropertiesTo active tree => pending tree - void SyncFromActiveLayer(const PictureLayerImpl* other); + void SyncFromActiveLayer(); + void SyncTiling(const PictureLayerTiling* tiling); protected: PictureLayerImpl(LayerTreeImpl* treeImpl, int id); + void AddTiling(float contents_scale, gfx::Size tile_size); + void SyncFromActiveLayer(const PictureLayerImpl* other); PictureLayerTilingSet tilings_; scoped_refptr<PicturePileImpl> pile_; + Region invalidation_; gfx::Transform last_screen_space_transform_; double last_update_time_; diff --git a/cc/picture_layer_tiling_set.cc b/cc/picture_layer_tiling_set.cc index 7f5dcc9..e2ccc29 100644 --- a/cc/picture_layer_tiling_set.cc +++ b/cc/picture_layer_tiling_set.cc @@ -14,15 +14,29 @@ PictureLayerTilingSet::PictureLayerTilingSet( PictureLayerTilingSet::~PictureLayerTilingSet() { } -void PictureLayerTilingSet::CloneFrom(const PictureLayerTilingSet& other) { +void PictureLayerTilingSet::CloneAll( + const PictureLayerTilingSet& other, + const Region& invalidation) { layer_bounds_ = other.layer_bounds_; tilings_.clear(); tilings_.reserve(other.tilings_.size()); for (size_t i = 0; i < other.tilings_.size(); ++i) { tilings_.append(other.tilings_[i]->Clone()); + tilings_.last()->Invalidate(invalidation); } } +void PictureLayerTilingSet::Clone( + const PictureLayerTiling* tiling, + const Region& invalidation) { + + for (size_t i = 0; i < tilings_.size(); ++i) + DCHECK_NE(tilings_[i]->contents_scale(), tiling->contents_scale()); + + tilings_.append(tiling->Clone()); + tilings_.last()->Invalidate(invalidation); +} + void PictureLayerTilingSet::SetLayerBounds(gfx::Size layer_bounds) { if (layer_bounds_ == layer_bounds) return; @@ -43,11 +57,13 @@ void PictureLayerTilingSet::Invalidate(const Region& invalidation) { tilings_[i]->Invalidate(invalidation); } -void PictureLayerTilingSet::AddTiling(float contents_scale, - gfx::Size tile_size) { +const PictureLayerTiling* PictureLayerTilingSet::AddTiling( + float contents_scale, + gfx::Size tile_size) { tilings_.append(PictureLayerTiling::Create(contents_scale, tile_size)); tilings_.last()->SetClient(client_); tilings_.last()->SetLayerBounds(layer_bounds_); + return tilings_.last(); } void PictureLayerTilingSet::Reset() { diff --git a/cc/picture_layer_tiling_set.h b/cc/picture_layer_tiling_set.h index bc70927..29ad92f 100644 --- a/cc/picture_layer_tiling_set.h +++ b/cc/picture_layer_tiling_set.h @@ -18,14 +18,20 @@ class CC_EXPORT PictureLayerTilingSet { ~PictureLayerTilingSet(); // Shallow copies all data (except client) from other. - void CloneFrom(const PictureLayerTilingSet& other); + void CloneAll( + const PictureLayerTilingSet& other, + const Region& invalidation); + void Clone(const PictureLayerTiling* tiling, const Region& invalidation); + + // TODO(enne): Remove this once syncing happens to the pending tree. + void Invalidate(const Region& invalidation); void SetLayerBounds(gfx::Size layer_bounds); gfx::Size LayerBounds() const; - void Invalidate(const Region& invalidation); - - void AddTiling(float contents_scale, gfx::Size tile_size); + const PictureLayerTiling* AddTiling( + float contents_scale, + gfx::Size tile_size); size_t num_tilings() const { return tilings_.size(); } void Reset(); @@ -76,6 +82,7 @@ class CC_EXPORT PictureLayerTilingSet { PictureLayerTilingClient* client_; gfx::Size layer_bounds_; ScopedPtrVector<PictureLayerTiling> tilings_; + Region invalidation_; friend class Iterator; }; |