| 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/test/fake_picture_pile_impl.h" | 5 #include "cc/test/fake_picture_pile_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "cc/test/impl_side_painting_settings.h" | 10 #include "cc/test/impl_side_painting_settings.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 FakePicturePileImpl::FakePicturePileImpl() {} | 15 FakePicturePileImpl::FakePicturePileImpl() {} |
| 16 | 16 |
| 17 FakePicturePileImpl::~FakePicturePileImpl() {} | 17 FakePicturePileImpl::~FakePicturePileImpl() {} |
| 18 | 18 |
| 19 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( | 19 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( |
| 20 const gfx::Size& tile_size, | 20 const gfx::Size& tile_size, |
| 21 const gfx::Size& layer_bounds) { | 21 const gfx::Size& layer_bounds) { |
| 22 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); | 22 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); |
| 23 pile->tiling().SetTotalSize(layer_bounds); | 23 pile->tiling().SetTotalSize(layer_bounds); |
| 24 pile->tiling().SetMaxTextureSize(tile_size); | 24 pile->tiling().SetMaxTextureSize(tile_size); |
| 25 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size); | 25 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size); |
| 26 pile->recorded_viewport_ = gfx::Rect(layer_bounds); |
| 27 pile->has_any_recordings_ = true; |
| 26 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) { | 28 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) { |
| 27 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y) | 29 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y) |
| 28 pile->AddRecordingAt(x, y); | 30 pile->AddRecordingAt(x, y); |
| 29 } | 31 } |
| 30 pile->UpdateRecordedRegion(); | |
| 31 return pile; | 32 return pile; |
| 32 } | 33 } |
| 33 | 34 |
| 34 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( | 35 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( |
| 35 const gfx::Size& tile_size, | 36 const gfx::Size& tile_size, |
| 36 const gfx::Size& layer_bounds) { | 37 const gfx::Size& layer_bounds) { |
| 37 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); | 38 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); |
| 38 pile->tiling().SetTotalSize(layer_bounds); | 39 pile->tiling().SetTotalSize(layer_bounds); |
| 39 pile->tiling().SetMaxTextureSize(tile_size); | 40 pile->tiling().SetMaxTextureSize(tile_size); |
| 40 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size); | 41 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size); |
| 41 pile->UpdateRecordedRegion(); | 42 pile->recorded_viewport_ = gfx::Rect(); |
| 43 pile->has_any_recordings_ = false; |
| 42 return pile; | 44 return pile; |
| 43 } | 45 } |
| 44 | 46 |
| 45 scoped_refptr<FakePicturePileImpl> | 47 scoped_refptr<FakePicturePileImpl> |
| 46 FakePicturePileImpl::CreatePileWithRecordedRegion( | 48 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( |
| 47 const gfx::Size& tile_size, | 49 const gfx::Size& tile_size, |
| 48 const gfx::Size& layer_bounds, | 50 const gfx::Size& layer_bounds) { |
| 49 const Region& recorded_region) { | |
| 50 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); | 51 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); |
| 51 pile->tiling().SetTotalSize(layer_bounds); | 52 pile->tiling().SetTotalSize(layer_bounds); |
| 52 pile->tiling().SetMaxTextureSize(tile_size); | 53 pile->tiling().SetMaxTextureSize(tile_size); |
| 53 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size); | 54 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size); |
| 54 pile->SetRecordedRegionForTesting(recorded_region); | 55 // This simulates a false positive for this flag. |
| 56 pile->recorded_viewport_ = gfx::Rect(); |
| 57 pile->has_any_recordings_ = true; |
| 55 return pile; | 58 return pile; |
| 56 } | 59 } |
| 57 | 60 |
| 58 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreatePile() { | 61 scoped_refptr<FakePicturePileImpl> |
| 62 FakePicturePileImpl::CreateInfiniteFilledPile() { |
| 59 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); | 63 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); |
| 60 gfx::Size size(std::numeric_limits<int>::max(), | 64 gfx::Size size(std::numeric_limits<int>::max(), |
| 61 std::numeric_limits<int>::max()); | 65 std::numeric_limits<int>::max()); |
| 62 pile->Resize(size); | 66 pile->Resize(size); |
| 63 pile->recorded_region_ = Region(gfx::Rect(size)); | 67 pile->tiling().SetTotalSize(size); |
| 68 pile->tiling().SetMaxTextureSize(size); |
| 69 pile->SetTileGridSize(size); |
| 70 pile->recorded_viewport_ = gfx::Rect(size); |
| 71 pile->has_any_recordings_ = true; |
| 72 pile->AddRecordingAt(0, 0); |
| 64 return pile; | 73 return pile; |
| 65 } | 74 } |
| 66 | 75 |
| 67 void FakePicturePileImpl::AddRecordingAt(int x, int y) { | 76 void FakePicturePileImpl::AddRecordingAt(int x, int y) { |
| 68 EXPECT_GE(x, 0); | 77 EXPECT_GE(x, 0); |
| 69 EXPECT_GE(y, 0); | 78 EXPECT_GE(y, 0); |
| 70 EXPECT_LT(x, tiling_.num_tiles_x()); | 79 EXPECT_LT(x, tiling_.num_tiles_x()); |
| 71 EXPECT_LT(y, tiling_.num_tiles_y()); | 80 EXPECT_LT(y, tiling_.num_tiles_y()); |
| 72 | 81 |
| 73 if (HasRecordingAt(x, y)) | 82 if (HasRecordingAt(x, y)) |
| 74 return; | 83 return; |
| 75 gfx::Rect bounds(tiling().TileBounds(x, y)); | 84 gfx::Rect bounds(tiling().TileBounds(x, y)); |
| 76 bounds.Inset(-buffer_pixels(), -buffer_pixels()); | 85 bounds.Inset(-buffer_pixels(), -buffer_pixels()); |
| 77 | 86 |
| 78 scoped_refptr<Picture> picture( | 87 scoped_refptr<Picture> picture( |
| 79 Picture::Create(bounds, &client_, tile_grid_info_, true, 0)); | 88 Picture::Create(bounds, &client_, tile_grid_info_, true, 0)); |
| 80 picture_map_[std::pair<int, int>(x, y)].SetPicture(picture); | 89 picture_map_[std::pair<int, int>(x, y)].SetPicture(picture); |
| 81 EXPECT_TRUE(HasRecordingAt(x, y)); | 90 EXPECT_TRUE(HasRecordingAt(x, y)); |
| 82 | 91 |
| 83 UpdateRecordedRegion(); | 92 has_any_recordings_ = true; |
| 84 } | 93 } |
| 85 | 94 |
| 86 void FakePicturePileImpl::RemoveRecordingAt(int x, int y) { | 95 void FakePicturePileImpl::RemoveRecordingAt(int x, int y) { |
| 87 EXPECT_GE(x, 0); | 96 EXPECT_GE(x, 0); |
| 88 EXPECT_GE(y, 0); | 97 EXPECT_GE(y, 0); |
| 89 EXPECT_LT(x, tiling_.num_tiles_x()); | 98 EXPECT_LT(x, tiling_.num_tiles_x()); |
| 90 EXPECT_LT(y, tiling_.num_tiles_y()); | 99 EXPECT_LT(y, tiling_.num_tiles_y()); |
| 91 | 100 |
| 92 if (!HasRecordingAt(x, y)) | 101 if (!HasRecordingAt(x, y)) |
| 93 return; | 102 return; |
| 94 picture_map_.erase(std::pair<int, int>(x, y)); | 103 picture_map_.erase(std::pair<int, int>(x, y)); |
| 95 EXPECT_FALSE(HasRecordingAt(x, y)); | 104 EXPECT_FALSE(HasRecordingAt(x, y)); |
| 96 | |
| 97 UpdateRecordedRegion(); | |
| 98 } | 105 } |
| 99 | 106 |
| 100 void FakePicturePileImpl::RerecordPile() { | 107 void FakePicturePileImpl::RerecordPile() { |
| 101 for (int y = 0; y < num_tiles_y(); ++y) { | 108 for (int y = 0; y < num_tiles_y(); ++y) { |
| 102 for (int x = 0; x < num_tiles_x(); ++x) { | 109 for (int x = 0; x < num_tiles_x(); ++x) { |
| 103 RemoveRecordingAt(x, y); | 110 RemoveRecordingAt(x, y); |
| 104 AddRecordingAt(x, y); | 111 AddRecordingAt(x, y); |
| 105 } | 112 } |
| 106 } | 113 } |
| 107 } | 114 } |
| 108 | 115 |
| 109 } // namespace cc | 116 } // namespace cc |
| OLD | NEW |