| 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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/geometry/rect_conversions.h" | 12 #include "ui/gfx/geometry/rect_conversions.h" |
| 13 #include "ui/gfx/geometry/size_conversions.h" | 13 #include "ui/gfx/geometry/size_conversions.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class TestPicturePile : public PicturePile { | 18 class TestPicturePile : public PicturePile { |
| 19 public: | 19 public: |
| 20 ~TestPicturePile() override {} |
| 21 |
| 20 using PicturePile::buffer_pixels; | 22 using PicturePile::buffer_pixels; |
| 21 using PicturePile::CanRasterSlowTileCheck; | 23 using PicturePile::CanRasterSlowTileCheck; |
| 22 using PicturePile::Clear; | 24 using PicturePile::Clear; |
| 23 | 25 |
| 24 PictureMap& picture_map() { return picture_map_; } | 26 PictureMap& picture_map() { return picture_map_; } |
| 25 const gfx::Rect& recorded_viewport() const { return recorded_viewport_; } | 27 const gfx::Rect& recorded_viewport() const { return recorded_viewport_; } |
| 26 | 28 |
| 27 bool CanRasterLayerRect(const gfx::Rect& layer_rect) { | 29 bool CanRasterLayerRect(const gfx::Rect& layer_rect) { |
| 28 return CanRaster(1.f, layer_rect); | 30 return CanRaster(1.f, layer_rect); |
| 29 } | 31 } |
| 30 | 32 |
| 31 typedef PicturePile::PictureInfo PictureInfo; | 33 typedef PicturePile::PictureInfo PictureInfo; |
| 32 typedef PicturePile::PictureMapKey PictureMapKey; | 34 typedef PicturePile::PictureMapKey PictureMapKey; |
| 33 typedef PicturePile::PictureMap PictureMap; | 35 typedef PicturePile::PictureMap PictureMap; |
| 34 | |
| 35 protected: | |
| 36 ~TestPicturePile() override {} | |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 class PicturePileTestBase { | 38 class PicturePileTestBase { |
| 40 public: | 39 public: |
| 41 PicturePileTestBase() | 40 PicturePileTestBase() |
| 42 : background_color_(SK_ColorBLUE), | 41 : background_color_(SK_ColorBLUE), |
| 43 min_scale_(0.125), | 42 min_scale_(0.125), |
| 44 frame_number_(0), | 43 frame_number_(0), |
| 45 contents_opaque_(false) {} | 44 contents_opaque_(false) {} |
| 46 | 45 |
| 47 void InitializeData() { | 46 void InitializeData() { |
| 48 pile_ = make_scoped_refptr(new TestPicturePile()); | 47 pile_.SetTileGridSize(gfx::Size(1000, 1000)); |
| 49 pile_->SetTileGridSize(gfx::Size(1000, 1000)); | 48 pile_.SetMinContentsScale(min_scale_); |
| 50 pile_->SetMinContentsScale(min_scale_); | |
| 51 client_ = FakeContentLayerClient(); | 49 client_ = FakeContentLayerClient(); |
| 52 SetTilingSize(pile_->tiling().max_texture_size()); | 50 SetTilingSize(pile_.tiling().max_texture_size()); |
| 53 } | 51 } |
| 54 | 52 |
| 55 void SetTilingSize(const gfx::Size& tiling_size) { | 53 void SetTilingSize(const gfx::Size& tiling_size) { |
| 56 Region invalidation; | 54 Region invalidation; |
| 57 gfx::Rect viewport_rect(tiling_size); | 55 gfx::Rect viewport_rect(tiling_size); |
| 58 UpdateAndExpandInvalidation(&invalidation, tiling_size, viewport_rect); | 56 UpdateAndExpandInvalidation(&invalidation, tiling_size, viewport_rect); |
| 59 } | 57 } |
| 60 | 58 |
| 61 gfx::Size tiling_size() const { return pile_->tiling_size(); } | 59 gfx::Size tiling_size() const { return pile_.tiling_size(); } |
| 62 gfx::Rect tiling_rect() const { return gfx::Rect(pile_->tiling_size()); } | 60 gfx::Rect tiling_rect() const { return gfx::Rect(pile_.tiling_size()); } |
| 63 | 61 |
| 64 bool UpdateAndExpandInvalidation(Region* invalidation, | 62 bool UpdateAndExpandInvalidation(Region* invalidation, |
| 65 const gfx::Size& layer_size, | 63 const gfx::Size& layer_size, |
| 66 const gfx::Rect& visible_layer_rect) { | 64 const gfx::Rect& visible_layer_rect) { |
| 67 frame_number_++; | 65 frame_number_++; |
| 68 return pile_->UpdateAndExpandInvalidation(&client_, | 66 return pile_.UpdateAndExpandInvalidation(&client_, |
| 69 invalidation, | 67 invalidation, |
| 70 background_color_, | 68 background_color_, |
| 71 contents_opaque_, | 69 contents_opaque_, |
| 72 false, | 70 false, |
| 73 layer_size, | 71 layer_size, |
| 74 visible_layer_rect, | 72 visible_layer_rect, |
| 75 frame_number_, | 73 frame_number_, |
| 76 Picture::RECORD_NORMALLY, | 74 Picture::RECORD_NORMALLY, |
| 77 &stats_instrumentation_); | 75 &stats_instrumentation_); |
| 78 } | 76 } |
| 79 | 77 |
| 80 bool UpdateWholePile() { | 78 bool UpdateWholePile() { |
| 81 Region invalidation = tiling_rect(); | 79 Region invalidation = tiling_rect(); |
| 82 bool result = UpdateAndExpandInvalidation( | 80 bool result = UpdateAndExpandInvalidation( |
| 83 &invalidation, tiling_size(), tiling_rect()); | 81 &invalidation, tiling_size(), tiling_rect()); |
| 84 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 82 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
| 85 return result; | 83 return result; |
| 86 } | 84 } |
| 87 | 85 |
| 88 FakeContentLayerClient client_; | 86 FakeContentLayerClient client_; |
| 89 FakeRenderingStatsInstrumentation stats_instrumentation_; | 87 FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 90 scoped_refptr<TestPicturePile> pile_; | 88 TestPicturePile pile_; |
| 91 SkColor background_color_; | 89 SkColor background_color_; |
| 92 float min_scale_; | 90 float min_scale_; |
| 93 int frame_number_; | 91 int frame_number_; |
| 94 bool contents_opaque_; | 92 bool contents_opaque_; |
| 95 }; | 93 }; |
| 96 | 94 |
| 97 class PicturePileTest : public PicturePileTestBase, public testing::Test { | 95 class PicturePileTest : public PicturePileTestBase, public testing::Test { |
| 98 public: | 96 public: |
| 99 virtual void SetUp() override { InitializeData(); } | 97 virtual void SetUp() override { InitializeData(); } |
| 100 }; | 98 }; |
| 101 | 99 |
| 102 TEST_F(PicturePileTest, InvalidationOnTileBorderOutsideInterestRect) { | 100 TEST_F(PicturePileTest, InvalidationOnTileBorderOutsideInterestRect) { |
| 103 // Don't expand the interest rect past what we invalidate. | 101 // Don't expand the interest rect past what we invalidate. |
| 104 pile_->SetPixelRecordDistanceForTesting(0); | 102 pile_.SetPixelRecordDistanceForTesting(0); |
| 105 | 103 |
| 106 gfx::Size tile_size(100, 100); | 104 gfx::Size tile_size(100, 100); |
| 107 pile_->tiling().SetMaxTextureSize(tile_size); | 105 pile_.tiling().SetMaxTextureSize(tile_size); |
| 108 | 106 |
| 109 gfx::Size pile_size(400, 400); | 107 gfx::Size pile_size(400, 400); |
| 110 SetTilingSize(pile_size); | 108 SetTilingSize(pile_size); |
| 111 | 109 |
| 112 // We have multiple tiles. | 110 // We have multiple tiles. |
| 113 EXPECT_GT(pile_->tiling().num_tiles_x(), 2); | 111 EXPECT_GT(pile_.tiling().num_tiles_x(), 2); |
| 114 EXPECT_GT(pile_->tiling().num_tiles_y(), 2); | 112 EXPECT_GT(pile_.tiling().num_tiles_y(), 2); |
| 115 | 113 |
| 116 // Record everything. | 114 // Record everything. |
| 117 Region invalidation(tiling_rect()); | 115 Region invalidation(tiling_rect()); |
| 118 UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect()); | 116 UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect()); |
| 119 | 117 |
| 120 // +----------+-----------------+-----------+ | 118 // +----------+-----------------+-----------+ |
| 121 // | | VVVV 1,0| | | 119 // | | VVVV 1,0| | |
| 122 // | | VVVV | | | 120 // | | VVVV | | |
| 123 // | | VVVV | | | 121 // | | VVVV | | |
| 124 // | ...|.................|... | | 122 // | ...|.................|... | |
| (...skipping 13 matching lines...) Expand all Loading... |
| 138 // VV = interest rect (what we will record) | 136 // VV = interest rect (what we will record) |
| 139 // | 137 // |
| 140 // The first invalidation is inside VV, so it does not touch border pixels of | 138 // The first invalidation is inside VV, so it does not touch border pixels of |
| 141 // tile 1,1. | 139 // tile 1,1. |
| 142 // | 140 // |
| 143 // The second invalidation goes below VV into the .. border pixels of 1,1. | 141 // The second invalidation goes below VV into the .. border pixels of 1,1. |
| 144 | 142 |
| 145 // This is the VV interest rect which will be entirely inside 1,0 and not | 143 // This is the VV interest rect which will be entirely inside 1,0 and not |
| 146 // touch the border of 1,1. | 144 // touch the border of 1,1. |
| 147 gfx::Rect interest_rect( | 145 gfx::Rect interest_rect( |
| 148 pile_->tiling().TilePositionX(1) + pile_->tiling().border_texels(), | 146 pile_.tiling().TilePositionX(1) + pile_.tiling().border_texels(), |
| 149 0, | 147 0, |
| 150 10, | 148 10, |
| 151 pile_->tiling().TileSizeY(0) - pile_->tiling().border_texels()); | 149 pile_.tiling().TileSizeY(0) - pile_.tiling().border_texels()); |
| 152 | 150 |
| 153 // Invalidate tile 1,0 only. This is a rect that avoids the borders of any | 151 // Invalidate tile 1,0 only. This is a rect that avoids the borders of any |
| 154 // other tiles. | 152 // other tiles. |
| 155 gfx::Rect invalidate_tile = interest_rect; | 153 gfx::Rect invalidate_tile = interest_rect; |
| 156 // This should cause the tile 1,0 to be invalidated and re-recorded. The | 154 // This should cause the tile 1,0 to be invalidated and re-recorded. The |
| 157 // invalidation did not need to be expanded. | 155 // invalidation did not need to be expanded. |
| 158 invalidation = invalidate_tile; | 156 invalidation = invalidate_tile; |
| 159 UpdateAndExpandInvalidation(&invalidation, tiling_size(), interest_rect); | 157 UpdateAndExpandInvalidation(&invalidation, tiling_size(), interest_rect); |
| 160 EXPECT_EQ(invalidate_tile, invalidation); | 158 EXPECT_EQ(invalidate_tile, invalidation); |
| 161 | 159 |
| 162 // Invalidate tile 1,0 and 1,1 by invalidating something that only touches the | 160 // Invalidate tile 1,0 and 1,1 by invalidating something that only touches the |
| 163 // border of 1,1 (and is inside the tile bounds of 1,0). This is a 10px wide | 161 // border of 1,1 (and is inside the tile bounds of 1,0). This is a 10px wide |
| 164 // strip from the top of the tiling onto the border pixels of tile 1,1 that | 162 // strip from the top of the tiling onto the border pixels of tile 1,1 that |
| 165 // avoids border pixels of any other tiles. | 163 // avoids border pixels of any other tiles. |
| 166 gfx::Rect invalidate_border = interest_rect; | 164 gfx::Rect invalidate_border = interest_rect; |
| 167 invalidate_border.Inset(0, 0, 0, -1); | 165 invalidate_border.Inset(0, 0, 0, -1); |
| 168 // This should cause the tile 1,0 and 1,1 to be invalidated. The 1,1 tile will | 166 // This should cause the tile 1,0 and 1,1 to be invalidated. The 1,1 tile will |
| 169 // not be re-recorded since it does not touch the interest rect, so the | 167 // not be re-recorded since it does not touch the interest rect, so the |
| 170 // invalidation should be expanded to cover all of 1,1. | 168 // invalidation should be expanded to cover all of 1,1. |
| 171 invalidation = invalidate_border; | 169 invalidation = invalidate_border; |
| 172 UpdateAndExpandInvalidation(&invalidation, tiling_size(), interest_rect); | 170 UpdateAndExpandInvalidation(&invalidation, tiling_size(), interest_rect); |
| 173 Region expected_invalidation = invalidate_border; | 171 Region expected_invalidation = invalidate_border; |
| 174 expected_invalidation.Union(pile_->tiling().TileBounds(1, 1)); | 172 expected_invalidation.Union(pile_.tiling().TileBounds(1, 1)); |
| 175 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 173 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 176 } | 174 } |
| 177 | 175 |
| 178 TEST_F(PicturePileTest, SmallInvalidateInflated) { | 176 TEST_F(PicturePileTest, SmallInvalidateInflated) { |
| 179 // Invalidate something inside a tile. | 177 // Invalidate something inside a tile. |
| 180 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); | 178 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); |
| 181 UpdateAndExpandInvalidation(&invalidate_rect, tiling_size(), tiling_rect()); | 179 UpdateAndExpandInvalidation(&invalidate_rect, tiling_size(), tiling_rect()); |
| 182 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); | 180 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); |
| 183 | 181 |
| 184 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 182 EXPECT_EQ(1, pile_.tiling().num_tiles_x()); |
| 185 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 183 EXPECT_EQ(1, pile_.tiling().num_tiles_y()); |
| 186 | 184 |
| 187 TestPicturePile::PictureInfo& picture_info = | 185 TestPicturePile::PictureInfo& picture_info = |
| 188 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 186 pile_.picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
| 189 // We should have a picture. | 187 // We should have a picture. |
| 190 EXPECT_TRUE(!!picture_info.GetPicture()); | 188 EXPECT_TRUE(!!picture_info.GetPicture()); |
| 191 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( | 189 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( |
| 192 picture_info.GetPicture()->LayerRect(), min_scale_); | 190 picture_info.GetPicture()->LayerRect(), min_scale_); |
| 193 | 191 |
| 194 // The the picture should be large enough that scaling it never makes a rect | 192 // The the picture should be large enough that scaling it never makes a rect |
| 195 // smaller than 1 px wide or tall. | 193 // smaller than 1 px wide or tall. |
| 196 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << | 194 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << |
| 197 picture_rect.ToString(); | 195 picture_rect.ToString(); |
| 198 } | 196 } |
| 199 | 197 |
| 200 TEST_F(PicturePileTest, LargeInvalidateInflated) { | 198 TEST_F(PicturePileTest, LargeInvalidateInflated) { |
| 201 // Invalidate something inside a tile. | 199 // Invalidate something inside a tile. |
| 202 Region invalidate_rect(gfx::Rect(50, 50, 100, 100)); | 200 Region invalidate_rect(gfx::Rect(50, 50, 100, 100)); |
| 203 UpdateAndExpandInvalidation(&invalidate_rect, tiling_size(), tiling_rect()); | 201 UpdateAndExpandInvalidation(&invalidate_rect, tiling_size(), tiling_rect()); |
| 204 EXPECT_EQ(gfx::Rect(50, 50, 100, 100).ToString(), invalidate_rect.ToString()); | 202 EXPECT_EQ(gfx::Rect(50, 50, 100, 100).ToString(), invalidate_rect.ToString()); |
| 205 | 203 |
| 206 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 204 EXPECT_EQ(1, pile_.tiling().num_tiles_x()); |
| 207 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 205 EXPECT_EQ(1, pile_.tiling().num_tiles_y()); |
| 208 | 206 |
| 209 TestPicturePile::PictureInfo& picture_info = | 207 TestPicturePile::PictureInfo& picture_info = |
| 210 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 208 pile_.picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
| 211 EXPECT_TRUE(!!picture_info.GetPicture()); | 209 EXPECT_TRUE(!!picture_info.GetPicture()); |
| 212 | 210 |
| 213 int expected_inflation = pile_->buffer_pixels(); | 211 int expected_inflation = pile_.buffer_pixels(); |
| 214 | 212 |
| 215 const Picture* base_picture = picture_info.GetPicture(); | 213 const Picture* base_picture = picture_info.GetPicture(); |
| 216 gfx::Rect base_picture_rect(pile_->tiling_size()); | 214 gfx::Rect base_picture_rect(pile_.tiling_size()); |
| 217 base_picture_rect.Inset(-expected_inflation, -expected_inflation); | 215 base_picture_rect.Inset(-expected_inflation, -expected_inflation); |
| 218 EXPECT_EQ(base_picture_rect.ToString(), | 216 EXPECT_EQ(base_picture_rect.ToString(), |
| 219 base_picture->LayerRect().ToString()); | 217 base_picture->LayerRect().ToString()); |
| 220 } | 218 } |
| 221 | 219 |
| 222 TEST_F(PicturePileTest, InvalidateOnTileBoundaryInflated) { | 220 TEST_F(PicturePileTest, InvalidateOnTileBoundaryInflated) { |
| 223 gfx::Size new_tiling_size = | 221 gfx::Size new_tiling_size = |
| 224 gfx::ToCeiledSize(gfx::ScaleSize(pile_->tiling_size(), 2.f)); | 222 gfx::ToCeiledSize(gfx::ScaleSize(pile_.tiling_size(), 2.f)); |
| 225 // This creates initial pictures. | 223 // This creates initial pictures. |
| 226 SetTilingSize(new_tiling_size); | 224 SetTilingSize(new_tiling_size); |
| 227 | 225 |
| 228 // Due to border pixels, we should have 3 tiles. | 226 // Due to border pixels, we should have 3 tiles. |
| 229 EXPECT_EQ(3, pile_->tiling().num_tiles_x()); | 227 EXPECT_EQ(3, pile_.tiling().num_tiles_x()); |
| 230 EXPECT_EQ(3, pile_->tiling().num_tiles_y()); | 228 EXPECT_EQ(3, pile_.tiling().num_tiles_y()); |
| 231 | 229 |
| 232 // We should have 1/.125 - 1 = 7 border pixels. | 230 // We should have 1/.125 - 1 = 7 border pixels. |
| 233 EXPECT_EQ(7, pile_->buffer_pixels()); | 231 EXPECT_EQ(7, pile_.buffer_pixels()); |
| 234 EXPECT_EQ(7, pile_->tiling().border_texels()); | 232 EXPECT_EQ(7, pile_.tiling().border_texels()); |
| 235 | 233 |
| 236 // Invalidate everything to have a non zero invalidation frequency. | 234 // Invalidate everything to have a non zero invalidation frequency. |
| 237 UpdateWholePile(); | 235 UpdateWholePile(); |
| 238 | 236 |
| 239 // Invalidate something just over a tile boundary by a single pixel. | 237 // Invalidate something just over a tile boundary by a single pixel. |
| 240 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). | 238 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). |
| 241 Region invalidate_rect( | 239 Region invalidate_rect( |
| 242 gfx::Rect(pile_->tiling().TileBoundsWithBorder(0, 0).right(), | 240 gfx::Rect(pile_.tiling().TileBoundsWithBorder(0, 0).right(), |
| 243 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, | 241 pile_.tiling().TileBoundsWithBorder(0, 0).bottom() - 1, |
| 244 50, | 242 50, |
| 245 50)); | 243 50)); |
| 246 Region expected_invalidation = invalidate_rect; | 244 Region expected_invalidation = invalidate_rect; |
| 247 UpdateAndExpandInvalidation(&invalidate_rect, tiling_size(), tiling_rect()); | 245 UpdateAndExpandInvalidation(&invalidate_rect, tiling_size(), tiling_rect()); |
| 248 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString()); | 246 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString()); |
| 249 | 247 |
| 250 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 248 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 251 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 249 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 252 TestPicturePile::PictureInfo& picture_info = | 250 TestPicturePile::PictureInfo& picture_info = |
| 253 pile_->picture_map() | 251 pile_.picture_map() |
| 254 .find(TestPicturePile::PictureMapKey(i, j)) | 252 .find(TestPicturePile::PictureMapKey(i, j)) |
| 255 ->second; | 253 ->second; |
| 256 | 254 |
| 257 // Expect (1, 1) and (1, 0) to be invalidated once more | 255 // Expect (1, 1) and (1, 0) to be invalidated once more |
| 258 // than the rest of the tiles. | 256 // than the rest of the tiles. |
| 259 if (i == 1 && (j == 0 || j == 1)) { | 257 if (i == 1 && (j == 0 || j == 1)) { |
| 260 EXPECT_FLOAT_EQ( | 258 EXPECT_FLOAT_EQ( |
| 261 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 259 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
| 262 picture_info.GetInvalidationFrequencyForTesting()); | 260 picture_info.GetInvalidationFrequencyForTesting()); |
| 263 } else { | 261 } else { |
| 264 EXPECT_FLOAT_EQ( | 262 EXPECT_FLOAT_EQ( |
| 265 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 263 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
| 266 picture_info.GetInvalidationFrequencyForTesting()); | 264 picture_info.GetInvalidationFrequencyForTesting()); |
| 267 } | 265 } |
| 268 } | 266 } |
| 269 } | 267 } |
| 270 } | 268 } |
| 271 | 269 |
| 272 TEST_F(PicturePileTest, InvalidateOnFullLayer) { | 270 TEST_F(PicturePileTest, InvalidateOnFullLayer) { |
| 273 UpdateWholePile(); | 271 UpdateWholePile(); |
| 274 | 272 |
| 275 // Everything was invalidated once so far. | 273 // Everything was invalidated once so far. |
| 276 for (auto& it : pile_->picture_map()) { | 274 for (auto& it : pile_.picture_map()) { |
| 277 EXPECT_FLOAT_EQ( | 275 EXPECT_FLOAT_EQ( |
| 278 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 276 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
| 279 it.second.GetInvalidationFrequencyForTesting()); | 277 it.second.GetInvalidationFrequencyForTesting()); |
| 280 } | 278 } |
| 281 | 279 |
| 282 // Invalidate everything, | 280 // Invalidate everything, |
| 283 Region invalidation = tiling_rect(); | 281 Region invalidation = tiling_rect(); |
| 284 UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect()); | 282 UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect()); |
| 285 | 283 |
| 286 // Everything was invalidated again. | 284 // Everything was invalidated again. |
| 287 for (auto& it : pile_->picture_map()) { | 285 for (auto& it : pile_.picture_map()) { |
| 288 EXPECT_FLOAT_EQ( | 286 EXPECT_FLOAT_EQ( |
| 289 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 287 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
| 290 it.second.GetInvalidationFrequencyForTesting()); | 288 it.second.GetInvalidationFrequencyForTesting()); |
| 291 } | 289 } |
| 292 } | 290 } |
| 293 | 291 |
| 294 TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) { | 292 TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) { |
| 295 gfx::Size new_tiling_size = | 293 gfx::Size new_tiling_size = |
| 296 gfx::ToCeiledSize(gfx::ScaleSize(pile_->tiling_size(), 4.f)); | 294 gfx::ToCeiledSize(gfx::ScaleSize(pile_.tiling_size(), 4.f)); |
| 297 SetTilingSize(new_tiling_size); | 295 SetTilingSize(new_tiling_size); |
| 298 | 296 |
| 299 gfx::Rect viewport(tiling_size().width(), 1); | 297 gfx::Rect viewport(tiling_size().width(), 1); |
| 300 | 298 |
| 301 // Update the whole pile until the invalidation frequency is high. | 299 // Update the whole pile until the invalidation frequency is high. |
| 302 for (int frame = 0; frame < 33; ++frame) { | 300 for (int frame = 0; frame < 33; ++frame) { |
| 303 UpdateWholePile(); | 301 UpdateWholePile(); |
| 304 } | 302 } |
| 305 | 303 |
| 306 // Make sure we have a high invalidation frequency. | 304 // Make sure we have a high invalidation frequency. |
| 307 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 305 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 308 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 306 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 309 TestPicturePile::PictureInfo& picture_info = | 307 TestPicturePile::PictureInfo& picture_info = |
| 310 pile_->picture_map() | 308 pile_.picture_map() |
| 311 .find(TestPicturePile::PictureMapKey(i, j)) | 309 .find(TestPicturePile::PictureMapKey(i, j)) |
| 312 ->second; | 310 ->second; |
| 313 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) | 311 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) |
| 314 << "i " << i << " j " << j; | 312 << "i " << i << " j " << j; |
| 315 } | 313 } |
| 316 } | 314 } |
| 317 | 315 |
| 318 // Update once more with a small viewport. | 316 // Update once more with a small viewport. |
| 319 Region invalidation(tiling_rect()); | 317 Region invalidation(tiling_rect()); |
| 320 UpdateAndExpandInvalidation(&invalidation, tiling_size(), viewport); | 318 UpdateAndExpandInvalidation(&invalidation, tiling_size(), viewport); |
| 321 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 319 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
| 322 | 320 |
| 323 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 321 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 324 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 322 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 325 TestPicturePile::PictureInfo& picture_info = | 323 TestPicturePile::PictureInfo& picture_info = |
| 326 pile_->picture_map() | 324 pile_.picture_map() |
| 327 .find(TestPicturePile::PictureMapKey(i, j)) | 325 .find(TestPicturePile::PictureMapKey(i, j)) |
| 328 ->second; | 326 ->second; |
| 329 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); | 327 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); |
| 330 | 328 |
| 331 // If the y far enough away we expect to find no picture (no re-recording | 329 // If the y far enough away we expect to find no picture (no re-recording |
| 332 // happened). For close y, the picture should change. | 330 // happened). For close y, the picture should change. |
| 333 if (j >= 2) | 331 if (j >= 2) |
| 334 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; | 332 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 335 else | 333 else |
| 336 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 334 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 337 } | 335 } |
| 338 } | 336 } |
| 339 | 337 |
| 340 // Update a partial tile that doesn't get recorded. We should expand the | 338 // Update a partial tile that doesn't get recorded. We should expand the |
| 341 // invalidation to the entire tiles that overlap it. | 339 // invalidation to the entire tiles that overlap it. |
| 342 Region small_invalidation = | 340 Region small_invalidation = |
| 343 gfx::Rect(pile_->tiling().TileBounds(3, 4).x(), | 341 gfx::Rect(pile_.tiling().TileBounds(3, 4).x(), |
| 344 pile_->tiling().TileBounds(3, 4).y() + 10, | 342 pile_.tiling().TileBounds(3, 4).y() + 10, |
| 345 1, | 343 1, |
| 346 1); | 344 1); |
| 347 UpdateAndExpandInvalidation(&small_invalidation, tiling_size(), viewport); | 345 UpdateAndExpandInvalidation(&small_invalidation, tiling_size(), viewport); |
| 348 EXPECT_TRUE(small_invalidation.Contains(gfx::UnionRects( | 346 EXPECT_TRUE(small_invalidation.Contains(gfx::UnionRects( |
| 349 pile_->tiling().TileBounds(2, 4), pile_->tiling().TileBounds(3, 4)))) | 347 pile_.tiling().TileBounds(2, 4), pile_.tiling().TileBounds(3, 4)))) |
| 350 << small_invalidation.ToString(); | 348 << small_invalidation.ToString(); |
| 351 | 349 |
| 352 // Now update with no invalidation and full viewport | 350 // Now update with no invalidation and full viewport |
| 353 Region empty_invalidation; | 351 Region empty_invalidation; |
| 354 UpdateAndExpandInvalidation( | 352 UpdateAndExpandInvalidation( |
| 355 &empty_invalidation, tiling_size(), tiling_rect()); | 353 &empty_invalidation, tiling_size(), tiling_rect()); |
| 356 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString()); | 354 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString()); |
| 357 | 355 |
| 358 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 356 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 359 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 357 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 360 TestPicturePile::PictureInfo& picture_info = | 358 TestPicturePile::PictureInfo& picture_info = |
| 361 pile_->picture_map() | 359 pile_.picture_map() |
| 362 .find(TestPicturePile::PictureMapKey(i, j)) | 360 .find(TestPicturePile::PictureMapKey(i, j)) |
| 363 ->second; | 361 ->second; |
| 364 // Expect the invalidation frequency to be less than 1, since we just | 362 // Expect the invalidation frequency to be less than 1, since we just |
| 365 // updated with no invalidations. | 363 // updated with no invalidations. |
| 366 EXPECT_LT(picture_info.GetInvalidationFrequencyForTesting(), 1.f); | 364 EXPECT_LT(picture_info.GetInvalidationFrequencyForTesting(), 1.f); |
| 367 | 365 |
| 368 // We expect that there are pictures everywhere now. | 366 // We expect that there are pictures everywhere now. |
| 369 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 367 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 370 } | 368 } |
| 371 } | 369 } |
| 372 } | 370 } |
| 373 | 371 |
| 374 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { | 372 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { |
| 375 gfx::Rect rect(0, 0, 5, 5); | 373 gfx::Rect rect(0, 0, 5, 5); |
| 376 EXPECT_TRUE(pile_->CanRasterLayerRect(rect)); | 374 EXPECT_TRUE(pile_.CanRasterLayerRect(rect)); |
| 377 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect)); | 375 EXPECT_TRUE(pile_.CanRasterSlowTileCheck(rect)); |
| 378 | 376 |
| 379 pile_->Clear(); | 377 pile_.Clear(); |
| 380 | 378 |
| 381 // Make sure both the cache-aware check (using recorded region) and the normal | 379 // Make sure both the cache-aware check (using recorded region) and the normal |
| 382 // check are both false after clearing. | 380 // check are both false after clearing. |
| 383 EXPECT_FALSE(pile_->CanRasterLayerRect(rect)); | 381 EXPECT_FALSE(pile_.CanRasterLayerRect(rect)); |
| 384 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect)); | 382 EXPECT_FALSE(pile_.CanRasterSlowTileCheck(rect)); |
| 385 } | 383 } |
| 386 | 384 |
| 387 TEST_F(PicturePileTest, FrequentInvalidationCanRaster) { | 385 TEST_F(PicturePileTest, FrequentInvalidationCanRaster) { |
| 388 // This test makes sure that if part of the page is frequently invalidated | 386 // This test makes sure that if part of the page is frequently invalidated |
| 389 // and doesn't get re-recorded, then CanRaster is not true for any | 387 // and doesn't get re-recorded, then CanRaster is not true for any |
| 390 // tiles touching it, but is true for adjacent tiles, even if it | 388 // tiles touching it, but is true for adjacent tiles, even if it |
| 391 // overlaps on borders (edge case). | 389 // overlaps on borders (edge case). |
| 392 gfx::Size new_tiling_size = | 390 gfx::Size new_tiling_size = |
| 393 gfx::ToCeiledSize(gfx::ScaleSize(pile_->tiling_size(), 4.f)); | 391 gfx::ToCeiledSize(gfx::ScaleSize(pile_.tiling_size(), 4.f)); |
| 394 SetTilingSize(new_tiling_size); | 392 SetTilingSize(new_tiling_size); |
| 395 | 393 |
| 396 gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1); | 394 gfx::Rect tile01_borders = pile_.tiling().TileBoundsWithBorder(0, 1); |
| 397 gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2); | 395 gfx::Rect tile02_borders = pile_.tiling().TileBoundsWithBorder(0, 2); |
| 398 gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1); | 396 gfx::Rect tile01_noborders = pile_.tiling().TileBounds(0, 1); |
| 399 gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2); | 397 gfx::Rect tile02_noborders = pile_.tiling().TileBounds(0, 2); |
| 400 | 398 |
| 401 // Sanity check these two tiles are overlapping with borders, since this is | 399 // Sanity check these two tiles are overlapping with borders, since this is |
| 402 // what the test is trying to repro. | 400 // what the test is trying to repro. |
| 403 EXPECT_TRUE(tile01_borders.Intersects(tile02_borders)); | 401 EXPECT_TRUE(tile01_borders.Intersects(tile02_borders)); |
| 404 EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders)); | 402 EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders)); |
| 405 UpdateWholePile(); | 403 UpdateWholePile(); |
| 406 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); | 404 EXPECT_TRUE(pile_.CanRasterLayerRect(tile01_noborders)); |
| 407 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); | 405 EXPECT_TRUE(pile_.CanRasterSlowTileCheck(tile01_noborders)); |
| 408 EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders)); | 406 EXPECT_TRUE(pile_.CanRasterLayerRect(tile02_noborders)); |
| 409 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders)); | 407 EXPECT_TRUE(pile_.CanRasterSlowTileCheck(tile02_noborders)); |
| 410 // Sanity check that an initial paint goes down the fast path of having | 408 // Sanity check that an initial paint goes down the fast path of having |
| 411 // a valid recorded viewport. | 409 // a valid recorded viewport. |
| 412 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 410 EXPECT_TRUE(!pile_.recorded_viewport().IsEmpty()); |
| 413 | 411 |
| 414 // Update the whole layer until the invalidation frequency is high. | 412 // Update the whole layer until the invalidation frequency is high. |
| 415 for (int frame = 0; frame < 33; ++frame) { | 413 for (int frame = 0; frame < 33; ++frame) { |
| 416 UpdateWholePile(); | 414 UpdateWholePile(); |
| 417 } | 415 } |
| 418 | 416 |
| 419 // Update once more with a small viewport. | 417 // Update once more with a small viewport. |
| 420 gfx::Rect viewport(tiling_size().width(), 1); | 418 gfx::Rect viewport(tiling_size().width(), 1); |
| 421 Region invalidation(tiling_rect()); | 419 Region invalidation(tiling_rect()); |
| 422 UpdateAndExpandInvalidation(&invalidation, tiling_size(), viewport); | 420 UpdateAndExpandInvalidation(&invalidation, tiling_size(), viewport); |
| 423 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 421 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
| 424 | 422 |
| 425 // Sanity check some pictures exist and others don't. | 423 // Sanity check some pictures exist and others don't. |
| 426 EXPECT_TRUE(pile_->picture_map() | 424 EXPECT_TRUE(pile_.picture_map() |
| 427 .find(TestPicturePile::PictureMapKey(0, 1)) | 425 .find(TestPicturePile::PictureMapKey(0, 1)) |
| 428 ->second.GetPicture()); | 426 ->second.GetPicture()); |
| 429 EXPECT_FALSE(pile_->picture_map() | 427 EXPECT_FALSE(pile_.picture_map() |
| 430 .find(TestPicturePile::PictureMapKey(0, 2)) | 428 .find(TestPicturePile::PictureMapKey(0, 2)) |
| 431 ->second.GetPicture()); | 429 ->second.GetPicture()); |
| 432 | 430 |
| 433 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); | 431 EXPECT_TRUE(pile_.CanRasterLayerRect(tile01_noborders)); |
| 434 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); | 432 EXPECT_TRUE(pile_.CanRasterSlowTileCheck(tile01_noborders)); |
| 435 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); | 433 EXPECT_FALSE(pile_.CanRasterLayerRect(tile02_noborders)); |
| 436 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); | 434 EXPECT_FALSE(pile_.CanRasterSlowTileCheck(tile02_noborders)); |
| 437 } | 435 } |
| 438 | 436 |
| 439 TEST_F(PicturePileTest, NoInvalidationValidViewport) { | 437 TEST_F(PicturePileTest, NoInvalidationValidViewport) { |
| 440 // This test validates that the recorded_viewport cache of full tiles | 438 // This test validates that the recorded_viewport cache of full tiles |
| 441 // is still valid for some use cases. If it's not, it's a performance | 439 // is still valid for some use cases. If it's not, it's a performance |
| 442 // issue because CanRaster checks will go down the slow path. | 440 // issue because CanRaster checks will go down the slow path. |
| 443 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 441 EXPECT_TRUE(!pile_.recorded_viewport().IsEmpty()); |
| 444 | 442 |
| 445 // No invalidation, same viewport. | 443 // No invalidation, same viewport. |
| 446 Region invalidation; | 444 Region invalidation; |
| 447 UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect()); | 445 UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect()); |
| 448 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 446 EXPECT_TRUE(!pile_.recorded_viewport().IsEmpty()); |
| 449 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 447 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 450 | 448 |
| 451 // Partial invalidation, same viewport. | 449 // Partial invalidation, same viewport. |
| 452 invalidation = gfx::Rect(0, 0, 1, 1); | 450 invalidation = gfx::Rect(0, 0, 1, 1); |
| 453 UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect()); | 451 UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect()); |
| 454 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 452 EXPECT_TRUE(!pile_.recorded_viewport().IsEmpty()); |
| 455 EXPECT_EQ(gfx::Rect(0, 0, 1, 1).ToString(), invalidation.ToString()); | 453 EXPECT_EQ(gfx::Rect(0, 0, 1, 1).ToString(), invalidation.ToString()); |
| 456 | 454 |
| 457 // No invalidation, changing viewport. | 455 // No invalidation, changing viewport. |
| 458 invalidation = Region(); | 456 invalidation = Region(); |
| 459 UpdateAndExpandInvalidation( | 457 UpdateAndExpandInvalidation( |
| 460 &invalidation, tiling_size(), gfx::Rect(5, 5, 5, 5)); | 458 &invalidation, tiling_size(), gfx::Rect(5, 5, 5, 5)); |
| 461 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 459 EXPECT_TRUE(!pile_.recorded_viewport().IsEmpty()); |
| 462 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 460 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 463 } | 461 } |
| 464 | 462 |
| 465 TEST_F(PicturePileTest, BigFullLayerInvalidation) { | 463 TEST_F(PicturePileTest, BigFullLayerInvalidation) { |
| 466 gfx::Size huge_layer_size(100000000, 100000000); | 464 gfx::Size huge_layer_size(100000000, 100000000); |
| 467 gfx::Rect viewport(300000, 400000, 5000, 6000); | 465 gfx::Rect viewport(300000, 400000, 5000, 6000); |
| 468 | 466 |
| 469 // Resize the pile. | 467 // Resize the pile. |
| 470 Region invalidation; | 468 Region invalidation; |
| 471 UpdateAndExpandInvalidation(&invalidation, huge_layer_size, viewport); | 469 UpdateAndExpandInvalidation(&invalidation, huge_layer_size, viewport); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 UpdateAndExpandInvalidation(&invalidation, huge_layer_size, viewport); | 529 UpdateAndExpandInvalidation(&invalidation, huge_layer_size, viewport); |
| 532 | 530 |
| 533 // Invalidation inside the recording rect does not need to be expanded. | 531 // Invalidation inside the recording rect does not need to be expanded. |
| 534 invalidation = viewport; | 532 invalidation = viewport; |
| 535 UpdateAndExpandInvalidation(&invalidation, huge_layer_size, viewport); | 533 UpdateAndExpandInvalidation(&invalidation, huge_layer_size, viewport); |
| 536 EXPECT_EQ(viewport.ToString(), invalidation.ToString()); | 534 EXPECT_EQ(viewport.ToString(), invalidation.ToString()); |
| 537 | 535 |
| 538 // Invalidation outside the recording rect should expand to the tiles it | 536 // Invalidation outside the recording rect should expand to the tiles it |
| 539 // covers. | 537 // covers. |
| 540 gfx::Rect recorded_over_tiles = | 538 gfx::Rect recorded_over_tiles = |
| 541 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); | 539 pile_.tiling().ExpandRectToTileBounds(pile_.recorded_viewport()); |
| 542 gfx::Rect invalidation_outside( | 540 gfx::Rect invalidation_outside( |
| 543 recorded_over_tiles.right(), recorded_over_tiles.y(), 30, 30); | 541 recorded_over_tiles.right(), recorded_over_tiles.y(), 30, 30); |
| 544 invalidation = invalidation_outside; | 542 invalidation = invalidation_outside; |
| 545 UpdateAndExpandInvalidation(&invalidation, huge_layer_size, viewport); | 543 UpdateAndExpandInvalidation(&invalidation, huge_layer_size, viewport); |
| 546 gfx::Rect expanded_recorded_viewport = | 544 gfx::Rect expanded_recorded_viewport = |
| 547 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); | 545 pile_.tiling().ExpandRectToTileBounds(pile_.recorded_viewport()); |
| 548 Region expected_invalidation = | 546 Region expected_invalidation = |
| 549 pile_->tiling().ExpandRectToTileBounds(invalidation_outside); | 547 pile_.tiling().ExpandRectToTileBounds(invalidation_outside); |
| 550 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 548 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 551 } | 549 } |
| 552 | 550 |
| 553 enum Corner { | 551 enum Corner { |
| 554 TOP_LEFT, | 552 TOP_LEFT, |
| 555 TOP_RIGHT, | 553 TOP_RIGHT, |
| 556 BOTTOM_LEFT, | 554 BOTTOM_LEFT, |
| 557 BOTTOM_RIGHT, | 555 BOTTOM_RIGHT, |
| 558 }; | 556 }; |
| 559 | 557 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 gfx::Size grow_down_tiling_size(6 * tile_size + offset, | 589 gfx::Size grow_down_tiling_size(6 * tile_size + offset, |
| 592 8 * tile_size + offset); | 590 8 * tile_size + offset); |
| 593 gfx::Size grow_right_tiling_size(8 * tile_size + offset, | 591 gfx::Size grow_right_tiling_size(8 * tile_size + offset, |
| 594 6 * tile_size + offset); | 592 6 * tile_size + offset); |
| 595 gfx::Size grow_both_tiling_size(8 * tile_size + offset, | 593 gfx::Size grow_both_tiling_size(8 * tile_size + offset, |
| 596 8 * tile_size + offset); | 594 8 * tile_size + offset); |
| 597 | 595 |
| 598 Region invalidation; | 596 Region invalidation; |
| 599 Region expected_invalidation; | 597 Region expected_invalidation; |
| 600 | 598 |
| 601 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); | 599 pile_.tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 602 SetTilingSize(base_tiling_size); | 600 SetTilingSize(base_tiling_size); |
| 603 | 601 |
| 604 // We should have a recording for every tile. | 602 // We should have a recording for every tile. |
| 605 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 603 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 606 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 604 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 607 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 605 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 608 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 606 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 609 TestPicturePile::PictureMapKey key(i, j); | 607 TestPicturePile::PictureMapKey key(i, j); |
| 610 TestPicturePile::PictureMap& map = pile_->picture_map(); | 608 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 611 TestPicturePile::PictureMap::iterator it = map.find(key); | 609 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 612 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 610 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 613 } | 611 } |
| 614 } | 612 } |
| 615 | 613 |
| 616 UpdateAndExpandInvalidation( | 614 UpdateAndExpandInvalidation( |
| 617 &invalidation, | 615 &invalidation, |
| 618 grow_down_tiling_size, | 616 grow_down_tiling_size, |
| 619 CornerSinglePixelRect(corner, grow_down_tiling_size)); | 617 CornerSinglePixelRect(corner, grow_down_tiling_size)); |
| 620 | 618 |
| 621 // We should have lost the recordings in the bottom row. | 619 // We should have lost the recordings in the bottom row. |
| 622 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 620 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 623 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); | 621 EXPECT_EQ(8, pile_.tiling().num_tiles_y()); |
| 624 for (int i = 0; i < 6; ++i) { | 622 for (int i = 0; i < 6; ++i) { |
| 625 for (int j = 0; j < 6; ++j) { | 623 for (int j = 0; j < 6; ++j) { |
| 626 TestPicturePile::PictureMapKey key(i, j); | 624 TestPicturePile::PictureMapKey key(i, j); |
| 627 TestPicturePile::PictureMap& map = pile_->picture_map(); | 625 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 628 TestPicturePile::PictureMap::iterator it = map.find(key); | 626 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 629 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); | 627 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); |
| 630 } | 628 } |
| 631 } | 629 } |
| 632 | 630 |
| 633 // We invalidated all new pixels in the recording. | 631 // We invalidated all new pixels in the recording. |
| 634 expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), | 632 expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), |
| 635 gfx::Rect(base_tiling_size)); | 633 gfx::Rect(base_tiling_size)); |
| 636 // But the new pixels don't cover the whole bottom row. | 634 // But the new pixels don't cover the whole bottom row. |
| 637 gfx::Rect bottom_row = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), | 635 gfx::Rect bottom_row = gfx::UnionRects(pile_.tiling().TileBounds(0, 5), |
| 638 pile_->tiling().TileBounds(5, 5)); | 636 pile_.tiling().TileBounds(5, 5)); |
| 639 EXPECT_FALSE(expected_invalidation.Contains(bottom_row)); | 637 EXPECT_FALSE(expected_invalidation.Contains(bottom_row)); |
| 640 // We invalidated the entire old bottom row. | 638 // We invalidated the entire old bottom row. |
| 641 expected_invalidation.Union(bottom_row); | 639 expected_invalidation.Union(bottom_row); |
| 642 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 640 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 643 invalidation.Clear(); | 641 invalidation.Clear(); |
| 644 | 642 |
| 645 UpdateWholePile(); | 643 UpdateWholePile(); |
| 646 UpdateAndExpandInvalidation(&invalidation, | 644 UpdateAndExpandInvalidation(&invalidation, |
| 647 base_tiling_size, | 645 base_tiling_size, |
| 648 CornerSinglePixelRect(corner, base_tiling_size)); | 646 CornerSinglePixelRect(corner, base_tiling_size)); |
| 649 | 647 |
| 650 // We should have lost the recordings that are now outside the tiling only. | 648 // We should have lost the recordings that are now outside the tiling only. |
| 651 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 649 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 652 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 650 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 653 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 651 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 654 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 652 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 655 TestPicturePile::PictureMapKey key(i, j); | 653 TestPicturePile::PictureMapKey key(i, j); |
| 656 TestPicturePile::PictureMap& map = pile_->picture_map(); | 654 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 657 TestPicturePile::PictureMap::iterator it = map.find(key); | 655 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 658 EXPECT_EQ(j < 6, it != map.end() && it->second.GetPicture()); | 656 EXPECT_EQ(j < 6, it != map.end() && it->second.GetPicture()); |
| 659 } | 657 } |
| 660 } | 658 } |
| 661 | 659 |
| 662 // No invalidation when shrinking. | 660 // No invalidation when shrinking. |
| 663 expected_invalidation.Clear(); | 661 expected_invalidation.Clear(); |
| 664 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 662 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 665 invalidation.Clear(); | 663 invalidation.Clear(); |
| 666 | 664 |
| 667 UpdateWholePile(); | 665 UpdateWholePile(); |
| 668 UpdateAndExpandInvalidation( | 666 UpdateAndExpandInvalidation( |
| 669 &invalidation, | 667 &invalidation, |
| 670 grow_right_tiling_size, | 668 grow_right_tiling_size, |
| 671 CornerSinglePixelRect(corner, grow_right_tiling_size)); | 669 CornerSinglePixelRect(corner, grow_right_tiling_size)); |
| 672 | 670 |
| 673 // We should have lost the recordings in the right column. | 671 // We should have lost the recordings in the right column. |
| 674 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); | 672 EXPECT_EQ(8, pile_.tiling().num_tiles_x()); |
| 675 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 673 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 676 for (int i = 0; i < 6; ++i) { | 674 for (int i = 0; i < 6; ++i) { |
| 677 for (int j = 0; j < 6; ++j) { | 675 for (int j = 0; j < 6; ++j) { |
| 678 TestPicturePile::PictureMapKey key(i, j); | 676 TestPicturePile::PictureMapKey key(i, j); |
| 679 TestPicturePile::PictureMap& map = pile_->picture_map(); | 677 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 680 TestPicturePile::PictureMap::iterator it = map.find(key); | 678 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 681 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); | 679 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); |
| 682 } | 680 } |
| 683 } | 681 } |
| 684 | 682 |
| 685 // We invalidated all new pixels in the recording. | 683 // We invalidated all new pixels in the recording. |
| 686 expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), | 684 expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), |
| 687 gfx::Rect(base_tiling_size)); | 685 gfx::Rect(base_tiling_size)); |
| 688 // But the new pixels don't cover the whole right_column. | 686 // But the new pixels don't cover the whole right_column. |
| 689 gfx::Rect right_column = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 687 gfx::Rect right_column = gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 690 pile_->tiling().TileBounds(5, 5)); | 688 pile_.tiling().TileBounds(5, 5)); |
| 691 EXPECT_FALSE(expected_invalidation.Contains(right_column)); | 689 EXPECT_FALSE(expected_invalidation.Contains(right_column)); |
| 692 // We invalidated the entire old right column. | 690 // We invalidated the entire old right column. |
| 693 expected_invalidation.Union(right_column); | 691 expected_invalidation.Union(right_column); |
| 694 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 692 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 695 invalidation.Clear(); | 693 invalidation.Clear(); |
| 696 | 694 |
| 697 UpdateWholePile(); | 695 UpdateWholePile(); |
| 698 UpdateAndExpandInvalidation(&invalidation, | 696 UpdateAndExpandInvalidation(&invalidation, |
| 699 base_tiling_size, | 697 base_tiling_size, |
| 700 CornerSinglePixelRect(corner, base_tiling_size)); | 698 CornerSinglePixelRect(corner, base_tiling_size)); |
| 701 | 699 |
| 702 // We should have lost the recordings that are now outside the tiling only. | 700 // We should have lost the recordings that are now outside the tiling only. |
| 703 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 701 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 704 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 702 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 705 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 703 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 706 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 704 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 707 TestPicturePile::PictureMapKey key(i, j); | 705 TestPicturePile::PictureMapKey key(i, j); |
| 708 TestPicturePile::PictureMap& map = pile_->picture_map(); | 706 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 709 TestPicturePile::PictureMap::iterator it = map.find(key); | 707 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 710 EXPECT_EQ(i < 6, it != map.end() && it->second.GetPicture()); | 708 EXPECT_EQ(i < 6, it != map.end() && it->second.GetPicture()); |
| 711 } | 709 } |
| 712 } | 710 } |
| 713 | 711 |
| 714 // No invalidation when shrinking. | 712 // No invalidation when shrinking. |
| 715 expected_invalidation.Clear(); | 713 expected_invalidation.Clear(); |
| 716 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 714 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 717 invalidation.Clear(); | 715 invalidation.Clear(); |
| 718 | 716 |
| 719 UpdateWholePile(); | 717 UpdateWholePile(); |
| 720 UpdateAndExpandInvalidation( | 718 UpdateAndExpandInvalidation( |
| 721 &invalidation, | 719 &invalidation, |
| 722 grow_both_tiling_size, | 720 grow_both_tiling_size, |
| 723 CornerSinglePixelRect(corner, grow_both_tiling_size)); | 721 CornerSinglePixelRect(corner, grow_both_tiling_size)); |
| 724 | 722 |
| 725 // We should have lost the recordings in the right column and bottom row. | 723 // We should have lost the recordings in the right column and bottom row. |
| 726 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); | 724 EXPECT_EQ(8, pile_.tiling().num_tiles_x()); |
| 727 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); | 725 EXPECT_EQ(8, pile_.tiling().num_tiles_y()); |
| 728 for (int i = 0; i < 6; ++i) { | 726 for (int i = 0; i < 6; ++i) { |
| 729 for (int j = 0; j < 6; ++j) { | 727 for (int j = 0; j < 6; ++j) { |
| 730 TestPicturePile::PictureMapKey key(i, j); | 728 TestPicturePile::PictureMapKey key(i, j); |
| 731 TestPicturePile::PictureMap& map = pile_->picture_map(); | 729 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 732 TestPicturePile::PictureMap::iterator it = map.find(key); | 730 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 733 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); | 731 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); |
| 734 } | 732 } |
| 735 } | 733 } |
| 736 | 734 |
| 737 // We invalidated all new pixels in the recording. | 735 // We invalidated all new pixels in the recording. |
| 738 expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), | 736 expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), |
| 739 gfx::Rect(base_tiling_size)); | 737 gfx::Rect(base_tiling_size)); |
| 740 // But the new pixels don't cover the whole right_column. | 738 // But the new pixels don't cover the whole right_column. |
| 741 Region right_column_and_bottom_row = | 739 Region right_column_and_bottom_row = |
| 742 UnionRegions(gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 740 UnionRegions(gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 743 pile_->tiling().TileBounds(5, 5)), | 741 pile_.tiling().TileBounds(5, 5)), |
| 744 gfx::UnionRects(pile_->tiling().TileBounds(0, 5), | 742 gfx::UnionRects(pile_.tiling().TileBounds(0, 5), |
| 745 pile_->tiling().TileBounds(5, 5))); | 743 pile_.tiling().TileBounds(5, 5))); |
| 746 EXPECT_FALSE(expected_invalidation.Contains(right_column_and_bottom_row)); | 744 EXPECT_FALSE(expected_invalidation.Contains(right_column_and_bottom_row)); |
| 747 // We invalidated the entire old right column and the old bottom row. | 745 // We invalidated the entire old right column and the old bottom row. |
| 748 expected_invalidation.Union(right_column_and_bottom_row); | 746 expected_invalidation.Union(right_column_and_bottom_row); |
| 749 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 747 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 750 invalidation.Clear(); | 748 invalidation.Clear(); |
| 751 | 749 |
| 752 UpdateWholePile(); | 750 UpdateWholePile(); |
| 753 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect()); | 751 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect()); |
| 754 | 752 |
| 755 // We should have lost the recordings that are now outside the tiling only. | 753 // We should have lost the recordings that are now outside the tiling only. |
| 756 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 754 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 757 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 755 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 758 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 756 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 759 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 757 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 760 TestPicturePile::PictureMapKey key(i, j); | 758 TestPicturePile::PictureMapKey key(i, j); |
| 761 TestPicturePile::PictureMap& map = pile_->picture_map(); | 759 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 762 TestPicturePile::PictureMap::iterator it = map.find(key); | 760 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 763 EXPECT_EQ(i < 6 && j < 6, it != map.end() && it->second.GetPicture()); | 761 EXPECT_EQ(i < 6 && j < 6, it != map.end() && it->second.GetPicture()); |
| 764 } | 762 } |
| 765 } | 763 } |
| 766 | 764 |
| 767 // No invalidation when shrinking. | 765 // No invalidation when shrinking. |
| 768 expected_invalidation.Clear(); | 766 expected_invalidation.Clear(); |
| 769 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 767 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 770 invalidation.Clear(); | 768 invalidation.Clear(); |
| 771 } | 769 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 783 gfx::Size grow_down_tiling_size(6 * tile_size + offset, | 781 gfx::Size grow_down_tiling_size(6 * tile_size + offset, |
| 784 6 * tile_size + offset + 5); | 782 6 * tile_size + offset + 5); |
| 785 gfx::Size grow_right_tiling_size(6 * tile_size + offset + 5, | 783 gfx::Size grow_right_tiling_size(6 * tile_size + offset + 5, |
| 786 6 * tile_size + offset); | 784 6 * tile_size + offset); |
| 787 gfx::Size grow_both_tiling_size(6 * tile_size + offset + 5, | 785 gfx::Size grow_both_tiling_size(6 * tile_size + offset + 5, |
| 788 6 * tile_size + offset + 5); | 786 6 * tile_size + offset + 5); |
| 789 | 787 |
| 790 Region invalidation; | 788 Region invalidation; |
| 791 Region expected_invalidation; | 789 Region expected_invalidation; |
| 792 | 790 |
| 793 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); | 791 pile_.tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 794 SetTilingSize(base_tiling_size); | 792 SetTilingSize(base_tiling_size); |
| 795 | 793 |
| 796 // We should have a recording for every tile. | 794 // We should have a recording for every tile. |
| 797 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 795 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 798 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 796 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 799 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 797 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 800 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 798 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 801 TestPicturePile::PictureMapKey key(i, j); | 799 TestPicturePile::PictureMapKey key(i, j); |
| 802 TestPicturePile::PictureMap& map = pile_->picture_map(); | 800 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 803 TestPicturePile::PictureMap::iterator it = map.find(key); | 801 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 804 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 802 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 805 } | 803 } |
| 806 } | 804 } |
| 807 | 805 |
| 808 UpdateAndExpandInvalidation( | 806 UpdateAndExpandInvalidation( |
| 809 &invalidation, | 807 &invalidation, |
| 810 grow_down_tiling_size, | 808 grow_down_tiling_size, |
| 811 CornerSinglePixelRect(corner, grow_down_tiling_size)); | 809 CornerSinglePixelRect(corner, grow_down_tiling_size)); |
| 812 | 810 |
| 813 // We should have lost the recordings in the bottom row that do not intersect | 811 // We should have lost the recordings in the bottom row that do not intersect |
| 814 // the interest rect. | 812 // the interest rect. |
| 815 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 813 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 816 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 814 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 817 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 815 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 818 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 816 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 819 TestPicturePile::PictureMapKey key(i, j); | 817 TestPicturePile::PictureMapKey key(i, j); |
| 820 TestPicturePile::PictureMap& map = pile_->picture_map(); | 818 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 821 TestPicturePile::PictureMap::iterator it = map.find(key); | 819 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 822 bool expect_tile; | 820 bool expect_tile; |
| 823 switch (corner) { | 821 switch (corner) { |
| 824 case TOP_LEFT: | 822 case TOP_LEFT: |
| 825 case TOP_RIGHT: | 823 case TOP_RIGHT: |
| 826 expect_tile = j < 5; | 824 expect_tile = j < 5; |
| 827 break; | 825 break; |
| 828 case BOTTOM_LEFT: | 826 case BOTTOM_LEFT: |
| 829 // The interest rect in the bottom left tile means we'll record it. | 827 // The interest rect in the bottom left tile means we'll record it. |
| 830 expect_tile = j < 5 || (j == 5 && i == 0); | 828 expect_tile = j < 5 || (j == 5 && i == 0); |
| 831 break; | 829 break; |
| 832 case BOTTOM_RIGHT: | 830 case BOTTOM_RIGHT: |
| 833 // The interest rect in the bottom right tile means we'll record it. | 831 // The interest rect in the bottom right tile means we'll record it. |
| 834 expect_tile = j < 5 || (j == 5 && i == 5); | 832 expect_tile = j < 5 || (j == 5 && i == 5); |
| 835 break; | 833 break; |
| 836 } | 834 } |
| 837 EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); | 835 EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); |
| 838 } | 836 } |
| 839 } | 837 } |
| 840 | 838 |
| 841 // We invalidated the bottom row outside the new interest rect. The tile that | 839 // We invalidated the bottom row outside the new interest rect. The tile that |
| 842 // insects the interest rect in invalidated only on its new pixels. | 840 // insects the interest rect in invalidated only on its new pixels. |
| 843 switch (corner) { | 841 switch (corner) { |
| 844 case TOP_LEFT: | 842 case TOP_LEFT: |
| 845 case TOP_RIGHT: | 843 case TOP_RIGHT: |
| 846 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), | 844 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(0, 5), |
| 847 pile_->tiling().TileBounds(5, 5)); | 845 pile_.tiling().TileBounds(5, 5)); |
| 848 break; | 846 break; |
| 849 case BOTTOM_LEFT: | 847 case BOTTOM_LEFT: |
| 850 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(1, 5), | 848 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(1, 5), |
| 851 pile_->tiling().TileBounds(5, 5)); | 849 pile_.tiling().TileBounds(5, 5)); |
| 852 expected_invalidation.Union(SubtractRects( | 850 expected_invalidation.Union(SubtractRects(pile_.tiling().TileBounds(0, 5), |
| 853 pile_->tiling().TileBounds(0, 5), gfx::Rect(base_tiling_size))); | 851 gfx::Rect(base_tiling_size))); |
| 854 break; | 852 break; |
| 855 case BOTTOM_RIGHT: | 853 case BOTTOM_RIGHT: |
| 856 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), | 854 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(0, 5), |
| 857 pile_->tiling().TileBounds(4, 5)); | 855 pile_.tiling().TileBounds(4, 5)); |
| 858 expected_invalidation.Union(SubtractRects( | 856 expected_invalidation.Union(SubtractRects(pile_.tiling().TileBounds(5, 5), |
| 859 pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); | 857 gfx::Rect(base_tiling_size))); |
| 860 break; | 858 break; |
| 861 } | 859 } |
| 862 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 860 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 863 invalidation.Clear(); | 861 invalidation.Clear(); |
| 864 | 862 |
| 865 UpdateWholePile(); | 863 UpdateWholePile(); |
| 866 UpdateAndExpandInvalidation(&invalidation, | 864 UpdateAndExpandInvalidation(&invalidation, |
| 867 base_tiling_size, | 865 base_tiling_size, |
| 868 CornerSinglePixelRect(corner, base_tiling_size)); | 866 CornerSinglePixelRect(corner, base_tiling_size)); |
| 869 | 867 |
| 870 // We should have lost nothing. | 868 // We should have lost nothing. |
| 871 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 869 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 872 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 870 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 873 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 871 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 874 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 872 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 875 TestPicturePile::PictureMapKey key(i, j); | 873 TestPicturePile::PictureMapKey key(i, j); |
| 876 TestPicturePile::PictureMap& map = pile_->picture_map(); | 874 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 877 TestPicturePile::PictureMap::iterator it = map.find(key); | 875 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 878 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 876 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 879 } | 877 } |
| 880 } | 878 } |
| 881 | 879 |
| 882 // We invalidated nothing. | 880 // We invalidated nothing. |
| 883 expected_invalidation.Clear(); | 881 expected_invalidation.Clear(); |
| 884 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 882 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 885 invalidation.Clear(); | 883 invalidation.Clear(); |
| 886 | 884 |
| 887 UpdateWholePile(); | 885 UpdateWholePile(); |
| 888 UpdateAndExpandInvalidation( | 886 UpdateAndExpandInvalidation( |
| 889 &invalidation, | 887 &invalidation, |
| 890 grow_right_tiling_size, | 888 grow_right_tiling_size, |
| 891 CornerSinglePixelRect(corner, grow_right_tiling_size)); | 889 CornerSinglePixelRect(corner, grow_right_tiling_size)); |
| 892 | 890 |
| 893 // We should have lost the recordings in the right column. | 891 // We should have lost the recordings in the right column. |
| 894 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 892 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 895 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 893 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 896 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 894 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 897 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 895 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 898 TestPicturePile::PictureMapKey key(i, j); | 896 TestPicturePile::PictureMapKey key(i, j); |
| 899 TestPicturePile::PictureMap& map = pile_->picture_map(); | 897 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 900 TestPicturePile::PictureMap::iterator it = map.find(key); | 898 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 901 bool expect_tile; | 899 bool expect_tile; |
| 902 switch (corner) { | 900 switch (corner) { |
| 903 case TOP_LEFT: | 901 case TOP_LEFT: |
| 904 case BOTTOM_LEFT: | 902 case BOTTOM_LEFT: |
| 905 expect_tile = i < 5; | 903 expect_tile = i < 5; |
| 906 break; | 904 break; |
| 907 case TOP_RIGHT: | 905 case TOP_RIGHT: |
| 908 // The interest rect in the top right tile means we'll record it. | 906 // The interest rect in the top right tile means we'll record it. |
| 909 expect_tile = i < 5 || (j == 0 && i == 5); | 907 expect_tile = i < 5 || (j == 0 && i == 5); |
| 910 break; | 908 break; |
| 911 case BOTTOM_RIGHT: | 909 case BOTTOM_RIGHT: |
| 912 // The interest rect in the bottom right tile means we'll record it. | 910 // The interest rect in the bottom right tile means we'll record it. |
| 913 expect_tile = i < 5 || (j == 5 && i == 5); | 911 expect_tile = i < 5 || (j == 5 && i == 5); |
| 914 break; | 912 break; |
| 915 } | 913 } |
| 916 EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); | 914 EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); |
| 917 } | 915 } |
| 918 } | 916 } |
| 919 | 917 |
| 920 // We invalidated the right column outside the new interest rect. The tile | 918 // We invalidated the right column outside the new interest rect. The tile |
| 921 // that insects the interest rect in invalidated only on its new pixels. | 919 // that insects the interest rect in invalidated only on its new pixels. |
| 922 switch (corner) { | 920 switch (corner) { |
| 923 case TOP_LEFT: | 921 case TOP_LEFT: |
| 924 case BOTTOM_LEFT: | 922 case BOTTOM_LEFT: |
| 925 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 923 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 926 pile_->tiling().TileBounds(5, 5)); | 924 pile_.tiling().TileBounds(5, 5)); |
| 927 break; | 925 break; |
| 928 case TOP_RIGHT: | 926 case TOP_RIGHT: |
| 929 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 1), | 927 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(5, 1), |
| 930 pile_->tiling().TileBounds(5, 5)); | 928 pile_.tiling().TileBounds(5, 5)); |
| 931 expected_invalidation.Union(SubtractRects( | 929 expected_invalidation.Union(SubtractRects(pile_.tiling().TileBounds(5, 0), |
| 932 pile_->tiling().TileBounds(5, 0), gfx::Rect(base_tiling_size))); | 930 gfx::Rect(base_tiling_size))); |
| 933 break; | 931 break; |
| 934 case BOTTOM_RIGHT: | 932 case BOTTOM_RIGHT: |
| 935 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 933 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 936 pile_->tiling().TileBounds(5, 4)); | 934 pile_.tiling().TileBounds(5, 4)); |
| 937 expected_invalidation.Union(SubtractRects( | 935 expected_invalidation.Union(SubtractRects(pile_.tiling().TileBounds(5, 5), |
| 938 pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); | 936 gfx::Rect(base_tiling_size))); |
| 939 break; | 937 break; |
| 940 } | 938 } |
| 941 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 939 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 942 invalidation.Clear(); | 940 invalidation.Clear(); |
| 943 | 941 |
| 944 UpdateWholePile(); | 942 UpdateWholePile(); |
| 945 UpdateAndExpandInvalidation(&invalidation, | 943 UpdateAndExpandInvalidation(&invalidation, |
| 946 base_tiling_size, | 944 base_tiling_size, |
| 947 CornerSinglePixelRect(corner, base_tiling_size)); | 945 CornerSinglePixelRect(corner, base_tiling_size)); |
| 948 | 946 |
| 949 // We should have lost nothing. | 947 // We should have lost nothing. |
| 950 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 948 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 951 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 949 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 952 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 950 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 953 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 951 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 954 TestPicturePile::PictureMapKey key(i, j); | 952 TestPicturePile::PictureMapKey key(i, j); |
| 955 TestPicturePile::PictureMap& map = pile_->picture_map(); | 953 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 956 TestPicturePile::PictureMap::iterator it = map.find(key); | 954 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 957 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 955 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 958 } | 956 } |
| 959 } | 957 } |
| 960 | 958 |
| 961 // We invalidated nothing. | 959 // We invalidated nothing. |
| 962 expected_invalidation.Clear(); | 960 expected_invalidation.Clear(); |
| 963 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 961 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 964 invalidation.Clear(); | 962 invalidation.Clear(); |
| 965 | 963 |
| 966 UpdateWholePile(); | 964 UpdateWholePile(); |
| 967 UpdateAndExpandInvalidation( | 965 UpdateAndExpandInvalidation( |
| 968 &invalidation, | 966 &invalidation, |
| 969 grow_both_tiling_size, | 967 grow_both_tiling_size, |
| 970 CornerSinglePixelRect(corner, grow_both_tiling_size)); | 968 CornerSinglePixelRect(corner, grow_both_tiling_size)); |
| 971 | 969 |
| 972 // We should have lost the recordings in the right column and bottom row. The | 970 // We should have lost the recordings in the right column and bottom row. The |
| 973 // tile that insects the interest rect in invalidated only on its new pixels. | 971 // tile that insects the interest rect in invalidated only on its new pixels. |
| 974 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 972 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 975 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 973 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 976 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 974 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 977 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 975 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 978 TestPicturePile::PictureMapKey key(i, j); | 976 TestPicturePile::PictureMapKey key(i, j); |
| 979 TestPicturePile::PictureMap& map = pile_->picture_map(); | 977 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 980 TestPicturePile::PictureMap::iterator it = map.find(key); | 978 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 981 bool expect_tile; | 979 bool expect_tile; |
| 982 switch (corner) { | 980 switch (corner) { |
| 983 case TOP_LEFT: | 981 case TOP_LEFT: |
| 984 expect_tile = i < 5 && j < 5; | 982 expect_tile = i < 5 && j < 5; |
| 985 break; | 983 break; |
| 986 case TOP_RIGHT: | 984 case TOP_RIGHT: |
| 987 // The interest rect in the top right tile means we'll record it. | 985 // The interest rect in the top right tile means we'll record it. |
| 988 expect_tile = (i < 5 && j < 5) || (j == 0 && i == 5); | 986 expect_tile = (i < 5 && j < 5) || (j == 0 && i == 5); |
| 989 break; | 987 break; |
| 990 case BOTTOM_LEFT: | 988 case BOTTOM_LEFT: |
| 991 // The interest rect in the bottom left tile means we'll record it. | 989 // The interest rect in the bottom left tile means we'll record it. |
| 992 expect_tile = (i < 5 && j < 5) || (j == 5 && i == 0); | 990 expect_tile = (i < 5 && j < 5) || (j == 5 && i == 0); |
| 993 break; | 991 break; |
| 994 case BOTTOM_RIGHT: | 992 case BOTTOM_RIGHT: |
| 995 // The interest rect in the bottom right tile means we'll record it. | 993 // The interest rect in the bottom right tile means we'll record it. |
| 996 expect_tile = (i < 5 && j < 5) || (j == 5 && i == 5); | 994 expect_tile = (i < 5 && j < 5) || (j == 5 && i == 5); |
| 997 break; | 995 break; |
| 998 } | 996 } |
| 999 EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()) | 997 EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()) |
| 1000 << i << "," << j; | 998 << i << "," << j; |
| 1001 } | 999 } |
| 1002 } | 1000 } |
| 1003 | 1001 |
| 1004 // We invalidated the right column and the bottom row outside the new interest | 1002 // We invalidated the right column and the bottom row outside the new interest |
| 1005 // rect. The tile that insects the interest rect in invalidated only on its | 1003 // rect. The tile that insects the interest rect in invalidated only on its |
| 1006 // new pixels. | 1004 // new pixels. |
| 1007 switch (corner) { | 1005 switch (corner) { |
| 1008 case TOP_LEFT: | 1006 case TOP_LEFT: |
| 1009 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 1007 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 1010 pile_->tiling().TileBounds(5, 5)); | 1008 pile_.tiling().TileBounds(5, 5)); |
| 1011 expected_invalidation.Union(gfx::UnionRects( | 1009 expected_invalidation.Union(gfx::UnionRects( |
| 1012 pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5))); | 1010 pile_.tiling().TileBounds(0, 5), pile_.tiling().TileBounds(5, 5))); |
| 1013 break; | 1011 break; |
| 1014 case TOP_RIGHT: | 1012 case TOP_RIGHT: |
| 1015 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 1), | 1013 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(5, 1), |
| 1016 pile_->tiling().TileBounds(5, 5)); | 1014 pile_.tiling().TileBounds(5, 5)); |
| 1017 expected_invalidation.Union(gfx::UnionRects( | 1015 expected_invalidation.Union(gfx::UnionRects( |
| 1018 pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5))); | 1016 pile_.tiling().TileBounds(0, 5), pile_.tiling().TileBounds(5, 5))); |
| 1019 expected_invalidation.Union(SubtractRects( | 1017 expected_invalidation.Union(SubtractRects(pile_.tiling().TileBounds(5, 0), |
| 1020 pile_->tiling().TileBounds(5, 0), gfx::Rect(base_tiling_size))); | 1018 gfx::Rect(base_tiling_size))); |
| 1021 break; | 1019 break; |
| 1022 case BOTTOM_LEFT: | 1020 case BOTTOM_LEFT: |
| 1023 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 1021 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 1024 pile_->tiling().TileBounds(5, 5)); | 1022 pile_.tiling().TileBounds(5, 5)); |
| 1025 expected_invalidation.Union(gfx::UnionRects( | 1023 expected_invalidation.Union(gfx::UnionRects( |
| 1026 pile_->tiling().TileBounds(1, 5), pile_->tiling().TileBounds(5, 5))); | 1024 pile_.tiling().TileBounds(1, 5), pile_.tiling().TileBounds(5, 5))); |
| 1027 expected_invalidation.Union(SubtractRects( | 1025 expected_invalidation.Union(SubtractRects(pile_.tiling().TileBounds(0, 5), |
| 1028 pile_->tiling().TileBounds(0, 5), gfx::Rect(base_tiling_size))); | 1026 gfx::Rect(base_tiling_size))); |
| 1029 break; | 1027 break; |
| 1030 case BOTTOM_RIGHT: | 1028 case BOTTOM_RIGHT: |
| 1031 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 1029 expected_invalidation = gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 1032 pile_->tiling().TileBounds(5, 4)); | 1030 pile_.tiling().TileBounds(5, 4)); |
| 1033 expected_invalidation.Union(gfx::UnionRects( | 1031 expected_invalidation.Union(gfx::UnionRects( |
| 1034 pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(4, 5))); | 1032 pile_.tiling().TileBounds(0, 5), pile_.tiling().TileBounds(4, 5))); |
| 1035 expected_invalidation.Union(SubtractRegions( | 1033 expected_invalidation.Union(SubtractRegions( |
| 1036 pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); | 1034 pile_.tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); |
| 1037 break; | 1035 break; |
| 1038 } | 1036 } |
| 1039 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 1037 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 1040 invalidation.Clear(); | 1038 invalidation.Clear(); |
| 1041 | 1039 |
| 1042 UpdateWholePile(); | 1040 UpdateWholePile(); |
| 1043 UpdateAndExpandInvalidation(&invalidation, | 1041 UpdateAndExpandInvalidation(&invalidation, |
| 1044 base_tiling_size, | 1042 base_tiling_size, |
| 1045 CornerSinglePixelRect(corner, base_tiling_size)); | 1043 CornerSinglePixelRect(corner, base_tiling_size)); |
| 1046 | 1044 |
| 1047 // We should have lost nothing. | 1045 // We should have lost nothing. |
| 1048 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1046 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1049 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1047 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1050 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1048 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1051 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1049 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1052 TestPicturePile::PictureMapKey key(i, j); | 1050 TestPicturePile::PictureMapKey key(i, j); |
| 1053 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1051 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1054 TestPicturePile::PictureMap::iterator it = map.find(key); | 1052 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1055 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1053 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1056 } | 1054 } |
| 1057 } | 1055 } |
| 1058 | 1056 |
| 1059 // We invalidated nothing. | 1057 // We invalidated nothing. |
| 1060 expected_invalidation.Clear(); | 1058 expected_invalidation.Clear(); |
| 1061 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 1059 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 1062 invalidation.Clear(); | 1060 invalidation.Clear(); |
| 1063 } | 1061 } |
| 1064 | 1062 |
| 1065 INSTANTIATE_TEST_CASE_P( | 1063 INSTANTIATE_TEST_CASE_P( |
| 1066 PicturePileResizeCornerTests, | 1064 PicturePileResizeCornerTests, |
| 1067 PicturePileResizeCornerTest, | 1065 PicturePileResizeCornerTest, |
| 1068 ::testing::Values(TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT)); | 1066 ::testing::Values(TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT)); |
| 1069 | 1067 |
| 1070 TEST_F(PicturePileTest, ResizePileInsideInterestRect) { | 1068 TEST_F(PicturePileTest, ResizePileInsideInterestRect) { |
| 1071 // This size chosen to be small enough that all the rects below fit inside the | 1069 // This size chosen to be small enough that all the rects below fit inside the |
| 1072 // the interest rect, so they are smaller than kPixelDistanceToRecord in each | 1070 // the interest rect, so they are smaller than kPixelDistanceToRecord in each |
| 1073 // dimension. | 1071 // dimension. |
| 1074 int tile_size = 100; | 1072 int tile_size = 100; |
| 1075 gfx::Size base_tiling_size(5 * tile_size, 5 * tile_size); | 1073 gfx::Size base_tiling_size(5 * tile_size, 5 * tile_size); |
| 1076 gfx::Size grow_down_tiling_size(5 * tile_size, 7 * tile_size); | 1074 gfx::Size grow_down_tiling_size(5 * tile_size, 7 * tile_size); |
| 1077 gfx::Size grow_right_tiling_size(7 * tile_size, 5 * tile_size); | 1075 gfx::Size grow_right_tiling_size(7 * tile_size, 5 * tile_size); |
| 1078 gfx::Size grow_both_tiling_size(7 * tile_size, 7 * tile_size); | 1076 gfx::Size grow_both_tiling_size(7 * tile_size, 7 * tile_size); |
| 1079 | 1077 |
| 1080 Region invalidation; | 1078 Region invalidation; |
| 1081 Region expected_invalidation; | 1079 Region expected_invalidation; |
| 1082 | 1080 |
| 1083 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); | 1081 pile_.tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 1084 SetTilingSize(base_tiling_size); | 1082 SetTilingSize(base_tiling_size); |
| 1085 | 1083 |
| 1086 // We should have a recording for every tile. | 1084 // We should have a recording for every tile. |
| 1087 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1085 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1088 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1086 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1089 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1087 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1090 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1088 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1091 TestPicturePile::PictureMapKey key(i, j); | 1089 TestPicturePile::PictureMapKey key(i, j); |
| 1092 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1090 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1093 TestPicturePile::PictureMap::iterator it = map.find(key); | 1091 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1094 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1092 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1095 } | 1093 } |
| 1096 } | 1094 } |
| 1097 | 1095 |
| 1098 UpdateAndExpandInvalidation( | 1096 UpdateAndExpandInvalidation( |
| 1099 &invalidation, grow_down_tiling_size, gfx::Rect(1, 1)); | 1097 &invalidation, grow_down_tiling_size, gfx::Rect(1, 1)); |
| 1100 | 1098 |
| 1101 // We should have a recording for every tile. | 1099 // We should have a recording for every tile. |
| 1102 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1100 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1103 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); | 1101 EXPECT_EQ(8, pile_.tiling().num_tiles_y()); |
| 1104 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1102 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1105 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1103 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1106 TestPicturePile::PictureMapKey key(i, j); | 1104 TestPicturePile::PictureMapKey key(i, j); |
| 1107 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1105 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1108 TestPicturePile::PictureMap::iterator it = map.find(key); | 1106 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1109 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1107 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1110 } | 1108 } |
| 1111 } | 1109 } |
| 1112 | 1110 |
| 1113 // We invalidated the newly exposed pixels on the bottom row of tiles. | 1111 // We invalidated the newly exposed pixels on the bottom row of tiles. |
| 1114 expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), | 1112 expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), |
| 1115 gfx::Rect(base_tiling_size)); | 1113 gfx::Rect(base_tiling_size)); |
| 1116 Region bottom_row_new_pixels = | 1114 Region bottom_row_new_pixels = |
| 1117 SubtractRegions(gfx::UnionRects(pile_->tiling().TileBounds(0, 5), | 1115 SubtractRegions(gfx::UnionRects(pile_.tiling().TileBounds(0, 5), |
| 1118 pile_->tiling().TileBounds(5, 5)), | 1116 pile_.tiling().TileBounds(5, 5)), |
| 1119 gfx::Rect(base_tiling_size)); | 1117 gfx::Rect(base_tiling_size)); |
| 1120 EXPECT_TRUE(expected_invalidation.Contains(bottom_row_new_pixels)); | 1118 EXPECT_TRUE(expected_invalidation.Contains(bottom_row_new_pixels)); |
| 1121 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 1119 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 1122 invalidation.Clear(); | 1120 invalidation.Clear(); |
| 1123 | 1121 |
| 1124 UpdateWholePile(); | 1122 UpdateWholePile(); |
| 1125 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect(1, 1)); | 1123 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect(1, 1)); |
| 1126 | 1124 |
| 1127 // We should have a recording for every tile. | 1125 // We should have a recording for every tile. |
| 1128 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1126 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1129 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1127 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1130 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1128 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1131 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1129 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1132 TestPicturePile::PictureMapKey key(i, j); | 1130 TestPicturePile::PictureMapKey key(i, j); |
| 1133 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1131 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1134 TestPicturePile::PictureMap::iterator it = map.find(key); | 1132 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1135 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1133 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1136 } | 1134 } |
| 1137 } | 1135 } |
| 1138 | 1136 |
| 1139 // No invalidation when shrinking. | 1137 // No invalidation when shrinking. |
| 1140 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1138 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 1141 invalidation.Clear(); | 1139 invalidation.Clear(); |
| 1142 | 1140 |
| 1143 UpdateWholePile(); | 1141 UpdateWholePile(); |
| 1144 UpdateAndExpandInvalidation( | 1142 UpdateAndExpandInvalidation( |
| 1145 &invalidation, grow_right_tiling_size, gfx::Rect(1, 1)); | 1143 &invalidation, grow_right_tiling_size, gfx::Rect(1, 1)); |
| 1146 | 1144 |
| 1147 // We should have a recording for every tile. | 1145 // We should have a recording for every tile. |
| 1148 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); | 1146 EXPECT_EQ(8, pile_.tiling().num_tiles_x()); |
| 1149 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1147 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1150 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1148 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1151 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1149 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1152 TestPicturePile::PictureMapKey key(i, j); | 1150 TestPicturePile::PictureMapKey key(i, j); |
| 1153 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1151 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1154 TestPicturePile::PictureMap::iterator it = map.find(key); | 1152 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1155 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1153 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1156 } | 1154 } |
| 1157 } | 1155 } |
| 1158 | 1156 |
| 1159 // We invalidated the newly exposed pixels on the right column of tiles. | 1157 // We invalidated the newly exposed pixels on the right column of tiles. |
| 1160 expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), | 1158 expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), |
| 1161 gfx::Rect(base_tiling_size)); | 1159 gfx::Rect(base_tiling_size)); |
| 1162 Region right_column_new_pixels = | 1160 Region right_column_new_pixels = |
| 1163 SubtractRegions(gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 1161 SubtractRegions(gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 1164 pile_->tiling().TileBounds(5, 5)), | 1162 pile_.tiling().TileBounds(5, 5)), |
| 1165 gfx::Rect(base_tiling_size)); | 1163 gfx::Rect(base_tiling_size)); |
| 1166 EXPECT_TRUE(expected_invalidation.Contains(right_column_new_pixels)); | 1164 EXPECT_TRUE(expected_invalidation.Contains(right_column_new_pixels)); |
| 1167 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 1165 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 1168 invalidation.Clear(); | 1166 invalidation.Clear(); |
| 1169 | 1167 |
| 1170 UpdateWholePile(); | 1168 UpdateWholePile(); |
| 1171 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect(1, 1)); | 1169 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect(1, 1)); |
| 1172 | 1170 |
| 1173 // We should have lost the recordings that are now outside the tiling only. | 1171 // We should have lost the recordings that are now outside the tiling only. |
| 1174 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1172 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1175 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1173 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1176 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1174 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1177 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1175 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1178 TestPicturePile::PictureMapKey key(i, j); | 1176 TestPicturePile::PictureMapKey key(i, j); |
| 1179 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1177 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1180 TestPicturePile::PictureMap::iterator it = map.find(key); | 1178 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1181 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1179 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1182 } | 1180 } |
| 1183 } | 1181 } |
| 1184 | 1182 |
| 1185 // No invalidation when shrinking. | 1183 // No invalidation when shrinking. |
| 1186 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1184 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 1187 invalidation.Clear(); | 1185 invalidation.Clear(); |
| 1188 | 1186 |
| 1189 UpdateWholePile(); | 1187 UpdateWholePile(); |
| 1190 UpdateAndExpandInvalidation( | 1188 UpdateAndExpandInvalidation( |
| 1191 &invalidation, grow_both_tiling_size, gfx::Rect(1, 1)); | 1189 &invalidation, grow_both_tiling_size, gfx::Rect(1, 1)); |
| 1192 | 1190 |
| 1193 // We should have a recording for every tile. | 1191 // We should have a recording for every tile. |
| 1194 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); | 1192 EXPECT_EQ(8, pile_.tiling().num_tiles_x()); |
| 1195 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); | 1193 EXPECT_EQ(8, pile_.tiling().num_tiles_y()); |
| 1196 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1194 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1197 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1195 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1198 TestPicturePile::PictureMapKey key(i, j); | 1196 TestPicturePile::PictureMapKey key(i, j); |
| 1199 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1197 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1200 TestPicturePile::PictureMap::iterator it = map.find(key); | 1198 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1201 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1199 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1202 } | 1200 } |
| 1203 } | 1201 } |
| 1204 | 1202 |
| 1205 // We invalidated the newly exposed pixels on the bottom row and right column | 1203 // We invalidated the newly exposed pixels on the bottom row and right column |
| 1206 // of tiles. | 1204 // of tiles. |
| 1207 expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), | 1205 expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), |
| 1208 gfx::Rect(base_tiling_size)); | 1206 gfx::Rect(base_tiling_size)); |
| 1209 Region bottom_row_and_right_column_new_pixels = SubtractRegions( | 1207 Region bottom_row_and_right_column_new_pixels = SubtractRegions( |
| 1210 UnionRegions(gfx::UnionRects(pile_->tiling().TileBounds(0, 5), | 1208 UnionRegions(gfx::UnionRects(pile_.tiling().TileBounds(0, 5), |
| 1211 pile_->tiling().TileBounds(5, 5)), | 1209 pile_.tiling().TileBounds(5, 5)), |
| 1212 gfx::UnionRects(pile_->tiling().TileBounds(5, 0), | 1210 gfx::UnionRects(pile_.tiling().TileBounds(5, 0), |
| 1213 pile_->tiling().TileBounds(5, 5))), | 1211 pile_.tiling().TileBounds(5, 5))), |
| 1214 gfx::Rect(base_tiling_size)); | 1212 gfx::Rect(base_tiling_size)); |
| 1215 EXPECT_TRUE( | 1213 EXPECT_TRUE( |
| 1216 expected_invalidation.Contains(bottom_row_and_right_column_new_pixels)); | 1214 expected_invalidation.Contains(bottom_row_and_right_column_new_pixels)); |
| 1217 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 1215 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 1218 invalidation.Clear(); | 1216 invalidation.Clear(); |
| 1219 | 1217 |
| 1220 UpdateWholePile(); | 1218 UpdateWholePile(); |
| 1221 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect()); | 1219 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect()); |
| 1222 | 1220 |
| 1223 // We should have lost the recordings that are now outside the tiling only. | 1221 // We should have lost the recordings that are now outside the tiling only. |
| 1224 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1222 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1225 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1223 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1226 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1224 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1227 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1225 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1228 TestPicturePile::PictureMapKey key(i, j); | 1226 TestPicturePile::PictureMapKey key(i, j); |
| 1229 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1227 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1230 TestPicturePile::PictureMap::iterator it = map.find(key); | 1228 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1231 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1229 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1232 } | 1230 } |
| 1233 } | 1231 } |
| 1234 | 1232 |
| 1235 // No invalidation when shrinking. | 1233 // No invalidation when shrinking. |
| 1236 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1234 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 1237 invalidation.Clear(); | 1235 invalidation.Clear(); |
| 1238 } | 1236 } |
| 1239 | 1237 |
| 1240 TEST_F(PicturePileTest, SmallResizePileInsideInterestRect) { | 1238 TEST_F(PicturePileTest, SmallResizePileInsideInterestRect) { |
| 1241 // This size chosen to be small enough that all the rects below fit inside the | 1239 // This size chosen to be small enough that all the rects below fit inside the |
| 1242 // the interest rect, so they are smaller than kPixelDistanceToRecord in each | 1240 // the interest rect, so they are smaller than kPixelDistanceToRecord in each |
| 1243 // dimension. | 1241 // dimension. |
| 1244 int tile_size = 100; | 1242 int tile_size = 100; |
| 1245 gfx::Size base_tiling_size(5 * tile_size, 5 * tile_size); | 1243 gfx::Size base_tiling_size(5 * tile_size, 5 * tile_size); |
| 1246 gfx::Size grow_down_tiling_size(5 * tile_size, 5 * tile_size + 5); | 1244 gfx::Size grow_down_tiling_size(5 * tile_size, 5 * tile_size + 5); |
| 1247 gfx::Size grow_right_tiling_size(5 * tile_size + 5, 5 * tile_size); | 1245 gfx::Size grow_right_tiling_size(5 * tile_size + 5, 5 * tile_size); |
| 1248 gfx::Size grow_both_tiling_size(5 * tile_size + 5, 5 * tile_size + 5); | 1246 gfx::Size grow_both_tiling_size(5 * tile_size + 5, 5 * tile_size + 5); |
| 1249 | 1247 |
| 1250 Region invalidation; | 1248 Region invalidation; |
| 1251 Region expected_invalidation; | 1249 Region expected_invalidation; |
| 1252 | 1250 |
| 1253 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); | 1251 pile_.tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 1254 SetTilingSize(base_tiling_size); | 1252 SetTilingSize(base_tiling_size); |
| 1255 | 1253 |
| 1256 // We should have a recording for every tile. | 1254 // We should have a recording for every tile. |
| 1257 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1255 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1258 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1256 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1259 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1257 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1260 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1258 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1261 TestPicturePile::PictureMapKey key(i, j); | 1259 TestPicturePile::PictureMapKey key(i, j); |
| 1262 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1260 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1263 TestPicturePile::PictureMap::iterator it = map.find(key); | 1261 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1264 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1262 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1265 } | 1263 } |
| 1266 } | 1264 } |
| 1267 | 1265 |
| 1268 UpdateAndExpandInvalidation( | 1266 UpdateAndExpandInvalidation( |
| 1269 &invalidation, grow_down_tiling_size, gfx::Rect(1, 1)); | 1267 &invalidation, grow_down_tiling_size, gfx::Rect(1, 1)); |
| 1270 | 1268 |
| 1271 // We should have a recording for every tile. | 1269 // We should have a recording for every tile. |
| 1272 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1270 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1273 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1271 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1274 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1272 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1275 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1273 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1276 TestPicturePile::PictureMapKey key(i, j); | 1274 TestPicturePile::PictureMapKey key(i, j); |
| 1277 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1275 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1278 TestPicturePile::PictureMap::iterator it = map.find(key); | 1276 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1279 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1277 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1280 } | 1278 } |
| 1281 } | 1279 } |
| 1282 | 1280 |
| 1283 // We invalidated the newly exposed pixels. | 1281 // We invalidated the newly exposed pixels. |
| 1284 expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), | 1282 expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), |
| 1285 gfx::Rect(base_tiling_size)); | 1283 gfx::Rect(base_tiling_size)); |
| 1286 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 1284 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 1287 invalidation.Clear(); | 1285 invalidation.Clear(); |
| 1288 | 1286 |
| 1289 UpdateWholePile(); | 1287 UpdateWholePile(); |
| 1290 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect(1, 1)); | 1288 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect(1, 1)); |
| 1291 | 1289 |
| 1292 // We should have a recording for every tile. | 1290 // We should have a recording for every tile. |
| 1293 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1291 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1294 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1292 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1295 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1293 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1296 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1294 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1297 TestPicturePile::PictureMapKey key(i, j); | 1295 TestPicturePile::PictureMapKey key(i, j); |
| 1298 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1296 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1299 TestPicturePile::PictureMap::iterator it = map.find(key); | 1297 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1300 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1298 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1301 } | 1299 } |
| 1302 } | 1300 } |
| 1303 | 1301 |
| 1304 // No invalidation when shrinking. | 1302 // No invalidation when shrinking. |
| 1305 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1303 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 1306 invalidation.Clear(); | 1304 invalidation.Clear(); |
| 1307 | 1305 |
| 1308 UpdateWholePile(); | 1306 UpdateWholePile(); |
| 1309 UpdateAndExpandInvalidation( | 1307 UpdateAndExpandInvalidation( |
| 1310 &invalidation, grow_right_tiling_size, gfx::Rect(1, 1)); | 1308 &invalidation, grow_right_tiling_size, gfx::Rect(1, 1)); |
| 1311 | 1309 |
| 1312 // We should have a recording for every tile. | 1310 // We should have a recording for every tile. |
| 1313 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1311 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1314 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1312 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1315 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1313 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1316 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1314 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1317 TestPicturePile::PictureMapKey key(i, j); | 1315 TestPicturePile::PictureMapKey key(i, j); |
| 1318 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1316 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1319 TestPicturePile::PictureMap::iterator it = map.find(key); | 1317 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1320 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1318 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1321 } | 1319 } |
| 1322 } | 1320 } |
| 1323 | 1321 |
| 1324 // We invalidated the newly exposed pixels. | 1322 // We invalidated the newly exposed pixels. |
| 1325 expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), | 1323 expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), |
| 1326 gfx::Rect(base_tiling_size)); | 1324 gfx::Rect(base_tiling_size)); |
| 1327 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 1325 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 1328 invalidation.Clear(); | 1326 invalidation.Clear(); |
| 1329 | 1327 |
| 1330 UpdateWholePile(); | 1328 UpdateWholePile(); |
| 1331 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect(1, 1)); | 1329 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect(1, 1)); |
| 1332 | 1330 |
| 1333 // We should have lost the recordings that are now outside the tiling only. | 1331 // We should have lost the recordings that are now outside the tiling only. |
| 1334 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1332 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1335 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1333 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1336 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1334 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1337 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1335 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1338 TestPicturePile::PictureMapKey key(i, j); | 1336 TestPicturePile::PictureMapKey key(i, j); |
| 1339 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1337 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1340 TestPicturePile::PictureMap::iterator it = map.find(key); | 1338 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1341 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1339 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1342 } | 1340 } |
| 1343 } | 1341 } |
| 1344 | 1342 |
| 1345 // No invalidation when shrinking. | 1343 // No invalidation when shrinking. |
| 1346 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1344 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 1347 invalidation.Clear(); | 1345 invalidation.Clear(); |
| 1348 | 1346 |
| 1349 UpdateWholePile(); | 1347 UpdateWholePile(); |
| 1350 UpdateAndExpandInvalidation( | 1348 UpdateAndExpandInvalidation( |
| 1351 &invalidation, grow_both_tiling_size, gfx::Rect(1, 1)); | 1349 &invalidation, grow_both_tiling_size, gfx::Rect(1, 1)); |
| 1352 | 1350 |
| 1353 // We should have a recording for every tile. | 1351 // We should have a recording for every tile. |
| 1354 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1352 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1355 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1353 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1356 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1354 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1357 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1355 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1358 TestPicturePile::PictureMapKey key(i, j); | 1356 TestPicturePile::PictureMapKey key(i, j); |
| 1359 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1357 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1360 TestPicturePile::PictureMap::iterator it = map.find(key); | 1358 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1361 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1359 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1362 } | 1360 } |
| 1363 } | 1361 } |
| 1364 | 1362 |
| 1365 // We invalidated the newly exposed pixels. | 1363 // We invalidated the newly exposed pixels. |
| 1366 expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), | 1364 expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), |
| 1367 gfx::Rect(base_tiling_size)); | 1365 gfx::Rect(base_tiling_size)); |
| 1368 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 1366 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 1369 invalidation.Clear(); | 1367 invalidation.Clear(); |
| 1370 | 1368 |
| 1371 UpdateWholePile(); | 1369 UpdateWholePile(); |
| 1372 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect()); | 1370 UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect()); |
| 1373 | 1371 |
| 1374 // We should have lost the recordings that are now outside the tiling only. | 1372 // We should have lost the recordings that are now outside the tiling only. |
| 1375 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 1373 EXPECT_EQ(6, pile_.tiling().num_tiles_x()); |
| 1376 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 1374 EXPECT_EQ(6, pile_.tiling().num_tiles_y()); |
| 1377 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 1375 for (int i = 0; i < pile_.tiling().num_tiles_x(); ++i) { |
| 1378 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 1376 for (int j = 0; j < pile_.tiling().num_tiles_y(); ++j) { |
| 1379 TestPicturePile::PictureMapKey key(i, j); | 1377 TestPicturePile::PictureMapKey key(i, j); |
| 1380 TestPicturePile::PictureMap& map = pile_->picture_map(); | 1378 TestPicturePile::PictureMap& map = pile_.picture_map(); |
| 1381 TestPicturePile::PictureMap::iterator it = map.find(key); | 1379 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 1382 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1380 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 1383 } | 1381 } |
| 1384 } | 1382 } |
| 1385 | 1383 |
| 1386 // No invalidation when shrinking. | 1384 // No invalidation when shrinking. |
| 1387 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1385 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 1388 invalidation.Clear(); | 1386 invalidation.Clear(); |
| 1389 } | 1387 } |
| 1390 | 1388 |
| 1391 TEST_F(PicturePileTest, SolidRectangleIsSolid) { | 1389 TEST_F(PicturePileTest, SolidRectangleIsSolid) { |
| 1392 // If the client has no contents, the solid state will be true. | 1390 // If the client has no contents, the solid state will be true. |
| 1393 Region invalidation1(tiling_rect()); | 1391 Region invalidation1(tiling_rect()); |
| 1394 UpdateAndExpandInvalidation(&invalidation1, tiling_size(), tiling_rect()); | 1392 UpdateAndExpandInvalidation(&invalidation1, tiling_size(), tiling_rect()); |
| 1395 EXPECT_TRUE(pile_->is_solid_color()); | 1393 EXPECT_TRUE(pile_.is_solid_color()); |
| 1396 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), pile_->solid_color()); | 1394 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), pile_.solid_color()); |
| 1397 | 1395 |
| 1398 // If there is a single rect that covers the view, the solid | 1396 // If there is a single rect that covers the view, the solid |
| 1399 // state will be true. | 1397 // state will be true. |
| 1400 SkPaint paint; | 1398 SkPaint paint; |
| 1401 paint.setColor(SK_ColorCYAN); | 1399 paint.setColor(SK_ColorCYAN); |
| 1402 client_.add_draw_rect(tiling_rect(), paint); | 1400 client_.add_draw_rect(tiling_rect(), paint); |
| 1403 Region invalidation2(tiling_rect()); | 1401 Region invalidation2(tiling_rect()); |
| 1404 UpdateAndExpandInvalidation(&invalidation2, tiling_size(), tiling_rect()); | 1402 UpdateAndExpandInvalidation(&invalidation2, tiling_size(), tiling_rect()); |
| 1405 EXPECT_TRUE(pile_->is_solid_color()); | 1403 EXPECT_TRUE(pile_.is_solid_color()); |
| 1406 EXPECT_EQ(SK_ColorCYAN, pile_->solid_color()); | 1404 EXPECT_EQ(SK_ColorCYAN, pile_.solid_color()); |
| 1407 | 1405 |
| 1408 // If a second smaller rect is draw that doesn't cover the viewport | 1406 // If a second smaller rect is draw that doesn't cover the viewport |
| 1409 // completely, the solid state will be false. | 1407 // completely, the solid state will be false. |
| 1410 gfx::Rect smallRect = tiling_rect(); | 1408 gfx::Rect smallRect = tiling_rect(); |
| 1411 smallRect.Inset(10, 10, 10, 10); | 1409 smallRect.Inset(10, 10, 10, 10); |
| 1412 client_.add_draw_rect(smallRect, paint); | 1410 client_.add_draw_rect(smallRect, paint); |
| 1413 Region invalidation3(tiling_rect()); | 1411 Region invalidation3(tiling_rect()); |
| 1414 UpdateAndExpandInvalidation(&invalidation3, tiling_size(), tiling_rect()); | 1412 UpdateAndExpandInvalidation(&invalidation3, tiling_size(), tiling_rect()); |
| 1415 EXPECT_FALSE(pile_->is_solid_color()); | 1413 EXPECT_FALSE(pile_.is_solid_color()); |
| 1416 | 1414 |
| 1417 // If a third rect is drawn over everything, we should be solid again. | 1415 // If a third rect is drawn over everything, we should be solid again. |
| 1418 paint.setColor(SK_ColorRED); | 1416 paint.setColor(SK_ColorRED); |
| 1419 client_.add_draw_rect(tiling_rect(), paint); | 1417 client_.add_draw_rect(tiling_rect(), paint); |
| 1420 Region invalidation4(tiling_rect()); | 1418 Region invalidation4(tiling_rect()); |
| 1421 UpdateAndExpandInvalidation(&invalidation4, tiling_size(), tiling_rect()); | 1419 UpdateAndExpandInvalidation(&invalidation4, tiling_size(), tiling_rect()); |
| 1422 EXPECT_TRUE(pile_->is_solid_color()); | 1420 EXPECT_TRUE(pile_.is_solid_color()); |
| 1423 EXPECT_EQ(SK_ColorRED, pile_->solid_color()); | 1421 EXPECT_EQ(SK_ColorRED, pile_.solid_color()); |
| 1424 | 1422 |
| 1425 // If we draw too many, we don't bother doing the analysis and we should no | 1423 // If we draw too many, we don't bother doing the analysis and we should no |
| 1426 // longer be in a solid state. There are 8 rects, two clips and a translate. | 1424 // longer be in a solid state. There are 8 rects, two clips and a translate. |
| 1427 client_.add_draw_rect(tiling_rect(), paint); | 1425 client_.add_draw_rect(tiling_rect(), paint); |
| 1428 client_.add_draw_rect(tiling_rect(), paint); | 1426 client_.add_draw_rect(tiling_rect(), paint); |
| 1429 client_.add_draw_rect(tiling_rect(), paint); | 1427 client_.add_draw_rect(tiling_rect(), paint); |
| 1430 client_.add_draw_rect(tiling_rect(), paint); | 1428 client_.add_draw_rect(tiling_rect(), paint); |
| 1431 client_.add_draw_rect(tiling_rect(), paint); | 1429 client_.add_draw_rect(tiling_rect(), paint); |
| 1432 Region invalidation5(tiling_rect()); | 1430 Region invalidation5(tiling_rect()); |
| 1433 UpdateAndExpandInvalidation(&invalidation5, tiling_size(), tiling_rect()); | 1431 UpdateAndExpandInvalidation(&invalidation5, tiling_size(), tiling_rect()); |
| 1434 EXPECT_FALSE(pile_->is_solid_color()); | 1432 EXPECT_FALSE(pile_.is_solid_color()); |
| 1435 } | 1433 } |
| 1436 | 1434 |
| 1437 } // namespace | 1435 } // namespace |
| 1438 } // namespace cc | 1436 } // namespace cc |
| OLD | NEW |