| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "cc/layers/picture_layer.h" | 9 #include "cc/layers/picture_layer.h" |
| 10 #include "cc/test/fake_content_layer_client.h" | 10 #include "cc/test/fake_content_layer_client.h" |
| 11 #include "cc/test/fake_impl_proxy.h" | 11 #include "cc/test/fake_impl_proxy.h" |
| 12 #include "cc/test/fake_layer_tree_host_impl.h" | 12 #include "cc/test/fake_layer_tree_host_impl.h" |
| 13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
| 14 #include "cc/test/fake_picture_pile_impl.h" |
| 14 #include "cc/test/impl_side_painting_settings.h" | 15 #include "cc/test/impl_side_painting_settings.h" |
| 15 #include "cc/trees/layer_tree_impl.h" | 16 #include "cc/trees/layer_tree_impl.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/skia/include/core/SkDevice.h" | 18 #include "third_party/skia/include/core/SkDevice.h" |
| 18 #include "ui/gfx/rect_conversions.h" | 19 #include "ui/gfx/rect_conversions.h" |
| 19 | 20 |
| 20 namespace cc { | 21 namespace cc { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 class TestablePictureLayerImpl : public PictureLayerImpl { | 24 class TestablePictureLayerImpl : public PictureLayerImpl { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 LayerTreeImpl* tree_impl, | 49 LayerTreeImpl* tree_impl, |
| 49 int id, | 50 int id, |
| 50 scoped_refptr<PicturePileImpl> pile) | 51 scoped_refptr<PicturePileImpl> pile) |
| 51 : PictureLayerImpl(tree_impl, id) { | 52 : PictureLayerImpl(tree_impl, id) { |
| 52 pile_ = pile; | 53 pile_ = pile; |
| 53 SetBounds(pile_->size()); | 54 SetBounds(pile_->size()); |
| 54 CreateTilingSet(); | 55 CreateTilingSet(); |
| 55 } | 56 } |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 class TestablePicturePileImpl : public PicturePileImpl { | |
| 59 public: | |
| 60 static scoped_refptr<TestablePicturePileImpl> CreateFilledPile( | |
| 61 gfx::Size tile_size, | |
| 62 gfx::Size layer_bounds) { | |
| 63 scoped_refptr<TestablePicturePileImpl> pile(new TestablePicturePileImpl()); | |
| 64 pile->tiling().SetTotalSize(layer_bounds); | |
| 65 pile->tiling().SetMaxTextureSize(tile_size); | |
| 66 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size); | |
| 67 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) { | |
| 68 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y) | |
| 69 pile->AddRecordingAt(x, y); | |
| 70 } | |
| 71 pile->UpdateRecordedRegion(); | |
| 72 return pile; | |
| 73 } | |
| 74 | |
| 75 static scoped_refptr<TestablePicturePileImpl> CreateEmptyPile( | |
| 76 gfx::Size tile_size, | |
| 77 gfx::Size layer_bounds) { | |
| 78 scoped_refptr<TestablePicturePileImpl> pile(new TestablePicturePileImpl()); | |
| 79 pile->tiling().SetTotalSize(layer_bounds); | |
| 80 pile->tiling().SetMaxTextureSize(tile_size); | |
| 81 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size); | |
| 82 pile->UpdateRecordedRegion(); | |
| 83 return pile; | |
| 84 } | |
| 85 | |
| 86 TilingData& tiling() { return tiling_; } | |
| 87 | |
| 88 void AddRecordingAt(int x, int y) { | |
| 89 EXPECT_GE(x, 0); | |
| 90 EXPECT_GE(y, 0); | |
| 91 EXPECT_LT(x, tiling_.num_tiles_x()); | |
| 92 EXPECT_LT(y, tiling_.num_tiles_y()); | |
| 93 | |
| 94 if (HasRecordingAt(x, y)) | |
| 95 return; | |
| 96 gfx::Rect bounds(tiling().TileBounds(x, y)); | |
| 97 scoped_refptr<Picture> picture(Picture::Create(bounds)); | |
| 98 picture->Record(&client_, NULL, tile_grid_info_); | |
| 99 picture_list_map_[std::pair<int, int>(x, y)].push_back(picture); | |
| 100 EXPECT_TRUE(HasRecordingAt(x, y)); | |
| 101 | |
| 102 UpdateRecordedRegion(); | |
| 103 } | |
| 104 | |
| 105 void RemoveRecordingAt(int x, int y) { | |
| 106 EXPECT_GE(x, 0); | |
| 107 EXPECT_GE(y, 0); | |
| 108 EXPECT_LT(x, tiling_.num_tiles_x()); | |
| 109 EXPECT_LT(y, tiling_.num_tiles_y()); | |
| 110 | |
| 111 if (!HasRecordingAt(x, y)) | |
| 112 return; | |
| 113 picture_list_map_.erase(std::pair<int, int>(x, y)); | |
| 114 EXPECT_FALSE(HasRecordingAt(x, y)); | |
| 115 | |
| 116 UpdateRecordedRegion(); | |
| 117 } | |
| 118 | |
| 119 void add_draw_rect(const gfx::Rect& rect) { | |
| 120 client_.add_draw_rect(rect); | |
| 121 } | |
| 122 | |
| 123 protected: | |
| 124 TestablePicturePileImpl() : PicturePileImpl(false) {} | |
| 125 | |
| 126 virtual ~TestablePicturePileImpl() {} | |
| 127 | |
| 128 FakeContentLayerClient client_; | |
| 129 }; | |
| 130 | |
| 131 class MockCanvas : public SkCanvas { | 59 class MockCanvas : public SkCanvas { |
| 132 public: | 60 public: |
| 133 explicit MockCanvas(SkDevice* device) : SkCanvas(device) {} | 61 explicit MockCanvas(SkDevice* device) : SkCanvas(device) {} |
| 134 | 62 |
| 135 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { | 63 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { |
| 136 // Capture calls before SkCanvas quickReject() kicks in. | 64 // Capture calls before SkCanvas quickReject() kicks in. |
| 137 rects_.push_back(rect); | 65 rects_.push_back(rect); |
| 138 } | 66 } |
| 139 | 67 |
| 140 std::vector<SkRect> rects_; | 68 std::vector<SkRect> rects_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 138 } |
| 211 | 139 |
| 212 protected: | 140 protected: |
| 213 void TestTileGridAlignmentCommon() { | 141 void TestTileGridAlignmentCommon() { |
| 214 // Layer to span 4 raster tiles in x and in y | 142 // Layer to span 4 raster tiles in x and in y |
| 215 ImplSidePaintingSettings settings; | 143 ImplSidePaintingSettings settings; |
| 216 gfx::Size layer_size( | 144 gfx::Size layer_size( |
| 217 settings.default_tile_size.width() * 7 / 2, | 145 settings.default_tile_size.width() * 7 / 2, |
| 218 settings.default_tile_size.height() * 7 / 2); | 146 settings.default_tile_size.height() * 7 / 2); |
| 219 | 147 |
| 220 scoped_refptr<TestablePicturePileImpl> pending_pile = | 148 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 221 TestablePicturePileImpl::CreateFilledPile(layer_size, layer_size); | 149 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); |
| 222 scoped_refptr<TestablePicturePileImpl> active_pile = | 150 scoped_refptr<FakePicturePileImpl> active_pile = |
| 223 TestablePicturePileImpl::CreateFilledPile(layer_size, layer_size); | 151 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); |
| 224 | 152 |
| 225 SetupTrees(pending_pile, active_pile); | 153 SetupTrees(pending_pile, active_pile); |
| 226 | 154 |
| 227 host_impl_.active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f); | 155 host_impl_.active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f); |
| 228 float result_scale_x, result_scale_y; | 156 float result_scale_x, result_scale_y; |
| 229 gfx::Size result_bounds; | 157 gfx::Size result_bounds; |
| 230 active_layer_->CalculateContentsScale( | 158 active_layer_->CalculateContentsScale( |
| 231 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | 159 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 232 | 160 |
| 233 // Add 1x1 rects at the centers of each tile, then re-record pile contents | 161 // Add 1x1 rects at the centers of each tile, then re-record pile contents |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 211 |
| 284 TEST_F(PictureLayerImplTest, TileGridAlignmentHiDPI) { | 212 TEST_F(PictureLayerImplTest, TileGridAlignmentHiDPI) { |
| 285 host_impl_.SetDeviceScaleFactor(2.f); | 213 host_impl_.SetDeviceScaleFactor(2.f); |
| 286 TestTileGridAlignmentCommon(); | 214 TestTileGridAlignmentCommon(); |
| 287 } | 215 } |
| 288 | 216 |
| 289 TEST_F(PictureLayerImplTest, CloneNoInvalidation) { | 217 TEST_F(PictureLayerImplTest, CloneNoInvalidation) { |
| 290 gfx::Size tile_size(100, 100); | 218 gfx::Size tile_size(100, 100); |
| 291 gfx::Size layer_bounds(400, 400); | 219 gfx::Size layer_bounds(400, 400); |
| 292 | 220 |
| 293 scoped_refptr<TestablePicturePileImpl> pending_pile = | 221 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 294 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 222 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 295 scoped_refptr<TestablePicturePileImpl> active_pile = | 223 scoped_refptr<FakePicturePileImpl> active_pile = |
| 296 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 224 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 297 | 225 |
| 298 SetupTrees(pending_pile, active_pile); | 226 SetupTrees(pending_pile, active_pile); |
| 299 | 227 |
| 300 Region invalidation; | 228 Region invalidation; |
| 301 AddDefaultTilingsWithInvalidation(invalidation); | 229 AddDefaultTilingsWithInvalidation(invalidation); |
| 302 | 230 |
| 303 EXPECT_EQ(pending_layer_->tilings().num_tilings(), | 231 EXPECT_EQ(pending_layer_->tilings().num_tilings(), |
| 304 active_layer_->tilings().num_tilings()); | 232 active_layer_->tilings().num_tilings()); |
| 305 | 233 |
| 306 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); | 234 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); |
| 307 EXPECT_GT(tilings.num_tilings(), 0u); | 235 EXPECT_GT(tilings.num_tilings(), 0u); |
| 308 for (size_t i = 0; i < tilings.num_tilings(); ++i) | 236 for (size_t i = 0; i < tilings.num_tilings(); ++i) |
| 309 VerifyAllTilesExistAndHavePile(tilings.tiling_at(i), active_pile.get()); | 237 VerifyAllTilesExistAndHavePile(tilings.tiling_at(i), active_pile.get()); |
| 310 } | 238 } |
| 311 | 239 |
| 312 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { | 240 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { |
| 313 gfx::Size tile_size(100, 100); | 241 gfx::Size tile_size(100, 100); |
| 314 gfx::Size layer_bounds(400, 400); | 242 gfx::Size layer_bounds(400, 400); |
| 315 gfx::Rect layer_invalidation(150, 200, 30, 180); | 243 gfx::Rect layer_invalidation(150, 200, 30, 180); |
| 316 | 244 |
| 317 scoped_refptr<TestablePicturePileImpl> pending_pile = | 245 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 318 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 246 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 319 scoped_refptr<TestablePicturePileImpl> active_pile = | 247 scoped_refptr<FakePicturePileImpl> active_pile = |
| 320 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 248 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 321 | 249 |
| 322 SetupTrees(pending_pile, active_pile); | 250 SetupTrees(pending_pile, active_pile); |
| 323 | 251 |
| 324 Region invalidation(layer_invalidation); | 252 Region invalidation(layer_invalidation); |
| 325 AddDefaultTilingsWithInvalidation(invalidation); | 253 AddDefaultTilingsWithInvalidation(invalidation); |
| 326 | 254 |
| 327 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); | 255 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); |
| 328 EXPECT_GT(tilings.num_tilings(), 0u); | 256 EXPECT_GT(tilings.num_tilings(), 0u); |
| 329 for (size_t i = 0; i < tilings.num_tilings(); ++i) { | 257 for (size_t i = 0; i < tilings.num_tilings(); ++i) { |
| 330 const PictureLayerTiling* tiling = tilings.tiling_at(i); | 258 const PictureLayerTiling* tiling = tilings.tiling_at(i); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 344 else | 272 else |
| 345 EXPECT_EQ(active_pile, iter->picture_pile()); | 273 EXPECT_EQ(active_pile, iter->picture_pile()); |
| 346 } | 274 } |
| 347 } | 275 } |
| 348 } | 276 } |
| 349 | 277 |
| 350 TEST_F(PictureLayerImplTest, CloneFullInvalidation) { | 278 TEST_F(PictureLayerImplTest, CloneFullInvalidation) { |
| 351 gfx::Size tile_size(90, 80); | 279 gfx::Size tile_size(90, 80); |
| 352 gfx::Size layer_bounds(300, 500); | 280 gfx::Size layer_bounds(300, 500); |
| 353 | 281 |
| 354 scoped_refptr<TestablePicturePileImpl> pending_pile = | 282 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 355 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 283 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 356 scoped_refptr<TestablePicturePileImpl> active_pile = | 284 scoped_refptr<FakePicturePileImpl> active_pile = |
| 357 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 285 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 358 | 286 |
| 359 SetupTrees(pending_pile, active_pile); | 287 SetupTrees(pending_pile, active_pile); |
| 360 | 288 |
| 361 Region invalidation((gfx::Rect(layer_bounds))); | 289 Region invalidation((gfx::Rect(layer_bounds))); |
| 362 AddDefaultTilingsWithInvalidation(invalidation); | 290 AddDefaultTilingsWithInvalidation(invalidation); |
| 363 | 291 |
| 364 EXPECT_EQ(pending_layer_->tilings().num_tilings(), | 292 EXPECT_EQ(pending_layer_->tilings().num_tilings(), |
| 365 active_layer_->tilings().num_tilings()); | 293 active_layer_->tilings().num_tilings()); |
| 366 | 294 |
| 367 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); | 295 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); |
| 368 EXPECT_GT(tilings.num_tilings(), 0u); | 296 EXPECT_GT(tilings.num_tilings(), 0u); |
| 369 for (size_t i = 0; i < tilings.num_tilings(); ++i) | 297 for (size_t i = 0; i < tilings.num_tilings(); ++i) |
| 370 VerifyAllTilesExistAndHavePile(tilings.tiling_at(i), pending_pile.get()); | 298 VerifyAllTilesExistAndHavePile(tilings.tiling_at(i), pending_pile.get()); |
| 371 } | 299 } |
| 372 | 300 |
| 373 TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) { | 301 TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) { |
| 374 gfx::Size tile_size(90, 80); | 302 gfx::Size tile_size(90, 80); |
| 375 gfx::Size active_layer_bounds(300, 500); | 303 gfx::Size active_layer_bounds(300, 500); |
| 376 gfx::Size pending_layer_bounds(400, 800); | 304 gfx::Size pending_layer_bounds(400, 800); |
| 377 | 305 |
| 378 scoped_refptr<TestablePicturePileImpl> pending_pile = | 306 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 379 TestablePicturePileImpl::CreateFilledPile(tile_size, | 307 FakePicturePileImpl::CreateFilledPile(tile_size, |
| 380 pending_layer_bounds); | 308 pending_layer_bounds); |
| 381 scoped_refptr<TestablePicturePileImpl> active_pile = | 309 scoped_refptr<FakePicturePileImpl> active_pile = |
| 382 TestablePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds); | 310 FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds); |
| 383 | 311 |
| 384 SetupTrees(pending_pile, active_pile); | 312 SetupTrees(pending_pile, active_pile); |
| 385 | 313 |
| 386 Region invalidation; | 314 Region invalidation; |
| 387 AddDefaultTilingsWithInvalidation(invalidation); | 315 AddDefaultTilingsWithInvalidation(invalidation); |
| 388 | 316 |
| 389 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); | 317 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); |
| 390 EXPECT_GT(tilings.num_tilings(), 0u); | 318 EXPECT_GT(tilings.num_tilings(), 0u); |
| 391 for (size_t i = 0; i < tilings.num_tilings(); ++i) { | 319 for (size_t i = 0; i < tilings.num_tilings(); ++i) { |
| 392 const PictureLayerTiling* tiling = tilings.tiling_at(i); | 320 const PictureLayerTiling* tiling = tilings.tiling_at(i); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 408 EXPECT_EQ(active_pile, iter->picture_pile()); | 336 EXPECT_EQ(active_pile, iter->picture_pile()); |
| 409 } | 337 } |
| 410 } | 338 } |
| 411 } | 339 } |
| 412 } | 340 } |
| 413 | 341 |
| 414 TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) { | 342 TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) { |
| 415 gfx::Size tile_size(400, 400); | 343 gfx::Size tile_size(400, 400); |
| 416 gfx::Size layer_bounds(1300, 1900); | 344 gfx::Size layer_bounds(1300, 1900); |
| 417 | 345 |
| 418 scoped_refptr<TestablePicturePileImpl> pending_pile = | 346 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 419 TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 347 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
| 420 scoped_refptr<TestablePicturePileImpl> active_pile = | 348 scoped_refptr<FakePicturePileImpl> active_pile = |
| 421 TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 349 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
| 422 | 350 |
| 423 // Fill in some of active pile, but more of pending pile. | 351 // Fill in some of active pile, but more of pending pile. |
| 424 int hole_count = 0; | 352 int hole_count = 0; |
| 425 for (int x = 0; x < active_pile->tiling().num_tiles_x(); ++x) { | 353 for (int x = 0; x < active_pile->tiling().num_tiles_x(); ++x) { |
| 426 for (int y = 0; y < active_pile->tiling().num_tiles_y(); ++y) { | 354 for (int y = 0; y < active_pile->tiling().num_tiles_y(); ++y) { |
| 427 if ((x + y) % 2) { | 355 if ((x + y) % 2) { |
| 428 pending_pile->AddRecordingAt(x, y); | 356 pending_pile->AddRecordingAt(x, y); |
| 429 active_pile->AddRecordingAt(x, y); | 357 active_pile->AddRecordingAt(x, y); |
| 430 } else { | 358 } else { |
| 431 hole_count++; | 359 hole_count++; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 else | 394 else |
| 467 EXPECT_FALSE(*iter); | 395 EXPECT_FALSE(*iter); |
| 468 } | 396 } |
| 469 } | 397 } |
| 470 } | 398 } |
| 471 | 399 |
| 472 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) { | 400 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) { |
| 473 gfx::Size tile_size(400, 400); | 401 gfx::Size tile_size(400, 400); |
| 474 gfx::Size layer_bounds(1300, 1900); | 402 gfx::Size layer_bounds(1300, 1900); |
| 475 | 403 |
| 476 scoped_refptr<TestablePicturePileImpl> pending_pile = | 404 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 477 TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 405 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
| 478 scoped_refptr<TestablePicturePileImpl> active_pile = | 406 scoped_refptr<FakePicturePileImpl> active_pile = |
| 479 TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 407 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
| 480 | 408 |
| 481 float result_scale_x, result_scale_y; | 409 float result_scale_x, result_scale_y; |
| 482 gfx::Size result_bounds; | 410 gfx::Size result_bounds; |
| 483 | 411 |
| 484 SetupTrees(pending_pile, active_pile); | 412 SetupTrees(pending_pile, active_pile); |
| 485 | 413 |
| 486 // These are included in the scale given to the layer. | 414 // These are included in the scale given to the layer. |
| 487 host_impl_.SetDeviceScaleFactor(1.f); | 415 host_impl_.SetDeviceScaleFactor(1.f); |
| 488 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f); | 416 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f); |
| 489 | 417 |
| 490 pending_layer_->CalculateContentsScale( | 418 pending_layer_->CalculateContentsScale( |
| 491 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | 419 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 492 | 420 |
| 493 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); | 421 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); |
| 494 } | 422 } |
| 495 | 423 |
| 496 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) { | 424 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) { |
| 497 gfx::Size tile_size(400, 400); | 425 gfx::Size tile_size(400, 400); |
| 498 gfx::Size layer_bounds(1300, 1900); | 426 gfx::Size layer_bounds(1300, 1900); |
| 499 | 427 |
| 500 scoped_refptr<TestablePicturePileImpl> pending_pile = | 428 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 501 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 429 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 502 scoped_refptr<TestablePicturePileImpl> active_pile = | 430 scoped_refptr<FakePicturePileImpl> active_pile = |
| 503 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 431 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 504 | 432 |
| 505 float result_scale_x, result_scale_y; | 433 float result_scale_x, result_scale_y; |
| 506 gfx::Size result_bounds; | 434 gfx::Size result_bounds; |
| 507 | 435 |
| 508 SetupTrees(pending_pile, active_pile); | 436 SetupTrees(pending_pile, active_pile); |
| 509 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); | 437 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); |
| 510 | 438 |
| 511 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 439 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 512 EXPECT_LT(low_res_factor, 1.f); | 440 EXPECT_LT(low_res_factor, 1.f); |
| 513 | 441 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 pending_layer_->tilings().tiling_at(0)->contents_scale()); | 504 pending_layer_->tilings().tiling_at(0)->contents_scale()); |
| 577 EXPECT_FLOAT_EQ( | 505 EXPECT_FLOAT_EQ( |
| 578 1.9f * low_res_factor, | 506 1.9f * low_res_factor, |
| 579 pending_layer_->tilings().tiling_at(3)->contents_scale()); | 507 pending_layer_->tilings().tiling_at(3)->contents_scale()); |
| 580 } | 508 } |
| 581 | 509 |
| 582 TEST_F(PictureLayerImplTest, CleanUpTilings) { | 510 TEST_F(PictureLayerImplTest, CleanUpTilings) { |
| 583 gfx::Size tile_size(400, 400); | 511 gfx::Size tile_size(400, 400); |
| 584 gfx::Size layer_bounds(1300, 1900); | 512 gfx::Size layer_bounds(1300, 1900); |
| 585 | 513 |
| 586 scoped_refptr<TestablePicturePileImpl> pending_pile = | 514 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 587 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 515 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 588 scoped_refptr<TestablePicturePileImpl> active_pile = | 516 scoped_refptr<FakePicturePileImpl> active_pile = |
| 589 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 517 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 590 | 518 |
| 591 float result_scale_x, result_scale_y; | 519 float result_scale_x, result_scale_y; |
| 592 gfx::Size result_bounds; | 520 gfx::Size result_bounds; |
| 593 std::vector<PictureLayerTiling*> used_tilings; | 521 std::vector<PictureLayerTiling*> used_tilings; |
| 594 | 522 |
| 595 SetupTrees(pending_pile, active_pile); | 523 SetupTrees(pending_pile, active_pile); |
| 596 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); | 524 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); |
| 597 | 525 |
| 598 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 526 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 599 EXPECT_LT(low_res_factor, 1.f); | 527 EXPECT_LT(low_res_factor, 1.f); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 ASSERT_EQ(3u, active_layer_->tilings().num_tilings()); | 617 ASSERT_EQ(3u, active_layer_->tilings().num_tilings()); |
| 690 used_tilings.clear(); | 618 used_tilings.clear(); |
| 691 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 619 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 692 ASSERT_EQ(2u, active_layer_->tilings().num_tilings()); | 620 ASSERT_EQ(2u, active_layer_->tilings().num_tilings()); |
| 693 } | 621 } |
| 694 | 622 |
| 695 TEST_F(PictureLayerImplTest, DidLoseOutputSurface) { | 623 TEST_F(PictureLayerImplTest, DidLoseOutputSurface) { |
| 696 gfx::Size tile_size(400, 400); | 624 gfx::Size tile_size(400, 400); |
| 697 gfx::Size layer_bounds(1300, 1900); | 625 gfx::Size layer_bounds(1300, 1900); |
| 698 | 626 |
| 699 scoped_refptr<TestablePicturePileImpl> pending_pile = | 627 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 700 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 628 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 701 scoped_refptr<TestablePicturePileImpl> active_pile = | 629 scoped_refptr<FakePicturePileImpl> active_pile = |
| 702 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 630 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 703 | 631 |
| 704 float result_scale_x, result_scale_y; | 632 float result_scale_x, result_scale_y; |
| 705 gfx::Size result_bounds; | 633 gfx::Size result_bounds; |
| 706 | 634 |
| 707 SetupTrees(pending_pile, active_pile); | 635 SetupTrees(pending_pile, active_pile); |
| 708 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); | 636 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); |
| 709 | 637 |
| 710 // These are included in the scale given to the layer. | 638 // These are included in the scale given to the layer. |
| 711 host_impl_.SetDeviceScaleFactor(1.7f); | 639 host_impl_.SetDeviceScaleFactor(1.7f); |
| 712 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(3.2f, 3.2f, 3.2f); | 640 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(3.2f, 3.2f, 3.2f); |
| 713 | 641 |
| 714 pending_layer_->CalculateContentsScale( | 642 pending_layer_->CalculateContentsScale( |
| 715 1.3f, false, &result_scale_x, &result_scale_y, &result_bounds); | 643 1.3f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 716 EXPECT_EQ(2u, pending_layer_->tilings().num_tilings()); | 644 EXPECT_EQ(2u, pending_layer_->tilings().num_tilings()); |
| 717 | 645 |
| 718 // All tilings should be removed when losing output surface. | 646 // All tilings should be removed when losing output surface. |
| 719 active_layer_->DidLoseOutputSurface(); | 647 active_layer_->DidLoseOutputSurface(); |
| 720 EXPECT_EQ(0u, active_layer_->tilings().num_tilings()); | 648 EXPECT_EQ(0u, active_layer_->tilings().num_tilings()); |
| 721 pending_layer_->DidLoseOutputSurface(); | 649 pending_layer_->DidLoseOutputSurface(); |
| 722 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); | 650 EXPECT_EQ(0u, pending_layer_->tilings().num_tilings()); |
| 723 | 651 |
| 724 // This should create new tilings. | 652 // This should create new tilings. |
| 725 pending_layer_->CalculateContentsScale( | 653 pending_layer_->CalculateContentsScale( |
| 726 1.3f, false, &result_scale_x, &result_scale_y, &result_bounds); | 654 1.3f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 727 EXPECT_EQ(2u, pending_layer_->tilings().num_tilings()); | 655 EXPECT_EQ(2u, pending_layer_->tilings().num_tilings()); |
| 728 } | 656 } |
| 729 | 657 |
| 730 } // namespace | 658 } // namespace |
| 731 } // namespace cc | 659 } // namespace cc |
| OLD | NEW |