| 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 <map> | 5 #include <map> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "cc/resources/picture_pile.h" | 8 #include "cc/resources/picture_pile.h" |
| 9 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
| 10 #include "cc/test/fake_rendering_stats_instrumentation.h" | 10 #include "cc/test/fake_rendering_stats_instrumentation.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class PicturePileTest : public testing::Test { | 39 class PicturePileTest : public testing::Test { |
| 40 public: | 40 public: |
| 41 PicturePileTest() | 41 PicturePileTest() |
| 42 : pile_(new TestPicturePile()), | 42 : pile_(new TestPicturePile()), |
| 43 background_color_(SK_ColorBLUE), | 43 background_color_(SK_ColorBLUE), |
| 44 min_scale_(0.125), | 44 min_scale_(0.125), |
| 45 frame_number_(0), | 45 frame_number_(0), |
| 46 contents_opaque_(false) { | 46 contents_opaque_(false) { |
| 47 pile_->SetTilingRect(gfx::Rect(pile_->tiling().max_texture_size())); | |
| 48 pile_->SetTileGridSize(gfx::Size(1000, 1000)); | 47 pile_->SetTileGridSize(gfx::Size(1000, 1000)); |
| 49 pile_->SetMinContentsScale(min_scale_); | 48 pile_->SetMinContentsScale(min_scale_); |
| 49 SetTilingRect(gfx::Rect(pile_->tiling().max_texture_size())); |
| 50 } |
| 51 |
| 52 void SetTilingRect(const gfx::Rect& tiling_rect) { |
| 53 Region invalidation; |
| 54 UpdateAndExpandInvalidation(&invalidation, tiling_rect, tiling_rect); |
| 50 } | 55 } |
| 51 | 56 |
| 52 gfx::Rect tiling_rect() const { return pile_->tiling_rect(); } | 57 gfx::Rect tiling_rect() const { return pile_->tiling_rect(); } |
| 53 | 58 |
| 54 bool UpdateAndExpandInvalidation(Region* invalidation, | 59 bool UpdateAndExpandInvalidation(Region* invalidation, |
| 60 const gfx::Rect& layer_bounds_rect, |
| 55 const gfx::Rect& visible_layer_rect) { | 61 const gfx::Rect& visible_layer_rect) { |
| 56 frame_number_++; | 62 frame_number_++; |
| 57 return pile_->UpdateAndExpandInvalidation(&client_, | 63 return pile_->UpdateAndExpandInvalidation(&client_, |
| 58 invalidation, | 64 invalidation, |
| 59 background_color_, | 65 background_color_, |
| 60 contents_opaque_, | 66 contents_opaque_, |
| 61 false, | 67 false, |
| 68 layer_bounds_rect, |
| 62 visible_layer_rect, | 69 visible_layer_rect, |
| 63 frame_number_, | 70 frame_number_, |
| 64 Picture::RECORD_NORMALLY, | 71 Picture::RECORD_NORMALLY, |
| 65 &stats_instrumentation_); | 72 &stats_instrumentation_); |
| 66 } | 73 } |
| 67 | 74 |
| 68 bool UpdateWholePile() { | 75 bool UpdateWholePile() { |
| 69 Region invalidation = tiling_rect(); | 76 Region invalidation = tiling_rect(); |
| 70 bool result = UpdateAndExpandInvalidation(&invalidation, tiling_rect()); | 77 bool result = UpdateAndExpandInvalidation( |
| 78 &invalidation, tiling_rect(), tiling_rect()); |
| 71 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 79 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
| 72 return result; | 80 return result; |
| 73 } | 81 } |
| 74 | 82 |
| 75 FakeContentLayerClient client_; | 83 FakeContentLayerClient client_; |
| 76 FakeRenderingStatsInstrumentation stats_instrumentation_; | 84 FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 77 scoped_refptr<TestPicturePile> pile_; | 85 scoped_refptr<TestPicturePile> pile_; |
| 78 SkColor background_color_; | 86 SkColor background_color_; |
| 79 float min_scale_; | 87 float min_scale_; |
| 80 int frame_number_; | 88 int frame_number_; |
| 81 bool contents_opaque_; | 89 bool contents_opaque_; |
| 82 }; | 90 }; |
| 83 | 91 |
| 84 TEST_F(PicturePileTest, SmallInvalidateInflated) { | 92 TEST_F(PicturePileTest, SmallInvalidateInflated) { |
| 85 UpdateWholePile(); | |
| 86 | |
| 87 // Invalidate something inside a tile. | 93 // Invalidate something inside a tile. |
| 88 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); | 94 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); |
| 89 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); | 95 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect(), tiling_rect()); |
| 90 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); | 96 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); |
| 91 | 97 |
| 92 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 98 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
| 93 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 99 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
| 94 | 100 |
| 95 TestPicturePile::PictureInfo& picture_info = | 101 TestPicturePile::PictureInfo& picture_info = |
| 96 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 102 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
| 97 // We should have a picture. | 103 // We should have a picture. |
| 98 EXPECT_TRUE(!!picture_info.GetPicture()); | 104 EXPECT_TRUE(!!picture_info.GetPicture()); |
| 99 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( | 105 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( |
| 100 picture_info.GetPicture()->LayerRect(), min_scale_); | 106 picture_info.GetPicture()->LayerRect(), min_scale_); |
| 101 | 107 |
| 102 // The the picture should be large enough that scaling it never makes a rect | 108 // The the picture should be large enough that scaling it never makes a rect |
| 103 // smaller than 1 px wide or tall. | 109 // smaller than 1 px wide or tall. |
| 104 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << | 110 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << |
| 105 picture_rect.ToString(); | 111 picture_rect.ToString(); |
| 106 } | 112 } |
| 107 | 113 |
| 108 TEST_F(PicturePileTest, LargeInvalidateInflated) { | 114 TEST_F(PicturePileTest, LargeInvalidateInflated) { |
| 109 UpdateWholePile(); | |
| 110 | |
| 111 // Invalidate something inside a tile. | 115 // Invalidate something inside a tile. |
| 112 Region invalidate_rect(gfx::Rect(50, 50, 100, 100)); | 116 Region invalidate_rect(gfx::Rect(50, 50, 100, 100)); |
| 113 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); | 117 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect(), tiling_rect()); |
| 114 EXPECT_EQ(gfx::Rect(50, 50, 100, 100).ToString(), invalidate_rect.ToString()); | 118 EXPECT_EQ(gfx::Rect(50, 50, 100, 100).ToString(), invalidate_rect.ToString()); |
| 115 | 119 |
| 116 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 120 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
| 117 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 121 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
| 118 | 122 |
| 119 TestPicturePile::PictureInfo& picture_info = | 123 TestPicturePile::PictureInfo& picture_info = |
| 120 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 124 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
| 121 EXPECT_TRUE(!!picture_info.GetPicture()); | 125 EXPECT_TRUE(!!picture_info.GetPicture()); |
| 122 | 126 |
| 123 int expected_inflation = pile_->buffer_pixels(); | 127 int expected_inflation = pile_->buffer_pixels(); |
| 124 | 128 |
| 125 Picture* base_picture = picture_info.GetPicture(); | 129 Picture* base_picture = picture_info.GetPicture(); |
| 126 gfx::Rect base_picture_rect = pile_->tiling_rect(); | 130 gfx::Rect base_picture_rect = pile_->tiling_rect(); |
| 127 base_picture_rect.Inset(-expected_inflation, -expected_inflation); | 131 base_picture_rect.Inset(-expected_inflation, -expected_inflation); |
| 128 EXPECT_EQ(base_picture_rect.ToString(), | 132 EXPECT_EQ(base_picture_rect.ToString(), |
| 129 base_picture->LayerRect().ToString()); | 133 base_picture->LayerRect().ToString()); |
| 130 } | 134 } |
| 131 | 135 |
| 132 TEST_F(PicturePileTest, InvalidateOnTileBoundaryInflated) { | 136 TEST_F(PicturePileTest, InvalidateOnTileBoundaryInflated) { |
| 133 gfx::Rect new_tiling_rect = | 137 gfx::Rect new_tiling_rect = |
| 134 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 2.f)); | 138 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 2.f)); |
| 135 pile_->SetTilingRect(new_tiling_rect); | 139 // This creates initial pictures. |
| 140 SetTilingRect(new_tiling_rect); |
| 136 | 141 |
| 137 // Due to border pixels, we should have 3 tiles. | 142 // Due to border pixels, we should have 3 tiles. |
| 138 EXPECT_EQ(3, pile_->tiling().num_tiles_x()); | 143 EXPECT_EQ(3, pile_->tiling().num_tiles_x()); |
| 139 EXPECT_EQ(3, pile_->tiling().num_tiles_y()); | 144 EXPECT_EQ(3, pile_->tiling().num_tiles_y()); |
| 140 | 145 |
| 141 // We should have 1/.125 - 1 = 7 border pixels. | 146 // We should have 1/.125 - 1 = 7 border pixels. |
| 142 EXPECT_EQ(7, pile_->buffer_pixels()); | 147 EXPECT_EQ(7, pile_->buffer_pixels()); |
| 143 EXPECT_EQ(7, pile_->tiling().border_texels()); | 148 EXPECT_EQ(7, pile_->tiling().border_texels()); |
| 144 | 149 |
| 145 // Update the whole layer to create initial pictures. | 150 // Invalidate everything to have a non zero invalidation frequency. |
| 146 UpdateWholePile(); | |
| 147 | |
| 148 // Invalidate everything again to have a non zero invalidation | |
| 149 // frequency. | |
| 150 UpdateWholePile(); | 151 UpdateWholePile(); |
| 151 | 152 |
| 152 // Invalidate something just over a tile boundary by a single pixel. | 153 // Invalidate something just over a tile boundary by a single pixel. |
| 153 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). | 154 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). |
| 154 Region invalidate_rect( | 155 Region invalidate_rect( |
| 155 gfx::Rect(pile_->tiling().TileBoundsWithBorder(0, 0).right(), | 156 gfx::Rect(pile_->tiling().TileBoundsWithBorder(0, 0).right(), |
| 156 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, | 157 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, |
| 157 50, | 158 50, |
| 158 50)); | 159 50)); |
| 159 Region expected_invalidation = invalidate_rect; | 160 Region expected_invalidation = invalidate_rect; |
| 160 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); | 161 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect(), tiling_rect()); |
| 161 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString()); | 162 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString()); |
| 162 | 163 |
| 163 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 164 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 164 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 165 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 165 TestPicturePile::PictureInfo& picture_info = | 166 TestPicturePile::PictureInfo& picture_info = |
| 166 pile_->picture_map() | 167 pile_->picture_map() |
| 167 .find(TestPicturePile::PictureMapKey(i, j)) | 168 .find(TestPicturePile::PictureMapKey(i, j)) |
| 168 ->second; | 169 ->second; |
| 169 | 170 |
| 170 // Expect (1, 1) and (1, 0) to be invalidated once more | 171 // Expect (1, 1) and (1, 0) to be invalidated once more |
| 171 // than the rest of the tiles. | 172 // than the rest of the tiles. |
| 172 if (i == 1 && (j == 0 || j == 1)) { | 173 if (i == 1 && (j == 0 || j == 1)) { |
| 173 EXPECT_FLOAT_EQ( | 174 EXPECT_FLOAT_EQ( |
| 174 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 175 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
| 175 picture_info.GetInvalidationFrequencyForTesting()); | 176 picture_info.GetInvalidationFrequencyForTesting()); |
| 176 } else { | 177 } else { |
| 177 EXPECT_FLOAT_EQ( | 178 EXPECT_FLOAT_EQ( |
| 178 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 179 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
| 179 picture_info.GetInvalidationFrequencyForTesting()); | 180 picture_info.GetInvalidationFrequencyForTesting()); |
| 180 } | 181 } |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 } | 184 } |
| 184 | 185 |
| 185 TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) { | 186 TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) { |
| 186 gfx::Rect new_tiling_rect = | 187 gfx::Rect new_tiling_rect = |
| 187 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 4.f)); | 188 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 4.f)); |
| 188 pile_->SetTilingRect(new_tiling_rect); | 189 SetTilingRect(new_tiling_rect); |
| 189 | 190 |
| 190 gfx::Rect viewport( | 191 gfx::Rect viewport( |
| 191 tiling_rect().x(), tiling_rect().y(), tiling_rect().width(), 1); | 192 tiling_rect().x(), tiling_rect().y(), tiling_rect().width(), 1); |
| 192 | 193 |
| 193 // Update the whole pile until the invalidation frequency is high. | 194 // Update the whole pile until the invalidation frequency is high. |
| 194 for (int frame = 0; frame < 33; ++frame) { | 195 for (int frame = 0; frame < 33; ++frame) { |
| 195 UpdateWholePile(); | 196 UpdateWholePile(); |
| 196 } | 197 } |
| 197 | 198 |
| 198 // Make sure we have a high invalidation frequency. | 199 // Make sure we have a high invalidation frequency. |
| 199 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 200 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 200 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 201 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 201 TestPicturePile::PictureInfo& picture_info = | 202 TestPicturePile::PictureInfo& picture_info = |
| 202 pile_->picture_map() | 203 pile_->picture_map() |
| 203 .find(TestPicturePile::PictureMapKey(i, j)) | 204 .find(TestPicturePile::PictureMapKey(i, j)) |
| 204 ->second; | 205 ->second; |
| 205 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) | 206 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) |
| 206 << "i " << i << " j " << j; | 207 << "i " << i << " j " << j; |
| 207 } | 208 } |
| 208 } | 209 } |
| 209 | 210 |
| 210 // Update once more with a small viewport. | 211 // Update once more with a small viewport. |
| 211 Region invalidation = tiling_rect(); | 212 Region invalidation = tiling_rect(); |
| 212 UpdateAndExpandInvalidation(&invalidation, viewport); | 213 UpdateAndExpandInvalidation(&invalidation, tiling_rect(), viewport); |
| 213 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 214 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
| 214 | 215 |
| 215 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 216 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 216 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 217 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 217 TestPicturePile::PictureInfo& picture_info = | 218 TestPicturePile::PictureInfo& picture_info = |
| 218 pile_->picture_map() | 219 pile_->picture_map() |
| 219 .find(TestPicturePile::PictureMapKey(i, j)) | 220 .find(TestPicturePile::PictureMapKey(i, j)) |
| 220 ->second; | 221 ->second; |
| 221 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); | 222 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); |
| 222 | 223 |
| 223 // If the y far enough away we expect to find no picture (no re-recording | 224 // If the y far enough away we expect to find no picture (no re-recording |
| 224 // happened). For close y, the picture should change. | 225 // happened). For close y, the picture should change. |
| 225 if (j >= 2) | 226 if (j >= 2) |
| 226 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; | 227 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 227 else | 228 else |
| 228 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 229 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 229 } | 230 } |
| 230 } | 231 } |
| 231 | 232 |
| 232 // Update a partial tile that doesn't get recorded. We should expand the | 233 // Update a partial tile that doesn't get recorded. We should expand the |
| 233 // invalidation to the entire tiles that overlap it. | 234 // invalidation to the entire tiles that overlap it. |
| 234 Region small_invalidation = | 235 Region small_invalidation = |
| 235 gfx::Rect(pile_->tiling().TileBounds(3, 4).x(), | 236 gfx::Rect(pile_->tiling().TileBounds(3, 4).x(), |
| 236 pile_->tiling().TileBounds(3, 4).y() + 10, | 237 pile_->tiling().TileBounds(3, 4).y() + 10, |
| 237 1, | 238 1, |
| 238 1); | 239 1); |
| 239 UpdateAndExpandInvalidation(&small_invalidation, viewport); | 240 UpdateAndExpandInvalidation(&small_invalidation, tiling_rect(), viewport); |
| 240 EXPECT_TRUE(small_invalidation.Contains(gfx::UnionRects( | 241 EXPECT_TRUE(small_invalidation.Contains(gfx::UnionRects( |
| 241 pile_->tiling().TileBounds(2, 4), pile_->tiling().TileBounds(3, 4)))) | 242 pile_->tiling().TileBounds(2, 4), pile_->tiling().TileBounds(3, 4)))) |
| 242 << small_invalidation.ToString(); | 243 << small_invalidation.ToString(); |
| 243 | 244 |
| 244 // Now update with no invalidation and full viewport | 245 // Now update with no invalidation and full viewport |
| 245 Region empty_invalidation; | 246 Region empty_invalidation; |
| 246 UpdateAndExpandInvalidation(&empty_invalidation, tiling_rect()); | 247 UpdateAndExpandInvalidation( |
| 248 &empty_invalidation, tiling_rect(), tiling_rect()); |
| 247 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString()); | 249 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString()); |
| 248 | 250 |
| 249 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 251 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 250 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 252 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 251 TestPicturePile::PictureInfo& picture_info = | 253 TestPicturePile::PictureInfo& picture_info = |
| 252 pile_->picture_map() | 254 pile_->picture_map() |
| 253 .find(TestPicturePile::PictureMapKey(i, j)) | 255 .find(TestPicturePile::PictureMapKey(i, j)) |
| 254 ->second; | 256 ->second; |
| 255 // Expect the invalidation frequency to be less than 1, since we just | 257 // Expect the invalidation frequency to be less than 1, since we just |
| 256 // updated with no invalidations. | 258 // updated with no invalidations. |
| 257 EXPECT_LT(picture_info.GetInvalidationFrequencyForTesting(), 1.f); | 259 EXPECT_LT(picture_info.GetInvalidationFrequencyForTesting(), 1.f); |
| 258 | 260 |
| 259 // We expect that there are pictures everywhere now. | 261 // We expect that there are pictures everywhere now. |
| 260 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 262 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 261 } | 263 } |
| 262 } | 264 } |
| 263 } | 265 } |
| 264 | 266 |
| 265 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { | 267 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { |
| 266 UpdateWholePile(); | |
| 267 | |
| 268 gfx::Rect rect(0, 0, 5, 5); | 268 gfx::Rect rect(0, 0, 5, 5); |
| 269 EXPECT_TRUE(pile_->CanRasterLayerRect(rect)); | 269 EXPECT_TRUE(pile_->CanRasterLayerRect(rect)); |
| 270 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect)); | 270 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect)); |
| 271 | 271 |
| 272 pile_->Clear(); | 272 pile_->Clear(); |
| 273 | 273 |
| 274 // Make sure both the cache-aware check (using recorded region) and the normal | 274 // Make sure both the cache-aware check (using recorded region) and the normal |
| 275 // check are both false after clearing. | 275 // check are both false after clearing. |
| 276 EXPECT_FALSE(pile_->CanRasterLayerRect(rect)); | 276 EXPECT_FALSE(pile_->CanRasterLayerRect(rect)); |
| 277 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect)); | 277 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 TEST_F(PicturePileTest, FrequentInvalidationCanRaster) { | 280 TEST_F(PicturePileTest, FrequentInvalidationCanRaster) { |
| 281 // This test makes sure that if part of the page is frequently invalidated | 281 // This test makes sure that if part of the page is frequently invalidated |
| 282 // and doesn't get re-recorded, then CanRaster is not true for any | 282 // and doesn't get re-recorded, then CanRaster is not true for any |
| 283 // tiles touching it, but is true for adjacent tiles, even if it | 283 // tiles touching it, but is true for adjacent tiles, even if it |
| 284 // overlaps on borders (edge case). | 284 // overlaps on borders (edge case). |
| 285 gfx::Rect new_tiling_rect = | 285 gfx::Rect new_tiling_rect = |
| 286 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 4.f)); | 286 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 4.f)); |
| 287 pile_->SetTilingRect(new_tiling_rect); | 287 SetTilingRect(new_tiling_rect); |
| 288 | 288 |
| 289 gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1); | 289 gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1); |
| 290 gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2); | 290 gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2); |
| 291 gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1); | 291 gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1); |
| 292 gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2); | 292 gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2); |
| 293 | 293 |
| 294 // Sanity check these two tiles are overlapping with borders, since this is | 294 // Sanity check these two tiles are overlapping with borders, since this is |
| 295 // what the test is trying to repro. | 295 // what the test is trying to repro. |
| 296 EXPECT_TRUE(tile01_borders.Intersects(tile02_borders)); | 296 EXPECT_TRUE(tile01_borders.Intersects(tile02_borders)); |
| 297 EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders)); | 297 EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders)); |
| 298 UpdateWholePile(); | 298 UpdateWholePile(); |
| 299 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); | 299 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
| 300 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); | 300 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
| 301 EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders)); | 301 EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders)); |
| 302 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders)); | 302 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
| 303 // Sanity check that an initial paint goes down the fast path of having | 303 // Sanity check that an initial paint goes down the fast path of having |
| 304 // a valid recorded viewport. | 304 // a valid recorded viewport. |
| 305 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 305 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 306 | 306 |
| 307 // Update the whole layer until the invalidation frequency is high. | 307 // Update the whole layer until the invalidation frequency is high. |
| 308 for (int frame = 0; frame < 33; ++frame) { | 308 for (int frame = 0; frame < 33; ++frame) { |
| 309 UpdateWholePile(); | 309 UpdateWholePile(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Update once more with a small viewport. | 312 // Update once more with a small viewport. |
| 313 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); | 313 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); |
| 314 Region invalidation(tiling_rect()); | 314 Region invalidation(tiling_rect()); |
| 315 UpdateAndExpandInvalidation(&invalidation, viewport); | 315 UpdateAndExpandInvalidation(&invalidation, tiling_rect(), viewport); |
| 316 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 316 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
| 317 | 317 |
| 318 // Sanity check some pictures exist and others don't. | 318 // Sanity check some pictures exist and others don't. |
| 319 EXPECT_TRUE(pile_->picture_map() | 319 EXPECT_TRUE(pile_->picture_map() |
| 320 .find(TestPicturePile::PictureMapKey(0, 1)) | 320 .find(TestPicturePile::PictureMapKey(0, 1)) |
| 321 ->second.GetPicture()); | 321 ->second.GetPicture()); |
| 322 EXPECT_FALSE(pile_->picture_map() | 322 EXPECT_FALSE(pile_->picture_map() |
| 323 .find(TestPicturePile::PictureMapKey(0, 2)) | 323 .find(TestPicturePile::PictureMapKey(0, 2)) |
| 324 ->second.GetPicture()); | 324 ->second.GetPicture()); |
| 325 | 325 |
| 326 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); | 326 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
| 327 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); | 327 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
| 328 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); | 328 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); |
| 329 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); | 329 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
| 330 } | 330 } |
| 331 | 331 |
| 332 TEST_F(PicturePileTest, NoInvalidationValidViewport) { | 332 TEST_F(PicturePileTest, NoInvalidationValidViewport) { |
| 333 // This test validates that the recorded_viewport cache of full tiles | 333 // This test validates that the recorded_viewport cache of full tiles |
| 334 // is still valid for some use cases. If it's not, it's a performance | 334 // is still valid for some use cases. If it's not, it's a performance |
| 335 // issue because CanRaster checks will go down the slow path. | 335 // issue because CanRaster checks will go down the slow path. |
| 336 UpdateWholePile(); | |
| 337 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 336 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 338 | 337 |
| 339 // No invalidation, same viewport. | 338 // No invalidation, same viewport. |
| 340 Region invalidation; | 339 Region invalidation; |
| 341 UpdateAndExpandInvalidation(&invalidation, tiling_rect()); | 340 UpdateAndExpandInvalidation(&invalidation, tiling_rect(), tiling_rect()); |
| 342 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 341 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 343 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 342 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 344 | 343 |
| 345 // Partial invalidation, same viewport. | 344 // Partial invalidation, same viewport. |
| 346 invalidation = gfx::Rect(0, 0, 1, 1); | 345 invalidation = gfx::Rect(0, 0, 1, 1); |
| 347 UpdateAndExpandInvalidation(&invalidation, tiling_rect()); | 346 UpdateAndExpandInvalidation(&invalidation, tiling_rect(), tiling_rect()); |
| 348 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 347 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 349 EXPECT_EQ(gfx::Rect(0, 0, 1, 1).ToString(), invalidation.ToString()); | 348 EXPECT_EQ(gfx::Rect(0, 0, 1, 1).ToString(), invalidation.ToString()); |
| 350 | 349 |
| 351 // No invalidation, changing viewport. | 350 // No invalidation, changing viewport. |
| 352 invalidation = Region(); | 351 invalidation = Region(); |
| 353 UpdateAndExpandInvalidation(&invalidation, gfx::Rect(5, 5, 5, 5)); | 352 UpdateAndExpandInvalidation( |
| 353 &invalidation, tiling_rect(), gfx::Rect(5, 5, 5, 5)); |
| 354 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 354 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 355 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 355 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 356 } | 356 } |
| 357 | 357 |
| 358 TEST_F(PicturePileTest, InvalidationOutsideRecordingRect) { | 358 TEST_F(PicturePileTest, InvalidationOutsideRecordingRect) { |
| 359 gfx::Rect huge_layer_rect(10000000, 20000000); | 359 gfx::Rect huge_layer_rect(10000000, 20000000); |
| 360 gfx::Rect viewport(300000, 400000, 5000, 6000); | 360 gfx::Rect viewport(300000, 400000, 5000, 6000); |
| 361 | 361 |
| 362 pile_->SetTilingRect(huge_layer_rect); | 362 // Resize the pile and set up the interest rect. |
| 363 Region invalidation; |
| 364 UpdateAndExpandInvalidation(&invalidation, huge_layer_rect, viewport); |
| 363 | 365 |
| 364 // Invalidation inside the recording rect does not need to be expanded. | 366 // Invalidation inside the recording rect does not need to be expanded. |
| 365 Region invalidation = viewport; | 367 invalidation = viewport; |
| 366 UpdateAndExpandInvalidation(&invalidation, viewport); | 368 UpdateAndExpandInvalidation(&invalidation, huge_layer_rect, viewport); |
| 367 EXPECT_EQ(viewport.ToString(), invalidation.ToString()); | 369 EXPECT_EQ(viewport.ToString(), invalidation.ToString()); |
| 368 | 370 |
| 369 // Invalidation outside the recording rect should expand to the tiles it | 371 // Invalidation outside the recording rect should expand to the tiles it |
| 370 // covers. | 372 // covers. |
| 371 gfx::Rect recorded_over_tiles = | 373 gfx::Rect recorded_over_tiles = |
| 372 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); | 374 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); |
| 373 gfx::Rect invalidation_outside( | 375 gfx::Rect invalidation_outside( |
| 374 recorded_over_tiles.right(), recorded_over_tiles.y(), 30, 30); | 376 recorded_over_tiles.right(), recorded_over_tiles.y(), 30, 30); |
| 375 invalidation = invalidation_outside; | 377 invalidation = invalidation_outside; |
| 376 UpdateAndExpandInvalidation(&invalidation, viewport); | 378 UpdateAndExpandInvalidation(&invalidation, huge_layer_rect, viewport); |
| 377 gfx::Rect expanded_recorded_viewport = | 379 gfx::Rect expanded_recorded_viewport = |
| 378 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); | 380 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); |
| 379 Region expected_invalidation = | 381 Region expected_invalidation = |
| 380 pile_->tiling().ExpandRectToTileBounds(invalidation_outside); | 382 pile_->tiling().ExpandRectToTileBounds(invalidation_outside); |
| 381 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 383 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 382 } | 384 } |
| 383 | 385 |
| 384 TEST_F(PicturePileTest, ResizePile) { | 386 TEST_F(PicturePileTest, ResizePileOutsideInterestRect) { |
| 385 gfx::Size tile_size(100, 100); | 387 // This size chosen to be larger than the interest rect size, which is |
| 386 gfx::Rect base_tiling_rect(5 * 100, 5 * 100); | 388 // at least kPixelDistanceToRecord * 2 in each dimension. |
| 387 gfx::Rect grow_down_tiling_rect(5 * 100, 7 * 100); | 389 int tile_size = 100000; |
| 388 gfx::Rect grow_right_tiling_rect(7 * 100, 5 * 100); | 390 gfx::Rect base_tiling_rect(5 * tile_size, 5 * tile_size); |
| 389 gfx::Rect grow_both_tiling_rect(7 * 100, 7 * 100); | 391 gfx::Rect grow_down_tiling_rect(5 * tile_size, 7 * tile_size); |
| 392 gfx::Rect grow_right_tiling_rect(7 * tile_size, 5 * tile_size); |
| 393 gfx::Rect grow_both_tiling_rect(7 * tile_size, 7 * tile_size); |
| 390 | 394 |
| 391 pile_->tiling().SetMaxTextureSize(tile_size); | 395 Region invalidation; |
| 392 pile_->SetTilingRect(base_tiling_rect); | 396 Region expected_invalidation; |
| 393 UpdateWholePile(); | 397 |
| 398 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 399 SetTilingRect(base_tiling_rect); |
| 394 | 400 |
| 395 // We should have a recording for every tile. | 401 // We should have a recording for every tile. |
| 396 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 402 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 397 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 403 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 398 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 404 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 399 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 405 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 400 TestPicturePile::PictureMapKey key(i, j); | 406 TestPicturePile::PictureMapKey key(i, j); |
| 401 TestPicturePile::PictureMap& map = pile_->picture_map(); | 407 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 402 TestPicturePile::PictureMap::iterator it = map.find(key); | 408 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 403 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 409 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 404 } | 410 } |
| 405 } | 411 } |
| 406 | 412 |
| 407 UpdateWholePile(); | 413 UpdateAndExpandInvalidation( |
| 408 pile_->SetTilingRect(grow_down_tiling_rect); | 414 &invalidation, grow_down_tiling_rect, gfx::Rect(1, 1)); |
| 409 | 415 |
| 410 // We should have lost the recordings in the bottom row. | 416 // We should have lost the recordings in the bottom row. |
| 411 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 417 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 412 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); | 418 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); |
| 413 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 419 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 414 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 420 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 415 TestPicturePile::PictureMapKey key(i, j); | 421 TestPicturePile::PictureMapKey key(i, j); |
| 416 TestPicturePile::PictureMap& map = pile_->picture_map(); | 422 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 417 TestPicturePile::PictureMap::iterator it = map.find(key); | 423 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 418 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); | 424 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); |
| 419 } | 425 } |
| 420 } | 426 } |
| 421 | 427 |
| 428 // We invalidated the old bottom row. |
| 429 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), |
| 430 pile_->tiling().TileBounds(5, 5)); |
| 431 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 432 invalidation.Clear(); |
| 433 |
| 422 UpdateWholePile(); | 434 UpdateWholePile(); |
| 423 pile_->SetTilingRect(base_tiling_rect); | 435 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 424 | 436 |
| 425 // We should have lost the recordings that are now outside the tiling only. | 437 // We should have lost the recordings that are now outside the tiling only. |
| 426 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 438 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 427 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 439 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 428 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 440 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 429 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 441 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 430 TestPicturePile::PictureMapKey key(i, j); | 442 TestPicturePile::PictureMapKey key(i, j); |
| 431 TestPicturePile::PictureMap& map = pile_->picture_map(); | 443 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 432 TestPicturePile::PictureMap::iterator it = map.find(key); | 444 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 433 EXPECT_EQ(j < 6, it != map.end() && it->second.GetPicture()); | 445 EXPECT_EQ(j < 6, it != map.end() && it->second.GetPicture()); |
| 434 } | 446 } |
| 435 } | 447 } |
| 436 | 448 |
| 449 // No invalidation when shrinking. |
| 450 expected_invalidation.Clear(); |
| 451 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 452 invalidation.Clear(); |
| 453 |
| 437 UpdateWholePile(); | 454 UpdateWholePile(); |
| 438 pile_->SetTilingRect(grow_right_tiling_rect); | 455 UpdateAndExpandInvalidation( |
| 456 &invalidation, grow_right_tiling_rect, gfx::Rect(1, 1)); |
| 439 | 457 |
| 440 // We should have lost the recordings in the right column. | 458 // We should have lost the recordings in the right column. |
| 441 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); | 459 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); |
| 442 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 460 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 443 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 461 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 444 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 462 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 445 TestPicturePile::PictureMapKey key(i, j); | 463 TestPicturePile::PictureMapKey key(i, j); |
| 446 TestPicturePile::PictureMap& map = pile_->picture_map(); | 464 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 447 TestPicturePile::PictureMap::iterator it = map.find(key); | 465 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 448 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); | 466 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); |
| 449 } | 467 } |
| 450 } | 468 } |
| 451 | 469 |
| 470 // We invalidated the old right column. |
| 471 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 472 pile_->tiling().TileBounds(5, 5)); |
| 473 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 474 invalidation.Clear(); |
| 475 |
| 452 UpdateWholePile(); | 476 UpdateWholePile(); |
| 453 pile_->SetTilingRect(base_tiling_rect); | 477 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 454 | 478 |
| 455 // We should have lost the recordings that are now outside the tiling only. | 479 // We should have lost the recordings that are now outside the tiling only. |
| 456 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 480 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 457 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 481 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 458 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 482 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 459 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 483 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 460 TestPicturePile::PictureMapKey key(i, j); | 484 TestPicturePile::PictureMapKey key(i, j); |
| 461 TestPicturePile::PictureMap& map = pile_->picture_map(); | 485 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 462 TestPicturePile::PictureMap::iterator it = map.find(key); | 486 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 463 EXPECT_EQ(i < 6, it != map.end() && it->second.GetPicture()); | 487 EXPECT_EQ(i < 6, it != map.end() && it->second.GetPicture()); |
| 464 } | 488 } |
| 465 } | 489 } |
| 466 | 490 |
| 491 // No invalidation when shrinking. |
| 492 expected_invalidation.Clear(); |
| 493 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 494 invalidation.Clear(); |
| 495 |
| 467 UpdateWholePile(); | 496 UpdateWholePile(); |
| 468 pile_->SetTilingRect(grow_both_tiling_rect); | 497 UpdateAndExpandInvalidation( |
| 498 &invalidation, grow_both_tiling_rect, gfx::Rect(1, 1)); |
| 469 | 499 |
| 470 // We should have lost the recordings in the right column and bottom row. | 500 // We should have lost the recordings in the right column and bottom row. |
| 471 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); | 501 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); |
| 472 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); | 502 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); |
| 473 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 503 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 474 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 504 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 475 TestPicturePile::PictureMapKey key(i, j); | 505 TestPicturePile::PictureMapKey key(i, j); |
| 476 TestPicturePile::PictureMap& map = pile_->picture_map(); | 506 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 477 TestPicturePile::PictureMap::iterator it = map.find(key); | 507 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 478 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); | 508 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); |
| 479 } | 509 } |
| 480 } | 510 } |
| 481 | 511 |
| 512 // We invalidated the old right column and the old bottom row. |
| 513 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 514 pile_->tiling().TileBounds(5, 5)); |
| 515 expected_invalidation.Union(gfx::UnionRects( |
| 516 pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5))); |
| 517 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 518 invalidation.Clear(); |
| 519 |
| 482 UpdateWholePile(); | 520 UpdateWholePile(); |
| 483 pile_->SetTilingRect(base_tiling_rect); | 521 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect()); |
| 484 | 522 |
| 485 // We should have lost the recordings that are now outside the tiling only. | 523 // We should have lost the recordings that are now outside the tiling only. |
| 486 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 524 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 487 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 525 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 488 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 526 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 489 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 527 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 490 TestPicturePile::PictureMapKey key(i, j); | 528 TestPicturePile::PictureMapKey key(i, j); |
| 491 TestPicturePile::PictureMap& map = pile_->picture_map(); | 529 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 492 TestPicturePile::PictureMap::iterator it = map.find(key); | 530 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 493 EXPECT_EQ(i < 6 && j < 6, it != map.end() && it->second.GetPicture()); | 531 EXPECT_EQ(i < 6 && j < 6, it != map.end() && it->second.GetPicture()); |
| 494 } | 532 } |
| 495 } | 533 } |
| 534 |
| 535 // No invalidation when shrinking. |
| 536 expected_invalidation.Clear(); |
| 537 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 538 invalidation.Clear(); |
| 496 } | 539 } |
| 497 | 540 |
| 498 TEST_F(PicturePileTest, SmallResizePile) { | 541 TEST_F(PicturePileTest, SmallResizePileOutsideInterestRect) { |
| 499 gfx::Size tile_size(100, 100); | 542 // This size chosen to be larger than the interest rect size, which is |
| 500 gfx::Rect base_tiling_rect(5 * 100, 5 * 100); | 543 // at least kPixelDistanceToRecord * 2 in each dimension. |
| 501 gfx::Rect grow_down_tiling_rect(5 * 100, 5 * 100 + 5); | 544 int tile_size = 100000; |
| 502 gfx::Rect grow_right_tiling_rect(5 * 100 + 5, 5 * 100); | 545 gfx::Rect base_tiling_rect(5 * tile_size, 5 * tile_size); |
| 503 gfx::Rect grow_both_tiling_rect(5 * 100 + 5, 5 * 100 + 5); | 546 gfx::Rect grow_down_tiling_rect(5 * tile_size, 5 * tile_size + 5); |
| 547 gfx::Rect grow_right_tiling_rect(5 * tile_size + 5, 5 * tile_size); |
| 548 gfx::Rect grow_both_tiling_rect(5 * tile_size + 5, 5 * tile_size + 5); |
| 504 | 549 |
| 505 pile_->tiling().SetMaxTextureSize(tile_size); | 550 Region invalidation; |
| 506 pile_->SetTilingRect(base_tiling_rect); | 551 Region expected_invalidation; |
| 507 UpdateWholePile(); | 552 |
| 553 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 554 SetTilingRect(base_tiling_rect); |
| 508 | 555 |
| 509 // We should have a recording for every tile. | 556 // We should have a recording for every tile. |
| 510 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 557 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 511 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 558 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 512 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 559 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 513 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 560 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 514 TestPicturePile::PictureMapKey key(i, j); | 561 TestPicturePile::PictureMapKey key(i, j); |
| 515 TestPicturePile::PictureMap& map = pile_->picture_map(); | 562 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 516 TestPicturePile::PictureMap::iterator it = map.find(key); | 563 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 517 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 564 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 518 } | 565 } |
| 519 } | 566 } |
| 520 | 567 |
| 521 UpdateWholePile(); | 568 UpdateAndExpandInvalidation( |
| 522 pile_->SetTilingRect(grow_down_tiling_rect); | 569 &invalidation, grow_down_tiling_rect, gfx::Rect(1, 1)); |
| 523 | 570 |
| 524 // We should have lost the recordings in the bottom row. | 571 // We should have lost the recordings in the bottom row. |
| 525 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 572 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 526 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 573 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 527 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 574 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 528 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 575 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 529 TestPicturePile::PictureMapKey key(i, j); | 576 TestPicturePile::PictureMapKey key(i, j); |
| 530 TestPicturePile::PictureMap& map = pile_->picture_map(); | 577 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 531 TestPicturePile::PictureMap::iterator it = map.find(key); | 578 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 532 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); | 579 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); |
| 533 } | 580 } |
| 534 } | 581 } |
| 535 | 582 |
| 583 // We invalidated the bottom row. |
| 584 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), |
| 585 pile_->tiling().TileBounds(5, 5)); |
| 586 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 587 invalidation.Clear(); |
| 588 |
| 536 UpdateWholePile(); | 589 UpdateWholePile(); |
| 537 pile_->SetTilingRect(base_tiling_rect); | 590 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 538 | 591 |
| 539 // We should have lost nothing. | 592 // We should have lost nothing. |
| 540 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 593 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 541 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 594 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 542 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 595 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 543 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 596 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 544 TestPicturePile::PictureMapKey key(i, j); | 597 TestPicturePile::PictureMapKey key(i, j); |
| 545 TestPicturePile::PictureMap& map = pile_->picture_map(); | 598 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 546 TestPicturePile::PictureMap::iterator it = map.find(key); | 599 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 547 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 600 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 548 } | 601 } |
| 549 } | 602 } |
| 550 | 603 |
| 604 // We invalidated nothing. |
| 605 expected_invalidation.Clear(); |
| 606 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 607 invalidation.Clear(); |
| 608 |
| 551 UpdateWholePile(); | 609 UpdateWholePile(); |
| 552 pile_->SetTilingRect(grow_right_tiling_rect); | 610 UpdateAndExpandInvalidation( |
| 611 &invalidation, grow_right_tiling_rect, gfx::Rect(1, 1)); |
| 553 | 612 |
| 554 // We should have lost the recordings in the right column. | 613 // We should have lost the recordings in the right column. |
| 555 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 614 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 556 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 615 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 557 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 616 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 558 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 617 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 559 TestPicturePile::PictureMapKey key(i, j); | 618 TestPicturePile::PictureMapKey key(i, j); |
| 560 TestPicturePile::PictureMap& map = pile_->picture_map(); | 619 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 561 TestPicturePile::PictureMap::iterator it = map.find(key); | 620 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 562 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); | 621 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); |
| 563 } | 622 } |
| 564 } | 623 } |
| 565 | 624 |
| 625 // We invalidated the right column. |
| 626 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 627 pile_->tiling().TileBounds(5, 5)); |
| 628 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 629 invalidation.Clear(); |
| 630 |
| 566 UpdateWholePile(); | 631 UpdateWholePile(); |
| 567 pile_->SetTilingRect(base_tiling_rect); | 632 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 568 | 633 |
| 569 // We should have lost nothing. | 634 // We should have lost nothing. |
| 570 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 635 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 571 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 636 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 572 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 637 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 573 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 638 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 574 TestPicturePile::PictureMapKey key(i, j); | 639 TestPicturePile::PictureMapKey key(i, j); |
| 575 TestPicturePile::PictureMap& map = pile_->picture_map(); | 640 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 576 TestPicturePile::PictureMap::iterator it = map.find(key); | 641 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 577 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 642 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 578 } | 643 } |
| 579 } | 644 } |
| 580 | 645 |
| 646 // We invalidated nothing. |
| 647 expected_invalidation.Clear(); |
| 648 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 649 invalidation.Clear(); |
| 650 |
| 581 UpdateWholePile(); | 651 UpdateWholePile(); |
| 582 pile_->SetTilingRect(grow_both_tiling_rect); | 652 UpdateAndExpandInvalidation( |
| 653 &invalidation, grow_both_tiling_rect, gfx::Rect(1, 1)); |
| 583 | 654 |
| 584 // We should have lost the recordings in the right column and bottom row. | 655 // We should have lost the recordings in the right column and bottom row. |
| 585 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 656 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 586 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 657 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 587 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 658 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 588 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 659 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 589 TestPicturePile::PictureMapKey key(i, j); | 660 TestPicturePile::PictureMapKey key(i, j); |
| 590 TestPicturePile::PictureMap& map = pile_->picture_map(); | 661 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 591 TestPicturePile::PictureMap::iterator it = map.find(key); | 662 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 592 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); | 663 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); |
| 593 } | 664 } |
| 594 } | 665 } |
| 595 | 666 |
| 667 // We invalidated the right column and the bottom row. |
| 668 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 669 pile_->tiling().TileBounds(5, 5)); |
| 670 expected_invalidation.Union(gfx::UnionRects( |
| 671 pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5))); |
| 672 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 673 invalidation.Clear(); |
| 674 |
| 596 UpdateWholePile(); | 675 UpdateWholePile(); |
| 597 pile_->SetTilingRect(base_tiling_rect); | 676 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 598 | 677 |
| 599 // We should have lost nothing. | 678 // We should have lost nothing. |
| 600 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 679 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 601 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 680 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 602 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 681 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 603 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 682 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 604 TestPicturePile::PictureMapKey key(i, j); | 683 TestPicturePile::PictureMapKey key(i, j); |
| 605 TestPicturePile::PictureMap& map = pile_->picture_map(); | 684 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 606 TestPicturePile::PictureMap::iterator it = map.find(key); | 685 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 607 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 686 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 608 } | 687 } |
| 609 } | 688 } |
| 689 |
| 690 // We invalidated nothing. |
| 691 expected_invalidation.Clear(); |
| 692 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 693 invalidation.Clear(); |
| 610 } | 694 } |
| 611 | 695 |
| 696 TEST_F(PicturePileTest, ResizePileInsideInterestRect) { |
| 697 // This size chosen to be small enough that all the rects below fit inside the |
| 698 // the interest rect, so they are smaller than kPixelDistanceToRecord in each |
| 699 // dimension. |
| 700 int tile_size = 100; |
| 701 gfx::Rect base_tiling_rect(5 * tile_size, 5 * tile_size); |
| 702 gfx::Rect grow_down_tiling_rect(5 * tile_size, 7 * tile_size); |
| 703 gfx::Rect grow_right_tiling_rect(7 * tile_size, 5 * tile_size); |
| 704 gfx::Rect grow_both_tiling_rect(7 * tile_size, 7 * tile_size); |
| 705 |
| 706 Region invalidation; |
| 707 |
| 708 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 709 SetTilingRect(base_tiling_rect); |
| 710 |
| 711 // We should have a recording for every tile. |
| 712 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 713 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 714 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 715 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 716 TestPicturePile::PictureMapKey key(i, j); |
| 717 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 718 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 719 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 720 } |
| 721 } |
| 722 |
| 723 UpdateAndExpandInvalidation( |
| 724 &invalidation, grow_down_tiling_rect, gfx::Rect(1, 1)); |
| 725 |
| 726 // We should have a recording for every tile. |
| 727 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 728 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); |
| 729 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 730 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 731 TestPicturePile::PictureMapKey key(i, j); |
| 732 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 733 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 734 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 735 } |
| 736 } |
| 737 |
| 738 // No invalidation since we re-recorded existing stuff. |
| 739 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 740 invalidation.Clear(); |
| 741 |
| 742 UpdateWholePile(); |
| 743 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 744 |
| 745 // We should have a recording for every tile. |
| 746 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 747 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 748 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 749 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 750 TestPicturePile::PictureMapKey key(i, j); |
| 751 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 752 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 753 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 754 } |
| 755 } |
| 756 |
| 757 // No invalidation when shrinking. |
| 758 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 759 invalidation.Clear(); |
| 760 |
| 761 UpdateWholePile(); |
| 762 UpdateAndExpandInvalidation( |
| 763 &invalidation, grow_right_tiling_rect, gfx::Rect(1, 1)); |
| 764 |
| 765 // We should have a recording for every tile. |
| 766 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); |
| 767 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 768 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 769 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 770 TestPicturePile::PictureMapKey key(i, j); |
| 771 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 772 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 773 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 774 } |
| 775 } |
| 776 |
| 777 // No invalidation since we re-recorded existing stuff. |
| 778 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 779 invalidation.Clear(); |
| 780 |
| 781 UpdateWholePile(); |
| 782 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 783 |
| 784 // We should have lost the recordings that are now outside the tiling only. |
| 785 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 786 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 787 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 788 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 789 TestPicturePile::PictureMapKey key(i, j); |
| 790 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 791 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 792 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 793 } |
| 794 } |
| 795 |
| 796 // No invalidation when shrinking. |
| 797 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 798 invalidation.Clear(); |
| 799 |
| 800 UpdateWholePile(); |
| 801 UpdateAndExpandInvalidation( |
| 802 &invalidation, grow_both_tiling_rect, gfx::Rect(1, 1)); |
| 803 |
| 804 // We should have a recording for every tile. |
| 805 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); |
| 806 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); |
| 807 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 808 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 809 TestPicturePile::PictureMapKey key(i, j); |
| 810 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 811 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 812 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 813 } |
| 814 } |
| 815 |
| 816 // No invalidation since we re-recorded existing stuff. |
| 817 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 818 invalidation.Clear(); |
| 819 |
| 820 UpdateWholePile(); |
| 821 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect()); |
| 822 |
| 823 // We should have lost the recordings that are now outside the tiling only. |
| 824 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 825 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 826 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 827 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 828 TestPicturePile::PictureMapKey key(i, j); |
| 829 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 830 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 831 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 832 } |
| 833 } |
| 834 |
| 835 // No invalidation when shrinking. |
| 836 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 837 invalidation.Clear(); |
| 838 } |
| 839 |
| 840 TEST_F(PicturePileTest, SmallResizePileInsideInterestRect) { |
| 841 // This size chosen to be small enough that all the rects below fit inside the |
| 842 // the interest rect, so they are smaller than kPixelDistanceToRecord in each |
| 843 // dimension. |
| 844 int tile_size = 100; |
| 845 gfx::Rect base_tiling_rect(5 * tile_size, 5 * tile_size); |
| 846 gfx::Rect grow_down_tiling_rect(5 * tile_size, 5 * tile_size + 5); |
| 847 gfx::Rect grow_right_tiling_rect(5 * tile_size + 5, 5 * tile_size); |
| 848 gfx::Rect grow_both_tiling_rect(5 * tile_size + 5, 5 * tile_size + 5); |
| 849 |
| 850 Region invalidation; |
| 851 |
| 852 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 853 SetTilingRect(base_tiling_rect); |
| 854 |
| 855 // We should have a recording for every tile. |
| 856 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 857 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 858 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 859 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 860 TestPicturePile::PictureMapKey key(i, j); |
| 861 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 862 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 863 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 864 } |
| 865 } |
| 866 |
| 867 UpdateAndExpandInvalidation( |
| 868 &invalidation, grow_down_tiling_rect, gfx::Rect(1, 1)); |
| 869 |
| 870 // We should have a recording for every tile. |
| 871 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 872 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 873 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 874 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 875 TestPicturePile::PictureMapKey key(i, j); |
| 876 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 877 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 878 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 879 } |
| 880 } |
| 881 |
| 882 // No invalidation since we re-recorded existing stuff. |
| 883 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 884 invalidation.Clear(); |
| 885 |
| 886 UpdateWholePile(); |
| 887 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 888 |
| 889 // We should have a recording for every tile. |
| 890 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 891 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 892 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 893 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 894 TestPicturePile::PictureMapKey key(i, j); |
| 895 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 896 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 897 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 898 } |
| 899 } |
| 900 |
| 901 // No invalidation when shrinking. |
| 902 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 903 invalidation.Clear(); |
| 904 |
| 905 UpdateWholePile(); |
| 906 UpdateAndExpandInvalidation( |
| 907 &invalidation, grow_right_tiling_rect, gfx::Rect(1, 1)); |
| 908 |
| 909 // We should have a recording for every tile. |
| 910 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 911 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 912 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 913 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 914 TestPicturePile::PictureMapKey key(i, j); |
| 915 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 916 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 917 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 918 } |
| 919 } |
| 920 |
| 921 // No invalidation since we re-recorded existing stuff. |
| 922 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 923 invalidation.Clear(); |
| 924 |
| 925 UpdateWholePile(); |
| 926 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 927 |
| 928 // We should have lost the recordings that are now outside the tiling only. |
| 929 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 930 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 931 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 932 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 933 TestPicturePile::PictureMapKey key(i, j); |
| 934 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 935 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 936 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 937 } |
| 938 } |
| 939 |
| 940 // No invalidation when shrinking. |
| 941 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 942 invalidation.Clear(); |
| 943 |
| 944 UpdateWholePile(); |
| 945 UpdateAndExpandInvalidation( |
| 946 &invalidation, grow_both_tiling_rect, gfx::Rect(1, 1)); |
| 947 |
| 948 // We should have a recording for every tile. |
| 949 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 950 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 951 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 952 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 953 TestPicturePile::PictureMapKey key(i, j); |
| 954 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 955 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 956 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 957 } |
| 958 } |
| 959 |
| 960 // No invalidation since we re-recorded existing stuff. |
| 961 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 962 invalidation.Clear(); |
| 963 |
| 964 UpdateWholePile(); |
| 965 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect()); |
| 966 |
| 967 // We should have lost the recordings that are now outside the tiling only. |
| 968 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 969 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 970 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 971 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 972 TestPicturePile::PictureMapKey key(i, j); |
| 973 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 974 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 975 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 976 } |
| 977 } |
| 978 |
| 979 // No invalidation when shrinking. |
| 980 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 981 invalidation.Clear(); |
| 982 } |
| 983 |
| 612 } // namespace | 984 } // namespace |
| 613 } // namespace cc | 985 } // namespace cc |
| OLD | NEW |