| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <map> | 5 #include <map> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "cc/resources/picture_pile.h" | 8 #include "cc/resources/picture_pile.h" |
| 9 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
| 10 #include "cc/test/fake_rendering_stats_instrumentation.h" | 10 #include "cc/test/fake_rendering_stats_instrumentation.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 PictureMap& picture_map() { return picture_map_; } | 22 PictureMap& picture_map() { return picture_map_; } |
| 23 | 23 |
| 24 typedef PicturePile::PictureInfo PictureInfo; | 24 typedef PicturePile::PictureInfo PictureInfo; |
| 25 typedef PicturePile::PictureMapKey PictureMapKey; | 25 typedef PicturePile::PictureMapKey PictureMapKey; |
| 26 typedef PicturePile::PictureMap PictureMap; | 26 typedef PicturePile::PictureMap PictureMap; |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 virtual ~TestPicturePile() {} | 29 virtual ~TestPicturePile() {} |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 TEST(PicturePileTest, SmallInvalidateInflated) { | 32 class PicturePileTest : public testing::Test { |
| 33 FakeContentLayerClient client; | 33 public: |
| 34 FakeRenderingStatsInstrumentation stats_instrumentation; | 34 PicturePileTest() |
| 35 scoped_refptr<TestPicturePile> pile = new TestPicturePile; | 35 : pile_(new TestPicturePile()), |
| 36 SkColor background_color = SK_ColorBLUE; | 36 background_color_(SK_ColorBLUE), |
| 37 min_scale_(0.125), |
| 38 frame_number_(0), |
| 39 contents_opaque_(false) { |
| 40 pile_->Resize(pile_->tiling().max_texture_size()); |
| 41 pile_->SetTileGridSize(gfx::Size(1000, 1000)); |
| 42 pile_->SetMinContentsScale(min_scale_); |
| 43 } |
| 37 | 44 |
| 38 float min_scale = 0.125; | 45 gfx::Rect layer_rect() const { return gfx::Rect(pile_->size()); } |
| 39 gfx::Size base_picture_size = pile->tiling().max_texture_size(); | |
| 40 | 46 |
| 41 gfx::Size layer_size = base_picture_size; | 47 bool Update(const Region& invalidation, const gfx::Rect& visible_layer_rect) { |
| 42 pile->Resize(layer_size); | 48 frame_number_++; |
| 43 pile->SetTileGridSize(gfx::Size(1000, 1000)); | 49 return pile_->Update(&client_, |
| 44 pile->SetMinContentsScale(min_scale); | 50 background_color_, |
| 51 contents_opaque_, |
| 52 invalidation, |
| 53 visible_layer_rect, |
| 54 frame_number_, |
| 55 &stats_instrumentation_); |
| 56 } |
| 45 | 57 |
| 46 // Update the whole layer. | 58 bool UpdateWholeLayer() { return Update(layer_rect(), layer_rect()); } |
| 47 pile->Update(&client, | 59 |
| 48 background_color, | 60 FakeContentLayerClient client_; |
| 49 false, | 61 FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 50 gfx::Rect(layer_size), | 62 scoped_refptr<TestPicturePile> pile_; |
| 51 gfx::Rect(layer_size), | 63 SkColor background_color_; |
| 52 1, | 64 float min_scale_; |
| 53 &stats_instrumentation); | 65 int frame_number_; |
| 66 bool contents_opaque_; |
| 67 }; |
| 68 |
| 69 TEST_F(PicturePileTest, SmallInvalidateInflated) { |
| 70 UpdateWholeLayer(); |
| 54 | 71 |
| 55 // Invalidate something inside a tile. | 72 // Invalidate something inside a tile. |
| 56 gfx::Rect invalidate_rect(50, 50, 1, 1); | 73 gfx::Rect invalidate_rect(50, 50, 1, 1); |
| 57 pile->Update(&client, | 74 Update(invalidate_rect, layer_rect()); |
| 58 background_color, | |
| 59 false, | |
| 60 invalidate_rect, | |
| 61 gfx::Rect(layer_size), | |
| 62 2, | |
| 63 &stats_instrumentation); | |
| 64 | 75 |
| 65 EXPECT_EQ(1, pile->tiling().num_tiles_x()); | 76 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
| 66 EXPECT_EQ(1, pile->tiling().num_tiles_y()); | 77 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
| 67 | 78 |
| 68 TestPicturePile::PictureInfo& picture_info = | 79 TestPicturePile::PictureInfo& picture_info = |
| 69 pile->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 80 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
| 70 // We should have a picture. | 81 // We should have a picture. |
| 71 EXPECT_TRUE(!!picture_info.GetPicture()); | 82 EXPECT_TRUE(!!picture_info.GetPicture()); |
| 72 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( | 83 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( |
| 73 picture_info.GetPicture()->LayerRect(), min_scale); | 84 picture_info.GetPicture()->LayerRect(), min_scale_); |
| 74 | 85 |
| 75 // The the picture should be large enough that scaling it never makes a rect | 86 // The the picture should be large enough that scaling it never makes a rect |
| 76 // smaller than 1 px wide or tall. | 87 // smaller than 1 px wide or tall. |
| 77 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << | 88 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << |
| 78 picture_rect.ToString(); | 89 picture_rect.ToString(); |
| 79 } | 90 } |
| 80 | 91 |
| 81 TEST(PicturePileTest, LargeInvalidateInflated) { | 92 TEST_F(PicturePileTest, LargeInvalidateInflated) { |
| 82 FakeContentLayerClient client; | 93 UpdateWholeLayer(); |
| 83 FakeRenderingStatsInstrumentation stats_instrumentation; | |
| 84 scoped_refptr<TestPicturePile> pile = new TestPicturePile; | |
| 85 SkColor background_color = SK_ColorBLUE; | |
| 86 | |
| 87 float min_scale = 0.125; | |
| 88 gfx::Size base_picture_size = pile->tiling().max_texture_size(); | |
| 89 | |
| 90 gfx::Size layer_size = base_picture_size; | |
| 91 pile->Resize(layer_size); | |
| 92 pile->SetTileGridSize(gfx::Size(1000, 1000)); | |
| 93 pile->SetMinContentsScale(min_scale); | |
| 94 | |
| 95 // Update the whole layer. | |
| 96 pile->Update(&client, | |
| 97 background_color, | |
| 98 false, | |
| 99 gfx::Rect(layer_size), | |
| 100 gfx::Rect(layer_size), | |
| 101 1, | |
| 102 &stats_instrumentation); | |
| 103 | 94 |
| 104 // Invalidate something inside a tile. | 95 // Invalidate something inside a tile. |
| 105 gfx::Rect invalidate_rect(50, 50, 100, 100); | 96 gfx::Rect invalidate_rect(50, 50, 100, 100); |
| 106 pile->Update(&client, | 97 Update(invalidate_rect, layer_rect()); |
| 107 background_color, | |
| 108 false, | |
| 109 invalidate_rect, | |
| 110 gfx::Rect(layer_size), | |
| 111 2, | |
| 112 &stats_instrumentation); | |
| 113 | 98 |
| 114 EXPECT_EQ(1, pile->tiling().num_tiles_x()); | 99 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
| 115 EXPECT_EQ(1, pile->tiling().num_tiles_y()); | 100 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
| 116 | 101 |
| 117 TestPicturePile::PictureInfo& picture_info = | 102 TestPicturePile::PictureInfo& picture_info = |
| 118 pile->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 103 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
| 119 EXPECT_TRUE(!!picture_info.GetPicture()); | 104 EXPECT_TRUE(!!picture_info.GetPicture()); |
| 120 | 105 |
| 121 int expected_inflation = pile->buffer_pixels(); | 106 int expected_inflation = pile_->buffer_pixels(); |
| 122 | 107 |
| 123 Picture* base_picture = picture_info.GetPicture(); | 108 Picture* base_picture = picture_info.GetPicture(); |
| 124 gfx::Rect base_picture_rect(layer_size); | 109 gfx::Rect base_picture_rect(pile_->size()); |
| 125 base_picture_rect.Inset(-expected_inflation, -expected_inflation); | 110 base_picture_rect.Inset(-expected_inflation, -expected_inflation); |
| 126 EXPECT_EQ(base_picture_rect.ToString(), | 111 EXPECT_EQ(base_picture_rect.ToString(), |
| 127 base_picture->LayerRect().ToString()); | 112 base_picture->LayerRect().ToString()); |
| 128 } | 113 } |
| 129 | 114 |
| 130 TEST(PicturePileTest, InvalidateOnTileBoundaryInflated) { | 115 TEST_F(PicturePileTest, InvalidateOnTileBoundaryInflated) { |
| 131 FakeContentLayerClient client; | 116 gfx::Size layer_size = gfx::ToFlooredSize(gfx::ScaleSize(pile_->size(), 2.f)); |
| 132 FakeRenderingStatsInstrumentation stats_instrumentation; | 117 pile_->Resize(layer_size); |
| 133 scoped_refptr<TestPicturePile> pile = new TestPicturePile; | |
| 134 SkColor background_color = SK_ColorBLUE; | |
| 135 | |
| 136 float min_scale = 0.125; | |
| 137 gfx::Size base_picture_size = pile->tiling().max_texture_size(); | |
| 138 | |
| 139 gfx::Size layer_size = | |
| 140 gfx::ToFlooredSize(gfx::ScaleSize(base_picture_size, 2.f)); | |
| 141 pile->Resize(layer_size); | |
| 142 pile->SetTileGridSize(gfx::Size(1000, 1000)); | |
| 143 pile->SetMinContentsScale(min_scale); | |
| 144 | 118 |
| 145 // Due to border pixels, we should have 3 tiles. | 119 // Due to border pixels, we should have 3 tiles. |
| 146 EXPECT_EQ(3, pile->tiling().num_tiles_x()); | 120 EXPECT_EQ(3, pile_->tiling().num_tiles_x()); |
| 147 EXPECT_EQ(3, pile->tiling().num_tiles_y()); | 121 EXPECT_EQ(3, pile_->tiling().num_tiles_y()); |
| 148 | 122 |
| 149 // We should have 1/.125 - 1 = 7 border pixels. | 123 // We should have 1/.125 - 1 = 7 border pixels. |
| 150 EXPECT_EQ(7, pile->buffer_pixels()); | 124 EXPECT_EQ(7, pile_->buffer_pixels()); |
| 151 EXPECT_EQ(7, pile->tiling().border_texels()); | 125 EXPECT_EQ(7, pile_->tiling().border_texels()); |
| 152 | 126 |
| 153 // Update the whole layer to create initial pictures. | 127 // Update the whole layer to create initial pictures. |
| 154 pile->Update(&client, | 128 UpdateWholeLayer(); |
| 155 background_color, | |
| 156 false, | |
| 157 gfx::Rect(layer_size), | |
| 158 gfx::Rect(layer_size), | |
| 159 0, | |
| 160 &stats_instrumentation); | |
| 161 | 129 |
| 162 // Invalidate everything again to have a non zero invalidation | 130 // Invalidate everything again to have a non zero invalidation |
| 163 // frequency. | 131 // frequency. |
| 164 pile->Update(&client, | 132 UpdateWholeLayer(); |
| 165 background_color, | |
| 166 false, | |
| 167 gfx::Rect(layer_size), | |
| 168 gfx::Rect(layer_size), | |
| 169 1, | |
| 170 &stats_instrumentation); | |
| 171 | 133 |
| 172 // Invalidate something just over a tile boundary by a single pixel. | 134 // Invalidate something just over a tile boundary by a single pixel. |
| 173 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). | 135 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). |
| 174 gfx::Rect invalidate_rect( | 136 gfx::Rect invalidate_rect( |
| 175 pile->tiling().TileBoundsWithBorder(0, 0).right(), | 137 pile_->tiling().TileBoundsWithBorder(0, 0).right(), |
| 176 pile->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, | 138 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, |
| 177 50, | 139 50, |
| 178 50); | 140 50); |
| 179 pile->Update(&client, | 141 Update(invalidate_rect, layer_rect()); |
| 180 background_color, | |
| 181 false, | |
| 182 invalidate_rect, | |
| 183 gfx::Rect(layer_size), | |
| 184 2, | |
| 185 &stats_instrumentation); | |
| 186 | 142 |
| 187 for (int i = 0; i < pile->tiling().num_tiles_x(); ++i) { | 143 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 188 for (int j = 0; j < pile->tiling().num_tiles_y(); ++j) { | 144 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 189 TestPicturePile::PictureInfo& picture_info = | 145 TestPicturePile::PictureInfo& picture_info = |
| 190 pile->picture_map().find( | 146 pile_->picture_map() |
| 191 TestPicturePile::PictureMapKey(i, j))->second; | 147 .find(TestPicturePile::PictureMapKey(i, j)) |
| 148 ->second; |
| 192 | 149 |
| 193 // Expect (1, 1) and (1, 0) to be invalidated once more | 150 // Expect (1, 1) and (1, 0) to be invalidated once more |
| 194 // than the rest of the tiles. | 151 // than the rest of the tiles. |
| 195 if (i == 1 && (j == 0 || j == 1)) { | 152 if (i == 1 && (j == 0 || j == 1)) { |
| 196 EXPECT_FLOAT_EQ( | 153 EXPECT_FLOAT_EQ( |
| 197 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 154 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
| 198 picture_info.GetInvalidationFrequencyForTesting()); | 155 picture_info.GetInvalidationFrequencyForTesting()); |
| 199 } else { | 156 } else { |
| 200 EXPECT_FLOAT_EQ( | 157 EXPECT_FLOAT_EQ( |
| 201 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 158 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
| 202 picture_info.GetInvalidationFrequencyForTesting()); | 159 picture_info.GetInvalidationFrequencyForTesting()); |
| 203 } | 160 } |
| 204 } | 161 } |
| 205 } | 162 } |
| 206 } | 163 } |
| 207 | 164 |
| 208 TEST(PicturePileTest, StopRecordingOffscreenInvalidations) { | 165 TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) { |
| 209 FakeContentLayerClient client; | 166 gfx::Size layer_size = gfx::ToFlooredSize(gfx::ScaleSize(pile_->size(), 4.f)); |
| 210 FakeRenderingStatsInstrumentation stats_instrumentation; | 167 pile_->Resize(layer_size); |
| 211 scoped_refptr<TestPicturePile> pile = new TestPicturePile; | |
| 212 SkColor background_color = SK_ColorBLUE; | |
| 213 | |
| 214 float min_scale = 0.125; | |
| 215 gfx::Size base_picture_size = pile->tiling().max_texture_size(); | |
| 216 | |
| 217 gfx::Size layer_size = | |
| 218 gfx::ToFlooredSize(gfx::ScaleSize(base_picture_size, 4.f)); | |
| 219 pile->Resize(layer_size); | |
| 220 pile->SetTileGridSize(gfx::Size(1000, 1000)); | |
| 221 pile->SetMinContentsScale(min_scale); | |
| 222 | 168 |
| 223 gfx::Rect viewport(0, 0, layer_size.width(), 1); | 169 gfx::Rect viewport(0, 0, layer_size.width(), 1); |
| 224 | 170 |
| 225 // Update the whole layer until the invalidation frequency is high. | 171 // Update the whole layer until the invalidation frequency is high. |
| 226 int frame; | 172 for (int frame = 0; frame < 33; ++frame) { |
| 227 for (frame = 0; frame < 33; ++frame) { | 173 UpdateWholeLayer(); |
| 228 pile->Update(&client, | |
| 229 background_color, | |
| 230 false, | |
| 231 gfx::Rect(layer_size), | |
| 232 viewport, | |
| 233 frame, | |
| 234 &stats_instrumentation); | |
| 235 } | 174 } |
| 236 | 175 |
| 237 // Make sure we have a high invalidation frequency. | 176 // Make sure we have a high invalidation frequency. |
| 238 for (int i = 0; i < pile->tiling().num_tiles_x(); ++i) { | 177 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 239 for (int j = 0; j < pile->tiling().num_tiles_y(); ++j) { | 178 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 240 TestPicturePile::PictureInfo& picture_info = | 179 TestPicturePile::PictureInfo& picture_info = |
| 241 pile->picture_map().find( | 180 pile_->picture_map() |
| 242 TestPicturePile::PictureMapKey(i, j))->second; | 181 .find(TestPicturePile::PictureMapKey(i, j)) |
| 182 ->second; |
| 243 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) | 183 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) |
| 244 << "i " << i << " j " << j; | 184 << "i " << i << " j " << j; |
| 245 } | 185 } |
| 246 } | 186 } |
| 247 | 187 |
| 248 // Update once more with a small viewport 0,0 layer_width by 1 | 188 // Update once more with a small viewport 0,0 layer_width by 1 |
| 249 pile->Update(&client, | 189 Update(layer_rect(), viewport); |
| 250 background_color, | |
| 251 false, | |
| 252 gfx::Rect(layer_size), | |
| 253 viewport, | |
| 254 frame, | |
| 255 &stats_instrumentation); | |
| 256 | 190 |
| 257 for (int i = 0; i < pile->tiling().num_tiles_x(); ++i) { | 191 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 258 for (int j = 0; j < pile->tiling().num_tiles_y(); ++j) { | 192 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 259 TestPicturePile::PictureInfo& picture_info = | 193 TestPicturePile::PictureInfo& picture_info = |
| 260 pile->picture_map().find( | 194 pile_->picture_map() |
| 261 TestPicturePile::PictureMapKey(i, j))->second; | 195 .find(TestPicturePile::PictureMapKey(i, j)) |
| 196 ->second; |
| 262 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); | 197 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); |
| 263 | 198 |
| 264 // If the y far enough away we expect to find no picture (no re-recording | 199 // If the y far enough away we expect to find no picture (no re-recording |
| 265 // happened). For close y, the picture should change. | 200 // happened). For close y, the picture should change. |
| 266 if (j >= 2) | 201 if (j >= 2) |
| 267 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; | 202 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 268 else | 203 else |
| 269 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 204 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 270 } | 205 } |
| 271 } | 206 } |
| 272 | 207 |
| 273 // Now update with no invalidation and full viewport | 208 // Now update with no invalidation and full viewport |
| 274 pile->Update(&client, | 209 Update(gfx::Rect(), layer_rect()); |
| 275 background_color, | |
| 276 false, | |
| 277 gfx::Rect(), | |
| 278 gfx::Rect(layer_size), | |
| 279 frame+1, | |
| 280 &stats_instrumentation); | |
| 281 | 210 |
| 282 for (int i = 0; i < pile->tiling().num_tiles_x(); ++i) { | 211 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 283 for (int j = 0; j < pile->tiling().num_tiles_y(); ++j) { | 212 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 284 TestPicturePile::PictureInfo& picture_info = | 213 TestPicturePile::PictureInfo& picture_info = |
| 285 pile->picture_map().find( | 214 pile_->picture_map() |
| 286 TestPicturePile::PictureMapKey(i, j))->second; | 215 .find(TestPicturePile::PictureMapKey(i, j)) |
| 216 ->second; |
| 287 // Expect the invalidation frequency to be less than 1, since we just | 217 // Expect the invalidation frequency to be less than 1, since we just |
| 288 // updated with no invalidations. | 218 // updated with no invalidations. |
| 289 float expected_frequency = | 219 float expected_frequency = |
| 290 1.0f - | 220 1.0f - |
| 291 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED; | 221 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED; |
| 292 | 222 |
| 293 EXPECT_FLOAT_EQ(expected_frequency, | 223 EXPECT_FLOAT_EQ(expected_frequency, |
| 294 picture_info.GetInvalidationFrequencyForTesting()); | 224 picture_info.GetInvalidationFrequencyForTesting()); |
| 295 | 225 |
| 296 // We expect that there are pictures everywhere now. | 226 // We expect that there are pictures everywhere now. |
| 297 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 227 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
| 298 } | 228 } |
| 299 } | 229 } |
| 300 } | 230 } |
| 301 | 231 |
| 302 } // namespace | 232 } // namespace |
| 303 } // namespace cc | 233 } // namespace cc |
| OLD | NEW |