diff options
author | skyostil@google.com <skyostil@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 13:03:52 +0000 |
---|---|---|
committer | skyostil@google.com <skyostil@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 13:03:52 +0000 |
commit | 5e427e1232e0297002146af18f3df7633474f77e (patch) | |
tree | 4cc47a7b53090dcf6369300b8034dec16af0ecc2 /cc | |
parent | 5ab08b85eb3cace8d8a9ada2beab220096da207f (diff) | |
download | chromium_src-5e427e1232e0297002146af18f3df7633474f77e.zip chromium_src-5e427e1232e0297002146af18f3df7633474f77e.tar.gz chromium_src-5e427e1232e0297002146af18f3df7633474f77e.tar.bz2 |
Revert 207360 "cc: Recycle tilings to make SetLiveTilesRect cheaper"
PictureLayerTilingSetSyncTest.Invalidation seems to be flaky on Android. For example:
http://build.chromium.org/p/chromium.fyi/builders/Android%20Tests%20%28JB%20GalaxyNexus%29%28dbg%29/builds/12538/steps/cc_unittests/logs/stdio
> cc: Recycle tilings to make SetLiveTilesRect cheaper
>
> Rather than recreating new tilings every frame, use the tilings and old tiles
> from the recycle tree in order to prevent excessive amounts of tile allocations
> (1 per tile) during the first update. In order to reuse a tiling from two
> frames ago, the tilings must be resized, invalidated, have their pile updated,
> and also any missing tiles that can now be rastered need to be filled in.
>
> This brings back a bunch of functions that were removed in
> https://codereview.chromium.org/14600003/ to enable tilings to be resized and
> updated at times other than SetLiveTilesRect.
>
> This patch makes SetLiveTilesRect on the pending tree go from 2.2ms to 0.16ms
> on average on an N4 for the heavy page linked in the bug with ~700 tiles. On a
> page with about 300 tiles and fewer commits, this patch is a slight win but is
> mostly in the noise.
>
> R=danakj@chromium.org
> BUG=248954
>
> Review URL: https://chromiumcodereview.appspot.com/16888016
TBR=enne@chromium.org
Review URL: https://codereview.chromium.org/17176009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layers/picture_layer.cc | 2 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl.cc | 38 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl.h | 3 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling.cc | 74 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling.h | 7 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling_set.cc | 49 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling_set.h | 11 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling_set_unittest.cc | 269 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling_unittest.cc | 4 | ||||
-rw-r--r-- | cc/test/fake_picture_layer_impl.cc | 2 | ||||
-rw-r--r-- | cc/test/fake_picture_layer_tiling_client.h | 1 |
11 files changed, 31 insertions, 429 deletions
diff --git a/cc/layers/picture_layer.cc b/cc/layers/picture_layer.cc index 7ab5847..179a2cf 100644 --- a/cc/layers/picture_layer.cc +++ b/cc/layers/picture_layer.cc @@ -41,7 +41,7 @@ void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { layer_impl->UpdateTwinLayer(); layer_impl->SetIsMask(is_mask_); - layer_impl->CreateTilingSetIfNeeded(); + layer_impl->CreateTilingSet(); // Unlike other properties, invalidation must always be set on layer_impl. // See PictureLayerImpl::PushPropertiesTo for more details. layer_impl->invalidation_.Clear(); diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc index 7283bec..84a7d9c 100644 --- a/cc/layers/picture_layer_impl.cc +++ b/cc/layers/picture_layer_impl.cc @@ -60,10 +60,17 @@ scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); } -void PictureLayerImpl::CreateTilingSetIfNeeded() { +void PictureLayerImpl::CreateTilingSet() { DCHECK(layer_tree_impl()->IsPendingTree()); - if (!tilings_) - tilings_.reset(new PictureLayerTilingSet(this, bounds())); + DCHECK(!tilings_); + tilings_.reset(new PictureLayerTilingSet(this, bounds())); +} + +void PictureLayerImpl::TransferTilingSet( + scoped_ptr<PictureLayerTilingSet> tilings) { + DCHECK(layer_tree_impl()->IsActiveTree()); + tilings->SetClient(this); + tilings_ = tilings.Pass(); } void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { @@ -77,13 +84,9 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { twin_layer_ = NULL; layer_impl->SetIsMask(is_mask_); + layer_impl->TransferTilingSet(tilings_.Pass()); layer_impl->pile_ = pile_; - pile_ = NULL; - - layer_impl->tilings_.swap(tilings_); - layer_impl->tilings_->SetClient(layer_impl); - if (tilings_) - tilings_->SetClient(this); + pile_ = PicturePileImpl::Create(is_using_lcd_text_); layer_impl->raster_page_scale_ = raster_page_scale_; layer_impl->raster_device_scale_ = raster_device_scale_; @@ -557,6 +560,8 @@ void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { // trade-off for memory (use the same pile as much as possible, by switching // during DidBecomeActive) and for time (don't bother checking every tile // during activation to see if the new pile can still raster it). + // + // TODO(enne): Clean up this double loop. for (int x = 0; x < pile_->num_tiles_x(); ++x) { for (int y = 0; y < pile_->num_tiles_y(); ++y) { bool previously_had = other->pile_->HasRecordingAt(x, y); @@ -573,16 +578,11 @@ void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { difference_region.Subtract(gfx::Rect(other->bounds())); invalidation_.Union(difference_region); - if (CanHaveTilings()) { - // The reason the active layer's invalidation is needed here is becuase - // the recycle tree hasn't had that invalidation applied to it yet. - tilings_->SyncTilings(*other->tilings_, - bounds(), - other->invalidation_, - MinimumContentsScale()); - } else { - tilings_->RemoveAllTilings(); - } + tilings_->RemoveAllTilings(); + if (CanHaveTilings()) + tilings_->AddTilingsToMatchScales(*other->tilings_, MinimumContentsScale()); + + DCHECK(bounds() == tilings_->layer_bounds()); } void PictureLayerImpl::SyncTiling( diff --git a/cc/layers/picture_layer_impl.h b/cc/layers/picture_layer_impl.h index 7d97156..ad96c6f 100644 --- a/cc/layers/picture_layer_impl.h +++ b/cc/layers/picture_layer_impl.h @@ -67,7 +67,8 @@ class CC_EXPORT PictureLayerImpl void SyncTiling(const PictureLayerTiling* tiling); void UpdateTwinLayer(); - void CreateTilingSetIfNeeded(); + void CreateTilingSet(); + void TransferTilingSet(scoped_ptr<PictureLayerTilingSet> tilings); // Mask-related functions void SetIsMask(bool is_mask); diff --git a/cc/resources/picture_layer_tiling.cc b/cc/resources/picture_layer_tiling.cc index 75e06f8..0dc42fa 100644 --- a/cc/resources/picture_layer_tiling.cc +++ b/cc/resources/picture_layer_tiling.cc @@ -128,74 +128,6 @@ void PictureLayerTiling::DestroyAndRecreateTilesWithText() { } } -void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { - const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); - for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_); iter; - ++iter) { - TileMapKey key = iter.index(); - TileMap::iterator find = tiles_.find(key); - if (find != tiles_.end()) - continue; - CreateTile(key.first, key.second, twin_tiling); - } -} - -void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) { - if (layer_bounds_ == layer_bounds) - return; - - DCHECK(!layer_bounds.IsEmpty()); - - gfx::Size old_layer_bounds = layer_bounds_; - layer_bounds_ = layer_bounds; - gfx::Size old_content_bounds = tiling_data_.total_size(); - gfx::Size content_bounds = - gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); - - gfx::Size tile_size = client_->CalculateTileSize(content_bounds); - if (tile_size != tiling_data_.max_texture_size()) { - tiling_data_.SetTotalSize(content_bounds); - tiling_data_.SetMaxTextureSize(tile_size); - Reset(); - return; - } - - // Any tiles outside our new bounds are invalid and should be dropped. - gfx::Rect bounded_live_tiles_rect(live_tiles_rect_); - bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds)); - SetLiveTilesRect(bounded_live_tiles_rect); - tiling_data_.SetTotalSize(content_bounds); - - // Create tiles for newly exposed areas. - Region layer_region((gfx::Rect(layer_bounds_))); - layer_region.Subtract(gfx::Rect(old_layer_bounds)); - Invalidate(layer_region); -} - -void PictureLayerTiling::Invalidate(const Region& layer_region) { - std::vector<TileMapKey> new_tile_keys; - for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { - gfx::Rect layer_rect = iter.rect(); - gfx::Rect content_rect = - gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); - content_rect.Intersect(live_tiles_rect_); - if (content_rect.IsEmpty()) - continue; - for (TilingData::Iterator iter(&tiling_data_, content_rect); iter; ++iter) { - TileMapKey key(iter.index()); - TileMap::iterator find = tiles_.find(key); - if (find == tiles_.end()) - continue; - tiles_.erase(find); - new_tile_keys.push_back(key); - } - } - - const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); - for (size_t i = 0; i < new_tile_keys.size(); ++i) - CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); -} - PictureLayerTiling::CoverageIterator::CoverageIterator() : tiling_(NULL), current_tile_(NULL), @@ -555,12 +487,6 @@ void PictureLayerTiling::DidBecomeActive() { } } -void PictureLayerTiling::UpdateTilesToCurrentPile() { - for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { - client_->UpdatePile(it->second.get()); - } -} - scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); state->SetInteger("num_tiles", tiles_.size()); diff --git a/cc/resources/picture_layer_tiling.h b/cc/resources/picture_layer_tiling.h index 37031e5..6818868 100644 --- a/cc/resources/picture_layer_tiling.h +++ b/cc/resources/picture_layer_tiling.h @@ -54,10 +54,7 @@ class CC_EXPORT PictureLayerTiling { gfx::Size layer_bounds, PictureLayerTilingClient* client); gfx::Size layer_bounds() const { return layer_bounds_; } - void SetLayerBounds(gfx::Size layer_bounds); - void Invalidate(const Region& layer_region); void DestroyAndRecreateTilesWithText(); - void CreateMissingTilesInLiveTilesRect(); void SetClient(PictureLayerTilingClient* client); void set_resolution(TileResolution resolution) { resolution_ = resolution; } @@ -65,8 +62,6 @@ class CC_EXPORT PictureLayerTiling { gfx::Rect ContentRect() const; gfx::SizeF ContentSizeF() const; - gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } - gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } float contents_scale() const { return contents_scale_; } void CreateAllTilesForTesting() { @@ -150,8 +145,6 @@ class CC_EXPORT PictureLayerTiling { // also updates the pile on each tile to be the current client's pile. void DidBecomeActive(); - void UpdateTilesToCurrentPile(); - bool NeedsUpdateForFrameAtTime(double frame_time_in_seconds) { return frame_time_in_seconds != last_impl_frame_time_in_seconds_; } diff --git a/cc/resources/picture_layer_tiling_set.cc b/cc/resources/picture_layer_tiling_set.cc index c2bfb93..9ca9a6a 100644 --- a/cc/resources/picture_layer_tiling_set.cc +++ b/cc/resources/picture_layer_tiling_set.cc @@ -36,55 +36,26 @@ void PictureLayerTilingSet::SetClient(PictureLayerTilingClient* client) { tilings_[i]->SetClient(client_); } -void PictureLayerTilingSet::SyncTilings( +void PictureLayerTilingSet::AddTilingsToMatchScales( const PictureLayerTilingSet& other, - gfx::Size new_layer_bounds, - const Region& layer_invalidation, float minimum_contents_scale) { - if (new_layer_bounds.IsEmpty()) { - RemoveAllTilings(); - layer_bounds_ = new_layer_bounds; - return; - } - + DCHECK(tilings_.empty()); tilings_.reserve(other.tilings_.size()); - - // Remove any tilings that aren't in |other| or don't meet the minimum. - for (size_t i = 0; i < tilings_.size(); ++i) { - float scale = tilings_[i]->contents_scale(); - if (scale >= minimum_contents_scale && !!other.TilingAtScale(scale)) - continue; - // Swap with the last element and remove it. - tilings_.swap(tilings_.begin() + i, tilings_.end() - 1); - tilings_.pop_back(); - --i; - } - - // Add any missing tilings from |other| that meet the minimum. for (size_t i = 0; i < other.tilings_.size(); ++i) { float contents_scale = other.tilings_[i]->contents_scale(); if (contents_scale < minimum_contents_scale) continue; - if (PictureLayerTiling* this_tiling = TilingAtScale(contents_scale)) { - this_tiling->set_resolution(other.tilings_[i]->resolution()); - this_tiling->UpdateTilesToCurrentPile(); - this_tiling->SetLayerBounds(new_layer_bounds); - this_tiling->Invalidate(layer_invalidation); - this_tiling->CreateMissingTilesInLiveTilesRect(); - DCHECK(this_tiling->tile_size() == - client_->CalculateTileSize(this_tiling->ContentRect().size())); - continue; - } scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create( contents_scale, - new_layer_bounds, + layer_bounds_, client_); + // We need to copy the resolution to ensure that the information is not + // lost on this tiling. This is safe, since we know the current set begins + // empty (ie we will not end up with multiple HIGH RES tilings). new_tiling->set_resolution(other.tilings_[i]->resolution()); tilings_.push_back(new_tiling.Pass()); } tilings_.sort(LargestToSmallestScaleFunctor()); - - layer_bounds_ = new_layer_bounds; } void PictureLayerTilingSet::DestroyAndRecreateTilesWithText() { @@ -105,14 +76,6 @@ PictureLayerTiling* PictureLayerTilingSet::AddTiling(float contents_scale) { return appended; } -PictureLayerTiling* PictureLayerTilingSet::TilingAtScale(float scale) const { - for (size_t i = 0; i < tilings_.size(); ++i) { - if (tilings_[i]->contents_scale() == scale) - return tilings_[i]; - } - return NULL; -} - void PictureLayerTilingSet::RemoveAllTilings() { tilings_.clear(); } diff --git a/cc/resources/picture_layer_tiling_set.h b/cc/resources/picture_layer_tiling_set.h index aba6802..3a7b251 100644 --- a/cc/resources/picture_layer_tiling_set.h +++ b/cc/resources/picture_layer_tiling_set.h @@ -19,16 +19,9 @@ class CC_EXPORT PictureLayerTilingSet { ~PictureLayerTilingSet(); void SetClient(PictureLayerTilingClient* client); - const PictureLayerTilingClient* client() const { return client_; } - // Make this set of tilings match the same set of content scales from |other|. - // Delete any tilings that don't meet |minimum_contents_scale|. Recreate - // any tiles that intersect |layer_invalidation|. Update the size of all - // tilings to |new_layer_bounds|. - void SyncTilings( + void AddTilingsToMatchScales( const PictureLayerTilingSet& other, - gfx::Size new_layer_bounds, - const Region& layer_invalidation, float minimum_contents_scale); gfx::Size layer_bounds() const { return layer_bounds_; } @@ -42,8 +35,6 @@ class CC_EXPORT PictureLayerTilingSet { return tilings_[idx]; } - PictureLayerTiling* TilingAtScale(float scale) const; - // Remove all tilings. void RemoveAllTilings(); diff --git a/cc/resources/picture_layer_tiling_set_unittest.cc b/cc/resources/picture_layer_tiling_set_unittest.cc index 822fffb..7d92d83 100644 --- a/cc/resources/picture_layer_tiling_set_unittest.cc +++ b/cc/resources/picture_layer_tiling_set_unittest.cc @@ -4,7 +4,6 @@ #include "cc/resources/picture_layer_tiling_set.h" -#include <map> #include <vector> #include "cc/resources/resource_pool.h" @@ -148,273 +147,5 @@ TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_NotEqual) { runTest(10, 1.f, 1.f, 4.5f, 5.f); } -class PictureLayerTilingSetSyncTest : public testing::Test { - public: - PictureLayerTilingSetSyncTest() - : tile_size_(gfx::Size(10, 10)), - source_bounds_(gfx::Size(30, 20)), - target_bounds_(gfx::Size(30, 30)) { - source_client_.SetTileSize(tile_size_); - target_client_.SetTileSize(tile_size_); - source_.reset(new PictureLayerTilingSet(&source_client_, source_bounds_)); - target_.reset(new PictureLayerTilingSet(&target_client_, target_bounds_)); - } - - // Sync from source to target. - void SyncTilings(gfx::Size new_bounds, - const Region& invalidation, - float minimum_scale) { - for (size_t i = 0; i < source_->num_tilings(); ++i) - source_->tiling_at(i)->CreateAllTilesForTesting(); - for (size_t i = 0; i < target_->num_tilings(); ++i) - target_->tiling_at(i)->CreateAllTilesForTesting(); - - target_->SyncTilings( - *source_.get(), new_bounds, invalidation, minimum_scale); - } - void SyncTilings(gfx::Size new_bounds) { - Region invalidation; - SyncTilings(new_bounds, invalidation, 0.f); - } - void SyncTilings(gfx::Size new_bounds, const Region& invalidation) { - SyncTilings(new_bounds, invalidation, 0.f); - } - void SyncTilings(gfx::Size new_bounds, float minimum_scale) { - Region invalidation; - SyncTilings(new_bounds, invalidation, minimum_scale); - } - - void VerifyTargetEqualsSource(gfx::Size new_bounds) const { - ASSERT_FALSE(new_bounds.IsEmpty()); - EXPECT_EQ(target_->num_tilings(), source_->num_tilings()); - EXPECT_EQ(target_->layer_bounds().ToString(), new_bounds.ToString()); - - for (size_t i = 0; i < target_->num_tilings(); ++i) { - ASSERT_GT(source_->num_tilings(), i); - const PictureLayerTiling* source_tiling = source_->tiling_at(i); - const PictureLayerTiling* target_tiling = target_->tiling_at(i); - EXPECT_EQ(target_tiling->layer_bounds().ToString(), - new_bounds.ToString()); - EXPECT_EQ(source_tiling->contents_scale(), - target_tiling->contents_scale()); - } - - EXPECT_EQ(source_->client(), &source_client_); - EXPECT_EQ(target_->client(), &target_client_); - ValidateTargetTilingSet(); - } - - void ValidateTargetTilingSet() const { - // Tilings should be sorted largest to smallest. - if (target_->num_tilings() > 0) { - float last_scale = target_->tiling_at(0)->contents_scale(); - for (size_t i = 1; i < target_->num_tilings(); ++i) { - const PictureLayerTiling* target_tiling = target_->tiling_at(i); - EXPECT_LT(target_tiling->contents_scale(), last_scale); - last_scale = target_tiling->contents_scale(); - } - } - - for (size_t i = 0; i < target_->num_tilings(); ++i) - ValidateTiling(target_->tiling_at(i), target_client_.pile()); - } - - void ValidateTiling(const PictureLayerTiling* tiling, - const PicturePileImpl* pile) const { - if (tiling->ContentRect().IsEmpty()) - EXPECT_TRUE(tiling->live_tiles_rect().IsEmpty()); - else if (!tiling->live_tiles_rect().IsEmpty()) - EXPECT_TRUE(tiling->ContentRect().Contains(tiling->live_tiles_rect())); - - std::vector<Tile*> tiles = tiling->AllTilesForTesting(); - for (size_t i = 0; i < tiles.size(); ++i) { - const Tile* tile = tiles[i]; - ASSERT_TRUE(!!tile); - EXPECT_EQ(tile->picture_pile(), pile); - EXPECT_TRUE(tile->content_rect().Intersects(tiling->live_tiles_rect())) - << "All tiles must be inside the live tiles rect."; - } - - for (PictureLayerTiling::CoverageIterator iter( - tiling, tiling->contents_scale(), tiling->live_tiles_rect()); - iter; - ++iter) { - EXPECT_TRUE(*iter) << "The live tiles rect must be full."; - } - } - - gfx::Size tile_size_; - - FakePictureLayerTilingClient source_client_; - gfx::Size source_bounds_; - scoped_ptr<PictureLayerTilingSet> source_; - - FakePictureLayerTilingClient target_client_; - gfx::Size target_bounds_; - scoped_ptr<PictureLayerTilingSet> target_; -}; - -TEST_F(PictureLayerTilingSetSyncTest, EmptyBounds) { - float source_scales[] = {1.f, 1.2f}; - for (size_t i = 0; i < arraysize(source_scales); ++i) - source_->AddTiling(source_scales[i]); - - gfx::Size new_bounds; - SyncTilings(new_bounds); - EXPECT_EQ(target_->num_tilings(), 0u); - EXPECT_EQ(target_->layer_bounds().ToString(), new_bounds.ToString()); -} - -TEST_F(PictureLayerTilingSetSyncTest, AllNew) { - float source_scales[] = {0.5f, 1.f, 1.2f}; - for (size_t i = 0; i < arraysize(source_scales); ++i) - source_->AddTiling(source_scales[i]); - float target_scales[] = {0.75f, 1.4f, 3.f}; - for (size_t i = 0; i < arraysize(target_scales); ++i) - target_->AddTiling(target_scales[i]); - - gfx::Size new_bounds(15, 40); - SyncTilings(new_bounds); - VerifyTargetEqualsSource(new_bounds); -} - -Tile* FindTileAtOrigin(PictureLayerTiling* tiling) { - std::vector<Tile*> tiles = tiling->AllTilesForTesting(); - for (size_t i = 0; i < tiles.size(); ++i) { - if (tiles[i]->content_rect().origin() == gfx::Point()) - return tiles[i]; - } - return NULL; -} - -TEST_F(PictureLayerTilingSetSyncTest, KeepExisting) { - float source_scales[] = {0.7f, 1.f, 1.1f, 2.f}; - for (size_t i = 0; i < arraysize(source_scales); ++i) - source_->AddTiling(source_scales[i]); - float target_scales[] = {0.5f, 1.f, 2.f}; - for (size_t i = 0; i < arraysize(target_scales); ++i) - target_->AddTiling(target_scales[i]); - - PictureLayerTiling* tiling1 = source_->TilingAtScale(1.f); - ASSERT_TRUE(tiling1); - tiling1->CreateAllTilesForTesting(); - EXPECT_EQ(tiling1->contents_scale(), 1.f); - Tile* tile1 = FindTileAtOrigin(tiling1); - ASSERT_TRUE(tile1); - - PictureLayerTiling* tiling2 = source_->TilingAtScale(2.f); - tiling2->CreateAllTilesForTesting(); - ASSERT_TRUE(tiling2); - EXPECT_EQ(tiling2->contents_scale(), 2.f); - Tile* tile2 = FindTileAtOrigin(tiling2); - ASSERT_TRUE(tile2); - - gfx::Size new_bounds(15, 40); - SyncTilings(new_bounds); - VerifyTargetEqualsSource(new_bounds); - - EXPECT_EQ(tiling1, source_->TilingAtScale(1.f)); - EXPECT_EQ(tile1, FindTileAtOrigin(tiling1)); - EXPECT_FALSE(tiling1->live_tiles_rect().IsEmpty()); - - EXPECT_EQ(tiling2, source_->TilingAtScale(2.f)); - EXPECT_EQ(tile2, FindTileAtOrigin(tiling2)); - EXPECT_FALSE(tiling2->live_tiles_rect().IsEmpty()); -} - -TEST_F(PictureLayerTilingSetSyncTest, EmptySet) { - float target_scales[] = {0.2f, 1.f}; - for (size_t i = 0; i < arraysize(target_scales); ++i) - target_->AddTiling(target_scales[i]); - - gfx::Size new_bounds(15, 40); - SyncTilings(new_bounds); - VerifyTargetEqualsSource(new_bounds); -} - -TEST_F(PictureLayerTilingSetSyncTest, MinimumScale) { - float source_scales[] = {0.7f, 1.f, 1.1f, 2.f}; - for (size_t i = 0; i < arraysize(source_scales); ++i) - source_->AddTiling(source_scales[i]); - float target_scales[] = {0.5f, 0.7f, 1.f, 1.1f, 2.f}; - for (size_t i = 0; i < arraysize(target_scales); ++i) - target_->AddTiling(target_scales[i]); - - gfx::Size new_bounds(15, 40); - float minimum_scale = 1.5f; - SyncTilings(new_bounds, minimum_scale); - - EXPECT_EQ(target_->num_tilings(), 1u); - EXPECT_EQ(target_->tiling_at(0)->contents_scale(), 2.f); - ValidateTargetTilingSet(); -} - -TEST_F(PictureLayerTilingSetSyncTest, Invalidation) { - source_->AddTiling(2.f); - target_->AddTiling(2.f); - target_->tiling_at(0)->CreateAllTilesForTesting(); - - Region layer_invalidation; - layer_invalidation.Union(gfx::Rect(0, 0, 1, 1)); - layer_invalidation.Union(gfx::Rect(0, 15, 1, 1)); - // Out of bounds layer_invalidation. - layer_invalidation.Union(gfx::Rect(100, 100, 1, 1)); - - Region content_invalidation; - for (Region::Iterator iter(layer_invalidation); iter.has_rect(); - iter.next()) { - gfx::Rect content_rect = gfx::ScaleToEnclosingRect(iter.rect(), 2.f); - content_invalidation.Union(content_rect); - } - - std::vector<Tile*> old_tiles = target_->tiling_at(0)->AllTilesForTesting(); - std::map<gfx::Point, Tile*> old_tile_map; - for (size_t i = 0; i < old_tiles.size(); ++i) - old_tile_map[old_tiles[i]->content_rect().origin()] = old_tiles[i]; - - SyncTilings(target_bounds_, layer_invalidation); - VerifyTargetEqualsSource(target_bounds_); - - std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting(); - for (size_t i = 0; i < new_tiles.size(); ++i) { - const Tile* tile = new_tiles[i]; - std::map<gfx::Point, Tile*>::iterator find = - old_tile_map.find(tile->content_rect().origin()); - if (content_invalidation.Intersects(tile->content_rect())) - EXPECT_NE(tile, find->second); - else - EXPECT_EQ(tile, find->second); - } -} - -TEST_F(PictureLayerTilingSetSyncTest, TileSizeChange) { - source_->AddTiling(1.f); - target_->AddTiling(1.f); - - target_->tiling_at(0)->CreateAllTilesForTesting(); - std::vector<Tile*> original_tiles = - target_->tiling_at(0)->AllTilesForTesting(); - EXPECT_GT(original_tiles.size(), 0u); - gfx::Size new_tile_size(100, 100); - target_client_.SetTileSize(new_tile_size); - EXPECT_NE(target_->tiling_at(0)->tile_size().ToString(), - new_tile_size.ToString()); - - gfx::Size new_bounds(15, 40); - SyncTilings(new_bounds); - VerifyTargetEqualsSource(new_bounds); - - EXPECT_EQ(target_->tiling_at(0)->tile_size().ToString(), - new_tile_size.ToString()); - - // All old tiles should not be present in new tiles. - std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting(); - for (size_t i = 0; i < original_tiles.size(); ++i) { - std::vector<Tile*>::iterator find = - std::find(new_tiles.begin(), new_tiles.end(), original_tiles[i]); - EXPECT_TRUE(find == new_tiles.end()); - } -} - } // namespace } // namespace cc diff --git a/cc/resources/picture_layer_tiling_unittest.cc b/cc/resources/picture_layer_tiling_unittest.cc index c76c2b4..e708251 100644 --- a/cc/resources/picture_layer_tiling_unittest.cc +++ b/cc/resources/picture_layer_tiling_unittest.cc @@ -138,7 +138,6 @@ class PictureLayerTilingIteratorTest : public testing::Test { FakePictureLayerTilingClient client_; scoped_ptr<TestablePictureLayerTiling> tiling_; - private: DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); }; @@ -683,8 +682,7 @@ TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { // Add the same tilings to the pending set. PictureLayerTilingSet pending_set(&client_, layer_bounds); - Region invalidation; - pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); + pending_set.AddTilingsToMatchScales(active_set, 0.f); // The pending tiling starts with no tiles. VerifyTiles(pending_set.tiling_at(0), diff --git a/cc/test/fake_picture_layer_impl.cc b/cc/test/fake_picture_layer_impl.cc index dd383a6..d55d680 100644 --- a/cc/test/fake_picture_layer_impl.cc +++ b/cc/test/fake_picture_layer_impl.cc @@ -14,7 +14,7 @@ FakePictureLayerImpl::FakePictureLayerImpl( append_quads_count_(0) { pile_ = pile; SetBounds(pile_->size()); - CreateTilingSetIfNeeded(); + CreateTilingSet(); } FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl* tree_impl, int id) diff --git a/cc/test/fake_picture_layer_tiling_client.h b/cc/test/fake_picture_layer_tiling_client.h index d32cb1e..3593661 100644 --- a/cc/test/fake_picture_layer_tiling_client.h +++ b/cc/test/fake_picture_layer_tiling_client.h @@ -29,7 +29,6 @@ class FakePictureLayerTilingClient : public PictureLayerTilingClient { void SetTileSize(gfx::Size tile_size); gfx::Size TileSize() const { return tile_size_; } scoped_refptr<PicturePileImpl> pile() { return pile_; } - const PicturePileImpl* pile() const { return pile_; } virtual const Region* GetInvalidation() OVERRIDE; virtual const PictureLayerTiling* GetTwinTiling( |