| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "cc/layers/picture_layer.h" | 9 #include "cc/layers/picture_layer.h" |
| 10 #include "cc/test/fake_content_layer_client.h" | 10 #include "cc/test/fake_content_layer_client.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 static scoped_ptr<TestablePictureLayerImpl> Create( | 25 static scoped_ptr<TestablePictureLayerImpl> Create( |
| 26 LayerTreeImpl* tree_impl, | 26 LayerTreeImpl* tree_impl, |
| 27 int id, | 27 int id, |
| 28 scoped_refptr<PicturePileImpl> pile) { | 28 scoped_refptr<PicturePileImpl> pile) { |
| 29 return make_scoped_ptr(new TestablePictureLayerImpl(tree_impl, id, pile)); | 29 return make_scoped_ptr(new TestablePictureLayerImpl(tree_impl, id, pile)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 PictureLayerTilingSet& tilings() { return *tilings_; } | 32 PictureLayerTilingSet& tilings() { return *tilings_; } |
| 33 Region& invalidation() { return invalidation_; } | 33 Region& invalidation() { return invalidation_; } |
| 34 | 34 |
| 35 virtual gfx::Size CalculateTileSize( | |
| 36 gfx::Size current_tile_size, | |
| 37 gfx::Size content_bounds) OVERRIDE { | |
| 38 if (current_tile_size.IsEmpty()) | |
| 39 return gfx::Size(100, 100); | |
| 40 return current_tile_size; | |
| 41 } | |
| 42 | |
| 43 using PictureLayerImpl::AddTiling; | 35 using PictureLayerImpl::AddTiling; |
| 44 using PictureLayerImpl::CleanUpTilingsOnActiveLayer; | 36 using PictureLayerImpl::CleanUpTilingsOnActiveLayer; |
| 45 | 37 |
| 46 private: | 38 private: |
| 47 TestablePictureLayerImpl( | 39 TestablePictureLayerImpl( |
| 48 LayerTreeImpl* tree_impl, | 40 LayerTreeImpl* tree_impl, |
| 49 int id, | 41 int id, |
| 50 scoped_refptr<PicturePileImpl> pile) | 42 scoped_refptr<PicturePileImpl> pile) |
| 51 : PictureLayerImpl(tree_impl, id) { | 43 : PictureLayerImpl(tree_impl, id) { |
| 52 pile_ = pile; | 44 pile_ = pile; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 154 |
| 163 SetupPendingTree(pending_pile); | 155 SetupPendingTree(pending_pile); |
| 164 pending_layer_ = static_cast<TestablePictureLayerImpl*>( | 156 pending_layer_ = static_cast<TestablePictureLayerImpl*>( |
| 165 host_impl_.pending_tree()->LayerById(id_)); | 157 host_impl_.pending_tree()->LayerById(id_)); |
| 166 } | 158 } |
| 167 | 159 |
| 168 void AddDefaultTilingsWithInvalidation(const Region& invalidation) { | 160 void AddDefaultTilingsWithInvalidation(const Region& invalidation) { |
| 169 active_layer_->AddTiling(2.3f); | 161 active_layer_->AddTiling(2.3f); |
| 170 active_layer_->AddTiling(1.0f); | 162 active_layer_->AddTiling(1.0f); |
| 171 active_layer_->AddTiling(0.5f); | 163 active_layer_->AddTiling(0.5f); |
| 164 for (size_t i = 0; i < active_layer_->tilings().num_tilings(); ++i) |
| 165 active_layer_->tilings().tiling_at(i)->CreateAllTilesForTesting(); |
| 172 pending_layer_->invalidation() = invalidation; | 166 pending_layer_->invalidation() = invalidation; |
| 173 pending_layer_->SyncFromActiveLayer(); | 167 pending_layer_->SyncFromActiveLayer(); |
| 168 for (size_t i = 0; i < pending_layer_->tilings().num_tilings(); ++i) |
| 169 pending_layer_->tilings().tiling_at(i)->CreateAllTilesForTesting(); |
| 174 } | 170 } |
| 175 | 171 |
| 176 void SetupPendingTree( | 172 void SetupPendingTree( |
| 177 scoped_refptr<PicturePileImpl> pile) { | 173 scoped_refptr<PicturePileImpl> pile) { |
| 178 host_impl_.CreatePendingTree(); | 174 host_impl_.CreatePendingTree(); |
| 179 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 175 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
| 180 // Clear recycled tree. | 176 // Clear recycled tree. |
| 181 pending_tree->DetachLayerTree(); | 177 pending_tree->DetachLayerTree(); |
| 182 | 178 |
| 183 scoped_ptr<TestablePictureLayerImpl> pending_layer = | 179 scoped_ptr<TestablePictureLayerImpl> pending_layer = |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 220 |
| 225 SetupTrees(pending_pile, active_pile); | 221 SetupTrees(pending_pile, active_pile); |
| 226 | 222 |
| 227 host_impl_.active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f); | 223 host_impl_.active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f); |
| 228 float result_scale_x, result_scale_y; | 224 float result_scale_x, result_scale_y; |
| 229 gfx::Size result_bounds; | 225 gfx::Size result_bounds; |
| 230 active_layer_->CalculateContentsScale( | 226 active_layer_->CalculateContentsScale( |
| 231 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | 227 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 232 | 228 |
| 233 // Add 1x1 rects at the centers of each tile, then re-record pile contents | 229 // Add 1x1 rects at the centers of each tile, then re-record pile contents |
| 230 active_layer_->tilings().tiling_at(0)->CreateAllTilesForTesting(); |
| 234 std::vector<Tile*> tiles = | 231 std::vector<Tile*> tiles = |
| 235 active_layer_->tilings().tiling_at(0)->AllTilesForTesting(); | 232 active_layer_->tilings().tiling_at(0)->AllTilesForTesting(); |
| 236 EXPECT_EQ(16u, tiles.size()); | 233 EXPECT_EQ(16u, tiles.size()); |
| 237 std::vector<SkRect> rects; | 234 std::vector<SkRect> rects; |
| 238 std::vector<Tile*>::const_iterator tile_iter; | 235 std::vector<Tile*>::const_iterator tile_iter; |
| 239 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { | 236 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { |
| 240 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); | 237 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); |
| 241 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1); | 238 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1); |
| 242 active_pile->add_draw_rect(rect); | 239 active_pile->add_draw_rect(rect); |
| 243 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1)); | 240 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1)); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 gfx::Rect(active_layer_bounds), | 391 gfx::Rect(active_layer_bounds), |
| 395 tiling->contents_scale())); | 392 tiling->contents_scale())); |
| 396 for (PictureLayerTiling::CoverageIterator | 393 for (PictureLayerTiling::CoverageIterator |
| 397 iter(tiling, | 394 iter(tiling, |
| 398 tiling->contents_scale(), | 395 tiling->contents_scale(), |
| 399 tiling->ContentRect()); | 396 tiling->ContentRect()); |
| 400 iter; | 397 iter; |
| 401 ++iter) { | 398 ++iter) { |
| 402 EXPECT_TRUE(*iter); | 399 EXPECT_TRUE(*iter); |
| 403 EXPECT_FALSE(iter.geometry_rect().IsEmpty()); | 400 EXPECT_FALSE(iter.geometry_rect().IsEmpty()); |
| 401 std::vector<Tile*> active_tiles = |
| 402 active_layer_->tilings().tiling_at(i)->AllTilesForTesting(); |
| 403 std::vector<Tile*> pending_tiles = tiling->AllTilesForTesting(); |
| 404 if (iter.geometry_rect().right() >= active_content_bounds.width() || | 404 if (iter.geometry_rect().right() >= active_content_bounds.width() || |
| 405 iter.geometry_rect().bottom() >= active_content_bounds.height()) { | 405 iter.geometry_rect().bottom() >= active_content_bounds.height() || |
| 406 active_tiles[0]->content_rect().size() != |
| 407 pending_tiles[0]->content_rect().size()) { |
| 406 EXPECT_EQ(pending_pile, iter->picture_pile()); | 408 EXPECT_EQ(pending_pile, iter->picture_pile()); |
| 407 } else { | 409 } else { |
| 408 EXPECT_EQ(active_pile, iter->picture_pile()); | 410 EXPECT_EQ(active_pile, iter->picture_pile()); |
| 409 } | 411 } |
| 410 } | 412 } |
| 411 } | 413 } |
| 412 } | 414 } |
| 413 | 415 |
| 414 TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) { | 416 TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) { |
| 415 gfx::Size tile_size(400, 400); | 417 gfx::Size tile_size(400, 400); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); | 724 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); |
| 723 | 725 |
| 724 // This should create new tilings. | 726 // This should create new tilings. |
| 725 pending_layer_->CalculateContentsScale( | 727 pending_layer_->CalculateContentsScale( |
| 726 1.3f, false, &result_scale_x, &result_scale_y, &result_bounds); | 728 1.3f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 727 EXPECT_EQ(2u, pending_layer_->tilings().num_tilings()); | 729 EXPECT_EQ(2u, pending_layer_->tilings().num_tilings()); |
| 728 } | 730 } |
| 729 | 731 |
| 730 } // namespace | 732 } // namespace |
| 731 } // namespace cc | 733 } // namespace cc |
| OLD | NEW |