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